diff --git a/CMakeLists.txt b/CMakeLists.txt index c490f6c..62593ba 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,7 +10,6 @@ set(dependencies esp_https_ota esp_partition - expected fmt cpputils diff --git a/src/espasyncota.cpp b/src/espasyncota.cpp index 342b213..eb6d12f 100644 --- a/src/espasyncota.cpp +++ b/src/espasyncota.cpp @@ -51,20 +51,20 @@ EspAsyncOta::~EspAsyncOta() endTask(); } -tl::expected EspAsyncOta::startTask() +std::expected EspAsyncOta::startTask() { if (m_taskHandle) { constexpr auto msg = "ota task handle is not null"; ESP_LOGW(TAG, "%s", msg); - return tl::make_unexpected(msg); + return std::unexpected(msg); } if (const auto bits = m_eventGroup.getBits(); bits & TASK_RUNNING_BIT) { constexpr auto msg = "ota task already running"; ESP_LOGW(TAG, "%s", msg); - return tl::make_unexpected(msg); + return std::unexpected(msg); } m_eventGroup.clearBits(TASK_RUNNING_BIT | START_REQUEST_BIT | REQUEST_RUNNING_BIT | REQUEST_VERIFYING_BIT | REQUEST_FINISHED_BIT | REQUEST_SUCCEEDED_BIT | END_TASK_BIT | TASK_ENDED_BIT | ABORT_REQUEST_BIT); @@ -74,14 +74,14 @@ tl::expected EspAsyncOta::startTask() { auto msg = fmt::format("failed creating ota task {}", result); ESP_LOGE(TAG, "%.*s", msg.size(), msg.data()); - return tl::make_unexpected(std::move(msg)); + return std::unexpected(std::move(msg)); } if (!m_taskHandle) { constexpr auto msg = "ota task handle is null"; ESP_LOGW(TAG, "%s", msg); - return tl::make_unexpected(msg); + return std::unexpected(msg); } ESP_LOGD(TAG, "created ota task %s", m_taskName); @@ -100,7 +100,7 @@ tl::expected EspAsyncOta::startTask() return {}; } -tl::expected EspAsyncOta::endTask() +std::expected EspAsyncOta::endTask() { if (const auto bits = m_eventGroup.getBits(); !(bits & TASK_RUNNING_BIT)) @@ -109,7 +109,7 @@ tl::expected EspAsyncOta::endTask() { constexpr auto msg = "Another end request is already pending"; ESP_LOGE(TAG, "%s", msg); - return tl::make_unexpected(msg); + return std::unexpected(msg); } m_eventGroup.setBits(END_TASK_BIT); @@ -158,29 +158,29 @@ OtaCloudUpdateStatus EspAsyncOta::status() const return OtaCloudUpdateStatus::Idle; } -tl::expected EspAsyncOta::trigger(std::string_view url, std::string_view cert_pem, +std::expected EspAsyncOta::trigger(std::string_view url, std::string_view cert_pem, std::string_view client_key, std::string_view client_cert) { if (!m_taskHandle) { if (auto result = startTask(); !result) - return tl::make_unexpected(std::move(result).error()); + return std::unexpected(std::move(result).error()); } if (const auto bits = m_eventGroup.getBits(); !(bits & TASK_RUNNING_BIT)) - return tl::make_unexpected("ota cloud task not running"); + return std::unexpected("ota cloud task not running"); else if (bits & (START_REQUEST_BIT | REQUEST_RUNNING_BIT)) - return tl::make_unexpected("ota cloud already running"); + return std::unexpected("ota cloud already running"); else if (bits & REQUEST_FINISHED_BIT) - return tl::make_unexpected("ota cloud not fully finished, try again"); + return std::unexpected("ota cloud not fully finished, try again"); else assert(!(bits & REQUEST_SUCCEEDED_BIT)); if (url.empty()) - return tl::make_unexpected("empty firmware url"); + return std::unexpected("empty firmware url"); if (const auto result = esphttpdutils::urlverify(url); !result) - return tl::make_unexpected(fmt::format("could not verify firmware url: {}", result.error())); + return std::unexpected(fmt::format("could not verify firmware url: {}", result.error())); m_url = std::string{url}; m_cert_pem = cert_pem; @@ -193,12 +193,12 @@ tl::expected EspAsyncOta::trigger(std::string_view url, std:: return {}; } -tl::expected EspAsyncOta::abort() +std::expected EspAsyncOta::abort() { if (const auto bits = m_eventGroup.getBits(); !(bits & (START_REQUEST_BIT | REQUEST_RUNNING_BIT))) - return tl::make_unexpected("no ota job is running!"); + return std::unexpected("no ota job is running!"); else if (bits & ABORT_REQUEST_BIT) - return tl::make_unexpected("an abort has already been requested!"); + return std::unexpected("an abort has already been requested!"); m_eventGroup.setBits(ABORT_REQUEST_BIT); ESP_LOGI(TAG, "ota cloud update abort requested"); diff --git a/src/espasyncota.h b/src/espasyncota.h index 8a76368..3f6bd47 100644 --- a/src/espasyncota.h +++ b/src/espasyncota.h @@ -3,13 +3,11 @@ // system includes #include #include +#include // esp-idf includes #include -// 3rdparty lib includes -#include - // local includes #include "taskutils.h" #include "wrappers/event_group.h" @@ -31,8 +29,8 @@ public: EspAsyncOta(const char *taskName="asyncOtaTask", uint32_t stackSize=4096, espcpputils::CoreAffinity coreAffinity=espcpputils::CoreAffinity::Core1); ~EspAsyncOta(); - tl::expected startTask(); - tl::expected endTask(); + std::expected startTask(); + std::expected endTask(); int progress() const { return m_progress; } std::optional totalSize() const { return m_totalSize; } @@ -40,8 +38,8 @@ public: const std::string &message() const { return m_message; } const std::optional &appDesc() const { return m_appDesc; } OtaCloudUpdateStatus status() const; - tl::expected trigger(std::string_view url, std::string_view cert_pem, std::string_view client_key, std::string_view client_cert); - tl::expected abort(); + std::expected trigger(std::string_view url, std::string_view cert_pem, std::string_view client_key, std::string_view client_cert); + std::expected abort(); void update();