Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add device-energy-management cluster example app code for 1.4 #33910

Merged
merged 83 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
83 commits
Select commit Hold shift + click to select a range
90ac94b
Get the EVSE app building and test TC_DEM_2_2 passing
PeterC1965 Jun 13, 2024
c683503
Get all targets building
PeterC1965 Jun 13, 2024
0ac11b7
Address JamesH review comments
PeterC1965 Jun 15, 2024
3cb089f
Rename utils.cpp to DEMUtils.cpp
PeterC1965 Jun 15, 2024
6688c42
Address JamesH review comments
PeterC1965 Jun 15, 2024
f0858e1
Restyled by whitespace
restyled-commits Jun 15, 2024
757bc1c
Restyled by clang-format
restyled-commits Jun 15, 2024
eccee31
Restyled by gn
restyled-commits Jun 15, 2024
d176136
Restyled by prettier-markdown
restyled-commits Jun 15, 2024
86d7929
Restyled by autopep8
restyled-commits Jun 15, 2024
e9c2f5f
Restyled by isort
restyled-commits Jun 15, 2024
78742f6
Merge branch 'master' into add-dem-example-code-for-1-4
PeterC1965 Jun 15, 2024
a45e6dd
Fix compilation problem by including lib/core/DataModelTypes.h
PeterC1965 Jun 15, 2024
fe103a9
Fix compilation problem by including
PeterC1965 Jun 15, 2024
a6f0b6d
Save examples/all-clusters-app/all-clusters-common/all-clusters-app.z…
PeterC1965 Jun 15, 2024
9cef023
Restyled by clang-format
restyled-commits Jun 15, 2024
2cbe9c6
Apply further code review changes
PeterC1965 Jun 19, 2024
46e8f0c
Restyled by clang-format
restyled-commits Jun 19, 2024
78e6951
Restyled by gn
restyled-commits Jun 19, 2024
73a6430
Address code review comments from AndreiL
PeterC1965 Jun 20, 2024
cfc815e
Restyled by whitespace
restyled-commits Jun 20, 2024
b2c1616
Restyled by clang-format
restyled-commits Jun 20, 2024
61cca47
Fix ESP build
PeterC1965 Jun 20, 2024
55d778e
Fix ESP build
PeterC1965 Jun 20, 2024
6c65ac4
Restyled by clang-format
restyled-commits Jun 20, 2024
c55ca01
Rename src/python_testing/TC_DEM_Utils.py src/python_testing/DEMTestB…
PeterC1965 Jun 25, 2024
d469ba0
Put time util funtions into namespace + drop the Utils prefix
PeterC1965 Jun 25, 2024
a89767f
Restyled by whitespace
restyled-commits Jun 25, 2024
2038023
Restyled by isort
restyled-commits Jun 25, 2024
4417749
Merge branch 'master' into add-dem-example-code-for-1-4
PeterC1965 Jun 25, 2024
6a76ba9
Try to address setForecast comments from Boris
PeterC1965 Jul 3, 2024
5ebaf22
Remove unnecessary SetXXX methods from the device energy management c…
PeterC1965 Jul 3, 2024
5e90f9f
Merge branch 'master' into add-dem-example-code-for-1-4
PeterC1965 Jul 3, 2024
afcc61f
Restyled by clang-format
restyled-commits Jul 3, 2024
78633e0
Apply code review changes suggested by Louis-Philip Beliveau
PeterC1965 Jul 13, 2024
85bae27
Document the API for GetForecast and GetPowerAdjustmentCapability
PeterC1965 Jul 15, 2024
3ed6f14
Document the GetForecast and GetPowerAdjustmentCapability APIs
PeterC1965 Jul 15, 2024
5fee7b9
Update src/app/clusters/device-energy-management-server/device-energy…
PeterC1965 Jul 18, 2024
7194f5b
Update src/app/clusters/device-energy-management-server/device-energy…
PeterC1965 Jul 18, 2024
d93a68e
Address review comments from Boris
PeterC1965 Jul 18, 2024
a1d146c
Sync up with code review comments from PR34234
PeterC1965 Jul 18, 2024
441d586
Sync up with code review comments from PR34234 that caused some retur…
PeterC1965 Jul 18, 2024
e2fff77
Merge branch 'master' into add-dem-example-code-for-1-4
PeterC1965 Jul 18, 2024
c984a59
Restyled by clang-format
restyled-commits Jul 18, 2024
b52bc59
modifyForecastRequest: Failure should be returned if a slot number > …
PeterC1965 Jul 18, 2024
0c48248
Update examples/energy-management-app/energy-management-common/includ…
PeterC1965 Jul 18, 2024
5f9896e
Update examples/energy-management-app/energy-management-common/includ…
PeterC1965 Jul 18, 2024
178b5a6
Update examples/energy-management-app/energy-management-common/includ…
PeterC1965 Jul 18, 2024
d2369fe
Update examples/energy-management-app/energy-management-common/includ…
PeterC1965 Jul 18, 2024
27fef24
Update examples/energy-management-app/energy-management-common/includ…
PeterC1965 Jul 18, 2024
2ed990b
Update examples/energy-management-app/energy-management-common/src/DE…
PeterC1965 Jul 18, 2024
412b2e4
Update examples/energy-management-app/energy-management-common/includ…
PeterC1965 Jul 18, 2024
cb04ca1
Update examples/energy-management-app/energy-management-common/src/DE…
PeterC1965 Jul 18, 2024
1db507a
Update examples/energy-management-app/energy-management-common/src/DE…
PeterC1965 Jul 18, 2024
083f324
Address review comments from Boris
PeterC1965 Jul 18, 2024
979353f
Update examples/energy-management-app/energy-management-common/src/De…
PeterC1965 Jul 18, 2024
3e56098
Address further review comments from Boris
PeterC1965 Jul 18, 2024
df78a95
Address further review comments from Boris
PeterC1965 Jul 18, 2024
be69ceb
Address further review comments from Boris
PeterC1965 Jul 18, 2024
3c57718
Update examples/energy-management-app/energy-management-common/src/De…
PeterC1965 Jul 18, 2024
b8d55ce
Address further review comments from Boris
PeterC1965 Jul 18, 2024
38a065e
Merge branch 'master' into add-dem-example-code-for-1-4
PeterC1965 Jul 18, 2024
8ad9905
Merge branch 'master' into add-dem-example-code-for-1-4
PeterC1965 Jul 18, 2024
7a9ded1
Update examples/energy-management-app/energy-management-common/src/DE…
PeterC1965 Jul 18, 2024
2001980
Update examples/energy-management-app/energy-management-common/src/En…
PeterC1965 Jul 18, 2024
940f102
Update examples/energy-management-app/energy-management-common/src/De…
PeterC1965 Jul 18, 2024
2cdc894
Update examples/energy-management-app/energy-management-common/src/De…
PeterC1965 Jul 18, 2024
1c5e33d
Apply further review comments from Boris
PeterC1965 Jul 20, 2024
14beb82
Used a bitmap rather than uint8_t and sync EnergyTimeUtils files from…
PeterC1965 Jul 20, 2024
fa59eb6
Update following review comments from Boris
PeterC1965 Jul 20, 2024
932c0c3
Merge branch 'master' into add-dem-example-code-for-1-4
PeterC1965 Jul 22, 2024
48014ef
Allow more time for forecast.startTime in test setup as tests can tak…
PeterC1965 Jul 23, 2024
6fcc1e7
Update examples/energy-management-app/energy-management-common/src/De…
PeterC1965 Jul 24, 2024
207f907
Update examples/energy-management-app/energy-management-common/src/En…
PeterC1965 Jul 24, 2024
0b1392f
Update examples/energy-management-app/energy-management-common/src/De…
PeterC1965 Jul 24, 2024
9bbcc88
Addressing further review comments from Boris
PeterC1965 Jul 24, 2024
07a172f
Fix small issue found as a result of the DEM test script review
PeterC1965 Jul 24, 2024
242b27f
Protect against forecast being null
PeterC1965 Jul 24, 2024
5d4c2b1
Remove src/python_testing/DEMTestBase.py as renamed in PR34234
PeterC1965 Jul 25, 2024
a955ceb
Merge branch 'master' into add-dem-example-code-for-1-4
PeterC1965 Jul 25, 2024
d924fa9
Update following review comment from Andrei
PeterC1965 Jul 25, 2024
07ed1fa
Restyled by clang-format
restyled-commits Jul 25, 2024
eecd532
Merge branch 'master' into add-dem-example-code-for-1-4
PeterC1965 Jul 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@

