Skip to main content

rufield_core/
modality.rs

1//! Modality registry (ADR-260 §8) and field tensor axes (§9).
2
3use serde::{Deserialize, Serialize};
4
5/// The 15 sensing modalities defined in the RuField MFS modality registry
6/// (ADR-260 §8). Each maps to a stable numeric code on the wire.
7#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
8#[serde(rename_all = "snake_case")]
9pub enum Modality {
10    /// 1 — WiFi Channel State Information (ESP32 C6, Intel BE200, AP CSI).
11    WifiCsi,
12    /// 2 — WiFi Channel Impulse Response.
13    WifiCir,
14    /// 3 — WiFi Beamforming Feedback.
15    WifiBfld,
16    /// 4 — UWB HRP ranging (IEEE 802.15.4z).
17    UwbHrp,
18    /// 5 — Bluetooth Channel Sounding (phase + timing primitives).
19    BleChannelSounding,
20    /// 6 — mmWave range-Doppler radar.
21    MmwaveRadar,
22    /// 7 — Ultrasonic echo / time-of-flight.
23    Ultrasonic,
24    /// 8 — Subsonic structural vibration / room resonance.
25    Subsonic,
26    /// 9 — Thermal array or passive IR.
27    InfraredThermal,
28    /// 10 — Reflected (active) infrared.
29    ActiveInfrared,
30    /// 11 — Phase-based optical range (lidar).
31    LidarPhase,
32    /// 12 — NV diamond / OPM magnetic field trace.
33    QuantumMagnetic,
34    /// 13 — Atom interferometer / precision IMU.
35    QuantumInertial,
36    /// 14 — Optional visual event stream.
37    EventCamera,
38    /// 15 — Simulator or replay source.
39    SyntheticSim,
40}
41
42impl Modality {
43    /// Stable numeric registry code (ADR-260 §8, 1-indexed).
44    #[must_use]
45    pub fn code(self) -> u8 {
46        match self {
47            Modality::WifiCsi => 1,
48            Modality::WifiCir => 2,
49            Modality::WifiBfld => 3,
50            Modality::UwbHrp => 4,
51            Modality::BleChannelSounding => 5,
52            Modality::MmwaveRadar => 6,
53            Modality::Ultrasonic => 7,
54            Modality::Subsonic => 8,
55            Modality::InfraredThermal => 9,
56            Modality::ActiveInfrared => 10,
57            Modality::LidarPhase => 11,
58            Modality::QuantumMagnetic => 12,
59            Modality::QuantumInertial => 13,
60            Modality::EventCamera => 14,
61            Modality::SyntheticSim => 15,
62        }
63    }
64
65    /// All 15 modalities in registry order.
66    #[must_use]
67    pub fn all() -> [Modality; 15] {
68        [
69            Modality::WifiCsi,
70            Modality::WifiCir,
71            Modality::WifiBfld,
72            Modality::UwbHrp,
73            Modality::BleChannelSounding,
74            Modality::MmwaveRadar,
75            Modality::Ultrasonic,
76            Modality::Subsonic,
77            Modality::InfraredThermal,
78            Modality::ActiveInfrared,
79            Modality::LidarPhase,
80            Modality::QuantumMagnetic,
81            Modality::QuantumInertial,
82            Modality::EventCamera,
83            Modality::SyntheticSim,
84        ]
85    }
86}
87
88/// A semantic axis of a [`crate::FieldTensor`] (ADR-260 §9). Axes label the
89/// dimensions of the tensor so consumers can interpret the numeric values
90/// without out-of-band knowledge.
91#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
92#[serde(rename_all = "snake_case")]
93pub enum FieldAxis {
94    /// Time samples.
95    Time,
96    /// Frequency / subcarrier bins.
97    Frequency,
98    /// Phase component.
99    Phase,
100    /// Amplitude component.
101    Amplitude,
102    /// Range bins (radar / ToF).
103    Range,
104    /// Velocity / Doppler bins.
105    Velocity,
106    /// Angle-of-arrival bins.
107    Angle,
108    /// Temperature (thermal IR).
109    Temperature,
110    /// Structural vibration.
111    Vibration,
112    /// Per-element uncertainty.
113    Uncertainty,
114    /// Spatial channel / antenna index.
115    Channel,
116}
117
118#[cfg(test)]
119mod tests {
120    use super::*;
121
122    #[test]
123    fn modality_has_15_variants() {
124        assert_eq!(Modality::all().len(), 15);
125    }
126
127    #[test]
128    fn modality_codes_are_1_to_15_unique() {
129        let codes: Vec<u8> = Modality::all().iter().map(|m| m.code()).collect();
130        assert_eq!(codes, (1..=15).collect::<Vec<u8>>());
131    }
132
133    #[test]
134    fn modality_serde_snake_case() {
135        let j = serde_json::to_string(&Modality::WifiCsi).unwrap();
136        assert_eq!(j, "\"wifi_csi\"");
137        let m: Modality = serde_json::from_str("\"mmwave_radar\"").unwrap();
138        assert_eq!(m, Modality::MmwaveRadar);
139    }
140}