Skip to main content

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        /// Requested SID
25        rsid: UdsCommand,
26        /// Negative response code definition according to protocol
27        def: Option<String>,
28    },
29    /// Response empty
30    #[error("ECU did not respond to the request")]
31    EmptyResponse,
32    /// ECU Responded but send a message that wasn't a reply for the sent message
33    #[error("ECU response is wrong command. Expected: {want}, received {received}")]
34    WrongMessage {
35        /// Requested SID
36        want: UdsCommand,
37        /// Received SID from ECU
38        received: UdsCommand,
39    },
40    /// ECU Responded wrong PCI type
41    #[error("ECU response is wrong PCI type. Expected: {want:?}, received {received:?}")]
42    WrongPciType {
43        /// Requested SID
44        want: PciType,
45        /// Received SID from ECU
46        received: PciType,
47    },
48    /// Diagnostic server terminated!?
49    #[error("Diagnostic server was not running")]
50    ServerNotRunning,
51    /// ECU Responded with a message, but the length was incorrect
52    #[error("ECU response size was not the correct length")]
53    InvalidResponseLength,
54    /// A parameter given to the function is invalid. Check the function's documentation
55    /// for more information
56    #[error("Diagnostic function parameter invalid")]
57    ParameterInvalid,
58    /// Error with underlying communication channel
59    #[error("Diagnostic server hardware channel error")]
60    ChannelError,
61    /// Device hardware error
62    #[error("Diagnostic server hardware error")]
63    HardwareError,
64    /// Feauture is not iumplemented yet
65    #[error("Diagnostic server feature is unimplemented: '{0}'")]
66    NotImplemented(String),
67    /// Mismatched PID response ID
68    #[error(
69        "Requested Ident 0x{:04X?}, but received ident 0x{:04X?}",
70        want,
71        received
72    )]
73    MismatchedIdentResponse {
74        /// Requested PID
75        want: u16,
76        /// Received PID from ECU
77        received: u16,
78    },
79    /// timeout response
80    #[error("ECU server didn't response in time")]
81    Timeout,
82    /// Other Diagnostic Error
83    #[error("Diag Frame Error: {error}")]
84    FrameError { error: FrameError },
85    /// Other Diagnostic Error
86    #[error("Unkown Diagnostic Error")]
87    Others,
88}