#pragma once

#include <app-common/zap-generated/cluster-enums.h>
#include <app/util/config.h>
#include <cstring>
#include <lib/core/CHIPError.h>
#include <lib/support/BitMask.h>
#include <protocols/Protocols.h>
#include <time.h>

Expand All @@ -45,19 +47,26 @@ CHIP_ERROR GetEpochTS(uint32_t & chipEpoch);
*
* @param unixEpoch (as time_t)
*
* @return bitmap value for day of week
* Sunday = 0x00, Monday = 0x01 ... Saturday = 0x40 (1<<6)
* @return bitmap value for day of week as defined by EnergyEvse::TargetDayOfWeekBitmap. Note
* only one bit will be set for the day of the week.
*/
uint8_t GetLocalDayOfWeekFromUnixEpoch(time_t unixEpoch);
BitMask<EnergyEvse::TargetDayOfWeekBitmap> GetLocalDayOfWeekFromUnixEpoch(time_t unixEpoch);

/**
* @brief Helper function to get current timestamp and work out the day of week based on localtime
*
* @param reference to hold the day of week as a bitmap
* @param reference to hold the day of week as a bitmap as defined by EnergyEvse::TargetDayOfWeekBitmap.
* Note only one bit will be set for the current day.
*/
CHIP_ERROR GetLocalDayOfWeekNow(BitMask<EnergyEvse::TargetDayOfWeekBitmap> & dayOfWeekMap);

