mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-19 03:45:30 +08:00
Add connectTo/disconnectFrom/canConnect to Simulator drivers
Removed checkConnection() as driver is passive only. refs #187
This commit is contained in:
@@ -41,7 +41,17 @@ namespace BlackCore
|
|||||||
//! \brief Are we connected to the simulator?
|
//! \brief Are we connected to the simulator?
|
||||||
virtual bool isConnected() const = 0;
|
virtual bool isConnected() const = 0;
|
||||||
|
|
||||||
|
//! \brief Can we connect?
|
||||||
|
virtual bool canConnect() = 0;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
|
//! \brief Connect to simulator
|
||||||
|
virtual bool connectTo() = 0;
|
||||||
|
|
||||||
|
//! \brief Disconnect from simulator
|
||||||
|
virtual bool disconnectFrom() = 0;
|
||||||
|
|
||||||
//! Return user aircraft object
|
//! Return user aircraft object
|
||||||
virtual BlackMisc::Aviation::CAircraft getOwnAircraft() const = 0;
|
virtual BlackMisc::Aviation::CAircraft getOwnAircraft() const = 0;
|
||||||
|
|
||||||
|
|||||||
@@ -31,12 +31,12 @@ namespace BlackSimPlugin
|
|||||||
m_simRunning(false),
|
m_simRunning(false),
|
||||||
m_hSimConnect(nullptr),
|
m_hSimConnect(nullptr),
|
||||||
m_nextObjID(1),
|
m_nextObjID(1),
|
||||||
m_simulatorInfo(CSimulatorInfo::FSX())
|
m_simulatorInfo(CSimulatorInfo::FSX()),
|
||||||
|
m_simconnectTimerId(-1)
|
||||||
{
|
{
|
||||||
CFsxSimulatorSetup setup;
|
CFsxSimulatorSetup setup;
|
||||||
setup.init(); // this fetches important setting on local side
|
setup.init(); // this fetches important setting on local side
|
||||||
this->m_simulatorInfo.setSimulatorSetup(setup.getSettings());
|
this->m_simulatorInfo.setSimulatorSetup(setup.getSettings());
|
||||||
QTimer::singleShot(5000, this, SLOT(checkConnection()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CSimulatorFsx::isConnected() const
|
bool CSimulatorFsx::isConnected() const
|
||||||
@@ -44,6 +44,49 @@ namespace BlackSimPlugin
|
|||||||
return m_isConnected;
|
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)
|
void CSimulatorFsx::addRemoteAircraft(const CCallsign &callsign, const QString &type, const CAircraftSituation &initialSituation)
|
||||||
{
|
{
|
||||||
Q_UNUSED(type);
|
Q_UNUSED(type);
|
||||||
@@ -257,22 +300,6 @@ namespace BlackSimPlugin
|
|||||||
update();
|
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()
|
void CSimulatorFsx::dispatch()
|
||||||
{
|
{
|
||||||
SimConnect_CallDispatch(m_hSimConnect, SimConnectProc, this);
|
SimConnect_CallDispatch(m_hSimConnect, SimConnectProc, this);
|
||||||
|
|||||||
@@ -61,6 +61,16 @@ namespace BlackSimPlugin
|
|||||||
//! \copydoc ISimulator::isConnected()
|
//! \copydoc ISimulator::isConnected()
|
||||||
virtual bool isConnected() const override;
|
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()
|
//! \copydoc ISimulator::getOwnAircraft()
|
||||||
virtual BlackMisc::Aviation::CAircraft getOwnAircraft() const override { return m_ownAircraft; }
|
virtual BlackMisc::Aviation::CAircraft getOwnAircraft() const override { return m_ownAircraft; }
|
||||||
|
|
||||||
@@ -114,8 +124,6 @@ namespace BlackSimPlugin
|
|||||||
virtual void timerEvent(QTimerEvent *event);
|
virtual void timerEvent(QTimerEvent *event);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
//! \brief Try to connect
|
|
||||||
void checkConnection();
|
|
||||||
|
|
||||||
//! \brief Dispatch SimConnect messages
|
//! \brief Dispatch SimConnect messages
|
||||||
void dispatch();
|
void dispatch();
|
||||||
@@ -151,6 +159,8 @@ namespace BlackSimPlugin
|
|||||||
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, SimConnectObject> m_simConnectObjects;
|
QHash<BlackMisc::Aviation::CCallsign, SimConnectObject> m_simConnectObjects;
|
||||||
|
|
||||||
|
int m_simconnectTimerId;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user