From b23c3462e4c2220bef13528b1dc26743abbf059f Mon Sep 17 00:00:00 2001 From: Frank Kopp Date: Tue, 6 Feb 2024 23:53:16 +0100 Subject: [PATCH 01/12] Added a source parameter with the A32NX version to the simBrief URL --- .../src/EFB/Apis/Simbrief/simbriefParser.ts | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/fbw-a32nx/src/systems/instruments/src/EFB/Apis/Simbrief/simbriefParser.ts b/fbw-a32nx/src/systems/instruments/src/EFB/Apis/Simbrief/simbriefParser.ts index 3dff8833382..0f250455727 100644 --- a/fbw-a32nx/src/systems/instruments/src/EFB/Apis/Simbrief/simbriefParser.ts +++ b/fbw-a32nx/src/systems/instruments/src/EFB/Apis/Simbrief/simbriefParser.ts @@ -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'; @@ -11,7 +12,7 @@ const getRequestData: RequestInit = { method: 'GET', }; -export const getSimbriefData = (navigraphUsername: string, overrideSimbriefID: string): Promise => { +export const getSimbriefData = async (navigraphUsername: string, overrideSimbriefID: string): Promise => { const simbriefApiUrl = new URL(SIMBRIEF_BASE_URL); const simbriefApiParams = simbriefApiUrl.searchParams; @@ -23,15 +24,19 @@ 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 + const versionInfo = await AircraftVersionChecker.getBuildInfo(); + simbriefApiParams.append('source', `fbw-${versionInfo.version}`); + simbriefApiUrl.search = simbriefApiParams.toString(); + console.log('simbriefApiUrl', simbriefApiUrl); - return fetch(simbriefApiUrl.toString(), getRequestData) - .then((res) => { - if (!res.ok) { - return res.json().then((json) => Promise.reject(new Error(json.fetch.status))); - } - return res.json().then((json) => simbriefDataParser(json)); - }); + const res = await fetch(simbriefApiUrl.toString(), getRequestData); + if (!res.ok) { + return res.json().then((json) => Promise.reject(new Error(json.fetch.status))); + } + const resJson = await res.json(); + return simbriefDataParser(resJson); }; const simbriefDataParser = (simbriefJson: any): ISimbriefData => { From cc5a334ff1aec9196cfaec228935237a17e8957a Mon Sep 17 00:00:00 2001 From: Frank Kopp Date: Wed, 7 Feb 2024 01:09:34 +0100 Subject: [PATCH 02/12] Commented the getAirframeType function --- fbw-a32nx/src/systems/instruments/src/EFB/Efb.tsx | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/fbw-a32nx/src/systems/instruments/src/EFB/Efb.tsx b/fbw-a32nx/src/systems/instruments/src/EFB/Efb.tsx index 98f8217a208..0f9ca8c1882 100644 --- a/fbw-a32nx/src/systems/instruments/src/EFB/Efb.tsx +++ b/fbw-a32nx/src/systems/instruments/src/EFB/Efb.tsx @@ -37,13 +37,13 @@ const BATTERY_DURATION_CHARGE_MIN = 180; const BATTERY_DURATION_DISCHARGE_MIN = 540; const LoadingScreen = () => ( -
+
); const EmptyBatteryScreen = () => ( -
+
); @@ -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.SHUTOFF); @@ -300,7 +303,7 @@ const Efb = () => { switch (powerState) { case PowerStates.SHUTOFF: case PowerStates.STANDBY: - return
; + return
; case PowerStates.LOADING: case PowerStates.SHUTDOWN: return ; @@ -328,7 +331,7 @@ const Efb = () => { />
-
+
From 29ba96006e2dade355dcdd5cdf3dac041a0ad818 Mon Sep 17 00:00:00 2001 From: Frank Kopp Date: Wed, 7 Feb 2024 01:10:10 +0100 Subject: [PATCH 03/12] Added the aircraft name to the version as a prefix --- scripts/metadata.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/metadata.js b/scripts/metadata.js index 18984bea1c6..a78eb4e8145 100644 --- a/scripts/metadata.js +++ b/scripts/metadata.js @@ -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`); From ac7de9660bea7412abfa30592be36f946721bada Mon Sep 17 00:00:00 2001 From: Frank Kopp Date: Wed, 7 Feb 2024 01:10:43 +0100 Subject: [PATCH 04/12] Loading the correct aircraft type build info --- fbw-a32nx/src/systems/shared/src/AircraftVersionChecker.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/fbw-a32nx/src/systems/shared/src/AircraftVersionChecker.ts b/fbw-a32nx/src/systems/shared/src/AircraftVersionChecker.ts index 7be7b4be968..613c360422d 100644 --- a/fbw-a32nx/src/systems/shared/src/AircraftVersionChecker.ts +++ b/fbw-a32nx/src/systems/shared/src/AircraftVersionChecker.ts @@ -5,6 +5,7 @@ import Compare from 'semver/functions/compare'; import { CommitInfo, GitVersions, ReleaseInfo } from '@flybywiresim/api-client'; import { NotificationManager, PopUpDialog } from '@flybywiresim/fbw-sdk'; +import { getAirframeType } from '../../instruments/src/EFB/Efb'; /** * Contains the a32nx_build_info.json file's information in a structured way. @@ -104,7 +105,8 @@ export class AircraftVersionChecker { if (this.buildInfo) { return this.buildInfo; } - await fetch('/VFS/a32nx_build_info.json').then((response) => { + const aircraft = getAirframeType() === 'A380_842' ? 'a380x' : 'a32nx'; + await fetch(`/VFS/${aircraft}_build_info.json`).then((response) => { response.json().then((json) => { this.buildInfo = ({ built: json.built, @@ -115,6 +117,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; From 1e1a46df0e7c6afea1bab0d070619e79d2ccf789 Mon Sep 17 00:00:00 2001 From: Frank Kopp Date: Wed, 7 Feb 2024 13:50:11 +0100 Subject: [PATCH 05/12] Catch error if build info file cannot be loaded (a380x issue only) --- .../src/EFB/Apis/Simbrief/simbriefParser.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/fbw-a32nx/src/systems/instruments/src/EFB/Apis/Simbrief/simbriefParser.ts b/fbw-a32nx/src/systems/instruments/src/EFB/Apis/Simbrief/simbriefParser.ts index 0f250455727..d0824ce7e00 100644 --- a/fbw-a32nx/src/systems/instruments/src/EFB/Apis/Simbrief/simbriefParser.ts +++ b/fbw-a32nx/src/systems/instruments/src/EFB/Apis/Simbrief/simbriefParser.ts @@ -24,9 +24,16 @@ export const getSimbriefData = async (navigraphUsername: string, overrideSimbrie simbriefApiParams.append('json', '1'); - // adding the build version to the url parameters to allow Navigraph/Simbrief to track requests from the A32NX - const versionInfo = await AircraftVersionChecker.getBuildInfo(); - simbriefApiParams.append('source', `fbw-${versionInfo.version}`); + // 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 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 for now) + try { + const versionInfo = await AircraftVersionChecker.getBuildInfo(); + simbriefApiParams.append('source', `fbw-${versionInfo.version}`); + } catch (e) { + console.error('Error getting build info', e); + } simbriefApiUrl.search = simbriefApiParams.toString(); console.log('simbriefApiUrl', simbriefApiUrl); From 058dad8c74b78d815ef9bea8b70204fbc0554290 Mon Sep 17 00:00:00 2001 From: Frank Kopp Date: Wed, 7 Feb 2024 13:56:42 +0100 Subject: [PATCH 06/12] Changed parameter name to client on Navigraph's suggestion --- .../instruments/src/EFB/Apis/Simbrief/simbriefParser.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fbw-a32nx/src/systems/instruments/src/EFB/Apis/Simbrief/simbriefParser.ts b/fbw-a32nx/src/systems/instruments/src/EFB/Apis/Simbrief/simbriefParser.ts index d0824ce7e00..369e6426ae7 100644 --- a/fbw-a32nx/src/systems/instruments/src/EFB/Apis/Simbrief/simbriefParser.ts +++ b/fbw-a32nx/src/systems/instruments/src/EFB/Apis/Simbrief/simbriefParser.ts @@ -27,10 +27,10 @@ export const getSimbriefData = async (navigraphUsername: string, overrideSimbrie // 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 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 for now) + // this try/catch could be removed, but it doesn't hurt to have it here for now) try { const versionInfo = await AircraftVersionChecker.getBuildInfo(); - simbriefApiParams.append('source', `fbw-${versionInfo.version}`); + simbriefApiParams.append('client', `fbw-${versionInfo.version}`); } catch (e) { console.error('Error getting build info', e); } From 0577c73e490a173f7a6d38dbe56cadb89b7b8f66 Mon Sep 17 00:00:00 2001 From: Frank Kopp Date: Wed, 7 Feb 2024 14:34:43 +0100 Subject: [PATCH 07/12] Reverted accidental change --- .../src/EFB/Apis/Simbrief/simbriefParser.ts | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/fbw-a32nx/src/systems/instruments/src/EFB/Apis/Simbrief/simbriefParser.ts b/fbw-a32nx/src/systems/instruments/src/EFB/Apis/Simbrief/simbriefParser.ts index 369e6426ae7..39abaf352e6 100644 --- a/fbw-a32nx/src/systems/instruments/src/EFB/Apis/Simbrief/simbriefParser.ts +++ b/fbw-a32nx/src/systems/instruments/src/EFB/Apis/Simbrief/simbriefParser.ts @@ -26,8 +26,8 @@ export const getSimbriefData = async (navigraphUsername: string, overrideSimbrie // 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 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 for now) + // 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 for now try { const versionInfo = await AircraftVersionChecker.getBuildInfo(); simbriefApiParams.append('client', `fbw-${versionInfo.version}`); @@ -38,12 +38,13 @@ export const getSimbriefData = async (navigraphUsername: string, overrideSimbrie simbriefApiUrl.search = simbriefApiParams.toString(); console.log('simbriefApiUrl', simbriefApiUrl); - const res = await fetch(simbriefApiUrl.toString(), getRequestData); - if (!res.ok) { - return res.json().then((json) => Promise.reject(new Error(json.fetch.status))); - } - const resJson = await res.json(); - return simbriefDataParser(resJson); + return fetch(simbriefApiUrl.toString(), getRequestData) + .then((res) => { + if (!res.ok) { + return res.json().then((json) => Promise.reject(new Error(json.fetch.status))); + } + return res.json().then((json) => simbriefDataParser(json)); + }); }; const simbriefDataParser = (simbriefJson: any): ISimbriefData => { From 8a2b4592273893a89af3148faa90edc18868120a Mon Sep 17 00:00:00 2001 From: Frank Kopp Date: Wed, 7 Feb 2024 15:59:39 +0100 Subject: [PATCH 08/12] Changed comment --- .../instruments/src/EFB/Apis/Simbrief/simbriefParser.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fbw-a32nx/src/systems/instruments/src/EFB/Apis/Simbrief/simbriefParser.ts b/fbw-a32nx/src/systems/instruments/src/EFB/Apis/Simbrief/simbriefParser.ts index 39abaf352e6..a70ae53b7f4 100644 --- a/fbw-a32nx/src/systems/instruments/src/EFB/Apis/Simbrief/simbriefParser.ts +++ b/fbw-a32nx/src/systems/instruments/src/EFB/Apis/Simbrief/simbriefParser.ts @@ -25,9 +25,9 @@ export const getSimbriefData = async (navigraphUsername: string, overrideSimbrie 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 and + // 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 for now + // 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}`); From 621d7b9b2586531f5e0f513ac6a9eddc70ace522 Mon Sep 17 00:00:00 2001 From: Frank Kopp Date: Thu, 8 Feb 2024 13:25:31 +0100 Subject: [PATCH 09/12] Adding aircraft type check independent from Efb based on Aircraft Name simvar. --- .../shared/src/AircraftVersionChecker.ts | 6 ++++-- .../systems/shared/src/aircraftTypeCheck.ts | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 fbw-common/src/systems/shared/src/aircraftTypeCheck.ts diff --git a/fbw-a32nx/src/systems/shared/src/AircraftVersionChecker.ts b/fbw-a32nx/src/systems/shared/src/AircraftVersionChecker.ts index 613c360422d..d2320c4ea64 100644 --- a/fbw-a32nx/src/systems/shared/src/AircraftVersionChecker.ts +++ b/fbw-a32nx/src/systems/shared/src/AircraftVersionChecker.ts @@ -5,7 +5,7 @@ import Compare from 'semver/functions/compare'; import { CommitInfo, GitVersions, ReleaseInfo } from '@flybywiresim/api-client'; import { NotificationManager, PopUpDialog } from '@flybywiresim/fbw-sdk'; -import { getAirframeType } from '../../instruments/src/EFB/Efb'; +import { getAircraftType } from '../../../../../fbw-common/src/systems/shared/src/aircraftTypeCheck'; /** * Contains the a32nx_build_info.json file's information in a structured way. @@ -105,7 +105,9 @@ export class AircraftVersionChecker { if (this.buildInfo) { return this.buildInfo; } - const aircraft = getAirframeType() === 'A380_842' ? 'a380x' : 'a32nx'; + + const aircraft = getAircraftType(); + await fetch(`/VFS/${aircraft}_build_info.json`).then((response) => { response.json().then((json) => { this.buildInfo = ({ diff --git a/fbw-common/src/systems/shared/src/aircraftTypeCheck.ts b/fbw-common/src/systems/shared/src/aircraftTypeCheck.ts new file mode 100644 index 00000000000..50a6332726f --- /dev/null +++ b/fbw-common/src/systems/shared/src/aircraftTypeCheck.ts @@ -0,0 +1,19 @@ +// Copyright (c) 2023-2024 FlyByWire Simulations +// SPDX-License-Identifier: GPL-3.0 + +/** + * Determine the aircraft type - not using the EFB getAircraftName() function to avoid the Efb dependency + * @returns {string} - the aircraft type (a32nx, a380x, other) + */ +export function getAircraftType() { + 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; +} From d911457eda617d34a16d742176d205b3f48bf8a1 Mon Sep 17 00:00:00 2001 From: Frank Kopp Date: Thu, 8 Feb 2024 23:22:08 +0100 Subject: [PATCH 10/12] Commenting --- fbw-common/src/systems/shared/src/aircraftTypeCheck.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fbw-common/src/systems/shared/src/aircraftTypeCheck.ts b/fbw-common/src/systems/shared/src/aircraftTypeCheck.ts index 50a6332726f..1b48fe3b144 100644 --- a/fbw-common/src/systems/shared/src/aircraftTypeCheck.ts +++ b/fbw-common/src/systems/shared/src/aircraftTypeCheck.ts @@ -2,10 +2,10 @@ // SPDX-License-Identifier: GPL-3.0 /** - * Determine the aircraft type - not using the EFB getAircraftName() function to avoid the Efb dependency + * Determine the aircraft type using the Aircraft Title SimVar. * @returns {string} - the aircraft type (a32nx, a380x, other) */ -export function getAircraftType() { +export function getAircraftType(): string { const aircraftName :string = SimVar.GetSimVarValue('TITLE', 'string'); let aircraft: string; if (aircraftName.includes('A320')) { From 56e4df4117288483d9acdec7f1e1ac47621b6d59 Mon Sep 17 00:00:00 2001 From: Frank Kopp Date: Thu, 8 Feb 2024 23:39:57 +0100 Subject: [PATCH 11/12] Using shared sdk import --- .../shared/src/AircraftVersionChecker.ts | 3 +-- fbw-common/src/systems/shared/src/index.ts | 21 ++++++++++--------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/fbw-a32nx/src/systems/shared/src/AircraftVersionChecker.ts b/fbw-a32nx/src/systems/shared/src/AircraftVersionChecker.ts index d2320c4ea64..69b0cdb7e26 100644 --- a/fbw-a32nx/src/systems/shared/src/AircraftVersionChecker.ts +++ b/fbw-a32nx/src/systems/shared/src/AircraftVersionChecker.ts @@ -4,8 +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 } from '../../../../../fbw-common/src/systems/shared/src/aircraftTypeCheck'; +import { getAircraftType, NotificationManager, PopUpDialog } from '@flybywiresim/fbw-sdk'; /** * Contains the a32nx_build_info.json file's information in a structured way. diff --git a/fbw-common/src/systems/shared/src/index.ts b/fbw-common/src/systems/shared/src/index.ts index 86e847c07e0..6d3018d2e43 100644 --- a/fbw-common/src/systems/shared/src/index.ts +++ b/fbw-common/src/systems/shared/src/index.ts @@ -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'; From 428007fed3dee0413c982cad68e2c6f58e94e541 Mon Sep 17 00:00:00 2001 From: Frank Kopp Date: Fri, 9 Feb 2024 00:25:18 +0100 Subject: [PATCH 12/12] Removed debug output --- .../systems/instruments/src/EFB/Apis/Simbrief/simbriefParser.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/fbw-a32nx/src/systems/instruments/src/EFB/Apis/Simbrief/simbriefParser.ts b/fbw-a32nx/src/systems/instruments/src/EFB/Apis/Simbrief/simbriefParser.ts index a70ae53b7f4..dc4d3837664 100644 --- a/fbw-a32nx/src/systems/instruments/src/EFB/Apis/Simbrief/simbriefParser.ts +++ b/fbw-a32nx/src/systems/instruments/src/EFB/Apis/Simbrief/simbriefParser.ts @@ -36,7 +36,6 @@ export const getSimbriefData = async (navigraphUsername: string, overrideSimbrie } simbriefApiUrl.search = simbriefApiParams.toString(); - console.log('simbriefApiUrl', simbriefApiUrl); return fetch(simbriefApiUrl.toString(), getRequestData) .then((res) => {