Skip to content

Commit a4dca6b

Browse files
committed
mosaic-X5 : better disk use reporting using DiskStatus
1 parent 79cfb30 commit a4dca6b

File tree

2 files changed

+54
-119
lines changed

2 files changed

+54
-119
lines changed

Firmware/RTK_Everywhere/GNSS_Mosaic.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ typedef struct {
1919
const mosaicExpectedID mosaicExpectedIDs[] = {
2020
{ 4007, true, 96, "PVTGeodetic" },
2121
{ 4013, false, 0, "ChannelStatus" },
22+
{ 4059, false, 0, "DiskStatus" },
2223
{ 4090, false, 0, "InputLink" },
2324
{ 4097, false, 0, "EncapsulatedOutput" },
2425
{ 5914, true, 24, "ReceiverTime" },
@@ -47,9 +48,10 @@ const mosaicExpectedID mosaicExpectedIDs[] = {
4748
// This indicates if RTCM corrections are being received - on COM2
4849
#define MOSAIC_SBF_INPUTLINK_STREAM (MOSAIC_SBF_EXTEVENT_STREAM + 1)
4950

50-
// Output SBF ChannelStatus messages on this stream - on COM1 only
51-
// These provide the count of satellites being tracked
52-
#define MOSAIC_SBF_CHANNELSTATUS_STREAM (MOSAIC_SBF_INPUTLINK_STREAM + 1)
51+
// Output SBF ChannelStatus and DiskStatus messages on this stream - on COM1 only
52+
// ChannelStatus provides the count of satellites being tracked
53+
// DiskStatus provides the disk usage
54+
#define MOSAIC_SBF_STATUS_STREAM (MOSAIC_SBF_INPUTLINK_STREAM + 1)
5355

5456
// TODO: allow the user to define their own SBF stream for logging to DSK1 - through the menu / web config
5557
// But, in the interim, the user can define their own SBF stream (>= Stream3) via the X5 web page over USB-C
@@ -1029,6 +1031,9 @@ class GNSS_MOSAIC : GNSS
10291031
// Save the data from the SBF Block 4013
10301032
void storeBlock4013(SEMP_PARSE_STATE *parse);
10311033

1034+
// Save the data from the SBF Block 4059
1035+
void storeBlock4059(SEMP_PARSE_STATE *parse);
1036+
10321037
// Save the data from the SBF Block 4090
10331038
void storeBlock4090(SEMP_PARSE_STATE *parse);
10341039

@@ -1049,11 +1054,9 @@ class GNSS_MOSAIC : GNSS
10491054
// Poll routine to update the GNSS state
10501055
void update();
10511056

1052-
bool updateSD();
1057+
void updateSD();
10531058

10541059
void waitSBFReceiverSetup(unsigned long timeout);
1055-
1056-
void waitSBFDiskStatus(unsigned long timeout);
10571060
};
10581061

10591062
#endif // __GNSS_MOSAIC_H__

Firmware/RTK_Everywhere/GNSS_Mosaic.ino

Lines changed: 45 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -579,9 +579,10 @@ bool GNSS_MOSAIC::configureOnce()
579579
setting = String("sso,Stream" + String(MOSAIC_SBF_INPUTLINK_STREAM) + ",COM1,InputLink,sec1\n\r");
580580
response &= sendWithResponse(setting, "SBFOutput");
581581

582-
// Output SBF ChannelStatus on its own stream - at 0.5Hz - on COM1 only
583-
// OnChange is too often. The message is typically 1000 bytes in size.
584-
setting = String("sso,Stream" + String(MOSAIC_SBF_CHANNELSTATUS_STREAM) + ",COM1,ChannelStatus,sec2\n\r");
582+
// Output SBF ChannelStatus and DiskStatus on their own stream - at 0.5Hz - on COM1 only
583+
// For ChannelStatus: OnChange is too often. The message is typically 1000 bytes in size.
584+
// For DiskStatus: DiskUsage is slow to update. 0.5Hz is plenty fast enough.
585+
setting = String("sso,Stream" + String(MOSAIC_SBF_STATUS_STREAM) + ",COM1,ChannelStatus+DiskStatus,sec2\n\r");
585586
response &= sendWithResponse(setting, "SBFOutput");
586587

587588
response &= setElevation(settings.minElev);
@@ -2473,6 +2474,37 @@ void GNSS_MOSAIC::storeBlock4013(SEMP_PARSE_STATE *parse)
24732474

24742475
}
24752476

2477+
//----------------------------------------
2478+
// Save the data from the SBF Block 4059
2479+
//----------------------------------------
2480+
void GNSS_MOSAIC::storeBlock4059(SEMP_PARSE_STATE *parse)
2481+
{
2482+
if (sempSbfGetU1(parse, 14) < 1) // Check N is at least 1
2483+
return;
2484+
2485+
if (sempSbfGetU1(parse, 20 + 0) != 1) // Check DiskID is 1
2486+
return;
2487+
2488+
uint64_t diskUsageMSB = sempSbfGetU2(parse, 20 + 2); // DiskUsageMSB
2489+
uint64_t diskUsageLSB = sempSbfGetU4(parse, 20 + 4); // DiskUsageLSB
2490+
2491+
if ((diskUsageMSB == 65535) && (diskUsageLSB == 4294967295)) // Do-Not-Use
2492+
return;
2493+
2494+
uint64_t diskSizeMB = sempSbfGetU4(parse, 20 + 8); // DiskSize in megabytes
2495+
2496+
if (diskSizeMB == 0) // Do-Not-Use
2497+
return;
2498+
2499+
uint64_t diskUsage = (diskUsageMSB * 4294967296) + diskUsageLSB;
2500+
2501+
sdCardSize = diskSizeMB * 1048576; // Convert to bytes
2502+
2503+
sdFreeSpace = sdCardSize - diskUsage;
2504+
2505+
_diskStatusSeen = true;
2506+
}
2507+
24762508
//----------------------------------------
24772509
// Save the data from the SBF Block 4090
24782510
//----------------------------------------
@@ -2576,7 +2608,9 @@ void GNSS_MOSAIC::update()
25762608
static uint64_t previousFreeSpace = 0;
25772609
if (millis() > (sdCardSizeLastCheck + sdCardSizeCheckInterval))
25782610
{
2579-
if (updateSD()) // updateSD will only return true if a card is inserted and the card size has been read
2611+
updateSD(); // Check if the card has been removed / inserted
2612+
2613+
if (_diskStatusSeen) // Check if the DiskStatus SBF message has been processed
25802614
{
25812615
// If previousFreeSpace hasn't been initialized, initialize it
25822616
if (previousFreeSpace == 0)
@@ -2603,13 +2637,9 @@ void GNSS_MOSAIC::update()
26032637
previousFreeSpace = sdFreeSpace;
26042638
}
26052639
}
2606-
else
2607-
{
2608-
// updateSD failed. So sdFreeSpace can't be trusted and the log cannot be increasing
2609-
logIncreasing = false;
2610-
}
26112640

2612-
sdCardSizeLastCheck = millis();
2641+
sdCardSizeLastCheck = millis(); // Update the timer
2642+
_diskStatusSeen = false; // Clear the flag
26132643
}
26142644

