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