Skip to content

Commit 6a5cff3

Browse files
lpbeliveau-silabsrestyled-commitsCopilot
authored
[Electrical-Sensor] Electrical Power Measurement code driven PR#2 (project-chip#42071)
* Moved code between the backwards compatibility and the new cluster object headers * Restyled by whitespace * Restyled by clang-format * Separated the Cluster and Delegate codes * Update src/app/clusters/electrical-power-measurement-server/ElectricalPowerMeasurementDelegate.h Co-authored-by: Copilot <[email protected]> * Restyled by whitespace * Restyled by clang-format --------- Co-authored-by: Restyled.io <[email protected]> Co-authored-by: Copilot <[email protected]>
1 parent 9548aca commit 6a5cff3

File tree

5 files changed

+133
-71
lines changed

5 files changed

+133
-71
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
*
3+
* Copyright (c) 2025 Project CHIP Authors
4+
* All rights reserved.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
#pragma once
19+
20+
#include <app-common/zap-generated/cluster-objects.h>
21+
22+
namespace chip {
23+
namespace app {
24+
namespace Clusters {
25+
namespace ElectricalPowerMeasurement {
26+
27+
enum class OptionalAttributes : uint32_t
28+
{
29+
kOptionalAttributeRanges = 0x1,
30+
kOptionalAttributeVoltage = 0x2,
31+
kOptionalAttributeActiveCurrent = 0x4,
32+
kOptionalAttributeReactiveCurrent = 0x8,
33+
kOptionalAttributeApparentCurrent = 0x10,
34+
kOptionalAttributeReactivePower = 0x20,
35+
kOptionalAttributeApparentPower = 0x40,
36+
kOptionalAttributeRMSVoltage = 0x80,
37+
kOptionalAttributeRMSCurrent = 0x100,
38+
kOptionalAttributeRMSPower = 0x200,
39+
kOptionalAttributeFrequency = 0x400,
40+
kOptionalAttributePowerFactor = 0x800,
41+
kOptionalAttributeNeutralCurrent = 0x1000,
42+
};
43+
44+
} // namespace ElectricalPowerMeasurement
45+
} // namespace Clusters
46+
} // namespace app
47+
} // namespace chip
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
*
3+
* Copyright (c) 2025 Project CHIP Authors
4+
* All rights reserved.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
#pragma once
19+
20+
#include <app-common/zap-generated/cluster-objects.h>
21+
#include <lib/core/Optional.h>
22+
namespace chip {
23+
namespace app {
24+
namespace Clusters {
25+
namespace ElectricalPowerMeasurement {
26+
27+
class Delegate
28+
{
29+
public:
30+
virtual ~Delegate() = default;
31+
32+
void SetEndpointId(EndpointId aEndpoint) { mEndpointId = aEndpoint; }
33+
34+
virtual PowerModeEnum GetPowerMode() = 0;
35+
virtual uint8_t GetNumberOfMeasurementTypes() = 0;
36+
37+
/* These functions are called by the ReadAttribute handler to iterate through lists
38+
* The cluster server will call Start<Type>Read to allow the delegate to create a temporary
39+
* lock on the data.
40+
* The delegate is expected to not change these values once Start<Type>Read has been called
41+
* until the End<Type>Read() has been called (e.g. releasing a lock on the data)
42+
*/
43+
virtual CHIP_ERROR StartAccuracyRead() = 0;
44+
virtual CHIP_ERROR GetAccuracyByIndex(uint8_t, Structs::MeasurementAccuracyStruct::Type &) = 0;
45+
virtual CHIP_ERROR EndAccuracyRead() = 0;
46+
47+
virtual CHIP_ERROR StartRangesRead() = 0;
48+
virtual CHIP_ERROR GetRangeByIndex(uint8_t, Structs::MeasurementRangeStruct::Type &) = 0;
49+
virtual CHIP_ERROR EndRangesRead() = 0;
50+
51+
virtual CHIP_ERROR StartHarmonicCurrentsRead() = 0;
52+
virtual CHIP_ERROR GetHarmonicCurrentsByIndex(uint8_t, Structs::HarmonicMeasurementStruct::Type &) = 0;
53+
virtual CHIP_ERROR EndHarmonicCurrentsRead() = 0;
54+
55+
virtual CHIP_ERROR StartHarmonicPhasesRead() = 0;
56+
virtual CHIP_ERROR GetHarmonicPhasesByIndex(uint8_t, Structs::HarmonicMeasurementStruct::Type &) = 0;
57+
virtual CHIP_ERROR EndHarmonicPhasesRead() = 0;
58+
59+
virtual DataModel::Nullable<int64_t> GetVoltage() = 0;
60+
virtual DataModel::Nullable<int64_t> GetActiveCurrent() = 0;
61+
virtual DataModel::Nullable<int64_t> GetReactiveCurrent() = 0;
62+
virtual DataModel::Nullable<int64_t> GetApparentCurrent() = 0;
63+
virtual DataModel::Nullable<int64_t> GetActivePower() = 0;
64+
virtual DataModel::Nullable<int64_t> GetReactivePower() = 0;
65+
virtual DataModel::Nullable<int64_t> GetApparentPower() = 0;
66+
virtual DataModel::Nullable<int64_t> GetRMSVoltage() = 0;
67+
virtual DataModel::Nullable<int64_t> GetRMSCurrent() = 0;
68+
virtual DataModel::Nullable<int64_t> GetRMSPower() = 0;
69+
virtual DataModel::Nullable<int64_t> GetFrequency() = 0;
70+
virtual DataModel::Nullable<int64_t> GetPowerFactor() = 0;
71+
virtual DataModel::Nullable<int64_t> GetNeutralCurrent() = 0;
72+
73+
protected:
74+
EndpointId mEndpointId = 0;
75+
};
76+
77+
} // namespace ElectricalPowerMeasurement
78+
} // namespace Clusters
79+
} // namespace app
80+
} // namespace chip

