Ref T436, allow to set a global offset altitude for testing (example: ".altos ? -10m")

This commit is contained in:
Klaus Basan
2018-11-23 02:43:11 +01:00
parent 31ba0c1520
commit 62860eb30b
4 changed files with 37 additions and 20 deletions

View File

@@ -364,12 +364,21 @@ namespace BlackCore
if (!m_airspace) { return false; } if (!m_airspace) { return false; }
if (parser.countParts() < 2) { return false; } if (parser.countParts() < 2) { return false; }
const CCallsign cs(parser.part(1)); const QString csPart(parser.part(1));
CCallsign cs;
if (csPart.contains('?'))
{
cs = IRemoteAircraftProvider::testAltitudeOffsetCallsign(); // wildcard
}
else
{
cs = CCallsign(csPart);
if (!m_airspace->isAircraftInRange(cs)) if (!m_airspace->isAircraftInRange(cs))
{ {
CLogMessage(this).validationError("Altitude offset unknown callsign"); CLogMessage(this).validationError("Altitude offset unknown callsign");
return false; return false;
} }
}
CLength os(CLength::null()); CLength os(CLength::null());
if (parser.hasPart(2)) if (parser.hasPart(2))

View File

@@ -223,7 +223,7 @@ namespace BlackCore
BlackMisc::CSimpleCommandParser::registerCommand({".m", "alias: .msg"}); BlackMisc::CSimpleCommandParser::registerCommand({".m", "alias: .msg"});
BlackMisc::CSimpleCommandParser::registerCommand({".m 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({".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({".watchdog on|off", "enable/disable network watchdog (testing)"});
BlackMisc::CSimpleCommandParser::registerCommand({".wallop message", "send a wallop message"}); BlackMisc::CSimpleCommandParser::registerCommand({".wallop message", "send a wallop message"});
BlackMisc::CSimpleCommandParser::registerCommand({".reinit", "re-initialize all aircraft"}); BlackMisc::CSimpleCommandParser::registerCommand({".reinit", "re-initialize all aircraft"});

View File

@@ -671,24 +671,20 @@ namespace BlackMisc
return m_testOffset.contains(callsign); return m_testOffset.contains(callsign);
} }
CAircraftSituation CRemoteAircraftProvider::addTestAltitudeOffsetToSituation(const CAircraftSituation &situation) const bool CRemoteAircraftProvider::hasTestAltitudeOffsetGlobalValue() 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); QReadLocker l(&m_lockSituations);
os = m_testOffset.value(cs); return m_testOffset.contains(testAltitudeOffsetCallsign());
} }
CAircraftSituation CRemoteAircraftProvider::addTestAltitudeOffsetToSituation(const CAircraftSituation &situation) const
{
const CCallsign cs(situation.getCallsign());
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; } if (os.isNull() || os.isZeroEpsilonConsidered()) { return situation; }
return situation.withAltitudeOffset(os); return situation.withAltitudeOffset(os);
} }
@@ -1047,5 +1043,11 @@ namespace BlackMisc
partsList.removeBefore(ts); partsList.removeBefore(ts);
Q_ASSERT_X(partsList.size() >= 1, Q_FUNC_INFO, "Need at least 1 value"); 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
} // namespace } // namespace

View File

@@ -259,6 +259,9 @@ namespace BlackMisc
//! Remove outdated aircraft parts, but never the most recent one //! Remove outdated aircraft parts, but never the most recent one
static void removeOutdatedParts(Aviation::CAircraftPartsList &partsList); static void removeOutdatedParts(Aviation::CAircraftPartsList &partsList);
//! Wildcard callsign
static const Aviation::CCallsign &testAltitudeOffsetCallsign();
protected: protected:
//! Constructor //! Constructor
IRemoteAircraftProvider(); IRemoteAircraftProvider();
@@ -369,6 +372,9 @@ namespace BlackMisc
//! Has test offset value? //! Has test offset value?
bool hasTestAltitudeOffset(const Aviation::CCallsign &callsign) const; bool hasTestAltitudeOffset(const Aviation::CCallsign &callsign) const;
//! Has test offset value?
bool hasTestAltitudeOffsetGlobalValue() const;
//! Offset for callsign //! Offset for callsign
bool testAddAltitudeOffset(const Aviation::CCallsign &callsign, const PhysicalQuantities::CLength &offset); bool testAddAltitudeOffset(const Aviation::CCallsign &callsign, const PhysicalQuantities::CLength &offset);