Skip to content

Commit

Permalink
fix(atsu/efb): use msfs metar rather than fsx cloud data (#8256)
Browse files Browse the repository at this point in the history
* efb: use msfs metar rather than fsx cloud data

* EFB: Rename MSFS Option

* atsu: use msfs metar rather than fsx cloud data

* doc: changelog
  • Loading branch information
tracernz authored Oct 20, 2023
1 parent 112c19e commit 638b15e
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 18 deletions.
1 change: 1 addition & 0 deletions .github/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
1. [COND] Add Air Conditioning systems failures - @mjuhe (Miquel Juhe)
1. [COND] Fixed Temp-Indication on CRZ page showing cockpit temperature for fwd and aft cabin - @cptnuss-ops (Lukas)
1. [FMS] Show ILS ident and frequency on ARRIVAL page - @tracernz (Mike)
1. [EFB/ATSU] Use MSFS METAR data rather than FSX cloud data from FBW API - @tracernz (Mike)

## 0.10.0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
// SPDX-License-Identifier: GPL-3.0

import React, { FC, useEffect, useState } from 'react';
import { Metar } from '@flybywiresim/api-client';
import { Metar as FbwApiMetar } from '@flybywiresim/api-client';
import { Droplet, Speedometer2, ThermometerHalf, Wind } from 'react-bootstrap-icons';
import { MetarParserType, parseMetar, useInterval, usePersistentNumberProperty, usePersistentProperty } from '@flybywiresim/fbw-sdk';
import { Metar as MsfsMetar } from '@microsoft/msfs-sdk';
import { t } from '../../translation';
import { SimpleInput } from '../../UtilComponents/Form/SimpleInput/SimpleInput';
import { ColoredMetar } from './ColorMetar';
Expand Down Expand Up @@ -76,7 +77,7 @@ export const WeatherWidget: FC<WeatherWidgetProps> = ({ name, simbriefIcao, user
const [metarSource] = usePersistentProperty('CONFIG_METAR_SRC', 'MSFS');
const [metarError, setErrorMetar] = useState('');
const [usingColoredMetar] = usePersistentNumberProperty('EFB_USING_COLOREDMETAR', 1);
const source = metarSource === 'MSFS' ? 'MS' : metarSource;
const source = metarSource;

const getBaroTypeForAirport = (icao: string) => (['K', 'C', 'M', 'P', 'RJ', 'RO', 'TI', 'TJ']
.some((r) => icao.toUpperCase().startsWith(r)) ? 'IN HG' : 'HPA');
Expand Down Expand Up @@ -120,15 +121,39 @@ export const WeatherWidget: FC<WeatherWidgetProps> = ({ name, simbriefIcao, user
}
};

function getMetar(icao: any, source: any) {
async function getMetar(icao: string, source: string): Promise<void> {
if (icao.length !== 4 || icao === '----') {
return new Promise(() => {
setErrorMetar(t('Dashboard.ImportantInformation.Weather.NoIcaoProvided'));
setErrorMetar(t('Dashboard.ImportantInformation.Weather.NoIcaoProvided'));
dispatch(setMetar(MetarParserTypeProp));
return Promise.resolve();
}

// Comes from the sim rather than the FBW API
if (source === 'MSFS') {
let metar: MsfsMetar;
// Catch parsing error separately
try {
metar = await Coherent.call('GET_METAR_BY_IDENT', icao);
if (metar.icao !== icao.toUpperCase()) {
throw new Error('No METAR available');
}
} catch (err) {
console.log(`Error while retrieving Metar: ${err}`);
setErrorMetar(`${err.toString()}`);
dispatch(setMetar(MetarParserTypeProp));
});
}
try {
const metarParse = parseMetar(metar.metarString);
dispatch(setMetar(metarParse));
} catch (err) {
console.log(`Error while parsing Metar ("${metar.metarString}"): ${err}`);
setErrorMetar(`${t('Dashboard.ImportantInformation.Weather.MetarParsingError')}: ${err.toString().replace(/^Error: /, '').toUpperCase()}`);
dispatch(setMetar(MetarParserTypeProp));
}
return Promise.resolve();
}

return Metar.get(icao, source)
return FbwApiMetar.get(icao, source)
.then((result) => {
// For METAR source Microsoft result.metar is undefined without throwing an error.
// For the other METAR sources an error is thrown (Request failed with status code 404)
Expand Down Expand Up @@ -184,9 +209,9 @@ export const WeatherWidget: FC<WeatherWidgetProps> = ({ name, simbriefIcao, user
? <p>{t('Dashboard.ImportantInformation.Weather.Loading')}</p>
: (
<>
<div className="flex flex-row justify-between items-center">
<div className="flex flex-row items-center justify-between">
<SimpleInput
className="w-32 !text-2xl font-medium text-center uppercase"
className="w-32 text-center !text-2xl font-medium uppercase"
placeholder={simbriefIcao || 'ICAO'}
value={userIcao ?? simbriefIcao}
onChange={(value) => handleIcao(value)}
Expand All @@ -208,7 +233,7 @@ export const WeatherWidget: FC<WeatherWidgetProps> = ({ name, simbriefIcao, user
? (
<>
<div
className="flex flex-row justify-between items-center mt-4 w-full"
className="mt-4 flex w-full flex-row items-center justify-between"
>
<div className="flex flex-col items-center space-y-1">
<Speedometer2 size={35} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export const AtsuAocPage = () => {
];

const metarSourceButtons: ButtonType[] = [
{ name: 'MeteoBlue', setting: 'MSFS' },
{ name: 'MSFS', setting: 'MSFS' },
{ name: 'PilotEdge', setting: 'PILOTEDGE' },
{ name: 'IVAO', setting: 'IVAO' },
{ name: 'VATSIM', setting: 'VATSIM' },
Expand Down Expand Up @@ -208,7 +208,7 @@ export const AtsuAocPage = () => {

<SettingItem name={t('Settings.AtsuAoc.HoppieUserId')}>
<SimpleInput
className="text-center w-30"
className="w-30 text-center"
value={hoppieUserId}
onBlur={(value) => handleHoppieUsernameInput(value.replace(/\s/g, ''))}
onChange={(value) => setHoppieUserId(value)}
Expand Down
13 changes: 9 additions & 4 deletions fbw-a32nx/src/systems/instruments/src/EFB/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export const ErrorFallback = ({ resetErrorBoundary }: ErrorFallbackProps) => {
const [sentryEnabled] = usePersistentProperty(SENTRY_CONSENT_KEY, SentryConsentState.Refused);

return (
<div className="flex justify-center items-center w-full h-screen bg-theme-body">
<div className="bg-theme-body flex h-screen w-full items-center justify-center">
<div className="max-w-4xl">
<Error />
<div className="mt-6 space-y-12">
Expand All @@ -68,12 +68,12 @@ export const ErrorFallback = ({ resetErrorBoundary }: ErrorFallbackProps) => {
You have opted into anonymous error reporting and this issue has been relayed to us. If you want immediate support, please share the following code to a member of staff in the #support channel on the FlyByWire Discord server:
</h2>

<h1 className="text-4xl font-extrabold tracking-wider text-center">{sessionId}</h1>
<h1 className="text-center text-4xl font-extrabold tracking-wider">{sessionId}</h1>
</>
)}

<div className="py-4 px-8 w-full text-theme-body hover:text-utility-red bg-utility-red hover:bg-theme-body rounded-md border-2 border-utility-red transition duration-100" onClick={resetErrorBoundary}>
<h2 className="font-bold text-center text-current">Reset Display</h2>
<div className="text-theme-body hover:text-utility-red bg-utility-red hover:bg-theme-body border-utility-red w-full rounded-md border-2 px-8 py-4 transition duration-100" onClick={resetErrorBoundary}>
<h2 className="text-center font-bold text-current">Reset Display</h2>
</div>
</div>
</div>
Expand All @@ -94,6 +94,11 @@ const setup = () => {
readSettingsFromPersistentStorage();
migrateSettings();
setSessionId();

// Needed to fetch METARs from the sim
RegisterViewListener('JS_LISTENER_FACILITY', () => {
console.log('JS_LISTENER_FACILITY registered.');
}, true);
};

if (process.env.VITE_BUILD) {
Expand Down
5 changes: 5 additions & 0 deletions fbw-a32nx/src/systems/systems-host/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ class SystemsHost extends BaseInstrument {

this.powerSupply.connectedCallback();
this.atsu.connectedCallback();

// Needed to fetch METARs from the sim
RegisterViewListener('JS_LISTENER_FACILITY', () => {
console.log('JS_LISTENER_FACILITY registered.');
}, true);
}

public Update(): void {
Expand Down
11 changes: 9 additions & 2 deletions fbw-common/src/systems/datalink/router/src/Router.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2021 FlyByWire Simulations
// Copyright (c) 2021, 2023 FlyByWire Simulations
// SPDX-License-Identifier: GPL-3.0

import {
Expand All @@ -17,6 +17,7 @@ import {
} from '@datalink/common';
import { NXDataStore } from '@flybywiresim/fbw-sdk';
import { EventBus } from '@microsoft/msfs-sdk';
import { MsfsConnector } from './msfs/MsfsConnector';
import { Vdl } from './vhf/VDL';
import { HoppieConnector } from './webinterfaces/HoppieConnector';
import { NXApiConnector } from './webinterfaces/NXApiConnector';
Expand Down Expand Up @@ -230,7 +231,13 @@ export class Router {

if (index < icaos.length) {
if (requestMetar === true) {
retval = await NXApiConnector.receiveMetar(icaos[index], message).then(() => this.receiveWeatherData(requestMetar, icaos, index + 1, message));
const storedMetarSrc = NXDataStore.get('CONFIG_METAR_SRC', 'MSFS');

if (storedMetarSrc === 'MSFS') {
retval = await MsfsConnector.receiveMsfsMetar(icaos[index], message).then(() => this.receiveWeatherData(requestMetar, icaos, index + 1, message));
} else {
retval = await NXApiConnector.receiveMetar(icaos[index], message).then(() => this.receiveWeatherData(requestMetar, icaos, index + 1, message));
}
} else {
retval = await NXApiConnector.receiveTaf(icaos[index], message).then(() => this.receiveWeatherData(requestMetar, icaos, index + 1, message));
}
Expand Down
22 changes: 22 additions & 0 deletions fbw-common/src/systems/datalink/router/src/msfs/MsfsConnector.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright (c) 2023 FlyByWire Simulations
// SPDX-License-Identifier: GPL-3.0

import { AtsuStatusCodes, WeatherMessage } from '@datalink/common';
import { Metar } from '@microsoft/msfs-sdk';

export class MsfsConnector {
public static async receiveMsfsMetar(icao: string, message: WeatherMessage): Promise<AtsuStatusCodes> {
try {
const metar: Metar = await Coherent.call('GET_METAR_BY_IDENT', icao);
let report = metar.metarString;
if (!report || metar.icao !== icao) {
report = 'NO METAR AVAILABLE';
}
message.Reports.push({ airport: icao, report });
return AtsuStatusCodes.Ok;
} catch {
message.Reports.push({ airport: icao, report: 'NO METAR AVAILABLE' });
return AtsuStatusCodes.Ok;
}
}
}

0 comments on commit 638b15e

Please sign in to comment.