Skip to content

Commit d65372a

Browse files
authored
Merge pull request #24 from Navigraph/docs
Update readme to align with rewrite
2 parents 39d823b + fcdf142 commit d65372a

File tree

1 file changed

+71
-61
lines changed

1 file changed

+71
-61
lines changed

README.md

Lines changed: 71 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,40 @@
1-
# Navigraph Navigation Data Interface for MSFS
1+
<div align="center" >
2+
<a href="https://navigraph.com">
3+
<img src="https://navigraph.com/assets/images/navigraph_logo_only.svg" alt="Logo" width="80" height="80">
4+
</a>
25

3-
The Navigraph Navigation Data Interface enables developers to download and integrate navigation data from Navigraph directly into add-on aircraft in MSFS.
6+
<div align="center">
7+
<h1>Navigraph Navigation Data Interface for MSFS</h1>
8+
</div>
9+
10+
<p>The Navigraph Navigation Data Interface enables developers to download and integrate navigation data from Navigraph directly into add-on aircraft in MSFS.</p>
11+
12+
<br/>
13+
</div>
414

515
## Key Features
616

717
- Navigraph DFD Format: Leverage specialized support for Navigraph's DFD format, based on SQLite, which includes an SQL interface on the commbus for efficient data handling.
818
- Javascript and WASM support: The navdata interface is accessible from both Javascript (Coherent) and WASM, providing flexibility for developers.
9-
- Supports updating of custom data formats.
1019
- Xbox compatibility: Works on PC and Xbox.
1120
- Persistence: All data is persisted in the `work` folder of the aircraft.
1221

1322
## Repository Structure
1423

15-
Here's an overview on the structure of this repository, which is designed to be as simple as possible to use
16-
17-
- `examples/`
18-
- Contains sample implementations for using the navigation data interface
24+
- `example/`
1925
- `aircraft/` includes a base aircraft to test in the sim
2026
- `gauge/` includes a very simple TypeScript instrument to communicate with the WASM module
2127
- `src/`
22-
- `database` Includes rust source code for interfacing with a DFD sqlite file (not WASM specific)
23-
- `js` Includes source code for the JS interface for using the sdk
24-
- `test` Includes code for testing the JS and Rust code using a Node runtime
25-
- `wasm` includes the Rust source code for the WASM module which handles the downloading of the database file, and interfacing with the database implementation
28+
- `ts` includes source code for the JS interface for interfacing with the WASM module
29+
- `wasm` includes the Rust source code for the WASM module which handles the downloading of the database file, and interfacing with the database
2630

2731
## Including in Your Aircraft
2832

2933
1. You'll need to either build the WASM module yourself (not recommended, but documented further down) or download it from [the latest release](https://github.com/Navigraph/msfs-navigation-data-interface/releases) (alternatively you can download it off of a commit by looking at the uploaded artifacts).
3034
2. Add the WASM module into your `panel` folder in `PackageSources`
3135
3. Add the following entry into `panel.cfg` (make sure to replace `NN` with the proper `VCockpit` ID):
3236

