/ firmware / src / services / system.rs
system.rs
 1  use embassy_time::Instant;
 2  
 3  use crate::{
 4      config::board,
 5      filesystems::sd,
 6      networking, power,
 7      sensors::manager,
 8      services::{data_logger, identity},
 9  };
10  
11  pub struct StorageSnapshot {
12      pub sd_card_size_mb: u32,
13  }
14  
15  pub struct SleepStatusSnapshot {
16      pub pending: bool,
17      pub requested_duration_seconds: u64,
18      pub wake_cause: &'static str,
19  }
20  
21  pub struct DataLoggerSnapshot {
22      pub interval_seconds: u64,
23      pub path: &'static str,
24  }
25  
26  pub struct SystemSnapshot {
27      pub hostname: &'static str,
28      pub platform: &'static str,
29      pub ssh_user: &'static str,
30      pub uptime_seconds: u64,
31      pub heap_free: usize,
32      pub heap_used: usize,
33      pub heap_total: usize,
34      pub network: networking::wifi::WifiSnapshot,
35      pub storage: StorageSnapshot,
36      pub sensors: manager::StatusSnapshot,
37      pub sleep: SleepStatusSnapshot,
38      pub data_logger: DataLoggerSnapshot,
39  }
40  
41  pub fn snapshot() -> SystemSnapshot {
42      let heap_free = esp_alloc::HEAP.free();
43      let heap_used = esp_alloc::HEAP.used();
44      let wifi_snapshot = networking::wifi::snapshot();
45      let storage_snapshot = sd::snapshot();
46  
47      SystemSnapshot {
48          hostname: identity::hostname(),
49          platform: board::PLATFORM,
50          ssh_user: identity::ssh_user(),
51          uptime_seconds: Instant::now().as_secs(),
52          heap_free,
53          heap_used,
54          heap_total: heap_free + heap_used,
55          network: wifi_snapshot,
56          storage: StorageSnapshot {
57              sd_card_size_mb: storage_snapshot.sd_card_size_mb,
58          },
59          sensors: manager::snapshot(),
60          sleep: {
61              let sleep_snapshot = power::sleep::snapshot();
62              SleepStatusSnapshot {
63                  pending: sleep_snapshot.pending,
64                  requested_duration_seconds: sleep_snapshot.requested_duration_seconds,
65                  wake_cause: sleep_snapshot.wake_cause,
66              }
67          },
68          data_logger: {
69              let data_logger_snapshot = data_logger::snapshot();
70              DataLoggerSnapshot {
71                  interval_seconds: data_logger_snapshot.interval_seconds,
72                  path: data_logger_snapshot.path,
73              }
74          },
75      }
76  }