Skip to content

Commit f86db6b

Browse files
committed
Enable different msgs on BT vs Logging. Combine UBX/NMEA logs into one.
1 parent 4c4db37 commit f86db6b

File tree

12 files changed

+405
-488
lines changed

12 files changed

+405
-488
lines changed

Firmware/RTK_Surveyor/RTK_Surveyor.ino

Lines changed: 19 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,9 @@
3232
(Done) Firmware upgrade menu
3333
Enable various debug outputs sent over BT
3434
35-
Fix file date/time updates
35+
Test file date/time updates
3636
Test firmware loading
37-
Test file listing from debug menu
38-
Test file creation from cold start (date/time invalid)
39-
37+
Add blinking log file icon
4038
*/
4139

4240
const int FIRMWARE_VERSION_MAJOR = 1;
@@ -97,12 +95,8 @@ SPIClass spi = SPIClass(VSPI); //We need to pass the class into SD.begin so we c
9795

9896
char settingsFileName[40] = "SFE_Surveyor_Settings.txt"; //File to read/write system settings to
9997

100-
SdFile nmeaFile; //File that all gnss nmea setences are written to
10198
SdFile ubxFile; //File that all gnss ubx messages setences are written to
102-
103-
unsigned long lastNMEALogSyncTime = 0; //Used to record to SD every half second
10499
unsigned long lastUBXLogSyncTime = 0; //Used to record to SD every half second
105-
106100
long startLogTime_minutes = 0; //Mark when we start logging so we can stop logging after maxLogTime_minutes
107101

108102
//SdFat crashes when F9PSerialReadTask() is called in the middle of a ubx file write within loop()
@@ -131,8 +125,8 @@ uint32_t serverBytesSent = 0; //Just a running total
131125
#include <SparkFun_u-blox_GNSS_Arduino_Library.h> //http://librarymanager/All#SparkFun_u-blox_GNSS
132126
SFE_UBLOX_GNSS i2cGNSS;
133127

134-
//Note: There are two prevalent versions of the ZED-F9P: v1.12 (part# -01B) and v1.13 (-02B).
135-
//v1.13 causes the RTK LED to not function if SBAS is enabled. To avoid this, we
128+
//Note: There are two prevalent versions of the ZED-F9P: v1.12 (part# -01B) and v1.13 (-02B).
129+
//v1.13 causes the RTK LED to not function if SBAS is enabled. To avoid this, we
136130
//disable SBAS by default.
137131

138132
//Used for config ZED for things not supported in library: getPortSettings, getSerialRate, getNMEASettings, getRTCMSettings
@@ -141,6 +135,9 @@ SFE_UBLOX_GNSS i2cGNSS;
141135
uint8_t settingPayload[MAX_PAYLOAD_SIZE];
142136

143137
#define gnssFileBufferSize 16384 // Allocate 16KBytes of RAM for UBX message storage
138+
139+
TaskHandle_t F9PI2CTaskHandle = NULL; //Task for regularly checking I2C
140+
const int i2cTaskStackSize = 2000;
144141
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
145142

146143
//Battery fuel gauge and PWM LEDs
@@ -179,8 +176,7 @@ TaskHandle_t F9PSerialWriteTaskHandle = NULL; //Store handles so that we can kil
179176
TaskHandle_t startUART2TaskHandle = NULL; //Dummy task to start UART2 on core 0.
180177
bool uart2Started = false;
181178

182-
//Reduced stack size from 10,000 to 1,000 to make room for WiFi/NTRIP server capabilities
183-
//Increase stacks to 2k to allow for dual file write of NMEA/UBX using built in SD library
179+
//Reduced stack size from 10,000 to 2,000 to make room for WiFi/NTRIP server capabilities
184180
const int readTaskStackSize = 2000;
185181
const int writeTaskStackSize = 2000;
186182
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
@@ -308,7 +304,7 @@ void loop()
308304

309305
updateRTC(); //Set system time to GNSS once we have fix
310306

311-
updateLogs(); //Record any new UBX data. Create files or close NMEA and UBX files as needed.
307+
updateLogs(); //Record any new data. Create or close files as needed.
312308

