c - bluez 中 GATT 服务的回调方法是什么样的?

标签 c bluetooth-lowenergy bluez gatt

使用 BlueZ 添加 GATT 服务(使用“gatt_service_add()”)时,您可以为 ATTRIB_READ、ATTRIB_WRITE 等指定各种回调方法。有一个“读取”已给定特征的示例:

static uint8_t battery_state_read(struct attribute *a,  struct btd_device *device, gpointer user_data);

其他功能(例如:写入)的方法是什么样的?

最佳答案

我最近一直在使用 bluez 4.101 来启动 GATT 服务器,您需要查看位于“proximity”目录中(至少在 bluez 4.101 中)的“linkloss.c”。或者我猜这里: https://github.com/pauloborges/bluez/blob/master/profiles/proximity/linkloss.c

链接丢失服务是通过可写回调注册的,例如:

svc_added = gatt_service_add(adapter,
        GATT_PRIM_SVC_UUID, &uuid,
        /* Alert level characteristic */
        GATT_OPT_CHR_UUID16, ALERT_LEVEL_CHR_UUID,
        GATT_OPT_CHR_PROPS,
            ATT_CHAR_PROPER_READ | ATT_CHAR_PROPER_WRITE,
        GATT_OPT_CHR_VALUE_CB, ATTRIB_READ,
            link_loss_alert_lvl_read, lladapter,
        GATT_OPT_CHR_VALUE_CB, ATTRIB_WRITE,
            link_loss_alert_lvl_write, lladapter,
        GATT_OPT_CHR_VALUE_GET_HANDLE,
            &lladapter->alert_lvl_value_handle,
        GATT_OPT_INVALID);

回调结构如下:

static uint8_t link_loss_alert_lvl_write(struct attribute *a, struct btd_device *device, gpointer user_data)
{
 /*stuff*/
}

“attribute”结构包含传递给可写回调的数据。

关于c - bluez 中 GATT 服务的回调方法是什么样的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22957711/

相关文章:

bluetooth-lowenergy - 写入 GATT 描述符会产生写入不允许错误

android - 如何使用 RSSI 改进蓝牙距离测量?

iphone - 将 iPhone 与 2 个低能耗设备连接

bluetooth - 无法连接到 Raspberry Pi 上的 BLE 设备

c - 如何用 C 中的结构修复无限循环

c - C 中 mktime 的不一致结果

c - 用我自己的 close() 函数替换 Linux 中的 close() 函数

c - 通过引用传递 char

ios - 带有 Bluez 和 Bleno 的覆盆子蓝牙外设

android - 在 Raspberry pi3 上使用 C (BlueZ) 的蓝牙不会写入 Android。读书没问题