mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-23 07:15:35 +08:00
refs #291, getAirportsInRange for simulator, simulator context
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
#include "blacksim/simulatorinfolist.h"
|
||||
#include "blackmisc/nwaircraftmodel.h"
|
||||
#include "blackmisc/avaircraft.h"
|
||||
#include "blackmisc/avairportlist.h"
|
||||
#include "blackmisc/project.h"
|
||||
#include <QObject>
|
||||
|
||||
@@ -81,6 +82,9 @@ namespace BlackCore
|
||||
//! Simulator info
|
||||
virtual BlackSim::CSimulatorInfo getSimulatorInfo() const = 0;
|
||||
|
||||
//! Airports in range
|
||||
virtual BlackMisc::Aviation::CAirportList getAirportsInRange() const = 0;
|
||||
|
||||
//! Aircraft model
|
||||
virtual BlackMisc::Network::CAircraftModel getOwnAircraftModel() const = 0;
|
||||
|
||||
|
||||
@@ -93,12 +93,20 @@ namespace BlackCore
|
||||
Network::CAircraftModel CContextSimulator::getOwnAircraftModel() const
|
||||
{
|
||||
// If no ISimulator object is available, return a dummy.
|
||||
if (!m_simulator)
|
||||
return Network::CAircraftModel();
|
||||
if (!m_simulator) { return Network::CAircraftModel(); }
|
||||
|
||||
return this->m_simulator->getAircraftModel();
|
||||
}
|
||||
|
||||
CAirportList CContextSimulator::getAirportsInRange() const
|
||||
{
|
||||
// If no ISimulator object is available, return a dummy.
|
||||
if (!m_simulator) { return CAirportList(); }
|
||||
|
||||
return this->m_simulator->getAirportsInRange();
|
||||
}
|
||||
}
|
||||
|
||||
bool CContextSimulator::loadSimulatorPlugin(const CSimulatorInfo &simulatorInfo)
|
||||
{
|
||||
if (this->m_simulator && this->m_simulator->getSimulatorInfo() == simulatorInfo) { return true; } // already loaded
|
||||
|
||||
@@ -59,6 +59,9 @@ namespace BlackCore
|
||||
//! \copydoc IContextSimulator::getAircraftModel()
|
||||
virtual BlackMisc::Network::CAircraftModel getOwnAircraftModel() const override;
|
||||
|
||||
//! \copydoc IContextSimulator::getAirportsInRange()
|
||||
virtual BlackMisc::Aviation::CAirportList getAirportsInRange() const override;
|
||||
|
||||
//! \copydoc IContextSimulator::loadSimulatorPlugin()
|
||||
virtual bool loadSimulatorPlugin(const BlackSim::CSimulatorInfo &simulatorInfo) override;
|
||||
|
||||
|
||||
@@ -63,6 +63,11 @@ namespace BlackCore
|
||||
return m_dBusInterface->callDBusRet<BlackMisc::Network::CAircraftModel>(QLatin1Literal("getOwnAircraftModel"));
|
||||
}
|
||||
|
||||
CAirportList CContextSimulatorProxy::getAirportsInRange() const
|
||||
{
|
||||
return m_dBusInterface->callDBusRet<BlackMisc::Aviation::CAirportList>(QLatin1Literal("getAirportsInRange"));
|
||||
}
|
||||
|
||||
BlackSim::CSimulatorInfo CContextSimulatorProxy::getSimulatorInfo() const
|
||||
{
|
||||
return m_dBusInterface->callDBusRet<BlackSim::CSimulatorInfo>(QLatin1Literal("getSimulatorInfo"));
|
||||
|
||||
@@ -57,6 +57,9 @@ namespace BlackCore
|
||||
//! \copydoc IContextSimulator::getAircraftModel()
|
||||
virtual BlackMisc::Network::CAircraftModel getOwnAircraftModel() const override;
|
||||
|
||||
//! \copydoc IContextSimulator::getAirportsInRange()
|
||||
virtual BlackMisc::Aviation::CAirportList getAirportsInRange() const override;
|
||||
|
||||
//! \copydoc IContextSimulator::getSimulatorInfo
|
||||
virtual BlackSim::CSimulatorInfo getSimulatorInfo() const override;
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "blacksim/simulatorinfo.h"
|
||||
#include "blackmisc/statusmessage.h"
|
||||
#include "blackmisc/avaircraft.h"
|
||||
#include "blackmisc/avairportlist.h"
|
||||
#include "blackmisc/nwaircraftmodel.h"
|
||||
#include <QObject>
|
||||
|
||||
@@ -84,6 +85,10 @@ namespace BlackCore
|
||||
//! Aircraft Model
|
||||
virtual BlackMisc::Network::CAircraftModel getAircraftModel() const = 0;
|
||||
|
||||
//! Airports in range
|
||||
virtual BlackMisc::Aviation::CAirportList getAirportsInRange() const = 0;
|
||||
|
||||
|
||||
signals:
|
||||
//! Emitted when the connection status has changed
|
||||
void statusChanged(ISimulator::Status status);
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include "blacksim/fsx/fsxsimulatorsetup.h"
|
||||
#include "blacksim/simulatorinfo.h"
|
||||
#include "blackmisc/project.h"
|
||||
#include "blackmisc/avairportlist.h"
|
||||
|
||||
#include <QTimer>
|
||||
#include <QtConcurrent>
|
||||
@@ -278,10 +279,14 @@ namespace BlackSimPlugin
|
||||
Q_UNUSED(hr);
|
||||
}
|
||||
|
||||
CAirportList CSimulatorFsx::getAirportsInRange() const
|
||||
{
|
||||
return this->m_airportsInRange;
|
||||
}
|
||||
|
||||
void CALLBACK CSimulatorFsx::SimConnectProc(SIMCONNECT_RECV *pData, DWORD /* cbData */, void *pContext)
|
||||
{
|
||||
CSimulatorFsx *simulatorFsx = static_cast<CSimulatorFsx *>(pContext);
|
||||
|
||||
switch (pData->dwID)
|
||||
{
|
||||
case SIMCONNECT_RECV_ID_OPEN:
|
||||
@@ -370,8 +375,30 @@ namespace BlackSimPlugin
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
case SIMCONNECT_RECV_ID_AIRPORT_LIST:
|
||||
{
|
||||
SIMCONNECT_RECV_AIRPORT_LIST *pAirportList = (SIMCONNECT_RECV_AIRPORT_LIST *) pData;
|
||||
for (unsigned i = 0; i < pAirportList->dwArraySize; ++i)
|
||||
{
|
||||
SIMCONNECT_DATA_FACILITY_AIRPORT *pFacilityAirport = pAirportList->rgData + i;
|
||||
if (!pFacilityAirport) break;
|
||||
const QString icao(pFacilityAirport->Icao);
|
||||
if (icao.isEmpty()) continue; // airfield without ICAO code
|
||||
CCoordinateGeodetic pos(pFacilityAirport->Latitude, pFacilityAirport->Longitude, pFacilityAirport->Altitude);
|
||||
CAirport airport(CAirportIcao(icao), pos);
|
||||
const CCoordinateGeodetic posAircraft = simulatorFsx->getOwnAircraft().getPosition();
|
||||
airport.calculcateDistanceToPlane(posAircraft);
|
||||
simulatorFsx->m_airportsInRange.replaceOrAddByIcao(airport);
|
||||
if (simulatorFsx->m_airportsInRange.size() > 20)
|
||||
{
|
||||
const CLength maxDistance(200.0, CLengthUnit::NM());
|
||||
simulatorFsx->m_airportsInRange.removeIfOutsideRange(posAircraft, maxDistance, true);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
} // switch
|
||||
} // method
|
||||
|
||||
void CSimulatorFsx::onSimRunning()
|
||||
{
|
||||
@@ -520,6 +547,9 @@ namespace BlackSimPlugin
|
||||
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");
|
||||
|
||||
// facility
|
||||
hr = SimConnect_SubscribeToFacilities(m_hSimConnect, SIMCONNECT_FACILITY_LIST_TYPE_AIRPORT, m_nextObjID++);
|
||||
return hr;
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include "blackcore/simulator.h"
|
||||
#include "blackcore/interpolator_linear.h"
|
||||
#include "blackmisc/avaircraft.h"
|
||||
#include "blackmisc/avairportlist.h"
|
||||
#include "blackmisc/statusmessage.h"
|
||||
#include "blackmisc/nwaircraftmodel.h"
|
||||
#include "blacksim/simulatorinfo.h"
|
||||
@@ -125,6 +126,10 @@ namespace BlackSimPlugin
|
||||
//! \copydoc ISimulator::getAircraftModel()
|
||||
virtual BlackMisc::Network::CAircraftModel getAircraftModel() const override { return m_aircraftModel; }
|
||||
|
||||
//! \copydoc ISimulator::getAirportsInRange
|
||||
virtual BlackMisc::Aviation::CAirportList getAirportsInRange() const override;
|
||||
|
||||
|
||||
//! \brief Called when sim has started
|
||||
void onSimRunning();
|
||||
|
||||
@@ -180,12 +185,13 @@ namespace BlackSimPlugin
|
||||
bool m_isConnected; //!< Is simulator connected?
|
||||
bool m_simRunning; //!< Simulator running?
|
||||
HANDLE m_hSimConnect; //!< Handle to SimConnect object
|
||||
uint m_nextObjID;
|
||||
uint m_nextObjID; //!< object ID TODO: also used as request id, where to we place other request ids as for facilities
|
||||
QString simulatorDetails;
|
||||
BlackSim::CSimulatorInfo m_simulatorInfo;
|
||||
BlackMisc::Aviation::CAircraft m_ownAircraft; //!< Object representing our own aircraft from simulator
|
||||
QHash<BlackMisc::Aviation::CCallsign, CSimConnectObject> m_simConnectObjects;
|
||||
BlackMisc::Network::CAircraftModel m_aircraftModel;
|
||||
BlackMisc::Aviation::CAirportList m_airportsInRange;
|
||||
|
||||
int m_simconnectTimerId;
|
||||
int m_skipCockpitUpdateCycles; //!< Skip some update cycles to allow changes in simulator cockpit to be set
|
||||
|
||||
@@ -202,6 +202,13 @@ namespace BlackSimPlugin
|
||||
return { m_xplaneData.aircraftModelPath, true };
|
||||
}
|
||||
|
||||
BlackMisc::Aviation::CAirportList CSimulatorXPlane::getAirportsInRange() const
|
||||
{
|
||||
// TODO: Fill with airports nearby from sim
|
||||
BlackMisc::Aviation::CAirportList airports;
|
||||
return airports;
|
||||
}
|
||||
|
||||
bool CSimulatorXPlane::updateOwnSimulatorCockpit(const BlackMisc::Aviation::CAircraft &aircraft)
|
||||
{
|
||||
if (! isConnected()) { return false; }
|
||||
|
||||
@@ -74,6 +74,9 @@ namespace BlackSimPlugin
|
||||
//! \copydoc BlackCore::ISimulator::getAircraftModel
|
||||
virtual BlackMisc::Network::CAircraftModel getAircraftModel() const override;
|
||||
|
||||
//! Airports in range
|
||||
virtual BlackMisc::Aviation::CAirportList getAirportsInRange() const override;
|
||||
|
||||
private slots:
|
||||
void serviceRegistered(const QString &serviceName);
|
||||
void serviceUnregistered();
|
||||
|
||||
Reference in New Issue
Block a user