从“室内自行车数据"特征解码蓝牙数据 [英] Decode bluetooth data from the Indoor Bike Data characteristic

查看:64
本文介绍了从“室内自行车数据"特征解码蓝牙数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用健身器材服务"和室内自行车数据"特征来获取踏频数据.通过使用nRF Connect Android应用程序,我可以看到数据在那里,示例数据:

  inst.速度8.5km/h机构节奏每分钟45.0机构功率8W心率0 bpm//与十六进制相同的数据44 02 52 03 5A 00 08 00 00 

查看室内自行车数据特征的规范,它说标记字段应编码为16bit(

数据与nRF Connect Android中的上述数据不匹配.有谁知道为什么提供的数据和屏幕截图中的值不匹配以及我如何获取其余数据?

解决方案

您对flags字段进行的按位操作看起来不正确.

我已经执行以下操作:

  var ble_bytes = new Uint8Array([0x44,0x02,0x52,0x03,0x5A,0x00,0x08,0x00,0x00]).buffer;var view = new DataView(ble_bytes)标志= view.getUint16(0,true);var i;对于(i = 0; i< 16; i ++){console.log('flags ['+ i +'] ='+(!!(flags>>> i& 1)));}console.log('瞬时速度='+ view.getUint16(2,true)/100)console.log('瞬时节奏='+ view.getUint16(4,true)* 0.5)console.log('瞬时功率='+ view.getInt16(6,true))console.log('Heart Rate ='+ view.getUint8(8,true)) 

哪个给了我输出:

 >"flags [0] = false";>"flags [1] = false">"flags [2] = true">"flags [3] = false";>"flags [4] = false">"flags [5] = false">"flags [6] = true">"flags [7] = false">"flags [8] = false">"flags [9] = true">"flags [10] = false">"flags [11] = false">"flags [12] = false">"flags [13] = false">"flags [14] = false">"flags [15] = false">瞬时速度= 8.5"表示瞬时速度= 8.5".>瞬时节奏= 45">瞬时功率= 8"表示瞬时功率= 8".>心率= 0"; 

这表示存在瞬时节奏瞬时功率,<心律> .字段瞬时速度始终存在.

我已经据此转换了字节,这似乎与您从nRF Connect应用程序中获得的匹配.

I'm trying to use the Fitness Machine Service + the Indoor Bike Data characteristic to get the cadence data. By using the nRF Connect Android App I can see that the data is there, sample data:

inst. speed  8.5km/h
inst. cadence 45.0 per min
inst. power 8W
Heart rate 0 bpm

//same data as hex 44 02 52 03 5A 00 08 00 00 

Looking at spec for the Indoor Bike Data characteristic it says that the flag field should be encoded as 16bit(spec) but when I try something like,

const characteristic = await char.startNotifications()
characteristic.addEventListener('characteristicvaluechanged', (data) => {
  const flags = data.getUint16(0, true);
    
  console.table([ flags & 0x0,flags & 0x1, flags & 0x2,flags & 0x3, flags & 0x4,flags & 0x5, flags & 0x6,flags & 0x7, flags & 0x8,flags & 0x9, flags & 0x10,flags & 0x11, flags & 0x12,flags & 0x13, flags & 0x14,flags & 0x15, flags & 0x16])
});

which outputs:

The data doesn't match up with the above data from nRF Connect Android. Does anyone know why the data provided and the values in the screenshot don't match up and how I can get the rest of the data?

解决方案

Your bitwise operation on the flags field does not look to be correct.

I have done the following:

var ble_bytes = new Uint8Array([0x44, 0x02, 0x52, 0x03, 0x5A, 0x00, 0x08, 0x00, 0x00]).buffer;
var view = new DataView(ble_bytes)

flags = view.getUint16(0, true);
var i;
for (i = 0; i < 16; i++) {
  console.log('flags[' + i + '] = ' + (!!(flags >>> i & 1)));
}
console.log('Instantaneous Speed = ' + view.getUint16(2, true) / 100)
console.log('Instantaneous Cadence = ' + view.getUint16(4, true) * 0.5)
console.log('Instantaneous Power  = ' + view.getInt16(6, true))
console.log('Heart Rate  = ' + view.getUint8(8, true))

Which gave me the output of:

> "flags[0] = false"
> "flags[1] = false"
> "flags[2] = true"
> "flags[3] = false"
> "flags[4] = false"
> "flags[5] = false"
> "flags[6] = true"
> "flags[7] = false"
> "flags[8] = false"
> "flags[9] = true"
> "flags[10] = false"
> "flags[11] = false"
> "flags[12] = false"
> "flags[13] = false"
> "flags[14] = false"
> "flags[15] = false"
> "Instantaneous Speed = 8.5"
> "Instantaneous Cadence = 45"
> "Instantaneous Power  = 8"
> "Heart Rate  = 0"

Which indicates there is Instantaneous Cadence present, Instantaneous Power present, Heart Rate present. The field Instantaneous Speed is always present.

I've converted the bytes according to that and it seems to match with what you got from the nRF Connect app.

这篇关于从“室内自行车数据"特征解码蓝牙数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