Skip to content

Commit 2b71961

Browse files
committed
TcpServer: Output TCP Server, NTRIP Caster or Base Caster messages
1 parent 5555408 commit 2b71961

File tree

1 file changed

+77
-27
lines changed

1 file changed

+77
-27
lines changed

Firmware/RTK_Everywhere/TcpServer.ino

Lines changed: 77 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ const char *const tcpServerStateName[] = {
8282

8383
const int tcpServerStateNameEntries = sizeof(tcpServerStateName) / sizeof(tcpServerStateName[0]);
8484

85-
const RtkMode_t tcpServerMode = RTK_MODE_BASE_FIXED | RTK_MODE_BASE_SURVEY_IN | RTK_MODE_ROVER;
85+
const RtkMode_t baseCasterMode = RTK_MODE_BASE_FIXED;
86+
const RtkMode_t tcpServerMode = RTK_MODE_ROVER
87+
| RTK_MODE_BASE_SURVEY_IN;
8688

8789
//----------------------------------------
8890
// Locals
@@ -92,6 +94,7 @@ const RtkMode_t tcpServerMode = RTK_MODE_BASE_FIXED | RTK_MODE_BASE_SURVEY_IN |
9294
static NetworkServer *tcpServer = nullptr;
9395
static uint8_t tcpServerState;
9496
static uint32_t tcpServerTimer;
97+
static const char * tcpServerName;
9598

9699
// TCP server clients
97100
static volatile uint8_t tcpServerClientConnected;
@@ -146,7 +149,8 @@ int32_t tcpServerClientSendData(int index, uint8_t *data, uint16_t length)
146149
if (length > 0)
147150
tcpServerClientDataSent = tcpServerClientDataSent | (1 << index);
148151
if ((settings.debugTcpServer || PERIODIC_DISPLAY(PD_TCP_SERVER_CLIENT_DATA)) && (!inMainMenu))
149-
systemPrintf("TCP server wrote %d bytes to %s\r\n", length,
152+
systemPrintf("%s wrote %d bytes to %s\r\n",
153+
tcpServerName, length,
150154
tcpServerClientIpAddress[index].toString().c_str());
151155
}
152156

@@ -167,22 +171,66 @@ int32_t tcpServerClientSendData(int index, uint8_t *data, uint16_t length)
167171
bool tcpServerEnabled(const char ** line)
168172
{
169173
bool enabled;
174+
const char * name;
170175

171176
do
172177
{
178+
// Determine if the server is enabled
173179
enabled = false;
180+
if ((settings.enableTcpServer
181+
|| settings.enableNtripCaster
182+
|| settings.baseCasterOverride) == false)
183+
{
184+
*line = ", Not enabled!";
185+
break;
186+
}
187+
188+
// Determine if the TCP server should be running
189+
if ((EQ_RTK_MODE(tcpServerMode) && settings.enableTcpServer))
190+
{
191+
// TCP server running in Rover mode
192+
name = "TCP Server";
193+
}
194+
195+
// Determine if the base caster should be running
196+
else if (EQ_RTK_MODE(baseCasterMode)
197+
&& (settings.enableNtripCaster || settings.baseCasterOverride))
198+
{
199+
// Select the base caster WiFi mode and port number
200+
if (settings.baseCasterOverride)
201+
{
202+
name = "Base Caster";
203+
}
204+
else
205+
{
206+
name = "NTRIP Caster";
207+
}
208+
}
174209

175-
// Verify the operating mode
176-
if (NEQ_RTK_MODE(tcpServerMode))
210+
// Wrong mode for TCP server or base caster operation
211+
else
177212
{
178213
*line = ", Wrong mode!";
179214
break;
180215
}
181216

182-
// Verify still enabled
183-
enabled = settings.enableTcpServer || settings.baseCasterOverride;
184-
if (enabled == false)
185-
*line = ", Not enabled!";
217+
// Only change modes when in off state
218+
if (tcpServerState == TCP_SERVER_STATE_OFF)
219+
{
220+
// Update the TCP server configuration
221+
tcpServerName = name;
222+
}
223+
224+
// Shutdown and restart the TCP server when configuration changes
225+
else if (name != tcpServerName)
226+
{
227+
*line = ", Wrong state to switch configuration!";
228+
break;
229+
}
230+
231+
// The server is enabled and in the correct mode
232+
*line = "";
233+
enabled = true;
186234
} while (0);
187235
return enabled;
188236
}
@@ -265,7 +313,7 @@ void tcpServerSetState(uint8_t newState)
265313
{
266314
if (newState >= TCP_SERVER_STATE_MAX)
267315
{
268-
systemPrintf("Unknown TCP Server state: %d\r\n", tcpServerState);
316+
systemPrintf("Unknown %s state: %d\r\n", tcpServerName, tcpServerState);
269317
reportFatalError("Unknown TCP Server state");
270318
}
271319
else
@@ -281,7 +329,7 @@ bool tcpServerStart()
281329
IPAddress localIp;
282330

283331
if (settings.debugTcpServer && (!inMainMenu))
284-
systemPrintln("TCP server starting the server");
332+
systemPrintf("%s starting the server\r\n", tcpServerName);
285333

286334
uint16_t tcpPort = settings.tcpServerPort;
287335
if(settings.baseCasterOverride == true)
@@ -296,12 +344,8 @@ bool tcpServerStart()
296344
online.tcpServer = true;
297345

298346
localIp = networkGetIpAddress();
299-
if (settings.enableNtripCaster || settings.baseCasterOverride)
300-
systemPrintf("TCP server online, IP address %s:%d, responding as NTRIP Caster\r\n", localIp.toString().c_str(),
301-
tcpPort);
302-
else
303-
systemPrintf("TCP server online, IP address %s:%d\r\n", localIp.toString().c_str(), tcpPort);
304-
347+
systemPrintf("%s online, IP address %s:%d\r\n", tcpServerName,
348+
localIp.toString().c_str(), tcpPort);
305349
return true;
306350
}
307351

@@ -316,7 +360,8 @@ void tcpServerStop()
316360
if (online.tcpServer)
317361
{
318362
if (settings.debugTcpServer && (!inMainMenu))
319-
systemPrintf("TcpServer: Notifying GNSS UART task to stop sending data\r\n");
363+
systemPrintf("%s: Notifying GNSS UART task to stop sending data\r\n",
364+
tcpServerName);
320365

321366
// Notify the GNSS UART tasks of the TCP server shutdown
322367
online.tcpServer = false;
@@ -336,15 +381,15 @@ void tcpServerStop()
336381
{
337382
// Stop the TCP server
338383
if (settings.debugTcpServer && (!inMainMenu))
339-
systemPrintln("TcpServer: Stopping the server");
384+
systemPrintf("%s: Stopping the server\r\n", tcpServerName);
340385
tcpServer->stop();
341386
delete tcpServer;
342387
tcpServer = nullptr;
343388
}
344389

345390
// Stop using the network
346391
if (settings.debugTcpServer && (!inMainMenu))
347-
systemPrintln("TcpServer: Stopping network consumers");
392+
systemPrintf("%s: Stopping network consumers\r\n", tcpServerName);
348393
networkConsumerOffline(NETCONSUMER_TCP_SERVER);
349394
if (tcpServerState != TCP_SERVER_STATE_OFF)
350395
{
@@ -379,10 +424,13 @@ void tcpServerStopClient(int index)
379424
dataSent = ((millis() - tcpServerTimer) < TCP_SERVER_CLIENT_DATA_TIMEOUT)
380425
|| (tcpServerClientDataSent & (1 << index));
381426
if (!dataSent)
382-
systemPrintf("TCP Server: No data sent over %d seconds\r\n", TCP_SERVER_CLIENT_DATA_TIMEOUT / 1000);
427+
systemPrintf("%s: No data sent over %d seconds\r\n",
428+
tcpServerName,
429+
TCP_SERVER_CLIENT_DATA_TIMEOUT / 1000);
383430
if (!connected)
384-
systemPrintf("TCP Server: Link to client broken\r\n");
385-
systemPrintf("TCP server client %d disconnected from %s\r\n", index,
431+
systemPrintf("%s: Link to client broken\r\n", tcpServerName);
432+
systemPrintf("%s client %d disconnected from %s\r\n",
433+
tcpServerName, index,
386434
tcpServerClientIpAddress[index].toString().c_str());
387435
}
388436

@@ -447,7 +495,7 @@ void tcpServerUpdate()
447495
if (enabled)
448496
{
449497
if (settings.debugTcpServer && (!inMainMenu))
450-
systemPrintln("TCP server start");
498+
systemPrintf("%s start/r/n", tcpServerName);
451499
if (settings.tcpUdpOverWiFiStation == true)
452500
networkConsumerAdd(NETCONSUMER_TCP_SERVER, NETWORK_ANY, __FILE__, __LINE__);
453501
else
@@ -485,7 +533,7 @@ void tcpServerUpdate()
485533
if ((settings.debugTcpServer || PERIODIC_DISPLAY(PD_TCP_SERVER_DATA)) && (!inMainMenu))
486534
{
487535
PERIODIC_CLEAR(PD_TCP_SERVER_DATA);
488-
systemPrintln("TCP server initiating shutdown");
536+
systemPrintf("%s initiating shutdown\r\n", tcpServerName);
489537
}
490538

491539
// Network connection failed, attempt to restart the network
@@ -510,7 +558,8 @@ void tcpServerUpdate()
510558
if (PERIODIC_DISPLAY(PD_TCP_SERVER_DATA) && (!inMainMenu))
511559
{
512560
PERIODIC_CLEAR(PD_TCP_SERVER_DATA);
513-
systemPrintf("TCP server client %d connected to %s\r\n", index,
561+
systemPrintf("%s client %d connected to %s\r\n",
562+
tcpServerName, index,
514563
tcpServerClientIpAddress[index].toString().c_str());
515564
}
516565
}
@@ -544,7 +593,8 @@ void tcpServerUpdate()
544593
if ((settings.debugTcpServer || PERIODIC_DISPLAY(PD_TCP_SERVER_DATA)) && (!inMainMenu))
545594
{
546595
PERIODIC_CLEAR(PD_TCP_SERVER_DATA);
547-
systemPrintf("TCP server client %d connected to %s\r\n", index,
596+
systemPrintf("%s client %d connected to %s\r\n",
597+
tcpServerName, index,
548598
tcpServerClientIpAddress[index].toString().c_str());
549599
}
550600

@@ -614,7 +664,7 @@ void tcpServerUpdate()
614664
// Periodically display the TCP state
615665
if (PERIODIC_DISPLAY(PD_TCP_SERVER_STATE) && (!inMainMenu))
616666
{
617-
systemPrintf("TCP Server state: %s%s\r\n",
667+
systemPrintf("%s state: %s%s\r\n", tcpServerName,
618668
tcpServerStateName[tcpServerState], line);
619669
PERIODIC_CLEAR(PD_TCP_SERVER_STATE);
620670
}

0 commit comments

Comments
 (0)