Skip to content

Commit c7513a1

Browse files
committed
Merge branch 'delegate/door-lock' into 'main'
components/esp-matter: Add delegate for door-lock,... See merge request app-frameworks/esp-matter!761
2 parents 753dc3e + 949c589 commit c7513a1

7 files changed

+243
-5
lines changed

components/esp_matter/esp_matter_attribute.cpp

+62
Original file line numberDiff line numberDiff line change
@@ -4738,5 +4738,67 @@ attribute_t *create_opt_out_state(cluster_t *cluster, uint8_t value)
47384738
} /* attribute */
47394739
} /* device_energy_management */
47404740

4741+
namespace application_basic {
4742+
namespace attribute {
4743+
attribute_t *create_vendor_name(cluster_t *cluster, char *value, uint16_t length)
4744+
{
4745+
if (length > k_max_vendor_name_length) {
4746+
ESP_LOGE(TAG, "Could not create attribute, string length out of bound");
4747+
return NULL;
4748+
}
4749+
return esp_matter::attribute::create(cluster, ApplicationBasic::Attributes::VendorName::Id, ATTRIBUTE_FLAG_NONE,
4750+
esp_matter_char_str(value, length), k_max_vendor_name_length);
4751+
}
4752+
4753+
attribute_t *create_vendor_id(cluster_t *cluster, uint16_t value)
4754+
{
4755+
return esp_matter::attribute::create(cluster, ApplicationBasic::Attributes::VendorID::Id, ATTRIBUTE_FLAG_NONE,
4756+
esp_matter_uint16(value));
4757+
}
4758+
4759+
attribute_t *create_application_name(cluster_t *cluster, char *value, uint16_t length)
4760+
{
4761+
return esp_matter::attribute::create(cluster, ApplicationBasic::Attributes::ApplicationName::Id, ATTRIBUTE_FLAG_NONE,
4762+
esp_matter_char_str(value, length));
4763+
}
4764+
4765+
attribute_t *create_product_id(cluster_t *cluster, uint16_t value)
4766+
{
4767+
return esp_matter::attribute::create(cluster, ApplicationBasic::Attributes::ProductID::Id, ATTRIBUTE_FLAG_NONE,
4768+
esp_matter_uint16(value));
4769+
}
4770+
4771+
attribute_t *create_application(cluster_t *cluster, uint8_t *value, uint16_t length, uint16_t count)
4772+
{
4773+
return esp_matter::attribute::create(cluster, ApplicationBasic::Attributes::Application::Id, ATTRIBUTE_FLAG_NONE,
4774+
esp_matter_array(value, length, count));
4775+
}
4776+
4777+
attribute_t *create_status(cluster_t *cluster, uint8_t value)
4778+
{
4779+
return esp_matter::attribute::create(cluster, ApplicationBasic::Attributes::Status::Id, ATTRIBUTE_FLAG_NONE,
4780+
esp_matter_enum8(value));
4781+
}
4782+
4783+
attribute_t *create_application_version(cluster_t *cluster, char *value, uint16_t length)
4784+
{
4785+
if (length > k_max_application_version_length) {
4786+
ESP_LOGE(TAG, "Could not create attribute, string length out of bound");
4787+
return NULL;
4788+
}
4789+
return esp_matter::attribute::create(cluster, ApplicationBasic::Attributes::ApplicationVersion::Id,
4790+
ATTRIBUTE_FLAG_NONE, esp_matter_char_str(value, length),
4791+
k_max_application_version_length);
4792+
}
4793+
4794+
attribute_t *create_allowed_vendor_list(cluster_t *cluster, uint8_t *value, uint16_t length, uint16_t count)
4795+
{
4796+
return esp_matter::attribute::create(cluster, ApplicationBasic::Attributes::AllowedVendorList::Id, ATTRIBUTE_FLAG_NONE,
4797+
esp_matter_array(value, length, count));
4798+
}
4799+
4800+
} /* attribute */
4801+
} /* application_basic */
4802+
47414803
} /* cluster */
47424804
} /* esp_matter */

components/esp_matter/esp_matter_attribute.h

+16
Original file line numberDiff line numberDiff line change
@@ -1090,5 +1090,21 @@ attribute_t *create_opt_out_state(cluster_t *cluster, uint8_t value);
10901090
} /* attribute */
10911091
} /* device_energy_management */
10921092

