Skip to content

Commit d34c6f8

Browse files
committed
esp-matter: add device type version for all the supported device types
1 parent 83fec9a commit d34c6f8

File tree

6 files changed

+200
-29
lines changed

6 files changed

+200
-29
lines changed

components/esp_matter/esp_matter_core.cpp

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ typedef struct _endpoint {
141141
uint16_t endpoint_id;
142142
uint8_t device_type_count;
143143
uint32_t device_type_ids[ESP_MATTER_MAX_DEVICE_TYPE_COUNT];
144+
uint8_t device_type_versions[ESP_MATTER_MAX_DEVICE_TYPE_COUNT];
144145
uint16_t flags;
145146
_cluster_t *cluster_list;
146147
EmberAfEndpointType *endpoint_type;
@@ -395,7 +396,6 @@ esp_err_t enable(endpoint_t *endpoint, uint16_t parent_endpoint_id)
395396
current_endpoint->endpoint_type = endpoint_type;
396397

397398
/* Device types */
398-
int default_device_version = 1;
399399
EmberAfDeviceType *device_types_ptr = (EmberAfDeviceType *)calloc(current_endpoint->device_type_count, sizeof(EmberAfDeviceType));
400400
if (!device_types_ptr) {
401401
ESP_LOGE(TAG, "Couldn't allocate device_types");
@@ -406,7 +406,7 @@ esp_err_t enable(endpoint_t *endpoint, uint16_t parent_endpoint_id)
406406
}
407407
for (size_t i = 0; i < current_endpoint->device_type_count; ++i) {
408408
device_types_ptr[i].deviceId = current_endpoint->device_type_ids[i];
409-
device_types_ptr[i].deviceVersion = default_device_version;
409+
device_types_ptr[i].deviceVersion = current_endpoint->device_type_versions[i];
410410
}
411411
chip::Span<EmberAfDeviceType> device_types(device_types_ptr, current_endpoint->device_type_count);
412412
current_endpoint->device_types_ptr = device_types_ptr;
@@ -1670,7 +1670,7 @@ uint16_t get_id(endpoint_t *endpoint)
16701670
return current_endpoint->endpoint_id;
16711671
}
16721672

1673-
esp_err_t add_device_type_id(endpoint_t *endpoint, uint32_t device_type_id)
1673+
esp_err_t add_device_type(endpoint_t *endpoint, uint32_t device_type_id, uint8_t device_type_version)
16741674
{
16751675
if (!endpoint) {
16761676
ESP_LOGE(TAG, "Endpoint cannot be NULL");
@@ -1682,6 +1682,7 @@ esp_err_t add_device_type_id(endpoint_t *endpoint, uint32_t device_type_id)
16821682
return ESP_FAIL;
16831683
}
16841684
current_endpoint->device_type_ids[current_endpoint->device_type_count] = device_type_id;
1685+
current_endpoint->device_type_versions[current_endpoint->device_type_count] = device_type_version;
16851686
current_endpoint->device_type_count++;
16861687
return ESP_OK;
16871688
}
@@ -1701,6 +1702,21 @@ uint32_t *get_device_type_ids(endpoint_t *endpoint, uint8_t *device_type_count_p
17011702
return current_endpoint->device_type_ids;
17021703
}
17031704

1705+
uint8_t *get_device_type_versions(endpoint_t *endpoint, uint8_t *device_type_count_ptr)
1706+
{
1707+
if (!endpoint) {
1708+
ESP_LOGE(TAG, "Endpoint cannot be NULL");
1709+
return NULL;
1710+
}
1711+
if (!device_type_count_ptr) {
1712+
ESP_LOGE(TAG, "device type count pointer cannot be NULL");
1713+
return NULL;
1714+
}
1715+
_endpoint_t *current_endpoint = (_endpoint_t *)endpoint;
1716+
*device_type_count_ptr = current_endpoint->device_type_count;
1717+
return current_endpoint->device_type_versions;
1718+
}
1719+
17041720
void *get_priv_data(uint16_t endpoint_id)
17051721
{
17061722
node_t *node = node::get();

components/esp_matter/esp_matter_core.h

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,21 +196,22 @@ endpoint_t *get_next(endpoint_t *endpoint);
196196
*/
197197
uint16_t get_id(endpoint_t *endpoint);
198198

199-
/** Add device type ID
199+
/** Add device type ID and verision
200200
*
201-
* Add the device type ID for the endpoint.
201+
* Add the device type ID and version for the endpoint.
202202
*
203203
* @param[in] endpoint Endpoint handle.
204204
* @param[in] device_type_id Device type ID.
205+
* @parma[in] device_type_version Device type version.
205206
*
206207
* @return ESP_OK on success.
207208
* @return error in case of failure.
208209
*/
209-
esp_err_t add_device_type_id(endpoint_t *endpoint, uint32_t device_type_id);
210+
esp_err_t add_device_type(endpoint_t *endpoint, uint32_t device_type_id, uint8_t device_type_version);
210211

211212
/** Get device type ID array
212213
*
213-
* Get the device type ID array for the endpoint.
214+
* Get the device type ID array for the endpoint. This array is aligned with the device type version array.
214215
*
215216
* @param[in] endpoint Endpoint handle.
216217
* @param[out] device_type_count_ptr the pointer of device type ID array length.
@@ -220,6 +221,18 @@ esp_err_t add_device_type_id(endpoint_t *endpoint, uint32_t device_type_id);
220221
*/
221222
uint32_t *get_device_type_ids(endpoint_t *endpoint, uint8_t *device_type_count_ptr);
222223

224+
/** Get device type version array
225+
*
226+
* Get the device type version array for the endpoint. This array is aligned with the device type ID array.
227+
*
228+
* @param[in] endpoint Endpoint handle.
229+
* @param[out] device_type_count_ptr the pointer of device type version array length.
230+
*
231+
* @return device type version array on success.
232+
* @return NULL when the endpoint or the device_type_count_ptr is NULL.
233+
*/
234+
uint8_t *get_device_type_versions(endpoint_t *endpoint, uint8_t *device_type_count_ptr);
235+
223236
/** Get private data
224237
*
225238
* Get the private data passed while creating the endpoint.

0 commit comments

Comments
 (0)