Skip to content

Commit

Permalink
Add Electrical power measurement to energy management app (project-ch…
Browse files Browse the repository at this point in the history
…ip#31616)

* Hoist shared enums and bitmaps into detail namespace

* Regenerate

* Add electrical measurement clusters

* Add NumberOfMeasurements attribute

* Bump to latest spec

* Bump ZAP version

* Remove Electrical Measurement cluster

* Add initial Electrical Power Measurement cluster implementation

* Revert "Remove Electrical Measurement cluster"

This reverts commit 47f5298.

* Fix incorrect min/max values on energy attributes

* Formatting electrical-power-measurement-server

* Regen after restoring deprecated electrical measurement cluster

* Re-add inexplicably important blank line to zap_execution.py

* De-alphabetize list of files to avoid breaking GH action

* Semi-realphabetize?

* Added EPM cluster to Energy Management App

* Restore strangely dropped events

* Better BitMask handling

* Change min/max on electrical measurements to be decimal instead of hex

* Rename meas-and-sense to measurement-and-sensing.xml

* Remove seemingly superfluous attribute requirements on Descriptor cluster on Electrical Measurement

* Updates to electrical-power-measurement-server based on comments

* Take all-clusters-zap from upstream-master.

* Added side=server into electrical-power and electrical-energy clusters XML so events can be enabled in ZAP

* Updated all-clusters.zap and reran autogen. Added EPM cluster to energy-management-app.zap

* Added initial version of EPM delegate and instance to energy-management-app

* Enabled Electrical Energy Measurement in example-energy-management-app ZAP and regen all.

* Added ElectricalEnergyMeasurement to chip-repl __init__.py

* Restyled by isort

* Changed feature map to indicate CUME and IMP support only

* Adding into __all__ some missing clusters which are causing flake8 issues.

* Removed out of date comment

* Added a test event trigger to fake energy reporting readings into the EEM cluster (hooks ready for EPM cluster)

* Added new Energy Reporting TE Trigger delegate

* Updated random calculation and scaled into mWh (divide by 3600)

* Restyled by whitespace

* Restyled by gn

* Removed accidental launch.json inclusion

* Fix for ARM linux etc builds due to gn dependency check error

* Added code review suggestions.

* More code review suggestions fixed.

* Hoist shared enums and bitmaps into detail namespace

* Regenerate

* Add electrical measurement clusters

* Add NumberOfMeasurements attribute

* Bump to latest spec

* Bump ZAP version

* Remove Electrical Measurement cluster

* Add initial Electrical Power Measurement cluster implementation

* Revert "Remove Electrical Measurement cluster"

This reverts commit 47f5298.

* Fix incorrect min/max values on energy attributes

* Formatting electrical-power-measurement-server

* Regen after restoring deprecated electrical measurement cluster

* Re-add inexplicably important blank line to zap_execution.py

* De-alphabetize list of files to avoid breaking GH action

* Semi-realphabetize?

* Restore strangely dropped events

* Better BitMask handling

* Change min/max on electrical measurements to be decimal instead of hex

* Rename meas-and-sense to measurement-and-sensing.xml

* Remove seemingly superfluous attribute requirements on Descriptor cluster on Electrical Measurement

* Updates to electrical-power-measurement-server based on comments

* Remove defaults from MeasurementAccuracyRangeStruct to match spec update

* Restore side="server" to events

* Move common enums and bitmaps to detail:: instead of detail::Enums and detail::Bitmaps; remove superfluous using statement

* Assign ID to Electrical Sensor device type

* Removed EPM and EEM from Root Node Device

* Restyled formatting is different than clang-format

* Re-add FeatureMap to attributeAccessInterfaceAttributes for EEM and EPM

* Regen after merge

* Added electrical-energy-measurement-server to CMakelist to fix linker issue.

* Lock client on Electrical Sensor device type

* Remove unneeded using statement now that Enums are in detail::

* Check for null iterators and error

* Switch to ResourceExhausted from CHIP_ERROR_INTERNAL

* Re-enabled EEM in energy management app and regen all after previous merge

* Some refactoring to add EPM Instance into the EVSEManufacturer class to clean up containment. Added ability to fake voltage, power and current to the TE triggers.

* Missed one file.

* Fixed crash due to unassigned dg pointer. Power/Voltage/Current faking working too.

* Touch file since restyled crashed

* Restyled by gn

* Restyled by isort

* Add stub for EPM cluster

* Reverted whitespace change

* Did regen_all after merge from master to resolve conflicts.

* Put back line of clusters which somehow got deleted accidentally.

* Remerged ZAP file and regen all after resolving conflicts.

* Fixes for Python tests

* Correct name for Ember init callback

* Formatting

* Sync optional attributes list with .zap file for EPM

* Add missing features to EPM stub

* Revert FeatureMap in attributeAccessInterfaceAttributes

* Allow FeatureMap in EEM constructor; add all-clusters-app EEM stub

* Forgot zcl-with-test-extensions

* Unregister EEM attribute access in destructor

* Remove redundant returns to keep clang-tidy happy

* Fix for issue mentioned in code review on EEM cluster limiting the number of endpoints it allows.

* Refactoring to have a common EvseMain across all platforms to avoid making changes in multiple places

* Added electrical-power-measurement-server to ESP32 CMakeLists.txt

* Updated Matter device types to add EVSE

* Open and saved energy-management-app.zap and regen_all

* Removed duplicate ElectricalEnergyMeasurment class which was accidentally merged in. Fixed issue raised about ElectricalEnergyMeasurement array size not working on bridges.

* Added support for test event triggers and handling of reading events into matter_testing_support.

* Made TC_EEVSE_Utils.py use the matter_testing_support instead of its own local copy.

* Restyled by isort

* Cherry pick from Tweaks to EVSE Test plans (Issue project-chip#31460)

* Changed the random value generation to make the values +/- and handle sign conversion to avoid compile warnings

* Enabled cumulativeEnergyExported in Energy-management-app.

* Added initial electrical power measurement 2.2 test case

* Changed copyright date

* Code review comment fixes.

* Changed to c++ style cast

* Fixed trailing whitepace

* Added support for testing read of EEM attributes and change of values

* Corrected EPM references in TC_EEM_2_2. Added TC_EEM_2_3

* Added periodic energy reporting, and new cumulativeEnergyReset attribute into energy-management-app.zap

* Added periodic energy reading support and TC_EEM_2_3 to 2_5.

* Python removed unused logging and EventChangeCallback

* Updates to align to test plan PR project-chip#3949

* Added initial EEM_2_1 test script.

* Added example of setting EEM Accuracy and EEM CumulativeEnergyReset structure - TC_EEM_2_1 now passes

* Restyled by whitespace

* Restyled

* Removed extra spaces in TC_EEM_2_1.py

* Removed unused EnergyManagementManager.cpp/.h

* Fixed PowerMode = kAc

* Initial TC_EPM_2_1.py script

* Restyled by isort

* Merged TC_EEVSE tests back in

* Initialized NumberOfMeasurementTypes

* Added EEM 2.1,2.2,2.3,2.4,2.5 and EPM 2.1,2.2 into CI workflow tests.yaml

* Interim state - partially refactored how Measurement Structs are encoded similar to how ModeBase clusters are implemented. Needs tidy up. Will break all-clusters for now

* Removed SetNumberOfMeasurementTypes since this can be derived from the ArraySize(kMeasurementAccuracies). Added more stringent checking in test script of measurementTypes and ranges.

* Completed TC_EPM_2_1.py script

* Corrected test plan spec reference.

* Test EPM_2_1 now runs and passes. Allows checking that attributes are supported, and skips test if not. Validation of values ignores Nulls (which are allowed). Turned on Ranges attribute.

* Revert unintended change to tests.yaml

* Python test case code-review updates

* Removed old range iterator.

* Fixed lint issues and adjusted timings to match the test plan pr.

* Fixed all-clusters electrical-power-measurement cluster by using the energy-management-app/common Delegate

* Implemented HarmonicCurrents and HarmonicStructs (to return empty list for now)

* Changed the API to ensure that a delegate doesn't change the data mid-way through a read, so the cluster server signals with a StartxxxRead and EndxxxRead call

* Applying suggested changes

* Incorporated feedback from review to simplify the code

* Removed comment per code review

---------

Co-authored-by: Hasty Granbery <[email protected]>
Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
3 people authored and raul-marquez-csa committed Feb 16, 2024
1 parent aeb3fe3 commit e906966
Show file tree
Hide file tree
Showing 42 changed files with 2,501 additions and 934 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -483,9 +483,16 @@ jobs:
scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --app out/linux-x64-lock-ipv6only-no-ble-no-wifi-tsan-clang-test/chip-lock-app --factoryreset --app-args "--discriminator 1234 --KVS kvs1 --trace-to json:out/trace_data/app-{SCRIPT_BASE_NAME}.json" --script "src/python_testing/TC_DRLK_2_3.py" --script-args "--storage-path admin_storage.json --commissioning-method on-network --discriminator 1234 --passcode 20202021 --PICS src/app/tests/suites/certification/ci-pics-values --trace-to json:out/trace_data/test-{SCRIPT_BASE_NAME}.json --trace-to perfetto:out/trace_data/test-{SCRIPT_BASE_NAME}.perfetto"'
scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --app out/linux-x64-all-clusters-ipv6only-no-ble-no-wifi-tsan-clang-test/chip-all-clusters-app --factoryreset --app-args "--discriminator 1234 --KVS kvs1 --trace-to json:out/trace_data/app-{SCRIPT_BASE_NAME}.json" --script "src/python_testing/TC_DeviceBasicComposition.py" --script-args "--storage-path admin_storage.json --manual-code 10054912339 --PICS src/app/tests/suites/certification/ci-pics-values --trace-to json:out/trace_data/test-{SCRIPT_BASE_NAME}.json --trace-to perfetto:out/trace_data/test-{SCRIPT_BASE_NAME}.perfetto"'
scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --app out/linux-x64-lock-ipv6only-no-ble-no-wifi-tsan-clang-test/chip-lock-app --factoryreset --app-args "--discriminator 1234 --KVS kvs1 --trace-to json:out/trace_data/app-{SCRIPT_BASE_NAME}.json" --script "src/python_testing/TC_DeviceConformance.py" --script-args "--storage-path admin_storage.json --manual-code 10054912339 --bool-arg ignore_in_progress:True allow_provisional:True --PICS src/app/tests/suites/certification/ci-pics-values --trace-to json:out/trace_data/test-{SCRIPT_BASE_NAME}.json --trace-to perfetto:out/trace_data/test-{SCRIPT_BASE_NAME}.perfetto --tests test_TC_IDM_10_2"'
scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --app out/linux-x64-energy-management-ipv6only-no-ble-no-wifi-tsan-clang-test/chip-energy-management-app --factoryreset --app-args "--discriminator 1234 --KVS kvs1 --trace-to json:out/trace_data/app-{SCRIPT_BASE_NAME}.json --enable-key 000102030405060708090a0b0c0d0e0f" --script "src/python_testing/TC_EEM_2_1.py" --script-args "--storage-path admin_storage.json --commissioning-method on-network --discriminator 1234 --passcode 20202021 --hex-arg enableKey:000102030405060708090a0b0c0d0e0f --endpoint 1 --trace-to json:out/trace_data/test-{SCRIPT_BASE_NAME}.json --trace-to perfetto:out/trace_data/test-{SCRIPT_BASE_NAME}.perfetto"'
scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --app out/linux-x64-energy-management-ipv6only-no-ble-no-wifi-tsan-clang-test/chip-energy-management-app --factoryreset --app-args "--discriminator 1234 --KVS kvs1 --trace-to json:out/trace_data/app-{SCRIPT_BASE_NAME}.json --enable-key 000102030405060708090a0b0c0d0e0f" --script "src/python_testing/TC_EEM_2_2.py" --script-args "--storage-path admin_storage.json --commissioning-method on-network --discriminator 1234 --passcode 20202021 --hex-arg enableKey:000102030405060708090a0b0c0d0e0f --endpoint 1 --trace-to json:out/trace_data/test-{SCRIPT_BASE_NAME}.json --trace-to perfetto:out/trace_data/test-{SCRIPT_BASE_NAME}.perfetto"'
scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --app out/linux-x64-energy-management-ipv6only-no-ble-no-wifi-tsan-clang-test/chip-energy-management-app --factoryreset --app-args "--discriminator 1234 --KVS kvs1 --trace-to json:out/trace_data/app-{SCRIPT_BASE_NAME}.json --enable-key 000102030405060708090a0b0c0d0e0f" --script "src/python_testing/TC_EEM_2_3.py" --script-args "--storage-path admin_storage.json --commissioning-method on-network --discriminator 1234 --passcode 20202021 --hex-arg enableKey:000102030405060708090a0b0c0d0e0f --endpoint 1 --trace-to json:out/trace_data/test-{SCRIPT_BASE_NAME}.json --trace-to perfetto:out/trace_data/test-{SCRIPT_BASE_NAME}.perfetto"'
scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --app out/linux-x64-energy-management-ipv6only-no-ble-no-wifi-tsan-clang-test/chip-energy-management-app --factoryreset --app-args "--discriminator 1234 --KVS kvs1 --trace-to json:out/trace_data/app-{SCRIPT_BASE_NAME}.json --enable-key 000102030405060708090a0b0c0d0e0f" --script "src/python_testing/TC_EEM_2_4.py" --script-args "--storage-path admin_storage.json --commissioning-method on-network --discriminator 1234 --passcode 20202021 --hex-arg enableKey:000102030405060708090a0b0c0d0e0f --endpoint 1 --trace-to json:out/trace_data/test-{SCRIPT_BASE_NAME}.json --trace-to perfetto:out/trace_data/test-{SCRIPT_BASE_NAME}.perfetto"'
scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --app out/linux-x64-energy-management-ipv6only-no-ble-no-wifi-tsan-clang-test/chip-energy-management-app --factoryreset --app-args "--discriminator 1234 --KVS kvs1 --trace-to json:out/trace_data/app-{SCRIPT_BASE_NAME}.json --enable-key 000102030405060708090a0b0c0d0e0f" --script "src/python_testing/TC_EEM_2_5.py" --script-args "--storage-path admin_storage.json --commissioning-method on-network --discriminator 1234 --passcode 20202021 --hex-arg enableKey:000102030405060708090a0b0c0d0e0f --endpoint 1 --trace-to json:out/trace_data/test-{SCRIPT_BASE_NAME}.json --trace-to perfetto:out/trace_data/test-{SCRIPT_BASE_NAME}.perfetto"'
scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --app out/linux-x64-energy-management-ipv6only-no-ble-no-wifi-tsan-clang-test/chip-energy-management-app --factoryreset --app-args "--discriminator 1234 --KVS kvs1 --trace-to json:out/trace_data/app-{SCRIPT_BASE_NAME}.json --enable-key 000102030405060708090a0b0c0d0e0f" --script "src/python_testing/TC_EEVSE_2_2.py" --script-args "--storage-path admin_storage.json --commissioning-method on-network --discriminator 1234 --passcode 20202021 --hex-arg enableKey:000102030405060708090a0b0c0d0e0f --endpoint 1 --trace-to json:out/trace_data/test-{SCRIPT_BASE_NAME}.json --trace-to perfetto:out/trace_data/test-{SCRIPT_BASE_NAME}.perfetto"'
scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --app out/linux-x64-energy-management-ipv6only-no-ble-no-wifi-tsan-clang-test/chip-energy-management-app --factoryreset --app-args "--discriminator 1234 --KVS kvs1 --trace-to json:out/trace_data/app-{SCRIPT_BASE_NAME}.json --enable-key 000102030405060708090a0b0c0d0e0f" --script "src/python_testing/TC_EEVSE_2_4.py" --script-args "--storage-path admin_storage.json --commissioning-method on-network --discriminator 1234 --passcode 20202021 --hex-arg enableKey:000102030405060708090a0b0c0d0e0f --endpoint 1 --trace-to json:out/trace_data/test-{SCRIPT_BASE_NAME}.json --trace-to perfetto:out/trace_data/test-{SCRIPT_BASE_NAME}.perfetto"'
scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --app out/linux-x64-energy-management-ipv6only-no-ble-no-wifi-tsan-clang-test/chip-energy-management-app --factoryreset --app-args "--discriminator 1234 --KVS kvs1 --trace-to json:out/trace_data/app-{SCRIPT_BASE_NAME}.json --enable-key 000102030405060708090a0b0c0d0e0f" --script "src/python_testing/TC_EEVSE_2_5.py" --script-args "--storage-path admin_storage.json --commissioning-method on-network --discriminator 1234 --passcode 20202021 --hex-arg enableKey:000102030405060708090a0b0c0d0e0f --endpoint 1 --trace-to json:out/trace_data/test-{SCRIPT_BASE_NAME}.json --trace-to perfetto:out/trace_data/test-{SCRIPT_BASE_NAME}.perfetto"'
scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --app out/linux-x64-energy-management-ipv6only-no-ble-no-wifi-tsan-clang-test/chip-energy-management-app --factoryreset --app-args "--discriminator 1234 --KVS kvs1 --trace-to json:out/trace_data/app-{SCRIPT_BASE_NAME}.json --enable-key 000102030405060708090a0b0c0d0e0f" --script "src/python_testing/TC_EPM_2_1.py" --script-args "--storage-path admin_storage.json --commissioning-method on-network --discriminator 1234 --passcode 20202021 --hex-arg enableKey:000102030405060708090a0b0c0d0e0f --endpoint 1 --trace-to json:out/trace_data/test-{SCRIPT_BASE_NAME}.json --trace-to perfetto:out/trace_data/test-{SCRIPT_BASE_NAME}.perfetto"'
scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --app out/linux-x64-energy-management-ipv6only-no-ble-no-wifi-tsan-clang-test/chip-energy-management-app --factoryreset --app-args "--discriminator 1234 --KVS kvs1 --trace-to json:out/trace_data/app-{SCRIPT_BASE_NAME}.json --enable-key 000102030405060708090a0b0c0d0e0f" --script "src/python_testing/TC_EPM_2_2.py" --script-args "--storage-path admin_storage.json --commissioning-method on-network --discriminator 1234 --passcode 20202021 --hex-arg enableKey:000102030405060708090a0b0c0d0e0f --endpoint 1 --trace-to json:out/trace_data/test-{SCRIPT_BASE_NAME}.json --trace-to perfetto:out/trace_data/test-{SCRIPT_BASE_NAME}.perfetto"'
scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --app out/linux-x64-all-clusters-ipv6only-no-ble-no-wifi-tsan-clang-test/chip-all-clusters-app --factoryreset --app-args "--discriminator 1234 --KVS kvs1 --trace-to json:out/trace_data/app-{SCRIPT_BASE_NAME}.json" --script "src/python_testing/TC_FAN_3_1.py" --script-args "--storage-path admin_storage.json --commissioning-method on-network --discriminator 1234 --passcode 20202021 --trace-to json:out/trace_data/test-{SCRIPT_BASE_NAME}.json --trace-to perfetto:out/trace_data/test-{SCRIPT_BASE_NAME}.perfetto"'
scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --app out/linux-x64-all-clusters-ipv6only-no-ble-no-wifi-tsan-clang-test/chip-all-clusters-app --factoryreset --app-args "--discriminator 1234 --KVS kvs1 --trace-to json:out/trace_data/app-{SCRIPT_BASE_NAME}.json" --script "src/python_testing/TC_FAN_3_2.py" --script-args "--storage-path admin_storage.json --commissioning-method on-network --discriminator 1234 --passcode 20202021 --trace-to json:out/trace_data/test-{SCRIPT_BASE_NAME}.json --trace-to perfetto:out/trace_data/test-{SCRIPT_BASE_NAME}.perfetto"'
scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --app out/linux-x64-all-clusters-ipv6only-no-ble-no-wifi-tsan-clang-test/chip-all-clusters-app --factoryreset --app-args "--discriminator 1234 --KVS kvs1 --trace-to json:out/trace_data/app-{SCRIPT_BASE_NAME}.json" --script "src/python_testing/TC_FAN_3_3.py" --script-args "--storage-path admin_storage.json --commissioning-method on-network --discriminator 1234 --passcode 20202021 --trace-to json:out/trace_data/test-{SCRIPT_BASE_NAME}.json --trace-to perfetto:out/trace_data/test-{SCRIPT_BASE_NAME}.perfetto"'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,239 +16,25 @@
* limitations under the License.
*/

#include <app/clusters/electrical-power-measurement-server/electrical-power-measurement-server.h>
#include <ElectricalPowerMeasurementDelegate.h>

using namespace chip;
using namespace chip::app::Clusters;
using namespace chip::app::Clusters::ElectricalPowerMeasurement;
using namespace chip::app::Clusters::ElectricalPowerMeasurement::Structs;

namespace chip {
namespace app {
namespace Clusters {
namespace ElectricalPowerMeasurement {

static MeasurementAccuracyRangeStruct::Type activeCurrentAccuracyRanges[] = { { .rangeMin = 500, .rangeMax = 1000 } };

class StubAccuracyIterator : public Delegate::AccuracyIterator
{
public:
size_t Count() override;
bool Next(MeasurementAccuracyStruct::Type & output) override;
void Release() override;

private:
uint8_t mIndex;
};

size_t StubAccuracyIterator::Count()
{
return 1;
}

bool StubAccuracyIterator::Next(MeasurementAccuracyStruct::Type & output)
{
if (mIndex >= 1)
{
return false;
}
output.measurementType = MeasurementTypeEnum::kActiveCurrent;
output.measured = true;
output.minMeasuredValue = -10000000;
output.maxMeasuredValue = 10000000;
output.accuracyRanges = DataModel::List<const MeasurementAccuracyRangeStruct::Type>(activeCurrentAccuracyRanges);
mIndex++;
return true;
}

void StubAccuracyIterator::Release()
{
mIndex = 0;
}

class StubRangeIterator : public Delegate::RangeIterator
{
public:
size_t Count() override;
bool Next(MeasurementRangeStruct::Type & output) override;
void Release() override;
};

size_t StubRangeIterator::Count()
{
return 0;
}

bool StubRangeIterator::Next(MeasurementRangeStruct::Type & output)
{
return false;
}

void StubRangeIterator::Release() {}

class StubHarmonicMeasurementIterator : public Delegate::HarmonicMeasurementIterator
{
public:
size_t Count() override;
bool Next(HarmonicMeasurementStruct::Type & output) override;
void Release() override;
};

size_t StubHarmonicMeasurementIterator::Count()
{
return 0;
}

bool StubHarmonicMeasurementIterator::Next(HarmonicMeasurementStruct::Type & output)
{
return false;
}

void StubHarmonicMeasurementIterator::Release() {}

static StubAccuracyIterator accuracyIterator;
static StubRangeIterator rangeIterator;
static StubHarmonicMeasurementIterator harmonicMeasurementIterator;

class ElectricalPowerMeasurementDelegate : public Delegate
{
public:
PowerModeEnum GetPowerMode() override;
uint8_t GetNumberOfMeasurementTypes() override;
AccuracyIterator * IterateAccuracy() override;
RangeIterator * IterateRanges() override;
DataModel::Nullable<int64_t> GetVoltage() override;
DataModel::Nullable<int64_t> GetActiveCurrent() override;
DataModel::Nullable<int64_t> GetReactiveCurrent() override;
DataModel::Nullable<int64_t> GetApparentCurrent() override;
DataModel::Nullable<int64_t> GetActivePower() override;
DataModel::Nullable<int64_t> GetReactivePower() override;
DataModel::Nullable<int64_t> GetApparentPower() override;
DataModel::Nullable<int64_t> GetRMSVoltage() override;
DataModel::Nullable<int64_t> GetRMSCurrent() override;
DataModel::Nullable<int64_t> GetRMSPower() override;
DataModel::Nullable<int64_t> GetFrequency() override;
HarmonicMeasurementIterator * IterateHarmonicCurrents() override;
HarmonicMeasurementIterator * IterateHarmonicPhases() override;
DataModel::Nullable<int64_t> GetPowerFactor() override;
DataModel::Nullable<int64_t> GetNeutralCurrent() override;

~ElectricalPowerMeasurementDelegate() = default;
};

PowerModeEnum ElectricalPowerMeasurementDelegate::GetPowerMode()
{
return PowerModeEnum::kAc;
}

uint8_t ElectricalPowerMeasurementDelegate::GetNumberOfMeasurementTypes()
{
return 1;
}

Delegate::AccuracyIterator * ElectricalPowerMeasurementDelegate::IterateAccuracy()
{
return &accuracyIterator;
}

Delegate::RangeIterator * ElectricalPowerMeasurementDelegate::IterateRanges()
{
return &rangeIterator;
}

DataModel::Nullable<int64_t> ElectricalPowerMeasurementDelegate::GetVoltage()
{
return {};
}

DataModel::Nullable<int64_t> ElectricalPowerMeasurementDelegate::GetActiveCurrent()
{
return {};
}

DataModel::Nullable<int64_t> ElectricalPowerMeasurementDelegate::GetReactiveCurrent()
{
return {};
}

DataModel::Nullable<int64_t> ElectricalPowerMeasurementDelegate::GetApparentCurrent()
{
return {};
}

DataModel::Nullable<int64_t> ElectricalPowerMeasurementDelegate::GetActivePower()
{
return DataModel::Nullable<int64_t>(10000);
}

DataModel::Nullable<int64_t> ElectricalPowerMeasurementDelegate::GetReactivePower()
{
return {};
}

DataModel::Nullable<int64_t> ElectricalPowerMeasurementDelegate::GetApparentPower()
{
return {};
}

DataModel::Nullable<int64_t> ElectricalPowerMeasurementDelegate::GetRMSVoltage()
{
return {};
}

DataModel::Nullable<int64_t> ElectricalPowerMeasurementDelegate::GetRMSCurrent()
{
return {};
}

DataModel::Nullable<int64_t> ElectricalPowerMeasurementDelegate::GetRMSPower()
{
return {};
}

DataModel::Nullable<int64_t> ElectricalPowerMeasurementDelegate::GetFrequency()
{
return {};
}

Delegate::HarmonicMeasurementIterator * ElectricalPowerMeasurementDelegate::IterateHarmonicCurrents()
{
return &harmonicMeasurementIterator;
}

Delegate::HarmonicMeasurementIterator * ElectricalPowerMeasurementDelegate::IterateHarmonicPhases()
{
return &harmonicMeasurementIterator;
}

DataModel::Nullable<int64_t> ElectricalPowerMeasurementDelegate::GetPowerFactor()
{
return {};
}

DataModel::Nullable<int64_t> ElectricalPowerMeasurementDelegate::GetNeutralCurrent()
{
return {};
}

} // namespace ElectricalPowerMeasurement
} // namespace Clusters
} // namespace app
} // namespace chip

static std::unique_ptr<ElectricalPowerMeasurement::Delegate> gDelegate;
static std::unique_ptr<ElectricalPowerMeasurement::Instance> gInstance;
static std::unique_ptr<ElectricalPowerMeasurementDelegate> gEPMDelegate;
static std::unique_ptr<ElectricalPowerMeasurementInstance> gEPMInstance;

void emberAfElectricalPowerMeasurementClusterInitCallback(chip::EndpointId endpointId)
{
VerifyOrDie(endpointId == 1); // this cluster is only enabled for endpoint 1.
VerifyOrDie(!gInstance);
VerifyOrDie(!gEPMInstance);

gDelegate = std::make_unique<ElectricalPowerMeasurementDelegate>();
if (gDelegate)
gEPMDelegate = std::make_unique<ElectricalPowerMeasurementDelegate>();
if (gEPMDelegate)
{
gInstance = std::make_unique<Instance>(
endpointId, *gDelegate,
gEPMInstance = std::make_unique<ElectricalPowerMeasurementInstance>(
endpointId, *gEPMDelegate,
BitMask<Feature, uint32_t>(Feature::kDirectCurrent, Feature::kAlternatingCurrent, Feature::kPolyphasePower,
Feature::kHarmonics, Feature::kPowerQuality),
BitMask<OptionalAttributes, uint32_t>(
Expand All @@ -260,6 +46,6 @@ void emberAfElectricalPowerMeasurementClusterInitCallback(chip::EndpointId endpo
OptionalAttributes::kOptionalAttributeFrequency, OptionalAttributes::kOptionalAttributePowerFactor,
OptionalAttributes::kOptionalAttributeNeutralCurrent));

gInstance->Init();
gEPMInstance->Init();
}
}
1 change: 1 addition & 0 deletions examples/all-clusters-app/ameba/chip_main.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ list(

${chip_dir}/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp
${chip_dir}/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementManager.cpp
${chip_dir}/examples/energy-management-app/energy-management-common/src/ElectricalPowerMeasurementDelegate.cpp
${chip_dir}/examples/energy-management-app/energy-management-common/src/EnergyEvseDelegateImpl.cpp
${chip_dir}/examples/energy-management-app/energy-management-common/src/EnergyEvseManager.cpp

Expand Down
1 change: 1 addition & 0 deletions examples/all-clusters-app/asr/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ asr_executable("clusters_app") {
"${chip_root}/examples/all-clusters-app/all-clusters-common/src/static-supported-temperature-levels.cpp",
"${chip_root}/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp",
"${chip_root}/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementManager.cpp",
"${chip_root}/examples/energy-management-app/energy-management-common/src/ElectricalPowerMeasurementDelegate.cpp",
"${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyEvseDelegateImpl.cpp",
"${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyEvseManager.cpp",
"${examples_plat_dir}/ButtonHandler.cpp",
Expand Down
Loading

0 comments on commit e906966

Please sign in to comment.