Skip to content

Commit 192c893

Browse files
authored
Merge pull request #715 from sparkfun/pcUpdates
Add separate SD for mosaic X5. Add savePossibleSettings
2 parents 7926c91 + 1a85756 commit 192c893

File tree

11 files changed

+218
-102
lines changed

11 files changed

+218
-102
lines changed

Firmware/RTK_Everywhere/Begin.ino

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,7 @@ void beginBoard()
652652
present.invertedFastPowerOff = true;
653653
present.gnss_to_uart = true;
654654
present.gnss_to_uart2 = true;
655+
present.mosaicMicroSd;
655656
present.microSdCardDetectLow = true; // Except microSD is connected to mosaic... present.microSd is false
656657

657658
present.minCno = true;

Firmware/RTK_Everywhere/GNSS.ino

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ void gnssDetectReceiverType()
198198
present.minCno = true;
199199
present.minElevation = true;
200200
present.dynamicModel = true;
201+
present.mosaicMicroSd = true;
201202
// present.needsExternalPpl = true; // Nope. No L-Band support...
202203

203204
#endif // COMPILE_MOSAICX5

Firmware/RTK_Everywhere/GNSS_Mosaic.h

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -596,8 +596,34 @@ 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+
// Check if SV is stale based on its lastSeen
617+
struct find_stale_sv
618+
{
619+
const unsigned long expireAfter_millis = 2000;
620+
unsigned long millisNow;
621+
find_stale_sv(unsigned long now) : millisNow(now) {}
622+
bool operator () (const svTracking_t& m) const
623+
{
624+
return (millisNow > (m.lastSeen + expireAfter_millis));
625+
}
626+
};
601627

602628
// Constructor
603629
GNSS_MOSAIC() : _determiningFixedPosition(true), _clkBias_ms(0),
@@ -606,8 +632,7 @@ class GNSS_MOSAIC : GNSS
606632
_antennaIsOpen(false), _antennaIsShorted(false),
607633
GNSS()
608634
{
609-
svInTracking.clear();
610-
//svInPVT.clear();
635+
svInTracking.clear();
611636
}
612637

613638
// If we have decryption keys, configure module

Firmware/RTK_Everywhere/GNSS_Mosaic.ino

Lines changed: 64 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -26,30 +26,46 @@ GNSS_Mosaic.ino
2626
// File type "1" is NMEA
2727
//==============================================================================
2828

