#[derive(Copy, Clone, Debug, PartialEq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[repr(u8)]
pub enum NmtState {
Bootup = 0,
Stopped = 4,
Operational = 5,
PreOperational = 127,
}
impl core::fmt::Display for NmtState {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
NmtState::Bootup => write!(f, "Bootup"),
NmtState::Stopped => write!(f, "Stopped"),
NmtState::Operational => write!(f, "Operational"),
NmtState::PreOperational => write!(f, "PreOperational"),
}
}
}
#[derive(Clone, Copy, Debug)]
pub struct InvalidNmtStateError(pub u8);
impl TryFrom<u8> for NmtState {
type Error = InvalidNmtStateError;
fn try_from(value: u8) -> Result<Self, Self::Error> {
use NmtState::*;
match value {
x if x == Bootup as u8 => Ok(Bootup),
x if x == Stopped as u8 => Ok(Stopped),
x if x == Operational as u8 => Ok(Operational),
x if x == PreOperational as u8 => Ok(PreOperational),
_ => Err(InvalidNmtStateError(value)),
}
}
}