// 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 WII5Sh3dConfig.h * @brief WII5 adapter for the Sh3d shared configuration layer. */ #ifndef WII5Sh3dConfig_h #define WII5Sh3dConfig_h #include //assumes Arduino IDE v1.0 or greater #include //assumes Arduino IDE v1.0 or greater #include #include /* Features: * Automatic configuration depending on hardware: * Size of EEPROM * TODO * Automatic Versioning * Automatic counters * EEPROM protection - by alternative locations * Ability to extend * Passing in one or more STRUCTS for the unused areas * Helpers, like counters */ // ============================================================================== // Address and Sizes // ============================================================================== // TODO Should be variable, this needs lots of work #define totalLen 512 #define totalStart 0 #define configStart 0 #define configLen 128 #define extraStart 128 #define extraLen 384 // ============================================================================== // Signature (experimenting) // ============================================================================== // TODO HARD CODED FOR NOW #define CONFIG_TYPE 114 #define CONFIG_VERSION 12 // ============================================================================== // Main Struct // ============================================================================== typedef struct { // Internal - config data - might need more? SH3D_TYPE_PACKET_TYPE configType; // Config Type SH3D_TYPE_PACKET_VERSION configVersion; // Config Versio // Device ID SH3D_TYPE_UNIQUEID nodeId; // Counters - To be moved around SH3D_TYPE_COUNTER runCount; // Run ID - New ID each time device is booted SH3D_TYPE_COUNTER recordCount; // Records, likes sesnsor data // Some common and Basic configurables about this device // TODO how often - eg. do we want to do it every minute, every hour, daily, etc // Hard coded for Storage System - needs work SH3D_TYPE_COUNTER storageLogLast; SH3D_TYPE_COUNTER storageSensorLast; } typeConfig; class WII5Sh3dConfig { public: void begin( ); bool initialized = false; // Do reads void readConfig(); void updateConfig(); SH3D_TYPE_UNIQUEID getNodeId(); SH3D_TYPE_UNIQUEID setNodeId(SH3D_TYPE_UNIQUEID newId); SH3D_TYPE_COUNTER getRunCount(); SH3D_TYPE_COUNTER updateRunCount(); SH3D_TYPE_COUNTER clearRunCount(SH3D_TYPE_COUNTER setId = 0); // Record ID for Sensors SH3D_TYPE_COUNTER getRecordCount(); SH3D_TYPE_COUNTER updateRecordCount(); SH3D_TYPE_COUNTER clearRecordCount(SH3D_TYPE_COUNTER setId = 0); // Storage SH3D_TYPE_COUNTER getStorageLogLast(); SH3D_TYPE_COUNTER updateStorageLogLast(); SH3D_TYPE_COUNTER clearStorageLogLast(SH3D_TYPE_COUNTER setId = 0); SH3D_TYPE_COUNTER getStorageSensorLast(); SH3D_TYPE_COUNTER updateStorageSensorLast(); SH3D_TYPE_COUNTER clearStorageSensorLast(SH3D_TYPE_COUNTER setId = 0); // Not sure I like these names, `` uint16_t sizeExtra(); uint16_t startExtra(); void readExtra(char *data, uint16_t len, uint16_t offset); void updateExtra(char *data, uint16_t len, uint16_t offset); // Storage Location etc - as we can't errase a whole device bool getFlashErased(); bool setFlashErased(bool in); protected: typeConfig dataConfig; // Main Config Data }; extern WII5Sh3dConfig sh3dNodeConfig; #endif