Skip to content

Commit 98188cf

Browse files
committed
Add flush. Add sizeof to createNMEASentence. Add button. Add base LED
1 parent 3dc0198 commit 98188cf

File tree

10 files changed

+103
-77
lines changed

10 files changed

+103
-77
lines changed

Firmware/RTK_Surveyor/Begin.ino

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ void initializePowerPins()
7777
pin_zed_tx_ready = 34;
7878
pin_microSD_CardDetect = 36;
7979
pin_Ethernet_Interrupt = 33;
80+
pin_setupButton = 0;
8081

8182
pin_radio_rx = 17; // Radio RX In = ESP TX Out
8283
pin_radio_tx = 16; // Radio TX Out = ESP RX In
@@ -894,6 +895,8 @@ void beginSystemState()
894895
firstRoverStart = true; //Allow user to enter test screen during first rover start
895896
if (systemState == STATE_BASE_NOT_STARTED)
896897
firstRoverStart = false;
898+
899+
setupBtn = new Button(pin_setupButton); //Create the button in memory
897900
}
898901

899902
//Starts task for monitoring button presses

Firmware/RTK_Surveyor/Buttons.ino

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44
void powerOnCheck()
55
{
66
powerPressedStartTime = millis();
7-
if (digitalRead(pin_powerSenseAndControl) == LOW)
8-
delay(500);
7+
if (pin_powerSenseAndControl >= 0)
8+
if (digitalRead(pin_powerSenseAndControl) == LOW)
9+
delay(500);
910

1011
#ifndef ENABLE_DEVELOPER
11-
if (digitalRead(pin_powerSenseAndControl) != LOW)
12-
powerDown(false); //Power button tap. Returning to off state.
12+
if (pin_powerSenseAndControl >= 0)
13+
if (digitalRead(pin_powerSenseAndControl) != LOW)
14+
powerDown(false); //Power button tap. Returning to off state.
1315
#endif
1416

1517
powerPressedStartTime = 0; //Reset var to return to normal 'on' state
@@ -31,11 +33,20 @@ void powerDown(bool displayInfo)
3133
delay(2000);
3234
}
3335

34-
pinMode(pin_powerSenseAndControl, OUTPUT);
35-
digitalWrite(pin_powerSenseAndControl, LOW);
36+
if (pin_powerSenseAndControl >= 0)
37+
{
38+
pinMode(pin_powerSenseAndControl, OUTPUT);
39+
digitalWrite(pin_powerSenseAndControl, LOW);
40+
}
41+
42+
if (pin_powerFastOff >= 0)
43+
{
44+
pinMode(pin_powerFastOff, OUTPUT);
45+
digitalWrite(pin_powerFastOff, LOW);
46+
}
3647

37-
pinMode(pin_powerFastOff, OUTPUT);
38-
digitalWrite(pin_powerFastOff, LOW);
48+
if ((productVariant == RTK_FACET) || (productVariant == RTK_FACET_LBAND) || (productVariant == REFERENCE_STATION))
49+
digitalWrite(pin_peripheralPowerControl, LOW);
3950

4051
while (1)
4152
delay(1);

Firmware/RTK_Surveyor/FileSdFatMMC.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,16 @@ class FileSdFatMMC : public SdFile
166166
#endif
167167
};
168168

