Skip to content

Commit

Permalink
Merge pull request #3 from Navigraph/bundled-navigation-data
Browse files Browse the repository at this point in the history
  • Loading branch information
SkySails authored May 14, 2024
2 parents 401b2ce + 312d3e1 commit 2d8906f
Show file tree
Hide file tree
Showing 27 changed files with 763 additions and 196 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
run: npm ci

- name: Run linting
run: npm run lint:js -- -- --max-warnings 0
run: npm run lint:js -- --max-warnings 0

build-test:
name: Build & test 🛠️
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ Here's an overview on the structure of this repository, which is designed to be
```
- Note that if you already have a `VCockpit` with `NO_TEXTURE` you can just add another `htmlgauge` to it, while making sure to increase the index

## Dealing with Bundled Navigation Data

If you bundle outdated navigation data in your aircraft and you want this module to handle updating it for users with subscriptions, place the navigation data into the `NavigationData` directory in `PackageSources`. You can see an example [here](examples/aircraft/PackageSources/NavigationData/)

## Where is the Navigation Data Stored?

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. (although it gets copied into the `work` directory at runtime)

## Building the Sample Aircraft

Before building, make sure you have properly created and set an `.env` file in `examples/gauge`! An example can be found in the `.env.example` file in that directory. Replace with your credentials
Expand Down
22 changes: 11 additions & 11 deletions examples/aircraft/NavigationDataInterfaceAircraftProject.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Version="2" Name="NavigationDataInterfaceAircraftProject" FolderName="Packages" PublishingGroupFolderName="PublishingGroupsContent" MetadataFolderName="PackagesMetadata" PublishingGroupMetadataFolderName="PublishingGroupsMetadata">
<OutputDirectory>.</OutputDirectory>
<TemporaryOutputDirectory>_PackageInt</TemporaryOutputDirectory>
<PublishingGroupTemporaryOutputDirectory>_PublishingGroupInt</PublishingGroupTemporaryOutputDirectory>
<Packages>
<Package>PackageDefinitions\navigraph-aircraft-navigation-data-interface-sample.xml</Package>
</Packages>
<PublishingGroups/>
</Project>

<?xml version="1.0" encoding="utf-8"?>
<Project Version="2" Name="NavigationDataInterfaceAircraftProject" FolderName="Packages" PublishingGroupFolderName="PublishingGroupsContent" MetadataFolderName="PackagesMetadata" PublishingGroupMetadataFolderName="PublishingGroupsMetadata">
<OutputDirectory>.</OutputDirectory>
<TemporaryOutputDirectory>_PackageInt</TemporaryOutputDirectory>
<PublishingGroupTemporaryOutputDirectory>_PublishingGroupInt</PublishingGroupTemporaryOutputDirectory>
<Packages>
<Package>PackageDefinitions\navigraph-aircraft-navigation-data-interface-sample.xml</Package>
</Packages>
<PublishingGroups/>
</Project>

Original file line number Diff line number Diff line change
@@ -1,48 +1,56 @@
<?xml version="1.0" encoding="utf-8"?>
<AssetPackage Version="0.1.0">
<ItemSettings>
<ContentType>AIRCRAFT</ContentType>
<Title>Navigraph Navigation Data Interface Sample Aircraft</Title>
<Manufacturer>My Manufacturer</Manufacturer>
<Creator>Navigraph</Creator>
</ItemSettings>
<Flags>
<VisibleInStore>true</VisibleInStore>
<CanBeReferenced>true</CanBeReferenced>
</Flags>
<AssetGroups>
<AssetGroup Name="ContentInfo">
<Type>Copy</Type>
<Flags>
<FSXCompatibility>false</FSXCompatibility>
</Flags>
<AssetDir>PackageDefinitions\navigraph-aircraft-navigation-data-interface-sample\ContentInfo\</AssetDir>
<OutputDir>ContentInfo\navigraph-aircraft-navigation-data-interface-sample\</OutputDir>
</AssetGroup>
<AssetGroup Name="Data">
<Type>Copy</Type>
<Flags>
<FSXCompatibility>false</FSXCompatibility>
</Flags>
<AssetDir>PackageSources\Data\</AssetDir>
<OutputDir>Data\</OutputDir>
</AssetGroup>
<AssetGroup Name="SimObject">
<Type>SimObject</Type>
<Flags>
<FSXCompatibility>false</FSXCompatibility>
</Flags>
<AssetDir>PackageSources\SimObjects\Airplanes\Navigraph_Navigation_Data_Interface_Aircraft\</AssetDir>
<OutputDir>SimObjects\Airplanes\Navigraph_Navigation_Data_Interface_Aircraft\</OutputDir>
</AssetGroup>
<AssetGroup Name="html_ui">
<Type>Copy</Type>
<Flags>
<FSXCompatibility>false</FSXCompatibility>
</Flags>
<AssetDir>PackageSources\html_ui\</AssetDir>
<OutputDir>html_ui\</OutputDir>
</AssetGroup>
</AssetGroups>
</AssetPackage>

<?xml version="1.0" encoding="utf-8"?>
<AssetPackage Version="0.1.0">
<ItemSettings>
<ContentType>AIRCRAFT</ContentType>
<Title>Navigraph Navigation Data Interface Sample Aircraft</Title>
<Manufacturer>My Manufacturer</Manufacturer>
<Creator>Navigraph</Creator>
</ItemSettings>
<Flags>
<VisibleInStore>true</VisibleInStore>
<CanBeReferenced>true</CanBeReferenced>
</Flags>
<AssetGroups>
<AssetGroup Name="ContentInfo">
<Type>Copy</Type>
<Flags>
<FSXCompatibility>false</FSXCompatibility>
</Flags>
<AssetDir>PackageDefinitions\navigraph-aircraft-navigation-data-interface-sample\ContentInfo\</AssetDir>
<OutputDir>ContentInfo\navigraph-aircraft-navigation-data-interface-sample\</OutputDir>
</AssetGroup>
<AssetGroup Name="Data">
<Type>Copy</Type>
<Flags>
<FSXCompatibility>false</FSXCompatibility>
</Flags>
<AssetDir>PackageSources\Data\</AssetDir>
<OutputDir>Data\</OutputDir>
</AssetGroup>
<AssetGroup Name="NavigationData">
<Type>Copy</Type>
<Flags>
<FSXCompatibility>false</FSXCompatibility>
</Flags>
<AssetDir>PackageSources\NavigationData\</AssetDir>
<OutputDir>NavigationData\</OutputDir>
</AssetGroup>
<AssetGroup Name="SimObject">
<Type>SimObject</Type>
<Flags>
<FSXCompatibility>false</FSXCompatibility>
</Flags>
<AssetDir>PackageSources\SimObjects\Airplanes\Navigraph_Navigation_Data_Interface_Aircraft\</AssetDir>
<OutputDir>SimObjects\Airplanes\Navigraph_Navigation_Data_Interface_Aircraft\</OutputDir>
</AssetGroup>
<AssetGroup Name="html_ui">
<Type>Copy</Type>
<Flags>
<FSXCompatibility>false</FSXCompatibility>
</Flags>
<AssetDir>PackageSources\html_ui\</AssetDir>
<OutputDir>html_ui\</OutputDir>
</AssetGroup>
</AssetGroups>
</AssetPackage>

1 change: 1 addition & 0 deletions examples/aircraft/PackageSources/NavigationData/cycle.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"cycle":"2101","revision":"1","name":"Navigraph Avionics", "format": "dfd", "validityPeriod": "2021-01-25/2021-02-20"}
Binary file not shown.
16 changes: 1 addition & 15 deletions examples/gauge/Components/InterfaceSample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export class InterfaceSample extends DisplayComponent<InterfaceSampleProps> {
private readonly dropdownRef = FSComponent.createRef<Dropdown>()
private readonly downloadButtonRef = FSComponent.createRef<HTMLButtonElement>()
private readonly executeButtonRef = FSComponent.createRef<HTMLButtonElement>()
private readonly setActiveButtonRef = FSComponent.createRef<HTMLButtonElement>()
private readonly inputRef = FSComponent.createRef<HTMLInputElement>()

private cancelSource = CancelToken.source()
Expand Down Expand Up @@ -69,9 +68,6 @@ export class InterfaceSample extends DisplayComponent<InterfaceSampleProps> {
<div ref={this.downloadButtonRef} class="button">
Download
</div>
<div ref={this.setActiveButtonRef} class="button">
Set as Active
</div>
<input ref={this.inputRef} type="text" id="sql" name="sql" value="ESSA" class="text-field" />
<div ref={this.executeButtonRef} class="button">
Execute SQL
Expand Down Expand Up @@ -103,16 +99,6 @@ export class InterfaceSample extends DisplayComponent<InterfaceSampleProps> {
.catch(e => console.error(e))
})

this.setActiveButtonRef.instance.addEventListener("click", () => {
const format = this.dropdownRef.instance.getNavigationDataFormat()
if (!format) return
// This will only work if the database specified is a SQLite database
this.navigationDataInterface
.set_active_database(format)
.then(() => console.info("WASM set active database"))
.catch(err => this.displayError(String(err)))
})

AuthService.user.sub(user => {
if (user) {
this.qrCodeRef.instance.src = ""
Expand Down Expand Up @@ -173,7 +159,7 @@ export class InterfaceSample extends DisplayComponent<InterfaceSampleProps> {
const pkg = await packages.getPackage(format)

// Download navigation data to work dir
await this.navigationDataInterface.download_navigation_data(pkg.file.url, pkg.format)
await this.navigationDataInterface.download_navigation_data(pkg.file.url)
this.displayMessage("Navigation data downloaded")
} catch (err) {
if (err instanceof Error) this.displayError(err.message)
Expand Down
39 changes: 29 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,10 @@
"eslint-plugin-prettier": "^5.0.1",
"jest": "^29.7.0",
"prettier": "^3.0.3",
"random-bigint": "^0.0.1",
"ts-jest": "^29.1.1",
"ts-node": "^10.9.2",
"tsup": "^8.0.1",
"typescript": "^5.2.2",
"uuid": "^9.0.1"
}
}
}
42 changes: 31 additions & 11 deletions src/database/src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,35 +27,53 @@ use crate::{
vhf_navaid::VhfNavaid,
waypoint::Waypoint,
},
sql_structs::{self},
util,
sql_structs, util,
};

pub struct Database {
database: Option<Connection>,
pub path: Option<String>,
}

#[derive(Debug)]
struct NoDatabaseOpen;

impl Display for NoDatabaseOpen {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { write!(f, "No database open") }
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "No database open")
}
}

impl Error for NoDatabaseOpen {}

impl Database {
pub fn new() -> Self { Database { database: None } }
pub fn new() -> Self {
Database {
database: None,
path: None,
}
}

fn get_database(&self) -> Result<&Connection, NoDatabaseOpen> { self.database.as_ref().ok_or(NoDatabaseOpen) }
fn get_database(&self) -> Result<&Connection, NoDatabaseOpen> {
self.database.as_ref().ok_or(NoDatabaseOpen)
}

pub fn set_active_database(&mut self, mut path: String) -> Result<(), Box<dyn Error>> {
// Check if the path is a directory and if it is, search for a sqlite file
let formatted_path = format!("\\work/{}", path);
if util::get_path_type(std::path::Path::new(&formatted_path)) == util::PathType::Directory {
path = util::find_sqlite_file(&formatted_path)?;
pub fn set_active_database(&mut self, path: String) -> Result<(), Box<dyn Error>> {
let path = match util::find_sqlite_file(&path) {
Ok(new_path) => new_path,
Err(_) => path,
};
println!("[NAVIGRAPH] Setting active database to {}", path);
self.close_connection();
if util::is_sqlite_file(&path)? {
self.open_connection(path.clone())?;
}
self.path = Some(path);

Ok(())
}

pub fn open_connection(&mut self, path: String) -> Result<(), Box<dyn Error>> {
// We have to open with flags because the SQLITE_OPEN_CREATE flag with the default open causes the file to
// be overwritten
let flags = OpenFlags::SQLITE_OPEN_READ_ONLY | OpenFlags::SQLITE_OPEN_URI | OpenFlags::SQLITE_OPEN_NO_MUTEX;
Expand Down Expand Up @@ -541,5 +559,7 @@ impl Database {
Ok(data)
}

pub fn close_connection(&mut self) { self.database = None; }
pub fn close_connection(&mut self) {
self.database = None;
}
}
4 changes: 3 additions & 1 deletion src/database/src/math.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ pub type Minutes = f64;
pub type KiloHertz = f64;
pub type MegaHertz = f64;

pub(crate) fn feet_to_meters(metres: Meters) -> Feet { metres / 3.28084 }
pub(crate) fn feet_to_meters(metres: Meters) -> Feet {
metres / 3.28084
}

#[derive(Serialize, Deserialize, Debug, Copy, Clone)]
pub struct Coordinates {
Expand Down
Loading

0 comments on commit 2d8906f

Please sign in to comment.