1093+
namespace application_basic {
1094+
constexpr uint8_t k_max_vendor_name_length = 32;
1095+
constexpr uint8_t k_max_application_version_length = 32;
1096+
1097+
namespace attribute {
1098+
attribute_t *create_vendor_name(cluster_t *cluster, char *value, uint16_t length);
1099+
attribute_t *create_vendor_id(cluster_t *cluster, uint16_t value);
1100+
attribute_t *create_application_name(cluster_t *cluster, char *value, uint16_t length);
1101+
attribute_t *create_product_id(cluster_t *cluster, uint16_t value);
1102+
attribute_t *create_application(cluster_t *cluster, uint8_t *value, uint16_t length, uint16_t count);
1103+
attribute_t *create_status(cluster_t *cluster, uint16_t value);
1104+
attribute_t *create_application_version(cluster_t *cluster, char *value, uint16_t length);
1105+
attribute_t *create_allowed_vendor_list(cluster_t *cluster, uint8_t *value, uint16_t length, uint16_t count);
1106+
} /* attribute */
1107+
} /* application_basic */
1108+
10931109
} /* cluster */
10941110
} /* esp_matter */

components/esp_matter/esp_matter_cluster.cpp

+60
Original file line numberDiff line numberDiff line change
@@ -871,6 +871,10 @@ cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags)
871871
}
872872

873873
if (flags & CLUSTER_FLAG_SERVER) {
874+
if (config -> delegate != nullptr) {
875+
static const auto delegate_init_cb = TimeSynchronizationDelegateInitCB;
876+
set_delegate_and_init_callback(cluster, delegate_init_cb, config->delegate);
877+
}
874878
static const auto plugin_server_init_cb = CALL_ONCE(MatterTimeSynchronizationPluginServerInitCallback);
875879
set_plugin_server_init_callback(cluster, plugin_server_init_cb);
876880
add_function_list(cluster, function_list, function_flags);
@@ -2530,6 +2534,10 @@ cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags)
25302534
}
25312535

25322536
if (flags & CLUSTER_FLAG_SERVER) {
2537+
if (config && config -> delegate != nullptr) {
2538+
static const auto delegate_init_cb = DoorLockDelegateInitCB;
2539+
set_delegate_and_init_callback(cluster, delegate_init_cb, config->delegate);
2540+
}
25332541
static const auto plugin_server_init_cb = CALL_ONCE(MatterDoorLockPluginServerInitCallback);
25342542
set_plugin_server_init_callback(cluster, plugin_server_init_cb);
25352543
add_function_list(cluster, function_list, function_flags);
@@ -2854,6 +2862,10 @@ cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags, uint32_
28542862
}
28552863

28562864
if (flags & CLUSTER_FLAG_SERVER) {
2865+
if (config && config -> delegate != nullptr) {
2866+
static const auto delegate_init_cb = BooleanStateConfigurationDelegateInitCB;
2867+
set_delegate_and_init_callback(cluster, delegate_init_cb, config->delegate);
2868+
}
28572869
static const auto plugin_server_init_cb = CALL_ONCE(MatterBooleanStateConfigurationPluginServerInitCallback);
28582870
set_plugin_server_init_callback(cluster, plugin_server_init_cb);
28592871
add_function_list(cluster, function_list, function_flags);
@@ -4122,6 +4134,54 @@ cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags)
41224134
}
41234135
} /* device_energy_management_mode */
41244136

