From 69621fd2b6aa5415563d62680b2313140c7f855f Mon Sep 17 00:00:00 2001 From: Guoguo Date: Fri, 12 Jun 2026 08:52:44 -0700 Subject: [PATCH] feat: support FFE4 19-byte format with fitting and run_state fields MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Per 协议简述(3): FFE4 now 19 bytes — adds Byte17 fitting status (0=not fitted, 1=fitted) and Byte18 run state (0=IDLE, 1=scanning, 2=treating, FF=fault). Maintains backward compat with 17-byte format. --- miniprogram/services/ble/connection.js | 8 +++++++- miniprogram/services/ble/protocol.js | 19 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/miniprogram/services/ble/connection.js b/miniprogram/services/ble/connection.js index 1dad359..0ef5ccf 100644 --- a/miniprogram/services/ble/connection.js +++ b/miniprogram/services/ble/connection.js @@ -98,8 +98,14 @@ function handleValueChange(res) { console.warn('[BLE] ADC checksum mismatch, dropping') return } - emit('adc', { pd: parsed.pd, vbat: vbatMv, battery: batteryPct }) + emit('adc', { pd: parsed.pd, vbat: vbatMv, battery: batteryPct, fitting: parsed.fitting, run_state: parsed.run_state }) emit('battery', { battery: batteryPct, vbat: vbatMv }) + if (parsed.fitting !== -1) { + emit('fitting', { fitting: parsed.fitting }) + } + if (parsed.run_state !== -1) { + emit('run_state', { run_state: parsed.run_state }) + } return } diff --git a/miniprogram/services/ble/protocol.js b/miniprogram/services/ble/protocol.js index b0a81c8..fc1c6b4 100644 --- a/miniprogram/services/ble/protocol.js +++ b/miniprogram/services/ble/protocol.js @@ -199,6 +199,23 @@ function parseVendorStatus(buffer) { if (bytes.length === 1) { return { type: 'heartbeat', heartbeat: bytes[0], is_heartbeat: true, raw_hex: bytesToHex(bytes) } } + if (bytes.length === 19) { + var checksum19 = xorChecksum(bytes.slice(0, 18)) + var pds19 = [] + for (var p = 0; p < 7; p++) { + pds19.push(bytes[p * 2] | (bytes[p * 2 + 1] << 8)) + } + return { + type: 'adc', + is_heartbeat: false, + pd: pds19, + vbat: bytes[14] | (bytes[15] << 8), + fitting: bytes[16], + run_state: bytes[17], + checksum_ok: checksum19 === bytes[18], + raw_hex: bytesToHex(bytes) + } + } if (bytes.length === 17) { var checksum = xorChecksum(bytes.slice(0, 16)) var pds = [] @@ -210,6 +227,8 @@ function parseVendorStatus(buffer) { is_heartbeat: false, pd: pds, vbat: bytes[14] | (bytes[15] << 8), + fitting: -1, + run_state: -1, checksum_ok: checksum === bytes[16], raw_hex: bytesToHex(bytes) }