ipmi-rs-core 0.5.0

A pure rust implementation of the core primitives of the IPMI spec
Documentation
use crate::sensor_event::{RawSensorReading, ThresholdReading};
use crate::storage::sdr::record::SensorId;
use crate::storage::sdr::Record;

const FAN_2A_SDR: [u8; 55] = [
    0x0E, 0x00, 0x0D, 0x00, 0x51, 0x01, 0x30, 0x20, 0x00, 0x32, 0x07, 0x01, 0x7F, 0xD4, 0x04, 0x01,
    0x05, 0x30, 0x05, 0x00, 0x03, 0x00, 0x00, 0x12, 0x00, 0x00, 0x78, 0x02, 0x00, 0x02, 0x30, 0x00,
    0x07, 0x54, 0xC5, 0x8B, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0x05, 0x07, 0x01, 0x01, 0x00, 0x00,
    0x00, 0xC5, 0x46, 0x61, 0x6E, 0x32, 0x41,
];
const FAN_2A_READING: [u8; 3] = [0x2c, 0xc0, 0xc0];
#[test]
fn test_decode_fan_rpm() {
    let sensor = Record::parse(&FAN_2A_SDR[2..]).unwrap();
    assert_eq!(
        SensorId::Ascii8BAndLatin1("Fan2A".to_string()),
        sensor.common_data().unwrap().sensor_id
    );
    let raw_reading = RawSensorReading::parse(&FAN_2A_READING).unwrap();
    let reading: ThresholdReading = (&raw_reading).into();
    assert_eq!(
        "5280.00 rpm",
        sensor
            .full_sensor()
            .unwrap()
            .display_reading(reading.reading.unwrap())
            .unwrap()
    );
}

const INLET_TEMP_SDR: [u8; 60] = [
    0x13, 0x00, 0x12, 0x00, 0x51, 0x01, 0x35, 0x20, 0x00, 0x04, 0x07, 0x01, 0x7F, 0x68, 0x01, 0x01,
    0x85, 0x32, 0x85, 0x32, 0x1B, 0x09, 0x00, 0x01, 0x00, 0x00, 0x01, 0x02, 0x80, 0xC2, 0x30, 0x00,
    0x07, 0x97, 0xC5, 0x8B, 0xFF, 0x00, 0xFF, 0xAF, 0xAA, 0x00, 0x79, 0x83, 0x01, 0x01, 0x00, 0x00,
    0x00, 0xCA, 0x49, 0x6E, 0x6C, 0x65, 0x74, 0x20, 0x54, 0x65, 0x6D, 0x70,
];
const INLET_TEMP_READING: [u8; 3] = [0x99, 0xc0, 0xc0];
#[test]
fn test_decode_inlet_temp() {
    let sensor = Record::parse(&INLET_TEMP_SDR[2..]).unwrap();
    assert_eq!(
        SensorId::Ascii8BAndLatin1("Inlet Temp".to_string()),
        sensor.common_data().unwrap().sensor_id
    );
    let raw_reading = RawSensorReading::parse(&INLET_TEMP_READING).unwrap();
    let reading: ThresholdReading = (&raw_reading).into();
    assert_eq!(
        "25.00 °C",
        sensor
            .full_sensor()
            .unwrap()
            .display_reading(reading.reading.unwrap())
            .unwrap()
    );
}