-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added initial version of EPM delegate and instance to energy-manageme…
…nt-app
- Loading branch information
1 parent
7b937ac
commit 383deef
Showing
2 changed files
with
413 additions
and
0 deletions.
There are no files selected for viewing
127 changes: 127 additions & 0 deletions
127
...ergy-management-app/energy-management-common/include/ElectricalPowerMeasurementDelegate.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
/* | ||
* | ||
* Copyright (c) 2024 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. | ||
*/ | ||
#pragma once | ||
|
||
#include <app/clusters/electrical-power-measurement-server/electrical-power-measurement-server.h> | ||
#include <app/util/af-types.h> | ||
#include <lib/core/CHIPError.h> | ||
|
||
namespace chip { | ||
namespace app { | ||
namespace Clusters { | ||
namespace ElectricalPowerMeasurement { | ||
|
||
class ElectricalPowerMeasurementDelegate : public Delegate | ||
{ | ||
public: | ||
~ElectricalPowerMeasurementDelegate() = default; | ||
|
||
static constexpr uint8_t kMaxNumberOfMeasurementTypes = 14; // From spec | ||
static constexpr uint8_t kDefaultNumberOfMeasurementTypes = 1; | ||
|
||
// Attribute Accessors | ||
PowerModeEnum GetPowerMode() override { return mPowerMode; } | ||
uint8_t GetNumberOfMeasurementTypes() override { return mNumberOfMeasurementTypes; }; | ||
DataModel::List<const Structs::MeasurementAccuracyStruct::Type> GetAccuracy() override; | ||
DataModel::List<const Structs::MeasurementRangeStruct::Type> GetRanges() override; | ||
DataModel::Nullable<int64_t> GetVoltage() override { return mVoltage; } | ||
DataModel::Nullable<int64_t> GetActiveCurrent() override { return mActiveCurrent; } | ||
DataModel::Nullable<int64_t> GetReactiveCurrent() override { return mReactiveCurrent; } | ||
DataModel::Nullable<int64_t> GetApparentCurrent() override { return mApparentCurrent; } | ||
DataModel::Nullable<int64_t> GetActivePower() override { return mActivePower; } | ||
DataModel::Nullable<int64_t> GetReactivePower() override { return mReactivePower; } | ||
DataModel::Nullable<int64_t> GetApparentPower() override { return mApparentPower; } | ||
DataModel::Nullable<int64_t> GetRMSVoltage() override { return mRMSVoltage; } | ||
DataModel::Nullable<int64_t> GetRMSCurrent() override { return mRMSCurrent; } | ||
DataModel::Nullable<int64_t> GetRMSPower() override { return mRMSPower; } | ||
DataModel::Nullable<int64_t> GetFrequency() override { return mFrequency; } | ||
DataModel::Nullable<DataModel::List<Structs::HarmonicMeasurementStruct::Type>> GetHarmonicCurrents() override; | ||
DataModel::Nullable<DataModel::List<Structs::HarmonicMeasurementStruct::Type>> GetHarmonicPhases() override; | ||
DataModel::Nullable<int64_t> GetPowerFactor() override { return mPowerFactor; } | ||
DataModel::Nullable<int64_t> GetNeutralCurrent() override { return mNeutralCurrent; }; | ||
|
||
// Internal Application API to set attribute values | ||
CHIP_ERROR SetPowerMode(PowerModeEnum); | ||
CHIP_ERROR SetNumberOfMeasurementTypes(uint8_t); | ||
CHIP_ERROR SetAccuracy(); // TODO | ||
CHIP_ERROR SetRanges(); // TODO | ||
CHIP_ERROR SetVoltage(DataModel::Nullable<int64_t>); | ||
CHIP_ERROR SetActiveCurrent(DataModel::Nullable<int64_t>); | ||
CHIP_ERROR SetReactiveCurrent(DataModel::Nullable<int64_t>); | ||
CHIP_ERROR SetApparentCurrent(DataModel::Nullable<int64_t>); | ||
CHIP_ERROR SetActivePower(DataModel::Nullable<int64_t>); | ||
CHIP_ERROR SetReactivePower(DataModel::Nullable<int64_t>); | ||
CHIP_ERROR SetApparentPower(DataModel::Nullable<int64_t>); | ||
CHIP_ERROR SetRMSVoltage(DataModel::Nullable<int64_t>); | ||
CHIP_ERROR SetRMSCurrent(DataModel::Nullable<int64_t>); | ||
CHIP_ERROR SetRMSPower(DataModel::Nullable<int64_t>); | ||
CHIP_ERROR SetFrequency(DataModel::Nullable<int64_t>); | ||
// DataModel::Nullable<DataModel::List<Structs::HarmonicMeasurementStruct::Type>>;// TODO | ||
// DataModel::Nullable<DataModel::List<Structs::HarmonicMeasurementStruct::Type>>;// TODO | ||
CHIP_ERROR SetPowerFactor(DataModel::Nullable<int64_t>); | ||
CHIP_ERROR SetNeutralCurrent(DataModel::Nullable<int64_t>); | ||
|
||
private: | ||
// Attribute storage | ||
PowerModeEnum mPowerMode; | ||
uint8_t mNumberOfMeasurementTypes = kDefaultNumberOfMeasurementTypes; | ||
DataModel::Nullable<int64_t> mVoltage; | ||
DataModel::Nullable<int64_t> mActiveCurrent; | ||
DataModel::Nullable<int64_t> mReactiveCurrent; | ||
DataModel::Nullable<int64_t> mApparentCurrent; | ||
DataModel::Nullable<int64_t> mActivePower; | ||
DataModel::Nullable<int64_t> mReactivePower; | ||
DataModel::Nullable<int64_t> mApparentPower; | ||
DataModel::Nullable<int64_t> mRMSVoltage; | ||
DataModel::Nullable<int64_t> mRMSCurrent; | ||
DataModel::Nullable<int64_t> mRMSPower; | ||
DataModel::Nullable<int64_t> mFrequency; | ||
DataModel::Nullable<DataModel::List<Structs::HarmonicMeasurementStruct::Type>> mHarmonicCurrents; | ||
DataModel::Nullable<DataModel::List<Structs::HarmonicMeasurementStruct::Type>> mHarmonicPhases; | ||
DataModel::Nullable<int64_t> mPowerFactor; | ||
DataModel::Nullable<int64_t> mNeutralCurrent; | ||
}; | ||
|
||
class ElectricalPowerMeasurementInstance : public Instance | ||
{ | ||
public: | ||
ElectricalPowerMeasurementInstance(EndpointId aEndpointId, ElectricalPowerMeasurementDelegate & aDelegate, Feature aFeature, | ||
OptionalAttributes aOptionalAttributes) : | ||
ElectricalPowerMeasurement::Instance(aEndpointId, aDelegate, aFeature, aOptionalAttributes) | ||
{ | ||
mDelegate = &aDelegate; | ||
} | ||
|
||
// Delete copy constructor and assignment operator. | ||
ElectricalPowerMeasurementInstance(const ElectricalPowerMeasurementInstance &) = delete; | ||
ElectricalPowerMeasurementInstance(const ElectricalPowerMeasurementInstance &&) = delete; | ||
ElectricalPowerMeasurementInstance & operator=(const ElectricalPowerMeasurementInstance &) = delete; | ||
|
||
CHIP_ERROR Init(); | ||
void Shutdown(); | ||
|
||
ElectricalPowerMeasurementDelegate * GetDelegate() { return mDelegate; }; | ||
|
||
private: | ||
ElectricalPowerMeasurementDelegate * mDelegate; | ||
}; | ||
|
||
} // namespace ElectricalPowerMeasurement | ||
} // namespace Clusters | ||
} // namespace app | ||
} // namespace chip |
Oops, something went wrong.