29-
//----------------------------------------
30-
// Control the messages that get logged to SD
31-
//----------------------------------------
32-
void menuLogMosaic()
29+
void printMosaicCardSpace()
3330
{
34-
bool applyChanges = false;
35-
36-
while (1)
31+
// mosaicSdCardSize and mosaicSdFreeSpace are updated via the SBF 4059 (storeBlock4059)
32+
if (present.mosaicMicroSd)
3733
{
38-
systemPrintln();
39-
systemPrintln("Menu: Logging");
40-
4134
char sdCardSizeChar[20];
4235
String cardSize;
43-
stringHumanReadableSize(cardSize, sdCardSize);
36+
stringHumanReadableSize(cardSize, mosaicSdCardSize);
4437
cardSize.toCharArray(sdCardSizeChar, sizeof(sdCardSizeChar));
4538
char sdFreeSpaceChar[20];
4639
String freeSpace;
47-
stringHumanReadableSize(freeSpace, sdFreeSpace);
40+
stringHumanReadableSize(freeSpace, mosaicSdFreeSpace);
4841
freeSpace.toCharArray(sdFreeSpaceChar, sizeof(sdFreeSpaceChar));
4942

43+
// On Facet mosaic, the SD is connected directly to the X5 and is accessible
44+
// On Facet Flex X5, the internal mosaic SD card is not accessible
5045
char myString[70];
5146
snprintf(myString, sizeof(myString), "SD card size: %s / Free space: %s", sdCardSizeChar, sdFreeSpaceChar);
5247
systemPrintln(myString);
48+
}
49+
}
50+
51+
//----------------------------------------
52+
// Control the messages that get logged to SD
53+
//----------------------------------------
54+
void menuLogMosaic()
55+
{
56+
if (!present.mosaicMicroSd) // This may be needed for the G5 P3 ?
57+
return;
58+
59+
bool applyChanges = false;
60+
61+
while (1)
62+
{
63+
systemPrintln();
64+
systemPrintln("Menu: Mosaic Logging");
65+
systemPrintln();
66+
67+
printMosaicCardSpace();
68+
systemPrintln();
5369

5470
systemPrint("1) Log NMEA to microSD: ");
5571
if (settings.enableLogging == true)
@@ -2576,58 +2592,44 @@ void GNSS_MOSAIC::storeBlock4013(SEMP_PARSE_STATE *parse)
25762592

25772593
if (Tracking)
25782594
{
2579-
// SV is being tracked. If it is not in svInTracking, add it
2580-
std::vector<uint8_t>::iterator pos = std::find(svInTracking.begin(), svInTracking.end(), SVID);
2581-
if (pos == svInTracking.end())
2582-
svInTracking.push_back(SVID);
2595+
// SV is being tracked
2596+
std::vector<svTracking_t>::iterator pos = std::find_if(svInTracking.begin(), svInTracking.end(), find_sv(SVID));
2597+
if (pos == svInTracking.end()) // If it is not in svInTracking, add it
2598+
svInTracking.push_back({SVID, millis()});
2599+
else // Update lastSeen
2600+
{
2601+
svTracking_t sv = *pos;
2602+
sv.lastSeen = millis();
2603+
*pos = sv;
2604+
}
25832605
}
25842606
else
25852607
{
25862608
// SV is not being tracked. If it is in svInTracking, remove it
2587-
std::vector<uint8_t>::iterator pos = std::find(svInTracking.begin(), svInTracking.end(), SVID);
2609+
std::vector<svTracking_t>::iterator pos = std::find_if(svInTracking.begin(), svInTracking.end(), find_sv(SVID));
25882610
if (pos != svInTracking.end())
25892611
svInTracking.erase(pos);
25902612
}
2591-
2592-
// uint16_t PVTStatus = sempSbfGetU2(parse, 20 + ChannelInfoBytes + SB1Length + (j * SB2Length) + 4);
2593-
2594-
// bool Used = false;
2595-
// for (uint16_t shift = 0; shift < 16; shift += 2) // Step through each 2-bit status field
2596-
// {
2597-
// if ((PVTStatus & (0x0003 << shift)) == (0x0002 << shift)) // 2 : Used
2598-
// {
2599-
// Used = true;
2600-
// }
2601-
// }
2602-
2603-
// if (Used)
2604-
// {
2605-
// // SV is being used for PVT. If it is not in svInPVT, add it
2606-
// std::vector<uint8_t>::iterator pos =
2607-
// std::find(svInPVT.begin(), svInPVT.end(), SVID);
2608-
// if (pos == svInPVT.end())
2609-
// svInPVT.push_back(SVID);
2610-
// }
2611-
// else
2612-
// {
2613-
// // SV is not being used for PVT. If it is in svInPVT, remove it
2614-
// std::vector<uint8_t>::iterator pos =
2615-
// std::find(svInPVT.begin(), svInPVT.end(), SVID);
2616-
// if (pos != svInPVT.end())
2617-
// svInPVT.erase(pos);
2618-
// }
26192613
}
26202614

26212615
ChannelInfoBytes += SB1Length + (N2 * SB2Length);
26222616
}
26232617

2618+
// Erase stale SVs
2619+
bool keepGoing = true;
2620+
while (keepGoing)
2621+
{
2622+
std::vector<svTracking_t>::iterator pos = std::find_if(svInTracking.begin(), svInTracking.end(), find_stale_sv(millis()));
2623+
if (pos != svInTracking.end())
2624+
svInTracking.erase(pos);
2625+
else
2626+
keepGoing = false;
2627+
}
2628+
26242629
_satellitesInView = (uint8_t)std::distance(svInTracking.begin(), svInTracking.end());
26252630

26262631
// if (settings.debugGnss && !inMainMenu)
2627-
// {
2628-
// uint8_t _inPVT = (uint8_t)std::distance(svInPVT.begin(), svInPVT.end());
2629-
// systemPrintf("ChannelStatus: InTracking %d, InPVT %d\r\n", _satellitesInView, _inPVT);
2630-
// }
2632+
// systemPrintf("ChannelStatus: InTracking %d\r\n", _satellitesInView);
26312633
}
26322634

