转换来自设备的 React 本机 BLE 响应
Convert React native BLE response from device
我写信给你是因为我需要帮助转换来自 BLE 设备的回复,我想将其转换为可理解的数据,但我没有做到。我用的是 React native BLE manager library,蓝牙设备的文档是这样的。
"peripheral": "D6:AD:15:67:4A:A5", "service": "XXXXX-XXXXX-XXXXXX", "value": [85, 0, 255, 0, 0, 13, 0, 96, 93, 0, 0, 0, 0, 0, 49, 0, 0, 0, 1, 0]
从外围设备返回的值似乎映射到文档,如下所示:
85 = 0x55 = ACK Header
0 = 0x00 = ACKCMD
255 = 0xFF = ~ACKCMD_OK
0, 0 = 0x0000 = ACK_PKT_NR
13, 0 = 0x0d = ACK_BUF_SIZE
96 = 0x60 = SpO2
93, 0 = 0x5d00 = Pulse Rate
0, 0, 0, 0 = 0x00000000 = Step Count
49 = 0x31 = Battery
0 = 0x00 = Charging Status
0 = 0x00 = 3-axis
0 = 0x00 = PI
1 = 0x01 = Current state
0 = 0x00 = Reserved
要获得这些值,代码类似于:
const bytes = new Uint8Array([85, 0, 255, 0, 0, 13, 0, 96, 93, 0, 0, 0, 0, 0, 49, 0, 0, 0, 1, 0]);
const pulse = new DataView(bytes.buffer).getUint16(8, true)
const battery = new Uint8Array(bytes.buffer)[14];
console.log('Pulse Rate:' + pulse);
console.log('Battery Leve:' + battery);
我写信给你是因为我需要帮助转换来自 BLE 设备的回复,我想将其转换为可理解的数据,但我没有做到。我用的是 React native BLE manager library,蓝牙设备的文档是这样的。
"peripheral": "D6:AD:15:67:4A:A5", "service": "XXXXX-XXXXX-XXXXXX", "value": [85, 0, 255, 0, 0, 13, 0, 96, 93, 0, 0, 0, 0, 0, 49, 0, 0, 0, 1, 0]
从外围设备返回的值似乎映射到文档,如下所示:
85 = 0x55 = ACK Header
0 = 0x00 = ACKCMD
255 = 0xFF = ~ACKCMD_OK
0, 0 = 0x0000 = ACK_PKT_NR
13, 0 = 0x0d = ACK_BUF_SIZE
96 = 0x60 = SpO2
93, 0 = 0x5d00 = Pulse Rate
0, 0, 0, 0 = 0x00000000 = Step Count
49 = 0x31 = Battery
0 = 0x00 = Charging Status
0 = 0x00 = 3-axis
0 = 0x00 = PI
1 = 0x01 = Current state
0 = 0x00 = Reserved
要获得这些值,代码类似于:
const bytes = new Uint8Array([85, 0, 255, 0, 0, 13, 0, 96, 93, 0, 0, 0, 0, 0, 49, 0, 0, 0, 1, 0]);
const pulse = new DataView(bytes.buffer).getUint16(8, true)
const battery = new Uint8Array(bytes.buffer)[14];
console.log('Pulse Rate:' + pulse);
console.log('Battery Leve:' + battery);