BLE心率传感器值解释
我有一个Android应用程序,可从Polar H10设备获取心率测量值.我对如何解释心率完全迷失了.不幸的是,指向bluetooth.com网站的各种链接导致404错误.
I have an Android App where I get Heart Rate Measurements from a Polar H10 Device. I'm totally lost on how to interpret the heart rate. Various links to the bluetooth.com site are resulting in 404 errors unfortunately.
特征值是[16,59,83,4]
The characteristics value is i.e. [16, 59, 83, 4]
据我了解,第二个字节(59)是BPM的心率.但这似乎不是十进制数,因为该值升至127,然后继续为-127,-126,-125,...也不是十六进制.
From what I understood the second byte (59) is the heart rate in BPM. But this does not seem to be decimal as the value goes up to 127 and then goes on -127, -126, -125, ... It is not hex either.
我尝试过(在科特林)
characteristic.value[1].toUInt()
characteristic.value[1].toInt()
characteristic.value[1].toShort()
characteristic.value[1].toULong()
characteristic.value[1].toDouble()
-127出现后,所有值都会突然消失.
All values freak out as soon as the -127 appears.
我是否必须将59转换为二进制(59 = 111011)并在其中查看?请给我一些见识.
Do I have to convert the 59 to binary (59=111011) and see it in there? Please give me some insight.
###编辑(2021年4月12日)###
要获取这些值,我要做的是BluetoothDevice.connectGatt().然后按住关贸总协定.为了获得心率值,我寻找
What I do to get those values is a BluetoothDevice.connectGatt(). Then hold the GATT. In order to get heart rate values I look for
- 服务0x180d及其
- 特征0x2a37及其唯一
- 描述符0x2902.
然后,我通过在描述符上设置0x01来启用通知.然后,我在GattClientCallback.onCharacteristicChanged()回调中获取正在进行的事件.我将在下面添加所有数据的屏幕截图.
Then I enable notifications by setting 0x01 on the descriptor. I then get ongoing events in the GattClientCallback.onCharacteristicChanged() callback. I will add a screenshot below with all data.
据我了解,响应应该是6个字节长而不是4个字节,对不对?我在做什么错了?
From what I understood the response should be 6 bytes long instead of 4, right? What am I doing wrong?
在图片上,您会在最上方看到特征.它链接到服务180d,并且特性在底部保留4个字节的值.
On the picture you see the characteristic on the very top. It is linked to the service 180d and the characteristic holds the value with 4 bytes on the bottom.
看来我找到了一种通过如下方式获取值的方法
It seems I found a way by retrieving the value as follows
val hearRateDecimal = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, 1)
两件事很重要首先-UINT8的格式(尽管我不知道何时使用UINT8和何时使用UINT16.实际上我认为我需要使用UINT16,因为第一个字节实际上是16(请参阅上面的问题)秒-偏移量参数1
2 things are important first - the format of UINT8 (although I don't know when to use UINT8 and when UINT16. Actually I thought I need to use UINT16 as the first byte is actually 16 (see the question above) second - the offset parameter 1
我现在得到的是甚至超过127的整数->127,128,129,130,...
What I now get is an Integer even beyond 127 -> 127, 128, 129, 130, ...