#[allow(unused_imports)]
use super::*;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub struct FlexRayFlags(u16);
impl FlexRayFlags {
pub const TX: u16 = 0x0001;
pub const STARTUP: u16 = 0x0002;
pub const SYNC: u16 = 0x0004;
pub const NULL_FRAME: u16 = 0x0008;
pub const PAYLOAD_PREAMBLE: u16 = 0x0010;
pub const HEADER_CRC_ERROR: u16 = 0x0020;
pub const FRAME_CRC_ERROR: u16 = 0x0040;
pub const CODING_ERROR: u16 = 0x0080;
pub const TSS_VIOLATION: u16 = 0x0100;
pub const VALID: u16 = 0x0200;
pub const NM_VECTOR: u16 = 0x0400;
pub const DYNAMIC: u16 = 0x0800;
pub fn from_u16(value: u16) -> Self {
Self(value)
}
pub fn to_u16(self) -> u16 {
self.0
}
pub fn rx() -> Self {
Self(Self::VALID)
}
pub fn tx() -> Self {
Self(Self::TX | Self::VALID)
}
pub fn is_tx(self) -> bool {
self.0 & Self::TX != 0
}
pub fn is_rx(self) -> bool {
!self.is_tx()
}
pub fn is_startup(self) -> bool {
self.0 & Self::STARTUP != 0
}
pub fn is_sync(self) -> bool {
self.0 & Self::SYNC != 0
}
pub fn is_null_frame(self) -> bool {
self.0 & Self::NULL_FRAME != 0
}
pub fn has_payload_preamble(self) -> bool {
self.0 & Self::PAYLOAD_PREAMBLE != 0
}
pub fn has_header_crc_error(self) -> bool {
self.0 & Self::HEADER_CRC_ERROR != 0
}
pub fn has_frame_crc_error(self) -> bool {
self.0 & Self::FRAME_CRC_ERROR != 0
}
pub fn has_coding_error(self) -> bool {
self.0 & Self::CODING_ERROR != 0
}
pub fn is_valid(self) -> bool {
self.0 & Self::VALID != 0
}
pub fn has_nm_vector(self) -> bool {
self.0 & Self::NM_VECTOR != 0
}
pub fn is_dynamic(self) -> bool {
self.0 & Self::DYNAMIC != 0
}
pub fn has_error(self) -> bool {
self.0
& (Self::HEADER_CRC_ERROR
| Self::FRAME_CRC_ERROR
| Self::CODING_ERROR
| Self::TSS_VIOLATION)
!= 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_valid(self, valid: bool) -> Self {
if valid {
Self(self.0 | Self::VALID)
} else {
Self(self.0 & !Self::VALID)
}
}
pub fn with_startup(self, startup: bool) -> Self {
if startup {
Self(self.0 | Self::STARTUP)
} else {
Self(self.0 & !Self::STARTUP)
}
}
pub fn with_sync(self, sync: bool) -> Self {
if sync {
Self(self.0 | Self::SYNC)
} else {
Self(self.0 & !Self::SYNC)
}
}
pub fn with_null_frame(self, null_frame: bool) -> Self {
if null_frame {
Self(self.0 | Self::NULL_FRAME)
} else {
Self(self.0 & !Self::NULL_FRAME)
}
}
pub fn with_dynamic(self, dynamic: bool) -> Self {
if dynamic {
Self(self.0 | Self::DYNAMIC)
} else {
Self(self.0 & !Self::DYNAMIC)
}
}
}