33-
```
37+
```ini
3438
[VCockpitNN]
3539
size_mm=0,0
3640
pixel_size=0,0
@@ -39,89 +43,95 @@ Here's an overview on the structure of this repository, which is designed to be
3943
```
4044

4145
- 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
42-
4. **Optional**: Create a `Navigraph/config.json` file to assist with Sentry reports. This info will be reported to us should any error occur in the library. We will use this to directly reach out to you (the developer) for these errors.
4346

44-
- The file must look like
47+
4. **Optional**: Create a `Navigraph/config.json` file to provide additional metadata at runtime. This info will be reported to us should any error occur in the library, enabling us to directly reach out to you (the developer) to help track down the issue.
4548

46-
```json
47-
{
48-
"addon": {
49-
"developer": "Navigraph",
50-
"product": "Sample Aircraft"
51-
}
52-
}
53-
```
49+
- The file must follow this format:
50+
51+
```json
52+
{
53+
"addon": {
54+
"developer": "Navigraph",
55+
"product": "Sample Aircraft"
56+
}
57+
}
58+
```
5459

5560
## Dealing with Bundled Navigation Data
5661

57-
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 `Navigraph/BundledData` directory in `PackageSources`. You can see an example [here](examples/aircraft/PackageSources/Navigraph/BundledData/)
62+
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 `Navigraph/BundledData` directory in `PackageSources`. You can see an example [here](example/aircraft/PackageSources/Navigraph/BundledData/)
63+
64+
The navigation data interface will automatically use this database by default, making it immediately available on startup.
5865

5966
## Where is the Navigation Data Stored?
6067

6168
The default location for navigation data is `work/NavigationData`.
6269

63-
## Building the Sample Aircraft
70+
## Building the Sample Aircraft (MSFS2020)
6471

65-
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
72+
> [!NOTE]
73+
> This project is only meant to be tested in MSFS2020. We will add an example for MSFS2024 in the future.
6674
67-
1. [Download](https://nodejs.org/en/download) and install Node.js
68-
2. Open the `msfs-navigation-data-interface` folder in a terminal
69-
3. Run `npm i` the first time you build, in order to install dependencies
70-
4. Change directory to `src/js` using `cd src/js`
71-
5. Run `npm run build` to build the interface.
72-
6. Change directory to `examples/gauge` using `cd ../../examples/gauge/`
73-
7. Run `npm run build` to build into the `PackageSources` folder of the aircraft sample (or `npm run dev` to build into the `Packages` folder of the aircraft and listen to changes in the source).
74-
8. Make sure the WASM module is included in the [`panel`](examples/aircraft/PackageSources/SimObjects/Airplanes/Navigraph_Navigation_Data_Interface_Aircraft/panel) folder! Look at either [Including in Your Aircraft](#including-in-your-aircraft) or [Building the WASM Module Yourself](#building-the-wasm-module-yourself) for info on that
75-
9. Open the `examples/aircraft/NavigationDataInterfaceAircraftProject.xml` file in the simulator and build there
75+
> [!IMPORTANT]
76+
> Before building, make sure you have properly created and set an `.env` file in `example/gauge`! An example can be found in the `.env.example` file in that directory. Replace with your credentials.
77+
78+
1. Download and install [Bun](https://bun.sh/docs/installation)
79+
2. Open this repository in a terminal
80+
3. Run `bun i` the first time you build, in order to install dependencies
81+
4. Change directory to [`example/gauge`](example/gauge/) using `cd example/gauge`
82+
5. Run `bun run build` to build into the `PackageSources` folder of the aircraft sample (or `bun run dev` to build into the `Packages` folder of the aircraft and listen to changes in the source).
83+
6. Make sure the WASM module is included in the [`panel`](example/aircraft/PackageSources/SimObjects/Airplanes/Navigraph_Navigation_Data_Interface_Aircraft/panel) folder! Look at either [Including in Your Aircraft](#including-in-your-aircraft) or [Building the WASM Module Yourself](#building-the-wasm-module-yourself) instructions
84+
7. Open the `example/aircraft/NavigationDataInterfaceAircraftProject.xml` file in the simulator and build there
7685

7786
## Building the WASM Module Yourself
7887

79-
1. [Install](https://github.com/navigraph/cargo-msfs) cargo-msfs
80-
2. Run `npm run build:wasm` (must be on Windows)
88+
1. Create a `.env` file in the root of this repository, containing a `SENTRY_URL` variable. Provide your own DSN, or leave it empty.
89+
2. Run `bun run build:wasm` at the root of the repository (requires Docker)
8190
- This will take a while to download and build the first time, but subsequent runs will be quicker
82-
3. The compiled WASM module will be copied to `out` **and** `examples/aircraft/PackageSources/SimObjects/Airplanes/Navigraph_Navigation_Data_Interface_Aircraft/panel`
91+
3. The compiled WASM module will be copied to `dist/wasm`. There will be two folders - `2020` and `2024`, for each sim version
8392

8493
## Interfacing with the gauge manually
8594

8695
The navigation data interface acts as its own WASM gauge in sim, so in order to communicate with it, you must use the [CommBus](https://docs.flightsimulator.com/html/Programming_Tools/WASM/Communication_API/Communication_API.htm).
8796

88-
The gauge communicates using the following event names:
89-
90-
(Any types referenced can be found in `wasm/src/json_structs.rs`)
97+
The gauge communicates using the following event names (all types referenced can be found [here](src/ts)):
9198

92-
- `NAVIGRAPH_CallFunction`: This event is received by the interface and is used to trigger one of the interfaces functions. It takes in arguments of type `CallFunction`. The available functions and their expected parameters can be found in the `json_structs.rs` file
99+
- `NAVIGRAPH_CallFunction`: This event is received by the interface and is used to trigger one of the interfaces functions. It takes in arguments of type `CallFunction`. The available functions and their expected parameters can be found in the [`src/ts`](src/ts) file
93100
- `NAVIGRAPH_FunctionResult`: This event is sent by the interface as a response to a previously triggered function. Its result will have the type `FunctionResult`, with the data field containing the expected return type of the function.
94101
- `NAVIGRAPH_Event`: This event is sent by the interface to give indications of progress or that the interface is running correctly.
95102

96103
### Example
97104

98-
Below is an example of communicating with the interface in JS. (We provide a JS wrapper, the code below is just a basic example to show how it works). Please read the CommBus documentation to determine how to interface with CommBus in your chosen language. `src/js` contains our JS wrapper, it is also a useful example for implementing a fully fleshed out wrapper.
105+
Below is an example of communicating with the interface in JS. Please read the CommBus documentation to determine how to interface with CommBus in your chosen language. [`src/ts`](src/ts) contains our JS wrapper, it is also a useful example for implementing a fully fleshed out wrapper.
106+
107+
> [!IMPORTANT]
108+
> We provide a JS wrapper that handles this for you. The below is just a quick look at how it works.
99109
100110
```js
101-
const queue = []
111+
const queue = [];
102112

