@@ -250,7 +250,6 @@ bool ntripServerConnectLimitReached(int serverIndex)
250
250
if (settings.enableNtripServer && (!limitReached))
251
251
networkRestart (NETWORK_USER_NTRIP_SERVER + serverIndex);
252
252
253
- // Shutdown the NTRIP server
254
253
ntripServerStop (serverIndex, limitReached || (!settings.enableNtripServer ));
255
254
256
255
ntripServer->connectionAttempts ++;
@@ -452,22 +451,30 @@ void ntripServerRestart(int serverIndex)
452
451
// Update the state of the NTRIP server state machine
453
452
void ntripServerSetState (NTRIP_SERVER_DATA * ntripServer, uint8_t newState)
454
453
{
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
+ }
456
463
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 )
458
466
{
459
467
if (ntripServer->state == newState)
460
- systemPrintf (" %d: *" , serverIndex);
468
+ systemPrintf (" NTRIP server %d: *" , serverIndex); // If the state is not changing - print *
461
469
else
462
- systemPrintf (" %d: %s --> " , serverIndex, ntripServerStateName[ntripServer->state ]);
470
+ systemPrintf (" NTRIP server %d: %s --> " , serverIndex, ntripServerStateName[ntripServer->state ]);
463
471
}
464
472
ntripServer->state = newState;
465
- if (settings.debugNtripServerState || PERIODIC_DISPLAY (PD_NTRIP_SERVER_STATE) )
473
+ if (settings.debugNtripServerState )
466
474
{
467
- PERIODIC_CLEAR (PD_NTRIP_SERVER_STATE);
468
- if (newState >= NTRIP_SERVER_STATE_MAX)
475
+ if (ntripServer->state >= NTRIP_SERVER_STATE_MAX)
469
476
{
470
- systemPrintf (" Unknown NTRIP Server %d state: %d\r\n " , serverIndex, newState );
477
+ systemPrintf (" Unknown server state %d\r\n " , ntripServer-> state );
471
478
reportFatalError (" Unknown NTRIP Server state" );
472
479
}
473
480
else
@@ -478,7 +485,7 @@ void ntripServerSetState(NTRIP_SERVER_DATA * ntripServer, uint8_t newState)
478
485
// Shutdown the NTRIP server
479
486
void ntripServerShutdown (int serverIndex)
480
487
{
481
- ntripServerStop (serverIndex, true );
488
+ ntripServerStop (serverIndex, true , " ntripServerShutdown " );
482
489
}
483
490
484
491
// Start the NTRIP server
@@ -489,14 +496,13 @@ void ntripServerStart(int serverIndex)
489
496
490
497
// Start the NTRIP server
491
498
systemPrintf (" NTRIP Server %d start\r\n " , serverIndex);
492
- ntripServerStop (serverIndex, false );
499
+ ntripServerStop (serverIndex, false , " ntripServerStart " );
493
500
}
494
501
495
502
// Shutdown or restart the NTRIP server
496
503
void ntripServerStop (int serverIndex, bool shutdown)
497
504
{
498
505
bool enabled;
499
- int index;
500
506
NTRIP_SERVER_DATA * ntripServer = &ntripServerArray[serverIndex];
501
507
502
508
if (ntripServer->networkClient )
@@ -532,24 +538,24 @@ void ntripServerStop(int serverIndex, bool shutdown)
532
538
if (shutdown)
533
539
{
534
540
if (settings.debugNtripServerState )
535
- systemPrintf (" NTRIP Server %d shutdown requested! \r\n " , serverIndex);
541
+ systemPrintf (" ntripServerStop server %d shutdown requested\r\n " , serverIndex);
536
542
}
537
543
else
538
544
{
539
545
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);
541
547
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);
543
549
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);
545
551
}
546
552
ntripServerSetState (ntripServer, NTRIP_SERVER_OFF);
547
553
ntripServer->connectionAttempts = 0 ;
548
554
ntripServer->connectionAttemptTimeout = 0 ;
549
555
550
556
// Determine if any of the NTRIP servers are enabled
551
557
enabled = false ;
552
- for (index = 0 ; index < NTRIP_SERVER_MAX; index++)
558
+ for (int index = 0 ; index < NTRIP_SERVER_MAX; index++)
553
559
if (online.ntripServer [index])
554
560
{
555
561
enabled = true ;
@@ -558,7 +564,10 @@ void ntripServerStop(int serverIndex, bool shutdown)
558
564
settings.enableNtripServer = enabled;
559
565
}
560
566
else
567
+ {
568
+ systemPrintf (" ntripServerStop server %d start requested\r\n " , serverIndex);
561
569
ntripServerSetState (ntripServer, NTRIP_SERVER_ON);
570
+ }
562
571
}
563
572
564
573
// Update the NTRIP server state machine
@@ -572,15 +581,15 @@ void ntripServerUpdate(int serverIndex)
572
581
processRTCMBuffer ();
573
582
574
583
// 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
576
585
if (NEQ_RTK_MODE (ntripServerMode) || (!settings.enableNtripServer ))
577
586
{
578
587
if (ntripServer->state > NTRIP_SERVER_OFF)
579
588
{
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
584
593
}
585
594
}
586
595
@@ -608,7 +617,7 @@ void ntripServerUpdate(int serverIndex)
608
617
// Determine if the network has failed
609
618
if (networkIsShuttingDown (NETWORK_USER_NTRIP_SERVER + serverIndex))
610
619
// Failed to connect to to the network, attempt to restart the network
611
- ntripServerRestart (serverIndex);
620
+ ntripServerRestart (serverIndex); // Should this be ntripServerStop? TODO
612
621
613
622
// Determine if the network is connected to the media
614
623
else if (networkUserConnected (NETWORK_USER_NTRIP_SERVER + serverIndex))
@@ -636,7 +645,7 @@ void ntripServerUpdate(int serverIndex)
636
645
// Determine if the network has failed
637
646
if (networkIsShuttingDown (NETWORK_USER_NTRIP_SERVER + serverIndex))
638
647
// Failed to connect to to the network, attempt to restart the network
639
- ntripServerRestart (serverIndex);
648
+ ntripServerRestart (serverIndex); // Should this be ntripServerStop? TODO
640
649
641
650
else if (settings.enableNtripServer
642
651
&& (millis () - ntripServer->lastConnectionAttempt > ntripServer->connectionAttemptTimeout ))
@@ -654,7 +663,7 @@ void ntripServerUpdate(int serverIndex)
654
663
// Determine if the network has failed
655
664
if (networkIsShuttingDown (NETWORK_USER_NTRIP_SERVER + serverIndex))
656
665
// Failed to connect to to the network, attempt to restart the network
657
- ntripServerRestart (serverIndex);
666
+ ntripServerRestart (serverIndex); // Should this be ntripServerStop? TODO
658
667
659
668
// State change handled in ntripServerProcessRTCM
660
669
break ;
@@ -664,7 +673,7 @@ void ntripServerUpdate(int serverIndex)
664
673
// Determine if the network has failed
665
674
if (networkIsShuttingDown (NETWORK_USER_NTRIP_SERVER + serverIndex))
666
675
// Failed to connect to to the network, attempt to restart the network
667
- ntripServerRestart (serverIndex);
676
+ ntripServerRestart (serverIndex); // Should this be ntripServerStop? TODO
668
677
669
678
// Delay before opening the NTRIP server connection
670
679
else if ((millis () - ntripServer->timer ) >= ntripServer->connectionAttemptTimeout )
@@ -690,7 +699,7 @@ void ntripServerUpdate(int serverIndex)
690
699
// Determine if the network has failed
691
700
if (networkIsShuttingDown (NETWORK_USER_NTRIP_SERVER + serverIndex))
692
701
// Failed to connect to to the network, attempt to restart the network
693
- ntripServerRestart (serverIndex);
702
+ ntripServerRestart (serverIndex); // Should this be ntripServerStop? TODO
694
703
695
704
// Check if caster service responded
696
705
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)
776
785
// Determine if the network has failed
777
786
if (networkIsShuttingDown (NETWORK_USER_NTRIP_SERVER + serverIndex))
778
787
// Failed to connect to to the network, attempt to restart the network
779
- ntripServerRestart (serverIndex);
788
+ ntripServerRestart (serverIndex); // Should this be ntripServerStop? TODO
780
789
781
790
// Check for a broken connection
782
791
else if (!ntripServer->networkClient ->connected ())
@@ -817,7 +826,11 @@ void ntripServerUpdate(int serverIndex)
817
826
818
827
// Periodically display the state
819
828
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
+ }
821
834
}
822
835
823
836
// Update the NTRIP server state machine
0 commit comments