1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
//! Secure Write Request

/// Secure Write Request
///
/// Include a digital signature along with the control data
#[derive(Debug)]
pub struct Model5 {
    /// X
    ///
    /// Number of (offset, value) pairs being written
    ///
    /// Notes: A max of 50 (offset, value) pairs are allocated
    pub x: u16,
    /// Offset1
    ///
    /// Offset of control register to write value to
    pub off1: u16,
    /// Value1
    ///
    /// Value to write to control register at offset
    pub val1: u16,
    #[allow(missing_docs)]
    pub off2: u16,
    #[allow(missing_docs)]
    pub val2: u16,
    #[allow(missing_docs)]
    pub off3: u16,
    #[allow(missing_docs)]
    pub val3: u16,
    #[allow(missing_docs)]
    pub off4: u16,
    #[allow(missing_docs)]
    pub val4: u16,
    #[allow(missing_docs)]
    pub off5: u16,
    #[allow(missing_docs)]
    pub val5: u16,
    #[allow(missing_docs)]
    pub off6: u16,
    #[allow(missing_docs)]
    pub val6: u16,
    #[allow(missing_docs)]
    pub off7: u16,
    #[allow(missing_docs)]
    pub val7: u16,
    #[allow(missing_docs)]
    pub off8: u16,
    #[allow(missing_docs)]
    pub val8: u16,
    #[allow(missing_docs)]
    pub off9: u16,
    #[allow(missing_docs)]
    pub val9: u16,
    #[allow(missing_docs)]
    pub off10: u16,
    #[allow(missing_docs)]
    pub val10: u16,
    #[allow(missing_docs)]
    pub off11: u16,
    #[allow(missing_docs)]
    pub val11: u16,
    #[allow(missing_docs)]
    pub off12: u16,
    #[allow(missing_docs)]
    pub val12: u16,
    #[allow(missing_docs)]
    pub off13: u16,
    #[allow(missing_docs)]
    pub val13: u16,
    #[allow(missing_docs)]
    pub off14: u16,
    #[allow(missing_docs)]
    pub val14: u16,
    #[allow(missing_docs)]
    pub off15: u16,
    #[allow(missing_docs)]
    pub val15: u16,
    #[allow(missing_docs)]
    pub off16: u16,
    #[allow(missing_docs)]
    pub val16: u16,
    #[allow(missing_docs)]
    pub off17: u16,
    #[allow(missing_docs)]
    pub val17: u16,
    #[allow(missing_docs)]
    pub off18: u16,
    #[allow(missing_docs)]
    pub val18: u16,
    #[allow(missing_docs)]
    pub off19: u16,
    #[allow(missing_docs)]
    pub val19: u16,
    #[allow(missing_docs)]
    pub off20: u16,
    #[allow(missing_docs)]
    pub val20: u16,
    #[allow(missing_docs)]
    pub off21: u16,
    #[allow(missing_docs)]
    pub val21: u16,
    #[allow(missing_docs)]
    pub off22: u16,
    #[allow(missing_docs)]
    pub val22: u16,
    #[allow(missing_docs)]
    pub off23: u16,
    #[allow(missing_docs)]
    pub val23: u16,
    #[allow(missing_docs)]
    pub off24: u16,
    #[allow(missing_docs)]
    pub val24: u16,
    #[allow(missing_docs)]
    pub off25: u16,
    #[allow(missing_docs)]
    pub val25: u16,
    #[allow(missing_docs)]
    pub off26: u16,
    #[allow(missing_docs)]
    pub val26: u16,
    #[allow(missing_docs)]
    pub off27: u16,
    #[allow(missing_docs)]
    pub val27: u16,
    #[allow(missing_docs)]
    pub off28: u16,
    #[allow(missing_docs)]
    pub val28: u16,
    #[allow(missing_docs)]
    pub off29: u16,
    #[allow(missing_docs)]
    pub val29: u16,
    #[allow(missing_docs)]
    pub off30: u16,
    #[allow(missing_docs)]
    pub val30: u16,
    #[allow(missing_docs)]
    pub off31: u16,
    #[allow(missing_docs)]
    pub val31: u16,
    #[allow(missing_docs)]
    pub off32: u16,
    #[allow(missing_docs)]
    pub val32: u16,
    #[allow(missing_docs)]
    pub off33: u16,
    #[allow(missing_docs)]
    pub val33: u16,
    #[allow(missing_docs)]
    pub off34: u16,
    #[allow(missing_docs)]
    pub val34: u16,
    #[allow(missing_docs)]
    pub off35: u16,
    #[allow(missing_docs)]
    pub val35: u16,
    #[allow(missing_docs)]
    pub off36: u16,
    #[allow(missing_docs)]
    pub val36: u16,
    #[allow(missing_docs)]
    pub off37: u16,
    #[allow(missing_docs)]
    pub val37: u16,
    #[allow(missing_docs)]
    pub off38: u16,
    #[allow(missing_docs)]
    pub val38: u16,
    #[allow(missing_docs)]
    pub off39: u16,
    #[allow(missing_docs)]
    pub val39: u16,
    #[allow(missing_docs)]
    pub off40: u16,
    #[allow(missing_docs)]
    pub val40: u16,
    /// Timestamp
    ///
    /// Timestamp value is the number of seconds since January 1, 2000
    pub ts: u32,
    /// Milliseconds
    ///
    /// Millisecond counter 0-999
    pub ms: u16,
    /// Sequence
    ///
    /// Sequence number of request
    ///
    /// Notes: Shall be advanced for each request
    pub seq: u16,
    /// Role
    ///
    /// Signing key used 0-5
    ///
    /// Notes: Each controller is assigned a key index that maps to their access control role
    pub role: u16,
    /// Algorithm
    ///
    /// Algorithm used to compute the digital signature
    ///
    /// Notes: For future proof
    pub alg: Alg,
    /// N
    ///
    /// Number of registers comprising the digital signature.
    ///
    /// Notes: The value of N must be at least 4 (64 bits)
    pub n: u16,
}

