-
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.
Merged in DSRR-160-B-Implement_SDK_DEM_Delegate (pull request #326)
DSRR-160-B-Implement_SDK_DEM_Delegate Approved-by: James Harrow
- Loading branch information
Showing
3 changed files
with
165 additions
and
136 deletions.
There are no files selected for viewing
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
162 changes: 162 additions & 0 deletions
162
...nagement-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl_TestData.cpp
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,162 @@ | ||
/* | ||
* | ||
* 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 "DeviceEnergyManagementDelegateImpl.h" | ||
#include <string> | ||
|
||
using namespace chip::app::Clusters::DeviceEnergyManagement; | ||
using chip::Optional; | ||
using namespace chip::app; | ||
using CostsList = DataModel::List<const Structs::CostStruct::Type>; | ||
|
||
|
||
#ifdef DELEGATE_TEST_DATA | ||
static const Structs::SlotStruct::Type gSlot { | ||
static_cast<uint32_t>(120), // minDuration | ||
static_cast<uint32_t>(230), // maxDuration | ||
static_cast<uint32_t>(340), // defaultDuration | ||
static_cast<uint32_t>(450), // elapsedSlotTime | ||
static_cast<uint32_t>(560), // remainingSlotTime | ||
true, // slotIsPauseable | ||
static_cast<uint32_t>(670), // minPauseDuration | ||
static_cast<uint32_t>(780), // maxPauseDuration | ||
Optional<uint16_t>{0}, // manufacturerESAState; | ||
Optional<int64_t>{1}, // nominalPower; | ||
Optional<int64_t>{2}, // minPower; | ||
Optional<int64_t>{3}, // maxPower; | ||
Optional<int64_t>{4}, // nominalEnergy; | ||
|
||
Optional<DataModel::List<const Structs::CostStruct::Type>>{ | ||
DataModel::List<const Structs::CostStruct::Type>(), | ||
}, | ||
|
||
Optional<int64_t> {5}, // minPowerAdjustment; | ||
Optional<int64_t> {6}, // maxPowerAdjustment; | ||
Optional<uint32_t>{7}, // minDurationAdjustment; | ||
Optional<uint32_t>{8} // maxDurationAdjustment; | ||
}; | ||
|
||
// Just for testing. TODO: To be removed ? | ||
static void FillCostStruct(Structs::CostStruct::Type & cost) | ||
{ | ||
static uint8_t inc = 0; | ||
static CostTypeEnum t = CostTypeEnum::kComfort; | ||
|
||
cost.costType = t; | ||
cost.value = static_cast<int32_t>(222 + inc); | ||
cost.decimalPoints = static_cast<uint8_t>(111 + inc); | ||
cost.currency = Optional<uint16_t> { static_cast<uint16_t>(333 + inc)}; | ||
|
||
if (t == CostTypeEnum::kComfort) | ||
{ | ||
t = CostTypeEnum::kTemperature; | ||
} | ||
else | ||
{ | ||
t = CostTypeEnum::kComfort; | ||
} | ||
inc++; | ||
} | ||
|
||
// Just for testing. TODO: To be removed ? | ||
static void FillForecast(Structs::ForecastStruct::Type & forecast) | ||
{ | ||
forecast.forecastId = static_cast<uint16_t>(1234); | ||
|
||
forecast.activeSlotNumber.SetNonNull<uint16_t>(2345); | ||
forecast.startTime = static_cast<uint32_t>(34567); | ||
forecast.endTime = static_cast<uint32_t>(45678); | ||
forecast.earliestStartTime = Optional<DataModel::Nullable<uint32_t>> {DataModel::Nullable<uint32_t>{56789}}; // Optional<DataModel::Nullable<uint32_t>> | ||
forecast.latestEndTime = Optional<uint32_t> (static_cast<uint32_t>(67890)); | ||
forecast.isPauseable = true; | ||
|
||
uint32_t slotCount = 2; | ||
Structs::SlotStruct::Type * slots = new Structs::SlotStruct::Type[slotCount]; | ||
slots[0] = gSlot; | ||
|
||
slots[1].minDuration = gSlot.minDuration + 1; | ||
slots[1].maxDuration = gSlot.maxDuration + 1; | ||
slots[1].defaultDuration = gSlot.defaultDuration + 1; | ||
slots[1].elapsedSlotTime = gSlot.elapsedSlotTime + 1; | ||
slots[1].remainingSlotTime = gSlot.remainingSlotTime + 1; | ||
slots[1].slotIsPauseable = !gSlot.slotIsPauseable; | ||
slots[1].minPauseDuration = gSlot.minPauseDuration + 1; | ||
slots[1].maxPauseDuration = gSlot.maxPauseDuration + 1; | ||
slots[1].manufacturerESAState = Optional<uint16_t>{90}; | ||
slots[1].nominalPower = Optional<int64_t>{91}; | ||
slots[1].minPower = Optional<int64_t>{92}; | ||
slots[1].maxPower = Optional<int64_t>{93}; | ||
slots[1].nominalEnergy = Optional<int64_t>{94}; | ||
|
||
// Optional<DataModel::List<const Structs::CostStruct::Type>> costs; | ||
slots[1].costs = Optional<DataModel::List<const Structs::CostStruct::Type>>{ | ||
DataModel::List<const Structs::CostStruct::Type>()}; | ||
|
||
slots[1].minPowerAdjustment = Optional<int64_t>{95}; | ||
slots[1].maxPowerAdjustment = Optional<int64_t>{96}; | ||
slots[1].minDurationAdjustment = Optional<uint32_t>{97}; | ||
slots[1].maxDurationAdjustment = Optional<uint32_t>{98}; | ||
|
||
forecast.slots = DataModel::List<const Structs::SlotStruct::Type>(slots, slotCount); | ||
|
||
uint32_t costsCount = 2; | ||
Structs::CostStruct::Type * costs1 = new Structs::CostStruct::Type[costsCount]; | ||
Structs::CostStruct::Type * costs2 = new Structs::CostStruct::Type[costsCount]; | ||
|
||
FillCostStruct(costs1[0]); | ||
FillCostStruct(costs1[1]); | ||
FillCostStruct(costs2[0]); | ||
FillCostStruct(costs2[1]); | ||
|
||
slots[0].costs = Optional<CostsList> {CostsList(costs1, costsCount)}; | ||
slots[1].costs = Optional<CostsList> {CostsList(costs2, costsCount)}; | ||
} | ||
|
||
DeviceEnergyManagementDelegateImpl::DeviceEnergyManagementDelegateImpl() | ||
{ | ||
EmberAfStatus s = EMBER_ZCL_STATUS_SUCCESS; | ||
chip::EndpointId endpoint = this->sEndpoint; | ||
uint32_t fmap = static_cast<uint32_t>(DEM::Feature::kForecastAdjustment); | ||
|
||
// TODO: remove ? Force enables the ForecastAdjustment feature. | ||
s = DEM::Attributes::FeatureMap::Set(endpoint, fmap); | ||
if (EMBER_ZCL_STATUS_SUCCESS != s) | ||
{ | ||
ChipLogProgress(Zcl, "zzzzzzzzzzDEM: %s Failed FeatureMap::Set()", __FUNCTION__); | ||
goto DEPARTURES; | ||
} | ||
|
||
#if 0 // Set UserOptOut in ESAState for testing ? | ||
{ | ||
DEM::ESAStateEnum esaStatus = DEM::ESAStateEnum::kUserOptOut; | ||
s = DEM::Attributes::ESAState::Set(endpoint, esaStatus); | ||
if (EMBER_ZCL_STATUS_SUCCESS != s) | ||
{ | ||
ChipLogProgress(Zcl, "zzzzzzzzzzDEM: %s Failed to set() ESAStateEnum::kUserOptOut", __FUNCTION__); | ||
goto DEPARTURES; | ||
} | ||
} | ||
#endif | ||
|
||
FillForecast(mForecast); | ||
ChipLogProgress(Zcl, "zzzzzzzzzzDEM: %s Enabled Feature ForecastAdjustment", __FUNCTION__); | ||
|
||
DEPARTURES: | ||
return; | ||
} | ||
#endif |
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