@@ -82,7 +82,6 @@ NtripServer.ino
82
82
/* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
83
83
NTRIP Server States:
84
84
NTRIP_SERVER_OFF: Network off or using NTRIP Client
85
- NTRIP_SERVER_ON: WIFI_STATE_START state
86
85
NTRIP_SERVER_WAIT_FOR_NETWORK: Connecting to the network
87
86
NTRIP_SERVER_NETWORK_CONNECTED: Connected to the network
88
87
NTRIP_SERVER_WAIT_GNSS_DATA: Waiting for correction data from GNSS
@@ -94,12 +93,8 @@ NtripServer.ino
94
93
| ^
95
94
ntripServerStart | | ntripServerShutdown()
96
95
v |
97
- .---------> NTRIP_SERVER_ON <------- ------------.
96
+ .--> NTRIP_SERVER_WAIT_FOR_NETWORK < ------------.
98
97
| | |
99
- | | | ntripServerRestart()
100
- | v Fail |
101
- | NTRIP_SERVER_WAIT_FOR_NETWORK ------------->+
102
- | | ^
103
98
| | |
104
99
| v Fail |
105
100
| NTRIP_SERVER_NETWORK_CONNECTED ----------->+
@@ -145,7 +140,6 @@ static const int NTRIP_SERVER_CONNECTION_TIME = 5 * 60 * 1000;
145
140
enum NTRIPServerState
146
141
{
147
142
NTRIP_SERVER_OFF = 0 , // Using Bluetooth or NTRIP client
148
- NTRIP_SERVER_ON, // WIFI_STATE_START state
149
143
NTRIP_SERVER_WAIT_FOR_NETWORK, // Connecting to WiFi access point
150
144
NTRIP_SERVER_NETWORK_CONNECTED, // WiFi connected to an access point
151
145
NTRIP_SERVER_WAIT_GNSS_DATA, // Waiting for correction data from GNSS
@@ -157,7 +151,6 @@ enum NTRIPServerState
157
151
};
158
152
159
153
const char *const ntripServerStateName[] = {" NTRIP_SERVER_OFF" ,
160
- " NTRIP_SERVER_ON" ,
161
154
" NTRIP_SERVER_WAIT_FOR_NETWORK" ,
162
155
" NTRIP_SERVER_NETWORK_CONNECTED" ,
163
156
" NTRIP_SERVER_WAIT_GNSS_DATA" ,
@@ -169,6 +162,12 @@ const int ntripServerStateNameEntries = sizeof(ntripServerStateName) / sizeof(nt
169
162
170
163
const RtkMode_t ntripServerMode = RTK_MODE_BASE_FIXED;
171
164
165
+ // ----------------------------------------
166
+ // Macros
167
+ // ----------------------------------------
168
+
169
+ #define NETWORK_CONSUMER (x ) (NETCONSUMER_NTRIP_SERVER + x)
170
+
172
171
// ----------------------------------------
173
172
// Locals
174
173
// ----------------------------------------
@@ -345,7 +344,6 @@ void ntripServerPrintStateSummary(int serverIndex)
345
344
case NTRIP_SERVER_OFF:
346
345
systemPrint (" Disconnected" );
347
346
break ;
348
- case NTRIP_SERVER_ON:
349
347
case NTRIP_SERVER_WAIT_FOR_NETWORK:
350
348
case NTRIP_SERVER_NETWORK_CONNECTED:
351
349
case NTRIP_SERVER_WAIT_GNSS_DATA:
@@ -464,7 +462,7 @@ void ntripServerProcessRTCM(int serverIndex, uint8_t incoming)
464
462
// Indicate that the GNSS is providing correction data
465
463
else if (ntripServer->state == NTRIP_SERVER_WAIT_GNSS_DATA)
466
464
{
467
- ntripServerSetState (ntripServer , NTRIP_SERVER_CONNECTING);
465
+ ntripServerSetState (serverIndex , NTRIP_SERVER_CONNECTING);
468
466
}
469
467
}
470
468
@@ -503,20 +501,11 @@ void ntripServerRestart(int serverIndex)
503
501
// ----------------------------------------
504
502
// Update the state of the NTRIP server state machine
505
503
// ----------------------------------------
506
- void ntripServerSetState (NTRIP_SERVER_DATA *ntripServer , uint8_t newState)
504
+ void ntripServerSetState (int serverIndex , uint8_t newState)
507
505
{
508
- int serverIndex;
509
- for (serverIndex = 0 ; serverIndex < NTRIP_SERVER_MAX; serverIndex++)
510
- {
511
- if (ntripServer == &ntripServerArray[serverIndex])
512
- serverIndex = serverIndex;
513
- }
514
- if (serverIndex >= NTRIP_SERVER_MAX)
515
- {
516
- systemPrintf (" NTRIP Server: %p unknown NTRIP Server structure!\r\n " , (void *)ntripServer);
517
- return ;
518
- }
506
+ NTRIP_SERVER_DATA * ntripServer;
519
507
508
+ ntripServer = &ntripServerArray[serverIndex];
520
509
if (settings.debugNtripServerState )
521
510
{
522
511
if (ntripServer->state == newState)
@@ -556,8 +545,7 @@ void ntripServerStart(int serverIndex)
556
545
// Start the NTRIP server
557
546
systemPrintf (" NTRIP Server %d start\r\n " , serverIndex);
558
547
ntripServerStop (serverIndex, false );
559
- if (ntripServerEnabled (serverIndex, nullptr ))
560
- networkConsumerAdd (NETCONSUMER_NTRIP_SERVER_0 + serverIndex, NETWORK_ANY, __FILE__, __LINE__);
548
+ networkConsumerAdd (NETWORK_CONSUMER (serverIndex), NETWORK_ANY, __FILE__, __LINE__);
561
549
}
562
550
563
551
// ----------------------------------------
@@ -582,13 +570,13 @@ void ntripServerStop(int serverIndex, bool shutdown)
582
570
}
583
571
584
572
// Increase timeouts if we started the network
585
- if (ntripServer->state > NTRIP_SERVER_ON )
573
+ if (ntripServer->state > NTRIP_SERVER_OFF )
586
574
// Mark the Server stop so that we don't immediately attempt re-connect to Caster
587
575
ntripServer->timer = millis ();
588
576
589
577
// Determine the next NTRIP server state
590
578
online.ntripServer [serverIndex] = false ;
591
- networkConsumerOffline (NETCONSUMER_NTRIP_SERVER_0 + serverIndex);
579
+ networkConsumerOffline (NETWORK_CONSUMER ( serverIndex) );
592
580
if (shutdown)
593
581
{
594
582
if (settings.debugNtripServerState )
@@ -599,8 +587,8 @@ void ntripServerStop(int serverIndex, bool shutdown)
599
587
systemPrintf (" NTRIP Server %d caster port not configured!\r\n " , serverIndex);
600
588
if (settings.debugNtripServerState && (!settings.ntripServer_MountPoint [serverIndex][0 ]))
601
589
systemPrintf (" NTRIP Server %d mount point not configured!\r\n " , serverIndex);
602
- networkConsumerRemove (NETCONSUMER_NTRIP_SERVER_0 + serverIndex, NETWORK_ANY, __FILE__, __LINE__);
603
- ntripServerSetState (ntripServer , NTRIP_SERVER_OFF);
590
+ networkConsumerRemove (NETWORK_CONSUMER ( serverIndex) , NETWORK_ANY, __FILE__, __LINE__);
591
+ ntripServerSetState (serverIndex , NTRIP_SERVER_OFF);
604
592
ntripServer->connectionAttempts = 0 ;
605
593
ntripServer->connectionAttemptTimeout = 0 ;
606
594
@@ -617,7 +605,7 @@ void ntripServerStop(int serverIndex, bool shutdown)
617
605
{
618
606
if (settings.debugNtripServerState )
619
607
systemPrintf (" ntripServerStop server %d start requested\r\n " , serverIndex);
620
- ntripServerSetState (ntripServer, NTRIP_SERVER_ON );
608
+ ntripServerSetState (serverIndex, NTRIP_SERVER_WAIT_FOR_NETWORK );
621
609
}
622
610
}
623
611
@@ -634,8 +622,9 @@ void ntripServerUpdate(int serverIndex)
634
622
NTRIP_SERVER_DATA *ntripServer = &ntripServerArray[serverIndex];
635
623
636
624
// Shutdown the NTRIP server when the mode or setting changes
637
- DMW_ds (ntripServerSetState, ntripServer);
638
- connected = networkConsumerIsConnected (NETCONSUMER_NTRIP_SERVER_0 + serverIndex);
625
+ DMW_if
626
+ ntripServerSetState (serverIndex, ntripServer->state );
627
+ connected = networkConsumerIsConnected (NETWORK_CONSUMER (serverIndex));
639
628
enabled = ntripServerEnabled (serverIndex, &line);
640
629
if (!enabled && (ntripServer->state > NTRIP_SERVER_OFF))
641
630
ntripServerShutdown (serverIndex);
@@ -650,12 +639,11 @@ void ntripServerUpdate(int serverIndex)
650
639
{
651
640
case NTRIP_SERVER_OFF:
652
641
if (enabled)
642
+ {
643
+ // Start the network
653
644
ntripServerStart (serverIndex);
654
- break ;
655
-
656
- // Start the network
657
- case NTRIP_SERVER_ON:
658
- ntripServerSetState (ntripServer, NTRIP_SERVER_WAIT_FOR_NETWORK);
645
+ ntripServerSetState (serverIndex, NTRIP_SERVER_WAIT_FOR_NETWORK);
646
+ }
659
647
break ;
660
648
661
649
// Wait for a network media connection
@@ -676,15 +664,15 @@ void ntripServerUpdate(int serverIndex)
676
664
reportHeapNow (settings.debugNtripServerState );
677
665
678
666
// Reset the timeout when the network changes
679
- if (networkChanged (NETCONSUMER_NTRIP_SERVER_0 + serverIndex))
667
+ if (networkChanged (NETWORK_CONSUMER ( serverIndex) ))
680
668
{
681
669
ntripServer->connectionAttempts = 0 ;
682
670
ntripServer->connectionAttemptTimeout = 0 ;
683
671
}
684
672
685
673
// The network is available for the NTRIP server
686
- networkUserAdd (NETCONSUMER_NTRIP_SERVER_0 + serverIndex, __FILE__, __LINE__);
687
- ntripServerSetState (ntripServer , NTRIP_SERVER_NETWORK_CONNECTED);
674
+ networkUserAdd (NETWORK_CONSUMER ( serverIndex) , __FILE__, __LINE__);
675
+ ntripServerSetState (serverIndex , NTRIP_SERVER_NETWORK_CONNECTED);
688
676
}
689
677
}
690
678
break ;
@@ -703,7 +691,7 @@ void ntripServerUpdate(int serverIndex)
703
691
rtcmPacketsSent = 0 ;
704
692
705
693
// Open socket to NTRIP caster
706
- ntripServerSetState (ntripServer , NTRIP_SERVER_WAIT_GNSS_DATA);
694
+ ntripServerSetState (serverIndex , NTRIP_SERVER_WAIT_GNSS_DATA);
707
695
}
708
696
break ;
709
697
@@ -730,7 +718,7 @@ void ntripServerUpdate(int serverIndex)
730
718
{
731
719
// Connection open to NTRIP caster, wait for the authorization response
732
720
ntripServer->timer = millis ();
733
- ntripServerSetState (ntripServer , NTRIP_SERVER_AUTHORIZATION);
721
+ ntripServerSetState (serverIndex , NTRIP_SERVER_AUTHORIZATION);
734
722
}
735
723
}
736
724
break ;
@@ -794,7 +782,7 @@ void ntripServerUpdate(int serverIndex)
794
782
// We don't use a task because we use I2C hardware (and don't have a semaphore).
795
783
online.ntripServer [serverIndex] = true ;
796
784
ntripServer->startTime = millis ();
797
- ntripServerSetState (ntripServer , NTRIP_SERVER_CASTING);
785
+ ntripServerSetState (serverIndex , NTRIP_SERVER_CASTING);
798
786
}
799
787
800
788
// Look for '401 Unauthorized'
@@ -887,8 +875,6 @@ void ntripServerUpdate()
887
875
// ----------------------------------------
888
876
void ntripServerValidateTables ()
889
877
{
890
- if (NETCONSUMER_OTA_CLIENT != (NETCONSUMER_NTRIP_SERVER_0 + NTRIP_SERVER_MAX))
891
- reportFatalError (" Adjust NETCONSUMER_NTRIP_SERVER_* entries to match NTRIP_SERVER_MAX" );
892
878
if (ntripServerStateNameEntries != NTRIP_SERVER_STATE_MAX)
893
879
reportFatalError (" Fix ntripServerStateNameEntries to match NTRIPServerState" );
894
880
}
0 commit comments