/**
* @brief Helper function to get current timestamp and work out the current number of minutes
* past midnight based on localtime
*
* Sunday = 0x00, Monday = 0x01 ... Saturday = 0x40 (1<<6)
* @param reference to hold the number of minutes past midnight
*/
CHIP_ERROR GetLocalDayOfWeekNow(uint8_t & dayOfWeekMap);
CHIP_ERROR GetMinutesPastMidnight(uint16_t & minutesPastMidnight);

} // namespace DeviceEnergyManagement
} // namespace Clusters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ CHIP_ERROR ConfigureForecast(uint16_t numSlots)
return err;
}

// planned start time, in UTC, for the entire Forecast.
sForecastStruct.startTime = chipEpoch;
// planned start time, in UTC, for the entire Forecast. Allow to be a little
// time in the future as forecastStruct.startTime is used in some tests.
sForecastStruct.startTime = chipEpoch + 60;

// earliest start time, in UTC, that the entire Forecast can be shifted to. null value indicates that it can be started
// immediately.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ Status DeviceEnergyManagementDelegate::PowerAdjustRequest(const int64_t powerMw,

SetESAState(ESAStateEnum::kPowerAdjustActive);

// mPowerAdjustCapabilityStruct is guaranteed to have a value as validated in Instance::HandlePowerAdjustRequest.
// If it did not have a value, this method would not have been called.
hasty marked this conversation as resolved.
Show resolved Hide resolved
switch (cause)
{
case AdjustmentCauseEnum::kLocalOptimization:
Expand Down Expand Up @@ -927,7 +929,7 @@ CHIP_ERROR DeviceEnergyManagementDelegate::SetOptOutState(OptOutStateEnum newVal

if (oldValue != newValue)
{
ChipLogDetail(AppServer, "mOptOutState updated to %d mPowerAdjustmentInProgress %d", static_cast<int>(mOptOutState),
ChipLogDetail(AppServer, "mOptOutState updated to %d mPowerAdjustmentInProgress %d", to_underlying(mOptOutState),
mPowerAdjustmentInProgress);
MatterReportingAttributeChangeCallback(mEndpointId, DeviceEnergyManagement::Id, OptOutState::Id);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
*
* Copyright (c) 2024 Project CHIP Authors
* Copyright (c) 2023-2024 Project CHIP Authors
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
*
* Copyright (c) 2024 Project CHIP Authors
* Copyright (c) 2023-2024 Project CHIP Authors
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
*
* Copyright (c) 2024 Project CHIP Authors
* Copyright (c) 2023-2024 Project CHIP Authors
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ CHIP_ERROR GetEpochTS(uint32_t & chipEpoch)
if (!UnixEpochToChipEpochTime(unixEpoch, chipEpoch))
{
ChipLogError(Zcl, "Unable to convert Unix Epoch time to Matter Epoch Time");
return err;
return CHIP_ERROR_INCORRECT_STATE;
}

return CHIP_NO_ERROR;
Expand All @@ -80,10 +80,10 @@ CHIP_ERROR GetEpochTS(uint32_t & chipEpoch)
*
* @param unixEpoch (as time_t)
*
* @return bitmap value for day of week
* Sunday = 0x01, Monday = 0x01 ... Saturday = 0x40 (1<<6)
* @return bitmap value for day of week as defined by EnergyEvse::TargetDayOfWeekBitmap. Note
* only one bit will be set for the day of the week.
*/
uint8_t GetLocalDayOfWeekFromUnixEpoch(time_t unixEpoch)
BitMask<EnergyEvse::TargetDayOfWeekBitmap> GetLocalDayOfWeekFromUnixEpoch(time_t unixEpoch)
{
// Define a timezone structure and initialize it to the local timezone
// This will capture any daylight saving time changes
Expand All @@ -93,19 +93,19 @@ uint8_t GetLocalDayOfWeekFromUnixEpoch(time_t unixEpoch)
// Get the day of the week (0 = Sunday, 1 = Monday, ..., 6 = Saturday)
uint8_t dayOfWeek = static_cast<uint8_t>(local_time.tm_wday);

// Calculate the bitmap value based on the day of the week
// Calculate the bitmap value based on the day of the week. Note that the value in bitmap
// maps directly to the definition in EnergyEvse::TargetDayOfWeekBitmap.
uint8_t bitmap = static_cast<uint8_t>(1 << dayOfWeek);

return bitmap;
}
/**
* @brief Helper function to get current timestamp and work out the day of week based on localtime
*
* @param reference to hold the day of week as a bitmap
*
* Sunday = 0x01, Monday = 0x01 ... Saturday = 0x40 (1<<6)
* @return bitmap value for day of week as defined by EnergyEvse::TargetDayOfWeekBitmap. Note
* only one bit will be set for the current day.
*/
CHIP_ERROR GetLocalDayOfWeekNow(uint8_t & dayOfWeekMap)
CHIP_ERROR GetLocalDayOfWeekNow(BitMask<EnergyEvse::TargetDayOfWeekBitmap> & dayOfWeekMap)
{
System::Clock::Milliseconds64 cTMs;
CHIP_ERROR err = chip::System::SystemClock().GetClock_RealTimeMS(cTMs);
Expand All @@ -120,6 +120,33 @@ CHIP_ERROR GetLocalDayOfWeekNow(uint8_t & dayOfWeekMap)
return CHIP_NO_ERROR;
}

/**
* @brief Helper function to get current timestamp and work out the current number of minutes
* past midnight based on localtime
*
* @param reference to hold the number of minutes past midnight
*/
CHIP_ERROR GetMinutesPastMidnight(uint16_t & minutesPastMidnight)
{
chip::System::Clock::Milliseconds64 cTMs;
CHIP_ERROR err = chip::System::SystemClock().GetClock_RealTimeMS(cTMs);
PeterC1965 marked this conversation as resolved.
Show resolved Hide resolved
if (err != CHIP_NO_ERROR)
{
ChipLogError(Zcl, "EVSE: unable to get current time to check user schedules error=%" CHIP_ERROR_FORMAT, err.Format());
return err;
}
time_t unixEpoch = std::chrono::duration_cast<chip::System::Clock::Seconds32>(cTMs).count();

// Define a timezone structure and initialize it to the local timezone
// This will capture any daylight saving time changes
struct tm local_time;
localtime_r(&unixEpoch, &local_time);

minutesPastMidnight = static_cast<uint16_t>((local_time.tm_hour * 60) + local_time.tm_min);

return err;
}

} // namespace DeviceEnergyManagement
} // namespace Clusters
} // namespace app
Expand Down
Loading