From d431fa72bb4115647c8809797b856148493b5960 Mon Sep 17 00:00:00 2001 From: Alexander Klein Date: Wed, 14 Dec 2022 08:45:46 +0100 Subject: [PATCH] ntrip client safe without wlan --- lib/Navigation/navigation.cpp | 4 +++- lib/NtripClient/ntripClient.cpp | 28 +++++++++++++++++++++++----- lib/NtripClient/ntripClient.h | 10 ++++++---- src/SpecialMenus/GPS/menuGPS.cpp | 14 +++++++------- src/main.cpp | 8 +++++++- 5 files changed, 46 insertions(+), 18 deletions(-) diff --git a/lib/Navigation/navigation.cpp b/lib/Navigation/navigation.cpp index 9e74702..3193d69 100644 --- a/lib/Navigation/navigation.cpp +++ b/lib/Navigation/navigation.cpp @@ -52,6 +52,8 @@ void Navigation::init(Route* route) { this->route = route; else this->route = new Route(); + + this->ntripClient = new NTRIPClient(); } Navigation::~Navigation() { @@ -65,7 +67,7 @@ Navigation::~Navigation() { } void Navigation::initNtrip(String host, uint16_t port, String mountPoint, String user, String password) { - this->ntripClient = new NTRIPClient(this->gps, host.c_str(), port, mountPoint.c_str(), user.c_str(), password.c_str()); + this->ntripClient->init(this->gps, host.c_str(), port, mountPoint.c_str(), user.c_str(), password.c_str()); this->ntripClient->gpsConfiguration(); this->ntripClient->loop(); this->ntripClient->setActivated(false); diff --git a/lib/NtripClient/ntripClient.cpp b/lib/NtripClient/ntripClient.cpp index aff8bc6..c4e320c 100644 --- a/lib/NtripClient/ntripClient.cpp +++ b/lib/NtripClient/ntripClient.cpp @@ -11,7 +11,15 @@ #include "ntripClient.h" -NTRIPClient::NTRIPClient(SFE_UBLOX_GNSS* gps, const char* host, uint16_t port, const char* mountPoint, const char* user, const char* password) { +NTRIPClient::NTRIPClient() { + +} + +NTRIPClient::~NTRIPClient() { + delete this->ntripClient; +} + +void NTRIPClient::init(SFE_UBLOX_GNSS* gps, const char* host, uint16_t port, const char* mountPoint, const char* user, const char* password) { this->gps = gps; strcpy(this->host, host); this->port = port; @@ -20,10 +28,7 @@ NTRIPClient::NTRIPClient(SFE_UBLOX_GNSS* gps, const char* host, uint16_t port, c strcpy(this->password, password); this->ntripClient = new WiFiClient; -} - -NTRIPClient::~NTRIPClient() { - delete this->ntripClient; + this->state = NTRIPClientStates::closeConnection; } void NTRIPClient::loop() { @@ -84,6 +89,9 @@ void NTRIPClient::loop() { } break; + case NTRIPClientStates::notAvailable: + break; + default: std::cout << "Wrong state in NTRIPClient.cpp..." << std::endl; this->state = NTRIPClientStates::closeConnection; @@ -100,6 +108,16 @@ void NTRIPClient::gpsConfiguration() { this->gps->enableNMEAMessage(UBX_NMEA_GGA, COM_PORT_SPI, 10); } +bool NTRIPClient::setActivated(bool b) { + if (b && this->state != NTRIPClientStates::notAvailable) + this->activated = true; + else if (b) + return false; + this->activated = false; + return true; + +} + bool NTRIPClient::beginClient() { std::cout << "Opening socket to " << this->host << std::endl; diff --git a/lib/NtripClient/ntripClient.h b/lib/NtripClient/ntripClient.h index eb414c9..3a3c283 100644 --- a/lib/NtripClient/ntripClient.h +++ b/lib/NtripClient/ntripClient.h @@ -13,19 +13,21 @@ enum NTRIPClientStates { openConnection, pushData, closeConnection, - wait + wait, + notAvailable }; class NTRIPClient { public: - NTRIPClient(SFE_UBLOX_GNSS* gps, const char* host, uint16_t port, const char* mountPoint, const char* user, const char* password); + NTRIPClient(); ~NTRIPClient(); + void init(SFE_UBLOX_GNSS* gps, const char* host, uint16_t port, const char* mountPoint, const char* user, const char* password); void loop(); void gpsConfiguration(); void setTransmitLocation(bool b) { this->transmitLocation = b; } - void setActivated(bool b) { this->activated = b; } + bool setActivated(bool b); bool isConnected(); NTRIPClientStates getClientState() { return this->state; } @@ -40,7 +42,7 @@ class NTRIPClient { SFE_UBLOX_GNSS* gps; WiFiClient* ntripClient; - NTRIPClientStates state = NTRIPClientStates::closeConnection; + NTRIPClientStates state = NTRIPClientStates::notAvailable; bool transmitLocation = true; bool activated = true; diff --git a/src/SpecialMenus/GPS/menuGPS.cpp b/src/SpecialMenus/GPS/menuGPS.cpp index 329d294..ca728e0 100644 --- a/src/SpecialMenus/GPS/menuGPS.cpp +++ b/src/SpecialMenus/GPS/menuGPS.cpp @@ -130,24 +130,24 @@ void MenuGPS::printPage() const { break; case 3: { - bool status; - if (this->ntripClient->getClientState() == NTRIPClientStates::pushData) - status = true; - else - status = false; + NTRIPClientStates status = this->ntripClient->getClientState(); if (this->lcd) { lcd->clear(); lcd->setCursor(0, 0); lcd->print("NTRIP Client"); lcd->setCursor(0, 1); - if (status) + if (status == NTRIPClientStates::pushData) lcd->print("enabled"); + else if (status == NTRIPClientStates::notAvailable) + lcd->print("not available"); else lcd->print("disabled"); } - if (status) + if (status == NTRIPClientStates::pushData) std::cout << "NTRIP Client is enabled." << std::endl; + else if (status == NTRIPClientStates::notAvailable) + std::cout << "NTRIP Client is not available." << std::endl; else std::cout << "NTRIP Client is disabled" << std::endl; } diff --git a/src/main.cpp b/src/main.cpp index de83454..f43b911 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -206,9 +206,10 @@ void callbackControllerConnect() { // because after the setup the other core control the display. if (firstConnect) { lcd->init(); - main_m->printMenu(); firstConnect = false; } + + main_m->printMenu(); } void callbackControllerDisconnect() { @@ -261,6 +262,11 @@ void makeMenu() { auto disconnectController = [&]() { disconnectPs3 = true; + lcd->clear(); + lcd->setCursor(0, 0); + lcd->print("Controller is"); + lcd->setCursor(0, 1); + lcd->print("disconnected."); }; // Create Menu