传感服务器领域模型¶
传感服务器(Sensing Server)是 WiFi-DensePose 的单二进制部署形态。它从 ESP32 节点接收原始 CSI 帧,将其处理为感知特征,将实时数据流式传输到 Web UI,并提供一个自包含的工作流,用于记录数据、训练模型和运行推理——完全无需外部依赖。
本文档使用领域驱动设计(DDD)来定义系统:限界上下文拥有其数据和规则,聚合根强制不变量,值对象承载含义,领域事件连接一切。服务器实现为单个 Axum 二进制程序(wifi-densepose-sensing-server),所有状态通过 Arc<RwLock<AppStateInner>> 管理。
限界上下文:
| # | 上下文 | 职责 | 关键 ADR | 代码 |
|---|---|---|---|---|
| 1 | CSI 摄取 | 从 ESP32 UDP 接收 CSI 帧,解码并提取特征 | ADR-019, ADR-035 | sensing-server/src/main.rs |
| 2 | 模型管理 | 加载、卸载、列出 RVF 模型;LoRA 配置文件激活 | ADR-043 | sensing-server/src/model_manager.rs |
| 3 | CSI 记录 | 将 CSI 帧记录到 .jsonl 文件,管理记录会话 | ADR-043 | sensing-server/src/recording.rs |
| 4 | 训练流水线 | 后台训练运行、进度流式传输、对比预训练 | ADR-043 | sensing-server/src/training_api.rs |
| 5 | 可视化 | 通过 WebSocket 向 Web UI 流式传输、高斯泼溅渲染、数据透明度 | ADR-019, ADR-035 | ui/ |
除非另有说明,所有显示的代码路径均相对于 v2/crates/wifi-densepose-。
领域驱动设计规范¶
通用语言¶
| 术语 | 定义 |
|---|---|
| Sensing Update | 每个 tick 广播给 WebSocket 客户端的完整 JSON 消息,包含节点数据、特征、分类、信号场以及可选的生命体征 |
| Tick | 感知循环的一个处理周期(默认 100ms = 10 fps,可通过 --tick-ms 配置) |
| Data Source | CSI 数据的来源:esp32(UDP 端口 5005)、wifi(Windows RSSI)、simulated(合成数据)或 auto(先尝试 ESP32,然后回退) |
| RVF Model | 一个 .rvf 容器文件,包含训练权重、清单元数据、可选的 LoRA 适配器和生命体征配置 |
| LoRA Profile | 一种轻量级适配器,应用于基础 RVF 模型之上,用于特定环境的微调,无需重新训练整个模型 |
| Recording Session | 一段时间段,在此期间 CSI 帧被追加到 .csi.jsonl 文件中,由会话 ID 和可选的活动标签标识 |
| Training Run | 一个后台任务,加载记录的 CSI 数据、提取特征、训练正则化线性模型,并导出 .rvf 容器 |
| Frame History | 最近 100 个 CSI 幅度向量的环形缓冲区,用于时域分析(滑动窗口方差、Goertzel 呼吸估计) |
| Goertzel Filter | 一种频域估计器,应用于帧历史以通过 9 候选滤波器组检测呼吸频率(0.1--0.5 Hz) |
| Signal Field | 一个 20x1x20 的插值信号强度值网格,在 UI 中以高斯泼溅形式渲染 |
| Pose Source | 姿态关键点是 signal_derived(从 CSI 特征解析得出)还是 model_inference(来自已加载的 RVF 模型) |
| Progressive Loader | 一种两层模型加载策略:A 层立即加载以进行基本推理,B 层在后台加载以获得完整精度 |
| Sensing-Only Mode | 当 DensePose 后端不可用时的 UI 模式;隐藏 DensePose 标签页,仅显示感知和信号可视化 |
| AppStateInner | 持有所有服务器状态的唯一共享状态结构体,通过 Arc<RwLock<AppStateInner>> 访问 |
| PCK Score | 正确关键点百分比——姿态估计模型的主要精度指标 |
| Contrastive Pretraining | 在无标签 CSI 数据上进行自监督训练,在监督微调之前学习信号表示(ADR-024) |
限界上下文¶
1. CSI 摄取上下文¶
职责: 通过 UDP(端口 5005)从 ESP32 节点接收原始 CSI 帧,解码二进制协议,提取时域和频域特征,并在每个 tick 生成 SensingUpdate。
+------------------------------------------------------------+
| CSI Ingestion Context |
+------------------------------------------------------------+
| |
| +----------------+ +----------------+ |
| | UDP Listener | | Data Source | |
| | (port 5005) | | Selector | |
| | Esp32Frame | | (auto/esp32/ | |
| | parser | | wifi/sim) | |
| +-------+--------+ +-------+--------+ |
| | | |
| +----------+----------+ |
| v |
| +-------------------+ |
| | Frame History | |
| | Buffer | |
| | (VecDeque<Vec>, | |
| | 100 frames) | |
| +--------+----------+ |
| v |
| +-------------------+ |
| | Feature | |
| | Extractor | |
| | (Welford stats, | |
| | Goertzel FFT, | |
| | L2 motion) | |
| +--------+----------+ |
| v |
| +-------------------+ |
| | Vital Sign | |
| | Detector |---> SensingUpdate |
| | (HR, RR, | |
| | breathing) | |
| +-------------------+ |
| |
+------------------------------------------------------------+
2. 模型管理上下文¶
3. CSI 记录上下文¶
4. 训练流水线上下文¶
5. 可视化上下文¶
聚合:
/// Aggregate Root: The central shared state of the sensing server.
/// All mutations go through RwLock. All handler functions receive
/// State<Arc<RwLock<AppStateInner>>>.
pub struct AppStateInner {
/// Most recent sensing update broadcast to clients.
latest_update: Option<SensingUpdate>,
/// RSSI history for sparkline display.
rssi_history: VecDeque<f64>,
/// Circular buffer of recent CSI amplitude vectors (100 frames).
frame_history: VecDeque<Vec<f64>>,
/// Monotonic tick counter.
tick: u64,
/// Active data source identifier ("esp32", "wifi", "simulated").
source: String,
/// Broadcast channel for WebSocket fan-out.
tx: broadcast::Sender<String>,
/// Vital sign detector instance.
vital_detector: VitalSignDetector,
/// Most recent vital signs reading.
latest_vitals: VitalSigns,
/// Smoothed person count (EMA) for hysteresis.
smoothed_person_score: f64,
// ... model, recording, training fields (see other contexts)
}
值对象:
/// A complete sensing update broadcast to WebSocket clients each tick.
pub struct SensingUpdate {
pub msg_type: String, // always "sensing_update"
pub timestamp: f64, // Unix timestamp with ms precision
pub source: String, // "esp32" | "wifi" | "simulated"
pub tick: u64, // monotonic tick counter
pub nodes: Vec<NodeInfo>, // per-node CSI data
pub features: FeatureInfo, // extracted signal features
pub classification: ClassificationInfo,
pub signal_field: SignalField,
pub vital_signs: Option<VitalSigns>,
pub persons: Option<Vec<PersonDetection>>,
pub estimated_persons: Option<usize>,
}
/// Per-node CSI data received from one ESP32.
pub struct NodeInfo {
pub node_id: u8,
pub rssi_dbm: f64,
pub position: [f64; 3],
pub amplitude: Vec<f64>,
pub subcarrier_count: usize,
}
/// Extracted signal features from the frame history buffer.
pub struct FeatureInfo {
pub mean_rssi: f64,
pub variance: f64,
pub motion_band_power: f64,
pub breathing_band_power: f64,
pub dominant_freq_hz: f64,
pub change_points: usize,
pub spectral_power: f64,
}
/// Motion classification derived from features.
pub struct ClassificationInfo {
pub motion_level: String, // "empty" | "static" | "active"
pub presence: bool,
pub confidence: f64,
}
/// Interpolated signal field for Gaussian splat visualization.
pub struct SignalField {
pub grid_size: [usize; 3], // [20, 1, 20]
pub values: Vec<f64>,
}
/// ESP32 binary CSI frame (ADR-018 protocol, 20-byte header).
pub struct Esp32Frame {
pub magic: u32, // 0xC5100001
pub node_id: u8,
pub n_antennas: u8,
pub n_subcarriers: u8,
pub freq_mhz: u16,
pub sequence: u32,
pub rssi: i8,
pub noise_floor: i8,
pub amplitudes: Vec<f64>,
pub phases: Vec<f64>,
}
/// Data source selection enum.
pub enum DataSource {
Esp32Udp, // Real ESP32 CSI via UDP port 5005
WindowsRssi, // Windows WiFi RSSI via netsh
Simulated, // Synthetic sine-wave data
Auto, // Try ESP32, fall back to Windows, then simulated
}
领域服务:
- FeatureExtractionService -- 计算时间方差(Welford)、Goertzel 呼吸估计(9 带滤波器组)、L2 帧间运动分数、基于 SNR 的信号质量
- VitalSignDetectionService -- 从 CSI 相位历史中估计呼吸率、心率和置信度
- DataSourceSelectionService -- 探测 UDP 端口 5005 以获取 ESP32 帧;依次回退到 Windows RSSI,再到模拟数据
不变量: - 帧历史缓冲区从不超过 100 个条目(推送时丢弃最旧条目) - Goertzel 呼吸估计需要 SNR 高于噪声 3 倍才会被报告 - 源类型在启动时确定一次,运行时不会改变
2. 模型管理上下文¶
职责: 从 data/models/ 中发现 .rvf 模型文件,将权重加载到内存中用于推理,管理当前模型的生命周期,并支持 LoRA 配置文件激活。
+------------------------------------------------------------+
| Model Management Context |
+------------------------------------------------------------+
| |
| +----------------+ +----------------+ |
| | Model Scanner | | RVF Reader | |
| | (data/models/ | | (parse .rvf | |
| | *.rvf enum) | | manifest) | |
| +-------+--------+ +-------+--------+ |
| | | |
| +----------+----------+ |
| v |
| +-------------------+ |
| | Model Registry | |
| | (Vec<ModelInfo>) | |
| +--------+----------+ |
| v |
| +-------------------+ |
| | Model Loader | |
| | (RvfReader -> |---> LoadedModelState |
| | weights, | |
| | LoRA profiles) | |
| +--------+----------+ |
| v |
| +-------------------+ |
| | LoRA Activator | |
| | (profile switch) | |
| +-------------------+ |
| |
+------------------------------------------------------------+
聚合:
/// Aggregate Root: Runtime state for a loaded RVF model.
/// At most one LoadedModelState exists at any time.
pub struct LoadedModelState {
/// Model identifier (derived from filename without .rvf extension).
pub model_id: String,
/// Original filename on disk.
pub filename: String,
/// Version string from the RVF manifest.
pub version: String,
/// Description from the RVF manifest.
pub description: String,
/// LoRA profiles available in this model.
pub lora_profiles: Vec<String>,
/// Currently active LoRA profile (if any).
pub active_lora_profile: Option<String>,
/// Model weights (f32 parameters).
pub weights: Vec<f32>,
/// Number of frames processed since load.
pub frames_processed: u64,
/// Cumulative inference time for avg calculation.
pub total_inference_ms: f64,
/// When the model was loaded.
pub loaded_at: Instant,
}
值对象:
/// Summary information for a model discovered on disk.
pub struct ModelInfo {
pub id: String,
pub filename: String,
pub version: String,
pub description: String,
pub size_bytes: u64,
pub created_at: String,
pub pck_score: Option<f64>,
pub has_quantization: bool,
pub lora_profiles: Vec<String>,
pub segment_count: usize,
}
/// Information about the currently loaded model with runtime stats.
pub struct ActiveModelInfo {
pub model_id: String,
pub filename: String,
pub version: String,
pub description: String,
pub avg_inference_ms: f64,
pub frames_processed: u64,
pub pose_source: String, // "model_inference"
pub lora_profiles: Vec<String>,
pub active_lora_profile: Option<String>,
}
/// Request to load a model by ID.
pub struct LoadModelRequest {
pub model_id: String,
}
/// Request to activate a LoRA profile.
pub struct ActivateLoraRequest {
pub model_id: String,
pub profile_name: String,
}
领域服务:
- ModelScanService -- 在启动时扫描 data/models/ 中的 .rvf 文件,并使用 RvfReader 解析每个文件以提取清单元数据
- ModelLoadService -- 从 RVF 容器读取模型权重到内存,并设置 model_loaded = true
- LoraActivationService -- 在已加载模型上切换当前活动的 LoRA 适配器,而无需完全重新加载
不变量:
- 同一时间只能加载一个模型;加载新模型会隐式卸载之前的模型
- 在激活 LoRA 配置文件之前,必须先加载模型
- active_lora_profile 必须是模型声明的 lora_profiles 之一
- 如果模型当前已加载,则拒绝删除模型(必须先卸载)
- 如果 data/models/ 目录不存在,则在启动时创建
3. CSI 录制上下文¶
职责: 在活跃录制会话期间,将 CSI 帧捕获到 .csi.jsonl 文件中,管理会话生命周期,并提供对已存储录制的下载/删除操作。
+------------------------------------------------------------+
| CSI Recording Context |
+------------------------------------------------------------+
| |
| +----------------+ +----------------+ |
| | Start/Stop | | Auto-Stop | |
| | Controller | | Timer | |
| | (REST API) | | (duration_ | |
| | | | secs check) | |
| +-------+--------+ +-------+--------+ |
| | | |
| +----------+----------+ |
| v |
| +-------------------+ |
| | Recording State | |
| | (session_id, | |
| | frame_count, | |
| | file_path) | |
| +--------+----------+ |
| v |
| +-------------------+ |
| | Frame Writer | |
| | (maybe_record_ |---> .csi.jsonl file |
| | frame on each | |
| | tick) | |
| +--------+----------+ |
| v |
| +-------------------+ |
| | Metadata Writer | |
| | (.meta.json on | |
| | stop) | |
| +-------------------+ |
| |
+------------------------------------------------------------+
聚合:
/// Aggregate Root: Runtime state for the active CSI recording session.
/// At most one RecordingState can be active at any time.
pub struct RecordingState {
/// Whether a recording is currently active.
pub active: bool,
/// Session ID of the active recording.
pub session_id: String,
/// Session display name.
pub session_name: String,
/// Optional label / activity tag (e.g., "walking", "standing").
pub label: Option<String>,
/// Path to the JSONL file being written.
pub file_path: PathBuf,
/// Number of frames written so far.
pub frame_count: u64,
/// When the recording started (monotonic clock).
pub start_time: Instant,
/// ISO-8601 start timestamp for metadata.
pub started_at: String,
/// Optional auto-stop duration in seconds.
pub duration_secs: Option<u64>,
}
值对象:
/// Metadata for a completed or active recording session.
pub struct RecordingSession {
pub id: String,
pub name: String,
pub label: Option<String>,
pub started_at: String,
pub ended_at: Option<String>,
pub frame_count: u64,
pub file_size_bytes: u64,
pub file_path: String,
}
/// A single recorded CSI frame line (JSONL format).
pub struct RecordedFrame {
pub timestamp: f64,
pub subcarriers: Vec<f64>,
pub rssi: f64,
pub noise_floor: f64,
pub features: serde_json::Value,
}
/// Request to start a new recording session.
pub struct StartRecordingRequest {
pub session_name: String,
pub label: Option<String>,
pub duration_secs: Option<u64>,
}
领域服务:
- RecordingLifecycleService -- 创建新的 .csi.jsonl 文件,生成会话 ID,管理开始/停止转换
- FrameWriterService -- 在每个 tick 中通过 maybe_record_frame() 调用,向活动文件追加一行 RecordedFrame JSON
- AutoStopService -- 在每个 tick 中检查经过时间是否超过 duration_secs;超过时触发停止
- RecordingScanService -- 枚举 data/recordings/ 中的 .csi.jsonl 文件,并读取配套的 .meta.json 以获取会话元数据
不变量:
- 同一时间只能有一个活动录制会话;在活动会话存在时开始新录制会返回 HTTP 409 Conflict
- 设置了 duration_secs 的录制会在指定经过时间后自动停止
- 录制停止时会写入配套的 .meta.json 文件,记录最终帧数和时长
- 如果 data/recordings/ 目录不存在,启动时会创建它
- 帧写入器在每个 tick 获取 AppStateInner 的读锁;停止操作获取写锁
4. 训练流水线上下文¶
职责: 针对已录制的 CSI 数据运行后台训练,通过 WebSocket 流式传输 epoch 级进度,并将训练好的模型导出为 .rvf 容器。支持监督训练、对比预训练(ADR-024)和 LoRA 微调。
+------------------------------------------------------------+
| Training Pipeline Context |
+------------------------------------------------------------+
| |
| +----------------+ +----------------+ |
| | Training API | | WebSocket | |
| | (start/stop/ | | Progress | |
| | status) | | Streamer | |
| +-------+--------+ +-------+--------+ |
| | ^ |
| v | |
| +-------------------+ | |
| | Training | | |
| | Orchestrator +--------+ |
| | (tokio::spawn) | broadcast::Sender |
| +--------+----------+ |
| v |
| +-------------------+ |
| | Feature | |
| | Extractor | |
| | (subcarrier var, | |
| | Goertzel power, | |
| | temporal grad) | |
| +--------+----------+ |
| v |
| +-------------------+ |
| | Gradient Descent | |
| | Trainer | |
| | (batch SGD, |---> TrainingProgress |
| | early stopping, | |
| | warmup) | |
| +--------+----------+ |
| v |
| +-------------------+ |
| | RVF Exporter | |
| | (RvfBuilder -> |---> data/models/*.rvf |
| | .rvf container) | |
| +-------------------+ |
| |
+------------------------------------------------------------+
聚合:
/// Aggregate Root: Runtime training state stored in AppStateInner.
/// At most one training run can be active at any time.
pub struct TrainingState {
/// Current status snapshot.
pub status: TrainingStatus,
/// Handle to the background training task (for cancellation).
pub task_handle: Option<tokio::task::JoinHandle<()>>,
}
值对象:
/// Current training status (returned by GET /api/v1/train/status).
pub struct TrainingStatus {
pub active: bool,
pub epoch: u32,
pub total_epochs: u32,
pub train_loss: f64,
pub val_pck: f64, // Percentage of Correct Keypoints
pub val_oks: f64, // Object Keypoint Similarity
pub lr: f64, // current learning rate
pub best_pck: f64,
pub best_epoch: u32,
pub patience_remaining: u32,
pub eta_secs: Option<u64>,
pub phase: String, // "idle" | "training" | "complete" | "failed"
}
/// Progress update sent over WebSocket to connected UI clients.
pub struct TrainingProgress {
pub epoch: u32,
pub batch: u32,
pub total_batches: u32,
pub train_loss: f64,
pub val_pck: f64,
pub val_oks: f64,
pub lr: f64,
pub phase: String,
}
/// Training configuration submitted with a start request.
pub struct TrainingConfig {
pub epochs: u32, // default: 100
pub batch_size: u32, // default: 8
pub learning_rate: f64, // default: 0.001
pub weight_decay: f64, // default: 1e-4
pub early_stopping_patience: u32, // default: 20
pub warmup_epochs: u32, // default: 5
pub pretrained_rvf: Option<String>,
pub lora_profile: Option<String>,
}
/// Request to start supervised training.
pub struct StartTrainingRequest {
pub dataset_ids: Vec<String>, // recording session IDs
pub config: TrainingConfig,
}
/// Request to start contrastive pretraining (ADR-024).
pub struct PretrainRequest {
pub dataset_ids: Vec<String>,
pub epochs: u32, // default: 50
pub lr: f64, // default: 0.001
}
/// Request to start LoRA fine-tuning.
pub struct LoraTrainRequest {
pub base_model_id: String,
pub dataset_ids: Vec<String>,
pub profile_name: String,
pub rank: u8, // default: 8
pub epochs: u32, // default: 30
}
领域服务:
- TrainingOrchestrationService -- 启动一个后台 tokio::task,加载已录制的帧,运行特征提取,执行带早停和预热的梯度下降
- FeatureExtractionService -- 计算每个子载波的滑动窗口方差、时间梯度、跨 9 个频段的 Goertzel 频域功率,以及 3 个全局标量特征(平均幅度、标准差、运动分数)
- ProgressBroadcastService -- 通过 broadcast::Sender 通道发送 TrainingProgress 消息,WebSocket 处理器会订阅该通道
- RvfExportService -- 使用 RvfBuilder 将最佳检查点作为 .rvf 容器写入 data/models/
不变量:
- 同一时间只能有一个训练运行处于活动状态;在已有训练运行时启动训练会返回 HTTP 409 冲突
- 启动训练前,至少需要一个达到最小帧数的录制
- 早停会在 val_pck 连续 patience 个 epoch 没有改善时停止训练
- 学习率预热在 warmup_epochs 内从 0 线性升至 learning_rate
- 完成后,最佳模型(按 val_pck)会自动导出为 .rvf
- 训练状态阶段转换:idle -> training -> complete | failed -> idle
- 停止活动训练运行会通过 JoinHandle::abort() 中止后台任务,并将阶段重置为 idle
5. 可视化上下文¶
职责: 通过 WebSocket 向 Web UI 客户端流式传输感知数据,渲染高斯泼溅可视化,显示数据源透明性指示器,并管理 UI 模式(完整模式 vs. 仅感知模式)。
+------------------------------------------------------------+
| Visualization Context |
+------------------------------------------------------------+
| |
| +----------------+ +----------------+ |
| | WebSocket | | Sensing | |
| | Hub | | Service (JS) | |
| | (/ws/sensing) | | (client-side | |
| | broadcast:: | | reconnect + | |
| | Receiver | | sim fallback)| |
| +-------+--------+ +-------+--------+ |
| | | |
| +----------+----------+ |
| v |
| +----------------------------------------------+ |
| | UI Components | |
| | | |
| | +----------+ +----------+ +----------+ | |
| | | Sensing | | Live | | Models | | |
| | | Tab | | Demo Tab | | Tab | | |
| | | (splats) | | (pose) | | (manage) | | |
| | +----------+ +----------+ +----------+ | |
| | +----------+ +----------+ | |
| | | Recording| | Training | | |
| | | Tab | | Tab | | |
| | | (capture)| | (train) | | |
| | +----------+ +----------+ | |
| +----------------------------------------------+ |
| |
+------------------------------------------------------------+
值对象:
/// Data source indicator shown in the UI (ADR-035).
pub enum DataSourceIndicator {
LiveEsp32, // Green banner: "LIVE - ESP32"
Reconnecting, // Yellow banner: "RECONNECTING..."
Simulated, // Red banner: "SIMULATED DATA"
}
/// Pose estimation mode badge (ADR-035).
pub enum EstimationMode {
SignalDerived, // Green badge: analytical pose from CSI features
ModelInference, // Blue badge: neural network inference from loaded RVF
}
/// Render mode for pose visualization (ADR-035).
pub enum RenderMode {
Skeleton, // Green lines connecting joints + red keypoint dots
Keypoints, // Large colored dots with glow and labels
Heatmap, // Gaussian radial blobs per keypoint, faint skeleton overlay
Dense, // Body region segmentation with colored filled polygons
}
领域服务:
- WebSocketBroadcastService -- 订阅 broadcast::Sender<String>,并将每个 SensingUpdate JSON 转发给所有已连接的 WebSocket 客户端
- SensingServiceJS -- 客户端 JavaScript,用于管理 WebSocket 连接、跟踪 dataSource 状态,并在 5 次重连失败后(约 30 秒延迟)回退到模拟
- GaussianSplatRenderer -- 自定义 GLSL ShaderMaterial,在 20x20 地面网格上渲染点云泼溅,并按信号强度着色
- PoseRenderer -- 渲染骨架、关键点、热力图或稠密人体分割模式
- BackendDetector -- 自动检测完整 DensePose 后端是否可用;如果不可达,则设置 sensingOnlyMode = true
不变量:
- WebSocket 感知服务在应用初始化时启动,而不是在访问标签页时惰性启动(ADR-043 修复)
- 模拟回退延迟到 5 次重连失败(约 30 秒)之后,以避免过早使用合成数据
- pose_source 字段会经过数据转换传递,以便估计模式徽章正确显示
- Dashboard 和 Live Demo 标签页在加载时读取 sensingService.dataSource —— 服务必须已经连接
领域事件¶
| 事件 | 发布方 | 消费方 | 载荷 |
|---|---|---|---|
ServerStarted |
CSI 摄取 | 可视化 | { http_port, udp_port, source_type } |
CsiFrameIngested |
CSI 摄取 | 录制、可视化 | { source, node_id, subcarrier_count, tick } |
SensingUpdateBroadcast |
CSI 摄取 | 可视化(WebSocket) | 完整 SensingUpdate JSON |
ModelLoaded |
模型管理 | CSI 摄取(推理路径) | { model_id, weight_count, version } |
| 事件 | 发布者 | 消费者 | 负载 |
|---|---|---|---|
ModelUnloaded |
模型管理 | CSI 摄取 | { model_id } |
LoraProfileActivated |
模型管理 | CSI 摄取 | { model_id, profile_name } |
RecordingStarted |
录制 | 可视化 | { session_id, session_name, file_path } |
RecordingStopped |
录制 | 可视化 | { session_id, frame_count, duration_secs } |
TrainingStarted |
训练流水线 | 可视化 | { run_id, config, recording_ids } |
TrainingEpochComplete |
训练流水线 | 可视化(WebSocket) | { epoch, total_epochs, train_loss, val_pck, lr } |
TrainingComplete |
训练流水线 | 模型管理、可视化 | { run_id, final_pck, model_path } |
TrainingFailed |
训练流水线 | 可视化 | { run_id, error_message } |
WebSocketClientConnected |
可视化 | -- | { endpoint, client_addr } |
WebSocketClientDisconnected |
可视化 | -- | { endpoint, client_addr } |
在当前实现中,事件通过两种机制实现:
1. broadcast::Sender<String> 用于感知更新的 WebSocket 扇出
2. broadcast::Sender<TrainingProgress> 用于训练进度流式传输
3. 通过 RwLock 进行状态变更,其他上下文在下一个 tick 读取状态变化
上下文映射¶
+-------------------+ +---------------------+
| CSI Ingestion |--------->| Visualization |
| (produces | publish | (WebSocket |
| SensingUpdate) | -------> | consumers) |
+--------+----------+ +----------+----------+
| |
| maybe_record_frame() | reads dataSource
v |
+-------------------+ |
| CSI Recording | |
| (hooks into | |
| tick loop) | |
+--------+----------+ |
| |
| provides dataset_ids |
v |
+-------------------+ +----------+----------+
| Training Pipeline |--------->| Model Management |
| (reads .jsonl, | exports | (loads .rvf for |
| trains model) | .rvf --> | inference) |
+-------------------+ +----------+----------+
|
| model weights
v
+----------+----------+
| CSI Ingestion |
| (inference path |
| uses loaded model)|
+----------------------+
关系:
| 上游 | 下游 | 关系 | 机制 |
|---|---|---|---|
| CSI 摄取 | 可视化 | 发布语言 | broadcast::Sender<String> 配合 SensingUpdate JSON 模式 |
| CSI 摄取 | CSI 录制 | 共享内核 | 从摄取 tick 循环调用 maybe_record_frame() |
| CSI 录制 | 训练流水线 | 跟随者 | 训练读取录制生成的 .csi.jsonl 文件;格式无需协商 |
| 训练流水线 | 模型管理 | 供应商-消费者 | 训练将 .rvf 导出到 data/models/;模型管理扫描并加载 |
| 模型管理 | CSI 摄取 | 共享内核 | 加载的权重存储在 AppStateInner 中;摄取读取它们用于推理 |
| 训练流水线 | 可视化 | 发布语言 | broadcast::Sender<TrainingProgress> 配合进度 JSON 模式 |
防腐层¶
ESP32 二进制协议 ACL¶
ESP32 使用紧凑二进制协议(ADR-018)发送 CSI 帧:20 字节头部,魔数 0xC5100001,后接幅度和相位数组。摄取上下文中的 Esp32Frame 解析器在下游处理之前,将该二进制格式解码为领域值对象(NodeInfo、幅度/相位向量)。没有其他上下文处理原始 UDP 字节。
RVF 容器 ACL¶
.rvf 容器格式封装模型权重、清单元数据、生命体征配置以及可选的 LoRA 适配器。rvf_container 模块中的 RvfReader 和 RvfBuilder 类型在磁盘二进制格式与领域类型(ModelInfo、LoadedModelState)之间提供防腐层。训练流水线通过 RvfBuilder 写入;模型管理上下文通过 RvfReader 读取。
仅感知模式 ACL(客户端)¶
当 DensePose 后端(端口 8000)不可达时,客户端的 BackendDetector 会设置 sensingOnlyMode = true。ApiService.request() 方法会短路所有发往 DensePose 后端的请求,返回空响应而不是 ERR_CONNECTION_REFUSED。这可防止 DensePose 特定关注点泄漏到感知 UI 中。
JSONL 录制格式 ACL¶
CSI 帧以换行分隔的 JSON(.csi.jsonl)形式录制。RecordedFrame 结构体定义模式:{timestamp, subcarriers, rssi, noise_floor, features}。训练流水线通过该模式读取,提取子载波数组用于特征计算。如果内部感知表示发生变化,只需更新 maybe_record_frame() 序列化器——训练流水线仅依赖 RecordedFrame 契约。
REST API 接口¶
所有端点通过 Arc<RwLock<AppStateInner>> 共享 AppStateInner。
CSI 摄取与感知¶
| 方法 | 路径 | 上下文 | 描述 |
|---|---|---|---|
| GET | /api/v1/sensing/latest |
摄取 | 最新感知更新 |
| WS | /ws/sensing |
可视化 | 流式感知更新 |
模型管理¶
| 方法 | 路径 | 上下文 | 描述 |
|---|---|---|---|
| GET | /api/v1/models |
模型管理 | 列出所有发现的 .rvf 模型 |
| 方法 | 路径 | 上下文 | 描述 |
|---|---|---|---|
| GET | /api/v1/models/:id |
模型管理 | 特定模型的详细信息 |
| GET | /api/v1/models/active |
模型管理 | 带有运行时统计信息的活动模型 |
| POST | /api/v1/models/load |
模型管理 | 将模型权重加载到内存 |
| POST | /api/v1/models/unload |
模型管理 | 卸载活动模型 |
| DELETE | /api/v1/models/:id |
模型管理 | 从磁盘删除模型文件 |
| GET | /api/v1/models/lora/profiles |
模型管理 | 列出活动模型的 LoRA 配置文件 |
| POST | /api/v1/models/lora/activate |
模型管理 | 激活 LoRA 适配器 |
CSI 录制¶
| 方法 | 路径 | 上下文 | 描述 |
|---|---|---|---|
| POST | /api/v1/recording/start |
录制 | 开始新的录制会话 |
| POST | /api/v1/recording/stop |
录制 | 停止活动录制 |
| GET | /api/v1/recording/list |
录制 | 列出所有录制会话 |
| GET | /api/v1/recording/download/:id |
录制 | 下载 .csi.jsonl 文件 |
| DELETE | /api/v1/recording/:id |
录制 | 删除录制 |
训练流水线¶
| 方法 | 路径 | 上下文 | 描述 |
|---|---|---|---|
| POST | /api/v1/train/start |
训练 | 开始监督训练 |
| POST | /api/v1/train/stop |
训练 | 停止活动训练运行 |
| GET | /api/v1/train/status |
训练 | 当前训练阶段和指标 |
| POST | /api/v1/train/pretrain |
训练 | 开始对比预训练 |
| POST | /api/v1/train/lora |
训练 | 开始 LoRA 微调 |
| WS | /ws/train/progress |
训练 | 流式传输训练进度 |
文件布局¶
data/
+-- models/ # RVF model files
| +-- wifi-densepose-v1.rvf # Trained model container
| +-- wifi-densepose-field-v2.rvf # Environment-calibrated model
+-- recordings/ # CSI recording sessions
+-- walking-20260303_140000.csi.jsonl # Raw CSI frames (JSONL)
+-- walking-20260303_140000.csi.meta.json # Session metadata
+-- standing-20260303_141500.csi.jsonl
+-- standing-20260303_141500.csi.meta.json
crates/wifi-densepose-sensing-server/
+-- src/
+-- main.rs # Server entry, CLI args, AppStateInner, sensing loop
+-- model_manager.rs # Model Management bounded context
+-- recording.rs # CSI Recording bounded context
+-- training_api.rs # Training Pipeline bounded context
+-- rvf_container.rs # RVF format ACL (RvfReader, RvfBuilder)
+-- rvf_pipeline.rs # Progressive loader for model inference
+-- vital_signs.rs # Vital sign detection from CSI phase
+-- dataset.rs # Dataset loading for training
+-- trainer.rs # Core training loop implementation
+-- embedding.rs # Contrastive embedding extraction
+-- graph_transformer.rs # Graph transformer architecture
+-- sona.rs # SONA self-optimizing profile
+-- sparse_inference.rs # Sparse inference engine
+-- lib.rs # Public module re-exports
相关¶
- ADR-019:仅感知 UI 模式 -- 解耦的感知 UI、高斯泼溅、Python WebSocket 桥接
- ADR-035:实时感知 UI 准确性 -- 数据透明性、Goertzel 呼吸估计、信号响应式姿态
- ADR-043:感知服务器 UI API 完成 -- 模型、录制、训练端点;单二进制部署
- RuvSense 领域模型 -- 上游信号处理领域(多站感知、相干性、跟踪)
- WiFi-Mat 领域模型 -- 下游灾害响应领域
本页原文 Markdown:在 AtomGit 查看·内容源自开源项目 wi/RuView