1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
use super::*;
#[derive(Clone, Debug, PartialEq)]
pub struct GllData {
pub source: NavigationSystem,
pub latitude: Option<f64>,
pub longitude: Option<f64>,
pub timestamp: Option<DateTime<Utc>>,
pub data_valid: Option<bool>,
pub faa_mode: Option<FaaMode>,
}
impl LatLon for GllData {
fn latitude(&self) -> Option<f64> {
self.latitude
}
fn longitude(&self) -> Option<f64> {
self.longitude
}
}
pub(crate) fn handle(
sentence: &str,
nav_system: NavigationSystem,
) -> Result<ParsedMessage, ParseError> {
let now: DateTime<Utc> = Utc.ymd(2000, 1, 1).and_hms(0, 0, 0);
let split: Vec<&str> = sentence.split(',').collect();
Ok(ParsedMessage::Gll(GllData {
source: nav_system,
latitude: parse_latitude_ddmm_mmm(
split.get(1).unwrap_or(&""),
split.get(2).unwrap_or(&""),
)?,
longitude: parse_longitude_dddmm_mmm(
split.get(3).unwrap_or(&""),
split.get(4).unwrap_or(&""),
)?,
timestamp: parse_hhmmss(split.get(5).unwrap_or(&""), now).ok(),
data_valid: {
match *split.get(6).unwrap_or(&"") {
"A" => Some(true),
"V" => Some(false),
_ => None,
}
},
faa_mode: FaaMode::new(split.get(7).unwrap_or(&"")).ok(),
}))
}
#[cfg(test)]
mod test {
use super::*;
#[test]
fn test_parse_gagll() {
let mut p = NmeaParser::new();
match p.parse_sentence("$GAGLL,4916.45,N,12311.12,W,225444,A,D*48") {
Ok(ps) => {
match ps {
ParsedMessage::Gll(gll) => {
assert_eq!(gll.source, NavigationSystem::Galileo);
assert::close(gll.latitude.unwrap_or(0.0), 49.3, 0.1);
assert::close(gll.longitude.unwrap_or(0.0), -123.2, 0.1);
assert_eq!(gll.timestamp, {
Some(Utc.ymd(2000, 01, 01).and_hms(22, 54, 44))
});
assert_eq!(gll.data_valid, Some(true));
assert_eq!(gll.faa_mode, Some(FaaMode::Differential));
}
_ => {
assert!(false);
}
}
}
Err(e) => {
assert_eq!(e.to_string(), "OK");
}
}
}
}