26152645
// Update spartnCorrectionsReceived
@@ -2624,7 +2654,7 @@ void GNSS_MOSAIC::update()
26242654
}
26252655

26262656
//----------------------------------------
2627-
bool GNSS_MOSAIC::updateSD()
2657+
void GNSS_MOSAIC::updateSD()
26282658
{
26292659
// See comments in update() above
26302660
// updateSD() is probably the best place to check if an SD card has been inserted / removed
@@ -2663,45 +2693,8 @@ bool GNSS_MOSAIC::updateSD()
26632693
if (retries == retryLimit)
26642694
{
26652695
systemPrintln("Soft reset failed!");
2666-
return false;
26672696
}
26682697
}
2669-
2670-
if (!previousCardPresent) // If the card is not present, skip the list disk info
2671-
return false;
2672-
2673-
// Use ldi,DSK1 to read the disk information
2674-
// This is inefficient as the DiskInfo lists all files on the SD card
2675-
// exeSBFOnce DiskStatus is much more efficient
2676-
//
2677-
// char diskInfo[200];
2678-
// bool response =
2679-
// sendAndWaitForIdle("ldi,DSK1\n\r", "DiskInfo", 1000, 25, &diskInfo[0], sizeof(diskInfo), false); // No debug
2680-
// if (response)
2681-
// {
2682-
// char *ptr = strstr(diskInfo, " total=\"");
2683-
// if (ptr == nullptr)
2684-
// return false;
2685-
// ptr += strlen(" total=\"");
2686-
// sscanf(ptr, "%llu\"", &sdCardSize);
2687-
// ptr = strstr(ptr, " free=\"");
2688-
// if (ptr == nullptr)
2689-
// return false;
2690-
// ptr += strlen(" free=\"");
2691-
// sscanf(ptr, "%llu\"", &sdFreeSpace);
2692-
// }
2693-
// return response;
2694-
2695-
_diskStatusSeen = false;
2696-
2697-
// Request the DiskStatus SBF block using a esoc (exeSBFOnce) command on COM4
2698-
String request = "esoc,COM4,DiskStatus\n\r";
2699-
serial2GNSS->write(request.c_str(), request.length());
2700-
2701-
// Wait for up to 1 second for the DiskStatus
2702-
waitSBFDiskStatus(1000);
2703-
2704-
return _diskStatusSeen;
27052698
}
27062699

