Skip to content

Commit a6da273

Browse files
committed
Merge branch 'ota-impl-cfg-1-4' into 'release/v1.4'
[v1.4] components/esp-matter: remove the unnecessary debug log See merge request app-frameworks/esp-matter!1005
2 parents 22e612f + 68d67d0 commit a6da273

File tree

2 files changed

+67
-13
lines changed

2 files changed

+67
-13
lines changed

components/esp_matter/esp_matter_ota.cpp

+42-8
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
#include <app/clusters/ota-requestor/BDXDownloader.h>
1919
#include <app/clusters/ota-requestor/DefaultOTARequestor.h>
20-
#include <app/clusters/ota-requestor/DefaultOTARequestorDriver.h>
20+
#include <app/clusters/ota-requestor/ExtendedOTARequestorDriver.h>
2121
#include <app/clusters/ota-requestor/DefaultOTARequestorStorage.h>
2222
#include <platform/ESP32/OTAImageProcessorImpl.h>
2323

@@ -30,7 +30,7 @@ using chip::DefaultOTARequestor;
3030
using chip::DefaultOTARequestorStorage;
3131
using chip::OTAImageProcessorImpl;
3232
using chip::Server;
33-
using chip::DeviceLayer::DefaultOTARequestorDriver;
33+
using chip::DeviceLayer::ExtendedOTARequestorDriver;
3434

3535
using namespace esp_matter;
3636
using namespace esp_matter::endpoint;
@@ -39,10 +39,15 @@ using namespace esp_matter::cluster;
3939
#if CONFIG_ENABLE_OTA_REQUESTOR
4040
DefaultOTARequestor gRequestorCore;
4141
DefaultOTARequestorStorage gRequestorStorage;
42-
DefaultOTARequestorDriver gRequestorUser;
42+
ExtendedOTARequestorDriver gRequestorUser;
4343
BDXDownloader gDownloader;
4444
OTAImageProcessorImpl gImageProcessor;
45-
#endif
45+
46+
static esp_matter_ota_requestor_impl_t s_ota_requestor_impl = {
47+
.driver = &gRequestorUser,
48+
.image_processor = &gImageProcessor,
49+
};
50+
#endif // CONFIG_ENABLE_OTA_REQUESTOR
4651

4752
esp_err_t esp_matter_ota_requestor_init(void)
4853
{
@@ -61,16 +66,42 @@ esp_err_t esp_matter_ota_requestor_init(void)
6166
#endif
6267
}
6368

69+
static esp_err_t esp_matter_ota_override_impl(const esp_matter_ota_requestor_impl_t *impl)
70+
{
71+
#if CONFIG_ENABLE_OTA_REQUESTOR
72+
VerifyOrReturnError(impl != nullptr, ESP_ERR_INVALID_ARG);
73+
74+
if (impl->driver != nullptr) {
75+
s_ota_requestor_impl.driver = impl->driver;
76+
}
77+
if (impl->image_processor != nullptr) {
78+
s_ota_requestor_impl.image_processor = impl->image_processor;
79+
}
80+
81+
s_ota_requestor_impl.user_consent = impl->user_consent;
82+
83+
return ESP_OK;
84+
#else
85+
return ESP_ERR_NOT_SUPPORTED;
86+
#endif // CONFIG_ENABLE_OTA_REQUESTOR
87+
}
88+
6489
void esp_matter_ota_requestor_start(void)
6590
{
6691
#if CONFIG_ENABLE_OTA_REQUESTOR
6792
VerifyOrReturn(chip::GetRequestorInstance() == nullptr);
93+
6894
chip::SetRequestorInstance(&gRequestorCore);
6995
gRequestorStorage.Init(Server::GetInstance().GetPersistentStorage());
70-
gRequestorCore.Init(Server::GetInstance(), gRequestorStorage, gRequestorUser, gDownloader);
71-
gImageProcessor.SetOTADownloader(&gDownloader);
72-
gDownloader.SetImageProcessorDelegate(&gImageProcessor);
73-
gRequestorUser.Init(&gRequestorCore, &gImageProcessor);
96+
97+
gRequestorCore.Init(Server::GetInstance(), gRequestorStorage, *s_ota_requestor_impl.driver, gDownloader);
98+
99+
s_ota_requestor_impl.image_processor->SetOTADownloader(&gDownloader);
100+
101+
gDownloader.SetImageProcessorDelegate(s_ota_requestor_impl.image_processor);
102+
103+
s_ota_requestor_impl.driver->SetUserConsentDelegate(s_ota_requestor_impl.user_consent);
104+
s_ota_requestor_impl.driver->Init(&gRequestorCore, s_ota_requestor_impl.image_processor);
74105
#endif
75106
}
76107

@@ -93,6 +124,9 @@ esp_err_t esp_matter_ota_requestor_set_config(const esp_matter_ota_config_t & co
93124
if (config.watchdog_timeout) {
94125
gRequestorUser.SetWatchdogTimeout(config.watchdog_timeout);
95126
}
127+
if (config.impl != nullptr) {
128+
esp_matter_ota_override_impl(config.impl);
129+
}
96130

97131
return ESP_OK;
98132
#else

components/esp_matter/esp_matter_ota.h

+25-5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,19 @@
1717
#include "esp_err.h"
1818
#include "sdkconfig.h"
1919

20+
#include <app/clusters/ota-requestor/ExtendedOTARequestorDriver.h>
21+
#include <app/clusters/ota-requestor/OTARequestorUserConsentDelegate.h>
22+
#include <platform/ESP32/OTAImageProcessorImpl.h>
23+
24+
typedef struct {
25+
// ota requestor driver
26+
chip::DeviceLayer::ExtendedOTARequestorDriver *driver = nullptr;
27+
// user consent
28+
chip::ota::OTARequestorUserConsentDelegate *user_consent = nullptr;
29+
// ota image processor
30+
chip::OTAImageProcessorImpl *image_processor = nullptr;
31+
} esp_matter_ota_requestor_impl_t;
32+
2033
typedef struct {
2134
/**
2235
* Timeout (in seconds) for querying default OTA Providers
@@ -29,24 +42,31 @@ typedef struct {
2942
* Default timeout is 300 seconds
3043
*/
3144
uint32_t watchdog_timeout;
45+
/**
46+
* Options to override the default behavior of the OTA requestor
47+
* Refer to esp_matter_ota_requestor_impl_t for more details.
48+
* If not set, default implementation is used.
49+
*/
50+
const esp_matter_ota_requestor_impl_t *impl = nullptr;
3251
} esp_matter_ota_config_t;
3352

34-
35-
/** Initialize the Matter OTA Requestor
53+
/**
54+
* Initialize the Matter OTA Requestor
3655
*
56+
* Adds the OTA requestor server cluster and ota provider client cluster to root node endpoint.
3757
*/
3858
esp_err_t esp_matter_ota_requestor_init(void);
3959

40-
/**Start the Matter OTA Requestor
41-
*
60+
/**
61+
* Start the Matter OTA Requestor
4262
*/
4363
void esp_matter_ota_requestor_start(void);
4464

4565
/**
4666
* @brief This API initializes the handling of encrypted OTA image
4767
*
4868
* @param[in] key null terminated RSA-3072 key in PEM format.
49-
* The key buffer must remain allocated and should not be freed.
69+
* The key buffer must remain allocated and should not be freed.
5070
* @param[in] size Size of the key, size shall contain the null terminator as well.
5171
* If using `strlen` then please consider adding +1 to the size.
5272
*

0 commit comments

Comments
 (0)