Skip to content

Commit 97dcc45

Browse files
committed
Better TCP support - display the port on the OLED
1 parent d81b361 commit 97dcc45

File tree

8 files changed

+85
-22
lines changed

8 files changed

+85
-22
lines changed

Firmware/RTK_mosaic-T_Firmware/Begin.ino

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,13 @@ void beginBoard()
176176
}
177177
}
178178

179-
void beginConsole(bool allowAlt)
179+
void beginConsole(uint32_t baud, bool allowAlt)
180180
{
181+
// Don't try to print here. serialConsole may not have been initialized
182+
181183
if ((!allowAlt) || (!settings.enableTCPServer))
182184
{
183-
serialConsole.begin(115200, SERIAL_8N1, pin_serial0RX, pin_serial0TX);
185+
serialConsole.begin(baud, SERIAL_8N1, pin_serial0RX, pin_serial0TX);
184186
}
185187
else
186188
{
@@ -190,7 +192,7 @@ void beginConsole(bool allowAlt)
190192
}
191193
else
192194
{
193-
serialConsole.begin(115200, SERIAL_8N1, pin_serial0RX_Alt, pin_serial0TX_Alt);
195+
serialConsole.begin(baud, SERIAL_8N1, pin_serial0RX_Alt, pin_serial0TX_Alt);
194196
}
195197
}
196198

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/RTK_mosaic-T_Firmware.ino

Lines changed: 34 additions & 13 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
@@ -318,7 +326,7 @@ void setup()
318326
{
319327
initializeGlobals(); // Initialize any global variables that can't be given default values
320328

321-
beginConsole(false); // UART0 for programming and debugging. Don't allow Alt pins to be used yet
329+
beginConsole(115200, false); // UART0 for programming and debugging. Don't allow Alt pins to be used yet
322330
systemPrintln();
323331
systemPrintln();
324332

@@ -382,8 +390,10 @@ void setup()
382390

383391
systemPrintf("Boot time: %d\r\n", millis());
384392

385-
serialConsole.flush(); // Complete any previous prints
386-
beginConsole(true); // Swap to Alt pins if TCP is enabled
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
387397
}
388398

389399
void loop()
@@ -413,22 +423,30 @@ void loop()
413423
// Once we have a fix, sync system clock to GNSS
414424
void updateRTC()
415425
{
426+
static uint16_t syncAge = 0;
427+
416428
static bool firstTime = true;
417429
if (firstTime)
418430
{
419431
gnssTimeUpdated[0] = false; // This ensures gnssTimeUpdated[0] isn't stale
420432
firstTime = false;
421433
}
422434

423-
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
424436
{
425-
if (online.gnss == true) // Only do this if the GNSS is online
437+
if (gnssTimeUpdated[0]) // Only do this if we have fresh time
426438
{
427-
if (gnssTimeUpdated[0])
428-
{
429-
gnssTimeUpdated[0] = false;
439+
gnssTimeUpdated[0] = false;
430440

431-
if (gnssWNSet && gnssToWSet && gnssFineTime)
441+
syncAge++; // Update syncAge every second
442+
if (syncAge == 3600) // Wrap every hour
443+
syncAge = 0;
444+
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))
432450
{
433451
// To perform the time zone adjustment correctly, it's easiest if we convert the GNSS time and date
434452
// into Unix epoch first and then correct for the arrival time
@@ -443,11 +461,14 @@ void updateRTC()
443461

444462
online.rtc = true;
445463

446-
systemPrint("System time set to: ");
447-
systemPrintln(rtc.getDateTime(true));
464+
if (settings.enablePrintRtcSync)
465+
{
466+
systemPrint("System time set to: ");
467+
systemPrintln(rtc.getDateTime(true));
468+
}
448469
}
449470
}
450-
} // End online.gnss
451-
} // End online.rtc
471+
}
472+
}
452473
}
453474

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: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ void menuMain()
9393

9494
configureGNSSTCPServer(); // Configure TCP
9595

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+
96101
recordSystemSettings(); // Once all menus have exited, record the new settings to LittleFS and config file
97102

98103
clearBuffer(); // Empty buffer of any newline chars
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
@echo off
2+
3+
if [%1]==[] goto findPort
4+
5+
set COMPORT=%1
6+
goto erase
7+
8+
:findPort
9+
10+
for /f "tokens=2 delims=(" %%a in ('wmic path win32_pnpentity get caption /format:list ^| find "COM" ^| find "CH340"') do (
11+
for /f "tokens=1 delims=)" %%b in ("%%a") do (
12+
set COMPORT=%%b
13+
)
14+
)
15+
16+
:erase
17+
18+
set ESPTOOL="esptool.exe"
19+
20+
call %ESPTOOL% --chip esp32 -p %COMPORT% -b 460800 erase_flash

Firmware/Utils/esptool.exe

6.33 MB
Binary file not shown.

0 commit comments

Comments
 (0)