Skip to content

Commit

Permalink
Added initial version of EPM delegate and instance to energy-manageme…
Browse files Browse the repository at this point in the history
…nt-app
  • Loading branch information
jamesharrow committed Jan 22, 2024
1 parent 7b937ac commit 383deef
Show file tree
Hide file tree
Showing 2 changed files with 413 additions and 0 deletions.
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
Loading

0 comments on commit 383deef

Please sign in to comment.