From d49e03b0b7530509ec88e518253b195e957c076b Mon Sep 17 00:00:00 2001 From: Lee Leahy Date: Wed, 5 Jul 2023 08:24:21 -1000 Subject: [PATCH] Add COMPILE_NETWORK and simplify COMPILE_WIFI and COMPILE_ETHERNET --- Firmware/RTK_Surveyor/NtripClient.ino | 37 +++++++++----------------- Firmware/RTK_Surveyor/NtripServer.ino | 35 ++++++++++-------------- Firmware/RTK_Surveyor/RTK_Surveyor.ino | 6 +++++ 3 files changed, 33 insertions(+), 45 deletions(-) diff --git a/Firmware/RTK_Surveyor/NtripClient.ino b/Firmware/RTK_Surveyor/NtripClient.ino index 87e41849d..c11613e4f 100644 --- a/Firmware/RTK_Surveyor/NtripClient.ino +++ b/Firmware/RTK_Surveyor/NtripClient.ino @@ -1,3 +1,14 @@ +#if !COMPILE_NETWORK + +void ntripClientStart() +{ + systemPrintln("NTRIP Client not available: Ethernet and WiFi not compiled"); +} +void ntripClientStop(bool clientAllocated) {online.ntripClient = false;} +void ntripClientUpdate() {} + +#else // COMPILE_NETWORK + /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= NTRIP Client States: 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 //---------------------------------------- // The WiFi / Ethernet connection to the NTRIP caster to obtain RTCM data. -#if defined(COMPILE_WIFI) || defined(COMPILE_ETHERNET) static NTRIPClient *ntripClient; -#endif // COMPILE_WIFI || COMPILE_ETHERNET // Throttle the time between connection attempts // 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; bool ntripClientConnect() { -#if defined(COMPILE_WIFI) || defined(COMPILE_ETHERNET) if (!ntripClient) return false; @@ -157,9 +165,6 @@ bool ntripClientConnect() ntripClient->write((const uint8_t *)serverRequest, strlen(serverRequest)); ntripClientTimer = millis(); return true; -#else //! COMPILE_WIFI || COMPILE_ETHERNET - return false; -#endif // COMPILE_WIFI || COMPILE_ETHERNET } // Determine if another connection is possible or if the limit has been reached @@ -195,17 +200,12 @@ bool ntripClientConnectLimitReached() // Determine if NTRIP client data is available int ntripClientReceiveDataAvailable() { -#if defined(COMPILE_WIFI) || defined(COMPILE_ETHERNET) return ntripClient->available(); -#else //! COMPILE_WIFI || COMPILE_ETHERNET - return 0; -#endif // COMPILE_WIFI || COMPILE_ETHERNET } // Read the response from the NTRIP client void ntripClientResponse(char *response, size_t maxLength) { -#if defined(COMPILE_WIFI) || defined(COMPILE_ETHERNET) char *responseEnd; // Make sure that we can zero terminate the response @@ -216,7 +216,6 @@ void ntripClientResponse(char *response, size_t maxLength) { *response++ = ntripClient->read(); } -#endif // COMPILE_WIFI || COMPILE_ETHERNET // Zero terminate the response *response = '\0'; @@ -260,7 +259,6 @@ void ntripClientSetState(NTRIPClientState newState) void ntripClientStart() { -#if defined(COMPILE_WIFI) || defined(COMPILE_ETHERNET) // Stop NTRIP client and WiFi ntripClientStop(true); // Do not allocate new wifiClient @@ -280,15 +278,11 @@ void ntripClientStart() } ntripClientConnectionAttempts = 0; -#else //! COMPILE_WIFI || COMPILE_ETHERNET - systemPrintln("NTRIP Client not available: Ethernet and WiFi not compiled"); -#endif // COMPILE_WIFI || COMPILE_ETHERNET } // Stop the NTRIP client void ntripClientStop(bool wifiClientAllocated) { -#if defined(COMPILE_WIFI) || defined(COMPILE_ETHERNET) if (ntripClient) { // Break the NTRIP client connection if necessary @@ -324,7 +318,6 @@ void ntripClientStop(bool wifiClientAllocated) ntripClientSetState((ntripClient && (wifiClientAllocated == false)) ? NTRIP_CLIENT_ON : NTRIP_CLIENT_OFF); online.ntripClient = false; wifiIncomingRTCM = false; -#endif // COMPILE_WIFI || COMPILE_ETHERNET } // Determine if NTRIP Client is needed @@ -471,7 +464,6 @@ void ntripClientUpdate() break; case NTRIP_CLIENT_CONNECTING: -#if defined(COMPILE_WIFI) || defined(COMPILE_ETHERNET) // Check for no response from the caster service if (ntripClientReceiveDataAvailable() < strlen("ICY 200 OK")) // Wait until at least a few bytes have arrived { @@ -587,11 +579,9 @@ void ntripClientUpdate() } } } -#endif // COMPILE_WIFI || COMPILE_ETHERNET break; case NTRIP_CLIENT_CONNECTED: -#if defined(COMPILE_WIFI) || defined(COMPILE_ETHERNET) // Check for a broken connection if (!ntripClient->connected()) { @@ -636,14 +626,12 @@ void ntripClientUpdate() systemPrintf("NTRIP Client received %d RTCM bytes, pushed to ZED\r\n", rtcmCount); } } -#endif // COMPILE_WIFI || COMPILE_ETHERNET break; } } void pushGPGGA(NMEA_GGA_data_t *nmeaData) { -#if defined(COMPILE_WIFI) || defined(COMPILE_ETHERNET) // Provide the caster with our current position as needed if (ntripClient->connected() && settings.ntripClient_TransmitGGA == true) { @@ -658,5 +646,6 @@ void pushGPGGA(NMEA_GGA_data_t *nmeaData) ntripClient->print((const char *)nmeaData->nmea); } } -#endif // COMPILE_WIFI || COMPILE_ETHERNET } + +#endif // COMPILE_NETWORK diff --git a/Firmware/RTK_Surveyor/NtripServer.ino b/Firmware/RTK_Surveyor/NtripServer.ino index 76332d9e8..486aac4ae 100644 --- a/Firmware/RTK_Surveyor/NtripServer.ino +++ b/Firmware/RTK_Surveyor/NtripServer.ino @@ -1,3 +1,15 @@ +#if !COMPILE_NETWORK + +void ntripServerProcessRTCM(uint8_t incoming) {} +void ntripServerStart() +{ + systemPrintln("NTRIP Server not available: Ethernet and WiFi not compiled"); +} +void ntripServerStop(bool clientAllocated) {online.ntripServer = false;} +void ntripServerUpdate() {} + +#else // COMPILE_NETWORK + /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= NTRIP Server States: NTRIP_SERVER_OFF: WiFi off or using NTRIP Client @@ -60,9 +72,7 @@ static const int MAX_NTRIP_SERVER_CONNECTION_ATTEMPTS = 30; //---------------------------------------- // WiFi connection used to push RTCM to NTRIP caster over WiFi -#if defined(COMPILE_WIFI) || defined(COMPILE_ETHERNET) static NTRIPClient *ntripServer; -#endif // COMPILE_WIFI || COMPILE_ETHERNET // Count of bytes sent by the NTRIP server to the NTRIP caster uint32_t ntripServerBytesSent = 0; @@ -82,7 +92,6 @@ static uint32_t ntripServerStateLastDisplayed = 0; // Initiate a connection to the NTRIP caster bool ntripServerConnectCaster() { -#if defined(COMPILE_WIFI) || defined(COMPILE_ETHERNET) const int SERVER_BUFFER_SIZE = 512; char serverBuffer[SERVER_BUFFER_SIZE]; @@ -118,9 +127,6 @@ bool ntripServerConnectCaster() // Send the authorization credentials to the NTRIP caster ntripServer->write((const uint8_t *)serverBuffer, strlen(serverBuffer)); return true; -#else // COMPILE_WIFI || COMPILE_ETHERNET - return false; -#endif // COMPILE_WIFI || COMPILE_ETHERNET } // Determine if the connection limit has been reached @@ -163,7 +169,6 @@ bool ntripServerConnectLimitReached() // Read the authorization response from the NTRIP caster void ntripServerResponse(char *response, size_t maxLength) { -#if defined(COMPILE_WIFI) || defined(COMPILE_ETHERNET) char *responseEnd; // Make sure that we can zero terminate the response @@ -172,7 +177,6 @@ void ntripServerResponse(char *response, size_t maxLength) // Read bytes from the caster and store them while ((response < responseEnd) && ntripServer->available()) *response++ = ntripServer->read(); -#endif // COMPILE_WIFI || COMPILE_ETHERNET // Zero terminate the response *response = '\0'; @@ -223,7 +227,6 @@ void ntripServerSetState(NTRIPServerState newState) // This function gets called as each RTCM byte comes in void ntripServerProcessRTCM(uint8_t incoming) { -#if defined(COMPILE_WIFI) || defined(COMPILE_ETHERNET) if (ntripServerState == NTRIP_SERVER_CASTING) { // Generate and print timestamp if needed @@ -272,13 +275,11 @@ void ntripServerProcessRTCM(uint8_t incoming) ntripServerSetState(NTRIP_SERVER_CONNECTING); rtcmParsingState = RTCM_TRANSPORT_STATE_WAIT_FOR_PREAMBLE_D3; } -#endif // COMPILE_WIFI || COMPILE_ETHERNET } // Start the NTRIP server void ntripServerStart() { -#if defined(COMPILE_WIFI) || defined(COMPILE_ETHERNET) // Stop NTRIP server and WiFi ntripServerStop(true); // Don't allocate new wifiClient @@ -297,15 +298,11 @@ void ntripServerStart() } ntripServerConnectionAttempts = 0; -#else // COMPILE_WIFI || COMPILE_ETHERNET - systemPrintln("NTRIP Server not available: Ethernet and WiFi not compiled"); -#endif // COMPILE_WIFI || COMPILE_ETHERNET } // Stop the NTRIP server void ntripServerStop(bool wifiClientAllocated) { -#if defined(COMPILE_WIFI) || defined(COMPILE_ETHERNET) if (ntripServer) { // Break the NTRIP server connection if necessary @@ -332,8 +329,6 @@ void ntripServerStop(bool wifiClientAllocated) // Determine the next NTRIP server state ntripServerSetState((ntripServer && (wifiClientAllocated == false)) ? NTRIP_SERVER_ON : NTRIP_SERVER_OFF); -#endif // COMPILE_WIFI || COMPILE_ETHERNET - online.ntripServer = false; } @@ -486,7 +481,6 @@ void ntripServerUpdate() // Wait for authorization response case NTRIP_SERVER_AUTHORIZATION: // Check if caster service responded -#if defined(COMPILE_WIFI) || defined(COMPILE_ETHERNET) if (ntripServer->available() < strlen("ICY 200 OK")) // Wait until at least a few bytes have arrived { // Check for response timeout @@ -570,11 +564,9 @@ void ntripServerUpdate() } } } -#endif // COMPILE_WIFI || COMPILE_ETHERNET break; // NTRIP server authorized to send RTCM correction data to NTRIP caster case NTRIP_SERVER_CASTING: -#if defined(COMPILE_WIFI) || defined(COMPILE_ETHERNET) // Check for a broken connection if (!ntripServer->connected()) { @@ -593,7 +585,8 @@ void ntripServerUpdate() // All is well cyclePositionLEDs(); } -#endif // COMPILE_WIFI || COMPILE_ETHERNET break; } } + +#endif // COMPILE_NETWORK diff --git a/Firmware/RTK_Surveyor/RTK_Surveyor.ino b/Firmware/RTK_Surveyor/RTK_Surveyor.ino index bc071e25d..a182e7b2b 100644 --- a/Firmware/RTK_Surveyor/RTK_Surveyor.ino +++ b/Firmware/RTK_Surveyor/RTK_Surveyor.ino @@ -29,6 +29,12 @@ // #define REF_STN_GNSS_DEBUG //Uncomment this line to output GNSS library debug messages on serialGNSS. Ref Stn only. // Needs ENABLE_DEVELOPER +#if defined(COMPILE_WIFI) || defined(COMPILE_ETHERNET) +#define COMPILE_NETWORK true +#else // COMPILE_WIFI || COMPILE_ETHERNET +#define COMPILE_NETWORK false +#endif // COMPILE_WIFI || COMPILE_ETHERNET + // Always define ENABLE_DEVELOPER to enable its use in conditional statements #ifndef ENABLE_DEVELOPER #define ENABLE_DEVELOPER \