try to work ntrip client

This commit is contained in:
2022-10-24 22:08:19 +02:00
parent ee5bc9129a
commit e01127e3e3
12 changed files with 108 additions and 44 deletions
+45 -21
View File
@@ -13,11 +13,11 @@
NTRIPClient::NTRIPClient(SFE_UBLOX_GNSS* gps, const char* host, uint16_t port, const char* mountPoint, const char* user, const char* password) {
this->gps = gps;
this->host = host;
strcpy(this->host, host);
this->port = port;
this->mountPoint = mountPoint;
this->user = user;
this->password = password;
strcpy(this->mountPoint, mountPoint);
strcpy(this->user, user);
strcpy(this->password, password);
this->ntripClient = new WiFiClient;
}
@@ -35,17 +35,27 @@ void NTRIPClient::loop() {
this->gps->checkCallbacks();
if (millis() - this->lastGPGGAPushTime > this->pushGPGGATime) {
NMEA_GGA_data_t *data = nullptr;
this->lastGPGGAPushTime = millis();
// std::cout << "Try to push GPGGA data." << std::endl;
NMEA_GGA_data_t *data = new NMEA_GGA_data_t;
DebugTimes requestGpsData;
uint8_t res = this->gps->getLatestNMEAGPGGA(data);
requestGpsData.stopConsol("RequestGpsData", 5);
if (res == 2)
this->pushGPGGA(data);
delete data;
}
switch (this->state) {
case NTRIPClientStates::openConnection:
if (millis() - this->lastNtripConnectTime > this->tryReconnectTime)
if (millis() - this->lastNtripConnectTime < this->tryReconnectTime)
break;
if (!this->activated) {
this->state = NTRIPClientStates::closeConnection;
break;
}
std::cout << "Connecting to the NTRIP caster..." << std::endl;
if (this->beginClient()) {
std::cout << "Connected to the NTRIP caster!" << std::endl;
@@ -53,12 +63,12 @@ void NTRIPClient::loop() {
} else {
uint8_t seconds = this->tryReconnectTime / 1000;
std::cout << "Could not connect to the caster. Trying again in "
<< seconds << " seconds." << std::endl;
<< (int) seconds << " seconds." << std::endl;
this->lastNtripConnectTime = millis();
}
break;
case pushData:
case NTRIPClientStates::pushData:
if (!processConnection() || !this->activated)
this->state = NTRIPClientStates::closeConnection;
break;
@@ -72,6 +82,14 @@ void NTRIPClient::loop() {
case NTRIPClientStates::wait:
if (this->activated)
this->state = NTRIPClientStates::openConnection;
if (this->activated) {
std::cout << "state is openConnection" << std::endl;
}
break;
default:
std::cout << "Wrong state in NTRIPClient.cpp..." << std::endl;
this->state = NTRIPClientStates::closeConnection;
break;
}
}
@@ -79,7 +97,8 @@ void NTRIPClient::loop() {
void NTRIPClient::gpsConfiguration() {
this->gps->setI2COutput(COM_TYPE_UBX | COM_TYPE_NMEA);
this->gps->setPortInput(COM_PORT_I2C, COM_TYPE_UBX | COM_TYPE_NMEA | COM_TYPE_RTCM3);
this->gps->setDGNSSConfiguration(SFE_UBLOX_DGNSS_MODE_FIXED); // Set the differential mode - ambiguities are fixed whenever possible
// Set the differential mode - ambiguities are fixed whenever possible
// this->gps->setDGNSSConfiguration(SFE_UBLOX_DGNSS_MODE_FIXED);
this->gps->setNavigationFrequency(1);
this->gps->setMainTalkerID(SFE_UBLOX_MAIN_TALKER_ID_GP);
this->gps->enableNMEAMessage(UBX_NMEA_GGA, COM_PORT_I2C, 10);
@@ -107,7 +126,7 @@ bool NTRIPClient::beginClient() {
this->mountPoint);
// Credentials
uint8_t userCredentialsLength = strlen(this->user) + strlen(this->password) + 1;
uint8_t userCredentialsLength = strlen(this->user) + strlen(this->password) + 2;
char* userCredentials = new char[userCredentialsLength];
snprintf(userCredentials, userCredentialsLength, "%s:%s", this->user, this->password);
@@ -162,7 +181,7 @@ bool NTRIPClient::beginClient() {
if (httpStatusCode == 0) {
if (strstr(response, "200") != nullptr)
httpStatusCode = 200;
if (strstr(response, "400") != nullptr)
if (strstr(response, "401") != nullptr)
httpStatusCode = 401;
}
}
@@ -171,8 +190,12 @@ bool NTRIPClient::beginClient() {
// std::cout << "Caster response: " << response << std::endl;
if (httpStatusCode != 200) {
std::cout << "Failed to connect to " << this->host << std::endl;
if (httpStatusCode == 401)
std::cout << "Failed to connect to " << this->host << " - HTTP Code: " << (int) httpStatusCode
<< " Length of Response: " << responseIndex << std::endl;
if (httpStatusCode == 0)
std::cout << "Response: " << response << std::endl;
else if (httpStatusCode == 401)
std::cout << "Statuscode 401 - Unauthorized" << std::endl;
return false;
}
@@ -243,6 +266,7 @@ void NTRIPClient::printPVTdata(UBX_NAV_PVT_data_t *ubxDataStruct) {
else if (fixType == 3)
strcpy(fixTypeString, "GNSS + Dead Reckoning");
else if (fixType == 5)
strcpy(fixTypeString, "Time Only");
else
strcpy(fixTypeString, "UNKNOWN");
@@ -250,23 +274,23 @@ void NTRIPClient::printPVTdata(UBX_NAV_PVT_data_t *ubxDataStruct) {
uint8_t carrSoln = ubxDataStruct->flags.bits.carrSoln;
char carrSolnString[16];
if (carrSoln == 0)
strcpy(fixTypeString, "None");
strcpy(carrSolnString, "None");
else if (carrSoln == 1)
strcpy(fixTypeString, "Floating");
strcpy(carrSolnString, "Floating");
else if (carrSoln == 2)
strcpy(fixTypeString, "Fixed");
strcpy(carrSolnString, "Fixed");
else
strcpy(fixTypeString, "UNKNOWN");
strcpy(carrSolnString, "UNKNOWN");
uint32_t hAcc = ubxDataStruct->hAcc;
std::cout << "Lat: " << latitude
<< "Lng: " << longitude
<< "Alt: " << altitude << std::endl;
<< " Lng: " << longitude
<< " Alt: " << altitude << std::endl;
std::cout << "Fix: " << fixTypeString
<< "Carrier Solution: " << carrSolnString
<< "Horizontal Accuracy Estimate: " << hAcc << " mm" << std::endl;
<< " Carrier Solution: " << carrSolnString
<< " Horizontal Accuracy Estimate: " << hAcc << " mm" << std::endl;
}
bool NTRIPClient::isConnected() {