26332635
//----------------------------------------
@@ -2651,6 +2653,9 @@ void GNSS_MOSAIC::storeBlock4014(SEMP_PARSE_STATE *parse)
26512653
//----------------------------------------
26522654
void GNSS_MOSAIC::storeBlock4059(SEMP_PARSE_STATE *parse)
26532655
{
2656+
if (!present.mosaicMicroSd)
2657+
return;
2658+
26542659
if (sempSbfGetU1(parse, 14) < 1) // Check N is at least 1
26552660
return;
26562661

@@ -2670,9 +2675,15 @@ void GNSS_MOSAIC::storeBlock4059(SEMP_PARSE_STATE *parse)
26702675

26712676
uint64_t diskUsage = (diskUsageMSB * 4294967296) + diskUsageLSB;
26722677

2673-
sdCardSize = diskSizeMB * 1048576; // Convert to bytes
2678+
mosaicSdCardSize = diskSizeMB * 1048576; // Convert to bytes
2679+
2680+
mosaicSdFreeSpace = mosaicSdCardSize - diskUsage;
26742681

2675-
sdFreeSpace = sdCardSize - diskUsage;
2682+
if (!present.microSd) // Overwrite - if this is the only SD card
2683+
{
2684+
sdCardSize = mosaicSdCardSize;
2685+
sdFreeSpace = mosaicSdFreeSpace;
2686+
}
26762687

26772688
_diskStatusSeen = true;
26782689
}
@@ -2975,7 +2986,7 @@ bool GNSS_MOSAIC::isPresentOnSerial(HardwareSerial *serialPort, const char *comm
29752986

29762987
if (retries == retryLimit)
29772988
{
2978-
systemPrintln("Could not communicate with mosaic-X5! Attempting a soft reset...");
2989+
systemPrintln("Could not communicate with mosaic-X5 at selected baud rate. Attempting a soft reset...");
29792990

29802991
sendWithResponse(serialPort, "erst,soft,none\n\r", "ResetReceiver");
29812992

@@ -2991,7 +3002,7 @@ bool GNSS_MOSAIC::isPresentOnSerial(HardwareSerial *serialPort, const char *comm
29913002

29923003
if (retries == retryLimit)
29933004
{
2994-
systemPrintln("Could not communicate with mosaic-X5!");
3005+
systemPrintln("Could not communicate with mosaic-X5 at selected baud rate");
29953006
return(false);
29963007
}
29973008
}

Firmware/RTK_Everywhere/NVM.ino

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,21 @@ void recordSystemSettingsToFile(File *settingsFile)
227227
for (int i = 0; i < numRtkSettingsEntries; i++)
228228
{
229229
// Do not record this setting if it is not supported by the current platform
230-
if (settingAvailableOnPlatform(i) == false)
231-
continue;
230+
// But oh what a tangled web we weave...
231+
// Thanks to Facet Flex, initially we should be saving all possible settings.
232+
// Later, once we know what Flex GNSS is present, we save only the available
233+
// settings for that platform. Passing usePossibleSettings in as a parameter
234+
// would be messy. So, we'll use a global flag which is updated by commandIndexFill
235+
if (savePossibleSettings)
236+
{
237+
if (settingPossibleOnPlatform(i) == false)
238+
continue;
239+
}
240+
else
241+
{
242+
if (settingAvailableOnPlatform(i) == false)
243+
continue;
244+
}
232245

233246
switch (rtkSettingsEntries[i].type)
234247
{
@@ -1675,7 +1688,7 @@ bool parseLine(char *str)
16751688
// Last catch
16761689
if (knownSetting == false)
16771690
{
1678-
log_d("Unknown setting %s", settingName);
1691+
log_d("Unknown / unwanted setting %s", settingName);
16791692
}
16801693

16811694
return (true);

Firmware/RTK_Everywhere/RTK_Everywhere.ino

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,8 @@ const char *ringBufferSemaphoreHolder = "None";
368368
// Display used/free space in menu and config page
369369
uint64_t sdCardSize;
370370
uint64_t sdFreeSpace;
371+
uint64_t mosaicSdCardSize;
372+
uint64_t mosaicSdFreeSpace;
371373
bool outOfSDSpace;
372374
const uint32_t sdMinAvailableSpace = 10000000; // Minimum available bytes before SD is marked as out of space
373375

@@ -390,6 +392,9 @@ const int sdSizeCheckStackSize = 3000;
390392
bool sdSizeCheckTaskComplete;
391393

392394
char logFileName[sizeof("SFE_Reference_Station_230101_120101.ubx_plusExtraSpace")] = {0};
395+
396+
bool savePossibleSettings = true; // Save possible vs. available settings. See recordSystemSettingsToFile for details
397+
393398
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
394399

395400
// WiFi support
@@ -1310,9 +1315,7 @@ void setup()
13101315
gnssDetectReceiverType(); // If we don't know the receiver from the platform, auto-detect it. Uses settings.
13111316

13121317
DMW_b("commandIndexFillActual");
1313-
recordSystemSettings(); // Ensure the possible settings are saved - before we call commandIndexFillActual
13141318
commandIndexFillActual(); // Shrink the commandIndex table now we're certain what GNSS we have
1315-
loadSettings(); // Reload the settings after shrinking commandIndex
13161319
recordSystemSettings(); // Save the reduced settings now we're certain what GNSS we have
13171320

13181321
DMW_b("beginGnssUart");
@@ -1589,12 +1592,14 @@ void logUpdate()
15891592
{
15901593
if (logTimeExceeded())
15911594
{
1592-
systemPrintln("Log file: maximum logging time reached");
1595+
if (!inMainMenu)
1596+
systemPrintln("Log file: maximum logging time reached");
15931597
endSD(false, true); // Close down SD.
15941598
}
15951599
else
15961600
{
1597-
systemPrintln("Log file: log length reached");
1601+
if (!inMainMenu)
1602+
systemPrintln("Log file: log length reached");
15981603
endLogging(false, true); //(gotSemaphore, releaseSemaphore) Close file. Reset parser stats.
15991604
beginLogging(); // Create new file based on current RTC.
16001605
setLoggingType(); // Determine if we are standard, PPP, or custom. Changes logging icon accordingly.
@@ -1610,7 +1615,7 @@ void logUpdate()
16101615
{
16111616
lastFileReport = millis();
16121617

1613-
if (settings.enablePrintLogFileStatus)
1618+
if ((settings.enablePrintLogFileStatus) && (!inMainMenu))
16141619
{
16151620
systemPrintf("Log file size: %lld", logFileSize);
16161621

Firmware/RTK_Everywhere/Tasks.ino

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1600,7 +1600,7 @@ void handleGnssDataTask(void *e)
16001600
}
16011601
}
16021602

1603-
if (PERIODIC_DISPLAY(PD_SD_LOG_WRITE) && (bytesSent > 0))
1603+
if (PERIODIC_DISPLAY(PD_SD_LOG_WRITE) && (bytesSent > 0) && (!inMainMenu))
16041604
{
16051605
PERIODIC_CLEAR(PD_SD_LOG_WRITE);
16061606
systemPrintf("SD %d bytes written to log file\r\n", bytesToSend);
@@ -1613,7 +1613,7 @@ void handleGnssDataTask(void *e)
16131613
{
16141614
newEventToRecord = false;
16151615

1616-
if (settings.enablePrintLogFileStatus)
1616+
if ((settings.enablePrintLogFileStatus) && (!inMainMenu))
16171617
systemPrintln("Log file: recording event");
16181618

16191619
// Record trigger count with Time Of Week of rising edge (ms), Millisecond fraction of Time Of Week of
@@ -1651,7 +1651,7 @@ void handleGnssDataTask(void *e)
16511651
char ARPData[82]; // Max NMEA sentence length is 82
16521652
snprintf(ARPData, sizeof(ARPData), "%.4f,%.4f,%.4f,%.4f", x, y, z, h);
16531653

1654-
if (settings.enablePrintLogFileStatus)
1654+
if ((settings.enablePrintLogFileStatus) && (!inMainMenu))
16551655
systemPrintf("Log file: recording Antenna Reference Position %s\r\n", ARPData);
16561656

16571657
char nmeaMessage[82]; // Max NMEA sentence length is 82

Firmware/RTK_Everywhere/menuCommands.ino

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3548,6 +3548,8 @@ bool commandIndexFillActual()
35483548
}
35493549
bool commandIndexFill(bool usePossibleSettings)
35503550
{
3551+
savePossibleSettings = usePossibleSettings; // Update savePossibleSettings
3552+
35513553
int i;
35523554
const char *iCommandName;
35533555
int j;

Firmware/RTK_Everywhere/menuMain.ino

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -234,12 +234,8 @@ void menuMain()
234234
menuBase();
235235
else if (incoming == 4)
236236
menuPorts();
237-
#ifdef COMPILE_MOSAICX5
238-
else if (incoming == 5 && productVariant == RTK_FACET_MOSAIC)
239-
menuLogMosaic();
240-
#endif // COMPILE_MOSAICX5
241237
else if (incoming == 5 && productVariant != RTK_TORCH) // Torch does not have logging
242-
menuLog();
238+
menuLogSelection();
243239
else if (incoming == 6)
244240
menuWiFi();
245241
else if (incoming == 7)

0 commit comments

Comments
 (0)