diff --git a/components/esp_matter/esp_matter_cluster.cpp b/components/esp_matter/esp_matter_cluster.cpp index e9e9c4232..5c226e335 100644 --- a/components/esp_matter/esp_matter_cluster.cpp +++ b/components/esp_matter/esp_matter_cluster.cpp @@ -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); } diff --git a/components/esp_matter/esp_matter_cluster.h b/components/esp_matter/esp_matter_cluster.h index 8cdeb176d..73e1b9c6b 100644 --- a/components/esp_matter/esp_matter_cluster.h +++ b/components/esp_matter/esp_matter_cluster.h @@ -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); diff --git a/components/esp_matter/esp_matter_delegate_callbacks.cpp b/components/esp_matter/esp_matter_delegate_callbacks.cpp index bc20ffc47..48aa231e9 100644 --- a/components/esp_matter/esp_matter_delegate_callbacks.cpp +++ b/components/esp_matter/esp_matter_delegate_callbacks.cpp @@ -29,6 +29,8 @@ #include #include #include +#include +#include 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(delegate); + uint32_t feature_map = get_feature_map_value(endpoint_id, PowerTopology::Id); + powerTopologyInstance = new PowerTopology::Instance(endpoint_id, *power_topology_delegate, chip::BitMask(feature_map), chip::BitMask(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(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(feature_map), + chip::BitMask(0)); + electricalPowerMeasurementInstance->Init(); +} + } // namespace delegate_cb } // namespace cluster diff --git a/components/esp_matter/esp_matter_delegate_callbacks.h b/components/esp_matter/esp_matter_delegate_callbacks.h index 0e8ac156a..26b979e8c 100644 --- a/components/esp_matter/esp_matter_delegate_callbacks.h +++ b/components/esp_matter/esp_matter_delegate_callbacks.h @@ -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 diff --git a/docs/en/app_guide.rst b/docs/en/app_guide.rst index 0e3552c31..453826215 100644 --- a/docs/en/app_guide.rst +++ b/docs/en/app_guide.rst @@ -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