#[allow(unused_imports)]
use super::*;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub struct LinFlags(u8);
impl LinFlags {
pub const TX: u8 = 0x01;
pub const WAKEUP: u8 = 0x02;
pub const CHECKSUM_ERROR: u8 = 0x04;
pub const NO_RESPONSE: u8 = 0x08;
pub const SYNC_ERROR: u8 = 0x10;
pub const FRAMING_ERROR: u8 = 0x20;
pub const SHORT_RESPONSE: u8 = 0x40;
pub const ENHANCED_CHECKSUM: u8 = 0x80;
pub fn from_byte(value: u8) -> Self {
Self(value)
}
pub fn to_byte(self) -> u8 {
self.0
}
pub fn rx() -> Self {
Self(0)
}
pub fn tx() -> Self {
Self(Self::TX)
}
pub fn is_tx(self) -> bool {
self.0 & Self::TX != 0
}
pub fn is_rx(self) -> bool {
!self.is_tx()
}
pub fn is_wakeup(self) -> bool {
self.0 & Self::WAKEUP != 0
}
pub fn has_checksum_error(self) -> bool {
self.0 & Self::CHECKSUM_ERROR != 0
}
pub fn has_no_response(self) -> bool {
self.0 & Self::NO_RESPONSE != 0
}
pub fn has_sync_error(self) -> bool {
self.0 & Self::SYNC_ERROR != 0
}
pub fn has_framing_error(self) -> bool {
self.0 & Self::FRAMING_ERROR != 0
}
pub fn has_short_response(self) -> bool {
self.0 & Self::SHORT_RESPONSE != 0
}
pub fn uses_enhanced_checksum(self) -> bool {
self.0 & Self::ENHANCED_CHECKSUM != 0
}
pub fn has_error(self) -> bool {
self.0
& (Self::CHECKSUM_ERROR
| Self::NO_RESPONSE
| Self::SYNC_ERROR
| Self::FRAMING_ERROR
| Self::SHORT_RESPONSE)
!= 0
}
pub fn with_tx(self, tx: bool) -> Self {
if tx {
Self(self.0 | Self::TX)
} else {
Self(self.0 & !Self::TX)
}
}
pub fn with_enhanced_checksum(self, enhanced: bool) -> Self {
if enhanced {
Self(self.0 | Self::ENHANCED_CHECKSUM)
} else {
Self(self.0 & !Self::ENHANCED_CHECKSUM)
}
}
}