【发布时间】: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