在上文中
https://blog.csdn.net/feiwatson/article/details/82946933
配对了RaspberryPi和sensor Tag cc2650.
这里进一步读取并分析GATT
pi@raspberrypi:~ $ sudo gatttool -b 54:6C:0E:80:B4:86 --interactive
[54:6C:0E:80:B4:86][LE]> connect
Attempting to connect to 54:6C:0E:80:B4:86
Connection successful
[54:6C:0E:80:B4:86][LE]> char-desc 0x1c 0x21
handle: 0x001c, uuid: 00002800-0000-1000-8000-00805f9b34fb
handle: 0x001d, uuid: 00002803-0000-1000-8000-00805f9b34fb
handle: 0x001e, uuid: 00002a19-0000-1000-8000-00805f9b34fb
handle: 0x001f, uuid: 00002902-0000-1000-8000-00805f9b34fb
handle: 0x0020, uuid: 00002908-0000-1000-8000-00805f9b34fb
handle: 0x0021, uuid: 00002904-0000-1000-8000-00805f9b34fb
[54:6C:0E:80:B4:86][LE]> char-read-hnd 0x1c
Characteristic value/descriptor: 0f 18
[54:6C:0E:80:B4:86][LE]> char-read-hnd 0x1d
Characteristic value/descriptor: 12 1e 00 19 2a
[54:6C:0E:80:B4:86][LE]> char-read-hnd 0x1e
Characteristic value/descriptor: 59
[54:6C:0E:80:B4:86][LE]> char-read-hnd 0x1f
Characteristic value/descriptor: 00 00
[54:6C:0E:80:B4:86][LE]> char-read-hnd 0x20
Characteristic value/descriptor: 04 01
[54:6C:0E:80:B4:86][LE]> char-read-hnd 0x21
Characteristic value/descriptor: 04 00 ad 27 01 11 31
[54:6C:0E:80:B4:86][LE]>
先看handle 0x1c-0x21
[54:6C:0E:80:B4:86][LE]> char-desc 0x1c 0x21
handle: 0x001c, uuid: 00002800-0000-1000-8000-00805f9b34fb
handle: 0x001d, uuid: 00002803-0000-1000-8000-00805f9b34fb
handle: 0x001e, uuid: 00002a19-0000-1000-8000-00805f9b34fb
handle: 0x001f, uuid: 00002902-0000-1000-8000-00805f9b34fb
handle: 0x0020, uuid: 00002908-0000-1000-8000-00805f9b34fb
handle: 0x0021, uuid: 00002904-0000-1000-8000-00805f9b34fb
其中,handle 0x1c, type 为0x2800,
https://www.bluetooth.com/specifications/gatt/declarations
其值为
“UUID for a GATT Service”
读取0x21 handle的值,如下
[54:6C:0E:80:B4:86][LE]> char-read-hnd 0x1c Characteristic value/descriptor: 0f 18
得到的0x180f为custom UUID
通过primary command也可以通过UUID查到primary service的Handle
[54:6C:0E:80:B4:86][LE]> primary 0x180f
Starting handle: 0x001c Ending handle: 0x0021
接下来读取这个service的characteristc declaration
[54:6C:0E:80:B4:86][LE]> char-read-hnd 0x1d Characteristic value/descriptor: 12 1e 00 19 2a
值为12 1e 00 19 2a
其中,
0x2a19为value的UUID
0x001e为value的handle
0x12为characteristic properties
可以查到0x2a19是Battery Level的UUID
https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.characteristic.battery_level.xml
Name: Battery Level
Type: org.bluetooth.characteristic.battery_levelDownload / View
Assigned Number: 0x2A19
Abstract:
The current charge level of a battery. 100% represents fully charged while 0% represents fully discharged.
读取0x2a19的值,
[54:6C:0E:80:B4:86][LE]> char-read-hnd 0x1e Characteristic value/descriptor: 59
之前的command在读取primary service UUID 0x180f的handle时,包括handle 0x1c-0x21. 其中
handle: 0x0021, uuid: 00002904-0000-1000-8000-00805f9b34fb1
通过查看GATT Descriptor, 0x2904, 为“Characteristic Presentation Format”
https://www.bluetooth.com/specifications/gatt/descriptors
读取handle 0x21
[54:6C:0E:80:B4:86][LE]> char-read-hnd 0x21 Characteristic value/descriptor: 04 00 ad 27 01 11 31
The Characteristic Presentation Format descriptor defines the format of the Characteristic Value.
https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.descriptor.gatt.characteristic_presentation_format.xml
其中的值对应上面的链接
04:unsigned 8-bit integer
00:Exponent
0x27AD: UUID of unit
https://www.bluetooth.com/specifications/assigned-numbers/units
可以查到该unit为percentage
0x27AD percentage org.bluetooth.unit.percentage
https://www.bluetooth.com/specifications/assigned-numbers
https://www.bluetooth.com/specifications/gatt/declarations
https://www.bluetooth.com/specifications/gatt/descriptors