diff --git a/src/database/src/database.rs b/src/database/src/database.rs index 490198b8..ef387f34 100644 --- a/src/database/src/database.rs +++ b/src/database/src/database.rs @@ -112,7 +112,7 @@ impl Database { ValueRef::Integer(int) => Some(Value::Number(Number::from(int))), ValueRef::Real(real) => Some(Value::Number(Number::from_f64(real).unwrap())), ValueRef::Null => None, - ValueRef::Blob(_) => panic!("Unexpected value type Blob"), + ValueRef::Blob(_) => None, }; if let Some(value) = value { diff --git a/src/database/src/enums.rs b/src/database/src/enums.rs index 766167be..c82dca9c 100644 --- a/src/database/src/enums.rs +++ b/src/database/src/enums.rs @@ -62,6 +62,8 @@ pub enum TurnDirection { Left, #[serde(rename = "R")] Right, + #[serde(rename = "E")] + Either, } #[derive(Serialize, Deserialize, Debug, Copy, Clone)] @@ -366,6 +368,8 @@ pub enum RunwaySurface { Water, #[serde(rename = "BITU")] Bitumen, + #[serde(rename = "PAVD")] + Paved, #[serde(rename = "UNPV")] Unpaved, } diff --git a/src/database/src/output/airspace.rs b/src/database/src/output/airspace.rs index ec732cdc..596bcd94 100644 --- a/src/database/src/output/airspace.rs +++ b/src/database/src/output/airspace.rs @@ -24,6 +24,8 @@ pub enum PathType { RhumbLine, #[serde(rename = "A")] Arc, + #[serde(rename = "U")] + Unknown, } #[serde_with::skip_serializing_none] @@ -48,16 +50,16 @@ impl Path { match boundary_char { 'C' => Self { location: Coordinates { - lat: arc_latitude.unwrap(), - long: arc_longitude.unwrap(), + lat: arc_latitude.unwrap_or_default(), + long: arc_longitude.unwrap_or_default(), }, arc: None, path_type: PathType::Circle, }, 'G' | 'H' => Self { location: Coordinates { - lat: latitude.unwrap(), - long: longitude.unwrap(), + lat: latitude.unwrap_or_default(), + long: longitude.unwrap_or_default(), }, arc: None, path_type: match boundary_char { @@ -67,16 +69,16 @@ impl Path { }, 'L' | 'R' => Self { location: Coordinates { - lat: latitude.unwrap(), - long: longitude.unwrap(), + lat: latitude.unwrap_or_default(), + long: longitude.unwrap_or_default(), }, arc: Some(Arc { origin: Coordinates { - lat: arc_latitude.unwrap(), - long: arc_longitude.unwrap(), + lat: arc_latitude.unwrap_or_default(), + long: arc_longitude.unwrap_or_default(), }, - distance: arc_distance.unwrap(), - bearing: arc_bearing.unwrap(), + distance: arc_distance.unwrap_or_default(), + bearing: arc_bearing.unwrap_or_default(), direction: match boundary_char { 'R' => TurnDirection::Right, _ => TurnDirection::Left, @@ -84,7 +86,14 @@ impl Path { }), path_type: PathType::Arc, }, - _ => panic!("Invalid path type"), + _ => Self { + location: Coordinates { + lat: 0.0, + long: 0.0, + }, + arc: None, + path_type: PathType::Unknown, + }, } } } diff --git a/src/database/src/output/fix.rs b/src/database/src/output/fix.rs index 8325fed8..614ca440 100644 --- a/src/database/src/output/fix.rs +++ b/src/database/src/output/fix.rs @@ -70,7 +70,7 @@ impl Fix { "PI" => FixType::IlsNavaid, "D " => FixType::VhfNavaid, "EA" | "PC" => FixType::Waypoint, - x => panic!("Unexpected table: '{x}'"), + _ => FixType::None, }); Self { diff --git a/src/database/src/output/procedure_leg.rs b/src/database/src/output/procedure_leg.rs index 6fbaaffb..6facf190 100644 --- a/src/database/src/output/procedure_leg.rs +++ b/src/database/src/output/procedure_leg.rs @@ -126,10 +126,10 @@ impl From for ProcedureLeg { ar: leg.authorization_required, fix: if leg.waypoint_identifier.is_some() { Some(Fix::from_row_data( - leg.waypoint_latitude.unwrap(), - leg.waypoint_longitude.unwrap(), - leg.waypoint_identifier.unwrap(), - leg.waypoint_icao_code.unwrap(), + leg.waypoint_latitude.unwrap_or_default(), + leg.waypoint_longitude.unwrap_or_default(), + leg.waypoint_identifier.unwrap_or("ERROR".to_string()), + leg.waypoint_icao_code.unwrap_or("UNKN".to_string()), Some(leg.airport_identifier.clone()), leg.waypoint_ref_table, leg.waypoint_description_code.clone(), @@ -139,10 +139,11 @@ impl From for ProcedureLeg { }, recommended_navaid: if leg.recommended_navaid.is_some() { Some(Fix::from_row_data( - leg.recommended_navaid_latitude.unwrap(), - leg.recommended_navaid_longitude.unwrap(), - leg.recommended_navaid.unwrap(), - leg.recommended_navaid_icao_code.unwrap(), + leg.recommended_navaid_latitude.unwrap_or_default(), + leg.recommended_navaid_longitude.unwrap_or_default(), + leg.recommended_navaid.unwrap_or("ERROR".to_string()), + leg.recommended_navaid_icao_code + .unwrap_or("UNKN".to_string()), Some(leg.airport_identifier.clone()), leg.recommended_navaid_ref_table, leg.waypoint_description_code.clone(), @@ -166,10 +167,10 @@ impl From for ProcedureLeg { turn_direction: leg.turn_direction, arc_center_fix: if leg.center_waypoint.is_some() { Some(Fix::from_row_data( - leg.center_waypoint_latitude.unwrap(), - leg.center_waypoint_longitude.unwrap(), - leg.center_waypoint.unwrap(), - leg.center_waypoint_icao_code.unwrap(), + leg.center_waypoint_latitude.unwrap_or_default(), + leg.center_waypoint_longitude.unwrap_or_default(), + leg.center_waypoint.unwrap_or("ERROR".to_string()), + leg.center_waypoint_icao_code.unwrap_or("UNKN".to_string()), Some(leg.airport_identifier), leg.center_waypoint_ref_table, leg.waypoint_description_code, diff --git a/src/wasm/src/dispatcher.rs b/src/wasm/src/dispatcher.rs index 62b477b2..2a70e8de 100644 --- a/src/wasm/src/dispatcher.rs +++ b/src/wasm/src/dispatcher.rs @@ -49,6 +49,7 @@ pub struct Dispatcher<'a> { database: Database, delta_time: std::time::Duration, queue: Rc>>>>, + first_update: bool, } impl Dispatcher<'_> { @@ -57,17 +58,15 @@ impl Dispatcher<'_> { commbus: CommBus::default(), downloader: Rc::new(NavigationDataDownloader::new()), database: Database::new(), - delta_time: std::time::Duration::from_secs(u64::MAX), /* Initialize to max so that we send a heartbeat on - * the first update */ + delta_time: std::time::Duration::from_secs(0), /* Initialize to max so that we send a heartbeat on + * the first update */ queue: Rc::new(RefCell::new(Vec::new())), + first_update: true, } } pub fn on_msfs_event(&mut self, event: MSFSEvent) { match event { - MSFSEvent::PostInitialize => { - self.handle_initialized(); - } MSFSEvent::PreDraw(data) => { self.handle_update(data); } @@ -96,11 +95,18 @@ impl Dispatcher<'_> { } fn handle_update(&mut self, data: &sGaugeDrawData) { + // On the first update, handle initialization code. Additionally, there are edge cases + // where the delta time causes a panic so we need to skip the first update after that. + if self.first_update { + self.handle_initialized(); + self.first_update = false; + return; + } // Accumulate delta time for heartbeat self.delta_time += data.delta_time(); // Send heartbeat every 5 seconds - if self.delta_time >= std::time::Duration::from_secs(5) { + if self.delta_time >= std::time::Duration::from_secs(1) { Dispatcher::send_event(events::EventType::Heartbeat, None); self.delta_time = std::time::Duration::from_secs(0); } diff --git a/src/wasm/src/util.rs b/src/wasm/src/util.rs index 376c622d..e7f213ab 100644 --- a/src/wasm/src/util.rs +++ b/src/wasm/src/util.rs @@ -26,7 +26,7 @@ pub fn delete_folder_recursively(path: &Path, batch_size: Option) -> io:: let path = entry.path(); let path_type = get_path_type(&path); - if path.file_name().unwrap() == "" { + if path.file_name().is_none_or(|val| val.is_empty()) { eprintln!("[NAVIGRAPH]: Bugged entry"); continue; } @@ -79,7 +79,7 @@ pub fn copy_files_to_folder(from: &Path, to: &Path) -> io::Result<()> { let path = entry.path(); let path_type = get_path_type(&path); - if path.file_name().unwrap() == "" { + if path.file_name().is_none_or(|val| val.is_empty()) { eprintln!("[NAVIGRAPH]: Bugged entry"); continue; }