1

我使用 gattool 连接 Linux 虚拟机(Ubuntu)上的 BLE 设备。系统中共有三个角色:peripheral、central、laptop(只接收日志信息进行调试)

连接后,我需要向外围设备发送一条消息,以便在中央与外围设备交互时向 Linux 发送日志信息。所以我的代码是这样的:

connect
# cmd for the peripheral sending out logging
char-write-cmd 0x000f 70
# enable notification
char-write-req 0x000c 0100 --listen

如果外围设备可以继续向笔记本电脑发送日志记录,它可以正常打印通知。但是,如果外围设备在 (4-5) 秒内停止发送日志记录并在此之后恢复,则笔记本电脑将不再打印出该消息。但它并没有断开,因为之后我仍然可以写入外围并收到正常的反馈。而且也没有错误(gatttool:5840): GLib-WARNING **: Invalid file descriptor.

它的可能原因是什么以及如何解决它?谢谢!

样本结果:

[02:02:02:02:02:02][LE]> connect 
Attempting to connect to 02:02:02:02:02:02
Connection successful
[02:02:02:02:02:02][LE]> char-write-cmd 0x000f 70
listen:02:02:02:02][LE]> char-write-req 0x000c 0100 --l
Characteristic value was written successfully
Notification handle = 0x000b value: 4f 55 54 5f 4e 4f 5f 4d 4f 54 0d 0a 
Notification handle = 0x000b value: 43 4d 44 3a 30 31 0d 0a 
Notification handle = 0x000b value: 4f 55 54 5f 4e 4f 5f 4d 4f 54 0d 0a 
Notification handle = 0x000b value: 43 4d 44 3a 30 31 0d 0a 
Notification handle = 0x000b value: 4f 55 54 5f 4e 4f 5f 4d 4f 54 0d 0a 
Notification handle = 0x000b value: 43 4d 44 3a 30 30 0d 0a 
Notification handle = 0x000b value: 4f 55 54 5f 4e 4f 5f 4d 4f 54 0d 0a 
Notification handle = 0x000b value: 43 4d 44 3a 30 31 0d 0a 
Notification handle = 0x000b value: 4f 55 54 5f 4e 4f 5f 4d 4f 54 0d 0a 
Notification handle = 0x000b value: 43 4d 44 3a 30 30 0d 0a 
[02:02:02:02:02:02][LE]> char-write-cmd 0x000f 01
Notification handle = 0x000b value: 4f 55 54 5f 4e 4f 5f 4d 4f 54 0d 0a 
Notification handle = 0x000b value: 43 4d 44 3a 30 31 0d 0a 
Notification handle = 0x000b value: 4f 55 54 5f 4e 4f 5f 4d 4f 54 0d 0a 
Notification handle = 0x000b value: 43 4d 44 3a 30 30 0d 0a 
Notification handle = 0x000b value: 4f 55 54 5f 4e 4f 5f 4d 4f 54 0d 0a 
Notification handle = 0x000b value: 43 4d 44 3a 30 31 0d 0a 
Notification handle = 0x000b value: 31 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 64 00 00 

经过测试,我认为它更接近于“接收通知并存储它,但直到下一个命令到gatttool时才将它打印到终端”如果我向外围设备发送一些命令,这意味着外围设备也会向笔记本电脑发送一些命令,无论 gatttool 的下一个命令是什么,它都会打印出“已保存”的通知。测试结果:

[02:02:02:02:02:02][LE]> char-desc
Notification handle = 0x000b value: 4f 55 54 5f 4e 4f 5f 4d 4f 54 0d 0a 
Notification handle = 0x000b value: 43 4d 44 3a 30 30 0d 0a 
Notification handle = 0x000b value: 4f 55 54 5f 4e 4f 5f 4d 4f 54 0d 0a 
Notification handle = 0x000b value: 43 4d 44 3a 30 30 0d 0a 
Notification handle = 0x000b value: 4f 55 54 5f 4e 4f 5f 4d 4f 54 0d 0a 
Notification handle = 0x000b value: 43 4d 44 3a 30 30 0d 0a 
Notification handle = 0x000b value: 4f 55 54 5f 4e 4f 5f 4d 4f 54 0d 0a 
Notification handle = 0x000b value: 43 4d 44 3a 30 30 0d 0a 
Notification handle = 0x000b value: 4f 55 54 5f 4e 4f 5f 4d 4f 54 0d 0a 
Notification handle = 0x000b value: 43 4d 44 3a 30 30 0d 0a 
handle: 0x0001, uuid: 00002800-0000-1000-8000-00805f9b34fb
handle: 0x0002, uuid: 00002803-0000-1000-8000-00805f9b34fb

[02:02:02:02:02:02][LE]> char-read-hnd 0x0007
Notification handle = 0x000b value: 4f 55 54 5f 4e 4f 5f 4d 4f 54 0d 0a 
Notification handle = 0x000b value: 43 4d 44 3a 30 35 0d 0a 
Notification handle = 0x000b value: 50 4f 53 5f 49 4e 53 31 5f 4e 4f 5f 4d 4f 54 0d 0a 
Notification handle = 0x000b value: 43 4d 44 3a 30 35 0d 0a 
Notification handle = 0x000b value: 50 4f 53 5f 49 4e 53 31 5f 4e 4f 5f 4d 4f 54 0d 0a 
Notification handle = 0x000b value: 43 4d 44 3a 30 35 0d 0a 
Characteristic value/descriptor: 08 00 10 00 00 00 64 00 

来自 btmon 的结果。外围设备在 19:36:30 左右发出通知,但是当我在 Linux 上发送另一个 cmd 时,btmon 上的时间戳是 19:37。

> ACL Data RX: Handl.. flags 0x02 dlen 5  #40 [hci0] 2019-10-18 19:36:13.577156
      ATT: Write Response (0x13) len 0
< ACL Data TX: Handl.. flags 0x00 dlen 9  #41 [hci0] 2019-10-18 19:37:02.057819
      ATT: Write Request (0x12) len 4
        Handle: 0x000c
          Data: 0100
> ACL Data RX: Hand.. flags 0x02 dlen 19  #42 [hci0] 2019-10-18 19:37:02.154325
      ATT: Handle Value Notification (0x1b) len 14
        Handle: 0x000b
          Data: 4f55545f4e4f5f4d4f540d0a
4

0 回答 0