Skip to content

Commit d81b361

Browse files
committed
Add support for console-over-TCP
1 parent a7326f7 commit d81b361

File tree

9 files changed

+147
-14
lines changed

9 files changed

+147
-14
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: 26 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,30 @@ void beginBoard()
174176
}
175177
}
176178

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

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: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@
4949
int pin_errorLED = -1;
5050
int pin_lockLED = -1;
5151

52+
const int pin_serial0TX = 1;
53+
const int pin_serial0RX = 3;
54+
55+
int pin_serial0TX_Alt = -1;
56+
int pin_serial0RX_Alt = -1;
57+
5258
int pin_serial1TX = -1;
5359
int pin_serial1RX = -1;
5460
int pin_serial1CTS = -1;
@@ -142,6 +148,7 @@ GPS_PARSE_TABLE;
142148
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
143149

144150
#include <driver/uart.h> // Required for uart_set_rx_full_threshold() on cores <v2.0.5
151+
HardwareSerial serialConsole(0); // Use UART0 for Console
145152
HardwareSerial serialGNSS(1); // Use UART1 for GNSS
146153
HardwareSerial serialGNSSConfig(2); // Use UART2 for GNSS configuration
147154

@@ -311,7 +318,7 @@ void setup()
311318
{
312319
initializeGlobals(); // Initialize any global variables that can't be given default values
313320

314-
Serial.begin(115200); // UART0 for programming and debugging
321+
beginConsole(false); // UART0 for programming and debugging. Don't allow Alt pins to be used yet
315322
systemPrintln();
316323
systemPrintln();
317324

@@ -370,9 +377,13 @@ void setup()
370377
DMW_c("beginGNSS");
371378
beginGNSS(); // Connect to GNSS
372379

373-
Serial.flush(); // Complete any previous prints
380+
DMW_c("configureGNSSTCPServer");
381+
configureGNSSTCPServer(); // Configure TCP
374382

375383
systemPrintf("Boot time: %d\r\n", millis());
384+
385+
serialConsole.flush(); // Complete any previous prints
386+
beginConsole(true); // Swap to Alt pins if TCP is enabled
376387
}
377388

378389
void loop()

Firmware/RTK_mosaic-T_Firmware/menuMain.ino

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

94+
configureGNSSTCPServer(); // Configure TCP
95+
9496
recordSystemSettings(); // Once all menus have exited, record the new settings to LittleFS and config file
9597

9698
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(",");

Firmware/RTK_mosaic-T_Firmware/settings.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,8 @@ typedef struct
273273
double Ik = 0.151; // PI I term
274274
bool preferNonCompositeGPSBias = false; // Prefer non-composite GPS bias - if available. Mutex with preferNonCompositeGalileoBias
275275
bool preferNonCompositeGalileoBias = false; // Prefer non-composite Galileo bias - if available. Mutex with preferNonCompositeGPSBias
276+
bool enableTCPServer = false; // Enable and configure mosaic-T IPS1 for TCP2way for the ESP32 console
277+
uint16_t tcpServerPort = 28785;
276278

277279
// Add new settings above <------------------------------------------------------------>
278280

Firmware/RTK_mosaic-T_Firmware/support.ino

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,25 @@
11
// Helper functions to support printing to eiter the serial port or bluetooth connection
22

3-
// If we are printing to all endpoints, BT gets priority
43
int systemAvailable()
54
{
6-
return (Serial.available());
5+
return (serialConsole.available());
76
}
87

9-
// If we are printing to all endpoints, BT gets priority
108
int systemRead()
119
{
12-
return (Serial.read());
10+
return (serialConsole.read());
1311
}
1412

1513
// Output a buffer of the specified length to the serial port
1614
void systemWrite(const uint8_t *buffer, uint16_t length)
1715
{
18-
Serial.write(buffer, length);
16+
serialConsole.write(buffer, length);
1917
}
2018

2119
// Ensure all serial output has been transmitted, FIFOs are empty
2220
void systemFlush()
2321
{
24-
Serial.flush();
22+
serialConsole.flush();
2523
}
2624

2725
// Output a byte to the serial port
@@ -747,7 +745,7 @@ void formatFirmwareVersion(char prefix, uint8_t major, uint8_t minor, char *buff
747745
// The buffer is too small for the version number
748746
else
749747
{
750-
Serial.printf("ERROR: Buffer too small for version number!\r\n");
748+
serialConsole.printf("ERROR: Buffer too small for version number!\r\n");
751749
if (bufferLength > 0)
752750
*buffer = 0;
753751
}

0 commit comments

Comments
 (0)