// 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 WII5.h * @brief Top-level base class and global buffer declarations. */ #ifndef WII5_h #define WII5_h #include #include // Load the Board file - see board for type #include #include #include #include #include #define WII5_TIMERLAPS 5 // Try bitRead #define BitVal(data,y) ( (data>>y) & 1) /** Return Data.Y value **/ #define SetBit(data,y) data |= (1 << y) /** Set Data.Y to 1 **/ #define ClearBit(data,y) data &= ~(1 << y) /** Clear Data.Y to 0 **/ #ifdef WII5_BUFFER_STRING extern char wii5BufferString[WII5_BUFFER_STRING]; #endif #ifdef WII5_BUFFER_CONSOLE_BINARY extern char wii5BufferConsoleBinary[WII5_BUFFER_CONSOLE_BINARY]; #endif #ifdef WII5_BUFFER_CONSOLE_PRINT extern char wii5BufferConsolePrint[WII5_BUFFER_CONSOLE_PRINT]; #endif #ifdef WII5_BUFFER_CONSOLE_CMD extern char wii5BufferConsoleCmd[WII5_BUFFER_CONSOLE_CMD]; #endif #ifdef WII5_RADIO_LORA extern char wii5BufferRadio[WII5_BUFFER_RADIO]; #endif // Serial modules - (should have defines) #ifdef WII5_COMMS_IRIDIUM #define WII5_IRIDIUM_BIN_MAX 340 extern char wii5BufferIridium[WII5_BUFFER_IRIDIUM]; // Used for Serial In / Out extern char wii5BinaryIridium[WII5_IRIDIUM_BIN_MAX]; // Used to send and receive data to the modem #endif #ifdef WII5_BUFFER_SPARTON extern char wii5BufferSparton[WII5_BUFFER_SPARTON]; #endif #ifdef WII5_BUFFER_GPS extern char wii5BufferGPS[WII5_BUFFER_GPS]; #endif /** @brief Debug breadcrumb: print "DEBUG POINT: " to SerialConsole. */ void debugDo(uint32_t n); /** * @brief Common base class for WII5 drivers and controllers. * * Provides controllerId/driverId virtuals so subclasses identify themselves * to logging and status helpers. Concrete subclasses include WII5Power * (power-managed peripherals), WII5Mode (run-time modes), and the various * sensor / radio drivers. */ class WII5 { public: WII5() { // lastStatus = WII5STATUS_UNKNOWN; // lastErrorCount = 0; // lastErrorRepeat = 0; // lastErrorStatus = WII5STATUS_UNKNOWN; // lastError = WII5ERROR_UNKNOWN; // lastErrorString[0] = '\0'; } /** @brief Identify the controller category for logging/status. */ virtual WII5_CONTROLLERS controllerId(); /** @brief Identify the driver category for logging/status. */ virtual WII5_DRIVERS driverId(); // void setStatus(WII5_STATUS s); // void setErrorUnknown(); // void setErrorNone(); // void setError(WII5_ERRORS id, char *str); // void setError(WII5_ERRORS id, const __FlashStringHelper *str); // bool isError(); // Helpers to show values // bool getStatusOff(); // bool getStatusOn(); // bool getStatusValid(); // virtual void displayStatus(); // virtual void displayError(bool hideNone = false); // virtual void displayStatusFull(bool suprressNewLine = false); // virtual void metadataPrint(File* fh); /** @brief Sanity check: is the given timestamp in a plausible epoch range? */ virtual bool SJ(DdW when); /* virtual void displaySTATS(); void statsHighClear(); void statsHighPointStart(); void statsHighPointStop(); void statsHighDisplay(); */ protected: // STATUS - Last Status // elapsedMillis lastStatusAge; // time_t lastStatusT; // WII5_STATUS lastStatus; // at time of error // ERROR - Last Error // elapsedMillis lastErrorAge; // uint32_t lastErrorCount; // Count all errors... also consider repeats // uint32_t lastErrorRepeat; // Count of repeats // time_t lastErrorT; // WII5_STATUS lastErrorStatus; // at time of error // WII5_ERRORS lastError; // Error ID // char lastErrorString[WII5_ERROR_STRING_MAX]; // Error string /* // Stats - mostly automatic, but lap timers need manual input, see also displaySTATS void statsTimerStart(); uint8_t statsTimerLap(); void statsTimerStop(); elapsedMillis statsTimer; uint32_t statsFinal; uint32_t statsLap[WII5_TIMERLAPS]; uint8_t statsLap_count; // High Speed stats loops used for some operations uint32_t statsHigh_count; uint32_t statsHigh_total; elapsedMicros statsHigh_timer; */ }; #ifdef WII5_RADIO_LORA // extern RH_RF95 wii5RadioRF95; #endif // Mostly dependency stuff ! #include #include #include #include #include #include #include #include #include #include #include #include #ifdef WII5_RADIO_LORA #include #endif #ifdef WII5_GPS #include #endif #ifdef WII5_COMMS_IRIDIUM #include #endif #include #ifdef WII5_IMU_SPARTON #include #endif #ifdef WII5_STORAGE_SDBLOCK #include #endif #ifdef WII5_RTC #include #endif #include #include #include #include #include #include #include #include #include // Sh3d shared code #include #include #include #include // Data #include // Usefu libs #include // RTC #ifdef WII5_RTC #include #include "RTClib.h" #endif #endif