#ifndef OTA_MANAGER_H #define OTA_MANAGER_H #include #include #include "config_manager.h" #include "transport_manager.h" #include "gsm_manager.h" enum class OtaStatus : uint8_t { IDLE, CHECKING, DOWNLOADING, INSTALLING, SUCCESS, FAILED }; struct FirmwareInfo { String version; String url; uint32_t size; String checksum; String releaseNotes; bool mandatory; }; class OtaManager { public: void begin(ConfigManager& config, TransportManager& transport, GsmManager& gsm); void loop(); bool checkForUpdate(); bool startUpdate(const String& url, const String& checksum = ""); void requestUpdate(const String& url, const String& checksum = ""); OtaStatus getStatus() { return _status; } uint8_t getProgress() { return _progress; } String getStatusMessage() { return _statusMessage; } bool isUpdateAvailable() { return _updateAvailable; } const FirmwareInfo& getAvailableUpdate() { return _available; } bool needsValidation(); bool markValid(); bool rollback(); String getRunningPartition(); void onProgress(std::function cb) { _progressCallback = cb; } void onComplete(std::function cb) { _completeCallback = cb; } private: ConfigManager* _config; TransportManager* _transport; GsmManager* _gsm; OtaStatus _status; uint8_t _progress; String _statusMessage; bool _updateAvailable; FirmwareInfo _available; bool _updateRequested; String _pendingUrl; String _pendingChecksum; unsigned long _lastCheckMs; unsigned long _bootTimeMs; bool _firstCheckDone; std::function _progressCallback; std::function _completeCallback; bool performUpdate(const String& url); bool compareVersions(const String& current, const String& available); bool parseUrl(const String& url, String& host, uint16_t& port, String& path); }; #endif