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
// 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/file_io.yaml
// with generate.py. Please do not hand edit!
//****************************************************************************/
//! Messages for using device's onboard flash filesystem functionality. This
//! allows data to be stored persistently in the device's program flash with
//! wear-levelling using a simple filesystem interface. The file system
//! interface (CFS) defines an abstract API for reading directories and for
//! reading and writing files.
//!
//! Note that some of these messages share the same message type ID for both
//! the host request and the device response.

use super::lib::*;

/// Request advice on the optimal configuration for FileIO
///
/// Requests advice on the optimal configuration for a FileIO transfer.  Newer
/// version of FileIO can support greater throughput by supporting a large
/// window of FileIO data that can be in-flight during read or write
/// operations.
///
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[derive(Debug, Clone)]
pub struct MsgFileioConfigReq {
    /// The message sender_id
    #[cfg_attr(feature = "serde", serde(skip_serializing))]
    pub sender_id: Option<u16>,
    /// Advice sequence number
    #[cfg_attr(feature = "serde", serde(rename(serialize = "sequence")))]
    pub sequence: u32,
}

impl ConcreteMessage for MsgFileioConfigReq {
    const MESSAGE_TYPE: u16 = 4097;
    const MESSAGE_NAME: &'static str = "MSG_FILEIO_CONFIG_REQ";
}

