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