Skip to content

MSFS Com Volume and various fixes #354

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

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ jobs:
swiftinstaller-linux-64-${{ needs.preBuild.outputs.version }}.run
swiftinstaller-windows-64-${{ needs.preBuild.outputs.version }}.exe
swiftinstaller-macos-64-${{ needs.preBuild.outputs.version }}.dmg
xswiftbus-fat-allos-${{ needs.preBuild.outputs.version }}.7z
xswiftbus-fat-allos-${{ needs.preBuild.outputs.version }}.zip
swiftsymbols-allos-${{ needs.preBuild.outputs.version }}:swiftsymbols
- name: Publish doxygen
uses: actions/deploy-pages@v4
Expand Down
16 changes: 12 additions & 4 deletions src/gui/components/cockpitcomcomponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ namespace swift::gui::components
// Relay COM form signals
connect(ui->editor_Com, &CCockpitComForm::transponderModeChanged, this,
&CCockpitComComponent::transponderModeChanged);
connect(ui->editor_Com, &CCockpitComForm::transponderStateIdentEnded, this,
&CCockpitComComponent::transponderStateIdentEnded);

// hook up with changes from own aircraft context
if (sGui)
Expand Down Expand Up @@ -149,8 +147,18 @@ namespace swift::gui::components
// unavailable context during shutdown possible
// mostly when client runs with DBus, but DBus is down
if (!sGui || sGui->isShuttingDown() || !sGui->getIContextOwnAircraft()) { return false; }
return sGui->getIContextOwnAircraft()->updateCockpit(ownAircraft.getCom1System(), ownAircraft.getCom2System(),
ownAircraft.getTransponder(), identifier());

// The CockpitComForm triggering this slot only includes frequencies and transponder mode/code.
// Everything else is left as default default (especially radio volume and TX/RX state).
CComSystem com1 = sGui->getIContextOwnAircraft()->getOwnAircraft().getCom1System();
CComSystem com2 = sGui->getIContextOwnAircraft()->getOwnAircraft().getCom2System();
com1.setFrequencyActive(ownAircraft.getCom1System().getFrequencyActive());
com1.setFrequencyStandby(ownAircraft.getCom1System().getFrequencyStandby());
com2.setFrequencyActive(ownAircraft.getCom2System().getFrequencyActive());
com2.setFrequencyStandby(ownAircraft.getCom2System().getFrequencyStandby());

return sGui->getIContextOwnAircraft()->updateCockpit(com1, com2,
ownAircraft.getTransponder(), identifier());
}

void CCockpitComComponent::forceCockpitUpdateFromOwnAircraftContext()
Expand Down
3 changes: 0 additions & 3 deletions src/gui/components/cockpitcomcomponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ namespace swift::gui::components
//! \copydoc swift::gui::components::CTransponderModeSelector::transponderModeChanged
void transponderModeChanged(swift::misc::aviation::CTransponder::TransponderMode newMode);

//! \copydoc swift::gui::components::CTransponderModeSelector::transponderStateIdentEnded
void transponderStateIdentEnded();

//! @{
//! Request COM text messages
void requestCom1TextMessage();
Expand Down
5 changes: 3 additions & 2 deletions src/gui/components/transpondermodeselector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,30 +59,31 @@ namespace swift::gui::components
{
if (mode != CTransponder::StateIdent) { m_resetMode = mode; }
if (m_currentMode == mode) { return; }
if (m_currentMode == CTransponder::StateIdent) { emit this->transponderStateIdentEnded(); }
m_currentMode = mode;
const QString m = CTransponder::modeAsString(mode);
QComboBox::setCurrentText(m);
if (mode == CTransponder::StateIdent) { m_resetTimer.start(); }
else { m_resetTimer.stop(); }
emit this->transponderModeChanged(m_currentMode);
}

void CTransponderModeSelector::setSelectedTransponderModeStateIdent()
{
this->setSelectedTransponderMode(swift::misc::aviation::CTransponder::StateIdent);
emit this->transponderModeChanged(m_currentMode);
}

