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
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
// Copyright (C) 2015-2021 Swift Navigation Inc.
// Contact: https://support.swiftnav.com
//
// This source is subject to the license found in the file 'LICENSE' which must
// be be distributed together with this source. All other rights reserved.
//
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.

//****************************************************************************
// Automatically generated from yaml/swiftnav/sbp/flash.yaml
// with generate.py. Please do not hand edit!
//****************************************************************************/
//! Messages for reading/writing the device's onboard flash memory. Many of
//! these messages target specific flash memory peripherals used in Swift
//! Navigation devices: the STM32 flash and the M25Pxx FPGA configuration
//! flash from Piksi 2.3.1.  This module does not apply to Piksi Multi.

use super::lib::*;

/// Flash response message (host <= device)
///
/// This message defines success or failure codes for a variety of flash
/// memory requests from the host to the device. Flash read and write
/// messages, such as MSG_FLASH_READ_REQ, or MSG_FLASH_PROGRAM, may return
/// this message on failure.
///
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[derive(Debug, Clone)]
pub struct MsgFlashDone {
    /// The message sender_id
    #[cfg_attr(feature = "serde", serde(skip_serializing))]
    pub sender_id: Option<u16>,
    /// Response flags
    #[cfg_attr(feature = "serde", serde(rename(serialize = "response")))]
    pub response: u8,
}

impl ConcreteMessage for MsgFlashDone {
    const MESSAGE_TYPE: u16 = 224;
    const MESSAGE_NAME: &'static str = "MSG_FLASH_DONE";
}

impl SbpMessage for MsgFlashDone {
    fn message_name(&self) -> &'static str {
        <Self as ConcreteMessage>::MESSAGE_NAME
    }
    fn message_type(&self) -> u16 {
        <Self as ConcreteMessage>::MESSAGE_TYPE
    }
    fn sender_id(&self) -> Option<u16> {
        self.sender_id
    }
    fn set_sender_id(&mut self, new_id: u16) {
        self.sender_id = Some(new_id);
    }
    fn encoded_len(&self) -> usize {
        WireFormat::len(self) + crate::HEADER_LEN + crate::CRC_LEN
    }
}

impl TryFrom<Sbp> for MsgFlashDone {
    type Error = TryFromSbpError;
    fn try_from(msg: Sbp) -> Result<Self, Self::Error> {
        match msg {
            Sbp::MsgFlashDone(m) => Ok(m),
            _ => Err(TryFromSbpError),
        }
    }
}

impl WireFormat for MsgFlashDone {
    const MIN_LEN: usize = <u8 as WireFormat>::MIN_LEN;
    fn len(&self) -> usize {
        WireFormat::len(&self.response)
    }
    fn write<B: BufMut>(&self, buf: &mut B) {
        WireFormat::write(&self.response, buf);
    }
    fn parse_unchecked<B: Buf>(buf: &mut B) -> Self {
        MsgFlashDone {
            sender_id: None,
            response: WireFormat::parse_unchecked(buf),
        }
    }
}

/// Erase sector of device flash memory (host => device)
///
/// The flash erase message from the host erases a sector of either the STM or
/// M25 onboard flash memory. The device will reply with a MSG_FLASH_DONE
/// message containing the return code - FLASH_OK (0) on success or
/// FLASH_INVALID_FLASH (1) if the flash specified is invalid.
///
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[derive(Debug, Clone)]
pub struct MsgFlashErase {
    /// The message sender_id
    #[cfg_attr(feature = "serde", serde(skip_serializing))]
    pub sender_id: Option<u16>,
    /// Target flags
    #[cfg_attr(feature = "serde", serde(rename(serialize = "target")))]
    pub target: u8,
    /// Flash sector number to erase (0-11 for the STM, 0-15 for the M25)
    #[cfg_attr(feature = "serde", serde(rename(serialize = "sector_num")))]
    pub sector_num: u32,
}

