nmea_parser/gnss/dbs.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/// DBS - Depth Below Surface
20#[derive(Clone, Debug, PartialEq, Serialize)]
21pub struct DbsData {
22 /// Water depth below surface, meters
23 pub depth_meters: Option<f64>,
24
25 /// Water depth below surface, feet
26 pub depth_feet: Option<f64>,
27
28 /// Water depth below surface, Fathoms
29 pub depth_fathoms: Option<f64>,
30}
31
32// -------------------------------------------------------------------------------------------------
33
34/// xxDBS: Depth Below Surface
35pub(crate) fn handle(sentence: &str) -> Result<ParsedMessage, ParseError> {
36 let split: Vec<&str> = sentence.split(',').collect();
37
38 Ok(ParsedMessage::Dbs(DbsData {
39 depth_meters: pick_number_field(&split, 3)?,
40 depth_feet: pick_number_field(&split, 1)?,
41 depth_fathoms: pick_number_field(&split, 5)?,
42 }))
43}
44
45// -------------------------------------------------------------------------------------------------
46
47#[cfg(test)]
48mod test {
49 use super::*;
50 use crate::NmeaParser;
51
52 #[test]
53 fn test_parse_dpt() {
54 match NmeaParser::new().parse_sentence("$SDDBS,16.9,f,5.2,M,2.8,F*32") {
55 Ok(ps) => match ps {
56 ParsedMessage::Dbs(dbs) => {
57 assert_eq!(dbs.depth_meters, Some(5.2));
58 assert_eq!(dbs.depth_feet, Some(16.9));
59 assert_eq!(dbs.depth_fathoms, Some(2.8))
60 }
61 ParsedMessage::Incomplete => {
62 assert!(false);
63 }
64 _ => {
65 assert!(false);
66 }
67 },
68 Err(e) => {
69 assert_eq!(e.to_string(), "OK");
70 }
71 }
72 }
73}