mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-05-03 16:25:54 +08:00
New features for Simulator, refs #257
* Allow to display text alerts for ** Status messages ** Private chat messages * Updates from GUI cockpit to Simulator * A bit refactoring, e.g. event names according our standards
This commit is contained in:
@@ -20,7 +20,6 @@ namespace BlackSimPlugin
|
|||||||
hr = initOwnAircraft(hSimConnect);
|
hr = initOwnAircraft(hSimConnect);
|
||||||
hr = initRemoteAircraftSituation(hSimConnect);
|
hr = initRemoteAircraftSituation(hSimConnect);
|
||||||
hr = initGearHandlePosition(hSimConnect);
|
hr = initGearHandlePosition(hSimConnect);
|
||||||
hr = initSetCockpitEvents(hSimConnect);
|
|
||||||
return hr;
|
return hr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,16 +55,5 @@ namespace BlackSimPlugin
|
|||||||
hr = SimConnect_AddToDataDefinition(hSimConnect, CSimConnectDataDefinition::DataDefinitionGearHandlePosition, "GEAR HANDLE POSITION", "BOOL", SIMCONNECT_DATATYPE_INT32);
|
hr = SimConnect_AddToDataDefinition(hSimConnect, CSimConnectDataDefinition::DataDefinitionGearHandlePosition, "GEAR HANDLE POSITION", "BOOL", SIMCONNECT_DATATYPE_INT32);
|
||||||
return hr;
|
return hr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
HRESULT CSimConnectDataDefinition::initSetCockpitEvents(const HANDLE hSimConnect) {
|
|
||||||
HRESULT hr = S_OK;
|
|
||||||
hr = SimConnect_MapClientEventToSimEvent(hSimConnect, EventSetCom1Active, "COM_RADIO_SET");
|
|
||||||
hr = SimConnect_MapClientEventToSimEvent(hSimConnect, EventSetCom1Standby, "COM_STBY_RADIO_SET");
|
|
||||||
hr = SimConnect_MapClientEventToSimEvent(hSimConnect, EventSetCom2Active, "COM2_RADIO_SET");
|
|
||||||
hr = SimConnect_MapClientEventToSimEvent(hSimConnect, EventSetCom2Standby, "COM2_STBY_RADIO_SET");
|
|
||||||
hr = SimConnect_MapClientEventToSimEvent(hSimConnect, EventSetTransponderCode, "XPNDR_SET");
|
|
||||||
return hr;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ namespace BlackSimPlugin
|
|||||||
double pitch; //!< Pitch
|
double pitch; //!< Pitch
|
||||||
double bank; //!< Bank
|
double bank; //!< Bank
|
||||||
double velocity; //!< Ground velocity
|
double velocity; //!< Ground velocity
|
||||||
double simOnGround; //!< Is sim on ground?
|
double simOnGround; //!< Is aircraft on ground?
|
||||||
double transponderCode; //!< Transponder Code
|
double transponderCode; //!< Transponder Code
|
||||||
double com1ActiveMHz; //!< COM1 active frequency
|
double com1ActiveMHz; //!< COM1 active frequency
|
||||||
double com2ActiveMHz; //!< COM2 active frequency
|
double com2ActiveMHz; //!< COM2 active frequency
|
||||||
@@ -63,15 +63,6 @@ namespace BlackSimPlugin
|
|||||||
DataDefinitionGearHandlePosition
|
DataDefinitionGearHandlePosition
|
||||||
};
|
};
|
||||||
|
|
||||||
//! SimConnect Event IDs
|
|
||||||
enum Events {
|
|
||||||
EventSetCom1Active = 100, // not overlapping with DataDefinition
|
|
||||||
EventSetCom2Active,
|
|
||||||
EventSetCom1Standby,
|
|
||||||
EventSetCom2Standby,
|
|
||||||
EventSetTransponderCode
|
|
||||||
};
|
|
||||||
|
|
||||||
//! SimConnect request IDs
|
//! SimConnect request IDs
|
||||||
enum Requests
|
enum Requests
|
||||||
{
|
{
|
||||||
@@ -79,7 +70,6 @@ namespace BlackSimPlugin
|
|||||||
RequestRemoveAircraft = 2000
|
RequestRemoveAircraft = 2000
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
//! Constructor
|
//! Constructor
|
||||||
CSimConnectDataDefinition();
|
CSimConnectDataDefinition();
|
||||||
|
|
||||||
@@ -94,10 +84,6 @@ namespace BlackSimPlugin
|
|||||||
|
|
||||||
//! Initialize data definition for remote aircraft configuration
|
//! Initialize data definition for remote aircraft configuration
|
||||||
static HRESULT initGearHandlePosition(const HANDLE hSimConnect);
|
static HRESULT initGearHandlePosition(const HANDLE hSimConnect);
|
||||||
|
|
||||||
//! Initialize events required setting cockpit values
|
|
||||||
static HRESULT initSetCockpitEvents(const HANDLE hSimConnect);
|
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@
|
|||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QtConcurrent>
|
#include <QtConcurrent>
|
||||||
|
|
||||||
|
using namespace BlackMisc;
|
||||||
using namespace BlackMisc::Aviation;
|
using namespace BlackMisc::Aviation;
|
||||||
using namespace BlackMisc::PhysicalQuantities;
|
using namespace BlackMisc::PhysicalQuantities;
|
||||||
using namespace BlackMisc::Geo;
|
using namespace BlackMisc::Geo;
|
||||||
@@ -42,7 +43,8 @@ namespace BlackSimPlugin
|
|||||||
m_hSimConnect(nullptr),
|
m_hSimConnect(nullptr),
|
||||||
m_nextObjID(1),
|
m_nextObjID(1),
|
||||||
m_simulatorInfo(CSimulatorInfo::FSX()),
|
m_simulatorInfo(CSimulatorInfo::FSX()),
|
||||||
m_simconnectTimerId(-1)
|
m_simconnectTimerId(-1),
|
||||||
|
m_skipCockpitUpdateCycles(0)
|
||||||
{
|
{
|
||||||
CFsxSimulatorSetup setup;
|
CFsxSimulatorSetup setup;
|
||||||
setup.init(); // this fetches important setting on local side
|
setup.init(); // this fetches important setting on local side
|
||||||
@@ -69,7 +71,7 @@ namespace BlackSimPlugin
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
initSystemEvents();
|
initEvents();
|
||||||
initDataDefinitions();
|
initDataDefinitions();
|
||||||
m_simconnectTimerId = startTimer(10);
|
m_simconnectTimerId = startTimer(10);
|
||||||
m_isConnected = true;
|
m_isConnected = true;
|
||||||
@@ -175,7 +177,7 @@ namespace BlackSimPlugin
|
|||||||
return this->m_simulatorInfo;
|
return this->m_simulatorInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CSimulatorFsx::updateOwnCockpit(const CAircraft &ownAircraft)
|
bool CSimulatorFsx::updateOwnSimulatorCockpit(const CAircraft &ownAircraft)
|
||||||
{
|
{
|
||||||
CComSystem newCom1 = ownAircraft.getCom1System();
|
CComSystem newCom1 = ownAircraft.getCom1System();
|
||||||
CComSystem newCom2 = ownAircraft.getCom2System();
|
CComSystem newCom2 = ownAircraft.getCom2System();
|
||||||
@@ -185,10 +187,10 @@ namespace BlackSimPlugin
|
|||||||
if (newCom1 != this->m_ownAircraft.getCom1System())
|
if (newCom1 != this->m_ownAircraft.getCom1System())
|
||||||
{
|
{
|
||||||
if (newCom1.getFrequencyActive() != this->m_ownAircraft.getCom1System().getFrequencyActive())
|
if (newCom1.getFrequencyActive() != this->m_ownAircraft.getCom1System().getFrequencyActive())
|
||||||
SimConnect_TransmitClientEvent(m_hSimConnect, 0, CSimConnectDataDefinition::EventSetCom1Active,
|
SimConnect_TransmitClientEvent(m_hSimConnect, 0, EventSetCom1Active,
|
||||||
CBcdConversions::comFrequencyToBcdHz(newCom1.getFrequencyActive()), SIMCONNECT_GROUP_PRIORITY_HIGHEST, SIMCONNECT_EVENT_FLAG_GROUPID_IS_PRIORITY);
|
CBcdConversions::comFrequencyToBcdHz(newCom1.getFrequencyActive()), SIMCONNECT_GROUP_PRIORITY_HIGHEST, SIMCONNECT_EVENT_FLAG_GROUPID_IS_PRIORITY);
|
||||||
if (newCom1.getFrequencyStandby() != this->m_ownAircraft.getCom1System().getFrequencyStandby())
|
if (newCom1.getFrequencyStandby() != this->m_ownAircraft.getCom1System().getFrequencyStandby())
|
||||||
SimConnect_TransmitClientEvent(m_hSimConnect, 0, CSimConnectDataDefinition::EventSetCom1Standby,
|
SimConnect_TransmitClientEvent(m_hSimConnect, 0, EventSetCom1Standby,
|
||||||
CBcdConversions::comFrequencyToBcdHz(newCom1.getFrequencyStandby()), SIMCONNECT_GROUP_PRIORITY_HIGHEST, SIMCONNECT_EVENT_FLAG_GROUPID_IS_PRIORITY);
|
CBcdConversions::comFrequencyToBcdHz(newCom1.getFrequencyStandby()), SIMCONNECT_GROUP_PRIORITY_HIGHEST, SIMCONNECT_EVENT_FLAG_GROUPID_IS_PRIORITY);
|
||||||
|
|
||||||
this->m_ownAircraft.setCom1System(newCom1);
|
this->m_ownAircraft.setCom1System(newCom1);
|
||||||
@@ -198,13 +200,13 @@ namespace BlackSimPlugin
|
|||||||
if (newCom2 != this->m_ownAircraft.getCom2System())
|
if (newCom2 != this->m_ownAircraft.getCom2System())
|
||||||
{
|
{
|
||||||
if (newCom2.getFrequencyActive() != this->m_ownAircraft.getCom2System().getFrequencyActive())
|
if (newCom2.getFrequencyActive() != this->m_ownAircraft.getCom2System().getFrequencyActive())
|
||||||
SimConnect_TransmitClientEvent(m_hSimConnect, 0, CSimConnectDataDefinition::EventSetCom2Active,
|
SimConnect_TransmitClientEvent(m_hSimConnect, 0, EventSetCom2Active,
|
||||||
CBcdConversions::comFrequencyToBcdHz(newCom2.getFrequencyActive()), SIMCONNECT_GROUP_PRIORITY_HIGHEST, SIMCONNECT_EVENT_FLAG_GROUPID_IS_PRIORITY);
|
CBcdConversions::comFrequencyToBcdHz(newCom2.getFrequencyActive()), SIMCONNECT_GROUP_PRIORITY_HIGHEST, SIMCONNECT_EVENT_FLAG_GROUPID_IS_PRIORITY);
|
||||||
if (newCom2.getFrequencyStandby() != this->m_ownAircraft.getCom2System().getFrequencyStandby())
|
if (newCom2.getFrequencyStandby() != this->m_ownAircraft.getCom2System().getFrequencyStandby())
|
||||||
SimConnect_TransmitClientEvent(m_hSimConnect, 0, CSimConnectDataDefinition::EventSetCom2Standby,
|
SimConnect_TransmitClientEvent(m_hSimConnect, 0, EventSetCom2Standby,
|
||||||
CBcdConversions::comFrequencyToBcdHz(newCom2.getFrequencyStandby()), SIMCONNECT_GROUP_PRIORITY_HIGHEST, SIMCONNECT_EVENT_FLAG_GROUPID_IS_PRIORITY);
|
CBcdConversions::comFrequencyToBcdHz(newCom2.getFrequencyStandby()), SIMCONNECT_GROUP_PRIORITY_HIGHEST, SIMCONNECT_EVENT_FLAG_GROUPID_IS_PRIORITY);
|
||||||
|
|
||||||
this->m_ownAircraft.setCom2System(newCom1);
|
this->m_ownAircraft.setCom2System(newCom2);
|
||||||
changed = true;
|
changed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -212,22 +214,61 @@ namespace BlackSimPlugin
|
|||||||
{
|
{
|
||||||
if (newTransponder.getTransponderCode() != this->m_ownAircraft.getTransponder().getTransponderCode())
|
if (newTransponder.getTransponderCode() != this->m_ownAircraft.getTransponder().getTransponderCode())
|
||||||
{
|
{
|
||||||
SimConnect_TransmitClientEvent(m_hSimConnect, 0, CSimConnectDataDefinition::EventSetTransponderCode,
|
SimConnect_TransmitClientEvent(m_hSimConnect, 0, EventSetTransponderCode,
|
||||||
CBcdConversions::transponderCodeToBcd(newTransponder), SIMCONNECT_GROUP_PRIORITY_HIGHEST, SIMCONNECT_EVENT_FLAG_GROUPID_IS_PRIORITY);
|
CBcdConversions::transponderCodeToBcd(newTransponder), SIMCONNECT_GROUP_PRIORITY_HIGHEST, SIMCONNECT_EVENT_FLAG_GROUPID_IS_PRIORITY);
|
||||||
changed = true;
|
changed = true;
|
||||||
}
|
}
|
||||||
this->m_ownAircraft.setTransponder(newTransponder);
|
this->m_ownAircraft.setTransponder(newTransponder);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// avoid changes of cockpit back to old values due to an outdated read back value
|
||||||
|
if (changed) m_skipCockpitUpdateCycles = SkipUpdateCyclesForCockpit;
|
||||||
|
|
||||||
|
// bye
|
||||||
return changed;
|
return changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CSimulatorFsx::displayStatusMessage(const BlackMisc::CStatusMessage &message) const
|
||||||
|
{
|
||||||
|
QByteArray m = message.getMessage().toLocal8Bit().constData();
|
||||||
|
m.append('\0');
|
||||||
|
|
||||||
|
SIMCONNECT_TEXT_TYPE type = SIMCONNECT_TEXT_TYPE_PRINT_BLACK;
|
||||||
|
switch (message.getSeverity())
|
||||||
|
{
|
||||||
|
case CStatusMessage::SeverityInfo:
|
||||||
|
type = SIMCONNECT_TEXT_TYPE_PRINT_GREEN;
|
||||||
|
break;
|
||||||
|
case CStatusMessage::SeverityWarning:
|
||||||
|
type = SIMCONNECT_TEXT_TYPE_PRINT_YELLOW;
|
||||||
|
break;
|
||||||
|
case CStatusMessage::SeverityError:
|
||||||
|
type = SIMCONNECT_TEXT_TYPE_PRINT_RED;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
HRESULT hr = SimConnect_Text(
|
||||||
|
m_hSimConnect, type, 7.5, EventTextMessage, m.size(),
|
||||||
|
m.data()
|
||||||
|
);
|
||||||
|
Q_UNUSED(hr);
|
||||||
|
}
|
||||||
|
|
||||||
void CALLBACK CSimulatorFsx::SimConnectProc(SIMCONNECT_RECV *pData, DWORD /* cbData */, void *pContext)
|
void CALLBACK CSimulatorFsx::SimConnectProc(SIMCONNECT_RECV *pData, DWORD /* cbData */, void *pContext)
|
||||||
{
|
{
|
||||||
CSimulatorFsx *simulatorFsx = static_cast<CSimulatorFsx *>(pContext);
|
CSimulatorFsx *simulatorFsx = static_cast<CSimulatorFsx *>(pContext);
|
||||||
|
|
||||||
switch (pData->dwID)
|
switch (pData->dwID)
|
||||||
{
|
{
|
||||||
|
case SIMCONNECT_RECV_ID_OPEN:
|
||||||
|
{
|
||||||
|
SIMCONNECT_RECV_OPEN *event = (SIMCONNECT_RECV_OPEN *)pData;
|
||||||
|
simulatorFsx->simulatorDetails = QString("Open: AppName=\"%1\" AppVersion=%2.%3.%4.%5 SimConnectVersion=%6.%7.%8.%9")
|
||||||
|
.arg(event->szApplicationName)
|
||||||
|
.arg(event->dwApplicationVersionMajor).arg(event->dwApplicationVersionMinor).arg(event->dwApplicationBuildMajor).arg(event->dwApplicationBuildMinor)
|
||||||
|
.arg(event->dwSimConnectVersionMajor).arg(event->dwSimConnectVersionMinor).arg(event->dwSimConnectBuildMajor).arg(event->dwSimConnectBuildMinor);
|
||||||
|
simulatorFsx->displayStatusMessage(CStatusMessage::getInfoMessage(CProject::systemNameAndVersion()));
|
||||||
|
break;
|
||||||
|
}
|
||||||
case SIMCONNECT_RECV_ID_EXCEPTION:
|
case SIMCONNECT_RECV_ID_EXCEPTION:
|
||||||
{
|
{
|
||||||
SIMCONNECT_RECV_EXCEPTION *event = (SIMCONNECT_RECV_EXCEPTION *)pData;
|
SIMCONNECT_RECV_EXCEPTION *event = (SIMCONNECT_RECV_EXCEPTION *)pData;
|
||||||
@@ -236,7 +277,7 @@ namespace BlackSimPlugin
|
|||||||
}
|
}
|
||||||
case SIMCONNECT_RECV_ID_QUIT:
|
case SIMCONNECT_RECV_ID_QUIT:
|
||||||
{
|
{
|
||||||
simulatorFsx->onSimExit();
|
simulatorFsx->onSimExit(); // TODO: What is the difference to sim stopped?
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case SIMCONNECT_RECV_ID_EVENT:
|
case SIMCONNECT_RECV_ID_EVENT:
|
||||||
@@ -245,7 +286,7 @@ namespace BlackSimPlugin
|
|||||||
|
|
||||||
switch (event->uEventID)
|
switch (event->uEventID)
|
||||||
{
|
{
|
||||||
case EVENT_SIM_STATUS:
|
case EventSimStatus:
|
||||||
if (event->dwData)
|
if (event->dwData)
|
||||||
{
|
{
|
||||||
simulatorFsx->onSimRunning();
|
simulatorFsx->onSimRunning();
|
||||||
@@ -261,10 +302,10 @@ namespace BlackSimPlugin
|
|||||||
case SIMCONNECT_RECV_ID_EVENT_OBJECT_ADDREMOVE:
|
case SIMCONNECT_RECV_ID_EVENT_OBJECT_ADDREMOVE:
|
||||||
{
|
{
|
||||||
SIMCONNECT_RECV_EVENT_OBJECT_ADDREMOVE *event = static_cast<SIMCONNECT_RECV_EVENT_OBJECT_ADDREMOVE *>(pData);
|
SIMCONNECT_RECV_EVENT_OBJECT_ADDREMOVE *event = static_cast<SIMCONNECT_RECV_EVENT_OBJECT_ADDREMOVE *>(pData);
|
||||||
if (event->uEventID == EVENT_OBJECT_ADDED)
|
if (event->uEventID == EventObjectAdded)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
else if (event->uEventID == EVENT_OBJECT_REMOVED)
|
else if (event->uEventID == EventObjectRemoved)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -274,7 +315,7 @@ namespace BlackSimPlugin
|
|||||||
SIMCONNECT_RECV_EVENT_FRAME *event = (SIMCONNECT_RECV_EVENT_FRAME *) pData;
|
SIMCONNECT_RECV_EVENT_FRAME *event = (SIMCONNECT_RECV_EVENT_FRAME *) pData;
|
||||||
switch (event->uEventID)
|
switch (event->uEventID)
|
||||||
{
|
{
|
||||||
case EVENT_FRAME:
|
case EventFrame:
|
||||||
simulatorFsx->onSimFrame();
|
simulatorFsx->onSimFrame();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -304,15 +345,19 @@ namespace BlackSimPlugin
|
|||||||
|
|
||||||
void CSimulatorFsx::onSimRunning()
|
void CSimulatorFsx::onSimRunning()
|
||||||
{
|
{
|
||||||
|
if (m_simRunning) return;
|
||||||
m_simRunning = true;
|
m_simRunning = true;
|
||||||
SimConnect_RequestDataOnSimObject(m_hSimConnect, CSimConnectDataDefinition::RequestOwnAircraft,
|
SimConnect_RequestDataOnSimObject(m_hSimConnect, CSimConnectDataDefinition::RequestOwnAircraft,
|
||||||
CSimConnectDataDefinition::DataOwnAircraft,
|
CSimConnectDataDefinition::DataOwnAircraft,
|
||||||
SIMCONNECT_OBJECT_ID_USER, SIMCONNECT_PERIOD_VISUAL_FRAME);
|
SIMCONNECT_OBJECT_ID_USER, SIMCONNECT_PERIOD_VISUAL_FRAME);
|
||||||
|
emit simulatorStarted();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSimulatorFsx::onSimStopped()
|
void CSimulatorFsx::onSimStopped()
|
||||||
{
|
{
|
||||||
|
if (!m_simRunning) return;
|
||||||
m_simRunning = false;
|
m_simRunning = false;
|
||||||
|
emit simulatorStopped();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSimulatorFsx::onSimFrame()
|
void CSimulatorFsx::onSimFrame()
|
||||||
@@ -322,37 +367,46 @@ namespace BlackSimPlugin
|
|||||||
|
|
||||||
void CSimulatorFsx::onSimExit()
|
void CSimulatorFsx::onSimExit()
|
||||||
{
|
{
|
||||||
|
this->onSimStopped();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSimulatorFsx::updateOwnAircraftFromSim(DataDefinitionOwnAircraft aircraft)
|
void CSimulatorFsx::updateOwnAircraftFromSim(DataDefinitionOwnAircraft simulatorOwnAircraft)
|
||||||
{
|
{
|
||||||
BlackMisc::Geo::CCoordinateGeodetic position;
|
BlackMisc::Geo::CCoordinateGeodetic position;
|
||||||
position.setLatitude(CLatitude(aircraft.latitude, CAngleUnit::deg()));
|
position.setLatitude(CLatitude(simulatorOwnAircraft.latitude, CAngleUnit::deg()));
|
||||||
position.setLongitude(CLongitude(aircraft.longitude, CAngleUnit::deg()));
|
position.setLongitude(CLongitude(simulatorOwnAircraft.longitude, CAngleUnit::deg()));
|
||||||
|
|
||||||
BlackMisc::Aviation::CAircraftSituation aircraftSituation;
|
BlackMisc::Aviation::CAircraftSituation aircraftSituation;
|
||||||
aircraftSituation.setPosition(position);
|
aircraftSituation.setPosition(position);
|
||||||
aircraftSituation.setPitch(CAngle(aircraft.pitch, CAngleUnit::deg()));
|
aircraftSituation.setPitch(CAngle(simulatorOwnAircraft.pitch, CAngleUnit::deg()));
|
||||||
aircraftSituation.setBank(CAngle(aircraft.bank, CAngleUnit::deg()));
|
aircraftSituation.setBank(CAngle(simulatorOwnAircraft.bank, CAngleUnit::deg()));
|
||||||
aircraftSituation.setHeading(CHeading(aircraft.trueHeading, CHeading::True, CAngleUnit::deg()));
|
aircraftSituation.setHeading(CHeading(simulatorOwnAircraft.trueHeading, CHeading::True, CAngleUnit::deg()));
|
||||||
aircraftSituation.setGroundspeed(CSpeed(aircraft.velocity, CSpeedUnit::kts()));
|
aircraftSituation.setGroundspeed(CSpeed(simulatorOwnAircraft.velocity, CSpeedUnit::kts()));
|
||||||
aircraftSituation.setAltitude(CAltitude(aircraft.altitude, CAltitude::MeanSeaLevel, CLengthUnit::ft()));
|
aircraftSituation.setAltitude(CAltitude(simulatorOwnAircraft.altitude, CAltitude::MeanSeaLevel, CLengthUnit::ft()));
|
||||||
|
|
||||||
CComSystem com1;
|
|
||||||
com1.setFrequencyActive(CFrequency(aircraft.com1ActiveMHz, CFrequencyUnit::MHz()));
|
|
||||||
com1.setFrequencyStandby(CFrequency(aircraft.com1StandbyMHz, CFrequencyUnit::MHz()));
|
|
||||||
|
|
||||||
CComSystem com2;
|
|
||||||
com2.setFrequencyActive(CFrequency(aircraft.com2ActiveMHz, CFrequencyUnit::MHz()));
|
|
||||||
com2.setFrequencyStandby(CFrequency(aircraft.com2StandbyMHz, CFrequencyUnit::MHz()));
|
|
||||||
|
|
||||||
CTransponder transponder("Transponder", aircraft.transponderCode, CTransponder::ModeS);
|
|
||||||
|
|
||||||
m_ownAircraft.setSituation(aircraftSituation);
|
m_ownAircraft.setSituation(aircraftSituation);
|
||||||
m_ownAircraft.setCom1System(com1);
|
|
||||||
m_ownAircraft.setCom2System(com2);
|
CComSystem com1 = m_ownAircraft.getCom1System(); // set defaults
|
||||||
m_ownAircraft.setTransponder(transponder);
|
CComSystem com2 = m_ownAircraft.getCom2System();
|
||||||
|
CTransponder transponder = m_ownAircraft.getTransponder();
|
||||||
|
|
||||||
|
// When I change cockpit values in the sim (from GUI to simulator, not originating from simulator)
|
||||||
|
// it takes a little while before these values are set in the simulator.
|
||||||
|
// To avoid jitters, I wait some update cylces to stabilize the values
|
||||||
|
if (m_skipCockpitUpdateCycles < 1)
|
||||||
|
{
|
||||||
|
com1.setFrequencyActive(CFrequency(simulatorOwnAircraft.com1ActiveMHz, CFrequencyUnit::MHz()));
|
||||||
|
com1.setFrequencyStandby(CFrequency(simulatorOwnAircraft.com1StandbyMHz, CFrequencyUnit::MHz()));
|
||||||
|
m_ownAircraft.setCom1System(com1);
|
||||||
|
|
||||||
|
com2.setFrequencyActive(CFrequency(simulatorOwnAircraft.com2ActiveMHz, CFrequencyUnit::MHz()));
|
||||||
|
com2.setFrequencyStandby(CFrequency(simulatorOwnAircraft.com2StandbyMHz, CFrequencyUnit::MHz()));
|
||||||
|
m_ownAircraft.setCom2System(com2);
|
||||||
|
|
||||||
|
transponder.setTransponderCode(simulatorOwnAircraft.transponderCode);
|
||||||
|
m_ownAircraft.setTransponder(transponder);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
--m_skipCockpitUpdateCycles;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSimulatorFsx::setSimconnectObjectID(DWORD requestID, DWORD objectID)
|
void CSimulatorFsx::setSimconnectObjectID(DWORD requestID, DWORD objectID)
|
||||||
@@ -372,11 +426,11 @@ namespace BlackSimPlugin
|
|||||||
|
|
||||||
(*it).setObjectId(objectID);
|
(*it).setObjectId(objectID);
|
||||||
SimConnect_AIReleaseControl(m_hSimConnect, objectID, requestID);
|
SimConnect_AIReleaseControl(m_hSimConnect, objectID, requestID);
|
||||||
SimConnect_TransmitClientEvent(m_hSimConnect, objectID, EVENT_FREEZELAT, 1,
|
SimConnect_TransmitClientEvent(m_hSimConnect, objectID, EventFreezeLat, 1,
|
||||||
SIMCONNECT_GROUP_PRIORITY_HIGHEST, SIMCONNECT_EVENT_FLAG_GROUPID_IS_PRIORITY);
|
SIMCONNECT_GROUP_PRIORITY_HIGHEST, SIMCONNECT_EVENT_FLAG_GROUPID_IS_PRIORITY);
|
||||||
SimConnect_TransmitClientEvent(m_hSimConnect, objectID, EVENT_FREEZEALT, 1,
|
SimConnect_TransmitClientEvent(m_hSimConnect, objectID, EventFreezeAlt, 1,
|
||||||
SIMCONNECT_GROUP_PRIORITY_HIGHEST, SIMCONNECT_EVENT_FLAG_GROUPID_IS_PRIORITY);
|
SIMCONNECT_GROUP_PRIORITY_HIGHEST, SIMCONNECT_EVENT_FLAG_GROUPID_IS_PRIORITY);
|
||||||
SimConnect_TransmitClientEvent(m_hSimConnect, objectID, EVENT_FREEZEATT, 1,
|
SimConnect_TransmitClientEvent(m_hSimConnect, objectID, EventFreezeAtt, 1,
|
||||||
SIMCONNECT_GROUP_PRIORITY_HIGHEST, SIMCONNECT_EVENT_FLAG_GROUPID_IS_PRIORITY);
|
SIMCONNECT_GROUP_PRIORITY_HIGHEST, SIMCONNECT_EVENT_FLAG_GROUPID_IS_PRIORITY);
|
||||||
|
|
||||||
DataDefinitionGearHandlePosition gearHandle;
|
DataDefinitionGearHandlePosition gearHandle;
|
||||||
@@ -399,7 +453,7 @@ namespace BlackSimPlugin
|
|||||||
{
|
{
|
||||||
if (m_watcherConnect.result())
|
if (m_watcherConnect.result())
|
||||||
{
|
{
|
||||||
initSystemEvents();
|
initEvents();
|
||||||
initDataDefinitions();
|
initDataDefinitions();
|
||||||
m_simconnectTimerId = startTimer(50);
|
m_simconnectTimerId = startTimer(50);
|
||||||
m_isConnected = true;
|
m_isConnected = true;
|
||||||
@@ -416,18 +470,24 @@ namespace BlackSimPlugin
|
|||||||
m_simConnectObjects.remove(simObject.getCallsign());
|
m_simConnectObjects.remove(simObject.getCallsign());
|
||||||
}
|
}
|
||||||
|
|
||||||
HRESULT CSimulatorFsx::initSystemEvents()
|
HRESULT CSimulatorFsx::initEvents()
|
||||||
{
|
{
|
||||||
HRESULT hr = S_OK;
|
HRESULT hr = S_OK;
|
||||||
// System events
|
// System events
|
||||||
hr += SimConnect_SubscribeToSystemEvent(m_hSimConnect, EVENT_SIM_STATUS, "Sim");
|
hr += SimConnect_SubscribeToSystemEvent(m_hSimConnect, EventSimStatus, "Sim");
|
||||||
hr += SimConnect_SubscribeToSystemEvent(m_hSimConnect, EVENT_OBJECT_ADDED, "ObjectAdded");
|
hr += SimConnect_SubscribeToSystemEvent(m_hSimConnect, EventObjectAdded, "ObjectAdded");
|
||||||
hr += SimConnect_SubscribeToSystemEvent(m_hSimConnect, EVENT_OBJECT_REMOVED, "ObjectRemoved");
|
hr += SimConnect_SubscribeToSystemEvent(m_hSimConnect, EventObjectRemoved, "ObjectRemoved");
|
||||||
hr += SimConnect_SubscribeToSystemEvent(m_hSimConnect, EVENT_FRAME, "Frame");
|
hr += SimConnect_SubscribeToSystemEvent(m_hSimConnect, EventFrame, "Frame");
|
||||||
hr += SimConnect_MapClientEventToSimEvent(m_hSimConnect, EVENT_FREEZELAT, "FREEZE_LATITUDE_LONGITUDE_SET");
|
|
||||||
hr += SimConnect_MapClientEventToSimEvent(m_hSimConnect, EVENT_FREEZEALT, "FREEZE_ALTITUDE_SET");
|
|
||||||
hr += SimConnect_MapClientEventToSimEvent(m_hSimConnect, EVENT_FREEZEATT, "FREEZE_ATTITUDE_SET");
|
|
||||||
|
|
||||||
|
// Mapped events
|
||||||
|
hr += SimConnect_MapClientEventToSimEvent(m_hSimConnect, EventFreezeLat, "FREEZE_LATITUDE_LONGITUDE_SET");
|
||||||
|
hr += SimConnect_MapClientEventToSimEvent(m_hSimConnect, EventFreezeAlt, "FREEZE_ALTITUDE_SET");
|
||||||
|
hr += SimConnect_MapClientEventToSimEvent(m_hSimConnect, EventFreezeAtt, "FREEZE_ATTITUDE_SET");
|
||||||
|
hr += SimConnect_MapClientEventToSimEvent(m_hSimConnect, EventSetCom1Active, "COM_RADIO_SET");
|
||||||
|
hr += SimConnect_MapClientEventToSimEvent(m_hSimConnect, EventSetCom1Standby, "COM_STBY_RADIO_SET");
|
||||||
|
hr += SimConnect_MapClientEventToSimEvent(m_hSimConnect, EventSetCom2Active, "COM2_RADIO_SET");
|
||||||
|
hr += SimConnect_MapClientEventToSimEvent(m_hSimConnect, EventSetCom2Standby, "COM2_STBY_RADIO_SET");
|
||||||
|
hr += SimConnect_MapClientEventToSimEvent(m_hSimConnect, EventSetTransponderCode, "XPNDR_SET");
|
||||||
return hr;
|
return hr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,9 @@
|
|||||||
#include "blackcore/simulator.h"
|
#include "blackcore/simulator.h"
|
||||||
#include "blackcore/interpolator_linear.h"
|
#include "blackcore/interpolator_linear.h"
|
||||||
#include "blackmisc/avaircraft.h"
|
#include "blackmisc/avaircraft.h"
|
||||||
|
#include "blackmisc/statusmessage.h"
|
||||||
#include "blacksim/simulatorinfo.h"
|
#include "blacksim/simulatorinfo.h"
|
||||||
|
|
||||||
#include <simconnect/SimConnect.h>
|
#include <simconnect/SimConnect.h>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QtPlugin>
|
#include <QtPlugin>
|
||||||
@@ -43,17 +45,23 @@ namespace BlackSimPlugin
|
|||||||
virtual BlackSim::CSimulatorInfo getSimulatorInfo() const override;
|
virtual BlackSim::CSimulatorInfo getSimulatorInfo() const override;
|
||||||
};
|
};
|
||||||
|
|
||||||
//! SimConnect Event ID's
|
//! SimConnect Event IDs
|
||||||
enum EVENT_ID
|
enum EventIds
|
||||||
{
|
{
|
||||||
EVENT_SIM_STATUS,
|
EventSimStatus,
|
||||||
EVENT_OBJECT_ADDED,
|
EventObjectAdded,
|
||||||
EVENT_OBJECT_REMOVED,
|
EventObjectRemoved,
|
||||||
EVENT_SLEW_ON,
|
EventSlewOn,
|
||||||
EVENT_FRAME,
|
EventFrame,
|
||||||
EVENT_FREEZELAT,
|
EventFreezeLat,
|
||||||
EVENT_FREEZEALT,
|
EventFreezeAlt,
|
||||||
EVENT_FREEZEATT
|
EventFreezeAtt,
|
||||||
|
EventSetCom1Active,
|
||||||
|
EventSetCom2Active,
|
||||||
|
EventSetCom1Standby,
|
||||||
|
EventSetCom2Standby,
|
||||||
|
EventSetTransponderCode,
|
||||||
|
EventTextMessage
|
||||||
};
|
};
|
||||||
|
|
||||||
//! FSX Simulator Implementation
|
//! FSX Simulator Implementation
|
||||||
@@ -102,9 +110,12 @@ namespace BlackSimPlugin
|
|||||||
virtual BlackSim::CSimulatorInfo getSimulatorInfo() const override;
|
virtual BlackSim::CSimulatorInfo getSimulatorInfo() const override;
|
||||||
|
|
||||||
//! \copydoc ISimulator::updateOwnCockpit
|
//! \copydoc ISimulator::updateOwnCockpit
|
||||||
virtual bool updateOwnCockpit(const BlackMisc::Aviation::CAircraft &ownAircraft) override;
|
virtual bool updateOwnSimulatorCockpit(const BlackMisc::Aviation::CAircraft &ownAircraft) override;
|
||||||
|
|
||||||
//! \brief Called when sim has started
|
//! \copydoc ISimulator::displayStatusMessage
|
||||||
|
virtual void displayStatusMessage(const BlackMisc::CStatusMessage &message) const override;
|
||||||
|
|
||||||
|
//! \brief Called when simulat has been started
|
||||||
void onSimRunning();
|
void onSimRunning();
|
||||||
|
|
||||||
//! \brief Called when sim has stopped
|
//! \brief Called when sim has stopped
|
||||||
@@ -113,8 +124,8 @@ namespace BlackSimPlugin
|
|||||||
//! \brief Slot called every visual frame
|
//! \brief Slot called every visual frame
|
||||||
void onSimFrame();
|
void onSimFrame();
|
||||||
|
|
||||||
//! Called when data about our own aircraft is received
|
//! Called when data about our own aircraft are received
|
||||||
void updateOwnAircraftFromSim(DataDefinitionOwnAircraft aircraft);
|
void updateOwnAircraftFromSim(DataDefinitionOwnAircraft simulatorOwnAircraft);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Set ID of a SimConnect object
|
* \brief Set ID of a SimConnect object
|
||||||
@@ -144,23 +155,25 @@ namespace BlackSimPlugin
|
|||||||
void removeRemoteAircraft(const CSimConnectObject &simObject);
|
void removeRemoteAircraft(const CSimConnectObject &simObject);
|
||||||
|
|
||||||
//! Initialize SimConnect system events
|
//! Initialize SimConnect system events
|
||||||
HRESULT initSystemEvents();
|
HRESULT initEvents();
|
||||||
|
|
||||||
//! Initialize SimConnect data definitions
|
//! Initialize SimConnect data definitions
|
||||||
HRESULT initDataDefinitions();
|
HRESULT initDataDefinitions();
|
||||||
|
|
||||||
void update(); // TODO: @RW, please rename, update is meaningless
|
//! Update what?
|
||||||
|
void update(); // TODO: @RW, please rename, update is meaningless: what is updated?
|
||||||
|
|
||||||
bool m_isConnected; //!< Is sim connected
|
static const int SkipUpdateCyclesForCockpit = 10; //!< skip x cycles for updating cockpit again
|
||||||
bool m_simRunning; //!< Sim running.
|
bool m_isConnected; //!< Is simulator connected?
|
||||||
|
bool m_simRunning; //!< Simulator running?
|
||||||
HANDLE m_hSimConnect; //!< Handle to SimConnect object
|
HANDLE m_hSimConnect; //!< Handle to SimConnect object
|
||||||
uint m_nextObjID;
|
uint m_nextObjID;
|
||||||
|
QString simulatorDetails;
|
||||||
BlackSim::CSimulatorInfo m_simulatorInfo;
|
BlackSim::CSimulatorInfo m_simulatorInfo;
|
||||||
BlackMisc::Aviation::CAircraft m_ownAircraft; //!< Object representing our own aircraft from simulator
|
BlackMisc::Aviation::CAircraft m_ownAircraft; //!< Object representing our own aircraft from simulator
|
||||||
QHash<BlackMisc::Aviation::CCallsign, CSimConnectObject> m_simConnectObjects;
|
QHash<BlackMisc::Aviation::CCallsign, CSimConnectObject> m_simConnectObjects;
|
||||||
|
|
||||||
int m_simconnectTimerId;
|
int m_simconnectTimerId;
|
||||||
|
int m_skipCockpitUpdateCycles; //!< Skip some update cycles to allow changes in simulator cockpit to be set
|
||||||
QFutureWatcher<bool> m_watcherConnect;
|
QFutureWatcher<bool> m_watcherConnect;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user