nmea_parser/ais/vdm_t10.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// -------------------------------------------------------------------------------------------------
20
21/// Type 10: UTC/Date Inquiry
22#[derive(Default, Clone, Debug, PartialEq)]
23pub struct UtcDateInquiry {
24 /// True if the data is about own vessel, false if about other.
25 pub own_vessel: bool,
26
27 /// AIS station type.
28 pub station: Station,
29
30 /// Source MMSI (30 bits)
31 pub source_mmsi: u32,
32
33 /// Destination MMSI (30 bits)
34 pub destination_mmsi: u32,
35}
36
37// -------------------------------------------------------------------------------------------------
38
39/// AIS VDM/VDO type 10: UTC/Date Inquiry
40pub(crate) fn handle(
41 bv: &BitVec,
42 station: Station,
43 own_vessel: bool,
44) -> Result<ParsedMessage, ParseError> {
45 Ok(ParsedMessage::UtcDateInquiry(UtcDateInquiry {
46 own_vessel: { own_vessel },
47 station: { station },
48 source_mmsi: { pick_u64(bv, 8, 30) as u32 },
49 destination_mmsi: { pick_u64(bv, 40, 30) as u32 },
50 }))
51}
52
53// -------------------------------------------------------------------------------------------------
54
55#[cfg(test)]
56mod test {
57 use super::*;
58
59 #[test]
60 fn test_parse_vdm_type10() {
61 let mut p = NmeaParser::new();
62 match p.parse_sentence("!AIVDM,1,1,,B,:5MlU41GMK6@,0*6C") {
63 Ok(ps) => {
64 match ps {
65 // The expected result
66 ParsedMessage::UtcDateInquiry(udi) => {
67 assert_eq!(udi.source_mmsi, 366814480);
68 assert_eq!(udi.destination_mmsi, 366832740);
69 }
70 ParsedMessage::Incomplete => {
71 assert!(false);
72 }
73 _ => {
74 assert!(false);
75 }
76 }
77 }
78 Err(e) => {
79 assert_eq!(e.to_string(), "OK");
80 }
81 }
82 }
83}