【问题标题】:Getting Heart-rate variability from Polar H10 (UWP)从 Polar H10 (UWP) 获取心率变异性
【发布时间】:2018-10-26 23:41:50
【问题描述】:

我正在从 github (Windows) 运行 BLE 示例,并尝试从 Polar H10 获取心率变异性。

但是,它向我展示的唯一服务和特征如下:

// 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"
    },
    "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.  
     }
}

现在,我知道 Polar H10 确实可以为您提供心率变异性。那么为什么它没有显示给我呢?

有人知道吗?

编辑::

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

        byte flags = data[0];
        ushort offset = 1;
        bool HRC2 = (flags & 1) == 1;
        if (HRC2) //this means the BPM is un uint16
        {
            short hr = BitConverter.ToInt16(data, offset);
            offset += 2;
        }
        else //BPM is uint8
        {
            byte hr = data[offset];
            offset += 1;
        }

        //see if EE is available
        //if so, pull 2 bytes

        bool ee = (flags & (1 << 3)) != 0;
        if (ee)
            offset += 2;

        // see if RR is present 
        // if so, the number of RR values is total bytes left / 2(size of uInt 16)

        bool rr = ((flags & 1 << 4) != 0);
        if (rr)
        {
            int count = (data.Length - offset) / 2;
            for (int i = 0; i < count; i++)
            {
                //each existence of these values means an R-Wave was already detected
                //the ushort means the time (1/1024 seconds) since last r-wave

                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];
        }

      }
   }
 }

【问题讨论】:

  • 首先我们需要知道您是否能够读取来自特征 00002a37-0000-1000-8000-00805f9b34f 的通知。
  • 是的。这个特征给了我心率。

标签: c# uwp bluetooth-lowenergy


【解决方案1】:

如果您可以在通知中读取心跳,那么还有 rr-interval。 rr 间隔表示为 2 个字节(uint16)。 您需要 rr-interval 来计算应用中的心率变异性。

要获得 rr 间隔,您必须从收到的第一个字节中读取标志。 您从右到左将标志读取为二进制。

位 0 = 0:心率值格式设置为 UINT8。单位:BPM(1 字节)。
位 0 = 1:心率值格式设置为 UINT16。单位:BPM(2 字节)。

位 1 和 2:传感器接触状态位。这些与此无关。

位 3 = 0:能量消耗字段不存在。
位 3 = 1:存在能量消耗字段。格式 = uint16。单位:千焦耳。

位 4 = 0:RR 间隔值不存在。
位 4 = 1:存在一个或多个 RR-Interval 值。格式 = uint16。单位 1/1024 秒。

第 5、6 和 7 位:保留以供将来使用。

如果你的第一个字节例如 = 16 = 0x10 = 0b00010000 那么字节 2 = 是心率。

字节 3 和 4 是 rr 间隔。
字节 5 和 6(如果存在)rr 间隔。

要计算心率变异性,您必须在一段时间内对 rr-interval 值进行采样,并获取这些间隔的标准偏差。 计算标准差:

1. Work out the Mean (the simple average of the numbers)
2. Then for each number: subtract the Mean and square the result
3. Then work out the mean of those squared differences.
4. Take the square root of that and we are done!

如何在代码中做到这一点,我把它留给你,或者你可以谷歌它。

注意:

  1. SIG 规范中的字节对是最低有效字节优先, 所以对于 Windows 中的 uint16 表示,首先交换字节对的字节!
  2. rr-interval 不是毫秒,而是 1/1024 秒。 这是为了防止在无符号除法中丢失十进制数。

【讨论】:

  • 我获取心跳的方式只是普通整数。例如 77、81,它每两秒改变一次。它与 Microsoft 的低功耗蓝牙示例 C# 一起使用。如果您在此处查看图像(心率标记为红色和黄色)链接:ibb.co/m2tqrp 忽略设备名称。我之前也在做这个,基本上是一样的。
  • 如果您使用的是 Windows-universal-samples/Samples/BluetoothLE/cs/Scenario2_Client.xaml.cs,则使用 FormatValueByPresentation 和 ParseHeartRateValue 从原始字节数组中过滤心跳。接收到的字节数组中有更多字节未被此示例使用。这就是为什么我在回答中解释了如何获取和解释接收到的字节数组。
  • 是的,这正是我正在使用的。 [ Windows-universal-samples/Samples/BluetoothLE/cs/Scenario2_Client.xaml.cs ] 但我很困惑。我必须对此代码进行哪些调整?我相信你所解释的是正确的。但我真的不知道如何使用它。
  • 我可以更改该示例代码以获得心率变异性特征吗?
  • 我没有 Polar H10,因此无法进行任何测试。完全可以更改示例代码。在私有静态 ushort ParseHeartRateValue(byte[] data) 中的某处放置一个断点并检查数据的内容。让我知道包含的所有字节,也许我可以写一些代码。
猜你喜欢
  • 2019-03-28
  • 1970-01-01
  • 2020-06-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多