在这里定义设备名称、地址(但是实际地址好像每次复位后都是随机变化的一个不同的地址)。

这里定义了service-uuid和characteristic-uuid

刚好跟使用BlueroothLE GATT程序看到的最后两个service-uuid和characteristic-uuid相同。

Main函数代码结构:

判别有无User-Key按键按下,如果按下,并且BLE已经连接了的话,acc-service里面的axes-X轴的值加200,并更新。

在更新acc-service中,将X、Y、Z的值复制到buff,然后调用aci_gatt_update_char_value函数更新这个值。而底层协议栈更新之后,如果是notify权限,则发送notification给gatt-client,也就是我们的手机上的app。这样就出现了旋转立方体的效果。

以下是使用TI的BLE-dongle并使用BLE-Device-Monitor记录的各种属性、service、characteristic
-
<?xml version="1.0" encoding="UTF-8"?>
-
<attributes>
-
<attribute>
-
<handle>1</handle>
-
<type>0x2800</type>
-
<mnemonic>GATT Primary Service Declaration</mnemonic>
-
<value></value>
-
</attribute>
-
<attribute>
-
<handle>2</handle>
-
<type>0x2803</type>
-
<mnemonic>GATT Characteristic Declaration</mnemonic>
-
<value>20:03:00:05:2A</value>
-
</attribute>
-
<attribute>
-
<handle>3</handle>
-
<type>0x2A05</type>
-
<mnemonic>Service Changed</mnemonic>
-
<value></value>
-
</attribute>
-
<attribute>
-
<handle>4</handle>
-
<type>0x2902</type>
-
<mnemonic>Client Characteristic Configuration</mnemonic>
-
<value></value>
-
</attribute>
-
<attribute>
-
<handle>5</handle>
-
<type>0x2800</type>
-
<mnemonic>GATT Primary Service Declaration</mnemonic>
-
<value></value>
-
</attribute>
-
<attribute>
-
<handle>6</handle>
-
<type>0x2803</type>
-
<mnemonic>GATT Characteristic Declaration</mnemonic>
-
<value>4E:07:00:00:2A</value>
-
</attribute>
-
<attribute>
-
<handle>7</handle>
-
<type>0x2A00</type>
-
<mnemonic>Device Name</mnemonic>
-
<value>42:6C:75:65:4E:52:47</value>
-
</attribute>
-
<attribute>
-
<handle>8</handle>
-
<type>0x2803</type>
-
<mnemonic>GATT Characteristic Declaration</mnemonic>
-
<value>4E:09:00:01:2A</value>
-
</attribute>
-
<attribute>
-
<handle>9</handle>
-
<type>0x2A01</type>
-
<mnemonic>Appearance</mnemonic>
-
<value>02:00</value>
-
</attribute>
-
<attribute>
-
<handle>10</handle>
-
<type>0x2803</type>
-
<mnemonic>GATT Characteristic Declaration</mnemonic>
-
<value>0E:0B:00:02:2A</value>
-
</attribute>
-
<attribute>
-
<handle>11</handle>
-
<type>0x2A02</type>
-
<mnemonic>Peripheral Privacy Flag</mnemonic>
-
<value>00</value>
-
</attribute>
-
<attribute>
-
<handle>12</handle>
-
<type>0x2803</type>
-
<mnemonic>GATT Characteristic Declaration</mnemonic>
-
<value>0E:0D:00:03:2A</value>
-
</attribute>
-
<attribute>
-
<handle>13</handle>
-
<type>0x2A03</type>
-
<mnemonic>Reconnection Address</mnemonic>
-
<value>00:00:00:00:00:00</value>
-
</attribute>
-
<attribute>
-
<handle>14</handle>
-
<type>0x2803</type>
-
<mnemonic>GATT Characteristic Declaration</mnemonic>
-
<value>0A:0F:00:04:2A</value>
-
</attribute>
-
<attribute>
-
<handle>15</handle>
-
<type>0x2A04</type>
-
<mnemonic>Peripheral Preferred Connection Parameters</mnemonic>
-
<value>00:00:00:00:00:00:00:00</value>
-
</attribute>
-
<attribute>
-
<handle>16</handle>
-
<type>0x2800</type>
-
<mnemonic>GATT Primary Service Declaration</mnemonic>
-
<value></value>
-
</attribute>
-
<attribute>
-
<handle>17</handle>
-
<type>0x2803</type>
-
<mnemonic>GATT Characteristic Declaration</mnemonic>
-
<value>10:12:00:1B:C5:D5:A5:02:00:FC:8F:E1:11:4A:CF:A0:78:3E:E2</value>
-
</attribute>
-
<attribute>
-
<handle>18</handle>
-
<type>E23E78A0-CF4A-11E1-8FFC-0002A5D5C51B</type>
-
<mnemonic></mnemonic>
-
<value></value>
-
</attribute>
-
<attribute>
-
<handle>19</handle>
-
<type>0x2902</type>
-
<mnemonic>Client Characteristic Configuration</mnemonic>
-
<value>00:00</value>
-
</attribute>
-
<attribute>
-
<handle>20</handle>
-
<type>0x2803</type>
-
<mnemonic>GATT Characteristic Declaration</mnemonic>
-
<value>12:15:00:1B:C5:D5:A5:02:00:36:AC:E1:11:4B:CF:80:1B:0A:34</value>
-
</attribute>
-
<attribute>
-
<handle>21</handle>
-
<type>340A1B80-CF4B-11E1-AC36-0002A5D5C51B</type>
-
<mnemonic></mnemonic>
-
<value>58:02:00:00:00:00</value>
-
</attribute>
-
<attribute>
-
<handle>22</handle>
-
<type>0x2902</type>
-
<mnemonic>Client Characteristic Configuration</mnemonic>
-
<value>00:00</value>
-
</attribute>
-
<attribute>
-
<handle>23</handle>
-
<type>0x2800</type>
-
<mnemonic>GATT Primary Service Declaration</mnemonic>
-
<value></value>
-
</attribute>
-
<attribute>
-
<handle>24</handle>
-
<type>0x2803</type>
-
<mnemonic>GATT Characteristic Declaration</mnemonic>
-
<value>02:19:00:1B:C5:D5:A5:02:00:E3:A9:E2:11:77:E4:20:55:2E:A3</value>
-
</attribute>
-
<attribute>
-
<handle>25</handle>
-
<type>A32E5520-E477-11E2-A9E3-0002A5D5C51B</type>
-
<mnemonic></mnemonic>
-
<value>18:01</value>
-
</attribute>
-
<attribute>
-
<handle>26</handle>
-
<type>0x2904</type>
-
<mnemonic>Characteristic Presentation Format</mnemonic>
-
<value></value>
-
</attribute>
-
<attribute>
-
<handle>27</handle>
-
<type>0x2803</type>
-
<mnemonic>GATT Characteristic Declaration</mnemonic>
-
<value>02:1C:00:1B:C5:D5:A5:02:00:0B:84:E2:11:8B:E4:80:C4:20:CD</value>
-
</attribute>
-
<attribute>
-
<handle>28</handle>
-
<type>CD20C480-E48B-11E2-840B-0002A5D5C51B</type>
-
<mnemonic></mnemonic>
-
<value>20:87:01</value>
-
</attribute>
-
<attribute>
-
<handle>29</handle>
-
<type>0x2904</type>
-
<mnemonic>Characteristic Presentation Format</mnemonic>
-
<value>0F:FB:80:27:00:00:00</value>
-
</attribute>
-
<attribute>
-
<handle>30</handle>
-
<type>0x2803</type>
-
<mnemonic>GATT Characteristic Declaration</mnemonic>
-
<value>02:1F:00:1B:C5:D5:A5:02:00:73:A0:E2:11:8C:E4:60:0B:C5:01</value>
-
</attribute>
-
<attribute>
-
<handle>31</handle>
-
<type>01C50B60-E48C-11E2-A073-0002A5D5C51B</type>
-
<mnemonic></mnemonic>
-
<value>12:02</value>
-
</attribute>
-
<attribute>
-
<handle>32</handle>
-
<type>0x2904</type>
-
<mnemonic>Characteristic Presentation Format</mnemonic>
-
<value>06:FF:00:27:00:00:00</value>
-
</attribute>
-
</attributes>