Skip to content

Commit

Permalink
Merged in DSRR-158-RebasingBranch (pull request #319)
Browse files Browse the repository at this point in the history
DSRR-158 RebasingBranch

Approved-by: Farzad Raiyat
  • Loading branch information
jamesharrow committed Nov 22, 2023
2 parents 4e2ab45 + 250f69c commit a4b70f3
Show file tree
Hide file tree
Showing 8 changed files with 664 additions and 139 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ CHIP_ERROR DataModelLogger::LogEvent(const chip::app::EventHeader & header, chip
{{/first}}
case {{asUpperCamelCase parent.name}}::Events::{{asUpperCamelCase name}}::Id:
{
{{zapTypeToDecodableClusterObjectType name ns=parent.name forceNotOptional=true}} value;
{{asUpperCamelCase parent.name}}::Events::{{asUpperCamelCase name}}::DecodableType value;
ReturnErrorOnFailure(chip::app::DataModel::Decode(*data, value));
return DataModelLogger::LogValue("{{name}}", 1, value);
}
Expand Down
7 changes: 5 additions & 2 deletions src/app/chip_data_model.gni
Original file line number Diff line number Diff line change
Expand Up @@ -321,13 +321,16 @@ template("chip_data_model") {
"${_app_root}/clusters/${cluster}/${cluster}.cpp",
"${_app_root}/clusters/${cluster}/${cluster}.h",
]
} else if (cluster == "device-energy-management-server") {
sources += [
"${_app_root}/clusters/${cluster}/${cluster}.cpp",
"${_app_root}/clusters/${cluster}/DefaultDeviceEnergyManagementDelegate.cpp",
]
} else if (cluster == "energy-evse-server") {
sources += [
"${_app_root}/clusters/${cluster}/${cluster}.cpp",
"${_app_root}/clusters/${cluster}/DefaultEnergyEvseDelegate.cpp",
]
cflags +=
[ "-DTIME_SYNC_ENABLE_TSC_FEATURE=${time_sync_enable_tsc_feature}" ]
} else {
sources += [ "${_app_root}/clusters/${cluster}/${cluster}.cpp" ]
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
*
* 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 "DefaultDeviceEnergyManagementDelegate.h"
#include <string>

using namespace chip::app::Clusters::DeviceEnergyManagement;

CHIP_ERROR DefaultDeviceEnergyManagementDelegate::HandleGetForecast(chip::app::AttributeValueEncoder & aEncoder)
{
return aEncoder.EncodeList([this](const auto & encoder) -> CHIP_ERROR {
Structs::ForecastStruct::Type forecast;
forecast.forecastId = static_cast<uint16_t>(5678);
forecast.startTime = static_cast<uint32_t>(8765);
ReturnErrorOnFailure(encoder.Encode(forecast));
return CHIP_NO_ERROR;
});

ChipLogProgress(Zcl, "DEM: %s Temporary test implementation", __FUNCTION__);
return CHIP_ERROR_NOT_IMPLEMENTED;
}

CHIP_ERROR DefaultDeviceEnergyManagementDelegate::PowerAdjustRequest(const int64_t power, const uint32_t durationSec)
{
ChipLogProgress(Zcl, "DEM: %s not implemented", __FUNCTION__);
return CHIP_ERROR_NOT_IMPLEMENTED;
}

CHIP_ERROR DefaultDeviceEnergyManagementDelegate::CancelPowerAdjustRequest()
{
ChipLogProgress(Zcl, "DEM: %s not implemented", __FUNCTION__);
return CHIP_ERROR_NOT_IMPLEMENTED;
}

CHIP_ERROR DefaultDeviceEnergyManagementDelegate::StartTimeAdjustRequest(const uint32_t requestedStartTime)
{
ChipLogProgress(Zcl, "DEM: %s not implemented", __FUNCTION__);
return CHIP_ERROR_NOT_IMPLEMENTED;
}

CHIP_ERROR DefaultDeviceEnergyManagementDelegate::PauseRequest(const uint32_t duration)
{
ChipLogProgress(Zcl, "DEM: %s not implemented", __FUNCTION__);
return CHIP_ERROR_NOT_IMPLEMENTED;
}

CHIP_ERROR DefaultDeviceEnergyManagementDelegate::ResumeRequest()
{
ChipLogProgress(Zcl, "DEM: %s not implemented", __FUNCTION__);
return CHIP_ERROR_NOT_IMPLEMENTED;
}

CHIP_ERROR DefaultDeviceEnergyManagementDelegate::ModifyForecastRequest( const uint32_t forecastId, const DataModel::DecodableList<Structs::SlotAdjustmentStruct::DecodableType> & slotAdjustments)
{
ChipLogProgress(Zcl, "DEM: %s not implemented", __FUNCTION__);
return CHIP_ERROR_NOT_IMPLEMENTED;
}

CHIP_ERROR DefaultDeviceEnergyManagementDelegate::RequestConstraintBasedForecast(const DataModel::DecodableList<Structs::ConstraintsStruct::DecodableType> & constraints)
{
ChipLogProgress(Zcl, "DEM: %s not implemented", __FUNCTION__);
return CHIP_ERROR_NOT_IMPLEMENTED;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
*
* 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.
*/

#pragma once

#include "device-energy-management-delegate.h"

namespace chip {
namespace app {
namespace Clusters {
namespace DeviceEnergyManagement {

class DefaultDeviceEnergyManagementDelegate : public Delegate
{

public:
DefaultDeviceEnergyManagementDelegate() : Delegate(){};

CHIP_ERROR HandleGetForecast(chip::app::AttributeValueEncoder & aEncoder) override;

CHIP_ERROR PowerAdjustRequest(const int64_t power, const uint32_t duration) override;
CHIP_ERROR CancelPowerAdjustRequest() override;
CHIP_ERROR StartTimeAdjustRequest(const uint32_t requestedStartTime) override;
CHIP_ERROR PauseRequest(const uint32_t duration) override;
CHIP_ERROR ResumeRequest() override;
CHIP_ERROR ModifyForecastRequest( const uint32_t forecastId, const DataModel::DecodableList<Structs::SlotAdjustmentStruct::DecodableType> & slotAdjustments) override;
CHIP_ERROR RequestConstraintBasedForecast(const DataModel::DecodableList<Structs::ConstraintsStruct::DecodableType> & constraints) override;
};

} // namespace DeviceEnergyManagement
} // namespace Clusters
} // namespace app
} // namespace chip
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
/*
*
* 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.
*/

#pragma once

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

namespace chip {
namespace app {
namespace Clusters {
namespace DeviceEnergyManagement {

using SlotAdjustmentStruct = chip::app::Clusters::DeviceEnergyManagement::Structs::SlotAdjustmentStruct::Type;
using ConstraintsStruct = chip::app::Clusters::DeviceEnergyManagement::Structs::ConstraintsStruct::Type;


/** @brief
* Defines methods for implementing application-specific logic for the DeviceEnergyManagement Cluster.
*/
class Delegate
{
public:
inline bool HasFeature(Feature feature)
{
uint32_t map;
bool success = (Attributes::FeatureMap::Get(mEndpoint, &map) == EMBER_ZCL_STATUS_SUCCESS);
return success ? (map & to_underlying(feature)) : false;
}

inline EndpointId GetEndpoint() { return mEndpoint; }
inline void SetEndpoint(EndpointId ep) { mEndpoint = ep; }

/**
* @brief Support framework access to the Forecast struct, a 'complex' attribute.
*
* @param aEncoder Framework provided encoder to serialise a Forecast.
* @return CHIP_NO_ERROR if successfull; otherwise the command SHALL be rejected with appropriate error.
*/
virtual CHIP_ERROR HandleGetForecast(chip::app::AttributeValueEncoder & aEncoder) = 0;

/**
* @brief Delegate should implement a handler to begin to adjust client power
* consumption/generation to the level requested.
*
* @param power Milli-Watts the ESA SHALL use during the adjustment period. Positive values indicate the direction of current flow -towards- a load.
* @param duration The duration that the ESA SHALL maintain the requested power for.
* @return CHIP_NO_ERROR if the adjustment is accepted; otherwise the command SHALL be rejected with appropriate error.
*/
virtual CHIP_ERROR PowerAdjustRequest(const int64_t power, const uint32_t duration) = 0;

/**
* @brief Delegate SHALL make the ESA end the active power adjustment session & return to normal (or idle) power levels.
* The ESA SHALL also generate an PowerAdjustEnd Event and the ESAState SHALL be restored to Online.
*
* @return It should report SUCCESS if successful and FAILURE otherwise.
*/
virtual CHIP_ERROR CancelPowerAdjustRequest() = 0;

/**
* @brief Delegate for the ESA SHALL update its Forecast attribute with the RequestedStartTime including a new ForecastId.
*
* If the ESA supports ForecastAdjustment, and the ESAState is not UserOptOut and the RequestedStartTime is after
* the EarliestStartTime and the resulting EndTime is before the LatestEndTime, then ESA SHALL accept the request
* to modify the Start Time.
* A client can estimate the entire Forecast sequence duration by computing the EndTime - StartTime fields from the
* Forecast attribute, and therefore avoid scheduling the start time too late.
*
* @param requestedStartTime The requested start time in UTC that the client would like the appliance to shift its power forecast to.
* @return CHIP_NO_ERROR if the StartTime in the Forecast is updated, otherwise the command SHALL be rejected with appropriate CHIP_ERROR.
*/
virtual CHIP_ERROR StartTimeAdjustRequest(const uint32_t requestedStartTime) = 0;

/**
* @brief Delegate implementation:
* If the ESA supports FA and either the SlotIsPauseable field is true in the ActiveSlotNumber index in the
* Slots list, or the IsPausable field is true in the Forecast attribute structure, and the ESAState is not
* UserOptOut then the ESA SHALL pause its current operation.
* During this state the ESA SHALL not consume or produce significant power (other than required to keep its
* basic control system operational).
* The ESA SHALL also generate a Paused Event and the ESAState SHALL be restored to Paused.
*
* @param duration Duration that the ESA SHALL be paused for. SHALL be between MinPauseDuration & MaxPauseDuration for current slot.
* @return CHIP_NO_ERROR if the ESA is paused, otherwise returns other CHIP_ERRORs.
*/
virtual CHIP_ERROR PauseRequest(const uint32_t duration) = 0;

/**
* @brief Delegate implementation:
* If the ESA supports FA and it is currently Paused then the ESA SHALL resume its operation.
* The ESA SHALL also generate a Resumed Event and the ESAState SHALL be updated accordingly to
* reflect its current state.
*
* @return CHIP_NO_ERROR if the ESA is resumed, otherwise returns other CHIP_ERRORs.
*/
virtual CHIP_ERROR ResumeRequest() = 0;

/**
* @brief Delegate should implement:
* If the ESA supports FA, and the ESAState is not UserOptOut it SHALL attempt to adjust its power forecast.
* This allows a one or more modifications in a single command by sending a list of modifications (one for each 'slot').
* Attempts to modify slots which have already past, SHALL result in the entire command being rejected.
* If the ESA accepts the requested Forecast then it SHALL update its Forecast attribute (incrementing its ForecastId)
* and run the revised Forecast as its new intended operation.
*
* @param forecastId Indicates the ESA ForecastId that is to be modified.
* @param slotAdjustments List of adjustments to be applied to the ESA, corresponding to the expected ESA forecastId.
* @return CHIP_NO_ERROR if the entire list of SlotAdjustmentStruct are accepted, otherwise the command
* SHALL be rejected returning other CHIP_ERRORs.
*/
virtual CHIP_ERROR ModifyForecastRequest( const uint32_t forecastId, const DataModel::DecodableList<Structs::SlotAdjustmentStruct::DecodableType> & slotAdjustments) = 0;

/**
* @brief Delegate should implement:
* The ESA SHALL inspect the requested power limits to ensure that there are no overlapping elements. The ESA
* manufacturer may also reject the request if it could cause the user’s preferences to be breached (e.g. may
* cause the home to be too hot or too cold, or a battery to be insufficiently charged).
* If the ESA can meet the requested power limits, it SHALL regenerate a new Power Forecast with a new ForecastId.
*
* @param constraints Sequence of turn up/down power requests that the ESA is being asked to constrain its operation within.
* @return CHIP_NO_ERROR if successfull, otherwise the command SHALL be rejected returning other CHIP_ERRORs.
*/
virtual CHIP_ERROR RequestConstraintBasedForecast(const DataModel::DecodableList<Structs::ConstraintsStruct::DecodableType> & constraints) = 0;



virtual ~Delegate() = default;

private:
EndpointId mEndpoint = kRootEndpointId;
};

} // namespace DeviceEnergyManagement
} // namespace Clusters
} // namespace app
} // namespace chip
Loading

0 comments on commit a4b70f3

Please sign in to comment.