can_iso_tp/errors.rs
1//! Transport-layer error types.
2
3/// Timeout category identifiers (ISO-TP naming).
4///
5/// These names follow the ISO-TP timeout terminology:
6/// - `N_As` / `N_Ar` are sender/receiver timeouts for CAN frame transmission/reception.
7/// - `N_Bs` / `N_Br` relate to flow control and consecutive frame reception.
8/// - `N_Cs` relates to pacing between consecutive frames.
9#[derive(Debug, Clone, Copy, PartialEq, Eq)]
10pub enum TimeoutKind {
11 /// Timeout while sending a frame.
12 NAs,
13 /// Timeout while waiting for receive queue.
14 NAr,
15 /// Timeout waiting for flow control.
16 NBs,
17 /// Timeout waiting for consecutive frame.
18 NBr,
19 /// Timeout between consecutive frame sends.
20 NCs,
21}
22
23/// Transport-layer errors surfaced by the ISO-TP implementation.
24#[derive(Debug)]
25pub enum IsoTpError<E> {
26 /// Deadline exceeded for the indicated phase.
27 Timeout(TimeoutKind),
28 /// Frame received in an unexpected state.
29 UnexpectedPdu,
30 /// Sequence number mismatch.
31 BadSequence,
32 /// Remote side indicated overflow or length invalid.
33 Overflow,
34 /// Malformed CAN frame content.
35 InvalidFrame,
36 /// Configuration rejected at construction time.
37 InvalidConfig,
38 /// Backend would block in non-blocking mode.
39 WouldBlock,
40 /// Receive buffer could not fit data.
41 RxOverflow,
42 /// Operation attempted while a transfer is active.
43 NotIdle,
44 /// Wrapper around backend-specific errors.
45 LinkError(E),
46}
47
48impl<E> From<E> for IsoTpError<E> {
49 /// Convert a backend-specific error into [`IsoTpError::LinkError`].
50 fn from(err: E) -> Self {
51 IsoTpError::LinkError(err)
52 }
53}