Skip to content

Commit 0e0ce41

Browse files
authored
Merge pull request #2 from sparkfun/release_candidate
v1.1 - add TCP support
2 parents a7326f7 + 97dcc45 commit 0e0ce41

File tree

14 files changed

+226
-30
lines changed

14 files changed

+226
-30
lines changed

.github/workflows/build-for-release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ on:
66
env:
77
FILENAME_PREFIX: RTK_mosaic-T_Firmware
88
FIRMWARE_VERSION_MAJOR: 1
9-
FIRMWARE_VERSION_MINOR: 0
9+
FIRMWARE_VERSION_MINOR: 1
1010
CORE_VERSION: 3.0.1
1111

1212
jobs:

Firmware/RTK_mosaic-T_Firmware/Begin.ino

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ void beginBoard()
110110
pin_errorLED = 32;
111111
pin_lockLED = 33;
112112

113+
pin_serial0TX_Alt = 23;
114+
pin_serial0RX_Alt = 34;
113115
pin_serial1TX = 14;
114116
pin_serial1RX = 13;
115117
pin_serial1CTS = 26;
@@ -174,6 +176,32 @@ void beginBoard()
174176
}
175177
}
176178

179+
void beginConsole(uint32_t baud, bool allowAlt)
180+
{
181+
// Don't try to print here. serialConsole may not have been initialized
182+
183+
if ((!allowAlt) || (!settings.enableTCPServer))
184+
{
185+
serialConsole.begin(baud, SERIAL_8N1, pin_serial0RX, pin_serial0TX);
186+
}
187+
else
188+
{
189+
if ((pin_serial0RX_Alt < 0) || (pin_serial0TX_Alt < 0))
190+
{
191+
reportFatalError("No Serial0 Alt pins");
192+
}
193+
else
194+
{
195+
serialConsole.begin(baud, SERIAL_8N1, pin_serial0RX_Alt, pin_serial0TX_Alt);
196+
}
197+
}
198+
199+
delay(10);
200+
201+
while (serialConsole.available())
202+
serialConsole.read();
203+
}
204+
177205
// We want the UART1 interrupts to be pinned to core 0 to avoid competing with I2C interrupts
178206
// We do not start the UART1 here because the interrupts would be pinned to core 1
179207
// We instead start a task that runs on core 0, that then begins serial

Firmware/RTK_mosaic-T_Firmware/Display.ino

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,16 @@ void updateDisplay()
125125
oled->print(textLine);
126126
yPos += 8;
127127

128-
snprintf(textLine, sizeof(textLine), "IP %s",
129-
gnssIP.toString().c_str());
128+
if ((settings.enableTCPServer) && ((gnssSecond % 4) > 1)) // Print TCP Port for two seconds
129+
{
130+
snprintf(textLine, sizeof(textLine), "IP TCP Port %d",
131+
settings.tcpServerPort);
132+
}
133+
else
134+
{
135+
snprintf(textLine, sizeof(textLine), "IP %s",
136+
gnssIP.toString().c_str());
137+
}
130138
oled->setCursor(0, yPos);
131139
oled->print(textLine);
132140
yPos += 8;

Firmware/RTK_mosaic-T_Firmware/GNSS.ino

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,13 @@ bool initializeGNSS()
189189
return false;
190190
}
191191

192+
// Configure COM3 for daisy chain to IPS1
193+
if (!sendWithResponse("sdio, COM3, DC1, DC2\n\r", "DataInOut"))
194+
{
195+
systemPrintln("GNSS FAIL (DataInOut COM3)");
196+
return false;
197+
}
198+
192199
if (!sendWithResponse("sso, Stream1, COM1, Group1, sec1\n\r", "SBFOutput"))
193200
{
194201
systemPrintln("GNSS FAIL (SBFOutput Stream1)");
@@ -218,7 +225,7 @@ bool configureGNSSPPS()
218225

219226
systemPrintln("Configuring GNSS PPS");
220227

221-
String ppsParams = String("setPPSParameters, ");
228+
String ppsParams = String("spps, ");
222229
ppsParams += String(mosaicPPSParametersInterval[settings.ppsInterval]) + String(", ");
223230
ppsParams += String(mosaicPPSParametersPolarity[settings.ppsPolarity]) + String(", ");
224231
ppsParams += String(settings.ppsDelay_ns) + String(", ");
@@ -246,3 +253,57 @@ bool configureGNSSPPS()
246253
return true;
247254
}
248255

