Skip to content

Commit 56de3d2

Browse files
committed
Add settings.alignedLogFiles - resolves #630
1 parent f520466 commit 56de3d2

File tree

5 files changed

+43
-11
lines changed

5 files changed

+43
-11
lines changed

Firmware/RTK_Everywhere/AP-Config/index.html

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2016,7 +2016,7 @@
20162016
<label for="maxLogTime" class="box-margin40 col-sm-3 col-7 col-form-label">Max Logging
20172017
Time (min):
20182018
<span class="tt" data-bs-placement="right"
2019-
title="Once the max log time is achieved, logging will cease. This is useful for limiting long term, overnight, static surveys to a certain length of time. Default: 1440 minutes. Limits: 1 to 2880 minutes.">
2019+
title="Once the max log time is achieved, logging will cease. This is useful for limiting long term, overnight, static surveys to a certain length of time. Default: 1440 minutes. Limits: 0 to 1,051,200 minutes. 0 = no limit.">
20202020
<span class="icon-info-circle text-primary ms-2"></span>
20212021
</span>
20222022
</label>
@@ -2027,15 +2027,23 @@
20272027
<div class="form-group row">
20282028
<label for="maxLogLength" class="box-margin40 col-sm-3 col-7 col-form-label">Max Log
20292029
File Length (min):<span class="tt" data-bs-placement="right"
2030-
title="Once this length of time is achieved, a new log will be created. This is useful for creating multiple logs over a long survey. Default: 1440 minutes. Limits: 1 to 2880 minutes.">
2030+
title="Once this length of time is achieved, a new log will be created. This is useful for creating multiple logs over a long survey. Default: 1440 minutes. Limits: 0 to 2880 minutes. 0 = no limit.">
20312031
<span class="icon-info-circle text-primary ms-2"></span>
20322032
</span>
20332033
</label>
2034-
20352034
<input type="number" class="form-control box-small" id="maxLogLength">
20362035
<p id="maxLogLengthError" class="inlineError"></p>
20372036
</div>
20382037

2038+
<div class="form-check mt-1 box-margin20">
2039+
<label class="form-check-label" for="alignedLogFiles">Aligned Log Files</label>
2040+
<input class="form-check-input" type="checkbox" value="" id="alignedLogFiles" unchecked>
2041+
<span class="tt" data-bs-placement="right"
2042+
title="If enabled, log files will be aligned to the Max Log File Length. Only possible if the Max Log Length is an integral fraction of 24 hours.">
2043+
<span class="icon-info-circle text-primary ms-2"></span>
2044+
</span>
2045+
</div>
2046+
20392047
<div id="logFile" class="row">
20402048
<div class="mb-2">
20412049
<label for="logFile" class="form-group box-margin20">Log file name: <span

