mirror of
https://github.com/ruvnet/RuView.git
synced 2026-04-28 22:19:33 +00:00
ADR-081: Layer 3 mesh plane + Rust mirror trait — all 5 layers landed
Fully implements the remaining deferred pieces of the adaptive CSI mesh
firmware kernel. All 5 layers (Radio Abstraction, Adaptive Controller,
Mesh Sensing Plane, On-device Feature Extraction, Rust handoff) are
now implemented and host-tested end-to-end.
Layer 3 — Mesh Sensing Plane (firmware/esp32-csi-node/main/rv_mesh.{h,c}):
* 4 node roles: Unassigned / Anchor / Observer / FusionRelay / Coordinator
* 7 message types: TIME_SYNC, ROLE_ASSIGN, CHANNEL_PLAN,
CALIBRATION_START, FEATURE_DELTA, HEALTH, ANOMALY_ALERT
* 3 auth classes: None / HMAC-SHA256-session / Ed25519-batch
* Payload types: rv_node_status_t (28 B), rv_anomaly_alert_t (28 B),
rv_time_sync_t (16 B), rv_role_assign_t (16 B),
rv_channel_plan_t (24 B), rv_calibration_start_t (20 B)
* 16-byte envelope + payload + IEEE CRC32 trailer
* Pure rv_mesh_encode()/rv_mesh_decode() plus typed convenience encoders
* rv_mesh_send_health() + rv_mesh_send_anomaly() helpers
Controller wiring (adaptive_controller.c):
* Slow loop (30 s default) now emits HEALTH
* apply_decision() emits ANOMALY_ALERT on transitions to ALERT /
DEGRADED
* Role + mesh epoch tracked in module state; epoch bumps on role
change
Layer 5 — Rust mirror (crates/wifi-densepose-hardware/src/radio_ops.rs):
* RadioOps trait mirrors rv_radio_ops_t vtable
* MockRadio backend for offline tests
* MeshHeader / NodeStatus / AnomalyAlert types mirror rv_mesh.h
* Byte-identical IEEE CRC32 (poly 0xEDB88320) verified against
firmware test vectors (0xCBF43926 for "123456789")
* decode_mesh / decode_node_status / decode_anomaly_alert / encode_health
* 8 unit tests, including mesh_constants_match_firmware which asserts
MESH_MAGIC/VERSION/HEADER_SIZE/MAX_PAYLOAD match rv_mesh.h
byte-for-byte
* Exported from lib.rs
* signal/ruvector/train/mat crates untouched — satisfies ADR-081
portability acceptance test
Tests (all passing):
test_adaptive_controller: 18/18 (C, decide() 3.2 ns/call)
test_rv_feature_state: 15/15 (C, CRC32 87 MB/s)
test_rv_mesh: 27/27 (C, roundtrip 1.0 µs)
radio_ops::tests (Rust): 8/8
--- total: 68/68 assertions green ---
Docs:
* ADR-081 status flipped to Accepted
* Implementation-status matrix updated; L3 + Rust mirror both
marked Implemented
* Benchmarks table extended with rv_mesh encode+decode roundtrip
* Verification section updated with cargo test invocation
* CHANGELOG: two new entries for L3 mesh plane + Rust mirror
Remaining follow-ups (Phase 3.5 polish, not blocking):
* Mesh RX path (UDP listener + dispatch) on the firmware
* Ed25519 signing for CHANNEL_PLAN / CALIBRATION_START
* Hardware validation on COM7
This commit is contained in:
parent
d53e29506e
commit
8dfb031cb3
12 changed files with 1633 additions and 39 deletions
|
|
@ -15,6 +15,7 @@
|
|||
#include "adaptive_controller.h"
|
||||
#include "rv_radio_ops.h"
|
||||
#include "rv_feature_state.h"
|
||||
#include "rv_mesh.h"
|
||||
#include "edge_processing.h"
|
||||
#include "stream_sender.h"
|
||||
#include "csi_collector.h"
|
||||
|
|
@ -131,14 +132,57 @@ static void collect_observation(adapt_observation_t *out)
|
|||
|
||||
/* ---- Decision application ---- */
|
||||
|
||||
/* ADR-081 L3: epoch monotonically advances per mesh session. Seeded at
|
||||
* init; every major state transition or role change bumps it so
|
||||
* receivers can order events. */
|
||||
static uint32_t s_mesh_epoch = 1;
|
||||
|
||||
/* ADR-081 L3: current node role. Updated by ROLE_ASSIGN receipt (future
|
||||
* mesh-plane RX path) or forced by tests. Default Observer. */
|
||||
static uint8_t s_role = RV_ROLE_OBSERVER;
|
||||
|
||||
/* 8-byte node id. Upper 7 bytes are zero by default; byte 0 is the
|
||||
* legacy CSI node id for compatibility with the ADR-018 header. */
|
||||
static void node_id_bytes(uint8_t out[8])
|
||||
{
|
||||
memset(out, 0, 8);
|
||||
out[0] = csi_collector_get_node_id();
|
||||
}
|
||||
|
||||
static void apply_decision(const adapt_decision_t *dec)
|
||||
{
|
||||
const rv_radio_ops_t *ops = rv_radio_ops_get();
|
||||
adapt_state_t prev = s_state;
|
||||
|
||||
if (dec->change_state) {
|
||||
ESP_LOGI(TAG, "state %u → %u",
|
||||
(unsigned)s_state, (unsigned)dec->new_state);
|
||||
s_state = (adapt_state_t)dec->new_state;
|
||||
|
||||
/* ADR-081 L3: on transition to ALERT, emit ANOMALY_ALERT on the
|
||||
* mesh plane. On any role-relevant transition, bump the epoch. */
|
||||
if (s_state == ADAPT_STATE_ALERT && prev != ADAPT_STATE_ALERT) {
|
||||
uint8_t nid[8];
|
||||
node_id_bytes(nid);
|
||||
adapt_observation_t obs;
|
||||
float motion = 0.0f, anomaly = 0.0f;
|
||||
portENTER_CRITICAL(&s_obs_lock);
|
||||
if (s_obs_valid) { obs = s_last_obs; motion = obs.motion_score;
|
||||
anomaly = obs.anomaly_score; }
|
||||
portEXIT_CRITICAL(&s_obs_lock);
|
||||
uint8_t severity = (uint8_t)(anomaly * 255.0f);
|
||||
rv_mesh_send_anomaly(s_role, s_mesh_epoch, nid,
|
||||
RV_ANOMALY_COHERENCE_LOSS, severity,
|
||||
anomaly, motion);
|
||||
}
|
||||
if (s_state == ADAPT_STATE_DEGRADED && prev != ADAPT_STATE_DEGRADED) {
|
||||
uint8_t nid[8];
|
||||
node_id_bytes(nid);
|
||||
rv_mesh_send_anomaly(s_role, s_mesh_epoch, nid,
|
||||
RV_ANOMALY_PKT_YIELD_COLLAPSE,
|
||||
200, 1.0f, 0.0f);
|
||||
}
|
||||
s_mesh_epoch++;
|
||||
}
|
||||
|
||||
if (dec->change_profile && ops != NULL && ops->set_capture_profile != NULL) {
|
||||
|
|
@ -272,10 +316,16 @@ static void emit_feature_state(void)
|
|||
static void slow_loop_cb(TimerHandle_t t)
|
||||
{
|
||||
(void)t;
|
||||
/* Slow loop: log a heartbeat and (future Phase 3) publish HEALTH
|
||||
* messages + request CALIBRATION_START on sustained drift. */
|
||||
ESP_LOGI(TAG, "slow tick (state=%u, feature_state_seq=%u)",
|
||||
(unsigned)s_state, (unsigned)s_feature_state_seq);
|
||||
/* ADR-081 L3: publish a HEALTH mesh message every slow tick
|
||||
* (default 30 s). The coordinator uses these to track liveness and
|
||||
* detect sync-error drift. */
|
||||
uint8_t nid[8];
|
||||
node_id_bytes(nid);
|
||||
rv_mesh_send_health(s_role, s_mesh_epoch, nid);
|
||||
|
||||
ESP_LOGI(TAG, "slow tick (state=%u, feature_state_seq=%u, role=%u, epoch=%u) HEALTH sent",
|
||||
(unsigned)s_state, (unsigned)s_feature_state_seq,
|
||||
(unsigned)s_role, (unsigned)s_mesh_epoch);
|
||||
}
|
||||
|
||||
/* ---- Public API ---- */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue