nmea_parser/gnss/hdt.rs
1/*
2Copyright 2021 Linus Eing
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/// HDT - Heading, true
20#[derive(Clone, Debug, PartialEq, Serialize)]
21pub struct HdtData {
22 /// Heading - true
23 pub heading_true: Option<f64>,
24}
25
26// -------------------------------------------------------------------------------------------------
27
28/// xxHDT: Heading, true
29pub(crate) fn handle(sentence: &str) -> Result<ParsedMessage, ParseError> {
30 let split: Vec<&str> = sentence.split(',').collect();
31
32 Ok(ParsedMessage::Hdt(HdtData {
33 heading_true: pick_number_field(&split, 1)?,
34 }))
35}
36
37// -------------------------------------------------------------------------------------------------
38
39#[cfg(test)]
40mod test {
41 use super::*;
42
43 #[test]
44 fn test_parse_hdt() {
45 match NmeaParser::new().parse_sentence("$IIHDT,15.0,T*16") {
46 Ok(ps) => match ps {
47 ParsedMessage::Hdt(hdt) => {
48 assert_eq!(hdt.heading_true, Some(15.0))
49 }
50 _ => {
51 assert!(false);
52 }
53 },
54 Err(e) => {
55 assert_eq!(e.to_string(), "OK");
56 }
57 }
58 }
59}