Skip to content

Commit

Permalink
chore: cpp framework improvements and additions (#8640)
Browse files Browse the repository at this point in the history
* Added getDataDefinitionVarByName to DataManager

* Cleanup, formatting and commenting

* Added additional libs and functions

* Added GTest framework and some initial tests

* Added arinc library and initial unit tests

* Added arinc library and initial unit tests

* Refactored test folders and move dampener class to lib

* Improved clang-format to align assignment expressions

* Code documentation

* Removed unnecessary include definition

* Code documentation

* Improved handling of aircraft prefix

* removed old comment

* Code reformatting

* Fix Master Alarm when pressing T.O CONFIG when Flaps or not yet deployed.
  • Loading branch information
frankkopp authored Sep 13, 2024
1 parent 713037f commit c4ab989
Show file tree
Hide file tree
Showing 77 changed files with 2,336 additions and 1,050 deletions.
9 changes: 9 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,12 @@ BasedOnStyle: Chromium
---
Language: Cpp
ColumnLimit: 140
AlignArrayOfStructures: Left
AlignConsecutiveAssignments: Consecutive
AlignConsecutiveDeclarations: Consecutive
AlignConsecutiveShortCaseStatements:
Enabled: true




34 changes: 16 additions & 18 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

# Project folders

# === A32NX ===
/fbw-a32nx/*
/fbw-a32nx/.env.local
!/fbw-a32nx/README.md
Expand All @@ -51,14 +52,13 @@
/fbw-a32nx/src/base/flybywire-aircraft-a320-neo/SimObjects/AirPlanes/FlyByWire_A320_NEO/model/*.gltf
/fbw-a32nx/src/systems/instruments/aceBundles
/fbw-a32nx/src/systems/instruments/buildSrc/custom/*

/fbw-a32nx/src/localization/msfs/downloaded/*.locPak
/fbw-a32nx/src/systems/instruments/src/EFB/dist
/fbw-a32nx/src/systems/instruments/src/EFB/web/

/fbw-a32nx/src/wasm/systems/a320_hydraulic_simulation_graphs/*.png
/fbw-a32nx/src/wasm/systems/a320_pneumatic_simulation_graph_data/*.txt

# === A380X ===
/fbw-a380x/*
/fbw-a380x/.env.local
!/fbw-a380x/README.md
Expand All @@ -72,9 +72,11 @@
/fbw-a380x/src/systems/instruments/aceBundles
/fbw-a380x/src/localization/msfs/downloaded/*.locPak

# === Common ===
!/fbw-common/**
/fbw-common/src/systems/instruments/src/EFB/Localization/data/downloaded/*.json

# === Ingame Panels Checklist Fix ===
/fbw-ingamepanels-checklist-fix/*
!/fbw-ingamepanels-checklist-fix/README.md
!/fbw-ingamepanels-checklist-fix/docs/
Expand All @@ -83,34 +85,30 @@
!/fbw-ingamepanels-checklist-fix/src/**
/fbw-ingamepanels-checklist-fix/out

!/scripts/**

!/build-utils.js

# === Tools ===
!/tools/**
/tools/fdr2csv/*.exe
/tools/fdr2csv/build/
/tools/fdr2csv/cmake-build*

# avoid issues when switching branches during transistion from old to new structure
/src/
/fbw-common/msfs-avionics-mirror/src/sdk/build
/fbw-common/msfs-avionics-mirror/src/sdk/build/**
/msfs-avionics-mirror/
/flybywire-aircraft-a320-neo/
/flybywire-aircraft-a320-neo-lock-highlight/

# Build scripts
!/scripts/**
!/build-utils.js

# explicit exclusions
/.env
*.tgz
localazy.keys.json

# build artifacts
node_modules/
target/
obj/
cmake-build*/
*.tgz
build/
out/
cmake-*/
*.wasm
cmake-build*

localazy.keys.json

# MacOS files
**/.DS_Store
1 change: 0 additions & 1 deletion fbw-a32nx/src/wasm/extra-backend-a32nx/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ set(INCLUDE_FILES
${CMAKE_CURRENT_SOURCE_DIR}/src/Pushback/Pushback_A32NX.h
${FBW_COMMON}/cpp-msfs-framework/Example/ExampleModule.h
${FBW_COMMON}/cpp-msfs-framework/Example/longtext.h
${FBW_COMMON}/extra-backend/Pushback/InertialDampener.hpp
${FBW_COMMON}/extra-backend/Pushback/Pushback.h
${FBW_COMMON}/extra-backend/AircraftPresets/AircraftPresets.h
${FBW_COMMON}/extra-backend/AircraftPresets/PresetProcedures.h
Expand Down
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 @@ -156,6 +156,7 @@ class AircraftPresetProcedures_A32NX {
ProcedureStep{"Spoiler Arm", 3090, false, 2000, "(L:A32NX_SPOILERS_ARMED) 1 ==", "1 (>K:SPOILERS_ARM_SET)"},
ProcedureStep{"Rudder Trim Reset", 3100, false, 2000, "(A:RUDDER TRIM, Radians) 0 ==", "0 (>K:RUDDER_TRIM_SET)"},
ProcedureStep{"Flaps 1", 3110, false, 3000, "(L:A32NX_FLAPS_HANDLE_INDEX) 1 ==", "1 (>L:A32NX_FLAPS_HANDLE_INDEX)"},

// SOP: TAXI
ProcedureStep{"NOSE Lt Taxi", 3120, false, 1000, "(A:CIRCUIT SWITCH ON:20, Bool)", "0 (>L:LIGHTING_LANDING_1) (A:CIRCUIT SWITCH ON:20, Bool) ! if{ 20 (>K:ELECTRICAL_CIRCUIT_TOGGLE)"},
ProcedureStep{"RWY TURN OFF Lt L On", 3130, false, 0, "(A:CIRCUIT SWITCH ON:21, Bool)", "(A:CIRCUIT SWITCH ON:21, Bool) ! if{ 21 (>K:ELECTRICAL_CIRCUIT_TOGGLE)"},
Expand All @@ -166,6 +167,12 @@ class AircraftPresetProcedures_A32NX {
ProcedureStep{"TCAS TRAFFIC Abv", 2100, false, 2000, "(L:A32NX_SWITCH_TCAS_TRAFFIC_POSITION) 2 ==", "2 (>L:A32NX_SWITCH_TCAS_TRAFFIC_POSITION)"},
ProcedureStep{"Autobrake Max", 3080, false, 2000, "(L:A32NX_AUTOBRAKES_ARMED_MODE) 3 ==", "3 (>L:A32NX_AUTOBRAKES_ARMED_MODE_SET)"},
ProcedureStep{"TERR ON ND Capt. On", 3080, false, 2000, "(L:A32NX_EFIS_TERR_L_ACTIVE) 1 ==", "1 (>L:A32NX_EFIS_TERR_L_ACTIVE)"},

ProcedureStep{"Await Flaps 1+F", 3110, true, 1000, "", "(L:A32NX_LEFT_FLAPS_POSITION_PERCENT) 24 >= "
"(L:A32NX_RIGHT_FLAPS_POSITION_PERCENT) 24 >= && "},
ProcedureStep{"Await Slats 1+F", 3110, true, 1000, "", "(L:A32NX_LEFT_SLATS_POSITION_PERCENT) 66 >= "
"(L:A32NX_RIGHT_SLATS_POSITION_PERCENT) 66 >= && "},

ProcedureStep{"T.O Config", 3085, false, 200, "", "1 (>L:A32NX_BTN_TOCONFIG)"},
ProcedureStep{"T.O Config", 3085, false, 2000, "", "0 (>L:A32NX_BTN_TOCONFIG)"},
},
Expand Down Expand Up @@ -219,7 +226,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 @@ -13,7 +13,6 @@

#include <MSFS/Legacy/gauges.h>
#include <MSFS/MSFS.h>
#include <MSFS/MSFS_Render.h>

#include "MsfsHandler.h"

Expand All @@ -34,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 All @@ -49,7 +48,7 @@ AircraftPresets aircraftPresets(msfsHandler, AircraftPresetProcedures_A32NX::air
* https://docs.flightsimulator.com/html/Content_Configuration/SimObjects/Aircraft_SimO/Instruments/C_C++_Gauges.htm?rhhlterm=_gauge_callback&rhsearch=_gauge_callback
*/
extern "C" {
[[maybe_unused]] MSFS_CALLBACK bool Gauge_Extra_Backend_gauge_callback([[maybe_unused]] FsContext ctx, int svcId, void* pData) {
MSFS_CALLBACK bool Gauge_Extra_Backend_gauge_callback([[maybe_unused]] FsContext ctx, int svcId, void* pData) {
switch (svcId) {
case PANEL_SERVICE_PRE_INSTALL: {
return msfsHandler.initialize();
Expand Down
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
Loading

0 comments on commit c4ab989

Please sign in to comment.