Skip to content

Commit

Permalink
Merge pull request #19 from datdenkikniet/sdrs
Browse files Browse the repository at this point in the history
Sdrs
  • Loading branch information
datdenkikniet authored May 15, 2024
2 parents f3ee8de + aaef4ad commit c6cdccc
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 35 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* Rudimentary RMCP+ support. ([#13])
* Add more SDR record types. ([#10], [#18])
* Breaking change: improve error reporting in SDR records. ([#10], [#18])
* Fix SDR iteration. ([#19])

[#6]: https://github.com/datdenkikniet/ipmi-rs/pull/6
[#7]: https://github.com/datdenkikniet/ipmi-rs/pull/7
Expand All @@ -19,6 +20,7 @@
[#13]: https://github.com/datdenkikniet/ipmi-rs/pull/13
[#14]: https://github.com/datdenkikniet/ipmi-rs/pull/14
[#18]: https://github.com/datdenkikniet/ipmi-rs/pull/18
[#19]: https://github.com/datdenkikniet/ipmi-rs/pull/19

# [0.2.1](https://github.com/datdenkikniet/ipmi-rs/tree/v0.2.1)

Expand Down
22 changes: 12 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,12 @@ where

fn next(&mut self) -> Option<Self::Item> {
let current_id = self.next_id?;

if current_id.is_last() {
self.next_id.take();
return None;
}

let next_record = self
.ipmi
.send_recv(sdr::GetDeviceSdr::new(None, current_id));
Expand All @@ -125,14 +131,14 @@ where
(Some(record.record), next_record_id)
}
Err(IpmiError::ParsingFailed {
error: ParseResponseError::Parse((e, next_id)),
error: ParseResponseError::Parse((e, next_record_id)),
..
}) => {
log::warn!(
"Recoverable error while parsing SDR record 0x{:04X}: {e:?}",
current_id.value()
);
(None, next_id)
(None, next_record_id)
}
Err(e) => {
log::error!(
Expand All @@ -144,16 +150,12 @@ where
}
};

if current_id.is_last() {
if next_record_id == current_id {
log::error!("Got duplicate SDR record IDs! Stopping iteration.");
self.next_id.take();
return None;
} else {
if next_record_id == current_id {
log::error!("Got duplicate SDR record IDs! Stopping iteration.");
self.next_id.take();
return None;
} else {
self.next_id = Some(next_record_id);
}
self.next_id = Some(next_record_id);
}

value
Expand Down
76 changes: 51 additions & 25 deletions src/storage/sdr/record/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -712,38 +712,19 @@ pub enum RecordContents {

impl Record {
pub fn common_data(&self) -> Option<&SensorRecordCommon> {
match &self.contents {
RecordContents::FullSensor(s) => Some(s.common()),
RecordContents::CompactSensor(s) => Some(s.common()),
RecordContents::EventOnlySensor(_) => None,
RecordContents::FruDeviceLocator(_) => None,
RecordContents::McDeviceLocator(_) => None,
RecordContents::Unknown { .. } => None,
}
self.contents.common_data()
}

pub fn full_sensor(&self) -> Option<&FullSensorRecord> {
if let RecordContents::FullSensor(full_sensor) = &self.contents {
Some(full_sensor)
} else {
None
}
self.contents.full_sensor()
}

pub fn compact_sensor(&self) -> Option<&CompactSensorRecord> {
if let RecordContents::CompactSensor(compact_sensor) = &self.contents {
Some(compact_sensor)
} else {
None
}
self.contents.compact_sensor()
}

pub fn event_only(&self) -> Option<&EventOnlySensorRecord> {
if let RecordContents::EventOnlySensor(event) = &self.contents {
Some(event)
} else {
None
}
self.contents.event_only()
}

pub fn parse(data: &[u8]) -> Result<Self, ParseError> {
Expand Down Expand Up @@ -790,7 +771,52 @@ impl Record {
}

pub fn id(&self) -> Option<&SensorId> {
match &self.contents {
self.contents.id()
}

pub fn sensor_number(&self) -> Option<SensorNumber> {
self.contents.sensor_number()
}
}

impl RecordContents {
pub fn common_data(&self) -> Option<&SensorRecordCommon> {
match self {
RecordContents::FullSensor(s) => Some(s.common()),
RecordContents::CompactSensor(s) => Some(s.common()),
RecordContents::EventOnlySensor(_) => None,
RecordContents::FruDeviceLocator(_) => None,
RecordContents::McDeviceLocator(_) => None,
RecordContents::Unknown { .. } => None,
}
}

pub fn full_sensor(&self) -> Option<&FullSensorRecord> {
if let RecordContents::FullSensor(full_sensor) = self {
Some(full_sensor)
} else {
None
}
}

pub fn compact_sensor(&self) -> Option<&CompactSensorRecord> {
if let RecordContents::CompactSensor(compact_sensor) = self {
Some(compact_sensor)
} else {
None
}
}

pub fn event_only(&self) -> Option<&EventOnlySensorRecord> {
if let RecordContents::EventOnlySensor(event) = self {
Some(event)
} else {
None
}
}

pub fn id(&self) -> Option<&SensorId> {
match self {
RecordContents::FullSensor(full) => Some(full.id_string()),
RecordContents::CompactSensor(compact) => Some(compact.id_string()),
RecordContents::EventOnlySensor(event) => Some(&event.id_string),
Expand All @@ -801,7 +827,7 @@ impl Record {
}

pub fn sensor_number(&self) -> Option<SensorNumber> {
match &self.contents {
match self {
RecordContents::FullSensor(full) => Some(full.sensor_number()),
RecordContents::CompactSensor(compact) => Some(compact.sensor_number()),
RecordContents::EventOnlySensor(event) => Some(event.key.sensor_number),
Expand Down

0 comments on commit c6cdccc

Please sign in to comment.