diff --git a/lib/Navigation/navigation.h b/lib/Navigation/navigation.h index 65d5689..b0f42a8 100644 --- a/lib/Navigation/navigation.h +++ b/lib/Navigation/navigation.h @@ -35,7 +35,7 @@ struct CourseCorrection /** * @brief This class navigate an object * - * The class use the given Route and the gps device + * The class use the given Route and the gnss device * to tell the driver in which direction he have to * be drive and the distance to the next checkpoint. * diff --git a/lib/NtripClient/ntripClient.cpp b/lib/NtripClient/ntripClient.cpp index 731442c..7eeb2cc 100644 --- a/lib/NtripClient/ntripClient.cpp +++ b/lib/NtripClient/ntripClient.cpp @@ -11,8 +11,8 @@ #include "ntripClient.h" -NTRIPClient::NTRIPClient(SFE_UBLOX_GNSS *gps, const char *host, uint16_t port, const char *mountPoint, const char *user, const char *password) - : gps{gps}, port{port}, host{host}, mountPoint{mountPoint}, user{user}, password{password}, ntripClient{new WiFiClient}, state{NTRIPClientStates::closeConnection} +NTRIPClient::NTRIPClient(SFE_UBLOX_GNSS *gnss, const char *host, uint16_t port, const char *mountPoint, const char *user, const char *password) + : gnss{gnss}, port{port}, host{host}, mountPoint{mountPoint}, user{user}, password{password}, ntripClient{new WiFiClient}, state{NTRIPClientStates::closingConnection} { Component::loopDelay = NTRIPClient::loopDelay; } @@ -26,10 +26,10 @@ void NTRIPClient::run() { switch (this->state) { - case NTRIPClientStates::openConnection: + case NTRIPClientStates::openingConnection: if (!this->activated) { - this->state = NTRIPClientStates::closeConnection; + this->state = NTRIPClientStates::closingConnection; break; } @@ -37,33 +37,33 @@ void NTRIPClient::run() if (this->beginClient()) { std::cout << "Connected to the NTRIP caster!" << std::endl; - this->state = NTRIPClientStates::pushData; + this->state = NTRIPClientStates::pushingData; } else { std::cout << "Failed!" << std::endl; - this->state = NTRIPClientStates::wait; + this->state = NTRIPClientStates::waiting; this->activated = false; } break; - case NTRIPClientStates::pushData: + case NTRIPClientStates::pushingData: if (!processConnection() || !this->activated) { - this->state = NTRIPClientStates::closeConnection; + this->state = NTRIPClientStates::closingConnection; } break; - case NTRIPClientStates::closeConnection: + case NTRIPClientStates::closingConnection: std::cout << "Closing the connection to the NTRIP caster..." << std::endl; this->closeConnection(); - state = NTRIPClientStates::wait; + state = NTRIPClientStates::waiting; break; - case NTRIPClientStates::wait: + case NTRIPClientStates::waiting: if (this->activated) { - this->state = NTRIPClientStates::openConnection; + this->state = NTRIPClientStates::openingConnection; } else { @@ -76,7 +76,7 @@ void NTRIPClient::run() default: std::cout << "Wrong state in NTRIPClient.cpp..." << std::endl; - this->state = NTRIPClientStates::closeConnection; + this->state = NTRIPClientStates::closingConnection; break; } } @@ -86,14 +86,14 @@ void NTRIPClient::runAsChild() this->pushGPGGA(); } -void NTRIPClient::gpsConfiguration() +void NTRIPClient::gnssConfiguration() { - this->gps->setSPIOutput(COM_TYPE_UBX | COM_TYPE_NMEA); - this->gps->setPortInput(COM_PORT_SPI, COM_TYPE_UBX | COM_TYPE_NMEA | COM_TYPE_RTCM3); + this->gnss->setSPIOutput(COM_TYPE_UBX | COM_TYPE_NMEA); + this->gnss->setPortInput(COM_PORT_SPI, COM_TYPE_UBX | COM_TYPE_NMEA | COM_TYPE_RTCM3); // Set the differential mode - ambiguities are fixed whenever possible - this->gps->setDGNSSConfiguration(SFE_UBLOX_DGNSS_MODE_FIXED); - this->gps->setMainTalkerID(SFE_UBLOX_MAIN_TALKER_ID_GP); - this->gps->enableNMEAMessage(UBX_NMEA_GGA, COM_PORT_SPI, 10); + 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); } bool NTRIPClient::setActivated(bool state) @@ -145,11 +145,55 @@ bool NTRIPClient::beginClient() std::cout << "Requesting NTRIP Data from mount point " << this->mountPoint << std::endl; // Generate the server request (GET) - snprintf(static_cast(serverRequest), - this->bufferSize, - static_cast("GET /%s HTTP/1.0\r\nUser-Agent: NTRIP SparkFun u-blox Client v1.0\r\n"), - this->mountPoint); + if (this->useNtripRev1) + { + snprintf(static_cast(serverRequest), + this->bufferSize, + static_cast("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"), + this->mountPoint, + this->host, + this->port); + } + else + { + snprintf(static_cast(serverRequest), + this->bufferSize, + static_cast("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"), + this->mountPoint, + this->host, + this->port); + } + // Add own Position if activated + if (this->transmitLocation && !this->useNtripRev1) + { + auto *data = new NMEA_GGA_data_t; + const uint8_t res = this->gnss->getLatestNMEAGPGGA(data); + if (res > 0) // valid data + { + char positionUpdate[this->bufferSizePushGPGGA]; + snprintf(static_cast(positionUpdate), + this->bufferSizePushGPGGA, + static_cast("Ntrip-GGA: %s\r\n"), + data->nmea); + strncat(static_cast(serverRequest), static_cast(positionUpdate), this->bufferSize); + } + delete data; + + this->lastGPGGAPushTime = millis(); + } + + if (this->user && this->password) + { // Credentials const uint8_t userCredentialsLength = strlen(this->user) + strlen(this->password) + 2; auto *userCredentials = new char[userCredentialsLength]; @@ -168,6 +212,8 @@ bool NTRIPClient::beginClient() // Add the encoded credentials to the server request strncat(static_cast(serverRequest), static_cast(credentials), this->bufferSize); + } + strncat(static_cast(serverRequest), static_cast("\r\n"), this->bufferSize); std::cout << static_cast("serverRequest size: ") @@ -273,7 +319,7 @@ bool NTRIPClient::processConnection() if (rtcmCount > 0) { this->lastReceivedRtcmTime = millis(); - this->gps->pushRawData(static_cast(rtcmData), rtcmCount); + this->gnss->pushRawData(static_cast(rtcmData), rtcmCount); // std::cout << "Pushed " << rtcmCount << " RTCM bytes to ZED." << std::endl; } } @@ -334,15 +380,21 @@ void NTRIPClient::pushGPGGA() } auto *data = new NMEA_GGA_data_t; - const uint8_t res = this->gps->getLatestNMEAGPGGA(data); - if (res == 2) + const uint8_t res = this->gnss->getLatestNMEAGPGGA(data); + if (res == 2) // 2 means fresh data { - this->ntripClient->print(reinterpret_cast(data)); + char positionUpdate[this->bufferSizePushGPGGA]; + snprintf(static_cast(positionUpdate), + this->bufferSizePushGPGGA, + static_cast("%s\r\n"), + data->nmea); + this->ntripClient->write(positionUpdate, strlen(positionUpdate)); + std::cout << "Position update: " << positionUpdate << std::endl; } delete data; } bool NTRIPClient::isConnected() { - return this->state == NTRIPClientStates::pushData; + return this->state == NTRIPClientStates::pushingData; } diff --git a/lib/NtripClient/ntripClient.h b/lib/NtripClient/ntripClient.h index 9c2fded..5ea0dd3 100644 --- a/lib/NtripClient/ntripClient.h +++ b/lib/NtripClient/ntripClient.h @@ -27,10 +27,10 @@ */ enum NTRIPClientStates { - openConnection, - pushData, - closeConnection, - wait, + openingConnection, + pushingData, + closingConnection, + waiting, notAvailable }; @@ -47,21 +47,21 @@ public: /** * @brief Construct a new NTRIPClient object * - * @param gps The Gnss module + * @param gnss The Gnss module * @param host * @param port * @param mountPoint * @param user * @param password */ - NTRIPClient(SFE_UBLOX_GNSS *gps, const char *host, uint16_t port, const char *mountPoint, const char *user, const char *password); + NTRIPClient(SFE_UBLOX_GNSS *gnss, const char *host, uint16_t port, const char *mountPoint, const char *user = nullptr, const char *password = nullptr); ~NTRIPClient(); /** * @brief Configure the Gnss module to accept correction data * */ - void gpsConfiguration(); + void gnssConfiguration(); /** * @brief Activate or deactivate the location transmission @@ -82,6 +82,7 @@ public: */ bool setActivated(bool state); void setAutoReconnect(bool state); + void useOutdatedNtripRev1 (bool rev1 = false ) { this->useNtripRev1 = rev1; } bool isConnected(); @@ -103,13 +104,14 @@ private: bool processConnection(); void checkAutoReconnect(); - SFE_UBLOX_GNSS *gps; + SFE_UBLOX_GNSS *gnss; WiFiClient *ntripClient; NTRIPClientStates state = NTRIPClientStates::notAvailable; bool transmitLocation = false; bool activated = true; bool autoReconnect = false; + bool useNtripRev1 = false; uint8_t reconnectAttemps = 0; uint16_t port; @@ -126,6 +128,7 @@ private: const uint16_t reconnectDelayTime = 1000; const uint16_t timeOut = 10000; const uint16_t bufferSize = 512; + const uint16_t bufferSizePushGPGGA = 128; const uint16_t pushGPGGATime = 10000; static constexpr uint8_t loopDelay = 20; diff --git a/lib/Sensors/sensorData.cpp b/lib/Sensors/sensorData.cpp index f5246e8..70f9e39 100644 --- a/lib/Sensors/sensorData.cpp +++ b/lib/Sensors/sensorData.cpp @@ -28,7 +28,7 @@ SensorData::~SensorData() void SensorData::enableNtrip(String host, uint16_t port, String mountPoint, String user, String password) { this->ntripClient = new NTRIPClient(this->gnss, host.c_str(), port, mountPoint.c_str(), user.c_str(), password.c_str()); - this->ntripClient->gpsConfiguration(); + this->ntripClient->gnssConfiguration(); this->ntripClient->loop(); this->ntripClient->setActivated(false); this->isNtripInit = true; diff --git a/src/SpecialMenus/SensorData/menuSensorData.cpp b/src/SpecialMenus/SensorData/menuSensorData.cpp index 19ec032..c79d85b 100644 --- a/src/SpecialMenus/SensorData/menuSensorData.cpp +++ b/src/SpecialMenus/SensorData/menuSensorData.cpp @@ -113,7 +113,7 @@ void MenuSensorData::printPage() const lineOne = "UNKNOWN"; } const NTRIPClientStates status = this->sensorData->getNtripState(); - if (status == NTRIPClientStates::pushData) + if (status == NTRIPClientStates::pushingData) { lineTwo.concat("enabled"); } diff --git a/src/SpecialMenus/driveModi/Autopilot/menuAutopilot.cpp b/src/SpecialMenus/driveModi/Autopilot/menuAutopilot.cpp index eb97490..d720e8f 100644 --- a/src/SpecialMenus/driveModi/Autopilot/menuAutopilot.cpp +++ b/src/SpecialMenus/driveModi/Autopilot/menuAutopilot.cpp @@ -120,7 +120,7 @@ void MenuAutopilot::printPage() const const uint8_t carrSoln = gpsData->flags.bits.carrSoln; lineOne = "GNSS: "; - if (status == NTRIPClientStates::pushData) + if (status == NTRIPClientStates::pushingData) { if (carrSoln == 0) { diff --git a/src/SpecialMenus/driveModi/CaptureRoute/menuCaptureRoute.cpp b/src/SpecialMenus/driveModi/CaptureRoute/menuCaptureRoute.cpp index f5a46ed..e7f3ff5 100644 --- a/src/SpecialMenus/driveModi/CaptureRoute/menuCaptureRoute.cpp +++ b/src/SpecialMenus/driveModi/CaptureRoute/menuCaptureRoute.cpp @@ -63,7 +63,7 @@ void MenuCaptureRoute::printPage() const NTRIPClientStates status = this->captureRoute->getSensorData()->getNtripClient()->getClientState(); lineOne = "NTRIP Client is"; - if (status == NTRIPClientStates::pushData) + if (status == NTRIPClientStates::pushingData) { lineTwo = "enabled"; }