Complete Rebuild, with Subsystems for each component. RTOS Tasks. (help by Claude)
This commit is contained in:
121
vesper/src/OTAManager/OTAManager.hpp
Normal file
121
vesper/src/OTAManager/OTAManager.hpp
Normal file
@@ -0,0 +1,121 @@
|
||||
/*
|
||||
* ═══════════════════════════════════════════════════════════════════════════════════
|
||||
* OTAMANAGER.HPP - Over-The-Air Update Management System
|
||||
* ═══════════════════════════════════════════════════════════════════════════════════
|
||||
*
|
||||
* 🔄 THE UPDATE ORCHESTRATOR OF VESPER 🔄
|
||||
*
|
||||
* This class manages over-the-air firmware updates with safe, reliable
|
||||
* update mechanisms, version checking, and comprehensive error handling.
|
||||
*
|
||||
* 📋 VERSION: 2.0 (Enhanced OTA management)
|
||||
* 📅 DATE: 2025
|
||||
* 👨💻 AUTHOR: Advanced Bell Systems
|
||||
* ═══════════════════════════════════════════════════════════════════════════════════
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <HTTPClient.h>
|
||||
#include <Update.h>
|
||||
#include <WiFi.h>
|
||||
#include <SD.h>
|
||||
#include <mbedtls/md.h>
|
||||
#include <ArduinoJson.h>
|
||||
#include <functional>
|
||||
#include "../FileManager/FileManager.hpp"
|
||||
|
||||
class ConfigManager; // Forward declaration
|
||||
|
||||
class OTAManager {
|
||||
public:
|
||||
enum class Status {
|
||||
IDLE,
|
||||
CHECKING_VERSION,
|
||||
DOWNLOADING,
|
||||
INSTALLING,
|
||||
SUCCESS,
|
||||
FAILED
|
||||
};
|
||||
|
||||
enum class ErrorCode {
|
||||
NONE,
|
||||
HTTP_ERROR,
|
||||
VERSION_CHECK_FAILED,
|
||||
DOWNLOAD_FAILED,
|
||||
INSUFFICIENT_SPACE,
|
||||
WRITE_FAILED,
|
||||
VERIFICATION_FAILED,
|
||||
CHECKSUM_MISMATCH,
|
||||
METADATA_PARSE_FAILED
|
||||
};
|
||||
|
||||
// Callback types
|
||||
using ProgressCallback = std::function<void(size_t current, size_t total)>;
|
||||
using StatusCallback = std::function<void(Status status, ErrorCode error)>;
|
||||
|
||||
explicit OTAManager(ConfigManager& configManager);
|
||||
|
||||
void begin();
|
||||
void setFileManager(FileManager* fm);
|
||||
void checkForUpdates();
|
||||
void checkForUpdates(const String& channel); // Check specific channel
|
||||
void update();
|
||||
void update(const String& channel); // Update from specific channel
|
||||
void checkFirmwareUpdateFromSD(); // Check SD for firmware update
|
||||
bool performManualUpdate(); // Manual update triggered by app
|
||||
bool performManualUpdate(const String& channel); // Manual update from specific channel
|
||||
|
||||
// Hardware identification
|
||||
String getHardwareVariant() const;
|
||||
void setHardwareVariant(const String& variant); // Deprecated: Use ConfigManager instead
|
||||
|
||||
// Status and info
|
||||
Status getStatus() const { return _status; }
|
||||
ErrorCode getLastError() const { return _lastError; }
|
||||
float getCurrentVersion() const;
|
||||
float getAvailableVersion() const { return _availableVersion; }
|
||||
bool isUpdateAvailable() const { return _updateAvailable; }
|
||||
|
||||
// Callbacks
|
||||
void setProgressCallback(ProgressCallback callback) { _progressCallback = callback; }
|
||||
void setStatusCallback(StatusCallback callback) { _statusCallback = callback; }
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════════════════
|
||||
// HEALTH CHECK METHOD
|
||||
// ═══════════════════════════════════════════════════════════════════════════════
|
||||
|
||||
/** @brief Check if OTAManager is in healthy state */
|
||||
bool isHealthy() const;
|
||||
|
||||
private:
|
||||
ConfigManager& _configManager;
|
||||
FileManager* _fileManager;
|
||||
Status _status;
|
||||
ErrorCode _lastError;
|
||||
float _availableVersion;
|
||||
bool _updateAvailable;
|
||||
String _availableChecksum;
|
||||
String _updateChannel;
|
||||
bool _isMandatory;
|
||||
bool _isEmergency;
|
||||
|
||||
ProgressCallback _progressCallback;
|
||||
StatusCallback _statusCallback;
|
||||
|
||||
void setStatus(Status status, ErrorCode error = ErrorCode::NONE);
|
||||
void notifyProgress(size_t current, size_t total);
|
||||
bool checkVersion();
|
||||
bool checkVersion(const String& channel);
|
||||
bool checkChannelsMetadata();
|
||||
bool downloadAndInstall();
|
||||
bool downloadAndInstall(const String& channel);
|
||||
bool downloadToSD(const String& url, const String& expectedChecksum);
|
||||
bool verifyChecksum(const String& filePath, const String& expectedChecksum);
|
||||
String calculateSHA256(const String& filePath);
|
||||
bool installFromSD(const String& filePath);
|
||||
String buildChannelUrl(const String& channel) const;
|
||||
String buildMetadataUrl(const String& channel) const;
|
||||
String buildFirmwareUrl(const String& channel) const;
|
||||
};
|
||||
Reference in New Issue
Block a user