Skip to content

Commit b5f3d10

Browse files
committed
Add NMEA TXT to log recording reset reason.
See issue #41
1 parent 6875d27 commit b5f3d10

File tree

3 files changed

+45
-10
lines changed

3 files changed

+45
-10
lines changed

Firmware/RTK_Surveyor/Begin.ino

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ void beginBoard()
9797

9898
Serial.printf("SparkFun RTK %s v%d.%d-%s\r\n", platformPrefix, FIRMWARE_VERSION_MAJOR, FIRMWARE_VERSION_MINOR, __DATE__);
9999

100-
//For all boards, check reset reason. If reset was do to wdt or panic, append last log
100+
//For all boards, check reset reason. If reset was due to wdt or panic, append last log
101101
if (esp_reset_reason() == ESP_RST_POWERON)
102102
{
103103
reuseLastLog = false; //Start new log

Firmware/RTK_Surveyor/System.ino

+16
Original file line numberDiff line numberDiff line change
@@ -776,3 +776,19 @@ boolean SFE_UBLOX_GNSS_ADD::getModuleInfo(uint16_t maxWait)
776776

777777
return (true); //Success!
778778
}
779+
780+
//Create $GNTXT, type message complete with CRC
781+
//https://www.nmea.org/Assets/20160520%20txt%20amendment.pdf
782+
//Used for reporting a system reboot inside the log
783+
void createNMEASentence(uint8_t sentenceNumber, uint8_t textID, char *nmeaMessage, char *textMessage)
784+
{
785+
char nmeaTxt[82]; //Max NMEA sentence length is 82
786+
sprintf(nmeaTxt, "$GNTXT,01,%02d,%02d,%s*", sentenceNumber, textID, textMessage);
787+
788+
//From: http://engineeringnotes.blogspot.com/2015/02/generate-crc-for-nmea-strings-arduino.html
789+
byte CRC = 0; // XOR chars between '$' and '*'
790+
for (byte x = 1 ; x < strlen(nmeaTxt) - 1; x++)
791+
CRC = CRC ^ nmeaTxt[x];
792+
793+
sprintf(nmeaMessage, "%s%02X", nmeaTxt, CRC);
794+
}

Firmware/RTK_Surveyor/menuMessages.ino

+28-9
Original file line numberDiff line numberDiff line change
@@ -307,8 +307,8 @@ void beginLogging()
307307
{
308308
//Based on GPS data/time, create a log file in the format SFE_Surveyor_YYMMDD_HHMMSS.ubx
309309
bool timeValid = false;
310-
// if (i2cGNSS.getTimeValid() == true && i2cGNSS.getDateValid() == true) //Will pass if ZED's RTC is reporting (regardless of GNSS fix)
311-
// timeValid = true;
310+
// if (i2cGNSS.getTimeValid() == true && i2cGNSS.getDateValid() == true) //Will pass if ZED's RTC is reporting (regardless of GNSS fix)
311+
// timeValid = true;
312312
if (i2cGNSS.getConfirmedTime() == true && i2cGNSS.getConfirmedDate() == true) //Requires GNSS fix
313313
timeValid = true;
314314

@@ -346,11 +346,30 @@ void beginLogging()
346346

347347
startLogTime_minutes = millis() / 1000L / 60; //Mark now as start of logging
348348

349-
//TODO For debug only, remove
349+
//Add NMEA txt message with restart reason
350+
char rstReason[30];
351+
switch (esp_reset_reason())
352+
{
353+
case ESP_RST_UNKNOWN: strcpy(rstReason, "ESP_RST_UNKNOWN"); break;
354+
case ESP_RST_POWERON : strcpy(rstReason, "ESP_RST_POWERON"); break;
355+
case ESP_RST_SW : strcpy(rstReason, "ESP_RST_SW"); break;
356+
case ESP_RST_PANIC : strcpy(rstReason, "ESP_RST_PANIC"); break;
357+
case ESP_RST_INT_WDT : strcpy(rstReason, "ESP_RST_INT_WDT"); break;
358+
case ESP_RST_TASK_WDT : strcpy(rstReason, "ESP_RST_TASK_WDT"); break;
359+
case ESP_RST_WDT : strcpy(rstReason, "ESP_RST_WDT"); break;
360+
case ESP_RST_DEEPSLEEP : strcpy(rstReason, "ESP_RST_DEEPSLEEP"); break;
361+
case ESP_RST_BROWNOUT : strcpy(rstReason, "ESP_RST_BROWNOUT"); break;
362+
case ESP_RST_SDIO : strcpy(rstReason, "ESP_RST_SDIO"); break;
363+
default : strcpy(rstReason, "Unknown");
364+
}
365+
366+
char nmeaMessage[82]; //Max NMEA sentence length is 82
367+
createNMEASentence(1, 1, nmeaMessage, rstReason); //sentenceNumber, textID
368+
ubxFile.println(nmeaMessage);
369+
350370
if (reuseLastLog == true)
351371
{
352372
Serial.println(F("Appending last available log"));
353-
ubxFile.println("Append file due to system reset");
354373
}
355374

356375
xSemaphoreGive(xFATSemaphore);
@@ -455,7 +474,7 @@ void setMessageOffsets(char* messageType, int& startOfBlock, int& endOfBlock)
455474
{
456475
char messageNamePiece[40]; //UBX_RTCM
457476
sprintf(messageNamePiece, "UBX_%s", messageType); //Put UBX_ infront of type
458-
477+
459478
//Find the first occurrence
460479
for (startOfBlock = 0 ; startOfBlock < MAX_UBX_MSG ; startOfBlock++)
461480
{
@@ -490,13 +509,13 @@ bool setMessageRateByName(char *msgName, uint8_t msgRate)
490509
{
491510
for (int x = 0 ; x < MAX_UBX_MSG ; x++)
492511
{
493-
if(strcmp(ubxMessages[x].msgTextName, msgName) == 0)
512+
if (strcmp(ubxMessages[x].msgTextName, msgName) == 0)
494513
{
495514
ubxMessages[x].msgRate = msgRate;
496-
return(true);
497-
}
515+
return (true);
516+
}
498517
}
499518

500519
Serial.printf("setMessageRateByName: %s not found\n\r", msgName);
501-
return(false);
520+
return (false);
502521
}

0 commit comments

Comments
 (0)