Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(a380x): Consider .flt file loading state for WASM startup #9586

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
1. [A32NX] Fixed appearance of FCU decals on MSFS2024 - @tracernz (Mike)
1. [FMS] Fixed issue with airport loading timing out on MSFS2024 - @tracernz (Mike)
1. [A32NX] Fixed APU fire detection - @tracernz (Mike)
1. [MSFS2024] Fix systems initialization behavior for MSFS2024 - @flogross89 (floridude)
1. [A380X/COND] Fix wasm crash during rapid decompression - @mjuhe (Miquel Juhe)

## 0.12.0
Expand Down
29 changes: 18 additions & 11 deletions fbw-a32nx/docs/a320-simvars.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,16 @@

## Uncategorized

- A32NX_IS_READY
- A32NX_STARTUP_STATE
- Bool
- Indicates that the JavaScript part is ready
- Indicates the startup state of the aircraft systems
- State | Value
--- | ---
Uninitialized | 0
FltFileLoaded | 1
ExtrasHostInitialized | 2
InstrumentsInitialized | 3
WasmInitialized | 4

- A32NX_IS_STATIONARY
- Bool
Expand All @@ -48,19 +55,19 @@
- Bool
- Indicates if any GND equipment is visible or not

- A32NX_START_STATE
- A32NX_FLT_INIT_STATE
- Enum
- Indicates the state in which MSFS started
- State | Value
--- | ---
Hangar | 1
Apron | 2
Taxi | 3
Runway | 4
Climb | 5
Cruise | 6
Approach | 7
Final | 8
Hangar | 0
Apron | 1
Taxi | 2
Runway | 3
Climb | 4
Cruise | 5
Approach | 6
Final | 7

- A32NX_NO_SMOKING_MEMO
- Boolean that determines whether the NO SMOKING memo should be visible on the upper ECAM
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ FoldingWingsHandle=False
FoldingWingsState=0, 0

[LocalVars.0]
A32NX_START_STATE=5
A32NX_STARTUP_STATE=1
A32NX_FLT_INIT_STATE=4
XMLVAR_RMP_L_On=1
XMLVAR_RMP_R_On=1
XMLVAR_Baro1_Mode=1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ FoldingWingsHandle=False
FoldingWingsState=0, 0

[LocalVars.0]
A32NX_IS_READY=0
A32NX_START_STATE=7
A32NX_STARTUP_STATE=1
A32NX_FLT_INIT_STATE=6
A32NX_RMP_L_TOGGLE_SWITCH=1
A32NX_RMP_R_TOGGLE_SWITCH=1
A32NX_RMP_L_SELECTED_MODE=1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ FoldingWingsState=0, 0
ExternalPowerSwitch=False

[LocalVars.0]
A32NX_IS_READY=0
A32NX_START_STATE=2
A32NX_STARTUP_STATE=1
A32NX_FLT_INIT_STATE=1
A32NX_RMP_L_TOGGLE_SWITCH=1
A32NX_RMP_R_TOGGLE_SWITCH=1
A32NX_RMP_L_SELECTED_MODE=1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ FoldingWingsHandle=False
FoldingWingsState=0, 0

[LocalVars.0]
A32NX_IS_READY=0
A32NX_START_STATE=6
A32NX_STARTUP_STATE=1
A32NX_FLT_INIT_STATE=5
A32NX_RMP_L_TOGGLE_SWITCH=1
A32NX_RMP_R_TOGGLE_SWITCH=1
A32NX_RMP_L_SELECTED_MODE=1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ LaunchBarSwitch=False
SeatBeltsSwitch = True

[LocalVars.0]
A32NX_IS_READY=0
A32NX_START_STATE=8
A32NX_STARTUP_STATE=1
A32NX_FLT_INIT_STATE=7
A32NX_RMP_L_TOGGLE_SWITCH=1
A32NX_RMP_R_TOGGLE_SWITCH=1
A32NX_RMP_L_SELECTED_MODE=1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ FoldingWingsState=0, 0
ExternalPowerSwitch=False

[LocalVars.0]
A32NX_IS_READY=0
A32NX_START_STATE=1
A32NX_STARTUP_STATE=1
A32NX_FLT_INIT_STATE=0
A32NX_RMP_L_TOGGLE_SWITCH=1
A32NX_RMP_R_TOGGLE_SWITCH=1
A32NX_RMP_L_SELECTED_MODE=1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ LaunchBarSwitch=False
SeatBeltsSwitch = True

