Skip to content

Commit

Permalink
[Silabs] Fix silabs energy mangement app (#35658)
Browse files Browse the repository at this point in the history
* Fix BUILD.gn which was broken in moving files around in energy management app.

* Added BUILD.gn arguments to enable different feature support. Updated README. Added test event triggers.

* Removed blank lines

* Added test event triggers

* [Silabs] Fix silabs energy mangement app

* Fix gn conditional inclusions

* Fix GN conflict

---------

Co-authored-by: James Harrow <james.harrow@gmail.com>
Co-authored-by: lpbeliveau-silabs <louis-philip.beliveau@silabs.com>
Co-authored-by: Faisal Bhaiyat <faisal.bhaiyat@silabs.com>
  • Loading branch information
4 people authored Sep 20, 2024
1 parent 7b8467b commit be3c70a
Show file tree
Hide file tree
Showing 10 changed files with 203 additions and 38 deletions.
72 changes: 54 additions & 18 deletions examples/energy-management-app/silabs/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,21 @@ import("${examples_common_plat_dir}/args.gni")
declare_args() {
# Dump memory usage at link time.
chip_print_memory_usage = false

# Enable test event triggers by default: Disable these in production devices
sl_enable_energy_evse_trigger = true
sl_enable_energy_reporting_trigger = true
sl_enable_water_heater_management_trigger = true
sl_enable_device_energy_management_trigger = true

# Device Energy Management feature support - only one of these can be true
# or both can be disabled if forecasting is not supported
sl_dem_support_power_forecast_reporting = true
sl_dem_support_state_forecast_reporting = false

# Only one of these examples should be enabled
sl_enable_example_evse_device = true
sl_enable_example_water_heater_device = false
}

if (slc_generate) {
Expand Down Expand Up @@ -101,7 +116,11 @@ if (wifi_soc) {
"${examples_plat_dir}",
"${chip_root}/src/lib",
"${examples_common_plat_dir}",
"../energy-management-common/include",
"${chip_root}/examples/energy-management-app/energy-management-common/common/include",
"${chip_root}/examples/energy-management-app/energy-management-common/device-energy-management/include",
"${chip_root}/examples/energy-management-app/energy-management-common/energy-evse/include",
"${chip_root}/examples/energy-management-app/energy-management-common/energy-reporting/include",
"${chip_root}/examples/energy-management-app/energy-management-common/water-heater/include",
]

if (use_wf200) {
Expand Down Expand Up @@ -131,28 +150,45 @@ silabs_executable("energy-management-app") {
include_dirs = [ "include" ]
defines = []

defines += [
"SL_MATTER_CONFIG_ENABLE_ENERGY_EVSE_TRIGGER=${sl_enable_energy_evse_trigger}",
"SL_MATTER_CONFIG_ENABLE_ENERGY_REPORTING_TRIGGER=${sl_enable_energy_reporting_trigger}",
"SL_MATTER_CONFIG_ENABLE_WATER_HEATER_MANAGEMENT_TRIGGER=${sl_enable_water_heater_management_trigger}",
"SL_MATTER_CONFIG_ENABLE_DEVICE_ENERGY_MANAGEMENT_TRIGGER=${sl_enable_device_energy_management_trigger}",
"SL_MATTER_CONFIG_DEM_SUPPORT_POWER_FORECAST_REPORTING=${sl_dem_support_power_forecast_reporting}",
"SL_MATTER_CONFIG_DEM_SUPPORT_STATE_FORECAST_REPORTING=${sl_dem_support_state_forecast_reporting}",
"SL_MATTER_CONFIG_ENABLE_EXAMPLE_EVSE_DEVICE=${sl_enable_example_evse_device}",
"SL_CONFIG_ENABLE_EXAMPLE_WATER_HEATER_DEVICE=${sl_enable_example_water_heater_device}",
]

if (silabs_board == "BRD2704A") {
defines += [ "SL_STATUS_LED=0" ]
}

sources = [
"${chip_root}/examples/energy-management-app/energy-management-common/src/ChargingTargetsMemMgr.cpp",
"${chip_root}/examples/energy-management-app/energy-management-common/src/DEMTestEventTriggers.cpp",
"${chip_root}/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp",
"${chip_root}/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementManager.cpp",
"${chip_root}/examples/energy-management-app/energy-management-common/src/EVSEManufacturerImpl.cpp",
"${chip_root}/examples/energy-management-app/energy-management-common/src/ElectricalPowerMeasurementDelegate.cpp",
"${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyEvseDelegateImpl.cpp",
"${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyEvseEventTriggers.cpp",
"${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyEvseMain.cpp",
"${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyEvseManager.cpp",
"${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyEvseTargetsStore.cpp",
"${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyReportingEventTriggers.cpp",
"${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyTimeUtils.cpp",
"${chip_root}/examples/energy-management-app/energy-management-common/src/FakeReadings.cpp",
"${chip_root}/examples/energy-management-app/energy-management-common/src/PowerTopologyDelegate.cpp",
"${chip_root}/examples/energy-management-app/energy-management-common/src/device-energy-management-mode.cpp",
"${chip_root}/examples/energy-management-app/energy-management-common/src/energy-evse-mode.cpp",
"${chip_root}/examples/energy-management-app/energy-management-common/common/src/EnergyTimeUtils.cpp",
"${chip_root}/examples/energy-management-app/energy-management-common/device-energy-management/src/DEMTestEventTriggers.cpp",
"${chip_root}/examples/energy-management-app/energy-management-common/device-energy-management/src/DeviceEnergyManagementDelegateImpl.cpp",
"${chip_root}/examples/energy-management-app/energy-management-common/device-energy-management/src/DeviceEnergyManagementManager.cpp",
"${chip_root}/examples/energy-management-app/energy-management-common/device-energy-management/src/device-energy-management-mode.cpp",
"${chip_root}/examples/energy-management-app/energy-management-common/energy-evse/src/ChargingTargetsMemMgr.cpp",
"${chip_root}/examples/energy-management-app/energy-management-common/energy-evse/src/EVSEManufacturerImpl.cpp",
"${chip_root}/examples/energy-management-app/energy-management-common/energy-evse/src/EnergyEvseDelegateImpl.cpp",
"${chip_root}/examples/energy-management-app/energy-management-common/energy-evse/src/EnergyEvseEventTriggers.cpp",
"${chip_root}/examples/energy-management-app/energy-management-common/energy-evse/src/EnergyEvseMain.cpp",
"${chip_root}/examples/energy-management-app/energy-management-common/energy-evse/src/EnergyEvseManager.cpp",
"${chip_root}/examples/energy-management-app/energy-management-common/energy-evse/src/EnergyEvseTargetsStore.cpp",
"${chip_root}/examples/energy-management-app/energy-management-common/energy-evse/src/energy-evse-mode.cpp",
"${chip_root}/examples/energy-management-app/energy-management-common/energy-reporting/src/ElectricalPowerMeasurementDelegate.cpp",
"${chip_root}/examples/energy-management-app/energy-management-common/energy-reporting/src/EnergyReportingEventTriggers.cpp",
"${chip_root}/examples/energy-management-app/energy-management-common/energy-reporting/src/FakeReadings.cpp",
"${chip_root}/examples/energy-management-app/energy-management-common/energy-reporting/src/PowerTopologyDelegate.cpp",
"${chip_root}/examples/energy-management-app/energy-management-common/water-heater/src/WaterHeaterMain.cpp",
"${chip_root}/examples/energy-management-app/energy-management-common/water-heater/src/WhmDelegateImpl.cpp",
"${chip_root}/examples/energy-management-app/energy-management-common/water-heater/src/WhmInstance.cpp",
"${chip_root}/examples/energy-management-app/energy-management-common/water-heater/src/WhmMain.cpp",
"${chip_root}/examples/energy-management-app/energy-management-common/water-heater/src/WhmManufacturer.cpp",
"${chip_root}/examples/energy-management-app/energy-management-common/water-heater/src/water-heater-mode.cpp",
"${examples_common_plat_dir}/main.cpp",
"src/AppTask.cpp",
]
Expand Down
26 changes: 21 additions & 5 deletions examples/energy-management-app/silabs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ An example showing the use of CHIP on the Silicon Labs EFR32 MG12 and MG24.
## Introduction

The EFR32 Energy Management example provides a baseline demonstration of a EVSE
device, built using Matter and the Silicon Labs gecko SDK. It can be controlled
by a Chip controller over an Openthread or Wifi network..
or Water Heater device, built using Matter and the Silicon Labs gecko SDK. It
can be controlled by a Chip controller over an Openthread or Wifi network.

The EFR32 device can be commissioned over Bluetooth Low Energy where the device
and the Chip controller will exchange security information with the Rendez-vous
Expand All @@ -45,9 +45,9 @@ If the LCD is enabled, the LCD on the Silabs WSTK shows a QR Code containing the
needed commissioning information for the BLE connection and starting the
Rendez-vous procedure.

The EVSE example is intended to serve both as a means to explore the workings of
Matter as well as a template for creating real products based on the Silicon
Labs platform.
The EVSE and Water Heater examples are intended to serve both as a means to
explore the workings of Matter Energy Management as well as a template for
creating real products based on the Silicon Labs platform.

## Building

Expand Down Expand Up @@ -99,9 +99,25 @@ Labs platform.
$ git submodule update --init
$ source third_party/connectedhomeip/scripts/activate.sh
$ export SILABS_BOARD=BRD4187C

To build the EVSE example

$ gn gen out/debug
$ ninja -C out/debug

To build the Water Heater example you can change the args to gn gen (see
BUILD.gn for arg options)

$ gn gen out/debug --args='chip_enable_example_evse_device=false chip_enable_example_water_heater_device=true'
$ ninja -C out/debug

To change Device Energy Management feature support (e.g. Power forecast or
State forecast reporting), you can change the args to gn gen (see BUILD.gn
for arg options)

$ gn gen out/debug --args='chip_dem_support_state_forecast_reporting=true chip_dem_support_power_forecast_reporting=false'
$ ninja -C out/debug

- To delete generated executable, libraries and object files use:

$ cd ~/connectedhomeip/examples/energy-management-app/silabs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ silabs_sdk_target = get_label_info(":sdk", "label_no_toolchain")
chip_enable_openthread = false
import("${chip_root}/src/platform/silabs/wifi_args.gni")

sl_enable_test_event_trigger = true
chip_enable_ota_requestor = false
disable_lcd = true
app_data_model =
Expand Down
4 changes: 2 additions & 2 deletions examples/energy-management-app/silabs/include/AppTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

#include "AppEvent.h"
#include "BaseApplication.h"
#include "EnergyEvseManager.h"

#include "FreeRTOS.h"
#include "timers.h" // provides FreeRTOS timer support
#include <ble/BLEEndPoint.h>
Expand Down Expand Up @@ -80,7 +80,7 @@ class AppTask : public BaseApplication

private:
static AppTask sAppTask;
static void EvseActionEventHandler(AppEvent * aEvent);
static void EnergyManagementActionEventHandler(AppEvent * aEvent);

static void UpdateClusterState(intptr_t context);

Expand Down
1 change: 1 addition & 0 deletions examples/energy-management-app/silabs/openthread.gni
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ app_data_model =
chip_enable_ota_requestor = false
chip_enable_openthread = true
disable_lcd = true
sl_enable_test_event_trigger = true

openthread_external_platform =
"${chip_root}/third_party/openthread/platforms/efr32:libopenthread-efr32"
116 changes: 109 additions & 7 deletions examples/energy-management-app/silabs/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@
#include "AppConfig.h"
#include "AppEvent.h"
#include "LEDWidget.h"
#if SL_MATTER_CONFIG_ENABLE_EXAMPLE_EVSE_DEVICE
#include <EnergyEvseMain.h>
#endif
#if SL_CONFIG_ENABLE_EXAMPLE_WATER_HEATER_DEVICE
#include <WaterHeaterMain.h>
#endif
#include <app-common/zap-generated/cluster-enums.h>
#include <app-common/zap-generated/cluster-objects.h>
#include <app-common/zap-generated/ids/Attributes.h>
Expand All @@ -43,6 +48,24 @@

#include <platform/CHIPDeviceLayer.h>

#ifdef SL_MATTER_TEST_EVENT_TRIGGER_ENABLED
#include <app/TestEventTriggerDelegate.h>

#if SL_MATTER_CONFIG_ENABLE_ENERGY_EVSE_TRIGGER
#include <app/clusters/energy-evse-server/EnergyEvseTestEventTriggerHandler.h>
#endif
#if SL_MATTER_CONFIG_ENABLE_ENERGY_REPORTING_TRIGGER
#include <app/clusters/electrical-energy-measurement-server/EnergyReportingTestEventTriggerHandler.h>
#endif
#if SL_MATTER_CONFIG_ENABLE_WATER_HEATER_MANAGEMENT_TRIGGER
#include <app/clusters/water-heater-management-server/WaterHeaterManagementTestEventTriggerHandler.h>
#endif
#if SL_MATTER_CONFIG_ENABLE_DEVICE_ENERGY_MANAGEMENT_TRIGGER
#include <app/clusters/device-energy-management-server/DeviceEnergyManagementTestEventTriggerHandler.h>
#endif

#endif // SL_MATTER_TEST_EVENT_TRIGGER_ENABLED

#if (defined(SL_CATALOG_SIMPLE_LED_LED1_PRESENT) || defined(SIWX_917))
#define EVSE_LED 1
#else
Expand All @@ -53,28 +76,47 @@
#define APP_EVSE_SWITCH 1

namespace {
LEDWidget sEvseLED;
LEDWidget sEnergyManagementLED;
}

using namespace chip;
using namespace chip::app;
using namespace chip::app::Clusters;
using namespace chip::app::Clusters::DeviceEnergyManagement;
using namespace chip::app::Clusters::DeviceEnergyManagement::Attributes;
using namespace chip::app::Clusters::WaterHeaterManagement;
using namespace ::chip::DeviceLayer;
using namespace ::chip::DeviceLayer::Silabs;
using namespace ::chip::DeviceLayer::Internal;
using namespace chip::TLV;

#ifdef SL_MATTER_TEST_EVENT_TRIGGER_ENABLED
static EnergyEvseTestEventTriggerHandler sEnergyEvseTestEventTriggerHandler;
static EnergyReportingTestEventTriggerHandler sEnergyReportingTestEventTriggerHandler;
static DeviceEnergyManagementTestEventTriggerHandler sDeviceEnergyManagementTestEventTriggerHandler;
#endif

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

// Keep track of the parsed featureMap option
#if (SL_MATTER_CONFIG_DEM_SUPPORT_POWER_FORECAST_REPORTING) && (SL_MATTER_CONFIG_DEM_SUPPORT_STATE_FORECAST_REPORTING)
#error Cannot define SL_MATTER_CONFIG_DEM_SUPPORT_POWER_FORECAST_REPORTING and SL_MATTER_CONFIG_DEM_SUPPORT_STATE_FORECAST_REPORTING
#endif

#if SL_MATTER_CONFIG_DEM_SUPPORT_POWER_FORECAST_REPORTING
static chip::BitMask<Feature> sFeatureMap(Feature::kPowerAdjustment, Feature::kPowerForecastReporting,
Feature::kStateForecastReporting, Feature::kStartTimeAdjustment, Feature::kPausable,
Feature::kForecastAdjustment, Feature::kConstraintBasedAdjustment);
Feature::kStartTimeAdjustment, Feature::kPausable, Feature::kForecastAdjustment,
Feature::kConstraintBasedAdjustment);
#elif SL_MATTER_CONFIG_DEM_SUPPORT_STATE_FORECAST_REPORTING
static chip::BitMask<Feature> sFeatureMap(Feature::kPowerAdjustment, Feature::kStateForecastReporting,
Feature::kStartTimeAdjustment, Feature::kPausable, Feature::kForecastAdjustment,
Feature::kConstraintBasedAdjustment);
#else
static chip::BitMask<Feature> sFeatureMap(Feature::kPowerAdjustment);
#endif

chip::BitMask<Feature> GetFeatureMapFromCmdLine()
{
Expand All @@ -91,14 +133,33 @@ AppTask AppTask::sAppTask;
void ApplicationInit()
{
chip::DeviceLayer::PlatformMgr().LockChipStack();
SILABS_LOG("==================================================");
#if SL_MATTER_CONFIG_ENABLE_EXAMPLE_EVSE_DEVICE
SILABS_LOG("energy-management-example EVSE starting. featureMap 0x%08lx", DeviceEnergyManagement::sFeatureMap.Raw());

EvseApplicationInit();
sEvseLED.Init(EVSE_LED);
#endif // CONFIG_ENABLE_EXAMPLE_EVSE_DEVICE

#if SL_CONFIG_ENABLE_EXAMPLE_WATER_HEATER_DEVICE
SILABS_LOG("energy-management-example WaterHeater starting. featureMap 0x%08lx", DeviceEnergyManagement::sFeatureMap.Raw());

FullWhmApplicationInit();
#endif // CONFIG_ENABLE_EXAMPLE_WATER_HEATER_DEVICE
SILABS_LOG("==================================================");

sEnergyManagementLED.Init(EVSE_LED);
chip::DeviceLayer::PlatformMgr().UnlockChipStack();
}
void ApplicationShutdown()
{
chip::DeviceLayer::PlatformMgr().LockChipStack();
#if SL_MATTER_CONFIG_ENABLE_EXAMPLE_EVSE_DEVICE
EvseApplicationShutdown();
#endif // CONFIG_ENABLE_EXAMPLE_EVSE_DEVICE

#if SL_CONFIG_ENABLE_EXAMPLE_WATER_HEATER_DEVICE
FullWhmApplicationShutdown();
#endif // CONFIG_ENABLE_EXAMPLE_WATER_HEATER_DEVICE
chip::DeviceLayer::PlatformMgr().UnlockChipStack();
}

Expand All @@ -108,7 +169,11 @@ CHIP_ERROR AppTask::Init()
chip::DeviceLayer::Silabs::GetPlatform().SetButtonsCb(AppTask::ButtonEventHandler);

#ifdef DISPLAY_ENABLED
GetLCD().Init((uint8_t *) "energy-management-App");
#if SL_MATTER_CONFIG_ENABLE_EXAMPLE_EVSE_DEVICE
GetLCD().Init((uint8_t *) "energy-management-App (EVSE)");
#elif SL_CONFIG_ENABLE_EXAMPLE_WATER_HEATER_DEVICE
GetLCD().Init((uint8_t *) "energy-management-App (WaterHeater)");
#endif
#endif

err = BaseApplication::Init();
Expand All @@ -120,6 +185,43 @@ CHIP_ERROR AppTask::Init()

ApplicationInit();

#ifdef SL_MATTER_TEST_EVENT_TRIGGER_ENABLED
TestEventTriggerDelegate * pTestEventDelegate = Server::GetInstance().GetTestEventTriggerDelegate();

#if SL_MATTER_CONFIG_ENABLE_ENERGY_EVSE_TRIGGER
static EnergyEvseTestEventTriggerHandler sEnergyEvseTestEventTriggerHandler;
if (pTestEventDelegate != nullptr)
{
VerifyOrDie(pTestEventDelegate->AddHandler(&sEnergyEvseTestEventTriggerHandler) == CHIP_NO_ERROR);
}
#endif

#if SL_MATTER_CONFIG_ENABLE_ENERGY_REPORTING_TRIGGER
static EnergyReportingTestEventTriggerHandler sEnergyReportingTestEventTriggerHandler;
if (pTestEventDelegate != nullptr)
{
VerifyOrDie(pTestEventDelegate->AddHandler(&sEnergyReportingTestEventTriggerHandler) == CHIP_NO_ERROR);
}

#endif
#if SL_MATTER_CONFIG_ENABLE_WATER_HEATER_MANAGEMENT_TRIGGER
static WaterHeaterManagementTestEventTriggerHandler sWaterHeaterManagementTestEventTriggerHandler;

if (pTestEventDelegate != nullptr)
{
VerifyOrDie(pTestEventDelegate->AddHandler(&sWaterHeaterManagementTestEventTriggerHandler) == CHIP_NO_ERROR);
}
#endif
#if SL_MATTER_CONFIG_ENABLE_DEVICE_ENERGY_MANAGEMENT_TRIGGER
static DeviceEnergyManagementTestEventTriggerHandler sDeviceEnergyManagementTestEventTriggerHandler;
if (pTestEventDelegate != nullptr)
{
VerifyOrDie(pTestEventDelegate->AddHandler(&sDeviceEnergyManagementTestEventTriggerHandler) == CHIP_NO_ERROR);
}
#endif

#endif // SL_MATTER_TEST_EVENT_TRIGGER_ENABLED

// Update the LCD with the Stored value. Show QR Code if not provisioned
#ifdef DISPLAY_ENABLED
GetLCD().WriteDemoUI(LightMgr().IsLightOn());
Expand Down Expand Up @@ -168,7 +270,7 @@ void AppTask::AppTaskMain(void * pvParameter)
}
}

void AppTask::EvseActionEventHandler(AppEvent * aEvent)
void AppTask::EnergyManagementActionEventHandler(AppEvent * aEvent)
{
bool initiated = false;
int32_t actor;
Expand Down Expand Up @@ -201,7 +303,7 @@ void AppTask::ButtonEventHandler(uint8_t button, uint8_t btnAction)

if (button == APP_EVSE_SWITCH && btnAction == static_cast<uint8_t>(SilabsPlatform::ButtonAction::ButtonPressed))
{
button_event.Handler = EvseActionEventHandler;
button_event.Handler = EnergyManagementActionEventHandler;
AppTask::GetAppTask().PostEvent(&button_event);
}
else if (button == APP_FUNCTION_BUTTON)
Expand Down
3 changes: 0 additions & 3 deletions examples/platform/silabs/SiWx917/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ declare_args() {
#default Wifi Password
chip_default_wifi_psk = ""

# Enable TestEventTrigger in GeneralDiagnostics cluster
sl_enable_test_event_trigger = false

# The EnableKey in hex string format used by TestEventTrigger command in
# GeneralDiagnostics cluster. The length of the string should be 16 bytes.
sl_test_event_trigger_enable_key = "00112233445566778899AABBCCDDEEFF"
Expand Down
Loading

0 comments on commit be3c70a

Please sign in to comment.