我正在运行github (Windows)的BLE样本,并试图从极地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.
}
}
现在,我知道极地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];
}
}
}
}
发布于 2018-10-22 18:29:20
如果您可以读取通知中的心跳,则还可以读取rr-间隔。rr-间隔表示为2个字节( uint16).您需要rr-间隔来计算应用程序中的心率变异性。
要获得rr-间隔,必须从接收到的第一个字节中读取标志。您将标志从右到左以二进制形式读取。
位0= 0:心率值格式设置为UINT8。单位:BPM (1字节)。
位0= 1:心率值格式设置为UINT16。单位:BPM (2字节)。
位1和2:传感器接触状态位。这些都与此无关。
位3= 0:能量消耗场不存在。
位3= 1:能量消耗场存在。Format = uint16单位:千焦耳。
位4= 0: RR-间隔值不存在.
位4= 1:存在一个或多个RR-区间值.Format = uint16单位1/1024秒。
第5、6和7条:留待将来使用。
例如,如果您的第一个字节= 16 = 0x10 = 0b00010000,那么字节2=是心率。
字节3和4是rr-间隔.
字节5和6(如果存在)rr-间隔。
要计算心率变异性,必须对一段时间内的rr-区间值进行采样,并取这些间隔的标准差。要计算标准偏差:
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!
如何在代码中做到这一点,我让你自己决定,或者你可以搜索它。
注意:
https://stackoverflow.com/questions/52882552
复制相似问题