impl ConcreteMessage for MsgFlashErase {
    const MESSAGE_TYPE: u16 = 226;
    const MESSAGE_NAME: &'static str = "MSG_FLASH_ERASE";
}

impl SbpMessage for MsgFlashErase {
    fn message_name(&self) -> &'static str {
        <Self as ConcreteMessage>::MESSAGE_NAME
    }
    fn message_type(&self) -> u16 {
        <Self as ConcreteMessage>::MESSAGE_TYPE
    }
    fn sender_id(&self) -> Option<u16> {
        self.sender_id
    }
    fn set_sender_id(&mut self, new_id: u16) {
        self.sender_id = Some(new_id);
    }
    fn encoded_len(&self) -> usize {
        WireFormat::len(self) + crate::HEADER_LEN + crate::CRC_LEN
    }
}

impl TryFrom<Sbp> for MsgFlashErase {
    type Error = TryFromSbpError;
    fn try_from(msg: Sbp) -> Result<Self, Self::Error> {
        match msg {
            Sbp::MsgFlashErase(m) => Ok(m),
            _ => Err(TryFromSbpError),
        }
    }
}

impl WireFormat for MsgFlashErase {
    const MIN_LEN: usize = <u8 as WireFormat>::MIN_LEN + <u32 as WireFormat>::MIN_LEN;
    fn len(&self) -> usize {
        WireFormat::len(&self.target) + WireFormat::len(&self.sector_num)
    }
    fn write<B: BufMut>(&self, buf: &mut B) {
        WireFormat::write(&self.target, buf);
        WireFormat::write(&self.sector_num, buf);
    }
    fn parse_unchecked<B: Buf>(buf: &mut B) -> Self {
        MsgFlashErase {
            sender_id: None,
            target: WireFormat::parse_unchecked(buf),
            sector_num: WireFormat::parse_unchecked(buf),
        }
    }
}

/// Program flash addresses
///
/// The flash program message programs a set of addresses of either the STM or
/// M25 flash. The device replies with either a MSG_FLASH_DONE message
/// containing the return code FLASH_OK (0) on success, or FLASH_INVALID_LEN
/// (2) if the maximum write size is exceeded. Note that the sector-containing
/// addresses must be erased before addresses can be programmed.
///
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[derive(Debug, Clone)]
pub struct MsgFlashProgram {
    /// The message sender_id
    #[cfg_attr(feature = "serde", serde(skip_serializing))]
    pub sender_id: Option<u16>,
    /// Target flags
    #[cfg_attr(feature = "serde", serde(rename(serialize = "target")))]
    pub target: u8,
    /// Starting address offset to program
    #[cfg_attr(feature = "serde", serde(rename(serialize = "addr_start")))]
    pub addr_start: [u8; 3],
    /// Length of set of addresses to program, counting up from starting address
    #[cfg_attr(feature = "serde", serde(rename(serialize = "addr_len")))]
    pub addr_len: u8,
    /// Data to program addresses with, with length N=addr_len
    #[cfg_attr(feature = "serde", serde(rename(serialize = "data")))]
    pub data: Vec<u8>,
}

impl ConcreteMessage for MsgFlashProgram {
    const MESSAGE_TYPE: u16 = 230;
    const MESSAGE_NAME: &'static str = "MSG_FLASH_PROGRAM";
}

impl SbpMessage for MsgFlashProgram {
    fn message_name(&self) -> &'static str {
        <Self as ConcreteMessage>::MESSAGE_NAME
    }
    fn message_type(&self) -> u16 {
        <Self as ConcreteMessage>::MESSAGE_TYPE
    }
    fn sender_id(&self) -> Option<u16> {
        self.sender_id
    }
    fn set_sender_id(&mut self, new_id: u16) {
        self.sender_id = Some(new_id);
    }
    fn encoded_len(&self) -> usize {
        WireFormat::len(self) + crate::HEADER_LEN + crate::CRC_LEN
    }
}

