bnr_xfs/history/
system_use_history.rs

1use crate::xfs::method_response::XfsMethodResponse;
2use crate::{create_xfs_array, create_xfs_date_time, create_xfs_i4, create_xfs_struct};
3use crate::{Error, Result};
4
5const SENSOR_TEMPS_LEN: usize = 4;
6const SENSOR_TEMP_DEFAULT: SensorTemperature = SensorTemperature::new();
7
8create_xfs_date_time!(
9    CurrentDateTime,
10    "currentDateTime",
11    "Represents the device current date time."
12);
13
14create_xfs_i4!(UpTime, "upTime", "Represents the device up time.");
15
16create_xfs_i4!(
17    TotalUpTime,
18    "totalUpTime",
19    "Represents the device total up time."
20);
21
22create_xfs_i4!(
23    TimeSinceOperational,
24    "timeSinceOperational",
25    "Represents the device time since operational."
26);
27
28create_xfs_i4!(
29    SystemCycleCount,
30    "systemCycleCount",
31    "Represents the device system cycle count."
32);
33
34create_xfs_i4!(
35    SystemTemperature,
36    "systemTemperature",
37    "Represents the device system temperature."
38);
39
40create_xfs_i4!(
41    SensorTemperature,
42    "",
43    "Represents a device sensor temperature."
44);
45
46create_xfs_array!(
47    RecognitionSensorTemperatures,
48    "recognitionSensorTemperatures",
49    SensorTemperature,
50    SENSOR_TEMPS_LEN,
51    SENSOR_TEMP_DEFAULT,
52    "Represents the device recognition sensor temperatures."
53);
54
55create_xfs_i4!(
56    PowerSupplyVoltage,
57    "powerSupplyVoltage",
58    "Represents a device power supply voltage."
59);
60
61create_xfs_struct!(
62    SystemUseHistory,
63    "systemUseHistory",
64    [
65        current_date_time: CurrentDateTime,
66        up_time: UpTime,
67        total_up_time: TotalUpTime,
68        time_since_operational: TimeSinceOperational,
69        system_cycle_count: SystemCycleCount,
70        system_temperature: SystemTemperature,
71        recognition_sensor_temperatures: RecognitionSensorTemperatures,
72        power_supply_voltage: PowerSupplyVoltage
73    ],
74    "Represents the system use history."
75);
76
77impl TryFrom<&XfsMethodResponse> for SystemUseHistory {
78    type Error = Error;
79
80    fn try_from(val: &XfsMethodResponse) -> Result<Self> {
81        val.as_params()?
82            .params()
83            .iter()
84            .map(|m| m.inner())
85            .find(|m| m.value().xfs_struct().is_some())
86            .ok_or(Error::Xfs(format!(
87                "Expected SystemUseHistory XfsMethodResponse, have: {val}"
88            )))?
89            .value()
90            .try_into()
91    }
92}
93
94impl TryFrom<XfsMethodResponse> for SystemUseHistory {
95    type Error = Error;
96
97    fn try_from(val: XfsMethodResponse) -> Result<Self> {
98        (&val).try_into()
99    }
100}