@@ -175,6 +175,9 @@ const char * const ntripClientStateName[] =
175175
176176const 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
371356void ntripClientPrintStateSummary ()
372357{
@@ -504,20 +489,12 @@ void ntripClientShutdown()
504489// Start the NTRIP client
505490void 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
566549void 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