impl TryFrom<Sbp> for MsgFlashProgram {
    type Error = TryFromSbpError;
    fn try_from(msg: Sbp) -> Result<Self, Self::Error> {
        match msg {
            Sbp::MsgFlashProgram(m) => Ok(m),
            _ => Err(TryFromSbpError),
        }
    }
}

impl WireFormat for MsgFlashProgram {
    const MIN_LEN: usize = <u8 as WireFormat>::MIN_LEN
        + <[u8; 3] as WireFormat>::MIN_LEN
        + <u8 as WireFormat>::MIN_LEN
        + <Vec<u8> as WireFormat>::MIN_LEN;
    fn len(&self) -> usize {
        WireFormat::len(&self.target)
            + WireFormat::len(&self.addr_start)
            + WireFormat::len(&self.addr_len)
            + WireFormat::len(&self.data)
    }
    fn write<B: BufMut>(&self, buf: &mut B) {
        WireFormat::write(&self.target, buf);
        WireFormat::write(&self.addr_start, buf);
        WireFormat::write(&self.addr_len, buf);
        WireFormat::write(&self.data, buf);
    }
    fn parse_unchecked<B: Buf>(buf: &mut B) -> Self {
        MsgFlashProgram {
            sender_id: None,
            target: WireFormat::parse_unchecked(buf),
            addr_start: WireFormat::parse_unchecked(buf),
            addr_len: WireFormat::parse_unchecked(buf),
            data: WireFormat::parse_unchecked(buf),
        }
    }
}

/// Read STM or M25 flash address request (host => device)
///
/// The flash read message reads a set of addresses of either the STM or M25
/// onboard flash. The device replies with a MSG_FLASH_READ_RESP message
/// containing either the read data on success or a MSG_FLASH_DONE message
/// containing the return code FLASH_INVALID_LEN (2) if the maximum read size
/// is exceeded or FLASH_INVALID_ADDR (3) if the address is outside of the
/// allowed range.
///
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[derive(Debug, Clone)]
pub struct MsgFlashReadReq {
    /// The message sender_id
    #[cfg_attr(feature = "serde", serde(skip_serializing))]
    pub sender_id: Option<u16>,
    /// Target flags
    #[cfg_attr(feature = "serde", serde(rename(serialize = "target")))]
    pub target: u8,
    /// Starting address offset to read from
    #[cfg_attr(feature = "serde", serde(rename(serialize = "addr_start")))]
    pub addr_start: [u8; 3],
    /// Length of set of addresses to read, counting up from starting address
    #[cfg_attr(feature = "serde", serde(rename(serialize = "addr_len")))]
    pub addr_len: u8,
}

impl ConcreteMessage for MsgFlashReadReq {
    const MESSAGE_TYPE: u16 = 231;
    const MESSAGE_NAME: &'static str = "MSG_FLASH_READ_REQ";
}

impl SbpMessage for MsgFlashReadReq {
    fn message_name(&self) -> &'static str {
        <Self as ConcreteMessage>::MESSAGE_NAME
    }
    fn message_type(&self) -> u16 {
        <Self as ConcreteMessage>::MESSAGE_TYPE
    }
    fn sender_id(&self) -> Option<u16> {
        self.sender_id
    }
    fn set_sender_id(&mut self, new_id: u16) {
        self.sender_id = Some(new_id);
    }
    fn encoded_len(&self) -> usize {
        WireFormat::len(self) + crate::HEADER_LEN + crate::CRC_LEN
    }
}

impl TryFrom<Sbp> for MsgFlashReadReq {
    type Error = TryFromSbpError;
    fn try_from(msg: Sbp) -> Result<Self, Self::Error> {
        match msg {
            Sbp::MsgFlashReadReq(m) => Ok(m),
            _ => Err(TryFromSbpError),
        }
    }
}