void CTransponderModeSelector::setSelectedTransponderModeAsString(const QString &mode)
{
CTransponder::TransponderMode m = CTransponder::modeFromString(mode);
if (m_currentMode == m) return; // nothing to change
this->setSelectedTransponderMode(m);
emit this->transponderModeChanged(m_currentMode);
}

void CTransponderModeSelector::resetTransponderMode()
{
if (!this->isIdentSelected()) return; // avoid unnecessary events
this->setSelectedTransponderMode(m_resetMode);
emit this->transponderModeChanged(m_currentMode);
}
} // namespace swift::gui::components
9 changes: 3 additions & 6 deletions src/gui/components/transpondermodeselector.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@ namespace swift::gui::components
//! Ident selected
bool isIdentSelected() const;

//! reset to last mode (unequal ident)
void resetTransponderMode();

//! Selected transponder mode
void setSelectedTransponderModeAsString(const QString &mode);

Expand All @@ -60,10 +57,10 @@ namespace swift::gui::components
//! Mode / state has been changed
void transponderModeChanged(swift::misc::aviation::CTransponder::TransponderMode newMode);

//! Ident phase ended
void transponderStateIdentEnded();

private:
//! reset to last mode (unequal ident)
void resetTransponderMode();

swift::misc::aviation::CTransponder::TransponderMode m_currentMode =
swift::misc::aviation::CTransponder::StateStandby;
swift::misc::aviation::CTransponder::TransponderMode m_resetMode =
Expand Down
2 changes: 0 additions & 2 deletions src/gui/editors/cockpitcomform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ namespace swift::gui::editors
// XPDR
connect(ui->cbp_ComPanelTransponderMode, &CTransponderModeSelector::transponderModeChanged, this,
&CCockpitComForm::transponderModeChanged);
connect(ui->cbp_ComPanelTransponderMode, &CTransponderModeSelector::transponderStateIdentEnded, this,
&CCockpitComForm::transponderStateIdentEnded);

// COM GUI events
connect(ui->tb_ComPanelCom1Toggle, &QPushButton::clicked, this, &CCockpitComForm::onGuiChangedCockpitValues);
Expand Down
3 changes: 0 additions & 3 deletions src/gui/editors/cockpitcomform.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,6 @@ namespace swift::gui::editors
//! \copydoc swift::gui::components::CTransponderModeSelector::transponderModeChanged
void transponderModeChanged(swift::misc::aviation::CTransponder::TransponderMode newMode);

//! \copydoc swift::gui::components::CTransponderModeSelector::transponderStateIdentEnded
void transponderStateIdentEnded();

//! Request to test SELCAL
void testSelcal();

Expand Down
33 changes: 12 additions & 21 deletions src/plugins/simulator/fsxcommon/simconnectdatadefinition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ namespace swift::simplugin::fsxcommon
hr += initRemoteAircraftSimDataSet(hSimConnect);
hr += initSimulatorEnvironment(hSimConnect);
hr += initSbDataArea(hSimConnect);
if (simInfo.isMSFS()) { hr += initMSFSTransponder(hSimConnect); }
if (simInfo.isMSFS2024()) { hr += initMSFS2024Transponder(hSimConnect); }
if (simInfo.isMSFS() || simInfo.isMSFS2024()) { hr += initMSFSTransponder(hSimConnect); }
return hr;
}