4137+
namespace application_basic {
4138+
const function_generic_t *function_list = NULL;
4139+
const int function_flags = CLUSTER_FLAG_NONE;
4140+
4141+
cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags, uint32_t features)
4142+
{
4143+
cluster_t *cluster = cluster::create(endpoint, ApplicationBasic::Id, flags);
4144+
if (!cluster) {
4145+
ESP_LOGE(TAG, "Could not create cluster");
4146+
return NULL;
4147+
}
4148+
if (flags & CLUSTER_FLAG_SERVER) {
4149+
if (config -> delegate != nullptr) {
4150+
static const auto delegate_init_cb = ApplicationBasicDelegateInitCB;
4151+
set_delegate_and_init_callback(cluster, delegate_init_cb, config->delegate);
4152+
}
4153+
static const auto plugin_server_init_cb = CALL_ONCE(MatterApplicationBasicPluginServerInitCallback);
4154+
set_plugin_server_init_callback(cluster, plugin_server_init_cb);
4155+
add_function_list(cluster, function_list, function_flags);
4156+
}
4157+
if (flags & CLUSTER_FLAG_CLIENT) {
4158+
create_default_binding_cluster(endpoint);
4159+
}
4160+
4161+
if (flags & CLUSTER_FLAG_SERVER) {
4162+
/* Attributes managed internally */
4163+
global::attribute::create_feature_map(cluster, 0);
4164+
#if CHIP_CONFIG_ENABLE_EVENTLIST_ATTRIBUTE
4165+
global::attribute::create_event_list(cluster, NULL, 0, 0);
4166+
#endif
4167+
4168+
/* Attributes should managed by application */
4169+
attribute::create_application_name(cluster, NULL, 0);
4170+
attribute::create_application(cluster, NULL, 0 , 0);
4171+
attribute::create_status(cluster, 0);
4172+
attribute::create_application_version(cluster, NULL, 0);
4173+
attribute::create_allowed_vendor_list(cluster, NULL, 0 , 0);
4174+
/** Attributes not managed internally **/
4175+
if (config) {
4176+
global::attribute::create_cluster_revision(cluster, config->cluster_revision);
4177+
} else {
4178+
ESP_LOGE(TAG, "Config is NULL. Cannot add some attributes.");
4179+
}
4180+
}
4181+
return cluster;
4182+
}
4183+
} /* application_basic */
4184+
41254185
// namespace binary_input_basic {
41264186
// // ToDo
41274187
// } /* binary_input_basic */

components/esp_matter/esp_matter_cluster.h

+16-3
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,8 @@ cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags);
217217
namespace time_synchronization {
218218
typedef struct config {
219219
uint16_t cluster_revision;
220-
config() : cluster_revision(2) {}
220+
void *delegate;
221+
config() : cluster_revision(2), delegate(nullptr) {}
221222
} config_t;
222223

223224
cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags);
@@ -613,7 +614,8 @@ typedef struct config {
613614
bool actuator_enabled;
614615
uint8_t operating_mode;
615616
uint16_t supported_operating_modes;
616-
config() : cluster_revision(7), lock_state(0), lock_type(0), actuator_enabled(0), operating_mode(0), supported_operating_modes(0xFFF6) {}
617+
void *delegate;
618+
config() : cluster_revision(7), lock_state(0), lock_type(0), actuator_enabled(0), operating_mode(0), supported_operating_modes(0xFFF6), delegate(nullptr) {}
617619
} config_t;
618620

619621
cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags);
@@ -699,7 +701,8 @@ typedef struct config {
699701
feature::audible::config_t audible;
700702
feature::alarm_suppress::config_t alarm_suppress;
701703
feature::sensitivity_level::config_t sensitivity_level;
702-
config() : cluster_revision(1) {}
704+
void *delegate;
705+
config() : cluster_revision(1), delegate(nullptr) {}
703706
} config_t;
704707

705708
cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags, uint32_t features);
@@ -980,5 +983,15 @@ typedef struct config {
980983
cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags);
981984
} /* device_energy_management_mode */
982985

986+
namespace application_basic {
987+
typedef struct config {
988+
uint16_t cluster_revision;
989+
void *delegate;
990+
config() : cluster_revision(1), delegate(nullptr) {}
991+
} config_t;
992+
993+
cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags);
994+
} /* application_basic */
995+
983996
} /* cluster */
984997
} /* esp_matter */

components/esp_matter/esp_matter_delegate_callbacks.cpp

+44
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525
#include <app/clusters/laundry-dryer-controls-server/laundry-dryer-controls-server.h>
2626
#include <app/clusters/valve-configuration-and-control-server/valve-configuration-and-control-server.h>
2727
#include <app/clusters/device-energy-management-server/device-energy-management-server.h>
28+
#include <app/clusters/door-lock-server/door-lock-server.h>
29+
#include <app/clusters/boolean-state-configuration-server/boolean-state-configuration-server.h>
30+
#include <app/clusters/time-synchronization-server/time-synchronization-server.h>
31+
#include <app/clusters/application-basic-server/application-basic-server.h>
2832

2933
using namespace chip::app::Clusters;
3034
namespace esp_matter {
@@ -224,6 +228,46 @@ void DeviceEnergyManagementDelegateInitCB(void *delegate, uint16_t endpoint_id)
224228
deviceEnergyManagementInstance->Init();
225229
}
226230

