|
|
|
@@ -47,6 +47,7 @@ void NTRIPClient::run()
|
|
|
|
|
{
|
|
|
|
|
std::cout << "Failed!" << std::endl;
|
|
|
|
|
this->state = NTRIPClientStates::waiting;
|
|
|
|
|
this->lastReconnectTime = millis();
|
|
|
|
|
this->activated = false;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
@@ -97,7 +98,7 @@ void NTRIPClient::gnssConfiguration()
|
|
|
|
|
// Set the differential mode - ambiguities are fixed whenever possible
|
|
|
|
|
this->gnss->setDGNSSConfiguration(SFE_UBLOX_DGNSS_MODE_FIXED);
|
|
|
|
|
this->gnss->setMainTalkerID(SFE_UBLOX_MAIN_TALKER_ID_GP);
|
|
|
|
|
this->gnss->enableNMEAMessage(UBX_NMEA_GGA, COM_PORT_SPI, 10);
|
|
|
|
|
this->gnss->enableNMEAMessage(UBX_NMEA_GGA, COM_PORT_SPI);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool NTRIPClient::setActivated(bool state)
|
|
|
|
@@ -153,11 +154,7 @@ bool NTRIPClient::beginClient()
|
|
|
|
|
{
|
|
|
|
|
snprintf(static_cast<char *>(serverRequest),
|
|
|
|
|
this->bufferSize,
|
|
|
|
|
static_cast<const char *>("GET /%s HTTP/1.0\r\n\
|
|
|
|
|
Host: %s:%u\r\n\
|
|
|
|
|
User-Agent: NTRIP KleiaxNtripClient/0.1\r\n\
|
|
|
|
|
Accept: */*\r\n\
|
|
|
|
|
Connection: close\r\n"),
|
|
|
|
|
static_cast<const char *>("GET /%s HTTP/1.0\r\nHost: %s:%u\r\nUser-Agent: NTRIP KleiaxNtripClient/0.1\r\nAccept: */*\r\nConnection: close\r\n"),
|
|
|
|
|
this->mountPoint,
|
|
|
|
|
this->host,
|
|
|
|
|
this->port);
|
|
|
|
@@ -166,12 +163,7 @@ bool NTRIPClient::beginClient()
|
|
|
|
|
{
|
|
|
|
|
snprintf(static_cast<char *>(serverRequest),
|
|
|
|
|
this->bufferSize,
|
|
|
|
|
static_cast<const char *>("GET /%s HTTP/1.1\r\n\
|
|
|
|
|
Host: %s:%u\r\n\
|
|
|
|
|
Ntrip-Version: Ntrip/2.0\r\n\
|
|
|
|
|
User-Agent: NTRIP KleiaxNtripClient/0.1\r\n\
|
|
|
|
|
Accept: */*\r\n\
|
|
|
|
|
Connection: close\r\n"),
|
|
|
|
|
static_cast<const char *>("GET /%s HTTP/1.1\r\nHost: %s:%u\r\nNtrip-Version: Ntrip/2.0\r\nUser-Agent: NTRIP KleiaxNtripClient/0.1\r\nAccept: */*\r\nConnection: close\r\n"),
|
|
|
|
|
this->mountPoint,
|
|
|
|
|
this->host,
|
|
|
|
|
this->port);
|
|
|
|
@@ -180,6 +172,7 @@ bool NTRIPClient::beginClient()
|
|
|
|
|
// Add own Position if activated
|
|
|
|
|
if (this->transmitLocation && !this->useNtripRev1)
|
|
|
|
|
{
|
|
|
|
|
std::cout << "NTRIPClient::beginClient - Add own position to server request." << std::endl;
|
|
|
|
|
auto *data = new NMEA_GGA_data_t;
|
|
|
|
|
const uint8_t res = this->gnss->getLatestNMEAGPGGA(data);
|
|
|
|
|
if (res > 0) // valid data
|
|
|
|
@@ -187,10 +180,14 @@ bool NTRIPClient::beginClient()
|
|
|
|
|
char positionUpdate[this->bufferSizePushGPGGA];
|
|
|
|
|
snprintf(static_cast<char *>(positionUpdate),
|
|
|
|
|
this->bufferSizePushGPGGA,
|
|
|
|
|
static_cast<const char *>("Ntrip-GGA: %s\r\n"),
|
|
|
|
|
static_cast<const char *>("Ntrip-GGA: %s"),
|
|
|
|
|
data->nmea);
|
|
|
|
|
strncat(static_cast<char *>(serverRequest), static_cast<const char *>(positionUpdate), this->bufferSize);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
std::cout << "NTRIPClient::beginClient - No valid data to send position to caster." << std::endl;
|
|
|
|
|
}
|
|
|
|
|
delete data;
|
|
|
|
|
|
|
|
|
|
this->lastGPGGAPushTime = millis();
|
|
|
|
@@ -198,24 +195,24 @@ bool NTRIPClient::beginClient()
|
|
|
|
|
|
|
|
|
|
if (this->user && this->password)
|
|
|
|
|
{
|
|
|
|
|
// Credentials
|
|
|
|
|
const uint8_t userCredentialsLength = strlen(this->user) + strlen(this->password) + 2;
|
|
|
|
|
auto *userCredentials = new char[userCredentialsLength];
|
|
|
|
|
snprintf(static_cast<char *>(userCredentials), userCredentialsLength, static_cast<const char *>("%s:%s"), this->user, this->password);
|
|
|
|
|
// Credentials
|
|
|
|
|
const uint8_t userCredentialsLength = strlen(this->user) + strlen(this->password) + 2;
|
|
|
|
|
auto *userCredentials = new char[userCredentialsLength];
|
|
|
|
|
snprintf(static_cast<char *>(userCredentials), userCredentialsLength, static_cast<const char *>("%s:%s"), this->user, this->password);
|
|
|
|
|
|
|
|
|
|
std::cout << "Sending credentials: " << userCredentials << std::endl;
|
|
|
|
|
std::cout << "Sending credentials: " << userCredentials << std::endl;
|
|
|
|
|
|
|
|
|
|
// Encode
|
|
|
|
|
const base64 base;
|
|
|
|
|
const String strEncodedCredentials = base64::encode(userCredentials);
|
|
|
|
|
delete userCredentials;
|
|
|
|
|
char encodedCredentials[strEncodedCredentials.length() + 1];
|
|
|
|
|
strEncodedCredentials.toCharArray(static_cast<char *>(encodedCredentials), sizeof(encodedCredentials));
|
|
|
|
|
// Encode
|
|
|
|
|
const base64 base;
|
|
|
|
|
const String strEncodedCredentials = base64::encode(userCredentials);
|
|
|
|
|
delete userCredentials;
|
|
|
|
|
char encodedCredentials[strEncodedCredentials.length() + 1];
|
|
|
|
|
strEncodedCredentials.toCharArray(static_cast<char *>(encodedCredentials), sizeof(encodedCredentials));
|
|
|
|
|
|
|
|
|
|
snprintf(credentials, sizeof(credentials), static_cast<const char *>("Authorization: Basic %s\r\n"), static_cast<const char *>(encodedCredentials));
|
|
|
|
|
snprintf(credentials, sizeof(credentials), static_cast<const char *>("Authorization: Basic %s\r\n"), static_cast<const char *>(encodedCredentials));
|
|
|
|
|
|
|
|
|
|
// Add the encoded credentials to the server request
|
|
|
|
|
strncat(static_cast<char *>(serverRequest), static_cast<const char *>(credentials), this->bufferSize);
|
|
|
|
|
// Add the encoded credentials to the server request
|
|
|
|
|
strncat(static_cast<char *>(serverRequest), static_cast<const char *>(credentials), this->bufferSize);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
strncat(static_cast<char *>(serverRequest), static_cast<const char *>("\r\n"), this->bufferSize);
|
|
|
|
@@ -367,7 +364,7 @@ void NTRIPClient::checkAutoReconnect()
|
|
|
|
|
|
|
|
|
|
void NTRIPClient::pushGPGGA()
|
|
|
|
|
{
|
|
|
|
|
if (!this->transmitLocation && !this->activated)
|
|
|
|
|
if ((!this->transmitLocation || !this->activated) || !this->ntripClient->connected())
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
@@ -378,23 +375,22 @@ void NTRIPClient::pushGPGGA()
|
|
|
|
|
}
|
|
|
|
|
this->lastGPGGAPushTime = millis();
|
|
|
|
|
|
|
|
|
|
if (!this->ntripClient->connected())
|
|
|
|
|
{
|
|
|
|
|
std::cout << "Failed to pushing GGA to server: " << std::endl;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto *data = new NMEA_GGA_data_t;
|
|
|
|
|
const uint8_t res = this->gnss->getLatestNMEAGPGGA(data);
|
|
|
|
|
if (res == 2) // 2 means fresh data
|
|
|
|
|
if (res > 0) // 2 means fresh data
|
|
|
|
|
{
|
|
|
|
|
char positionUpdate[this->bufferSizePushGPGGA];
|
|
|
|
|
snprintf(static_cast<char *>(positionUpdate),
|
|
|
|
|
this->bufferSizePushGPGGA,
|
|
|
|
|
static_cast<const char *>("%s\r\n"),
|
|
|
|
|
static_cast<const char *>("%s"),
|
|
|
|
|
data->nmea);
|
|
|
|
|
this->ntripClient->write(positionUpdate, strlen(positionUpdate));
|
|
|
|
|
std::cout << "Position update: " << positionUpdate << std::endl;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
std::cout << "NTRIPClient::pushGPGGA - No valid data to send position to caster." << std::endl;
|
|
|
|
|
}
|
|
|
|
|
delete data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|