Skip to content

Commit b8013f6

Browse files
committed
TcpServer: Don't send data until the client enters *_CLIENT_SENDING_DATA
1 parent 637da35 commit b8013f6

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

Firmware/RTK_Everywhere/TcpServer.ino

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ static const char * tcpServerName;
119119
// TCP server clients
120120
static volatile uint8_t tcpServerClientConnected;
121121
static volatile uint8_t tcpServerClientDataSent;
122+
static volatile uint8_t tcpServerClientSendingData;
122123
static uint32_t tcpServerClientTimer[TCP_SERVER_MAX_CLIENTS];
123124
static volatile uint8_t tcpServerClientWriteError;
124125
static NetworkClient *tcpServerClient[TCP_SERVER_MAX_CLIENTS];
@@ -295,7 +296,7 @@ int32_t tcpServerSendData(uint16_t dataHead)
295296
tail = tcpServerClientTails[index];
296297

297298
// Determine if the client is connected
298-
if (!(tcpServerClientConnected & (1 << index)))
299+
if ((tcpServerClientSendingData & (1 << index)) == 0)
299300
tail = dataHead;
300301
else
301302
{
@@ -437,6 +438,7 @@ void tcpServerClientUpdate(uint8_t index)
437438
tcpServerClient[index]->write(confirmConnection, strlen(confirmConnection));
438439

439440
// Start sending RTCM
441+
tcpServerClientSendingData = tcpServerClientSendingData | (1 << index);
440442
tcpServerClientState[index] = TCP_SERVER_CLIENT_SENDING_DATA;
441443
}
442444
break;
@@ -491,8 +493,11 @@ void tcpServerClientUpdate(uint8_t index)
491493
if (tcpServerInCasterMode)
492494
tcpServerClientState[index] = TCP_SERVER_CLIENT_WAIT_REQUEST;
493495
else
496+
{
494497
// Make client online after any NTRIP injections so ring buffer can start outputting data to it
498+
tcpServerClientSendingData = tcpServerClientSendingData | (1 << index);
495499
tcpServerClientState[index] = TCP_SERVER_CLIENT_SENDING_DATA;
500+
}
496501
break;
497502
}
498503
}
@@ -607,6 +612,9 @@ void tcpServerStopClient(int index)
607612
bool connected;
608613
bool dataSent;
609614

615+
// Stop sending data
616+
tcpServerClientSendingData = tcpServerClientSendingData & ~(1 << index);
617+
610618
// Determine if a client was allocated
611619
if (tcpServerClient[index])
612620
{

0 commit comments

Comments
 (0)