From 75f2a0fd1714d4d7829abc93dc268be5895eb89e Mon Sep 17 00:00:00 2001 From: Zach Grimaldi Date: Sun, 17 Nov 2024 14:00:24 -0500 Subject: [PATCH] feat(v0.0.21): returns number of bytes received on partial response --- Cargo.toml | 2 +- src/lib.rs | 24 +++++++++++++++++++++--- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 98dec91..b998ce7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mcp2003a" -version = "0.0.20" +version = "0.0.21" description = "MCP2003A LIN transceiver driver with embedded-hal traits for no-std environments." edition = "2021" license = "MIT" diff --git a/src/lib.rs b/src/lib.rs index 1bb3f97..d71ca5d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -90,15 +90,33 @@ use config::*; #[derive(Debug)] pub enum Mcp2003aError { + /// Some serial error occurred. UartError(embedded_hal_nb::nb::Error), + + /// The UART write was not ready to send the next byte. UartWriteNotReady, + + /// Sync byte was not read back, likely indicating the bus is not active. SyncByteNotReceivedBack, + + /// Sync byte was read back, but the ID byte was not received. IdByteNotReceivedBack, + + /// Sync and ID bytes were read back (indicating the bus is active), but no data was received. LinDeviceTimeoutNoResponse, - LinDeviceTimeoutPartialResponse, + + /// Partial response with the number of bytes received. + LinDeviceTimeoutPartialResponse(usize), + + /// Data bytes were received, but the checksum was not received after the data. LinReadNoChecksumReceived, - LinReadInvalidChecksum, + + /// After the data bytes and checksum were received, there were still more delivered. LinReadExceedsBuffer, + + /// Not used by the library, but implementers can use this to indicate the checksum was invalid. + /// (Useful to maintain the same error type for that last step) + LinReadInvalidChecksum, } /// MCP2003A LIN Transceiver @@ -326,7 +344,7 @@ where return Err(Mcp2003aError::LinDeviceTimeoutNoResponse); } if data_bytes_received < buffer.len() { - return Err(Mcp2003aError::LinDeviceTimeoutPartialResponse); + return Err(Mcp2003aError::LinDeviceTimeoutPartialResponse(data_bytes_received)); } if !checksum_received { return Err(Mcp2003aError::LinReadNoChecksumReceived);