Files
corescope-rx/src/frames.js
T
efitenandClaude Opus 4.8 db83810878 feat: scaffold corescope-rx capture app (BLE companion → MQTT coverage)
Protocol core implemented + unit-tested (meshpacket: path[last]/advert pubkey,
direct-only rule; frames: 0x88 snr/rssi/raw). Working skeleton for transport
(Web Bluetooth NUS), GPS, IndexedDB queue, MQTT.js publisher and field UI.
Remaining work in docs/plan.md (spikes + harden + verify).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-09 16:47:30 +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) };
}