[英]How do callback methods for GATT services in bluez look like?
When adding a GATT Service using BlueZ (using 'gatt_service_add()') you can specify various callback methods for ATTRIB_READ, ATTRIB_WRITE, etc. There is an example for 'reading' the characteristics already given: 使用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);
How do the methods look like for other features (eg: write)? 其他功能的方法如何(例如:写入)?
I've been working with bluez 4.101 recently bringing up a GATT server, you'll want to take a look at "linkloss.c" located (in bluez 4.101 at least) in the "proximity" directory. 我一直在使用bluez 4.101最近打开一个GATT服务器,你需要看一下位于“proximity”目录中的“linkloss.c”(至少在bluez 4.101中)。 Or here I guess: https://github.com/pauloborges/bluez/blob/master/profiles/proximity/linkloss.c 或者在这里我想: https : //github.com/pauloborges/bluez/blob/master/profiles/proximity/linkloss.c
The link loss service is registered with writable callbacks like: 链路丢失服务注册了可写回调,如:
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);
Where the callback structure is like: 回调结构如下:
static uint8_t link_loss_alert_lvl_write(struct attribute *a, struct btd_device *device, gpointer user_data)
{
/*stuff*/
}
The "attribute" struct contains the data passed to the writable callback. “attribute”结构包含传递给可写回调的数据。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.