impl SbpMessage for MsgFileioConfigReq {
    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 MsgFileioConfigReq {
    type Error = TryFromSbpError;
    fn try_from(msg: Sbp) -> Result<Self, Self::Error> {
        match msg {
            Sbp::MsgFileioConfigReq(m) => Ok(m),
            _ => Err(TryFromSbpError),
        }
    }
}

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

/// Response with advice on the optimal configuration for FileIO.

///
/// The advice on the optimal configuration for a FileIO transfer.  Newer
/// version of FileIO can support greater throughput by supporting a large
/// window of FileIO data that can be in-flight during read or write
/// operations.
///
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[derive(Debug, Clone)]
pub struct MsgFileioConfigResp {
    /// The message sender_id
    #[cfg_attr(feature = "serde", serde(skip_serializing))]
    pub sender_id: Option<u16>,
    /// Advice sequence number
    #[cfg_attr(feature = "serde", serde(rename(serialize = "sequence")))]
    pub sequence: u32,
    /// The number of SBP packets in the data in-flight window
    #[cfg_attr(feature = "serde", serde(rename(serialize = "window_size")))]
    pub window_size: u32,
    /// The number of SBP packets sent in one PDU
    #[cfg_attr(feature = "serde", serde(rename(serialize = "batch_size")))]
    pub batch_size: u32,
    /// The version of FileIO that is supported
    #[cfg_attr(feature = "serde", serde(rename(serialize = "fileio_version")))]
    pub fileio_version: u32,
}

impl ConcreteMessage for MsgFileioConfigResp {
    const MESSAGE_TYPE: u16 = 4098;
    const MESSAGE_NAME: &'static str = "MSG_FILEIO_CONFIG_RESP";
}

impl SbpMessage for MsgFileioConfigResp {
    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 MsgFileioConfigResp {
    type Error = TryFromSbpError;
    fn try_from(msg: Sbp) -> Result<Self, Self::Error> {
        match msg {
            Sbp::MsgFileioConfigResp(m) => Ok(m),
            _ => Err(TryFromSbpError),
        }
    }
}

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

/// List files in a directory (host => device)
///
/// The read directory message lists the files in a directory on the device's
/// onboard flash file system.  The offset parameter can be used to skip the
/// first n elements of the file list. Returns a MSG_FILEIO_READ_DIR_RESP
/// message containing the directory listings as a NULL delimited list. The
/// listing is chunked over multiple SBP packets. The sequence number in the
/// request will be returned in the response.  If message is invalid, a
/// followup MSG_PRINT message will print "Invalid fileio read message". A
/// device will only respond to this message when it is received from sender
/// ID 0x42.
///
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[derive(Debug, Clone)]
pub struct MsgFileioReadDirReq {
    /// The message sender_id
    #[cfg_attr(feature = "serde", serde(skip_serializing))]
    pub sender_id: Option<u16>,
    /// Read sequence number
    #[cfg_attr(feature = "serde", serde(rename(serialize = "sequence")))]
    pub sequence: u32,
    /// The offset to skip the first n elements of the file list
    #[cfg_attr(feature = "serde", serde(rename(serialize = "offset")))]
    pub offset: u32,
    /// Name of the directory to list
    #[cfg_attr(feature = "serde", serde(rename(serialize = "dirname")))]
    pub dirname: SbpString<Vec<u8>, NullTerminated>,
}

impl ConcreteMessage for MsgFileioReadDirReq {
    const MESSAGE_TYPE: u16 = 169;
    const MESSAGE_NAME: &'static str = "MSG_FILEIO_READ_DIR_REQ";
}

impl SbpMessage for MsgFileioReadDirReq {
    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 MsgFileioReadDirReq {
    type Error = TryFromSbpError;
    fn try_from(msg: Sbp) -> Result<Self, Self::Error> {
        match msg {
            Sbp::MsgFileioReadDirReq(m) => Ok(m),
            _ => Err(TryFromSbpError),
        }
    }
}

impl WireFormat for MsgFileioReadDirReq {
    const MIN_LEN: usize = <u32 as WireFormat>::MIN_LEN
        + <u32 as WireFormat>::MIN_LEN
        + <SbpString<Vec<u8>, NullTerminated> as WireFormat>::MIN_LEN;
    fn len(&self) -> usize {
        WireFormat::len(&self.sequence)
            + WireFormat::len(&self.offset)
            + WireFormat::len(&self.dirname)
    }
    fn write<B: BufMut>(&self, buf: &mut B) {
        WireFormat::write(&self.sequence, buf);
        WireFormat::write(&self.offset, buf);
        WireFormat::write(&self.dirname, buf);
    }
    fn parse_unchecked<B: Buf>(buf: &mut B) -> Self {
        MsgFileioReadDirReq {
            sender_id: None,
            sequence: WireFormat::parse_unchecked(buf),
            offset: WireFormat::parse_unchecked(buf),
            dirname: WireFormat::parse_unchecked(buf),
        }
    }
}

/// Files listed in a directory (host <= device)
///
/// The read directory message lists the files in a directory on the device's
/// onboard flash file system. Message contains the directory listings as a
/// NULL delimited list. The listing is chunked over multiple SBP packets and
/// the end of the list is identified by an packet with no entries. The
/// sequence number in the response is preserved from the request.
///
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[derive(Debug, Clone)]
pub struct MsgFileioReadDirResp {
    /// The message sender_id
    #[cfg_attr(feature = "serde", serde(skip_serializing))]
    pub sender_id: Option<u16>,
    /// Read sequence number
    #[cfg_attr(feature = "serde", serde(rename(serialize = "sequence")))]
    pub sequence: u32,
    /// Contents of read directory
    #[cfg_attr(feature = "serde", serde(rename(serialize = "contents")))]
    pub contents: Vec<u8>,
}

impl ConcreteMessage for MsgFileioReadDirResp {
    const MESSAGE_TYPE: u16 = 170;
    const MESSAGE_NAME: &'static str = "MSG_FILEIO_READ_DIR_RESP";
}

impl SbpMessage for MsgFileioReadDirResp {
    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 MsgFileioReadDirResp {
    type Error = TryFromSbpError;
    fn try_from(msg: Sbp) -> Result<Self, Self::Error> {
        match msg {
            Sbp::MsgFileioReadDirResp(m) => Ok(m),
            _ => Err(TryFromSbpError),
        }
    }
}

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

/// Read file from the file system (host => device)
///
/// The file read message reads a certain length (up to 255 bytes) from a
/// given offset into a file, and returns the data in a MSG_FILEIO_READ_RESP
/// message where the message length field indicates how many bytes were
/// successfully read. The sequence number in the request will be returned in
/// the response. If the message is invalid, a followup MSG_PRINT message will
/// print "Invalid fileio read message". A device will only respond to this
/// message when it is received from sender ID 0x42.
///
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[derive(Debug, Clone)]
pub struct MsgFileioReadReq {
    /// The message sender_id
    #[cfg_attr(feature = "serde", serde(skip_serializing))]
    pub sender_id: Option<u16>,
    /// Read sequence number
    #[cfg_attr(feature = "serde", serde(rename(serialize = "sequence")))]
    pub sequence: u32,
    /// File offset
    #[cfg_attr(feature = "serde", serde(rename(serialize = "offset")))]
    pub offset: u32,
    /// Chunk size to read
    #[cfg_attr(feature = "serde", serde(rename(serialize = "chunk_size")))]
    pub chunk_size: u8,
    /// Name of the file to read from
    #[cfg_attr(feature = "serde", serde(rename(serialize = "filename")))]
    pub filename: SbpString<Vec<u8>, NullTerminated>,
}

impl ConcreteMessage for MsgFileioReadReq {
    const MESSAGE_TYPE: u16 = 168;
    const MESSAGE_NAME: &'static str = "MSG_FILEIO_READ_REQ";
}

impl SbpMessage for MsgFileioReadReq {
    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 MsgFileioReadReq {
    type Error = TryFromSbpError;
    fn try_from(msg: Sbp) -> Result<Self, Self::Error> {
        match msg {
            Sbp::MsgFileioReadReq(m) => Ok(m),
            _ => Err(TryFromSbpError),
        }
    }
}

impl WireFormat for MsgFileioReadReq {
    const MIN_LEN: usize = <u32 as WireFormat>::MIN_LEN
        + <u32 as WireFormat>::MIN_LEN
        + <u8 as WireFormat>::MIN_LEN
        + <SbpString<Vec<u8>, NullTerminated> as WireFormat>::MIN_LEN;
    fn len(&self) -> usize {
        WireFormat::len(&self.sequence)
            + WireFormat::len(&self.offset)
            + WireFormat::len(&self.chunk_size)
            + WireFormat::len(&self.filename)
    }
    fn write<B: BufMut>(&self, buf: &mut B) {
        WireFormat::write(&self.sequence, buf);
        WireFormat::write(&self.offset, buf);
        WireFormat::write(&self.chunk_size, buf);
        WireFormat::write(&self.filename, buf);
    }
    fn parse_unchecked<B: Buf>(buf: &mut B) -> Self {
        MsgFileioReadReq {
            sender_id: None,
            sequence: WireFormat::parse_unchecked(buf),
            offset: WireFormat::parse_unchecked(buf),
            chunk_size: WireFormat::parse_unchecked(buf),
            filename: WireFormat::parse_unchecked(buf),
        }
    }
}

/// File read from the file system (host <= device)
///
/// The file read message reads a certain length (up to 255 bytes) from a
/// given offset into a file, and returns the data in a message where the
/// message length field indicates how many bytes were successfully read. The
/// sequence number in the response is preserved from the request.
///
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[derive(Debug, Clone)]
pub struct MsgFileioReadResp {
    /// The message sender_id
    #[cfg_attr(feature = "serde", serde(skip_serializing))]
    pub sender_id: Option<u16>,
    /// Read sequence number
    #[cfg_attr(feature = "serde", serde(rename(serialize = "sequence")))]
    pub sequence: u32,
    /// Contents of read file
    #[cfg_attr(feature = "serde", serde(rename(serialize = "contents")))]
    pub contents: Vec<u8>,
}

impl ConcreteMessage for MsgFileioReadResp {
    const MESSAGE_TYPE: u16 = 163;
    const MESSAGE_NAME: &'static str = "MSG_FILEIO_READ_RESP";
}

impl SbpMessage for MsgFileioReadResp {
    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 MsgFileioReadResp {
    type Error = TryFromSbpError;
    fn try_from(msg: Sbp) -> Result<Self, Self::Error> {
        match msg {
            Sbp::MsgFileioReadResp(m) => Ok(m),
            _ => Err(TryFromSbpError),
        }
    }
}

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

/// Delete a file from the file system (host => device)
///
/// The file remove message deletes a file from the file system. If the
/// message is invalid, a followup MSG_PRINT message will print "Invalid
/// fileio remove message". A device will only process this message when it is
/// received from sender ID 0x42.
///
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[derive(Debug, Clone)]
pub struct MsgFileioRemove {
    /// The message sender_id
    #[cfg_attr(feature = "serde", serde(skip_serializing))]
    pub sender_id: Option<u16>,
    /// Name of the file to delete
    #[cfg_attr(feature = "serde", serde(rename(serialize = "filename")))]
    pub filename: SbpString<Vec<u8>, NullTerminated>,
}

impl ConcreteMessage for MsgFileioRemove {
    const MESSAGE_TYPE: u16 = 172;
    const MESSAGE_NAME: &'static str = "MSG_FILEIO_REMOVE";
}

impl SbpMessage for MsgFileioRemove {
    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 MsgFileioRemove {
    type Error = TryFromSbpError;
    fn try_from(msg: Sbp) -> Result<Self, Self::Error> {
        match msg {
            Sbp::MsgFileioRemove(m) => Ok(m),
            _ => Err(TryFromSbpError),
        }
    }
}

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

/// Write to file (host => device)
///
/// The file write message writes a certain length (up to 255 bytes) of data
/// to a file at a given offset. Returns a copy of the original
/// MSG_FILEIO_WRITE_RESP message to check integrity of the write. The
/// sequence number in the request will be returned in the response. If
/// message is invalid, a followup MSG_PRINT message will print "Invalid
/// fileio write message". A device will only process this message when it is
/// received from sender ID 0x42.
///
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[derive(Debug, Clone)]
pub struct MsgFileioWriteReq {
    /// The message sender_id
    #[cfg_attr(feature = "serde", serde(skip_serializing))]
    pub sender_id: Option<u16>,
    /// Write sequence number
    #[cfg_attr(feature = "serde", serde(rename(serialize = "sequence")))]
    pub sequence: u32,
    /// Offset into the file at which to start writing in bytes
    #[cfg_attr(feature = "serde", serde(rename(serialize = "offset")))]
    pub offset: u32,
    /// Name of the file to write to
    #[cfg_attr(feature = "serde", serde(rename(serialize = "filename")))]
    pub filename: SbpString<Vec<u8>, NullTerminated>,
    /// Variable-length array of data to write
    #[cfg_attr(feature = "serde", serde(rename(serialize = "data")))]
    pub data: Vec<u8>,
}

impl ConcreteMessage for MsgFileioWriteReq {
    const MESSAGE_TYPE: u16 = 173;
    const MESSAGE_NAME: &'static str = "MSG_FILEIO_WRITE_REQ";
}

impl SbpMessage for MsgFileioWriteReq {
    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 MsgFileioWriteReq {
    type Error = TryFromSbpError;
    fn try_from(msg: Sbp) -> Result<Self, Self::Error> {
        match msg {
            Sbp::MsgFileioWriteReq(m) => Ok(m),
            _ => Err(TryFromSbpError),
        }
    }
}

impl WireFormat for MsgFileioWriteReq {
    const MIN_LEN: usize = <u32 as WireFormat>::MIN_LEN
        + <u32 as WireFormat>::MIN_LEN
        + <SbpString<Vec<u8>, NullTerminated> as WireFormat>::MIN_LEN
        + <Vec<u8> as WireFormat>::MIN_LEN;
    fn len(&self) -> usize {
        WireFormat::len(&self.sequence)
            + WireFormat::len(&self.offset)
            + WireFormat::len(&self.filename)
            + WireFormat::len(&self.data)
    }
    fn write<B: BufMut>(&self, buf: &mut B) {
        WireFormat::write(&self.sequence, buf);
        WireFormat::write(&self.offset, buf);
        WireFormat::write(&self.filename, buf);
        WireFormat::write(&self.data, buf);
    }
    fn parse_unchecked<B: Buf>(buf: &mut B) -> Self {
        MsgFileioWriteReq {
            sender_id: None,
            sequence: WireFormat::parse_unchecked(buf),
            offset: WireFormat::parse_unchecked(buf),
            filename: WireFormat::parse_unchecked(buf),
            data: WireFormat::parse_unchecked(buf),
        }
    }
}

/// File written to (host <= device)
///
/// The file write message writes a certain length (up to 255 bytes) of data
/// to a file at a given offset. The message is a copy of the original
/// MSG_FILEIO_WRITE_REQ message to check integrity of the write. The sequence
/// number in the response is preserved from the request.
///
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[derive(Debug, Clone)]
pub struct MsgFileioWriteResp {
    /// The message sender_id
    #[cfg_attr(feature = "serde", serde(skip_serializing))]
    pub sender_id: Option<u16>,
    /// Write sequence number
    #[cfg_attr(feature = "serde", serde(rename(serialize = "sequence")))]
    pub sequence: u32,
}

impl ConcreteMessage for MsgFileioWriteResp {
    const MESSAGE_TYPE: u16 = 171;
    const MESSAGE_NAME: &'static str = "MSG_FILEIO_WRITE_RESP";
}

impl SbpMessage for MsgFileioWriteResp {
    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 MsgFileioWriteResp {
    type Error = TryFromSbpError;
    fn try_from(msg: Sbp) -> Result<Self, Self::Error> {
        match msg {
            Sbp::MsgFileioWriteResp(m) => Ok(m),
            _ => Err(TryFromSbpError),
        }
    }
}

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