uds_client/uds_client/
mod.rs

1mod client;
2mod frame;
3mod pci;
4mod response;
5mod services;
6
7use automotive_diag::uds::{UdsCommand, UdsError};
8pub use client::UdsClient;
9pub use frame::*;
10pub use pci::{PciByte, PciType};
11pub use response::{Response, ResponseSlot};
12pub use services::RealTimeType;
13
14#[derive(Clone, Debug, thiserror::Error)]
15/// Diagnostic server error
16pub enum DiagError {
17    #[error("Diagnostic server does not support the request")]
18    NotSupported,
19    /// Negative Response from ECU
20    #[error("ECU error: 0x{:02X} ({:?})", *code as u8, def)]
21    ECUError {
22        /// Raw Negative response code from ECU
23        code: UdsError,
24        /// Negative response code definition according to protocol
25        def: Option<String>,
26    },
27    /// Response empty
28    #[error("ECU did not respond to the request")]
29    EmptyResponse,
30    /// ECU Responded but send a message that wasn't a reply for the sent message
31    #[error("ECU response is wrong command. Expected: {want}, received {received}")]
32    WrongMessage {
33        /// Requested SID
34        want: UdsCommand,
35        /// Received SID from ECU
36        received: UdsCommand,
37    },
38    /// ECU Responded wrong PCI type
39    #[error("ECU response is wrong PCI type. Expected: {want:?}, received {received:?}")]
40    WrongPciType {
41        /// Requested SID
42        want: PciType,
43        /// Received SID from ECU
44        received: PciType,
45    },
46    /// Diagnostic server terminated!?
47    #[error("Diagnostic server was not running")]
48    ServerNotRunning,
49    /// ECU Responded with a message, but the length was incorrect
50    #[error("ECU response size was not the correct length")]
51    InvalidResponseLength,
52    /// A parameter given to the function is invalid. Check the function's documentation
53    /// for more information
54    #[error("Diagnostic function parameter invalid")]
55    ParameterInvalid,
56    /// Error with underlying communication channel
57    #[error("Diagnostic server hardware channel error")]
58    ChannelError,
59    /// Device hardware error
60    #[error("Diagnostic server hardware error")]
61    HardwareError,
62    /// Feauture is not iumplemented yet
63    #[error("Diagnostic server feature is unimplemented: '{0}'")]
64    NotImplemented(String),
65    /// Mismatched PID response ID
66    #[error(
67        "Requested Ident 0x{:04X?}, but received ident 0x{:04X?}",
68        want,
69        received
70    )]
71    MismatchedIdentResponse {
72        /// Requested PID
73        want: u16,
74        /// Received PID from ECU
75        received: u16,
76    },
77    /// timeout response
78    #[error("ECU server didn't response in time")]
79    Timeout,
80    /// Other Diagnostic Error
81    #[error("Diag Frame Error: {error}")]
82    FrameError { error: FrameError },
83    /// Other Diagnostic Error
84    #[error("Unkown Diagnostic Error")]
85    Others,
86}