#[allow(missing_docs)]

impl Model5 {
    pub const X: crate::PointDef<Self, u16> = crate::PointDef::new(0, 1, true);
    pub const OFF1: crate::PointDef<Self, u16> = crate::PointDef::new(1, 1, true);
    pub const VAL1: crate::PointDef<Self, u16> = crate::PointDef::new(2, 1, true);
    pub const OFF2: crate::PointDef<Self, u16> = crate::PointDef::new(3, 1, true);
    pub const VAL2: crate::PointDef<Self, u16> = crate::PointDef::new(4, 1, true);
    pub const OFF3: crate::PointDef<Self, u16> = crate::PointDef::new(5, 1, true);
    pub const VAL3: crate::PointDef<Self, u16> = crate::PointDef::new(6, 1, true);
    pub const OFF4: crate::PointDef<Self, u16> = crate::PointDef::new(7, 1, true);
    pub const VAL4: crate::PointDef<Self, u16> = crate::PointDef::new(8, 1, true);
    pub const OFF5: crate::PointDef<Self, u16> = crate::PointDef::new(9, 1, true);
    pub const VAL5: crate::PointDef<Self, u16> = crate::PointDef::new(10, 1, true);
    pub const OFF6: crate::PointDef<Self, u16> = crate::PointDef::new(11, 1, true);
    pub const VAL6: crate::PointDef<Self, u16> = crate::PointDef::new(12, 1, true);
    pub const OFF7: crate::PointDef<Self, u16> = crate::PointDef::new(13, 1, true);
    pub const VAL7: crate::PointDef<Self, u16> = crate::PointDef::new(14, 1, true);
    pub const OFF8: crate::PointDef<Self, u16> = crate::PointDef::new(15, 1, true);
    pub const VAL8: crate::PointDef<Self, u16> = crate::PointDef::new(16, 1, true);
    pub const OFF9: crate::PointDef<Self, u16> = crate::PointDef::new(17, 1, true);
    pub const VAL9: crate::PointDef<Self, u16> = crate::PointDef::new(18, 1, true);
    pub const OFF10: crate::PointDef<Self, u16> = crate::PointDef::new(19, 1, true);
    pub const VAL10: crate::PointDef<Self, u16> = crate::PointDef::new(20, 1, true);
    pub const OFF11: crate::PointDef<Self, u16> = crate::PointDef::new(21, 1, true);
    pub const VAL11: crate::PointDef<Self, u16> = crate::PointDef::new(22, 1, true);
    pub const OFF12: crate::PointDef<Self, u16> = crate::PointDef::new(23, 1, true);
    pub const VAL12: crate::PointDef<Self, u16> = crate::PointDef::new(24, 1, true);
    pub const OFF13: crate::PointDef<Self, u16> = crate::PointDef::new(25, 1, true);
    pub const VAL13: crate::PointDef<Self, u16> = crate::PointDef::new(26, 1, true);
    pub const OFF14: crate::PointDef<Self, u16> = crate::PointDef::new(27, 1, true);
    pub const VAL14: crate::PointDef<Self, u16> = crate::PointDef::new(28, 1, true);
    pub const OFF15: crate::PointDef<Self, u16> = crate::PointDef::new(29, 1, true);
    pub const VAL15: crate::PointDef<Self, u16> = crate::PointDef::new(30, 1, true);
    pub const OFF16: crate::PointDef<Self, u16> = crate::PointDef::new(31, 1, true);
    pub const VAL16: crate::PointDef<Self, u16> = crate::PointDef::new(32, 1, true);
    pub const OFF17: crate::PointDef<Self, u16> = crate::PointDef::new(33, 1, true);
    pub const VAL17: crate::PointDef<Self, u16> = crate::PointDef::new(34, 1, true);
    pub const OFF18: crate::PointDef<Self, u16> = crate::PointDef::new(35, 1, true);
    pub const VAL18: crate::PointDef<Self, u16> = crate::PointDef::new(36, 1, true);
    pub const OFF19: crate::PointDef<Self, u16> = crate::PointDef::new(37, 1, true);
    pub const VAL19: crate::PointDef<Self, u16> = crate::PointDef::new(38, 1, true);
    pub const OFF20: crate::PointDef<Self, u16> = crate::PointDef::new(39, 1, true);
    pub const VAL20: crate::PointDef<Self, u16> = crate::PointDef::new(40, 1, true);
    pub const OFF21: crate::PointDef<Self, u16> = crate::PointDef::new(41, 1, true);
    pub const VAL21: crate::PointDef<Self, u16> = crate::PointDef::new(42, 1, true);
    pub const OFF22: crate::PointDef<Self, u16> = crate::PointDef::new(43, 1, true);
    pub const VAL22: crate::PointDef<Self, u16> = crate::PointDef::new(44, 1, true);
    pub const OFF23: crate::PointDef<Self, u16> = crate::PointDef::new(45, 1, true);
    pub const VAL23: crate::PointDef<Self, u16> = crate::PointDef::new(46, 1, true);
    pub const OFF24: crate::PointDef<Self, u16> = crate::PointDef::new(47, 1, true);
    pub const VAL24: crate::PointDef<Self, u16> = crate::PointDef::new(48, 1, true);
    pub const OFF25: crate::PointDef<Self, u16> = crate::PointDef::new(49, 1, true);
    pub const VAL25: crate::PointDef<Self, u16> = crate::PointDef::new(50, 1, true);
    pub const OFF26: crate::PointDef<Self, u16> = crate::PointDef::new(51, 1, true);
    pub const VAL26: crate::PointDef<Self, u16> = crate::PointDef::new(52, 1, true);
    pub const OFF27: crate::PointDef<Self, u16> = crate::PointDef::new(53, 1, true);
    pub const VAL27: crate::PointDef<Self, u16> = crate::PointDef::new(54, 1, true);
    pub const OFF28: crate::PointDef<Self, u16> = crate::PointDef::new(55, 1, true);
    pub const VAL28: crate::PointDef<Self, u16> = crate::PointDef::new(56, 1, true);
    pub const OFF29: crate::PointDef<Self, u16> = crate::PointDef::new(57, 1, true);
    pub const VAL29: crate::PointDef<Self, u16> = crate::PointDef::new(58, 1, true);
    pub const OFF30: crate::PointDef<Self, u16> = crate::PointDef::new(59, 1, true);
    pub const VAL30: crate::PointDef<Self, u16> = crate::PointDef::new(60, 1, true);
    pub const OFF31: crate::PointDef<Self, u16> = crate::PointDef::new(61, 1, true);
    pub const VAL31: crate::PointDef<Self, u16> = crate::PointDef::new(62, 1, true);
    pub const OFF32: crate::PointDef<Self, u16> = crate::PointDef::new(63, 1, true);
    pub const VAL32: crate::PointDef<Self, u16> = crate::PointDef::new(64, 1, true);
    pub const OFF33: crate::PointDef<Self, u16> = crate::PointDef::new(65, 1, true);
    pub const VAL33: crate::PointDef<Self, u16> = crate::PointDef::new(66, 1, true);
    pub const OFF34: crate::PointDef<Self, u16> = crate::PointDef::new(67, 1, true);
    pub const VAL34: crate::PointDef<Self, u16> = crate::PointDef::new(68, 1, true);
    pub const OFF35: crate::PointDef<Self, u16> = crate::PointDef::new(69, 1, true);
    pub const VAL35: crate::PointDef<Self, u16> = crate::PointDef::new(70, 1, true);
    pub const OFF36: crate::PointDef<Self, u16> = crate::PointDef::new(71, 1, true);
    pub const VAL36: crate::PointDef<Self, u16> = crate::PointDef::new(72, 1, true);
    pub const OFF37: crate::PointDef<Self, u16> = crate::PointDef::new(73, 1, true);
    pub const VAL37: crate::PointDef<Self, u16> = crate::PointDef::new(74, 1, true);
    pub const OFF38: crate::PointDef<Self, u16> = crate::PointDef::new(75, 1, true);
    pub const VAL38: crate::PointDef<Self, u16> = crate::PointDef::new(76, 1, true);
    pub const OFF39: crate::PointDef<Self, u16> = crate::PointDef::new(77, 1, true);
    pub const VAL39: crate::PointDef<Self, u16> = crate::PointDef::new(78, 1, true);
    pub const OFF40: crate::PointDef<Self, u16> = crate::PointDef::new(79, 1, true);
    pub const VAL40: crate::PointDef<Self, u16> = crate::PointDef::new(80, 1, true);
    pub const TS: crate::PointDef<Self, u32> = crate::PointDef::new(81, 2, true);
    pub const MS: crate::PointDef<Self, u16> = crate::PointDef::new(83, 1, true);
    pub const SEQ: crate::PointDef<Self, u16> = crate::PointDef::new(84, 1, true);
    pub const ROLE: crate::PointDef<Self, u16> = crate::PointDef::new(85, 1, true);
    pub const ALG: crate::PointDef<Self, Alg> = crate::PointDef::new(86, 1, true);
    pub const N: crate::PointDef<Self, u16> = crate::PointDef::new(87, 1, true);
}