impl WireFormat for MsgFlashReadReq {
    const MIN_LEN: usize = <u8 as WireFormat>::MIN_LEN
        + <[u8; 3] as WireFormat>::MIN_LEN
        + <u8 as WireFormat>::MIN_LEN;
    fn len(&self) -> usize {
        WireFormat::len(&self.target)
            + WireFormat::len(&self.addr_start)
            + WireFormat::len(&self.addr_len)
    }
    fn write<B: BufMut>(&self, buf: &mut B) {
        WireFormat::write(&self.target, buf);
        WireFormat::write(&self.addr_start, buf);
        WireFormat::write(&self.addr_len, buf);
    }
    fn parse_unchecked<B: Buf>(buf: &mut B) -> Self {
        MsgFlashReadReq {
            sender_id: None,
            target: WireFormat::parse_unchecked(buf),
            addr_start: WireFormat::parse_unchecked(buf),
            addr_len: WireFormat::parse_unchecked(buf),
        }
    }
}

/// Read STM or M25 flash address response (host <= device)
///
/// The flash read message reads a set of addresses of either the STM or M25
/// onboard flash. The device replies with a MSG_FLASH_READ_RESP message
/// containing either the read data on success or a MSG_FLASH_DONE message
/// containing the return code FLASH_INVALID_LEN (2) if the maximum read size
/// is exceeded or FLASH_INVALID_ADDR (3) if the address is outside of the
/// allowed range.
///
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[derive(Debug, Clone)]
pub struct MsgFlashReadResp {
    /// The message sender_id
    #[cfg_attr(feature = "serde", serde(skip_serializing))]
    pub sender_id: Option<u16>,
    /// Target flags
    #[cfg_attr(feature = "serde", serde(rename(serialize = "target")))]
    pub target: u8,
    /// Starting address offset to read from
    #[cfg_attr(feature = "serde", serde(rename(serialize = "addr_start")))]
    pub addr_start: [u8; 3],
    /// Length of set of addresses to read, counting up from starting address
    #[cfg_attr(feature = "serde", serde(rename(serialize = "addr_len")))]
    pub addr_len: u8,
}

impl ConcreteMessage for MsgFlashReadResp {
    const MESSAGE_TYPE: u16 = 225;
    const MESSAGE_NAME: &'static str = "MSG_FLASH_READ_RESP";
}

impl SbpMessage for MsgFlashReadResp {
    fn message_name(&self) -> &'static str {
        <Self as ConcreteMessage>::MESSAGE_NAME
    }
    fn message_type(&self) -> u16 {
        <Self as ConcreteMessage>::MESSAGE_TYPE
    }
    fn sender_id(&self) -> Option<u16> {
        self.sender_id
    }
    fn set_sender_id(&mut self, new_id: u16) {
        self.sender_id = Some(new_id);
    }
    fn encoded_len(&self) -> usize {
        WireFormat::len(self) + crate::HEADER_LEN + crate::CRC_LEN
    }
}

impl TryFrom<Sbp> for MsgFlashReadResp {
    type Error = TryFromSbpError;
    fn try_from(msg: Sbp) -> Result<Self, Self::Error> {
        match msg {
            Sbp::MsgFlashReadResp(m) => Ok(m),
            _ => Err(TryFromSbpError),
        }
    }
}

impl WireFormat for MsgFlashReadResp {
    const MIN_LEN: usize = <u8 as WireFormat>::MIN_LEN
        + <[u8; 3] as WireFormat>::MIN_LEN
        + <u8 as WireFormat>::MIN_LEN;
    fn len(&self) -> usize {
        WireFormat::len(&self.target)
            + WireFormat::len(&self.addr_start)
            + WireFormat::len(&self.addr_len)
    }
    fn write<B: BufMut>(&self, buf: &mut B) {
        WireFormat::write(&self.target, buf);
        WireFormat::write(&self.addr_start, buf);
        WireFormat::write(&self.addr_len, buf);
    }
    fn parse_unchecked<B: Buf>(buf: &mut B) -> Self {
        MsgFlashReadResp {
            sender_id: None,
            target: WireFormat::parse_unchecked(buf),
            addr_start: WireFormat::parse_unchecked(buf),
            addr_len: WireFormat::parse_unchecked(buf),
        }
    }
}

