Files
wifi-densepose/firmware/esp32-csi-node/main/csi_collector.h
ruv 303871275b feat: ADR-029/031 TDM sensing protocol, channel hopping, and NVS config
Implement the hardware and firmware portions of RuvSense (ADR-029) and
RuView (ADR-031) for multistatic WiFi sensing:

Rust (wifi-densepose-hardware):
- TdmSchedule: uniform slot assignments with configurable cycle period,
  guard intervals, and processing window (default 4-node 20 Hz)
- TdmCoordinator: manages sensing cycles, tracks per-slot completion,
  cumulative clock drift compensation (±10 ppm over 50 ms = 0.5 us)
- SyncBeacon: 16-byte wire format for cycle synchronization with
  drift correction offsets
- TdmSlotCompleted event for aggregator notification
- 18 unit tests + 4 doctests, all passing

Firmware (C, ESP32):
- Channel-hop table in csi_collector.c (s_hop_channels, configurable
  via csi_collector_set_hop_table)
- Timer-driven channel hopping via esp_timer at dwell intervals
- NDP frame injection stub via esp_wifi_80211_tx()
- Backward-compatible: hop_count=1 disables hopping entirely
- NVS config extension: hop_count, chan_list, dwell_ms, tdm_slot,
  tdm_node_count with bounds validation and Kconfig fallback defaults

Co-Authored-By: claude-flow <ruv@ruv.net>
2026-03-01 21:33:48 -05:00

85 lines
2.6 KiB
C

/**
* @file csi_collector.h
* @brief CSI data collection and ADR-018 binary frame serialization.
*/
#ifndef CSI_COLLECTOR_H
#define CSI_COLLECTOR_H
#include <stdint.h>
#include <stddef.h>
#include "esp_wifi_types.h"
/** ADR-018 magic number. */
#define CSI_MAGIC 0xC5110001
/** ADR-018 header size in bytes. */
#define CSI_HEADER_SIZE 20
/** Maximum frame buffer size (header + 4 antennas * 256 subcarriers * 2 bytes). */
#define CSI_MAX_FRAME_SIZE (CSI_HEADER_SIZE + 4 * 256 * 2)
/** Maximum number of channels in the hop table (ADR-029). */
#define CSI_HOP_CHANNELS_MAX 6
/**
* Initialize CSI collection.
* Registers the WiFi CSI callback.
*/
void csi_collector_init(void);
/**
* Serialize CSI data into ADR-018 binary frame format.
*
* @param info WiFi CSI info from the ESP-IDF callback.
* @param buf Output buffer (must be at least CSI_MAX_FRAME_SIZE bytes).
* @param buf_len Size of the output buffer.
* @return Number of bytes written, or 0 on error.
*/
size_t csi_serialize_frame(const wifi_csi_info_t *info, uint8_t *buf, size_t buf_len);
/**
* Configure the channel-hop table for multi-band sensing (ADR-029).
*
* When hop_count == 1 the collector stays on the single configured channel
* (backward-compatible with the original single-channel mode).
*
* @param channels Array of WiFi channel numbers (1-14 for 2.4 GHz, 36-177 for 5 GHz).
* @param hop_count Number of entries in the channels array (1..CSI_HOP_CHANNELS_MAX).
* @param dwell_ms Dwell time per channel in milliseconds (>= 10).
*/
void csi_collector_set_hop_table(const uint8_t *channels, uint8_t hop_count, uint32_t dwell_ms);
/**
* Advance to the next channel in the hop table.
*
* Called by the hop timer callback. If hop_count <= 1 this is a no-op.
* Calls esp_wifi_set_channel() internally.
*/
void csi_hop_next_channel(void);
/**
* Start the channel-hop timer.
*
* Creates an esp_timer periodic callback that fires every dwell_ms
* milliseconds, calling csi_hop_next_channel(). If hop_count <= 1
* the timer is not started (single-channel backward-compatible mode).
*/
void csi_collector_start_hop_timer(void);
/**
* Inject an NDP (Null Data Packet) frame for sensing.
*
* Uses esp_wifi_80211_tx() to send a preamble-only frame (~24 us airtime)
* that triggers CSI measurement at all receivers. This is the "sensing-first"
* TX mechanism described in ADR-029.
*
* @return ESP_OK on success, or an error code.
*
* @note TODO: Full NDP frame construction. Currently sends a minimal
* null-data frame as a placeholder.
*/
esp_err_t csi_inject_ndp_frame(void);
#endif /* CSI_COLLECTOR_H */