nmea_parser/gnss/
stn.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/// STN - MSK Receiver Signal
20#[derive(Clone, Debug, PartialEq, Serialize)]
21pub struct StnData {
22    /// Navigation system
23    pub source: NavigationSystem,
24
25    /// Talker id numer (0-99)
26    pub talker_id: Option<u8>,
27}
28
29// -------------------------------------------------------------------------------------------------
30
31/// xxSTN: MSK Receiver Signal
32pub(crate) fn handle(
33    sentence: &str,
34    nav_system: NavigationSystem,
35) -> Result<ParsedMessage, ParseError> {
36    let split: Vec<&str> = sentence.split(',').collect();
37
38    Ok(ParsedMessage::Stn(StnData {
39        source: nav_system,
40        talker_id: pick_number_field(&split, 1)?,
41    }))
42}
43
44// -------------------------------------------------------------------------------------------------
45
46#[cfg(test)]
47mod test {
48    use super::*;
49
50    #[test]
51    fn test_parse_cpstn() {
52        match NmeaParser::new().parse_sentence("$GPSTN,23") {
53            Ok(ps) => match ps {
54                ParsedMessage::Stn(stn) => {
55                    assert_eq!(stn.source, NavigationSystem::Gps);
56                    assert_eq!(stn.talker_id, Some(23));
57                }
58                ParsedMessage::Incomplete => {
59                    assert!(false);
60                }
61                _ => {
62                    assert!(false);
63                }
64            },
65            Err(e) => {
66                assert_eq!(e.to_string(), "OK");
67            }
68        }
69    }
70}