nmea_parser/gnss/mtw.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/// MTW - Mean Temperature of Water
20#[derive(Clone, Debug, PartialEq, Serialize)]
21pub struct MtwData {
22 /// Water temperature in degrees Celsius
23 pub temperature: Option<f64>,
24}
25
26// -------------------------------------------------------------------------------------------------
27
28/// xxMTW: Mean Temperature of Water
29pub(crate) fn handle(sentence: &str) -> Result<ParsedMessage, ParseError> {
30 let split: Vec<&str> = sentence.split(',').collect();
31
32 Ok(ParsedMessage::Mtw(MtwData {
33 temperature: pick_number_field(&split, 1)?,
34 }))
35}
36
37// -------------------------------------------------------------------------------------------------
38
39#[cfg(test)]
40mod test {
41 use super::*;
42 use crate::NmeaParser;
43
44 #[test]
45 fn test_parse_dpt() {
46 match NmeaParser::new().parse_sentence("$INMTW,17.9,C*1B") {
47 Ok(ps) => match ps {
48 ParsedMessage::Mtw(mtw) => {
49 assert_eq!(mtw.temperature, Some(17.9))
50 }
51 ParsedMessage::Incomplete => {
52 assert!(false);
53 }
54 _ => {
55 assert!(false);
56 }
57 },
58 Err(e) => {
59 assert_eq!(e.to_string(), "OK");
60 }
61 }
62 }
63}