256+
bool configureGNSSTCPServer()
257+
{
258+
if (!online.gnss)
259+
return false;
260+
261+
systemPrintln("Configuring GNSS TCP Server");
262+
263+
String tcpParams = String("siss, IPS1, ");
264+
265+
if (settings.enableTCPServer)
266+
{
267+
tcpParams += String(settings.tcpServerPort) + String(", TCP2Way\n\r");
268+
}
269+
else
270+
{
271+
tcpParams += String("0\n\r");
272+
}
273+
274+
int retries = 3;
275+
276+
while (!sendWithResponse(tcpParams, "IPServerSettings") && (retries > 0))
277+
{
278+
systemPrintln("No response from mosaic. Retrying - with escape sequence...");
279+
sendWithResponse("SSSSSSSSSSSSSSSSSSSS\n\r", "COM4>"); // Send escape sequence
280+
retries--;
281+
}
282+
283+
if (retries == 0)
284+
{
285+
systemPrintln("GNSS FAIL (IPServerSettings)");
286+
return false;
287+
}
288+
289+
// Configure IPS1
290+
if (settings.enableTCPServer)
291+
{
292+
if (!sendWithResponse("sdio, IPS1, DC2, DC1\n\r", "DataInOut"))
293+
{
294+
systemPrintln("GNSS FAIL (DataInOut IPS1)");
295+
return false;
296+
}
297+
}
298+
else
299+
{
300+
if (!sendWithResponse("sdio, IPS1, none, none\n\r", "DataInOut"))
301+
{
302+
systemPrintln("GNSS FAIL (DataInOut IPS1)");
303+
return false;
304+
}
305+
}
306+
307+
systemPrintln("GNSS TCP Server configured");
308+
return true;
309+
}

Firmware/RTK_mosaic-T_Firmware/NVM.ino

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ void recordSystemSettingsToFile(File *settingsFile)
9898
settingsFile->printf("%s=%0.3e\r\n", "Ik", settings.Ik);
9999
settingsFile->printf("%s=%d\r\n", "preferNonCompositeGPSBias", settings.preferNonCompositeGPSBias);
100100
settingsFile->printf("%s=%d\r\n", "preferNonCompositeGalileoBias", settings.preferNonCompositeGalileoBias);
101+
settingsFile->printf("%s=%d\r\n", "enableTCPServer", settings.enableTCPServer);
102+
settingsFile->printf("%s=%d\r\n", "tcpServerPort", settings.tcpServerPort);
103+
101104

102105
//settingsFile->printf("%s=%d\r\n", "", settings.);
103106

@@ -366,6 +369,10 @@ bool parseLine(char *str, Settings *settings)
366369
settings->preferNonCompositeGPSBias = d;
367370
else if (strcmp(settingName, "preferNonCompositeGalileoBias") == 0)
368371
settings->preferNonCompositeGalileoBias = d;
372+
else if (strcmp(settingName, "enableTCPServer") == 0)
373+
settings->enableTCPServer = d;
374+
else if (strcmp(settingName, "tcpServerPort") == 0)
375+
settings->tcpServerPort = d;
369376

370377
//else if (strcmp(settingName, "") == 0)
371378
// settings-> = d;

Firmware/RTK_mosaic-T_Firmware/RTK_mosaic-T_Firmware.ino

Lines changed: 44 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@
1111
Set the board to "ESP32 Wrover Module"
1212
1313
Settings are pulled from ESP32's file system LittleFS.
14+
15+
Version history:
16+
1.0: Initial release
17+
1.1: Add TCP support
18+
The console can be accessed via TCP (COM3 is daisy chained to IPS1)
19+
On the v1.0 PCB, link:
20+
mosaic COM3 TX (TX3) to ESP32 GPIO 34
21+
mosaic COM3 RX (RX3) to ESP32 GPIO 23
1422
*/
1523

1624
// This is passed in from compiler extra flags
@@ -49,6 +57,12 @@
4957
int pin_errorLED = -1;
5058
int pin_lockLED = -1;
5159

