diff --git a/.vscode/settings.json b/.vscode/settings.json index d055b55..38afa8c 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,5 +1,6 @@ { "files.insertFinalNewline": true, + "editor.wordWrap": "on", "cSpell.ignoreWords": [ "ledc", "write" @@ -132,6 +133,7 @@ "Doxygen", "Dutycycle", "gast", + "gnss", "GNSS", "GPGGA", "HSPI", @@ -140,9 +142,12 @@ "kleiax", "Lebennig", "microcontroller", + "Mqtt", "MQTT", "NMEA", "NMEAGPGGA", + "ntrip", + "Ntrip", "NTRIP", "pcnt", "pidl", @@ -150,6 +155,8 @@ "Punica", "RHEDE", "Rtcm", + "sapos", + "SAPOS", "Schalke", "Soln", "Systeminformation", diff --git a/include/networkConfig.h b/include/networkConfig.h index 16bf1f2..1b06810 100644 --- a/include/networkConfig.h +++ b/include/networkConfig.h @@ -14,7 +14,9 @@ #include -#define HOTSPOT +#define ZUHAUSE +#define SAPOS_NI +// #define RTK2GO #ifdef HOTSPOT namespace NetworkConfig @@ -61,7 +63,7 @@ namespace NetworkConfig { const char ssid[] = "Tuedelkram"; const char password[] = "3!Kaesehoch"; - const char ip[] = "192.168.178.11"; + const char ip[] = "192.168.178.13"; const char subnet[] = "255.255.255.0"; const char gateway[] = "192.168.178.1"; const char dns[] = "8.8.8.8"; @@ -77,6 +79,7 @@ namespace MqttConfig const char password[] = "p?{$_~5%hBM7wrcFkr55KWr#"; } +#ifdef RTK2GO namespace NtripConfig { const char host[] = "rtk2go.com"; @@ -86,4 +89,18 @@ namespace NtripConfig // const char mountPoint[] = "Rtkramerntrip"; const char user[] = "alklein1@gmx.de"; const char password[] = "none"; + const bool sendOwnPosition = false; } +#endif // RTK2GO + +#ifdef SAPOS_NI +namespace NtripConfig +{ + const char host[] = "sapos-ni-ntrip.de"; + const uint16_t port = 2101; + const char mountPoint[] = "VRS_3_4G_NI"; + const char user[] = "ni_FHDo01"; + const char password[] = "ALdx-1-3e49"; + const bool sendOwnPosition = true; +} +#endif // RTK2GO diff --git a/lib/NtripClient/ntripClient.cpp b/lib/NtripClient/ntripClient.cpp index e34f39a..936798d 100644 --- a/lib/NtripClient/ntripClient.cpp +++ b/lib/NtripClient/ntripClient.cpp @@ -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(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"), + static_cast("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(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"), + static_cast("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(positionUpdate), this->bufferSizePushGPGGA, - static_cast("Ntrip-GGA: %s\r\n"), + static_cast("Ntrip-GGA: %s"), data->nmea); strncat(static_cast(serverRequest), static_cast(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(userCredentials), userCredentialsLength, static_cast("%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(userCredentials), userCredentialsLength, static_cast("%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(encodedCredentials), sizeof(encodedCredentials)); + // Encode + const base64 base; + const String strEncodedCredentials = base64::encode(userCredentials); + delete userCredentials; + char encodedCredentials[strEncodedCredentials.length() + 1]; + strEncodedCredentials.toCharArray(static_cast(encodedCredentials), sizeof(encodedCredentials)); - snprintf(credentials, sizeof(credentials), static_cast("Authorization: Basic %s\r\n"), static_cast(encodedCredentials)); + snprintf(credentials, sizeof(credentials), static_cast("Authorization: Basic %s\r\n"), static_cast(encodedCredentials)); - // Add the encoded credentials to the server request - strncat(static_cast(serverRequest), static_cast(credentials), this->bufferSize); + // 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); @@ -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(positionUpdate), this->bufferSizePushGPGGA, - static_cast("%s\r\n"), + static_cast("%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; } diff --git a/lib/NtripClient/ntripClient.h b/lib/NtripClient/ntripClient.h index 86af643..0afc544 100644 --- a/lib/NtripClient/ntripClient.h +++ b/lib/NtripClient/ntripClient.h @@ -130,7 +130,7 @@ private: const uint16_t timeOut = 10000; const uint16_t bufferSize = 512; const uint16_t bufferSizePushGPGGA = 128; - const uint16_t pushGPGGATime = 10000; + const uint16_t pushGPGGATime = 5000; static constexpr uint8_t loopDelay = 20; }; diff --git a/lib/Sensors/sensorData.cpp b/lib/Sensors/sensorData.cpp index 689eb72..605938f 100644 --- a/lib/Sensors/sensorData.cpp +++ b/lib/Sensors/sensorData.cpp @@ -25,11 +25,12 @@ SensorData::~SensorData() delete this->ntripClient; } -void SensorData::enableNtrip(String host, uint16_t port, String mountPoint, String user, String password) +void SensorData::enableNtrip(String host, uint16_t port, String mountPoint, String user, String password, bool sendOwnPosition) { this->ntripClient = new NTRIPClient(this->gnss, host.c_str(), port, mountPoint.c_str(), user.c_str(), password.c_str()); this->ntripClient->gnssConfiguration(); this->ntripClient->loop(); + this->ntripClient->setTransmitLocation(sendOwnPosition); this->ntripClient->setActivated(false); this->isNtripInit = true; this->addChildComponent(this->ntripClient); @@ -264,7 +265,7 @@ void SensorData::initGnss() std::cout << "u-blox protocol version: " << static_cast(versionHigh) << "." << static_cast(versionLow) << std::endl; this->gnss->setSPIOutput(COM_TYPE_UBX); - this->gnss->enableNMEAMessage(UBX_NMEA_GGA, COM_PORT_SPI, 10); + this->gnss->enableNMEAMessage(UBX_NMEA_GGA, COM_PORT_SPI); this->gnss->setUSBOutput(COM_TYPE_UBX | COM_TYPE_NMEA); this->gnss->setAutoPVTcallbackPtr(&(SensorData::savePVTdata)); // SensorData::setOutputStatusPrintPVTdata(true); diff --git a/lib/Sensors/sensorData.h b/lib/Sensors/sensorData.h index a441dea..b964784 100644 --- a/lib/Sensors/sensorData.h +++ b/lib/Sensors/sensorData.h @@ -38,7 +38,7 @@ public: SensorData(); ~SensorData(); - void enableNtrip(String host, uint16_t port, String mountPoint, String user, String password); + void enableNtrip(String host, uint16_t port, String mountPoint, String user, String password, bool sendOwnPosition = false); /** * @brief Enable the gnss module over spi diff --git a/src/SpecialMenus/SensorData/menuSensorData.cpp b/src/SpecialMenus/SensorData/menuSensorData.cpp index c79d85b..fb25c70 100644 --- a/src/SpecialMenus/SensorData/menuSensorData.cpp +++ b/src/SpecialMenus/SensorData/menuSensorData.cpp @@ -150,3 +150,28 @@ void MenuSensorData::printPage() const this->print(lineOne, lineTwo); } + +void MenuSensorData::runCommand() +{ + switch (this->getCurrentPage()) + { + case 5: + { + NTRIPClient* client = this->sensorData->getNtripClient(); + NTRIPClientStates state = client->getClientState(); + if (state == NTRIPClientStates::pushingData) + { + client->deactivate(); + } + else if (state == NTRIPClientStates::waiting) + { + client->activate(); + } + } + break; + + default: + + break; + } +} diff --git a/src/SpecialMenus/SensorData/menuSensorData.h b/src/SpecialMenus/SensorData/menuSensorData.h index 83d820b..2ecf78e 100644 --- a/src/SpecialMenus/SensorData/menuSensorData.h +++ b/src/SpecialMenus/SensorData/menuSensorData.h @@ -30,6 +30,7 @@ public: private: void printPage() const override; + void runCommand() override; SensorData *sensorData; }; diff --git a/src/main.cpp b/src/main.cpp index 8769fe0..7700fac 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -129,7 +129,8 @@ void setup() NtripConfig::port, static_cast(NtripConfig::mountPoint), static_cast(NtripConfig::user), - static_cast(NtripConfig::password)); + static_cast(NtripConfig::password), + NtripConfig::sendOwnPosition); sensorData->enableGyroscope(); driveManager = new DriveManager(&moveController, sensorData, controlPad->getControlPadDataPtr());