/** * @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" /** * @brief States for the state machine. * */ enum NTRIPClientStates { openConnection, pushData, closeConnection, wait, 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: /** * @brief Construct a new NTRIPClient object * * @param gps 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(); /** * @brief Runs the state machine. * * See NTRIPClientStates for more information. * Should be called ever main loop. */ void loop(); /** * @brief Configure the Gnss module to accept correction data * */ void gpsConfiguration(); /** * @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); bool isConnected(); /** * @brief Get the Client State object * * Returns the state of the State machine * * @return NTRIPClientStates */ NTRIPClientStates getClientState() { return this->state; } private: void pushGPGGA(); bool beginClient(); void closeConnection(); bool processConnection(); void checkAutoReconnect(); SFE_UBLOX_GNSS* gps; WiFiClient* ntripClient; NTRIPClientStates state = NTRIPClientStates::notAvailable; bool transmitLocation = true; bool activated = true; bool autoReconnect = false; uint8_t reconnectAttemps = 0; uint16_t port; uint32_t lastReceivedRtcmTime = 0; // uint32_t lastNtripConnectTime = 0; // can deleted? uint32_t lastGPGGAPushTime = 0; uint32_t lastLoopTime = 0; uint32_t lastReconnectTime = 0; char host[128]; char mountPoint[128]; char user[128]; char password[128]; const uint8_t delayTime = 20; const uint8_t maxReconnectAttemps = 10; const uint16_t reconnectDelayTime = 1000; const uint16_t timeOut = 5000; const uint16_t bufferSize = 512; const uint16_t pushGPGGATime = 10000; }; #endif