Firmware/RTK_Everywhere/AP-Config/src/main.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,8 +1004,8 @@ function validateFields() {
10041004

10051005
//System Config
10061006
if (ge("enableLogging").checked == true) {
1007-
checkElementValue("maxLogTime", 1, 1051200, "Must be 1 to 1,051,200", "collapseSystemConfig");
1008-
checkElementValue("maxLogLength", 1, 1051200, "Must be 1 to 1,051,200", "collapseSystemConfig");
1007+
checkElementValue("maxLogTime", 0, 1051200, "Must be 0 to 1,051,200", "collapseSystemConfig");
1008+
checkElementValue("maxLogLength", 0, 2880, "Must be 0 to 2880", "collapseSystemConfig");
10091009
}
10101010
else {
10111011
clearElement("maxLogTime", 60 * 24);

Firmware/RTK_Everywhere/RTK_Everywhere.ino

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -325,9 +325,8 @@ SdFat *sd;
325325

326326
SdFile *logFile; // File that all GNSS messages sentences are written to
327327
unsigned long lastUBXLogSyncTime; // Used to record to SD every half second
328-
int startLogTime_minutes; // Mark when we start any logging so we can stop logging after maxLogTime_minutes
329-
int startCurrentLogTime_minutes;
330-
// Mark when we start this specific log file so we can close it after x minutes and start a new one
328+
int startLogTime_minutes; // Mark when we (re)start any logging so we can stop logging after maxLogTime_minutes
329+
unsigned long nextLogTime_ms; // Open the next log file at this many millis()
331330

332331
// System crashes if two tasks access a file at the same time
333332
// So we use a semaphore to see if the file system is available
@@ -1474,7 +1473,10 @@ bool logLengthExceeded() // Limit individual files to maxLogLength_minutes
14741473
if (settings.maxLogLength_minutes == 0) // No limit if maxLogLength_minutes is zero
14751474
return false;
14761475

1477-
return ((systemTime_minutes - startCurrentLogTime_minutes) >= settings.maxLogLength_minutes);
1476+
if (nextLogTime_ms == 0) // Keep logging if nextLogTime_ms has not been set
1477+
return false;
1478+
1479+
return (millis() >= nextLogTime_ms); // Note: this will roll over every ~50 days...
14781480
}
14791481

14801482
// Create or close files as needed (startup or as the user changes settings)

Firmware/RTK_Everywhere/menuMessages.ino

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ void menuLog()
9898
else if (incoming == 2 && settings.enableLogging == true)
9999
{
100100
// Arbitrary 2 year limit. See https://github.com/sparkfun/SparkFun_RTK_Firmware/issues/86
101+
// Note: the 2 year limit is fine. But systemTime_minutes is based on millis(), and millis()
102+
// will roll over every 2^32ms = ~50 days...
103+
// TODO: use the GNSS epoch (uint32_t seconds plus uint32_t microseconds) to resolve this.
101104
getNewSetting("Enter max minutes before logging stops", 0, 60 * 24 * 365 * 2, &settings.maxLogTime_minutes);
102105
}
103106
else if (incoming == 3 && settings.enableLogging == true)
@@ -288,7 +291,24 @@ bool beginLogging(const char *customFileName)
288291

289292
sdUpdateFileCreateTimestamp(logFile); // Update the file to create time & date
290293

291-
startCurrentLogTime_minutes = millis() / 1000L / 60; // Mark now as start of logging
294+
// Calculate the time of the next log file change
295+
nextLogTime_ms = 0; // Default to no limit
296+
if ((settings.alignedLogFiles) && (settings.maxLogLength_minutes > 0))
297+
{
298+
// Aligned logging is only possible if the interval is an integral fraction of 24 hours
299+
if ((24 * 60 * 2) % settings.maxLogLength_minutes == 0)
300+
{
301+
// Calculate when the next log file should be opened - in millis()
302+
unsigned long hoursAsMillis = rtc.getMillis() + (rtc.getSecond() * 1000)
303+
+ (rtc.getMinute() * 1000 * 60) + (rtc.getHour(true) * 1000 * 60 * 60);
304+
unsigned long maxLogLength_ms = (unsigned long)settings.maxLogLength_minutes * 60 * 1000;
305+
unsigned long millisFromPreviousLog = hoursAsMillis % maxLogLength_ms;
306+
unsigned long millisToNextLog = maxLogLength_ms - millisFromPreviousLog;
307+
nextLogTime_ms = millis() + millisToNextLog;
308+
}
309+
}
310+
if ((nextLogTime_ms == 0) && (settings.maxLogLength_minutes > 0)) // Non-aligned logging
311+
nextLogTime_ms = millis() + ((unsigned long)settings.maxLogLength_minutes * 60 * 1000);
292312

293313
// Add NMEA txt message with restart reason
294314
char rstReason[30];

Firmware/RTK_Everywhere/settings.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,8 @@ struct Settings
726726
bool debugHttpClientState = false; // Debug the HTTP Client state machine
727727

728728
// Log file
729-
bool enableLogging = true; // If an SD card is present, log default sentences
729+
bool alignedLogFiles = false; // If true, align log files as per #630
730+
bool enableLogging = true; // If an SD card is present, log default sentences
730731
bool enablePrintLogFileMessages = false;
731732
bool enablePrintLogFileStatus = true;
732733
int maxLogLength_minutes = 60 * 24; // Default to 24 hours
@@ -1338,6 +1339,7 @@ const RTK_Settings_Entry rtkSettingsEntries[] =
13381339
// g s x k 2 c h d d Type Qual Variable Name
13391340

13401341
// Log file
1342+
{ 1, 1, 0, 1, 1, 1, 0, 1, 1, _bool, 0, & settings.alignedLogFiles, "alignedLogFiles", },
13411343
{ 1, 1, 0, 1, 1, 1, 0, 1, 1, _bool, 0, & settings.enableLogging, "enableLogging", },
13421344
{ 0, 0, 0, 1, 1, 1, 0, 1, 1, _bool, 0, & settings.enablePrintLogFileMessages, "enablePrintLogFileMessages", },
13431345
{ 0, 0, 0, 1, 1, 1, 0, 1, 1, _bool, 0, & settings.enablePrintLogFileStatus, "enablePrintLogFileStatus", },

0 commit comments

Comments
 (0)