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
pub use msg_ndb_event::MsgNdbEvent;
pub mod msg_ndb_event {
#![allow(unused_imports)]
use super::*;
use crate::messages::gnss::*;
use crate::messages::lib::*;
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[derive(Debug, Clone)]
pub struct MsgNdbEvent {
#[cfg_attr(feature = "serde", serde(skip_serializing))]
pub sender_id: Option<u16>,
#[cfg_attr(feature = "serde", serde(rename(serialize = "recv_time")))]
pub recv_time: u64,
#[cfg_attr(feature = "serde", serde(rename(serialize = "event")))]
pub event: u8,
#[cfg_attr(feature = "serde", serde(rename(serialize = "object_type")))]
pub object_type: u8,
#[cfg_attr(feature = "serde", serde(rename(serialize = "result")))]
pub result: u8,
#[cfg_attr(feature = "serde", serde(rename(serialize = "data_source")))]
pub data_source: u8,
#[cfg_attr(feature = "serde", serde(rename(serialize = "object_sid")))]
pub object_sid: GnssSignal,
#[cfg_attr(feature = "serde", serde(rename(serialize = "src_sid")))]
pub src_sid: GnssSignal,
#[cfg_attr(feature = "serde", serde(rename(serialize = "original_sender")))]
pub original_sender: u16,
}
impl MsgNdbEvent {
pub fn event_type(&self) -> Result<EventType, u8> {
get_bit_range!(self.event, u8, u8, 1, 0).try_into()
}
pub fn set_event_type(&mut self, event_type: EventType) {
set_bit_range!(&mut self.event, event_type, u8, u8, 1, 0);
}
pub fn event_object_type(&self) -> Result<EventObjectType, u8> {
get_bit_range!(self.object_type, u8, u8, 2, 0).try_into()
}
pub fn set_event_object_type(&mut self, event_object_type: EventObjectType) {
set_bit_range!(&mut self.object_type, event_object_type, u8, u8, 2, 0);
}
pub fn event_result(&self) -> Result<EventResult, u8> {
get_bit_range!(self.result, u8, u8, 3, 0).try_into()
}
pub fn set_event_result(&mut self, event_result: EventResult) {
set_bit_range!(&mut self.result, event_result, u8, u8, 3, 0);
}
pub fn data_source(&self) -> Result<DataSource, u8> {
get_bit_range!(self.data_source, u8, u8, 1, 0).try_into()
}
pub fn set_data_source(&mut self, data_source: DataSource) {
set_bit_range!(&mut self.data_source, data_source, u8, u8, 1, 0);
}
}
impl ConcreteMessage for MsgNdbEvent {
const MESSAGE_TYPE: u16 = 1024;
const MESSAGE_NAME: &'static str = "MSG_NDB_EVENT";
}
impl SbpMessage for MsgNdbEvent {
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 MsgNdbEvent {
type Error = TryFromSbpError;
fn try_from(msg: Sbp) -> Result<Self, Self::Error> {
match msg {
Sbp::MsgNdbEvent(m) => Ok(m),
_ => Err(TryFromSbpError),
}
}
}
impl WireFormat for MsgNdbEvent {
const MIN_LEN: usize = <u64 as WireFormat>::MIN_LEN
+ <u8 as WireFormat>::MIN_LEN
+ <u8 as WireFormat>::MIN_LEN
+ <u8 as WireFormat>::MIN_LEN
+ <u8 as WireFormat>::MIN_LEN
+ <GnssSignal as WireFormat>::MIN_LEN
+ <GnssSignal as WireFormat>::MIN_LEN
+ <u16 as WireFormat>::MIN_LEN;
fn len(&self) -> usize {
WireFormat::len(&self.recv_time)
+ WireFormat::len(&self.event)
+ WireFormat::len(&self.object_type)
+ WireFormat::len(&self.result)
+ WireFormat::len(&self.data_source)
+ WireFormat::len(&self.object_sid)
+ WireFormat::len(&self.src_sid)
+ WireFormat::len(&self.original_sender)
}
fn write<B: BufMut>(&self, buf: &mut B) {
WireFormat::write(&self.recv_time, buf);
WireFormat::write(&self.event, buf);
WireFormat::write(&self.object_type, buf);
WireFormat::write(&self.result, buf);
WireFormat::write(&self.data_source, buf);
WireFormat::write(&self.object_sid, buf);
WireFormat::write(&self.src_sid, buf);
WireFormat::write(&self.original_sender, buf);
}
fn parse_unchecked<B: Buf>(buf: &mut B) -> Self {
MsgNdbEvent {
sender_id: None,
recv_time: WireFormat::parse_unchecked(buf),
event: WireFormat::parse_unchecked(buf),
object_type: WireFormat::parse_unchecked(buf),
result: WireFormat::parse_unchecked(buf),
data_source: WireFormat::parse_unchecked(buf),
object_sid: WireFormat::parse_unchecked(buf),
src_sid: WireFormat::parse_unchecked(buf),
original_sender: WireFormat::parse_unchecked(buf),
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum EventType {
UNKNOWN = 0,
STORE = 1,
FETCH = 2,
ERASE = 3,
}
impl std::fmt::Display for EventType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
EventType::UNKNOWN => f.write_str("UNKNOWN"),
EventType::STORE => f.write_str("STORE"),
EventType::FETCH => f.write_str("FETCH"),
EventType::ERASE => f.write_str("ERASE"),
}
}
}
impl TryFrom<u8> for EventType {
type Error = u8;
fn try_from(i: u8) -> Result<Self, Self::Error> {
match i {
0 => Ok(EventType::UNKNOWN),
1 => Ok(EventType::STORE),
2 => Ok(EventType::FETCH),
3 => Ok(EventType::ERASE),
i => Err(i),
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum EventObjectType {
UNKNOWN = 0,
EPHEMERIS = 1,
ALMANAC = 2,
AlmanacWn = 3,
IoNO = 4,
L2CCap = 5,
LGF = 6,
}
impl std::fmt::Display for EventObjectType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
EventObjectType::UNKNOWN => f.write_str("UNKNOWN"),
EventObjectType::EPHEMERIS => f.write_str("EPHEMERIS"),
EventObjectType::ALMANAC => f.write_str("ALMANAC"),
EventObjectType::AlmanacWn => f.write_str("ALMANAC_WN"),
EventObjectType::IoNO => f.write_str("IONO"),
EventObjectType::L2CCap => f.write_str("L2C_CAP"),
EventObjectType::LGF => f.write_str("LGF"),
}
}
}
impl TryFrom<u8> for EventObjectType {
type Error = u8;
fn try_from(i: u8) -> Result<Self, Self::Error> {
match i {
0 => Ok(EventObjectType::UNKNOWN),
1 => Ok(EventObjectType::EPHEMERIS),
2 => Ok(EventObjectType::ALMANAC),
3 => Ok(EventObjectType::AlmanacWn),
4 => Ok(EventObjectType::IoNO),
5 => Ok(EventObjectType::L2CCap),
6 => Ok(EventObjectType::LGF),
i => Err(i),
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum EventResult {
NdbErrNone = 0,
NdbErrMissingIe = 1,
NdbErrUnsupported = 2,
NdbErrFileIo = 3,
NdbErrInitDone = 4,
NdbErrBadParam = 5,
NdbErrUnreliableData = 6,
NdbErrAlgorithmError = 7,
NdbErrNoData = 8,
NdbErrNoChange = 9,
NdbErrOlderData = 10,
}
impl std::fmt::Display for EventResult {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
EventResult::NdbErrNone => f.write_str("NDB_ERR_NONE"),
EventResult::NdbErrMissingIe => f.write_str("NDB_ERR_MISSING_IE"),
EventResult::NdbErrUnsupported => f.write_str("NDB_ERR_UNSUPPORTED"),
EventResult::NdbErrFileIo => f.write_str("NDB_ERR_FILE_IO"),
EventResult::NdbErrInitDone => f.write_str("NDB_ERR_INIT_DONE"),
EventResult::NdbErrBadParam => f.write_str("NDB_ERR_BAD_PARAM"),
EventResult::NdbErrUnreliableData => f.write_str("NDB_ERR_UNRELIABLE_DATA"),
EventResult::NdbErrAlgorithmError => f.write_str("NDB_ERR_ALGORITHM_ERROR"),
EventResult::NdbErrNoData => f.write_str("NDB_ERR_NO_DATA"),
EventResult::NdbErrNoChange => f.write_str("NDB_ERR_NO_CHANGE"),
EventResult::NdbErrOlderData => f.write_str("NDB_ERR_OLDER_DATA"),
}
}
}
impl TryFrom<u8> for EventResult {
type Error = u8;
fn try_from(i: u8) -> Result<Self, Self::Error> {
match i {
0 => Ok(EventResult::NdbErrNone),
1 => Ok(EventResult::NdbErrMissingIe),
2 => Ok(EventResult::NdbErrUnsupported),
3 => Ok(EventResult::NdbErrFileIo),
4 => Ok(EventResult::NdbErrInitDone),
5 => Ok(EventResult::NdbErrBadParam),
6 => Ok(EventResult::NdbErrUnreliableData),
7 => Ok(EventResult::NdbErrAlgorithmError),
8 => Ok(EventResult::NdbErrNoData),
9 => Ok(EventResult::NdbErrNoChange),
10 => Ok(EventResult::NdbErrOlderData),
i => Err(i),
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum DataSource {
NdbDsUndefined = 0,
NdbDsInit = 1,
NdbDsReceiver = 2,
NdbDsSbp = 3,
}
impl std::fmt::Display for DataSource {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
DataSource::NdbDsUndefined => f.write_str("NDB_DS_UNDEFINED"),
DataSource::NdbDsInit => f.write_str("NDB_DS_INIT"),
DataSource::NdbDsReceiver => f.write_str("NDB_DS_RECEIVER"),
DataSource::NdbDsSbp => f.write_str("NDB_DS_SBP"),
}
}
}
impl TryFrom<u8> for DataSource {
type Error = u8;
fn try_from(i: u8) -> Result<Self, Self::Error> {
match i {
0 => Ok(DataSource::NdbDsUndefined),
1 => Ok(DataSource::NdbDsInit),
2 => Ok(DataSource::NdbDsReceiver),
3 => Ok(DataSource::NdbDsSbp),
i => Err(i),
}
}
}
}