src/app/clusters/electrical-power-measurement-server/app_config_dependent_sources.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,7 @@ TARGET_SOURCES(
1717
${APP_TARGET}
1818
PRIVATE
1919
"${CLUSTER_DIR}/ElectricalPowerMeasurementCluster.cpp"
20+
"${CLUSTER_DIR}/ElectricalPowerMeasurementCluster.h"
21+
"${CLUSTER_DIR}/ElectricalPowerMeasurementDelegate.h"
2022
"${CLUSTER_DIR}/electrical-power-measurement-server.h"
2123
)

src/app/clusters/electrical-power-measurement-server/app_config_dependent_sources.gni

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,7 @@
1313
# limitations under the License.
1414
app_config_dependent_sources = [
1515
"ElectricalPowerMeasurementCluster.cpp",
16+
"ElectricalPowerMeasurementCluster.h",
17+
"ElectricalPowerMeasurementDelegate.h",
1618
"electrical-power-measurement-server.h",
1719
]

src/app/clusters/electrical-power-measurement-server/electrical-power-measurement-server.h

Lines changed: 2 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -17,84 +17,15 @@
1717
*/
1818
#pragma once
1919

20-
#include <lib/core/Optional.h>
21-
22-
#include <app-common/zap-generated/cluster-objects.h>
20+
#include "ElectricalPowerMeasurementCluster.h"
21+
#include "ElectricalPowerMeasurementDelegate.h"
2322
#include <app/AttributeAccessInterface.h>
24-
#include <protocols/interaction_model/StatusCode.h>
2523

