1#[derive(Clone, Copy, Debug, PartialEq)]
6pub struct ObjectId {
7 pub index: u16,
9 pub sub: u8,
11}
12
13#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
17#[repr(u8)]
18pub enum ObjectCode {
19 Null = 0,
23 Domain = 2,
27 DefType = 5,
29 DefStruct = 6,
31 #[default]
33 Var = 7,
34 Array = 8,
36 Record = 9,
38}
39
40impl TryFrom<u8> for ObjectCode {
41 type Error = ();
42
43 fn try_from(value: u8) -> Result<Self, Self::Error> {
44 match value {
45 0 => Ok(ObjectCode::Null),
46 2 => Ok(ObjectCode::Domain),
47 5 => Ok(ObjectCode::DefType),
48 6 => Ok(ObjectCode::DefStruct),
49 7 => Ok(ObjectCode::Var),
50 8 => Ok(ObjectCode::Array),
51 9 => Ok(ObjectCode::Record),
52 _ => Err(()),
53 }
54 }
55}
56
57#[derive(Copy, Clone, Debug, Default, PartialEq)]
59pub enum AccessType {
60 #[default]
62 Ro,
63 Wo,
65 Rw,
67 Const,
69}
70
71impl AccessType {
72 pub fn is_readable(&self) -> bool {
74 matches!(self, AccessType::Ro | AccessType::Rw | AccessType::Const)
75 }
76
77 pub fn is_writable(&self) -> bool {
79 matches!(self, AccessType::Rw | AccessType::Wo)
80 }
81}
82
83#[derive(Copy, Clone, Debug, Default, PartialEq)]
85#[cfg_attr(
86 feature = "std",
87 derive(serde::Deserialize),
88 serde(rename_all = "lowercase")
89)]
90pub enum PdoMappable {
91 #[default]
93 None,
94 Rpdo,
96 Tpdo,
98 Both,
100}
101
102impl PdoMappable {
103 pub fn supports_tpdo(&self) -> bool {
105 matches!(self, PdoMappable::Tpdo | PdoMappable::Both)
106 }
107
108 pub fn supports_rpdo(&self) -> bool {
110 matches!(self, PdoMappable::Rpdo | PdoMappable::Both)
111 }
112}
113
114#[derive(Copy, Clone, Debug, Default, PartialEq)]
116#[repr(u16)]
117pub enum DataType {
118 Boolean = 1,
120 #[default]
121 Int8 = 2,
123 Int16 = 3,
125 Int32 = 4,
127 UInt8 = 5,
129 UInt16 = 6,
131 UInt32 = 7,
133 Real32 = 8,
135 VisibleString = 9,
137 OctetString = 0xa,
139 UnicodeString = 0xb,
141 TimeOfDay = 0xc,
143 TimeDifference = 0xd,
145 Domain = 0xf,
148 Other(u16),
150}
151
152impl From<u16> for DataType {
153 fn from(value: u16) -> Self {
154 use DataType::*;
155 match value {
156 1 => Boolean,
157 2 => Int8,
158 3 => Int16,
159 4 => Int32,
160 5 => UInt8,
161 6 => UInt16,
162 7 => UInt32,
163 8 => Real32,
164 9 => VisibleString,
165 0xa => OctetString,
166 0xb => UnicodeString,
167 0xf => Domain,
168 _ => Other(value),
169 }
170 }
171}
172
173impl DataType {
174 pub fn is_str(&self) -> bool {
176 matches!(
177 self,
178 Self::VisibleString | Self::OctetString | Self::UnicodeString
179 )
180 }
181}
182
183#[derive(Clone, Copy, Debug, Default, PartialEq)]
185pub struct SubInfo {
186 pub size: usize,
188 pub data_type: DataType,
190 pub access_type: AccessType,
192 pub pdo_mapping: PdoMappable,
194 pub persist: bool,
196}
197
198impl SubInfo {
199 pub const MAX_SUB_NUMBER: SubInfo = SubInfo {
201 size: 1,
202 data_type: DataType::UInt8,
203 access_type: AccessType::Const,
204 pdo_mapping: PdoMappable::None,
205 persist: false,
206 };
207
208 pub const fn new_u32() -> Self {
210 Self {
211 size: 4,
212 data_type: DataType::UInt32,
213 access_type: AccessType::Ro,
214 pdo_mapping: PdoMappable::None,
215 persist: false,
216 }
217 }
218
219 pub const fn new_u16() -> Self {
221 Self {
222 size: 2,
223 data_type: DataType::UInt16,
224 access_type: AccessType::Ro,
225 pdo_mapping: PdoMappable::None,
226 persist: false,
227 }
228 }
229
230 pub const fn new_u8() -> Self {
232 Self {
233 size: 1,
234 data_type: DataType::UInt8,
235 access_type: AccessType::Ro,
236 pdo_mapping: PdoMappable::None,
237 persist: false,
238 }
239 }
240
241 pub const fn new_i32() -> Self {
243 Self {
244 size: 4,
245 data_type: DataType::Int32,
246 access_type: AccessType::Ro,
247 pdo_mapping: PdoMappable::None,
248 persist: false,
249 }
250 }
251
252 pub const fn new_i16() -> Self {
254 Self {
255 size: 2,
256 data_type: DataType::Int16,
257 access_type: AccessType::Ro,
258 pdo_mapping: PdoMappable::None,
259 persist: false,
260 }
261 }
262
263 pub const fn new_i8() -> Self {
265 Self {
266 size: 1,
267 data_type: DataType::Int8,
268 access_type: AccessType::Ro,
269 pdo_mapping: PdoMappable::None,
270 persist: false,
271 }
272 }
273
274 pub const fn new_f32() -> Self {
276 Self {
277 size: 4,
278 data_type: DataType::Real32,
279 access_type: AccessType::Ro,
280 pdo_mapping: PdoMappable::None,
281 persist: false,
282 }
283 }
284
285 pub const fn new_visibile_str(size: usize) -> Self {
287 Self {
288 size,
289 data_type: DataType::VisibleString,
290 access_type: AccessType::Ro,
291 pdo_mapping: PdoMappable::None,
292 persist: false,
293 }
294 }
295
296 pub const fn ro_access(mut self) -> Self {
298 self.access_type = AccessType::Ro;
299 self
300 }
301
302 pub const fn rw_access(mut self) -> Self {
304 self.access_type = AccessType::Rw;
305 self
306 }
307
308 pub const fn const_access(mut self) -> Self {
310 self.access_type = AccessType::Const;
311 self
312 }
313
314 pub const fn wo_access(mut self) -> Self {
316 self.access_type = AccessType::Wo;
317 self
318 }
319
320 pub const fn persist(mut self, value: bool) -> Self {
322 self.persist = value;
323 self
324 }
325}