60+
const int pin_serial0TX = 1;
61+
const int pin_serial0RX = 3;
62+
63+
int pin_serial0TX_Alt = -1;
64+
int pin_serial0RX_Alt = -1;
65+
5266
int pin_serial1TX = -1;
5367
int pin_serial1RX = -1;
5468
int pin_serial1CTS = -1;
@@ -142,6 +156,7 @@ GPS_PARSE_TABLE;
142156
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
143157

144158
#include <driver/uart.h> // Required for uart_set_rx_full_threshold() on cores <v2.0.5
159+
HardwareSerial serialConsole(0); // Use UART0 for Console
145160
HardwareSerial serialGNSS(1); // Use UART1 for GNSS
146161
HardwareSerial serialGNSSConfig(2); // Use UART2 for GNSS configuration
147162

@@ -311,7 +326,7 @@ void setup()
311326
{
312327
initializeGlobals(); // Initialize any global variables that can't be given default values
313328

314-
Serial.begin(115200); // UART0 for programming and debugging
329+
beginConsole(115200, false); // UART0 for programming and debugging. Don't allow Alt pins to be used yet
315330
systemPrintln();
316331
systemPrintln();
317332

@@ -370,9 +385,15 @@ void setup()
370385
DMW_c("beginGNSS");
371386
beginGNSS(); // Connect to GNSS
372387

373-
Serial.flush(); // Complete any previous prints
388+
DMW_c("configureGNSSTCPServer");
389+
configureGNSSTCPServer(); // Configure TCP
374390

375391
systemPrintf("Boot time: %d\r\n", millis());
392+
393+
if (settings.enableTCPServer)
394+
systemPrintf("TCP Server is enabled. Please connect on port %d to view the console\r\n", settings.tcpServerPort);
395+
396+
beginConsole(115200, true); // Swap to Alt pins if TCP is enabled
376397
}
377398

378399
void loop()
@@ -402,22 +423,30 @@ void loop()
402423
// Once we have a fix, sync system clock to GNSS
403424
void updateRTC()
404425
{
426+
static uint16_t syncAge = 0;
427+
405428
static bool firstTime = true;
406429
if (firstTime)
407430
{
408431
gnssTimeUpdated[0] = false; // This ensures gnssTimeUpdated[0] isn't stale
409432
firstTime = false;
410433
}
411434

412-
if (online.rtc == false) // Only do this if the rtc has not been sync'd previously
435+
if (online.gnss == true) // Only do this if the GNSS is online
413436
{
414-
if (online.gnss == true) // Only do this if the GNSS is online
437+
if (gnssTimeUpdated[0]) // Only do this if we have fresh time
415438
{
416-
if (gnssTimeUpdated[0])
417-
{
418-
gnssTimeUpdated[0] = false;
439+
gnssTimeUpdated[0] = false;
440+
441+
syncAge++; // Update syncAge every second
442+
if (syncAge == 3600) // Wrap every hour
443+
syncAge = 0;
419444

420-
if (gnssWNSet && gnssToWSet && gnssFineTime)
445+
if (gnssWNSet && gnssToWSet && gnssFineTime) // Only do this if FineTime is set
446+
{
447+
// Only do this if the rtc has not been sync'd previously
448+
// or if it is an hour since the last sync
449+
if ((online.rtc == false) || (syncAge == 0))
421450
{
422451
// To perform the time zone adjustment correctly, it's easiest if we convert the GNSS time and date
423452
// into Unix epoch first and then correct for the arrival time
@@ -432,11 +461,14 @@ void updateRTC()
432461

433462
online.rtc = true;
434463

435-
systemPrint("System time set to: ");
436-
systemPrintln(rtc.getDateTime(true));
464+
if (settings.enablePrintRtcSync)
465+
{
466+
systemPrint("System time set to: ");
467+
systemPrintln(rtc.getDateTime(true));
468+
}
437469
}
438470
}
439-
} // End online.gnss
440-
} // End online.rtc
471+
}
472+
}
441473
}
442474

