Skip to content

Commit d685ba7

Browse files
committed
Make NTRIP_SERVER_DATA ntripServerArray[] volatile - prevents unneeded disconnects "due to lack of RTCM data"
1 parent c7c6377 commit d685ba7

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

Firmware/RTK_Everywhere/NtripServer.ino

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ const RtkMode_t ntripServerMode = RTK_MODE_BASE_FIXED;
173173
//----------------------------------------
174174

175175
// NTRIP Servers
176-
static NTRIP_SERVER_DATA ntripServerArray[NTRIP_SERVER_MAX];
176+
volatile static NTRIP_SERVER_DATA ntripServerArray[NTRIP_SERVER_MAX];
177177

178178
//----------------------------------------
179179
// NTRIP Server Routines
@@ -184,7 +184,7 @@ static NTRIP_SERVER_DATA ntripServerArray[NTRIP_SERVER_MAX];
184184
//----------------------------------------
185185
bool ntripServerConnectCaster(int serverIndex)
186186
{
187-
NTRIP_SERVER_DATA *ntripServer = &ntripServerArray[serverIndex];
187+
volatile NTRIP_SERVER_DATA *ntripServer = &ntripServerArray[serverIndex];
188188
const int SERVER_BUFFER_SIZE = 512;
189189
char serverBuffer[SERVER_BUFFER_SIZE];
190190

@@ -239,7 +239,7 @@ bool ntripServerConnectLimitReached(int serverIndex)
239239
{
240240
bool limitReached;
241241
int minutes;
242-
NTRIP_SERVER_DATA *ntripServer = &ntripServerArray[serverIndex];
242+
volatile NTRIP_SERVER_DATA *ntripServer = &ntripServerArray[serverIndex];
243243
int seconds;
244244

245245
// Retry the connection a few times
@@ -249,8 +249,8 @@ bool ntripServerConnectLimitReached(int serverIndex)
249249
// Shutdown the NTRIP server
250250
ntripServerStop(serverIndex, limitReached || (!ntripServerEnabled(serverIndex, nullptr)));
251251

252-
ntripServer->connectionAttempts++;
253-
ntripServer->connectionAttemptsTotal++;
252+
ntripServer->connectionAttempts = ntripServer->connectionAttempts + 1;
253+
ntripServer->connectionAttemptsTotal = ntripServer->connectionAttemptsTotal + 1;
254254
if (settings.debugNtripServerState)
255255
ntripServerPrintStatus(serverIndex);
256256

@@ -334,7 +334,7 @@ bool ntripServerEnabled(int serverIndex, const char ** line)
334334
//----------------------------------------
335335
void ntripServerPrintStateSummary(int serverIndex)
336336
{
337-
NTRIP_SERVER_DATA *ntripServer = &ntripServerArray[serverIndex];
337+
volatile NTRIP_SERVER_DATA *ntripServer = &ntripServerArray[serverIndex];
338338

339339
switch (ntripServer->state)
340340
{
@@ -362,7 +362,7 @@ void ntripServerPrintStateSummary(int serverIndex)
362362
//----------------------------------------
363363
void ntripServerPrintStatus(int serverIndex)
364364
{
365-
NTRIP_SERVER_DATA *ntripServer = &ntripServerArray[serverIndex];
365+
volatile NTRIP_SERVER_DATA *ntripServer = &ntripServerArray[serverIndex];
366366
uint64_t milliseconds;
367367
uint32_t days;
368368
byte hours;
@@ -410,7 +410,7 @@ void ntripServerPrintStatus(int serverIndex)
410410
//----------------------------------------
411411
void ntripServerProcessRTCM(int serverIndex, uint8_t incoming)
412412
{
413-
NTRIP_SERVER_DATA *ntripServer = &ntripServerArray[serverIndex];
413+
volatile NTRIP_SERVER_DATA *ntripServer = &ntripServerArray[serverIndex];
414414

415415
if (ntripServer->state == NTRIP_SERVER_CASTING)
416416
{
@@ -445,8 +445,8 @@ void ntripServerProcessRTCM(int serverIndex, uint8_t incoming)
445445
if (ntripServer->networkClient && ntripServer->networkClient->connected())
446446
{
447447
ntripServer->networkClient->write(incoming); // Send this byte to socket
448-
ntripServer->bytesSent++;
449-
ntripServer->rtcmBytesSent++;
448+
ntripServer->bytesSent = ntripServer->bytesSent + 1;
449+
ntripServer->rtcmBytesSent = ntripServer->rtcmBytesSent + 1;
450450
ntripServer->timer = millis();
451451
netOutgoingRTCM = true;
452452
}
@@ -464,7 +464,7 @@ void ntripServerProcessRTCM(int serverIndex, uint8_t incoming)
464464
//----------------------------------------
465465
void ntripServerResponse(int serverIndex, char *response, size_t maxLength)
466466
{
467-
NTRIP_SERVER_DATA *ntripServer = &ntripServerArray[serverIndex];
467+
volatile NTRIP_SERVER_DATA *ntripServer = &ntripServerArray[serverIndex];
468468
char *responseEnd;
469469

470470
// Make sure that we can zero terminate the response
@@ -483,7 +483,7 @@ void ntripServerResponse(int serverIndex, char *response, size_t maxLength)
483483
//----------------------------------------
484484
void ntripServerRestart(int serverIndex)
485485
{
486-
NTRIP_SERVER_DATA *ntripServer = &ntripServerArray[serverIndex];
486+
volatile NTRIP_SERVER_DATA *ntripServer = &ntripServerArray[serverIndex];
487487

488488
// Save the previous uptime value
489489
if (ntripServer->state == NTRIP_SERVER_CASTING)
@@ -496,7 +496,7 @@ void ntripServerRestart(int serverIndex)
496496
//----------------------------------------
497497
void ntripServerSetState(int serverIndex, uint8_t newState)
498498
{
499-
NTRIP_SERVER_DATA * ntripServer;
499+
volatile NTRIP_SERVER_DATA * ntripServer;
500500

501501
ntripServer = &ntripServerArray[serverIndex];
502502
if (settings.debugNtripServerState)
@@ -548,7 +548,7 @@ void ntripServerStop(int serverIndex, bool shutdown)
548548
{
549549
bool enabled;
550550
int index;
551-
NTRIP_SERVER_DATA *ntripServer = &ntripServerArray[serverIndex];
551+
volatile NTRIP_SERVER_DATA *ntripServer = &ntripServerArray[serverIndex];
552552

553553
if (ntripServer->networkClient)
554554
{
@@ -612,7 +612,7 @@ void ntripServerUpdate(int serverIndex)
612612
const char * line = "";
613613

614614
// Get the NTRIP data structure
615-
NTRIP_SERVER_DATA *ntripServer = &ntripServerArray[serverIndex];
615+
volatile NTRIP_SERVER_DATA *ntripServer = &ntripServerArray[serverIndex];
616616

617617
// Shutdown the NTRIP server when the mode or setting changes
618618
DMW_if

Firmware/RTK_Everywhere/settings.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -358,12 +358,12 @@ enum PeriodDisplayValues
358358

359359
#ifdef COMPILE_NETWORK
360360

361-
// NTRIP Server data
362-
typedef struct _NTRIP_SERVER_DATA
361+
// NTRIP Server data - the array is declared volatile in NtripServer.ino
362+
typedef struct
363363
{
364364
// Network connection used to push RTCM to NTRIP caster
365365
NetworkClient *networkClient;
366-
volatile uint8_t state;
366+
uint8_t state;
367367

368368
// Count of bytes sent by the NTRIP server to the NTRIP caster
369369
uint32_t bytesSent;

0 commit comments

Comments
 (0)