Files
espasyncota/src/espasyncota.h
T

72 lines
2.1 KiB
C++
Raw Normal View History

2021-08-05 11:57:44 +02:00
#pragma once
// system includes
#include <optional>
#include <string>
2023-02-27 17:27:00 +01:00
#include <expected>
2021-08-05 11:57:44 +02:00
// esp-idf includes
2022-09-17 22:14:27 +02:00
#include <esp_app_desc.h>
2021-08-05 11:57:44 +02:00
// local includes
#include "taskutils.h"
#include "wrappers/event_group.h"
#include "espchrono.h"
#include "cpptypesafeenum.h"
2021-08-05 11:57:44 +02:00
#define OtaCloudUpdateStatusValues(x) \
x(Idle) \
x(Updating) \
x(Failed) \
x(Succeeded) \
2022-04-20 14:53:47 +02:00
x(NotReady) \
x(Verifying)
DECLARE_TYPESAFE_ENUM(OtaCloudUpdateStatus, : uint8_t, OtaCloudUpdateStatusValues)
2021-08-05 11:57:44 +02:00
class EspAsyncOta
{
public:
EspAsyncOta(const char *taskName="asyncOtaTask", uint32_t stackSize=4096, espcpputils::CoreAffinity coreAffinity=espcpputils::CoreAffinity::Core1);
2021-08-05 11:57:44 +02:00
~EspAsyncOta();
2023-02-27 17:27:00 +01:00
std::expected<void, std::string> startTask();
std::expected<void, std::string> endTask();
2021-08-05 11:57:44 +02:00
int progress() const { return m_progress; }
std::optional<int> totalSize() const { return m_totalSize; }
void setTotalSize(int totalSize) { m_totalSize = totalSize; }
const std::string &message() const { return m_message; }
const std::optional<esp_app_desc_t> &appDesc() const { return m_appDesc; }
OtaCloudUpdateStatus status() const;
2023-08-04 16:26:22 +02:00
std::expected<void, std::string> trigger(std::string_view url, std::string_view cert_pem, bool use_global_ca,
std::string_view client_key, std::string_view client_cert);
2023-02-27 17:27:00 +01:00
std::expected<void, std::string> abort();
2021-08-05 11:57:44 +02:00
void update();
private:
static void otaTask(void *arg);
void otaTask();
const char * const m_taskName;
2021-08-06 15:27:14 +02:00
const uint32_t m_stackSize;
2021-08-05 11:57:44 +02:00
const espcpputils::CoreAffinity m_coreAffinity;
int m_progress{};
std::optional<int> m_totalSize;
std::string m_message;
std::optional<esp_app_desc_t> m_appDesc;
espcpputils::event_group m_eventGroup;
TaskHandle_t m_taskHandle{};
std::optional<espchrono::millis_clock::time_point> m_finishedTs;
std::optional<espchrono::millis_clock::time_point> m_lastInfo;
std::string m_url;
std::string_view m_cert_pem;
2023-08-04 16:26:22 +02:00
bool m_use_global_ca;
2021-08-05 11:57:44 +02:00
std::string_view m_client_key;
std::string_view m_client_cert;
};