mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-05-04 00:45:46 +08:00
Ref T243, verify parts/positions order (latest first)
This commit is contained in:
@@ -1288,10 +1288,11 @@ namespace BlackCore
|
|||||||
// list from new to old
|
// list from new to old
|
||||||
QWriteLocker lock(&m_lockSituations);
|
QWriteLocker lock(&m_lockSituations);
|
||||||
CAircraftSituationList &situationList = m_situationsByCallsign[callsign];
|
CAircraftSituationList &situationList = m_situationsByCallsign[callsign];
|
||||||
situationList.push_frontMaxElements(situation, MaxSituationsPerCallsign);
|
situationList.push_frontMaxElements(situation, IRemoteAircraftProvider::MaxSituationsPerCallsign);
|
||||||
|
|
||||||
// check sort order
|
// check sort order
|
||||||
Q_ASSERT_X(situationList.size() < 2 || situationList[0].getMSecsSinceEpoch() >= situationList[1].getMSecsSinceEpoch(), Q_FUNC_INFO, "wrong sort order");
|
Q_ASSERT_X(situationList.isSortedAdjustedLatestFirst(), Q_FUNC_INFO, "wrong sort order");
|
||||||
|
Q_ASSERT_X(situationList.size() <= IRemoteAircraftProvider::MaxSituationsPerCallsign, Q_FUNC_INFO, "Wrong size");
|
||||||
}
|
}
|
||||||
|
|
||||||
void CAirspaceMonitor::storeAircraftParts(const CCallsign &callsign, const CAircraftParts &parts)
|
void CAirspaceMonitor::storeAircraftParts(const CCallsign &callsign, const CAircraftParts &parts)
|
||||||
@@ -1311,7 +1312,8 @@ namespace BlackCore
|
|||||||
m_aircraftSupportingParts.insert(callsign); // mark as callsign which supports parts
|
m_aircraftSupportingParts.insert(callsign); // mark as callsign which supports parts
|
||||||
|
|
||||||
// check sort order
|
// check sort order
|
||||||
Q_ASSERT_X(partsList.size() < 2 || partsList[0].getMSecsSinceEpoch() >= partsList[1].getMSecsSinceEpoch(), Q_FUNC_INFO, "wrong sort order");
|
Q_ASSERT_X(partsList.isSortedAdjustedLatestFirst(), Q_FUNC_INFO, "wrong sort order");
|
||||||
|
Q_ASSERT_X(partsList.size() <= IRemoteAircraftProvider::MaxPartsPerCallsign, Q_FUNC_INFO, "Wrong size");
|
||||||
}
|
}
|
||||||
|
|
||||||
void CAirspaceMonitor::sendInitialAtcQueries(const CCallsign &callsign)
|
void CAirspaceMonitor::sendInitialAtcQueries(const CCallsign &callsign)
|
||||||
|
|||||||
@@ -236,9 +236,15 @@ namespace BlackMisc
|
|||||||
return emptyParts;
|
return emptyParts;
|
||||||
}
|
}
|
||||||
|
|
||||||
// find the first parts not in the correct order, keep only the parts before that one
|
// with the latest updates of T243 the order and the offsets are supposed to be correct
|
||||||
const auto end = std::is_sorted_until(m_aircraftParts.begin(), m_aircraftParts.end(), [](auto && a, auto && b) { return b.getAdjustedMSecsSinceEpoch() < a.getAdjustedMSecsSinceEpoch(); });
|
// so even mixing fast/slow updates shall work
|
||||||
const auto validParts = makeRange(m_aircraftParts.begin(), end);
|
Q_ASSERT_X(m_aircraftParts.isSortedAdjustedLatestFirst(), Q_FUNC_INFO, "Wrong sort order");
|
||||||
|
|
||||||
|
// Ref T243, KB 2018-02, can be removed in future, we verify parts above
|
||||||
|
// Parts are supposed to be in correct order
|
||||||
|
// const auto end = std::is_sorted_until(m_aircraftParts.begin(), m_aircraftParts.end(), [](auto && a, auto && b) { return b.getAdjustedMSecsSinceEpoch() < a.getAdjustedMSecsSinceEpoch(); });
|
||||||
|
// const auto validParts = makeRange(m_aircraftParts.begin(), end);
|
||||||
|
const CAircraftPartsList &validParts = m_aircraftParts;
|
||||||
|
|
||||||
// stop if we don't have any parts
|
// stop if we don't have any parts
|
||||||
if (validParts.isEmpty()) { return {}; }
|
if (validParts.isEmpty()) { return {}; }
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
#include "blackmisc/simulation/interpolationhints.h"
|
#include "blackmisc/simulation/interpolationhints.h"
|
||||||
#include "blackmisc/logmessage.h"
|
#include "blackmisc/logmessage.h"
|
||||||
#include "blackmisc/compare.h"
|
#include "blackmisc/compare.h"
|
||||||
|
#include "blackmisc/verify.h"
|
||||||
#include "blackmisc/range.h"
|
#include "blackmisc/range.h"
|
||||||
#include "blackmisc/sequence.h"
|
#include "blackmisc/sequence.h"
|
||||||
#include "blackmisc/statusmessage.h"
|
#include "blackmisc/statusmessage.h"
|
||||||
@@ -55,12 +56,18 @@ namespace BlackMisc
|
|||||||
Q_UNUSED(hints);
|
Q_UNUSED(hints);
|
||||||
status.reset();
|
status.reset();
|
||||||
|
|
||||||
// find the first situation not in the correct order, keep only the situations before that one
|
// with the latest updates of T243 the order and the offsets are supposed to be correct
|
||||||
// any updates in wrong chronological order are discounted
|
// so even mixing fast/slow updates shall work
|
||||||
const auto end = std::is_sorted_until(m_aircraftSituations.begin(), m_aircraftSituations.end(), [](auto && a, auto && b) { return b.getAdjustedMSecsSinceEpoch() < a.getAdjustedMSecsSinceEpoch(); });
|
BLACK_VERIFY_X(m_aircraftSituations.isSortedAdjustedLatestFirst(), Q_FUNC_INFO, "Wrong sort order");
|
||||||
const auto validSituations = makeRange(m_aircraftSituations.begin(), end);
|
Q_ASSERT_X(m_aircraftSituations.size() <= IRemoteAircraftProvider::MaxSituationsPerCallsign, Q_FUNC_INFO, "Wrong size");
|
||||||
|
|
||||||
|
// Ref T243, KB 2018-02, can be removed in future, we verify situations above
|
||||||
|
// Situations are supposed to be in correct order
|
||||||
|
// const auto end = std::is_sorted_until(m_aircraftSituations.begin(), m_aircraftSituations.end(), [](auto && a, auto && b) { return b.getAdjustedMSecsSinceEpoch() < a.getAdjustedMSecsSinceEpoch(); });
|
||||||
|
// const auto validSituations = makeRange(m_aircraftSituations.begin(), end);
|
||||||
|
|
||||||
// find the first situation earlier than the current time
|
// find the first situation earlier than the current time
|
||||||
|
const CAircraftSituationList &validSituations = m_aircraftSituations; // if needed, we could also copy here
|
||||||
const auto pivot = std::partition_point(validSituations.begin(), validSituations.end(), [ = ](auto && s) { return s.getAdjustedMSecsSinceEpoch() > currentTimeMsSinceEpoc; });
|
const auto pivot = std::partition_point(validSituations.begin(), validSituations.end(), [ = ](auto && s) { return s.getAdjustedMSecsSinceEpoch() > currentTimeMsSinceEpoc; });
|
||||||
const auto situationsNewer = makeRange(validSituations.begin(), pivot);
|
const auto situationsNewer = makeRange(validSituations.begin(), pivot);
|
||||||
const auto situationsOlder = makeRange(pivot, validSituations.end());
|
const auto situationsOlder = makeRange(pivot, validSituations.end());
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
#include "blackmisc/simulation/interpolatorspline.h"
|
#include "blackmisc/simulation/interpolatorspline.h"
|
||||||
#include "blackmisc/simulation/interpolationhints.h"
|
#include "blackmisc/simulation/interpolationhints.h"
|
||||||
#include "blackmisc/logmessage.h"
|
#include "blackmisc/logmessage.h"
|
||||||
|
#include "blackmisc/verify.h"
|
||||||
|
|
||||||
using namespace BlackMisc::Aviation;
|
using namespace BlackMisc::Aviation;
|
||||||
using namespace BlackMisc::Geo;
|
using namespace BlackMisc::Geo;
|
||||||
@@ -104,15 +105,18 @@ namespace BlackMisc
|
|||||||
// recalculate derivatives only if they changed
|
// recalculate derivatives only if they changed
|
||||||
if (currentTimeMsSinceEpoc > m_nextSampleAdjustedTime)
|
if (currentTimeMsSinceEpoc > m_nextSampleAdjustedTime)
|
||||||
{
|
{
|
||||||
// find the first situation not in the correct order, keep only the situations before that one
|
// with the latest updates of T243 the order and the offsets are supposed to be correct
|
||||||
//! \todo KB 2-2018, IMHO the sorting by adjusted times is wrong. we should sort by received time
|
// so even mixing fast/slow updates shall work
|
||||||
// when mixing fast/slow updates, the postion is represented when it is sent, not when it is used
|
Q_ASSERT_X(m_aircraftSituations.isSortedAdjustedLatestFirst(), Q_FUNC_INFO, "Wrong sort order");
|
||||||
// see example below
|
Q_ASSERT_X(m_aircraftSituations.size() <= IRemoteAircraftProvider::MaxSituationsPerCallsign, Q_FUNC_INFO, "Wrong size");
|
||||||
// so why do we check here only, and do not sort
|
|
||||||
const auto end = std::is_sorted_until(m_aircraftSituations.begin(), m_aircraftSituations.end(), [](auto && a, auto && b) { return b.getAdjustedMSecsSinceEpoch() < a.getAdjustedMSecsSinceEpoch(); });
|
// Ref T243, KB 2018-02, can be removed in future, we verify situations above
|
||||||
const auto validSituations = makeRange(m_aircraftSituations.begin(), end);
|
// Situations are supposed to be in correct order
|
||||||
|
// const auto end = std::is_sorted_until(m_aircraftSituations.begin(), m_aircraftSituations.end(), [](auto && a, auto && b) { return b.getAdjustedMSecsSinceEpoch() < a.getAdjustedMSecsSinceEpoch(); });
|
||||||
|
// const auto validSituations = makeRange(m_aircraftSituations.begin(), end);
|
||||||
|
|
||||||
// find the first situation earlier than the current time
|
// find the first situation earlier than the current time
|
||||||
|
const CAircraftSituationList &validSituations = m_aircraftSituations; // if needed, we could also copy here
|
||||||
const auto pivot = std::partition_point(validSituations.begin(), validSituations.end(), [ = ](auto && s) { return s.getAdjustedMSecsSinceEpoch() > currentTimeMsSinceEpoc; });
|
const auto pivot = std::partition_point(validSituations.begin(), validSituations.end(), [ = ](auto && s) { return s.getAdjustedMSecsSinceEpoch() > currentTimeMsSinceEpoc; });
|
||||||
const auto situationsNewer = makeRange(validSituations.begin(), pivot);
|
const auto situationsNewer = makeRange(validSituations.begin(), pivot);
|
||||||
const auto situationsOlder = makeRange(pivot, validSituations.end());
|
const auto situationsOlder = makeRange(pivot, validSituations.end());
|
||||||
|
|||||||
Reference in New Issue
Block a user