use crate::cpu::RxMessage;
#[repr(C)]
pub struct FPGAInfo {
info: u8,
}
impl FPGAInfo {
pub const fn new(info: u8) -> Self {
Self { info }
}
pub const fn is_thermal_assert(&self) -> bool {
(self.info & 0x01) != 0
}
pub const fn info(&self) -> u8 {
self.info
}
}
impl From<&RxMessage> for FPGAInfo {
fn from(msg: &RxMessage) -> Self {
Self { info: msg.data }
}
}
#[cfg(test)]
mod tests {
use std::mem::size_of;
use super::*;
#[test]
fn fpga_info() {
assert_eq!(size_of::<FPGAInfo>(), 1);
let info = FPGAInfo::new(0x00);
assert!(!info.is_thermal_assert());
assert_eq!(info.info(), 0x00);
let info = FPGAInfo::new(0x01);
assert!(info.is_thermal_assert());
assert_eq!(info.info(), 0x01);
let info = FPGAInfo::new(0x02);
assert!(!info.is_thermal_assert());
assert_eq!(info.info(), 0x02);
let rx = RxMessage { ack: 0, data: 0x01 };
let info = FPGAInfo::from(&rx);
assert!(info.is_thermal_assert());
assert_eq!(info.info(), 0x01);
}
}