Merge branch 'delegates1' into 'main'

components/esp_matter: Add delegate apis for electric sensor clusters

See merge request app-frameworks/esp-matter!768
This commit is contained in:
Hrishikesh Dhayagude
2024-06-11 12:28:29 +08:00
5 changed files with 71 additions and 7 deletions
@@ -3693,6 +3693,10 @@ cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags, uint32_
}
if (flags & CLUSTER_FLAG_SERVER) {
if (config -> delegate != nullptr) {
static const auto delegate_init_cb = PowerTopologyDelegateInitCB;
set_delegate_and_init_callback(cluster, delegate_init_cb, config->delegate);
}
add_function_list(cluster, function_list, function_flags);
}
@@ -3742,6 +3746,10 @@ cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags, uint32_
}
if (flags & CLUSTER_FLAG_SERVER) {
if (config -> delegate != nullptr) {
static const auto delegate_init_cb = ElectricalPowerMeasurementDelegateInitCB;
set_delegate_and_init_callback(cluster, delegate_init_cb, config->delegate);
}
add_function_list(cluster, function_list, function_flags);
}
+6 -3
View File
@@ -901,7 +901,8 @@ cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags);
namespace power_topology {
typedef struct config {
uint16_t cluster_revision;
config() : cluster_revision(1) {}
void *delegate;
config() : cluster_revision(1), delegate(nullptr) {}
} config_t;
cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags, uint32_t features);
@@ -910,7 +911,8 @@ cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags, uint32_
namespace electrical_power_measurement {
typedef struct config {
uint16_t cluster_revision;
config() : cluster_revision(1) {}
void *delegate;
config() : cluster_revision(1), delegate(nullptr) {}
} config_t;
cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags, uint32_t features);
@@ -919,7 +921,8 @@ cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags, uint32_
namespace electrical_energy_measurement {
typedef struct config {
uint16_t cluster_revision;
config() : cluster_revision(1) {}
void *delegate;
config() : cluster_revision(1), delegate(nullptr) {}
} config_t;
cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags, uint32_t features);
@@ -29,6 +29,8 @@
#include <app/clusters/boolean-state-configuration-server/boolean-state-configuration-server.h>
#include <app/clusters/time-synchronization-server/time-synchronization-server.h>
#include <app/clusters/application-basic-server/application-basic-server.h>
#include <app/clusters/power-topology-server/power-topology-server.h>
#include <app/clusters/electrical-power-measurement-server/electrical-power-measurement-server.h>
using namespace chip::app::Clusters;
namespace esp_matter {
@@ -268,6 +270,35 @@ void ApplicationBasicDelegateInitCB(void *delegate, uint16_t endpoint_id)
ApplicationBasic::SetDefaultDelegate(endpoint_id, application_basic_delegate);
}
void PowerTopologyDelegateInitCB(void *delegate, uint16_t endpoint_id)
{
if(delegate == nullptr)
{
return;
}
static PowerTopology::Instance * powerTopologyInstance = nullptr;
PowerTopology::Delegate *power_topology_delegate = static_cast<PowerTopology::Delegate*>(delegate);
uint32_t feature_map = get_feature_map_value(endpoint_id, PowerTopology::Id);
powerTopologyInstance = new PowerTopology::Instance(endpoint_id, *power_topology_delegate, chip::BitMask<PowerTopology::Feature,
uint32_t>(feature_map), chip::BitMask<PowerTopology::OptionalAttributes, uint32_t>(0));
powerTopologyInstance->Init();
}
void ElectricalPowerMeasurementDelegateInitCB(void *delegate, uint16_t endpoint_id)
{
if(delegate == nullptr)
{
return;
}
static ElectricalPowerMeasurement::Instance * electricalPowerMeasurementInstance = nullptr;
ElectricalPowerMeasurement::Delegate *electrical_power_measurement_delegate = static_cast<ElectricalPowerMeasurement::Delegate*>(delegate);
uint32_t feature_map = get_feature_map_value(endpoint_id, ElectricalPowerMeasurement::Id);
electricalPowerMeasurementInstance = new ElectricalPowerMeasurement::Instance(endpoint_id, *electrical_power_measurement_delegate,
chip::BitMask<ElectricalPowerMeasurement::Feature, uint32_t>(feature_map),
chip::BitMask<ElectricalPowerMeasurement::OptionalAttributes, uint32_t>(0));
electricalPowerMeasurementInstance->Init();
}
} // namespace delegate_cb
} // namespace cluster
@@ -38,6 +38,8 @@ void DoorLockDelegateInitCB(void *delegate, uint16_t endpoint_id);
void BooleanStateConfigurationDelegateInitCB(void *delegate, uint16_t endpoint_id);
void TimeSynchronizationDelegateInitCB(void *delegate, uint16_t endpoint_id);
void ApplicationBasicDelegateInitCB(void *delegate, uint16_t endpoint_id);
void PowerTopologyDelegateInitCB(void *delegate, uint16_t endpoint_id);
void ElectricalPowerMeasurementDelegateInitCB(void *delegate, uint16_t endpoint_id);
} // namespace delegate_cb
} // namespace cluster
+24 -4
View File
@@ -130,7 +130,7 @@ ModeWaterHeater, ModeRefrigerator, ModeLaundryWasher and ModeMicrowaveOven.
9.1.10 Door Lock Cluster
------------------------
.. csv-table:: Delegate and its impl
.. csv-table::
:header: "Delegate Class", "Reference Implementation"
`Door Lock`_, None
@@ -138,7 +138,7 @@ ModeWaterHeater, ModeRefrigerator, ModeLaundryWasher and ModeMicrowaveOven.
9.1.11 Boolean State Configuration Cluster
------------------------------------------
.. csv-table:: Delegate and its impl
.. csv-table::
:header: "Delegate Class", "Reference Implementation"
`Boolean State Configuration`_, None
@@ -146,7 +146,7 @@ ModeWaterHeater, ModeRefrigerator, ModeLaundryWasher and ModeMicrowaveOven.
9.1.12 Time Synchronization Cluster
-----------------------------------
.. csv-table:: Delegate and its impl
.. csv-table::
:header: "Delegate Class", "Reference Implementation"
`Time Synchronization`_, `Time Synchronization Delegate`_
@@ -154,11 +154,27 @@ ModeWaterHeater, ModeRefrigerator, ModeLaundryWasher and ModeMicrowaveOven.
9.1.13 Application Basic Cluster
--------------------------------
.. csv-table:: Delegate and its impl
.. csv-table::
:header: "Delegate Class", "Reference Implementation"
`Application Basic`_, None
9.1.14 Power Topology Cluster
-----------------------------
.. csv-table::
:header: "Delegate Class", "Reference Implementation"
`Power Topology`_, `Power Topology Delegate`_
9.1.15 Electrical Power Measurement Cluster
-------------------------------------------
.. csv-table::
:header: "Delegate Class", "Reference Implementation"
`Electrical Power Measurement`_, `Electrical Power Measurement Delegate`_
.. note::
Make sure that after implementing delegate class, you set the delegate class pointer at the time of creating cluster.
@@ -198,3 +214,7 @@ ModeWaterHeater, ModeRefrigerator, ModeLaundryWasher and ModeMicrowaveOven.
.. _`Time Synchronization`: https://github.com/project-chip/connectedhomeip/blob/master/src/app/clusters/time-synchronization-server/time-synchronization-delegate.h
.. _`Time Synchronization Delegate`: https://github.com/project-chip/connectedhomeip/blob/master/src/app/clusters/time-synchronization-server/DefaultTimeSyncDelegate.h
.. _`Application Basic`: https://github.com/project-chip/connectedhomeip/blob/master/src/app/clusters/application-basic-server/application-basic-delegate.h
.. _`Power Topology`: https://github.com/project-chip/connectedhomeip/blob/master/src/app/clusters/power-topology-server/power-topology-server.h
.. _`Power Topology Delegate`: https://github.com/project-chip/connectedhomeip/blob/master/examples/energy-management-app/energy-management-common/include/PowerTopologyDelegate.h
.. _`Electrical Power Measurement`: https://github.com/project-chip/connectedhomeip/blob/master/src/app/clusters/electrical-power-measurement-server/electrical-power-measurement-server.h
.. _`Electrical Power Measurement Delegate`: https://github.com/project-chip/connectedhomeip/blob/master/examples/energy-management-app/energy-management-common/include/ElectricalPowerMeasurementDelegate.h