[英]How do I send a long notification with Bluez, example?
I need to send a long (let's say 10Kb) notification from Bluez 5.37 on my Linux device to a mobile phone. 我需要在我的Linux设备上将Bluez 5.37的长(例如10Kb)通知发送到手机。
My implementation is based on src/shared/gatt-server.c
. 我的实现基于
src/shared/gatt-server.c
。
I cannot find an example of this in Bluez. 我在Bluez找不到这个例子。
src/shared/gatt-server.c
, bt_gatt_server_send_notification()
is strictly trimming the packet to MTU-1 and discards the rest. src/shared/gatt-server.c
bt_gatt_server_send_notification()
src/shared/gatt-server.c
, bt_gatt_server_send_notification()
严格将数据包修改为MTU-1并丢弃其余数据包。 I must need an output queue for this, like in gatt-client.c
. 我必须要有一个输出队列,就像在
gatt-client.c
。 bt_gatt_client_read_long_value()
looks like an example of what I need, but for long characteristic reads. bt_gatt_client_read_long_value()
看起来像我需要的一个例子,但是对于长特征读取。
Which way is better? 哪种方式更好? Does an example of any of the three ways exist?
是否存在三种方式中的任何一种的例子?
I'm not entitled to disclose the code, but here's the basic idea of what I did. 我无权透露代码,但这是我所做的基本想法。 I use a tools/bgatt-server.c as an base for my peripheral.
我使用tools / bgatt-server.c作为我的外围设备的基础。
notification_buffer
being sent and the notification_position
in the server
's fields; notification_buffer
发送和notification_position
在server
的领域; bt_gatt_server_send_notification_with_callback()
function in gatt-server.c
. bt_gatt_server_send_notification_with_callback()
gatt-server.c
实现bt_gatt_server_send_notification_with_callback()
函数。 It should do the same as bt_gatt_server_send_notification()
but have extra void *user_data
and bt_gatt_server_destroy_func_t destroy
arguments, and pass them to bt_att_send()
. bt_gatt_server_send_notification()
一样,但是有额外的void *user_data
和bt_gatt_server_destroy_func_t destroy
参数,并将它们传递给bt_att_send()
。 This will enqueue the next invocation of destroy
callback when the bluez output queue becomes free. destroy
回调的调用排入队列。 bt_gatt_server_destroy_func_t
that calculates the next chunk to be sent from server's notification_buffer
and notification_position
fields, send them with bt_gatt_server_send_notification_with_callback()
and passes server
as user_data
and itself as the destroy
callback. bt_gatt_server_destroy_func_t
,计算从服务器的notification_buffer
和notification_position
字段发送的下一个块,使用bt_gatt_server_send_notification_with_callback()
发送它们,并将server
作为user_data
和自身作为destroy
回调传递。 messageId
and 2 bytes for packetId - this way, one can have messages up to 17*65536 bytes length. messageId
和2个字节的packetId - 这样,一个可以有长达17 * 65536字节的消息。 Plus, this leaves the opportunity to re-request a packet for reliable delivery in the future. I do this for Bluez: 我为Bluez这样做:
PRLOG("Send Notify, %d bytes\n", send_len);
do {
if (RPService.valid) {
send_res = bt_gatt_server_send_notification (pCharac->server->gatt, pCharac->handle,
pTx, mMIN(send_len, mBLE_TRANSFER_SIZE));
} else {
break;
}
if (send_res) {
pTx += mBLE_TRANSFER_SIZE;
send_len -= mBLE_TRANSFER_SIZE;
} else {
PRLOG(" Notify write failed...wait\n");
usleep(mTX_WAIT);
}
} while (send_len > 0);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.