@@ -22,11 +22,16 @@ void menuLog()
2222 sdFreeSpaceChar
2323 );
2424 systemPrintln (myString);
25+
26+ if (online.logging )
27+ {
28+ systemPrintf (" Current log file name: %s\r\n " , logFileName);
29+ }
2530 }
2631 else
2732 systemPrintln (" No microSD card is detected" );
2833
29- if (bufferOverruns)
34+ if (bufferOverruns)
3035 systemPrintf (" Buffer overruns: %d\r\n " , bufferOverruns);
3136
3237 systemPrint (" 1) Log to microSD: " );
@@ -94,8 +99,8 @@ void menuLog()
9499 }
95100 else if (incoming == 4 && settings.enableLogging == true && online.logging == true )
96101 {
97- endSD (false , true ); // Close down file. A new one will be created at the next calling of updateLogs() .
98- beginLogging ();
102+ endLogging (false , true ); // (gotSemaphore, releaseSemaphore) Close file. Reset parser stats .
103+ beginLogging (); // Create new file based on current RTC.
99104 setLoggingType (); // Determine if we are standard, PPP, or custom. Changes logging icon accordingly.
100105 }
101106 else if (incoming == 5 )
@@ -329,22 +334,27 @@ void beginLogging(const char *customFileName)
329334 {
330335 if (online.microSD == true && settings.enableLogging == true && online.rtc == true ) // We can't create a file until we have date/time
331336 {
332- char fileName[66 + 6 + 40 ] = " " ;
333-
334337 if (strlen (customFileName) == 0 )
335338 {
336339 // Generate a standard log file name
337340 if (reuseLastLog == true ) // attempt to use previous log
338341 {
339- if (findLastLog (fileName) == false )
342+ reuseLastLog = false ;
343+
344+ if (findLastLog (logFileName) == false )
340345 log_d (" Failed to find last log. Making new one." );
341346 else
342347 log_d (" Using last log file." );
343348 }
349+ else
350+ {
351+ // We are not reusing the last log, so erase the global/original filename
352+ strcpy (logFileName, " " );
353+ }
344354
345- if (strlen (fileName ) == 0 )
355+ if (strlen (logFileName ) == 0 )
346356 {
347- sprintf (fileName , " %s_%02d%02d%02d_%02d%02d%02d.ubx" , // SdFat library
357+ sprintf (logFileName , " %s_%02d%02d%02d_%02d%02d%02d.ubx" , // SdFat library
348358 platformFilePrefix,
349359 rtc.getYear () - 2000 , rtc.getMonth () + 1 , rtc.getDay (), // ESP32Time returns month:0-11
350360 rtc.getHour (true ), rtc.getMinute (), rtc.getSecond () // ESP32Time getHour(true) returns hour:0-23
@@ -353,7 +363,7 @@ void beginLogging(const char *customFileName)
353363 }
354364 else
355365 {
356- strcpy (fileName , customFileName);
366+ strcpy (logFileName , customFileName);
357367 }
358368
359369 // Attempt to write to file system. This avoids collisions with file writing in F9PSerialReadTask()
@@ -364,9 +374,9 @@ void beginLogging(const char *customFileName)
364374 // O_CREAT - create the file if it does not exist
365375 // O_APPEND - seek to the end of the file prior to each write
366376 // O_WRITE - open for write
367- if (ubxFile->open (fileName , O_CREAT | O_APPEND | O_WRITE) == false )
377+ if (ubxFile->open (logFileName , O_CREAT | O_APPEND | O_WRITE) == false )
368378 {
369- systemPrintf (" Failed to create GNSS UBX data file: %s\r\n " , fileName );
379+ systemPrintf (" Failed to create GNSS UBX data file: %s\r\n " , logFileName );
370380 online.logging = false ;
371381 xSemaphoreGive (sdCardSemaphore);
372382 return ;
@@ -439,7 +449,7 @@ void beginLogging(const char *customFileName)
439449 return ;
440450 }
441451
442- systemPrintf (" Log file name: %s\r\n " , fileName );
452+ systemPrintf (" Log file name: %s\r\n " , logFileName );
443453 online.logging = true ;
444454 } // online.sd, enable.logging, online.rtc
445455 } // online.logging
@@ -521,15 +531,15 @@ bool findLastLog(char *lastLogName)
521531 const char * LOG_EXTENSION = " ubx" ;
522532 const char * LOG_PREFIX = platformFilePrefix;
523533 char fname[50 ]; // Handle long file names
524-
534+
525535 dir.open (" /" ); // Open root
526-
536+
527537 while (tempFile.openNext (&dir, O_READ))
528538 {
529539 if (tempFile.isFile ())
530540 {
531541 tempFile.getName (fname, sizeof (fname));
532-
542+
533543 // Check for matching file name prefix and extension
534544 if (strcmp (LOG_EXTENSION, &fname[strlen (fname) - strlen (LOG_EXTENSION)]) == 0 )
535545 {
@@ -551,7 +561,7 @@ bool findLastLog(char *lastLogName)
551561 const char * LOG_EXTENSION = " ubx" ;
552562 const char * LOG_PREFIX = platformFilePrefix;
553563 char fname[50 ]; // Handle long file names
554-
564+
555565 dir = SD_MMC.open (" /" ); // Open root
556566
557567 if (dir && dir.isDirectory ())
@@ -562,7 +572,7 @@ bool findLastLog(char *lastLogName)
562572 if (!tempFile.isDirectory ())
563573 {
564574 snprintf (fname, sizeof (fname), " %s" , tempFile.name ());
565-
575+
566576 // Check for matching file name prefix and extension
567577 if (strcmp (LOG_EXTENSION, &fname[strlen (fname) - strlen (LOG_EXTENSION)]) == 0 )
568578 {
0 commit comments