mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-30 14:15:35 +08:00
refs #452, adjusted airspace monitor
* made BlackMisc::Network::CWebDataServicesAware * adjusted to new classes / code such as CAircraft -> CSimulatedAircraft
This commit is contained in:
committed by
Mathew Sutcliffe
parent
5fc0c66112
commit
c80f352710
@@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
#include "airspace_monitor.h"
|
#include "airspace_monitor.h"
|
||||||
#include "blackcore/blackcorefreefunctions.h"
|
#include "blackcore/blackcorefreefunctions.h"
|
||||||
#include "blackcore/web_datareader.h"
|
#include "blackcore/webdataservices.h"
|
||||||
#include "blackcore/vatsimbookingreader.h"
|
#include "blackcore/vatsimbookingreader.h"
|
||||||
#include "blackcore/vatsimdatafilereader.h"
|
#include "blackcore/vatsimdatafilereader.h"
|
||||||
#include "blackmisc/project.h"
|
#include "blackmisc/project.h"
|
||||||
@@ -30,10 +30,11 @@ using namespace BlackMisc::Weather;
|
|||||||
namespace BlackCore
|
namespace BlackCore
|
||||||
{
|
{
|
||||||
|
|
||||||
CAirspaceMonitor::CAirspaceMonitor(BlackMisc::Simulation::IOwnAircraftProvider *ownAircraftProvider, INetwork *network, CWebDataReader *webDataReader, QObject *parent)
|
CAirspaceMonitor::CAirspaceMonitor(BlackMisc::Simulation::IOwnAircraftProvider *ownAircraftProvider, INetwork *network, CWebDataServices *webDataReader, QObject *parent)
|
||||||
: QObject(parent),
|
: QObject(parent),
|
||||||
COwnAircraftAware(ownAircraftProvider),
|
COwnAircraftAware(ownAircraftProvider),
|
||||||
m_network(network), m_webDataReader(webDataReader),
|
CWebDataServicesAware(webDataReader),
|
||||||
|
m_network(network),
|
||||||
m_analyzer(new CAirspaceAnalyzer(ownAircraftProvider, this, network, this))
|
m_analyzer(new CAirspaceAnalyzer(ownAircraftProvider, this, network, this))
|
||||||
{
|
{
|
||||||
this->setObjectName("CAirspaceMonitor");
|
this->setObjectName("CAirspaceMonitor");
|
||||||
@@ -83,6 +84,12 @@ namespace BlackCore
|
|||||||
return m_aircraftInRange.findFirstByCallsign(callsign);
|
return m_aircraftInRange.findFirstByCallsign(callsign);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CAircraftModel CAirspaceMonitor::getAircraftInRangeModelForCallsign(const CCallsign &callsign) const
|
||||||
|
{
|
||||||
|
CSimulatedAircraft aircraft(getAircraftInRangeForCallsign(callsign)); // threadsafe
|
||||||
|
return aircraft.getModel();
|
||||||
|
}
|
||||||
|
|
||||||
int CAirspaceMonitor::getAircraftInRangeCount() const
|
int CAirspaceMonitor::getAircraftInRangeCount() const
|
||||||
{
|
{
|
||||||
QReadLocker l(&m_lockAircraft);
|
QReadLocker l(&m_lockAircraft);
|
||||||
@@ -245,7 +252,7 @@ namespace BlackCore
|
|||||||
CUser user = station.getController();
|
CUser user = station.getController();
|
||||||
users.push_back(user);
|
users.push_back(user);
|
||||||
}
|
}
|
||||||
for (const CAircraft &aircraft : this->getAircraftInRange())
|
for (const CSimulatedAircraft &aircraft : this->getAircraftInRange())
|
||||||
{
|
{
|
||||||
CUser user = aircraft.getPilot();
|
CUser user = aircraft.getPilot();
|
||||||
users.push_back(user);
|
users.push_back(user);
|
||||||
@@ -268,7 +275,7 @@ namespace BlackCore
|
|||||||
}
|
}
|
||||||
|
|
||||||
// do aircraft first, this will handle most callsigns
|
// do aircraft first, this will handle most callsigns
|
||||||
for (const CAircraft &aircraft : this->getAircraftInRange())
|
for (const CSimulatedAircraft &aircraft : this->getAircraftInRange())
|
||||||
{
|
{
|
||||||
if (searchList.isEmpty()) break;
|
if (searchList.isEmpty()) break;
|
||||||
CCallsign callsign = aircraft.getCallsign();
|
CCallsign callsign = aircraft.getCallsign();
|
||||||
@@ -296,7 +303,7 @@ namespace BlackCore
|
|||||||
// those are the ones not in range
|
// those are the ones not in range
|
||||||
for (const CCallsign &callsign : searchList)
|
for (const CCallsign &callsign : searchList)
|
||||||
{
|
{
|
||||||
CUserList usersByCallsign = this->m_webDataReader->getDataFileReader()->getUsersForCallsign(callsign);
|
CUserList usersByCallsign = this->getUsersForCallsign(callsign);
|
||||||
if (usersByCallsign.isEmpty())
|
if (usersByCallsign.isEmpty())
|
||||||
{
|
{
|
||||||
CUser user;
|
CUser user;
|
||||||
@@ -341,14 +348,14 @@ namespace BlackCore
|
|||||||
void CAirspaceMonitor::requestDataUpdates()
|
void CAirspaceMonitor::requestDataUpdates()
|
||||||
{
|
{
|
||||||
if (!this->m_network->isConnected()) { return; }
|
if (!this->m_network->isConnected()) { return; }
|
||||||
for (const CAircraft &aircraft : this->getAircraftInRange())
|
for (const CSimulatedAircraft &aircraft : this->getAircraftInRange())
|
||||||
{
|
{
|
||||||
const CCallsign cs(aircraft.getCallsign());
|
const CCallsign cs(aircraft.getCallsign());
|
||||||
this->m_network->sendFrequencyQuery(cs);
|
this->m_network->sendFrequencyQuery(cs);
|
||||||
|
|
||||||
// we only query ICAO if we have none yet
|
// we only query ICAO if we have none yet
|
||||||
// it happens sometimes with some FSD servers (e.g our testserver) a first query is skipped
|
// it happens sometimes with some FSD servers (e.g our testserver) a first query is skipped
|
||||||
if (!aircraft.hasValidAircraftDesignator())
|
if (!aircraft.hasAircraftDesignator())
|
||||||
{
|
{
|
||||||
this->m_network->sendIcaoCodesQuery(cs);
|
this->m_network->sendIcaoCodesQuery(cs);
|
||||||
}
|
}
|
||||||
@@ -382,7 +389,7 @@ namespace BlackCore
|
|||||||
{
|
{
|
||||||
m_metars.clear();
|
m_metars.clear();
|
||||||
m_flightPlanCache.clear();
|
m_flightPlanCache.clear();
|
||||||
m_icaoCodeCache.clear();
|
m_modelCache.clear();
|
||||||
|
|
||||||
removeAllOnlineAtcStations();
|
removeAllOnlineAtcStations();
|
||||||
removeAllAircraft();
|
removeAllAircraft();
|
||||||
@@ -425,24 +432,32 @@ namespace BlackCore
|
|||||||
|
|
||||||
void CAirspaceMonitor::ps_realNameReplyReceived(const CCallsign &callsign, const QString &realname)
|
void CAirspaceMonitor::ps_realNameReplyReceived(const CCallsign &callsign, const QString &realname)
|
||||||
{
|
{
|
||||||
Q_ASSERT(this->m_webDataReader->getDataFileReader());
|
|
||||||
if (!this->m_connected || realname.isEmpty()) { return; }
|
if (!this->m_connected || realname.isEmpty()) { return; }
|
||||||
CPropertyIndexVariantMap vm({CAtcStation::IndexController, CUser::IndexRealName}, realname);
|
|
||||||
this->m_atcStationsOnline.applyIf(&CAtcStation::getCallsign, callsign, vm);
|
|
||||||
this->m_atcStationsBooked.applyIf(&CAtcStation::getCallsign, callsign, vm);
|
|
||||||
|
|
||||||
CVoiceCapabilities caps = this->m_webDataReader->getDataFileReader()->getVoiceCapabilityForCallsign(callsign);
|
CPropertyIndexVariantMap vm;
|
||||||
vm = CPropertyIndexVariantMap({CAircraft::IndexPilot, CUser::IndexRealName}, realname);
|
int wasAtc = false;
|
||||||
vm.addValue({ CSimulatedAircraft::IndexClient, CClient::IndexUser, CUser::IndexRealName }, realname);
|
if (callsign.hasSuffix())
|
||||||
vm.addValue({ CSimulatedAircraft::IndexClient, CClient::IndexVoiceCapabilities }, caps);
|
|
||||||
|
|
||||||
// lock block
|
|
||||||
{
|
{
|
||||||
QWriteLocker l(&m_lockAircraft);
|
// very likely and ATC callsign
|
||||||
this->m_aircraftInRange.applyIf(&CAircraft::getCallsign, callsign, vm);
|
vm = CPropertyIndexVariantMap({CAtcStation::IndexController, CUser::IndexRealName}, realname);
|
||||||
|
int c1 = this->m_atcStationsOnline.applyIf(&CAtcStation::getCallsign, callsign, vm);
|
||||||
|
int c2 = this->m_atcStationsBooked.applyIf(&CAtcStation::getCallsign, callsign, vm);
|
||||||
|
wasAtc = c1 > 0 || c2 > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!wasAtc)
|
||||||
|
{
|
||||||
|
vm = CPropertyIndexVariantMap({CSimulatedAircraft::IndexPilot, CUser::IndexRealName}, realname);
|
||||||
|
|
||||||
|
// lock block
|
||||||
|
{
|
||||||
|
QWriteLocker l(&m_lockAircraft);
|
||||||
|
this->m_aircraftInRange.applyIf(&CSimulatedAircraft::getCallsign, callsign, vm);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Client
|
// Client
|
||||||
|
CVoiceCapabilities caps = this->getVoiceCapabilityForCallsign(callsign);
|
||||||
vm = CPropertyIndexVariantMap({CClient::IndexUser, CUser::IndexRealName}, realname);
|
vm = CPropertyIndexVariantMap({CClient::IndexUser, CUser::IndexRealName}, realname);
|
||||||
vm.addValue({ CClient::IndexVoiceCapabilities }, caps);
|
vm.addValue({ CClient::IndexVoiceCapabilities }, caps);
|
||||||
if (!this->m_otherClients.containsCallsign(callsign)) { this->m_otherClients.push_back(CClient(callsign)); }
|
if (!this->m_otherClients.containsCallsign(callsign)) { this->m_otherClients.push_back(CClient(callsign)); }
|
||||||
@@ -459,26 +474,21 @@ namespace BlackCore
|
|||||||
capabilities.addValue(CClient::FsdWithAircraftConfig, (flags & INetwork::SupportsAircraftConfigs));
|
capabilities.addValue(CClient::FsdWithAircraftConfig, (flags & INetwork::SupportsAircraftConfigs));
|
||||||
|
|
||||||
CPropertyIndexVariantMap vm(CClient::IndexCapabilities, CVariant::from(capabilities));
|
CPropertyIndexVariantMap vm(CClient::IndexCapabilities, CVariant::from(capabilities));
|
||||||
CVoiceCapabilities caps = m_webDataReader->getDataFileReader()->getVoiceCapabilityForCallsign(callsign);
|
CVoiceCapabilities caps = this->getVoiceCapabilityForCallsign(callsign);
|
||||||
vm.addValue({CClient::IndexVoiceCapabilities}, caps);
|
vm.addValue({CClient::IndexVoiceCapabilities}, caps);
|
||||||
if (!this->m_otherClients.containsCallsign(callsign)) { this->m_otherClients.push_back(CClient(callsign)); }
|
if (!this->m_otherClients.containsCallsign(callsign)) { this->m_otherClients.push_back(CClient(callsign)); }
|
||||||
this->m_otherClients.applyIf(&CClient::getCallsign, callsign, vm);
|
this->m_otherClients.applyIf(&CClient::getCallsign, callsign, vm);
|
||||||
|
|
||||||
// apply same to client in aircraft
|
// foraircraft parts
|
||||||
vm.prependIndex(static_cast<int>(CSimulatedAircraft::IndexClient));
|
|
||||||
// lock block
|
|
||||||
{
|
|
||||||
QWriteLocker l(&m_lockAircraft);
|
|
||||||
this->m_aircraftInRange.applyIf(&CSimulatedAircraft::getCallsign, callsign, vm);
|
|
||||||
}
|
|
||||||
if (flags & INetwork::SupportsAircraftConfigs) m_network->sendAircraftConfigQuery(callsign);
|
if (flags & INetwork::SupportsAircraftConfigs) m_network->sendAircraftConfigQuery(callsign);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CAirspaceMonitor::ps_customFSinnPacketReceived(const CCallsign &callsign, const QString &airlineIcao, const QString &aircraftDesignator, const QString &combinedAircraftType, const QString &model)
|
void CAirspaceMonitor::ps_customFSinnPacketReceived(const CCallsign &callsign, const QString &airlineIcaoDesignator, const QString &aircraftIcaoDesignator, const QString &combinedAircraftType, const QString &model)
|
||||||
{
|
{
|
||||||
if (!this->m_connected || callsign.isEmpty() || model.isEmpty()) { return; }
|
if (!this->m_connected || callsign.isEmpty() || model.isEmpty()) { return; }
|
||||||
|
|
||||||
// Request of other client, I can get the other's model from that
|
// Request of other client, I can get the other's model from that
|
||||||
|
Q_UNUSED(combinedAircraftType);
|
||||||
CPropertyIndexVariantMap vm({ CClient::IndexModel, CAircraftModel::IndexModelString }, model);
|
CPropertyIndexVariantMap vm({ CClient::IndexModel, CAircraftModel::IndexModelString }, model);
|
||||||
vm.addValue({ CClient::IndexModel, CAircraftModel::IndexModelType }, static_cast<int>(CAircraftModel::TypeQueriedFromNetwork));
|
vm.addValue({ CClient::IndexModel, CAircraftModel::IndexModelType }, static_cast<int>(CAircraftModel::TypeQueriedFromNetwork));
|
||||||
if (!this->m_otherClients.containsCallsign(callsign))
|
if (!this->m_otherClients.containsCallsign(callsign))
|
||||||
@@ -489,34 +499,11 @@ namespace BlackCore
|
|||||||
}
|
}
|
||||||
this->m_otherClients.applyIf(&CClient::getCallsign, callsign, vm);
|
this->m_otherClients.applyIf(&CClient::getCallsign, callsign, vm);
|
||||||
|
|
||||||
// make index from plain -> to client
|
|
||||||
vm.prependIndex(static_cast<int>(CSimulatedAircraft::IndexClient));
|
|
||||||
bool aircraftContainsCallsign;
|
|
||||||
// lock block
|
|
||||||
{
|
|
||||||
QWriteLocker l(&m_lockAircraft);
|
|
||||||
int u = this->m_aircraftInRange.applyIf(&CSimulatedAircraft::getCallsign, callsign, vm);
|
|
||||||
// if update was successful we know we have that callsign, otherwise explicit check
|
|
||||||
aircraftContainsCallsign = (u > 0) || this->m_aircraftInRange.containsCallsign(callsign);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ICAO response from custom data
|
// ICAO response from custom data
|
||||||
if (!aircraftDesignator.isEmpty())
|
if (!aircraftIcaoDesignator.isEmpty())
|
||||||
{
|
{
|
||||||
CAircraftIcaoData icao(
|
// hand over, same functionality as would be needed here
|
||||||
CAircraftIcaoCode(aircraftDesignator, combinedAircraftType),
|
this->ps_icaoCodesReceived(callsign, aircraftIcaoDesignator, airlineIcaoDesignator, "");
|
||||||
CAirlineIcaoCode(airlineIcao)
|
|
||||||
); // from custom packet
|
|
||||||
if (aircraftContainsCallsign)
|
|
||||||
{
|
|
||||||
// we have that aircraft, set straight away
|
|
||||||
this->ps_icaoCodesReceived(callsign, icao);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// store in cache, we can retrieve laterxs
|
|
||||||
this->m_icaoCodeCache.insert(callsign, icao);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -547,7 +534,7 @@ namespace BlackCore
|
|||||||
|
|
||||||
void CAirspaceMonitor::removeAllAircraft()
|
void CAirspaceMonitor::removeAllAircraft()
|
||||||
{
|
{
|
||||||
for (const CAircraft &aircraft : getAircraftInRange())
|
for (const CSimulatedAircraft &aircraft : getAircraftInRange())
|
||||||
{
|
{
|
||||||
const CCallsign cs(aircraft.getCallsign());
|
const CCallsign cs(aircraft.getCallsign());
|
||||||
emit removedAircraft(cs);
|
emit removedAircraft(cs);
|
||||||
@@ -560,7 +547,7 @@ namespace BlackCore
|
|||||||
m_aircraftSupportingParts.clear();
|
m_aircraftSupportingParts.clear();
|
||||||
m_aircraftInRange.clear();
|
m_aircraftInRange.clear();
|
||||||
m_flightPlanCache.clear();
|
m_flightPlanCache.clear();
|
||||||
m_icaoCodeCache.clear();
|
m_modelCache.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CAirspaceMonitor::removeAllOtherClients()
|
void CAirspaceMonitor::removeAllOtherClients()
|
||||||
@@ -571,7 +558,7 @@ namespace BlackCore
|
|||||||
void CAirspaceMonitor::removeFromAircraftCaches(const CCallsign &callsign)
|
void CAirspaceMonitor::removeFromAircraftCaches(const CCallsign &callsign)
|
||||||
{
|
{
|
||||||
if (callsign.isEmpty()) { return; }
|
if (callsign.isEmpty()) { return; }
|
||||||
this->m_icaoCodeCache.remove(callsign);
|
this->m_modelCache.remove(callsign);
|
||||||
this->m_flightPlanCache.remove(callsign);
|
this->m_flightPlanCache.remove(callsign);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -609,7 +596,7 @@ namespace BlackCore
|
|||||||
for (auto client = this->m_otherClients.begin(); client != this->m_otherClients.end(); ++client)
|
for (auto client = this->m_otherClients.begin(); client != this->m_otherClients.end(); ++client)
|
||||||
{
|
{
|
||||||
if (client->hasSpecifiedVoiceCapabilities()) { continue; } // we already have voice caps
|
if (client->hasSpecifiedVoiceCapabilities()) { continue; } // we already have voice caps
|
||||||
CVoiceCapabilities vc = this->m_webDataReader->getDataFileReader()->getVoiceCapabilityForCallsign(client->getCallsign());
|
CVoiceCapabilities vc = this->getVoiceCapabilityForCallsign(client->getCallsign());
|
||||||
if (vc.isUnknown()) { continue; }
|
if (vc.isUnknown()) { continue; }
|
||||||
client->setVoiceCapabilities(vc);
|
client->setVoiceCapabilities(vc);
|
||||||
}
|
}
|
||||||
@@ -635,23 +622,19 @@ namespace BlackCore
|
|||||||
Q_ASSERT_X(remoteAircraft.hasValidCallsign(), Q_FUNC_INFO, "Invalid callsign");
|
Q_ASSERT_X(remoteAircraft.hasValidCallsign(), Q_FUNC_INFO, "Invalid callsign");
|
||||||
}
|
}
|
||||||
|
|
||||||
CClient remoteClient = this->m_otherClients.findFirstByCallsign(callsign);
|
|
||||||
remoteAircraft.setClient(remoteClient);
|
|
||||||
remoteAircraft.setModel(remoteClient.getAircraftModel());
|
|
||||||
|
|
||||||
// check if the name and ICAO query went properly through
|
// check if the name and ICAO query went properly through
|
||||||
bool dataComplete =
|
bool dataComplete =
|
||||||
remoteAircraft.hasValidAircraftDesignator() &&
|
remoteAircraft.hasAircraftDesignator() &&
|
||||||
(!m_serverSupportsNameQuery || remoteAircraft.hasValidRealName());
|
(!m_serverSupportsNameQuery || remoteAircraft.getModel().hasModelString());
|
||||||
|
|
||||||
if (trial < 3 && !dataComplete)
|
if (trial < 3 && !dataComplete)
|
||||||
{
|
{
|
||||||
// allow another period for the client data to arrive, otherwise go ahead
|
// allow another period for the data to arrive, otherwise go ahead
|
||||||
this->fireDelayedReadyForModelMatching(callsign, trial + 1);
|
this->fireDelayedReadyForModelMatching(callsign, trial + 1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Q_ASSERT(remoteAircraft.hasValidAircraftDesignator());
|
Q_ASSERT(remoteAircraft.hasAircraftDesignator());
|
||||||
Q_ASSERT(!m_serverSupportsNameQuery || remoteAircraft.hasValidRealName());
|
Q_ASSERT(!m_serverSupportsNameQuery || remoteAircraft.hasValidRealName());
|
||||||
emit this->readyForModelMatching(remoteAircraft);
|
emit this->readyForModelMatching(remoteAircraft);
|
||||||
}
|
}
|
||||||
@@ -664,7 +647,7 @@ namespace BlackCore
|
|||||||
if (stationsWithCallsign.isEmpty())
|
if (stationsWithCallsign.isEmpty())
|
||||||
{
|
{
|
||||||
// new station, init with data from data file
|
// new station, init with data from data file
|
||||||
CAtcStation station(this->m_webDataReader->getDataFileReader()->getAtcStationsForCallsign(callsign).frontOrDefault());
|
CAtcStation station(this->getAtcStationsForCallsign(callsign).frontOrDefault());
|
||||||
station.setCallsign(callsign);
|
station.setCallsign(callsign);
|
||||||
station.setRange(range);
|
station.setRange(range);
|
||||||
station.setFrequency(frequency);
|
station.setFrequency(frequency);
|
||||||
@@ -788,35 +771,82 @@ namespace BlackCore
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CAirspaceMonitor::ps_icaoCodesReceived(const CCallsign &callsign, const CAircraftIcaoData &icaoData)
|
void CAirspaceMonitor::ps_icaoCodesReceived(const BlackMisc::Aviation::CCallsign &callsign, const QString aircraftIcaoDesignator, const QString &airlineIcaoDesignator, const QString &livery)
|
||||||
{
|
{
|
||||||
Q_ASSERT(BlackCore::isCurrentThreadObjectThread(this));
|
Q_ASSERT_X(BlackCore::isCurrentThreadObjectThread(this), Q_FUNC_INFO, "not in main thread");
|
||||||
Q_ASSERT(!callsign.isEmpty());
|
Q_ASSERT_X(!callsign.isEmpty(), Q_FUNC_INFO, "no callsign");
|
||||||
if (!this->m_connected) { return; }
|
if (!this->m_connected) { return; }
|
||||||
|
|
||||||
// update
|
if (aircraftIcaoDesignator.isEmpty() && airlineIcaoDesignator.isEmpty() && livery.isEmpty()) { return; }
|
||||||
CPropertyIndexVariantMap vm(CAircraft::IndexIcao, CVariant::from(icaoData));
|
|
||||||
if (!icaoData.hasAircraftDesignator())
|
CSimulatedAircraft remoteAircraft(this->getAircraftInRangeForCallsign(callsign));
|
||||||
|
bool existingAircraft = !remoteAircraft.getCallsign().isEmpty();
|
||||||
|
|
||||||
|
CAircraftModel model; // generate a model for that aircraft
|
||||||
|
if (existingAircraft)
|
||||||
{
|
{
|
||||||
// empty so far, try to fetch from data file
|
model = remoteAircraft.getModel();
|
||||||
CLogMessage(this).warning("Empty ICAO info for %1 %2") << callsign.toQString() << icaoData.toQString();
|
m_modelCache.remove(callsign);
|
||||||
CAircraftIcaoData icaoDataFromDataFile = this->m_webDataReader->getDataFileReader()->getIcaoInfo(callsign);
|
|
||||||
if (!icaoDataFromDataFile.hasAircraftDesignator()) { return; } // give up!
|
|
||||||
vm = CPropertyIndexVariantMap(CAircraft::IndexIcao, CVariant::from(icaoDataFromDataFile));
|
|
||||||
}
|
}
|
||||||
// ICAO code received when aircraft is already removed or not yet ready
|
else if (m_modelCache.contains(callsign))
|
||||||
// We add it to cache and use it when aircraft is created
|
{
|
||||||
int c;
|
model = m_modelCache[callsign];
|
||||||
|
}
|
||||||
|
|
||||||
|
// already matched with DB?
|
||||||
|
if (model.getModelType() != CAircraftModel::TypeQueriedFromNetwork && model.getModelType() != CAircraftModel::TypeFsdData) { return; }
|
||||||
|
|
||||||
|
// we have no DB model yet, but do we have model string?
|
||||||
|
if (model.hasModelString())
|
||||||
|
{
|
||||||
|
CAircraftModel modelFromDb(this->getModelForModelString(model.getModelString()));
|
||||||
|
if (modelFromDb.hasValidDbKey()) { model = modelFromDb; }
|
||||||
|
}
|
||||||
|
|
||||||
|
// only if not yet matched with DB
|
||||||
|
if (!model.hasValidDbKey() && CLivery::isValidCombinedCode(livery))
|
||||||
|
{
|
||||||
|
CAircraftModelList models(this->getModelsForAircraftDesignatorAndLiveryCombinedCode(aircraftIcaoDesignator, livery));
|
||||||
|
if (models.isEmpty())
|
||||||
|
{
|
||||||
|
// no models for that livery
|
||||||
|
CLivery databaseLivery(this->getLiveryForCombinedCode(livery));
|
||||||
|
if (databaseLivery.hasValidDbKey())
|
||||||
|
{
|
||||||
|
// we have found a livery in the DB
|
||||||
|
model.setLivery(databaseLivery);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// create a pseudo livery, try to find airline first
|
||||||
|
CAirlineIcaoCode airlineIcao(this->getAirlineIcaoCodeForDesignator(airlineIcaoDesignator));
|
||||||
|
if (!airlineIcao.hasValidDbKey()) { airlineIcao = CAirlineIcaoCode(airlineIcaoDesignator); }
|
||||||
|
CLivery liveryDummy(livery, airlineIcao, "Generated");
|
||||||
|
model.setLivery(liveryDummy);
|
||||||
|
}
|
||||||
|
|
||||||
|
CAircraftIcaoCode aircraftIcao(this->getAircraftIcaoCodeForDesignator(aircraftIcaoDesignator));
|
||||||
|
if (!aircraftIcao.hasValidDbKey()) { aircraftIcao = CAircraftIcaoCode(aircraftIcaoDesignator); }
|
||||||
|
model.setModelType(CAircraftModel::TypeFsdData);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// model by livery data
|
||||||
|
model = models.front();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int c = 0;
|
||||||
{
|
{
|
||||||
QWriteLocker l(&m_lockAircraft);
|
QWriteLocker l(&m_lockAircraft);
|
||||||
if (!this->m_aircraftInRange.containsCallsign(callsign))
|
if (!this->m_aircraftInRange.containsCallsign(callsign))
|
||||||
{
|
{
|
||||||
this->m_icaoCodeCache.insert(callsign, icaoData);
|
this->m_modelCache.insert(callsign, model);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// update
|
// we know the aircraft, so we update
|
||||||
c = this->m_aircraftInRange.applyIfCallsign(callsign, vm);
|
c = this->m_aircraftInRange.setAircraftModel(callsign, model);
|
||||||
}
|
}
|
||||||
if (c > 0) { ps_sendReadyForModelMatching(callsign, 1); }
|
if (c > 0) { ps_sendReadyForModelMatching(callsign, 1); }
|
||||||
}
|
}
|
||||||
@@ -843,19 +873,18 @@ namespace BlackCore
|
|||||||
aircraft.setSituation(situation);
|
aircraft.setSituation(situation);
|
||||||
aircraft.setTransponder(transponder);
|
aircraft.setTransponder(transponder);
|
||||||
aircraft.calculcateDistanceAndBearingToOwnAircraft(getOwnAircraftPosition()); // distance from myself
|
aircraft.calculcateDistanceAndBearingToOwnAircraft(getOwnAircraftPosition()); // distance from myself
|
||||||
|
this->updateWithVatsimDataFileData(aircraft);
|
||||||
|
|
||||||
// ICAO from cache if avialable
|
// ICAO from cache if avialable
|
||||||
bool setIcao = false;
|
bool setModel = false;
|
||||||
if (this->m_icaoCodeCache.contains(callsign))
|
if (this->m_modelCache.contains(callsign))
|
||||||
{
|
{
|
||||||
CAircraftIcaoData icao = this->m_icaoCodeCache.value(callsign);
|
CAircraftModel model = this->m_modelCache.value(callsign);
|
||||||
this->m_icaoCodeCache.remove(callsign);
|
this->m_modelCache.remove(callsign);
|
||||||
aircraft.setIcaoInfo(icao);
|
aircraft.setModel(model);
|
||||||
setIcao = true;
|
setModel = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
this->m_webDataReader->getDataFileReader()->updateWithVatsimDataFileData(aircraft);
|
|
||||||
|
|
||||||
// only place where aircraft is added
|
// only place where aircraft is added
|
||||||
this->m_aircraftInRange.push_back(aircraft);
|
this->m_aircraftInRange.push_back(aircraft);
|
||||||
|
|
||||||
@@ -873,7 +902,8 @@ namespace BlackCore
|
|||||||
|
|
||||||
// Send a custom FSinn query only if we don't have the exact model yet
|
// Send a custom FSinn query only if we don't have the exact model yet
|
||||||
CClient c = this->m_otherClients.findByCallsign(callsign).frontOrDefault();
|
CClient c = this->m_otherClients.findByCallsign(callsign).frontOrDefault();
|
||||||
if (c.getAircraftModel().getModelType() != CAircraftModel::TypeQueriedFromNetwork)
|
CAircraftModel::ModelType modelType = c.getAircraftModel().getModelType();
|
||||||
|
if (modelType != CAircraftModel::TypeQueriedFromNetwork && modelType != CAircraftModel::TypeDatabaseEntry)
|
||||||
{
|
{
|
||||||
this->m_network->sendCustomFsinnQuery(callsign);
|
this->m_network->sendCustomFsinnQuery(callsign);
|
||||||
}
|
}
|
||||||
@@ -883,7 +913,7 @@ namespace BlackCore
|
|||||||
this->m_network->sendServerQuery(callsign);
|
this->m_network->sendServerQuery(callsign);
|
||||||
|
|
||||||
// keep as last
|
// keep as last
|
||||||
if (setIcao)
|
if (setModel)
|
||||||
{
|
{
|
||||||
this->fireDelayedReadyForModelMatching(callsign);
|
this->fireDelayedReadyForModelMatching(callsign);
|
||||||
}
|
}
|
||||||
@@ -900,9 +930,9 @@ namespace BlackCore
|
|||||||
CLength distance = getOwnAircraft().calculateGreatCircleDistance(situation.getPosition());
|
CLength distance = getOwnAircraft().calculateGreatCircleDistance(situation.getPosition());
|
||||||
distance.switchUnit(CLengthUnit::NM());
|
distance.switchUnit(CLengthUnit::NM());
|
||||||
CPropertyIndexVariantMap vm;
|
CPropertyIndexVariantMap vm;
|
||||||
vm.addValue(CAircraft::IndexTransponder, transponder);
|
vm.addValue(CSimulatedAircraft::IndexTransponder, transponder);
|
||||||
vm.addValue(CAircraft::IndexSituation, situation);
|
vm.addValue(CSimulatedAircraft::IndexSituation, situation);
|
||||||
vm.addValue(CAircraft::IndexDistanceToOwnAircraft, distance);
|
vm.addValue(CSimulatedAircraft::IndexDistanceToOwnAircraft, distance);
|
||||||
|
|
||||||
// here I expect always a changed value
|
// here I expect always a changed value
|
||||||
this->m_aircraftInRange.applyIfCallsign(callsign, vm);
|
this->m_aircraftInRange.applyIfCallsign(callsign, vm);
|
||||||
@@ -941,8 +971,8 @@ namespace BlackCore
|
|||||||
CLength distance = getOwnAircraft().calculateGreatCircleDistance(iterimSituation.getPosition());
|
CLength distance = getOwnAircraft().calculateGreatCircleDistance(iterimSituation.getPosition());
|
||||||
distance.switchUnit(CLengthUnit::NM()); // lloks nicer
|
distance.switchUnit(CLengthUnit::NM()); // lloks nicer
|
||||||
CPropertyIndexVariantMap vm;
|
CPropertyIndexVariantMap vm;
|
||||||
vm.addValue(CAircraft::IndexSituation, iterimSituation);
|
vm.addValue(CSimulatedAircraft::IndexSituation, iterimSituation);
|
||||||
vm.addValue(CAircraft::IndexDistanceToOwnAircraft, distance);
|
vm.addValue(CSimulatedAircraft::IndexDistanceToOwnAircraft, distance);
|
||||||
|
|
||||||
// here I expect always a changed value
|
// here I expect always a changed value
|
||||||
{
|
{
|
||||||
@@ -975,7 +1005,6 @@ namespace BlackCore
|
|||||||
containsCallsign = this->m_aircraftInRange.containsCallsign(callsign);
|
containsCallsign = this->m_aircraftInRange.containsCallsign(callsign);
|
||||||
if (containsCallsign) { this->m_aircraftInRange.removeByCallsign(callsign); }
|
if (containsCallsign) { this->m_aircraftInRange.removeByCallsign(callsign); }
|
||||||
}
|
}
|
||||||
|
|
||||||
if (containsCallsign) { emit this->removedAircraft(callsign); }
|
if (containsCallsign) { emit this->removedAircraft(callsign); }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -985,10 +1014,10 @@ namespace BlackCore
|
|||||||
|
|
||||||
// update
|
// update
|
||||||
int changed;
|
int changed;
|
||||||
CPropertyIndexVariantMap vm({CAircraft::IndexCom1System, CComSystem::IndexActiveFrequency}, CVariant::from(frequency));
|
CPropertyIndexVariantMap vm({CSimulatedAircraft::IndexCom1System, CComSystem::IndexActiveFrequency}, CVariant::from(frequency));
|
||||||
{
|
{
|
||||||
QWriteLocker l(&m_lockAircraft);
|
QWriteLocker l(&m_lockAircraft);
|
||||||
changed = this->m_aircraftInRange.applyIf(&CAircraft::getCallsign, callsign, vm, true);
|
changed = this->m_aircraftInRange.applyIf(&CSimulatedAircraft::getCallsign, callsign, vm, true);
|
||||||
}
|
}
|
||||||
if (changed > 0) { emit this->changedAircraftInRange(); }
|
if (changed > 0) { emit this->changedAircraftInRange(); }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,28 +22,30 @@
|
|||||||
#include "blackmisc/aviation/atcstationlist.h"
|
#include "blackmisc/aviation/atcstationlist.h"
|
||||||
#include "blackmisc/aviation/aircraftsituationlist.h"
|
#include "blackmisc/aviation/aircraftsituationlist.h"
|
||||||
#include "blackmisc/weather/metarset.h"
|
#include "blackmisc/weather/metarset.h"
|
||||||
|
#include "blackmisc/network/webdataservicesprovider.h"
|
||||||
#include "blackmisc/network/clientlist.h"
|
#include "blackmisc/network/clientlist.h"
|
||||||
#include "blackmisc/aviation/flightplan.h"
|
|
||||||
#include "blackmisc/network/userlist.h"
|
#include "blackmisc/network/userlist.h"
|
||||||
|
#include "blackmisc/aviation/flightplan.h"
|
||||||
#include "blackmisc/aviation/callsignset.h"
|
#include "blackmisc/aviation/callsignset.h"
|
||||||
|
|
||||||
namespace BlackCore
|
namespace BlackCore
|
||||||
{
|
{
|
||||||
class CWebDataReader;
|
class CWebDataServices;
|
||||||
|
|
||||||
//! Keeps track of other entities in the airspace: aircraft, ATC stations, etc.
|
//! Keeps track of other entities in the airspace: aircraft, ATC stations, etc.
|
||||||
//! Central instance of data for \sa IRemoteAircraftProvider.
|
//! Central instance of data for \sa IRemoteAircraftProvider.
|
||||||
class BLACKCORE_EXPORT CAirspaceMonitor :
|
class BLACKCORE_EXPORT CAirspaceMonitor :
|
||||||
public QObject,
|
public QObject,
|
||||||
public BlackMisc::Simulation::IRemoteAircraftProvider, // those data will be provided from the class CAirspaceMonitor
|
public BlackMisc::Simulation::IRemoteAircraftProvider, // those data will be provided from the class CAirspaceMonitor
|
||||||
public BlackMisc::Simulation::COwnAircraftAware // used to obtain in memory inofmration about own aircraft
|
public BlackMisc::Simulation::COwnAircraftAware, // used to obtain in memory infomation about own aircraft
|
||||||
|
public BlackMisc::Network::CWebDataServicesAware // used to get web service data
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_INTERFACES(BlackMisc::Simulation::IRemoteAircraftProvider)
|
Q_INTERFACES(BlackMisc::Simulation::IRemoteAircraftProvider)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
//! Constructor
|
//! Constructor
|
||||||
CAirspaceMonitor(BlackMisc::Simulation::IOwnAircraftProvider *ownAircraft, INetwork *network, CWebDataReader *webDataReader, QObject *parent);
|
CAirspaceMonitor(BlackMisc::Simulation::IOwnAircraftProvider *ownAircraft, INetwork *network, CWebDataServices *webDataReader, QObject *parent);
|
||||||
|
|
||||||
//! \copydoc IRemoteAircraftProvider::getAircraftInRange
|
//! \copydoc IRemoteAircraftProvider::getAircraftInRange
|
||||||
//! \ingroup remoteaircraftprovider
|
//! \ingroup remoteaircraftprovider
|
||||||
@@ -53,6 +55,10 @@ namespace BlackCore
|
|||||||
//! \ingroup remoteaircraftprovider
|
//! \ingroup remoteaircraftprovider
|
||||||
virtual BlackMisc::Simulation::CSimulatedAircraft getAircraftInRangeForCallsign(const BlackMisc::Aviation::CCallsign &callsign) const override;
|
virtual BlackMisc::Simulation::CSimulatedAircraft getAircraftInRangeForCallsign(const BlackMisc::Aviation::CCallsign &callsign) const override;
|
||||||
|
|
||||||
|
//! \copydoc IRemoteAircraftProvider::getAircraftInRangeForCallsign
|
||||||
|
//! \ingroup remoteaircraftprovider
|
||||||
|
virtual BlackMisc::Simulation::CAircraftModel getAircraftInRangeModelForCallsign(const BlackMisc::Aviation::CCallsign &callsign) const override;
|
||||||
|
|
||||||
//! \copydoc IRemoteAircraftProvider::getAircraftInRangeCount
|
//! \copydoc IRemoteAircraftProvider::getAircraftInRangeCount
|
||||||
//! \ingroup remoteaircraftprovider
|
//! \ingroup remoteaircraftprovider
|
||||||
virtual int getAircraftInRangeCount() const override;
|
virtual int getAircraftInRangeCount() const override;
|
||||||
@@ -203,22 +209,21 @@ namespace BlackCore
|
|||||||
void airspaceAircraftSnapshot(const BlackMisc::Simulation::CAirspaceAircraftSnapshot &snapshot);
|
void airspaceAircraftSnapshot(const BlackMisc::Simulation::CAirspaceAircraftSnapshot &snapshot);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BlackMisc::Aviation::CAtcStationList m_atcStationsOnline;
|
BlackMisc::Aviation::CAtcStationList m_atcStationsOnline;
|
||||||
BlackMisc::Aviation::CAtcStationList m_atcStationsBooked;
|
BlackMisc::Aviation::CAtcStationList m_atcStationsBooked;
|
||||||
BlackMisc::Network::CClientList m_otherClients;
|
BlackMisc::Network::CClientList m_otherClients;
|
||||||
BlackMisc::Simulation::CSimulatedAircraftList m_aircraftInRange;
|
BlackMisc::Simulation::CSimulatedAircraftList m_aircraftInRange; //!< aircraft, thread safe access required
|
||||||
BlackMisc::Weather::CMetarSet m_metars;
|
BlackMisc::Weather::CMetarSet m_metars;
|
||||||
|
|
||||||
// hashs, because not sorted by key but keeping order
|
// hashs, because not sorted by key but keeping order
|
||||||
CSituationsPerCallsign m_situationsByCallsign; //!< situations, for performance reasons per callsign
|
CSituationsPerCallsign m_situationsByCallsign; //!< situations, for performance reasons per callsign, thread safe access required
|
||||||
CPartsPerCallsign m_partsByCallsign; //!< parts, for performance reasons per callsign
|
CPartsPerCallsign m_partsByCallsign; //!< parts, for performance reasons per callsign, thread safe access required
|
||||||
BlackMisc::Aviation::CCallsignSet m_aircraftSupportingParts; //!< aircraft supporting parts
|
BlackMisc::Aviation::CCallsignSet m_aircraftSupportingParts; //!< aircraft supporting parts, thread safe access required
|
||||||
|
|
||||||
QMap<BlackMisc::Aviation::CCallsign, BlackMisc::Aviation::CFlightPlan> m_flightPlanCache;
|
QMap<BlackMisc::Aviation::CCallsign, BlackMisc::Aviation::CFlightPlan> m_flightPlanCache;
|
||||||
QMap<BlackMisc::Aviation::CCallsign, BlackMisc::Aviation::CAircraftIcaoData> m_icaoCodeCache;
|
QMap<BlackMisc::Aviation::CCallsign, BlackMisc::Simulation::CAircraftModel> m_modelCache;
|
||||||
|
|
||||||
INetwork *m_network = nullptr;
|
INetwork *m_network = nullptr;
|
||||||
CWebDataReader *m_webDataReader = nullptr;
|
|
||||||
CAirspaceAnalyzer *m_analyzer = nullptr; //!< owned analyzer
|
CAirspaceAnalyzer *m_analyzer = nullptr; //!< owned analyzer
|
||||||
bool m_serverSupportsNameQuery = false; //!< not all servers support name query
|
bool m_serverSupportsNameQuery = false; //!< not all servers support name query
|
||||||
bool m_connected = false; //!< retrieve data
|
bool m_connected = false; //!< retrieve data
|
||||||
@@ -266,7 +271,7 @@ namespace BlackCore
|
|||||||
|
|
||||||
void ps_realNameReplyReceived(const BlackMisc::Aviation::CCallsign &callsign, const QString &realname);
|
void ps_realNameReplyReceived(const BlackMisc::Aviation::CCallsign &callsign, const QString &realname);
|
||||||
void ps_capabilitiesReplyReceived(const BlackMisc::Aviation::CCallsign &callsign, quint32 flags);
|
void ps_capabilitiesReplyReceived(const BlackMisc::Aviation::CCallsign &callsign, quint32 flags);
|
||||||
void ps_customFSinnPacketReceived(const BlackMisc::Aviation::CCallsign &callsign, const QString &p1, const QString &aircraftDesignator, const QString &combinedAircraftType, const QString &model);
|
void ps_customFSinnPacketReceived(const BlackMisc::Aviation::CCallsign &callsign, const QString &airlineIcaoDesignator, const QString &aircraftDesignator, const QString &combinedAircraftType, const QString &model);
|
||||||
void ps_serverReplyReceived(const BlackMisc::Aviation::CCallsign &callsign, const QString &server);
|
void ps_serverReplyReceived(const BlackMisc::Aviation::CCallsign &callsign, const QString &server);
|
||||||
void ps_metarReceived(const QString &metarMessage);
|
void ps_metarReceived(const QString &metarMessage);
|
||||||
void ps_flightPlanReceived(const BlackMisc::Aviation::CCallsign &callsign, const BlackMisc::Aviation::CFlightPlan &flightPlan);
|
void ps_flightPlanReceived(const BlackMisc::Aviation::CCallsign &callsign, const BlackMisc::Aviation::CFlightPlan &flightPlan);
|
||||||
@@ -274,7 +279,7 @@ namespace BlackCore
|
|||||||
void ps_atisReceived(const BlackMisc::Aviation::CCallsign &callsign, const BlackMisc::Aviation::CInformationMessage &atisMessage);
|
void ps_atisReceived(const BlackMisc::Aviation::CCallsign &callsign, const BlackMisc::Aviation::CInformationMessage &atisMessage);
|
||||||
void ps_atisVoiceRoomReceived(const BlackMisc::Aviation::CCallsign &callsign, const QString &url);
|
void ps_atisVoiceRoomReceived(const BlackMisc::Aviation::CCallsign &callsign, const QString &url);
|
||||||
void ps_atisLogoffTimeReceived(const BlackMisc::Aviation::CCallsign &callsign, const QString &zuluTime);
|
void ps_atisLogoffTimeReceived(const BlackMisc::Aviation::CCallsign &callsign, const QString &zuluTime);
|
||||||
void ps_icaoCodesReceived(const BlackMisc::Aviation::CCallsign &callsign, const BlackMisc::Aviation::CAircraftIcaoData &icaoData);
|
void ps_icaoCodesReceived(const BlackMisc::Aviation::CCallsign &callsign, const QString aircraftIcaoDesignator, const QString &airlineIcaoDesignator, const QString &livery);
|
||||||
void ps_pilotDisconnected(const BlackMisc::Aviation::CCallsign &callsign);
|
void ps_pilotDisconnected(const BlackMisc::Aviation::CCallsign &callsign);
|
||||||
void ps_frequencyReceived(const BlackMisc::Aviation::CCallsign &callsign, const BlackMisc::PhysicalQuantities::CFrequency &frequency);
|
void ps_frequencyReceived(const BlackMisc::Aviation::CCallsign &callsign, const BlackMisc::PhysicalQuantities::CFrequency &frequency);
|
||||||
void ps_receivedBookings(const BlackMisc::Aviation::CAtcStationList &bookedStations);
|
void ps_receivedBookings(const BlackMisc::Aviation::CAtcStationList &bookedStations);
|
||||||
|
|||||||
Reference in New Issue
Block a user