Skip to content

Commit

Permalink
feat(v0.0.21): returns number of bytes received on partial response
Browse files Browse the repository at this point in the history
  • Loading branch information
zpg6 committed Nov 17, 2024
1 parent ce6081b commit 75f2a0f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
24 changes: 21 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,33 @@ use config::*;

#[derive(Debug)]
pub enum Mcp2003aError<E> {
/// Some serial error occurred.
UartError(embedded_hal_nb::nb::Error<E>),

/// 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
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 75f2a0f

Please sign in to comment.