open_protocol/messages/
parameter_set.rs

1use open_protocol_codec_proc_macro::{OpenProtocolEncode, OpenProtocolDecode, OpenProtocolMessage};
2
3#[derive(Debug, Eq, PartialEq, Default, OpenProtocolEncode, OpenProtocolDecode)]
4pub enum RotationDirection {
5    #[default]
6    #[open_protocol_value(number=1)]
7    ClockWise,
8    #[open_protocol_value(number=2)]
9    CounterClockWise,
10}
11
12#[derive(Debug, Eq, PartialEq, Default, OpenProtocolEncode, OpenProtocolDecode)]
13pub enum RelayStatus {
14    #[default]
15    #[open_protocol_value(number=0)]
16    Inactive,
17    #[open_protocol_value(number=1)]
18    Active,
19}
20
21#[derive(Debug, Default, Eq, PartialEq, OpenProtocolEncode, OpenProtocolDecode, OpenProtocolMessage)]
22#[open_protocol_message(MID = 0010, revision = 1)]
23pub struct MID0010rev1 {
24}
25
26#[derive(Debug, Default, Eq, PartialEq, OpenProtocolEncode, OpenProtocolDecode, OpenProtocolMessage)]
27#[open_protocol_message(MID = 0011, revision = 1)]
28pub struct MID0011rev1 {
29    /// Three ASCII digits for the number of parameter sets
30    #[open_protocol_field(length = 3)]
31    pub number_of_parameter_sets: u16,
32
33    /// Three ASCII digits for each parameter set
34    #[open_protocol_field(list, amount = "number_of_parameter_sets", length = 3)]
35    pub parameter_set_ids: Vec<u16>,
36}
37
38#[derive(Debug, Default, Eq, PartialEq, OpenProtocolEncode, OpenProtocolDecode, OpenProtocolMessage)]
39#[open_protocol_message(MID = 0011, revision = 2)]
40pub struct MID0011rev2 {
41    /// Three ASCII digits for the number of parameter sets
42    #[open_protocol_field(length = 3)]
43    pub number_of_parameter_sets: u16,
44
45    /// Three ASCII digits for each parameter set
46    #[open_protocol_field(list, amount = "number_of_parameter_sets", length = 3)]
47    pub parameter_set_ids: Vec<u16>,
48
49    /// Three ASCII digits for each parameter set
50    #[open_protocol_field(list, amount = "number_of_parameter_sets", length = 2)]
51    pub cycles: Vec<u8>,
52}
53
54#[derive(Debug, Default, Eq, PartialEq, OpenProtocolEncode, OpenProtocolDecode, OpenProtocolMessage)]
55#[open_protocol_message(MID = 0011, revision = 3)]
56pub struct MID0011rev3 {
57    /// Three ASCII digits for the number of parameter sets
58    #[open_protocol_field(length = 3)]
59    pub number_of_parameter_sets: u16,
60
61    /// Three ASCII digits for each parameter set
62    #[open_protocol_field(list, amount = "number_of_parameter_sets", length = 3)]
63    pub parameter_set_ids: Vec<u16>,
64
65    /// Three ASCII digits for each parameter set
66    #[open_protocol_field(list, amount = "number_of_parameter_sets", length = 2)]
67    pub cycles: Vec<u8>,
68
69    /// our ASCII character for strings: “Mset” or “Pset” telling if Pset or Multistage
70    #[open_protocol_field(list, amount = "number_of_parameter_sets", length = 4)]
71    pub types: Vec<String>,
72}
73
74#[derive(Debug, Default, Eq, PartialEq, OpenProtocolEncode, OpenProtocolDecode, OpenProtocolMessage)]
75#[open_protocol_message(MID = 0011, revision = 4)]
76pub struct MID0011rev4 {
77    /// Three ASCII digits for the number of parameter sets
78    #[open_protocol_field(length = 3)]
79    pub number_of_parameter_sets: u16,
80
81    /// Three ASCII digits for each parameter set
82    #[open_protocol_field(list, amount = "number_of_parameter_sets", length = 3)]
83    pub parameter_set_ids: Vec<u16>,
84
85    /// Three ASCII digits for each parameter set
86    #[open_protocol_field(list, amount = "number_of_parameter_sets", length = 2)]
87    pub cycles: Vec<u8>,
88
89    /// our ASCII character for strings: “Mset” or “Pset” telling if Pset or Multistage
90    #[open_protocol_field(list, amount = "number_of_parameter_sets", length = 4)]
91    pub types: Vec<String>,
92
93    /// 19 ASCII characters YYYY-MM-DD:HH:MM:SS
94    #[open_protocol_field(list, amount = "number_of_parameter_sets", length = 19)]
95    pub date_of_last_change: Vec<String>,
96}
97
98#[derive(Debug, Default, Eq, PartialEq, OpenProtocolEncode, OpenProtocolDecode, OpenProtocolMessage)]
99#[open_protocol_message(MID = 0012, revision = 1)]
100pub struct MID0012rev1 {
101
102    /// Three ASCII digits for the parameter set ID
103    #[open_protocol_field(length = 3)]
104    pub parameter_set_id: u16,
105}
106
107#[derive(Debug, Default, Eq, PartialEq, OpenProtocolEncode, OpenProtocolDecode, OpenProtocolMessage)]
108#[open_protocol_message(MID = 0013, revision = 1)]
109pub struct MID0013rev1 {
110    /// Three ASCII digits for the parameter set ID
111    #[open_protocol_field(number = 1, length = 3)]
112    pub parameter_set_id: u16,
113
114    /// 25 ASCII characters for the parameter set name, right-padded with spaces if less
115    #[open_protocol_field(number = 2, length = 25)]
116    pub parameter_set_name: String,
117
118    /// One ASCII digit for rotation direction: 1=CW, 2=CCW
119    #[open_protocol_field(number = 3, length = 1)]
120    pub rotation_direction: RotationDirection,
121
122    /// Two ASCII digits for batch size
123    #[open_protocol_field(number = 4, length = 2)]
124    pub batch_size: u8,
125
126    /// Six ASCII digits for torque minimum, multiplied by 100
127    #[open_protocol_field(number = 5, length = 6)]
128    pub torque_min: u32,
129
130    /// Six ASCII digits for torque maximum, multiplied by 100
131    #[open_protocol_field(number = 6, length = 6)]
132    pub torque_max: u32,
133
134    /// Six ASCII digits for the final torque target, multiplied by 100
135    #[open_protocol_field(number = 7, length = 6)]
136    pub final_torque_target: u32,
137
138    /// Five ASCII digits for angle minimum
139    #[open_protocol_field(number = 8, length = 5)]
140    pub angle_min: u16,
141
142    /// Five ASCII digits for angle maximum
143    #[open_protocol_field(number = 9, length = 5)]
144    pub angle_max: u16,
145
146    /// Five ASCII digits for the final angle target
147    #[open_protocol_field(number = 10, length = 5)]
148    pub final_angle_target: u16,
149}
150
151#[derive(Debug, Default, Eq, PartialEq, OpenProtocolEncode, OpenProtocolDecode, OpenProtocolMessage)]
152#[open_protocol_message(MID = 0013, revision = 2)]
153pub struct MID0013rev2 {
154    /// Three ASCII digits for the parameter set ID
155    #[open_protocol_field(number = 1, length = 3)]
156    pub parameter_set_id: u16,
157
158    /// 25 ASCII characters for the parameter set name, right-padded with spaces if less
159    #[open_protocol_field(number = 2, length = 25)]
160    pub parameter_set_name: String,
161
162    /// One ASCII digit for rotation direction: 1=CW, 2=CCW
163    #[open_protocol_field(number = 3, length = 1)]
164    pub rotation_direction: RotationDirection,
165
166    /// Two ASCII digits for batch size
167    #[open_protocol_field(number = 4, length = 2)]
168    pub batch_size: u8,
169
170    /// Six ASCII digits for torque minimum, multiplied by 100
171    #[open_protocol_field(number = 5, length = 6)]
172    pub torque_min: u32,
173
174    /// Six ASCII digits for torque maximum, multiplied by 100
175    #[open_protocol_field(number = 6, length = 6)]
176    pub torque_max: u32,
177
178    /// Six ASCII digits for the final torque target, multiplied by 100
179    #[open_protocol_field(number = 7, length = 6)]
180    pub final_torque_target: u32,
181
182    /// Five ASCII digits for angle minimum
183    #[open_protocol_field(number = 8, length = 5)]
184    pub angle_min: u16,
185
186    /// Five ASCII digits for angle maximum
187    #[open_protocol_field(number = 9, length = 5)]
188    pub angle_max: u16,
189
190    /// Five ASCII digits for the final angle target
191    #[open_protocol_field(number = 10, length = 5)]
192    pub final_angle_target: u16,
193
194    /// Five ASCII digits for angle maximum
195    #[open_protocol_field(number = 11, length = 6)]
196    pub first_target: u32,
197
198    /// Five ASCII digits for the final angle target
199    #[open_protocol_field(number = 12, length = 6)]
200    pub start_final_angle: u32,
201}
202
203#[derive(Debug, Default, Eq, PartialEq, OpenProtocolEncode, OpenProtocolDecode, OpenProtocolMessage)]
204#[open_protocol_message(MID = 0014, revision = 1)]
205pub struct MID0014rev1 {
206}
207
208#[derive(Debug, Default, Eq, PartialEq, OpenProtocolEncode, OpenProtocolDecode, OpenProtocolMessage)]
209#[open_protocol_message(MID = 0015, revision = 1)]
210pub struct MID0015rev1 {
211    /// Three ASCII digits for the parameter set ID
212    #[open_protocol_field(number = 1, length = 3)]
213    pub parameter_set_id: u16,
214
215    /// 19 ASCII characters for the date of the last change in the parameter set settings
216    #[open_protocol_field(number = 2, length = 19)]
217    pub date_of_last_change: String,
218}
219
220#[derive(Debug, Default, Eq, PartialEq, OpenProtocolEncode, OpenProtocolDecode, OpenProtocolMessage)]
221#[open_protocol_message(MID = 0015, revision = 2)]
222pub struct MID0015rev2 {
223    /// Three ASCII digits for the parameter set ID (000-999)
224    #[open_protocol_field(number = 1, length = 3)]
225    pub parameter_set_id: u16,
226
227    /// 25 ASCII characters for the parameter set name, right-padded with spaces if less than 25 characters
228    #[open_protocol_field(number = 2, length = 25)]
229    pub parameter_set_name: String,
230
231    /// 19 ASCII characters for the date of the last change in the parameter set (YYYY-MM-DD:HH:MM:SS)
232    #[open_protocol_field(number = 3, length = 19)]
233    pub date_of_last_change: String,
234
235    /// 1 ASCII character for the rotation direction (1 = CW, 2 = CCW)
236    #[open_protocol_field(number = 4, length = 1)]
237    pub rotation_direction: u8,
238
239    /// Two ASCII digits for the batch size (00-99)
240    #[open_protocol_field(number = 5, length = 2)]
241    pub batch_size: u8,
242
243    /// Six ASCII digits for the torque minimum, multiplied by 100 (000000-999999)
244    #[open_protocol_field(number = 6, length = 6)]
245    pub torque_min: u32,
246
247    /// Six ASCII digits for the torque maximum, multiplied by 100 (000000-999999)
248    #[open_protocol_field(number = 7, length = 6)]
249    pub torque_max: u32,
250
251    /// Six ASCII digits for the final torque target, multiplied by 100 (000000-999999)
252    #[open_protocol_field(number = 8, length = 6)]
253    pub final_torque_target: u32,
254
255    /// Five ASCII digits for the angle minimum (00000-99999)
256    #[open_protocol_field(number = 9, length = 5)]
257    pub angle_min: u16,
258
259    /// Five ASCII digits for the angle maximum (00000-99999)
260    #[open_protocol_field(number = 10, length = 5)]
261    pub angle_max: u16,
262
263    /// Five ASCII digits for the final angle target (00000-99999)
264    #[open_protocol_field(number = 11, length = 5)]
265    pub final_angle_target: u16,
266
267    /// Six ASCII digits for the first torque target, multiplied by 100 (000000-999999)
268    #[open_protocol_field(number = 12, length = 6)]
269    pub first_torque_target: u32,
270
271    /// Six ASCII digits for the start final angle, multiplied by 100 (000000-999999)
272    #[open_protocol_field(number = 13, length = 6)]
273    pub start_final_angle: u32,
274}
275
276#[derive(Debug, Default, Eq, PartialEq, OpenProtocolEncode, OpenProtocolDecode, OpenProtocolMessage)]
277#[open_protocol_message(MID = 0016, revision = 1)]
278pub struct MID0016rev1 {
279}
280
281#[derive(Debug, Default, Eq, PartialEq, OpenProtocolEncode, OpenProtocolDecode, OpenProtocolMessage)]
282#[open_protocol_message(MID = 0017, revision = 1)]
283pub struct MID0017rev1 {
284}
285
286#[derive(Debug, Default, Eq, PartialEq, OpenProtocolEncode, OpenProtocolDecode, OpenProtocolMessage)]
287#[open_protocol_message(MID = 0018, revision = 1)]
288pub struct MID0018rev1 {
289    /// Three ASCII digits for the parameter set ID
290    #[open_protocol_field(number = 1, length = 3)]
291    pub parameter_set_id: u16,
292}
293
294#[derive(Debug, Default, Eq, PartialEq, OpenProtocolEncode, OpenProtocolDecode, OpenProtocolMessage)]
295#[open_protocol_message(MID = 0019, revision = 1)]
296pub struct MID0019rev1 {
297    /// Three ASCII digits for the parameter set ID (000-999)
298    #[open_protocol_field(number = 1, length = 3)]
299    pub parameter_set_id: u16,
300
301    /// Two ASCII digits for the batch size (00-99)
302    #[open_protocol_field(number = 2, length = 2)]
303    pub batch_size: u8,
304}
305
306#[derive(Debug, Default, Eq, PartialEq, OpenProtocolEncode, OpenProtocolDecode, OpenProtocolMessage)]
307#[open_protocol_message(MID = 0019, revision = 2)]
308pub struct MID0019rev2 {
309    /// Three ASCII digits for the parameter set ID (000-999)
310    #[open_protocol_field(number = 1, length = 3)]
311    pub parameter_set_id: u16,
312
313    /// Four ASCII digits for the batch size (0000-9999)
314    #[open_protocol_field(number = 2, length = 4)]
315    pub batch_size: u16,
316}
317
318#[derive(Debug, Default, Eq, PartialEq, OpenProtocolEncode, OpenProtocolDecode, OpenProtocolMessage)]
319#[open_protocol_message(MID = 0020, revision = 1)]
320pub struct MID0020rev1 {
321
322    /// Three ASCII digits for the parameter set ID (000-999)
323    #[open_protocol_field(number = 1, length = 3)]
324    pub parameter_set_id: u16,
325}
326
327#[derive(Debug, Default, Eq, PartialEq, OpenProtocolEncode, OpenProtocolDecode, OpenProtocolMessage)]
328#[open_protocol_message(MID = 0021, revision = 1)]
329pub struct MID0021rev1 {
330}
331
332#[derive(Debug, Default, Eq, PartialEq, OpenProtocolEncode, OpenProtocolDecode, OpenProtocolMessage)]
333#[open_protocol_message(MID = 0022, revision = 1)]
334pub struct MID0022rev1 {
335
336    /// One ASCII digit representing the relay status (0 = inactive, 1 = active)
337    #[open_protocol_field(number = 1, length = 1)]
338    pub relay_status: RelayStatus,
339}
340
341#[derive(Debug, Default, Eq, PartialEq, OpenProtocolEncode, OpenProtocolDecode, OpenProtocolMessage)]
342#[open_protocol_message(MID = 2506, revision = 1)]
343pub struct MID2506rev1 {
344
345    /// Four ASCII digits for the program ID. A zero value is illegal.
346    #[open_protocol_field(number = 1, length = 4)]
347    pub program_id: u32,
348
349    /// Three ASCII digits for the node type (e.g., 201 for a multistep tightening program)
350    #[open_protocol_field(number = 2, length = 3)]
351    pub node_type: u16,
352}
353
354#[cfg(test)]
355mod tests {
356    use open_protocol_codec::{decode, encode};
357    use super::*;
358
359    #[test]
360    fn encode_0010() {
361        let message = MID0010rev1 {};
362
363        let result = encode::encode(&message);
364
365        assert_eq!(result, Ok("".to_string()));
366    }
367
368    #[test]
369    fn encode_0012() {
370        let message = MID0012rev1 { parameter_set_id: 12 };
371
372        let result = encode::encode(&message);
373
374        assert_eq!(result, Ok("012".to_string()));
375    }
376
377    #[test]
378    fn encode_0011rev1() {
379        let message = MID0011rev1 {
380            number_of_parameter_sets: 5,
381            parameter_set_ids: vec![1, 2, 3, 10, 20],
382        };
383
384        let result = encode::encode(&message);
385
386        assert_eq!(result, Ok("005001002003010020".to_string()));
387    }
388
389    #[test]
390    fn decode_0011rev1() {
391        let message = "005001002003010020";
392
393        let result = decode::decode(message.as_bytes());
394
395        assert_eq!(result, Ok(MID0011rev1 {
396            number_of_parameter_sets: 5,
397            parameter_set_ids: vec![1, 2, 3, 10, 20],
398        }));
399    }
400}