use super::*;
#[derive(Clone, Debug, PartialEq, Serialize)]
pub struct GllData {
pub source: NavigationSystem,
pub latitude: Option<f64>,
pub longitude: Option<f64>,
#[serde(with = "json_date_time_utc")]
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.with_ymd_and_hms(2000, 1, 1, 0, 0, 0).single().unwrap();
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, {
Utc.with_ymd_and_hms(2000, 01, 01, 22, 54, 44).single()
});
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");
}
}
}
}