Skip to main content

rullst_iot/
lib.rs

1//! Rullst IoT data models, protocol frame helpers, and signed firmware gate.
2//!
3//! This crate does not currently provide MQTT/CoAP network transport, hardware
4//! HSM bindings, or post-quantum cryptography. It does provide bounded MQTT 5
5//! PUBLISH and CoAP request encoders. Deterministic fixtures resembling other
6//! capabilities require the explicit `experimental-simulators` feature.
7
8#![cfg_attr(not(feature = "std"), no_std)]
9
10extern crate alloc;
11use alloc::string::String;
12use serde::{Deserialize, Serialize};
13
14// Bounded protocol encoders (not network clients or transports).
15pub mod coap;
16pub mod mqtt;
17
18// State models and protocol frame helpers (not hardware drivers).
19pub mod ble;
20pub mod gpio;
21pub mod i2c;
22pub mod modbus;
23
24// Statistical evaluation and HTML rendering helpers.
25pub mod anomaly;
26pub mod ui;
27
28// Topology state and signed OTA verification.
29pub mod mesh;
30pub mod ota;
31
32// Explicitly simulated cryptographic fixtures.
33#[cfg(feature = "experimental-simulators")]
34pub mod hsm;
35#[cfg(feature = "experimental-simulators")]
36pub mod pqc;
37
38// Power recommendations and digital-twin state.
39pub mod power;
40pub mod twin;
41
42// Re-exports
43pub use anomaly::{AnomalyDetector, AnomalyState};
44pub use ble::{GattCharacteristic, GattService};
45pub use coap::{CoapCodecError, CoapMessageType, CoapMethod, CoapRequest, MAX_COAP_DATAGRAM_BYTES};
46pub use gpio::{GpioPin, PinMode, PinState};
47#[cfg(feature = "experimental-simulators")]
48pub use hsm::{SimulatedHsmDevice, SimulatedHsmProfile};
49pub use i2c::I2cHelper;
50pub use mesh::{MeshNode, MeshTopology, NodeStatus};
51pub use modbus::{ModbusFrame, ModbusFunction};
52#[cfg(feature = "experimental-simulators")]
53pub use mqtt::SimulatedMqttPayloadFormatter;
54pub use mqtt::{MAX_MQTT_PACKET_BYTES, MqttCodecError, MqttPublish, MqttQos};
55pub use ota::{
56    BootPartition, OtaCommit, OtaError, OtaManager, OtaManifest, OtaStatus, RollbackCounterError,
57    RollbackCounterStore,
58};
59pub use power::{HarvesterState, PowerGovernor, PowerMode};
60#[cfg(feature = "experimental-simulators")]
61pub use pqc::SimulatedPqcFixture;
62pub use twin::{DigitalTwin, TwinSyncError};
63pub use ui::IotDashboard;
64
65/// Sensor payload telemetry model for IoT nodes.
66#[derive(Clone, Debug, Serialize, Deserialize)]
67pub struct SensorTelemetry {
68    /// Device identifier string.
69    pub device_id: String,
70    /// Sensor metric name (e.g. "temperature", "humidity", "vibration").
71    pub metric: String,
72    /// Floating point metric reading.
73    pub value: f64,
74    /// UNIX timestamp in seconds.
75    pub timestamp: u64,
76}
77
78impl SensorTelemetry {
79    /// Creates a new SensorTelemetry instance.
80    pub fn new(
81        device_id: impl Into<String>,
82        metric: impl Into<String>,
83        value: f64,
84        timestamp: u64,
85    ) -> Self {
86        Self {
87            device_id: device_id.into(),
88            metric: metric.into(),
89            value,
90            timestamp,
91        }
92    }
93}
94
95#[cfg(test)]
96mod tests {
97    use super::*;
98
99    #[test]
100    fn test_sensor_telemetry() {
101        let t = SensorTelemetry::new("esp32-node-01", "temperature", 24.5, 1700000000);
102        assert_eq!(t.device_id, "esp32-node-01");
103        assert_eq!(t.metric, "temperature");
104        assert_eq!(t.value, 24.5);
105    }
106}