Updated to new esp-idf

This commit is contained in:
2023-02-27 17:27:00 +01:00
parent 0803e2339c
commit 538a1ff50a
3 changed files with 22 additions and 25 deletions

View File

@ -10,7 +10,6 @@ set(dependencies
esp_https_ota
esp_partition
expected
fmt
cpputils

View File

@ -51,20 +51,20 @@ EspAsyncOta::~EspAsyncOta()
endTask();
}
tl::expected<void, std::string> EspAsyncOta::startTask()
std::expected<void, std::string> 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<void, std::string> 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<void, std::string> EspAsyncOta::startTask()
return {};
}
tl::expected<void, std::string> EspAsyncOta::endTask()
std::expected<void, std::string> EspAsyncOta::endTask()
{
if (const auto bits = m_eventGroup.getBits();
!(bits & TASK_RUNNING_BIT))
@ -109,7 +109,7 @@ tl::expected<void, std::string> 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<void, std::string> EspAsyncOta::trigger(std::string_view url, std::string_view cert_pem,
std::expected<void, std::string> 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<void, std::string> EspAsyncOta::trigger(std::string_view url, std::
return {};
}
tl::expected<void, std::string> EspAsyncOta::abort()
std::expected<void, std::string> 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");

View File

@ -3,13 +3,11 @@
// system includes
#include <optional>
#include <string>
#include <expected>
// esp-idf includes
#include <esp_app_desc.h>
// 3rdparty lib includes
#include <tl/expected.hpp>
// 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<void, std::string> startTask();
tl::expected<void, std::string> endTask();
std::expected<void, std::string> startTask();
std::expected<void, std::string> endTask();
int progress() const { return m_progress; }
std::optional<int> totalSize() const { return m_totalSize; }
@ -40,8 +38,8 @@ public:
const std::string &message() const { return m_message; }
const std::optional<esp_app_desc_t> &appDesc() const { return m_appDesc; }
OtaCloudUpdateStatus status() const;
tl::expected<void, std::string> trigger(std::string_view url, std::string_view cert_pem, std::string_view client_key, std::string_view client_cert);
tl::expected<void, std::string> abort();
std::expected<void, std::string> trigger(std::string_view url, std::string_view cert_pem, std::string_view client_key, std::string_view client_cert);
std::expected<void, std::string> abort();
void update();