Expand Down Expand Up @@ -179,9 +178,18 @@ namespace swift::simplugin::fsxcommon
"ROTATION VELOCITY BODY Y", "Radians per second");
hr += SimConnect_AddToDataDefinition(hSimConnect, CSimConnectDefinitions::DataOwnAircraft,
"ROTATION VELOCITY BODY Z", "Radians per second");
// FS2020
// MSFS 2020/2024 only. Placed at the end because non-MSFS simulators fail with these and skip them.
// Only access the members when using MSFS!
hr += SimConnect_AddToDataDefinition(hSimConnect, CSimConnectDefinitions::DataOwnAircraft,
"INDICATED ALTITUDE CALIBRATED", "Feet");
hr += SimConnect_AddToDataDefinition(hSimConnect, CSimConnectDefinitions::DataOwnAircraft,
"TRANSPONDER STATE:1", "Enum");
hr += SimConnect_AddToDataDefinition(hSimConnect, CSimConnectDefinitions::DataOwnAircraft,
"TRANSPONDER IDENT:1", "Bool");
hr += SimConnect_AddToDataDefinition(hSimConnect, CSimConnectDefinitions::DataOwnAircraft,
"COM VOLUME:1", "Percent");
hr += SimConnect_AddToDataDefinition(hSimConnect, CSimConnectDefinitions::DataOwnAircraft,
"COM VOLUME:2", "Percent");

hr += SimConnect_AddToDataDefinition(hSimConnect, CSimConnectDefinitions::DataOwnAircraftTitle, "TITLE",
nullptr, SIMCONNECT_DATATYPE_STRING256);
Expand Down Expand Up @@ -412,28 +420,11 @@ namespace swift::simplugin::fsxcommon
HRESULT hr = s_ok();
hr += SimConnect_AddToDataDefinition(hSimConnect, CSimConnectDefinitions::DataTransponderModeMSFS,
"TRANSPONDER STATE:1", "Enum");
hr += SimConnect_AddToDataDefinition(hSimConnect, CSimConnectDefinitions::DataTransponderModeMSFS,
"TRANSPONDER IDENT:1", "Bool");
if (isFailure(hr))
{
CLogMessage(static_cast<CSimConnectDefinitions *>(nullptr))
.error(u"SimConnect error: MSFS transponder data definitions %1")
<< hr;
}
return hr;
}

HRESULT CSimConnectDefinitions::initMSFS2024Transponder(const HANDLE hSimConnect)
{
HRESULT hr = s_ok();
hr += SimConnect_AddToDataDefinition(hSimConnect, CSimConnectDefinitions::DataTransponderModeMSFS,
"TRANSPONDER STATE:1", "Enum");
hr += SimConnect_AddToDataDefinition(hSimConnect, CSimConnectDefinitions::DataTransponderModeMSFS,
"TRANSPONDER IDENT:1", "Bool");
if (isFailure(hr))
{
CLogMessage(static_cast<CSimConnectDefinitions *>(nullptr))
.error(u"SimConnect error: MSFS2024 transponder data definitions %1")
.error(u"SimConnect error: MSFS transponder data definitions %1")
<< hr;
}
return hr;
Expand Down
14 changes: 6 additions & 8 deletions src/plugins/simulator/fsxcommon/simconnectdatadefinition.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,11 @@ namespace swift::simplugin::fsxcommon
double rotationVelocityBodyX; //!< Rotation Velocity Body X
double rotationVelocityBodyY; //!< Rotation Velocity Body Y
double rotationVelocityBodyZ; //!< Rotation Velocity Body Z
// 44
double altitudeCalibratedFt; //!< Altitude without temperature effect (ft, FS2020)
// 45
double altitudeCalibratedFt; //!< Altitude without temperature effect (ft, MSFS)
double transponderMode; //!< transponder state (MSFS)
double ident; //!< ident (MSFS)
double com1Volume; //!< COM1 volume (MSFS)
double com2Volume; //!< COM2 volume (MSFS)
};

//! Data struct of aircraft position
Expand Down Expand Up @@ -253,9 +255,9 @@ namespace swift::simplugin::fsxcommon
struct DataDefinitionMSFSTransponderMode
{
double transponderMode = 1; //!< transponder state simvar
double ident = 0; //!< ident
};


