From 62860eb30b3e09b2a6dca5e2f6838d4f73f356c4 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Fri, 23 Nov 2018 02:43:11 +0100 Subject: [PATCH] Ref T436, allow to set a global offset altitude for testing (example: ".altos ? -10m") --- src/blackcore/context/contextnetworkimpl.cpp | 17 +++++++--- src/blackcore/context/contextnetworkimpl.h | 2 +- .../simulation/remoteaircraftprovider.cpp | 32 ++++++++++--------- .../simulation/remoteaircraftprovider.h | 6 ++++ 4 files changed, 37 insertions(+), 20 deletions(-) diff --git a/src/blackcore/context/contextnetworkimpl.cpp b/src/blackcore/context/contextnetworkimpl.cpp index 9bd5df833..b04058bd8 100644 --- a/src/blackcore/context/contextnetworkimpl.cpp +++ b/src/blackcore/context/contextnetworkimpl.cpp @@ -364,11 +364,20 @@ namespace BlackCore if (!m_airspace) { return false; } if (parser.countParts() < 2) { return false; } - const CCallsign cs(parser.part(1)); - if (!m_airspace->isAircraftInRange(cs)) + const QString csPart(parser.part(1)); + CCallsign cs; + if (csPart.contains('?')) { - CLogMessage(this).validationError("Altitude offset unknown callsign"); - return false; + cs = IRemoteAircraftProvider::testAltitudeOffsetCallsign(); // wildcard + } + else + { + cs = CCallsign(csPart); + if (!m_airspace->isAircraftInRange(cs)) + { + CLogMessage(this).validationError("Altitude offset unknown callsign"); + return false; + } } CLength os(CLength::null()); diff --git a/src/blackcore/context/contextnetworkimpl.h b/src/blackcore/context/contextnetworkimpl.h index d7625f687..6aaa0e5e5 100644 --- a/src/blackcore/context/contextnetworkimpl.h +++ b/src/blackcore/context/contextnetworkimpl.h @@ -223,7 +223,7 @@ namespace BlackCore 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({".altos callsign offsetvalue", "set altitude offset value (testing)"}); + BlackMisc::CSimpleCommandParser::registerCommand({".altos callsign|? offsetvalue", "set altitude offset value (testing)"}); BlackMisc::CSimpleCommandParser::registerCommand({".watchdog on|off", "enable/disable network watchdog (testing)"}); BlackMisc::CSimpleCommandParser::registerCommand({".wallop message", "send a wallop message"}); BlackMisc::CSimpleCommandParser::registerCommand({".reinit", "re-initialize all aircraft"}); diff --git a/src/blackmisc/simulation/remoteaircraftprovider.cpp b/src/blackmisc/simulation/remoteaircraftprovider.cpp index e7cc678a2..50f48dc78 100644 --- a/src/blackmisc/simulation/remoteaircraftprovider.cpp +++ b/src/blackmisc/simulation/remoteaircraftprovider.cpp @@ -671,24 +671,20 @@ namespace BlackMisc return m_testOffset.contains(callsign); } + bool CRemoteAircraftProvider::hasTestAltitudeOffsetGlobalValue() const + { + QReadLocker l(&m_lockSituations); + return m_testOffset.contains(testAltitudeOffsetCallsign()); + } + CAircraftSituation CRemoteAircraftProvider::addTestAltitudeOffsetToSituation(const CAircraftSituation &situation) const { - // for global offset testing set "true" - constexpr bool globalOffsetTest = false; - const CCallsign cs(situation.getCallsign()); - // cppcheck-suppress knownConditionTrueFalse - if (!globalOffsetTest && !this->hasTestAltitudeOffset(cs)) { return situation; } - CLength os; - if (globalOffsetTest) - { - os = CLength(100, CLengthUnit::ft()); - } - else - { - QReadLocker l(&m_lockSituations); - os = m_testOffset.value(cs); - } + const bool globalOffset = this->hasTestAltitudeOffsetGlobalValue(); + if (!globalOffset && !this->hasTestAltitudeOffset(cs)) { return situation; } + + QReadLocker l(&m_lockSituations); + const CLength os = m_testOffset.contains(cs) ? m_testOffset.value(cs) : m_testOffset.value(testAltitudeOffsetCallsign()); if (os.isNull() || os.isZeroEpsilonConsidered()) { return situation; } return situation.withAltitudeOffset(os); } @@ -1047,5 +1043,11 @@ namespace BlackMisc partsList.removeBefore(ts); Q_ASSERT_X(partsList.size() >= 1, Q_FUNC_INFO, "Need at least 1 value"); } + + const CCallsign &IRemoteAircraftProvider::testAltitudeOffsetCallsign() + { + static const CCallsign wildcard("ZZZZ"); + return wildcard; + } } // namespace } // namespace diff --git a/src/blackmisc/simulation/remoteaircraftprovider.h b/src/blackmisc/simulation/remoteaircraftprovider.h index e9fe3c000..f6d5dcf3b 100644 --- a/src/blackmisc/simulation/remoteaircraftprovider.h +++ b/src/blackmisc/simulation/remoteaircraftprovider.h @@ -259,6 +259,9 @@ namespace BlackMisc //! Remove outdated aircraft parts, but never the most recent one static void removeOutdatedParts(Aviation::CAircraftPartsList &partsList); + //! Wildcard callsign + static const Aviation::CCallsign &testAltitudeOffsetCallsign(); + protected: //! Constructor IRemoteAircraftProvider(); @@ -369,6 +372,9 @@ namespace BlackMisc //! Has test offset value? bool hasTestAltitudeOffset(const Aviation::CCallsign &callsign) const; + //! Has test offset value? + bool hasTestAltitudeOffsetGlobalValue() const; + //! Offset for callsign bool testAddAltitudeOffset(const Aviation::CCallsign &callsign, const PhysicalQuantities::CLength &offset);