add ota requestor and provider device definition

This commit is contained in:
liyashuai
2024-07-26 14:29:06 +08:00
parent c8bf81d941
commit 54ffd18ecd
3 changed files with 132 additions and 12 deletions
@@ -79,6 +79,105 @@ esp_err_t add(endpoint_t *endpoint, config_t *config)
}
} /* root_node */
namespace ota_requestor{
uint32_t get_device_type_id()
{
return ESP_MATTER_OTA_REQUESTOR_DEVICE_TYPE_ID;
}
uint8_t get_device_type_version()
{
return ESP_MATTER_OTA_REQUESTOR_DEVICE_TYPE_VERSION;
}
endpoint_t *create(node_t *node, config_t *config, uint8_t flags, void *priv_data)
{
#ifdef CONFIG_ENABLE_OTA_REQUESTOR
endpoint_t *endpoint = endpoint::create(node, flags, priv_data);
add(endpoint, config);
return endpoint;
#else
ESP_LOGE(TAG, "Need enable CONFIG_ENABLE_OTA_REQUESTOR to enable ota requestor function");
return nullptr;
#endif
}
esp_err_t add(endpoint_t *endpoint, config_t *config)
{
#ifdef CONFIG_ENABLE_OTA_REQUESTOR
if (!endpoint) {
ESP_LOGE(TAG, "Endpoint cannot be NULL");
return ESP_ERR_INVALID_ARG;
}
esp_err_t err = add_device_type(endpoint, get_device_type_id(), get_device_type_version());
if (err != ESP_OK) {
ESP_LOGE(TAG, "Failed to add device type id:%" PRIu32 ",err: %d", get_device_type_id(), err);
return err;
}
cluster_t *cluster = descriptor::create(endpoint, &(config->descriptor), CLUSTER_FLAG_SERVER);
if (!cluster) {
return ESP_ERR_INVALID_STATE;
}
cluster_t *cluster_p = cluster::ota_provider::create(endpoint, NULL, CLUSTER_FLAG_CLIENT);
cluster_t *cluster_r = cluster::ota_requestor::create(endpoint, &(config->ota_requestor), CLUSTER_FLAG_SERVER);
if (!cluster_p || !cluster_r) {
return ESP_FAIL;
}
return ESP_OK;
#else
ESP_LOGE(TAG, "Need enable CONFIG_ENABLE_OTA_REQUESTOR to enable ota requestor function");
return ESP_FAIL;
#endif
}
} /** ota_requestor **/
namespace ota_provider{
uint32_t get_device_type_id()
{
return ESP_MATTER_OTA_PROVIDER_DEVICE_TYPE_ID;
}
uint8_t get_device_type_version()
{
return ESP_MATTER_OTA_PROVIDER_DEVICE_TYPE_VERSION;
}
endpoint_t *create(node_t *node, config_t *config, uint8_t flags, void *priv_data)
{
endpoint_t *endpoint = endpoint::create(node, flags, priv_data);
add(endpoint, config);
return endpoint;
}
esp_err_t add(endpoint_t *endpoint, config_t *config)
{
if (!endpoint) {
ESP_LOGE(TAG, "Endpoint cannot be NULL");
return ESP_ERR_INVALID_ARG;
}
esp_err_t err = add_device_type(endpoint, get_device_type_id(), get_device_type_version());
if (err != ESP_OK) {
ESP_LOGE(TAG, "Failed to add device type id:%" PRIu32 ",err: %d", get_device_type_id(), err);
return err;
}
cluster_t *cluster = descriptor::create(endpoint, &(config->descriptor), CLUSTER_FLAG_SERVER);
if (!cluster) {
return ESP_ERR_INVALID_STATE;
}
cluster = cluster::ota_provider::create(endpoint, &(config->ota_provider), CLUSTER_FLAG_SERVER);
if (!cluster) {
return ESP_FAIL;
}
return ESP_OK;
}
} /** ota_provider **/
namespace power_source_device{
uint32_t get_device_type_id()
{
+31 -3
View File
@@ -21,6 +21,10 @@
/* Replace these with IDs from submodule whenever they are implemented */
#define ESP_MATTER_ROOT_NODE_DEVICE_TYPE_ID 0x0016
#define ESP_MATTER_ROOT_NODE_DEVICE_TYPE_VERSION 2
#define ESP_MATTER_OTA_REQUESTOR_DEVICE_TYPE_ID 0x0012
#define ESP_MATTER_OTA_REQUESTOR_DEVICE_TYPE_VERSION 1
#define ESP_MATTER_OTA_PROVIDER_DEVICE_TYPE_ID 0x0014
#define ESP_MATTER_OTA_PROVIDER_DEVICE_TYPE_VERSION 1
#define ESP_MATTER_POWER_SOURCE_DEVICE_TYPE_ID 0x0011
#define ESP_MATTER_POWER_SOURCE_DEVICE_TYPE_VERSION 1
#define ESP_MATTER_AGGREGATOR_DEVICE_TYPE_ID 0x000E
@@ -156,6 +160,30 @@ endpoint_t *create(node_t *node, config_t *config, uint8_t flags, void *priv_dat
esp_err_t add(endpoint_t *endpoint, config_t *config);
} /* root_node */
namespace ota_requestor{
typedef struct config {
cluster::descriptor::config_t descriptor;
cluster::ota_requestor::config_t ota_requestor;
} config_t;
uint32_t get_device_type_id();
uint8_t get_device_type_version();
endpoint_t *create(node_t *node, config_t *config, uint8_t flags, void *priv_data);
esp_err_t add(endpoint_t *endpoint, config_t *config);
} /* ota_requestor */
namespace ota_provider{
typedef struct config {
cluster::descriptor::config_t descriptor;
cluster::ota_provider::config_t ota_provider;
} config_t;
uint32_t get_device_type_id();
uint8_t get_device_type_version();
endpoint_t *create(node_t *node, config_t *config, uint8_t flags, void *priv_data);
esp_err_t add(endpoint_t *endpoint, config_t *config);
} /* ota_provider */
namespace power_source_device{
typedef struct config {
cluster::descriptor::config_t descriptor;
@@ -831,12 +859,12 @@ typedef struct config {
* @param[in] identify_callback This callback is invoked when clients interact with the Identify Cluster.
* In the callback implementation, an endpoint can identify itself.
* (e.g., by flashing an LED or light).
* @param[in] priv_data Private data to send to the node. This parameter is optional
* and defaults to nullptr.This private data can be accessed in the attribute callback
* @param[in] priv_data Private data to send to the node. This parameter is optional
* and defaults to nullptr.This private data can be accessed in the attribute callback
* for the root endpoint only.
*/
node_t *create(config_t *config, attribute::callback_t attribute_callback,
identification::callback_t identify_callback, void* priv_data = nullptr);
identification::callback_t identify_callback, void* priv_data = nullptr);
} /* node */
} /* esp_matter */
+2 -9
View File
@@ -47,7 +47,7 @@ OTAImageProcessorImpl gImageProcessor;
esp_err_t esp_matter_ota_requestor_init(void)
{
#if (CONFIG_ENABLE_OTA_REQUESTOR && (FIXED_ENDPOINT_COUNT == 0))
ota_requestor::config_t config;
endpoint::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);
@@ -55,14 +55,7 @@ esp_err_t esp_matter_ota_requestor_init(void)
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;
return endpoint::ota_requestor::add(root_node_endpoint, &config);
#else
return ESP_ERR_NOT_SUPPORTED;
#endif