Skip to main content

ace_can/
error.rs

1// region: CanError
2
3#[derive(Debug)]
4pub enum CanError {
5    /// The CAN ID value exceeds the valid range for its type.
6    /// Standard: 0x000–0x7FF, Extended: 0x00000000–0x1FFFFFFF.
7    InvalidId,
8    /// The data length code exceeds the physical maximum for the frame type.
9    /// Classic CAN: 0–8, CAN FD: valid DLC values mapping to 0–64.
10    InvalidDlc(u8),
11    /// The frame buffer is too short to contain the declared DLC worth of data.
12    BufferTooShort { expected: usize, actual: usize },
13    /// A flag combination in the frame is illegal per the CAN/CAN FD spec.
14    /// e.g. RTR set on a CAN FD frame, BRS set without EDL.
15    InvalidFlags,
16    /// Underlying transport error from ace-core.
17    Transport(ace_core::DiagError),
18}
19
20impl From<ace_core::DiagError> for CanError {
21    fn from(e: ace_core::DiagError) -> Self {
22        CanError::Transport(e)
23    }
24}
25
26// endregion: CanError
27
28// region: IsoTpError
29
30#[derive(Debug)]
31pub enum IsoTpError {
32    /// A consecutive frame arrived with an unexpected sequence number.
33    /// Indicates a lost or reordered frame.
34    SequenceError { expected: u8, actual: u8 },
35    /// A consecutive frame arrived before a first frame was received.
36    /// The reassembler was not in an active session.
37    UnexpectedConsecutiveFrame,
38    /// A flow control frame arrived with an unknown flow status nibble.
39    UnknownFlowStatus(u8),
40    /// The declared message length in the first frame is zero.
41    InvalidLength,
42    /// The payload provided to the segmenter exceeds what ISO-TP can
43    /// express in a first frame length field (classic CAN: 4095 bytes,
44    /// CAN FD: 4294967295 bytes via escape sequence).
45    PayloadTooLarge,
46    /// A single frame was received with a length of zero.
47    EmptySingleFrame,
48    /// The frame buffer does not contain enough bytes for the PCI
49    /// given the current addressing mode.
50    FrameTooShort { actual: usize },
51    /// The reassembler received a new first frame while already mid-session.
52    /// The previous session is abandoned.
53    SessionAborted,
54    /// Underlying CAN frame error.
55    Can(CanError),
56    /// The PCI bytes upper nibble does not match any known ISO-TP frame type.
57    UnknownFrameType(u8),
58}
59
60impl From<CanError> for IsoTpError {
61    fn from(e: CanError) -> Self {
62        IsoTpError::Can(e)
63    }
64}
65
66impl From<ace_core::DiagError> for IsoTpError {
67    fn from(e: ace_core::DiagError) -> Self {
68        IsoTpError::Can(CanError::Transport(e))
69    }
70}
71
72// endregion: IsoTpError