103113
const listener = RegisterCommBusListener(() => {
104114
listener.on("NAVIGRAPH_FunctionResult", jsonArgs => {
105-
const args = JSON.parse(jsonArgs)
115+
const args = JSON.parse(jsonArgs);
106116

107117
// When a FunctionResult is received, find the item in queue which matches the id, and resolve or reject it
108-
const queueItem = queue.find(m => m.id === args.id)
118+
const queueItem = queue.find(m => m.id === args.id);
109119

110120
if (queueItem) {
111-
queue.splice(queue.indexOf(queueItem), 1)
112-
const data = args.data
121+
queue.splice(queue.indexOf(queueItem), 1);
122+
const data = args.data;
113123

114124
if (args.status === FunctionResultStatus.Success) {
115-
queueItem.resolve(data)
125+
queueItem.resolve(data);
116126
} else {
117-
queueItem.reject(new Error(typeof data === "string" ? data : "Unknown error"))
127+
queueItem.reject(new Error(typeof data === "string" ? data : "Unknown error"));
118128
}
119129
}
120-
})
121-
}) // RegisterCommBusListener is a function provided by sim
130+
});
131+
}); // RegisterCommBusListener is a function provided by sim
122132

123133
function getAirport(ident) {
124-
const id = Utils.generateGUID() // Utils is a class provided by sim
134+
const id = Utils.generateGUID(); // Utils is a class provided by sim
125135

126136
const args = {
127137
function: "GetAirport", // The name of the function being called
@@ -130,21 +140,21 @@ function getAirport(ident) {
130140
// The parameters of the function
131141
ident,
132142
},
133-
}
143+
};
134144

135-
listener.callWasm("NAVIGRAPH_CallFunction", JSON.stringify(args))
145+
listener.callWasm("NAVIGRAPH_CallFunction", JSON.stringify(args));
136146

137147
return new Promise((resolve, reject) => {
138148
queue.push({
139149
id,
140150
resolve: response => resolve(response),
141151
reject: error => reject(error),
142-
})
143-
})
152+
});
153+
});
144154
}
145155

146156
function executeSql(sql, params) {
147-
const id = Utils.generateGUID() // Utils is a class provided by sim
157+
const id = Utils.generateGUID(); // Utils is a class provided by sim
148158

149159
const args = {
150160
function: "ExecuteSQLQuery", // The name of the function being called
@@ -154,16 +164,16 @@ function executeSql(sql, params) {
154164
sql,
155165
params,
156166
},
157-
}
167+
};
158168

159-
listener.callWasm("NAVIGRAPH_CallFunction", JSON.stringify(args))
169+
listener.callWasm("NAVIGRAPH_CallFunction", JSON.stringify(args));
160170

161171
return new Promise((resolve, reject) => {
162172
queue.push({
163173
id,
164174
resolve: response => resolve(response),
165175
reject: error => reject(error),
166-
})
167-
})
176+
});
177+
});
168178
}
169179
```

0 commit comments

Comments
 (0)