Chinaunix首页 | 论坛 | 博客
  • 博客访问: 9465358
  • 博文数量: 1751
  • 博客积分: 12961
  • 博客等级: 上将
  • 技术积分: 20101
  • 用 户 组: 普通用户
  • 注册时间: 2009-01-09 11:25
个人简介

偷得浮生半桶水(半日闲), 好记性不如抄下来(烂笔头). 信息爆炸的时代, 学习是一项持续的工作.

文章分类

全部博文(1751)

文章存档

2024年(26)

2023年(26)

2022年(112)

2021年(217)

2020年(157)

2019年(192)

2018年(81)

2017年(78)

2016年(70)

2015年(52)

2014年(40)

2013年(51)

2012年(85)

2011年(45)

2010年(231)

2009年(287)

分类: 其他平台

2019-07-12 14:11:45


点击(此处)折叠或打开

  1. 使用ROOT

  2. #hcitool lescan ### 扫描低功耗蓝牙设备
  3.     C3:E7:A5:6A:D6:43 T207A

  4. #gatttool -b C3:E7:A5:6A:D6:43 -I ### 打开一个与远程设备的会话,-I 表示交互模式
  5.     [C3:E7:A5:6A:D6:43][LE]> help

  6. help Show this help
  7. exit Exit interactive mode
  8. quit Exit interactive mode
  9. connect [address [address type]] Connect to a remote device
  10. disconnect Disconnect from a remote device
  11. primary [UUID] Primary Service Discovery
  12. included [start hnd [end hnd]] Find Included Services
  13. characteristics [start hnd [end hnd [UUID]]] Characteristics Discovery
  14. char-desc [start hnd] [end hnd] Characteristics Descriptor Discovery
  15. char-read-hnd <handle> Characteristics Value/Descriptor Read by handle
  16. char-read-uuid <UUID> [start hnd] [end hnd] Characteristics Value/Descriptor Read by UUID
  17. char-write-req <handle> <new value> Characteristic Value Write (Write Request)
  18. char-write-cmd <handle> <new value> Characteristic Value Write (No response)
  19. sec-level [low | medium | high] Set security level. Default: low
  20. mtu <value> Exchange MTU for GATT/ATT
  21.     ### connect 表示连接远程设备,连接成功后,提示符签名的状态会显示 "CON" :
  22.     [C3:E7:A5:6A:D6:43][LE]> connect
  23.         Attempting to connect to C3:E7:A5:6A:D6:43
  24.         Connection successful
  25.     [C3:E7:A5:6A:D6:43][LE]> ### 此时 前缀颜色会变成蓝色, 代表连接成功。

  26.        ### primary 命令会列出远程设备上所有的 Service ,每个服务所在的 handle 范围
  27.     [C3:E7:A5:6A:D6:43][LE]> primary
  28.         attr handle: 0x0001, end grp handle: 0x0009 uuid: 00001800-0000-1000-8000-00805f9b34fb
  29.         attr handle: 0x000a, end grp handle: 0x000a uuid: 00001801-0000-1000-8000-00805f9b34fb
  30.         attr handle: 0x000b, end grp handle: 0xffff uuid: 680c21d9-c946-4c1f-9c11-baa1c21329e7

  31.        ### 用 primary 680c21d9-c946-4c1f-9c11-baa1c21329e7 查看 UUID 的 Service
  32.     [C3:E7:A5:6A:D6:43][LE]> primary 680c21d9-c946-4c1f-9c11-baa1c21329e7
  33.     Starting handle: 0x000b Ending handle: 0xffff
  34.  
  35.     ### 执行 characteristics 0x000b 0xffff 可以发现它有N个 characteristics :
  36.     [C3:E7:A5:6A:D6:43][LE]> characteristics 0x000b 0xffff
  37.     handle: 0x000c, char properties: 0x1a, char value handle: 0x000d, uuid: 3f0afd88-7770-46b0-b5e7-9fc099598964
  38.     handle: 0x000f, char properties: 0x12, char value handle: 0x0010, uuid: 003bbdf2-c634-4b3d-ab56-7ec889b89a37
  39.     handle: 0x0012, char properties: 0x1a, char value handle: 0x0013, uuid: a02b947e-df97-4516-996a-1882521e0ead
  40.     handle: 0x0015, char properties: 0x1a, char value handle: 0x0016, uuid: f0f26c9b-2c8c-49ac-ab60-fe03def1b40c
  41.     handle: 0x0018, char properties: 0x1a, char value handle: 0x0019, uuid: 7bd47f30-5602-4389-b069-8305731308b6
  42.     handle: 0x001b, char properties: 0x1a, char value handle: 0x001c, uuid: 80f9d8bc-3bff-45bb-a181-2d6a37991208
  43.     handle: 0x001e, char properties: 0x12, char value handle: 0x001f, uuid: 1e63b1eb-d4ed-444e-af54-c1e965192501
  44.     handle: 0x0021, char properties: 0x12, char value handle: 0x0022, uuid: 17b1613e-98f2-4436-bcde-23af17a10c72
  45.     handle: 0x0024, char properties: 0x12, char value handle: 0x0025, uuid: 28d01d60-89de-4bfa-b6e9-651ba596232c
  46.     handle: 0x0027, char properties: 0x12, char value handle: 0x0028, uuid: 5b10c428-af2f-486f-aee1-9dbd79b6bccb
  47.     handle: 0x002a, char properties: 0x12, char value handle: 0x002b, uuid: 9eed0e27-09c0-4d1c-bd92-7c441daba850
  48.     handle: 0x002d, char properties: 0x18, char value handle: 0x002e, uuid: 5955aa10-e085-4030-8aa6-bdfac89ac32b
  49.     handle: 0x0030, char properties: 0x18, char value handle: 0x0031, uuid: ed83b848-da03-4a0a-a2dc-8b401080e473
  50.     handle: 0x0033, char properties: 0x12, char value handle: 0x0034, uuid: f4a67d7d-379d-4183-9c03-4b6ea5103291
  51.     handle: 0x0036, char properties: 0x12, char value handle: 0x0037, uuid: 0eb2bc59-baf1-4c1c-8535-8a0204c69de5
  52.     ### char properties 表示 characteristic 的属性
  53.     ### char value handle 表示 characteristic 的值所在的 attribute 的 handle
  54.     

  55.     [C3:E7:A5:6A:D6:43][LE]> char-desc 0x000b 0xffff ### 列出特征值的所有 Desc
  56.         handle: 0x000b, uuid: 00002800-0000-1000-8000-00805f9b34fb
  57.         handle: 0x000c, uuid: 00002803-0000-1000-8000-00805f9b34fb
  58.         handle: 0x000d, uuid: 3f0afd88-7770-46b0-b5e7-9fc099598964
  59.         handle: 0x000e, uuid: 00002902-0000-1000-8000-00805f9b34fb
  60.         handle: 0x000f, uuid: 00002803-0000-1000-8000-00805f9b34fb
  61.         handle: 0x0010, uuid: 003bbdf2-c634-4b3d-ab56-7ec889b89a37
  62.         handle: 0x0011, uuid: 00002902-0000-1000-8000-00805f9b34fb
  63.         handle: 0x0012, uuid: 00002803-0000-1000-8000-00805f9b34fb
  64.         handle: 0x0013, uuid: a02b947e-df97-4516-996a-1882521e0ead
  65.         handle: 0x0014, uuid: 00002902-0000-1000-8000-00805f9b34fb
  66.         handle: 0x0015, uuid: 00002803-0000-1000-8000-00805f9b34fb
  67.         handle: 0x0016, uuid: f0f26c9b-2c8c-49ac-ab60-fe03def1b40c
  68.         handle: 0x0017, uuid: 00002902-0000-1000-8000-00805f9b34fb
  69.         handle: 0x0018, uuid: 00002803-0000-1000-8000-00805f9b34fb
  70.         handle: 0x0019, uuid: 7bd47f30-5602-4389-b069-8305731308b6
  71.         handle: 0x001a, uuid: 00002902-0000-1000-8000-00805f9b34fb
  72.         handle: 0x001b, uuid: 00002803-0000-1000-8000-00805f9b34fb
  73.         handle: 0x001c, uuid: 80f9d8bc-3bff-45bb-a181-2d6a37991208
  74.         handle: 0x001d, uuid: 00002902-0000-1000-8000-00805f9b34fb
  75.         handle: 0x001e, uuid: 00002803-0000-1000-8000-00805f9b34fb
  76.         handle: 0x001f, uuid: 1e63b1eb-d4ed-444e-af54-c1e965192501
  77.         handle: 0x0020, uuid: 00002902-0000-1000-8000-00805f9b34fb
  78.         handle: 0x0021, uuid: 00002803-0000-1000-8000-00805f9b34fb
  79.         handle: 0x0022, uuid: 17b1613e-98f2-4436-bcde-23af17a10c72
  80.         handle: 0x0023, uuid: 00002902-0000-1000-8000-00805f9b34fb
  81.         handle: 0x0024, uuid: 00002803-0000-1000-8000-00805f9b34fb
  82.         handle: 0x0025, uuid: 28d01d60-89de-4bfa-b6e9-651ba596232c
  83.         handle: 0x0026, uuid: 00002902-0000-1000-8000-00805f9b34fb
  84.         handle: 0x0027, uuid: 00002803-0000-1000-8000-00805f9b34fb
  85.         handle: 0x0028, uuid: 5b10c428-af2f-486f-aee1-9dbd79b6bccb
  86.         handle: 0x0029, uuid: 00002902-0000-1000-8000-00805f9b34fb
  87.         handle: 0x002a, uuid: 00002803-0000-1000-8000-00805f9b34fb
  88.         handle: 0x002b, uuid: 9eed0e27-09c0-4d1c-bd92-7c441daba850
  89.         handle: 0x002c, uuid: 00002902-0000-1000-8000-00805f9b34fb
  90.         handle: 0x002d, uuid: 00002803-0000-1000-8000-00805f9b34fb
  91.         handle: 0x002e, uuid: 5955aa10-e085-4030-8aa6-bdfac89ac32b
  92.         handle: 0x002f, uuid: 00002902-0000-1000-8000-00805f9b34fb
  93.         handle: 0x0030, uuid: 00002803-0000-1000-8000-00805f9b34fb
  94.         handle: 0x0031, uuid: ed83b848-da03-4a0a-a2dc-8b401080e473
  95.         handle: 0x0032, uuid: 00002902-0000-1000-8000-00805f9b34fb
  96.         handle: 0x0033, uuid: 00002803-0000-1000-8000-00805f9b34fb
  97.         handle: 0x0034, uuid: f4a67d7d-379d-4183-9c03-4b6ea5103291
  98.         handle: 0x0035, uuid: 00002902-0000-1000-8000-00805f9b34fb
  99.         handle: 0x0036, uuid: 00002803-0000-1000-8000-00805f9b34fb
  100.         handle: 0x0037, uuid: 0eb2bc59-baf1-4c1c-8535-8a0204c69de5
  101.         handle: 0x0038, uuid: 00002902-0000-1000-8000-00805f9b34fb

  102.     ### 从中选出一个比较注意的一个获取对应 handle 描述。例如 handle: 0x0010, uuid: 003bbdf2-c634-4b3d-ab56-7ec889b89a37
  103.     ### char-read-hnd 0x0010
  104.     [C3:E7:A5:6A:D6:43][LE]> char-read-hnd 0x0010
  105.         Characteristic value/descriptor: 02 14 f5 ff ff bb ec ff ff fc fe ff ff 5b 04 31 43 9a 0e 00 00 64 35 91 ac 19 00 00 64 93 5a ce 14 00 00 64 90 10 88 22 00 00 64
  106.         ### 当前的值为 0, 这个 characteristic 的属性是 Notify ,所以要向 handle 0x0010 写入 0x0100 (X86 是小端),使能 Notify ,然后就会不停的收到数据
  107.     
  108.     [C3:E7:A5:6A:D6:43][LE]> char-write-req 0x0010 0100
  109.         Notification handle = 0x001a value: 41 47 3a 20 37 30 34 38 20 37 30 39 35 20 36 30 20 2d 31 37
  110.         ...


  111.     以上的步骤可以使用一个命令实现,即在非交互模式下,用 --listen 选项启动监听模式来接收通知:
  112.     #gatttool -b C3:E7:A5:6A:D6:43 --char-write-req --handle=0x001b --value=0100 --listen
  113.     如果只是读取某个handle的内容, 则
  114.     #gatttool -b C3:E7:A5:6A:D6:43 --char-read --handle=0x0010
  115.       Characteristic value/descriptor: 02 14 f5 ff ff bb ec ff ff fc fe ff ff 5b 04 31 43 9a 0e 00 00 64 35 91 ac 19 00 00 64 93 5a ce 14 00 00 64 90 10 88 22 00 00 64
