1#[repr(u8)]
4#[derive(Debug, Default, Clone, Copy, 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), Reserved(u8),
79}
80
81impl From<u8> for Code {
82 fn from(value: u8) -> Self {
83 match value {
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(value),
154 _ => Self::Reserved(value),
155 }
156 }
157}
158
159impl Into<u8> for Code {
160 fn into(self) -> u8 {
161 match self {
162 Self::Positive => 0x00,
163
164 Self::GeneralReject => 0x10,
165 Self::ServiceNotSupported => 0x11,
166 Self::SubFunctionNotSupported => 0x12,
167 Self::IncorrectMessageLengthOrInvalidFormat => 0x13,
168 Self::ResponseTooLong => 0x14,
169
170 Self::BusyRepeatRequest => 0x21,
171 Self::ConditionsNotCorrect => 0x22,
172
173 Self::RequestSequenceError => 0x24,
174 Self::NoResponseFromSubnetComponent => 0x25,
175 Self::FailurePreventsExecutionOfRequestedAction => 0x26,
176
177 Self::RequestOutOfRange => 0x31,
178
179 Self::SecurityAccessDenied => 0x33,
180 Self::AuthenticationRequired => 0x34,
181 Self::InvalidKey => 0x35,
182 Self::ExceedNumberOfAttempts => 0x36,
183 Self::RequiredTimeDelayNotExpired => 0x37,
184 Self::SecureDataTransmissionRequired => 0x38,
185 Self::SecureDataTransmissionNotAllowed => 0x39,
186 Self::SecureDataVerificationFailed => 0x3A,
187
188 Self::CertificateVerificationFailedInvalidTimePeriod => 0x50,
189 Self::CertificateVerificationFailedInvalidSignature => 0x51,
190 Self::CertificateVerificationFailedInvalidChainOfTrust => 0x52,
191 Self::CertificateVerificationFailedInvalidType => 0x53,
192 Self::CertificateVerificationFailedInvalidFormat => 0x54,
193 Self::CertificateVerificationFailedInvalidContent => 0x55,
194 Self::CertificateVerificationFailedInvalidScope => 0x56,
195 Self::CertificateVerificationFailedInvalidCertificate => 0x57,
196 Self::OwnershipVerificationFailed => 0x58,
197 Self::ChallengeCalculationFailed => 0x59,
198 Self::SettingAccessRightsFailed => 0x5A,
199 Self::SessionKeyCreationDerivationFailed => 0x5B,
200 Self::ConfigurationDataUsageFailed => 0x5C,
201 Self::DeAuthenticationFailed => 0x5D,
202
203 Self::UploadDownloadNotAccepted => 0x70,
204 Self::TransferDataSuspended => 0x71,
205 Self::GeneralProgrammingFailure => 0x72,
206 Self::WrongBlockSequenceCounter => 0x73,
207
208 Self::RequestCorrectlyReceivedResponsePending => 0x78,
209
210 Self::SubFunctionNotSupportedInActiveSession => 0x7E,
211 Self::ServiceNotSupportedInActiveSession => 0x7F,
212
213 Self::RpmTooHigh => 0x81,
214 Self::RpmTooLow => 0x82,
215 Self::EngineIsRunning => 0x83,
216 Self::EngineIsNotRunning => 0x84,
217 Self::EngineRunTimeTooLow => 0x85,
218 Self::TemperatureTooHigh => 0x86,
219 Self::TemperatureTooLow => 0x87,
220 Self::VehicleSpeedTooHigh => 0x88,
221 Self::VehicleSpeedTooLow => 0x89,
222 Self::ThrottlePedalTooHigh => 0x8A,
223 Self::ThrottlePedalTooLow => 0x8B,
224 Self::TransmissionRangeNotInNeutral => 0x8C,
225 Self::TransmissionRangeNotInGear => 0x8D,
226 Self::BrakeSwitchNotClosed => 0x8F,
227 Self::ShifterLeverNotInPark => 0x90,
228 Self::TorqueConverterClutchLocked => 0x91,
229 Self::VoltageTooHigh => 0x92,
230 Self::VoltageTooLow => 0x93,
231 Self::ResourceTemporarilyNotAvailable => 0x94,
232 Self::VehicleManufacturerSpecific(v) => v,
233 Self::Reserved(v) => v,
234 }
235 }
236}