/// Write M25 flash status register (host => device)
///
/// The flash status message writes to the 8-bit M25 flash status register.
/// The device replies with a MSG_FLASH_DONE message.
///
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[derive(Debug, Clone)]
pub struct MsgM25FlashWriteStatus {
    /// The message sender_id
    #[cfg_attr(feature = "serde", serde(skip_serializing))]
    pub sender_id: Option<u16>,
    /// Byte to write to the M25 flash status register
    #[cfg_attr(feature = "serde", serde(rename(serialize = "status")))]
    pub status: [u8; 1],
}

impl ConcreteMessage for MsgM25FlashWriteStatus {
    const MESSAGE_TYPE: u16 = 243;
    const MESSAGE_NAME: &'static str = "MSG_M25_FLASH_WRITE_STATUS";
}

impl SbpMessage for MsgM25FlashWriteStatus {
    fn message_name(&self) -> &'static str {
        <Self as ConcreteMessage>::MESSAGE_NAME
    }
    fn message_type(&self) -> u16 {
        <Self as ConcreteMessage>::MESSAGE_TYPE
    }
    fn sender_id(&self) -> Option<u16> {
        self.sender_id
    }
    fn set_sender_id(&mut self, new_id: u16) {
        self.sender_id = Some(new_id);
    }
    fn encoded_len(&self) -> usize {
        WireFormat::len(self) + crate::HEADER_LEN + crate::CRC_LEN
    }
}

impl TryFrom<Sbp> for MsgM25FlashWriteStatus {
    type Error = TryFromSbpError;
    fn try_from(msg: Sbp) -> Result<Self, Self::Error> {
        match msg {
            Sbp::MsgM25FlashWriteStatus(m) => Ok(m),
            _ => Err(TryFromSbpError),
        }
    }
}

impl WireFormat for MsgM25FlashWriteStatus {
    const MIN_LEN: usize = <[u8; 1] as WireFormat>::MIN_LEN;
    fn len(&self) -> usize {
        WireFormat::len(&self.status)
    }
    fn write<B: BufMut>(&self, buf: &mut B) {
        WireFormat::write(&self.status, buf);
    }
    fn parse_unchecked<B: Buf>(buf: &mut B) -> Self {
        MsgM25FlashWriteStatus {
            sender_id: None,
            status: WireFormat::parse_unchecked(buf),
        }
    }
}

/// Lock sector of STM flash memory (host => device)
///
/// The flash lock message locks a sector of the STM flash memory. The device
/// replies with a MSG_FLASH_DONE message.
///
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[derive(Debug, Clone)]
pub struct MsgStmFlashLockSector {
    /// The message sender_id
    #[cfg_attr(feature = "serde", serde(skip_serializing))]
    pub sender_id: Option<u16>,
    /// Flash sector number to lock
    #[cfg_attr(feature = "serde", serde(rename(serialize = "sector")))]
    pub sector: u32,
}

impl ConcreteMessage for MsgStmFlashLockSector {
    const MESSAGE_TYPE: u16 = 227;
    const MESSAGE_NAME: &'static str = "MSG_STM_FLASH_LOCK_SECTOR";
}

impl SbpMessage for MsgStmFlashLockSector {
    fn message_name(&self) -> &'static str {
        <Self as ConcreteMessage>::MESSAGE_NAME
    }
    fn message_type(&self) -> u16 {
        <Self as ConcreteMessage>::MESSAGE_TYPE
    }
    fn sender_id(&self) -> Option<u16> {
        self.sender_id
    }
    fn set_sender_id(&mut self, new_id: u16) {
        self.sender_id = Some(new_id);
    }
    fn encoded_len(&self) -> usize {
        WireFormat::len(self) + crate::HEADER_LEN + crate::CRC_LEN
    }
}

