mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-30 20:15:35 +08:00
Add connectTo/disconnectFrom/canConnect to Simulator drivers
Removed checkConnection() as driver is passive only. refs #187
This commit is contained in:
@@ -31,12 +31,12 @@ namespace BlackSimPlugin
|
||||
m_simRunning(false),
|
||||
m_hSimConnect(nullptr),
|
||||
m_nextObjID(1),
|
||||
m_simulatorInfo(CSimulatorInfo::FSX())
|
||||
m_simulatorInfo(CSimulatorInfo::FSX()),
|
||||
m_simconnectTimerId(-1)
|
||||
{
|
||||
CFsxSimulatorSetup setup;
|
||||
setup.init(); // this fetches important setting on local side
|
||||
this->m_simulatorInfo.setSimulatorSetup(setup.getSettings());
|
||||
QTimer::singleShot(5000, this, SLOT(checkConnection()));
|
||||
}
|
||||
|
||||
bool CSimulatorFsx::isConnected() const
|
||||
@@ -44,6 +44,49 @@ namespace BlackSimPlugin
|
||||
return m_isConnected;
|
||||
}
|
||||
|
||||
bool CSimulatorFsx::connectTo()
|
||||
{
|
||||
if(m_isConnected)
|
||||
return true;
|
||||
|
||||
if (FAILED(SimConnect_Open(&m_hSimConnect, "BlackBox", nullptr, 0, 0, 0)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
initSystemEvents();
|
||||
initDataDefinitions();
|
||||
m_simconnectTimerId = startTimer(50);
|
||||
m_isConnected = true;
|
||||
|
||||
emit connectionChanged(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CSimulatorFsx::disconnectFrom()
|
||||
{
|
||||
SimConnect_Close(m_hSimConnect);
|
||||
killTimer(m_simconnectTimerId);
|
||||
m_isConnected = false;
|
||||
|
||||
emit connectionChanged(false);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CSimulatorFsx::canConnect()
|
||||
{
|
||||
if (m_isConnected)
|
||||
return true;
|
||||
|
||||
if (FAILED(SimConnect_Open(&m_hSimConnect, "BlackBox", nullptr, 0, 0, 0)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
SimConnect_Close(m_hSimConnect);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CSimulatorFsx::addRemoteAircraft(const CCallsign &callsign, const QString &type, const CAircraftSituation &initialSituation)
|
||||
{
|
||||
Q_UNUSED(type);
|
||||
@@ -257,22 +300,6 @@ namespace BlackSimPlugin
|
||||
update();
|
||||
}
|
||||
|
||||
void CSimulatorFsx::checkConnection()
|
||||
{
|
||||
if (FAILED(SimConnect_Open(&m_hSimConnect, "BlackBox", nullptr, 0, 0, 0)))
|
||||
{
|
||||
// QTimer::singleShot(5000, this, SLOT(checkConnection()));
|
||||
return;
|
||||
}
|
||||
|
||||
initSystemEvents();
|
||||
initDataDefinitions();
|
||||
startTimer(50);
|
||||
m_isConnected = true;
|
||||
|
||||
emit connectionChanged(true);
|
||||
}
|
||||
|
||||
void CSimulatorFsx::dispatch()
|
||||
{
|
||||
SimConnect_CallDispatch(m_hSimConnect, SimConnectProc, this);
|
||||
|
||||
@@ -61,6 +61,16 @@ namespace BlackSimPlugin
|
||||
//! \copydoc ISimulator::isConnected()
|
||||
virtual bool isConnected() const override;
|
||||
|
||||
//! \copydoc ISimulator::canConnect()
|
||||
virtual bool canConnect() override;
|
||||
|
||||
public slots:
|
||||
|
||||
//! \copydoc ISimulator::connectTo()
|
||||
virtual bool connectTo() override;
|
||||
|
||||
//! \copydoc ISimulator::disconnectFrom()
|
||||
virtual bool disconnectFrom() override;
|
||||
//! \copydoc ISimulator::getOwnAircraft()
|
||||
virtual BlackMisc::Aviation::CAircraft getOwnAircraft() const override { return m_ownAircraft; }
|
||||
|
||||
@@ -114,8 +124,6 @@ namespace BlackSimPlugin
|
||||
virtual void timerEvent(QTimerEvent *event);
|
||||
|
||||
private slots:
|
||||
//! \brief Try to connect
|
||||
void checkConnection();
|
||||
|
||||
//! \brief Dispatch SimConnect messages
|
||||
void dispatch();
|
||||
@@ -151,6 +159,8 @@ namespace BlackSimPlugin
|
||||
BlackSim::CSimulatorInfo m_simulatorInfo;
|
||||
BlackMisc::Aviation::CAircraft m_ownAircraft; //!< Object representing our own aircraft from simulator
|
||||
QHash<BlackMisc::Aviation::CCallsign, SimConnectObject> m_simConnectObjects;
|
||||
|
||||
int m_simconnectTimerId;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user