我必须读和写一些价值观的自行车智能教练与BLE (蓝牙低能)使用颤振。当我试图从GATT特性org.bluetooth.characteristic.supported_power_range (在bluetooth.org站点https://www.bluetooth.com/specifications/gatt/characteristics/上找到)读取值时,我得到了Int列表0,200,0,1,0的返回值。
关贸总协定的特点是: Min.,Max有3个sint16字段。和步长瓦茨(功率)。
Byte传输顺序还指出,最不重要的八进制是首先传输的。
我的猜测是,这3个参数是在Int数组中返回的,每个数组的值为8位。但我不能解释200的最大功率设置。因为聪明的教练应该提供最大的。2300瓦电阻(精英驱动https://www.elite-it.com/de/produkte/home-trainer/rollentrainer-interaktive/drivo)
输出结果来自以下代码片段:
device.readCharacteristic(savedCharacteristics[Characteristics.SUPPORTED_POWER_RANGE]).then((List<int> result) {
result.forEach((i) {
print(i.toString());
});
});
// result: [0,0,200,0,1,0]也许有人知道如何解释flutter_blue特征输出的二进制/十六进制/dec值。或者一些暗示是很好的
编辑
对于未来的读者,我找到了解决办法。因为我读错了特征,我有点生气。
回归值0,0,200,0,1,0为支持的抗性水平。( 20%,200显示20%,分辨率为0.1,如GATT规范所述)

我还得到了支持的功率级别的返回值,该值为0,160,15,1,0。现在,解决方案如何读取2字节的最大功率级别:您得到了160,15规范sais LSO (最不重要的八进制优先,不要混淆它与LSB最不重要的位优先)。事实上,你必须读15,160。现在,使用第一个Byte 15*256 + 160 = 4000进行计算,这是训练器支持的最大功率,就像数据表中的一样。
我希望我能帮到别人。谢谢这两个答复,他们也是正确的,并帮助我发现了我的错误。
发布于 2019-06-06 11:48:38
我也有同样的问题,连接到极地H10恢复HR和RR间隔。可能不是100%一样,但我认为我的案子可以指导你解决你的问题。
我收到的清单和你喜欢的一样,这两个例子:
[0,60][16,61,524,2]通过查看GATT蓝牙心率服务的规范,我发现所检索的列表中的每个元素都匹配您所订阅的特征所传输的数据的1字节。对于该服务,第一个字节,即列表的第一个元素,有一些标志要指出HR值(16)之后是否有RR值,或者没有(0)。这只是许多不同的情况中的两种情况,它们可以根据标志值来锁定,但我认为这表明了第一个字节是多么重要。
在此之后,HR值被编码为8位(UINT8)的无符号整数,也就是说,HR值匹配前面显示的列表中的第二个元素。然而,RR间隔被编码为一个无符号整数eith 16位(UINT16),因此它使列表#2 16、61、524、2的最后两个元素的转换复杂化,因为我们应该使用16位来获得这个值,并且字节的顺序不正确。
这是我们导入库数据的时候
import 'dart:typed_data';
...
_parseHr(List<int> value) {
// First sort the values in the list to interpret correctly the bytes
List<int> valueSorted = [];
valueSorted.insert(0, value[0]);
valueSorted.insert(1, value[1]);
for (var i=0; i< (value.length-3); i++) {
valueSorted.insert(i+2, value[i+3]);
valueSorted.insert(i+3, value[i+2]);
}
// Get flags directly from list
var flags = valueSorted[0];
// Get the ByteBuffer view of the data to recode it later
var buffer = new Uint8List.fromList(valueSorted).buffer; // Buffer bytes from list
if (flags == 0) {
// HR
var hrBuffer = new ByteData.view(buffer, 1, 1); // Get second byte
var hr = hrBuffer.getUint8(0); // Recode as UINT8
print(hr);
}
if (flags == 16) {
// HR
var hrBuffer = new ByteData.view(buffer, 1, 1); // Get second byte
var hr = hrBuffer.getUint8(0); // Recode as UINT8
// RR (more than one can be retrieved in the list)
var nRr = (valueSorted.length-2)/2; // Remove flags and hr from byte count; then split in two since RR is coded as UINT16
List<int> rrs = [];
for (var i = 0; i < nRr; i++) {
var rrBuffer = new ByteData.view(buffer, 2+(i*2), 2); // Get pairs of bytes counting since the 3rd byte
var rr = rrBuffer.getUint16(0); // Recode as UINT16
rrs.insert(i,rr);
}
print(rrs);
}希望它有所帮助,关键是获取排序列表的缓冲区视图,获取所需的字节,并按照标准指出对它们进行重新编码。
发布于 2021-02-15 22:39:18
我用了print(new String.fromCharCodes(value));,这对我来说很管用。
value是你从List<int> value = await characteristic.read();回来的
我感谢ukBaz对这个问题的回答。将数据写入BLE设备并读取其响应颤振?
发布于 2019-05-28 12:54:04
您可以使用my package 包装器将此数据转换为您可以理解的十进制值:
import 'dart:typed_data';
final buffer = Uint16List.fromList(result).buffer;// Don't forget to add it to your pubspec.yaml
//dependencies:
// byte_data_wrapper:
// git: git://github.com/Taym95/byte_data_wrapper.git
import 'byte_data_wrapper/byte_data_wrapper.dart';
final byteDataCreator = ByteDataCreator.view(buffer);// You can use getUint8() if valeu is Uint8
final min = byteDataCreator.getUint16();
final max = byteDataCreator.getUint16();
final stepSize = byteDataCreator.getUint16();https://stackoverflow.com/questions/56330018
复制相似问题