//! Client areas
enum ClientAreaId
{
Expand Down Expand Up @@ -293,7 +295,6 @@ namespace swift::simplugin::fsxcommon
RequestOwnAircraft,
RequestOwnAircraftTitle,
RequestSbData, //!< SB client area / XPDR mode
RequestMSFSTransponder, //!< MSFS XPDR mode/ident
RequestFacility,
RequestEndMarker //!< free request ids can start here
};
Expand Down Expand Up @@ -345,9 +346,6 @@ namespace swift::simplugin::fsxcommon

//! Initialize data definition for MSFS transponder
static HRESULT initMSFSTransponder(const HANDLE hSimConnect);

//! Initialize data definition for MSFS transponder
static HRESULT initMSFS2024Transponder(const HANDLE hSimConnect);
};
} // namespace swift::simplugin::fsxcommon

Expand Down
43 changes: 20 additions & 23 deletions src/plugins/simulator/fsxcommon/simulatorfsxcommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,6 @@ namespace swift::simplugin::fsxcommon
{
DataDefinitionMSFSTransponderMode t;
t.transponderMode = (newTransponder.isInStandby() ? 1 : 4);
t.ident = newTransponder.isIdentifying();

HRESULT hr = s_ok();

Expand Down Expand Up @@ -528,7 +527,6 @@ namespace swift::simplugin::fsxcommon
SIMCONNECT_PERIOD_SECOND, SIMCONNECT_DATA_REQUEST_FLAG_CHANGED),
"Cannot request title", Q_FUNC_INFO, "SimConnect_RequestDataOnSimObject");

// TODO TZ use MSFS2024 FSUIPC?
if (!this->getSimulatorPluginInfo().getSimulatorInfo().isMSFS() &&
!this->getSimulatorPluginInfo().getSimulatorInfo().isMSFS2024())
{
Expand All @@ -542,15 +540,6 @@ namespace swift::simplugin::fsxcommon
SIMCONNECT_CLIENT_DATA_REQUEST_FLAG_CHANGED),
"Cannot request client data", Q_FUNC_INFO, "SimConnect_RequestClientData");
}
else
{
hr += this->logAndTraceSendId(
SimConnect_RequestDataOnSimObject(m_hSimConnect, CSimConnectDefinitions::RequestMSFSTransponder,
CSimConnectDefinitions::DataTransponderModeMSFS,
SIMCONNECT_OBJECT_ID_USER, SIMCONNECT_PERIOD_VISUAL_FRAME,
SIMCONNECT_DATA_REQUEST_FLAG_CHANGED),
"Cannot request MSFS transponder data", Q_FUNC_INFO, "SimConnect_RequestDataOnSimObject");
}

if (isFailure(hr)) { return; }
this->emitSimulatorCombinedStatus(); // force sending status
Expand Down Expand Up @@ -693,6 +682,20 @@ namespace swift::simplugin::fsxcommon
CAltitude(simulatorOwnAircraft.altitudeFt, CAltitude::MeanSeaLevel, CLengthUnit::ft()));
}

void CSimulatorFsxCommon::setTransponderMode(
[[maybe_unused]] swift::misc::aviation::CTransponder &transponder,
[[maybe_unused]] const swift::simplugin::fsxcommon::DataDefinitionOwnAircraft &simulatorOwnAircraft)
{ /* Do not modify the transponder mode by default. Only MSFS allows to read it from SimVars */ }

void CSimulatorFsxCommon::setComVolume(
[[maybe_unused]] swift::misc::aviation::CComSystem &com,
[[maybe_unused]] const swift::simplugin::fsxcommon::DataDefinitionOwnAircraft &simulatorOwnAircraft,
[[maybe_unused]] swift::misc::aviation::CComSystem::ComUnit unit)
{
/* Do not modify the COM volume by default. Only MSFS allows to read it from SimVars */
}


