mirror of
https://github.com/ruvnet/RuView.git
synced 2026-04-30 06:59:33 +00:00
Turns the ADR-081 scaffolding into a working adaptive CSI mesh kernel:
Layer 1 radio abstraction has an ESP32 binding and a mock binding; Layer 2
adaptive controller runs on FreeRTOS timers; Layer 4 feature-state packet
is emitted at 5 Hz by default, replacing raw ADR-018 CSI as the default
upstream.
New files:
firmware/esp32-csi-node/main/adaptive_controller_decide.c (pure policy)
firmware/esp32-csi-node/main/rv_radio_ops_mock.c (QEMU binding)
firmware/esp32-csi-node/tests/host/Makefile (host tests)
firmware/esp32-csi-node/tests/host/test_adaptive_controller.c
firmware/esp32-csi-node/tests/host/test_rv_feature_state.c
firmware/esp32-csi-node/tests/host/esp_err.h (shim)
firmware/esp32-csi-node/tests/host/.gitignore
Modified:
adaptive_controller.c — includes pure decide.c; emit_feature_state()
wired into fast loop (200 ms = 5 Hz)
rv_radio_ops_esp32.c — get_health() fills pkt_yield + send_fail
csi_collector.{c,h} — pkt_yield/send_fail accessors (ADR-081 L1)
rv_feature_state.h — packed size corrected to 60 bytes
(was incorrectly 80 in initial commit)
main.c — mock binding registered under mock CSI
CMakeLists.txt — rv_radio_ops_mock.c under CSI_MOCK_ENABLED
scripts/validate_qemu_output.py — 3 new ADR-081 checks (17/18/19)
docs/adr/ADR-081-*.md — status → Accepted (partial);
implementation-status matrix; measured
benchmarks (decide 3.2 ns, CRC32 614 ns);
bandwidth 300 B/s @ 5 Hz (99.7% vs raw);
verification section
CHANGELOG.md — artifact-level entries
Tests (host, gcc -O2 -std=c11):
test_adaptive_controller: 18/18 pass, decide() = 3.2 ns/call
test_rv_feature_state: 15/15 pass, CRC32(56 B) = 614 ns/pkt, 87 MB/s
sizeof(rv_feature_state_t) == 60 asserted
IEEE CRC32 known vectors verified
Deferred (tracked in ADR-081 roadmap Phase 3/4):
Layer 3 mesh-plane message types, role-assignment FSM, Rust-side mirror
trait in crates/wifi-densepose-hardware/src/radio_ops.rs.
98 lines
2.6 KiB
C
98 lines
2.6 KiB
C
/**
|
|
* @file rv_radio_ops_mock.c
|
|
* @brief ADR-081 Layer 1 — Mock binding for QEMU / offline testing.
|
|
*
|
|
* When CONFIG_CSI_MOCK_ENABLED is set (ADR-061 QEMU flow), there is no
|
|
* real WiFi driver to wrap. This binding provides the same ops table as
|
|
* the ESP32 binding but records state into in-process statics and
|
|
* accepts every call. It exists primarily to satisfy ADR-081's
|
|
* portability acceptance test: a second binding must compile against
|
|
* the same controller and mesh-plane code without modification.
|
|
*
|
|
* Only compiled when CONFIG_CSI_MOCK_ENABLED is set. Registered from
|
|
* main.c in the mock branch.
|
|
*/
|
|
|
|
#include "sdkconfig.h"
|
|
|
|
#ifdef CONFIG_CSI_MOCK_ENABLED
|
|
|
|
#include "rv_radio_ops.h"
|
|
#include "mock_csi.h"
|
|
|
|
#include <string.h>
|
|
#include "esp_err.h"
|
|
#include "esp_log.h"
|
|
|
|
static const char *TAG = "rv_radio_mock";
|
|
|
|
static uint8_t s_channel = 6;
|
|
static uint8_t s_bw = 20;
|
|
static uint8_t s_profile = RV_PROFILE_PASSIVE_LOW_RATE;
|
|
static uint8_t s_mode = RV_RADIO_MODE_PASSIVE_RX;
|
|
static bool s_csi_on = true;
|
|
|
|
static int mock_init(void)
|
|
{
|
|
ESP_LOGI(TAG, "mock radio ops: init");
|
|
return ESP_OK;
|
|
}
|
|
|
|
static int mock_set_channel(uint8_t ch, uint8_t bw)
|
|
{
|
|
s_channel = ch;
|
|
s_bw = (bw == 40) ? 40 : 20;
|
|
return ESP_OK;
|
|
}
|
|
|
|
static int mock_set_mode(uint8_t mode)
|
|
{
|
|
s_mode = mode;
|
|
return ESP_OK;
|
|
}
|
|
|
|
static int mock_set_csi_enabled(bool en)
|
|
{
|
|
s_csi_on = en;
|
|
return ESP_OK;
|
|
}
|
|
|
|
static int mock_set_capture_profile(uint8_t profile_id)
|
|
{
|
|
if (profile_id >= RV_PROFILE_COUNT) return ESP_ERR_INVALID_ARG;
|
|
s_profile = profile_id;
|
|
return ESP_OK;
|
|
}
|
|
|
|
static int mock_get_health(rv_radio_health_t *out)
|
|
{
|
|
if (out == NULL) return ESP_ERR_INVALID_ARG;
|
|
memset(out, 0, sizeof(*out));
|
|
|
|
/* Mock yield: mirror mock_csi's generator rate so the adaptive
|
|
* controller sees a sensible pkt_yield in QEMU. */
|
|
out->pkt_yield_per_sec = 20; /* MOCK_CSI_INTERVAL_MS = 50 → 20 Hz */
|
|
out->rssi_median_dbm = -55;
|
|
out->noise_floor_dbm = -95;
|
|
out->current_channel = s_channel;
|
|
out->current_bw_mhz = s_bw;
|
|
out->current_profile = s_profile;
|
|
return ESP_OK;
|
|
}
|
|
|
|
static const rv_radio_ops_t s_mock_ops = {
|
|
.init = mock_init,
|
|
.set_channel = mock_set_channel,
|
|
.set_mode = mock_set_mode,
|
|
.set_csi_enabled = mock_set_csi_enabled,
|
|
.set_capture_profile = mock_set_capture_profile,
|
|
.get_health = mock_get_health,
|
|
};
|
|
|
|
void rv_radio_ops_mock_register(void)
|
|
{
|
|
rv_radio_ops_register(&s_mock_ops);
|
|
ESP_LOGI(TAG, "mock radio ops registered (QEMU / offline mode)");
|
|
}
|
|
|
|
#endif /* CONFIG_CSI_MOCK_ENABLED */
|