pub mod nb;
mod id;
pub use self::id::*;
pub use self::nb::*;
pub trait Frame: Sized {
fn new(id: impl Into<Id>, data: &[u8]) -> Option<Self>;
fn new_remote(id: impl Into<Id>, dlc: usize) -> Option<Self>;
fn is_extended(&self) -> bool;
fn is_standard(&self) -> bool {
!self.is_extended()
}
fn is_remote_frame(&self) -> bool;
fn is_data_frame(&self) -> bool {
!self.is_remote_frame()
}
fn id(&self) -> Id;
fn dlc(&self) -> usize;
fn data(&self) -> &[u8];
}
pub trait Error: core::fmt::Debug {
fn kind(&self) -> ErrorKind;
}
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub enum ErrorKind {
Overrun,
Bit,
Stuff,
Crc,
Form,
Acknowledge,
Other,
}
impl Error for ErrorKind {
fn kind(&self) -> ErrorKind {
*self
}
}
impl core::fmt::Display for ErrorKind {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
ErrorKind::Overrun => write!(f, "The peripheral receive buffer was overrun"),
ErrorKind::Bit => write!(
f,
"Bit value that is monitored differs from the bit value sent"
),
ErrorKind::Stuff => write!(f, "Sixth consecutive equal bits detected"),
ErrorKind::Crc => write!(f, "Calculated CRC sequence does not equal the received one"),
ErrorKind::Form => write!(
f,
"A fixed-form bit field contains one or more illegal bits"
),
ErrorKind::Acknowledge => write!(f, "Transmitted frame was not acknowledged"),
ErrorKind::Other => write!(
f,
"A different error occurred. The original error may contain more information"
),
}
}
}