impl crate::Model for Model5 {
    const ID: u16 = 5;
    fn from_data(data: &[u16]) -> Result<Self, crate::ReadModelError> {
        Ok(Self {
            x: Self::X.from_data(data)?,
            off1: Self::OFF1.from_data(data)?,
            val1: Self::VAL1.from_data(data)?,
            off2: Self::OFF2.from_data(data)?,
            val2: Self::VAL2.from_data(data)?,
            off3: Self::OFF3.from_data(data)?,
            val3: Self::VAL3.from_data(data)?,
            off4: Self::OFF4.from_data(data)?,
            val4: Self::VAL4.from_data(data)?,
            off5: Self::OFF5.from_data(data)?,
            val5: Self::VAL5.from_data(data)?,
            off6: Self::OFF6.from_data(data)?,
            val6: Self::VAL6.from_data(data)?,
            off7: Self::OFF7.from_data(data)?,
            val7: Self::VAL7.from_data(data)?,
            off8: Self::OFF8.from_data(data)?,
            val8: Self::VAL8.from_data(data)?,
            off9: Self::OFF9.from_data(data)?,
            val9: Self::VAL9.from_data(data)?,
            off10: Self::OFF10.from_data(data)?,
            val10: Self::VAL10.from_data(data)?,
            off11: Self::OFF11.from_data(data)?,
            val11: Self::VAL11.from_data(data)?,
            off12: Self::OFF12.from_data(data)?,
            val12: Self::VAL12.from_data(data)?,
            off13: Self::OFF13.from_data(data)?,
            val13: Self::VAL13.from_data(data)?,
            off14: Self::OFF14.from_data(data)?,
            val14: Self::VAL14.from_data(data)?,
            off15: Self::OFF15.from_data(data)?,
            val15: Self::VAL15.from_data(data)?,
            off16: Self::OFF16.from_data(data)?,
            val16: Self::VAL16.from_data(data)?,
            off17: Self::OFF17.from_data(data)?,
            val17: Self::VAL17.from_data(data)?,
            off18: Self::OFF18.from_data(data)?,
            val18: Self::VAL18.from_data(data)?,
            off19: Self::OFF19.from_data(data)?,
            val19: Self::VAL19.from_data(data)?,
            off20: Self::OFF20.from_data(data)?,
            val20: Self::VAL20.from_data(data)?,
            off21: Self::OFF21.from_data(data)?,
            val21: Self::VAL21.from_data(data)?,
            off22: Self::OFF22.from_data(data)?,
            val22: Self::VAL22.from_data(data)?,
            off23: Self::OFF23.from_data(data)?,
            val23: Self::VAL23.from_data(data)?,
            off24: Self::OFF24.from_data(data)?,
            val24: Self::VAL24.from_data(data)?,
            off25: Self::OFF25.from_data(data)?,
            val25: Self::VAL25.from_data(data)?,
            off26: Self::OFF26.from_data(data)?,
            val26: Self::VAL26.from_data(data)?,
            off27: Self::OFF27.from_data(data)?,
            val27: Self::VAL27.from_data(data)?,
            off28: Self::OFF28.from_data(data)?,
            val28: Self::VAL28.from_data(data)?,
            off29: Self::OFF29.from_data(data)?,
            val29: Self::VAL29.from_data(data)?,
            off30: Self::OFF30.from_data(data)?,
            val30: Self::VAL30.from_data(data)?,
            off31: Self::OFF31.from_data(data)?,
            val31: Self::VAL31.from_data(data)?,
            off32: Self::OFF32.from_data(data)?,
            val32: Self::VAL32.from_data(data)?,
            off33: Self::OFF33.from_data(data)?,
            val33: Self::VAL33.from_data(data)?,
            off34: Self::OFF34.from_data(data)?,
            val34: Self::VAL34.from_data(data)?,
            off35: Self::OFF35.from_data(data)?,
            val35: Self::VAL35.from_data(data)?,
            off36: Self::OFF36.from_data(data)?,
            val36: Self::VAL36.from_data(data)?,
            off37: Self::OFF37.from_data(data)?,
            val37: Self::VAL37.from_data(data)?,
            off38: Self::OFF38.from_data(data)?,
            val38: Self::VAL38.from_data(data)?,
            off39: Self::OFF39.from_data(data)?,
            val39: Self::VAL39.from_data(data)?,
            off40: Self::OFF40.from_data(data)?,
            val40: Self::VAL40.from_data(data)?,
            ts: Self::TS.from_data(data)?,
            ms: Self::MS.from_data(data)?,
            seq: Self::SEQ.from_data(data)?,
            role: Self::ROLE.from_data(data)?,
            alg: Self::ALG.from_data(data)?,
            n: Self::N.from_data(data)?,
        })
    }
}

