Skip to content

Commit 3585919

Browse files
authored
Merge pull request #524 from LeeLeahy2/define-network
Add COMPILE_NETWORK and simplify COMPILE_WIFI and COMPILE_ETHERNET
2 parents 574123a + d49e03b commit 3585919

File tree

3 files changed

+33
-45
lines changed

3 files changed

+33
-45
lines changed

Firmware/RTK_Surveyor/NtripClient.ino

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
#if !COMPILE_NETWORK
2+
3+
void ntripClientStart()
4+
{
5+
systemPrintln("NTRIP Client not available: Ethernet and WiFi not compiled");
6+
}
7+
void ntripClientStop(bool clientAllocated) {online.ntripClient = false;}
8+
void ntripClientUpdate() {}
9+
10+
#else // COMPILE_NETWORK
11+
112
/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
213
NTRIP Client States:
314
NTRIP_CLIENT_OFF: WiFi off or using NTRIP server
@@ -62,9 +73,7 @@ static const int NTRIPCLIENT_MS_BETWEEN_GGA = 5000; // 5s between transmission o
6273
//----------------------------------------
6374

6475
// The WiFi / Ethernet connection to the NTRIP caster to obtain RTCM data.
65-
#if defined(COMPILE_WIFI) || defined(COMPILE_ETHERNET)
6676
static NTRIPClient *ntripClient;
67-
#endif // COMPILE_WIFI || COMPILE_ETHERNET
6877

6978
// Throttle the time between connection attempts
7079
// ms - Max of 4,294,967,295 or 4.3M seconds or 71,000 minutes or 1193 hours or 49 days between attempts
@@ -83,7 +92,6 @@ unsigned long lastGGAPush = 0;
8392

8493
bool ntripClientConnect()
8594
{
86-
#if defined(COMPILE_WIFI) || defined(COMPILE_ETHERNET)
8795
if (!ntripClient)
8896
return false;
8997

@@ -160,9 +168,6 @@ bool ntripClientConnect()
160168
ntripClient->write((const uint8_t *)serverRequest, strlen(serverRequest));
161169
ntripClientTimer = millis();
162170
return true;
163-
#else //! COMPILE_WIFI || COMPILE_ETHERNET
164-
return false;
165-
#endif // COMPILE_WIFI || COMPILE_ETHERNET
166171
}
167172

168173
// Determine if another connection is possible or if the limit has been reached
@@ -198,17 +203,12 @@ bool ntripClientConnectLimitReached()
198203
// Determine if NTRIP client data is available
199204
int ntripClientReceiveDataAvailable()
200205
{
201-
#if defined(COMPILE_WIFI) || defined(COMPILE_ETHERNET)
202206
return ntripClient->available();
203-
#else //! COMPILE_WIFI || COMPILE_ETHERNET
204-
return 0;
205-
#endif // COMPILE_WIFI || COMPILE_ETHERNET
206207
}
207208

208209
// Read the response from the NTRIP client
209210
void ntripClientResponse(char *response, size_t maxLength)
210211
{
211-
#if defined(COMPILE_WIFI) || defined(COMPILE_ETHERNET)
212212
char *responseEnd;
213213

214214
// Make sure that we can zero terminate the response
@@ -219,7 +219,6 @@ void ntripClientResponse(char *response, size_t maxLength)
219219
{
220220
*response++ = ntripClient->read();
221221
}
222-
#endif // COMPILE_WIFI || COMPILE_ETHERNET
223222

224223
// Zero terminate the response
225224
*response = '\0';
@@ -263,7 +262,6 @@ void ntripClientSetState(NTRIPClientState newState)
263262

264263
void ntripClientStart()
265264
{
266-
#if defined(COMPILE_WIFI) || defined(COMPILE_ETHERNET)
267265
// Stop NTRIP client and WiFi
268266
ntripClientStop(true); // Do not allocate new wifiClient
269267

@@ -283,15 +281,11 @@ void ntripClientStart()
283281
}
284282

285283
ntripClientConnectionAttempts = 0;
286-
#else //! COMPILE_WIFI || COMPILE_ETHERNET
287-
systemPrintln("NTRIP Client not available: Ethernet and WiFi not compiled");
288-
#endif // COMPILE_WIFI || COMPILE_ETHERNET
289284
}
290285

