1#[cfg(feature = "strum")]
2macro_rules! impl_as_str {
3 ($enum:ty) => {
4 impl $enum {
5 pub fn as_str(&self) -> &str {
7 self.as_ref()
8 }
9 }
10 };
11}
12
13#[repr(u32)]
14#[cfg_attr(feature = "num_enum", derive(num_enum::TryFromPrimitive))]
15#[cfg_attr(feature = "num_enum", derive(strum::AsRefStr))]
16#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
17pub enum PduIt {
19 IoUnum32 = 0x1000,
21 IoProgVoltage = 0x1001,
23 IoByteArray = 0x1002,
25 IoFilter = 0x1003,
27 IoEventQueueProperty = 0x1004,
29 RscStatus = 0x1100,
31 Param = 0x1200,
33 Result = 0x1300,
35 Status = 0x1301,
37 Error = 0x1302,
39 Info = 0x1303,
41 RscId = 0x1400,
43 RscConflict = 0x1500,
45 ModuleId = 0x1600,
47 UniqueRespIdTable = 0x1700,
49 IoVehicleIdRequest = 0x1800,
51 EthSwitchState = 0x1801,
53 EntityAddress = 0x1802,
55 EntityStatus = 0x1803,
57}
58
59#[cfg(feature = "strum")]
60#[cfg(feature = "strum")]
61impl_as_str!(PduIt);
62
63#[repr(u32)]
64#[cfg_attr(feature = "num_enum", derive(num_enum::TryFromPrimitive))]
65#[cfg_attr(feature = "num_enum", derive(strum::AsRefStr))]
66#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
67pub enum PduCopt {
69 StartComm = 0x8001,
71 StopComm = 0x8002,
73 UpdateParam = 0x8003,
75 SendRecv = 0x8004,
77 Delay = 0x8005,
79 RestoreParam = 0x8006,
82}
83
84#[cfg(feature = "strum")]
85#[cfg(feature = "strum")]
86impl_as_str!(PduCopt);
87
88#[repr(u32)]
89#[cfg_attr(feature = "num_enum", derive(num_enum::TryFromPrimitive))]
90#[cfg_attr(feature = "num_enum", derive(strum::AsRefStr))]
91#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
92pub enum PduObjt {
94 Protocol = 0x8021,
96 BusType = 0x8022,
98 IoCtrl = 0x8023,
100 ComParam = 0x8024,
102 PinType = 0x8025,
104 Resource = 0x8026,
106}
107
108#[cfg(feature = "strum")]
109#[cfg(feature = "strum")]
110impl_as_str!(PduObjt);
111
112#[repr(u32)]
113#[cfg_attr(feature = "num_enum", derive(num_enum::TryFromPrimitive))]
114#[cfg_attr(feature = "num_enum", derive(strum::AsRefStr))]
115#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
116pub enum PduStatus {
118 CopstIdle = 0x8010,
120 CopstExecuting = 0x8011,
122 CopstFinished = 0x8012,
124 CopstCancelled = 0x8013,
126 CopstWaiting = 0x8014,
128 CllstOffline = 0x8050,
130 CllstOnline = 0x8051,
132 CllstCommStarted = 0x8052,
134 ModstReady = 0x8060,
136 ModstNotReady = 0x8061,
138 ModstNotAvail = 0x8062,
140 ModstAvail = 0x8063,
142}
143
144#[cfg(feature = "strum")]
145#[cfg(feature = "strum")]
146impl_as_str!(PduStatus);
147
148#[repr(u32)]
149#[cfg_attr(feature = "num_enum", derive(num_enum::TryFromPrimitive))]
150#[cfg_attr(feature = "num_enum", derive(strum::AsRefStr))]
151#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
152pub enum PduInfo {
154 ModuleListChange = 0x8070,
156 ResourceLockChange = 0x8071,
158 ComParamChange = 0x8072,
160}
161
162#[cfg(feature = "strum")]
163#[cfg(feature = "strum")]
164impl_as_str!(PduInfo);
165
166#[repr(u32)]
167#[cfg_attr(feature = "num_enum", derive(num_enum::TryFromPrimitive))]
168#[cfg_attr(feature = "num_enum", derive(strum::AsRefStr))]
169#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
170pub enum PduEvtData {
172 Available = 0x801,
174 Lost = 0x0802,
176}
177
178#[cfg(feature = "strum")]
179#[cfg(feature = "strum")]
180impl_as_str!(PduEvtData);
181
182#[repr(u32)]
183#[cfg_attr(feature = "num_enum", derive(num_enum::TryFromPrimitive))]
184#[cfg_attr(feature = "num_enum", derive(strum::AsRefStr))]
185#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
186pub enum PduFilter {
188 Pass = 0x00000001,
190 Block = 0x00000002,
192 PassUudt = 0x00000011,
194 BlockUudt = 0x00000012,
196}
197
198#[cfg(feature = "strum")]
199#[cfg(feature = "strum")]
200impl_as_str!(PduFilter);
201
202#[repr(u32)]
203#[cfg_attr(feature = "num_enum", derive(num_enum::TryFromPrimitive))]
204#[cfg_attr(feature = "num_enum", derive(strum::AsRefStr))]
205#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
206pub enum PduQueueMode {
208 Unlimited = 0x00000000,
211 Limited = 0x00000001,
214 Circular = 0x00000002,
217}
218
219#[cfg(feature = "strum")]
220impl_as_str!(PduQueueMode);
221
222#[repr(u32)]
223#[cfg_attr(feature = "num_enum", derive(num_enum::TryFromPrimitive))]
224#[cfg_attr(feature = "num_enum", derive(strum::AsRefStr))]
225#[cfg_attr(feature = "thiserror", derive(thiserror::Error))]
226#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
227pub enum PduError {
229 #[cfg_attr(feature = "thiserror", error("No error (function call OK)"))]
231 StatusNoError = 0x00000000,
232
233 #[cfg_attr(feature = "thiserror", error("Function call failed (Generic failure)"))]
235 FctFailed = 0x00000001,
236
237 #[cfg_attr(feature = "thiserror", error("Reserved for ISO 22900-2"))]
239 Reserved1 = 0x00000010,
240
241 #[cfg_attr(
243 feature = "thiserror",
244 error("Communication failed between host and MVCI")
245 )]
246 CommPcToVciFailed = 0x00000011,
247
248 #[cfg_attr(feature = "thiserror", error("PDU API has not yet been constructed"))]
250 PduApiNotConstructed = 0x00000020,
251
252 #[cfg_attr(
254 feature = "thiserror",
255 error("PDU Destruct was not called before another PDU Construct")
256 )]
257 SharingViolation = 0x00000021,
258
259 #[cfg_attr(feature = "thiserror", error("Resource is already in use"))]
261 ResourceBusy = 0x00000030,
262
263 #[cfg_attr(feature = "thiserror", error("Resource table changed"))]
265 ResourceTableChanged = 0x00000031,
266
267 #[cfg_attr(feature = "thiserror", error("Generic resource error"))]
269 ResourceError = 0x00000032,
270
271 #[cfg_attr(
273 feature = "thiserror",
274 error("ComLogicalLink cannot be offline and perform the requested action")
275 )]
276 CllNotConnected = 0x00000040,
277
278 #[cfg_attr(
280 feature = "thiserror",
281 error("ComLogicalLink must be started to perform the requested action")
282 )]
283 CllNotStarted = 0x00000041,
284
285 #[cfg_attr(
287 feature = "thiserror",
288 error("A parameter parsed into the function was invalid")
289 )]
290 InvalidParameters = 0x00000050,
291
292 #[cfg_attr(feature = "thiserror", error("A handle provided was invalid"))]
294 InvalidHandle = 0x00000060,
295
296 #[cfg_attr(feature = "thiserror", error("Option value was unsupported"))]
298 ValueNotSupported = 0x00000061,
299
300 #[cfg_attr(feature = "thiserror", error("IOCTL Command ID was unsupported"))]
302 IdNotSupported = 0x00000062,
303
304 #[cfg_attr(
306 feature = "thiserror",
307 error("Communication parameter was unsupported")
308 )]
309 ComParamNotSupported = 0x00000063,
310
311 #[cfg_attr(
313 feature = "thiserror",
314 error(
315 "Physical communication parameter cannot be changed as it is locked by another LogicalLink"
316 )
317 )]
318 ComParamLocked = 0x00000064,
319
320 #[cfg_attr(feature = "thiserror", error("Transmit queue is full"))]
322 TxQueueFull = 0x00000070,
323
324 #[cfg_attr(feature = "thiserror", error("No more events are available to read"))]
326 EventQueueEmpty = 0x00000071,
327
328 #[cfg_attr(
330 feature = "thiserror",
331 error("IOCTL - Voltage value supplied is unsupported by the MVCI module")
332 )]
333 VoltageNotSupported = 0x00000080,
334
335 #[cfg_attr(
337 feature = "thiserror",
338 error("IOCTL - Pin or resource is not supported by the MVCI module")
339 )]
340 MuxRscNotSupported = 0x00000081,
341
342 #[cfg_attr(
344 feature = "thiserror",
345 error("Cable attached to MVCI module is unknown")
346 )]
347 CableUnknown = 0x00000082,
348
349 #[cfg_attr(feature = "thiserror", error("No cable attached to the MVCI module"))]
351 NoCableDetected = 0x00000083,
352
353 #[cfg_attr(feature = "thiserror", error("ComLogicalLink is already connected"))]
355 CllConnected = 0x00000084,
356
357 #[cfg_attr(
359 feature = "thiserror",
360 error("Physical Com parameters cannot be changes as a temporary one")
361 )]
362 TempParamNotAllowed = 0x00000090,
363
364 #[cfg_attr(feature = "thiserror", error("Resource is already locked"))]
366 RscLocked = 0x000000A0,
367
368 #[cfg_attr(
370 feature = "thiserror",
371 error("Resource is already locked by another ComLogicalLink")
372 )]
373 RscLockedByAnotherCll = 0x000000A1,
374
375 #[cfg_attr(feature = "thiserror", error("Resource is already unlocked"))]
377 RscNotLocked = 0x000000A2,
378
379 #[cfg_attr(feature = "thiserror", error("Module is not connected or ready"))]
381 ModuleNotConnected = 0x000000A3,
382
383 #[cfg_attr(feature = "thiserror", error("API software is out of date"))]
385 ApiSwOutOfDate = 0x000000A4,
386
387 #[cfg_attr(feature = "thiserror", error("VCI firmware is out of date"))]
389 ModuleFwOutOfDate = 0x000000A5,
390
391 #[cfg_attr(
393 feature = "thiserror",
394 error("Requested pin is not routed by the MVCI's cable")
395 )]
396 PinNotConnected = 0x000000A6,
397
398 #[cfg_attr(feature = "thiserror", error("IP protocol not supported"))]
400 IpProtocolNotSupported = 0x000000B0,
401
402 #[cfg_attr(
404 feature = "thiserror",
405 error("DoIP Routing activation failed (Generic failure)")
406 )]
407 DoIpRoutingActivationFailed = 0x000000B1,
408
409 #[cfg_attr(
411 feature = "thiserror",
412 error("DoIP Routing activation failed - missing / wrong authentication")
413 )]
414 DoIpRoutingActivationAuthFailed = 0x000000B2,
415
416 #[cfg_attr(
418 feature = "thiserror",
419 error("DoIP Logical address is defined multiple times so it is ambiguous")
420 )]
421 DoIpAmbiguousLogicalAddress = 0x000000B3,
422
423 #[cfg_attr(
425 feature = "thiserror",
426 error("DoIP Routing activation failed - Unknown or invalid source address")
427 )]
428 DoIpRoutineActivationInvalidSrcAddress = 0x000000B4,
429
430 #[cfg_attr(
432 feature = "thiserror",
433 error("DoIP Routing activation failed - No more free sockets available")
434 )]
435 DoIpRoutingActivationNoDataSocketAvailable = 0x000000B5,
436
437 #[cfg_attr(
439 feature = "thiserror",
440 error("DoIP Routing activation failed - The source address changed")
441 )]
442 DoIpRoutineActivationSourceAddressChanged = 0x000000B6,
443
444 #[cfg_attr(
446 feature = "thiserror",
447 error("DoIP Routing activation failed - Source address already in use")
448 )]
449 DoIpRoutingActivationSourceAddressInUse = 0x000000B7,
450
451 #[cfg_attr(
453 feature = "thiserror",
454 error("DoIP Routing activation failed - Rejected confirmation")
455 )]
456 DoIpRoutineActivationConfirmationRejected = 0x000000B8,
457
458 #[cfg_attr(
460 feature = "thiserror",
461 error("DoIP Routing activation failed - Requested activation type was unsupported")
462 )]
463 DoIpRoutineActivationTypeUnsupported = 0x000000B9,
464
465 #[cfg_attr(
467 feature = "thiserror",
468 error("DoIP Routing activation failed - Response code was unknown")
469 )]
470 DoIpRoutineActivationResponseCodeUnknown = 0x000000BA,
471
472 #[cfg_attr(
474 feature = "thiserror",
475 error("DoIP Routing activation failed - Timeout waiting for activation response")
476 )]
477 DoIpRoutingActivationResponseTimeout = 0x000000BB,
478
479 #[cfg_attr(feature = "thiserror", error("DoIP general timeout"))]
481 DoIpResponseTimeout = 0x000000BC,
482}
483
484#[cfg(feature = "strum")]
485impl_as_str!(PduError);
486
487impl PduError {
488 pub fn is_success(&self) -> bool {
490 matches!(self, PduError::StatusNoError)
491 }
492}
493
494#[repr(u32)]
495#[cfg_attr(feature = "num_enum", derive(num_enum::TryFromPrimitive))]
496#[cfg_attr(feature = "num_enum", derive(strum::AsRefStr))]
497#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
498pub enum PduErrorEvt {
500 NoError = 0x00000000,
502 FrameStruct = 0x00000100,
504 TxError = 0x00000101,
506 TesterPresentError = 0x00000102,
508 RscLocked = 0x00000109,
510 RxTimeout = 0x00000103,
512 RxError = 0x00000104,
514 ProtErr = 0x00000105,
516 LostCommToVci = 0x00000106,
518 VciHardwareFault = 0x00000107,
520 InitError = 0x00000108,
522}
523
524#[cfg(feature = "strum")]
525impl_as_str!(PduErrorEvt);
526
527#[repr(u32)]
528#[cfg_attr(feature = "num_enum", derive(num_enum::TryFromPrimitive))]
529#[cfg_attr(feature = "num_enum", derive(strum::AsRefStr))]
530#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
531pub enum PduPt {
533 Unum8 = 0x000000101,
535 Snum8 = 0x000000102,
537 Unum16 = 0x000000103,
539 Snum16 = 0x000000104,
541 Unum32 = 0x000000105,
543 Snum32 = 0x000000106,
545 ByteField = 0x000000107,
547 StructField = 0x000000108,
549 LongField = 0x00000109,
551}
552
553#[cfg(feature = "strum")]
554impl_as_str!(PduPt);
555
556#[repr(u32)]
557#[cfg_attr(feature = "num_enum", derive(num_enum::TryFromPrimitive))]
558#[cfg_attr(feature = "num_enum", derive(strum::AsRefStr))]
559#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
560pub enum PduPc {
562 Timing = 1,
564 Init = 2,
566 Com = 3,
568 ErrHdl = 4,
570 BusType = 5,
572 UniqueId = 6,
574 TesterPresent = 7,
576}
577
578#[cfg(feature = "strum")]
579impl_as_str!(PduPc);
580
581#[repr(u32)]
582#[cfg_attr(feature = "num_enum", derive(num_enum::TryFromPrimitive))]
583#[cfg_attr(feature = "num_enum", derive(strum::AsRefStr))]
584#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
585pub enum PduCpst {
587 SessionTiming = 0x00000001,
589 AccessTiming = 0x00000002,
591}
592
593#[cfg(feature = "strum")]
594impl_as_str!(PduCpst);
595
596#[repr(u8)]
597#[cfg_attr(feature = "num_enum", derive(num_enum::TryFromPrimitive))]
598#[cfg_attr(feature = "num_enum", derive(strum::AsRefStr))]
599#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
600pub enum VidPreselectMode {
602 None = 0,
604 Vin = 1,
606 Eid = 2,
608}
609
610#[cfg(feature = "strum")]
611impl_as_str!(VidPreselectMode);
612
613#[repr(u8)]
614#[cfg_attr(feature = "num_enum", derive(num_enum::TryFromPrimitive))]
615#[cfg_attr(feature = "num_enum", derive(strum::AsRefStr))]
616#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
617pub enum CombinationMode {
619 None = 0,
621 VIN = 1,
623 Group = 2,
625 All = 3,
627}
628
629#[cfg(feature = "strum")]
630impl_as_str!(CombinationMode);
631
632#[repr(u8)]
633#[cfg_attr(feature = "num_enum", derive(num_enum::TryFromPrimitive))]
634#[cfg_attr(feature = "num_enum", derive(strum::AsRefStr))]
635#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
636pub enum TimingSet {
638 Default = 1,
640 OverrideReceived = 2,
642 OverrideTester = 3,
644 Normal = 4,
646 Extended = 0xFF,
648}
649
650#[cfg(feature = "strum")]
651impl_as_str!(TimingSet);
652
653#[cfg(feature = "serde")]
654impl serde::Serialize for TimingSet {
655 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
656 where
657 S: serde::Serializer,
658 {
659 let value = match self {
660 TimingSet::Default => 1,
661 TimingSet::OverrideReceived => 2,
662 TimingSet::OverrideTester => 3,
663 TimingSet::Normal => 4,
664 TimingSet::Extended => 0xFF,
665 };
666
667 serializer.serialize_u8(value)
668 }
669}
670
671#[cfg(feature = "serde")]
672impl<'de> serde::Deserialize<'de> for TimingSet {
673 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
674 where
675 D: serde::Deserializer<'de>,
676 {
677 struct TimingSetVisitor;
678
679 impl<'de> serde::de::Visitor<'de> for TimingSetVisitor {
680 type Value = TimingSet;
681
682 fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
683 formatter.write_str("TimingSet as u8 or string")
684 }
685
686 fn visit_u64<E>(self, value: u64) -> Result<Self::Value, E>
687 where
688 E: serde::de::Error,
689 {
690 match value {
691 1 => Ok(TimingSet::Default),
692 2 => Ok(TimingSet::OverrideReceived),
693 3 => Ok(TimingSet::OverrideTester),
694 4 => Ok(TimingSet::Normal),
695 0xFF => Ok(TimingSet::Extended),
696 v => Err(E::custom(format!("unknown value {:#04X}", v))),
697 }
698 }
699
700 fn visit_str<E>(self, value: &str) -> Result<Self::Value, E>
701 where
702 E: serde::de::Error,
703 {
704 match value {
705 "Default" | "default" => Ok(TimingSet::Default),
706 "OverrideReceived" | "override_received" => Ok(TimingSet::OverrideReceived),
707 "OverrideTester" | "override_tester" => Ok(TimingSet::OverrideTester),
708 "Normal" | "normal" => Ok(TimingSet::Normal),
709 "Extended" | "extended" => Ok(TimingSet::Extended),
710 v => Err(E::custom(format!("unknown TimingSet {}", v))),
711 }
712 }
713 }
714
715 deserializer.deserialize_any(TimingSetVisitor)
716 }
717}