java中检测数据波动,如何从BLE制造商数据波动中获得所需值

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>

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:

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
百度地图定位Cordova插件,支持Android,IOS 可以在此地址查看example 基于百度地图Android版定位SDK(v7.1)以及百度地图IOS SDK (v3.2.1) 一,申请Android及IOS版密钥 申请密钥Android定位SDK 每一个AndroidManifest.xml 的package属性 对应一个AK,不可混用 iOS SDK开发密钥 每一个Bundle Identifier 对应一个AK,不可混用 二,安装插件```` cordova plugin add cordova-plugin-baidumaplocation --variable ANDROID_KEY="" --variable IOS_KEY="" //此处的API_KEY_XX来自于第一步,直接替换,也可以最后跟 --save 参数,将插件信息保存到config.xml //如果只需要Android端或者IOS端,可以只填写一个相应的AK,但是都不填肯定不行 三,使用方法 // 进行定位 baidumap_location.getCurrentPosition(function (result) {     console.log(JSON.stringify(result, null, 4)); }, function (error) { }); 获得定位信息,返回JSON格式数据: {     "time": "2017-02-25 17:30:00",//获取时间     "latitude": 34.6666666,//纬度     "lontitude": 117.8888,//经度     "radius": 61.9999999,//半径     //--------Android 独享 begin     "locType": 161,//定位类型                                                 "locTypeDescription": "NetWork location successful!",//定位类型解释        "userIndoorState": 1,//是否室内                                          //--------Android 独享 end     //--------IOS 独享 begin     "title": "我的位置",//定位标注点标题信息     "subtitle": "我的位置",//定位标注点子标题信息     //--------IOS 独享 end } 具体字段内容请参照: Android版 BDLocation v7.1 IOS版 BMKUserLocation 如果Android版获取到的信息是: {     "locType": 505,     "locTypeDescription": "NetWork location failed because baidu location service check the key is unlegal, please check the key in AndroidManifest.xml !",     "latitude": 5e-324,     "lontitude": 5e-324,     "radius": 0,     "userIndoorState": -1,     "direction": -1 } 说明Key有问题,可以检查下生成的AndroidManifest.xml文件里面是否有如下信息                                                           如果没有,说明插件使用不当,尝试重新安装,如果有这些信息,说明Key与当前程序AndroidManifest.xml 的package名不一致,请检查Key的申请信息是否正确 四,查看当前安装了哪些插件 cordova plugin ls 五,删除本插件 cordova plugin rm cordova-plugin-baidumaplocation 标签:cordova
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值