Skip to content

Commit fb4e604

Browse files
committed
Merge branch 'controller/timed_write_backport_release_1_3' into 'release/v1.3'
[v1.3] backport: components/esp_matter_controller: support timed write See merge request app-frameworks/esp-matter!982
2 parents eda7e67 + 9c7467b commit fb4e604

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

components/esp_matter_controller/commands/esp_matter_controller_write_command.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ void write_command::on_device_connected_fcn(void *context, ExchangeManager &exch
4747
write_command *cmd = (write_command *)context;
4848
chip::OperationalDeviceProxy device_proxy(&exchangeMgr, sessionHandle);
4949
esp_err_t err = interaction::write::send_request(&device_proxy, cmd->m_attr_path, cmd->m_attr_val_str,
50-
cmd->m_chunked_callback, chip::NullOptional);
50+
cmd->m_chunked_callback, cmd->m_timed_write_timeout_ms);
5151
if (err != ESP_OK) {
5252
chip::Platform::Delete(cmd);
5353
}
@@ -88,14 +88,14 @@ esp_err_t write_command::send_command()
8888
}
8989

9090
esp_err_t send_write_attr_command(uint64_t node_id, uint16_t endpoint_id, uint32_t cluster_id, uint32_t attribute_id,
91-
const char *attr_val_json_str)
91+
const char *attr_val_json_str, chip::Optional<uint16_t> timed_write_timeout_ms)
9292
{
9393
if (!attr_val_json_str) {
9494
ESP_LOGE(TAG, "attribute value json string cannot be NULL");
9595
return ESP_ERR_INVALID_ARG;
9696
}
97-
write_command *cmd =
98-
chip::Platform::New<write_command>(node_id, endpoint_id, cluster_id, attribute_id, attr_val_json_str);
97+
write_command *cmd = chip::Platform::New<write_command>(node_id, endpoint_id, cluster_id, attribute_id,
98+
attr_val_json_str, timed_write_timeout_ms);
9999

100100
if (!cmd) {
101101
ESP_LOGE(TAG, "Failed to alloc memory for cluster_command");

components/esp_matter_controller/commands/esp_matter_controller_write_command.h

+7-2
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,12 @@ class write_command : public WriteClient::Callback {
4242
public:
4343
/** Constructor for command with an attribute path**/
4444
write_command(uint64_t node_id, uint16_t endpoint_id, uint32_t cluster_id, uint32_t attribute_id,
45-
const char *attribute_val_str)
45+
const char *attribute_val_str,
46+
const chip::Optional<uint16_t> timed_write_timeout_ms = chip::NullOptional)
4647
: m_node_id(node_id)
4748
, m_attr_path(endpoint_id, cluster_id, attribute_id)
4849
, m_chunked_callback(this)
50+
, m_timed_write_timeout_ms(timed_write_timeout_ms)
4951
, on_device_connected_cb(on_device_connected_fcn, this)
5052
, on_device_connection_failure_cb(on_device_connection_failure_fcn, this)
5153
{
@@ -87,6 +89,7 @@ class write_command : public WriteClient::Callback {
8789
AttributePathParams m_attr_path;
8890
ChunkedWriteCallback m_chunked_callback;
8991
char m_attr_val_str[k_attr_val_str_buf_size];
92+
chip::Optional<uint16_t> m_timed_write_timeout_ms;
9093

9194
static void on_device_connected_fcn(void *context, ExchangeManager &exchangeMgr,
9295
const SessionHandle &sessionHandle);
@@ -104,12 +107,14 @@ class write_command : public WriteClient::Callback {
104107
* @param[in] attribute_id AttributeId
105108
* @param[in] attr_val_json_str Attribute value string with JSON format
106109
* (https://docs.espressif.com/projects/esp-matter/en/latest/esp32/developing.html#write-attribute-commands)
110+
* @param[in] timed_write_timeout_ms Timeout in millisecond for timed-write attribute
107111
*
108112
* @return ESP_OK on success.
109113
* @return error in case of failure.
110114
*/
111115
esp_err_t send_write_attr_command(uint64_t node_id, uint16_t endpoint_id, uint32_t cluster_id, uint32_t attribute_id,
112-
const char *attr_val_json_str);
116+
const char *attr_val_json_str,
117+
chip::Optional<uint16_t> timed_write_timeout_ms = chip::NullOptional);
113118

114119
} // namespace controller
115120
} // namespace esp_matter

components/esp_matter_controller/core/esp_matter_controller_console.cpp

+10-2
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ static esp_err_t controller_read_attr_handler(int argc, char **argv)
415415

416416
static esp_err_t controller_write_attr_handler(int argc, char **argv)
417417
{
418-
if (argc != 5) {
418+
if (argc < 5) {
419419
return ESP_ERR_INVALID_ARG;
420420
}
421421

@@ -425,6 +425,14 @@ static esp_err_t controller_write_attr_handler(int argc, char **argv)
425425
uint32_t attribute_id = string_to_uint32(argv[3]);
426426
char *attribute_val_str = argv[4];
427427

428+
if (argc > 5) {
429+
uint16_t timed_write_timeout_ms = string_to_uint16(argv[5]);
430+
if (timed_write_timeout_ms > 0) {
431+
return controller::send_write_attr_command(node_id, endpoint_id, cluster_id, attribute_id,
432+
attribute_val_str, chip::MakeOptional(timed_write_timeout_ms));
433+
}
434+
}
435+
428436
return controller::send_write_attr_command(node_id, endpoint_id, cluster_id, attribute_id, attribute_val_str);
429437
}
430438

@@ -574,7 +582,7 @@ esp_err_t controller_register_commands()
574582
.name = "write-attr",
575583
.description =
576584
"Write attributes of the nodes.\n"
577-
"\tUsage: controller write-attr <node-id> <endpoint-id> <cluster-id> <attr-id> <attr-value>\n"
585+
"\tUsage: controller write-attr <node-id> <endpoint-id> <cluster-id> <attr-id> <attr-value> [timed_write_timeout_ms]\n"
578586
"\tNotes: attr-value should be a JSON object that contains the attribute value JSON item."
579587
"You can get the format of the attr-value from "
580588
"https://docs.espressif.com/projects/esp-matter/en/latest/esp32/"

0 commit comments

Comments
 (0)