rtcm_rs/msg/
msm_mappings.rs

1/*
2macro_rules! sig_id_impl {
3    ($type_name:ident) => {
4        impl $type_name {
5            pub fn new(band: u8, attribute: char) -> $type_name {
6                $type_name(band, attribute)
7            }
8            pub fn band(self) -> u8 {
9                self.0
10            }
11            pub fn attribute(self) -> char {
12                self.1
13            }
14            pub fn is_valid(self) -> bool {
15                to_id(self).is_some()
16            }
17        }
18        #[cfg(feature = "test_gen")]
19        impl $crate::source_repr::SourceRepr for $type_name {
20            fn to_source(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
21                use core::fmt::Write;
22                write!(f, "{}::new(", stringify!($type_name))?;
23                self.0.to_source(f)?;
24                f.write_char(',')?;
25                self.1.to_source(f)?;
26                f.write_char(')')?;
27
28                Ok(())
29            }
30        }
31    };
32}  */
33
34macro_rules! msm_mappings {
35    (
36        gnss: $gnss:ident,
37        mappings: [ $( $num:literal => $band:literal|$attr:literal ),+ ]
38    ) => {
39        pub mod $gnss {
40            #[cfg(feature = "serde")]
41            use $crate::{Deserialize, Serialize};
42            #[cfg(feature = "serde")]
43            extern crate sd;
44
45            #[derive(Clone, Copy, PartialEq, Eq, Default, Debug)]
46            #[cfg_attr(feature = "serde", derive(Serialize, Deserialize), serde(crate = "sd"))]
47            pub struct SigId(u8, char);
48
49            impl SigId {
50                pub fn new(band: u8, attribute: char) -> SigId {
51                    SigId(band, attribute)
52                }
53                pub fn band(self) -> u8 {
54                    self.0
55                }
56                pub fn attribute(self) -> char {
57                    self.1
58                }
59                pub fn is_valid(self) -> bool {
60                    to_id(self).is_some()
61                }
62            }
63            #[allow(unused)]
64            pub fn to_sig(id: u8) -> Option<SigId> {
65                match id {
66                    $(
67                        $num => Some(SigId($band,$attr)),
68                    )+
69                    _ => None,
70                }
71            }
72
73            pub fn to_id(sig: SigId) -> Option<u8> {
74                match sig {
75                    $(
76                        SigId($band, $attr) => Some($num),
77                    )+
78                    _ => None,
79                }
80            }
81
82            #[cfg(feature = "test_gen")]
83            impl $crate::source_repr::SourceRepr for SigId {
84                fn to_source(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
85                    use core::fmt::Write;
86                    write!(f, "{}::new(", stringify!(SigId))?;
87                    self.0.to_source(f)?;
88                    f.write_char(',')?;
89                    self.1.to_source(f)?;
90                    f.write_char(')')?;
91
92                    Ok(())
93                }
94            }
95
96            #[cfg(feature = "test_gen")]
97            pub fn random_id<R: rand::Rng + ?Sized>(rng: &mut R, subset:usize) -> u8 {
98                const IDS:&[u8] = &[ $($num),+ ];
99                let id_idx:usize = ((subset % 32) + (rng.gen::<usize>() % id_len_div64())) % IDS.len();
100                IDS[id_idx]
101            }
102            #[cfg(feature = "test_gen")]
103            pub fn id_len_div64() -> usize {
104                let len = (&[ $($num),+ ]).len();
105                if len == 32 { return 32; }
106                if len >= 16 { return 16; }
107                if len >= 8 { return 8; }
108                if len >= 4 { return 4; }
109                if len >= 2 { return 2; }
110                return 1;
111            }
112            impl core::cmp::PartialOrd for SigId {
113                fn partial_cmp(&self, other: &Self) -> Option<core::cmp::Ordering> {
114                    let l = to_id(*self);
115                    let r = to_id(*other);
116                    if let (Some(l), Some(r)) = (l, r) {
117                        return l.partial_cmp(&r);
118                    } else {
119                        None
120                    }
121                }
122            }
123            impl core::cmp::Ord for SigId {
124                fn cmp(&self, other: &Self) -> core::cmp::Ordering {
125                    let l = to_id(*self);
126                    let r = to_id(*other);
127                    if let (Some(l), Some(r)) = (l, r) {
128                        return l.cmp(&r);
129                    }
130                    if let (None, Some(_)) = (l, r) {
131                        return core::cmp::Ordering::Greater;
132                    }
133                    if let (Some(_), None) = (l, r) {
134                        return core::cmp::Ordering::Less;
135                    }
136                    match self.0.cmp(&other.0) {
137                        core::cmp::Ordering::Less => core::cmp::Ordering::Less,
138                        core::cmp::Ordering::Equal => self.1.cmp(&other.1),
139                        core::cmp::Ordering::Greater => core::cmp::Ordering::Greater,
140                    }
141                }
142            }
143        }
144    };
145}
146
147msm_mappings!(
148    gnss: gps,
149    mappings: [
150        2 => 1|'C',
151        3 => 1|'P',
152        4 => 1|'W',
153        8 => 2|'C',
154        9 => 2|'P',
155        10 => 2|'W',
156        15 => 2|'S',
157        16 => 2|'L',
158        17 => 2|'X',
159        22 => 5|'I',
160        23 => 5|'Q',
161        24 => 5|'X',
162        30 => 1|'S',
163        31 => 1|'L',
164        32 => 1|'X'
165    ]
166);
167
168msm_mappings!(
169    gnss: glo,
170    mappings: [
171        2 => 1|'C',
172        3 => 1|'P',
173        8 => 2|'C',
174        9 => 2|'P'
175    ]
176);
177
178msm_mappings!(
179    gnss: gal,
180    mappings: [
181        2 => 1|'C',
182        3 => 1|'A',
183        4 => 1|'B',
184        5 => 1|'X',
185        6 => 1|'Z',
186        8 => 6|'C',
187        9 => 6|'A',
188        10 => 6|'B',
189        11 => 6|'X',
190        12 => 6|'Z',
191        14 => 7|'I',
192        15 => 7|'Q',
193        16 => 7|'X',
194        18 => 8|'I',
195        19 => 8|'Q',
196        20 => 8|'X',
197        22 => 5|'I',
198        23 => 5|'Q',
199        24 => 5|'X'
200    ]
201);
202
203msm_mappings!(
204    gnss: sbas,
205    mappings: [
206        2 => 1|'C',
207        22 => 5|'I',
208        23 => 5|'Q',
209        24 => 5|'X'
210
211    ]
212);
213
214msm_mappings!(
215    gnss: qzss,
216    mappings: [
217        2 => 1|'C',
218        9 => 6|'S',
219        10 => 6|'L',
220        11 => 6|'X',
221        15 => 2|'S',
222        16 => 2|'L',
223        17 => 2|'X',
224        22 => 5|'I',
225        23 => 5|'Q',
226        24 => 5|'X',
227        30 => 1|'S',
228        31 => 1|'L',
229        32 => 1|'X'
230    ]
231);
232
233msm_mappings!(
234    gnss: bds,
235    mappings: [
236        2 => 2|'I',
237        3 => 2|'Q',
238        4 => 2|'X',
239        8 => 6|'I',
240        9 => 6|'Q',
241        10 => 6|'X',
242        14 => 7|'I',
243        15 => 7|'Q',
244        16 => 7|'X',
245        22 => 5|'D',
246        23 => 5|'P',
247        24 => 5|'X',
248        25 => 7|'D',
249        30 => 1|'D',
250        31 => 1|'P',
251        32 => 1|'X'
252    ]
253);
254
255msm_mappings!(
256    gnss: navic,
257    mappings: [
258        8 => 9|'A',
259        22 => 5|'A'
260    ]
261);