Skip to content

Commit 5e3bcc3

Browse files
committed
feat: add meta info about databases
1 parent 0b69c1d commit 5e3bcc3

File tree

15 files changed

+352
-121
lines changed

15 files changed

+352
-121
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ If you bundle outdated navigation data in your aircraft and you want this module
3636

3737
## Where is the Navigation Data Stored?
3838

39-
The default location for navigation data is `work/NavigationData`. If you have bundled navigation data, its located in the `NavigationData` folder in the root of your project. You can use the `GetActiveDatabasePath` function from the interface to find the most up to date version installed.
39+
The default location for navigation data is `work/NavigationData`. If you have bundled navigation data, its located in the `NavigationData` folder in the root of your project.
4040

4141
## Building the Sample Aircraft
4242

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
<?xml version="1.0" encoding="utf-8"?>
2-
<Project Version="2" Name="NavigationDataInterfaceAircraftProject" FolderName="Packages" PublishingGroupFolderName="PublishingGroupsContent" MetadataFolderName="PackagesMetadata" PublishingGroupMetadataFolderName="PublishingGroupsMetadata">
3-
<OutputDirectory>.</OutputDirectory>
4-
<TemporaryOutputDirectory>_PackageInt</TemporaryOutputDirectory>
5-
<PublishingGroupTemporaryOutputDirectory>_PublishingGroupInt</PublishingGroupTemporaryOutputDirectory>
6-
<Packages>
7-
<Package>PackageDefinitions\navigraph-aircraft-navigation-data-interface-sample.xml</Package>
8-
</Packages>
9-
<PublishingGroups/>
10-
</Project>
11-
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project Version="2" Name="NavigationDataInterfaceAircraftProject" FolderName="Packages" PublishingGroupFolderName="PublishingGroupsContent" MetadataFolderName="PackagesMetadata" PublishingGroupMetadataFolderName="PublishingGroupsMetadata">
3+
<OutputDirectory>.</OutputDirectory>
4+
<TemporaryOutputDirectory>_PackageInt</TemporaryOutputDirectory>
5+
<PublishingGroupTemporaryOutputDirectory>_PublishingGroupInt</PublishingGroupTemporaryOutputDirectory>
6+
<Packages>
7+
<Package>PackageDefinitions\navigraph-aircraft-navigation-data-interface-sample.xml</Package>
8+
</Packages>
9+
<PublishingGroups/>
10+
</Project>
11+
Lines changed: 56 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,56 @@
1-
<?xml version="1.0" encoding="utf-8"?>
2-
<AssetPackage Version="0.1.0">
3-
<ItemSettings>
4-
<ContentType>AIRCRAFT</ContentType>
5-
<Title>Navigraph Navigation Data Interface Sample Aircraft</Title>
6-
<Manufacturer>My Manufacturer</Manufacturer>
7-
<Creator>Navigraph</Creator>
8-
</ItemSettings>
9-
<Flags>
10-
<VisibleInStore>true</VisibleInStore>
11-
<CanBeReferenced>true</CanBeReferenced>
12-
</Flags>
13-
<AssetGroups>
14-
<AssetGroup Name="ContentInfo">
15-
<Type>Copy</Type>
16-
<Flags>
17-
<FSXCompatibility>false</FSXCompatibility>
18-
</Flags>
19-
<AssetDir>PackageDefinitions\navigraph-aircraft-navigation-data-interface-sample\ContentInfo\</AssetDir>
20-
<OutputDir>ContentInfo\navigraph-aircraft-navigation-data-interface-sample\</OutputDir>
21-
</AssetGroup>
22-
<AssetGroup Name="Data">
23-
<Type>Copy</Type>
24-
<Flags>
25-
<FSXCompatibility>false</FSXCompatibility>
26-
</Flags>
27-
<AssetDir>PackageSources\Data\</AssetDir>
28-
<OutputDir>Data\</OutputDir>
29-
</AssetGroup>
30-
<AssetGroup Name="SimObject">
31-
<Type>SimObject</Type>
32-
<Flags>
33-
<FSXCompatibility>false</FSXCompatibility>
34-
</Flags>
35-
<AssetDir>PackageSources\SimObjects\Airplanes\Navigraph_Navigation_Data_Interface_Aircraft\</AssetDir>
36-
<OutputDir>SimObjects\Airplanes\Navigraph_Navigation_Data_Interface_Aircraft\</OutputDir>
37-
</AssetGroup>
38-
<AssetGroup Name="html_ui">
39-
<Type>Copy</Type>
40-
<Flags>
41-
<FSXCompatibility>false</FSXCompatibility>
42-
</Flags>
43-
<AssetDir>PackageSources\html_ui\</AssetDir>
44-
<OutputDir>html_ui\</OutputDir>
45-
</AssetGroup>
46-
<AssetGroup Name="NavigationData">
47-
<Type>Copy</Type>
48-
<Flags>
49-
<FSXCompatibility>false</FSXCompatibility>
50-
</Flags>
51-
<AssetDir>PackageSources\NavigationData\</AssetDir>
52-
<OutputDir>NavigationData\</OutputDir>
53-
</AssetGroup>
54-
</AssetGroups>
55-
</AssetPackage>
56-
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<AssetPackage Version="0.1.0">
3+
<ItemSettings>
4+
<ContentType>AIRCRAFT</ContentType>
5+
<Title>Navigraph Navigation Data Interface Sample Aircraft</Title>
6+
<Manufacturer>My Manufacturer</Manufacturer>
7+
<Creator>Navigraph</Creator>
8+
</ItemSettings>
9+
<Flags>
10+
<VisibleInStore>true</VisibleInStore>
11+
<CanBeReferenced>true</CanBeReferenced>
12+
</Flags>
13+
<AssetGroups>
14+
<AssetGroup Name="ContentInfo">
15+
<Type>Copy</Type>
16+
<Flags>
17+
<FSXCompatibility>false</FSXCompatibility>
18+
</Flags>
19+
<AssetDir>PackageDefinitions\navigraph-aircraft-navigation-data-interface-sample\ContentInfo\</AssetDir>
20+
<OutputDir>ContentInfo\navigraph-aircraft-navigation-data-interface-sample\</OutputDir>
21+
</AssetGroup>
22+
<AssetGroup Name="Data">
23+
<Type>Copy</Type>
24+
<Flags>
25+
<FSXCompatibility>false</FSXCompatibility>
26+
</Flags>
27+
<AssetDir>PackageSources\Data\</AssetDir>
28+
<OutputDir>Data\</OutputDir>
29+
</AssetGroup>
30+
<AssetGroup Name="NavigationData">
31+
<Type>Copy</Type>
32+
<Flags>
33+
<FSXCompatibility>false</FSXCompatibility>
34+
</Flags>
35+
<AssetDir>PackageSources\NavigationData\</AssetDir>
36+
<OutputDir>NavigationData\</OutputDir>
37+
</AssetGroup>
38+
<AssetGroup Name="SimObject">
39+
<Type>SimObject</Type>
40+
<Flags>
41+
<FSXCompatibility>false</FSXCompatibility>
42+
</Flags>
43+
<AssetDir>PackageSources\SimObjects\Airplanes\Navigraph_Navigation_Data_Interface_Aircraft\</AssetDir>
44+
<OutputDir>SimObjects\Airplanes\Navigraph_Navigation_Data_Interface_Aircraft\</OutputDir>
45+
</AssetGroup>
46+
<AssetGroup Name="html_ui">
47+
<Type>Copy</Type>
48+
<Flags>
49+
<FSXCompatibility>false</FSXCompatibility>
50+
</Flags>
51+
<AssetDir>PackageSources\html_ui\</AssetDir>
52+
<OutputDir>html_ui\</OutputDir>
53+
</AssetGroup>
54+
</AssetGroups>
55+
</AssetPackage>
56+

