islabtech_upw_sensor_v1/system_status/
mod.rs

1use serde::{Deserialize, Serialize};
2use std::fmt::{Debug, Display};
3
4mod serde_datetime;
5
6/// hold information describing the current system status of the [`Device`](crate::Device)
7///
8/// Note that this struct only describes a momentary state. It does not automatically update. If you
9/// want to get the system status at a new point in time, call [`Device::system_status()`](crate::Device::system_status()) again.
10#[derive(Debug, Serialize, Deserialize, PartialEq)]
11pub struct SystemStatus {
12    pub firmware: FirmwareSystemStatus,
13    pub hardware: HardwareSystemStatus,
14    pub time: TimeSystemStatus,
15}
16
17#[derive(Debug, Serialize, Deserialize, PartialEq)]
18pub struct FirmwareSystemStatus {
19    /// firmware version
20    pub version: semver::Version,
21
22    pub updates: FirmwareUpdatesSystemStatus,
23}
24
25#[derive(Debug, Serialize, Deserialize, PartialEq)]
26pub struct FirmwareUpdatesSystemStatus {
27    /// whether automatic updates are enabled
28    pub enabled: bool,
29}
30
31#[derive(Debug, Serialize, Deserialize, PartialEq)]
32pub struct HardwareSystemStatus {
33    /// hardware version
34    pub version: semver::Version,
35
36    /// unique serial number identifying this device
37    pub serial_number: SerialNumber,
38}
39#[derive(Debug, Serialize, Deserialize, PartialEq)]
40pub struct TimeSystemStatus {
41    /// milliseconds elapsed since device last booted
42    pub milliseconds_since_boot: u64,
43
44    /// seconds elapsed since device last booted
45    pub seconds_since_boot: u64,
46
47    /// current system time of the device
48    #[serde(with = "serde_datetime", rename = "epoch_time")]
49    pub current_time: chrono::DateTime<chrono::Utc>,
50}
51
52#[derive(Serialize, Deserialize, PartialEq)]
53pub struct SerialNumber(pub String);
54impl Display for SerialNumber {
55    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
56        write!(f, "{}", self.0)
57    }
58}
59impl Debug for SerialNumber {
60    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
61        write!(f, "{}", self)
62    }
63}