Skip to content

Commit 6d33b7d

Browse files
committed
Merge branch 'add_ota_requestor_provider_device_type_1.3' into 'release/v1.3'
backport: components/esp-matter:add ota requestor and provider device definition See merge request app-frameworks/esp-matter!947
2 parents 38fbb86 + 760d5bb commit 6d33b7d

File tree

3 files changed

+129
-9
lines changed

3 files changed

+129
-9
lines changed

components/esp_matter/esp_matter_endpoint.cpp

+99
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,105 @@ esp_err_t add(endpoint_t *endpoint, config_t *config)
8585
}
8686
} /* root_node */
8787

88+
namespace ota_requestor{
89+
uint32_t get_device_type_id()
90+
{
91+
return ESP_MATTER_OTA_REQUESTOR_DEVICE_TYPE_ID;
92+
}
93+
94+
uint8_t get_device_type_version()
95+
{
96+
return ESP_MATTER_OTA_REQUESTOR_DEVICE_TYPE_VERSION;
97+
}
98+
99+
endpoint_t *create(node_t *node, config_t *config, uint8_t flags, void *priv_data)
100+
{
101+
#ifdef CONFIG_ENABLE_OTA_REQUESTOR
102+
endpoint_t *endpoint = endpoint::create(node, flags, priv_data);
103+
add(endpoint, config);
104+
return endpoint;
105+
#else
106+
ESP_LOGE(TAG, "Need enable CONFIG_ENABLE_OTA_REQUESTOR to enable ota requestor function");
107+
return nullptr;
108+
#endif
109+
}
110+
111+
esp_err_t add(endpoint_t *endpoint, config_t *config)
112+
{
113+
#ifdef CONFIG_ENABLE_OTA_REQUESTOR
114+
if (!endpoint) {
115+
ESP_LOGE(TAG, "Endpoint cannot be NULL");
116+
return ESP_ERR_INVALID_ARG;
117+
}
118+
esp_err_t err = add_device_type(endpoint, get_device_type_id(), get_device_type_version());
119+
if (err != ESP_OK) {
120+
ESP_LOGE(TAG, "Failed to add device type id:%" PRIu32 ",err: %d", get_device_type_id(), err);
121+
return err;
122+
}
123+
124+
cluster_t *cluster = descriptor::create(endpoint, &(config->descriptor), CLUSTER_FLAG_SERVER);
125+
if (!cluster) {
126+
return ESP_ERR_INVALID_STATE;
127+
}
128+
cluster_t *cluster_p = cluster::ota_provider::create(endpoint, NULL, CLUSTER_FLAG_CLIENT);
129+
cluster_t *cluster_r = cluster::ota_requestor::create(endpoint, &(config->ota_requestor), CLUSTER_FLAG_SERVER);
130+
if (!cluster_p || !cluster_r) {
131+
return ESP_FAIL;
132+
}
133+
134+
return ESP_OK;
135+
#else
136+
ESP_LOGE(TAG, "Need enable CONFIG_ENABLE_OTA_REQUESTOR to enable ota requestor function");
137+
return ESP_FAIL;
138+
#endif
139+
}
140+
141+
} /** ota_requestor **/
142+
143+
namespace ota_provider{
144+
uint32_t get_device_type_id()
145+
{
146+
return ESP_MATTER_OTA_PROVIDER_DEVICE_TYPE_ID;
147+
}
148+
149+
uint8_t get_device_type_version()
150+
{
151+
return ESP_MATTER_OTA_PROVIDER_DEVICE_TYPE_VERSION;
152+
}
153+
154+
endpoint_t *create(node_t *node, config_t *config, uint8_t flags, void *priv_data)
155+
{
156+
endpoint_t *endpoint = endpoint::create(node, flags, priv_data);
157+
add(endpoint, config);
158+
return endpoint;
159+
}
160+
161+
esp_err_t add(endpoint_t *endpoint, config_t *config)
162+
{
163+
if (!endpoint) {
164+
ESP_LOGE(TAG, "Endpoint cannot be NULL");
165+
return ESP_ERR_INVALID_ARG;
166+
}
167+
esp_err_t err = add_device_type(endpoint, get_device_type_id(), get_device_type_version());
168+
if (err != ESP_OK) {
169+
ESP_LOGE(TAG, "Failed to add device type id:%" PRIu32 ",err: %d", get_device_type_id(), err);
170+
return err;
171+
}
172+
173+
cluster_t *cluster = descriptor::create(endpoint, &(config->descriptor), CLUSTER_FLAG_SERVER);
174+
if (!cluster) {
175+
return ESP_ERR_INVALID_STATE;
176+
}
177+
cluster = cluster::ota_provider::create(endpoint, &(config->ota_provider), CLUSTER_FLAG_SERVER);
178+
if (!cluster) {
179+
return ESP_FAIL;
180+
}
181+
182+
return ESP_OK;
183+
}
184+
185+
} /** ota_provider **/
186+
88187
namespace power_source_device{
89188
uint32_t get_device_type_id()
90189
{

components/esp_matter/esp_matter_endpoint.h

+28
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
/* Replace these with IDs from submodule whenever they are implemented */
2222
#define ESP_MATTER_ROOT_NODE_DEVICE_TYPE_ID 0x0016
2323
#define ESP_MATTER_ROOT_NODE_DEVICE_TYPE_VERSION 2
24+
#define ESP_MATTER_OTA_REQUESTOR_DEVICE_TYPE_ID 0x0012
25+
#define ESP_MATTER_OTA_REQUESTOR_DEVICE_TYPE_VERSION 1
26+
#define ESP_MATTER_OTA_PROVIDER_DEVICE_TYPE_ID 0x0014
27+
#define ESP_MATTER_OTA_PROVIDER_DEVICE_TYPE_VERSION 1
2428
#define ESP_MATTER_POWER_SOURCE_DEVICE_TYPE_ID 0x0011
2529
#define ESP_MATTER_POWER_SOURCE_DEVICE_TYPE_VERSION 1
2630
#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
156160
esp_err_t add(endpoint_t *endpoint, config_t *config);
157161
} /* root_node */
158162

163+
namespace ota_requestor{
164+
typedef struct config {
165+
cluster::descriptor::config_t descriptor;
166+
cluster::ota_requestor::config_t ota_requestor;
167+
} config_t;
168+
169+
uint32_t get_device_type_id();
170+
uint8_t get_device_type_version();
171+
endpoint_t *create(node_t *node, config_t *config, uint8_t flags, void *priv_data);
172+
esp_err_t add(endpoint_t *endpoint, config_t *config);
173+
} /* ota_requestor */
174+
175+
namespace ota_provider{
176+
typedef struct config {
177+
cluster::descriptor::config_t descriptor;
178+
cluster::ota_provider::config_t ota_provider;
179+
} config_t;
180+
181+
uint32_t get_device_type_id();
182+
uint8_t get_device_type_version();
183+
endpoint_t *create(node_t *node, config_t *config, uint8_t flags, void *priv_data);
184+
esp_err_t add(endpoint_t *endpoint, config_t *config);
185+
} /* ota_provider */
186+
159187
namespace power_source_device{
160188
typedef struct config {
161189
cluster::descriptor::config_t descriptor;

components/esp_matter/esp_matter_ota.cpp

+2-9
Original file line numberDiff line numberDiff line change
@@ -47,22 +47,15 @@ OTAImageProcessorImpl gImageProcessor;
4747
esp_err_t esp_matter_ota_requestor_init(void)
4848
{
4949
#if (CONFIG_ENABLE_OTA_REQUESTOR && (FIXED_ENDPOINT_COUNT == 0))
50-
ota_requestor::config_t config;
50+
endpoint::ota_requestor::config_t config;
5151
node_t *root_node = esp_matter::node::get();
5252
endpoint_t *root_node_endpoint = esp_matter::endpoint::get(root_node, 0);
5353

5454
if (!root_node || !root_node_endpoint) {
5555
return ESP_FAIL;
5656
}
5757

58-
cluster_t *cluster_p = ota_provider::create(root_node_endpoint, NULL, CLUSTER_FLAG_CLIENT);
59-
cluster_t *cluster_r = ota_requestor::create(root_node_endpoint, &config, CLUSTER_FLAG_SERVER);
60-
61-
if (!cluster_p || !cluster_r) {
62-
return ESP_FAIL;
63-
}
64-
65-
return ESP_OK;
58+
return endpoint::ota_requestor::add(root_node_endpoint, &config);
6659
#else
6760
return ESP_ERR_NOT_SUPPORTED;
6861
#endif

0 commit comments

Comments
 (0)