diff --git a/examples/energy-management-app/silabs/BUILD.gn b/examples/energy-management-app/silabs/BUILD.gn index b51ed59de6f52c..624cfff6250a85 100644 --- a/examples/energy-management-app/silabs/BUILD.gn +++ b/examples/energy-management-app/silabs/BUILD.gn @@ -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) { @@ -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) { @@ -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", ] diff --git a/examples/energy-management-app/silabs/README.md b/examples/energy-management-app/silabs/README.md index 06fc6f5c46b176..96237911df0989 100644 --- a/examples/energy-management-app/silabs/README.md +++ b/examples/energy-management-app/silabs/README.md @@ -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 @@ -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 @@ -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 diff --git a/examples/energy-management-app/silabs/build_for_wifi_args.gni b/examples/energy-management-app/silabs/build_for_wifi_args.gni index bfded904a34176..1b1c0ecd6a7c78 100644 --- a/examples/energy-management-app/silabs/build_for_wifi_args.gni +++ b/examples/energy-management-app/silabs/build_for_wifi_args.gni @@ -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 = diff --git a/examples/energy-management-app/silabs/include/AppTask.h b/examples/energy-management-app/silabs/include/AppTask.h index 99114610948952..b7105da42878db 100644 --- a/examples/energy-management-app/silabs/include/AppTask.h +++ b/examples/energy-management-app/silabs/include/AppTask.h @@ -28,7 +28,7 @@ #include "AppEvent.h" #include "BaseApplication.h" -#include "EnergyEvseManager.h" + #include "FreeRTOS.h" #include "timers.h" // provides FreeRTOS timer support #include @@ -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); diff --git a/examples/energy-management-app/silabs/openthread.gni b/examples/energy-management-app/silabs/openthread.gni index 2813a5a1fb0bda..b45952e0c5f24b 100644 --- a/examples/energy-management-app/silabs/openthread.gni +++ b/examples/energy-management-app/silabs/openthread.gni @@ -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" diff --git a/examples/energy-management-app/silabs/src/AppTask.cpp b/examples/energy-management-app/silabs/src/AppTask.cpp index 4ed73efb28711e..42069a85b5de84 100644 --- a/examples/energy-management-app/silabs/src/AppTask.cpp +++ b/examples/energy-management-app/silabs/src/AppTask.cpp @@ -21,7 +21,12 @@ #include "AppConfig.h" #include "AppEvent.h" #include "LEDWidget.h" +#if SL_MATTER_CONFIG_ENABLE_EXAMPLE_EVSE_DEVICE #include +#endif +#if SL_CONFIG_ENABLE_EXAMPLE_WATER_HEATER_DEVICE +#include +#endif #include #include #include @@ -43,6 +48,24 @@ #include +#ifdef SL_MATTER_TEST_EVENT_TRIGGER_ENABLED +#include + +#if SL_MATTER_CONFIG_ENABLE_ENERGY_EVSE_TRIGGER +#include +#endif +#if SL_MATTER_CONFIG_ENABLE_ENERGY_REPORTING_TRIGGER +#include +#endif +#if SL_MATTER_CONFIG_ENABLE_WATER_HEATER_MANAGEMENT_TRIGGER +#include +#endif +#if SL_MATTER_CONFIG_ENABLE_DEVICE_ENERGY_MANAGEMENT_TRIGGER +#include +#endif + +#endif // SL_MATTER_TEST_EVENT_TRIGGER_ENABLED + #if (defined(SL_CATALOG_SIMPLE_LED_LED1_PRESENT) || defined(SIWX_917)) #define EVSE_LED 1 #else @@ -53,7 +76,7 @@ #define APP_EVSE_SWITCH 1 namespace { -LEDWidget sEvseLED; +LEDWidget sEnergyManagementLED; } using namespace chip; @@ -61,20 +84,39 @@ 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 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 sFeatureMap(Feature::kPowerAdjustment, Feature::kStateForecastReporting, + Feature::kStartTimeAdjustment, Feature::kPausable, Feature::kForecastAdjustment, + Feature::kConstraintBasedAdjustment); +#else +static chip::BitMask sFeatureMap(Feature::kPowerAdjustment); +#endif chip::BitMask GetFeatureMapFromCmdLine() { @@ -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(); } @@ -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(); @@ -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()); @@ -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; @@ -201,7 +303,7 @@ void AppTask::ButtonEventHandler(uint8_t button, uint8_t btnAction) if (button == APP_EVSE_SWITCH && btnAction == static_cast(SilabsPlatform::ButtonAction::ButtonPressed)) { - button_event.Handler = EvseActionEventHandler; + button_event.Handler = EnergyManagementActionEventHandler; AppTask::GetAppTask().PostEvent(&button_event); } else if (button == APP_FUNCTION_BUTTON) diff --git a/examples/platform/silabs/SiWx917/BUILD.gn b/examples/platform/silabs/SiWx917/BUILD.gn index 6ead7f31154b09..156fb38e4916fc 100644 --- a/examples/platform/silabs/SiWx917/BUILD.gn +++ b/examples/platform/silabs/SiWx917/BUILD.gn @@ -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" diff --git a/examples/platform/silabs/efr32/BUILD.gn b/examples/platform/silabs/efr32/BUILD.gn index 3691091a0bc3c7..91cd2c1a0a58d6 100644 --- a/examples/platform/silabs/efr32/BUILD.gn +++ b/examples/platform/silabs/efr32/BUILD.gn @@ -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" diff --git a/examples/platform/silabs/provision/BUILD.gn b/examples/platform/silabs/provision/BUILD.gn index ccd5b919bc0379..f9e056f5ffa8a2 100644 --- a/examples/platform/silabs/provision/BUILD.gn +++ b/examples/platform/silabs/provision/BUILD.gn @@ -47,6 +47,18 @@ source_set("storage") { } deps = [ "${chip_root}/src/lib" ] + public_deps = [ "${chip_root}/src/platform/silabs/provision:provision-headers" ] + + if (sl_enable_test_event_trigger) { + # Temporary workaround since we have duplicated configurations + if (wifi_soc) { + public_configs = [ "${chip_root}/examples/platform/silabs/SiWx917:test-event-trigger-config" ] + } else { + public_configs = [ + "${chip_root}/examples/platform/silabs/efr32:test-event-trigger-config", + ] + } + } } diff --git a/third_party/silabs/efr32_sdk.gni b/third_party/silabs/efr32_sdk.gni index 3f30a0ca52f867..1d4472a8bd7cfd 100644 --- a/third_party/silabs/efr32_sdk.gni +++ b/third_party/silabs/efr32_sdk.gni @@ -86,6 +86,9 @@ declare_args() { # Factory Provision storage use_provision_flash_storage = wifi_soc + + # Enable TestEventTrigger in GeneralDiagnostics cluster + sl_enable_test_event_trigger = false } examples_plat_dir = "${chip_root}/examples/platform/silabs/efr32"