Skip to main content

ace_client/
event.rs

1// region: Imports
2
3use heapless::Vec;
4
5// endregion: Imports
6
7// region: Client Event
8
9/// An observable event emitted by the UDS client.
10///
11/// Events accumulate in the client's event queue across ticks and are drained by the caller via
12/// `drain_events()`. Each event corresponds to a completed or failed request exchange.
13///
14/// The caller decides what to do with each event - the client never retries, escalates, or takes
15/// corrective action autonomously.
16
17#[derive(Debug, Clone, PartialEq, Eq)]
18pub enum ClientEvent<const MAX_DATA: usize> {
19    /// A positive response was received for the given service.
20    ///
21    /// `sid` is the request SID (not the response SID).
22    /// `data` contains the response payload bytes after the response SID.
23    PositiveResponse { sid: u8, data: Vec<u8, MAX_DATA> },
24
25    /// A negative response was received.
26    ///
27    /// `sid` is the request SID.
28    /// `nrc` is the Negative Response Code byte.
29    NegativeResponse { sid: u8, nrc: u8 },
30
31    /// A `0x78` Response Pending NRC was received.
32    ///
33    /// The client has switched to the P2* extended timeout and is still waiting for the final
34    /// response. This event is emitted once per `0x78` received - the caller can observe how many
35    /// were received before the final response.
36    ResponsePending { sid: u8 },
37
38    /// No response was received within the P2 or P2* timeout.
39    ///
40    /// The pending request has been discarded. The caller must decide whether to retry.
41    Timeout { sid: u8 },
42
43    /// A periodic data response arrived from the server.
44    ///
45    /// `[periodic_data_identifier (1 byte), data_record (n bytes)]`
46    ///
47    /// No SID prefix is present - `did` is the first byte of the frame, which is the low byte of
48    /// the periodic DID identifier. `data` contains the data record bytes that followed.
49    ///
50    /// Only emitted for DID low bytes registered via `subscribe_periodic`
51    PeriodicData {
52        /// Low byte of the periodic DID identifier.
53        did: u8,
54
55        /// Data record bytes
56        data: Vec<u8, MAX_DATA>,
57    },
58
59    /// A response arrived with no matching pending request.
60    ///
61    /// This can occur under fault injection (reordered or delayed responses arriving after a
62    /// timeout) or if the server sends an unsolicited response.
63    Unsolicited { data: Vec<u8, MAX_DATA> },
64}
65
66// endregion: Client Event