试图从Polar H10获得心率变异性[蓝牙低能耗样本UWP] [英] Trying to get Heart Rate Variability from Polar H10 [Bluetooth Low Energy Sample UWP]

查看:723
本文介绍了试图从Polar H10获得心率变异性[蓝牙低能耗样本UWP]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在与Polar H10合作,以获取其心率变异性.

I am working with Polar H10 to get the Heart Rate Variability from it.

我正在运行蓝牙低能耗示例来自Microsoft.

I am running Bluetooth Low Energy Sample from Microsoft.

我已使用此样本从另一个极性设备(Polar OH1)获取心率,并且效果很好.

I have used this sample to get the heart rates from another polar device (Polar OH1) and it worked fine.

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

But now I want to get the HRV from Polar H10. But BLE sample code is not really showing me the HRV Characteristic which it should just like heart rate.

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

These are the only characteristics I am seeing:

 // 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吗?

Does anyone know what adjustments should I make to the code so that I can get 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];
        }
    }

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

////AFTER UPDATING ABOVE METHOD//////

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

    }

推荐答案

您使用的设备遵循心率蓝牙"规范.因此,它发送的数据应遵守该标准.如果您参考本文档 ,您将阅读问题中列出的0x2A37特性,但不应将其作为整数接收.

The device you use follow the Heart Rate Bluetooth specification. So the data it sends should respect this standard. if you refer to this documentation, you will read the 0x2A37 characteristic, which you listed in your question, but you should not receive it as an int.

我链接的文档中列出了特性给出的不同值.我认为您会对"RR间隔"感兴趣,该间隔的分辨率为1/1024秒.

The different values given by the characteristic are listed in the documentation I linked. I think that you will be interested by the 'RR-Interval', which is given with a resolution of 1/1024 second.

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

You will need to retrieve the required bytes from your value. Be careful about the byte order. As the documentation states:

上表中的字段按从LSO到MSO的顺序排列. LSO =最低有效八位位组,MSO =最高有效八位位组.

The fields in the above table are in the order of LSO to MSO. Where LSO = Least Significant Octet and MSO = Most Significant Octet.

因为RR间隔是一个uint16,所以您正在寻找该值的最后2个字节.

So you are looking for the last 2 bytes of the value, since the RR-Interval is an uint16.

这篇关于试图从Polar H10获得心率变异性[蓝牙低能耗样本UWP]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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