295abb37ee
Firmware for an autonomous wave-measurement buoy (ATmega2560-based WII5 v2 board). Reads wave motion from a Sparton AHRS-M1/M2 IMU, samples GPS and battery state, and reports back over Iridium SBD satellite telemetry. Originally developed 2012-2024. This is the first public release. Code, documentation, and field-tested operating modes (Capture, Sleep, Position, ManualTest, SelfTest, LowBattery) are licensed under Apache 2.0 — see LICENSE and NOTICE. See README.md for an overview and build instructions, CONTRIBUTING.md for how to contribute, and DEPLOYMENTS.md for the field-deployment log.
222 lines
5.5 KiB
C++
222 lines
5.5 KiB
C++
// SPDX-License-Identifier: Apache-2.0
|
|
// Copyright (c) 2012-2024 Scott Penrose <scottp@dd.com.au> 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 <elapsedMillis.h>
|
|
#include <TimeLib.h>
|
|
|
|
// Load the Board file - see board for type
|
|
#include <WII5_board.h>
|
|
#include <WII5DataShared.h>
|
|
#include <WII5Data.h>
|
|
#include <WII5Strings.h>
|
|
#include <WII5Config.h>
|
|
|
|
#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: <n> <count>" 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 <WII5Mode.h>
|
|
#include <WII5Power.h>
|
|
#include <WII5SerialManager.h>
|
|
|
|
#include <WII5ModeSleep.h>
|
|
#include <WII5ModeCapture.h>
|
|
#include <WII5ModeLowBattery.h>
|
|
#include <WII5ModeManualTest.h>
|
|
#include <WII5ModePosition.h>
|
|
#include <WII5ModeSelfTest.h>
|
|
#include <WII5Commands.h>
|
|
#include <WII5Controller.h>
|
|
#include <WII5Data.h>
|
|
#ifdef WII5_RADIO_LORA
|
|
#include <WII5RadioLoRa.h>
|
|
#endif
|
|
#ifdef WII5_GPS
|
|
#include <WII5GPS.h>
|
|
#endif
|
|
#ifdef WII5_COMMS_IRIDIUM
|
|
#include <WII5Iridium.h>
|
|
#endif
|
|
#include <WII5Maths.h>
|
|
#ifdef WII5_IMU_SPARTON
|
|
#include <WII5Sparton.h>
|
|
#endif
|
|
|
|
#ifdef WII5_STORAGE_SDBLOCK
|
|
#include <SDBlock.h>
|
|
#endif
|
|
|
|
#ifdef WII5_RTC
|
|
#include <WII5RTC.h>
|
|
#endif
|
|
#include <WII5Communications.h>
|
|
#include <WII5Battery.h>
|
|
#include <WII5Weather_18B20.h>
|
|
#include <WII5Help.h>
|
|
#include <WII5Display.h>
|
|
#include <WII5SerialDebug.h>
|
|
#include <WII5SerialStatus.h>
|
|
#include <WII5SerialMaths.h>
|
|
#include <WII5Setup.h>
|
|
|
|
// Sh3d shared code
|
|
#include <WII5Sh3dConfig.h>
|
|
#include <WII5Sh3dConsole.h>
|
|
#include <WII5Sh3dIO.h>
|
|
#include <WII5Sh3dUtil.h>
|
|
|
|
// Data
|
|
#include <WII5BinData.h>
|
|
|
|
// Usefu libs
|
|
#include <TimeLib.h>
|
|
|
|
// RTC
|
|
#ifdef WII5_RTC
|
|
#include <Wire.h>
|
|
#include "RTClib.h"
|
|
#endif
|
|
|
|
#endif
|