mod cme_error;
mod cms_error;
mod connection_error;
pub use cme_error::CmeError;
pub use cms_error::CmsError;
pub use connection_error::ConnectionError;
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum InternalError<'a> {
Read,
Write,
Timeout,
InvalidResponse,
Aborted,
Parse,
Error,
CmeError(CmeError),
CmsError(CmsError),
ConnectionError(ConnectionError),
Custom(&'a [u8]),
}
#[cfg(feature = "defmt")]
impl<'a> defmt::Format for InternalError<'a> {
fn format(&self, f: defmt::Formatter) {
match self {
InternalError::Read => defmt::write!(f, "InternalError::Read"),
InternalError::Write => defmt::write!(f, "InternalError::Write"),
InternalError::Timeout => defmt::write!(f, "InternalError::Timeout"),
InternalError::InvalidResponse => defmt::write!(f, "InternalError::InvalidResponse"),
InternalError::Aborted => defmt::write!(f, "InternalError::Aborted"),
InternalError::Parse => defmt::write!(f, "InternalError::Parse"),
InternalError::Error => defmt::write!(f, "InternalError::Error"),
InternalError::CmeError(e) => defmt::write!(f, "InternalError::CmeError({:?})", e),
InternalError::CmsError(e) => defmt::write!(f, "InternalError::CmsError({:?})", e),
InternalError::ConnectionError(e) => {
defmt::write!(f, "InternalError::ConnectionError({:?})", e)
}
InternalError::Custom(e) => {
defmt::write!(f, "InternalError::Custom({=[u8]:a})", &e)
}
}
}
}
#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum Error {
Read,
Write,
Timeout,
InvalidResponse,
Aborted,
Parse,
Error,
CmeError(CmeError),
CmsError(CmsError),
ConnectionError(ConnectionError),
Custom,
#[cfg(feature = "custom-error-messages")]
CustomMessage(heapless::Vec<u8, 64>),
}
impl<'a> From<InternalError<'a>> for Error {
fn from(ie: InternalError) -> Self {
match ie {
InternalError::Read => Self::Read,
InternalError::Write => Self::Write,
InternalError::Timeout => Self::Timeout,
InternalError::InvalidResponse => Self::InvalidResponse,
InternalError::Aborted => Self::Aborted,
InternalError::Parse => Self::Parse,
InternalError::Error => Self::Error,
InternalError::CmeError(e) => Self::CmeError(e),
InternalError::CmsError(e) => Self::CmsError(e),
InternalError::ConnectionError(e) => Self::ConnectionError(e),
#[cfg(feature = "custom-error-messages")]
InternalError::Custom(e) => Self::CustomMessage(
heapless::Vec::from_slice(&e[..core::cmp::min(e.len(), 64)]).unwrap_or_default(),
),
#[cfg(not(feature = "custom-error-messages"))]
InternalError::Custom(_) => Self::Custom,
}
}
}