mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-09 05:28:09 +08:00
Ref T241, changed CAirspaceAnalyzer ctor so signals (CAirspaceMonitor) can be used
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
*/
|
||||
|
||||
#include "blackcore/airspaceanalyzer.h"
|
||||
#include "airspacemonitor.h"
|
||||
#include "blackmisc/aviation/aircraftsituation.h"
|
||||
#include "blackmisc/aviation/callsign.h"
|
||||
#include "blackmisc/aviation/transponder.h"
|
||||
@@ -30,10 +31,10 @@ using namespace BlackMisc::PhysicalQuantities;
|
||||
|
||||
namespace BlackCore
|
||||
{
|
||||
CAirspaceAnalyzer::CAirspaceAnalyzer(IOwnAircraftProvider *ownAircraftProvider, IRemoteAircraftProvider *remoteAircraftProvider, INetwork *network, QObject *parent) :
|
||||
CContinuousWorker(parent, "CAirspaceAnalyzer"),
|
||||
CAirspaceAnalyzer::CAirspaceAnalyzer(IOwnAircraftProvider *ownAircraftProvider, INetwork *network, CAirspaceMonitor *airspaceMonitorParent) :
|
||||
CContinuousWorker(airspaceMonitorParent, "CAirspaceAnalyzer"),
|
||||
COwnAircraftAware(ownAircraftProvider),
|
||||
CRemoteAircraftAware(remoteAircraftProvider)
|
||||
CRemoteAircraftAware(airspaceMonitorParent)
|
||||
{
|
||||
Q_ASSERT_X(network, Q_FUNC_INFO, "Network object required to connect");
|
||||
|
||||
@@ -44,20 +45,22 @@ namespace BlackCore
|
||||
bool c = connect(&m_updateTimer, &QTimer::timeout, this, &CAirspaceAnalyzer::onTimeout);
|
||||
Q_ASSERT(c);
|
||||
|
||||
// disconnect
|
||||
// network connected
|
||||
c = connect(network, &INetwork::pilotDisconnected, this, &CAirspaceAnalyzer::watchdogRemoveAircraftCallsign);
|
||||
Q_ASSERT(c);
|
||||
c = connect(network, &INetwork::atcDisconnected, this, &CAirspaceAnalyzer::watchdogRemoveAtcCallsign);
|
||||
Q_ASSERT(c);
|
||||
c = connect(network, &INetwork::connectionStatusChanged, this, &CAirspaceAnalyzer::onConnectionStatusChanged);
|
||||
Q_ASSERT(c);
|
||||
|
||||
// update
|
||||
c = connect(network, &INetwork::aircraftPositionUpdate, this, &CAirspaceAnalyzer::watchdogTouchAircraftCallsign);
|
||||
// network situations
|
||||
c = connect(network, &INetwork::aircraftPositionUpdate, this, &CAirspaceAnalyzer::onNetworkPositionUpdate);
|
||||
Q_ASSERT(c);
|
||||
c = connect(network, &INetwork::atcPositionUpdate, this, &CAirspaceAnalyzer::watchdogTouchAtcCallsign);
|
||||
Q_ASSERT(c);
|
||||
|
||||
// network
|
||||
c = connect(network, &INetwork::connectionStatusChanged, this, &CAirspaceAnalyzer::onConnectionStatusChanged);
|
||||
// Monitor
|
||||
c = connect(airspaceMonitorParent, &CAirspaceMonitor::addedAircraftSituation, this, &CAirspaceAnalyzer::watchdogTouchAircraftCallsign);
|
||||
Q_ASSERT(c);
|
||||
Q_UNUSED(c);
|
||||
|
||||
@@ -83,10 +86,15 @@ namespace BlackCore
|
||||
CAirspaceAnalyzer::~CAirspaceAnalyzer()
|
||||
{ }
|
||||
|
||||
void CAirspaceAnalyzer::watchdogTouchAircraftCallsign(const CAircraftSituation &situation, const CTransponder &transponder)
|
||||
void CAirspaceAnalyzer::onNetworkPositionUpdate(const CAircraftSituation &situation, const CTransponder &transponder)
|
||||
{
|
||||
Q_UNUSED(transponder);
|
||||
this->watchdogTouchAircraftCallsign(situation);
|
||||
}
|
||||
|
||||
void CAirspaceAnalyzer::watchdogTouchAircraftCallsign(const CAircraftSituation &situation)
|
||||
{
|
||||
Q_ASSERT_X(!situation.getCallsign().isEmpty(), Q_FUNC_INFO, "No callsign in situaton");
|
||||
Q_UNUSED(transponder);
|
||||
m_aircraftCallsignTimestamps[situation.getCallsign()] = QDateTime::currentMSecsSinceEpoch();
|
||||
}
|
||||
|
||||
@@ -140,34 +148,37 @@ namespace BlackCore
|
||||
|
||||
void CAirspaceAnalyzer::watchdogCheckTimeouts()
|
||||
{
|
||||
qint64 currentTimeMsEpoch = QDateTime::currentMSecsSinceEpoch();
|
||||
|
||||
qint64 callDiffMs = currentTimeMsEpoch - m_lastWatchdogCallMsSinceEpoch;
|
||||
qint64 callThresholdMs = static_cast<int>(m_updateTimer.interval() * 1.5);
|
||||
const qint64 currentTimeMsEpoch = QDateTime::currentMSecsSinceEpoch();
|
||||
const qint64 callDiffMs = currentTimeMsEpoch - m_lastWatchdogCallMsSinceEpoch;
|
||||
const qint64 callThresholdMs = static_cast<qint64>(m_updateTimer.interval() * 1.5);
|
||||
m_lastWatchdogCallMsSinceEpoch = currentTimeMsEpoch;
|
||||
|
||||
// this is a trick to not remove everything while debugging
|
||||
if (callDiffMs > callThresholdMs) { return; }
|
||||
|
||||
qint64 aircraftTimeoutMs = m_timeoutAircraft.valueInteger(CTimeUnit::ms());
|
||||
qint64 atcTimeoutMs = m_timeoutAtc.valueInteger(CTimeUnit::ms());
|
||||
qint64 timeoutAircraftEpochMs = currentTimeMsEpoch - aircraftTimeoutMs;
|
||||
qint64 timeoutAtcEpochMs = currentTimeMsEpoch - atcTimeoutMs;
|
||||
const qint64 aircraftTimeoutMs = m_timeoutAircraft.valueInteger(CTimeUnit::ms());
|
||||
const qint64 atcTimeoutMs = m_timeoutAtc.valueInteger(CTimeUnit::ms());
|
||||
const qint64 timeoutAircraftEpochMs = currentTimeMsEpoch - aircraftTimeoutMs;
|
||||
const qint64 timeoutAtcEpochMs = currentTimeMsEpoch - atcTimeoutMs;
|
||||
|
||||
for (const CCallsign &callsign : m_aircraftCallsignTimestamps.keys()) // clazy:exclude=container-anti-pattern,range-loop
|
||||
const QList<CCallsign> callsignsAircraft = m_aircraftCallsignTimestamps.keys();
|
||||
for (const CCallsign &callsign : callsignsAircraft) // clazy:exclude=container-anti-pattern,range-loop
|
||||
{
|
||||
if (m_aircraftCallsignTimestamps.value(callsign) > timeoutAircraftEpochMs) { continue; }
|
||||
CLogMessage(this).debug() << "Aircraft " << callsign.toQString() << "timed out!";
|
||||
const qint64 tsv = m_aircraftCallsignTimestamps.value(callsign);
|
||||
if (tsv > timeoutAircraftEpochMs) { continue; }
|
||||
CLogMessage(this).debug() << "Aircraft " << callsign.toQString() << "timed out! " << (currentTimeMsEpoch - tsv) << "ms";
|
||||
m_aircraftCallsignTimestamps.remove(callsign);
|
||||
emit timeoutAircraft(callsign);
|
||||
emit this->timeoutAircraft(callsign);
|
||||
}
|
||||
|
||||
for (const CCallsign &callsign : m_atcCallsignTimestamps.keys()) // clazy:exclude=container-anti-pattern,range-loop
|
||||
const QList<CCallsign> callsignsAtc = m_atcCallsignTimestamps.keys();
|
||||
for (const CCallsign &callsign : callsignsAtc) // clazy:exclude=container-anti-pattern,range-loop
|
||||
{
|
||||
const qint64 tsv = m_aircraftCallsignTimestamps.value(callsign);
|
||||
if (m_atcCallsignTimestamps.value(callsign) > timeoutAtcEpochMs) { continue; }
|
||||
CLogMessage(this).debug() << "ATC " << callsign.toQString() << "timed out!";
|
||||
CLogMessage(this).debug() << "ATC " << callsign.toQString() << "timed out! " << (currentTimeMsEpoch - tsv) << "ms";
|
||||
m_atcCallsignTimestamps.remove(callsign);
|
||||
emit timeoutAtc(callsign);
|
||||
emit this->timeoutAtc(callsign);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,14 +14,14 @@
|
||||
|
||||
#include "blackcore/blackcoreexport.h"
|
||||
#include "blackcore/network.h"
|
||||
#include "blackmisc/simulation/airspaceaircraftsnapshot.h"
|
||||
#include "blackmisc/simulation/ownaircraftprovider.h"
|
||||
#include "blackmisc/simulation/remoteaircraftprovider.h"
|
||||
#include "blackmisc/geo/coordinategeodetic.h"
|
||||
#include "blackmisc/pq/frequency.h"
|
||||
#include "blackmisc/pq/length.h"
|
||||
#include "blackmisc/pq/time.h"
|
||||
#include "blackmisc/pq/units.h"
|
||||
#include "blackmisc/simulation/airspaceaircraftsnapshot.h"
|
||||
#include "blackmisc/simulation/ownaircraftprovider.h"
|
||||
#include "blackmisc/simulation/remoteaircraftprovider.h"
|
||||
#include "blackmisc/worker.h"
|
||||
|
||||
#include <QHash>
|
||||
@@ -42,6 +42,8 @@ namespace BlackMisc
|
||||
|
||||
namespace BlackCore
|
||||
{
|
||||
class CAirspaceMonitor;
|
||||
|
||||
//! Class monitoring and analyzing (closest aircraft, outdated aircraft / watchdog) airspace
|
||||
//! in background.
|
||||
//!
|
||||
@@ -62,8 +64,8 @@ namespace BlackCore
|
||||
|
||||
//! Constructor
|
||||
CAirspaceAnalyzer(BlackMisc::Simulation::IOwnAircraftProvider *ownAircraftProvider,
|
||||
BlackMisc::Simulation::IRemoteAircraftProvider *remoteAircraftProvider,
|
||||
INetwork *network, QObject *parent);
|
||||
INetwork *network,
|
||||
CAirspaceMonitor *airspaceMonitorParent);
|
||||
|
||||
//! Get the latest snapshot
|
||||
//! \threadsafe
|
||||
@@ -97,7 +99,7 @@ namespace BlackCore
|
||||
void watchdogRemoveAtcCallsign(const BlackMisc::Aviation::CCallsign &callsign);
|
||||
|
||||
//! Reset timestamp for callsign
|
||||
void watchdogTouchAircraftCallsign(const BlackMisc::Aviation::CAircraftSituation &situation, const BlackMisc::Aviation::CTransponder &transponder);
|
||||
void watchdogTouchAircraftCallsign(const BlackMisc::Aviation::CAircraftSituation &situation);
|
||||
|
||||
//! Reset timestamp for callsign
|
||||
void watchdogTouchAtcCallsign(const BlackMisc::Aviation::CCallsign &callsign, const BlackMisc::PhysicalQuantities::CFrequency &frequency,
|
||||
@@ -106,6 +108,9 @@ namespace BlackCore
|
||||
//! Connection status of network changed
|
||||
void onConnectionStatusChanged(BlackCore::INetwork::ConnectionStatus oldStatus, BlackCore::INetwork::ConnectionStatus newStatus);
|
||||
|
||||
//! Network position update
|
||||
void onNetworkPositionUpdate(const BlackMisc::Aviation::CAircraftSituation &situation, const BlackMisc::Aviation::CTransponder &transponder);
|
||||
|
||||
//! Run a check
|
||||
void onTimeout();
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ namespace BlackCore
|
||||
: CRemoteAircraftProvider(parent),
|
||||
COwnAircraftAware(ownAircraftProvider),
|
||||
m_network(network),
|
||||
m_analyzer(new CAirspaceAnalyzer(ownAircraftProvider, this, network, this))
|
||||
m_analyzer(new CAirspaceAnalyzer(ownAircraftProvider, network, this))
|
||||
{
|
||||
this->setObjectName("CAirspaceMonitor");
|
||||
this->enableReverseLookupMessages(sApp->isDeveloperFlagSet());
|
||||
|
||||
Reference in New Issue
Block a user