mirror of
https://github.com/efiten/coredrive-rx.git
synced 2026-11-23 21:07:59 +00:00
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>
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) };
|
||
}
|