27072700
//----------------------------------------
@@ -2738,40 +2731,6 @@ void GNSS_MOSAIC::waitSBFReceiverSetup(unsigned long timeout)
27382731
sempStopParser(&sbfParse);
27392732
}
27402733

2741-
//----------------------------------------
2742-
void GNSS_MOSAIC::waitSBFDiskStatus(unsigned long timeout)
2743-
{
2744-
SEMP_PARSE_ROUTINE const sbfParserTable[] = {sempSbfPreamble};
2745-
const int sbfParserCount = sizeof(sbfParserTable) / sizeof(sbfParserTable[0]);
2746-
const char *const sbfParserNames[] = {
2747-
"SBF",
2748-
};
2749-
const int sbfParserNameCount = sizeof(sbfParserNames) / sizeof(sbfParserNames[0]);
2750-
2751-
SEMP_PARSE_STATE *sbfParse;
2752-
2753-
// Initialize the SBF parser for the mosaic-X5
2754-
sbfParse = sempBeginParser(sbfParserTable, sbfParserCount, sbfParserNames, sbfParserNameCount,
2755-
0, // Scratchpad bytes
2756-
500, // Buffer length
2757-
processSBFDiskStatus, // eom Call Back
2758-
"Sbf"); // Parser Name
2759-
if (!sbfParse)
2760-
reportFatalError("Failed to initialize the SBF parser");
2761-
2762-
unsigned long startTime = millis();
2763-
while ((millis() < (startTime + timeout)) && (_diskStatusSeen == false))
2764-
{
2765-
if (serial2GNSS->available())
2766-
{
2767-
// Update the parser state based on the incoming byte
2768-
sempParseNextByte(sbfParse, serial2GNSS->read());
2769-
}
2770-
}
2771-
2772-
sempStopParser(&sbfParse);
2773-
}
2774-
27752734
//==========================================================================
27762735
// Parser support routines
27772736
//==========================================================================
@@ -2868,37 +2827,6 @@ void processSBFReceiverSetup(SEMP_PARSE_STATE *parse, uint16_t type)
28682827
}
28692828
}
28702829

2871-
//----------------------------------------
2872-
void processSBFDiskStatus(SEMP_PARSE_STATE *parse, uint16_t type)
2873-
{
2874-
// If this is DiskStatus, extract some data
2875-
if (sempSbfGetBlockNumber(parse) == 4059)
2876-
{
2877-
if (sempSbfGetU1(parse, 14) < 1) // Check N is at least 1
2878-
return;
2879-
2880-
uint64_t diskUsageMSB = sempSbfGetU2(parse, 20 + 2); // DiskUsageMSB
2881-
uint64_t diskUsageLSB = sempSbfGetU4(parse, 20 + 4); // DiskUsageLSB
2882-
2883-
if ((diskUsageMSB == 65535) && (diskUsageLSB == 4294967295))
2884-
return;
2885-
2886-
uint64_t diskSizeMB = sempSbfGetU4(parse, 20 + 8); // DiskSize in megabytes
2887-
2888-
if (diskSizeMB == 0)
2889-
return;
2890-
2891-
uint64_t diskUsage = (diskUsageMSB * 4294967296) + diskUsageLSB;
2892-
2893-
sdCardSize = diskSizeMB * 1048576; // Convert to bytes
2894-
2895-
sdFreeSpace = sdCardSize - diskUsage;
2896-
2897-
GNSS_MOSAIC *mosaic = (GNSS_MOSAIC *)gnss;
2898-
mosaic->_diskStatusSeen = true;
2899-
}
2900-
}
2901-
29022830
//----------------------------------------
29032831
// Call back from within the SBF parser, for end of valid message
29042832
// Process a complete message incoming from parser
@@ -2927,6 +2855,10 @@ void processUart1SBF(SEMP_PARSE_STATE *parse, uint16_t type)
29272855
if (sempSbfGetBlockNumber(parse) == 4013)
29282856
mosaic->storeBlock4013(parse);
29292857

2858+
// If this is DiskStatus, extract some data
2859+
if (sempSbfGetBlockNumber(parse) == 4059)
2860+
mosaic->storeBlock4059(parse);
2861+
29302862
// If this is InputLink, extract some data
29312863
if (sempSbfGetBlockNumber(parse) == 4090)
29322864
mosaic->storeBlock4090(parse);

0 commit comments

Comments
 (0)