[LocalVars.0]
A32NX_IS_READY=0
A32NX_START_STATE=4
A32NX_STARTUP_STATE=1
A32NX_FLT_INIT_STATE=3
A32NX_RMP_L_TOGGLE_SWITCH=1
A32NX_RMP_R_TOGGLE_SWITCH=1
A32NX_RMP_L_SELECTED_MODE=1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ Potentiometer.96=0
Potentiometer.97=0

[LocalVars.0]
A32NX_START_STATE=3
A32NX_STARTUP_STATE=1
A32NX_FLT_INIT_STATE=2
A32NX_RMP_L_TOGGLE_SWITCH=1
A32NX_RMP_R_TOGGLE_SWITCH=1
A32NX_RMP_L_SELECTED_MODE=1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class A32NX_TipsManager {

checkAssistenceConfiguration() {
// only check when actually flying, otherwise return
if (SimVar.GetSimVarValue("L:A32NX_IS_READY", "Number") !== 1) {
if (SimVar.GetSimVarValue('L:A32NX_STARTUP_STATE', 'number') >= 3) {
this.wasAnyAssistanceActive = false;
return;
}
Expand Down
6 changes: 4 additions & 2 deletions fbw-a32nx/src/systems/extras-host/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// Copyright (c) 2022 FlyByWire Simulations
// SPDX-License-Identifier: GPL-3.0

import { Clock, EventBus, HEventPublisher, InstrumentBackplane } from '@microsoft/msfs-sdk';
import { Clock, EventBus, GameStateProvider, HEventPublisher, InstrumentBackplane } from '@microsoft/msfs-sdk';
import {
ExtrasSimVarPublisher,
FlightDeckBounds,
Expand All @@ -17,6 +17,7 @@ import {
MsfsMiscPublisher,
NotificationManager,
PilotSeatManager,
trySetAircraftReadyState,
} from '@flybywiresim/fbw-sdk';
import { PushbuttonCheck } from 'extras-host/modules/pushbutton_check/PushbuttonCheck';
import { FlightPlanAsoboSync } from 'extras-host/modules/flightplan_sync/FlightPlanAsoboSync';
Expand Down Expand Up @@ -167,7 +168,7 @@ class ExtrasHost extends BaseInstrument {
super.Update();

if (this.gameState !== GameState.ingame) {
const gs = this.getGameState();
const gs = GameStateProvider.get().get();
if (gs === GameState.ingame) {
this.hEventPublisher.startPublish();
this.versionCheck.startPublish();
Expand All @@ -182,6 +183,7 @@ class ExtrasHost extends BaseInstrument {
this.keyInterceptor.update();
this.aircraftSync.update();

trySetAircraftReadyState(GameStateProvider.get().get());
this.backplane.onUpdate();
}
}
Expand Down
29 changes: 0 additions & 29 deletions fbw-a32nx/src/systems/fmgc/src/components/ReadySignal.ts

This file was deleted.

3 changes: 1 addition & 2 deletions fbw-a32nx/src/systems/fmgc/src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
// SPDX-License-Identifier: GPL-3.0

import { FcuSync } from '@fmgc/components/FcuSync';
import { ReadySignal } from '@fmgc/components/ReadySignal';
import { FlightPlanService } from '@fmgc/flightplanning/FlightPlanService';
import { FmgcComponent } from './FmgcComponent';
import { FmsMessages } from './fms-messages';

const fmsMessages = new FmsMessages();

const components: FmgcComponent[] = [fmsMessages, new ReadySignal(), new FcuSync()];
const components: FmgcComponent[] = [fmsMessages, new FcuSync()];

export function initComponents(baseInstrument: BaseInstrument, flightPlanService: FlightPlanService): void {
components.forEach((component) => component.init(baseInstrument, flightPlanService));
Expand Down
3 changes: 2 additions & 1 deletion fbw-a32nx/src/systems/shared/src/flightphase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
//
// SPDX-License-Identifier: GPL-3.0

import { getStartupState, StartupState } from '@flybywiresim/fbw-sdk';
import { VerticalMode } from '@shared/autopilot';

export enum FmgcFlightPhase {
Expand All @@ -16,7 +17,7 @@ export enum FmgcFlightPhase {
}

export function isReady(): boolean {
return SimVar.GetSimVarValue('L:A32NX_IS_READY', 'number') === 1;
return getStartupState() >= StartupState.InstrumentsInitialized;
}

export function isSlewActive(): boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ void EngineControl_A32NX::initializeEngineControlData() {
const double rightAuxQuantity = simData.simVarsDataPtr->data().fuelTankQuantityRightAux; // gal

// only loads saved fuel quantity on C/D spawn
if (simData.startState->updateFromSim(timeStamp, tickCounter) == 2) {
if (simData.fltInitState->updateFromSim(timeStamp, tickCounter) == 2) {
// Load fuel configuration from file
fuelConfiguration.setConfigFilename(FILENAME_FADEC_CONF_DIRECTORY + atcId + FILENAME_FADEC_CONF_FILE_EXTENSION);
fuelConfiguration.loadConfigurationFromIni();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ class FadecSimData_A32NX {
NamedVariablePtr packsState[2];
NamedVariablePtr refuelRate;
NamedVariablePtr refuelStartedByUser;
NamedVariablePtr startState;
NamedVariablePtr fltInitState;
NamedVariablePtr thrustLimitClimb;
NamedVariablePtr thrustLimitFlex;
NamedVariablePtr thrustLimitIdle;
Expand Down Expand Up @@ -289,7 +289,7 @@ class FadecSimData_A32NX {
void initLvars(DataManager* dm) {
// TODO: consider DataDefinition for the groups tha are read/write each tick

startState = dm->make_named_var("A32NX_START_STATE", UNITS.Number, NO_AUTO_UPDATE);
fltInitState = dm->make_named_var("A32NX_FLT_INIT_STATE", UNITS.Number, NO_AUTO_UPDATE);

engineEgt[L] = dm->make_named_var("A32NX_ENGINE_EGT:1", UNITS.Number, AUTO_READ_WRITE);
engineEgt[R] = dm->make_named_var("A32NX_ENGINE_EGT:2", UNITS.Number, AUTO_READ_WRITE);
Expand Down
16 changes: 10 additions & 6 deletions fbw-a32nx/src/wasm/fbw_a320/src/FlyByWireInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ bool FlyByWireInterface::update(double sampleTime) {
// get sim data
SimData simData = simConnectInterface.getSimData();

if (idStartupState->get() < 3) {
return result;
}

// update performance monitoring
result &= updatePerformanceMonitoring(sampleTime);

Expand All @@ -86,7 +90,7 @@ bool FlyByWireInterface::update(double sampleTime) {
if (simData.slew_on) {
wasInSlew = true;
return result;
} else if (pauseDetected || simData.cameraState >= 10.0 || !idIsReady->get() || simData.simulationTime < 2) {
} else if (pauseDetected || simData.cameraState >= 10.0 || simData.simulationTime < 2) {
return result;
}

Expand Down Expand Up @@ -283,8 +287,8 @@ void FlyByWireInterface::loadConfiguration() {

void FlyByWireInterface::setupLocalVariables() {
// regsiter L variable for init state and ready signal
idIsReady = std::make_unique<LocalVariable>("A32NX_IS_READY");
idStartState = std::make_unique<LocalVariable>("A32NX_START_STATE");
idStartupState = std::make_unique<LocalVariable>("A32NX_STARTUP_STATE");
idFltInitState = std::make_unique<LocalVariable>("A32NX_FLT_INIT_STATE");

// regsiter L variable for logging
idLoggingFlightControlsEnabled = std::make_unique<LocalVariable>("A32NX_LOGGING_FLIGHT_CONTROLS_ENABLED");
Expand Down Expand Up @@ -833,7 +837,7 @@ void FlyByWireInterface::setupLocalVariables() {

bool FlyByWireInterface::handleFcuInitialization(double sampleTime) {
// init should be run only once and only when is ready is signaled
if (wasFcuInitialized || !idIsReady->get()) {
if (wasFcuInitialized || idStartupState->get() < 3) {
return true;
}

Expand All @@ -849,7 +853,7 @@ bool FlyByWireInterface::handleFcuInitialization(double sampleTime) {
auto timeSinceReady = simData.simulationTime - simulationTimeReady;

// determine if we need to run init code
if (idStartState->get() >= 5 && timeSinceReady > 6.0) {
if (idFltInitState->get() >= 5 && timeSinceReady > 6.0) {
// init FCU for in flight configuration
long targetAltitude = simData.H_ind_ft;
long targetHeading = std::fmod(simData.Psi_magnetic_deg, 360.0);
Expand All @@ -860,7 +864,7 @@ bool FlyByWireInterface::handleFcuInitialization(double sampleTime) {
simConnectInterface.sendEvent(SimConnectInterface::A32NX_FCU_VS_SET, simData.H_ind_ft < targetAltitude ? 1000 : -1000);
simConnectInterface.sendEvent(SimConnectInterface::A32NX_FCU_VS_PULL);
wasFcuInitialized = true;
} else if (idStartState->get() == 4 && timeSinceReady > 1.0) {
} else if (idFltInitState->get() == 4 && timeSinceReady > 1.0) {
// init FCU for on runway -> ready for take-off
simConnectInterface.sendEvent(SimConnectInterface::A32NX_FCU_ALT_SET, 15000);
wasFcuInitialized = true;
Expand Down
4 changes: 2 additions & 2 deletions fbw-a32nx/src/wasm/fbw_a320/src/FlyByWireInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ class FlyByWireInterface {

bool wasFcuInitialized = false;
double simulationTimeReady = 0.0;
std::unique_ptr<LocalVariable> idIsReady;
std::unique_ptr<LocalVariable> idStartState;
std::unique_ptr<LocalVariable> idStartupState;
std::unique_ptr<LocalVariable> idFltInitState;

bool developmentLocalVariablesEnabled = false;
bool useCalculatedLocalizerAndGlideSlope = false;
Expand Down
18 changes: 9 additions & 9 deletions fbw-a32nx/src/wasm/systems/a320_systems/src/hydraulic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ use systems::{
ReservoirAirPressure, ReverserPosition, SectionPressure, TrimmableHorizontalStabilizer,
},
simulation::{
InitContext, Read, Reader, SimulationElement, SimulationElementVisitor, SimulatorReader,
SimulatorWriter, StartState, UpdateContext, VariableIdentifier, Write,
FltInitState, InitContext, Read, Reader, SimulationElement, SimulationElementVisitor,
SimulatorReader, SimulatorWriter, UpdateContext, VariableIdentifier, Write,
},
};

Expand Down Expand Up @@ -808,8 +808,8 @@ impl A320RudderFactory {
}

fn new_rudder(context: &mut InitContext) -> RudderAssembly {
let init_at_center = context.start_state() == StartState::Taxi
|| context.start_state() == StartState::Runway
let init_at_center = context.flt_init_state() == FltInitState::Taxi
|| context.flt_init_state() == FltInitState::Runway
|| context.is_in_flight();

let assembly = Self::a320_rudder_assembly(context, init_at_center);
Expand Down Expand Up @@ -6619,10 +6619,10 @@ mod tests {
test_bed: SimulationTestBed<A320HydraulicsTestAircraft>,
}
impl A320HydraulicsTestBed {
fn new_with_start_state(start_state: StartState) -> Self {
fn new_with_flt_init_state(flt_init_state: FltInitState) -> Self {
Self {
test_bed: SimulationTestBed::new_with_start_state(
start_state,
test_bed: SimulationTestBed::new_with_flt_init_state(
flt_init_state,
A320HydraulicsTestAircraft::new,
),
}
Expand Down Expand Up @@ -7592,11 +7592,11 @@ mod tests {
}

fn test_bed_on_ground() -> A320HydraulicsTestBed {
A320HydraulicsTestBed::new_with_start_state(StartState::Apron)
A320HydraulicsTestBed::new_with_flt_init_state(FltInitState::Apron)
}

fn test_bed_in_flight() -> A320HydraulicsTestBed {
A320HydraulicsTestBed::new_with_start_state(StartState::Cruise)
A320HydraulicsTestBed::new_with_flt_init_state(FltInitState::Cruise)
}

fn test_bed_on_ground_with() -> A320HydraulicsTestBed {
Expand Down
Loading