#[doc = "Algorithm\n\nAlgorithm used to compute the digital signature\n\nNotes: For future proof"]
#[derive(Copy, Clone, Debug, Eq, PartialEq, strum :: FromRepr)]
#[repr(u16)]
pub enum Alg {
    #[doc = "Notes: For test purposes only"]
    None = 0,
    #[doc = ""]
    AesGmac64 = 1,
    #[doc = ""]
    Ecc256 = 2,
}
impl crate::Value for Alg {
    fn decode(data: &[u16]) -> Result<Self, crate::DecodeError> {
        let value = u16::decode(data)?;
        Self::from_repr(value).ok_or(crate::DecodeError::InvalidEnumValue)
    }
    fn encode(self) -> Box<[u16]> {
        (self as u16).encode()
    }
}
impl crate::Value for Option<Alg> {
    fn decode(data: &[u16]) -> Result<Self, crate::DecodeError> {
        let value = u16::decode(data)?;
        if value != 65535 {
            Ok(Some(
                Alg::from_repr(value).ok_or(crate::DecodeError::InvalidEnumValue)?,
            ))
        } else {
            Ok(None)
        }
    }
    fn encode(self) -> Box<[u16]> {
        if let Some(value) = self {
            value.encode()
        } else {
            65535.encode()
        }
    }
}