【问题标题】:Trying to get Heart Rate Variability from Polar H10 [Bluetooth Low Energy Sample UWP]尝试从 Polar H10 [Bluetooth Low Energy Sample UWP] 获取心率变异性
【发布时间】:2019-03-28 23:21:39
【问题描述】:

我正在使用 Polar H10 来获取心率变异性。

我正在运行来自 Microsoft 的 Bluetooth Low Energy Sample

我已使用此样本从另一个极地设备 (Polar OH1) 获取心率,它运行良好。

但现在我想从 Polar H10 获取 HRV。但是 BLE 示例代码并没有真正向我展示它应该像心率一样的 HRV 特征。

这些是我看到的唯一特征:

 // first layer keys are serviceUuid's
// second layer keys are characteristicUuid's
// with their respective name/description as values
{
    "1800"    /* Generic Access */                      : {
    "2a00": "Device Name",
    "2a01": "Appearance",
    "2a02": "Peripheral Privacy Flag",
    "2a03": "Reconnection Address",
    "2a04": "Peripheral Preferred Connection Parameters"
},
"1801"    /* Generic Attribute */                   : {
    "2a05": "Service Changed"
},
"180d"    /* Heart Rate */                          : {
    "2a37": "Heart Rate Measurement",
    "2a38": "Body Sensor Location"
   // This is where it should show Heart Rate Variability //
},
"180a"    /* Device Information */                  : {
    "2a23": "System ID",
    "2a24": "Model Number String",
    "2a25": "Serial Number String",
    "2a26": "Firmware Revision String",
    "2a27": "Hardware Revision String",
    "2a28": "Software Revision String",
    "2a29": "Manufacturer Name String"
},
"180f"    /* Battery Service */                     : {
    "2a19": "Battery Level"
},
"6217ff4b-fb31-1140-ad5a-a45545d7ecf3" /* unknown */: {
    "6217ff4c-c8ec-b1fb-1380-3ad986708e2d": "unknown", /* read:true */ // value = 
     uInt16Array [3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
    "6217ff4d-91bb-91d0-7e2a-7cd3bda8a1f3": "unknown" /* write:true, 
     indicate:true, descriptors:{ descriptorUuid: "2902" }*/
 {
     /* 6172 */
     this service has all the numbers which I have no idea about. 
     Example: 10905, 10906, and etc.  
  }
}

有谁知道我应该对代码进行哪些调整才能获得 HRV?

                 **EDIT::** 


           private static ushort ParseHeartRateValue(byte[] data)
    {

        // Heart Rate profile defined flag values
        const byte heartRateValueFormat = 0x01;

        byte flags = data[0];
        bool isHeartRateValueSizeLong = ((flags & heartRateValueFormat) != 0);

        if (isHeartRateValueSizeLong)
        {
            return BitConverter.ToUInt16(data, 1);
        }
        else
        {
            return data[1];
        }
    }

////以上方法更新后//////

          private static ushort ParseHeartRateValue(byte[] data)
    {
        ushort offset = 1;
        // Heart Rate profile defined flag values
        const byte heartRateValueFormat = 0x01;

        byte flags = data[0];
        bool rr = (flags & (1 << 4)) != 0;
        if (rr)
        {
            int count = (data.Length - offset) / 2;
            for (int i = 0; i < count; i++)
            {

                ushort value = BitConverter.ToUInt16(data, offset);

                double intervalLengthInSeconds = value / 1024.0;
                offset += 2;
            }
        }
        bool isHeartRateValueSizeLong = ((flags & heartRateValueFormat) != 0);

        if (isHeartRateValueSizeLong)
        {
            return BitConverter.ToUInt16(data, 1);
        }
        else 
        {
            return data[1];
        }

    }

【问题讨论】:

  • 您应该从服务 180d 的特征 2a37 中读取值。那里描述的数据格式:bluetooth.com/specifications/gatt/…
  • 2a37 只给我像 71、82、89 这样的整数心率,每两秒变化一次。
  • 在数字设备中它们应该是模拟的吗?
  • 是的,他们应该

标签: c# windows uwp bluetooth


【解决方案1】:

您使用的设备符合心率蓝牙规范。所以它发送的数据应该遵守这个标准。如果您引用this documentation,您将阅读您在问题中列出的 0x2A37 特征,但您不应将其作为 int 接收。

特性给出的不同值列在我链接的文档中。我认为您会对分辨率为 1/1024 秒的“RR-Interval”感兴趣。

您将需要从您的值中检索所需的字节。注意字节顺序。正如文档所述:

上表中的字段按 LSO 到 MSO 的顺序排列。其中 LSO = 最低有效八位字节,MSO = 最高有效八位字节。

所以您正在寻找该值的最后 2 个字节,因为 RR-Interval 是一个 uint16。

【讨论】:

  • 如果我理解正确,您需要 RR-Interval 来计算 HRV。在 Google 上搜索“hrv 和 RR 间隔”,您会找到向您解释这一点的资源。这些是我不完全理解的医学术语,所以我不会尝试解释它们:) 关于你的问题,我找到了一个答案,其中包含用 C# 编写的用于检索 RR-Interval 的代码。检查此问题的第一个答案(由 Daniel Judge 撰写):stackoverflow.com/questions/17422218/…
  • 是intervalLengthInSeconds变量
  • 不,您需要放置一个断点来检查变量是否包含您期望的内容。之后,您可以根据需要使用它
  • 是的。并查看它包含的值
  • 恐怕我帮不了你了。我不习惯使用这种东西,所以如果它不遵循文档,我不知道是什么问题
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-06-06
  • 1970-01-01
  • 1970-01-01
  • 2021-09-13
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多