169+
void flush()
170+
{
171+
if (USE_SPI_MICROSD)
172+
_sdFile->flush();
173+
#ifdef COMPILE_SD_MMC
174+
else
175+
_file->flush();
176+
#endif
177+
};
178+
169179
void updateFileAccessTimestamp()
170180
{
171181
if (USE_SPI_MICROSD)

Firmware/RTK_Surveyor/RTK_Surveyor.ino

Lines changed: 34 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -60,39 +60,39 @@
6060
//Hardware connections
6161
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
6262
//These pins are set in beginBoard()
63-
int pin_batteryLevelLED_Red;
64-
int pin_batteryLevelLED_Green;
65-
int pin_positionAccuracyLED_1cm;
66-
int pin_positionAccuracyLED_10cm;
67-
int pin_positionAccuracyLED_100cm;
68-
int pin_baseStatusLED;
69-
int pin_bluetoothStatusLED;
70-
int pin_microSD_CS;
71-
int pin_zed_tx_ready;
72-
int pin_zed_reset;
73-
int pin_batteryLevel_alert;
74-
75-
int pin_muxA;
76-
int pin_muxB;
77-
int pin_powerSenseAndControl;
78-
int pin_setupButton;
79-
int pin_powerFastOff;
80-
int pin_dac26;
81-
int pin_adc39;
82-
int pin_peripheralPowerControl;
83-
84-
int pin_radio_rx;
85-
int pin_radio_tx;
86-
int pin_radio_rst;
87-
int pin_radio_pwr;
88-
int pin_radio_cts;
89-
int pin_radio_rts;
90-
91-
int pin_Ethernet_CS;
92-
int pin_Ethernet_Interrupt;
93-
int pin_GNSS_CS;
94-
int pin_GNSS_TimePulse;
95-
int pin_microSD_CardDetect;
63+
int pin_batteryLevelLED_Red = -1;
64+
int pin_batteryLevelLED_Green = -1;
65+
int pin_positionAccuracyLED_1cm = -1;
66+
int pin_positionAccuracyLED_10cm = -1;
67+
int pin_positionAccuracyLED_100cm = -1;
68+
int pin_baseStatusLED = -1;
69+
int pin_bluetoothStatusLED = -1;
70+
int pin_microSD_CS = -1;
71+
int pin_zed_tx_ready = -1;
72+
int pin_zed_reset = -1;
73+
int pin_batteryLevel_alert = -1;
74+
75+
int pin_muxA = -1;
76+
int pin_muxB = -1;
77+
int pin_powerSenseAndControl = -1;
78+
int pin_setupButton = -1;
79+
int pin_powerFastOff = -1;
80+
int pin_dac26 = -1;
81+
int pin_adc39 = -1;
82+
int pin_peripheralPowerControl = -1;
83+
84+
int pin_radio_rx = -1;
85+
int pin_radio_tx = -1;
86+
int pin_radio_rst = -1;
87+
int pin_radio_pwr = -1;
88+
int pin_radio_cts = -1;
89+
int pin_radio_rts = -1;
90+
91+
int pin_Ethernet_CS = -1;
92+
int pin_Ethernet_Interrupt = -1;
93+
int pin_GNSS_CS = -1;
94+
int pin_GNSS_TimePulse = -1;
95+
int pin_microSD_CardDetect = -1;
9696
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
9797

9898
#include "esp_ota_ops.h" //Needed for partition counting and updateFromSD
@@ -308,7 +308,6 @@ volatile bool uart2pinned = false; //This variable is touched by core 0 but chec
308308

309309
volatile static int combinedSpaceRemaining = 0; //Overrun indicator
310310
volatile static long fileSize = 0; //Updated with each write
311-
volatile static long filePosition = 0; //Updated with each write
312311
int bufferOverruns = 0; //Running count of possible data losses since power-on
313312

314313
bool zedUartPassed = false; //Goes true during testing if ESP can communicate with ZED over UART
@@ -454,7 +453,6 @@ uint8_t loggingIconDisplayed = 0; //Increases every 500ms while logging
454453
uint8_t espnowIconDisplayed = 0; //Increases every 500ms while transmitting
455454

456455
uint64_t lastLogSize = 0;
457-
uint64_t lastLogPosition = 0;
458456
bool logIncreasing = false; //Goes true when log file is greater than lastLogSize or logPosition changes
459457
bool reuseLastLog = false; //Goes true if we have a reset due to software (rather than POR)
460458

@@ -792,7 +790,7 @@ void updateLogs()
792790
snprintf(eventData, sizeof(eventData), "%d,%d,%d,%d", triggerCount, triggerTowMsR, triggerTowSubMsR, triggerAccEst);
793791

794792
char nmeaMessage[82]; //Max NMEA sentence length is 82
795-
createNMEASentence(CUSTOM_NMEA_TYPE_EVENT, nmeaMessage, eventData); //textID, buffer, text
793+
createNMEASentence(CUSTOM_NMEA_TYPE_EVENT, nmeaMessage, sizeof(nmeaMessage), eventData); //textID, buffer, sizeOfBuffer, text
796794

797795
if (xSemaphoreTake(sdCardSemaphore, fatSemaphore_shortWait_ms) == pdPASS)
798796
{
@@ -844,11 +842,6 @@ void updateLogs()
844842
lastLogSize = fileSize;
845843
logIncreasing = true;
846844
}
847-
else if (filePosition != lastLogPosition)
848-
{
849-
lastLogPosition = filePosition;
850-
logIncreasing = true;
851-
}
852845
else
853846
{
854847
log_d("No increase in file size");

Firmware/RTK_Surveyor/States.ino

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ void updateSystemState()
101101
ledcWrite(ledBTChannel, 0); //Turn off BT LED
102102
}
103103

104+
if (productVariant == REFERENCE_STATION)
105+
digitalWrite(pin_baseStatusLED, LOW);
106+
104107
//Configure for rover mode
105108
displayRoverStart(0);
106109

@@ -232,6 +235,9 @@ void updateSystemState()
232235
ledcWrite(ledBTChannel, 0); //Turn off BT LED
233236
}
234237