231+
void DoorLockDelegateInitCB(void *delegate, uint16_t endpoint_id)
232+
{
233+
if(delegate == nullptr)
234+
{
235+
return;
236+
}
237+
DoorLock::Delegate *door_lock_delegate = static_cast<DoorLock::Delegate*>(delegate);
238+
DoorLock::SetDefaultDelegate(endpoint_id, door_lock_delegate);
239+
}
240+
241+
void BooleanStateConfigurationDelegateInitCB(void *delegate, uint16_t endpoint_id)
242+
{
243+
if(delegate == nullptr)
244+
{
245+
return;
246+
}
247+
BooleanStateConfiguration::Delegate *boolean_state_configuration_delegate = static_cast<BooleanStateConfiguration::Delegate*>(delegate);
248+
BooleanStateConfiguration::SetDefaultDelegate(endpoint_id, boolean_state_configuration_delegate);
249+
}
250+
251+
void TimeSynchronizationDelegateInitCB(void *delegate, uint16_t endpoint_id)
252+
{
253+
if(delegate == nullptr)
254+
{
255+
return;
256+
}
257+
TimeSynchronization::Delegate *time_synchronization_delegate = static_cast<TimeSynchronization::Delegate*>(delegate);
258+
TimeSynchronization::SetDefaultDelegate(time_synchronization_delegate);
259+
}
260+
261+
void ApplicationBasicDelegateInitCB(void *delegate, uint16_t endpoint_id)
262+
{
263+
if(delegate == nullptr)
264+
{
265+
return;
266+
}
267+
ApplicationBasic::Delegate *application_basic_delegate = static_cast<ApplicationBasic::Delegate*>(delegate);
268+
ApplicationBasic::SetDefaultDelegate(endpoint_id, application_basic_delegate);
269+
}
270+
227271
} // namespace delegate_cb
228272

229273
} // namespace cluster

components/esp_matter/esp_matter_delegate_callbacks.h

+4
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ void LaundryDryerControlsDelegateInitCB(void *delegate, uint16_t endpoint_id);
3434
void ValveConfigurationAndControlDelegateInitCB(void *delegate, uint16_t endpoint_id);
3535
void DeviceEnergyManagementDelegateInitCB(void *delegate, uint16_t endpoint_id);
3636
void DeviceEnergyManagementModeDelegateInitCB(void *delegate, uint16_t endpoint_id);
37+
void DoorLockDelegateInitCB(void *delegate, uint16_t endpoint_id);
38+
void BooleanStateConfigurationDelegateInitCB(void *delegate, uint16_t endpoint_id);
39+
void TimeSynchronizationDelegateInitCB(void *delegate, uint16_t endpoint_id);
40+
void ApplicationBasicDelegateInitCB(void *delegate, uint16_t endpoint_id);
3741
} // namespace delegate_cb
3842

3943
} // namespace cluster

docs/en/app_guide.rst

+41-2
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ ModeWaterHeater, ModeRefrigerator, ModeLaundryWasher and ModeMicrowaveOven.
8484
.. csv-table:: Delegate and its impl
8585
:header: "Delegate Class", "Reference Implementation"
8686

87-
`Microwave Oven Control`_, None
87+
`Microwave Oven Control`_, `Microwave Oven Control Delegate`_
8888

8989
9.1.5 Fan Control Cluster
9090
-------------------------
@@ -117,7 +117,7 @@ ModeWaterHeater, ModeRefrigerator, ModeLaundryWasher and ModeMicrowaveOven.
117117
.. csv-table:: Delegate and its impl
118118
:header: "Delegate Class", "Reference Implementation"
119119

120-
`Valve Configuration And Control`_, None
120+
`Valve Configuration And Control`_, `Valve Configuration And Control Delegate`_
121121

122122
9.1.9 Device Energy Management Cluster
123123
--------------------------------------
@@ -127,6 +127,38 @@ ModeWaterHeater, ModeRefrigerator, ModeLaundryWasher and ModeMicrowaveOven.
127127

128128
`Device Energy Management`_, `Device Energy Management Delegate`_
129129

