nmea_parser/gnss/
mss.rs

1/*
2Copyright 2020 Timo Saarinen
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8    http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16
17use super::*;
18
19/// MSS - Multiple Data ID
20#[derive(Clone, Debug, PartialEq, Serialize)]
21pub struct MssData {
22    /// Navigation system
23    pub source: NavigationSystem,
24
25    /// Signal strength (dB)
26    pub ss: Option<u8>,
27
28    /// Signal-to-noise ratio
29    pub snr: Option<u8>,
30
31    /// Beacon frequency
32    pub frequency: Option<f64>,
33
34    /// Beacon bit rate
35    pub bit_rate: Option<u32>,
36
37    /// Channel number
38    pub channel: Option<u32>,
39}
40
41// -------------------------------------------------------------------------------------------------
42
43/// xxMSS: Multiple Data ID
44pub(crate) fn handle(
45    sentence: &str,
46    nav_system: NavigationSystem,
47) -> Result<ParsedMessage, ParseError> {
48    let split: Vec<&str> = sentence.split(',').collect();
49
50    Ok(ParsedMessage::Mss(MssData {
51        source: nav_system,
52        ss: pick_number_field(&split, 1)?,
53        snr: pick_number_field(&split, 2)?,
54        frequency: pick_number_field(&split, 3)?,
55        bit_rate: pick_number_field(&split, 4)?,
56        channel: pick_number_field(&split, 5)?,
57    }))
58}
59
60// -------------------------------------------------------------------------------------------------
61
62#[cfg(test)]
63mod test {
64    use super::*;
65
66    #[test]
67    fn test_parse_cpmss() {
68        match NmeaParser::new().parse_sentence("$GPMSS,55,27,318.0,100,1*57") {
69            Ok(ps) => match ps {
70                ParsedMessage::Mss(mss) => {
71                    assert_eq!(mss.source, NavigationSystem::Gps);
72                    assert_eq!(mss.ss, Some(55));
73                    assert_eq!(mss.snr, Some(27));
74                    assert_eq!(mss.frequency, Some(318.0));
75                    assert_eq!(mss.bit_rate, Some(100));
76                    assert_eq!(mss.channel, Some(1));
77                }
78                ParsedMessage::Incomplete => {
79                    assert!(false);
80                }
81                _ => {
82                    assert!(false);
83                }
84            },
85            Err(e) => {
86                assert_eq!(e.to_string(), "OK");
87            }
88        }
89    }
90}