2624
namespace chip {
2725
namespace app {
2826
namespace Clusters {
2927
namespace ElectricalPowerMeasurement {
3028

31-
class Delegate
32-
{
33-
public:
34-
virtual ~Delegate() = default;
35-
36-
void SetEndpointId(EndpointId aEndpoint) { mEndpointId = aEndpoint; }
37-
38-
virtual PowerModeEnum GetPowerMode() = 0;
39-
virtual uint8_t GetNumberOfMeasurementTypes() = 0;
40-
41-
/* These functions are called by the ReadAttribute handler to iterate through lists
42-
* The cluster server will call Start<Type>Read to allow the delegate to create a temporary
43-
* lock on the data.
44-
* The delegate is expected to not change these values once Start<Type>Read has been called
45-
* until the End<Type>Read() has been called (e.g. releasing a lock on the data)
46-
*/
47-
virtual CHIP_ERROR StartAccuracyRead() = 0;
48-
virtual CHIP_ERROR GetAccuracyByIndex(uint8_t, Structs::MeasurementAccuracyStruct::Type &) = 0;
49-
virtual CHIP_ERROR EndAccuracyRead() = 0;
50-
51-
virtual CHIP_ERROR StartRangesRead() = 0;
52-
virtual CHIP_ERROR GetRangeByIndex(uint8_t, Structs::MeasurementRangeStruct::Type &) = 0;
53-
virtual CHIP_ERROR EndRangesRead() = 0;
54-
55-
virtual CHIP_ERROR StartHarmonicCurrentsRead() = 0;
56-
virtual CHIP_ERROR GetHarmonicCurrentsByIndex(uint8_t, Structs::HarmonicMeasurementStruct::Type &) = 0;
57-
virtual CHIP_ERROR EndHarmonicCurrentsRead() = 0;
58-
59-
virtual CHIP_ERROR StartHarmonicPhasesRead() = 0;
60-
virtual CHIP_ERROR GetHarmonicPhasesByIndex(uint8_t, Structs::HarmonicMeasurementStruct::Type &) = 0;
61-
virtual CHIP_ERROR EndHarmonicPhasesRead() = 0;
62-
63-
virtual DataModel::Nullable<int64_t> GetVoltage() = 0;
64-
virtual DataModel::Nullable<int64_t> GetActiveCurrent() = 0;
65-
virtual DataModel::Nullable<int64_t> GetReactiveCurrent() = 0;
66-
virtual DataModel::Nullable<int64_t> GetApparentCurrent() = 0;
67-
virtual DataModel::Nullable<int64_t> GetActivePower() = 0;
68-
virtual DataModel::Nullable<int64_t> GetReactivePower() = 0;
69-
virtual DataModel::Nullable<int64_t> GetApparentPower() = 0;
70-
virtual DataModel::Nullable<int64_t> GetRMSVoltage() = 0;
71-
virtual DataModel::Nullable<int64_t> GetRMSCurrent() = 0;
72-
virtual DataModel::Nullable<int64_t> GetRMSPower() = 0;
73-
virtual DataModel::Nullable<int64_t> GetFrequency() = 0;
74-
virtual DataModel::Nullable<int64_t> GetPowerFactor() = 0;
75-
virtual DataModel::Nullable<int64_t> GetNeutralCurrent() = 0;
76-
77-
protected:
78-
EndpointId mEndpointId = 0;
79-
};
80-
81-
enum class OptionalAttributes : uint32_t
82-
{
83-
kOptionalAttributeRanges = 0x1,
84-
kOptionalAttributeVoltage = 0x2,
85-
kOptionalAttributeActiveCurrent = 0x4,
86-
kOptionalAttributeReactiveCurrent = 0x8,
87-
kOptionalAttributeApparentCurrent = 0x10,
88-
kOptionalAttributeReactivePower = 0x20,
89-
kOptionalAttributeApparentPower = 0x40,
90-
kOptionalAttributeRMSVoltage = 0x80,
91-
kOptionalAttributeRMSCurrent = 0x100,
92-
kOptionalAttributeRMSPower = 0x200,
93-
kOptionalAttributeFrequency = 0x400,
94-
kOptionalAttributePowerFactor = 0x800,
95-
kOptionalAttributeNeutralCurrent = 0x1000,
96-
};
97-
9829
class Instance : public AttributeAccessInterface
9930
{
10031
public:

0 commit comments

Comments
 (0)