mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-08 03:35:35 +08:00
Ref T275, allow to disable airspace watchdog (needed when debugging to avoid timeouts)
This commit is contained in:
@@ -160,10 +160,12 @@ namespace BlackCore
|
||||
const qint64 atcTimeoutMs = m_timeoutAtc.valueInteger(CTimeUnit::ms());
|
||||
const qint64 timeoutAircraftEpochMs = currentTimeMsEpoch - aircraftTimeoutMs;
|
||||
const qint64 timeoutAtcEpochMs = currentTimeMsEpoch - atcTimeoutMs;
|
||||
const bool enabled = m_enabledWatchdog;
|
||||
|
||||
const QList<CCallsign> callsignsAircraft = m_aircraftCallsignTimestamps.keys();
|
||||
for (const CCallsign &callsign : callsignsAircraft) // clazy:exclude=container-anti-pattern,range-loop
|
||||
{
|
||||
if (!enabled) { m_aircraftCallsignTimestamps[callsign] = timeoutAircraftEpochMs + 1000; } // fake value so it can be re-enabled
|
||||
const qint64 tsv = m_aircraftCallsignTimestamps.value(callsign);
|
||||
if (tsv > timeoutAircraftEpochMs) { continue; }
|
||||
CLogMessage(this).debug() << "Aircraft " << callsign.toQString() << "timed out! " << (currentTimeMsEpoch - tsv) << "ms";
|
||||
@@ -174,6 +176,7 @@ namespace BlackCore
|
||||
const QList<CCallsign> callsignsAtc = m_atcCallsignTimestamps.keys();
|
||||
for (const CCallsign &callsign : callsignsAtc) // clazy:exclude=container-anti-pattern,range-loop
|
||||
{
|
||||
if (!enabled) { m_aircraftCallsignTimestamps[callsign] = timeoutAtcEpochMs + 1000; } // fake value so it can be re-enabled
|
||||
const qint64 tsv = m_aircraftCallsignTimestamps.value(callsign);
|
||||
if (m_atcCallsignTimestamps.value(callsign) > timeoutAtcEpochMs) { continue; }
|
||||
CLogMessage(this).debug() << "ATC " << callsign.toQString() << "timed out! " << (currentTimeMsEpoch - tsv) << "ms";
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#include <QReadWriteLock>
|
||||
#include <QTimer>
|
||||
#include <QtGlobal>
|
||||
#include <atomic>
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
@@ -67,6 +68,9 @@ namespace BlackCore
|
||||
INetwork *network,
|
||||
CAirspaceMonitor *airspaceMonitorParent);
|
||||
|
||||
//! Destructor
|
||||
virtual ~CAirspaceAnalyzer();
|
||||
|
||||
//! Get the latest snapshot
|
||||
//! \threadsafe
|
||||
BlackMisc::Simulation::CAirspaceAircraftSnapshot getLatestAirspaceAircraftSnapshot() const;
|
||||
@@ -74,10 +78,10 @@ namespace BlackCore
|
||||
//! Render restrictions in simulator
|
||||
void setSimulatorRenderRestrictionsChanged(bool restricted, bool enabled, int maxAircraft, const BlackMisc::PhysicalQuantities::CLength &maxRenderedDistance);
|
||||
|
||||
//! Destructor
|
||||
virtual ~CAirspaceAnalyzer();
|
||||
//! Enable/disable watchdog
|
||||
//! \remark primarily for debugging, where stopping at a breakpoint can cause multiple timeouts
|
||||
void setEnabledWatchdog(bool enabled) { m_enabledWatchdog = enabled; }
|
||||
|
||||
public slots:
|
||||
//! Clear
|
||||
void clear();
|
||||
|
||||
@@ -126,6 +130,7 @@ namespace BlackCore
|
||||
BlackMisc::PhysicalQuantities::CTime m_timeoutAircraft = { 15, BlackMisc::PhysicalQuantities::CTimeUnit::s() }; //!< Timeout value for watchdog functionality
|
||||
BlackMisc::PhysicalQuantities::CTime m_timeoutAtc = { 50, BlackMisc::PhysicalQuantities::CTimeUnit::s() }; //!< Timeout value for watchdog functionality
|
||||
qint64 m_lastWatchdogCallMsSinceEpoch; //!< when last called
|
||||
std::atomic_bool m_enabledWatchdog { true }; //!< watchdog enabled
|
||||
|
||||
// snapshot
|
||||
BlackMisc::Simulation::CAirspaceAircraftSnapshot m_latestAircraftSnapshot;
|
||||
|
||||
@@ -303,6 +303,14 @@ namespace BlackCore
|
||||
m_bookingsRequested = true;
|
||||
}
|
||||
|
||||
void CAirspaceMonitor::enableWatchdog(bool enable)
|
||||
{
|
||||
if (this->analyzer())
|
||||
{
|
||||
this->analyzer()->setEnabled(enable);
|
||||
}
|
||||
}
|
||||
|
||||
void CAirspaceMonitor::testCreateDummyOnlineAtcStations(int number)
|
||||
{
|
||||
if (number < 1) { return; }
|
||||
|
||||
@@ -118,6 +118,9 @@ namespace BlackCore
|
||||
//! Analyzer
|
||||
CAirspaceAnalyzer *analyzer() const { return m_analyzer; }
|
||||
|
||||
//! \copydoc CAirspaceAnalyzer::setEnabled
|
||||
void enableWatchdog(bool enable);
|
||||
|
||||
//! Gracefully shut down, e.g. for thread safety
|
||||
void gracefulShutdown();
|
||||
|
||||
|
||||
@@ -235,7 +235,7 @@ namespace BlackCore
|
||||
{
|
||||
Q_UNUSED(originator;)
|
||||
if (commandLine.isEmpty()) { return false; }
|
||||
static const QStringList cmds({ ".msg", ".m", ".altos", ".altoffset" });
|
||||
static const QStringList cmds({ ".msg", ".m", ".altos", ".altoffset", ".watchdog" });
|
||||
CSimpleCommandParser parser(cmds);
|
||||
parser.parse(commandLine);
|
||||
if (!parser.isKnownCommand()) { return false; }
|
||||
@@ -316,10 +316,11 @@ namespace BlackCore
|
||||
this->sendTextMessages(tml);
|
||||
return true;
|
||||
}
|
||||
else if (parser.matchesCommand(".altos", ".altoffet"))
|
||||
else if (parser.matchesCommand(".altos", ".altoffset"))
|
||||
{
|
||||
if (!m_airspace) { return false; }
|
||||
if (parser.countParts() < 2) { return false; }
|
||||
|
||||
const CCallsign cs(parser.part(1));
|
||||
if (!m_airspace->isAircraftInRange(cs))
|
||||
{
|
||||
@@ -332,17 +333,23 @@ namespace BlackCore
|
||||
{
|
||||
os.parseFromString(parser.part(2));
|
||||
}
|
||||
|
||||
const bool added = this->testAddAltitudeOffset(cs, os);
|
||||
if (added)
|
||||
{
|
||||
CLogMessage(this).info("Added altitude offset %1 for %2") << os.valueRoundedWithUnit(2) << cs.asString();
|
||||
}
|
||||
else
|
||||
{
|
||||
CLogMessage(this).info("Removed altitude offset %1") << cs.asString();
|
||||
}
|
||||
if (added) { CLogMessage(this).info("Added altitude offset %1 for %2") << os.valueRoundedWithUnit(2) << cs.asString(); }
|
||||
else { CLogMessage(this).info("Removed altitude offset %1") << cs.asString(); }
|
||||
|
||||
return true;
|
||||
}
|
||||
else if (parser.matchesCommand(".watchdog"))
|
||||
{
|
||||
if (!m_airspace) { return false; }
|
||||
if (parser.countParts() < 2) { return false; }
|
||||
|
||||
const bool watchdog = parser.toBool(1, true);
|
||||
m_airspace->enableWatchdog(watchdog);
|
||||
CLogMessage(this).info("Enabled watchdog: %1") << boolToYesNo(watchdog);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -201,9 +201,10 @@ namespace BlackCore
|
||||
{
|
||||
if (BlackMisc::CSimpleCommandParser::registered("BlackCore::CContextNetwork")) { return; }
|
||||
BlackMisc::CSimpleCommandParser::registerCommand({".m", "alias: .msg"});
|
||||
BlackMisc::CSimpleCommandParser::registerCommand({".m message <text>", "send text message"});
|
||||
BlackMisc::CSimpleCommandParser::registerCommand({".m callsign message <text>", "send text message"});
|
||||
BlackMisc::CSimpleCommandParser::registerCommand({".m message text", "send text message"});
|
||||
BlackMisc::CSimpleCommandParser::registerCommand({".m callsign message text", "send text message"});
|
||||
BlackMisc::CSimpleCommandParser::registerCommand({".altos callsign offsetvalue", "set altitude offset value (testing)"});
|
||||
BlackMisc::CSimpleCommandParser::registerCommand({".watchdog on|off", "enable/disable network watchdog (testing)"});
|
||||
}
|
||||
|
||||
//! \publicsection
|
||||
|
||||
Reference in New Issue
Block a user