mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-19 12:15:29 +08:00
refactor(msfs): Request transponder data with OwnAircraftData
This commit is contained in:
@@ -81,7 +81,6 @@ namespace swift::simplugin::fsxcommon
|
|||||||
hr += initRemoteAircraftSimDataSet(hSimConnect);
|
hr += initRemoteAircraftSimDataSet(hSimConnect);
|
||||||
hr += initSimulatorEnvironment(hSimConnect);
|
hr += initSimulatorEnvironment(hSimConnect);
|
||||||
hr += initSbDataArea(hSimConnect);
|
hr += initSbDataArea(hSimConnect);
|
||||||
if (simInfo.isMSFS() || simInfo.isMSFS2024()) { hr += initMSFSTransponder(hSimConnect); }
|
|
||||||
return hr;
|
return hr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -178,9 +177,13 @@ namespace swift::simplugin::fsxcommon
|
|||||||
"ROTATION VELOCITY BODY Y", "Radians per second");
|
"ROTATION VELOCITY BODY Y", "Radians per second");
|
||||||
hr += SimConnect_AddToDataDefinition(hSimConnect, CSimConnectDefinitions::DataOwnAircraft,
|
hr += SimConnect_AddToDataDefinition(hSimConnect, CSimConnectDefinitions::DataOwnAircraft,
|
||||||
"ROTATION VELOCITY BODY Z", "Radians per second");
|
"ROTATION VELOCITY BODY Z", "Radians per second");
|
||||||
// FS2020
|
// MSFS 2020/2024 only
|
||||||
hr += SimConnect_AddToDataDefinition(hSimConnect, CSimConnectDefinitions::DataOwnAircraft,
|
hr += SimConnect_AddToDataDefinition(hSimConnect, CSimConnectDefinitions::DataOwnAircraft,
|
||||||
"INDICATED ALTITUDE CALIBRATED", "Feet");
|
"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::DataOwnAircraftTitle, "TITLE",
|
hr += SimConnect_AddToDataDefinition(hSimConnect, CSimConnectDefinitions::DataOwnAircraftTitle, "TITLE",
|
||||||
nullptr, SIMCONNECT_DATATYPE_STRING256);
|
nullptr, SIMCONNECT_DATATYPE_STRING256);
|
||||||
@@ -406,22 +409,6 @@ namespace swift::simplugin::fsxcommon
|
|||||||
return hr;
|
return hr;
|
||||||
}
|
}
|
||||||
|
|
||||||
HRESULT CSimConnectDefinitions::initMSFSTransponder(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: MSFS transponder data definitions %1")
|
|
||||||
<< hr;
|
|
||||||
}
|
|
||||||
return hr;
|
|
||||||
}
|
|
||||||
|
|
||||||
DataDefinitionRemoteAircraftPartsWithoutLights::DataDefinitionRemoteAircraftPartsWithoutLights()
|
DataDefinitionRemoteAircraftPartsWithoutLights::DataDefinitionRemoteAircraftPartsWithoutLights()
|
||||||
{
|
{
|
||||||
this->resetToInvalid();
|
this->resetToInvalid();
|
||||||
|
|||||||
@@ -76,9 +76,9 @@ namespace swift::simplugin::fsxcommon
|
|||||||
double rotationVelocityBodyX; //!< Rotation Velocity Body X
|
double rotationVelocityBodyX; //!< Rotation Velocity Body X
|
||||||
double rotationVelocityBodyY; //!< Rotation Velocity Body Y
|
double rotationVelocityBodyY; //!< Rotation Velocity Body Y
|
||||||
double rotationVelocityBodyZ; //!< Rotation Velocity Body Z
|
double rotationVelocityBodyZ; //!< Rotation Velocity Body Z
|
||||||
// 44
|
double altitudeCalibratedFt; //!< Altitude without temperature effect (ft, MSFS)
|
||||||
double altitudeCalibratedFt; //!< Altitude without temperature effect (ft, FS2020)
|
double transponderMode; //!< transponder state (MSFS)
|
||||||
// 45
|
double ident; //!< ident (MSFS)
|
||||||
};
|
};
|
||||||
|
|
||||||
//! Data struct of aircraft position
|
//! Data struct of aircraft position
|
||||||
@@ -249,13 +249,6 @@ namespace swift::simplugin::fsxcommon
|
|||||||
QString toQString() const;
|
QString toQString() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
//! Data structure for MSFS transponder mode information
|
|
||||||
struct DataDefinitionMSFSTransponderMode
|
|
||||||
{
|
|
||||||
double transponderMode = 1; //!< transponder state simvar
|
|
||||||
double ident = 0; //!< ident
|
|
||||||
};
|
|
||||||
|
|
||||||
//! Client areas
|
//! Client areas
|
||||||
enum ClientAreaId
|
enum ClientAreaId
|
||||||
{
|
{
|
||||||
@@ -279,7 +272,6 @@ namespace swift::simplugin::fsxcommon
|
|||||||
DataRemoteAircraftModelData, //!< model data eventually used and reported back from simulator
|
DataRemoteAircraftModelData, //!< model data eventually used and reported back from simulator
|
||||||
DataRemoteAircraftSetData, //!< set model data such as airline
|
DataRemoteAircraftSetData, //!< set model data such as airline
|
||||||
DataSimEnvironment,
|
DataSimEnvironment,
|
||||||
DataTransponderModeMSFS,
|
|
||||||
DataClientAreaSb, //!< whole SB area, see http://squawkbox.ca/doc/sdk/fsuipc.php
|
DataClientAreaSb, //!< whole SB area, see http://squawkbox.ca/doc/sdk/fsuipc.php
|
||||||
DataClientAreaSbIdent, //!< SB ident single value 0x7b93/19
|
DataClientAreaSbIdent, //!< SB ident single value 0x7b93/19
|
||||||
DataClientAreaSbStandby, //!< SB standby 0x7b91/17
|
DataClientAreaSbStandby, //!< SB standby 0x7b91/17
|
||||||
@@ -293,7 +285,6 @@ namespace swift::simplugin::fsxcommon
|
|||||||
RequestOwnAircraft,
|
RequestOwnAircraft,
|
||||||
RequestOwnAircraftTitle,
|
RequestOwnAircraftTitle,
|
||||||
RequestSbData, //!< SB client area / XPDR mode
|
RequestSbData, //!< SB client area / XPDR mode
|
||||||
RequestMSFSTransponder, //!< MSFS XPDR mode/ident
|
|
||||||
RequestFacility,
|
RequestFacility,
|
||||||
RequestEndMarker //!< free request ids can start here
|
RequestEndMarker //!< free request ids can start here
|
||||||
};
|
};
|
||||||
@@ -342,9 +333,6 @@ namespace swift::simplugin::fsxcommon
|
|||||||
|
|
||||||
//! Initialize the SB data are
|
//! Initialize the SB data are
|
||||||
static HRESULT initSbDataArea(const HANDLE hSimConnect);
|
static HRESULT initSbDataArea(const HANDLE hSimConnect);
|
||||||
|
|
||||||
//! Initialize data definition for MSFS transponder
|
|
||||||
static HRESULT initMSFSTransponder(const HANDLE hSimConnect);
|
|
||||||
};
|
};
|
||||||
} // namespace swift::simplugin::fsxcommon
|
} // namespace swift::simplugin::fsxcommon
|
||||||
|
|
||||||
|
|||||||
@@ -528,7 +528,6 @@ namespace swift::simplugin::fsxcommon
|
|||||||
SIMCONNECT_PERIOD_SECOND, SIMCONNECT_DATA_REQUEST_FLAG_CHANGED),
|
SIMCONNECT_PERIOD_SECOND, SIMCONNECT_DATA_REQUEST_FLAG_CHANGED),
|
||||||
"Cannot request title", Q_FUNC_INFO, "SimConnect_RequestDataOnSimObject");
|
"Cannot request title", Q_FUNC_INFO, "SimConnect_RequestDataOnSimObject");
|
||||||
|
|
||||||
// TODO TZ use MSFS2024 FSUIPC?
|
|
||||||
if (!this->getSimulatorPluginInfo().getSimulatorInfo().isMSFS() &&
|
if (!this->getSimulatorPluginInfo().getSimulatorInfo().isMSFS() &&
|
||||||
!this->getSimulatorPluginInfo().getSimulatorInfo().isMSFS2024())
|
!this->getSimulatorPluginInfo().getSimulatorInfo().isMSFS2024())
|
||||||
{
|
{
|
||||||
@@ -542,15 +541,6 @@ namespace swift::simplugin::fsxcommon
|
|||||||
SIMCONNECT_CLIENT_DATA_REQUEST_FLAG_CHANGED),
|
SIMCONNECT_CLIENT_DATA_REQUEST_FLAG_CHANGED),
|
||||||
"Cannot request client data", Q_FUNC_INFO, "SimConnect_RequestClientData");
|
"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; }
|
if (isFailure(hr)) { return; }
|
||||||
this->emitSimulatorCombinedStatus(); // force sending status
|
this->emitSimulatorCombinedStatus(); // force sending status
|
||||||
@@ -693,6 +683,12 @@ namespace swift::simplugin::fsxcommon
|
|||||||
CAltitude(simulatorOwnAircraft.altitudeFt, CAltitude::MeanSeaLevel, CLengthUnit::ft()));
|
CAltitude(simulatorOwnAircraft.altitudeFt, CAltitude::MeanSeaLevel, CLengthUnit::ft()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CSimulatorFsxCommon::setTransponderMode(
|
||||||
|
swift::misc::aviation::CTransponder &transponder,
|
||||||
|
const swift::simplugin::fsxcommon::DataDefinitionOwnAircraft &simulatorOwnAircraft)
|
||||||
|
{ /* Do not modify the transponder mode by default. Only MSFS allows to read it from SimVars */ }
|
||||||
|
|
||||||
|
|
||||||
void CSimulatorFsxCommon::updateOwnAircraftFromSimulator(const DataDefinitionOwnAircraft &simulatorOwnAircraft)
|
void CSimulatorFsxCommon::updateOwnAircraftFromSimulator(const DataDefinitionOwnAircraft &simulatorOwnAircraft)
|
||||||
{
|
{
|
||||||
const qint64 ts = QDateTime::currentMSecsSinceEpoch();
|
const qint64 ts = QDateTime::currentMSecsSinceEpoch();
|
||||||
@@ -832,12 +828,13 @@ namespace swift::simplugin::fsxcommon
|
|||||||
|
|
||||||
CTransponder transponder(myAircraft.getTransponder());
|
CTransponder transponder(myAircraft.getTransponder());
|
||||||
transponder.setTransponderCode(qRound(simulatorOwnAircraft.transponderCode));
|
transponder.setTransponderCode(qRound(simulatorOwnAircraft.transponderCode));
|
||||||
|
setTransponderMode(transponder, simulatorOwnAircraft);
|
||||||
m_simTransponder = transponder;
|
m_simTransponder = transponder;
|
||||||
|
|
||||||
// if the simulator ever sends SELCAL, add it here.
|
// if the simulator ever sends SELCAL, add it here.
|
||||||
// m_selcal SELCAL sync.would go 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)
|
if (changedCom1 || changedCom2 || changedXpr)
|
||||||
{
|
{
|
||||||
@@ -1009,17 +1006,6 @@ namespace swift::simplugin::fsxcommon
|
|||||||
this->updateCockpit(myAircraft.getCom1System(), myAircraft.getCom2System(), myXpdr, this->identifier());
|
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)
|
bool CSimulatorFsxCommon::simulatorReportedObjectAdded(DWORD objectId)
|
||||||
{
|
{
|
||||||
if (this->isShuttingDownOrDisconnected()) { return true; } // pretend everything is fine
|
if (this->isShuttingDownOrDisconnected()) { return true; } // pretend everything is fine
|
||||||
|
|||||||
@@ -503,6 +503,11 @@ namespace swift::simplugin::fsxcommon
|
|||||||
setTrueAltitude(swift::misc::aviation::CAircraftSituation &aircraftSituation,
|
setTrueAltitude(swift::misc::aviation::CAircraftSituation &aircraftSituation,
|
||||||
const swift::simplugin::fsxcommon::DataDefinitionOwnAircraft &simulatorOwnAircraft);
|
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);
|
||||||
|
|
||||||
//! Called when data about our own aircraft are received
|
//! Called when data about our own aircraft are received
|
||||||
void updateOwnAircraftFromSimulator(const DataDefinitionOwnAircraft &simulatorOwnAircraft);
|
void updateOwnAircraftFromSimulator(const DataDefinitionOwnAircraft &simulatorOwnAircraft);
|
||||||
|
|
||||||
@@ -514,9 +519,6 @@ namespace swift::simplugin::fsxcommon
|
|||||||
//! \threadsafe
|
//! \threadsafe
|
||||||
void updateTransponderMode(const misc::aviation::CTransponder::TransponderMode xpdrMode);
|
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
|
//! An AI aircraft was added in the simulator
|
||||||
bool simulatorReportedObjectAdded(DWORD objectId);
|
bool simulatorReportedObjectAdded(DWORD objectId);
|
||||||
|
|
||||||
|
|||||||
@@ -245,7 +245,7 @@ namespace swift::simplugin::fsxcommon
|
|||||||
{
|
{
|
||||||
case CSimConnectDefinitions::RequestOwnAircraft:
|
case CSimConnectDefinitions::RequestOwnAircraft:
|
||||||
{
|
{
|
||||||
static_assert(sizeof(DataDefinitionOwnAircraft) == 45 * sizeof(double),
|
static_assert(sizeof(DataDefinitionOwnAircraft) == 47 * sizeof(double),
|
||||||
"DataDefinitionOwnAircraft has an incorrect size.");
|
"DataDefinitionOwnAircraft has an incorrect size.");
|
||||||
const DataDefinitionOwnAircraft *ownAircaft =
|
const DataDefinitionOwnAircraft *ownAircaft =
|
||||||
reinterpret_cast<const DataDefinitionOwnAircraft *>(&pObjData->dwData);
|
reinterpret_cast<const DataDefinitionOwnAircraft *>(&pObjData->dwData);
|
||||||
@@ -260,13 +260,6 @@ namespace swift::simplugin::fsxcommon
|
|||||||
simulatorFsxP3D->reverseLookupAndUpdateOwnAircraftModel(model);
|
simulatorFsxP3D->reverseLookupAndUpdateOwnAircraftModel(model);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case CSimConnectDefinitions::RequestMSFSTransponder:
|
|
||||||
{
|
|
||||||
const DataDefinitionMSFSTransponderMode *transponderMode =
|
|
||||||
reinterpret_cast<const DataDefinitionMSFSTransponderMode *>(&pObjData->dwData);
|
|
||||||
simulatorFsxP3D->updateMSFSTransponderMode(*transponderMode);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
const DWORD objectId = pObjData->dwObjectID;
|
const DWORD objectId = pObjData->dwObjectID;
|
||||||
|
|||||||
@@ -41,6 +41,20 @@ namespace swift::simplugin::msfs
|
|||||||
CLengthUnit::ft() };
|
CLengthUnit::ft() };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CSimulatorMsFs::setTransponderMode(
|
||||||
|
swift::misc::aviation::CTransponder& transponder,
|
||||||
|
const swift::simplugin::fsxcommon::DataDefinitionOwnAircraft& simulatorOwnAircraft)
|
||||||
|
{
|
||||||
|
auto mode = CTransponder::StateIdent;
|
||||||
|
if (!simulatorOwnAircraft.ident)
|
||||||
|
{
|
||||||
|
qRound(simulatorOwnAircraft.transponderMode) >= 3 ? mode = CTransponder::ModeC :
|
||||||
|
mode = CTransponder::StateStandby;
|
||||||
|
}
|
||||||
|
transponder.setTransponderMode(mode);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void CSimulatorMsFsListener::startImpl()
|
void CSimulatorMsFsListener::startImpl()
|
||||||
{
|
{
|
||||||
if (!loadAndResolveMSFSimConnect()) { return; }
|
if (!loadAndResolveMSFSimConnect()) { return; }
|
||||||
|
|||||||
@@ -30,6 +30,11 @@ namespace swift::simplugin::msfs
|
|||||||
virtual void
|
virtual void
|
||||||
setTrueAltitude(swift::misc::aviation::CAircraftSituation &aircraftSituation,
|
setTrueAltitude(swift::misc::aviation::CAircraftSituation &aircraftSituation,
|
||||||
const swift::simplugin::fsxcommon::DataDefinitionOwnAircraft &simulatorOwnAircraft) override;
|
const swift::simplugin::fsxcommon::DataDefinitionOwnAircraft &simulatorOwnAircraft) override;
|
||||||
|
|
||||||
|
void
|
||||||
|
setTransponderMode(swift::misc::aviation::CTransponder &transponder,
|
||||||
|
const swift::simplugin::fsxcommon::DataDefinitionOwnAircraft &simulatorOwnAircraft) override;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
//! Listener for MSFS
|
//! Listener for MSFS
|
||||||
|
|||||||
Reference in New Issue
Block a user