BLE中的心率值 [英] Heart Rate Value in BLE

查看:98
本文介绍了BLE中的心率值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很难从HR特性中获取有效值.我显然不能正确处理Dart中的值.

I am having a hard time getting a valid value out of the HR characteristics. I am clearly not handling the values properly in Dart.

示例数据:

List<int> value = [22, 56, 55, 4, 7, 3];

标志字段:我将主字节数组中的第一项转换为二进制以获取标志

Flags Field: I convert the first item in the main byte array to binary to get the flags

22 = 10110 (as binary)

这使我相信它是U16(位[0]为== 1)

this leads me to believe that it is U16 (bit[0] is == 1)

HR值:

因为它是16位,所以我试图获取1&中的字节.2个索引.然后,我尝试将它们缓冲到ByteData中.从那里,我将Endian设置为Little,将它们转换为Uint16.这给了我14136的值.显然,我缺少一些有关它应该如何工作的基本知识.

Because it is 16 bit I am trying to get the bytes in the 1 & 2 indexes. I then try to buffer them into a ByteData. From there I get convert them to Uint16 with the Endian set to Little. This is giving me a value of 14136. Clearly I am missing something fundamental about how this is supposed to work.

对于清除我不了解的有关如何处理16位BLE值的任何帮助,将不胜感激.

Any help in clearing up what I am not understanding about how to process the 16 bit BLE values would be much appreciated.

谢谢.

  /*
Constructor - constructs the heart rate value from a BLE message
 */
  HeartRate(List<int> values) {
    var flags = values[0];
    var s = flags.toRadixString(2);
    List<String> flagsArray = s.split("");

    int offset = 0;

    //Determine whether it is U16 or not
    if (flagsArray[0] == "0") {
      //Since it is Uint8 i will only get the first value
      var hr = values[1];
      print(hr);
    } else {
      //Since UTF 16 is two bytes I need to combine them
      //Create a buffer with the first two bytes after the flags
      var buffer = new Uint8List.fromList(values.sublist(1, 3)).buffer;
      var hrBuffer = new ByteData.view(buffer);
      var hr = hrBuffer.getUint16(0, Endian.little);
      print(hr);
    }
  }

推荐答案

更新后的数据看起来要好得多.这是解码方法,以及您从头开始解决这个问题的过程.

Your updated data looks much better. Here's how to decode it, and the process you'd use to figure this out yourself from scratch.

蓝牙网站最近已重组(〜2020年),特别是他们摆脱了一些文档查看器,这使查找和阅读IMO变得更加困难.所有文档都在心率服务(HRS)文档中,从 GATT页面链接,但是对于解析格式,我知道的最好的来源的XML是 org.bluetooth.characteristic.heart_rate_measurement .(自重组以来,我不知道如何在不搜索的情况下找到此页面.它似乎不再链接.)

The Bluetooth site has been reorganized recently (~2020), and in particular they got rid of some of the document viewers, which makes things much harder to find and read IMO. All the documentation is in the Heart Rate Service (HRS) document, linked from the main GATT page, but for just parsing the format, the best source I know of is the XML for org.bluetooth.characteristic.heart_rate_measurement. (Since the reorganization, I don't know how you can find this page without searching for it. It doesn't seem to be linked anymore.)

位的编号从LSB(0)到MSB(7).

Bits are numbered from LSB (0) to MSB (7).

  • 位0-心率值格式:0 =>每分钟UINT8次跳动
  • 位1-2-传感器接触状态:11 =>支持并检测到
  • 位3-能量消耗状态:0 =>不存在
  • 第4位-RR间隔:1 =>存在一个或多个值

RRS间隔的含义在上面链接的HRS文档中进行了说明.听起来您只是想获取心率值,所以我在这里不再赘述.

The meaning of RR-intervals is explained in the HRS document, linked above. It sounds like you just want the heart rate value, so I won't go into them here.

由于标志的位0为0,因此这是每分钟的心跳数.56.

Since Bit 0 of flags was 0, this is the beats per minute. 56.

您可能并不在意这些,但是这里有两个UINT16值(可以有任意数量的RR-Interval值).BLE始终是小尾数,因此[55,4]为1,079(55 + 4 << 8),[7,3]为775(7 + 3< 8).

You probably don't care about these, but there are two UINT16 values here (there can be an arbitrary number of RR-Interval values). BLE is always little-endian, so [55, 4] is 1,079 (55 + 4<<8), and [7, 3] is 775 (7 + 3<<8).

我相信文档对此有些混乱.XML建议这些值以秒为单位,但是注释说"1/1024秒的分辨率".表示这一点的正常方法是< BinaryExponent> -10</BinaryExponent> ,我敢肯定这就是他们的意思.因此,这些将是:

I believe the docs are a little confusing on this one. The XML suggests that these values are in seconds, but the comments say "Resolution of 1/1024 second." The normal way to express this would be <BinaryExponent>-10</BinaryExponent>, and I'm certain that's what they meant. So these would be:

  • RR0:1.05秒(1079/1024)
  • RR1:0.76秒(775/1024)

这篇关于BLE中的心率值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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