#[derive(Clone, Copy, Debug, PartialEq)]
pub enum DataLength {
Standard(u8),
Fdcan(u8),
}
impl DataLength {
pub fn new(len: u8, ff: FrameFormat) -> DataLength {
match ff {
FrameFormat::Standard => match len {
0..=8 => DataLength::Standard(len),
_ => panic!("DataLength > 8"),
},
FrameFormat::Fdcan => match len {
0..=64 => DataLength::Fdcan(len),
_ => panic!("DataLength > 64"),
},
}
}
pub fn new_standard(len: u8) -> DataLength {
Self::new(len, FrameFormat::Standard)
}
pub fn new_fdcan(len: u8) -> DataLength {
Self::new(len, FrameFormat::Fdcan)
}
pub fn len(&self) -> u8 {
match self {
DataLength::Standard(l) | DataLength::Fdcan(l) => *l,
}
}
pub(crate) fn dlc(&self) -> u8 {
match self {
DataLength::Standard(l) => *l,
DataLength::Fdcan(l) => match l {
0..=8 => *l,
9..=12 => 9,
13..=16 => 10,
17..=20 => 11,
21..=24 => 12,
25..=32 => 13,
33..=48 => 14,
49..=64 => 15,
_ => panic!("DataLength > 64"),
},
}
}
}
impl From<DataLength> for FrameFormat {
fn from(dl: DataLength) -> FrameFormat {
match dl {
DataLength::Standard(_) => FrameFormat::Standard,
DataLength::Fdcan(_) => FrameFormat::Fdcan,
}
}
}
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum Event {
NoEvent,
Event(u8),
}
impl From<Event> for EventControl {
fn from(e: Event) -> Self {
match e {
Event::NoEvent => EventControl::DoNotStore,
Event::Event(_) => EventControl::Store,
}
}
}
impl From<Option<u8>> for Event {
fn from(mm: Option<u8>) -> Self {
match mm {
None => Event::NoEvent,
Some(mm) => Event::Event(mm),
}
}
}
impl From<Event> for Option<u8> {
fn from(e: Event) -> Option<u8> {
match e {
Event::NoEvent => None,
Event::Event(mm) => Some(mm),
}
}
}
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum ErrorStateIndicator {
ErrorActive = 0,
ErrorPassive = 1,
}
impl From<ErrorStateIndicator> for bool {
#[inline(always)]
fn from(e: ErrorStateIndicator) -> Self {
e as u8 != 0
}
}
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum FrameFormat {
Standard = 0,
Fdcan = 1,
}
impl From<FrameFormat> for bool {
#[inline(always)]
fn from(e: FrameFormat) -> Self {
e as u8 != 0
}
}
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum IdType {
StandardId = 0,
ExtendedId = 1,
}
impl From<IdType> for bool {
#[inline(always)]
fn from(e: IdType) -> Self {
e as u8 != 0
}
}
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum RemoteTransmissionRequest {
TransmitDataFrame = 0,
TransmitRemoteFrame = 1,
}
impl From<RemoteTransmissionRequest> for bool {
#[inline(always)]
fn from(e: RemoteTransmissionRequest) -> Self {
e as u8 != 0
}
}
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum BitRateSwitching {
WithoutBRS = 0,
WithBRS = 1,
}
impl From<BitRateSwitching> for bool {
#[inline(always)]
fn from(e: BitRateSwitching) -> Self {
e as u8 != 0
}
}
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum EventControl {
DoNotStore,
Store,
}
impl From<EventControl> for bool {
#[inline(always)]
fn from(e: EventControl) -> Self {
e as u8 != 0
}
}
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum FilterFrameMatch {
DidMatch(u8),
DidNotMatch,
}
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum FilterType {
RangeFilter = 0b00,
DualIdFilter = 0b01,
ClassicFilter = 0b10,
FilterDisabled = 0b11,
}
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum FilterElementConfig {
DisableFilterElement = 0b000,
StoreInFifo0 = 0b001,
StoreInFifo1 = 0b010,
Reject = 0b011,
SetPriority = 0b100,
SetPriorityAndStoreInFifo0 = 0b101,
SetPriorityAndStoreInFifo1 = 0b110,
}