components/esp-matter: support to configure the ota implementation

Added a member variable in the ota config struct which lets user set the
different ota implementation.
This commit is contained in:
Shubham Patil
2024-10-08 18:44:01 +05:30
parent a07c3129aa
commit 72a860836b
2 changed files with 67 additions and 13 deletions
+42 -8
View File
@@ -17,7 +17,7 @@
#include <app/clusters/ota-requestor/BDXDownloader.h>
#include <app/clusters/ota-requestor/DefaultOTARequestor.h>
#include <app/clusters/ota-requestor/DefaultOTARequestorDriver.h>
#include <app/clusters/ota-requestor/ExtendedOTARequestorDriver.h>
#include <app/clusters/ota-requestor/DefaultOTARequestorStorage.h>
#include <platform/ESP32/OTAImageProcessorImpl.h>
@@ -30,7 +30,7 @@ using chip::DefaultOTARequestor;
using chip::DefaultOTARequestorStorage;
using chip::OTAImageProcessorImpl;
using chip::Server;
using chip::DeviceLayer::DefaultOTARequestorDriver;
using chip::DeviceLayer::ExtendedOTARequestorDriver;
using namespace esp_matter;
using namespace esp_matter::endpoint;
@@ -39,10 +39,15 @@ using namespace esp_matter::cluster;
#if CONFIG_ENABLE_OTA_REQUESTOR
DefaultOTARequestor gRequestorCore;
DefaultOTARequestorStorage gRequestorStorage;
DefaultOTARequestorDriver gRequestorUser;
ExtendedOTARequestorDriver gRequestorUser;
BDXDownloader gDownloader;
OTAImageProcessorImpl gImageProcessor;
#endif
static esp_matter_ota_requestor_impl_t s_ota_requestor_impl = {
.driver = &gRequestorUser,
.image_processor = &gImageProcessor,
};
#endif // CONFIG_ENABLE_OTA_REQUESTOR
esp_err_t esp_matter_ota_requestor_init(void)
{
@@ -61,16 +66,42 @@ esp_err_t esp_matter_ota_requestor_init(void)
#endif
}
static esp_err_t esp_matter_ota_override_impl(const esp_matter_ota_requestor_impl_t *impl)
{
#if CONFIG_ENABLE_OTA_REQUESTOR
VerifyOrReturnError(impl != nullptr, ESP_ERR_INVALID_ARG);
if (impl->driver != nullptr) {
s_ota_requestor_impl.driver = impl->driver;
}
if (impl->image_processor != nullptr) {
s_ota_requestor_impl.image_processor = impl->image_processor;
}
s_ota_requestor_impl.user_consent = impl->user_consent;
return ESP_OK;
#else
return ESP_ERR_NOT_SUPPORTED;
#endif // CONFIG_ENABLE_OTA_REQUESTOR
}
void esp_matter_ota_requestor_start(void)
{
#if CONFIG_ENABLE_OTA_REQUESTOR
VerifyOrReturn(chip::GetRequestorInstance() == nullptr);
chip::SetRequestorInstance(&gRequestorCore);
gRequestorStorage.Init(Server::GetInstance().GetPersistentStorage());
gRequestorCore.Init(Server::GetInstance(), gRequestorStorage, gRequestorUser, gDownloader);
gImageProcessor.SetOTADownloader(&gDownloader);
gDownloader.SetImageProcessorDelegate(&gImageProcessor);
gRequestorUser.Init(&gRequestorCore, &gImageProcessor);
gRequestorCore.Init(Server::GetInstance(), gRequestorStorage, *s_ota_requestor_impl.driver, gDownloader);
s_ota_requestor_impl.image_processor->SetOTADownloader(&gDownloader);
gDownloader.SetImageProcessorDelegate(s_ota_requestor_impl.image_processor);
s_ota_requestor_impl.driver->SetUserConsentDelegate(s_ota_requestor_impl.user_consent);
s_ota_requestor_impl.driver->Init(&gRequestorCore, s_ota_requestor_impl.image_processor);
#endif
}
@@ -93,6 +124,9 @@ esp_err_t esp_matter_ota_requestor_set_config(const esp_matter_ota_config_t & co
if (config.watchdog_timeout) {
gRequestorUser.SetWatchdogTimeout(config.watchdog_timeout);
}
if (config.impl != nullptr) {
esp_matter_ota_override_impl(config.impl);
}
return ESP_OK;
#else