Skip to content

Commit 71242a8

Browse files
committed
Network clients start and stop depending upon operating modes
Define the RTK operating modes and set these modes in States.ino. For each network user: * Add a bit mask specifying which modes the network user is active * Stop the network user when the enable or mode changes * Start the network user when the mode and enable are set
1 parent 3994e44 commit 71242a8

12 files changed

+135
-90
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 = BIT_RTK_MODE(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: 12 additions & 25 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 = BIT_RTK_MODE(RTK_MODE_ROVER)
179+
| BIT_RTK_MODE(RTK_MODE_BASE_SURVEY_IN);
180+
178181
//----------------------------------------
179182
// Locals
180183
//----------------------------------------
@@ -345,28 +348,6 @@ bool ntripClientConnectLimitReached()
345348
return limitReached;
346349
}
347350

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-
370351
// Print the NTRIP client state summary
371352
void ntripClientPrintStateSummary()
372353
{
@@ -565,14 +546,20 @@ void ntripClientStop(bool shutdown)
565546
// Stop task if the connection has dropped or if we receive no data for maxTimeBeforeHangup_ms
566547
void ntripClientUpdate()
567548
{
568-
if (ntripClientIsNeeded() == false)
569-
return;
549+
// Shutdown the NTRIP client when the mode or setting changes
550+
DMW_st(ntripClientSetState, ntripClientState);
551+
if (NEQ_RTK_MODE(ntripClientMode) || (!settings.enableNtripClient))
552+
{
553+
if (ntripClientState > NTRIP_CLIENT_OFF)
554+
ntripClientStop(true);
555+
}
570556

571557
// Enable the network and the NTRIP client if requested
572-
DMW_st(ntripClientSetState, ntripClientState);
573558
switch (ntripClientState)
574559
{
575560
case NTRIP_CLIENT_OFF:
561+
if (EQ_RTK_MODE(ntripClientMode) && settings.enableNtripClient)
562+
ntripClientStart();
576563
break;
577564

578565
// Start the network

Firmware/RTK_Surveyor/NtripServer.ino

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@ const char * const ntripServerStateName[] =
170170

171171
const int ntripServerStateNameEntries = sizeof(ntripServerStateName) / sizeof(ntripServerStateName[0]);
172172

173+
const RtkMode_t ntripServerMode = BIT_RTK_MODE(RTK_MODE_BASE_FIXED);
174+
173175
//----------------------------------------
174176
// Locals
175177
//----------------------------------------
@@ -187,9 +189,6 @@ static uint32_t ntripServerConnectionAttemptTimeout;
187189
static uint32_t ntripServerLastConnectionAttempt;
188190
static int ntripServerConnectionAttempts; // Count the number of connection attempts between restarts
189191

190-
// Last time the NTRIP server state was displayed
191-
static uint32_t ntripServerStateLastDisplayed;
192-
193192
// NTRIP server timer usage:
194193
// * Reconnection delay
195194
// * Measure the connection response time
@@ -549,29 +548,20 @@ void ntripServerUpdate()
549548
// This causes the state change from NTRIP_SERVER_WAIT_GNSS_DATA to NTRIP_SERVER_CONNECTING
550549
processRTCMBuffer();
551550

552-
if (settings.enableNtripServer == false)
551+
// Shutdown the NTRIP server when the mode or setting changes
552+
DMW_st(ntripServerSetState, ntripServerState);
553+
if (NEQ_RTK_MODE(ntripServerMode) || (!settings.enableNtripServer))
553554
{
554-
// If user turns off NTRIP Server via settings, stop server
555555
if (ntripServerState > NTRIP_SERVER_OFF)
556556
ntripServerShutdown();
557-
return;
558-
}
559-
560-
if (wifiInConfigMode())
561-
return; // Do not service NTRIP during WiFi config
562-
563-
// Periodically display the NTRIP server state
564-
if (settings.debugNtripServerState && ((millis() - ntripServerStateLastDisplayed) > 15000))
565-
{
566-
ntripServerSetState(ntripServerState);
567-
ntripServerStateLastDisplayed = millis();
568557
}
569558

570559
// Enable the network and the NTRIP server if requested
571-
DMW_st(ntripServerSetState, ntripServerState);
572560
switch (ntripServerState)
573561
{
574562
case NTRIP_SERVER_OFF:
563+
if (EQ_RTK_MODE(ntripServerMode) && settings.enableNtripServer)
564+
ntripServerStart();
575565
break;
576566

577567
// Start the network

Firmware/RTK_Surveyor/OtaClient.ino

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ const char * const otaStateNames[] =
6969
};
7070
const int otaStateEntries = sizeof(otaStateNames) / sizeof(otaStateNames[0]);
7171

72+
const RtkMode_t otaClientMode = BIT_RTK_MODE(RTK_MODE_BASE_FIXED)
73+
| BIT_RTK_MODE(RTK_MODE_BASE_SURVEY_IN)
74+
| BIT_RTK_MODE(RTK_MODE_BUBBLE_LEVEL)
75+
| BIT_RTK_MODE(RTK_MODE_NTP)
76+
| BIT_RTK_MODE(RTK_MODE_ROVER);
77+
7278
//----------------------------------------
7379
// Locals
7480
//----------------------------------------
@@ -340,6 +346,19 @@ void otaClientUpdate()
340346
// Perform the firmware update
341347
if (!inMainMenu)
342348
{
349+
// Shutdown the OTA client when the mode or setting changes
350+
DMW_st(otaSetState, otaState);
351+
if (NEQ_RTK_MODE(otaClientMode) || (!settings.enableAutoFirmwareUpdate))
352+
{
353+
if (otaState > OTA_STATE_OFF)
354+
{
355+
otaStop();
356+
357+
// Due to the interruption, enable a fast retry
358+
otaTimer = millis() - checkIntervalMillis + OTA_NO_PROGRESS_TIMEOUT;
359+
}
360+
}
361+
343362
// Walk the state machine to do the firmware update
344363
switch (otaState)
345364
{
@@ -353,7 +372,7 @@ void otaClientUpdate()
353372
// Over-the-air firmware updates are not active
354373
case OTA_STATE_OFF: {
355374
// Determine if the user enabled automatic firmware updates
356-
if (settings.enableAutoFirmwareUpdate)
375+
if (EQ_RTK_MODE(otaClientMode) && settings.enableAutoFirmwareUpdate)
357376
{
358377
// Wait until it is time to check for a firmware update
359378
checkIntervalMillis = settings.autoFirmwareCheckMinutes * 60 * 1000;

Firmware/RTK_Surveyor/PvtClient.ino

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ const char * const pvtClientStateName[] =
146146

147147
const int pvtClientStateNameEntries = sizeof(pvtClientStateName) / sizeof(pvtClientStateName[0]);
148148

149+
const RtkMode_t pvtClientMode = 0;
150+
149151
//----------------------------------------
150152
// Locals
151153
//----------------------------------------
@@ -374,6 +376,14 @@ void pvtClientUpdate()
374376
byte seconds;
375377
static uint32_t timer;
376378

379+
// Shutdown the PVT client when the mode or setting changes
380+
DMW_st(pvtClientSetState, pvtClientState);
381+
if (NEQ_RTK_MODE(pvtClientMode) || (!settings.enablePvtClient))
382+
{
383+
if (pvtClientState > PVT_CLIENT_STATE_OFF)
384+
pvtClientStop();
385+
}
386+
377387
/*
378388
PVT Client state machine
379389
@@ -395,7 +405,6 @@ void pvtClientUpdate()
395405
'--------------PVT_CLIENT_STATE_CONNECTED
396406
*/
397407

398-
DMW_st(pvtClientSetState, pvtClientState);
399408
switch (pvtClientState)
400409
{
401410
default:
@@ -406,7 +415,7 @@ void pvtClientUpdate()
406415
// Wait until the PVT client is enabled
407416
case PVT_CLIENT_STATE_OFF:
408417
// Determine if the PVT client should be running
409-
if (settings.enablePvtClient)
418+
if (EQ_RTK_MODE(pvtClientMode) && settings.enablePvtClient)
410419
{
411420
if (networkUserOpen(NETWORK_USER_PVT_CLIENT, NETWORK_TYPE_ACTIVE))
412421
{

Firmware/RTK_Surveyor/PvtServer.ino

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ const char * const pvtServerStateName[] =
5959

6060
const int pvtServerStateNameEntries = sizeof(pvtServerStateName) / sizeof(pvtServerStateName[0]);
6161

62+
const RtkMode_t pvtServerMode = 0;
63+
6264
//----------------------------------------
6365
// Locals
6466
//----------------------------------------
@@ -339,6 +341,14 @@ void pvtServerUpdate()
339341
int index;
340342
IPAddress ipAddress;
341343

344+
// Shutdown the PVT server when the mode or setting changes
345+
DMW_st(pvtServerSetState, pvtServerState);
346+
if (NEQ_RTK_MODE(pvtServerMode) || (!settings.enablePvtServer))
347+
{
348+
if (pvtServerState > PVT_SERVER_STATE_OFF)
349+
pvtServerStop();
350+
}
351+
342352
/*
343353
PVT Server state machine
344354
@@ -360,7 +370,6 @@ void pvtServerUpdate()
360370
'-----------PVT_SERVER_STATE_WAIT_NO_CLIENTS
361371
*/
362372

363-
DMW_st(pvtServerSetState, pvtServerState);
364373
switch (pvtServerState)
365374
{
366375
default:
@@ -369,7 +378,7 @@ void pvtServerUpdate()
369378
// Wait until the PVT server is enabled
370379
case PVT_SERVER_STATE_OFF:
371380
// Determine if the PVT server should be running
372-
if (settings.enablePvtServer && (!wifiInConfigMode()) && (!wifiIsConnected()))
381+
if (EQ_RTK_MODE(pvtServerMode) && settings.enablePvtServer && (!wifiIsConnected()))
373382
{
374383
if (networkUserOpen(NETWORK_USER_PVT_SERVER, NETWORK_TYPE_ACTIVE))
375384
{

0 commit comments

Comments
 (0)