void CSimulatorFsxCommon::updateOwnAircraftFromSimulator(const DataDefinitionOwnAircraft &simulatorOwnAircraft)
{
const qint64 ts = QDateTime::currentMSecsSinceEpoch();
Expand Down Expand Up @@ -797,6 +800,8 @@ namespace swift::simplugin::fsxcommon
if (!changedCom1Standby) { com1.setFrequencyStandby(myAircraft.getCom1System().getFrequencyStandby()); }
else { m_lastCom1Standby.setNull(); }

setComVolume(com1, simulatorOwnAircraft, CComSystem::Com1);

const bool changedCom1 = myAircraft.getCom1System() != com1;

m_simCom1 = com1;
Expand Down Expand Up @@ -825,19 +830,22 @@ namespace swift::simplugin::fsxcommon
if (!changedCom2Standby) { com2.setFrequencyStandby(myAircraft.getCom2System().getFrequencyStandby()); }
else { m_lastCom2Standby.setNull(); }

setComVolume(com2, simulatorOwnAircraft, CComSystem::Com2);

const bool changedCom2 = myAircraft.getCom2System() != com2;

m_simCom2 = com2;
Q_UNUSED(com2Test)

CTransponder transponder(myAircraft.getTransponder());
transponder.setTransponderCode(qRound(simulatorOwnAircraft.transponderCode));
setTransponderMode(transponder, simulatorOwnAircraft);
m_simTransponder = transponder;

// if the simulator ever sends SELCAL, add it here.
// m_selcal SELCAL sync.would go here

const bool changedXpr = (myAircraft.getTransponderCode() != transponder.getTransponderCode());
const bool changedXpr = (myAircraft.getTransponder() != transponder);

if (changedCom1 || changedCom2 || changedXpr)
{
Expand Down Expand Up @@ -1009,17 +1017,6 @@ namespace swift::simplugin::fsxcommon
this->updateCockpit(myAircraft.getCom1System(), myAircraft.getCom2System(), myXpdr, this->identifier());
}

void CSimulatorFsxCommon::updateMSFSTransponderMode(const DataDefinitionMSFSTransponderMode transponderMode)
{
auto mode = CTransponder::StateIdent;
if (!transponderMode.ident)
{
qRound(transponderMode.transponderMode) >= 3 ? mode = CTransponder::ModeC :
mode = CTransponder::StateStandby;
}
this->updateTransponderMode(mode);
}

bool CSimulatorFsxCommon::simulatorReportedObjectAdded(DWORD objectId)
{
if (this->isShuttingDownOrDisconnected()) { return true; } // pretend everything is fine
Expand Down
14 changes: 11 additions & 3 deletions src/plugins/simulator/fsxcommon/simulatorfsxcommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,17 @@ namespace swift::simplugin::fsxcommon
setTrueAltitude(swift::misc::aviation::CAircraftSituation &aircraftSituation,
const swift::simplugin::fsxcommon::DataDefinitionOwnAircraft &simulatorOwnAircraft);

//! Customization point for changing the transponder mode
virtual void
setTransponderMode(swift::misc::aviation::CTransponder &transponder,
const swift::simplugin::fsxcommon::DataDefinitionOwnAircraft &simulatorOwnAircraft);

//! Customization point for changing the COM volume
virtual void
setComVolume(swift::misc::aviation::CComSystem &com,
const swift::simplugin::fsxcommon::DataDefinitionOwnAircraft &simulatorOwnAircraft,
swift::misc::aviation::CComSystem::ComUnit unit);

//! Called when data about our own aircraft are received
void updateOwnAircraftFromSimulator(const DataDefinitionOwnAircraft &simulatorOwnAircraft);

Expand All @@ -514,9 +525,6 @@ namespace swift::simplugin::fsxcommon
//! \threadsafe
void updateTransponderMode(const misc::aviation::CTransponder::TransponderMode xpdrMode);

//! Update transponder mode from MSFS
void updateMSFSTransponderMode(const DataDefinitionMSFSTransponderMode transponderMode);

//! An AI aircraft was added in the simulator
bool simulatorReportedObjectAdded(DWORD objectId);

Expand Down
Loading