diff --git a/Cargo.toml b/Cargo.toml index 4acea1d..5cbaa5f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,6 +14,7 @@ documentation = "https://docs.rs/esp-at-nal" [dependencies] atat = "0.17.0" embedded-nal = "0.6.0" +defmt = { version = "0.3", optional = true } nb = "1.0.0" fugit = "0.3.6" fugit-timer = "0.1.3" @@ -27,6 +28,7 @@ mockall = "0.11.2" [features] default = ["examples"] +defmt = ["dep:defmt", "atat/defmt"] # Fail on warnings strict = [] diff --git a/src/stack.rs b/src/stack.rs index a60a2bc..fb9d9ab 100644 --- a/src/stack.rs +++ b/src/stack.rs @@ -124,6 +124,30 @@ pub enum Error { TimerError, } +#[cfg(feature = "defmt")] +impl defmt::Format for Error { + fn format(&self, f: defmt::Formatter) { + match self { + Error::EnablingMultiConnectionsFailed(e) => defmt::write!(f, "Error::EnablingMultiConnectionsFailed({})", e), + Error::EnablingPassiveSocketModeFailed(e) => defmt::write!(f, "Error::EnablingPassiveSocketModeFailed({})", e), + Error::ConnectError(e) => defmt::write!(f, "Error::ConnectError({})", e), + Error::TransmissionStartFailed(e) => defmt::write!(f, "Error::TransmissionStartFailed({})", e), + Error::SendFailed(e) => defmt::write!(f, "Error::SendFailed({})", e), + Error::ReceiveFailed(e) => defmt::write!(f, "Error::ReceiveFailed({})", e), + Error::CloseError(e) => defmt::write!(f, "Error::CloseError({})", e), + Error::PartialSend => defmt::write!(f, "Error::PartialSend"), + Error::UnconfirmedSocketState => defmt::write!(f, "Error::UnconfirmedSocketState"), + Error::NoSocketAvailable => defmt::write!(f, "Error::NoSocketAvailable"), + Error::AlreadyConnected => defmt::write!(f, "Error::AlreadyConnected"), + Error::SocketUnconnected => defmt::write!(f, "Error::SocketUnconnected"), + Error::ClosingSocket => defmt::write!(f, "Error::ClosingSocket"), + Error::ReceiveOverflow => defmt::write!(f, "Error::ReceiveOverflow"), + Error::UnexpectedWouldBlock => defmt::write!(f, "Error::UnexpectedWouldBlock"), + Error::TimerError => defmt::write!(f, "Error::TimerError"), + } + } +} + impl, const TIMER_HZ: u32, const TX_SIZE: usize, const RX_SIZE: usize> TcpClientStack for Adapter {