sbp/messages/
flash.rs

1// Copyright (C) 2015-2021 Swift Navigation Inc.
2// Contact: https://support.swiftnav.com
3//
4// This source is subject to the license found in the file 'LICENSE' which must
5// be distributed together with this source. All other rights reserved.
6//
7// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
8// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
9// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
10
11//****************************************************************************
12// Automatically generated from yaml/swiftnav/sbp/flash.yaml
13// with generate.py. Please do not hand edit!
14//****************************************************************************/
15//! Messages for reading/writing the device's onboard flash memory. Many of
16//! these messages target specific flash memory peripherals used in Swift
17//! Navigation devices: the STM32 flash and the M25Pxx FPGA configuration
18//! flash from Piksi 2.3.1.  This module does not apply to Piksi Multi.
19pub use msg_flash_done::MsgFlashDone;
20pub use msg_flash_erase::MsgFlashErase;
21pub use msg_flash_program::MsgFlashProgram;
22pub use msg_flash_read_req::MsgFlashReadReq;
23pub use msg_flash_read_resp::MsgFlashReadResp;
24pub use msg_m25_flash_write_status::MsgM25FlashWriteStatus;
25pub use msg_stm_flash_lock_sector::MsgStmFlashLockSector;
26pub use msg_stm_flash_unlock_sector::MsgStmFlashUnlockSector;
27pub use msg_stm_unique_id_req::MsgStmUniqueIdReq;
28pub use msg_stm_unique_id_resp::MsgStmUniqueIdResp;
29
30pub mod msg_flash_done {
31    #![allow(unused_imports)]
32
33    use super::*;
34    use crate::messages::lib::*;
35
36    /// Flash response message (host <= device)
37    ///
38    /// This message defines success or failure codes for a variety of flash
39    /// memory requests from the host to the device. Flash read and write
40    /// messages, such as MSG_FLASH_READ_REQ, or MSG_FLASH_PROGRAM, may return
41    /// this message on failure.
42    ///
43    #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
44    #[allow(clippy::derive_partial_eq_without_eq)]
45    #[derive(Debug, PartialEq, Clone)]
46    pub struct MsgFlashDone {
47        /// The message sender_id
48        #[cfg_attr(feature = "serde", serde(skip_serializing, alias = "sender"))]
49        pub sender_id: Option<u16>,
50        /// Response flags
51        #[cfg_attr(feature = "serde", serde(rename = "response"))]
52        pub response: u8,
53    }
54
55    impl MsgFlashDone {
56        /// Gets the [ResponseCode][self::ResponseCode] stored in the `response` bitfield.
57        ///
58        /// Returns `Ok` if the bitrange contains a known `ResponseCode` variant.
59        /// Otherwise the value of the bitrange is returned as an `Err(u8)`. This may be because of a malformed message,
60        /// or because new variants of `ResponseCode` were added.
61        pub fn response_code(&self) -> Result<ResponseCode, u8> {
62            get_bit_range!(self.response, u8, u8, 2, 0).try_into()
63        }
64
65        /// Set the bitrange corresponding to the [ResponseCode][ResponseCode] of the `response` bitfield.
66        pub fn set_response_code(&mut self, response_code: ResponseCode) {
67            set_bit_range!(&mut self.response, response_code, u8, u8, 2, 0);
68        }
69    }
70
71    impl ConcreteMessage for MsgFlashDone {
72        const MESSAGE_TYPE: u16 = 224;
73        const MESSAGE_NAME: &'static str = "MSG_FLASH_DONE";
74    }
75
76    impl SbpMessage for MsgFlashDone {
77        fn message_name(&self) -> &'static str {
78            <Self as ConcreteMessage>::MESSAGE_NAME
79        }
80        fn message_type(&self) -> Option<u16> {
81            Some(<Self as ConcreteMessage>::MESSAGE_TYPE)
82        }
83        fn sender_id(&self) -> Option<u16> {
84            self.sender_id
85        }
86        fn set_sender_id(&mut self, new_id: u16) {
87            self.sender_id = Some(new_id);
88        }
89        fn encoded_len(&self) -> usize {
90            WireFormat::len(self) + crate::HEADER_LEN + crate::CRC_LEN
91        }
92        fn is_valid(&self) -> bool {
93            true
94        }
95        fn into_valid_msg(self) -> Result<Self, crate::messages::invalid::Invalid> {
96            Ok(self)
97        }
98    }
99
100    impl FriendlyName for MsgFlashDone {
101        fn friendly_name() -> &'static str {
102            "FLASH DONE"
103        }
104    }
105
106    impl TryFrom<Sbp> for MsgFlashDone {
107        type Error = TryFromSbpError;
108        fn try_from(msg: Sbp) -> Result<Self, Self::Error> {
109            match msg {
110                Sbp::MsgFlashDone(m) => Ok(m),
111                _ => Err(TryFromSbpError(msg)),
112            }
113        }
114    }
115
116    impl WireFormat for MsgFlashDone {
117        const MIN_LEN: usize = <u8 as WireFormat>::MIN_LEN;
118        fn len(&self) -> usize {
119            WireFormat::len(&self.response)
120        }
121        fn write<B: BufMut>(&self, buf: &mut B) {
122            WireFormat::write(&self.response, buf);
123        }
124        fn parse_unchecked<B: Buf>(buf: &mut B) -> Self {
125            MsgFlashDone {
126                sender_id: None,
127                response: WireFormat::parse_unchecked(buf),
128            }
129        }
130    }
131
132    /// Response code
133    #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
134    pub enum ResponseCode {
135        /// FLASH_OK
136        FlashOk = 0,
137
138        /// FLASH_INVALID_FLASH
139        FlashInvalidFlash = 1,
140
141        /// FLASH_INVALID_LEN
142        FlashInvalidLen = 2,
143
144        /// FLASH_INVALID_ADDR
145        FlashInvalidAddr = 3,
146
147        /// FLASH_INVALID_RANGE
148        FlashInvalidRange = 4,
149
150        /// FLASH_INVALID_SECTOR
151        FlashInvalidSector = 5,
152    }
153
154    impl std::fmt::Display for ResponseCode {
155        fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
156            match self {
157                ResponseCode::FlashOk => f.write_str("FLASH_OK"),
158                ResponseCode::FlashInvalidFlash => f.write_str("FLASH_INVALID_FLASH"),
159                ResponseCode::FlashInvalidLen => f.write_str("FLASH_INVALID_LEN"),
160                ResponseCode::FlashInvalidAddr => f.write_str("FLASH_INVALID_ADDR"),
161                ResponseCode::FlashInvalidRange => f.write_str("FLASH_INVALID_RANGE"),
162                ResponseCode::FlashInvalidSector => f.write_str("FLASH_INVALID_SECTOR"),
163            }
164        }
165    }
166
167    impl TryFrom<u8> for ResponseCode {
168        type Error = u8;
169        fn try_from(i: u8) -> Result<Self, u8> {
170            match i {
171                0 => Ok(ResponseCode::FlashOk),
172                1 => Ok(ResponseCode::FlashInvalidFlash),
173                2 => Ok(ResponseCode::FlashInvalidLen),
174                3 => Ok(ResponseCode::FlashInvalidAddr),
175                4 => Ok(ResponseCode::FlashInvalidRange),
176                5 => Ok(ResponseCode::FlashInvalidSector),
177                i => Err(i),
178            }
179        }
180    }
181}
182
183pub mod msg_flash_erase {
184    #![allow(unused_imports)]
185
186    use super::*;
187    use crate::messages::lib::*;
188
189    /// Erase sector of device flash memory (host => device)
190    ///
191    /// The flash erase message from the host erases a sector of either the STM or
192    /// M25 onboard flash memory. The device will reply with a MSG_FLASH_DONE
193    /// message containing the return code - FLASH_OK (0) on success or
194    /// FLASH_INVALID_FLASH (1) if the flash specified is invalid.
195    ///
196    #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
197    #[allow(clippy::derive_partial_eq_without_eq)]
198    #[derive(Debug, PartialEq, Clone)]
199    pub struct MsgFlashErase {
200        /// The message sender_id
201        #[cfg_attr(feature = "serde", serde(skip_serializing, alias = "sender"))]
202        pub sender_id: Option<u16>,
203        /// Target flags
204        #[cfg_attr(feature = "serde", serde(rename = "target"))]
205        pub target: u8,
206        /// Flash sector number to erase (0-11 for the STM, 0-15 for the M25)
207        #[cfg_attr(feature = "serde", serde(rename = "sector_num"))]
208        pub sector_num: u32,
209    }
210
211    impl MsgFlashErase {
212        /// Gets the [FlashTargetToRead][self::FlashTargetToRead] stored in the `target` bitfield.
213        ///
214        /// Returns `Ok` if the bitrange contains a known `FlashTargetToRead` variant.
215        /// Otherwise the value of the bitrange is returned as an `Err(u8)`. This may be because of a malformed message,
216        /// or because new variants of `FlashTargetToRead` were added.
217        pub fn flash_target_to_read(&self) -> Result<FlashTargetToRead, u8> {
218            get_bit_range!(self.target, u8, u8, 0, 0).try_into()
219        }
220
221        /// Set the bitrange corresponding to the [FlashTargetToRead][FlashTargetToRead] of the `target` bitfield.
222        pub fn set_flash_target_to_read(&mut self, flash_target_to_read: FlashTargetToRead) {
223            set_bit_range!(&mut self.target, flash_target_to_read, u8, u8, 0, 0);
224        }
225    }
226
227    impl ConcreteMessage for MsgFlashErase {
228        const MESSAGE_TYPE: u16 = 226;
229        const MESSAGE_NAME: &'static str = "MSG_FLASH_ERASE";
230    }
231
232    impl SbpMessage for MsgFlashErase {
233        fn message_name(&self) -> &'static str {
234            <Self as ConcreteMessage>::MESSAGE_NAME
235        }
236        fn message_type(&self) -> Option<u16> {
237            Some(<Self as ConcreteMessage>::MESSAGE_TYPE)
238        }
239        fn sender_id(&self) -> Option<u16> {
240            self.sender_id
241        }
242        fn set_sender_id(&mut self, new_id: u16) {
243            self.sender_id = Some(new_id);
244        }
245        fn encoded_len(&self) -> usize {
246            WireFormat::len(self) + crate::HEADER_LEN + crate::CRC_LEN
247        }
248        fn is_valid(&self) -> bool {
249            true
250        }
251        fn into_valid_msg(self) -> Result<Self, crate::messages::invalid::Invalid> {
252            Ok(self)
253        }
254    }
255
256    impl FriendlyName for MsgFlashErase {
257        fn friendly_name() -> &'static str {
258            "FLASH ERASE"
259        }
260    }
261
262    impl TryFrom<Sbp> for MsgFlashErase {
263        type Error = TryFromSbpError;
264        fn try_from(msg: Sbp) -> Result<Self, Self::Error> {
265            match msg {
266                Sbp::MsgFlashErase(m) => Ok(m),
267                _ => Err(TryFromSbpError(msg)),
268            }
269        }
270    }
271
272    impl WireFormat for MsgFlashErase {
273        const MIN_LEN: usize = <u8 as WireFormat>::MIN_LEN + <u32 as WireFormat>::MIN_LEN;
274        fn len(&self) -> usize {
275            WireFormat::len(&self.target) + WireFormat::len(&self.sector_num)
276        }
277        fn write<B: BufMut>(&self, buf: &mut B) {
278            WireFormat::write(&self.target, buf);
279            WireFormat::write(&self.sector_num, buf);
280        }
281        fn parse_unchecked<B: Buf>(buf: &mut B) -> Self {
282            MsgFlashErase {
283                sender_id: None,
284                target: WireFormat::parse_unchecked(buf),
285                sector_num: WireFormat::parse_unchecked(buf),
286            }
287        }
288    }
289
290    /// Flash target to read
291    #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
292    pub enum FlashTargetToRead {
293        /// FLASH_STM
294        FlashStm = 0,
295
296        /// FLASH_M25
297        FlashM25 = 1,
298    }
299
300    impl std::fmt::Display for FlashTargetToRead {
301        fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
302            match self {
303                FlashTargetToRead::FlashStm => f.write_str("FLASH_STM"),
304                FlashTargetToRead::FlashM25 => f.write_str("FLASH_M25"),
305            }
306        }
307    }
308
309    impl TryFrom<u8> for FlashTargetToRead {
310        type Error = u8;
311        fn try_from(i: u8) -> Result<Self, u8> {
312            match i {
313                0 => Ok(FlashTargetToRead::FlashStm),
314                1 => Ok(FlashTargetToRead::FlashM25),
315                i => Err(i),
316            }
317        }
318    }
319}
320
321pub mod msg_flash_program {
322    #![allow(unused_imports)]
323
324    use super::*;
325    use crate::messages::lib::*;
326
327    /// Program flash addresses
328    ///
329    /// The flash program message programs a set of addresses of either the STM or
330    /// M25 flash. The device replies with either a MSG_FLASH_DONE message
331    /// containing the return code FLASH_OK (0) on success, or FLASH_INVALID_LEN
332    /// (2) if the maximum write size is exceeded. Note that the sector-containing
333    /// addresses must be erased before addresses can be programmed.
334    ///
335    #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
336    #[allow(clippy::derive_partial_eq_without_eq)]
337    #[derive(Debug, PartialEq, Clone)]
338    pub struct MsgFlashProgram {
339        /// The message sender_id
340        #[cfg_attr(feature = "serde", serde(skip_serializing, alias = "sender"))]
341        pub sender_id: Option<u16>,
342        /// Target flags
343        #[cfg_attr(feature = "serde", serde(rename = "target"))]
344        pub target: u8,
345        /// Starting address offset to program
346        #[cfg_attr(feature = "serde", serde(rename = "addr_start"))]
347        pub addr_start: [u8; 3],
348        /// Length of set of addresses to program, counting up from starting address
349        #[cfg_attr(feature = "serde", serde(rename = "addr_len"))]
350        pub addr_len: u8,
351        /// Data to program addresses with, with length N=addr_len
352        #[cfg_attr(feature = "serde", serde(rename = "data"))]
353        pub data: Vec<u8>,
354    }
355
356    impl MsgFlashProgram {
357        /// Gets the [FlashTargetToRead][self::FlashTargetToRead] stored in the `target` bitfield.
358        ///
359        /// Returns `Ok` if the bitrange contains a known `FlashTargetToRead` variant.
360        /// Otherwise the value of the bitrange is returned as an `Err(u8)`. This may be because of a malformed message,
361        /// or because new variants of `FlashTargetToRead` were added.
362        pub fn flash_target_to_read(&self) -> Result<FlashTargetToRead, u8> {
363            get_bit_range!(self.target, u8, u8, 0, 0).try_into()
364        }
365
366        /// Set the bitrange corresponding to the [FlashTargetToRead][FlashTargetToRead] of the `target` bitfield.
367        pub fn set_flash_target_to_read(&mut self, flash_target_to_read: FlashTargetToRead) {
368            set_bit_range!(&mut self.target, flash_target_to_read, u8, u8, 0, 0);
369        }
370    }
371
372    impl ConcreteMessage for MsgFlashProgram {
373        const MESSAGE_TYPE: u16 = 230;
374        const MESSAGE_NAME: &'static str = "MSG_FLASH_PROGRAM";
375    }
376
377    impl SbpMessage for MsgFlashProgram {
378        fn message_name(&self) -> &'static str {
379            <Self as ConcreteMessage>::MESSAGE_NAME
380        }
381        fn message_type(&self) -> Option<u16> {
382            Some(<Self as ConcreteMessage>::MESSAGE_TYPE)
383        }
384        fn sender_id(&self) -> Option<u16> {
385            self.sender_id
386        }
387        fn set_sender_id(&mut self, new_id: u16) {
388            self.sender_id = Some(new_id);
389        }
390        fn encoded_len(&self) -> usize {
391            WireFormat::len(self) + crate::HEADER_LEN + crate::CRC_LEN
392        }
393        fn is_valid(&self) -> bool {
394            true
395        }
396        fn into_valid_msg(self) -> Result<Self, crate::messages::invalid::Invalid> {
397            Ok(self)
398        }
399    }
400
401    impl FriendlyName for MsgFlashProgram {
402        fn friendly_name() -> &'static str {
403            "FLASH PROGRAM"
404        }
405    }
406
407    impl TryFrom<Sbp> for MsgFlashProgram {
408        type Error = TryFromSbpError;
409        fn try_from(msg: Sbp) -> Result<Self, Self::Error> {
410            match msg {
411                Sbp::MsgFlashProgram(m) => Ok(m),
412                _ => Err(TryFromSbpError(msg)),
413            }
414        }
415    }
416
417    impl WireFormat for MsgFlashProgram {
418        const MIN_LEN: usize = <u8 as WireFormat>::MIN_LEN
419            + <[u8; 3] as WireFormat>::MIN_LEN
420            + <u8 as WireFormat>::MIN_LEN
421            + <Vec<u8> as WireFormat>::MIN_LEN;
422        fn len(&self) -> usize {
423            WireFormat::len(&self.target)
424                + WireFormat::len(&self.addr_start)
425                + WireFormat::len(&self.addr_len)
426                + WireFormat::len(&self.data)
427        }
428        fn write<B: BufMut>(&self, buf: &mut B) {
429            WireFormat::write(&self.target, buf);
430            WireFormat::write(&self.addr_start, buf);
431            WireFormat::write(&self.addr_len, buf);
432            WireFormat::write(&self.data, buf);
433        }
434        fn parse_unchecked<B: Buf>(buf: &mut B) -> Self {
435            MsgFlashProgram {
436                sender_id: None,
437                target: WireFormat::parse_unchecked(buf),
438                addr_start: WireFormat::parse_unchecked(buf),
439                addr_len: WireFormat::parse_unchecked(buf),
440                data: WireFormat::parse_unchecked(buf),
441            }
442        }
443    }
444
445    /// Flash target to read
446    #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
447    pub enum FlashTargetToRead {
448        /// FLASH_STM
449        FlashStm = 0,
450
451        /// FLASH_M25
452        FlashM25 = 1,
453    }
454
455    impl std::fmt::Display for FlashTargetToRead {
456        fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
457            match self {
458                FlashTargetToRead::FlashStm => f.write_str("FLASH_STM"),
459                FlashTargetToRead::FlashM25 => f.write_str("FLASH_M25"),
460            }
461        }
462    }
463
464    impl TryFrom<u8> for FlashTargetToRead {
465        type Error = u8;
466        fn try_from(i: u8) -> Result<Self, u8> {
467            match i {
468                0 => Ok(FlashTargetToRead::FlashStm),
469                1 => Ok(FlashTargetToRead::FlashM25),
470                i => Err(i),
471            }
472        }
473    }
474}
475
476pub mod msg_flash_read_req {
477    #![allow(unused_imports)]
478
479    use super::*;
480    use crate::messages::lib::*;
481
482    /// Read STM or M25 flash address request (host => device)
483    ///
484    /// The flash read message reads a set of addresses of either the STM or M25
485    /// onboard flash. The device replies with a MSG_FLASH_READ_RESP message
486    /// containing either the read data on success or a MSG_FLASH_DONE message
487    /// containing the return code FLASH_INVALID_LEN (2) if the maximum read size
488    /// is exceeded or FLASH_INVALID_ADDR (3) if the address is outside of the
489    /// allowed range.
490    ///
491    #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
492    #[allow(clippy::derive_partial_eq_without_eq)]
493    #[derive(Debug, PartialEq, Clone)]
494    pub struct MsgFlashReadReq {
495        /// The message sender_id
496        #[cfg_attr(feature = "serde", serde(skip_serializing, alias = "sender"))]
497        pub sender_id: Option<u16>,
498        /// Target flags
499        #[cfg_attr(feature = "serde", serde(rename = "target"))]
500        pub target: u8,
501        /// Starting address offset to read from
502        #[cfg_attr(feature = "serde", serde(rename = "addr_start"))]
503        pub addr_start: [u8; 3],
504        /// Length of set of addresses to read, counting up from starting address
505        #[cfg_attr(feature = "serde", serde(rename = "addr_len"))]
506        pub addr_len: u8,
507    }
508
509    impl MsgFlashReadReq {
510        /// Gets the [FlashTargetToRead][self::FlashTargetToRead] stored in the `target` bitfield.
511        ///
512        /// Returns `Ok` if the bitrange contains a known `FlashTargetToRead` variant.
513        /// Otherwise the value of the bitrange is returned as an `Err(u8)`. This may be because of a malformed message,
514        /// or because new variants of `FlashTargetToRead` were added.
515        pub fn flash_target_to_read(&self) -> Result<FlashTargetToRead, u8> {
516            get_bit_range!(self.target, u8, u8, 0, 0).try_into()
517        }
518
519        /// Set the bitrange corresponding to the [FlashTargetToRead][FlashTargetToRead] of the `target` bitfield.
520        pub fn set_flash_target_to_read(&mut self, flash_target_to_read: FlashTargetToRead) {
521            set_bit_range!(&mut self.target, flash_target_to_read, u8, u8, 0, 0);
522        }
523    }
524
525    impl ConcreteMessage for MsgFlashReadReq {
526        const MESSAGE_TYPE: u16 = 231;
527        const MESSAGE_NAME: &'static str = "MSG_FLASH_READ_REQ";
528    }
529
530    impl SbpMessage for MsgFlashReadReq {
531        fn message_name(&self) -> &'static str {
532            <Self as ConcreteMessage>::MESSAGE_NAME
533        }
534        fn message_type(&self) -> Option<u16> {
535            Some(<Self as ConcreteMessage>::MESSAGE_TYPE)
536        }
537        fn sender_id(&self) -> Option<u16> {
538            self.sender_id
539        }
540        fn set_sender_id(&mut self, new_id: u16) {
541            self.sender_id = Some(new_id);
542        }
543        fn encoded_len(&self) -> usize {
544            WireFormat::len(self) + crate::HEADER_LEN + crate::CRC_LEN
545        }
546        fn is_valid(&self) -> bool {
547            true
548        }
549        fn into_valid_msg(self) -> Result<Self, crate::messages::invalid::Invalid> {
550            Ok(self)
551        }
552    }
553
554    impl FriendlyName for MsgFlashReadReq {
555        fn friendly_name() -> &'static str {
556            "FLASH READ REQ"
557        }
558    }
559
560    impl TryFrom<Sbp> for MsgFlashReadReq {
561        type Error = TryFromSbpError;
562        fn try_from(msg: Sbp) -> Result<Self, Self::Error> {
563            match msg {
564                Sbp::MsgFlashReadReq(m) => Ok(m),
565                _ => Err(TryFromSbpError(msg)),
566            }
567        }
568    }
569
570    impl WireFormat for MsgFlashReadReq {
571        const MIN_LEN: usize = <u8 as WireFormat>::MIN_LEN
572            + <[u8; 3] as WireFormat>::MIN_LEN
573            + <u8 as WireFormat>::MIN_LEN;
574        fn len(&self) -> usize {
575            WireFormat::len(&self.target)
576                + WireFormat::len(&self.addr_start)
577                + WireFormat::len(&self.addr_len)
578        }
579        fn write<B: BufMut>(&self, buf: &mut B) {
580            WireFormat::write(&self.target, buf);
581            WireFormat::write(&self.addr_start, buf);
582            WireFormat::write(&self.addr_len, buf);
583        }
584        fn parse_unchecked<B: Buf>(buf: &mut B) -> Self {
585            MsgFlashReadReq {
586                sender_id: None,
587                target: WireFormat::parse_unchecked(buf),
588                addr_start: WireFormat::parse_unchecked(buf),
589                addr_len: WireFormat::parse_unchecked(buf),
590            }
591        }
592    }
593
594    /// Flash target to read
595    #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
596    pub enum FlashTargetToRead {
597        /// FLASH_STM
598        FlashStm = 0,
599
600        /// FLASH_M25
601        FlashM25 = 1,
602    }
603
604    impl std::fmt::Display for FlashTargetToRead {
605        fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
606            match self {
607                FlashTargetToRead::FlashStm => f.write_str("FLASH_STM"),
608                FlashTargetToRead::FlashM25 => f.write_str("FLASH_M25"),
609            }
610        }
611    }
612
613    impl TryFrom<u8> for FlashTargetToRead {
614        type Error = u8;
615        fn try_from(i: u8) -> Result<Self, u8> {
616            match i {
617                0 => Ok(FlashTargetToRead::FlashStm),
618                1 => Ok(FlashTargetToRead::FlashM25),
619                i => Err(i),
620            }
621        }
622    }
623}
624
625pub mod msg_flash_read_resp {
626    #![allow(unused_imports)]
627
628    use super::*;
629    use crate::messages::lib::*;
630
631    /// Read STM or M25 flash address response (host <= device)
632    ///
633    /// The flash read message reads a set of addresses of either the STM or M25
634    /// onboard flash. The device replies with a MSG_FLASH_READ_RESP message
635    /// containing either the read data on success or a MSG_FLASH_DONE message
636    /// containing the return code FLASH_INVALID_LEN (2) if the maximum read size
637    /// is exceeded or FLASH_INVALID_ADDR (3) if the address is outside of the
638    /// allowed range.
639    ///
640    #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
641    #[allow(clippy::derive_partial_eq_without_eq)]
642    #[derive(Debug, PartialEq, Clone)]
643    pub struct MsgFlashReadResp {
644        /// The message sender_id
645        #[cfg_attr(feature = "serde", serde(skip_serializing, alias = "sender"))]
646        pub sender_id: Option<u16>,
647        /// Target flags
648        #[cfg_attr(feature = "serde", serde(rename = "target"))]
649        pub target: u8,
650        /// Starting address offset to read from
651        #[cfg_attr(feature = "serde", serde(rename = "addr_start"))]
652        pub addr_start: [u8; 3],
653        /// Length of set of addresses to read, counting up from starting address
654        #[cfg_attr(feature = "serde", serde(rename = "addr_len"))]
655        pub addr_len: u8,
656    }
657
658    impl MsgFlashReadResp {
659        /// Gets the [FlashTargetToRead][self::FlashTargetToRead] stored in the `target` bitfield.
660        ///
661        /// Returns `Ok` if the bitrange contains a known `FlashTargetToRead` variant.
662        /// Otherwise the value of the bitrange is returned as an `Err(u8)`. This may be because of a malformed message,
663        /// or because new variants of `FlashTargetToRead` were added.
664        pub fn flash_target_to_read(&self) -> Result<FlashTargetToRead, u8> {
665            get_bit_range!(self.target, u8, u8, 0, 0).try_into()
666        }
667
668        /// Set the bitrange corresponding to the [FlashTargetToRead][FlashTargetToRead] of the `target` bitfield.
669        pub fn set_flash_target_to_read(&mut self, flash_target_to_read: FlashTargetToRead) {
670            set_bit_range!(&mut self.target, flash_target_to_read, u8, u8, 0, 0);
671        }
672    }
673
674    impl ConcreteMessage for MsgFlashReadResp {
675        const MESSAGE_TYPE: u16 = 225;
676        const MESSAGE_NAME: &'static str = "MSG_FLASH_READ_RESP";
677    }
678
679    impl SbpMessage for MsgFlashReadResp {
680        fn message_name(&self) -> &'static str {
681            <Self as ConcreteMessage>::MESSAGE_NAME
682        }
683        fn message_type(&self) -> Option<u16> {
684            Some(<Self as ConcreteMessage>::MESSAGE_TYPE)
685        }
686        fn sender_id(&self) -> Option<u16> {
687            self.sender_id
688        }
689        fn set_sender_id(&mut self, new_id: u16) {
690            self.sender_id = Some(new_id);
691        }
692        fn encoded_len(&self) -> usize {
693            WireFormat::len(self) + crate::HEADER_LEN + crate::CRC_LEN
694        }
695        fn is_valid(&self) -> bool {
696            true
697        }
698        fn into_valid_msg(self) -> Result<Self, crate::messages::invalid::Invalid> {
699            Ok(self)
700        }
701    }
702
703    impl FriendlyName for MsgFlashReadResp {
704        fn friendly_name() -> &'static str {
705            "FLASH READ RESP"
706        }
707    }
708
709    impl TryFrom<Sbp> for MsgFlashReadResp {
710        type Error = TryFromSbpError;
711        fn try_from(msg: Sbp) -> Result<Self, Self::Error> {
712            match msg {
713                Sbp::MsgFlashReadResp(m) => Ok(m),
714                _ => Err(TryFromSbpError(msg)),
715            }
716        }
717    }
718
719    impl WireFormat for MsgFlashReadResp {
720        const MIN_LEN: usize = <u8 as WireFormat>::MIN_LEN
721            + <[u8; 3] as WireFormat>::MIN_LEN
722            + <u8 as WireFormat>::MIN_LEN;
723        fn len(&self) -> usize {
724            WireFormat::len(&self.target)
725                + WireFormat::len(&self.addr_start)
726                + WireFormat::len(&self.addr_len)
727        }
728        fn write<B: BufMut>(&self, buf: &mut B) {
729            WireFormat::write(&self.target, buf);
730            WireFormat::write(&self.addr_start, buf);
731            WireFormat::write(&self.addr_len, buf);
732        }
733        fn parse_unchecked<B: Buf>(buf: &mut B) -> Self {
734            MsgFlashReadResp {
735                sender_id: None,
736                target: WireFormat::parse_unchecked(buf),
737                addr_start: WireFormat::parse_unchecked(buf),
738                addr_len: WireFormat::parse_unchecked(buf),
739            }
740        }
741    }
742
743    /// Flash target to read
744    #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
745    pub enum FlashTargetToRead {
746        /// FLASH_STM
747        FlashStm = 0,
748
749        /// FLASH_M25
750        FlashM25 = 1,
751    }
752
753    impl std::fmt::Display for FlashTargetToRead {
754        fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
755            match self {
756                FlashTargetToRead::FlashStm => f.write_str("FLASH_STM"),
757                FlashTargetToRead::FlashM25 => f.write_str("FLASH_M25"),
758            }
759        }
760    }
761
762    impl TryFrom<u8> for FlashTargetToRead {
763        type Error = u8;
764        fn try_from(i: u8) -> Result<Self, u8> {
765            match i {
766                0 => Ok(FlashTargetToRead::FlashStm),
767                1 => Ok(FlashTargetToRead::FlashM25),
768                i => Err(i),
769            }
770        }
771    }
772}
773
774pub mod msg_m25_flash_write_status {
775    #![allow(unused_imports)]
776
777    use super::*;
778    use crate::messages::lib::*;
779
780    /// Write M25 flash status register (host => device)
781    ///
782    /// The flash status message writes to the 8-bit M25 flash status register.
783    /// The device replies with a MSG_FLASH_DONE message.
784    ///
785    #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
786    #[allow(clippy::derive_partial_eq_without_eq)]
787    #[derive(Debug, PartialEq, Clone)]
788    pub struct MsgM25FlashWriteStatus {
789        /// The message sender_id
790        #[cfg_attr(feature = "serde", serde(skip_serializing, alias = "sender"))]
791        pub sender_id: Option<u16>,
792        /// Byte to write to the M25 flash status register
793        #[cfg_attr(feature = "serde", serde(rename = "status"))]
794        pub status: [u8; 1],
795    }
796
797    impl ConcreteMessage for MsgM25FlashWriteStatus {
798        const MESSAGE_TYPE: u16 = 243;
799        const MESSAGE_NAME: &'static str = "MSG_M25_FLASH_WRITE_STATUS";
800    }
801
802    impl SbpMessage for MsgM25FlashWriteStatus {
803        fn message_name(&self) -> &'static str {
804            <Self as ConcreteMessage>::MESSAGE_NAME
805        }
806        fn message_type(&self) -> Option<u16> {
807            Some(<Self as ConcreteMessage>::MESSAGE_TYPE)
808        }
809        fn sender_id(&self) -> Option<u16> {
810            self.sender_id
811        }
812        fn set_sender_id(&mut self, new_id: u16) {
813            self.sender_id = Some(new_id);
814        }
815        fn encoded_len(&self) -> usize {
816            WireFormat::len(self) + crate::HEADER_LEN + crate::CRC_LEN
817        }
818        fn is_valid(&self) -> bool {
819            true
820        }
821        fn into_valid_msg(self) -> Result<Self, crate::messages::invalid::Invalid> {
822            Ok(self)
823        }
824    }
825
826    impl FriendlyName for MsgM25FlashWriteStatus {
827        fn friendly_name() -> &'static str {
828            "M25 FLASH WRITE STATUS"
829        }
830    }
831
832    impl TryFrom<Sbp> for MsgM25FlashWriteStatus {
833        type Error = TryFromSbpError;
834        fn try_from(msg: Sbp) -> Result<Self, Self::Error> {
835            match msg {
836                Sbp::MsgM25FlashWriteStatus(m) => Ok(m),
837                _ => Err(TryFromSbpError(msg)),
838            }
839        }
840    }
841
842    impl WireFormat for MsgM25FlashWriteStatus {
843        const MIN_LEN: usize = <[u8; 1] as WireFormat>::MIN_LEN;
844        fn len(&self) -> usize {
845            WireFormat::len(&self.status)
846        }
847        fn write<B: BufMut>(&self, buf: &mut B) {
848            WireFormat::write(&self.status, buf);
849        }
850        fn parse_unchecked<B: Buf>(buf: &mut B) -> Self {
851            MsgM25FlashWriteStatus {
852                sender_id: None,
853                status: WireFormat::parse_unchecked(buf),
854            }
855        }
856    }
857}
858
859pub mod msg_stm_flash_lock_sector {
860    #![allow(unused_imports)]
861
862    use super::*;
863    use crate::messages::lib::*;
864
865    /// Lock sector of STM flash memory (host => device)
866    ///
867    /// The flash lock message locks a sector of the STM flash memory. The device
868    /// replies with a MSG_FLASH_DONE message.
869    ///
870    #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
871    #[allow(clippy::derive_partial_eq_without_eq)]
872    #[derive(Debug, PartialEq, Clone)]
873    pub struct MsgStmFlashLockSector {
874        /// The message sender_id
875        #[cfg_attr(feature = "serde", serde(skip_serializing, alias = "sender"))]
876        pub sender_id: Option<u16>,
877        /// Flash sector number to lock
878        #[cfg_attr(feature = "serde", serde(rename = "sector"))]
879        pub sector: u32,
880    }
881
882    impl ConcreteMessage for MsgStmFlashLockSector {
883        const MESSAGE_TYPE: u16 = 227;
884        const MESSAGE_NAME: &'static str = "MSG_STM_FLASH_LOCK_SECTOR";
885    }
886
887    impl SbpMessage for MsgStmFlashLockSector {
888        fn message_name(&self) -> &'static str {
889            <Self as ConcreteMessage>::MESSAGE_NAME
890        }
891        fn message_type(&self) -> Option<u16> {
892            Some(<Self as ConcreteMessage>::MESSAGE_TYPE)
893        }
894        fn sender_id(&self) -> Option<u16> {
895            self.sender_id
896        }
897        fn set_sender_id(&mut self, new_id: u16) {
898            self.sender_id = Some(new_id);
899        }
900        fn encoded_len(&self) -> usize {
901            WireFormat::len(self) + crate::HEADER_LEN + crate::CRC_LEN
902        }
903        fn is_valid(&self) -> bool {
904            true
905        }
906        fn into_valid_msg(self) -> Result<Self, crate::messages::invalid::Invalid> {
907            Ok(self)
908        }
909    }
910
911    impl FriendlyName for MsgStmFlashLockSector {
912        fn friendly_name() -> &'static str {
913            "STM FLASH LOCK SECTOR"
914        }
915    }
916
917    impl TryFrom<Sbp> for MsgStmFlashLockSector {
918        type Error = TryFromSbpError;
919        fn try_from(msg: Sbp) -> Result<Self, Self::Error> {
920            match msg {
921                Sbp::MsgStmFlashLockSector(m) => Ok(m),
922                _ => Err(TryFromSbpError(msg)),
923            }
924        }
925    }
926
927    impl WireFormat for MsgStmFlashLockSector {
928        const MIN_LEN: usize = <u32 as WireFormat>::MIN_LEN;
929        fn len(&self) -> usize {
930            WireFormat::len(&self.sector)
931        }
932        fn write<B: BufMut>(&self, buf: &mut B) {
933            WireFormat::write(&self.sector, buf);
934        }
935        fn parse_unchecked<B: Buf>(buf: &mut B) -> Self {
936            MsgStmFlashLockSector {
937                sender_id: None,
938                sector: WireFormat::parse_unchecked(buf),
939            }
940        }
941    }
942}
943
944pub mod msg_stm_flash_unlock_sector {
945    #![allow(unused_imports)]
946
947    use super::*;
948    use crate::messages::lib::*;
949
950    /// Unlock sector of STM flash memory (host => device)
951    ///
952    /// The flash unlock message unlocks a sector of the STM flash memory. The
953    /// device replies with a MSG_FLASH_DONE message.
954    ///
955    #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
956    #[allow(clippy::derive_partial_eq_without_eq)]
957    #[derive(Debug, PartialEq, Clone)]
958    pub struct MsgStmFlashUnlockSector {
959        /// The message sender_id
960        #[cfg_attr(feature = "serde", serde(skip_serializing, alias = "sender"))]
961        pub sender_id: Option<u16>,
962        /// Flash sector number to unlock
963        #[cfg_attr(feature = "serde", serde(rename = "sector"))]
964        pub sector: u32,
965    }
966
967    impl ConcreteMessage for MsgStmFlashUnlockSector {
968        const MESSAGE_TYPE: u16 = 228;
969        const MESSAGE_NAME: &'static str = "MSG_STM_FLASH_UNLOCK_SECTOR";
970    }
971
972    impl SbpMessage for MsgStmFlashUnlockSector {
973        fn message_name(&self) -> &'static str {
974            <Self as ConcreteMessage>::MESSAGE_NAME
975        }
976        fn message_type(&self) -> Option<u16> {
977            Some(<Self as ConcreteMessage>::MESSAGE_TYPE)
978        }
979        fn sender_id(&self) -> Option<u16> {
980            self.sender_id
981        }
982        fn set_sender_id(&mut self, new_id: u16) {
983            self.sender_id = Some(new_id);
984        }
985        fn encoded_len(&self) -> usize {
986            WireFormat::len(self) + crate::HEADER_LEN + crate::CRC_LEN
987        }
988        fn is_valid(&self) -> bool {
989            true
990        }
991        fn into_valid_msg(self) -> Result<Self, crate::messages::invalid::Invalid> {
992            Ok(self)
993        }
994    }
995
996    impl FriendlyName for MsgStmFlashUnlockSector {
997        fn friendly_name() -> &'static str {
998            "STM FLASH UNLOCK SECTOR"
999        }
1000    }
1001
1002    impl TryFrom<Sbp> for MsgStmFlashUnlockSector {
1003        type Error = TryFromSbpError;
1004        fn try_from(msg: Sbp) -> Result<Self, Self::Error> {
1005            match msg {
1006                Sbp::MsgStmFlashUnlockSector(m) => Ok(m),
1007                _ => Err(TryFromSbpError(msg)),
1008            }
1009        }
1010    }
1011
1012    impl WireFormat for MsgStmFlashUnlockSector {
1013        const MIN_LEN: usize = <u32 as WireFormat>::MIN_LEN;
1014        fn len(&self) -> usize {
1015            WireFormat::len(&self.sector)
1016        }
1017        fn write<B: BufMut>(&self, buf: &mut B) {
1018            WireFormat::write(&self.sector, buf);
1019        }
1020        fn parse_unchecked<B: Buf>(buf: &mut B) -> Self {
1021            MsgStmFlashUnlockSector {
1022                sender_id: None,
1023                sector: WireFormat::parse_unchecked(buf),
1024            }
1025        }
1026    }
1027}
1028
1029pub mod msg_stm_unique_id_req {
1030    #![allow(unused_imports)]
1031
1032    use super::*;
1033    use crate::messages::lib::*;
1034
1035    /// Read device's hard-coded unique ID request (host => device)
1036    ///
1037    /// This message reads the device's hard-coded unique ID. The host requests
1038    /// the ID by sending a MSG_STM_UNIQUE_ID_REQ. The device responds with a
1039    /// MSG_STM_UNIQUE_ID_RESP with the 12-byte unique ID in the payload.
1040    ///
1041    #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1042    #[allow(clippy::derive_partial_eq_without_eq)]
1043    #[derive(Debug, PartialEq, Clone)]
1044    pub struct MsgStmUniqueIdReq {
1045        /// The message sender_id
1046        #[cfg_attr(feature = "serde", serde(skip_serializing, alias = "sender"))]
1047        pub sender_id: Option<u16>,
1048    }
1049
1050    impl ConcreteMessage for MsgStmUniqueIdReq {
1051        const MESSAGE_TYPE: u16 = 232;
1052        const MESSAGE_NAME: &'static str = "MSG_STM_UNIQUE_ID_REQ";
1053    }
1054
1055    impl SbpMessage for MsgStmUniqueIdReq {
1056        fn message_name(&self) -> &'static str {
1057            <Self as ConcreteMessage>::MESSAGE_NAME
1058        }
1059        fn message_type(&self) -> Option<u16> {
1060            Some(<Self as ConcreteMessage>::MESSAGE_TYPE)
1061        }
1062        fn sender_id(&self) -> Option<u16> {
1063            self.sender_id
1064        }
1065        fn set_sender_id(&mut self, new_id: u16) {
1066            self.sender_id = Some(new_id);
1067        }
1068        fn encoded_len(&self) -> usize {
1069            WireFormat::len(self) + crate::HEADER_LEN + crate::CRC_LEN
1070        }
1071        fn is_valid(&self) -> bool {
1072            true
1073        }
1074        fn into_valid_msg(self) -> Result<Self, crate::messages::invalid::Invalid> {
1075            Ok(self)
1076        }
1077    }
1078
1079    impl FriendlyName for MsgStmUniqueIdReq {
1080        fn friendly_name() -> &'static str {
1081            "STM UNIQUE ID REQ"
1082        }
1083    }
1084
1085    impl TryFrom<Sbp> for MsgStmUniqueIdReq {
1086        type Error = TryFromSbpError;
1087        fn try_from(msg: Sbp) -> Result<Self, Self::Error> {
1088            match msg {
1089                Sbp::MsgStmUniqueIdReq(m) => Ok(m),
1090                _ => Err(TryFromSbpError(msg)),
1091            }
1092        }
1093    }
1094
1095    impl WireFormat for MsgStmUniqueIdReq {
1096        const MIN_LEN: usize = 0;
1097        fn len(&self) -> usize {
1098            0
1099        }
1100        fn write<B: BufMut>(&self, _buf: &mut B) {}
1101        fn parse_unchecked<B: Buf>(_buf: &mut B) -> Self {
1102            MsgStmUniqueIdReq { sender_id: None }
1103        }
1104    }
1105}
1106
1107pub mod msg_stm_unique_id_resp {
1108    #![allow(unused_imports)]
1109
1110    use super::*;
1111    use crate::messages::lib::*;
1112
1113    /// Read device's hard-coded unique ID response (host <= device)
1114    ///
1115    /// This message reads the device's hard-coded unique ID. The host requests
1116    /// the ID by sending a MSG_STM_UNIQUE_ID_REQ. The device responds with a
1117    /// MSG_STM_UNIQUE_ID_RESP with the 12-byte unique ID in the payload.
1118    ///
1119    #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1120    #[allow(clippy::derive_partial_eq_without_eq)]
1121    #[derive(Debug, PartialEq, Clone)]
1122    pub struct MsgStmUniqueIdResp {
1123        /// The message sender_id
1124        #[cfg_attr(feature = "serde", serde(skip_serializing, alias = "sender"))]
1125        pub sender_id: Option<u16>,
1126        /// Device unique ID
1127        #[cfg_attr(feature = "serde", serde(rename = "stm_id"))]
1128        pub stm_id: [u8; 12],
1129    }
1130
1131    impl ConcreteMessage for MsgStmUniqueIdResp {
1132        const MESSAGE_TYPE: u16 = 229;
1133        const MESSAGE_NAME: &'static str = "MSG_STM_UNIQUE_ID_RESP";
1134    }
1135
1136    impl SbpMessage for MsgStmUniqueIdResp {
1137        fn message_name(&self) -> &'static str {
1138            <Self as ConcreteMessage>::MESSAGE_NAME
1139        }
1140        fn message_type(&self) -> Option<u16> {
1141            Some(<Self as ConcreteMessage>::MESSAGE_TYPE)
1142        }
1143        fn sender_id(&self) -> Option<u16> {
1144            self.sender_id
1145        }
1146        fn set_sender_id(&mut self, new_id: u16) {
1147            self.sender_id = Some(new_id);
1148        }
1149        fn encoded_len(&self) -> usize {
1150            WireFormat::len(self) + crate::HEADER_LEN + crate::CRC_LEN
1151        }
1152        fn is_valid(&self) -> bool {
1153            true
1154        }
1155        fn into_valid_msg(self) -> Result<Self, crate::messages::invalid::Invalid> {
1156            Ok(self)
1157        }
1158    }
1159
1160    impl FriendlyName for MsgStmUniqueIdResp {
1161        fn friendly_name() -> &'static str {
1162            "STM UNIQUE ID RESP"
1163        }
1164    }
1165
1166    impl TryFrom<Sbp> for MsgStmUniqueIdResp {
1167        type Error = TryFromSbpError;
1168        fn try_from(msg: Sbp) -> Result<Self, Self::Error> {
1169            match msg {
1170                Sbp::MsgStmUniqueIdResp(m) => Ok(m),
1171                _ => Err(TryFromSbpError(msg)),
1172            }
1173        }
1174    }
1175
1176    impl WireFormat for MsgStmUniqueIdResp {
1177        const MIN_LEN: usize = <[u8; 12] as WireFormat>::MIN_LEN;
1178        fn len(&self) -> usize {
1179            WireFormat::len(&self.stm_id)
1180        }
1181        fn write<B: BufMut>(&self, buf: &mut B) {
1182            WireFormat::write(&self.stm_id, buf);
1183        }
1184        fn parse_unchecked<B: Buf>(buf: &mut B) -> Self {
1185            MsgStmUniqueIdResp {
1186                sender_id: None,
1187                stm_id: WireFormat::parse_unchecked(buf),
1188            }
1189        }
1190    }
1191}