ipmi_rs/sensor_event/sensor_reading/
mod.rs1mod get;
2pub use get::GetSensorReading;
3
4use crate::storage::sdr::event_reading_type_code::Threshold;
5
6pub trait FromSensorReading {
7 type Sensor;
8
9 fn from(sensor: &Self::Sensor, reading: &RawSensorReading) -> Self;
10}
11
12#[derive(Debug, Clone, Copy)]
13pub struct RawSensorReading {
14 reading: u8,
15 all_event_messages_disabled: bool,
16 scanning_disabled: bool,
17 reading_or_state_unavailable: bool,
18 offset_data_1: Option<u8>,
19 #[allow(unused)]
20 offset_data_2: Option<u8>,
21}
22
23#[derive(Debug, Clone, Copy)]
24pub struct ThresholdStatus {
25 pub at_or_above_non_recoverable: bool,
26 pub at_or_above_upper_critical: bool,
27 pub at_or_above_upper_non_critical: bool,
28 pub at_or_below_lower_non_recoverable: bool,
29 pub at_or_below_lower_critical: bool,
30 pub at_or_below_lower_non_critical: bool,
31}
32
33#[derive(Debug, Clone, Copy)]
34pub struct ThresholdReading {
35 pub all_event_messages_disabled: bool,
36 pub scanning_disabled: bool,
37 pub reading: Option<u8>,
38 pub threshold_status: Option<ThresholdStatus>,
39}
40
41impl From<&RawSensorReading> for ThresholdReading {
42 fn from(in_reading: &RawSensorReading) -> Self {
43 let threshold_status = if in_reading.reading_or_state_unavailable {
44 None
45 } else {
46 in_reading.offset_data_1.map(|d| ThresholdStatus {
47 at_or_above_non_recoverable: (d & 0x20) == 0x20,
48 at_or_above_upper_critical: (d & 0x10 == 0x10),
49 at_or_above_upper_non_critical: (d & 0x08) == 0x08,
50 at_or_below_lower_non_recoverable: (d & 0x04) == 0x04,
51 at_or_below_lower_critical: (d & 0x20) == 0x20,
52 at_or_below_lower_non_critical: (d & 0x01) == 0x01,
53 })
54 };
55
56 let reading = if in_reading.reading_or_state_unavailable {
57 None
58 } else {
59 Some(in_reading.reading)
60 };
61
62 Self {
63 all_event_messages_disabled: in_reading.all_event_messages_disabled,
64 scanning_disabled: in_reading.scanning_disabled,
65 reading,
66 threshold_status,
67 }
68 }
69}
70
71impl FromSensorReading for ThresholdReading {
72 type Sensor = Threshold;
73
74 fn from(_: &Self::Sensor, in_reading: &RawSensorReading) -> Self {
75 in_reading.into()
76 }
77}