#gatttool --help-all
Usage:
  gatttool [OPTION...]
Help Options:
  -h, --help                                Show help options
  --help-all                                Show all help options
  --help-gatt                               Show all GATT commands
  --help-params                             Show all Primary Services/Characteristics arguments
  --help-char-read-write                    Show all Characteristics Value/Descriptor Read/Write arguments


GATT commands
  --primary                                 Primary Service Discovery
  --characteristics                         Characteristics Discovery
  --char-read                               Characteristics Value/Descriptor Read
  --char-write                              Characteristics Value Write Without Response (Write Command)
  --char-write-req                          Characteristics Value Write (Write Request)
  --char-desc                               Characteristics Descriptor Discovery
  --listen                                  Listen for notifications and indications


Primary Services/Characteristics arguments
  -s, --start=0x0001                        Starting handle(optional)
  -e, --end=0xffff                          Ending handle(optional)
  -u, --uuid=0x1801                         UUID16 or UUID128(optional)


Characteristics Value/Descriptor Read/Write arguments
  -a, --handle=0x0001                       Read/Write characteristic by handle(required)
  -n, --value=0x0001                        Write characteristic value (required for write operation)


Application Options:
  -i, --adapter=hciX                        Specify local adapter interface
  -b, --device=MAC                          Specify remote Bluetooth address
  -t, --addr-type=[public | random]         Set LE address type. Default: public
  -m, --mtu=MTU                             Specify the MTU size
  -p, --psm=PSM                             Specify the PSM for GATT/ATT over BR/EDR
  -l, --sec-level=[low | medium | high]     Set security level. Default: low
  -I, --interactive                         Use interactive mode
阅读(6363) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

iibull2019-07-12 14:48:13

如果要变成C的代码, 只能参考 bluez/blob/master/attrib/gatttool.c