Skip to content

Commit 6e2397d

Browse files
committed
feat: read enginepower from SimConnect
1 parent 6aa5a00 commit 6e2397d

11 files changed

Lines changed: 81 additions & 43 deletions

src/core/simulator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ namespace swift::core
607607

608608
const CCallsign &ISimulator::getTestCallsign()
609609
{
610-
static const CCallsign cs("SWIFT");
610+
static const CCallsign cs("SWT2026");
611611
return cs;
612612
}
613613

src/gui/components/simulatorcomponent.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,22 @@ namespace swift::gui::components
209209
iconRadio);
210210
this->addOrUpdateLiveDataByName(QStringLiteral("Transponder"), ownAircraft.getTransponderCodeFormatted(),
211211
iconRadio);
212+
213+
// TODO TZ
214+
const int engineCount = sGui->getISimulator()->getOwnAircraftParts().getEngines().getEngineCount();
215+
216+
for (int count = 0; count < engineCount; ++count)
217+
{
218+
const int engNum = count + 1;
219+
const int engof = sGui->getISimulator()->getOwnAircraftParts().getEngines().isEngineOn(engNum);
220+
this->addOrUpdateLiveDataByName(QStringLiteral("ENG%1OnOff").arg(engNum),
221+
engof < 0 ? QStringLiteral("N/A") : QString::number(engof, 'd', 1),
222+
CIcon(CIcons::ApplicationSimulator));
223+
const double engpwr = sGui->getISimulator()->getOwnAircraftParts().getEngines().getEnginePower(engNum);
224+
this->addOrUpdateLiveDataByName(QStringLiteral("ENG%1Pwr").arg(engNum),
225+
engpwr < 0 ? QStringLiteral("N/A") : QString::number(engpwr, 'f', 1),
226+
CIcon(CIcons::ApplicationSimulator));
227+
}
212228
}
213229

214230
void CSimulatorComponent::onSimulatorStatusChanged(int status)

src/misc/aviation/aircraftengine.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ namespace swift::misc::aviation
5353

5454
private:
5555
int m_number = 1;
56-
bool m_on = true;
56+
bool m_on = false;
5757
double m_power = 0.0;
5858

5959
SWIFT_METACLASS(

src/misc/aviation/aircraftenginelist.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ namespace swift::misc::aviation
6363
}
6464
}
6565

66-
void CAircraftEngineList::initEngines(int engineNumber, bool on, int enginePercentage)
66+
void CAircraftEngineList::initEngines(int engineNumber, bool on, double enginePercentage)
6767
{
6868
this->clear();
6969
for (int e = 0; e < engineNumber; e++)
@@ -73,7 +73,7 @@ namespace swift::misc::aviation
7373
}
7474
}
7575

76-
void CAircraftEngineList::setEnginePower(int engineNumber, int percentage)
76+
void CAircraftEngineList::setEnginePower(int engineNumber, double percentage)
7777
{
7878
Q_ASSERT(engineNumber > 0);
7979
for (CAircraftEngine &engine : *this)
@@ -86,7 +86,7 @@ namespace swift::misc::aviation
8686
}
8787
}
8888

89-
int CAircraftEngineList::getEnginePower(int engineNumber) const
89+
double CAircraftEngineList::getEnginePower(int engineNumber) const
9090
{
9191
Q_ASSERT(engineNumber > 0);
9292
return this->getEngine(engineNumber).getEnginePower();

src/misc/aviation/aircraftenginelist.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,20 +57,23 @@ namespace swift::misc::aviation
5757
void setEngines(const CAircraftEngine &engine, int engineNumber);
5858

5959
//! Init some engines
60-
void initEngines(int engineNumber, bool on, int enginePercentage);
60+
void initEngines(int engineNumber, bool on, double enginePercentage);
6161

6262
//! Is any engine on?
6363
bool isAnyEngineOn() const;
6464

65-
void setEnginePower(int engineNumber, int percentage);
65+
void setEnginePower(int engineNumber, double percentage);
6666

67-
int getEnginePower(int engineNumber) const;
67+
double getEnginePower(int engineNumber) const;
6868

6969
//! \copydoc swift::misc::mixin::JsonByMetaClass::toJson
7070
QJsonObject toJson() const;
7171

7272
//! \copydoc swift::misc::mixin::JsonByMetaClass::convertFromJson
7373
void convertFromJson(const QJsonObject &json);
74+
75+
//! Get engine count
76+
int getEngineCount() const { return this->size(); }
7477
};
7578
} // namespace swift::misc::aviation
7679

