c-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);

其他功能(例如:write)的方法看起来怎么样?

我最近一直在使用bluez 4.101,提出了一个GATT服务器,你会想看看"proximity"目录中的"linkloss.c"(至少在bluez 4.101中)。或者在这里,我想: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"结构包含传递给可写回调的数据。

相关内容

最新更新