mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-30 11:55:35 +08:00
refs #242, allows to change FSX cockpit from context
* Data definitions for FSX events * BCD conversion for COM and transponder * Update Cockpit method in context * Renamed setOwnAircraft -> updateOwnAircraftFromSim
This commit is contained in:
@@ -20,6 +20,7 @@ namespace BlackSimPlugin
|
||||
hr = initOwnAircraft(hSimConnect);
|
||||
hr = initRemoteAircraftSituation(hSimConnect);
|
||||
hr = initGearHandlePosition(hSimConnect);
|
||||
hr = initSetCockpitEvents(hSimConnect);
|
||||
return hr;
|
||||
}
|
||||
|
||||
@@ -39,7 +40,6 @@ namespace BlackSimPlugin
|
||||
hr = SimConnect_AddToDataDefinition(hSimConnect, CSimConnectDataDefinition::DataOwnAircraft, "COM ACTIVE FREQUENCY:2", "MHz");
|
||||
hr = SimConnect_AddToDataDefinition(hSimConnect, CSimConnectDataDefinition::DataOwnAircraft, "COM STANDBY FREQUENCY:1", "MHz");
|
||||
hr = SimConnect_AddToDataDefinition(hSimConnect, CSimConnectDataDefinition::DataOwnAircraft, "COM STANDBY FREQUENCY:2", "MHz");
|
||||
|
||||
return hr;
|
||||
}
|
||||
|
||||
@@ -56,5 +56,16 @@ namespace BlackSimPlugin
|
||||
hr = SimConnect_AddToDataDefinition(hSimConnect, CSimConnectDataDefinition::DataDefinitionGearHandlePosition, "GEAR HANDLE POSITION", "BOOL", SIMCONNECT_DATATYPE_INT32);
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,8 +63,18 @@ namespace BlackSimPlugin
|
||||
DataDefinitionGearHandlePosition
|
||||
};
|
||||
|
||||
//! \brief SimConnect request ID's
|
||||
enum Requests {
|
||||
//! SimConnect Event IDs
|
||||
enum Events {
|
||||
EventSetCom1Active = 100, // not overlapping with DataDefinition
|
||||
EventSetCom2Active,
|
||||
EventSetCom1Standby,
|
||||
EventSetCom2Standby,
|
||||
EventSetTransponderCode
|
||||
};
|
||||
|
||||
//! SimConnect request IDs
|
||||
enum Requests
|
||||
{
|
||||
RequestOwnAircraft = 1000,
|
||||
RequestRemoveAircraft = 2000
|
||||
};
|
||||
@@ -84,6 +94,10 @@ namespace BlackSimPlugin
|
||||
|
||||
//! Initialize data definition for remote aircraft configuration
|
||||
static HRESULT initGearHandlePosition(const HANDLE hSimConnect);
|
||||
|
||||
//! Initialize events required setting cockpit values
|
||||
static HRESULT initSetCockpitEvents(const HANDLE hSimConnect);
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,9 +5,12 @@
|
||||
|
||||
#include "simulator_fsx.h"
|
||||
#include "simconnect_datadefinition.h"
|
||||
#include "blacksim/fscommon/bcdconversions.h"
|
||||
#include "blacksim/fsx/simconnectutilities.h"
|
||||
#include "blacksim/fsx/fsxsimulatorsetup.h"
|
||||
#include "blacksim/simulatorinfo.h"
|
||||
#include "blackmisc/project.h"
|
||||
|
||||
#include <QTimer>
|
||||
#include <QtConcurrent>
|
||||
|
||||
@@ -15,6 +18,7 @@ using namespace BlackMisc::Aviation;
|
||||
using namespace BlackMisc::PhysicalQuantities;
|
||||
using namespace BlackMisc::Geo;
|
||||
using namespace BlackSim;
|
||||
using namespace BlackSim::FsCommon;
|
||||
using namespace BlackSim::Fsx;
|
||||
|
||||
namespace BlackSimPlugin
|
||||
@@ -57,10 +61,10 @@ namespace BlackSimPlugin
|
||||
|
||||
bool CSimulatorFsx::connectTo()
|
||||
{
|
||||
if(m_isConnected)
|
||||
if (m_isConnected)
|
||||
return true;
|
||||
|
||||
if (FAILED(SimConnect_Open(&m_hSimConnect, "BlackBox", nullptr, 0, 0, 0)))
|
||||
if (FAILED(SimConnect_Open(&m_hSimConnect, BlackMisc::CProject::systemNameAndVersionChar(), nullptr, 0, 0, 0)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -80,11 +84,10 @@ namespace BlackSimPlugin
|
||||
|
||||
auto asyncConnectFunc = [&]() -> bool
|
||||
{
|
||||
if (FAILED(SimConnect_Open(&m_hSimConnect, "BlackBox", nullptr, 0, 0, 0))) return false;
|
||||
|
||||
if (FAILED(SimConnect_Open(&m_hSimConnect, BlackMisc::CProject::systemNameAndVersionChar(), nullptr, 0, 0, 0))) return false;
|
||||
return true;
|
||||
};
|
||||
QFuture<bool> result = QtConcurrent::run( asyncConnectFunc );
|
||||
QFuture<bool> result = QtConcurrent::run(asyncConnectFunc);
|
||||
|
||||
m_watcherConnect.setFuture(result);
|
||||
}
|
||||
@@ -114,7 +117,7 @@ namespace BlackSimPlugin
|
||||
if (m_isConnected)
|
||||
return true;
|
||||
|
||||
if (FAILED(SimConnect_Open(&m_hSimConnect, "BlackBox", nullptr, 0, 0, 0)))
|
||||
if (FAILED(SimConnect_Open(&m_hSimConnect, BlackMisc::CProject::systemNameAndVersionChar(), nullptr, 0, 0, 0)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -172,6 +175,53 @@ namespace BlackSimPlugin
|
||||
return this->m_simulatorInfo;
|
||||
}
|
||||
|
||||
bool CSimulatorFsx::updateOwnCockpit(const CAircraft &ownAircraft)
|
||||
{
|
||||
CComSystem newCom1 = ownAircraft.getCom1System();
|
||||
CComSystem newCom2 = ownAircraft.getCom2System();
|
||||
CTransponder newTransponder = ownAircraft.getTransponder();
|
||||
|
||||
bool changed = false;
|
||||
if (newCom1 != this->m_ownAircraft.getCom1System())
|
||||
{
|
||||
if (newCom1.getFrequencyActive() != this->m_ownAircraft.getCom1System().getFrequencyActive())
|
||||
SimConnect_TransmitClientEvent(m_hSimConnect, 0, CSimConnectDataDefinition::EventSetCom1Active,
|
||||
CBcdConversions::comFrequencyToBcdHz(newCom1.getFrequencyActive()), SIMCONNECT_GROUP_PRIORITY_HIGHEST, SIMCONNECT_EVENT_FLAG_GROUPID_IS_PRIORITY);
|
||||
if (newCom1.getFrequencyStandby() != this->m_ownAircraft.getCom1System().getFrequencyStandby())
|
||||
SimConnect_TransmitClientEvent(m_hSimConnect, 0, CSimConnectDataDefinition::EventSetCom1Standby,
|
||||
CBcdConversions::comFrequencyToBcdHz(newCom1.getFrequencyStandby()), SIMCONNECT_GROUP_PRIORITY_HIGHEST, SIMCONNECT_EVENT_FLAG_GROUPID_IS_PRIORITY);
|
||||
|
||||
this->m_ownAircraft.setCom1System(newCom1);
|
||||
changed = true;
|
||||
}
|
||||
|
||||
if (newCom2 != this->m_ownAircraft.getCom2System())
|
||||
{
|
||||
if (newCom2.getFrequencyActive() != this->m_ownAircraft.getCom2System().getFrequencyActive())
|
||||
SimConnect_TransmitClientEvent(m_hSimConnect, 0, CSimConnectDataDefinition::EventSetCom2Active,
|
||||
CBcdConversions::comFrequencyToBcdHz(newCom2.getFrequencyActive()), SIMCONNECT_GROUP_PRIORITY_HIGHEST, SIMCONNECT_EVENT_FLAG_GROUPID_IS_PRIORITY);
|
||||
if (newCom2.getFrequencyStandby() != this->m_ownAircraft.getCom2System().getFrequencyStandby())
|
||||
SimConnect_TransmitClientEvent(m_hSimConnect, 0, CSimConnectDataDefinition::EventSetCom2Standby,
|
||||
CBcdConversions::comFrequencyToBcdHz(newCom2.getFrequencyStandby()), SIMCONNECT_GROUP_PRIORITY_HIGHEST, SIMCONNECT_EVENT_FLAG_GROUPID_IS_PRIORITY);
|
||||
|
||||
this->m_ownAircraft.setCom2System(newCom1);
|
||||
changed = true;
|
||||
}
|
||||
|
||||
if (newTransponder != this->m_ownAircraft.getTransponder())
|
||||
{
|
||||
if (newTransponder.getTransponderCode() != this->m_ownAircraft.getTransponder().getTransponderCode())
|
||||
{
|
||||
SimConnect_TransmitClientEvent(m_hSimConnect, 0, CSimConnectDataDefinition::EventSetTransponderCode,
|
||||
CBcdConversions::transponderCodeToBcd(newTransponder), SIMCONNECT_GROUP_PRIORITY_HIGHEST, SIMCONNECT_EVENT_FLAG_GROUPID_IS_PRIORITY);
|
||||
changed = true;
|
||||
}
|
||||
this->m_ownAircraft.setTransponder(newTransponder);
|
||||
}
|
||||
|
||||
return changed;
|
||||
}
|
||||
|
||||
void CALLBACK CSimulatorFsx::SimConnectProc(SIMCONNECT_RECV *pData, DWORD /* cbData */, void *pContext)
|
||||
{
|
||||
CSimulatorFsx *simulatorFsx = static_cast<CSimulatorFsx *>(pContext);
|
||||
@@ -217,23 +267,24 @@ namespace BlackSimPlugin
|
||||
else if (event->uEventID == EVENT_OBJECT_REMOVED)
|
||||
{
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case SIMCONNECT_RECV_ID_EVENT_FRAME:
|
||||
{
|
||||
SIMCONNECT_RECV_EVENT_FRAME *event = (SIMCONNECT_RECV_EVENT_FRAME *) pData;
|
||||
switch(event->uEventID)
|
||||
switch (event->uEventID)
|
||||
{
|
||||
case EVENT_FRAME:
|
||||
simulatorFsx->onSimFrame();
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case SIMCONNECT_RECV_ID_ASSIGNED_OBJECT_ID:
|
||||
{
|
||||
SIMCONNECT_RECV_ASSIGNED_OBJECT_ID *event = static_cast<SIMCONNECT_RECV_ASSIGNED_OBJECT_ID *>(pData);
|
||||
simulatorFsx->setSimconnectObjectID(event->dwRequestID, event->dwObjectID);
|
||||
break;
|
||||
}
|
||||
case SIMCONNECT_RECV_ID_SIMOBJECT_DATA:
|
||||
{
|
||||
@@ -243,12 +294,11 @@ namespace BlackSimPlugin
|
||||
case CSimConnectDataDefinition::RequestOwnAircraft:
|
||||
DataDefinitionOwnAircraft *ownAircaft;
|
||||
ownAircaft = (DataDefinitionOwnAircraft *)&pObjData->dwData;
|
||||
simulatorFsx->setOwnAircraft(*ownAircaft);
|
||||
simulatorFsx->updateOwnAircraftFromSim(*ownAircaft);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -275,7 +325,7 @@ namespace BlackSimPlugin
|
||||
|
||||
}
|
||||
|
||||
void CSimulatorFsx::setOwnAircraft(DataDefinitionOwnAircraft aircraft)
|
||||
void CSimulatorFsx::updateOwnAircraftFromSim(DataDefinitionOwnAircraft aircraft)
|
||||
{
|
||||
BlackMisc::Geo::CCoordinateGeodetic position;
|
||||
position.setLatitude(CLatitude(aircraft.latitude, CAngleUnit::deg()));
|
||||
@@ -358,8 +408,8 @@ namespace BlackSimPlugin
|
||||
}
|
||||
else
|
||||
emit statusChanged(ConnectionFailed);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void CSimulatorFsx::removeRemoteAircraft(const CSimConnectObject &simObject)
|
||||
{
|
||||
SimConnect_AIRemoveObject(m_hSimConnect, simObject.getObjectId(), simObject.getRequestId());
|
||||
@@ -404,6 +454,8 @@ namespace BlackSimPlugin
|
||||
position.Bank = situation.getBank().value();
|
||||
position.Heading = situation.getHeading().value(CAngleUnit::deg());
|
||||
position.Airspeed = situation.getGroundSpeed().value(CSpeedUnit::kts());
|
||||
|
||||
// TODO: epic fail for helicopters and VTOPs!
|
||||
position.OnGround = position.Airspeed < 30 ? 1 : 0;
|
||||
|
||||
DataDefinitionRemoteAircraftSituation ddAircraftSituation;
|
||||
|
||||
@@ -31,6 +31,7 @@ namespace BlackSimPlugin
|
||||
class Q_DECL_EXPORT CSimulatorFsxFactory : public QObject, public BlackCore::ISimulatorFactory
|
||||
{
|
||||
Q_OBJECT
|
||||
// TODO: @RW, move this string into CProject please
|
||||
Q_PLUGIN_METADATA(IID "net.vatsim.PilotClient.BlackCore.SimulatorInterface")
|
||||
Q_INTERFACES(BlackCore::ISimulatorFactory)
|
||||
|
||||
@@ -100,6 +101,9 @@ namespace BlackSimPlugin
|
||||
//! \copydoc ISimulator::getSimulatorInfo()
|
||||
virtual BlackSim::CSimulatorInfo getSimulatorInfo() const override;
|
||||
|
||||
//! \copydoc ISimulator::updateOwnCockpit
|
||||
virtual bool updateOwnCockpit(const BlackMisc::Aviation::CAircraft &ownAircraft) override;
|
||||
|
||||
//! \brief Called when sim has started
|
||||
void onSimRunning();
|
||||
|
||||
@@ -109,11 +113,8 @@ namespace BlackSimPlugin
|
||||
//! \brief Slot called every visual frame
|
||||
void onSimFrame();
|
||||
|
||||
/*!
|
||||
* \brief Called when data about our own aircraft is received
|
||||
* \param aircraft
|
||||
*/
|
||||
void setOwnAircraft(DataDefinitionOwnAircraft aircraft);
|
||||
//! Called when data about our own aircraft is received
|
||||
void updateOwnAircraftFromSim(DataDefinitionOwnAircraft aircraft);
|
||||
|
||||
/*!
|
||||
* \brief Set ID of a SimConnect object
|
||||
|
||||
Reference in New Issue
Block a user