src/plugins/simulator/fsxcommon/simconnectdatadefinition.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ namespace swift::simplugin::fsxcommon
114114
"Feet");
115115
hr += SimConnect_AddToDataDefinition(hSimConnect, CSimConnectDefinitions::DataOwnAircraft, "SIM ON GROUND",
116116
"Bool");
117+
// 12
117118
hr += SimConnect_AddToDataDefinition(hSimConnect, CSimConnectDefinitions::DataOwnAircraft, "LIGHT STROBE",
118119
"Bool");
119120
hr += SimConnect_AddToDataDefinition(hSimConnect, CSimConnectDefinitions::DataOwnAircraft, "LIGHT LANDING",
@@ -131,6 +132,7 @@ namespace swift::simplugin::fsxcommon
131132
SimConnect_AddToDataDefinition(hSimConnect, CSimConnectDefinitions::DataOwnAircraft, "LIGHT CABIN", "Bool");
132133
hr +=
133134
SimConnect_AddToDataDefinition(hSimConnect, CSimConnectDefinitions::DataOwnAircraft, "LIGHT WING", "Bool");
135+
// 21
134136

135137
hr += SimConnect_AddToDataDefinition(hSimConnect, CSimConnectDefinitions::DataOwnAircraft, "TRANSPONDER CODE:1",
136138
nullptr);
@@ -156,15 +158,17 @@ namespace swift::simplugin::fsxcommon
156158
"Enum");
157159
hr += SimConnect_AddToDataDefinition(hSimConnect, CSimConnectDefinitions::DataOwnAircraft, "COM STATUS:2",
158160
"Enum");
161+
// 33
159162
hr += SimConnect_AddToDataDefinition(hSimConnect, CSimConnectDefinitions::DataOwnAircraft,
160163
"FLAPS HANDLE PERCENT", "Percent Over 100");
161164
hr += SimConnect_AddToDataDefinition(hSimConnect, CSimConnectDefinitions::DataOwnAircraft,
162165
"SPOILERS HANDLE POSITION", "Percent Over 100");
163166
hr += SimConnect_AddToDataDefinition(hSimConnect, CSimConnectDefinitions::DataOwnAircraft,
164167
"GEAR HANDLE POSITION", "Bool");
168+
// 36
165169
hr += SimConnect_AddToDataDefinition(hSimConnect, CSimConnectDefinitions::DataOwnAircraft, "NUMBER OF ENGINES",
166170
"Number");
167-
// Simconnect supports index 1 - 4
171+
168172
hr += SimConnect_AddToDataDefinition(hSimConnect, CSimConnectDefinitions::DataOwnAircraft,
169173
"GENERAL ENG COMBUSTION:1", "Bool");
170174
hr += SimConnect_AddToDataDefinition(hSimConnect, CSimConnectDefinitions::DataOwnAircraft,
@@ -181,7 +185,7 @@ namespace swift::simplugin::fsxcommon
181185
"GENERAL ENG COMBUSTION:7", "Bool");
182186
hr += SimConnect_AddToDataDefinition(hSimConnect, CSimConnectDefinitions::DataOwnAircraft,
183187
"GENERAL ENG COMBUSTION:8", "Bool");
184-
188+
// 45
185189
hr += SimConnect_AddToDataDefinition(hSimConnect, CSimConnectDefinitions::DataOwnAircraft,
186190
"GENERAL ENG THROTTLE LEVER POSITION:1", "percent");
187191
hr += SimConnect_AddToDataDefinition(hSimConnect, CSimConnectDefinitions::DataOwnAircraft,
@@ -198,7 +202,7 @@ namespace swift::simplugin::fsxcommon
198202
"GENERAL ENG THROTTLE LEVER POSITION:7", "percent");
199203
hr += SimConnect_AddToDataDefinition(hSimConnect, CSimConnectDefinitions::DataOwnAircraft,
200204
"GENERAL ENG THROTTLE LEVER POSITION:8", "percent");
201-
205+
// 53
202206
hr += SimConnect_AddToDataDefinition(hSimConnect, CSimConnectDefinitions::DataOwnAircraft, "VELOCITY WORLD X",
203207
"Feet per second");
204208
hr += SimConnect_AddToDataDefinition(hSimConnect, CSimConnectDefinitions::DataOwnAircraft, "VELOCITY WORLD Y",
@@ -214,6 +218,7 @@ namespace swift::simplugin::fsxcommon
214218
// FS2020
215219
hr += SimConnect_AddToDataDefinition(hSimConnect, CSimConnectDefinitions::DataOwnAircraft,
216220
"INDICATED ALTITUDE CALIBRATED", "Feet");
221+
// 60
217222

218223
hr += SimConnect_AddToDataDefinition(hSimConnect, CSimConnectDefinitions::DataOwnAircraftTitle, "TITLE",
219224
nullptr, SIMCONNECT_DATATYPE_STRING256);

src/plugins/simulator/fsxcommon/simconnectdatadefinition.h

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@ namespace swift::simplugin::fsxcommon
4646
double lightBeacon; //!< Is beacon light on?
4747
double lightNav; //!< Is nav light on?
4848
double lightLogo; //!< Is logo light on?
49-
// 18
49+
double lightRecognition;
50+
double lightCabin; //!< Is cabin light on?
51+
double lightWing; //!< Is wing light on?
52+
// 21
5053
double transponderCode; //!< Transponder Code
5154
double com1ActiveMHz; //!< COM1 active frequency
5255
double com2ActiveMHz; //!< COM2 active frequency
@@ -59,11 +62,11 @@ namespace swift::simplugin::fsxcommon
5962
double comTest2; //!< COM2 test
6063
double comStatus1; //!< COM1 status
6164
double comStatus2; //!< COM2 status
62-
// 30
65+
// 33
6366
double flapsHandlePosition; //!< Flaps handle position in percent
6467
double spoilersHandlePosition; //!< Spoilers out? (flag)
6568
double gearHandlePosition; //!< Gear handle position (flag)
66-
// 33
69+
// 36
6770
double numberOfEngines; //!< Number of engines
6871
double engine1Combustion; //!< Engine 1 combustion flag
6972
double engine2Combustion; //!< Engine 2 combustion flag
@@ -73,16 +76,7 @@ namespace swift::simplugin::fsxcommon
7376
double engine6Combustion; //!< Engine 6 combustion flag
7477
double engine7Combustion; //!< Engine 7 combustion flag
7578
double engine8Combustion; //!< Engine 8 combustion flag
76-
// 42
77-
double velocityWorldX; //!< Velocity World X
78-
double velocityWorldY; //!< Velocity World Y
79-
double velocityWorldZ; //!< Velocity World Z
80-
double rotationVelocityBodyX; //!< Rotation Velocity Body X
81-
double rotationVelocityBodyY; //!< Rotation Velocity Body Y
82-
double rotationVelocityBodyZ; //!< Rotation Velocity Body Z
83-
// 48
84-
double altitudeCalibratedFt; //!< Altitude without temperature effect (ft, FS2020)
85-
// 49
79+
// 45
8680
double engine1Power; //!< Engine 1 power
8781
double engine2Power; //!< Engine 2 power
8882
double engine3Power; //!< Engine 3 power
@@ -91,7 +85,16 @@ namespace swift::simplugin::fsxcommon
9185
double engine6Power; //!< Engine 6 power
9286
double engine7Power; //!< Engine 7 power
9387
double engine8Power; //!< Engine 8 power
94-
// 57
88+
// 53
89+
double velocityWorldX; //!< Velocity World X
90+
double velocityWorldY; //!< Velocity World Y
91+
double velocityWorldZ; //!< Velocity World Z
92+
double rotationVelocityBodyX; //!< Rotation Velocity Body X
93+
double rotationVelocityBodyY; //!< Rotation Velocity Body Y
94+
double rotationVelocityBodyZ; //!< Rotation Velocity Body Z
95+
// 59
96+
double altitudeCalibratedFt; //!< Altitude without temperature effect (ft, FS2020)
97+
// 60
9598
};
9699