examples/aircraft/PackageSources/NavigationData/outdated-cycle/ESSA.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/database/src/math.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ pub type Minutes = f64;
1010
pub type KiloHertz = f64;
1111
pub type MegaHertz = f64;
1212

13-
pub(crate) fn feet_to_meters(metres: Meters) -> Feet { metres / 3.28084 }
13+
pub(crate) fn feet_to_meters(metres: Meters) -> Feet {
14+
metres / 3.28084
15+
}
1416

1517
#[derive(Serialize, Deserialize, Debug, Copy, Clone)]
1618
pub struct Coordinates {

src/database/src/sql_structs.rs

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,11 @@
11
use serde::Deserialize;
22

33
use super::enums::{
4-
AirwayDirection,
5-
AirwayLevel,
6-
AirwayRouteType,
7-
AltitudeDescriptor,
8-
LegType,
9-
SpeedDescriptor,
10-
TurnDirection,
4+
AirwayDirection, AirwayLevel, AirwayRouteType, AltitudeDescriptor, LegType, SpeedDescriptor, TurnDirection,
115
};
126
use crate::enums::{
13-
ApproachTypeIdentifier,
14-
CommunicationType,
15-
ControlledAirspaceType,
16-
FrequencyUnits,
17-
IfrCapability,
18-
RestrictiveAirspaceType,
19-
RunwaySurfaceCode,
7+
ApproachTypeIdentifier, CommunicationType, ControlledAirspaceType, FrequencyUnits, IfrCapability,
8+
RestrictiveAirspaceType, RunwaySurfaceCode,
209
};
2110

2211
#[derive(Deserialize, Debug)]

src/js/interface/NavigationDataInterfaceTypes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ export interface DownloadProgressData {
2424

2525
export enum NavigraphFunction {
2626
DownloadNavigationData = "DownloadNavigationData",
27-
GetActiveDatabasePath = "GetActiveDatabasePath",
2827
SetDownloadOptions = "SetDownloadOptions",
28+
GetNavigationDataInstallStatus = "GetNavigationDataInstallStatus",
2929
ExecuteSQLQuery = "ExecuteSQLQuery",
3030
GetDatabaseInfo = "GetDatabaseInfo",
3131
GetAirport = "GetAirport",

src/js/interface/NavigraphNavigationDataInterface.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
VhfNavaid,
1919
Waypoint,
2020
} from "../types"
21+
import { NavigationDataStatus } from "../types/meta"
2122
import {
2223
Callback,
2324
CommBusMessage,
@@ -75,16 +76,6 @@ export class NavigraphNavigationDataInterface {
7576
return await this.callWasmFunction("DownloadNavigationData", { url })
7677
}
7778

78-
/**
79-
* Gets the currently active database path
80-
*
81-
* @returns A promise that resolves with the path of the currently active database
82-
*/
83-
84-
public async get_active_database_path(): Promise<string> {
85-
return await this.callWasmFunction("GetActiveDatabasePath", {})
86-
}
87-
8879
/**
8980
* Sets the download options for all future downloads
9081
*
@@ -95,6 +86,15 @@ export class NavigraphNavigationDataInterface {
9586
return await this.callWasmFunction("SetDownloadOptions", batch_size)
9687
}
9788

89+
/**
90+
* Gets the installation status of the navigation data
91+
*
92+
* @returns A promise that resolves with the installation status
93+
*/
94+
public async get_navigation_data_install_status(): Promise<NavigationDataStatus> {
95+
return await this.callWasmFunction("GetNavigationDataInstallStatus", {})
96+
}
97+
9898
/**
9999
* Gets information about the currently active database
100100
*/

src/js/types/meta.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export enum InstallStatus {
2+
Bundled = "Bundled",
3+
Manual = "Manual",
4+
None = "None",
5+
}
6+
7+
export interface NavigationDataStatus {
8+
status: InstallStatus
9+
installedFormat: string | null
10+
installedCycle: string | null
11+
lastestCycle: string | null
12+
}

src/wasm/src/dispatcher.rs

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
11
use std::{cell::RefCell, error::Error, path::Path, rc::Rc};
22

3-
use msfs::{commbus::*, sys::sGaugeDrawData, MSFSEvent};
3+
use msfs::{commbus::*, network::NetworkRequestState, sys::sGaugeDrawData, MSFSEvent};
44
use navigation_database::database::Database;
55

66
use crate::{
7-
consts,
8-
download::downloader::{DownloadStatus, NavigationDataDownloader},
9-
json_structs::{
10-
data::GetActiveDatabasePathData,
7+
consts, download::downloader::{DownloadStatus, NavigationDataDownloader}, json_structs::{
118
events,
129
functions::{CallFunction, FunctionResult, FunctionStatus, FunctionType},
1310
params,
14-
},
15-
util::{self, path_exists},
11+
}, meta, network_helper::NetworkHelper, util::{self, path_exists}
1612
};
1713

1814
#[derive(PartialEq, Eq)]
@@ -28,6 +24,7 @@ pub struct Task {
2824
pub id: String,
2925
pub data: Option<serde_json::Value>,
3026
pub status: TaskStatus,
27+
pub associated_network_request: Option<NetworkHelper>,
3128
}
3229

3330
impl Task {
@@ -181,18 +178,16 @@ impl<'a> Dispatcher<'a> {
181178
// Now we can download the navigation data
182179
self.downloader.download(Rc::clone(task));
183180
},
184-
FunctionType::GetActiveDatabasePath => Dispatcher::execute_task(task.clone(), |t| {
185-
let data = GetActiveDatabasePathData {
186-
path: self.database.path.clone(),
187-
};
188-
189-
t.borrow_mut().status = TaskStatus::Success(Some(serde_json::to_value(data)?));
190-
191-
Ok(())
192-
}),
193181
FunctionType::SetDownloadOptions => {
194182
Dispatcher::execute_task(task.clone(), |t| self.downloader.set_download_options(t))
195183
},
184+
FunctionType::GetNavigationDataInstallStatus => {
185+
// We can't use the execute_task function here because the download process doesn't finish in the
186+
// function call, which results in slightly "messier" code
187+
188+
// We first need to initialize the network request and then wait for the response
189+
meta::start_network_request(Rc::clone(task))
190+
},
196191
FunctionType::ExecuteSQLQuery => Dispatcher::execute_task(task.clone(), |t| {
197192
let params = t.borrow().parse_data_as::<params::ExecuteSQLQueryParams>()?;
198193
let data = self.database.execute_sql_query(params.sql, params.params)?;
@@ -409,6 +404,30 @@ impl<'a> Dispatcher<'a> {
409404
}
410405
}
411406

407+
// Network request tasks
408+
for task in queue.iter().filter(|task| task.borrow().status == TaskStatus::InProgress) {
409+
let response_state = match task.borrow().associated_network_request {
410+
Some(ref request) => request.response_state(),
411+
None => continue,
412+
};
413+
let function_type = task.borrow().function_type;
414+
if response_state == NetworkRequestState::DataReady {
415+
match function_type {
416+
FunctionType::GetNavigationDataInstallStatus => {
417+
println!("[NAVIGRAPH] Network request completed, getting install status");
418+
meta::get_navigation_data_install_status(Rc::clone(task));
419+
println!("[NAVIGRAPH] Install status task completed");
420+
},
421+
_ => {
422+
// Should not happen for now
423+
println!("[NAVIGRAPH] Network request completed but no handler for this type of request");
424+
},
425+
}
426+
} else if response_state == NetworkRequestState::Failed {
427+
task.borrow_mut().status = TaskStatus::Failure("Network request failed".to_owned());
428+
}
429+
}
430+
412431
// Process completed tasks (everything should at least be in progress at this point)
413432
queue.retain(|task| {
414433
if let TaskStatus::InProgress = task.borrow().status {
@@ -468,6 +487,7 @@ impl<'a> Dispatcher<'a> {
468487
id: json_result.id,
469488
data: json_result.data,
470489
status: TaskStatus::NotStarted,
490+
associated_network_request: None,
471491
})));
472492

473493
Ok(())

0 commit comments

Comments
 (0)