如何从BLE制造商数据波动中获得所需值 [英] How to get desired values from BLE manufacturer data flutter
问题描述
我是扑朔迷离的新手,并且正在开发一个从BLE信标读取数据的应用程序.我已经扫描了设备,并获得了制造商数据{256:[0,0,0,16,1,57,33,18,0,0,154,10,0,0,94,0]}
设备制造商告诉我输入设备数据,例如:
KCBAdvDataManufacturerData =< .............. be是21 01 00 50 08 00 00 5e ..>
UUID-kCBAdvDataManufacturerData数据包包含传感器数据,如下所示:
字节索引8 – 11 =压力32位值
字节索引12 – 15 =温度32位值
字节索引16 =电池电量百分比
我完全不知道在Dart中如何从中实现它
{256:[0,0,0,16,1,57,33,18,0,0,154,10,0,0,94,0]}
到
字节索引8 – 11 =压力32位值
字节索引12 – 15 =温度32位值
字节索引16 =电池电量百分比
然后 以人类可理解的形式 这里的温度是以PSI为单位的C压力,电池是以%为单位.
有一个字节列表,因此您可以使用将4字节转换为有符号整数
我不确定为您提供的索引值看起来是否正确.我假设数据采用小尾数格式,所以我对数据的假设是:>
压力= [33,18,0,0] = 4641(您期望值约为46.41psi吗?)
温度= [154,10,0,0] = 2714(您是否期望值约为27.14c?)
电池= [94] = 94(您期望值94%吗?)
这可以通过以下方式完成:
import 'dart:typed_data';
var manufacturerData = Uint8List.fromList([0,0,0,16,1,57,33,18,0,0,154,10,0,0,94,0]);
var pressure = ByteData.sublistView(manufacturerData, 6, 10);
var temperature = ByteData.sublistView(manufacturerData, 10, 14);
var battery = ByteData.sublistView(manufacturerData, 14, 15);
main() {
print(pressure.getUint32(0, Endian.little));
print(temperature.getUint32(0, Endian.little));
print(battery.getUint8(0));
}
给我输出:
4641
2714
94
I am new to flutter and I am working on an app that reads data from a BLE beacon. I have scanned the device and got the manufacturer data as {256:[0,0,0,16,1,57,33,18,0,0,154,10,0,0,94,0]}
the device manufacturer told me to device data like :
KCBAdvDataManufacturerData = <.. .. .. .. .. .. .. .. be 21 01 00 50 08 00 00 5e ..>
The UUID - kCBAdvDataManufacturerData packet contains the sensor data as shown below:
Byte index 8 – 11 = Pressure 32bit value
Byte index 12 – 15 = Temperature 32bit value
Byte index 16 = Battery level in percentage
I am totally not getting any idea that in Dart how can I achieve it from
{256:[0,0,0,16,1,57,33,18,0,0,154,10,0,0,94,0]}
to
Byte index 8 – 11 = Pressure 32bit value
Byte index 12 – 15 = Temperature 32bit value
Byte index 16 = Battery level in percentage
and then in a human-understandable form here temperature is in C pressure in PSI and battery is in %.
There is a list of bytes so you can get sublists from that list with https://api.dart.dev/stable/2.9.1/dart-core/List/sublist.html
That sublist can be converted from 4 bytes into a signed integer for the pressure and temperature values:
Convert 4 byte into a signed integer
I am not sure the index values you have been given look quite right. I am assuming the data is in little endian format so my assumption on the data is:
Pressure = [33,18,0,0] = 4641 (Are you expecting a value of about 46.41psi?)
Temperature = [154,10,0,0] = 2714 (Are you expecting a value of about 27.14c?)
Battery = [94] = 94 (Are you expecting a value of 94%?)
This might be done like the following:
import 'dart:typed_data';
var manufacturerData = Uint8List.fromList([0,0,0,16,1,57,33,18,0,0,154,10,0,0,94,0]);
var pressure = ByteData.sublistView(manufacturerData, 6, 10);
var temperature = ByteData.sublistView(manufacturerData, 10, 14);
var battery = ByteData.sublistView(manufacturerData, 14, 15);
main() {
print(pressure.getUint32(0, Endian.little));
print(temperature.getUint32(0, Endian.little));
print(battery.getUint8(0));
}
Gives me the output:
4641
2714
94
这篇关于如何从BLE制造商数据波动中获得所需值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!