// SPDX-License-Identifier: Apache-2.0 // Copyright (c) 2012-2024 Scott Penrose and WII5 Buoy contributors // // This file is part of WII5 Buoy firmware. // See LICENSE for full terms. /** * @file WII5GPS.h * @brief GPS driver: NMEA parsing via TinyGPS++, time/position updates. */ #ifndef WII5GPS_h #define WII5GPS_h /* So one second after the module is powered on normally, you can have the actual RTC time in the $GPRMC NMEA sentence, even if the fixing tells 'V' like 'void' (invalid). But the time is valid RTC time, if your battery backup did not run out of power since you powered the system off. */ #include #include #define DEFAULT_MINUTES 5 #define UPDATE_TIME 60000 // TODO 2024 1 minute /** * @brief GPS driver: u-blox NMEA via TinyGPS++. * * Manages power-on, fix acquisition, and clock-update flows. NMEA sentences * are parsed off the WII5SerialManager base; the result feeds the global * `wii5Gps.gps` (TinyGPSPlus) instance for location/altitude/HDOP queries. */ class WII5GPS : public WII5Power, public WII5SerialManager { public: WII5GPS() {} virtual WII5_CONTROLLERS controllerId() {return WII5CONTROLLER_DRIVER;} virtual WII5_DRIVERS driverId() {return WII5DRIVER_GPS;} /** @brief One-time bring-up; pin config comes from the active board file. */ void begin(); /** @brief State-machine tick: drains NMEA, advances mode. */ void loop(); /** @brief Set how long the GPS stays on each acquisition window. */ void setMinutes(uint8_t newMinutes); /** @brief Current acquisition window length, in minutes. */ uint8_t getMinutes(); /** @brief Print a status dump; `toOther` optionally mirrors to a second Print. */ void dump(bool toConsole = true, Print* toOther = NULL); /** @brief Power off the GPS module. */ void off(); /** @brief Power on the GPS module. */ void on(); /** @brief One-shot acquisition tuned for time only. */ void autoTime(); /** @brief One-shot acquisition tuned for position. */ void autoPos(); /** @brief Long acquisition for high-quality fix. */ void autoAccurate(); /** @brief Periodic re-acquisition (continuous mode). */ void autoRepeat(); /** @brief True once a valid fix is available. */ bool ready(); /** @brief True if the most recent acquisition failed. */ bool isError(); /** @brief True if the time fix is valid (independent of position). */ bool isTimeValid(); /** @brief True if a state-machine cycle is in flight. */ bool isRunning(); uint32_t lastRunTime; time_t when; /** @brief True if the last fix is older than the configured timeout. */ bool old(); elapsedMillis sinceOnLast; // Simple - check how long since it has last been on protected: virtual void start(bool force = false); void stop(bool force = false); WII5_ERRORS lastError; bool finished; // The reqeust - e.g. wait for position bool running; WII5GPS_MODES step; WII5GPS_MODES stepLast; bool first; elapsedMillis stepWait; uint8_t minutes; elapsedMillis waitTime; elapsedMillis runTime; elapsedMillis lastTime; // Last time it was valid }; extern WII5GPS wii5Gps; #endif