mirror of
https://github.com/efiten/coredrive-rx.git
synced 2026-11-27 14:58:03 +00:00
frames.js declared its own copy of RESP_CODE_STATS = 24, but nothing imports it — rfstats.js has the copy parseStats actually uses. Delete the dead one so there is exactly one definition of this wire constant. publisher.js's header named only the /packets topic, understating the module's contract now that it also publishes RF samples on /rf. README's config.json section never documented rfSampler at all (it exists in public/config.example.json and config.js). Add it alongside fullRfLog, and warn that mqtt.js negotiates MQTT 3.1.1 — whose PUBACK carries no reason code — so a broker ACL denying the /rf subtopic still lets the app log "published N record(s)" while the server receives zero rows.
27 lines
1020 B
JavaScript
27 lines
1020 B
JavaScript
// Companion BLE frame parsing. Each TX-characteristic notification carries one
|
||
// complete frame (firmware SerialBLEInterface sends setValue+notify per frame,
|
||
// MAX_FRAME_SIZE=176; no length prefix / no reassembly needed).
|
||
|
||
export const PUSH_CODE_LOG_RX_DATA = 0x88; // [0x88][snr×4 int8][rssi int8][raw packet...]
|
||
|
||
function int8(b) { return b < 128 ? b : b - 256; }
|
||
|
||
// parseFrame takes a DataView (one notification) and returns a typed object.
|
||
// For 0x88 (our coverage source): { code, snr, rssi, raw: Uint8Array }.
|
||
// Other frame codes return { code, data } for the caller to handle/ignore.
|
||
export function parseFrame(dv) {
|
||
if (!dv || dv.byteLength < 1) return null;
|
||
const bytes = new Uint8Array(dv.buffer, dv.byteOffset, dv.byteLength);
|
||
const code = bytes[0];
|
||
if (code === PUSH_CODE_LOG_RX_DATA) {
|
||
if (bytes.length < 3) return null;
|
||
return {
|
||
code,
|
||
snr: int8(bytes[1]) / 4.0,
|
||
rssi: int8(bytes[2]),
|
||
raw: bytes.slice(3),
|
||
};
|
||
}
|
||
return { code, data: bytes.slice(1) };
|
||
}
|