Skip to content

Commit d2e8715

Browse files
authored
Merge pull request #718 from LeeLeahy2/modes
Network clients start and stop depending upon operating modes
2 parents 6f5c2ad + 599bf4c commit d2e8715

12 files changed

+192
-133
lines changed

Firmware/RTK_Surveyor/Developer.ino

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,6 @@ void networkVerifyTables() {}
5050
//----------------------------------------
5151

5252
void ntripClientPrintStatus() {systemPrint("NTRIP Client not compiled");}
53-
void ntripClientStart()
54-
{
55-
systemPrintln("NTRIP Client not available: Ethernet and WiFi not compiled");
56-
}
5753
void ntripClientStop(bool clientAllocated) {online.ntripClient = false;}
5854
void ntripClientUpdate() {}
5955
void ntripClientValidateTables() {}
@@ -65,10 +61,6 @@ void ntripClientValidateTables() {}
6561
bool ntripServerIsCasting() {return false;}
6662
void ntripServerPrintStatus() {systemPrint("NTRIP Server not compiled");}
6763
void ntripServerProcessRTCM(uint8_t incoming) {}
68-
void ntripServerStart()
69-
{
70-
systemPrintln("NTRIP Server not available: Ethernet and WiFi not compiled");
71-
}
7264
void ntripServerStop(bool clientAllocated) {online.ntripServer = false;}
7365
void ntripServerUpdate() {}
7466
void ntripServerValidateTables() {}

Firmware/RTK_Surveyor/NTP.ino

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ const char * const ntpServerStateName[] =
7575
};
7676
const int ntpServerStateNameEntries = sizeof(ntpServerStateName) / sizeof(ntpServerStateName[0]);
7777

78+
const RtkMode_t ntpServerMode = RTK_MODE_NTP;
79+
7880
//----------------------------------------
7981
// Locals
8082
//----------------------------------------
@@ -762,17 +764,6 @@ bool configureUbloxModuleNTP()
762764
// NTP Server routines
763765
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
764766

