Skip to content

Commit d49e03b

Browse files
committed
Add COMPILE_NETWORK and simplify COMPILE_WIFI and COMPILE_ETHERNET
1 parent a3ed882 commit d49e03b

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

@@ -157,9 +165,6 @@ bool ntripClientConnect()
157165
ntripClient->write((const uint8_t *)serverRequest, strlen(serverRequest));
158166
ntripClientTimer = millis();
159167
return true;
160-
#else //! COMPILE_WIFI || COMPILE_ETHERNET
161-
return false;
162-
#endif // COMPILE_WIFI || COMPILE_ETHERNET
163168
}
164169

165170
// Determine if another connection is possible or if the limit has been reached
@@ -195,17 +200,12 @@ bool ntripClientConnectLimitReached()
195200
// Determine if NTRIP client data is available
196201
int ntripClientReceiveDataAvailable()
197202
{
198-
#if defined(COMPILE_WIFI) || defined(COMPILE_ETHERNET)
199203
return ntripClient->available();
200-
#else //! COMPILE_WIFI || COMPILE_ETHERNET
201-
return 0;
202-
#endif // COMPILE_WIFI || COMPILE_ETHERNET
203204
}
204205

205206
// Read the response from the NTRIP client
206207
void ntripClientResponse(char *response, size_t maxLength)
207208
{
208-
#if defined(COMPILE_WIFI) || defined(COMPILE_ETHERNET)
209209
char *responseEnd;
210210

211211
// Make sure that we can zero terminate the response
@@ -216,7 +216,6 @@ void ntripClientResponse(char *response, size_t maxLength)
216216
{
217217
*response++ = ntripClient->read();
218218
}
219-
#endif // COMPILE_WIFI || COMPILE_ETHERNET
220219

221220
// Zero terminate the response
222221
*response = '\0';
@@ -260,7 +259,6 @@ void ntripClientSetState(NTRIPClientState newState)
260259

261260
void ntripClientStart()
262261
{
263-
#if defined(COMPILE_WIFI) || defined(COMPILE_ETHERNET)
264262
// Stop NTRIP client and WiFi
265263
ntripClientStop(true); // Do not allocate new wifiClient
266264

@@ -280,15 +278,11 @@ void ntripClientStart()
280278
}
281279

282280
ntripClientConnectionAttempts = 0;
283-
#else //! COMPILE_WIFI || COMPILE_ETHERNET
284-
systemPrintln("NTRIP Client not available: Ethernet and WiFi not compiled");
285-
#endif // COMPILE_WIFI || COMPILE_ETHERNET
286281
}
287282

288283
// Stop the NTRIP client
289284
void ntripClientStop(bool wifiClientAllocated)
290285
{
291-
#if defined(COMPILE_WIFI) || defined(COMPILE_ETHERNET)
292286
if (ntripClient)
293287
{
294288
// Break the NTRIP client connection if necessary
@@ -324,7 +318,6 @@ void ntripClientStop(bool wifiClientAllocated)
324318
ntripClientSetState((ntripClient && (wifiClientAllocated == false)) ? NTRIP_CLIENT_ON : NTRIP_CLIENT_OFF);
325319
online.ntripClient = false;
326320
wifiIncomingRTCM = false;
327-
#endif // COMPILE_WIFI || COMPILE_ETHERNET
328321
}
329322

330323
// Determine if NTRIP Client is needed
@@ -471,7 +464,6 @@ void ntripClientUpdate()
471464
break;
472465

473466
case NTRIP_CLIENT_CONNECTING:
474-
#if defined(COMPILE_WIFI) || defined(COMPILE_ETHERNET)
475467
// Check for no response from the caster service
476468
if (ntripClientReceiveDataAvailable() < strlen("ICY 200 OK")) // Wait until at least a few bytes have arrived
477469
{
@@ -587,11 +579,9 @@ void ntripClientUpdate()
587579
}
588580
}
589581
}
590-
#endif // COMPILE_WIFI || COMPILE_ETHERNET
591582
break;
592583

