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
4957int pin_errorLED = -1 ;
5058int 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+
5266int pin_serial1TX = -1 ;
5367int pin_serial1RX = -1 ;
5468int 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
145160HardwareSerial serialGNSS (1 ); // Use UART1 for GNSS
146161HardwareSerial 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
378399void loop ()
@@ -402,22 +423,30 @@ void loop()
402423// Once we have a fix, sync system clock to GNSS
403424void 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
0 commit comments