Initial public release of WII5 Buoy firmware
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.
This commit is contained in:
+114
@@ -0,0 +1,114 @@
|
||||
// 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 WII5Commands.h
|
||||
* @brief Command protocol handler: parses and dispatches @-prefixed commands.
|
||||
*/
|
||||
|
||||
#ifndef WII5Commands_h
|
||||
#define WII5Commands_h
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <WII5.h>
|
||||
|
||||
/**
|
||||
* @brief Text-protocol command parser and dispatcher.
|
||||
*
|
||||
* Accepts commands from multiple inputs (local console, Iridium SBD,
|
||||
* radio, buttons) in two syntaxes:
|
||||
* - "@AREA,cmd,arg1,arg2,..." (the AT-style protocol)
|
||||
* - "X;" single-letter "standard" style (used in manual test mode)
|
||||
*
|
||||
* Records the most recent command in lastCommand* members so result and
|
||||
* acknowledge replies can refer back to it.
|
||||
*/
|
||||
class WII5Commands : public WII5 {
|
||||
public:
|
||||
virtual WII5_CONTROLLERS controllerId() {return WII5CONTROLLER_COMMANDS;}
|
||||
/** @brief One-time bring-up. */
|
||||
void begin();
|
||||
|
||||
/** @brief Feed an AT-style command into the command pipeline as if it came from the console. */
|
||||
bool injectCommand(char *sendCmd);
|
||||
|
||||
/** @brief Drain pending "X;" single-letter commands from the console. */
|
||||
bool processConsoleStandard();
|
||||
|
||||
/** @brief Drain pending "@AREA,cmd,..." AT-style commands from the console. */
|
||||
bool processConsoleAT();
|
||||
|
||||
/** @brief Translate physical button events (click/long-hold) into commands. */
|
||||
bool processButtons();
|
||||
|
||||
/** @brief Drain pending packets from the LoRa network (if enabled). */
|
||||
bool processNetwork();
|
||||
|
||||
/** @brief Process any incoming BinData payload (typically from Iridium). */
|
||||
bool processBinData();
|
||||
|
||||
/** @brief Execute a parsed command; returns true on success. */
|
||||
bool runCommand(WII5_COMMANDS cmd, char** params = NULL, uint8_t paramsLen = 0);
|
||||
/** @brief Record the source/area of the command currently being processed. */
|
||||
void setupLast(WII5_DEVICES device, WII5_PORTS port, WII5_AREAS area, WII5_COMMANDS cmd = WII5COMMAND_NONE);
|
||||
/** @brief Finalize lastCommand bookkeeping (call after runCommand). */
|
||||
void doneLast();
|
||||
/** @brief Set the result + message for the last command (mutable buffer). */
|
||||
void resultLast(WII5_RESULTS result, char *message);
|
||||
/** @brief Set the result + message for the last command (PROGMEM string). */
|
||||
void resultLast(WII5_RESULTS result, const __FlashStringHelper *area);
|
||||
/** @brief Set the result for the last command without altering the message. */
|
||||
void resultLast(WII5_RESULTS result);
|
||||
|
||||
/** @brief Print a debug dump of command state to the console. */
|
||||
void dump();
|
||||
|
||||
elapsedMillis disableButtons;
|
||||
|
||||
// ------------------------------------------------------------------------------
|
||||
// lastCommand!
|
||||
|
||||
// When?
|
||||
elapsedMillis lastCommandAge;
|
||||
time_t lastCommandT;
|
||||
|
||||
// Who sent this?
|
||||
WII5_PORTS lastCommandPort;
|
||||
WII5_DEVICES lastCommandDevice;
|
||||
|
||||
// Which area and commands was parsed (e.g. area=WII5)
|
||||
WII5_AREAS lastCommandArea;
|
||||
|
||||
// Main command - e.g. SETTINGS_DEVICEID
|
||||
WII5_COMMANDS lastCommandCmd;
|
||||
uint32_t lastCommandParam1; // Keep just the params in int format - should be enough
|
||||
uint32_t lastCommandParam2; // Keep just the params in int format - should be enough
|
||||
uint32_t lastCommandParam3; // Keep just the params in int format - should be enough
|
||||
|
||||
// Result of command - success = yes/no
|
||||
WII5_RESULTS lastCommandResult;
|
||||
char lastCommandMessage[WII5_RESULT_MESSAGE]; // Error string
|
||||
|
||||
// Acknowldge reply
|
||||
bool lastCommandAckComplete;
|
||||
|
||||
protected:
|
||||
elapsedMillis delayWait;
|
||||
time_t when;
|
||||
|
||||
// ------------------------------------------------------------------------------
|
||||
// Button managmement
|
||||
elapsedMillis buttonHeld;
|
||||
elapsedMillis buttonReleaseWait;
|
||||
bool buttonActive;
|
||||
bool buttonReleased;
|
||||
uint8_t buttonMode;
|
||||
|
||||
// ------------------------------------------------------------------------------
|
||||
};
|
||||
|
||||
extern WII5Commands wii5Commands;
|
||||
#endif
|
||||
Reference in New Issue
Block a user