Skip to content

Commit 94169c4

Browse files
committed
TcpServer: Make port selection in tcpServerEnabled
1 parent 2b71961 commit 94169c4

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

Firmware/RTK_Everywhere/TcpServer.ino

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ const RtkMode_t tcpServerMode = RTK_MODE_ROVER
9292

9393
// TCP server
9494
static NetworkServer *tcpServer = nullptr;
95+
static uint16_t tcpServerPort;
9596
static uint8_t tcpServerState;
9697
static uint32_t tcpServerTimer;
9798
static const char * tcpServerName;
@@ -172,6 +173,7 @@ bool tcpServerEnabled(const char ** line)
172173
{
173174
bool enabled;
174175
const char * name;
176+
uint16_t port;
175177

176178
do
177179
{
@@ -190,6 +192,7 @@ bool tcpServerEnabled(const char ** line)
190192
{
191193
// TCP server running in Rover mode
192194
name = "TCP Server";
195+
port = settings.tcpServerPort;
193196
}
194197

195198
// Determine if the base caster should be running
@@ -200,10 +203,12 @@ bool tcpServerEnabled(const char ** line)
200203
if (settings.baseCasterOverride)
201204
{
202205
name = "Base Caster";
206+
port = 2101;
203207
}
204208
else
205209
{
206210
name = "NTRIP Caster";
211+
port = settings.tcpServerPort;
207212
}
208213
}
209214

@@ -219,10 +224,12 @@ bool tcpServerEnabled(const char ** line)
219224
{
220225
// Update the TCP server configuration
221226
tcpServerName = name;
227+
tcpServerPort = port;
222228
}
223229

224230
// Shutdown and restart the TCP server when configuration changes
225-
else if (name != tcpServerName)
231+
else if ((name != tcpServerName)
232+
|| (port != tcpServerPort))
226233
{
227234
*line = ", Wrong state to switch configuration!";
228235
break;
@@ -331,12 +338,8 @@ bool tcpServerStart()
331338
if (settings.debugTcpServer && (!inMainMenu))
332339
systemPrintf("%s starting the server\r\n", tcpServerName);
333340

334-
uint16_t tcpPort = settings.tcpServerPort;
335-
if(settings.baseCasterOverride == true)
336-
tcpPort = 2101;
337-
338341
// Start the TCP server
339-
tcpServer = new NetworkServer(tcpPort, TCP_SERVER_MAX_CLIENTS);
342+
tcpServer = new NetworkServer(tcpServerPort, TCP_SERVER_MAX_CLIENTS);
340343
if (!tcpServer)
341344
return false;
342345

@@ -345,7 +348,7 @@ bool tcpServerStart()
345348

346349
localIp = networkGetIpAddress();
347350
systemPrintf("%s online, IP address %s:%d\r\n", tcpServerName,
348-
localIp.toString().c_str(), tcpPort);
351+
localIp.toString().c_str(), tcpServerPort);
349352
return true;
350353
}
351354

0 commit comments

Comments
 (0)