Skip to main content

doip_definitions/doip_payload/
sync_status.rs

1use crate::error::{Error, Result};
2
3/// The synchronisation status of the VIN and the GID for the entity
4///
5/// This gives the status that all `DoIP` entities have synchronised their information
6/// about the VIN or GID of the vehicle.
7#[cfg_attr(feature = "python-bindings", pyo3::pyclass(eq, eq_int))]
8#[derive(Clone, Copy, Debug, PartialEq)]
9pub enum SyncStatus {
10    /// VIN/GID Synchronized
11    VinGidSynchronized = 0x00,
12
13    /// Reserved By ISO-13400 for byte value `01`
14    ReservedByIso13400_01 = 0x01,
15
16    /// Reserved By ISO-13400 for byte value `02`
17    ReservedByIso13400_02 = 0x02,
18
19    /// Reserved By ISO-13400 for byte value `03`
20    ReservedByIso13400_03 = 0x03,
21
22    /// Reserved By ISO-13400 for byte value `04`
23    ReservedByIso13400_04 = 0x04,
24
25    /// Reserved By ISO-13400 for byte value `05`
26    ReservedByIso13400_05 = 0x05,
27
28    /// Reserved By ISO-13400 for byte value `06`
29    ReservedByIso13400_06 = 0x06,
30
31    /// Reserved By ISO-13400 for byte value `07`
32    ReservedByIso13400_07 = 0x07,
33
34    /// Reserved By ISO-13400 for byte value `08`
35    ReservedByIso13400_08 = 0x08,
36
37    /// Reserved By ISO-13400 for byte value `09`
38    ReservedByIso13400_09 = 0x09,
39
40    /// Reserved By ISO-13400 for byte value `0A`
41    ReservedByIso13400_0A = 0x0A,
42
43    /// Reserved By ISO-13400 for byte value `0B`
44    ReservedByIso13400_0B = 0x0B,
45
46    /// Reserved By ISO-13400 for byte value `0C`
47    ReservedByIso13400_0C = 0x0C,
48
49    /// Reserved By ISO-13400 for byte value `0D`
50    ReservedByIso13400_0D = 0x0D,
51
52    /// Reserved By ISO-13400 for byte value `0E`
53    ReservedByIso13400_0E = 0x0E,
54
55    /// Reserved By ISO-13400 for byte value `0F`
56    ReservedByIso13400_0F = 0x0F,
57
58    /// VVIN/GID Not Synchronised
59    VinGidNotSynchronised = 0x10,
60}
61
62impl TryFrom<&u8> for SyncStatus {
63    type Error = Error;
64
65    fn try_from(value: &u8) -> Result<Self> {
66        let val = *value;
67
68        match val {
69            v if v == SyncStatus::VinGidSynchronized as u8 => Ok(SyncStatus::VinGidSynchronized),
70            v if v == SyncStatus::ReservedByIso13400_01 as u8 => {
71                Ok(SyncStatus::ReservedByIso13400_01)
72            }
73            v if v == SyncStatus::ReservedByIso13400_02 as u8 => {
74                Ok(SyncStatus::ReservedByIso13400_02)
75            }
76            v if v == SyncStatus::ReservedByIso13400_03 as u8 => {
77                Ok(SyncStatus::ReservedByIso13400_03)
78            }
79            v if v == SyncStatus::ReservedByIso13400_04 as u8 => {
80                Ok(SyncStatus::ReservedByIso13400_04)
81            }
82            v if v == SyncStatus::ReservedByIso13400_05 as u8 => {
83                Ok(SyncStatus::ReservedByIso13400_05)
84            }
85            v if v == SyncStatus::ReservedByIso13400_06 as u8 => {
86                Ok(SyncStatus::ReservedByIso13400_06)
87            }
88            v if v == SyncStatus::ReservedByIso13400_07 as u8 => {
89                Ok(SyncStatus::ReservedByIso13400_07)
90            }
91            v if v == SyncStatus::ReservedByIso13400_08 as u8 => {
92                Ok(SyncStatus::ReservedByIso13400_08)
93            }
94            v if v == SyncStatus::ReservedByIso13400_09 as u8 => {
95                Ok(SyncStatus::ReservedByIso13400_09)
96            }
97            v if v == SyncStatus::ReservedByIso13400_0A as u8 => {
98                Ok(SyncStatus::ReservedByIso13400_0A)
99            }
100            v if v == SyncStatus::ReservedByIso13400_0B as u8 => {
101                Ok(SyncStatus::ReservedByIso13400_0B)
102            }
103            v if v == SyncStatus::ReservedByIso13400_0C as u8 => {
104                Ok(SyncStatus::ReservedByIso13400_0C)
105            }
106            v if v == SyncStatus::ReservedByIso13400_0D as u8 => {
107                Ok(SyncStatus::ReservedByIso13400_0D)
108            }
109            v if v == SyncStatus::ReservedByIso13400_0E as u8 => {
110                Ok(SyncStatus::ReservedByIso13400_0E)
111            }
112            v if v == SyncStatus::ReservedByIso13400_0F as u8 => {
113                Ok(SyncStatus::ReservedByIso13400_0F)
114            }
115            v if v == SyncStatus::VinGidNotSynchronised as u8 => {
116                Ok(SyncStatus::VinGidNotSynchronised)
117            }
118            v => Err(Error::InvalidSyncStatus { value: v }),
119        }
120    }
121}
122
123impl From<SyncStatus> for u8 {
124    fn from(value: SyncStatus) -> Self {
125        value as u8
126    }
127}