593584
case NTRIP_CLIENT_CONNECTED:
594-
#if defined(COMPILE_WIFI) || defined(COMPILE_ETHERNET)
595585
// Check for a broken connection
596586
if (!ntripClient->connected())
597587
{
@@ -636,14 +626,12 @@ void ntripClientUpdate()
636626
systemPrintf("NTRIP Client received %d RTCM bytes, pushed to ZED\r\n", rtcmCount);
637627
}
638628
}
639-
#endif // COMPILE_WIFI || COMPILE_ETHERNET
640629
break;
641630
}
642631
}
643632

644633
void pushGPGGA(NMEA_GGA_data_t *nmeaData)
645634
{
646-
#if defined(COMPILE_WIFI) || defined(COMPILE_ETHERNET)
647635
// Provide the caster with our current position as needed
648636
if (ntripClient->connected() && settings.ntripClient_TransmitGGA == true)
649637
{
@@ -658,5 +646,6 @@ void pushGPGGA(NMEA_GGA_data_t *nmeaData)
658646
ntripClient->print((const char *)nmeaData->nmea);
659647
}
660648
}
661-
#endif // COMPILE_WIFI || COMPILE_ETHERNET
662649
}
650+
651+
#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

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

126132
// Determine if the connection limit has been reached
@@ -163,7 +169,6 @@ bool ntripServerConnectLimitReached()
163169
// Read the authorization response from the NTRIP caster
164170
void ntripServerResponse(char *response, size_t maxLength)
165171
{
166-
#if defined(COMPILE_WIFI) || defined(COMPILE_ETHERNET)
167172
char *responseEnd;
168173

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

177181
// Zero terminate the response
178182
*response = '\0';
@@ -223,7 +227,6 @@ void ntripServerSetState(NTRIPServerState newState)
223227
// This function gets called as each RTCM byte comes in
224228
void ntripServerProcessRTCM(uint8_t incoming)
225229
{
226-
#if defined(COMPILE_WIFI) || defined(COMPILE_ETHERNET)
227230
if (ntripServerState == NTRIP_SERVER_CASTING)
228231
{
229232
// Generate and print timestamp if needed
@@ -272,13 +275,11 @@ void ntripServerProcessRTCM(uint8_t incoming)
272275
ntripServerSetState(NTRIP_SERVER_CONNECTING);
273276
rtcmParsingState = RTCM_TRANSPORT_STATE_WAIT_FOR_PREAMBLE_D3;
274277
}
275-
#endif // COMPILE_WIFI || COMPILE_ETHERNET
276278
}
277279

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

@@ -297,15 +298,11 @@ void ntripServerStart()
297298
}
298299

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

305303
// Stop the NTRIP server
306304
void ntripServerStop(bool wifiClientAllocated)
307305
{
308-
#if defined(COMPILE_WIFI) || defined(COMPILE_ETHERNET)
309306
if (ntripServer)
310307
{
311308
// Break the NTRIP server connection if necessary
@@ -332,8 +329,6 @@ void ntripServerStop(bool wifiClientAllocated)
332329

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

@@ -486,7 +481,6 @@ void ntripServerUpdate()
486481
// Wait for authorization response
487482
case NTRIP_SERVER_AUTHORIZATION:
488483
// Check if caster service responded
489-
#if defined(COMPILE_WIFI) || defined(COMPILE_ETHERNET)
490484
if (ntripServer->available() < strlen("ICY 200 OK")) // Wait until at least a few bytes have arrived
491485
{
492486
// Check for response timeout
@@ -570,11 +564,9 @@ void ntripServerUpdate()
570564
}
571565
}
572566
}
573-
#endif // COMPILE_WIFI || COMPILE_ETHERNET
574567
break;
575568
// NTRIP server authorized to send RTCM correction data to NTRIP caster
576569
case NTRIP_SERVER_CASTING:
577-
#if defined(COMPILE_WIFI) || defined(COMPILE_ETHERNET)
578570
// Check for a broken connection
579571
if (!ntripServer->connected())
580572
{
@@ -593,7 +585,8 @@ void ntripServerUpdate()
593585
// All is well
594586
cyclePositionLEDs();
595587
}
596-
#endif // COMPILE_WIFI || COMPILE_ETHERNET
597588
break;
598589
}
599590
}
591+
592+
#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)