Skip to content

Commit

Permalink
feat: Added a parameter with the A32NX version to the flyPad simBrief…
Browse files Browse the repository at this point in the history
… URL (flybywiresim#8472)

* Added a source parameter with the A32NX version to the simBrief URL

* Commented the getAirframeType function

* Added the aircraft name to the version as a prefix

* Loading the correct aircraft type build info

* Catch error if build info file cannot be loaded (a380x issue only)

* Changed parameter name to client on Navigraph's suggestion

* Reverted accidental change

* Changed comment

* Adding aircraft type check independent from Efb based on Aircraft Name simvar.

* Commenting

* Using shared sdk import

* Removed debug output
  • Loading branch information
frankkopp authored Feb 9, 2024
1 parent 679a4f1 commit 49ee675
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
//
// SPDX-License-Identifier: GPL-3.0

import { AircraftVersionChecker } from '@shared/AircraftVersionChecker';
import { ISimbriefData } from './simbriefInterface';

const SIMBRIEF_BASE_URL = 'https://www.simbrief.com/api/xml.fetcher.php';
Expand All @@ -11,7 +12,7 @@ const getRequestData: RequestInit = {
method: 'GET',
};

export const getSimbriefData = (navigraphUsername: string, overrideSimbriefID: string): Promise<ISimbriefData> => {
export const getSimbriefData = async (navigraphUsername: string, overrideSimbriefID: string): Promise<ISimbriefData> => {
const simbriefApiUrl = new URL(SIMBRIEF_BASE_URL);
const simbriefApiParams = simbriefApiUrl.searchParams;

Expand All @@ -23,6 +24,17 @@ export const getSimbriefData = (navigraphUsername: string, overrideSimbriefID: s

simbriefApiParams.append('json', '1');

// Adding the build version to the url parameters to allow Navigraph/Simbrief to track requests from the A32NX
// The try/catch is there as the a380x build info file cannot be loaded with the current package setup/order and
// will throw an error - if this is fixed (build_info for a380x is readable from the flyPad for the A380X) then
// this try/catch could be removed, but it doesn't hurt to have it here even then as an extra safety measure
try {
const versionInfo = await AircraftVersionChecker.getBuildInfo();
simbriefApiParams.append('client', `fbw-${versionInfo.version}`);
} catch (e) {
console.error('Error getting build info', e);
}

simbriefApiUrl.search = simbriefApiParams.toString();

return fetch(simbriefApiUrl.toString(), getRequestData)
Expand Down
13 changes: 8 additions & 5 deletions fbw-a32nx/src/systems/instruments/src/EFB/Efb.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ const BATTERY_DURATION_CHARGE_MIN = 180;
const BATTERY_DURATION_DISCHARGE_MIN = 540;

const LoadingScreen = () => (
<div className="flex justify-center items-center w-screen h-screen bg-theme-statusbar">
<div className="flex h-screen w-screen items-center justify-center bg-theme-statusbar">
<FbwLogo width={128} height={120} className="text-theme-text" />
</div>
);

const EmptyBatteryScreen = () => (
<div className="flex justify-center items-center w-screen h-screen bg-theme-statusbar">
<div className="flex h-screen w-screen items-center justify-center bg-theme-statusbar">
<Battery size={128} className="text-utility-red" />
</div>
);
Expand Down Expand Up @@ -72,7 +72,10 @@ interface BatteryStatus {

export const usePower = () => React.useContext(PowerContext);

export const getAirframeType = () => new URL(document.querySelectorAll('vcockpit-panel > *')[0].getAttribute('url')).searchParams.get('Airframe');
// this returns either `A380_842` or `A320_251N` depending on the aircraft
export const getAirframeType = () => new URL(
document.querySelectorAll('vcockpit-panel > *')[0].getAttribute('url'),
).searchParams.get('Airframe');

const Efb = () => {
const [powerState, setPowerState] = useState<PowerStates>(PowerStates.SHUTOFF);
Expand Down Expand Up @@ -300,7 +303,7 @@ const Efb = () => {
switch (powerState) {
case PowerStates.SHUTOFF:
case PowerStates.STANDBY:
return <div className="w-screen h-screen" onClick={offToLoaded} />;
return <div className="h-screen w-screen" onClick={offToLoaded} />;
case PowerStates.LOADING:
case PowerStates.SHUTDOWN:
return <LoadingScreen />;
Expand Down Expand Up @@ -328,7 +331,7 @@ const Efb = () => {
/>
<div className="flex flex-row">
<ToolBar />
<div className="pt-14 pr-6 w-screen h-screen">
<div className="h-screen w-screen pr-6 pt-14">
<Switch>
<Route exact path="/">
<Redirect to="/dashboard" />
Expand Down
9 changes: 7 additions & 2 deletions fbw-a32nx/src/systems/shared/src/AircraftVersionChecker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
/* eslint-disable no-console */
import Compare from 'semver/functions/compare';
import { CommitInfo, GitVersions, ReleaseInfo } from '@flybywiresim/api-client';
import { NotificationManager, PopUpDialog } from '@flybywiresim/fbw-sdk';
import { getAircraftType, NotificationManager, PopUpDialog } from '@flybywiresim/fbw-sdk';

/**
* Contains the a32nx_build_info.json file's information in a structured way.
Expand Down Expand Up @@ -104,7 +104,10 @@ export class AircraftVersionChecker {
if (this.buildInfo) {
return this.buildInfo;
}
await fetch('/VFS/a32nx_build_info.json').then((response) => {

const aircraft = getAircraftType();

await fetch(`/VFS/${aircraft}_build_info.json`).then((response) => {
response.json().then((json) => {
this.buildInfo = ({
built: json.built,
Expand All @@ -115,6 +118,8 @@ export class AircraftVersionChecker {
prettyReleaseName: json.pretty_release_name,
version: json.version,
});
}).catch((error) => {
console.error('Failed to read build info: ', error);
});
});
return this.buildInfo;
Expand Down
19 changes: 19 additions & 0 deletions fbw-common/src/systems/shared/src/aircraftTypeCheck.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (c) 2023-2024 FlyByWire Simulations
// SPDX-License-Identifier: GPL-3.0

/**
* Determine the aircraft type using the Aircraft Title SimVar.
* @returns {string} - the aircraft type (a32nx, a380x, other)
*/
export function getAircraftType(): string {
const aircraftName :string = SimVar.GetSimVarValue('TITLE', 'string');
let aircraft: string;
if (aircraftName.includes('A320')) {
aircraft = 'a32nx';
} else if (aircraftName.includes('A380')) {
aircraft = 'a380x';
} else {
aircraft = 'other';
}
return aircraft;
}
21 changes: 11 additions & 10 deletions fbw-common/src/systems/shared/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
export * from './navigraph';
export * from './ApproachUtils';
export * from './arinc429';
export * from './Arinc429ConsumerSubject';
export * from './Arinc429RegisterSubject';
export * from './ArincConsumer';
export * from './ArincEventBus';
export * from './ArincEventBusSubscriber';
export * from './ata';
export * from './Constants';
export * from './FmMessages';
export * from './GenericDataListenerSync';
export * from './MathUtils';
export * from './PathVector';
export * from './RunwayUtils';
export * from './UpdateThrottler';
export * from './aircraftTypeCheck';
export * from './arinc429';
export * from './array';
export * from './ata';
export * from './bitFlags';
export * from './config';
export * from './Constants';
export * from './GenericDataListenerSync';
export * from './FmMessages';
export * from './logic';
export * from './MathUtils';
export * from './navdata';
export * from './navigraph';
export * from './notification';
export * from './parseMetar';
export * from './PathVector';
export * from './persistence';
export * from './popup';
export * from './RunwayUtils';
export * from './simvar';
export * from './units';
export * from './UpdateThrottler';
2 changes: 2 additions & 0 deletions scripts/metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ if (!filePrefixArg) {
process.exit(1);
}

object.version = filePrefixArg + '-' + object.version;

const write = (file) => writeFileSync(file, JSON.stringify(object, null, 4));

write(`${filePrefixArg}_build_info.json`);

0 comments on commit 49ee675

Please sign in to comment.