@@ -31,24 +31,48 @@ using chip::app::ConcreteDataAttributePath;
31
31
using chip::app::StatusIB;
32
32
using chip::app::WriteClient;
33
33
using chip::Messaging::ExchangeManager;
34
+ using chip::Platform::ScopedMemoryBufferWithSize;
34
35
using chip::TLV::TLVElementType;
35
36
using esp_matter::client::peer_device_t ;
36
37
using esp_matter::client::interaction::custom_encodable_type;
38
+ using esp_matter::client::interaction::multiple_write_encodable_type;
37
39
38
40
/* * Write command class to send a write interaction command to a server **/
39
41
class write_command : public WriteClient ::Callback {
40
42
public:
43
+ /* * Constructor for command with multiple paths**/
44
+ write_command (uint64_t node_id, ScopedMemoryBufferWithSize<AttributePathParams> &&attr_paths,
45
+ const char *attribute_val_str,
46
+ const chip::Optional<uint16_t > timed_write_timeout_ms = chip::NullOptional)
47
+ : m_node_id(node_id)
48
+ , m_attr_paths(std::move(attr_paths))
49
+ , m_chunked_callback(this )
50
+ , m_attr_vals(attribute_val_str)
51
+ , m_timed_write_timeout_ms(timed_write_timeout_ms)
52
+ , on_device_connected_cb(on_device_connected_fcn, this )
53
+ , on_device_connection_failure_cb(on_device_connection_failure_fcn, this )
54
+ {
55
+ }
56
+
41
57
/* * Constructor for command with an attribute path**/
42
58
write_command (uint64_t node_id, uint16_t endpoint_id, uint32_t cluster_id, uint32_t attribute_id,
43
59
const char *attribute_val_str,
44
60
const chip::Optional<uint16_t > timed_write_timeout_ms = chip::NullOptional)
45
61
: m_node_id(node_id)
46
- , m_attr_path(endpoint_id, cluster_id, attribute_id)
47
62
, m_chunked_callback(this )
48
- , m_attr_val (attribute_val_str, custom_encodable_type::interaction_type::k_write_attr )
63
+ , m_attr_vals (attribute_val_str)
49
64
, m_timed_write_timeout_ms(timed_write_timeout_ms)
50
65
, on_device_connected_cb(on_device_connected_fcn, this )
51
- , on_device_connection_failure_cb(on_device_connection_failure_fcn, this ) {}
66
+ , on_device_connection_failure_cb(on_device_connection_failure_fcn, this )
67
+ {
68
+ m_attr_paths.Alloc (1 );
69
+ if (m_attr_paths.Get ()) {
70
+ m_attr_paths[0 ] = AttributePathParams (endpoint_id, cluster_id, attribute_id);
71
+ } else {
72
+ ChipLogError (DeviceLayer, " Alloc space for attribute path failed!" );
73
+ assert (0 );
74
+ }
75
+ }
52
76
53
77
~write_command () {}
54
78
@@ -76,9 +100,9 @@ class write_command : public WriteClient::Callback {
76
100
77
101
private:
78
102
uint64_t m_node_id;
79
- AttributePathParams m_attr_path ;
103
+ ScopedMemoryBufferWithSize< AttributePathParams> m_attr_paths ;
80
104
ChunkedWriteCallback m_chunked_callback;
81
- custom_encodable_type m_attr_val ;
105
+ multiple_write_encodable_type m_attr_vals ;
82
106
chip::Optional<uint16_t > m_timed_write_timeout_ms;
83
107
84
108
static void on_device_connected_fcn (void *context, ExchangeManager &exchangeMgr,
@@ -106,5 +130,23 @@ esp_err_t send_write_attr_command(uint64_t node_id, uint16_t endpoint_id, uint32
106
130
const char *attr_val_json_str,
107
131
chip::Optional<uint16_t > timed_write_timeout_ms = chip::NullOptional);
108
132
133
+ /* * Send write attribute command to multiple attribute paths
134
+ *
135
+ * @param[in] node_id Remote NodeId
136
+ * @param[in] endpoint_ids EndpointIds
137
+ * @param[in] cluster_ids ClusterIds
138
+ * @param[in] attribute_ids AttributeIds
139
+ * @param[in] attr_val_json_str Attribute value string with JSON format
140
+ * (https://docs.espressif.com/projects/esp-matter/en/latest/esp32/developing.html#write-attribute-commands)
141
+ * @param[in] timed_write_timeout_ms Timeout in millisecond for timed-write attributes
142
+ *
143
+ * @return ESP_OK on success.
144
+ * @return error in case of failure.
145
+ */
146
+ esp_err_t send_write_attr_command (uint64_t node_id, ScopedMemoryBufferWithSize<uint16_t > &endpoint_ids,
147
+ ScopedMemoryBufferWithSize<uint32_t > &cluster_ids,
148
+ ScopedMemoryBufferWithSize<uint32_t > &attribute_ids, const char *attr_val_json_str,
149
+ chip::Optional<uint16_t > timed_write_timeout_ms = chip::NullOptional);
150
+
109
151
} // namespace controller
110
152
} // namespace esp_matter
0 commit comments