765-
// Stop the NTP server
766-
void ntpServerEnd()
767-
{
768-
}
769-
770-
// Determine if the NTP server is enabled
771-
bool ntpServerIsEnabled()
772-
{
773-
return (systemState >= STATE_NTPSERVER_NOT_STARTED) && (systemState <= STATE_NTPSERVER_SYNC);
774-
}
775-
776767
// Update the state of the NTP server state machine
777768
void ntpServerSetState(uint8_t newState)
778769
{
@@ -830,6 +821,14 @@ void ntpServerUpdate()
830821
if (!HAS_ETHERNET)
831822
return;
832823

824+
// Shutdown the NTP server when the mode or setting changes
825+
if (NEQ_RTK_MODE(ntpServerMode))
826+
{
827+
if (ntpServerState > NTP_STATE_OFF)
828+
ntpServerStop();
829+
return;
830+
}
831+
833832
// Process the NTP state
834833
DMW_st(ntpServerSetState, ntpServerState);
835834
switch (ntpServerState)
@@ -839,7 +838,7 @@ void ntpServerUpdate()
839838

840839
case NTP_STATE_OFF:
841840
// Determine if the NTP server is enabled
842-
if (ntpServerIsEnabled())
841+
if (EQ_RTK_MODE(ntpServerMode))
843842
{
844843
// Start the network
845844
if (networkUserOpen(NETWORK_USER_NTP_SERVER, NETWORK_TYPE_ETHERNET))
@@ -850,7 +849,7 @@ void ntpServerUpdate()
850849
// Wait for the network conection
851850
case NTP_STATE_NETWORK_STARTING:
852851
// Determine if the network has failed
853-
if (networkIsShuttingDown(NETWORK_USER_NTP_SERVER) || (!ntpServerIsEnabled()))
852+
if (networkIsShuttingDown(NETWORK_USER_NTP_SERVER))
854853
// Stop the NTP server, restart it if possible
855854
ntpServerStop();
856855

@@ -861,7 +860,7 @@ void ntpServerUpdate()
861860

862861
case NTP_STATE_NETWORK_CONNECTED:
863862
// Determine if the network has failed
864-
if (networkIsShuttingDown(NETWORK_USER_NTP_SERVER) || (!ntpServerIsEnabled()))
863+
if (networkIsShuttingDown(NETWORK_USER_NTP_SERVER))
865864
// Stop the NTP server, restart it if possible
866865
ntpServerStop();
867866

@@ -889,7 +888,7 @@ void ntpServerUpdate()
889888

890889
case NTP_STATE_SERVER_RUNNING:
891890
// Determine if the network has failed
892-
if (networkIsShuttingDown(NETWORK_USER_NTP_SERVER) || (!ntpServerIsEnabled()))
891+
if (networkIsShuttingDown(NETWORK_USER_NTP_SERVER))
893892
// Stop the NTP server, restart it if possible
894893
ntpServerStop();
895894

Firmware/RTK_Surveyor/Network.ino

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,17 +1160,14 @@ void networkUpdate()
11601160
if (PERIODIC_DISPLAY(PD_NETWORK_STATE))
11611161
PERIODIC_CLEAR(PD_NETWORK_STATE);
11621162

1163-
// Skip updates if in configure-via-ethernet mode
1164-
if (!configureViaEthernet)
1165-
{
1166-
ntpServerUpdate(); // Process any received NTP requests
1167-
ntripClientUpdate(); // Check the NTRIP client connection and move data NTRIP --> ZED
1168-
ntripServerUpdate(); // Check the NTRIP server connection and move data ZED --> NTRIP
1169-
otaClientUpdate(); // Perform automatic over-the-air firmware updates
1170-
pvtClientUpdate(); // Turn on the PVT client as needed
1171-
pvtServerUpdate(); // Turn on the PVT server as needed
1172-
pvtUdpServerUpdate(); // Turn on the PVT UDP server as needed
1173-
}
1163+
// Update the network services
1164+
ntpServerUpdate(); // Process any received NTP requests
1165+
ntripClientUpdate(); // Check the NTRIP client connection and move data NTRIP --> ZED
1166+
ntripServerUpdate(); // Check the NTRIP server connection and move data ZED --> NTRIP
1167+
otaClientUpdate(); // Perform automatic over-the-air firmware updates
1168+
pvtClientUpdate(); // Turn on the PVT client as needed
1169+
pvtServerUpdate(); // Turn on the PVT server as needed
1170+
pvtUdpServerUpdate(); // Turn on the PVT UDP server as needed
11741171

11751172
// Display the IP addresses
11761173
networkPeriodicallyDisplayIpAddress();

Firmware/RTK_Surveyor/NtripClient.ino

Lines changed: 39 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,9 @@ const char * const ntripClientStateName[] =
175175

176176
const int ntripClientStateNameEntries = sizeof(ntripClientStateName) / sizeof(ntripClientStateName[0]);
177177

178+
const RtkMode_t ntripClientMode = RTK_MODE_ROVER
179+
| RTK_MODE_BASE_SURVEY_IN;
180+
178181
//----------------------------------------
179182
// Locals
180183
//----------------------------------------
@@ -307,6 +310,10 @@ bool ntripClientConnectLimitReached()
307310
// Retry the connection a few times
308311
bool limitReached = (ntripClientConnectionAttempts >= MAX_NTRIP_CLIENT_CONNECTION_ATTEMPTS);
309312

313+
// Attempt to restart the network if possible
314+
if (settings.enableNtripClient && (!limitReached))
315+
networkRestart(NETWORK_USER_NTRIP_CLIENT);
316+
310317
// Restart the NTRIP client
311318
ntripClientStop(limitReached || (!settings.enableNtripClient));
312319

@@ -345,28 +352,6 @@ bool ntripClientConnectLimitReached()
345352
return limitReached;
346353
}
347354

348-
// Determine if NTRIP Client is needed
349-
bool ntripClientIsNeeded()
350-
{
351-
if (settings.enableNtripClient == false)
352-
{
353-
// If user turns off NTRIP Client via settings, stop server
354-
if (ntripClientState > NTRIP_CLIENT_OFF)
355-
ntripClientShutdown();
356-
return (false);
357-
}
358-
359-
if (wifiInConfigMode())
360-
return (false); // Do not service NTRIP during network config
361-
362-
// Allow NTRIP Client to run during Survey-In,
363-
// but do not allow NTRIP Client to run during Base
364-
if (systemState == STATE_BASE_TEMP_TRANSMITTING)
365-
return (false);
366-
367-
return (true);
368-
}
369-
370355
// Print the NTRIP client state summary
371356
void ntripClientPrintStateSummary()
372357
{
@@ -504,20 +489,12 @@ void ntripClientShutdown()
504489
// Start the NTRIP client
505490
void ntripClientStart()
506491
{
507-
// Stop NTRIP client
508-
ntripClientShutdown();
509-
510492
// Display the heap state
511493
reportHeapNow(settings.debugNtripClientState);
512494

513-
// Start the NTRIP client if enabled
514-
if (settings.enableNtripClient == true)
515-
{
516-
systemPrintln("NTRIP Client start");
517-
ntripClientSetState(NTRIP_CLIENT_ON);
518-
}
519-
520-
ntripClientConnectionAttempts = 0;
495+
// Start the NTRIP client
496+
systemPrintln("NTRIP Client start");
497+
ntripClientStop(false);
521498
}
522499

523500
// Shutdown or restart the NTRIP client
@@ -529,14 +506,6 @@ void ntripClientStop(bool shutdown)
529506
if (ntripClient->connected())
530507
ntripClient->stop();
531508

532-
// Attempt to restart the network if possible
533-
if (!shutdown)
534-
networkRestart(NETWORK_USER_NTRIP_CLIENT);
535-
536-
// Done with the network
537-
if (networkGetUserNetwork(NETWORK_USER_NTRIP_CLIENT))
538-
networkUserClose(NETWORK_USER_NTRIP_CLIENT);
539-
540509
// Free the NTRIP client resources
541510
delete ntripClient;
542511
ntripClient = nullptr;
@@ -545,9 +514,15 @@ void ntripClientStop(bool shutdown)
545514

546515
// Increase timeouts if we started the network
547516
if (ntripClientState > NTRIP_CLIENT_ON)
517+
{
548518
// Mark the Client stop so that we don't immediately attempt re-connect to Caster
549519
ntripClientTimer = millis();
550520

521+
// Done with the network
522+
if (networkGetUserNetwork(NETWORK_USER_NTRIP_CLIENT))
523+
networkUserClose(NETWORK_USER_NTRIP_CLIENT);
524+
}
525+
551526
// Return the Main Talker ID to "GN".
552527
if (online.gnss)
553528
{
@@ -556,23 +531,42 @@ void ntripClientStop(bool shutdown)
556531
}
557532

558533
// Determine the next NTRIP client state
559-
ntripClientSetState(shutdown ? NTRIP_CLIENT_OFF : NTRIP_CLIENT_ON);
560534
online.ntripClient = false;
561535
netIncomingRTCM = false;
536+
if (shutdown)
537+
{
538+
ntripClientSetState(NTRIP_CLIENT_OFF);
539+
settings.enableNtripClient = false;
540+
ntripClientConnectionAttempts = 0;
541+
ntripClientConnectionAttemptTimeout = 0;
542+
}
543+
else
544+
ntripClientSetState(NTRIP_CLIENT_ON);
562545
}
563546

564547
// Check for the arrival of any correction data. Push it to the GNSS.
565548
// Stop task if the connection has dropped or if we receive no data for maxTimeBeforeHangup_ms
566549
void ntripClientUpdate()
567550
{
568-
if (ntripClientIsNeeded() == false)
569-
return;
551+
// Shutdown the NTRIP client when the mode or setting changes
552+
DMW_st(ntripClientSetState, ntripClientState);
553+
if (NEQ_RTK_MODE(ntripClientMode) || (!settings.enableNtripClient))
554+
{
555+
if (ntripClientState > NTRIP_CLIENT_OFF)
556+
{
557+
ntripClientStop(false);
558+
ntripClientConnectionAttempts = 0;
559+
ntripClientConnectionAttemptTimeout = 0;
560+
ntripClientSetState(NTRIP_CLIENT_OFF);
561+
}
562+
}
570563

571564
// Enable the network and the NTRIP client if requested
572-
DMW_st(ntripClientSetState, ntripClientState);
573565
switch (ntripClientState)
574566
{
575567
case NTRIP_CLIENT_OFF:
568+
if (EQ_RTK_MODE(ntripClientMode) && settings.enableNtripClient)
569+
ntripClientStart();
576570
break;
577571

578572
// Start the network

0 commit comments

Comments
 (0)