From f6f719a67edb2a607732a971f2cd1e762046948e Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Thu, 14 Nov 2019 19:21:34 +0100 Subject: [PATCH] [FSD] "dot" command to restrict max. range for FSD positions Allows to limit the range in which we handle FSD positions (This also means FSD planes range) --- src/blackcore/airspacemonitor.cpp | 70 +++++++++++++++----- src/blackcore/airspacemonitor.h | 55 ++++++++++----- src/blackcore/context/contextnetworkimpl.cpp | 18 +++-- src/blackcore/context/contextnetworkimpl.h | 12 ++-- 4 files changed, 107 insertions(+), 48 deletions(-) diff --git a/src/blackcore/airspacemonitor.cpp b/src/blackcore/airspacemonitor.cpp index 484a75bb7..57e8c9406 100644 --- a/src/blackcore/airspacemonitor.cpp +++ b/src/blackcore/airspacemonitor.cpp @@ -118,6 +118,9 @@ namespace BlackCore // timer connect(&m_processTimer, &QTimer::timeout, this, &CAirspaceMonitor::process); m_processTimer.start(ProcessIntervalMs); + + // dot command + CAirspaceMonitor::registerHelp(); } bool CAirspaceMonitor::updateFastPositionEnabled(const CCallsign &callsign, bool enableFastPositonUpdates) @@ -392,6 +395,28 @@ namespace BlackCore return s.join(", "); } + bool CAirspaceMonitor::parseCommandLine(const QString &commandLine, const CIdentifier &originator) + { + Q_UNUSED(originator;) + if (commandLine.isEmpty()) { return false; } + static const QStringList cmds({ ".fsd" }); + CSimpleCommandParser parser(cmds); + parser.parse(commandLine); + if (!parser.isKnownCommand()) { return false; } + if (parser.matchesCommand(".fsd")) + { + if (parser.countParts() < 2) { return false; } + if (parser.matchesPart(1, "range") && parser.countParts() > 2) + { + const QString r = parser.part(2); + CLength d; + d.parseFromString(r); + this->setMaxRange(d); + } + } + return false; + } + void CAirspaceMonitor::process() { if (this->isConnectedAndNotShuttingDown()) @@ -426,6 +451,19 @@ namespace BlackCore return aircraft.size(); } + void CAirspaceMonitor::setMaxRange(const CLength &range) + { + int rInt = 125; + if (!range.isNull()) + { + rInt = range.valueInteger(CLengthUnit::NM()); + } + + CLogMessage(this).info(u"Set airspace max. range to %1NM") << rInt; + m_maxDistanceNM = rInt; + m_maxDistanceNMHysteresis = qRound(rInt * 1.1); + } + void CAirspaceMonitor::onRealNameReplyReceived(const CCallsign &callsign, const QString &realname) { if (!this->isConnectedAndNotShuttingDown() || realname.isEmpty()) { return; } @@ -1099,9 +1137,16 @@ namespace BlackCore return c; } - void CAirspaceMonitor::copilotDetected() + bool CAirspaceMonitor::handleMaxRange(const CAircraftSituation &situation) { - // for future usage + if (situation.isNull()) { return false; } + const int distanceNM = this->getOwnAircraft().calculateGreatCircleDistance(situation).valueInteger(CLengthUnit::NM()); + if (distanceNM > m_maxDistanceNMHysteresis) + { + this->removeAircraft(situation.getCallsign()); + return false; + } + return distanceNM <= m_maxDistanceNM; } bool CAirspaceMonitor::recallFsInnPacket(const CCallsign &callsign) @@ -1144,9 +1189,6 @@ namespace BlackCore void CAirspaceMonitor::onAircraftUpdateReceived(const CAircraftSituation &situation, const CTransponder &transponder) { - static constexpr int MaxDistanceNM = 125; - static constexpr int MaxDistanceNMHysteresis = qRound(1.1 * MaxDistanceNM); - Q_ASSERT_X(CThreadUtils::isCurrentThreadObjectThread(this), Q_FUNC_INFO, "Called in different thread"); if (!this->isConnectedAndNotShuttingDown()) { return; } @@ -1156,14 +1198,8 @@ namespace BlackCore if (this->isCopilotAircraft(callsign)) { return; } const bool existsInRange = this->isAircraftInRange(callsign); - // hardcoded range (FSD overload issue) - const int distanceNM = this->getOwnAircraft().calculateGreatCircleDistance(situation).valueInteger(CLengthUnit::NM()); - if (existsInRange && distanceNM > MaxDistanceNMHysteresis) - { - this->removeClient(callsign); - return; - } - if (distanceNM > MaxDistanceNM) { return; } + // range (FSD overload issue) + if (!this->handleMaxRange(situation)) { return; } // update client info this->autoAdjustCientGndCapability(situation); @@ -1208,7 +1244,8 @@ namespace BlackCore // checks Q_ASSERT_X(!callsign.isEmpty(), Q_FUNC_INFO, "Empty callsign"); - if (isCopilotAircraft(callsign)) { return; } + if (isCopilotAircraft(callsign)) { return; } + if (!this->isAircraftInRange(callsign)) { return; } if (CBuildConfig::isLocalDeveloperDebugBuild()) { @@ -1231,9 +1268,6 @@ namespace BlackCore // store situation history this->storeAircraftSituation(interimSituation); - // if we have no aircraft in range yet, we stop here - if (!this->isAircraftInRange(callsign)) { return; } - const bool samePosition = lastSituation.equalNormalVectorDouble(interimSituation); if (samePosition) { return; } // nothing to update @@ -1334,7 +1368,7 @@ namespace BlackCore if (oldSituations.size() > 1) { const bool extrapolated = correctedSituation.extrapolateElevation(oldSituations[0], oldSituations[1], oldChanges.frontOrDefault()); - Q_UNUSED(extrapolated); + Q_UNUSED(extrapolated) } } } // gnd. elevation diff --git a/src/blackcore/airspacemonitor.h b/src/blackcore/airspacemonitor.h index fdef3e21f..93b68c002 100644 --- a/src/blackcore/airspacemonitor.h +++ b/src/blackcore/airspacemonitor.h @@ -14,9 +14,6 @@ #include "blackcore/blackcoreexport.h" #include "blackmisc/simulation/settings/modelmatchersettings.h" #include "blackmisc/simulation/aircraftmodelsetprovider.h" -#include "blackmisc/network/server.h" -#include "blackmisc/network/ecosystem.h" -#include "blackmisc/network/connectionstatus.h" #include "blackmisc/simulation/aircraftmodel.h" #include "blackmisc/simulation/airspaceaircraftsnapshot.h" #include "blackmisc/simulation/matchinglog.h" @@ -24,18 +21,22 @@ #include "blackmisc/simulation/remoteaircraftprovider.h" #include "blackmisc/simulation/simulationenvironmentprovider.h" #include "blackmisc/simulation/simulatedaircraftlist.h" +#include "blackmisc/network/server.h" +#include "blackmisc/network/ecosystem.h" +#include "blackmisc/network/connectionstatus.h" #include "blackmisc/network/clientprovider.h" #include "blackmisc/network/userlist.h" -#include "blackmisc/geo/coordinategeodetic.h" #include "blackmisc/aviation/aircraftpartslist.h" #include "blackmisc/aviation/aircraftsituationlist.h" #include "blackmisc/aviation/atcstation.h" #include "blackmisc/aviation/atcstationlist.h" #include "blackmisc/aviation/callsignset.h" #include "blackmisc/aviation/flightplan.h" +#include "blackmisc/geo/coordinategeodetic.h" #include "blackmisc/pq/frequency.h" #include "blackmisc/pq/length.h" #include "blackmisc/pq/angle.h" +#include "blackmisc/simplecommandparser.h" #include "blackmisc/identifier.h" #include @@ -52,10 +53,7 @@ namespace BlackCore { - namespace Fsd - { - class CFSDClient; - } + namespace Fsd { class CFSDClient; } class CAirspaceAnalyzer; //! Keeps track of other entities in the airspace: aircraft, ATC stations, etc. @@ -145,6 +143,9 @@ namespace BlackCore //! Re-init all aircrft int reInitializeAllAircraft(); + //! Max (FSD) range + void setMaxRange(const BlackMisc::PhysicalQuantities::CLength &range); + //! Create dummy entries for performance tests //! \private for testing purposes void testCreateDummyOnlineAtcStations(int number); @@ -171,6 +172,22 @@ namespace BlackCore static QString enumToString(MatchingReadiness r); //! @} + //! \addtogroup swiftdotcommands + //! @{ + //!
+        //! .fsd range distance        max.range e.g. ".fsd range 100NM"
+        //! 
+ //! @} + //! \copydoc BlackCore::Context::IContextNetwork::parseCommandLine + bool parseCommandLine(const QString &commandLine, const BlackMisc::CIdentifier &originator); + + //! Register help + static void registerHelp() + { + if (BlackMisc::CSimpleCommandParser::registered("BlackCore::Fsd::CFSDClient")) { return; } + BlackMisc::CSimpleCommandParser::registerCommand({".fsd range distance", "FSD max. range"}); + } + signals: //! Online ATC stations were changed void changedAtcStationsOnline(); @@ -271,11 +288,18 @@ namespace BlackCore BlackMisc::CSettingReadOnly m_matchingSettings { this }; //!< settings QQueue m_queryAtis; //!< query the ATIS QQueue m_queryPilot; //!< query the pilot data - Fsd::CFSDClient *m_fsdClient = nullptr; //!< corresponding network interface - CAirspaceAnalyzer *m_analyzer = nullptr; //!< owned analyzer - bool m_bookingsRequested = false; //!< bookings have been requested, it can happen we receive an BlackCore::Vatsim::CVatsimBookingReader::atcBookingsReadUnchanged signal - QTimer m_processTimer; + Fsd::CFSDClient *m_fsdClient = nullptr; //!< corresponding network interface + CAirspaceAnalyzer *m_analyzer = nullptr; //!< owned analyzer + bool m_bookingsRequested = false; //!< bookings have been requested, it can happen we receive an BlackCore::Vatsim::CVatsimBookingReader::atcBookingsReadUnchanged signal + int m_maxDistanceNM = 125; //!< position range / FSD range + int m_maxDistanceNMHysteresis = qRound(1.1 * m_maxDistanceNM); + + // Processing interval static constexpr int ProcessIntervalMs = 50; // in ms + QTimer m_processTimer; + + //! Processing by timer + void process(); // model matching times static constexpr qint64 MMCheckAgainMs = 2000; @@ -283,9 +307,6 @@ namespace BlackCore static constexpr qint64 MMMaxAgeThresholdMs = MMCheckAgainMs * 10; static constexpr qint64 MMVerifyMs = MMCheckAgainMs * 12; - //! Processing by timer - void process(); - //! Remove ATC online stations void removeAllOnlineAtcStations(); @@ -356,8 +377,8 @@ namespace BlackCore //! Update booked station by callsign int updateBookedStation(const BlackMisc::Aviation::CCallsign &callsign, const BlackMisc::CPropertyIndexVariantMap &vm, bool skipEqualValues = true, bool sendSignal = true); - //! Co-pilot detected - void copilotDetected(); + //! Handle max.range + bool handleMaxRange(const BlackMisc::Aviation::CAircraftSituation &situation); //! Call CAirspaceMonitor::onCustomFSInnPacketReceived with stored packet bool recallFsInnPacket(const BlackMisc::Aviation::CCallsign &callsign); diff --git a/src/blackcore/context/contextnetworkimpl.cpp b/src/blackcore/context/contextnetworkimpl.cpp index c54e723b3..78058dd08 100644 --- a/src/blackcore/context/contextnetworkimpl.cpp +++ b/src/blackcore/context/contextnetworkimpl.cpp @@ -314,7 +314,7 @@ namespace BlackCore { Q_UNUSED(originator;) if (commandLine.isEmpty()) { return false; } - static const QStringList cmds({ ".msg", ".m", ".chat", ".altos", ".altoffset", ".addtimeos", ".addtimeoffset", ".wallop", ".watchdog", ".reinit", ".reinitialize", ".enable", ".disable", ".ignore", ".unignore" }); + static const QStringList cmds({ ".msg", ".m", ".chat", ".altos", ".altoffset", ".addtimeos", ".addtimeoffset", ".wallop", ".watchdog", ".reinit", ".reinitialize", ".enable", ".disable", ".ignore", ".unignore", ".fsd" }); CSimpleCommandParser parser(cmds); parser.parse(commandLine); if (!parser.isKnownCommand()) { return false; } @@ -470,8 +470,8 @@ namespace BlackCore else if (parser.matchesCommand(".wallop")) { if (parser.countParts() < 2) { return false; } - if (!m_fsdClient) { return false; } - if (!this->isConnected()) { return false; } + if (!m_fsdClient) { return false; } + if (!this->isConnected()) { return false; } const QString wallopMsg = parser.part(1).simplified().trimmed(); m_fsdClient->sendTextMessage(TextMessageGroups::AllSups, wallopMsg); return true; @@ -479,19 +479,23 @@ namespace BlackCore else if (parser.matchesCommand(".enable", ".unignore")) { if (parser.countParts() < 2) { return false; } - if (!m_fsdClient) { return false; } - if (!this->isConnected()) { return false; } + if (!m_fsdClient) { return false; } + if (!this->isConnected()) { return false; } const CCallsign cs(parser.part(1)); if (cs.isValid()) { this->updateAircraftEnabled(cs, true); } } else if (parser.matchesCommand(".disable", ".ignore")) { if (parser.countParts() < 2) { return false; } - if (!m_fsdClient) { return false; } - if (!this->isConnected()) { return false; } + if (!m_fsdClient) { return false; } + if (!this->isConnected()) { return false; } const CCallsign cs(parser.part(1)); if (cs.isValid()) { this->updateAircraftEnabled(cs, false); } } + else if (m_airspace && parser.matchesCommand(".fsd")) + { + return m_airspace->parseCommandLine(commandLine, originator); + } return false; } diff --git a/src/blackcore/context/contextnetworkimpl.h b/src/blackcore/context/contextnetworkimpl.h index 86884743f..c0ca04f0f 100644 --- a/src/blackcore/context/contextnetworkimpl.h +++ b/src/blackcore/context/contextnetworkimpl.h @@ -219,12 +219,12 @@ namespace BlackCore //! \addtogroup swiftdotcommands //! @{ //!
-            //! .m .msg .chat              message text
-            //! .altos .altoffset          altitude offset for testing
-            //! .addtimeos .addtimeoffse   additional offset time for testing
-            //! .reinit .reinitialize      re-initialize all aircraft
-            //! .watchdog on|off           watchdog on/off
-            //! .wallop message            send wallop message
+            //! .m .msg .chat callsign|freq. message   message text
+            //! .altos .altoffset                      altitude offset for testing
+            //! .addtimeos .addtimeoffset              additional offset time for testing
+            //! .reinit .reinitialize                  re-initialize all aircraft
+            //! .watchdog on|off                       watchdog on/off
+            //! .wallop message                        send wallop message
             //! 
//! @} //! \copydoc IContextNetwork::parseCommandLine