97100
//! Data struct of aircraft position

src/plugins/simulator/fsxcommon/simulatorfsxcommon.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -740,14 +740,20 @@ namespace swift::simplugin::fsxcommon
740740
dtb(simulatorOwnAircraft.lightNav), dtb(simulatorOwnAircraft.lightLogo));
741741

742742
CAircraftEngineList engines;
743-
const QList<bool> helperList { dtb(simulatorOwnAircraft.engine1Combustion),
744-
dtb(simulatorOwnAircraft.engine2Combustion),
745-
dtb(simulatorOwnAircraft.engine3Combustion),
746-
dtb(simulatorOwnAircraft.engine4Combustion) };
743+
const QList<bool> helperList {
744+
dtb(simulatorOwnAircraft.engine1Combustion), dtb(simulatorOwnAircraft.engine2Combustion),
745+
dtb(simulatorOwnAircraft.engine3Combustion), dtb(simulatorOwnAircraft.engine4Combustion),
746+
dtb(simulatorOwnAircraft.engine5Combustion), dtb(simulatorOwnAircraft.engine6Combustion),
747+
dtb(simulatorOwnAircraft.engine7Combustion), dtb(simulatorOwnAircraft.engine8Combustion)
748+
};
749+
const QList<double> powerList { simulatorOwnAircraft.engine1Power, simulatorOwnAircraft.engine2Power,
750+
simulatorOwnAircraft.engine3Power, simulatorOwnAircraft.engine4Power,
751+
simulatorOwnAircraft.engine5Power, simulatorOwnAircraft.engine6Power,
752+
simulatorOwnAircraft.engine7Power, simulatorOwnAircraft.engine8Power };
747753

