Skip to content

Commit

Permalink
Allow FeatureMap in EEM constructor; add all-clusters-app EEM stub
Browse files Browse the repository at this point in the history
  • Loading branch information
hasty committed Jan 27, 2024
1 parent 1203545 commit 37e8fed
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 62 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
*
* Copyright (c) 2023 Project CHIP Authors
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

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

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

static std::unique_ptr<ElectricalEnergyMeasurementAttrAccess> gAttrAccess;

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

gAttrAccess = std::make_unique<ElectricalEnergyMeasurementAttrAccess>(BitMask<Feature, uint32_t>(
Feature::kImportedEnergy, Feature::kExportedEnergy, Feature::kCumulativeEnergy, Feature::kPeriodicEnergy));

if (gAttrAccess)
{
gAttrAccess->Init();
}
}
1 change: 1 addition & 0 deletions examples/all-clusters-app/linux/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ source_set("chip-all-clusters-common") {
"${chip_root}/examples/all-clusters-app/all-clusters-common/src/device-energy-management-stub.cpp",
"${chip_root}/examples/all-clusters-app/all-clusters-common/src/dishwasher-alarm-stub.cpp",
"${chip_root}/examples/all-clusters-app/all-clusters-common/src/dishwasher-mode.cpp",
"${chip_root}/examples/all-clusters-app/all-clusters-common/src/electrical-energy-measurement-stub.cpp",
"${chip_root}/examples/all-clusters-app/all-clusters-common/src/electrical-power-measurement-stub.cpp",
"${chip_root}/examples/all-clusters-app/all-clusters-common/src/energy-evse-stub.cpp",
"${chip_root}/examples/all-clusters-app/all-clusters-common/src/fan-stub.cpp",
Expand Down
1 change: 1 addition & 0 deletions examples/all-clusters-app/tizen/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ source_set("chip-all-clusters-common") {
"${chip_root}/examples/all-clusters-app/all-clusters-common/src/bridged-actions-stub.cpp",
"${chip_root}/examples/all-clusters-app/all-clusters-common/src/concentration-measurement-instances.cpp",
"${chip_root}/examples/all-clusters-app/all-clusters-common/src/device-energy-management-stub.cpp",
"${chip_root}/examples/all-clusters-app/all-clusters-common/src/electrical-energy-measurement-stub.cpp",
"${chip_root}/examples/all-clusters-app/all-clusters-common/src/electrical-power-measurement-stub.cpp",
"${chip_root}/examples/all-clusters-app/all-clusters-common/src/energy-evse-stub.cpp",
"${chip_root}/examples/all-clusters-app/all-clusters-common/src/fan-stub.cpp",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1685,7 +1685,7 @@ endpoint 1 {
callback attribute acceptedCommandList;
callback attribute eventList;
callback attribute attributeList;
ram attribute featureMap default = 5;
callback attribute featureMap;
ram attribute clusterRevision default = 1;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,23 @@

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

namespace {
namespace chip {
namespace app {
namespace Clusters {
namespace ElectricalEnergyMeasurement {

using namespace chip;
using namespace chip::app::Clusters::ElectricalEnergyMeasurement;
using namespace chip::app::Clusters::ElectricalEnergyMeasurement::Attributes;
using namespace chip::app::Clusters::ElectricalEnergyMeasurement::Structs;

MeasurementData
gMeasurements[EMBER_AF_ELECTRICAL_ENERGY_MEASUREMENT_CLUSTER_SERVER_ENDPOINT_COUNT + CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT];

class ElectricalEnergyMeasurementAttrAccess : public app::AttributeAccessInterface
CHIP_ERROR ElectricalEnergyMeasurementAttrAccess::Init()
{
public:
ElectricalEnergyMeasurementAttrAccess() :
app::AttributeAccessInterface(Optional<EndpointId>::Missing(), app::Clusters::ElectricalEnergyMeasurement::Id)
{}

CHIP_ERROR Read(const app::ConcreteReadAttributePath & aPath, app::AttributeValueEncoder & aEncoder) override;
};
VerifyOrReturnError(registerAttributeAccessOverride(this), CHIP_ERROR_INCORRECT_STATE);
return CHIP_NO_ERROR;
}

CHIP_ERROR ElectricalEnergyMeasurementAttrAccess::Read(const app::ConcreteReadAttributePath & aPath,
app::AttributeValueEncoder & aEncoder)
Expand All @@ -55,6 +53,9 @@ CHIP_ERROR ElectricalEnergyMeasurementAttrAccess::Read(const app::ConcreteReadAt

switch (aPath.mAttributeId)
{
case FeatureMap::Id:
ReturnErrorOnFailure(aEncoder.Encode(mFeature));
break;
case Accuracy::Id:
if (data == nullptr)
{
Expand Down Expand Up @@ -90,15 +91,6 @@ CHIP_ERROR ElectricalEnergyMeasurementAttrAccess::Read(const app::ConcreteReadAt
return CHIP_NO_ERROR;
}

ElectricalEnergyMeasurementAttrAccess gAttrAccess;

} // namespace

namespace chip {
namespace app {
namespace Clusters {
namespace ElectricalEnergyMeasurement {

MeasurementData * MeasurementDataForEndpoint(EndpointId endpointId)
{
auto index = emberAfGetClusterServerEndpointIndex(endpointId, app::Clusters::ElectricalEnergyMeasurement::Id,
Expand Down Expand Up @@ -192,8 +184,3 @@ bool NotifyPeriodicEnergyMeasured(EndpointId endpointId, const Optional<EnergyMe
} // namespace Clusters
} // namespace app
} // namespace chip

void MatterElectricalEnergyMeasurementPluginServerInitCallback()
{
registerAttributeAccessOverride(&gAttrAccess);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <lib/core/Optional.h>

#include <app-common/zap-generated/cluster-objects.h>
#include <app/AttributeAccessInterface.h>

namespace chip {
namespace app {
Expand All @@ -35,6 +36,21 @@ struct MeasurementData
Optional<Structs::EnergyMeasurementStruct::Type> periodicExported;
};

class ElectricalEnergyMeasurementAttrAccess : public AttributeAccessInterface
{
public:
ElectricalEnergyMeasurementAttrAccess(BitMask<Feature> aFeature) :
app::AttributeAccessInterface(Optional<EndpointId>::Missing(), app::Clusters::ElectricalEnergyMeasurement::Id),
mFeature(aFeature)
{}

CHIP_ERROR Init();
CHIP_ERROR Read(const app::ConcreteReadAttributePath & aPath, app::AttributeValueEncoder & aEncoder) override;

private:
BitMask<Feature> mFeature;
};

bool NotifyCumulativeEnergyMeasured(EndpointId endpointId, const Optional<Structs::EnergyMeasurementStruct::Type> & energyImported,
const Optional<Structs::EnergyMeasurementStruct::Type> & energyExported);

Expand Down
1 change: 1 addition & 0 deletions src/app/util/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ void MatterDishwasherAlarmPluginServerInitCallback() {}
void MatterMicrowaveOvenModePluginServerInitCallback() {}
void MatterDeviceEnergyManagementModePluginServerInitCallback() {}
void MatterEnergyEvseModePluginServerInitCallback() {}
void MatterElectricalEnergyMeasurementPluginServerInitCallback() {}
void MatterElectricalPowerMeasurementPluginServerInitCallback() {}
// ****************************************
// Print out information about each cluster
Expand Down
3 changes: 2 additions & 1 deletion src/app/zap-templates/zcl/zcl.json
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,8 @@
"CumulativeEnergyImported",
"CumulativeEnergyExported",
"PeriodicEnergyImported",
"PeriodicEnergyExported"
"PeriodicEnergyExported",
"FeatureMap"
],
"Electrical Power Measurement": [
"PowerMode",
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 37e8fed

Please sign in to comment.