@@ -306,153 +306,111 @@ void beginLogging()
306306{
307307 if (online.logging == false )
308308 {
309- if (online.microSD == true && settings.enableLogging == true )
309+ if (online.microSD == true && settings.enableLogging == true && online. rtc == true ) // We can't create a file until we have date/time
310310 {
311- // Wait 1000ms between newLog creation for ZED to get date/time
312- if (millis () - lastBeginLoggingAttempt > 1000 )
313- {
314- lastBeginLoggingAttempt = millis ();
311+ char fileName[40 ] = " " ;
315312
316- char fileName[40 ] = " " ;
313+ if (reuseLastLog == true ) // attempt to use previous log
314+ {
315+ if (findLastLog (fileName) == false )
316+ log_d (" Failed to find last log. Making new one." );
317+ }
317318
318- i2cGNSS.checkUblox ();
319+ if (strlen (fileName) == 0 )
320+ {
321+ sprintf (fileName, " %s_%02d%02d%02d_%02d%02d%02d.ubx" , // SdFat library
322+ platformFilePrefix,
323+ rtc.getYear () - 2000 , rtc.getMonth (), rtc.getDay (),
324+ rtc.getHour (), rtc.getMinute (), rtc.getSecond ()
325+ );
326+ }
319327
320- if (reuseLastLog == true ) // attempt to use previous log
328+ // Attempt to write to file system. This avoids collisions with file writing in F9PSerialReadTask()
329+ if (xSemaphoreTake (xFATSemaphore, fatSemaphore_longWait_ms) == pdPASS)
330+ {
331+ // O_CREAT - create the file if it does not exist
332+ // O_APPEND - seek to the end of the file prior to each write
333+ // O_WRITE - open for write
334+ if (ubxFile.open (fileName, O_CREAT | O_APPEND | O_WRITE) == false )
321335 {
322- if ( findLastLog (fileName) == false )
323- {
324- Serial. println ( F ( " Failed to find last log. Making new one. " ) );
325- }
336+ Serial. printf ( " Failed to create GNSS UBX data file: %s \n\r " , fileName);
337+ online. logging = false ;
338+ xSemaphoreGive (xFATSemaphore );
339+ return ;
326340 }
327341
328- if (strlen (fileName) == 0 )
329- {
330- // Based on GPS data/time, create a log file in the format SFE_Surveyor_YYMMDD_HHMMSS.ubx
331- bool timeValid = false ;
332- // if (i2cGNSS.getTimeValid() == true && i2cGNSS.getDateValid() == true) //Will pass if ZED's RTC is reporting (regardless of GNSS fix)
333- // timeValid = true;
334- if (i2cGNSS.getConfirmedTime () == true && i2cGNSS.getConfirmedDate () == true ) // Requires GNSS fix
335- timeValid = true ;
336-
337- if (timeValid == false )
338- {
339- Serial.println (F (" beginLoggingUBX: No date/time available. No file created." ));
340- online.logging = false ;
341- return ;
342- }
342+ updateDataFileCreate (&ubxFile); // Update the file to create time & date
343343
344- sprintf (fileName, " %s_%02d%02d%02d_%02d%02d%02d.ubx" , // SdFat library
345- platformFilePrefix,
346- i2cGNSS.getYear () - 2000 , i2cGNSS.getMonth (), i2cGNSS.getDay (),
347- i2cGNSS.getHour (), i2cGNSS.getMinute (), i2cGNSS.getSecond ()
348- );
349- }
344+ startLogTime_minutes = millis () / 1000L / 60 ; // Mark now as start of logging
350345
351- // Attempt to write to file system. This avoids collisions with file writing in F9PSerialReadTask()
352- if (xSemaphoreTake (xFATSemaphore, fatSemaphore_longWait_ms) == pdPASS)
346+ // Add NMEA txt message with restart reason
347+ char rstReason[30 ];
348+ switch (esp_reset_reason ())
353349 {
354- // O_CREAT - create the file if it does not exist
355- // O_APPEND - seek to the end of the file prior to each write
356- // O_WRITE - open for write
357- if (ubxFile.open (fileName, O_CREAT | O_APPEND | O_WRITE) == false )
358- {
359- Serial.printf (" Failed to create GNSS UBX data file: %s\n\r " , fileName);
360- online.logging = false ;
361- xSemaphoreGive (xFATSemaphore);
362- return ;
363- }
364-
365- updateDataFileCreate (&ubxFile); // Update the file to create time & date
366-
367- startLogTime_minutes = millis () / 1000L / 60 ; // Mark now as start of logging
368-
369- // Add NMEA txt message with restart reason
370- char rstReason[30 ];
371- switch (esp_reset_reason ())
372- {
373- case ESP_RST_UNKNOWN: strcpy (rstReason, " ESP_RST_UNKNOWN" ); break ;
374- case ESP_RST_POWERON : strcpy (rstReason, " ESP_RST_POWERON" ); break ;
375- case ESP_RST_SW : strcpy (rstReason, " ESP_RST_SW" ); break ;
376- case ESP_RST_PANIC : strcpy (rstReason, " ESP_RST_PANIC" ); break ;
377- case ESP_RST_INT_WDT : strcpy (rstReason, " ESP_RST_INT_WDT" ); break ;
378- case ESP_RST_TASK_WDT : strcpy (rstReason, " ESP_RST_TASK_WDT" ); break ;
379- case ESP_RST_WDT : strcpy (rstReason, " ESP_RST_WDT" ); break ;
380- case ESP_RST_DEEPSLEEP : strcpy (rstReason, " ESP_RST_DEEPSLEEP" ); break ;
381- case ESP_RST_BROWNOUT : strcpy (rstReason, " ESP_RST_BROWNOUT" ); break ;
382- case ESP_RST_SDIO : strcpy (rstReason, " ESP_RST_SDIO" ); break ;
383- default : strcpy (rstReason, " Unknown" );
384- }
350+ case ESP_RST_UNKNOWN: strcpy (rstReason, " ESP_RST_UNKNOWN" ); break ;
351+ case ESP_RST_POWERON : strcpy (rstReason, " ESP_RST_POWERON" ); break ;
352+ case ESP_RST_SW : strcpy (rstReason, " ESP_RST_SW" ); break ;
353+ case ESP_RST_PANIC : strcpy (rstReason, " ESP_RST_PANIC" ); break ;
354+ case ESP_RST_INT_WDT : strcpy (rstReason, " ESP_RST_INT_WDT" ); break ;
355+ case ESP_RST_TASK_WDT : strcpy (rstReason, " ESP_RST_TASK_WDT" ); break ;
356+ case ESP_RST_WDT : strcpy (rstReason, " ESP_RST_WDT" ); break ;
357+ case ESP_RST_DEEPSLEEP : strcpy (rstReason, " ESP_RST_DEEPSLEEP" ); break ;
358+ case ESP_RST_BROWNOUT : strcpy (rstReason, " ESP_RST_BROWNOUT" ); break ;
359+ case ESP_RST_SDIO : strcpy (rstReason, " ESP_RST_SDIO" ); break ;
360+ default : strcpy (rstReason, " Unknown" );
361+ }
385362
386- char nmeaMessage[82 ]; // Max NMEA sentence length is 82
387- createNMEASentence (CUSTOM_NMEA_TYPE_RESET_REASON, nmeaMessage, rstReason); // textID, buffer, text
388- ubxFile.println (nmeaMessage);
363+ char nmeaMessage[82 ]; // Max NMEA sentence length is 82
364+ createNMEASentence (CUSTOM_NMEA_TYPE_RESET_REASON, nmeaMessage, rstReason); // textID, buffer, text
365+ ubxFile.println (nmeaMessage);
389366
390- // Record system firmware versions and info to log
391-
392- // SparkFun RTK Express v1.10-Feb 11 2022
393- char firmwareVersion[30 ]; // v1.3 December 31 2021
394- sprintf (firmwareVersion, " v%d.%d-%s" , FIRMWARE_VERSION_MAJOR, FIRMWARE_VERSION_MINOR, __DATE__);
395- createNMEASentence (CUSTOM_NMEA_TYPE_SYSTEM_VERSION, nmeaMessage, firmwareVersion); // textID, buffer, text
396- ubxFile.println (nmeaMessage);
367+ // Record system firmware versions and info to log
397368
398- // ZED-F9P firmware: HPG 1.30
399- createNMEASentence (CUSTOM_NMEA_TYPE_ZED_VERSION, nmeaMessage, zedFirmwareVersion); // textID, buffer, text
400- ubxFile.println (nmeaMessage);
369+ // SparkFun RTK Express v1.10-Feb 11 2022
370+ char firmwareVersion[30 ]; // v1.3 December 31 2021
371+ sprintf (firmwareVersion, " v%d.%d-%s" , FIRMWARE_VERSION_MAJOR, FIRMWARE_VERSION_MINOR, __DATE__);
372+ createNMEASentence (CUSTOM_NMEA_TYPE_SYSTEM_VERSION, nmeaMessage, firmwareVersion); // textID, buffer, text
373+ ubxFile.println (nmeaMessage);
401374
402- if (reuseLastLog == true )
403- {
404- Serial.println (F (" Appending last available log" ));
405- }
375+ // ZED-F9P firmware: HPG 1.30
376+ createNMEASentence (CUSTOM_NMEA_TYPE_ZED_VERSION, nmeaMessage, zedFirmwareVersion); // textID, buffer, text
377+ ubxFile.println (nmeaMessage);
406378
407- xSemaphoreGive (xFATSemaphore);
408- }
409- else
379+ if (reuseLastLog == true )
410380 {
411- Serial.println (F (" Failed to get file system lock to create GNSS UBX data file" ));
412- online.logging = false ;
413- return ;
381+ Serial.println (F (" Appending last available log" ));
414382 }
415383
416- Serial.printf (" Log file created: %s\n\r " , fileName);
417- online.logging = true ;
418- } // lastBeginLoggingAttempt > 1000ms
419- } // sdOnline, settings.logging = true
420- else
421- online.logging = false ;
422- } // online.logging = false
384+ xSemaphoreGive (xFATSemaphore);
385+ }
386+ else
387+ {
388+ Serial.println (F (" Failed to get file system lock to create GNSS UBX data file" ));
389+ online.logging = false ;
390+ return ;
391+ }
392+
393+ Serial.printf (" Log file created: %s\n\r " , fileName);
394+ online.logging = true ;
395+ } // online.sd, enable.logging, online.rtc
396+ } // online.logging
423397}
424398
425- // Updates the timestemp on a given data file
399+ // Update the file access and write time with date and time obtained from GNSS
426400void updateDataFileAccess (SdFile *dataFile)
427401{
428- bool timeValid = false ;
429- if (i2cGNSS.getTimeValid () == true && i2cGNSS.getDateValid () == true ) // Will pass if ZED's RTC is reporting (regardless of GNSS fix)
430- timeValid = true ;
431- if (i2cGNSS.getConfirmedTime () == true && i2cGNSS.getConfirmedDate () == true ) // Requires GNSS fix
432- timeValid = true ;
433-
434- if (timeValid == true )
402+ if (online.rtc == true )
435403 {
436- // Update the file access time
437- dataFile->timestamp (T_ACCESS, i2cGNSS.getYear (), i2cGNSS.getMonth (), i2cGNSS.getDay (), i2cGNSS.getHour (), i2cGNSS.getMinute (), i2cGNSS.getSecond ());
438- // Update the file write time
439- dataFile->timestamp (T_WRITE, i2cGNSS.getYear (), i2cGNSS.getMonth (), i2cGNSS.getDay (), i2cGNSS.getHour (), i2cGNSS.getMinute (), i2cGNSS.getSecond ());
404+ dataFile->timestamp (T_ACCESS, rtc.getYear (), rtc.getMonth (), rtc.getDay (), rtc.getHour (), rtc.getMinute (), rtc.getSecond ());
405+ dataFile->timestamp (T_WRITE, rtc.getYear (), rtc.getMonth (), rtc.getDay (), rtc.getHour (), rtc.getMinute (), rtc.getSecond ());
440406 }
441407}
442408
409+ // Update the file create time with date and time obtained from GNSS
443410void updateDataFileCreate (SdFile *dataFile)
444411{
445- bool timeValid = false ;
446- if (i2cGNSS.getTimeValid () == true && i2cGNSS.getDateValid () == true ) // Will pass if ZED's RTC is reporting (regardless of GNSS fix)
447- timeValid = true ;
448- if (i2cGNSS.getConfirmedTime () == true && i2cGNSS.getConfirmedDate () == true ) // Requires GNSS fix
449- timeValid = true ;
450-
451- if (timeValid == true )
452- {
453- // Update the file create time
454- dataFile->timestamp (T_CREATE, i2cGNSS.getYear (), i2cGNSS.getMonth (), i2cGNSS.getDay (), i2cGNSS.getHour (), i2cGNSS.getMinute (), i2cGNSS.getSecond ());
455- }
412+ if (online.rtc == true )
413+ dataFile->timestamp (T_CREATE, rtc.getYear (), rtc.getMonth (), rtc.getDay (), rtc.getHour (), rtc.getMinute (), rtc.getSecond ());
456414}
457415
458416// Finds last log
0 commit comments