238+
if (productVariant == REFERENCE_STATION)
239+
digitalWrite(pin_baseStatusLED, LOW);
240+
235241
displayBaseStart(0); //Show 'Base'
236242

237243
//Allow WiFi to continue running if NTRIP Client is needed for assisted survey in
@@ -271,7 +277,7 @@ void updateSystemState()
271277
{
272278
lastBaseLEDupdate = millis();
273279

274-
if (productVariant == RTK_SURVEYOR)
280+
if ((productVariant == RTK_SURVEYOR) || (productVariant == REFERENCE_STATION))
275281
digitalWrite(pin_baseStatusLED, !digitalRead(pin_baseStatusLED));
276282
}
277283

@@ -300,7 +306,7 @@ void updateSystemState()
300306
{
301307
lastBaseLEDupdate = millis();
302308

303-
if (productVariant == RTK_SURVEYOR)
309+
if ((productVariant == RTK_SURVEYOR) || (productVariant == REFERENCE_STATION))
304310
digitalWrite(pin_baseStatusLED, !digitalRead(pin_baseStatusLED));
305311
}
306312

@@ -313,7 +319,7 @@ void updateSystemState()
313319
systemPrintf("Observation Time: %d\r\n", svinObservationTime);
314320
systemPrintln("Base survey complete! RTCM now broadcasting.");
315321

316-
if (productVariant == RTK_SURVEYOR)
322+
if ((productVariant == RTK_SURVEYOR) || (productVariant == REFERENCE_STATION))
317323
digitalWrite(pin_baseStatusLED, HIGH); //Indicate survey complete
318324

