mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 23:05:36 +08:00
refs #358, adjusted simulator context and airspace monitor for model matching
This commit is contained in:
@@ -11,18 +11,20 @@
|
||||
#include "blackcore/blackcorefreefunctions.h"
|
||||
#include "blackmisc/project.h"
|
||||
#include "blackmisc/testing.h"
|
||||
#include "blackmisc/logmessage.h"
|
||||
#include "blackmisc/blackmiscfreefunctions.h"
|
||||
#include "blackmisc/propertyindexallclasses.h"
|
||||
|
||||
using namespace BlackMisc;
|
||||
using namespace BlackMisc::Aviation;
|
||||
using namespace BlackMisc::Audio;
|
||||
using namespace BlackMisc::Network;
|
||||
using namespace BlackMisc::Geo;
|
||||
using namespace BlackMisc::PhysicalQuantities;
|
||||
|
||||
namespace BlackCore
|
||||
{
|
||||
|
||||
using namespace BlackMisc;
|
||||
using namespace BlackMisc::Aviation;
|
||||
using namespace BlackMisc::Audio;
|
||||
using namespace BlackMisc::Network;
|
||||
using namespace BlackMisc::Geo;
|
||||
using namespace BlackMisc::PhysicalQuantities;
|
||||
|
||||
CAirspaceMonitor::CAirspaceMonitor(QObject *parent, INetwork *network, CVatsimBookingReader *bookings, CVatsimDataFileReader *dataFile)
|
||||
: QObject(parent), m_network(network), m_vatsimBookingReader(bookings), m_vatsimDataFileReader(dataFile),
|
||||
m_atcWatchdog(this), m_aircraftWatchdog(this)
|
||||
@@ -270,7 +272,7 @@ namespace BlackCore
|
||||
|
||||
// Request of other client, I can get the other's model from that
|
||||
CPropertyIndexVariantMap vm({ CClient::IndexModel, CAircraftModel::IndexModelString }, model);
|
||||
vm.addValue({ CClient::IndexModel, CAircraftModel::IndexIsQueriedModelString }, true);
|
||||
vm.addValue({ CClient::IndexModel, CAircraftModel::IndexModelType }, static_cast<int>(CAircraftModel::TypeQueriedFromNetwork));
|
||||
if (!this->m_otherClients.contains(&CClient::getCallsign, callsign))
|
||||
{
|
||||
// with custom packets it can happen,
|
||||
@@ -392,6 +394,13 @@ namespace BlackCore
|
||||
}
|
||||
}
|
||||
|
||||
void CAirspaceMonitor::ps_sendReadyForModelMatching(const CCallsign &callsign)
|
||||
{
|
||||
CAircraft remoteAircraft = this->m_aircraftInRange.findFirstByCallsign(callsign);
|
||||
CClient remoteClient = this->m_otherClients.findFirstByCallsign(callsign);
|
||||
emit readyForModelMatching(remoteAircraft, remoteClient);
|
||||
}
|
||||
|
||||
void CAirspaceMonitor::ps_atcPositionUpdate(const CCallsign &callsign, const BlackMisc::PhysicalQuantities::CFrequency &frequency, const CCoordinateGeodetic &position, const BlackMisc::PhysicalQuantities::CLength &range)
|
||||
{
|
||||
Q_ASSERT(BlackCore::isCurrentThreadCreatingThread(this));
|
||||
@@ -529,6 +538,22 @@ namespace BlackCore
|
||||
}
|
||||
int changed = this->m_aircraftInRange.applyIf(&CAircraft::getCallsign, callsign, vm, true);
|
||||
if (changed > 0) { emit this->changedAircraftInRange(); }
|
||||
|
||||
// we have most important data for model matching
|
||||
// but do we already have the client
|
||||
if (this->m_otherClients.contains(&CClient::getCallsign, callsign))
|
||||
{
|
||||
// yes, client with possible model string is there
|
||||
ps_sendReadyForModelMatching(callsign);
|
||||
}
|
||||
else
|
||||
{
|
||||
// allow another period for the client data to arrive, otherwise go ahead
|
||||
BlackMisc::singleShot(5000, QThread::currentThread(), [ = ]()
|
||||
{
|
||||
ps_sendReadyForModelMatching(callsign);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void CAirspaceMonitor::ps_aircraftUpdateReceived(const CCallsign &callsign, const CAircraftSituation &situation, const CTransponder &transponder)
|
||||
|
||||
@@ -98,6 +98,8 @@ namespace BlackCore
|
||||
//! An aircraft disappeared
|
||||
void removedAircraft(const BlackMisc::Aviation::CCallsign &callsign);
|
||||
|
||||
//! Read for model matching
|
||||
void readyForModelMatching(const BlackMisc::Aviation::CAircraft &remoteAircraft, const BlackMisc::Network::CClient &remoteClient);
|
||||
|
||||
public slots:
|
||||
//! Own aircraft updated
|
||||
@@ -128,7 +130,7 @@ namespace BlackCore
|
||||
BlackMisc::Aviation::CAircraft m_ownAircraft;
|
||||
BlackMisc::Network::CAircraftModel m_ownAircraftModel;
|
||||
|
||||
INetwork *m_network;
|
||||
INetwork *m_network = nullptr;
|
||||
CVatsimBookingReader *m_vatsimBookingReader;
|
||||
CVatsimDataFileReader *m_vatsimDataFileReader;
|
||||
CAirspaceWatchdog m_atcWatchdog;
|
||||
@@ -162,10 +164,11 @@ namespace BlackCore
|
||||
void ps_aircraftUpdateReceived(const BlackMisc::Aviation::CCallsign &callsign, const BlackMisc::Aviation::CAircraftSituation &situation, const BlackMisc::Aviation::CTransponder &transponder);
|
||||
void ps_pilotDisconnected(const BlackMisc::Aviation::CCallsign &callsign);
|
||||
void ps_frequencyReceived(const BlackMisc::Aviation::CCallsign &callsign, const BlackMisc::PhysicalQuantities::CFrequency &frequency);
|
||||
|
||||
void ps_receivedBookings(const BlackMisc::Aviation::CAtcStationList &bookedStations);
|
||||
void ps_receivedDataFile();
|
||||
|
||||
// non network related slots
|
||||
void ps_sendReadyForModelMatching(const BlackMisc::Aviation::CCallsign &callsign);
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
#include "blackcore/context_runtime.h"
|
||||
#include "blacksim/simulatorinfo.h"
|
||||
#include "blacksim/simulatorinfolist.h"
|
||||
#include "blackmisc/nwaircraftmodel.h"
|
||||
#include "blackmisc/nwaircraftmodellist.h"
|
||||
#include "blackmisc/avaircraft.h"
|
||||
#include "blackmisc/avairportlist.h"
|
||||
#include "blackmisc/project.h"
|
||||
@@ -76,6 +76,12 @@ namespace BlackCore
|
||||
//! Simulator combined status
|
||||
void simulatorStatusChanged(bool connected, bool running, bool paused);
|
||||
|
||||
//! Installed aircraft models ready or changed
|
||||
void installedAircraftModelsChanged();
|
||||
|
||||
//! A single model has been matched
|
||||
void modelMatchingCompleted(BlackMisc::Network::CAircraftModel model);
|
||||
|
||||
//! Emitted when own aircraft model changes
|
||||
//! \todo move to own aircraft context?
|
||||
void ownAircraftModelChanged(BlackMisc::Network::CAircraftModel model);
|
||||
@@ -112,6 +118,12 @@ namespace BlackCore
|
||||
//! Aircraft model
|
||||
virtual BlackMisc::Network::CAircraftModel getOwnAircraftModel() const = 0;
|
||||
|
||||
//! Installed models in simulator eco system
|
||||
virtual BlackMisc::Network::CAircraftModelList getInstalledModels() const = 0;
|
||||
|
||||
//! Remote aircraft in range having a valid model matching (which should be all aircraft in range)
|
||||
virtual BlackMisc::Network::CAircraftModelList getCurrentlyMatchedModels() const = 0;
|
||||
|
||||
//! Set time synchronization between simulator and user's computer time
|
||||
//! \remarks not all drivers implement this, e.g. if it is an intrinsic simulator feature
|
||||
virtual void setTimeSynchronization(bool enable, BlackMisc::PhysicalQuantities::CTime offset) = 0;
|
||||
|
||||
@@ -99,34 +99,57 @@ namespace BlackCore
|
||||
|
||||
Network::CAircraftModel CContextSimulator::getOwnAircraftModel() const
|
||||
{
|
||||
CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO;
|
||||
// If no ISimulator object is available, return a dummy.
|
||||
if (!m_simulator) { return Network::CAircraftModel(); }
|
||||
|
||||
return this->m_simulator->getAircraftModel();
|
||||
return this->m_simulator->getOwnAircraftModel();
|
||||
}
|
||||
|
||||
CAirportList CContextSimulator::getAirportsInRange() const
|
||||
{
|
||||
CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO;
|
||||
// If no ISimulator object is available, return a dummy.
|
||||
if (!m_simulator) { return CAirportList(); }
|
||||
|
||||
return this->m_simulator->getAirportsInRange();
|
||||
}
|
||||
|
||||
CAircraftModelList CContextSimulator::getInstalledModels() const
|
||||
{
|
||||
CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO;
|
||||
// If no ISimulator object is available, return a dummy.
|
||||
if (!m_simulator) { return CAircraftModelList(); }
|
||||
|
||||
return this->m_simulator->getInstalledModels();
|
||||
}
|
||||
|
||||
CAircraftModelList CContextSimulator::getCurrentlyMatchedModels() const
|
||||
{
|
||||
CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO;
|
||||
// If no ISimulator object is available, return a dummy.
|
||||
if (!m_simulator) { return CAircraftModelList(); }
|
||||
|
||||
return this->m_simulator->getCurrentlyMatchedModels();
|
||||
}
|
||||
|
||||
void CContextSimulator::setTimeSynchronization(bool enable, CTime offset)
|
||||
{
|
||||
CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO;
|
||||
if (!m_simulator) return;
|
||||
this->m_simulator->setTimeSynchronization(enable, offset);
|
||||
}
|
||||
|
||||
bool CContextSimulator::isTimeSynchronized() const
|
||||
{
|
||||
CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO;
|
||||
if (!m_simulator) return false;
|
||||
return this->m_simulator->isTimeSynchronized();
|
||||
}
|
||||
|
||||
CTime CContextSimulator::getTimeSynchronizationOffset() const
|
||||
{
|
||||
CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO;
|
||||
if (!m_simulator) return CTime(0, CTimeUnit::hrmin());
|
||||
return this->m_simulator->getTimeSynchronizationOffset();
|
||||
}
|
||||
@@ -169,7 +192,8 @@ namespace BlackCore
|
||||
|
||||
connect(m_simulator, &ISimulator::connectionStatusChanged, this, &CContextSimulator::ps_onConnectionStatusChanged);
|
||||
connect(m_simulator, &ISimulator::simulatorStatusChanged, this, &CContextSimulator::simulatorStatusChanged);
|
||||
connect(m_simulator, &ISimulator::aircraftModelChanged, this, &IContextSimulator::ownAircraftModelChanged);
|
||||
connect(m_simulator, &ISimulator::ownAircraftModelChanged, this, &IContextSimulator::ownAircraftModelChanged);
|
||||
connect(m_simulator, &ISimulator::modelMatchingCompleted, this, &IContextSimulator::modelMatchingCompleted);
|
||||
|
||||
// log
|
||||
connect(CLogHandler::instance(), &CLogHandler::localMessageLogged, m_simulator, &ISimulator::displayStatusMessage);
|
||||
@@ -177,12 +201,15 @@ namespace BlackCore
|
||||
|
||||
// connect with network
|
||||
CAirspaceMonitor *airspace = this->getRuntime()->getCContextNetwork()->getAirspaceMonitor();
|
||||
connect(airspace, &CAirspaceMonitor::addedAircraft, this, &CContextSimulator::ps_addRemoteAircraft);
|
||||
// connect(airspace, &CAirspaceMonitor::addedAircraft, this, &CContextSimulator::ps_addRemoteAircraft);
|
||||
connect(airspace, &CAirspaceMonitor::readyForModelMatching, this, &CContextSimulator::ps_addRemoteAircraft);
|
||||
connect(airspace, &CAirspaceMonitor::changedAircraftSituation, this, &CContextSimulator::ps_addAircraftSituation);
|
||||
connect(airspace, &CAirspaceMonitor::removedAircraft, this, &CContextSimulator::ps_removeRemoteAircraft);
|
||||
for (const auto &aircraft : airspace->getAircraftInRange())
|
||||
{
|
||||
m_simulator->addRemoteAircraft(aircraft.getCallsign(), aircraft.getSituation());
|
||||
// m_simulator->addRemoteAircraft(aircraft.getCallsign(), aircraft.getSituation());
|
||||
CClient client = airspace->getOtherClients().findFirstByCallsign(aircraft.getCallsign());
|
||||
m_simulator->addRemoteAircraft(aircraft, client);
|
||||
}
|
||||
|
||||
// apply latest settings
|
||||
@@ -265,13 +292,20 @@ namespace BlackCore
|
||||
}
|
||||
}
|
||||
|
||||
void CContextSimulator::ps_addRemoteAircraft(const CCallsign &callsign, const CAircraftSituation &initialSituation)
|
||||
void CContextSimulator::ps_addRemoteAircraft(const CAircraft &remoteAircraft, const CClient &remoteClient)
|
||||
{
|
||||
Q_ASSERT(this->m_simulator);
|
||||
if (!this->m_simulator) return;
|
||||
this->m_simulator->addRemoteAircraft(callsign, initialSituation);
|
||||
this->m_simulator->addRemoteAircraft(remoteAircraft, remoteClient);
|
||||
}
|
||||
|
||||
// void CContextSimulator::ps_addRemoteAircraft(const CCallsign &callsign, const CAircraftSituation &initialSituation)
|
||||
// {
|
||||
// Q_ASSERT(this->m_simulator);
|
||||
// if (!this->m_simulator) return;
|
||||
// this->m_simulator->addRemoteAircraft(callsign, initialSituation);
|
||||
// }
|
||||
|
||||
void CContextSimulator::ps_addAircraftSituation(const CCallsign &callsign, const CAircraftSituation &situation)
|
||||
{
|
||||
Q_ASSERT(this->m_simulator);
|
||||
@@ -361,7 +395,7 @@ namespace BlackCore
|
||||
bool CContextSimulator::isRunning() const
|
||||
{
|
||||
if (!this->m_simulator) return false;
|
||||
return this->m_simulator->isRunning();
|
||||
return this->m_simulator->isSimulating();
|
||||
}
|
||||
|
||||
void CContextSimulator::findSimulatorPlugins()
|
||||
|
||||
@@ -74,6 +74,12 @@ namespace BlackCore
|
||||
//! \copydoc IContextSimulator::getAirportsInRange()
|
||||
virtual BlackMisc::Aviation::CAirportList getAirportsInRange() const override;
|
||||
|
||||
//! \copydoc IContextSimulator::getInstalledModels()
|
||||
virtual BlackMisc::Network::CAircraftModelList getInstalledModels() const override;
|
||||
|
||||
//! \copydoc IContextSimulator::getCurrentlyMatchedModels()
|
||||
virtual BlackMisc::Network::CAircraftModelList getCurrentlyMatchedModels() const override;
|
||||
|
||||
//! \copydoc IContextSimulator::setTimeSynchronization
|
||||
virtual void setTimeSynchronization(bool enable, BlackMisc::PhysicalQuantities::CTime offset) override;
|
||||
|
||||
@@ -112,7 +118,8 @@ namespace BlackCore
|
||||
void ps_updateOwnAircraftContext();
|
||||
|
||||
//! \copydoc ISimulator::addRemoteAircraft
|
||||
void ps_addRemoteAircraft(const BlackMisc::Aviation::CCallsign &callsign, const BlackMisc::Aviation::CAircraftSituation &initialSituation);
|
||||
// void ps_addRemoteAircraft(const BlackMisc::Aviation::CCallsign &callsign, const BlackMisc::Aviation::CAircraftSituation &initialSituation);
|
||||
void ps_addRemoteAircraft(const BlackMisc::Aviation::CAircraft &remoteAircraft, const BlackMisc::Network::CClient &remoteClient);
|
||||
|
||||
//! \copydoc ISimulator::addAircraftSituation
|
||||
void ps_addAircraftSituation(const BlackMisc::Aviation::CCallsign &callsign, const BlackMisc::Aviation::CAircraftSituation &situation);
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
using namespace BlackMisc;
|
||||
using namespace BlackMisc::PhysicalQuantities;
|
||||
using namespace BlackMisc::Aviation;
|
||||
using namespace BlackMisc::Network;
|
||||
using namespace BlackMisc::Geo;
|
||||
using namespace BlackSim;
|
||||
|
||||
@@ -32,14 +33,17 @@ namespace BlackCore
|
||||
Q_ASSERT(s);
|
||||
s = connection.connect(serviceName, IContextSimulator::ObjectPath(), IContextSimulator::InterfaceName(),
|
||||
"startedChanged", this, SIGNAL(startedChanged(bool)));
|
||||
|
||||
Q_ASSERT(s);
|
||||
s = connection.connect(serviceName, IContextSimulator::ObjectPath(), IContextSimulator::InterfaceName(),
|
||||
"simulatorStatusChanged", this, SIGNAL(simulatorStatusChanged(bool,bool,bool)));
|
||||
"simulatorStatusChanged", this, SIGNAL(simulatorStatusChanged(bool, bool, bool)));
|
||||
Q_ASSERT(s);
|
||||
s = connection.connect(serviceName, IContextSimulator::ObjectPath(), IContextSimulator::InterfaceName(),
|
||||
"ownAircraftModelChanged", this, SIGNAL(ownAircraftModelChanged(BlackMisc::Network::CAircraftModel)));
|
||||
Q_ASSERT(s);
|
||||
|
||||
s = connection.connect(serviceName, IContextSimulator::ObjectPath(), IContextSimulator::InterfaceName(),
|
||||
"modelMatchingCompleted", this, SIGNAL(modelMatchingCompleted(BlackMisc::Network::CAircraftModel)));
|
||||
Q_ASSERT(s);
|
||||
Q_UNUSED(s);
|
||||
}
|
||||
|
||||
@@ -83,6 +87,16 @@ namespace BlackCore
|
||||
return m_dBusInterface->callDBusRet<BlackMisc::Aviation::CAirportList>(QLatin1Literal("getAirportsInRange"));
|
||||
}
|
||||
|
||||
CAircraftModelList CContextSimulatorProxy::getInstalledModels() const
|
||||
{
|
||||
return m_dBusInterface->callDBusRet<BlackMisc::Network::CAircraftModelList>(QLatin1Literal("getInstalledModels"));
|
||||
}
|
||||
|
||||
CAircraftModelList CContextSimulatorProxy::getCurrentlyMatchedModels() const
|
||||
{
|
||||
return m_dBusInterface->callDBusRet<BlackMisc::Network::CAircraftModelList>(QLatin1Literal("getCurrentlyMatchedModels"));
|
||||
}
|
||||
|
||||
BlackSim::CSimulatorInfo CContextSimulatorProxy::getSimulatorInfo() const
|
||||
{
|
||||
return m_dBusInterface->callDBusRet<BlackSim::CSimulatorInfo>(QLatin1Literal("getSimulatorInfo"));
|
||||
|
||||
@@ -73,6 +73,12 @@ namespace BlackCore
|
||||
//! \copydoc IContextSimulator::getAirportsInRange()
|
||||
virtual BlackMisc::Aviation::CAirportList getAirportsInRange() const override;
|
||||
|
||||
//! \copydoc IContextSimulator::getInstalledModels()
|
||||
virtual BlackMisc::Network::CAircraftModelList getInstalledModels() const override;
|
||||
|
||||
//! \copydoc IContextSimulator::getCurrentlyMatchedModels()
|
||||
virtual BlackMisc::Network::CAircraftModelList getCurrentlyMatchedModels() const override;
|
||||
|
||||
//! \copydoc IContextSimulator::getSimulatorInfo
|
||||
virtual BlackSim::CSimulatorInfo getSimulatorInfo() const override;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user