Skip to content

Commit 4fbef30

Browse files
Saschlflogross89
authored andcommitted
fix: revert fadec init with empty atcID (#10349) (#10358)
Revert "fix: fadec init with empty atcID (#10349)" This reverts commit c1c61f7. (cherry picked from commit 9ba42b3)
1 parent 89e2e87 commit 4fbef30

File tree

4 files changed

+53
-161
lines changed

4 files changed

+53
-161
lines changed

fbw-a32nx/src/wasm/fadec_a32nx/src/Fadec/EngineControlA32NX.cpp

Lines changed: 25 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,19 @@ void EngineControl_A32NX::update() {
3434
profilerUpdate.start();
3535
#endif
3636

37-
if (!fadecInitialized) {
38-
initializeEngineControlData();
39-
fadecInitialized = true;
37+
// Get ATC ID from sim to be able to load and store fuel levels
38+
// If not yet available, request it from sim and return early
39+
// If available initialize the engine control data
40+
if (atcId.empty()) {
41+
simData.atcIdDataPtr->requestUpdateFromSim(msfsHandlerPtr->getTimeStamp(), msfsHandlerPtr->getTickCounter());
42+
if (simData.atcIdDataPtr->hasChanged()) {
43+
atcId = simData.atcIdDataPtr->data().atcID;
44+
LOG_INFO("Fadec::EngineControl_A32NX::update() - received ATC ID: " + atcId);
45+
initializeEngineControlData();
46+
}
47+
return;
4048
}
4149

42-
loadFuelConfigIfPossible();
43-
4450
const double deltaTime = std::max(0.002, msfsHandlerPtr->getSimulationDeltaTime());
4551
const double simTime = msfsHandlerPtr->getSimulationTime();
4652
const double mach = simData.simVarsDataPtr->data().airSpeedMach;
@@ -145,40 +151,6 @@ void EngineControl_A32NX::update() {
145151
// PRIVATE
146152
// =============================================================================
147153

148-
void EngineControl_A32NX::loadFuelConfigIfPossible() {
149-
#ifdef PROFILING
150-
profilerEnsureFadecIsInitialized.start();
151-
#endif
152-
const FLOAT64 simTime = msfsHandlerPtr->getSimulationTime();
153-
const UINT64 tickCounter = msfsHandlerPtr->getTickCounter();
154-
155-
if (!hasLoadedFuelConfig) {
156-
bool isSimulationReady = msfsHandlerPtr->getAircraftIsReadyVar();
157-
158-
simData.atcIdDataPtr->requestUpdateFromSim(msfsHandlerPtr->getTimeStamp(), tickCounter);
159-
160-
// we only receive the data one tick later as we request it via simconnect. But it should be enought to only perform the check after
161-
// isSimulationReady as this is set by the JS instruments after spawn
162-
if (isSimulationReady) {
163-
if (simData.atcIdDataPtr->data().atcID[0] != '\0') {
164-
atcId = simData.atcIdDataPtr->data().atcID;
165-
LOG_INFO("Fadec::EngineControl_A32NX::ensureFadecIsInitialized() - received ATC ID: " + atcId);
166-
initializeFuelTanks(simTime, tickCounter);
167-
} else {
168-
LOG_INFO("Fadec::EngineControl_A32NX::ensureFadecIsInitialized() - no ATC ID received, taking default: " + atcId);
169-
}
170-
// if ATC ID is empty, we take the default and still set hasLoadedFuelConfig to as it won't change anymore
171-
hasLoadedFuelConfig = true;
172-
}
173-
}
174-
175-
#ifdef PROFILING
176-
profilerEnsureFadecIsInitialized.stop();
177-
if (msfsHandlerPtr->getTickCounter() % 100 == 0) {
178-
profilerEnsureFadecIsInitialized.print();
179-
}
180-
#endif
181-
}
182154
/**
183155
* @brief Initializes the engine control data.
184156
*
@@ -237,26 +209,7 @@ void EngineControl_A32NX::initializeEngineControlData() {
237209
simData.engineTimer[L]->set(0);
238210
simData.engineTimer[R]->set(0);
239211

240-
initializeFuelTanks(timeStamp, tickCounter);
241-
242-
// Initialize Pump State
243-
simData.fuelPumpState[L]->set(0);
244-
simData.fuelPumpState[R]->set(0);
245-
246-
// Initialize Thrust Limits
247-
simData.thrustLimitIdle->set(0);
248-
simData.thrustLimitClimb->set(0);
249-
simData.thrustLimitFlex->set(0);
250-
simData.thrustLimitMct->set(0);
251-
simData.thrustLimitToga->set(0);
252-
}
253-
254-
void EngineControl_A32NX::initializeFuelTanks(FLOAT64 timeStamp, UINT64 tickCounter) {
255-
LOG_INFO("Fadec::EngineControl_A32NX::initializeFuelTanks()");
256-
257-
#ifdef PROFILING
258-
ScopedTimer timer("Fadec::EngineControl_A32NX::initializeFuelTanks()");
259-
#endif
212+
// Initialize Fuel Tanks
260213
const double fuelWeightGallon = simData.simVarsDataPtr->data().fuelWeightPerGallon; // weight of gallon of jet A in lbs
261214

262215
const double centerQuantity = simData.simVarsDataPtr->data().fuelTankQuantityCenter; // gal
@@ -265,10 +218,6 @@ void EngineControl_A32NX::initializeFuelTanks(FLOAT64 timeStamp, UINT64 tickCoun
265218
const double leftAuxQuantity = simData.simVarsDataPtr->data().fuelTankQuantityLeftAux; // gal
266219
const double rightAuxQuantity = simData.simVarsDataPtr->data().fuelTankQuantityRightAux; // gal
267220

268-
LOG_INFO("Fadec::EngineControl_A32NX::initializeFuelTanks() - Current Fuel Levels from Sim:\n Center: " + std::to_string(centerQuantity) +
269-
" gal\n Left: " + std::to_string(leftQuantity) + " gal\n Right: " + std::to_string(rightQuantity) +
270-
" gal\n Left Aux: " + std::to_string(leftAuxQuantity) + " gal\n Right Aux: " + std::to_string(rightAuxQuantity) + " gal");
271-
272221
// only loads saved fuel quantity on C/D spawn
273222
if (simData.startState->updateFromSim(timeStamp, tickCounter) == 2) {
274223
// Load fuel configuration from file
@@ -298,6 +247,17 @@ void EngineControl_A32NX::initializeFuelTanks(FLOAT64 timeStamp, UINT64 tickCoun
298247
simData.fuelAuxLeftPre->set(leftAuxQuantity * fuelWeightGallon); // in Pounds
299248
simData.fuelAuxRightPre->set(rightAuxQuantity * fuelWeightGallon); // in Pounds
300249
}
250+
251+
// Initialize Pump State
252+
simData.fuelPumpState[L]->set(0);
253+
simData.fuelPumpState[R]->set(0);
254+
255+
// Initialize Thrust Limits
256+
simData.thrustLimitIdle->set(0);
257+
simData.thrustLimitClimb->set(0);
258+
simData.thrustLimitFlex->set(0);
259+
simData.thrustLimitMct->set(0);
260+
simData.thrustLimitToga->set(0);
301261
}
302262

303263
double EngineControl_A32NX::generateEngineImbalance() {
@@ -1013,11 +973,8 @@ void EngineControl_A32NX::updateFuel(double deltaTimeSeconds) {
1013973

1014974
//--------------------------------------------
1015975
// Will save the current fuel quantities at a certain interval
1016-
// if the simulation is ready
1017-
// and the aircraft is on the ground and the engines are off/shutting down
1018-
1019-
if (msfsHandlerPtr->getAircraftIsReadyVar() && msfsHandlerPtr->getSimOnGround() &&
1020-
(msfsHandlerPtr->getSimulationTime() - lastFuelSaveTime) > FUEL_SAVE_INTERVAL &&
976+
// if the aircraft is on the ground and the engines are off/shutting down
977+
if (msfsHandlerPtr->getSimOnGround() && (msfsHandlerPtr->getSimulationTime() - lastFuelSaveTime) > FUEL_SAVE_INTERVAL &&
1021978
(engine1State == OFF || engine1State == SHUTTING || engine2State == OFF || engine2State == SHUTTING)) {
1022979
fuelConfiguration.setFuelLeft(simData.fuelLeftPre->get() / weightLbsPerGallon);
1023980
fuelConfiguration.setFuelRight(simData.fuelRightPre->get() / weightLbsPerGallon);

fbw-a32nx/src/wasm/fadec_a32nx/src/Fadec/EngineControlA32NX.h

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,7 @@ class EngineControl_A32NX {
3434
FadecSimData_A32NX simData{};
3535

3636
// ATC ID for the aircraft used to load and store the fuel levels
37-
std::string atcId = "A32NX";
38-
39-
// Whether we have already loaded the fuel configuration from the config file
40-
bool hasLoadedFuelConfig = false;
41-
42-
bool fadecInitialized = false;
37+
std::string atcId{};
4338

4439
// Fuel configuration for loading and storing fuel levels
4540
FuelConfiguration_A32NX fuelConfiguration{};
@@ -103,8 +98,6 @@ class EngineControl_A32NX {
10398
SimpleProfiler profilerUpdateFuel{"Fadec::EngineControl_A32NX::updateFuel()", 100};
10499
SimpleProfiler profilerUpdateThrustLimits{"Fadec::EngineControl_A32NX::updateThrustLimits()", 100};
105100
SimpleProfiler profilerUpdateOil{"Fadec::EngineControl_A32NX::updateOil()", 100};
106-
SimpleProfiler profilerUpdateOil{"Fadec::EngineControl_A32NX::updateOil()", 100};
107-
SimpleProfiler profilerEnsureFadecIsInitialized{"Fadec::EngineControl_A32NX::ensureFadecIsInitialized()", 100};
108101
#endif
109102

110103
// ===========================================================================
@@ -133,22 +126,12 @@ class EngineControl_A32NX {
133126
// ===========================================================================
134127

135128
private:
136-
/**
137-
* @brief Initializes the required data for the engine simulation if it has not been initialized
138-
*/
139-
void loadFuelConfigIfPossible();
140-
141129
/**
142130
* @brief Initialize the FADEC and Fuel model
131+
* This is done after we have retrieved the ATC ID so we can load the fuel levels
143132
*/
144133
void initializeEngineControlData();
145134

146-
/**
147-
* @brief Initializes the fuel tanks based on a default config or the saved state of this livery
148-
* This method may be called multiple times during initialization
149-
*/
150-
void initializeFuelTanks(FLOAT64 timeStamp, UINT64 tickCounter);
151-
152135
/**
153136
* @brief Generates a random engine imbalance.
154137
*

fbw-a380x/src/wasm/fadec_a380x/src/Fadec/EngineControl_A380X.cpp

Lines changed: 25 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,19 @@ void EngineControl_A380X::update() {
3131
profilerUpdate.start();
3232
#endif
3333

34-
if (!fadecInitialized) {
35-
initializeEngineControlData();
36-
fadecInitialized = true;
34+
// Get ATC ID from sim to be able to load and store fuel levels
35+
// If not yet available, request it from sim and return early
36+
// If available initialize the engine control data
37+
if (atcId.empty()) {
38+
simData.atcIdDataPtr->requestUpdateFromSim(msfsHandlerPtr->getTimeStamp(), msfsHandlerPtr->getTickCounter());
39+
if (simData.atcIdDataPtr->hasChanged()) {
40+
atcId = simData.atcIdDataPtr->data().atcID;
41+
LOG_INFO("Fadec::EngineControl_A380X::update() - received ATC ID: " + atcId);
42+
initializeEngineControlData();
43+
}
44+
return;
3745
}
3846

39-
loadFuelConfigIfPossible();
40-
4147
const double deltaTime = std::max(0.002, msfsHandlerPtr->getSimulationDeltaTime());
4248
const double mach = simData.simVarsDataPtr->data().airSpeedMach;
4349
const double pressureAltitude = simData.simVarsDataPtr->data().pressureAltitude;
@@ -124,40 +130,6 @@ void EngineControl_A380X::update() {
124130
// Private methods
125131
// =====================================================================================================================
126132

127-
void EngineControl_A380X::loadFuelConfigIfPossible() {
128-
#ifdef PROFILING
129-
profilerEnsureFadecIsInitialized.start();
130-
#endif
131-
const FLOAT64 simTime = msfsHandlerPtr->getSimulationTime();
132-
const UINT64 tickCounter = msfsHandlerPtr->getTickCounter();
133-
134-
if (!hasLoadedFuelConfig) {
135-
bool isSimulationReady = msfsHandlerPtr->getAircraftIsReadyVar();
136-
137-
simData.atcIdDataPtr->requestUpdateFromSim(msfsHandlerPtr->getTimeStamp(), tickCounter);
138-
139-
// we only receive the data one tick later as we request it via simconnect. But it should be enought to only perform the check after
140-
// isSimulationReady as this is set by the JS instruments after spawn
141-
if (isSimulationReady) {
142-
if (simData.atcIdDataPtr->data().atcID[0] != '\0') {
143-
atcId = simData.atcIdDataPtr->data().atcID;
144-
LOG_INFO("Fadec::EngineControl_A380X::ensureFadecIsInitialized() - received ATC ID: " + atcId);
145-
initializeFuelTanks(simTime, tickCounter);
146-
} else {
147-
LOG_INFO("Fadec::EngineControl_A380X::ensureFadecIsInitialized() - no ATC ID received, taking default: " + atcId);
148-
}
149-
// if ATC ID is empty, we take the default and still set hasLoadedFuelConfig to as it won't change anymore
150-
hasLoadedFuelConfig = true;
151-
}
152-
}
153-
#ifdef PROFILING
154-
profilerEnsureFadecIsInitialized.stop();
155-
if (msfsHandlerPtr->getTickCounter() % 100 == 0) {
156-
profilerEnsureFadecIsInitialized.print();
157-
}
158-
#endif
159-
}
160-
161133
void EngineControl_A380X::initializeEngineControlData() {
162134
LOG_INFO("Fadec::EngineControl_A380X::initializeEngineControlData()");
163135

@@ -221,23 +193,6 @@ void EngineControl_A380X::initializeEngineControlData() {
221193
simData.engineTimer[E3]->set(0);
222194
simData.engineTimer[E4]->set(0);
223195

224-
initializeFuelTanks(timeStamp, tickCounter);
225-
226-
// Setting initial Fuel Flow
227-
simData.fuelPumpState[E1]->set(0);
228-
simData.fuelPumpState[E2]->set(0);
229-
simData.fuelPumpState[E3]->set(0);
230-
simData.fuelPumpState[E4]->set(0);
231-
232-
// Setting initial Thrust Limits
233-
simData.thrustLimitIdle->set(0);
234-
simData.thrustLimitClimb->set(0);
235-
simData.thrustLimitFlex->set(0);
236-
simData.thrustLimitMct->set(0);
237-
simData.thrustLimitToga->set(0);
238-
}
239-
240-
void EngineControl_A380X::initializeFuelTanks(FLOAT64 timeStamp, UINT64 tickCounter) {
241196
// Setting initial Fuel Levels
242197
const double weightLbsPerGallon = simData.simVarsDataPtr->data().fuelWeightLbsPerGallon;
243198

@@ -287,6 +242,19 @@ void EngineControl_A380X::initializeFuelTanks(FLOAT64 timeStamp, UINT64 tickCoun
287242
simData.fuelRightOuterPre->set(simData.fuelTankDataPtr->data().fuelSystemRightOuter * weightLbsPerGallon);
288243
simData.fuelTrimPre->set(simData.fuelTankDataPtr->data().fuelSystemTrim * weightLbsPerGallon);
289244
}
245+
246+
// Setting initial Fuel Flow
247+
simData.fuelPumpState[E1]->set(0);
248+
simData.fuelPumpState[E2]->set(0);
249+
simData.fuelPumpState[E3]->set(0);
250+
simData.fuelPumpState[E4]->set(0);
251+
252+
// Setting initial Thrust Limits
253+
simData.thrustLimitIdle->set(0);
254+
simData.thrustLimitClimb->set(0);
255+
simData.thrustLimitFlex->set(0);
256+
simData.thrustLimitMct->set(0);
257+
simData.thrustLimitToga->set(0);
290258
}
291259

292260
void EngineControl_A380X::generateIdleParameters(double pressAltitude, double mach, double ambientTemperature, double ambientPressure) {
@@ -905,7 +873,7 @@ void EngineControl_A380X::updateFuel(double deltaTimeSeconds) {
905873
simData.fuelExtraTankDataPtr->writeDataToSim();
906874
}
907875

908-
// Will save the current fuel quantities if the aircraft is on the ground AND engines being shutdown
876+
// Will save the current fuel quantities if on the ground AND engines being shutdown
909877
// AND 5 seconds have passed since the last save
910878
if (msfsHandlerPtr->getSimOnGround() && (msfsHandlerPtr->getSimulationTime() - lastFuelSaveTime) > 5.0 &&
911879
(engine1State == OFF || engine1State == SHUTTING || // 1

fbw-a380x/src/wasm/fadec_a380x/src/Fadec/EngineControl_A380X.h

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,7 @@ class EngineControl_A380X {
3434
FadecSimData_A380X simData{};
3535

3636
// ATC ID for the aircraft used to load and store the fuel levels
37-
std::string atcId = "A380X";
38-
39-
// Whether we have already loaded the fuel configuration from the config file
40-
bool hasLoadedFuelConfig = false;
41-
42-
bool fadecInitialized = false;
37+
std::string atcId{};
4338

4439
// Fuel configuration for loading and storing fuel levels
4540
FuelConfiguration_A380X fuelConfiguration{};
@@ -132,23 +127,12 @@ class EngineControl_A380X {
132127
// ===========================================================================
133128

134129
private:
135-
/**
136-
* @brief Initializes the required data for the engine simulation if it has not been initialized
137-
*/
138-
void loadFuelConfigIfPossible();
139-
140130
/**
141131
* @brief Initialize the FADEC and Fuel model
142132
* This is done after we have retrieved the ATC ID so we can load the fuel levels
143133
*/
144134
void initializeEngineControlData();
145135

146-
/**
147-
* @brief Initializes the fuel tanks based on a default config or the saved state of this livery
148-
* This method may be called multiple times during initialization
149-
*/
150-
void initializeFuelTanks(FLOAT64 timeStamp, UINT64 tickCounter);
151-
152136
/**
153137
* @brief Generate Idle / Initial Engine Parameters (non-imbalanced)
154138
*

0 commit comments

Comments
 (0)