313309
//Menu system via ESP32 USB connection
314310
if (Serial.available()) menuMain(); //Present user menu
@@ -319,42 +315,30 @@ void loop()
319315
delay(10); //A small delay prevents panic if no other I2C or functions are called
320316
}
321317

322-
//Create or close UBX/NMEA files as needed (startup or as user changes settings)
323-
//Push new UBX packets to log as needed
318+
//Create or close files as needed (startup or as user changes settings)
319+
//Push new data to log as needed
324320
void updateLogs()
325321
{
326-
if (online.nmeaLogging == false && settings.logNMEA == true)
327-
{
328-
beginLoggingNMEA();
329-
}
330-
else if (online.nmeaLogging == true && settings.logNMEA == false)
331-
{
332-
//Close down file
333-
nmeaFile.sync();
334-
nmeaFile.close();
335-
online.nmeaLogging = false;
336-
}
337-
338-
if (online.ubxLogging == false && settings.logUBX == true)
322+
if (online.logging == false && logMessages() == true)
339323
{
340-
beginLoggingUBX();
324+
beginLogging();
341325
}
342-
else if (online.ubxLogging == true && settings.logUBX == false)
326+
else if (online.logging == true && logMessages() == false)
343327
{
344328
//Close down file
345329
ubxFile.sync();
346330
ubxFile.close();
347-
online.ubxLogging = false;
331+
online.logging = false;
348332
}
349333

350-
if (online.ubxLogging == true)
334+
if (online.logging == true)
351335
{
352336
//Check if we are inside the max time window for logging
353337
if ((systemTime_minutes - startLogTime_minutes) < settings.maxLogTime_minutes)
354338
{
355339
while (i2cGNSS.fileBufferAvailable() >= sdWriteSize) // Check to see if we have at least sdWriteSize waiting in the buffer
356340
{
357-
//Attempt to write to file system. This avoids collisions with file writing in F9PSerialReadTask()
341+
//Attempt to write to file system. This avoids collisions with file writing from other functions like recordSystemSettingsToFile()
358342
if (xSemaphoreTake(xFATSemaphore, fatSemaphore_maxWait) == pdPASS)
359343
{
360344
uint8_t myBuffer[sdWriteSize]; // Create our own buffer to hold the data while we write it to SD card
@@ -382,17 +366,12 @@ void updateLogs()
382366
}
383367

384368
//Report file sizes to show recording is working
385-
if (online.nmeaLogging == true || online.ubxLogging == true)
369+
if (online.logging == true)
386370
{
387371
if (millis() - lastFileReport > 5000)
388372
{
389373
lastFileReport = millis();
390-
if (online.nmeaLogging == true && online.ubxLogging == true)
391-
Serial.printf("UBX and NMEA file size: %d / %d", ubxFile.fileSize(), nmeaFile.fileSize());
392-
else if (online.nmeaLogging == true)
393-
Serial.printf("NMEA file size: %d", nmeaFile.fileSize());
394-
else if (online.ubxLogging == true)
395-
Serial.printf("UBX file size: %d", ubxFile.fileSize());
374+
Serial.printf("UBX file size: %d", ubxFile.fileSize());
396375

397376
if ((systemTime_minutes - startLogTime_minutes) > settings.maxLogTime_minutes)
398377
Serial.printf(" reached max log time %d / System time %d",

Firmware/RTK_Surveyor/System.ino

Lines changed: 75 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ bool configureUbloxModule()
4040
#define OUTPUT_SETTING 14
4141
#define INPUT_SETTING 12
4242

43-
//UART1 will primarily be used to pass NMEA from ZED to ESP32 (eventually to cell phone)
43+
//UART1 will primarily be used to pass NMEA and UBX from ZED to ESP32 (eventually to cell phone)
4444
//but the phone can also provide RTCM data. So let's be sure to enable RTCM on UART1 input.
4545
//Protocol out = NMEA, protocol in = RTCM
4646
getPortSettings(COM_PORT_UART1); //Load the settingPayload with this port's settings
47-
if (settingPayload[OUTPUT_SETTING] != (COM_TYPE_NMEA) || settingPayload[INPUT_SETTING] != COM_TYPE_RTCM3)
47+
if (settingPayload[OUTPUT_SETTING] != (COM_TYPE_NMEA | COM_TYPE_UBX) || settingPayload[INPUT_SETTING] != COM_TYPE_RTCM3)
4848
{
49-
response &= i2cGNSS.setPortOutput(COM_PORT_UART1, COM_TYPE_NMEA); //Set the UART1 to output NMEA
49+
response &= i2cGNSS.setPortOutput(COM_PORT_UART1, COM_TYPE_NMEA | COM_TYPE_UBX); //Set the UART1 to output NMEA and UBX
5050
response &= i2cGNSS.setPortInput(COM_PORT_UART1, COM_TYPE_RTCM3); //Set the UART1 to input RTCM
5151
}
5252

@@ -66,9 +66,9 @@ bool configureUbloxModule()
6666
}
6767

6868
getPortSettings(COM_PORT_I2C); //Load the settingPayload with this port's settings
69-
if (settingPayload[OUTPUT_SETTING] != COM_TYPE_UBX || settingPayload[INPUT_SETTING] != COM_TYPE_UBX)
69+
if (settingPayload[OUTPUT_SETTING] != (COM_TYPE_UBX | COM_TYPE_NMEA) || settingPayload[INPUT_SETTING] != COM_TYPE_UBX)
7070
{
71-
response &= i2cGNSS.setPortOutput(COM_PORT_I2C, COM_TYPE_UBX); //Set the I2C port to output UBX only (turn off NMEA noise)
71+
response &= i2cGNSS.setPortOutput(COM_PORT_I2C, COM_TYPE_UBX | COM_TYPE_NMEA); //Set the I2C port to output UBX and NMEA
7272
response &= i2cGNSS.setPortInput(COM_PORT_I2C, COM_TYPE_UBX); //Set the I2C port to input UBX only
7373
}
7474

@@ -81,9 +81,8 @@ bool configureUbloxModule()
8181
response &= i2cGNSS.setPortInput(COM_PORT_USB, (COM_TYPE_UBX | COM_TYPE_NMEA | COM_TYPE_RTCM3)); //Set the USB port to everything
8282
}
8383

84-
response &= enableNMEASentences(COM_PORT_UART1); //Make sure the appropriate NMEA sentences are enabled
85-
86-
response &= enableRXMSentences(COM_PORT_I2C); //Make sure the appropriate RXM (RAXW and SFXBR) are enabled
84+
response &= enableMessages(COM_PORT_UART1, settings.broadcast); //Make sure the appropriate messages are enabled
85+
response &= enableMessages(COM_PORT_I2C, settings.log); //Make sure the appropriate messages are enabled
8786

8887
response &= i2cGNSS.setAutoPVT(true, false); //Tell the GPS to "send" each solution, but do not update stale data when accessed
8988
response &= i2cGNSS.setAutoHPPOSLLH(true, false); //Tell the GPS to "send" each high res solution, but do not update stale data when accessed
@@ -105,15 +104,14 @@ bool configureUbloxModule()
105104
return (false);
106105
}
107106

108-
//Enable callbacks and logging as needed
109-
if (settings.logRAWX == true)
110-
{
111-
i2cGNSS.logRXMRAWX(); // Enable RXM RAWX data logging
112-
}
113-
if (settings.logSFRBX == true)
114-
{
115-
i2cGNSS.logRXMSFRBX(); // Enable RXM SFRBX data logging
116-
}
107+
//Based on current settings, update the logging options within the GNSS library
108+
i2cGNSS.logRXMRAWX(settings.log.rawx);
109+
i2cGNSS.logRXMSFRBX(settings.log.sfrbx);
110+
111+
if (logNMEAMessages() == true)
112+
i2cGNSS.setNMEALoggingMask(SFE_UBLOX_FILTER_NMEA_ALL); // Enable logging of all enabled NMEA messages
113+
else
114+
i2cGNSS.setNMEALoggingMask(0); // Disable logging of all enabled NMEA messages
117115

118116
//Check rover switch and configure module accordingly
119117
//When switch is set to '1' = BASE, pin will be shorted to ground
@@ -143,57 +141,27 @@ bool configureUbloxModule()
143141
return (response);
144142
}
145143

146-
//Enable the RAWX and SFRBX message based on user's settings, on a given com port
147-
bool enableRXMSentences(uint8_t portType)
144+
//Enable the NMEA/UBX messages, based on given log or broadcast settings, for a given port
145+
bool enableMessages(uint8_t portType, gnssMessages messageSetting)
148146
{
149147
bool response = true;
150-
151-
if (settings.logRAWX == true)
152-
{
153-
if (getRAWXSettings(portType) != 1)
154-
response &= i2cGNSS.enableMessage(UBX_CLASS_RXM, UBX_RXM_RAWX, portType);
155-
}
156-
else if (settings.logRAWX == false)
157-
{
158-
if (getRAWXSettings(portType) != 0)
159-
response &= i2cGNSS.disableMessage(UBX_CLASS_RXM, UBX_RXM_RAWX, portType);
160-
}
161-
162-
if (settings.logSFRBX == true)
163-
{
164-
if (getSFRBXSettings(portType) != 1)
165-
response &= i2cGNSS.enableMessage(UBX_CLASS_RXM, UBX_RXM_SFRBX, portType);
166-
}
167-
else if (settings.logSFRBX == false)
168-
{
169-
if (getSFRBXSettings(portType) != 0)
170-
response &= i2cGNSS.disableMessage(UBX_CLASS_RXM, UBX_RXM_SFRBX, portType);
171-
}
172-
173-
return (response);
174-
}
175-
176-
//Enable the NMEA messages, based on user's settings, on a given com port
177-
bool enableNMEASentences(uint8_t portType)
178-
{
179-
bool response = true;
180-
if (settings.outputSentenceGGA == true)
148+
if (messageSetting.gga == true)
181149
{
182150
if (getNMEASettings(UBX_NMEA_GGA, portType) != 1)
183151
response &= i2cGNSS.enableNMEAMessage(UBX_NMEA_GGA, portType);
184152
}
185-
else if (settings.outputSentenceGGA == false)
153+
else if (messageSetting.gga == false)
186154
{
187155
if (getNMEASettings(UBX_NMEA_GGA, portType) != 0)
188156
response &= i2cGNSS.disableNMEAMessage(UBX_NMEA_GGA, portType);
189157
}
190158

191-
if (settings.outputSentenceGSA == true)
159+
if (messageSetting.gsa == true)
192160
{
193161
if (getNMEASettings(UBX_NMEA_GSA, portType) != 1)
194162
response &= i2cGNSS.enableNMEAMessage(UBX_NMEA_GSA, portType);
195163
}
196-
else if (settings.outputSentenceGSA == false)
164+
else if (messageSetting.gsa == false)
197165
{
198166
if (getNMEASettings(UBX_NMEA_GSA, portType) != 0)
199167
response &= i2cGNSS.disableNMEAMessage(UBX_NMEA_GSA, portType);
@@ -203,39 +171,61 @@ bool enableNMEASentences(uint8_t portType)
203171
//If the update rate is >1Hz then this data can overcome the BT capabilities causing timeouts and lag
204172
//So we set the GSV sentence to 1Hz regardless of update rate
205173
uint16_t measurementFrequency = (uint16_t)getMeasurementFrequency(); //Force to int
206-
if (settings.outputSentenceGSV == true)
174+
if (messageSetting.gsv == true)
207175
{
208176
if (getNMEASettings(UBX_NMEA_GSV, portType) != measurementFrequency)
209177
response &= i2cGNSS.enableNMEAMessage(UBX_NMEA_GSV, portType, measurementFrequency);
210178
}
211-
else if (settings.outputSentenceGSV == false)
179+
else if (messageSetting.gsv == false)
212180
{
213181
if (getNMEASettings(UBX_NMEA_GSV, portType) != 0)
214182
response &= i2cGNSS.disableNMEAMessage(UBX_NMEA_GSV, portType);
215183
}
216184

217-
if (settings.outputSentenceRMC == true)
185+
if (messageSetting.rmc == true)
218186
{
219187
if (getNMEASettings(UBX_NMEA_RMC, portType) != 1)
220188
response &= i2cGNSS.enableNMEAMessage(UBX_NMEA_RMC, portType);
221189
}
222-
else if (settings.outputSentenceRMC == false)
190+
else if (messageSetting.rmc == false)
223191
{
224192
if (getNMEASettings(UBX_NMEA_RMC, portType) != 0)
225193
response &= i2cGNSS.disableNMEAMessage(UBX_NMEA_RMC, portType);
226194
}
227195

228-
if (settings.outputSentenceGST == true)
196+
if (messageSetting.gst == true)
229197
{
230198
if (getNMEASettings(UBX_NMEA_GST, portType) != 1)
231199
response &= i2cGNSS.enableNMEAMessage(UBX_NMEA_GST, portType);
232200
}
233-
else if (settings.outputSentenceGST == false)
201+
else if (messageSetting.gst == false)
234202
{
235203
if (getNMEASettings(UBX_NMEA_GST, portType) != 0)
236204
response &= i2cGNSS.disableNMEAMessage(UBX_NMEA_GST, portType);
237205
}
238206

207+
if (messageSetting.rawx == true)
208+
{
209+
if (getRAWXSettings(portType) != 1)
210+
response &= i2cGNSS.enableMessage(UBX_CLASS_RXM, UBX_RXM_RAWX, portType);
211+
}
212+
else if (messageSetting.rawx == false)
213+
{
214+
if (getRAWXSettings(portType) != 0)
215+
response &= i2cGNSS.disableMessage(UBX_CLASS_RXM, UBX_RXM_RAWX, portType);
216+
}
217+
218+
if (messageSetting.sfrbx == true)
219+
{
220+
if (getSFRBXSettings(portType) != 1)
221+
response &= i2cGNSS.enableMessage(UBX_CLASS_RXM, UBX_RXM_SFRBX, portType);
222+
}
223+
else if (messageSetting.sfrbx == false)
224+
{
225+
if (getSFRBXSettings(portType) != 0)
226+
response &= i2cGNSS.disableMessage(UBX_CLASS_RXM, UBX_RXM_SFRBX, portType);
227+
}
228+
239229
return (response);
240230
}
241231

@@ -586,3 +576,29 @@ bool createTestFile()
586576

587577
return (false);
588578
}
579+
580+
//Returns true if any messages are enabled for logging
581+
bool logMessages()
582+
{
583+
if (logNMEAMessages())
584+
return (true);
585+
if (logUBXMessages())
586+
return (true);
587+
return (false);
588+
}
589+
590+
//Returns true if any of the NMEA messages are enabled for logging
591+
bool logNMEAMessages()
592+
{
593+
if (settings.log.gga == true || settings.log.gsa == true || settings.log.gsv == true || settings.log.rmc == true || settings.log.gst == true)
594+
return (true);
595+
return (false);
596+
}
597+
598+
//Returns true if any of the UBX messages are enabled for logging
599+
bool logUBXMessages()
600+
{
601+
if (settings.log.rawx == true || settings.log.sfrbx == true)
602+
return (true);
603+
return (false);
604+
}

Firmware/RTK_Surveyor/begin.ino

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,15 @@ void beginUART2()
8484
delay(1);
8585
}
8686

87+
//ESP32 requires the creation of an EEPROM space
88+
void beginEEPROM()
89+
{
90+
if (EEPROM.begin(EEPROM_SIZE) == false)
91+
Serial.println(F("beginEEPROM: Failed to initialize EEPROM"));
92+
else
93+
online.eeprom = true;
94+
}
95+
8796
void beginDisplay()
8897
{
8998
//0x3D is default on Qwiic board
@@ -149,7 +158,7 @@ void beginDisplay()
149158
//Connect to and configure ZED-F9P
150159
void beginGNSS()
151160
{
152-
if (settings.logUBX == true)
161+
if (logUBXMessages() == true)
153162
{
154163
i2cGNSS.disableUBX7Fcheck(); // RAWX data can legitimately contain 0x7F, so we need to disable the "7F" check in checkUbloxI2C
155164
}

0 commit comments

Comments
 (0)