2

环境:Bluez 5.14、Linux 3.1、USB Plugable BLE radio、TI BLE keyfob (CC2541 dev kit) Linux Device <---hci----> USB BLE Radio

我们使用 gatttool 在 TI keyfob 上启用按键事件并开始监听事件

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 断开连接事件。

4

1 回答 1

1

注意 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);
}
于 2014-02-17T21:48:10.140 回答