darra_ethercat/sugar/
conversions.rs1
2use crate::data::error::{EcState, LinkState, RedundancyState, CiA402State, CiA402Mode};
3use crate::slave::core::Slave;
4use crate::utils::ffi::SlaveIdentity;
5
6impl From<&Slave> for SlaveIdentity {
7
8 fn from(s: &Slave) -> Self {
9 SlaveIdentity {
10 vendor_id: s.vendor_id(),
11 product_code: s.product_id(),
12 revision_no: s.rev_id(),
13 serial_no: 0,
14 }
15 }
16}
17
18impl From<Slave> for SlaveIdentity {
19 fn from(s: Slave) -> Self {
20 (&s).into()
21 }
22}
23
24impl From<u8> for EcState {
25
26 fn from(v: u8) -> Self {
27 EcState::from_raw(v).unwrap_or(EcState::None)
28 }
29}
30
31impl From<EcState> for u8 {
32
33 fn from(s: EcState) -> u8 {
34 s as u8
35 }
36}
37
38impl From<EcState> for i32 {
39
40 fn from(s: EcState) -> i32 {
41 (s as u8) as i32
42 }
43}
44
45impl From<u8> for LinkState {
46 fn from(v: u8) -> Self {
47 LinkState::from_raw(v)
48 }
49}
50
51impl From<LinkState> for u8 {
52 fn from(s: LinkState) -> u8 {
53 s as u8
54 }
55}
56
57impl From<i32> for RedundancyState {
58 fn from(v: i32) -> Self {
59 RedundancyState::from_raw(v)
60 }
61}
62
63impl From<RedundancyState> for i32 {
64 fn from(s: RedundancyState) -> i32 {
65 s as i32
66 }
67}
68
69impl From<i32> for CiA402State {
70 fn from(v: i32) -> Self {
71 CiA402State::from_raw(v)
72 }
73}
74
75impl From<CiA402State> for i32 {
76 fn from(s: CiA402State) -> i32 {
77 s as i32
78 }
79}
80
81impl From<CiA402Mode> for i8 {
82 fn from(m: CiA402Mode) -> i8 {
83 m as i8
84 }
85}
86
87impl From<CiA402Mode> for i32 {
88 fn from(m: CiA402Mode) -> i32 {
89 (m as i8) as i32
90 }
91}
92
93impl From<EcState> for &'static str {
94 fn from(s: EcState) -> &'static str {
95 match s {
96 EcState::None => "None",
97 EcState::Init => "Init",
98 EcState::PreOp => "PreOp",
99 EcState::Boot => "Boot",
100 EcState::SafeOp => "SafeOp",
101 EcState::Operational => "OP",
102 }
103 }
104}
105
106impl From<LinkState> for &'static str {
107 fn from(s: LinkState) -> &'static str {
108 match s {
109 LinkState::Disconnected => "Disconnected",
110 LinkState::Connected => "Connected",
111 LinkState::Redundancy => "Redundancy",
112 LinkState::PrimaryOnly => "PrimaryOnly",
113 LinkState::SecondaryOnly => "SecondaryOnly",
114 }
115 }
116}
117
118impl From<RedundancyState> for &'static str {
119 fn from(s: RedundancyState) -> &'static str {
120 match s {
121 RedundancyState::None => "None",
122 RedundancyState::Primary => "PrimaryOnly",
123 RedundancyState::Secondary => "SecondaryOnly",
124 RedundancyState::Both => "Both",
125 }
126 }
127}