Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/database/src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions src/database/src/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ pub enum TurnDirection {
Left,
#[serde(rename = "R")]
Right,
#[serde(rename = "E")]
Either,
}

#[derive(Serialize, Deserialize, Debug, Copy, Clone)]
Expand Down Expand Up @@ -366,6 +368,8 @@ pub enum RunwaySurface {
Water,
#[serde(rename = "BITU")]
Bitumen,
#[serde(rename = "PAVD")]
Paved,
#[serde(rename = "UNPV")]
Unpaved,
}
Expand Down
31 changes: 20 additions & 11 deletions src/database/src/output/airspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ pub enum PathType {
RhumbLine,
#[serde(rename = "A")]
Arc,
#[serde(rename = "U")]
Unknown,
}

#[serde_with::skip_serializing_none]
Expand All @@ -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 {
Expand All @@ -67,24 +69,31 @@ 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,
},
}),
path_type: PathType::Arc,
},
_ => panic!("Invalid path type"),
_ => Self {
location: Coordinates {
lat: 0.0,
long: 0.0,
},
arc: None,
path_type: PathType::Unknown,
},
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/database/src/output/fix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl Fix {
"PI" => FixType::IlsNavaid,
"D " => FixType::VhfNavaid,
"EA" | "PC" => FixType::Waypoint,
x => panic!("Unexpected table: '{x}'"),
_ => FixType::None,
});

Self {
Expand Down
25 changes: 13 additions & 12 deletions src/database/src/output/procedure_leg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,10 @@ impl From<sql_structs::Procedures> 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(),
Expand All @@ -139,10 +139,11 @@ impl From<sql_structs::Procedures> 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(),
Expand All @@ -166,10 +167,10 @@ impl From<sql_structs::Procedures> 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,
Expand Down
18 changes: 12 additions & 6 deletions src/wasm/src/dispatcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ pub struct Dispatcher<'a> {
database: Database,
delta_time: std::time::Duration,
queue: Rc<RefCell<Vec<Rc<RefCell<Task>>>>>,
first_update: bool,
}

impl Dispatcher<'_> {
Expand All @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions src/wasm/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub fn delete_folder_recursively(path: &Path, batch_size: Option<usize>) -> 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;
}
Expand Down Expand Up @@ -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;
}
Expand Down