291286
// Stop the NTRIP client
292287
void ntripClientStop(bool wifiClientAllocated)
293288
{
294-
#if defined(COMPILE_WIFI) || defined(COMPILE_ETHERNET)
295289
if (ntripClient)
296290
{
297291
// Break the NTRIP client connection if necessary
@@ -327,7 +321,6 @@ void ntripClientStop(bool wifiClientAllocated)
327321
ntripClientSetState((ntripClient && (wifiClientAllocated == false)) ? NTRIP_CLIENT_ON : NTRIP_CLIENT_OFF);
328322
online.ntripClient = false;
329323
wifiIncomingRTCM = false;
330-
#endif // COMPILE_WIFI || COMPILE_ETHERNET
331324
}
332325

333326
// Determine if NTRIP Client is needed
@@ -474,7 +467,6 @@ void ntripClientUpdate()
474467
break;
475468

476469
case NTRIP_CLIENT_CONNECTING:
477-
#if defined(COMPILE_WIFI) || defined(COMPILE_ETHERNET)
478470
// Check for no response from the caster service
479471
if (ntripClientReceiveDataAvailable() < strlen("ICY 200 OK")) // Wait until at least a few bytes have arrived
480472
{
@@ -590,11 +582,9 @@ void ntripClientUpdate()
590582
}
591583
}
592584
}
593-
#endif // COMPILE_WIFI || COMPILE_ETHERNET
594585
break;
595586

596587
case NTRIP_CLIENT_CONNECTED:
597-
#if defined(COMPILE_WIFI) || defined(COMPILE_ETHERNET)
598588
// Check for a broken connection
599589
if (!ntripClient->connected())
600590
{
@@ -639,14 +629,12 @@ void ntripClientUpdate()
639629
systemPrintf("NTRIP Client received %d RTCM bytes, pushed to ZED\r\n", rtcmCount);
640630
}
641631
}
642-
#endif // COMPILE_WIFI || COMPILE_ETHERNET
643632
break;
644633
}
645634
}
646635

647636
void pushGPGGA(NMEA_GGA_data_t *nmeaData)
648637
{
649-
#if defined(COMPILE_WIFI) || defined(COMPILE_ETHERNET)
650638
// Provide the caster with our current position as needed
651639
if (ntripClient->connected() && settings.ntripClient_TransmitGGA == true)
652640
{
@@ -661,5 +649,6 @@ void pushGPGGA(NMEA_GGA_data_t *nmeaData)
661649
ntripClient->print((const char *)nmeaData->nmea);
662650
}
663651
}
664-
#endif // COMPILE_WIFI || COMPILE_ETHERNET
665652
}
653+
654+
#endif // COMPILE_NETWORK

Firmware/RTK_Surveyor/NtripServer.ino

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
#if !COMPILE_NETWORK
2+
3+
void ntripServerProcessRTCM(uint8_t incoming) {}
4+
void ntripServerStart()
5+
{
6+
systemPrintln("NTRIP Server not available: Ethernet and WiFi not compiled");
7+
}
8+
void ntripServerStop(bool clientAllocated) {online.ntripServer = false;}
9+
void ntripServerUpdate() {}
10+
11+
#else // COMPILE_NETWORK
12+
113
/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
214
NTRIP Server States:
315
NTRIP_SERVER_OFF: WiFi off or using NTRIP Client
@@ -60,9 +72,7 @@ static const int MAX_NTRIP_SERVER_CONNECTION_ATTEMPTS = 30;
6072
//----------------------------------------
6173

6274
// WiFi connection used to push RTCM to NTRIP caster over WiFi
63-
#if defined(COMPILE_WIFI) || defined(COMPILE_ETHERNET)
6475
static NTRIPClient *ntripServer;
65-
#endif // COMPILE_WIFI || COMPILE_ETHERNET
6676

6777
// Count of bytes sent by the NTRIP server to the NTRIP caster
6878
uint32_t ntripServerBytesSent = 0;
@@ -82,7 +92,6 @@ static uint32_t ntripServerStateLastDisplayed = 0;
8292
// Initiate a connection to the NTRIP caster
8393
bool ntripServerConnectCaster()
8494
{
85-
#if defined(COMPILE_WIFI) || defined(COMPILE_ETHERNET)
8695
const int SERVER_BUFFER_SIZE = 512;
8796
char serverBuffer[SERVER_BUFFER_SIZE];
8897

@@ -119,9 +128,6 @@ bool ntripServerConnectCaster()
119128
// Send the authorization credentials to the NTRIP caster
120129
ntripServer->write((const uint8_t *)serverBuffer, strlen(serverBuffer));
121130
return true;
122-
#else // COMPILE_WIFI || COMPILE_ETHERNET
123-
return false;
124-
#endif // COMPILE_WIFI || COMPILE_ETHERNET
125131
}
126132

