ota: make OTA clusters optional.

This commit is contained in:
liyashuai
2022-08-17 10:32:47 +08:00
committed by WanqQixiang
parent 6c875685fa
commit 4c5232934e
15 changed files with 55 additions and 34 deletions
+1 -1
View File
@@ -71,7 +71,7 @@ set(INCLUDE_DIRS_LIST "."
"${MATTER_SDK_PATH}/src"
"${ZAP_GENERATED_PATH}/../")
set(REQUIRES_LIST chip bt esp_matter_console)
set(REQUIRES_LIST chip bt esp_matter_console nvs_flash app_update esp32_mbedtls esp_system)
if ("${IDF_TARGET}" STREQUAL "esp32h2")
list(APPEND REQUIRES_LIST openthread esp_matter_openthread)
@@ -32,6 +32,7 @@
#if CHIP_DEVICE_CONFIG_ENABLE_THREAD
#include <esp_matter_openthread.h>
#endif
#include <esp_matter_ota.h>
using chip::CommandId;
using chip::DataVersion;
@@ -740,10 +741,17 @@ static esp_err_t chip_init(event_callback_t callback)
esp_err_t start(event_callback_t callback)
{
esp_err_t ota_err = esp_matter_ota_requestor_init();
esp_err_t err = chip_init(callback);
if (err != ESP_OK) {
ESP_LOGE(TAG, "Error initializing matter");
}
if ((ota_err == ESP_OK) && (err == ESP_OK)) {
esp_matter_ota_requestor_start();
}
return err;
}
@@ -65,8 +65,6 @@ endpoint_t *create(node_t *node, config_t *config, uint8_t flags, void *priv_dat
descriptor::create(endpoint, CLUSTER_FLAG_SERVER);
access_control::create(endpoint, CLUSTER_FLAG_SERVER);
basic::create(endpoint, &(config->basic), CLUSTER_FLAG_SERVER);
ota_provider::create(endpoint, NULL, CLUSTER_FLAG_CLIENT);
ota_requestor::create(endpoint, &(config->ota_requestor), CLUSTER_FLAG_SERVER);
general_commissioning::create(endpoint, &(config->general_commissioning), CLUSTER_FLAG_SERVER);
network_commissioning::create(endpoint, &(config->network_commissioning), CLUSTER_FLAG_SERVER);
general_diagnostics::create(endpoint, &(config->general_diagnostics), CLUSTER_FLAG_SERVER);
@@ -33,7 +33,6 @@ namespace endpoint {
namespace root_node {
typedef struct config {
cluster::basic::config_t basic;
cluster::ota_requestor::config_t ota_requestor;
cluster::general_commissioning::config_t general_commissioning;
cluster::network_commissioning::config_t network_commissioning;
cluster::general_diagnostics::config_t general_diagnostics;
@@ -13,7 +13,6 @@
// limitations under the License.
#include <esp_log.h>
#include <esp_matter_ota.h>
#include <string.h>
#include <app/clusters/ota-requestor/BDXDownloader.h>
@@ -22,26 +21,59 @@
#include <app/clusters/ota-requestor/DefaultOTARequestorStorage.h>
#include <platform/ESP32/OTAImageProcessorImpl.h>
#include <esp_matter.h>
using chip::BDXDownloader;
using chip::DefaultOTARequestor;
using chip::DefaultOTARequestorStorage;
using chip::DeviceLayer::DefaultOTARequestorDriver;
using chip::OTAImageProcessorImpl;
using chip::Server;
using namespace esp_matter;
using namespace esp_matter::endpoint;
using namespace esp_matter::cluster;
#if CONFIG_ENABLE_OTA_REQUESTOR
DefaultOTARequestor gRequestorCore;
DefaultOTARequestorStorage gRequestorStorage;
DefaultOTARequestorDriver gRequestorUser;
BDXDownloader gDownloader;
OTAImageProcessorImpl gImageProcessor;
#endif
void esp_matter_ota_requestor_init(void)
esp_err_t esp_matter_ota_requestor_init(void)
{
#if (CONFIG_ENABLE_OTA_REQUESTOR && (FIXED_ENDPOINT_COUNT == 0))
ota_requestor::config_t config;
node_t *root_node = esp_matter::node::get();
endpoint_t *root_node_endpoint = esp_matter::endpoint::get(root_node, 0);
if (!root_node || !root_node_endpoint) {
return ESP_FAIL;
}
cluster_t *cluster_p = ota_provider::create(root_node_endpoint, NULL, CLUSTER_FLAG_CLIENT);
cluster_t *cluster_r = ota_requestor::create(root_node_endpoint, &config, CLUSTER_FLAG_SERVER);
if (!cluster_p || !cluster_r) {
return ESP_FAIL;
}
return ESP_OK;
#else
return ESP_ERR_NOT_SUPPORTED;
#endif
}
void esp_matter_ota_requestor_start(void)
{
#if CONFIG_ENABLE_OTA_REQUESTOR
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);
}
#endif
}
@@ -17,9 +17,12 @@
#include "esp_err.h"
#include "sdkconfig.h"
#if CONFIG_ENABLE_OTA_REQUESTOR
/** Initialize the matter OTA Requestor
/** Initialize the Matter OTA Requestor
*
*/
void esp_matter_ota_requestor_init(void);
#endif
esp_err_t esp_matter_ota_requestor_init(void);
/**Start the Matter OTA Requestor
*
*/
void esp_matter_ota_requestor_start(void);
-3
View File
@@ -1,3 +0,0 @@
idf_component_register(SRCS "esp_matter_ota.cpp"
INCLUDE_DIRS "${CMAKE_CURRENT_LIST_DIR}"
REQUIRES esp_matter app_update esp32_mbedtls esp_system)