Skip to content

Commit

Permalink
Added BUILD.gn arguments to enable different feature support. Updated…
Browse files Browse the repository at this point in the history
… README. Added test event triggers.
  • Loading branch information
jamesharrow committed Sep 12, 2024
1 parent 0512e28 commit 78d6af8
Show file tree
Hide file tree
Showing 5 changed files with 150 additions and 15 deletions.
27 changes: 27 additions & 0 deletions examples/energy-management-app/silabs/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,22 @@ 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
chip_enable_energy_evse_trigger = true
chip_enable_energy_reporting_trigger = true
chip_enable_water_heater_management_trigger = true
chip_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
chip_dem_support_power_forecast_reporting = true
chip_dem_support_state_forecast_reporting = false

# Only one of these examples should be enabled
chip_enable_example_evse_device = true
chip_enable_example_water_heater_device = false

}

if (slc_generate) {
Expand Down Expand Up @@ -135,6 +151,17 @@ silabs_executable("energy-management-app") {
include_dirs = [ "include" ]
defines = []

defines += [
"CHIP_DEVICE_CONFIG_ENABLE_ENERGY_EVSE_TRIGGER=${chip_enable_energy_evse_trigger}",
"CHIP_DEVICE_CONFIG_ENABLE_ENERGY_REPORTING_TRIGGER=${chip_enable_energy_reporting_trigger}",
"CHIP_DEVICE_CONFIG_ENABLE_WATER_HEATER_MANAGEMENT_TRIGGER=${chip_enable_water_heater_management_trigger}",
"CHIP_DEVICE_CONFIG_ENABLE_DEVICE_ENERGY_MANAGEMENT_TRIGGER=${chip_enable_device_energy_management_trigger}",
"CHIP_DEVICE_CONFIG_DEM_SUPPORT_POWER_FORECAST_REPORTING=${chip_dem_support_power_forecast_reporting}",
"CHIP_DEVICE_CONFIG_DEM_SUPPORT_STATE_FORECAST_REPORTING=${chip_dem_support_state_forecast_reporting}",
"CHIP_DEVICE_CONFIG_ENABLE_EXAMPLE_EVSE_DEVICE=${chip_enable_example_evse_device}",
"CHIP_DEVICE_CONFIG_ENABLE_EXAMPLE_WATER_HEATER_DEVICE=${chip_enable_example_water_heater_device}",
]

if (silabs_board == "BRD2704A") {
defines += [ "SL_STATUS_LED=0" ]
}
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
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
106 changes: 99 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 CHIP_DEVICE_CONFIG_ENABLE_EXAMPLE_EVSE_DEVICE
#include <EnergyEvseMain.h>
#endif
#if CHIP_DEVICE_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,19 @@

#include <platform/CHIPDeviceLayer.h>

#if CONFIG_CHIP_DEVICE_CONFIG_ENABLE_ENERGY_EVSE_TRIGGER
#include <app/clusters/energy-evse-server/EnergyEvseTestEventTriggerHandler.h>
#endif
#if CONFIG_CHIP_DEVICE_CONFIG_ENABLE_ENERGY_REPORTING_TRIGGER
#include <app/clusters/electrical-energy-measurement-server/EnergyReportingTestEventTriggerHandler.h>
#endif
#if CONFIG_CHIP_DEVICE_CONFIG_ENABLE_WATER_HEATER_MANAGEMENT_TRIGGER
#include <app/clusters/water-heater-management-server/WaterHeaterManagementTestEventTriggerHandler.h>
#endif
#if CONFIG_CHIP_DEVICE_CONFIG_ENABLE_DEVICE_ENERGY_MANAGEMENT_TRIGGER
#include <app/clusters/device-energy-management-server/DeviceEnergyManagementTestEventTriggerHandler.h>
#endif

#if (defined(SL_CATALOG_SIMPLE_LED_LED1_PRESENT) || defined(SIWX_917))
#define EVSE_LED 1
#else
Expand All @@ -53,14 +71,15 @@
#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;
Expand All @@ -72,9 +91,21 @@ namespace Clusters {
namespace DeviceEnergyManagement {

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

#if CHIP_DEVICE_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 CHIP_DEVICE_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 +122,33 @@ AppTask AppTask::sAppTask;
void ApplicationInit()
{
chip::DeviceLayer::PlatformMgr().LockChipStack();
SILABS_LOG("==================================================");
#if CHIP_DEVICE_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 CHIP_DEVICE_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 CHIP_DEVICE_CONFIG_ENABLE_EXAMPLE_EVSE_DEVICE
EvseApplicationShutdown();
#endif // CONFIG_ENABLE_EXAMPLE_EVSE_DEVICE

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

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

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

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

ApplicationInit();

#if (CONFIG_CHIP_DEVICE_CONFIG_ENABLE_ENERGY_EVSE_TRIGGER) || (CONFIG_CHIP_DEVICE_CONFIG_ENABLE_ENERGY_REPORTING_TRIGGER) || \
(CONFIG_CHIP_DEVICE_CONFIG_ENABLE_WATER_HEATER_MANAGEMENT_TRIGGER) || \
(CONFIG_CHIP_DEVICE_CONFIG_ENABLE_DEVICE_ENERGY_MANAGEMENT_TRIGGER)
TestEventTriggerDelegate * pTestEventDelegate = Server::GetInstance().GetTestEventTriggerDelegate();
#endif

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

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

#endif
#if CONFIG_CHIP_DEVICE_CONFIG_ENABLE_WATER_HEATER_MANAGEMENT_TRIGGER
static WaterHeaterManagementTestEventTriggerHandler sWaterHeaterManagementTestEventTriggerHandler;

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

// 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 +260,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 +293,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
2 changes: 1 addition & 1 deletion examples/platform/esp32/common/Esp32AppServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include <app/TestEventTriggerDelegate.h>
#include <app/clusters/network-commissioning/network-commissioning.h>
#include <app/clusters/ota-requestor/OTATestEventTriggerHandler.h>
#include <app/clusters/water-heater-management-server/WaterHeaterManagementTestEventTriggerHandler.h>

#include <app/server/Dnssd.h>
#include <app/server/Server.h>
#include <platform/ESP32/NetworkCommissioningDriver.h>
Expand Down

0 comments on commit 78d6af8

Please sign in to comment.