319325
//Start the NTRIP server if requested
@@ -378,7 +384,7 @@ void updateSystemState()
378384
bool response = startFixedBase();
379385
if (response == true)
380386
{
381-
if (productVariant == RTK_SURVEYOR)
387+
if ((productVariant == RTK_SURVEYOR) || (productVariant == REFERENCE_STATION))
382388
digitalWrite(pin_baseStatusLED, HIGH); //Turn on base LED
383389

384390
//Start the NTRIP server if requested
@@ -431,7 +437,7 @@ void updateSystemState()
431437
if (online.logging == true)
432438
{
433439
char nmeaMessage[82]; //Max NMEA sentence length is 82
434-
createNMEASentence(CUSTOM_NMEA_TYPE_WAYPOINT, nmeaMessage, (char*)"CustomEvent"); //textID, buffer, text
440+
createNMEASentence(CUSTOM_NMEA_TYPE_WAYPOINT, nmeaMessage, sizeof(nmeaMessage), (char*)"CustomEvent"); //textID, buffer, sizeOfBuffer, text
435441
ubxFile->println(nmeaMessage);
436442
logged = true;
437443
}
@@ -597,16 +603,19 @@ void updateSystemState()
597603

598604
case (STATE_WIFI_CONFIG_NOT_STARTED):
599605
{
600-
if (productVariant == RTK_SURVEYOR)
606+
if ((productVariant == RTK_SURVEYOR) || (productVariant == REFERENCE_STATION))
601607
{
602608
//Start BT LED Fade to indicate start of WiFi
603609
btLEDTask.detach(); //Increase BT LED blinker task rate
604610
btLEDTask.attach(btLEDTaskPace33Hz, updateBTled); //Rate in seconds, callback
605611

606612
digitalWrite(pin_baseStatusLED, LOW);
607-
digitalWrite(pin_positionAccuracyLED_1cm, LOW);
608-
digitalWrite(pin_positionAccuracyLED_10cm, LOW);
609-
digitalWrite(pin_positionAccuracyLED_100cm, LOW);
613+
if (productVariant == RTK_SURVEYOR)
614+
{
615+
digitalWrite(pin_positionAccuracyLED_1cm, LOW);
616+
digitalWrite(pin_positionAccuracyLED_10cm, LOW);
617+
digitalWrite(pin_positionAccuracyLED_100cm, LOW);
618+
}
610619
}
611620

612621
displayWiFiConfigNotStarted(); //Display immediately during SD cluster pause

Firmware/RTK_Surveyor/System.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ void setMuxport(int channelNumber)
489489
//Create $GNTXT, type message complete with CRC
490490
//https://www.nmea.org/Assets/20160520%20txt%20amendment.pdf
491491
//Used for recording system events (boot reason, event triggers, etc) inside the log
492-
void createNMEASentence(customNmeaType_e textID, char *nmeaMessage, char *textMessage)
492+
void createNMEASentence(customNmeaType_e textID, char *nmeaMessage, size_t sizeOfNmeaMessage, char *textMessage)
493493
{
494494
//Currently we don't have messages longer than 82 char max so we hardcode the sentence numbers
495495
const uint8_t totalNumberOfSentences = 1;
@@ -503,7 +503,7 @@ void createNMEASentence(customNmeaType_e textID, char *nmeaMessage, char *textMe
503503
for (byte x = 1 ; x < strlen(nmeaTxt) - 1; x++)
504504
CRC = CRC ^ nmeaTxt[x];
505505

506-
snprintf(nmeaMessage, sizeof(nmeaMessage), "%s%02X", nmeaTxt, CRC);
506+
snprintf(nmeaMessage, sizeOfNmeaMessage, "%s%02X", nmeaTxt, CRC);
507507
}
508508

509509
//Reset settings struct to default initializers

Firmware/RTK_Surveyor/Tasks.ino

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -408,21 +408,22 @@ void handleGNSSDataTask(void *e)
408408
long startTime = millis();
409409

410410
sdBytesToRecord = ubxFile->write(&ringBuffer[sdTail], sliceToRecord);
411+
if (USE_MMC_MICROSD)
412+
ubxFile->flush();
411413
fileSize = ubxFile->fileSize(); //Update file size
412-
filePosition = ubxFile->position(); //Update file position
413414

414415
sdFreeSpace -= sliceToRecord; //Update remaining space on SD
415416

416417
//Force file sync every 60s
417418
if (millis() - lastUBXLogSyncTime > 60000)
418419
{
419-
if (productVariant == RTK_SURVEYOR)
420+
if ((productVariant == RTK_SURVEYOR) || (productVariant == REFERENCE_STATION))
420421
digitalWrite(pin_baseStatusLED, !digitalRead(pin_baseStatusLED)); //Blink LED to indicate logging activity
421422

422423
ubxFile->sync();
423424
ubxFile->updateFileAccessTimestamp(); // Update the file access time & date
424425

425-
if (productVariant == RTK_SURVEYOR)
426+
if ((productVariant == RTK_SURVEYOR) || (productVariant == REFERENCE_STATION))
426427
digitalWrite(pin_baseStatusLED, !digitalRead(pin_baseStatusLED)); //Return LED to previous state
427428

428429
lastUBXLogSyncTime = millis();

Firmware/RTK_Surveyor/menuFirmware.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ void updateFromSD(const char *firmwareFileName)
374374
//Bulk write from the SD file to flash
375375
while (firmwareFile.available())
376376
{
377-
if (productVariant == RTK_SURVEYOR)
377+
if ((productVariant == RTK_SURVEYOR) || (productVariant == REFERENCE_STATION))
378378
digitalWrite(pin_baseStatusLED, !digitalRead(pin_baseStatusLED)); //Toggle LED to indcate activity
379379

380380
int bytesToWrite = pageSize; //Max number of bytes to read

Firmware/RTK_Surveyor/menuMessages.ino

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,6 @@ void beginLogging(const char *customFileName)
374374

375375
fileSize = 0;
376376
lastLogSize = 0; //Reset counter - used for displaying active logging icon
377-
lastLogPosition = 0;
378377

379378
bufferOverruns = 0; //Reset counter
380379

@@ -404,25 +403,25 @@ void beginLogging(const char *customFileName)
404403

405404
//Mark top of log with system information
406405
char nmeaMessage[82]; //Max NMEA sentence length is 82
407-
createNMEASentence(CUSTOM_NMEA_TYPE_RESET_REASON, nmeaMessage, rstReason); //textID, buffer, text
406+
createNMEASentence(CUSTOM_NMEA_TYPE_RESET_REASON, nmeaMessage, sizeof(nmeaMessage), rstReason); //textID, buffer, sizeOfBuffer, text
408407
ubxFile->println(nmeaMessage);
409408

410409
//Record system firmware versions and info to log
411410

412411
//SparkFun RTK Express v1.10-Feb 11 2022
413412
char firmwareVersion[30]; //v1.3 December 31 2021
414413
snprintf(firmwareVersion, sizeof(firmwareVersion), "v%d.%d-%s", FIRMWARE_VERSION_MAJOR, FIRMWARE_VERSION_MINOR, __DATE__);
415-
createNMEASentence(CUSTOM_NMEA_TYPE_SYSTEM_VERSION, nmeaMessage, firmwareVersion); //textID, buffer, text
414+
createNMEASentence(CUSTOM_NMEA_TYPE_SYSTEM_VERSION, nmeaMessage, sizeof(nmeaMessage), firmwareVersion); //textID, buffer, sizeOfBuffer, text
416415
ubxFile->println(nmeaMessage);
417416

418417
//ZED-F9P firmware: HPG 1.30
419-
createNMEASentence(CUSTOM_NMEA_TYPE_ZED_VERSION, nmeaMessage, zedFirmwareVersion); //textID, buffer, text
418+
createNMEASentence(CUSTOM_NMEA_TYPE_ZED_VERSION, nmeaMessage, sizeof(nmeaMessage), zedFirmwareVersion); //textID, buffer, sizeOfBuffer, text
420419
ubxFile->println(nmeaMessage);
421420

422421
//Device BT MAC. See issue: https://github.com/sparkfun/SparkFun_RTK_Firmware/issues/346
423422
char macAddress[5];
424423
snprintf(macAddress, sizeof(macAddress), "%02X%02X", btMACAddress[4], btMACAddress[5]);
425-
createNMEASentence(CUSTOM_NMEA_TYPE_DEVICE_BT_ID, nmeaMessage, macAddress); //textID, buffer, text
424+
createNMEASentence(CUSTOM_NMEA_TYPE_DEVICE_BT_ID, nmeaMessage, sizeof(nmeaMessage), macAddress); //textID, buffer, sizeOfBuffer, text
426425
ubxFile->println(nmeaMessage);
427426

428427
if (reuseLastLog == true)
@@ -467,7 +466,7 @@ void endLogging(bool gotSemaphore, bool releaseSemaphore)
467466
failedParserMessages_UBX);
468467

469468
char nmeaMessage[82]; //Max NMEA sentence length is 82
470-
createNMEASentence(CUSTOM_NMEA_TYPE_PARSER_STATS, nmeaMessage, parserStats); //textID, buffer, text
469+
createNMEASentence(CUSTOM_NMEA_TYPE_PARSER_STATS, nmeaMessage, sizeof(nmeaMessage), parserStats); //textID, buffer, sizeOfBuffer, text
471470
ubxFile->println(nmeaMessage);
472471
ubxFile->sync();
473472

@@ -842,7 +841,7 @@ void updateLogTest()
842841
snprintf(logMessage, sizeof(logMessage), "Start log test: %dHz, %dMsg, %dMS", rate, messages, semaphoreWait);
843842

844843
char nmeaMessage[100]; //Max NMEA sentence length is 82
845-
createNMEASentence(CUSTOM_NMEA_TYPE_LOGTEST_STATUS, nmeaMessage, logMessage); //textID, buffer, text
844+
createNMEASentence(CUSTOM_NMEA_TYPE_LOGTEST_STATUS, nmeaMessage, sizeof(nmeaMessage), logMessage); //textID, buffer, sizeOfBuffer, text
846845

847846
if (xSemaphoreTake(sdCardSemaphore, fatSemaphore_longWait_ms) == pdPASS)
848847
{

0 commit comments

Comments
 (0)