[英]Bleno throws an index-out-of-range error on binary data
My code, that provides a BLE service, is running under nodejs and is using bleno package. 我提供BLE服务的代码在nodejs下运行,并且正在使用bleno包。
My service characteristic supports read
and notify
. 我的服务特性支持
read
和notify
。
Here is my simplified implementation of onSubscribe
function: 这是我对
onSubscribe
函数的简化实现:
function(maxValueSize, updateValueCallback) {
var a = buildPacket();
var buf = Buffer.from(a);
console.log('Buffer: ', buf);
updateValueCallback(this.RESULT_SUCCESS, buf);
}
Function buildPacket
returns a Uint8Array
of 20 bytes. 函数
buildPacket
返回一个20字节的Uint8Array
。 The console statement shows that the buffer is of 20 bytes and has the expected values. 控制台语句显示缓冲区为20个字节并具有预期值。
However, call to updateValueCallback
throws an error: 但是,调用
updateValueCallback
会引发错误:
RangeError: Index out of range
at checkInt (buffer.js:1187:11)
at Buffer.writeUInt8 (buffer.js:1233:5)
at Gatt.<anonymous> (/home/pi/Dev/MyTest/node_modules/bleno/lib/hci socket/gatt.js:881:33)
Here is the relevant code from gatt.js: 以下是gatt.js的相关代码:
878 if (useNotify) {
879 var notifyMessage = new Buffer(3 + dataLength);
880
881 notifyMessage.writeUInt8(ATT_OP_HANDLE_NOTIFY, 0);
882 notifyMessage.writeUInt16LE(valueHandle, 1);
Is there any step I am missing? 我有什么步骤吗?
Most examples on bleno I read seem to send string data. 我读过的bleno上的大多数例子似乎都发送了字符串数据。 However, I need to send binary data.
但是,我需要发送二进制数据。 Is there anything special required for sending binary data?
发送二进制数据有什么特殊要求吗?
Turns out updateValueCallback
takes only one parameter. 原来
updateValueCallback
只接受一个参数。 I should have looked at bleno examples a bit more carefully:-(. 我应该更仔细地看一下bleno的例子:-(。
Just passing buf
as the sole parameter fixed the problem. 只是通过
buf
作为唯一参数修复了问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.