Skip to content

Commit

Permalink
Enabled Electrical Energy Measurement in example-energy-management-ap… (
Browse files Browse the repository at this point in the history
#31622)

* 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.

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

---------

Co-authored-by: Restyled.io <commits@restyled.io>
  • Loading branch information
jamesharrow and restyled-commits authored Jan 27, 2024
1 parent 7456670 commit 69f8bd5
Show file tree
Hide file tree
Showing 16 changed files with 711 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -900,6 +900,85 @@ cluster GroupKeyManagement = 63 {
fabric command access(invoke: administer) KeySetReadAllIndices(): KeySetReadAllIndicesResponse = 4;
}

/** This cluster provides a mechanism for querying data about the electrical energy imported or provided by the server. */
provisional cluster ElectricalEnergyMeasurement = 145 {
revision 1;

enum MeasurementTypeEnum : enum16 {
kUnspecified = 0;
kVoltage = 1;
kActiveCurrent = 2;
kReactiveCurrent = 3;
kApparentCurrent = 4;
kActivePower = 5;
kReactivePower = 6;
kApparentPower = 7;
kRMSVoltage = 8;
kRMSCurrent = 9;
kRMSPower = 10;
kFrequency = 11;
kPowerFactor = 12;
kNeutralCurrent = 13;
kElectricalEnergy = 14;
}

bitmap Feature : bitmap32 {
kImportedEnergy = 0x1;
kExportedEnergy = 0x2;
kCumulativeEnergy = 0x4;
kPeriodicEnergy = 0x8;
}

struct MeasurementAccuracyRangeStruct {
int64s rangeMin = 0;
int64s rangeMax = 1;
optional percent100ths percentMax = 2;
optional percent100ths percentMin = 3;
optional percent100ths percentTypical = 4;
optional int64u fixedMax = 5;
optional int64u fixedMin = 6;
optional int64u fixedTypical = 7;
}

struct MeasurementAccuracyStruct {
MeasurementTypeEnum measurementType = 0;
boolean measured = 1;
int64s minMeasuredValue = 2;
int64s maxMeasuredValue = 3;
MeasurementAccuracyRangeStruct accuracyRanges[] = 4;
}

struct EnergyMeasurementStruct {
int64s energy = 0;
optional epoch_s startTimestamp = 1;
optional epoch_s endTimestamp = 2;
optional systime_ms startSystime = 3;
optional systime_ms endSystime = 4;
}

info event CumulativeEnergyMeasured = 0 {
optional EnergyMeasurementStruct energyImported = 0;
optional EnergyMeasurementStruct energyExported = 1;
}

info event PeriodicEnergyMeasured = 1 {
optional EnergyMeasurementStruct energyImported = 0;
optional EnergyMeasurementStruct energyExported = 1;
}

readonly attribute MeasurementAccuracyStruct accuracy = 0;
readonly attribute optional nullable EnergyMeasurementStruct cumulativeEnergyImported = 1;
readonly attribute optional nullable EnergyMeasurementStruct cumulativeEnergyExported = 2;
readonly attribute optional nullable EnergyMeasurementStruct periodicEnergyImported = 3;
readonly attribute optional nullable EnergyMeasurementStruct periodicEnergyExported = 4;
readonly attribute command_id generatedCommandList[] = 65528;
readonly attribute command_id acceptedCommandList[] = 65529;
readonly attribute event_id eventList[] = 65530;
readonly attribute attrib_id attributeList[] = 65531;
readonly attribute bitmap32 featureMap = 65532;
readonly attribute int16u clusterRevision = 65533;
}

/** This cluster allows a client to manage the power draw of a device. An example of such a client could be an Energy Management System (EMS) which controls an Energy Smart Appliance (ESA). */
provisional cluster DeviceEnergyManagement = 152 {
revision 3;
Expand Down Expand Up @@ -1598,6 +1677,18 @@ endpoint 1 {
callback attribute clusterRevision;
}

server cluster ElectricalEnergyMeasurement {
emits event CumulativeEnergyMeasured;
callback attribute accuracy;
callback attribute cumulativeEnergyImported;
callback attribute generatedCommandList;
callback attribute acceptedCommandList;
callback attribute eventList;
callback attribute attributeList;
ram attribute featureMap default = 5;
ram attribute clusterRevision default = 1;
}

server cluster DeviceEnergyManagement {
emits event PowerAdjustStart;
emits event PowerAdjustEnd;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2517,6 +2517,154 @@
}
]
},
{
"name": "Electrical Energy Measurement",
"code": 145,
"mfgCode": null,
"define": "ELECTRICAL_ENERGY_MEASUREMENT_CLUSTER",
"side": "server",
"enabled": 1,
"apiMaturity": "provisional",
"attributes": [
{
"name": "Accuracy",
"code": 0,
"mfgCode": null,
"side": "server",
"type": "MeasurementAccuracyStruct",
"included": 1,
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": null,
"reportable": 1,
"minInterval": 1,
"maxInterval": 65534,
"reportableChange": 0
},
{
"name": "CumulativeEnergyImported",
"code": 1,
"mfgCode": null,
"side": "server",
"type": "EnergyMeasurementStruct",
"included": 1,
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": null,
"reportable": 1,
"minInterval": 1,
"maxInterval": 65534,
"reportableChange": 0
},
{
"name": "GeneratedCommandList",
"code": 65528,
"mfgCode": null,
"side": "server",
"type": "array",
"included": 1,
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": null,
"reportable": 1,
"minInterval": 1,
"maxInterval": 65534,
"reportableChange": 0
},
{
"name": "AcceptedCommandList",
"code": 65529,
"mfgCode": null,
"side": "server",
"type": "array",
"included": 1,
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": null,
"reportable": 1,
"minInterval": 1,
"maxInterval": 65534,
"reportableChange": 0
},
{
"name": "EventList",
"code": 65530,
"mfgCode": null,
"side": "server",
"type": "array",
"included": 1,
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": null,
"reportable": 1,
"minInterval": 1,
"maxInterval": 65534,
"reportableChange": 0
},
{
"name": "AttributeList",
"code": 65531,
"mfgCode": null,
"side": "server",
"type": "array",
"included": 1,
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": null,
"reportable": 1,
"minInterval": 1,
"maxInterval": 65534,
"reportableChange": 0
},
{
"name": "FeatureMap",
"code": 65532,
"mfgCode": null,
"side": "server",
"type": "bitmap32",
"included": 1,
"storageOption": "RAM",
"singleton": 0,
"bounded": 0,
"defaultValue": "5",
"reportable": 1,
"minInterval": 1,
"maxInterval": 65534,
"reportableChange": 0
},
{
"name": "ClusterRevision",
"code": 65533,
"mfgCode": null,
"side": "server",
"type": "int16u",
"included": 1,
"storageOption": "RAM",
"singleton": 0,
"bounded": 0,
"defaultValue": "1",
"reportable": 1,
"minInterval": 1,
"maxInterval": 65534,
"reportableChange": 0
}
],
"events": [
{
"name": "CumulativeEnergyMeasured",
"code": 0,
"mfgCode": null,
"side": "server",
"included": 1
}
]
},
{
"name": "Device Energy Management",
"code": 152,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,56 @@ class EVSEManufacturer
*/
static void ApplicationCallbackHandler(const EVSECbInfo * cb, intptr_t arg);

/**
* @brief Allows a client application to send in power readings into the system
*
* @param[in] aEndpointId - Endpoint to send to EPM Cluster
* @param[in] aActivePower_mW - Power measured in milli-watts
* @param[in] aVoltage_mV - Voltage measured in milli-volts
* @param[in] aCurrent_mA - Current measured in milli-amps
*/
CHIP_ERROR SendPowerReading(EndpointId aEndpointId, int64_t aActivePower_mW, int64_t aVoltage_mV, int64_t aCurrent_mA);

/**
* @brief Allows a client application to send in energy readings into the system
*
* This is a helper function to add timestamps to the readings
*
* @param[in] aCumulativeEnergyImported -total energy imported in milli-watthours
* @param[in] aCumulativeEnergyExported -total energy exported in milli-watthours
*/
CHIP_ERROR SendEnergyReading(EndpointId aEndpointId, int64_t aCumulativeEnergyImported, int64_t aCumulativeEnergyExported);

/** Fake Meter data generation - used for testing EPM/EEM clusters */
/**
* @brief Starts a fake load/generator to periodically callback the power and energy
* clusters.
* @param[in] aEndpointId - which endpoint is the meter to be updated on
* @param[in] aPower_mW - the mean power of the load
* Positive power indicates Imported energy (e.g. a load)
* Negative power indicated Exported energy (e.g. a generator)
* @param[in] aPowerRandomness_mW This is used to scale random power fluctuations around the mean power of the load
*
* @param[in] aInterval_s - the callback interval in seconds
* @param[in] bReset - boolean: true will reset the energy values to 0
*/
void StartFakeReadings(EndpointId aEndpointId, int64_t aPower_mW, uint32_t aPowerRandomness_mW, uint8_t aInterval_s,
bool bReset);

/**
* @brief Stops any active updates to the fake load data callbacks
*/
void StopFakeReadings();

/**
* @brief Sends fake meter data into the cluster and restarts the timer
*/
void FakeReadingsUpdate();
/**
* @brief Timer expiry callback to handle fake load
*/
static void FakeReadingsTimerExpiry(System::Layer * systemLayer, void * manufacturer);

private:
EnergyEvseManager * mInstance;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@
#include <cstring>

using chip::Protocols::InteractionModel::Status;

/**
* @brief Helper function to get current timestamp in Epoch format
*
* @param chipEpoch reference to hold return timestamp
*/
CHIP_ERROR GetEpochTS(uint32_t & chipEpoch);

namespace chip {
namespace app {
namespace Clusters {
Expand Down
Loading

0 comments on commit 69f8bd5

Please sign in to comment.