ipmi_rs/sensor_event/sensor_reading/
get.rs1use crate::{
2 connection::{Address, Channel, CompletionCode, IpmiCommand, Message, ParseResponseError},
3 storage::sdr::record::{SensorKey, SensorNumber},
4};
5
6use super::RawSensorReading;
7
8impl RawSensorReading {
9 pub(crate) fn parse(data: &[u8]) -> Option<Self> {
10 if data.len() < 2 {
11 return None;
12 }
13
14 let reading = data[0];
15
16 let all_event_messages_disabled = (data[1] & 0x80) != 0x80;
18
19 let scanning_disabled = (data[1] & 0x40) != 0x40;
21
22 let reading_or_state_unavailable = (data[1] & 0x20) == 0x20;
23
24 let offset_data_1 = data.get(2).copied();
25 let offset_data_2 = data.get(3).copied();
26
27 Some(Self {
28 reading,
29 all_event_messages_disabled,
30 scanning_disabled,
31 reading_or_state_unavailable,
32 offset_data_1,
33 offset_data_2,
34 })
35 }
36}
37
38pub struct GetSensorReading {
39 sensor_number: SensorNumber,
40 address: Address,
41 channel: Channel,
42}
43
44impl GetSensorReading {
45 pub fn new(sensor_number: SensorNumber, address: Address, channel: Channel) -> Self {
46 Self {
47 sensor_number,
48 address,
49 channel,
50 }
51 }
52
53 pub fn for_sensor_key(value: &SensorKey) -> Self {
54 Self {
55 sensor_number: value.sensor_number,
56 address: Address(value.owner_id.into()),
57 channel: value.owner_channel,
58 }
59 }
60}
61
62impl From<GetSensorReading> for Message {
63 fn from(value: GetSensorReading) -> Self {
64 Message::new_request(
65 crate::connection::NetFn::SensorEvent,
66 0x2D,
67 vec![value.sensor_number.get()],
68 )
69 }
70}
71
72impl IpmiCommand for GetSensorReading {
73 type Output = RawSensorReading;
74
75 type Error = ();
76
77 fn parse_response(
78 completion_code: CompletionCode,
79 data: &[u8],
80 ) -> Result<Self::Output, ParseResponseError<Self::Error>> {
81 Self::check_cc_success(completion_code)?;
82
83 RawSensorReading::parse(data).ok_or(ParseResponseError::NotEnoughData)
84 }
85
86 fn target(&self) -> Option<(Address, Channel)> {
87 Some((self.address, self.channel))
88 }
89}