蓝牙学习(9) GATT

8 篇文章 0 订阅

在上文中
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

Reference

https://www.bluetooth.com/specifications/assigned-numbers
https://www.bluetooth.com/specifications/gatt/declarations
https://www.bluetooth.com/specifications/gatt/descriptors

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值