mirror of
https://github.com/ruvnet/RuView
synced 2026-07-19 16:53:18 +00:00
7831f29436
Bug #2 (root cause): LD2410 probe-detection matched only the 4-byte head 0xF4F3F2F1, so a floating UART at 256000 baud could phantom-detect a sensor and spawn a UART task. Now requires a full validated report frame (head + sane length + tail 0xF8F7F6F5), extracted to mmwave_detect.h and shared with a host unit test (test_mmwave_detect.c, 8 vectors) so firmware and test can't diverge. Matches the validate-before-trust approach used for MR60 in #1107. Bug #1: sendto ENOMEM used a fixed 100 ms backoff too short to drain sustained lwIP/WiFi buffer pressure, so a node could stay stuck. Now exponential (100->200->...->2000 ms per consecutive ENOMEM, reset on first successful send). Removing the phantom LD2410 task (bug #2) also removes the extra load that tipped the reporter's tier-2 node into the stuck state. Validated on ESP32-S3 QFN56 rev v0.2 (the reporter's silicon): tier-2 streams ~100 frames/s with no stuck ENOMEM and correctly reports no mmWave (no phantom). LD2410 predicate truth table proven (head-without-tail REJECTED). Could not reproduce the reporter's environment-specific floating-pin noise, so the deterministic proof is the host unit test.
38 lines
1.5 KiB
C
38 lines
1.5 KiB
C
/**
|
|
* @file mmwave_detect.h
|
|
* @brief Pure (host-testable) mmWave frame-validation predicates for probe-time
|
|
* sensor detection. No ESP-IDF deps — safe to #include in a host unit test.
|
|
*
|
|
* Detection must validate a *full* frame, never a bare header byte/pattern: a
|
|
* floating UART with no sensor reads line noise that can contain header-looking
|
|
* bytes, which the old loose checks mistook for a real sensor (#1107 MR60,
|
|
* #1135 LD2410). These predicates are the validate-before-trust gate.
|
|
*/
|
|
#ifndef MMWAVE_DETECT_H
|
|
#define MMWAVE_DETECT_H
|
|
|
|
#include <stdint.h>
|
|
#include <stdbool.h>
|
|
|
|
/**
|
|
* True iff buf[i..] begins a *validated* LD2410 report frame within [0,len):
|
|
* F4 F3 F2 F1 | len(LE,2) | data[len] | F8 F7 F6 F5
|
|
* Requires the head magic, a sane intra-frame length, AND the matching tail at
|
|
* head+6+len. Pure noise that merely contains 0xF4F3F2F1 fails the tail check.
|
|
*/
|
|
static inline bool mmwave_ld2410_valid_at(const uint8_t *buf, int i, int len)
|
|
{
|
|
if (i < 0 || i + 5 >= len) return false;
|
|
if (!(buf[i] == 0xF4 && buf[i+1] == 0xF3 && buf[i+2] == 0xF2 && buf[i+3] == 0xF1))
|
|
return false;
|
|
uint16_t flen = (uint16_t)buf[i+4] | ((uint16_t)buf[i+5] << 8);
|
|
/* Real LD2410 report frames are small (basic=13, engineering=35). */
|
|
if (flen < 1 || flen > 64) return false;
|
|
int tail = i + 6 + (int)flen;
|
|
if (tail + 3 >= len) return false;
|
|
return buf[tail] == 0xF8 && buf[tail+1] == 0xF7
|
|
&& buf[tail+2] == 0xF6 && buf[tail+3] == 0xF5;
|
|
}
|
|
|
|
#endif /* MMWAVE_DETECT_H */
|