1use std::fmt;
2
3#[derive(Clone, Default, PartialEq)]
8pub struct DeviceTelemetry {
9 pub temperature_c: Option<f32>,
12
13 pub link_throughput_mbps: Option<u32>,
15
16 pub transmission_errors: u64,
19
20 pub dropped_frames: u64,
22
23 pub corrupted_frames: u64,
25
26 pub power_consumption_mw: Option<u32>,
28}
29
30impl fmt::Debug for DeviceTelemetry {
31 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
32 f.debug_struct("DeviceTelemetry")
33 .field("temp_c", &self.temperature_c.unwrap_or(-1.0))
34 .field("link_mbps", &self.link_throughput_mbps.unwrap_or(0))
35 .field("errors", &self.transmission_errors)
36 .field("dropped", &self.dropped_frames)
37 .finish()
38 }
39}
40
41#[derive(Debug, Clone, Copy, PartialEq, Eq)]
43pub enum DeviceHealthStatus {
44 Healthy,
45 Warning(HealthIssue),
46 Critical(HealthIssue),
47}
48
49#[derive(Debug, Clone, Copy, PartialEq, Eq)]
50pub enum HealthIssue {
51 Overheating,
52 BandwidthSaturation,
53 HighPacketLoss,
54 SensorError,
55}
56
57impl DeviceTelemetry {
58 pub fn assess_health(&self) -> DeviceHealthStatus {
60 if let Some(t) = self.temperature_c {
61 if t > 85.0 {
62 return DeviceHealthStatus::Critical(HealthIssue::Overheating);
63 } else if t > 75.0 {
64 return DeviceHealthStatus::Warning(HealthIssue::Overheating);
65 }
66 }
67
68 if self.transmission_errors > 100 {
69 return DeviceHealthStatus::Warning(HealthIssue::HighPacketLoss);
70 }
71
72 DeviceHealthStatus::Healthy
73 }
74}