127133
// Determine if the connection limit has been reached
@@ -164,7 +170,6 @@ bool ntripServerConnectLimitReached()
164170
// Read the authorization response from the NTRIP caster
165171
void ntripServerResponse(char *response, size_t maxLength)
166172
{
167-
#if defined(COMPILE_WIFI) || defined(COMPILE_ETHERNET)
168173
char *responseEnd;
169174

170175
// Make sure that we can zero terminate the response
@@ -173,7 +178,6 @@ void ntripServerResponse(char *response, size_t maxLength)
173178
// Read bytes from the caster and store them
174179
while ((response < responseEnd) && ntripServer->available())
175180
*response++ = ntripServer->read();
176-
#endif // COMPILE_WIFI || COMPILE_ETHERNET
177181

178182
// Zero terminate the response
179183
*response = '\0';
@@ -224,7 +228,6 @@ void ntripServerSetState(NTRIPServerState newState)
224228
// This function gets called as each RTCM byte comes in
225229
void ntripServerProcessRTCM(uint8_t incoming)
226230
{
227-
#if defined(COMPILE_WIFI) || defined(COMPILE_ETHERNET)
228231
if (ntripServerState == NTRIP_SERVER_CASTING)
229232
{
230233
// Generate and print timestamp if needed
@@ -273,13 +276,11 @@ void ntripServerProcessRTCM(uint8_t incoming)
273276
ntripServerSetState(NTRIP_SERVER_CONNECTING);
274277
rtcmParsingState = RTCM_TRANSPORT_STATE_WAIT_FOR_PREAMBLE_D3;
275278
}
276-
#endif // COMPILE_WIFI || COMPILE_ETHERNET
277279
}
278280

279281
// Start the NTRIP server
280282
void ntripServerStart()
281283
{
282-
#if defined(COMPILE_WIFI) || defined(COMPILE_ETHERNET)
283284
// Stop NTRIP server and WiFi
284285
ntripServerStop(true); // Don't allocate new wifiClient
285286

@@ -298,15 +299,11 @@ void ntripServerStart()
298299
}
299300

300301
ntripServerConnectionAttempts = 0;
301-
#else // COMPILE_WIFI || COMPILE_ETHERNET
302-
systemPrintln("NTRIP Server not available: Ethernet and WiFi not compiled");
303-
#endif // COMPILE_WIFI || COMPILE_ETHERNET
304302
}
305303

306304
// Stop the NTRIP server
307305
void ntripServerStop(bool wifiClientAllocated)
308306
{
309-
#if defined(COMPILE_WIFI) || defined(COMPILE_ETHERNET)
310307
if (ntripServer)
311308
{
312309
// Break the NTRIP server connection if necessary
@@ -333,8 +330,6 @@ void ntripServerStop(bool wifiClientAllocated)
333330

334331
// Determine the next NTRIP server state
335332
ntripServerSetState((ntripServer && (wifiClientAllocated == false)) ? NTRIP_SERVER_ON : NTRIP_SERVER_OFF);
336-
#endif // COMPILE_WIFI || COMPILE_ETHERNET
337-
338333
online.ntripServer = false;
339334
}
340335

@@ -487,7 +482,6 @@ void ntripServerUpdate()
487482
// Wait for authorization response
488483
case NTRIP_SERVER_AUTHORIZATION:
489484
// Check if caster service responded
490-
#if defined(COMPILE_WIFI) || defined(COMPILE_ETHERNET)
491485
if (ntripServer->available() < strlen("ICY 200 OK")) // Wait until at least a few bytes have arrived
492486
{
493487
// Check for response timeout
@@ -571,11 +565,9 @@ void ntripServerUpdate()
571565
}
572566
}
573567
}
574-
#endif // COMPILE_WIFI || COMPILE_ETHERNET
575568
break;
576569
// NTRIP server authorized to send RTCM correction data to NTRIP caster
577570
case NTRIP_SERVER_CASTING:
578-
#if defined(COMPILE_WIFI) || defined(COMPILE_ETHERNET)
579571
// Check for a broken connection
580572
if (!ntripServer->connected())
581573
{
@@ -594,7 +586,8 @@ void ntripServerUpdate()
594586
// All is well
595587
cyclePositionLEDs();
596588
}
597-
#endif // COMPILE_WIFI || COMPILE_ETHERNET
598589
break;
599590
}
600591
}
592+
593+
#endif // COMPILE_NETWORK

Firmware/RTK_Surveyor/RTK_Surveyor.ino

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@
2929
// #define REF_STN_GNSS_DEBUG //Uncomment this line to output GNSS library debug messages on serialGNSS. Ref Stn only.
3030
// Needs ENABLE_DEVELOPER
3131

32+
#if defined(COMPILE_WIFI) || defined(COMPILE_ETHERNET)
33+
#define COMPILE_NETWORK true
34+
#else // COMPILE_WIFI || COMPILE_ETHERNET
35+
#define COMPILE_NETWORK false
36+
#endif // COMPILE_WIFI || COMPILE_ETHERNET
37+
3238
// Always define ENABLE_DEVELOPER to enable its use in conditional statements
3339
#ifndef ENABLE_DEVELOPER
3440
#define ENABLE_DEVELOPER \

0 commit comments

Comments
 (0)