Skip to main content

iso14229_1/response/
code.rs

1//! response code enum
2
3#[repr(u8)]
4#[derive(Debug, Copy, Clone, Default, Eq, PartialEq, Hash)]
5pub enum Code {
6    #[default]
7    Positive = 0x00,
8
9    GeneralReject = 0x10,
10    ServiceNotSupported = 0x11,
11    SubFunctionNotSupported = 0x12,
12    IncorrectMessageLengthOrInvalidFormat = 0x13,
13    ResponseTooLong = 0x14,
14
15    BusyRepeatRequest = 0x21,
16    ConditionsNotCorrect = 0x22,
17
18    RequestSequenceError = 0x24,
19    NoResponseFromSubnetComponent = 0x25,
20    FailurePreventsExecutionOfRequestedAction = 0x26,
21
22    RequestOutOfRange = 0x31,
23
24    SecurityAccessDenied = 0x33,
25    AuthenticationRequired = 0x34,
26    InvalidKey = 0x35,
27    ExceedNumberOfAttempts = 0x36,
28    RequiredTimeDelayNotExpired = 0x37,
29    SecureDataTransmissionRequired = 0x38,
30    SecureDataTransmissionNotAllowed = 0x39,
31    SecureDataVerificationFailed = 0x3A,
32
33    CertificateVerificationFailedInvalidTimePeriod = 0x50,
34    CertificateVerificationFailedInvalidSignature = 0x51,
35    CertificateVerificationFailedInvalidChainOfTrust = 0x52,
36    CertificateVerificationFailedInvalidType = 0x53,
37    CertificateVerificationFailedInvalidFormat = 0x54,
38    CertificateVerificationFailedInvalidContent = 0x55,
39    CertificateVerificationFailedInvalidScope = 0x56,
40    CertificateVerificationFailedInvalidCertificate = 0x57,
41    OwnershipVerificationFailed = 0x58,
42    ChallengeCalculationFailed = 0x59,
43    SettingAccessRightsFailed = 0x5A,
44    SessionKeyCreationDerivationFailed = 0x5B,
45    ConfigurationDataUsageFailed = 0x5C,
46    DeAuthenticationFailed = 0x5D,
47
48    UploadDownloadNotAccepted = 0x70,
49    TransferDataSuspended = 0x71,
50    GeneralProgrammingFailure = 0x72,
51    WrongBlockSequenceCounter = 0x73,
52
53    RequestCorrectlyReceivedResponsePending = 0x78,
54
55    SubFunctionNotSupportedInActiveSession = 0x7E,
56    ServiceNotSupportedInActiveSession = 0x7F,
57
58    RpmTooHigh = 0x81,
59    RpmTooLow = 0x82,
60    EngineIsRunning = 0x83,
61    EngineIsNotRunning = 0x84,
62    EngineRunTimeTooLow = 0x85,
63    TemperatureTooHigh = 0x86,
64    TemperatureTooLow = 0x87,
65    VehicleSpeedTooHigh = 0x88,
66    VehicleSpeedTooLow = 0x89,
67    ThrottlePedalTooHigh = 0x8A,
68    ThrottlePedalTooLow = 0x8B,
69    TransmissionRangeNotInNeutral = 0x8C,
70    TransmissionRangeNotInGear = 0x8D,
71    BrakeSwitchNotClosed = 0x8F,
72    ShifterLeverNotInPark = 0x90,
73    TorqueConverterClutchLocked = 0x91,
74    VoltageTooHigh = 0x92,
75    VoltageTooLow = 0x93,
76    ResourceTemporarilyNotAvailable = 0x94,
77    VehicleManufacturerSpecific(u8), // 0xF0~0xFE
78    Reserved(u8),
79}
80
81impl From<u8> for Code {
82    fn from(v: u8) -> Self {
83        match v {
84            0x00 => Self::Positive,
85
86            0x10 => Self::GeneralReject,
87            0x11 => Self::ServiceNotSupported,
88            0x12 => Self::SubFunctionNotSupported,
89            0x13 => Self::IncorrectMessageLengthOrInvalidFormat,
90            0x14 => Self::ResponseTooLong,
91
92            0x21 => Self::BusyRepeatRequest,
93
94            0x22 => Self::ConditionsNotCorrect,
95            0x24 => Self::RequestSequenceError,
96            0x25 => Self::NoResponseFromSubnetComponent,
97            0x26 => Self::FailurePreventsExecutionOfRequestedAction,
98
99            0x31 => Self::RequestOutOfRange,
100            0x33 => Self::SecurityAccessDenied,
101            0x34 => Self::AuthenticationRequired,
102            0x35 => Self::InvalidKey,
103            0x36 => Self::ExceedNumberOfAttempts,
104            0x37 => Self::RequiredTimeDelayNotExpired,
105            0x38 => Self::SecureDataTransmissionRequired,
106            0x39 => Self::SecureDataTransmissionNotAllowed,
107            0x3A => Self::SecureDataVerificationFailed,
108
109            0x50 => Self::CertificateVerificationFailedInvalidTimePeriod,
110            0x51 => Self::CertificateVerificationFailedInvalidSignature,
111            0x52 => Self::CertificateVerificationFailedInvalidChainOfTrust,
112            0x53 => Self::CertificateVerificationFailedInvalidType,
113            0x54 => Self::CertificateVerificationFailedInvalidFormat,
114            0x55 => Self::CertificateVerificationFailedInvalidContent,
115            0x56 => Self::CertificateVerificationFailedInvalidScope,
116            0x57 => Self::CertificateVerificationFailedInvalidCertificate,
117            0x58 => Self::OwnershipVerificationFailed,
118            0x59 => Self::ChallengeCalculationFailed,
119            0x5A => Self::SettingAccessRightsFailed,
120            0x5B => Self::SessionKeyCreationDerivationFailed,
121            0x5C => Self::ConfigurationDataUsageFailed,
122            0x5D => Self::DeAuthenticationFailed,
123
124            0x70 => Self::UploadDownloadNotAccepted,
125            0x71 => Self::TransferDataSuspended,
126            0x72 => Self::GeneralProgrammingFailure,
127            0x73 => Self::WrongBlockSequenceCounter,
128
129            0x78 => Self::RequestCorrectlyReceivedResponsePending,
130
131            0x7E => Self::SubFunctionNotSupportedInActiveSession,
132            0x7F => Self::ServiceNotSupportedInActiveSession,
133
134            0x81 => Self::RpmTooHigh,
135            0x82 => Self::RpmTooLow,
136            0x83 => Self::EngineIsRunning,
137            0x84 => Self::EngineIsNotRunning,
138            0x85 => Self::EngineRunTimeTooLow,
139            0x86 => Self::TemperatureTooHigh,
140            0x87 => Self::TemperatureTooLow,
141            0x88 => Self::VehicleSpeedTooHigh,
142            0x89 => Self::VehicleSpeedTooLow,
143            0x8A => Self::ThrottlePedalTooHigh,
144            0x8B => Self::ThrottlePedalTooLow,
145            0x8C => Self::TransmissionRangeNotInNeutral,
146            0x8D => Self::TransmissionRangeNotInGear,
147            0x8F => Self::BrakeSwitchNotClosed,
148            0x90 => Self::ShifterLeverNotInPark,
149            0x91 => Self::TorqueConverterClutchLocked,
150            0x92 => Self::VoltageTooHigh,
151            0x93 => Self::VoltageTooLow,
152            0x94 => Self::ResourceTemporarilyNotAvailable,
153            0xF0..=0xFE => Self::VehicleManufacturerSpecific(v),
154            _ => Self::Reserved(v),
155        }
156    }
157}
158
159impl From<Code> for u8 {
160    fn from(val: Code) -> Self {
161        match val {
162            Code::Positive => 0x00,
163
164            Code::GeneralReject => 0x10,
165            Code::ServiceNotSupported => 0x11,
166            Code::SubFunctionNotSupported => 0x12,
167            Code::IncorrectMessageLengthOrInvalidFormat => 0x13,
168            Code::ResponseTooLong => 0x14,
169
170            Code::BusyRepeatRequest => 0x21,
171            Code::ConditionsNotCorrect => 0x22,
172
173            Code::RequestSequenceError => 0x24,
174            Code::NoResponseFromSubnetComponent => 0x25,
175            Code::FailurePreventsExecutionOfRequestedAction => 0x26,
176
177            Code::RequestOutOfRange => 0x31,
178
179            Code::SecurityAccessDenied => 0x33,
180            Code::AuthenticationRequired => 0x34,
181            Code::InvalidKey => 0x35,
182            Code::ExceedNumberOfAttempts => 0x36,
183            Code::RequiredTimeDelayNotExpired => 0x37,
184            Code::SecureDataTransmissionRequired => 0x38,
185            Code::SecureDataTransmissionNotAllowed => 0x39,
186            Code::SecureDataVerificationFailed => 0x3A,
187
188            Code::CertificateVerificationFailedInvalidTimePeriod => 0x50,
189            Code::CertificateVerificationFailedInvalidSignature => 0x51,
190            Code::CertificateVerificationFailedInvalidChainOfTrust => 0x52,
191            Code::CertificateVerificationFailedInvalidType => 0x53,
192            Code::CertificateVerificationFailedInvalidFormat => 0x54,
193            Code::CertificateVerificationFailedInvalidContent => 0x55,
194            Code::CertificateVerificationFailedInvalidScope => 0x56,
195            Code::CertificateVerificationFailedInvalidCertificate => 0x57,
196            Code::OwnershipVerificationFailed => 0x58,
197            Code::ChallengeCalculationFailed => 0x59,
198            Code::SettingAccessRightsFailed => 0x5A,
199            Code::SessionKeyCreationDerivationFailed => 0x5B,
200            Code::ConfigurationDataUsageFailed => 0x5C,
201            Code::DeAuthenticationFailed => 0x5D,
202
203            Code::UploadDownloadNotAccepted => 0x70,
204            Code::TransferDataSuspended => 0x71,
205            Code::GeneralProgrammingFailure => 0x72,
206            Code::WrongBlockSequenceCounter => 0x73,
207
208            Code::RequestCorrectlyReceivedResponsePending => 0x78,
209
210            Code::SubFunctionNotSupportedInActiveSession => 0x7E,
211            Code::ServiceNotSupportedInActiveSession => 0x7F,
212
213            Code::RpmTooHigh => 0x81,
214            Code::RpmTooLow => 0x82,
215            Code::EngineIsRunning => 0x83,
216            Code::EngineIsNotRunning => 0x84,
217            Code::EngineRunTimeTooLow => 0x85,
218            Code::TemperatureTooHigh => 0x86,
219            Code::TemperatureTooLow => 0x87,
220            Code::VehicleSpeedTooHigh => 0x88,
221            Code::VehicleSpeedTooLow => 0x89,
222            Code::ThrottlePedalTooHigh => 0x8A,
223            Code::ThrottlePedalTooLow => 0x8B,
224            Code::TransmissionRangeNotInNeutral => 0x8C,
225            Code::TransmissionRangeNotInGear => 0x8D,
226            Code::BrakeSwitchNotClosed => 0x8F,
227            Code::ShifterLeverNotInPark => 0x90,
228            Code::TorqueConverterClutchLocked => 0x91,
229            Code::VoltageTooHigh => 0x92,
230            Code::VoltageTooLow => 0x93,
231            Code::ResourceTemporarilyNotAvailable => 0x94,
232            Code::VehicleManufacturerSpecific(v) => v,
233            Code::Reserved(v) => v,
234        }
235    }
236}