mirror of
https://github.com/espressif/esp-matter.git
synced 2026-04-27 19:13:13 +00:00
Merge branch 'controller/timed_write' into 'main'
components/esp_matter_controller: support timed write See merge request app-frameworks/esp-matter!965
This commit is contained in:
@@ -47,7 +47,7 @@ void write_command::on_device_connected_fcn(void *context, ExchangeManager &exch
|
||||
write_command *cmd = (write_command *)context;
|
||||
chip::OperationalDeviceProxy device_proxy(&exchangeMgr, sessionHandle);
|
||||
esp_err_t err = interaction::write::send_request(&device_proxy, cmd->m_attr_path, cmd->m_attr_val,
|
||||
cmd->m_chunked_callback, chip::NullOptional);
|
||||
cmd->m_chunked_callback, cmd->m_timed_write_timeout_ms);
|
||||
if (err != ESP_OK) {
|
||||
chip::Platform::Delete(cmd);
|
||||
}
|
||||
@@ -88,14 +88,14 @@ esp_err_t write_command::send_command()
|
||||
}
|
||||
|
||||
esp_err_t send_write_attr_command(uint64_t node_id, uint16_t endpoint_id, uint32_t cluster_id, uint32_t attribute_id,
|
||||
const char *attr_val_json_str)
|
||||
const char *attr_val_json_str, chip::Optional<uint16_t> timed_write_timeout_ms)
|
||||
{
|
||||
if (!attr_val_json_str) {
|
||||
ESP_LOGE(TAG, "attribute value json string cannot be NULL");
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
write_command *cmd =
|
||||
chip::Platform::New<write_command>(node_id, endpoint_id, cluster_id, attribute_id, attr_val_json_str);
|
||||
write_command *cmd = chip::Platform::New<write_command>(node_id, endpoint_id, cluster_id, attribute_id,
|
||||
attr_val_json_str, timed_write_timeout_ms);
|
||||
|
||||
if (!cmd) {
|
||||
ESP_LOGE(TAG, "Failed to alloc memory for cluster_command");
|
||||
|
||||
@@ -40,11 +40,13 @@ class write_command : public WriteClient::Callback {
|
||||
public:
|
||||
/** Constructor for command with an attribute path**/
|
||||
write_command(uint64_t node_id, uint16_t endpoint_id, uint32_t cluster_id, uint32_t attribute_id,
|
||||
const char *attribute_val_str)
|
||||
const char *attribute_val_str,
|
||||
const chip::Optional<uint16_t> timed_write_timeout_ms = chip::NullOptional)
|
||||
: m_node_id(node_id)
|
||||
, m_attr_path(endpoint_id, cluster_id, attribute_id)
|
||||
, m_chunked_callback(this)
|
||||
, m_attr_val(attribute_val_str, custom_encodable_type::interaction_type::k_write_attr)
|
||||
, m_timed_write_timeout_ms(timed_write_timeout_ms)
|
||||
, on_device_connected_cb(on_device_connected_fcn, this)
|
||||
, on_device_connection_failure_cb(on_device_connection_failure_fcn, this) {}
|
||||
|
||||
@@ -77,6 +79,7 @@ private:
|
||||
AttributePathParams m_attr_path;
|
||||
ChunkedWriteCallback m_chunked_callback;
|
||||
custom_encodable_type m_attr_val;
|
||||
chip::Optional<uint16_t> m_timed_write_timeout_ms;
|
||||
|
||||
static void on_device_connected_fcn(void *context, ExchangeManager &exchangeMgr,
|
||||
const SessionHandle &sessionHandle);
|
||||
@@ -94,12 +97,14 @@ private:
|
||||
* @param[in] attribute_id AttributeId
|
||||
* @param[in] attr_val_json_str Attribute value string with JSON format
|
||||
* (https://docs.espressif.com/projects/esp-matter/en/latest/esp32/developing.html#write-attribute-commands)
|
||||
* @param[in] timed_write_timeout_ms Timeout in millisecond for timed-write attribute
|
||||
*
|
||||
* @return ESP_OK on success.
|
||||
* @return error in case of failure.
|
||||
*/
|
||||
esp_err_t send_write_attr_command(uint64_t node_id, uint16_t endpoint_id, uint32_t cluster_id, uint32_t attribute_id,
|
||||
const char *attr_val_json_str);
|
||||
const char *attr_val_json_str,
|
||||
chip::Optional<uint16_t> timed_write_timeout_ms = chip::NullOptional);
|
||||
|
||||
} // namespace controller
|
||||
} // namespace esp_matter
|
||||
|
||||
@@ -455,7 +455,7 @@ static esp_err_t controller_read_attr_handler(int argc, char **argv)
|
||||
|
||||
static esp_err_t controller_write_attr_handler(int argc, char **argv)
|
||||
{
|
||||
if (argc != 5) {
|
||||
if (argc < 5) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
@@ -465,6 +465,14 @@ static esp_err_t controller_write_attr_handler(int argc, char **argv)
|
||||
uint32_t attribute_id = string_to_uint32(argv[3]);
|
||||
char *attribute_val_str = argv[4];
|
||||
|
||||
if (argc > 5) {
|
||||
uint16_t timed_write_timeout_ms = string_to_uint16(argv[5]);
|
||||
if (timed_write_timeout_ms > 0) {
|
||||
return controller::send_write_attr_command(node_id, endpoint_id, cluster_id, attribute_id,
|
||||
attribute_val_str, chip::MakeOptional(timed_write_timeout_ms));
|
||||
}
|
||||
}
|
||||
|
||||
return controller::send_write_attr_command(node_id, endpoint_id, cluster_id, attribute_id, attribute_val_str);
|
||||
}
|
||||
|
||||
@@ -638,7 +646,7 @@ esp_err_t controller_register_commands()
|
||||
.name = "write-attr",
|
||||
.description =
|
||||
"Write attributes of the nodes.\n"
|
||||
"\tUsage: controller write-attr <node-id> <endpoint-id> <cluster-id> <attr-id> <attr-value>\n"
|
||||
"\tUsage: controller write-attr <node-id> <endpoint-id> <cluster-id> <attr-id> <attr-value> [timed_write_timeout_ms]\n"
|
||||
"\tNotes: attr-value should be a JSON object that contains the attribute value JSON item."
|
||||
"You can get the format of the attr-value from "
|
||||
"https://docs.espressif.com/projects/esp-matter/en/latest/esp32/"
|
||||
|
||||
Reference in New Issue
Block a user