impl TryFrom<Sbp> for MsgStmFlashLockSector {
    type Error = TryFromSbpError;
    fn try_from(msg: Sbp) -> Result<Self, Self::Error> {
        match msg {
            Sbp::MsgStmFlashLockSector(m) => Ok(m),
            _ => Err(TryFromSbpError),
        }
    }
}

impl WireFormat for MsgStmFlashLockSector {
    const MIN_LEN: usize = <u32 as WireFormat>::MIN_LEN;
    fn len(&self) -> usize {
        WireFormat::len(&self.sector)
    }
    fn write<B: BufMut>(&self, buf: &mut B) {
        WireFormat::write(&self.sector, buf);
    }
    fn parse_unchecked<B: Buf>(buf: &mut B) -> Self {
        MsgStmFlashLockSector {
            sender_id: None,
            sector: WireFormat::parse_unchecked(buf),
        }
    }
}

/// Unlock sector of STM flash memory (host => device)
///
/// The flash unlock message unlocks a sector of the STM flash memory. The
/// device replies with a MSG_FLASH_DONE message.
///
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[derive(Debug, Clone)]
pub struct MsgStmFlashUnlockSector {
    /// The message sender_id
    #[cfg_attr(feature = "serde", serde(skip_serializing))]
    pub sender_id: Option<u16>,
    /// Flash sector number to unlock
    #[cfg_attr(feature = "serde", serde(rename(serialize = "sector")))]
    pub sector: u32,
}

impl ConcreteMessage for MsgStmFlashUnlockSector {
    const MESSAGE_TYPE: u16 = 228;
    const MESSAGE_NAME: &'static str = "MSG_STM_FLASH_UNLOCK_SECTOR";
}

impl SbpMessage for MsgStmFlashUnlockSector {
    fn message_name(&self) -> &'static str {
        <Self as ConcreteMessage>::MESSAGE_NAME
    }
    fn message_type(&self) -> u16 {
        <Self as ConcreteMessage>::MESSAGE_TYPE
    }
    fn sender_id(&self) -> Option<u16> {
        self.sender_id
    }
    fn set_sender_id(&mut self, new_id: u16) {
        self.sender_id = Some(new_id);
    }
    fn encoded_len(&self) -> usize {
        WireFormat::len(self) + crate::HEADER_LEN + crate::CRC_LEN
    }
}

impl TryFrom<Sbp> for MsgStmFlashUnlockSector {
    type Error = TryFromSbpError;
    fn try_from(msg: Sbp) -> Result<Self, Self::Error> {
        match msg {
            Sbp::MsgStmFlashUnlockSector(m) => Ok(m),
            _ => Err(TryFromSbpError),
        }
    }
}

impl WireFormat for MsgStmFlashUnlockSector {
    const MIN_LEN: usize = <u32 as WireFormat>::MIN_LEN;
    fn len(&self) -> usize {
        WireFormat::len(&self.sector)
    }
    fn write<B: BufMut>(&self, buf: &mut B) {
        WireFormat::write(&self.sector, buf);
    }
    fn parse_unchecked<B: Buf>(buf: &mut B) -> Self {
        MsgStmFlashUnlockSector {
            sender_id: None,
            sector: WireFormat::parse_unchecked(buf),
        }
    }
}

/// Read device's hard-coded unique ID request (host => device)

///
/// This message reads the device's hard-coded unique ID. The host requests
/// the ID by sending a MSG_STM_UNIQUE_ID_REQ. The device responds with a
/// MSG_STM_UNIQUE_ID_RESP with the 12-byte unique ID in the payload.
///
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[derive(Debug, Clone)]
pub struct MsgStmUniqueIdReq {
    /// The message sender_id
    #[cfg_attr(feature = "serde", serde(skip_serializing))]
    pub sender_id: Option<u16>,
}

impl ConcreteMessage for MsgStmUniqueIdReq {
    const MESSAGE_TYPE: u16 = 232;
    const MESSAGE_NAME: &'static str = "MSG_STM_UNIQUE_ID_REQ";
}

