Files
corescope-rx/src/frames.js
T
efiten 770bffdab1 cleanup: dedupe RESP_CODE_STATS, fix stale publisher.js header, document rfSampler
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.
2026-08-18 12:43:00 +02:00

27 lines
1020 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// 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) };
}