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
// 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/logging.yaml
// with generate.py. Please do not hand edit!
//****************************************************************************/
//! Logging and debugging messages from the device.
pub use msg_fwd::MsgFwd;
pub use msg_log::MsgLog;
pub use msg_print_dep::MsgPrintDep;

pub mod msg_fwd {
    #![allow(unused_imports)]

    use super::*;
    use crate::messages::lib::*;

    /// Wrapper for FWD a separate stream of information over SBP
    ///
    /// This message provides the ability to forward messages over SBP.  This may
    /// take the form of wrapping up SBP messages received by Piksi for logging
    /// purposes or wrapping another protocol with SBP.
    ///
    /// The source identifier indicates from what interface a forwarded stream
    /// derived. The protocol identifier identifies what the expected protocol the
    /// forwarded msg contains. Protocol 0 represents SBP and the remaining values
    /// are implementation defined.
    ///
    #[cfg_attr(feature = "serde", derive(serde::Serialize))]
    #[derive(Debug, Clone)]
    pub struct MsgFwd {
        /// The message sender_id
        #[cfg_attr(feature = "serde", serde(skip_serializing))]
        pub sender_id: Option<u16>,
        /// source identifier
        #[cfg_attr(feature = "serde", serde(rename(serialize = "source")))]
        pub source: u8,
        /// protocol identifier
        #[cfg_attr(feature = "serde", serde(rename(serialize = "protocol")))]
        pub protocol: u8,
        /// variable length wrapped binary message
        #[cfg_attr(feature = "serde", serde(rename(serialize = "fwd_payload")))]
        pub fwd_payload: Vec<u8>,
    }

    impl ConcreteMessage for MsgFwd {
        const MESSAGE_TYPE: u16 = 1026;
        const MESSAGE_NAME: &'static str = "MSG_FWD";
    }

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

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

pub mod msg_log {
    #![allow(unused_imports)]

    use super::*;
    use crate::messages::lib::*;

    /// Plaintext logging messages with levels
    ///
    /// This message contains a human-readable payload string from the device
    /// containing errors, warnings and informational messages at ERROR, WARNING,
    /// DEBUG, INFO logging levels.
    ///
    #[cfg_attr(feature = "serde", derive(serde::Serialize))]
    #[derive(Debug, Clone)]
    pub struct MsgLog {
        /// The message sender_id
        #[cfg_attr(feature = "serde", serde(skip_serializing))]
        pub sender_id: Option<u16>,
        /// Logging level
        #[cfg_attr(feature = "serde", serde(rename(serialize = "level")))]
        pub level: u8,
        /// Human-readable string
        #[cfg_attr(feature = "serde", serde(rename(serialize = "text")))]
        pub text: SbpString<Vec<u8>, Unterminated>,
    }

    impl MsgLog {
        /// Gets the [LoggingLevel][self::LoggingLevel] stored in the `level` bitfield.
        ///
        /// Returns `Ok` if the bitrange contains a known `LoggingLevel` variant.
        /// Otherwise the value of the bitrange is returned as an `Err(u8)`. This may be because of a malformed message,
        /// or because new variants of `LoggingLevel` were added.
        pub fn logging_level(&self) -> Result<LoggingLevel, u8> {
            get_bit_range!(self.level, u8, u8, 2, 0).try_into()
        }

        /// Set the bitrange corresponding to the [LoggingLevel][LoggingLevel] of the `level` bitfield.
        pub fn set_logging_level(&mut self, logging_level: LoggingLevel) {
            set_bit_range!(&mut self.level, logging_level, u8, u8, 2, 0);
        }
    }

    impl ConcreteMessage for MsgLog {
        const MESSAGE_TYPE: u16 = 1025;
        const MESSAGE_NAME: &'static str = "MSG_LOG";
    }

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

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

    /// Logging level
    #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
    pub enum LoggingLevel {
        /// EMERG
        EMERG = 0,

        /// ALERT
        ALERT = 1,

        /// CRIT
        CRIT = 2,

        /// ERROR
        ERROR = 3,

        /// WARN
        WARN = 4,

        /// NOTICE
        NOTICE = 5,

        /// INFO
        INFO = 6,

        /// DEBUG
        DEBUG = 7,
    }

    impl std::fmt::Display for LoggingLevel {
        fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
            match self {
                LoggingLevel::EMERG => f.write_str("EMERG"),
                LoggingLevel::ALERT => f.write_str("ALERT"),
                LoggingLevel::CRIT => f.write_str("CRIT"),
                LoggingLevel::ERROR => f.write_str("ERROR"),
                LoggingLevel::WARN => f.write_str("WARN"),
                LoggingLevel::NOTICE => f.write_str("NOTICE"),
                LoggingLevel::INFO => f.write_str("INFO"),
                LoggingLevel::DEBUG => f.write_str("DEBUG"),
            }
        }
    }

    impl TryFrom<u8> for LoggingLevel {
        type Error = u8;
        fn try_from(i: u8) -> Result<Self, Self::Error> {
            match i {
                0 => Ok(LoggingLevel::EMERG),
                1 => Ok(LoggingLevel::ALERT),
                2 => Ok(LoggingLevel::CRIT),
                3 => Ok(LoggingLevel::ERROR),
                4 => Ok(LoggingLevel::WARN),
                5 => Ok(LoggingLevel::NOTICE),
                6 => Ok(LoggingLevel::INFO),
                7 => Ok(LoggingLevel::DEBUG),
                i => Err(i),
            }
        }
    }
}

pub mod msg_print_dep {
    #![allow(unused_imports)]

    use super::*;
    use crate::messages::lib::*;

    /// Deprecated
    ///
    /// Deprecated.
    ///
    #[cfg_attr(feature = "serde", derive(serde::Serialize))]
    #[derive(Debug, Clone)]
    pub struct MsgPrintDep {
        /// The message sender_id
        #[cfg_attr(feature = "serde", serde(skip_serializing))]
        pub sender_id: Option<u16>,
        /// Human-readable string
        #[cfg_attr(feature = "serde", serde(rename(serialize = "text")))]
        pub text: SbpString<Vec<u8>, Unterminated>,
    }

    impl ConcreteMessage for MsgPrintDep {
        const MESSAGE_TYPE: u16 = 16;
        const MESSAGE_NAME: &'static str = "MSG_PRINT_DEP";
    }

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

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