#pragma once // system includes #include #include #include // esp-idf includes #include // local includes #include "taskutils.h" #include "wrappers/event_group.h" #include "espchrono.h" #include "cpptypesafeenum.h" #define OtaCloudUpdateStatusValues(x) \ x(Idle) \ x(Updating) \ x(Failed) \ x(Succeeded) \ x(NotReady) \ x(Verifying) DECLARE_TYPESAFE_ENUM(OtaCloudUpdateStatus, : uint8_t, OtaCloudUpdateStatusValues) class EspAsyncOta { public: EspAsyncOta(const char *taskName="asyncOtaTask", uint32_t stackSize=4096, espcpputils::CoreAffinity coreAffinity=espcpputils::CoreAffinity::Core1); ~EspAsyncOta(); std::expected startTask(); std::expected endTask(); int progress() const { return m_progress; } std::optional totalSize() const { return m_totalSize; } void setTotalSize(int totalSize) { m_totalSize = totalSize; } const std::string &message() const { return m_message; } const std::optional &appDesc() const { return m_appDesc; } OtaCloudUpdateStatus status() const; std::expected trigger(std::string_view url, std::string_view cert_pem, bool use_global_ca, std::string_view client_key, std::string_view client_cert); std::expected abort(); void update(); private: static void otaTask(void *arg); void otaTask(); const char * const m_taskName; const uint32_t m_stackSize; const espcpputils::CoreAffinity m_coreAffinity; int m_progress{}; std::optional m_totalSize; std::string m_message; std::optional m_appDesc; espcpputils::event_group m_eventGroup; TaskHandle_t m_taskHandle{}; std::optional m_finishedTs; std::optional m_lastInfo; std::string m_url; std::string_view m_cert_pem; bool m_use_global_ca; std::string_view m_client_key; std::string_view m_client_cert; };