Firmware/RTK_mosaic-T_Firmware/System.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ void reportHeap()
1414
{
1515
if (settings.enableHeapReport == true)
1616
{
17-
if (millis() - lastHeapReport > 1000)
17+
if (millis() - lastHeapReport >= settings.periodicPrintInterval_ms)
1818
{
1919
reportHeapNow(false);
2020
}

Firmware/RTK_mosaic-T_Firmware/Tasks.ino

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,14 @@ void gnssReadTask(void *e)
115115
while (true)
116116
{
117117
if ((settings.enableTaskReports == true) && !inMainMenu)
118-
systemPrintf("SerialReadTask High watermark: %d\r\n", uxTaskGetStackHighWaterMark(nullptr));
118+
{
119+
static unsigned long lastPrint = 0;
120+
if (millis() > (lastPrint + settings.periodicPrintInterval_ms))
121+
{
122+
systemPrintf("SerialReadTask High watermark: %d\r\n", uxTaskGetStackHighWaterMark(nullptr));
123+
lastPrint = millis();
124+
}
125+
}
119126

120127
while (serialGNSS.available())
121128
{
@@ -710,11 +717,11 @@ void ButtonCheckTask(void *e)
710717
{
711718
setupBtn->read();
712719

713-
if (setupBtn->isPressed()) // Switch is set to base mode
720+
if (setupBtn->isPressed())
714721
{
715722
// Do stuff... Maybe change the display?
716723
}
717-
else if (setupBtn->wasReleased()) // Switch is set to Rover
724+
else if (setupBtn->wasReleased())
718725
{
719726
// Do stuff... Maybe change the display?
720727
}

Firmware/RTK_mosaic-T_Firmware/menuMain.ino

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,13 @@ void menuMain()
9191
printUnknown(incoming);
9292
}
9393

94+
configureGNSSTCPServer(); // Configure TCP
95+
96+
if (settings.enableTCPServer)
97+
systemPrintf("TCP Server is enabled. Please connect on port %d to view the console\r\n", settings.tcpServerPort);
98+
99+
beginConsole(115200, true); // Swap to Alt pins if TCP is enabled
100+
94101
recordSystemSettings(); // Once all menus have exited, record the new settings to LittleFS and config file
95102

96103
clearBuffer(); // Empty buffer of any newline chars

Firmware/RTK_mosaic-T_Firmware/menuSystem.ino

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,12 @@ void menuOperation()
398398
systemPrint("13) Pulse-Per-Second Pulse Width (ms): ");
399399
systemPrintln(settings.ppsPulseWidth_ms);
400400

401+
systemPrint("14) TCP Server (IPS1): ");
402+
systemPrintf("%s\r\n", settings.enableTCPServer ? "Enabled" : "Disabled");
403+
404+
systemPrint("15) TCP Server Port: ");
405+
systemPrintln(settings.tcpServerPort);
406+
401407
systemPrintln("\r\nx) Exit");
402408

403409
byte incoming = getCharacterNumber();
@@ -534,6 +540,25 @@ void menuOperation()
534540
ppsStarted = false; // Restart PPS afterwards
535541
}
536542
}
543+
else if (incoming == 14)
544+
{
545+
settings.enableTCPServer ^= 1;
546+
}
547+
else if (incoming == 15)
548+
{
549+
systemPrint("Enter the TCP Server Port: ");
550+
int port = getNumber(); // Returns EXIT, TIMEOUT, or long
551+
if ((port != INPUT_RESPONSE_GETNUMBER_EXIT) &&
552+
(port != INPUT_RESPONSE_GETNUMBER_TIMEOUT))
553+
{
554+
if (port < 1 || port > 65534)
555+
systemPrintln("Error: Port is out of range");
556+
else
557+
{
558+
settings.tcpServerPort = port;
559+
}
560+
}
561+
}
537562
// Menu exit control
538563
else if (incoming == 'x')
539564
break;
@@ -563,12 +588,13 @@ void printCurrentConditions(bool CSV)
563588
firstTime = false;
564589
}
565590

566-
systemPrintf("%04d/%02d/%02d,%02d:%02d:%02d",
567-
gnssYear, gnssMonth, gnssDay, gnssHour, gnssMinute, gnssSecond);
568-
569591
uint32_t epochSecs;
570592
uint32_t epochMillis;
571593
convertGnssTimeToEpoch(&epochSecs, &epochMillis);
594+
595+
systemPrintf("%04d/%02d/%02d,%02d:%02d:%02d",
596+
gnssYear, gnssMonth, gnssDay, gnssHour, gnssMinute, gnssSecond);
597+
572598
systemPrintf(",%lu.%03lu", epochSecs, epochMillis);
573599

574600
systemPrint(",");

0 commit comments

Comments
 (0)