使用 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/