Skip to content

Commit

Permalink
Better documentation, a set of braces I missed last time around, and
Browse files Browse the repository at this point in the history
added an extra header include.
  • Loading branch information
drempelg committed Feb 9, 2024
1 parent d0bca83 commit a228f2d
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ struct EPrefDelegate : public Delegate
CHIP_ERROR GetLowPowerModeSensitivityAtIndex(chip::EndpointId aEndpoint, size_t aIndex, BalanceStruct::Type & balance) override;

size_t GetNumEnergyBalances(chip::EndpointId aEndpoint) override;
size_t GetNumLowPowerModes(chip::EndpointId aEndpoint) override;
size_t GetNumLowPowerModeSensitivities(chip::EndpointId aEndpoint) override;
};

EPrefDelegate::EPrefDelegate() : Delegate()
Expand All @@ -54,7 +54,7 @@ size_t EPrefDelegate::GetNumEnergyBalances(chip::EndpointId aEndpoint)
return (ArraySize(gsEnergyBalances));
}

size_t EPrefDelegate::GetNumLowPowerModes(chip::EndpointId aEndpoint)
size_t EPrefDelegate::GetNumLowPowerModeSensitivities(chip::EndpointId aEndpoint)
{
return (ArraySize(gsEnergyBalances));
}
Expand Down Expand Up @@ -87,7 +87,7 @@ EPrefDelegate::GetEnergyPriorityAtIndex(chip::EndpointId aEndpoint, size_t aInde
CHIP_ERROR
EPrefDelegate::GetLowPowerModeSensitivityAtIndex(chip::EndpointId aEndpoint, size_t aIndex, BalanceStruct::Type & balance)
{
if (aIndex < GetNumLowPowerModes(aEndpoint))
if (aIndex < GetNumLowPowerModeSensitivities(aEndpoint))
{
balance = gsPowerBalances[aIndex];
return CHIP_NO_ERROR;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@

#include "energy-preference-server.h"

#include <app/util/attribute-storage.h>
#include <app/util/attribute-storage.h> // Needed for registerAttributeAccessOverride

#include <app-common/zap-generated/attributes/Accessors.h>
#include <app-common/zap-generated/callback.h>
#include <app-common/zap-generated/cluster-objects.h>
#include <app-common/zap-generated/ids/Attributes.h>
#include <app/ConcreteAttributePath.h>
#include <app/AttributeAccessInterface.h> // added in case we ever don't need app/util/attribute-storage.h at some point.
#include <app/util/error-mapping.h>
#include <lib/core/CHIPEncoding.h>

Expand All @@ -34,7 +35,7 @@ using namespace chip::app::Clusters::EnergyPreference;
using namespace chip::app::Clusters::EnergyPreference::Structs;
using namespace chip::app::Clusters::EnergyPreference::Attributes;

using imcode = Protocols::InteractionModel::Status;
using Status = Protocols::InteractionModel::Status;

namespace {

Expand Down Expand Up @@ -159,7 +160,7 @@ Delegate * GetDelegate()

} // Set matter energy preferences delegate

Protocols::InteractionModel::Status
Status
MatterEnergyPreferenceClusterServerPreAttributeChangedCallback(const ConcreteAttributePath & attributePath,
EmberAfAttributeType attributeType, uint16_t size, uint8_t * value)
{
Expand All @@ -171,43 +172,45 @@ MatterEnergyPreferenceClusterServerPreAttributeChangedCallback(const ConcreteAtt
const bool lowPowerSupported = featureMapIsGood && ((ourFeatureMap & to_underlying(Feature::kLowPowerModeSensitivity)) != 0);

if (delegate == nullptr)
return imcode::UnsupportedWrite;
{
return Status::UnsupportedWrite;
}

switch (attributePath.mAttributeId)
{
case CurrentEnergyBalance::Id: {
if (balanceSupported == false)
{
return imcode::UnsupportedAttribute;
return Status::UnsupportedAttribute;
}

uint8_t index = Encoding::Get8(value);
size_t arraySize = delegate->GetNumEnergyBalances(endpoint);
if (index >= arraySize)
{
return imcode::ConstraintError;
return Status::ConstraintError;
}

return imcode::Success;
return Status::Success;
}

case CurrentLowPowerModeSensitivity::Id: {
if (lowPowerSupported == false)
{
return imcode::UnsupportedAttribute;
return Status::UnsupportedAttribute;
}

uint8_t index = Encoding::Get8(value);
size_t arraySize = delegate->GetNumLowPowerModes(endpoint);
size_t arraySize = delegate->GetNumLowPowerModeSensitivities(endpoint);
if (index >= arraySize)
{
return imcode::ConstraintError;
return Status::ConstraintError;
}

return imcode::Success;
return Status::Success;
}
default:
return imcode::Success;
return Status::Success;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,58 @@ namespace chip::app::Clusters::EnergyPreference

struct Delegate
{
//Note: This delegate does not handle the "Current Active" indexes attributes storage.
//eg: Current Energy Balance and Current Low Power Mode Sensitivity. These can be handled using
//ember built in storage, or via the external callbacks as desired by the implementer.

virtual ~Delegate() {}

// Gives a reference to the energy balance struct at aIndex
// Balance struct should exist for the life time of the matter server
/**
* Get an Energy Balance.
* @param aEndpoint The endpoint to query.
* @param aIndex The index of the balance, with 0 representing the first one.
* @param aOutBalance The BalanceStruct to copy the data into.
* @return CHIP_ERROR_NOT_FOUND if the index is out of range.
*/
virtual CHIP_ERROR GetEnergyBalanceAtIndex(chip::EndpointId aEndpoint, size_t aIndex,
chip::app::Clusters::EnergyPreference::Structs::BalanceStruct::Type & balance) = 0;
chip::app::Clusters::EnergyPreference::Structs::BalanceStruct::Type & aOutBalance) = 0;

// Gives a reference to the at aIndex
/**
* Get an Energy Priority.
* @param aEndpoint The endpoint to query.
* @param aIndex The index of the priority, with 0 representing the first one.
* @param aOutPriority The EnergyPriorityEnum to copy the data into.
* @return CHIP_ERROR_NOT_FOUND if the index is out of range.
*/
virtual CHIP_ERROR GetEnergyPriorityAtIndex(chip::EndpointId aEndpoint, size_t aIndex,
chip::app::Clusters::EnergyPreference::EnergyPriorityEnum & priority) = 0;
chip::app::Clusters::EnergyPreference::EnergyPriorityEnum & aOutPriority) = 0;


// Gives a reference to the low power mode sensitivity balance struct at aIndex
// Balance struct should exist for the life time of the matter server
/**
* Get a Power Sensitity Balance Struct.
* @param aEndpoint The endpoint to query.
* @param aIndex The index of the priority, with 0 representing the first one.
* @param aOutBalance The BalanceStruct to copy the data into.
* @return CHIP_ERROR_NOT_FOUND if the index is out of range.
*/
virtual CHIP_ERROR
GetLowPowerModeSensitivityAtIndex(chip::EndpointId aEndpoint, size_t aIndex,
chip::app::Clusters::EnergyPreference::Structs::BalanceStruct::Type & balance) = 0;
chip::app::Clusters::EnergyPreference::Structs::BalanceStruct::Type & aOutBalance) = 0;


/**
* Get the number of energy balances this endpoint has.
* @param aEndpoint The endpoint to query.
* @return the number of balance structs in the list.
*/
virtual size_t GetNumEnergyBalances(chip::EndpointId aEndpoint) = 0;
virtual size_t GetNumLowPowerModes(chip::EndpointId aEndpoint) = 0;

/**
* Get the number of low power mode sensitivities this endpoint has.
* @param aEndpoint The endpoint to query.
* @return the number of balance structs in the list.
*/
virtual size_t GetNumLowPowerModeSensitivities(chip::EndpointId aEndpoint) = 0;
};

void SetDelegate(Delegate * aDelegate);
Expand Down

0 comments on commit a228f2d

Please sign in to comment.