impl SbpMessage for MsgStmUniqueIdReq {
    fn message_name(&self) -> &'static str {
        <Self as ConcreteMessage>::MESSAGE_NAME
    }
    fn message_type(&self) -> u16 {
        <Self as ConcreteMessage>::MESSAGE_TYPE
    }
    fn sender_id(&self) -> Option<u16> {
        self.sender_id
    }
    fn set_sender_id(&mut self, new_id: u16) {
        self.sender_id = Some(new_id);
    }
    fn encoded_len(&self) -> usize {
        WireFormat::len(self) + crate::HEADER_LEN + crate::CRC_LEN
    }
}

impl TryFrom<Sbp> for MsgStmUniqueIdReq {
    type Error = TryFromSbpError;
    fn try_from(msg: Sbp) -> Result<Self, Self::Error> {
        match msg {
            Sbp::MsgStmUniqueIdReq(m) => Ok(m),
            _ => Err(TryFromSbpError),
        }
    }
}

impl WireFormat for MsgStmUniqueIdReq {
    const MIN_LEN: usize = 0;
    fn len(&self) -> usize {
        0
    }
    fn write<B: BufMut>(&self, _buf: &mut B) {}
    fn parse_unchecked<B: Buf>(_buf: &mut B) -> Self {
        MsgStmUniqueIdReq { sender_id: None }
    }
}

/// Read device's hard-coded unique ID response (host <= device)

///
/// This message reads the device's hard-coded unique ID. The host requests
/// the ID by sending a MSG_STM_UNIQUE_ID_REQ. The device responds with a
/// MSG_STM_UNIQUE_ID_RESP with the 12-byte unique ID in the payload.
///
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[derive(Debug, Clone)]
pub struct MsgStmUniqueIdResp {
    /// The message sender_id
    #[cfg_attr(feature = "serde", serde(skip_serializing))]
    pub sender_id: Option<u16>,
    /// Device unique ID
    #[cfg_attr(feature = "serde", serde(rename(serialize = "stm_id")))]
    pub stm_id: [u8; 12],
}

impl ConcreteMessage for MsgStmUniqueIdResp {
    const MESSAGE_TYPE: u16 = 229;
    const MESSAGE_NAME: &'static str = "MSG_STM_UNIQUE_ID_RESP";
}

impl SbpMessage for MsgStmUniqueIdResp {
    fn message_name(&self) -> &'static str {
        <Self as ConcreteMessage>::MESSAGE_NAME
    }
    fn message_type(&self) -> u16 {
        <Self as ConcreteMessage>::MESSAGE_TYPE
    }
    fn sender_id(&self) -> Option<u16> {
        self.sender_id
    }
    fn set_sender_id(&mut self, new_id: u16) {
        self.sender_id = Some(new_id);
    }
    fn encoded_len(&self) -> usize {
        WireFormat::len(self) + crate::HEADER_LEN + crate::CRC_LEN
    }
}

impl TryFrom<Sbp> for MsgStmUniqueIdResp {
    type Error = TryFromSbpError;
    fn try_from(msg: Sbp) -> Result<Self, Self::Error> {
        match msg {
            Sbp::MsgStmUniqueIdResp(m) => Ok(m),
            _ => Err(TryFromSbpError),
        }
    }
}

impl WireFormat for MsgStmUniqueIdResp {
    const MIN_LEN: usize = <[u8; 12] as WireFormat>::MIN_LEN;
    fn len(&self) -> usize {
        WireFormat::len(&self.stm_id)
    }
    fn write<B: BufMut>(&self, buf: &mut B) {
        WireFormat::write(&self.stm_id, buf);
    }
    fn parse_unchecked<B: Buf>(buf: &mut B) -> Self {
        MsgStmUniqueIdResp {
            sender_id: None,
            stm_id: WireFormat::parse_unchecked(buf),
        }
    }
}