Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 13 additions & 24 deletions Firmware/RTK_Surveyor/NtripClient.ino
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand All @@ -83,7 +92,6 @@ unsigned long lastGGAPush = 0;

bool ntripClientConnect()
{
#if defined(COMPILE_WIFI) || defined(COMPILE_ETHERNET)
if (!ntripClient)
return false;

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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';
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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())
{
Expand Down Expand Up @@ -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)
{
Expand All @@ -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
35 changes: 14 additions & 21 deletions Firmware/RTK_Surveyor/NtripServer.ino
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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];

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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';
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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;
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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())
{
Expand All @@ -593,7 +585,8 @@ void ntripServerUpdate()
// All is well
cyclePositionLEDs();
}
#endif // COMPILE_WIFI || COMPILE_ETHERNET
break;
}
}

#endif // COMPILE_NETWORK
6 changes: 6 additions & 0 deletions Firmware/RTK_Surveyor/RTK_Surveyor.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down