/** * @file ntripClient.h * @author Alexander Klein (alex@kleiax.de) * @brief Contains the class NTRIPClient * @version 0.1 * @date 2023-02-13 * * @copyright Copyright (c) 2023 * */ #ifndef NTRIP_CLIENT #define NTRIP_CLIENT #include #include #include #include #include #include "debugTimes.h" #include "component.h" /** * @brief States for the state machine. * */ enum NTRIPClientStates { openingConnection, pushingData, closingConnection, waiting, notAvailable }; /** * @brief Ntrip Client * * This class can connect to a ntrip server to pull correction * data and push it to a given gnss module. This module have to be compatible * with the SparkFun u-blox GNSS Arduino Library. */ class NTRIPClient : public Component { public: /** * @brief Construct a new NTRIPClient object * * @param gnss The Gnss module * @param host * @param port * @param mountPoint * @param user * @param 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 gnssConfiguration(); /** * @brief Activate or deactivate the location transmission * * Some server need the position of the Gnss module to send the * right correction data. * * @param b */ void setTransmitLocation(bool b) { this->transmitLocation = b; } /** * @brief Activate or deactivate the connection to the server. * * @param state * @return true success * @return false failure */ bool setActivated(bool state); void setAutoReconnect(bool state); void useOutdatedNtripRev1 (bool rev1 = false ) { this->useNtripRev1 = rev1; } bool isConnected(); /** * @brief Get the Client State object * * Returns the state of the State machine * * @return NTRIPClientStates */ NTRIPClientStates getClientState() { return this->state; } private: void run() override; void runAsChild() override; void pushGPGGA(); bool beginClient(); void closeConnection(); bool processConnection(); void checkAutoReconnect(); 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; uint32_t lastReceivedRtcmTime = 0; // uint32_t lastNtripConnectTime = 0; // can deleted? uint32_t lastGPGGAPushTime = 0; uint32_t lastReconnectTime = 0; static const uint8_t connectionDataLength = 32; char host[connectionDataLength]; char mountPoint[connectionDataLength]; char user[connectionDataLength]; char password[connectionDataLength]; const uint8_t maxReconnectAttemps = 10; const uint16_t reconnectDelayTime = 5000; const uint16_t timeOut = 10000; const uint16_t bufferSize = 512; const uint16_t bufferSizePushGPGGA = 128; const uint16_t pushGPGGATime = 5000; static constexpr uint8_t loopDelay = 20; }; #endif