Skip to content

Commit

Permalink
Code reformatting
Browse files Browse the repository at this point in the history
  • Loading branch information
frankkopp committed Aug 27, 2024
1 parent f4e4857 commit 8791046
Show file tree
Hide file tree
Showing 56 changed files with 855 additions and 847 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
class AircraftPresetProcedures_A32NX {
public:
const inline static PresetProceduresDefinition aircraftProcedureDefinition{
// clang-format off
// clang-format off
// @formatter:off

.POWERED_CONFIG_ON {
Expand Down Expand Up @@ -219,7 +219,7 @@ class AircraftPresetProcedures_A32NX {
}

// @formatter:on
// clang-format on
// clang-format on
};
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ ExampleModule exampleModule(msfsHandler);
// ADD ADDITIONAL MODULES HERE
// This is the only place these have to be added - everything else is handled automatically
LightingPresets_A32NX lightingPresets(msfsHandler);
Pushback_A32NX pushback(msfsHandler);
AircraftPresets aircraftPresets(msfsHandler, AircraftPresetProcedures_A32NX::aircraftProcedureDefinition);
Pushback_A32NX pushback(msfsHandler);
AircraftPresets aircraftPresets(msfsHandler, AircraftPresetProcedures_A32NX::aircraftProcedureDefinition);

/**
* Gauge Callback
Expand Down Expand Up @@ -65,4 +65,3 @@ MSFS_CALLBACK bool Gauge_Extra_Backend_gauge_callback([[maybe_unused]] FsContext
return false;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
* @brief Aircraft specific pushback implementation for the A32NX
*/
class Pushback_A32NX : public Pushback {
static constexpr FLOAT64 PARKING_BRAKE_FACTOR = 100.0; // slow down when parking brake is engaged by this factor
static constexpr FLOAT64 SPEED_FACTOR = 18.0; // ft/sec for "VELOCITY BODY Z" (also max speed)
static constexpr FLOAT64 TURN_SPEED_FACTOR = 0.5; // ft/sec for "ROTATION VELOCITY BODY Y"
static constexpr FLOAT64 PARKING_BRAKE_FACTOR = 100.0; // slow down when parking brake is engaged by this factor
static constexpr FLOAT64 SPEED_FACTOR = 18.0; // ft/sec for "VELOCITY BODY Z" (also max speed)
static constexpr FLOAT64 TURN_SPEED_FACTOR = 0.5; // ft/sec for "ROTATION VELOCITY BODY Y"

public:
/**
Expand All @@ -22,7 +22,7 @@ class Pushback_A32NX : public Pushback {
explicit Pushback_A32NX(MsfsHandler& msfsHandler) : Pushback(msfsHandler) {}

private:
constexpr int getParkBrakeFactor() const override final { return PARKING_BRAKE_FACTOR; }
constexpr int getParkBrakeFactor() const override final { return PARKING_BRAKE_FACTOR; }
constexpr FLOAT64 getSpeedFactor() const override final { return SPEED_FACTOR; }
constexpr FLOAT64 getTurnSpeedFactor() const override final { return TURN_SPEED_FACTOR; }
};
Expand Down
2 changes: 1 addition & 1 deletion fbw-a32nx/src/wasm/fadec_a32nx/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# A32NX FADEC

This is a new version of the FADEC system for the A32NX.
This is a new version of the FADEC system for the A32NX.
It is a migration and cleanup of the original FADEC system,
and is designed to be more modular and easier to maintain.
Original file line number Diff line number Diff line change
Expand Up @@ -556,9 +556,9 @@ double EngineControl_A32NX::updateFF(int engine,
double outFlow = 0;
if (correctedFuelFlow >= 1) {
outFlow = std::max(0.0, //
(correctedFuelFlow * Fadec::LBS_TO_KGS * EngineRatios::delta2(mach, ambientPressure) //
* (std::sqrt)(EngineRatios::theta2(mach, ambientTemperature))) //
- paramImbalance); //
(correctedFuelFlow * Fadec::LBS_TO_KGS * EngineRatios::delta2(mach, ambientPressure) //
* (std::sqrt)(EngineRatios::theta2(mach, ambientTemperature))) //
- paramImbalance); //
}
simData.engineFF[engine - 1]->set(outFlow);

Expand Down Expand Up @@ -1029,7 +1029,7 @@ void EngineControl_A32NX::updateThrustLimits(double simulationT
deltaThrust = (std::min)(clb - flex, timeDifference * transitionFactor);
}
if (flex + deltaThrust >= clb) {
wasFlexActive = false;
wasFlexActive = false;
isTransitionActive = false;
}
}
Expand Down
76 changes: 38 additions & 38 deletions fbw-a32nx/src/wasm/fadec_a32nx/src/Fadec/EngineControlA32NX.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,31 +40,31 @@ class EngineControl_A32NX {
FuelConfiguration_A32NX fuelConfiguration{};

// previous time the fuel levels were saved to file
double lastFuelSaveTime = 0.0;
double lastFuelSaveTime = 0.0;
static constexpr double FUEL_SAVE_INTERVAL = 5.0; // seconds

// some pump timings - unclear why these are needed
double pumpStateLeftTimeStamp = 0.0;
double pumpStateLeftTimeStamp = 0.0;
double pumpStateRightTimeStamp = 0.0;

bool isTransitionActive = false;
// thrust limits transition for flex
static constexpr double TRANSITION_WAIT_TIME = 10;

// values that need previous state
double prevFlexTemperature = 0.0;
double prevThrustLimitType = 0.0;
double prevEngineMasterPos[2] = {0, 0};
bool prevEngineStarterState[2] = {false, false};
double prevFlexTemperature = 0.0;
double prevThrustLimitType = 0.0;
double prevEngineMasterPos[2] = {0, 0};
bool prevEngineStarterState[2] = {false, false};

// FLX->CLB thrust limit transition
double transitionStartTime;
double transitionFactor;
bool wasFlexActive = false;
bool wasFlexActive = false;

// additional constants
static constexpr int MAX_OIL = 200;
static constexpr int MIN_OIL = 140;
static constexpr int MAX_OIL = 200;
static constexpr int MIN_OIL = 140;
static constexpr double FUEL_RATE_THRESHOLD = 661; // lbs/sec for determining fuel ui tampering

/**
Expand All @@ -78,11 +78,11 @@ class EngineControl_A32NX {
* @var SHUTTING The engine is in the process of shutting down.
*/
enum EngineState {
OFF = 0,
ON = 1,
STARTING = 2,
OFF = 0,
ON = 1,
STARTING = 2,
RESTARTING = 3,
SHUTTING = 4,
SHUTTING = 4,
};

#ifdef PROFILING
Expand Down Expand Up @@ -209,12 +209,12 @@ class EngineControl_A32NX {
* @return The current state of the engine as an enum of type EngineState.
* @see EngineState
*/
EngineControl_A32NX::EngineState engineStateMachine(int engine,
EngineControl_A32NX::EngineState engineStateMachine(int engine,
double engineIgniter,
bool engineStarter,
bool engineStarterTurnedOff,
bool engineMasterTurnedOn,
bool engineMasterTurnedOff,
bool engineStarter,
bool engineStarterTurnedOff,
bool engineMasterTurnedOn,
bool engineMasterTurnedOff,
double simN2,
double idleN2,
double ambientTemperature);
Expand All @@ -233,14 +233,14 @@ class EngineControl_A32NX {
*
* @see EngineState
*/
void engineStartProcedure(int engine,
void engineStartProcedure(int engine,
EngineState engineState,
double imbalance,
double deltaTime,
double engineTimer,
double simN2,
double pressureAltitude,
double ambientTemperature);
double imbalance,
double deltaTime,
double engineTimer,
double simN2,
double pressureAltitude,
double ambientTemperature);

/**
* @brief This function manages the engine shutdown procedure.
Expand All @@ -266,7 +266,7 @@ class EngineControl_A32NX {
* @param ambientPressure The current ambient pressure in hPa.
* @return The updated fuel flow as a double.
*/
double updateFF(int engine, //
double updateFF(int engine, //
double imbalance, //
double simCN1, //
double mach, //
Expand Down Expand Up @@ -301,16 +301,16 @@ class EngineControl_A32NX {
*
* @see EngineState
*/
void updateEGT(int engine,
double imbalance,
double deltaTime,
double simOnGround,
void updateEGT(int engine,
double imbalance,
double deltaTime,
double simOnGround,
EngineState engineState,
double simCN1,
double customFuelFlow,
double mach,
double pressureAltitude,
double ambientTemperature);
double simCN1,
double customFuelFlow,
double mach,
double pressureAltitude,
double ambientTemperature);

/**
* @brief FBW Fuel Consumption and Tanking. Updates Fuel Consumption with realistic values
Expand Down Expand Up @@ -338,9 +338,9 @@ class EngineControl_A32NX {
double ambientPressure,
double mach,
double simN1highest,
int packs,
int nai,
int wai);
int packs,
int nai,
int wai);
};

#endif // FLYBYWIRE_AIRCRAFT_ENGINECONTROL_A32NX_H
28 changes: 14 additions & 14 deletions fbw-a32nx/src/wasm/fadec_a32nx/src/Fadec/FuelConfiguration_A32NX.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@
class FuelConfiguration_A32NX {
private:
// Fuel tank default quantities in gallons
static constexpr double fuelCenterDefault = 0;
static constexpr double fuelLeftDefault = 411.34;
static constexpr double fuelRightDefault = fuelLeftDefault;
static constexpr double fuelLeftAuxDefault = 0;
static constexpr double fuelCenterDefault = 0;
static constexpr double fuelLeftDefault = 411.34;
static constexpr double fuelRightDefault = fuelLeftDefault;
static constexpr double fuelLeftAuxDefault = 0;
static constexpr double fuelRightAuxDefault = fuelLeftAuxDefault;

// Actual fuel tank quantities in gallons
double fuelCenter = fuelCenterDefault;
double fuelLeft = fuelLeftDefault;
double fuelRight = fuelRightDefault;
double fuelLeftAux = fuelLeftAuxDefault;
double fuelCenter = fuelCenterDefault;
double fuelLeft = fuelLeftDefault;
double fuelRight = fuelRightDefault;
double fuelLeftAux = fuelLeftAuxDefault;
double fuelRightAux = fuelRightAuxDefault;

std::string configFilename{"A32NX-default-fuel-config.ini"};
Expand Down Expand Up @@ -72,12 +72,12 @@ class FuelConfiguration_A32NX {
void saveConfigurationToIni();

/**
* @brief Converts the current fuel configuration to a string.
*
* This method is used to convert the current state of the fuel configuration into a string format.
* The string includes the quantities of fuel in each tank.
*
* @return A string representation of the current fuel configuration.
* @brief Converts the current fuel configuration to a string.
*
* This method is used to convert the current state of the fuel configuration into a string format.
* The string includes the quantities of fuel in each tank.
*
* @return A string representation of the current fuel configuration.
*/
std::string toString() const;

Expand Down
13 changes: 6 additions & 7 deletions fbw-a32nx/src/wasm/fadec_a32nx/src/Fadec/Polynomials_A32NX.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class Polynomial_A32NX {
*/
static double startFF(double fbwN2, double idleN2, double idleFF) {
const double normalN2 = fbwN2 / idleN2;
double normalFF = 0;
double normalFF = 0;

// If the normalized N2 percentage is less than or equal to 0.37, the FF is 0.
if (normalN2 <= 0.37) {
Expand Down Expand Up @@ -153,7 +153,6 @@ class Polynomial_A32NX {
// Normalize the current N2 percentage by dividing it with the idle N2 percentage.
const double normalizedN2 = fbwN2 / idleN2;


// Calculate the normalized EGT value based on the normalized N2 value
double normalizedEGT;
if (normalizedN2 < 0.17) {
Expand Down Expand Up @@ -255,8 +254,8 @@ class Polynomial_A32NX {
// data or a mathematical model of the engine's behavior.
// The choice to use different decay rates and steady state temperatures based on the previous
// EGT suggests that the engine's shutdown behavior changes at this threshold.
double threshold = ambientTemp + 140;
double decayRate = previousEGT > threshold ? 0.0257743 : 0.00072756;
double threshold = ambientTemp + 140;
double decayRate = previousEGT > threshold ? 0.0257743 : 0.00072756;
double steadyStateTemp = previousEGT > threshold ? 135 + ambientTemp : 30 + ambientTemp;
return steadyStateTemp + (previousEGT - steadyStateTemp) * exp(-decayRate * deltaTime);
}
Expand Down Expand Up @@ -380,9 +379,9 @@ class Polynomial_A32NX {
static double oilTemperature(double thermalEnergy, double previousOilTemp, double maxOilTemperature, double deltaTime) {
// these constants are likely derived from empirical data or a mathematical model of the engine's behavior
// they were not documented in the original code, and their names here are inferred from their usage
const double heatTransferCoefficient = 0.001;
const double energyScalingFactor = 0.002;
const double temperatureThreshold = 10;
const double heatTransferCoefficient = 0.001;
const double energyScalingFactor = 0.002;
const double temperatureThreshold = 10;
const double temperatureScalingFactor = 0.999997;

const double changeInThermalEnergy = thermalEnergy * deltaTime * energyScalingFactor;
Expand Down
31 changes: 15 additions & 16 deletions fbw-a32nx/src/wasm/fadec_a32nx/src/Fadec/Tables1502_A32NX.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,22 @@ class Tables1502_A32NX {
* @return A 2D array representing the CN2 - correctedN1 pairs.
*/
static constexpr double table1502[13][4] = {
{18.20, 0.00, 0.00, 17.00}, // CN2 = 18.20, correctedN1 = [0.00, 0.00] at Mach 0.2, correctedN1 = 17.00 at Mach 0.9
{22.00, 1.90, 1.90, 17.40}, // CN2 = 22.00, correctedN1 = [1.90, 1.90] at Mach 0.2, correctedN1 = 17.40 at Mach 0.9
{26.00, 2.50, 2.50, 18.20}, // CN2 = 26.00, correctedN1 = [2.50, 2.50] at Mach 0.2, correctedN1 = 18.20 at Mach 0.9
{57.00, 12.80, 12.80, 27.00}, // CN2 = 57.00, correctedN1 = [12.80, 12.80] at Mach 0.2, correctedN1 = 27.00 at Mach 0.9
{68.20, 19.60, 19.60, 34.83}, // CN2 = 68.20, correctedN1 = [19.60, 19.60] at Mach 0.2, correctedN1 = 34.83 at Mach 0.9
{77.00, 26.00, 26.00, 40.84}, // CN2 = 77.00, correctedN1 = [26.00, 26.00] at Mach 0.2, correctedN1 = 40.84 at Mach 0.9
{83.00, 31.42, 31.42, 44.77}, // CN2 = 83.00, correctedN1 = [31.42, 31.42] at Mach 0.2, correctedN1 = 44.77 at Mach 0.9
{89.00, 40.97, 40.97, 50.09}, // CN2 = 89.00, correctedN1 = [40.97, 40.97] at Mach 0.2, correctedN1 = 50.09 at Mach 0.9
{92.80, 51.00, 51.00, 55.04}, // CN2 = 92.80, correctedN1 = [51.00, 51.00] at Mach 0.2, correctedN1 = 55.04 at Mach 0.9
{97.00, 65.00, 65.00, 65.00}, // CN2 = 97.00, correctedN1 = [65.00, 65.00] at Mach 0.2, correctedN1 = 65.00 at Mach 0.9
{100.00, 77.00, 77.00, 77.00}, // CN2 = 100.00, correctedN1 = [77.00, 77.00] at Mach 0.2, correctedN1 = 77.00 at Mach 0.9
{104.00, 85.00, 85.00, 85.50}, // CN2 = 104.00, correctedN1 = [85.00, 85.00] at Mach 0.2, correctedN1 = 85.50 at Mach 0.9
{18.20, 0.00, 0.00, 17.00 }, // CN2 = 18.20, correctedN1 = [0.00, 0.00] at Mach 0.2, correctedN1 = 17.00 at Mach 0.9
{22.00, 1.90, 1.90, 17.40 }, // CN2 = 22.00, correctedN1 = [1.90, 1.90] at Mach 0.2, correctedN1 = 17.40 at Mach 0.9
{26.00, 2.50, 2.50, 18.20 }, // CN2 = 26.00, correctedN1 = [2.50, 2.50] at Mach 0.2, correctedN1 = 18.20 at Mach 0.9
{57.00, 12.80, 12.80, 27.00 }, // CN2 = 57.00, correctedN1 = [12.80, 12.80] at Mach 0.2, correctedN1 = 27.00 at Mach 0.9
{68.20, 19.60, 19.60, 34.83 }, // CN2 = 68.20, correctedN1 = [19.60, 19.60] at Mach 0.2, correctedN1 = 34.83 at Mach 0.9
{77.00, 26.00, 26.00, 40.84 }, // CN2 = 77.00, correctedN1 = [26.00, 26.00] at Mach 0.2, correctedN1 = 40.84 at Mach 0.9
{83.00, 31.42, 31.42, 44.77 }, // CN2 = 83.00, correctedN1 = [31.42, 31.42] at Mach 0.2, correctedN1 = 44.77 at Mach 0.9
{89.00, 40.97, 40.97, 50.09 }, // CN2 = 89.00, correctedN1 = [40.97, 40.97] at Mach 0.2, correctedN1 = 50.09 at Mach 0.9
{92.80, 51.00, 51.00, 55.04 }, // CN2 = 92.80, correctedN1 = [51.00, 51.00] at Mach 0.2, correctedN1 = 55.04 at Mach 0.9
{97.00, 65.00, 65.00, 65.00 }, // CN2 = 97.00, correctedN1 = [65.00, 65.00] at Mach 0.2, correctedN1 = 65.00 at Mach 0.9
{100.00, 77.00, 77.00, 77.00 }, // CN2 = 100.00, correctedN1 = [77.00, 77.00] at Mach 0.2, correctedN1 = 77.00 at Mach 0.9
{104.00, 85.00, 85.00, 85.50 }, // CN2 = 104.00, correctedN1 = [85.00, 85.00] at Mach 0.2, correctedN1 = 85.50 at Mach 0.9
{116.50, 101.00, 101.00, 101.00} // CN2 = 116.50, correctedN1 = [101.00, 101.00] at Mach 0.2, correctedN1 = 101.00 at Mach 0.9
};

public:

public:
/**
* @brief Calculates the expected CN2 at idle.
*
Expand Down Expand Up @@ -79,8 +78,8 @@ class Tables1502_A32NX {
}

// Retrieve the lower and upper bounds of the CN2 value and the correctedN1 value at Mach 0.2 and Mach 0.9
const double cn2lo = table1502[i - 1][0];
const double cn2hi = table1502[i][0];
const double cn2lo = table1502[i - 1][0];
const double cn2hi = table1502[i][0];
const double cn1lolo = table1502[i - 1][1];
const double cn1hilo = table1502[i][1];
const double cn1lohi = table1502[i - 1][3];
Expand Down
Loading

0 comments on commit 8791046

Please sign in to comment.