环境:Bluez 5.14、Linux 3.1、USB 可插拔 BLE 无线电、TI BLE 密钥卡(CC2541 开发套件)
Linux 设备 USB BLE 无线电
我们使用 gatttool 启用 TI 密钥卡上的按键事件并开始监听事件
gatttool -b [hardware ID] --char-write-req -a [handle] -n [value] --listen
(gatttool -b 90:59:AF:09:E1:5D --char-write-req -a 0x0048 -n 0100 --listen)
按密钥卡上的按钮并查看这些事件
Notification handle = 0x0047 value: 02
Notification handle = 0x0047 value: 00
Notification handle = 0x0047 value: 02
因此我们可以通过 Bluez 堆栈接收来自 Keyfob 的按键事件
客观的:
我们需要捕获 GATT 断开事件,即当我们从钥匙扣中取出电池时,GATT 连接迟早会断开。我们希望从 Bluez 堆栈接收断开连接事件。 Bluez 具有此功能,因为 Android 支持基于 Bluez 构建的 GATT 断开连接事件。
问题:
我们如何使用 Bluez 命令行 hcitool/gatttool 或 Bluez API 接收 GATT Disconnect 事件。
观察 G_IO_HUP 并正常关闭。
chan = gatt_connect(opt_src, opt_dst, opt_dst_type, opt_sec_level,
opt_psm, opt_mtu, connect_cb, &gerr);
if (chan == NULL) {
log_printf(LOG_LEVEL_ERROR,"%s: chan is NULL\n",__func__);
log_printf(LOG_LEVEL_ERROR,"%s\n", gerr->message);
g_error_free(gerr);
g_main_loop_quit(event_loop);
} else {
log_printf(LOG_LEVEL_INFO,"Connected to %s\n",opt_dst);
g_io_add_watch(chan, G_IO_HUP, channel_watcher, NULL);
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)