130+
9.1.10 Door Lock Cluster
131+
------------------------
132+
133+
.. csv-table:: Delegate and its impl
134+
:header: "Delegate Class", "Reference Implementation"
135+
136+
`Door Lock`_, None
137+
138+
9.1.11 Boolean State Configuration Cluster
139+
------------------------------------------
140+
141+
.. csv-table:: Delegate and its impl
142+
:header: "Delegate Class", "Reference Implementation"
143+
144+
`Boolean State Configuration`_, None
145+
146+
9.1.12 Time Synchronization Cluster
147+
-----------------------------------
148+
149+
.. csv-table:: Delegate and its impl
150+
:header: "Delegate Class", "Reference Implementation"
151+
152+
`Time Synchronization`_, `Time Synchronization Delegate`_
153+
154+
9.1.13 Application Basic Cluster
155+
--------------------------------
156+
157+
.. csv-table:: Delegate and its impl
158+
:header: "Delegate Class", "Reference Implementation"
159+
160+
`Application Basic`_, None
161+
130162

131163
.. note::
132164
Make sure that after implementing delegate class, you set the delegate class pointer at the time of creating cluster.
@@ -150,12 +182,19 @@ ModeWaterHeater, ModeRefrigerator, ModeLaundryWasher and ModeMicrowaveOven.
150182
.. _`Operational State`: https://github.com/project-chip/connectedhomeip/blob/master/src/app/clusters/operational-state-server/operational-state-server.h
151183
.. _`Operational State Delegate`: https://github.com/project-chip/connectedhomeip/blob/master/examples/all-clusters-app/all-clusters-common/include/operational-state-delegate-impl.h
152184
.. _`Microwave Oven Control`: https://github.com/project-chip/connectedhomeip/blob/master/src/app/clusters/microwave-oven-control-server/microwave-oven-control-server.h
185+
.. _`Microwave Oven Control Delegate`: https://github.com/project-chip/connectedhomeip/blob/master/microwave-oven-app/microwave-oven-common/include/microwave-oven-device.h
153186
.. _`Fan Control`: https://github.com/project-chip/connectedhomeip/blob/master/src/app/clusters/fan-control-server/fan-control-delegate.h
154187
.. _`Fan Control Delegate`: https://github.com/project-chip/connectedhomeip/blob/master/examples/all-clusters-app/all-clusters-common/src/fan-stub.cpp
155188
.. _`Resource Monitoring`: https://github.com/project-chip/connectedhomeip/blob/master/src/app/clusters/resource-monitoring-server/resource-monitoring-server.h
156189
.. _`Resource Monitoring Delegate`: https://github.com/project-chip/connectedhomeip/blob/master/examples/all-clusters-app/all-clusters-common/include/resource-monitoring-delegates.h
157190
.. _`Laundry Dryer Controls`: https://github.com/project-chip/connectedhomeip/blob/master/src/app/clusters/laundry-dryer-controls-server/laundry-dryer-controls-server.h
158191
.. _`Laundry Dryer Controls Delegate`: https://github.com/project-chip/connectedhomeip/blob/master/examples/all-clusters-app/all-clusters-common/include/laundry-dryer-controls-delegate-impl.h
159192
.. _`Valve Configuration And Control`: https://github.com/project-chip/connectedhomeip/blob/master/src/app/clusters/valve-configuration-and-control-server/valve-configuration-and-control-delegate.h
193+
.. _`Valve Configuration And Control Delegate`: https://github.com/project-chip/connectedhomeip/blob/master/all-clusters-app/linux/ValveControlDelegate.h
160194
.. _`Device Energy Management`: https://github.com/project-chip/connectedhomeip/blob/master/src/app/clusters/device-energy-management-server/device-energy-management-server.h
161195
.. _`Device Energy Management Delegate`: https://github.com/project-chip/connectedhomeip/blob/master/examples/energy-management-app/energy-management-common/include/DeviceEnergyManagementDelegateImpl.h
196+
.. _`Door Lock`: https://github.com/project-chip/connectedhomeip/blob/master/src/app/clusters/door-lock-server/door-lock-delegate.h
197+
.. _`Boolean State Configuration`: https://github.com/project-chip/connectedhomeip/blob/master/src/app/clusters/boolean-state-configuration-server/boolean-state-configuration-delegate.h
198+
.. _`Time Synchronization`: https://github.com/project-chip/connectedhomeip/blob/master/src/app/clusters/time-synchronization-server/time-synchronization-delegate.h
199+
.. _`Time Synchronization Delegate`: https://github.com/project-chip/connectedhomeip/blob/master/src/app/clusters/time-synchronization-server/DefaultTimeSyncDelegate.h
200+
.. _`Application Basic`: https://github.com/project-chip/connectedhomeip/blob/master/src/app/clusters/application-basic-server/application-basic-delegate.h

0 commit comments

Comments
 (0)