Skip to content

Commit 44d9816

Browse files
committed
Erase stale SVs from svInTracking
1 parent 06b02fe commit 44d9816

File tree

2 files changed

+42
-38
lines changed

2 files changed

+42
-38
lines changed

Firmware/RTK_Everywhere/GNSS_Mosaic.h

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -596,8 +596,33 @@ class GNSS_MOSAIC : GNSS
596596
float _lonStdDev;
597597
bool _receiverSetupSeen;
598598
bool _diskStatusSeen;
599-
std::vector<uint8_t> svInTracking;
600-
//std::vector<uint8_t> svInPVT;
599+
struct svTracking_t
600+
{
601+
uint8_t SVID;
602+
unsigned long lastSeen;
603+
};
604+
std::vector<svTracking_t> svInTracking;
605+
// Find sv in the vector of svTracking_t
606+
// https://stackoverflow.com/a/590005
607+
struct find_sv
608+
{
609+
uint8_t findThisSv;
610+
find_sv(uint8_t sv) : findThisSv(sv) {}
611+
bool operator () (const svTracking_t& m) const
612+
{
613+
return m.SVID == findThisSv;
614+
}
615+
};
616+
struct find_stale_sv
617+
{
618+
const unsigned long expireAfter_millis = 10000;
619+
unsigned long millisNow;
620+
find_stale_sv(unsigned long now) : millisNow(now) {}
621+
bool operator () (const svTracking_t& m) const
622+
{
623+
return (millisNow > (m.lastSeen + expireAfter_millis));
624+
}
625+
};
601626

602627
// Constructor
603628
GNSS_MOSAIC() : _determiningFixedPosition(true), _clkBias_ms(0),
@@ -607,7 +632,6 @@ class GNSS_MOSAIC : GNSS
607632
GNSS()
608633
{
609634
svInTracking.clear();
610-
//svInPVT.clear();
611635
}
612636

613637
// If we have decryption keys, configure module

Firmware/RTK_Everywhere/GNSS_Mosaic.ino

Lines changed: 15 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2593,57 +2593,37 @@ void GNSS_MOSAIC::storeBlock4013(SEMP_PARSE_STATE *parse)
25932593
if (Tracking)
25942594
{
25952595
// SV is being tracked. If it is not in svInTracking, add it
2596-
std::vector<uint8_t>::iterator pos = std::find(svInTracking.begin(), svInTracking.end(), SVID);
2596+
std::vector<svTracking_t>::iterator pos = std::find_if(svInTracking.begin(), svInTracking.end(), find_sv(SVID));
25972597
if (pos == svInTracking.end())
2598-
svInTracking.push_back(SVID);
2598+
svInTracking.push_back({SVID, millis()});
25992599
}
26002600
else
26012601
{
26022602
// SV is not being tracked. If it is in svInTracking, remove it
2603-
std::vector<uint8_t>::iterator pos = std::find(svInTracking.begin(), svInTracking.end(), SVID);
2603+
std::vector<svTracking_t>::iterator pos = std::find_if(svInTracking.begin(), svInTracking.end(), find_sv(SVID));
26042604
if (pos != svInTracking.end())
26052605
svInTracking.erase(pos);
26062606
}
2607-
2608-
// uint16_t PVTStatus = sempSbfGetU2(parse, 20 + ChannelInfoBytes + SB1Length + (j * SB2Length) + 4);
2609-
2610-
// bool Used = false;
2611-
// for (uint16_t shift = 0; shift < 16; shift += 2) // Step through each 2-bit status field
2612-
// {
2613-
// if ((PVTStatus & (0x0003 << shift)) == (0x0002 << shift)) // 2 : Used
2614-
// {
2615-
// Used = true;
2616-
// }
2617-
// }
2618-
2619-
// if (Used)
2620-
// {
2621-
// // SV is being used for PVT. If it is not in svInPVT, add it
2622-
// std::vector<uint8_t>::iterator pos =
2623-
// std::find(svInPVT.begin(), svInPVT.end(), SVID);
2624-
// if (pos == svInPVT.end())
2625-
// svInPVT.push_back(SVID);
2626-
// }
2627-
// else
2628-
// {
2629-
// // SV is not being used for PVT. If it is in svInPVT, remove it
2630-
// std::vector<uint8_t>::iterator pos =
2631-
// std::find(svInPVT.begin(), svInPVT.end(), SVID);
2632-
// if (pos != svInPVT.end())
2633-
// svInPVT.erase(pos);
2634-
// }
26352607
}
26362608

26372609
ChannelInfoBytes += SB1Length + (N2 * SB2Length);
26382610
}
26392611

2612+
// Erase stale SVs
2613+
bool keepGoing = true;
2614+
while (keepGoing)
2615+
{
2616+
std::vector<svTracking_t>::iterator pos = std::find_if(svInTracking.begin(), svInTracking.end(), find_stale_sv(millis()));
2617+
if (pos != svInTracking.end())
2618+
svInTracking.erase(pos);
2619+
else
2620+
keepGoing = false;
2621+
}
2622+
26402623
_satellitesInView = (uint8_t)std::distance(svInTracking.begin(), svInTracking.end());
26412624

26422625
// if (settings.debugGnss && !inMainMenu)
2643-
// {
2644-
// uint8_t _inPVT = (uint8_t)std::distance(svInPVT.begin(), svInPVT.end());
2645-
// systemPrintf("ChannelStatus: InTracking %d, InPVT %d\r\n", _satellitesInView, _inPVT);
2646-
// }
2626+
// systemPrintf("ChannelStatus: InTracking %d\r\n", _satellitesInView);
26472627
}
26482628

26492629
//----------------------------------------

0 commit comments

Comments
 (0)