我正在尝试从我的 React-Native 应用程序中读取我的 Fitbit Versa Lite 智能手表的心率,我能够获得心率的特征,并且能够获得如下编码的 base64 格式的值
Heart Rate Data: AAAAAAAAuQAA
当我解码 base64 字符串时,它显示为
Heart Rate Data: ¹
从以下链接查看蓝牙心率规格后
<Bit index="0" size="1" name="Heart Rate Value Format bit">
<Enumerations>
<Enumeration key="0" value="Heart Rate Value Format is set to UINT8. Units: beats per
minute (bpm)" requires="C1"/>
<Enumeration key="1" value="Heart Rate Value Format is set to UINT16. Units: beats per
minute (bpm)" requires="C2"/>
</Enumerations>
</Bit>
<Field name="Heart Rate Measurement Value (uint16)">
<InformativeText> Note: The format of the Heart Rate Measurement Value field is dependent
upon bit 0 of the Flags field. </InformativeText>
<Requirement>C2</Requirement>
<Format>uint16</Format>
<Unit>org.bluetooth.unit.period.beats_per_minute</Unit>
</Field>
现在考虑链接中的上述解释,我是否需要将 1 作为测量单位或 1 作为我从心率传感器接收到的数据字节。
用于读取特征的 React-Native 代码:
async readData(device) {
const services = await device.services();
console.log("Services:",services);
const characteristics = await services[1].characteristics();
// console.log(JSON.stringify(characteristicW));
console.log("Characteristics:",characteristics);
characteristics[0].monitor((err, update) => {
if (err) {
console.log(`characteristic error: ${err}`);
console.log(JSON.stringify(err));
} else {
console.log("Is Characteristics Readable:",update.isReadable);
console.log("Heart Rate Data:",base64.decode(update.value));
var data = new Uint16Array(base64.decode(update.value));
console.log("Heart Beats:",data[1]);
}
});
}
任何帮助表示赞赏。
谢谢你。