Skip to content

Commit e763587

Browse files
committed
Better NTRIP debugging
1 parent e742118 commit e763587

File tree

2 files changed

+54
-38
lines changed

2 files changed

+54
-38
lines changed

Firmware/RTK_Surveyor/NtripClient.ino

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -457,22 +457,22 @@ void ntripClientRestart()
457457
}
458458

459459
// Update the state of the NTRIP client state machine
460+
// PERIODIC_DISPLAY(PD_NTRIP_CLIENT_STATE) is handled by ntripClientUpdate
460461
void ntripClientSetState(uint8_t newState)
461462
{
462-
if (settings.debugNtripClientState || PERIODIC_DISPLAY(PD_NTRIP_CLIENT_STATE))
463+
if (settings.debugNtripClientState)
463464
{
464465
if (ntripClientState == newState)
465-
systemPrint("*");
466+
systemPrint("NTRIP client: *");
466467
else
467-
systemPrintf("%s --> ", ntripClientStateName[ntripClientState]);
468+
systemPrintf("NTRIP client: %s --> ", ntripClientStateName[ntripClientState]);
468469
}
469470
ntripClientState = newState;
470-
if (settings.debugNtripClientState || PERIODIC_DISPLAY(PD_NTRIP_CLIENT_STATE))
471+
if (settings.debugNtripClientState)
471472
{
472-
PERIODIC_CLEAR(PD_NTRIP_CLIENT_STATE);
473-
if (newState >= NTRIP_CLIENT_STATE_MAX)
473+
if (ntripClientState >= NTRIP_CLIENT_STATE_MAX)
474474
{
475-
systemPrintf("Unknown NTRIP Client state: %d\r\n", newState);
475+
systemPrintf("Unknown client state %d\r\n", ntripClientState);
476476
reportFatalError("Unknown NTRIP Client state");
477477
}
478478
else
@@ -554,7 +554,7 @@ void ntripClientUpdate()
554554
{
555555
if (ntripClientState > NTRIP_CLIENT_OFF)
556556
{
557-
ntripClientStop(false);
557+
ntripClientStop(true);
558558
ntripClientConnectionAttempts = 0;
559559
ntripClientConnectionAttemptTimeout = 0;
560560
ntripClientSetState(NTRIP_CLIENT_OFF);
@@ -856,7 +856,10 @@ void ntripClientUpdate()
856856

857857
// Periodically display the NTRIP client state
858858
if (PERIODIC_DISPLAY(PD_NTRIP_CLIENT_STATE))
859-
ntripClientSetState(ntripClientState);
859+
{
860+
systemPrintf("NTRIP client state: %s\r\n", ntripClientStateName[ntripClientState]);
861+
PERIODIC_CLEAR(PD_NTRIP_CLIENT_STATE);
862+
}
860863
}
861864

862865
// Verify the NTRIP client tables

Firmware/RTK_Surveyor/NtripServer.ino

Lines changed: 42 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,6 @@ bool ntripServerConnectLimitReached(int serverIndex)
250250
if (settings.enableNtripServer && (!limitReached))
251251
networkRestart(NETWORK_USER_NTRIP_SERVER + serverIndex);
252252

253-
// Shutdown the NTRIP server
254253
ntripServerStop(serverIndex, limitReached || (!settings.enableNtripServer));
255254

256255
ntripServer->connectionAttempts++;
@@ -452,22 +451,30 @@ void ntripServerRestart(int serverIndex)
452451
// Update the state of the NTRIP server state machine
453452
void ntripServerSetState(NTRIP_SERVER_DATA * ntripServer, uint8_t newState)
454453
{
455-
int serverIndex = ntripServer - &ntripServerArray[0];
454+
int serverIndex = -999;
455+
for (int index = 0; index < NTRIP_SERVER_MAX; index++)
456+
{
457+
if (ntripServer == &ntripServerArray[index])
458+
{
459+
serverIndex = index;
460+
break;
461+
}
462+
}
456463

457-
if (settings.debugNtripServerState || PERIODIC_DISPLAY(PD_NTRIP_SERVER_STATE))
464+
// PERIODIC_DISPLAY(PD_NTRIP_SERVER_STATE) is handled by ntripServerUpdate
465+
if (settings.debugNtripServerState)
458466
{
459467
if (ntripServer->state == newState)
460-
systemPrintf("%d: *", serverIndex);
468+
systemPrintf("NTRIP server %d: *", serverIndex); // If the state is not changing - print *
461469
else
462-
systemPrintf("%d: %s --> ", serverIndex, ntripServerStateName[ntripServer->state]);
470+
systemPrintf("NTRIP server %d: %s --> ", serverIndex, ntripServerStateName[ntripServer->state]);
463471
}
464472
ntripServer->state = newState;
465-
if (settings.debugNtripServerState || PERIODIC_DISPLAY(PD_NTRIP_SERVER_STATE))
473+
if (settings.debugNtripServerState)
466474
{
467-
PERIODIC_CLEAR(PD_NTRIP_SERVER_STATE);
468-
if (newState >= NTRIP_SERVER_STATE_MAX)
475+
if (ntripServer->state >= NTRIP_SERVER_STATE_MAX)
469476
{
470-
systemPrintf("Unknown NTRIP Server %d state: %d\r\n", serverIndex, newState);
477+
systemPrintf("Unknown server state %d\r\n", ntripServer->state);
471478
reportFatalError("Unknown NTRIP Server state");
472479
}
473480
else
@@ -478,7 +485,7 @@ void ntripServerSetState(NTRIP_SERVER_DATA * ntripServer, uint8_t newState)
478485
// Shutdown the NTRIP server
479486
void ntripServerShutdown(int serverIndex)
480487
{
481-
ntripServerStop(serverIndex, true);
488+
ntripServerStop(serverIndex, true, "ntripServerShutdown");
482489
}
483490

484491
// Start the NTRIP server
@@ -489,14 +496,13 @@ void ntripServerStart(int serverIndex)
489496

490497
// Start the NTRIP server
491498
systemPrintf("NTRIP Server %d start\r\n", serverIndex);
492-
ntripServerStop(serverIndex, false);
499+
ntripServerStop(serverIndex, false, "ntripServerStart");
493500
}
494501

495502
// Shutdown or restart the NTRIP server
496503
void ntripServerStop(int serverIndex, bool shutdown)
497504
{
498505
bool enabled;
499-
int index;
500506
NTRIP_SERVER_DATA * ntripServer = &ntripServerArray[serverIndex];
501507

502508
if (ntripServer->networkClient)
@@ -532,24 +538,24 @@ void ntripServerStop(int serverIndex, bool shutdown)
532538
if (shutdown)
533539
{
534540
if (settings.debugNtripServerState)
535-
systemPrintf("NTRIP Server %d shutdown requested!\r\n", serverIndex);
541+
systemPrintf("ntripServerStop server %d shutdown requested\r\n", serverIndex);
536542
}
537543
else
538544
{
539545
if (settings.debugNtripServerState && (!settings.ntripServer_CasterHost[serverIndex][0]))
540-
systemPrintf("NTRIP Server %d caster host not configured!\r\n", serverIndex);
546+
systemPrintf("ntripServerStop server %d caster host not configured!\r\n", serverIndex);
541547
if (settings.debugNtripServerState && (!settings.ntripServer_CasterPort[serverIndex]))
542-
systemPrintf("NTRIP Server %d caster port not configured!\r\n", serverIndex);
548+
systemPrintf("ntripServerStop server %d caster port not configured!\r\n", serverIndex);
543549
if (settings.debugNtripServerState && (!settings.ntripServer_MountPoint[serverIndex][0]))
544-
systemPrintf("NTRIP Server %d mount point not configured!\r\n", serverIndex);
550+
systemPrintf("ntripServerStop server %d mount point not configured!\r\n", serverIndex);
545551
}
546552
ntripServerSetState(ntripServer, NTRIP_SERVER_OFF);
547553
ntripServer->connectionAttempts = 0;
548554
ntripServer->connectionAttemptTimeout = 0;
549555

550556
// Determine if any of the NTRIP servers are enabled
551557
enabled = false;
552-
for (index = 0; index < NTRIP_SERVER_MAX; index++)
558+
for (int index = 0; index < NTRIP_SERVER_MAX; index++)
553559
if (online.ntripServer[index])
554560
{
555561
enabled = true;
@@ -558,7 +564,10 @@ void ntripServerStop(int serverIndex, bool shutdown)
558564
settings.enableNtripServer = enabled;
559565
}
560566
else
567+
{
568+
systemPrintf("ntripServerStop server %d start requested\r\n", serverIndex);
561569
ntripServerSetState(ntripServer, NTRIP_SERVER_ON);
570+
}
562571
}
563572

564573
// Update the NTRIP server state machine
@@ -572,15 +581,15 @@ void ntripServerUpdate(int serverIndex)
572581
processRTCMBuffer();
573582

574583
// Shutdown the NTRIP server when the mode or setting changes
575-
DMW_ds(ntripServerSetState, ntripServer);
584+
DMW_ds(ntripServerSetState, ntripServer); // DMW: set the server state to the same state - causes a print
576585
if (NEQ_RTK_MODE(ntripServerMode) || (!settings.enableNtripServer))
577586
{
578587
if (ntripServer->state > NTRIP_SERVER_OFF)
579588
{
580-
ntripServerStop(serverIndex, false);
581-
ntripServer->connectionAttempts = 0;
582-
ntripServer->connectionAttemptTimeout = 0;
583-
ntripServerSetState(ntripServer, NTRIP_SERVER_OFF);
589+
ntripServerStop(serverIndex, true); // This was false. Needs checking. TODO
590+
ntripServer->connectionAttempts = 0; // Duplicate? ntripServerStop does this... TODO
591+
ntripServer->connectionAttemptTimeout = 0; // Duplicate? ntripServerStop does this... TODO
592+
ntripServerSetState(ntripServer, NTRIP_SERVER_OFF); // Duplicate? ntripServerStop does this... TODO
584593
}
585594
}
586595

@@ -608,7 +617,7 @@ void ntripServerUpdate(int serverIndex)
608617
// Determine if the network has failed
609618
if (networkIsShuttingDown(NETWORK_USER_NTRIP_SERVER + serverIndex))
610619
// Failed to connect to to the network, attempt to restart the network
611-
ntripServerRestart(serverIndex);
620+
ntripServerRestart(serverIndex); // Should this be ntripServerStop? TODO
612621

613622
// Determine if the network is connected to the media
614623
else if (networkUserConnected(NETWORK_USER_NTRIP_SERVER + serverIndex))
@@ -636,7 +645,7 @@ void ntripServerUpdate(int serverIndex)
636645
// Determine if the network has failed
637646
if (networkIsShuttingDown(NETWORK_USER_NTRIP_SERVER + serverIndex))
638647
// Failed to connect to to the network, attempt to restart the network
639-
ntripServerRestart(serverIndex);
648+
ntripServerRestart(serverIndex); // Should this be ntripServerStop? TODO
640649

641650
else if (settings.enableNtripServer
642651
&& (millis() - ntripServer->lastConnectionAttempt > ntripServer->connectionAttemptTimeout))
@@ -654,7 +663,7 @@ void ntripServerUpdate(int serverIndex)
654663
// Determine if the network has failed
655664
if (networkIsShuttingDown(NETWORK_USER_NTRIP_SERVER + serverIndex))
656665
// Failed to connect to to the network, attempt to restart the network
657-
ntripServerRestart(serverIndex);
666+
ntripServerRestart(serverIndex); // Should this be ntripServerStop? TODO
658667

659668
// State change handled in ntripServerProcessRTCM
660669
break;
@@ -664,7 +673,7 @@ void ntripServerUpdate(int serverIndex)
664673
// Determine if the network has failed
665674
if (networkIsShuttingDown(NETWORK_USER_NTRIP_SERVER + serverIndex))
666675
// Failed to connect to to the network, attempt to restart the network
667-
ntripServerRestart(serverIndex);
676+
ntripServerRestart(serverIndex); // Should this be ntripServerStop? TODO
668677

669678
// Delay before opening the NTRIP server connection
670679
else if ((millis() - ntripServer->timer) >= ntripServer->connectionAttemptTimeout)
@@ -690,7 +699,7 @@ void ntripServerUpdate(int serverIndex)
690699
// Determine if the network has failed
691700
if (networkIsShuttingDown(NETWORK_USER_NTRIP_SERVER + serverIndex))
692701
// Failed to connect to to the network, attempt to restart the network
693-
ntripServerRestart(serverIndex);
702+
ntripServerRestart(serverIndex); // Should this be ntripServerStop? TODO
694703

695704
// Check if caster service responded
696705
else if (ntripServer->networkClient->available() < strlen("ICY 200 OK")) // Wait until at least a few bytes have arrived
@@ -776,7 +785,7 @@ void ntripServerUpdate(int serverIndex)
776785
// Determine if the network has failed
777786
if (networkIsShuttingDown(NETWORK_USER_NTRIP_SERVER + serverIndex))
778787
// Failed to connect to to the network, attempt to restart the network
779-
ntripServerRestart(serverIndex);
788+
ntripServerRestart(serverIndex); // Should this be ntripServerStop? TODO
780789

781790
// Check for a broken connection
782791
else if (!ntripServer->networkClient->connected())
@@ -817,7 +826,11 @@ void ntripServerUpdate(int serverIndex)
817826

818827
// Periodically display the state
819828
if (PERIODIC_DISPLAY(PD_NTRIP_SERVER_STATE))
820-
ntripServerSetState(ntripServer, ntripServer->state);
829+
{
830+
systemPrintf("NTRIP Server %d state: %s\r\n", serverIndex, ntripServerStateName[ntripServer->state]);
831+
if (serverIndex == (NTRIP_SERVER_MAX - 1))
832+
PERIODIC_CLEAR(PD_NTRIP_SERVER_STATE); // Clear the periodic display only on the last server
833+
}
821834
}
822835

823836
// Update the NTRIP server state machine

0 commit comments

Comments
 (0)