748754
for (int index = 0; index < simulatorOwnAircraft.numberOfEngines; ++index)
749755
{
750-
engines.push_back(CAircraftEngine(index + 1, helperList.value(index, true), 100));
756+
engines.push_back(CAircraftEngine(index + 1, helperList.value(index, false), powerList.value(index, 0)));
751757
}
752758

753759
const CAircraftParts parts(lights, dtb(simulatorOwnAircraft.gearHandlePosition),

src/plugins/simulator/fsxcommon/simulatorfsxsimconnectproc.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ namespace swift::simplugin::fsxcommon
245245
{
246246
case CSimConnectDefinitions::RequestOwnAircraft:
247247
{
248-
static_assert(sizeof(DataDefinitionOwnAircraft) == 57 * sizeof(double),
248+
static_assert(sizeof(DataDefinitionOwnAircraft) == 60 * sizeof(double),
249249
"DataDefinitionOwnAircraft has an incorrect size.");
250250
const DataDefinitionOwnAircraft *ownAircaft =
251251
reinterpret_cast<const DataDefinitionOwnAircraft *>(&pObjData->dwData);

src/plugins/simulator/msfs2024/simconnectdatadefinitionmsfs2024.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,7 @@ namespace swift::simplugin::msfs2024common
7777
double engine6Combustion; //!< Engine 6 combustion flag
7878
double engine7Combustion; //!< Engine 7 combustion flag
7979
double engine8Combustion; //!< Engine 8 combustion flag
80-
// 46
81-
double velocityWorldX; //!< Velocity World X
82-
double velocityWorldY; //!< Velocity World Y
83-
double velocityWorldZ; //!< Velocity World Z
84-
double rotationVelocityBodyX; //!< Rotation Velocity Body X
85-
double rotationVelocityBodyY; //!< Rotation Velocity Body Y
86-
double rotationVelocityBodyZ; //!< Rotation Velocity Body Z
87-
// 52
88-
double altitudeCalibratedFt; //!< Altitude without temperature effect (ft, FS2020)
89-
// 53
80+
// 45
9081
double engine1Power; //!< Engine 1 power
9182
double engine2Power; //!< Engine 2 power
9283
double engine3Power; //!< Engine 3 power
@@ -95,7 +86,16 @@ namespace swift::simplugin::msfs2024common
9586
double engine6Power; //!< Engine 6 power
9687
double engine7Power; //!< Engine 7 power
9788
double engine8Power; //!< Engine 8 power
98-
// 61
89+
// 53
90+
double velocityWorldX; //!< Velocity World X
91+
double velocityWorldY; //!< Velocity World Y
92+
double velocityWorldZ; //!< Velocity World Z
93+
double rotationVelocityBodyX; //!< Rotation Velocity Body X
94+
double rotationVelocityBodyY; //!< Rotation Velocity Body Y
95+
double rotationVelocityBodyZ; //!< Rotation Velocity Body Z
96+
// 59
97+
double altitudeCalibratedFt; //!< Altitude without temperature effect (ft, FS2020)
98+
// 60
9999
};
100100

101101
//! Data struct of aircraft position

0 commit comments

Comments
 (0)