Skip to content

Commit a2c6111

Browse files
committed
Merge branch 'controller/timed_write' into 'main'
components/esp_matter_controller: support timed write See merge request app-frameworks/esp-matter!965
2 parents e4433ad + e20a3bb commit a2c6111

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,
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
@@ -40,11 +40,13 @@ class write_command : public WriteClient::Callback {
4040
public:
4141
/** Constructor for command with an attribute path**/
4242
write_command(uint64_t node_id, uint16_t endpoint_id, uint32_t cluster_id, uint32_t attribute_id,
43-
const char *attribute_val_str)
43+
const char *attribute_val_str,
44+
const chip::Optional<uint16_t> timed_write_timeout_ms = chip::NullOptional)
4445
: m_node_id(node_id)
4546
, m_attr_path(endpoint_id, cluster_id, attribute_id)
4647
, m_chunked_callback(this)
4748
, m_attr_val(attribute_val_str, custom_encodable_type::interaction_type::k_write_attr)
49+
, m_timed_write_timeout_ms(timed_write_timeout_ms)
4850
, on_device_connected_cb(on_device_connected_fcn, this)
4951
, on_device_connection_failure_cb(on_device_connection_failure_fcn, this) {}
5052

@@ -77,6 +79,7 @@ class write_command : public WriteClient::Callback {
7779
AttributePathParams m_attr_path;
7880
ChunkedWriteCallback m_chunked_callback;
7981
custom_encodable_type m_attr_val;
82+
chip::Optional<uint16_t> m_timed_write_timeout_ms;
8083

8184
static void on_device_connected_fcn(void *context, ExchangeManager &exchangeMgr,
8285
const SessionHandle &sessionHandle);
@@ -94,12 +97,14 @@ class write_command : public WriteClient::Callback {
9497
* @param[in] attribute_id AttributeId
9598
* @param[in] attr_val_json_str Attribute value string with JSON format
9699
* (https://docs.espressif.com/projects/esp-matter/en/latest/esp32/developing.html#write-attribute-commands)
100+
* @param[in] timed_write_timeout_ms Timeout in millisecond for timed-write attribute
97101
*
98102
* @return ESP_OK on success.
99103
* @return error in case of failure.
100104
*/
101105
esp_err_t send_write_attr_command(uint64_t node_id, uint16_t endpoint_id, uint32_t cluster_id, uint32_t attribute_id,
102-
const char *attr_val_json_str);
106+
const char *attr_val_json_str,
107+
chip::Optional<uint16_t> timed_write_timeout_ms = chip::NullOptional);
103108

104109
} // namespace controller
105110
} // namespace esp_matter

components/esp_matter_controller/core/esp_matter_controller_console.cpp

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

456456
static esp_err_t controller_write_attr_handler(int argc, char **argv)
457457
{
458-
if (argc != 5) {
458+
if (argc < 5) {
459459
return ESP_ERR_INVALID_ARG;
460460
}
461461

@@ -465,6 +465,14 @@ static esp_err_t controller_write_attr_handler(int argc, char **argv)
465465
uint32_t attribute_id = string_to_uint32(argv[3]);
466466
char *attribute_val_str = argv[4];
467467

468+
if (argc > 5) {
469+
uint16_t timed_write_timeout_ms = string_to_uint16(argv[5]);
470+
if (timed_write_timeout_ms > 0) {
471+
return controller::send_write_attr_command(node_id, endpoint_id, cluster_id, attribute_id,
472+
attribute_val_str, chip::MakeOptional(timed_write_timeout_ms));
473+
}
474+
}
475+
468476
return controller::send_write_attr_command(node_id, endpoint_id, cluster_id, attribute_id, attribute_val_str);
469477
}
470478

@@ -638,7 +646,7 @@ esp_err_t controller_register_commands()
638646
.name = "write-attr",
639647
.description =
640648
"Write attributes of the nodes.\n"
641-
"\tUsage: controller write-attr <node-id> <endpoint-id> <cluster-id> <attr-id> <attr-value>\n"
649+
"\tUsage: controller write-attr <node-id> <endpoint-id> <cluster-id> <attr-id> <attr-value> [timed_write_timeout_ms]\n"
642650
"\tNotes: attr-value should be a JSON object that contains the attribute value JSON item."
643651
"You can get the format of the attr-value from "
644652
"https://docs.espressif.com/projects/esp-matter/en/latest/esp32/"

0 commit comments

Comments
 (0)