uds_rs/uds/
uds_definitions.rs

1//! Some custom defines for UDS functionality
2//!
3use num_enum::{IntoPrimitive, TryFromPrimitive};
4
5pub const SEND_RECEIVE_SID_OFFSET: u8 = 0x40;
6
7pub const NEGATIVE_RESPONSE_SID: u8 = 0x7F;
8
9pub fn to_received_sid(sid: u8) -> u8 {
10    sid + SEND_RECEIVE_SID_OFFSET
11}
12
13pub fn from_received_sid(sid: u8) -> u8 {
14    sid - SEND_RECEIVE_SID_OFFSET
15}
16
17/// Used for defining request Service Identifiers (SIDs)
18#[derive(IntoPrimitive, TryFromPrimitive, Debug, Clone, Copy, PartialEq, Eq)]
19#[repr(u8)]
20pub enum ServiceIdentifier {
21    DiagnosticSessionControl = 0x10,
22    EcuReset = 0x11,
23    SecurityAccess = 0x27,
24    CommunicationControl = 0x28,
25    Authentication = 0x29,
26    TesterPresent = 0x3E,
27    AccessTimingParameters = 0x83,
28    SecuredDataTransmission = 0x84,
29    ControlDtcSettings = 0x85,
30    ResponseOnEvent = 0x86,
31    LinkControl = 0x87,
32    ReadDataByIdentifier = 0x22,
33    ReadMemoryByAddress = 0x23,
34    ReadScalingDataByIdentifier = 0x24,
35    ReadDataByPeriodicIdentifier = 0x2A,
36    DynamicallyDefineDataIdentifier = 0x2C,
37    WriteDataByIdentifier = 0x2E,
38    WriteMemoryByAddress = 0x3D,
39    ClearDiagnosticInformation = 0x14,
40    ReadDtcInformation = 0x19,
41    InputOutputControlByIdentifier = 0x2F,
42    RoutineControl = 0x31,
43    RequestDownload = 0x34,
44    RequestUpload = 0x35,
45    TransferData = 0x36,
46    RequestTransferExit = 0x37,
47    RequestFileTransfer = 0x38,
48
49    NegativeResponse = 0x7F,
50}
51
52/// So called NRC - when server (ECU) sends negative response (SID 0x7F) it is followed by NRC byte, representing the error.
53#[derive(IntoPrimitive, TryFromPrimitive, Debug, PartialEq)]
54#[repr(u8)]
55pub enum NegativeResponseCode {
56    PositiveResponse = 0x00,
57    GeneralReject = 0x10,
58    ServiceNotSupported = 0x11,
59    SubFunctionNotSupported = 0x12,
60    IncorrectMessageLengthOrInvalidFormat = 0x13,
61    ResponseTooLong = 0x14,
62    BusyRepeatRequest = 0x21,
63    ConditionsNotCorrect = 0x22,
64    RequestSequenceError = 0x24,
65    NoResponseFromSubnetComponent = 0x25,
66    FailurePreventsExecutionOfRequestedAction = 0x26,
67    RequestOutOfRange = 0x31,
68    SecurityAccessDenied = 0x33,
69    InvalidKey = 0x35,
70    ExceededNumberOfAttempts = 0x36,
71    RequiredTimeDelayNotExpired = 0x37,
72    UploadDownloadNotAccepted = 0x70,
73    TransferDataSuspended = 0x71,
74    GeneralProgrammingFailure = 0x72,
75    WrongBlockSequenceCounter = 0x73,
76    RequestCorrectlyReceivedResponsePending = 0x78,
77    SubfunctionNotSupportedInActiveSession = 0x7E,
78    ServiceNotSupportedInActiveSession = 0x7F,
79    RpmTooHigh = 0x81,
80    RpmTooLow = 0x82,
81    EngineIsRunning = 0x83,
82    EngineIsNotRunning = 0x84,
83    EngineRunTimeTooLow = 0x85,
84    TemperatureTooHigh = 0x86,
85    TemperatureTooLow = 0x87,
86    VehicleSpeedTooHigh = 0x88,
87    VehicleSpeedTooLow = 0x89,
88    ThrottlePedalTooHigh = 0x8A,
89    ThrottlePedalTooLow = 0x8B,
90    TransmissionRangeNotInNeutral = 0x8C,
91    TransmissionRangeNotInGear = 0x8D,
92    BrakeSwitchNotClosed = 0x8F,
93    ShiftLeverNotInPark = 0x90,
94    TorqueConverterClutchLocked = 0x91,
95    VoltageTooHigh = 0x92,
96    VoltageTooLow = 0x93,
97}