From d11f85cea65c913ce0b2e5fa975d4a9a91c23cd3 Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Wed, 25 May 2022 15:11:12 -0400 Subject: [PATCH 1/5] Make device info provider available for EFR32. Ensure its storage is initialized --- examples/chef/efr32/BUILD.gn | 1 + examples/chef/efr32/src/main.cpp | 7 +++++++ examples/light-switch-app/efr32/src/main.cpp | 7 +++++++ examples/lighting-app/efr32/BUILD.gn | 1 + examples/lighting-app/efr32/src/main.cpp | 6 ++++++ examples/lock-app/efr32/BUILD.gn | 1 + examples/lock-app/efr32/src/main.cpp | 6 ++++++ examples/window-app/efr32/BUILD.gn | 1 + examples/window-app/efr32/src/main.cpp | 6 ++++++ 9 files changed, 36 insertions(+) diff --git a/examples/chef/efr32/BUILD.gn b/examples/chef/efr32/BUILD.gn index 071101cc34d883..4161916a993f49 100644 --- a/examples/chef/efr32/BUILD.gn +++ b/examples/chef/efr32/BUILD.gn @@ -197,6 +197,7 @@ efr32_executable("chef_app") { deps = [ ":chef-common", ":sdk", + "${chip_root}/examples/providers:device_info_provider", "${chip_root}/src/lib", "${chip_root}/src/setup_payload", ] diff --git a/examples/chef/efr32/src/main.cpp b/examples/chef/efr32/src/main.cpp index 21e8296ead1ac8..920f51b8e5805d 100644 --- a/examples/chef/efr32/src/main.cpp +++ b/examples/chef/efr32/src/main.cpp @@ -23,6 +23,8 @@ #include "init_efrPlatform.h" #include "sl_simple_button_instances.h" #include "sl_system_kernel.h" +#include +#include #include #define BLE_DEV_NAME "SiLabs-Chef-App" @@ -33,6 +35,8 @@ using namespace ::chip::DeviceLayer; #define UNUSED_PARAMETER(a) (a = a) volatile int apperror_cnt; +static chip::DeviceLayer::DeviceInfoProviderImpl gExampleDeviceInfoProvider; + // ================================================================================ // Main Code // ================================================================================ @@ -42,6 +46,9 @@ int main(void) if (EFR32MatterConfig::InitMatter(BLE_DEV_NAME) != CHIP_NO_ERROR) appError(CHIP_ERROR_INTERNAL); + gExampleDeviceInfoProvider.SetStorageDelegate(&Server::GetInstance().GetPersistentStorage()); + chip::DeviceLayer::SetDeviceInfoProvider(&gExampleDeviceInfoProvider); + EFR32_LOG("Starting App Task"); if (GetAppTask().StartAppTask() != CHIP_NO_ERROR) appError(CHIP_ERROR_INTERNAL); diff --git a/examples/light-switch-app/efr32/src/main.cpp b/examples/light-switch-app/efr32/src/main.cpp index d12a9a41f774c4..685d223daf8eed 100644 --- a/examples/light-switch-app/efr32/src/main.cpp +++ b/examples/light-switch-app/efr32/src/main.cpp @@ -23,6 +23,8 @@ #include "init_efrPlatform.h" #include "sl_simple_button_instances.h" #include "sl_system_kernel.h" +#include +#include #include #define BLE_DEV_NAME "SiLabs-Light-Switch" @@ -33,6 +35,8 @@ using namespace ::chip::DeviceLayer; #define UNUSED_PARAMETER(a) (a = a) volatile int apperror_cnt; +static chip::DeviceLayer::DeviceInfoProviderImpl gExampleDeviceInfoProvider; + // ================================================================================ // Main Code // ================================================================================ @@ -42,6 +46,9 @@ int main(void) if (EFR32MatterConfig::InitMatter(BLE_DEV_NAME) != CHIP_NO_ERROR) appError(CHIP_ERROR_INTERNAL); + gExampleDeviceInfoProvider.SetStorageDelegate(&Server::GetInstance().GetPersistentStorage()); + chip::DeviceLayer::SetDeviceInfoProvider(&gExampleDeviceInfoProvider); + EFR32_LOG("Starting App Task"); if (GetAppTask().StartAppTask() != CHIP_NO_ERROR) appError(CHIP_ERROR_INTERNAL); diff --git a/examples/lighting-app/efr32/BUILD.gn b/examples/lighting-app/efr32/BUILD.gn index bee89cccfa52d9..e82be7a6cb5a03 100644 --- a/examples/lighting-app/efr32/BUILD.gn +++ b/examples/lighting-app/efr32/BUILD.gn @@ -184,6 +184,7 @@ efr32_executable("lighting_app") { deps = [ ":sdk", "${chip_root}/examples/lighting-app/lighting-common", + "${chip_root}/examples/providers:device_info_provider", "${chip_root}/src/lib", "${chip_root}/src/setup_payload", ] diff --git a/examples/lighting-app/efr32/src/main.cpp b/examples/lighting-app/efr32/src/main.cpp index 94335a260fe9cc..54137f45c89043 100644 --- a/examples/lighting-app/efr32/src/main.cpp +++ b/examples/lighting-app/efr32/src/main.cpp @@ -23,6 +23,8 @@ #include "init_efrPlatform.h" #include "sl_simple_button_instances.h" #include "sl_system_kernel.h" +#include +#include #include #define BLE_DEV_NAME "SiLabs-Light" @@ -33,6 +35,7 @@ using namespace ::chip::DeviceLayer; #define UNUSED_PARAMETER(a) (a = a) volatile int apperror_cnt; +static chip::DeviceLayer::DeviceInfoProviderImpl gExampleDeviceInfoProvider; // ================================================================================ // Main Code @@ -43,6 +46,9 @@ int main(void) if (EFR32MatterConfig::InitMatter(BLE_DEV_NAME) != CHIP_NO_ERROR) appError(CHIP_ERROR_INTERNAL); + gExampleDeviceInfoProvider.SetStorageDelegate(&chip::Server::GetInstance().GetPersistentStorage()); + chip::DeviceLayer::SetDeviceInfoProvider(&gExampleDeviceInfoProvider); + EFR32_LOG("Starting App Task"); if (GetAppTask().StartAppTask() != CHIP_NO_ERROR) appError(CHIP_ERROR_INTERNAL); diff --git a/examples/lock-app/efr32/BUILD.gn b/examples/lock-app/efr32/BUILD.gn index ab479bb5175a86..b4f746235f262f 100644 --- a/examples/lock-app/efr32/BUILD.gn +++ b/examples/lock-app/efr32/BUILD.gn @@ -183,6 +183,7 @@ efr32_executable("lock_app") { deps = [ ":sdk", "${chip_root}/examples/lock-app/lock-common", + "${chip_root}/examples/providers:device_info_provider", "${chip_root}/src/lib", "${chip_root}/src/setup_payload", "${chip_root}/third_party/openthread/platforms:libopenthread-platform", diff --git a/examples/lock-app/efr32/src/main.cpp b/examples/lock-app/efr32/src/main.cpp index 1df236895f7091..cbc0c3643f07ff 100644 --- a/examples/lock-app/efr32/src/main.cpp +++ b/examples/lock-app/efr32/src/main.cpp @@ -23,6 +23,8 @@ #include "init_efrPlatform.h" #include "sl_simple_button_instances.h" #include "sl_system_kernel.h" +#include +#include #include #define BLE_DEV_NAME "SiLabs-Door-Lock" @@ -33,6 +35,7 @@ using namespace ::chip::DeviceLayer; #define UNUSED_PARAMETER(a) (a = a) volatile int apperror_cnt; +static chip::DeviceLayer::DeviceInfoProviderImpl gExampleDeviceInfoProvider; // ================================================================================ // Main Code @@ -43,6 +46,9 @@ int main(void) if (EFR32MatterConfig::InitMatter(BLE_DEV_NAME) != CHIP_NO_ERROR) appError(CHIP_ERROR_INTERNAL); + gExampleDeviceInfoProvider.SetStorageDelegate(&Server::GetInstance().GetPersistentStorage()); + chip::DeviceLayer::SetDeviceInfoProvider(&gExampleDeviceInfoProvider); + EFR32_LOG("Starting App Task"); if (GetAppTask().StartAppTask() != CHIP_NO_ERROR) appError(CHIP_ERROR_INTERNAL); diff --git a/examples/window-app/efr32/BUILD.gn b/examples/window-app/efr32/BUILD.gn index 61f5ed9b842af1..221838c0a14ffc 100644 --- a/examples/window-app/efr32/BUILD.gn +++ b/examples/window-app/efr32/BUILD.gn @@ -172,6 +172,7 @@ efr32_executable("window_app") { deps = [ ":sdk", + "${chip_root}/examples/providers:device_info_provider", "${chip_root}/examples/window-app/common:window-common", "${chip_root}/src/lib", "${chip_root}/src/setup_payload", diff --git a/examples/window-app/efr32/src/main.cpp b/examples/window-app/efr32/src/main.cpp index 81623bc486f388..eef12ddf99371d 100644 --- a/examples/window-app/efr32/src/main.cpp +++ b/examples/window-app/efr32/src/main.cpp @@ -23,6 +23,8 @@ #include "init_efrPlatform.h" #include "sl_simple_button_instances.h" #include "sl_system_kernel.h" +#include +#include #include #define BLE_DEV_NAME "Silabs-Window" @@ -31,6 +33,7 @@ using namespace ::chip::DeviceLayer; #define UNUSED_PARAMETER(a) (a = a) volatile int apperror_cnt; +static chip::DeviceLayer::DeviceInfoProviderImpl gExampleDeviceInfoProvider; // ================================================================================ // Main Code @@ -43,6 +46,9 @@ int main(void) if (EFR32MatterConfig::InitMatter(BLE_DEV_NAME) != CHIP_NO_ERROR) appError(CHIP_ERROR_INTERNAL); + gExampleDeviceInfoProvider.SetStorageDelegate(&chip::Server::GetInstance().GetPersistentStorage()); + chip::DeviceLayer::SetDeviceInfoProvider(&gExampleDeviceInfoProvider); + WindowApp & app = WindowApp::Instance(); EFR32_LOG("Starting App"); From 18c7936fbcc5c73c8615416faf4fdca994f6c3ed Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Wed, 25 May 2022 15:12:24 -0400 Subject: [PATCH 2/5] Ensure storage is initialized for NRF example as well --- examples/lighting-app/nrfconnect/main/AppTask.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/lighting-app/nrfconnect/main/AppTask.cpp b/examples/lighting-app/nrfconnect/main/AppTask.cpp index 9ee6c8eaa94785..9301570459d4a7 100644 --- a/examples/lighting-app/nrfconnect/main/AppTask.cpp +++ b/examples/lighting-app/nrfconnect/main/AppTask.cpp @@ -176,6 +176,7 @@ CHIP_ERROR AppTask::Init() static chip::CommonCaseDeviceServerInitParams initParams; (void) initParams.InitializeStaticResourcesBeforeServerInit(); + gExampleDeviceInfoProvider.SetStorageDelegate(&Server::GetInstance().GetPersistentStorage()); chip::DeviceLayer::SetDeviceInfoProvider(&gExampleDeviceInfoProvider); ReturnErrorOnFailure(chip::Server::GetInstance().Init(initParams)); From a6c7d318dd2fb193590db4aee3bd287ce78c2805 Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Wed, 25 May 2022 15:14:25 -0400 Subject: [PATCH 3/5] Ensure storage is initialized for linux examples as well --- examples/platform/linux/AppMain.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/examples/platform/linux/AppMain.cpp b/examples/platform/linux/AppMain.cpp index 26fea114267e54..13c758f95ab67e 100644 --- a/examples/platform/linux/AppMain.cpp +++ b/examples/platform/linux/AppMain.cpp @@ -240,6 +240,8 @@ int ChipLinuxAppInit(int argc, char * const argv[], OptionSet * customOptions) err = chip::examples::InitCommissionableDataProvider(gCommissionableDataProvider, LinuxDeviceOptions::GetInstance()); SuccessOrExit(err); DeviceLayer::SetCommissionableDataProvider(&gCommissionableDataProvider); + + gExampleDeviceInfoProvider.SetStorageDelegate(&chip::Server::GetInstance().GetPersistentStorage()); DeviceLayer::SetDeviceInfoProvider(&gExampleDeviceInfoProvider); err = chip::examples::InitConfigurationManager(reinterpret_cast(ConfigurationMgr()), From 12fba680fd07a66d6d9d199471a71ba7ae45a9e7 Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Wed, 25 May 2022 15:49:16 -0400 Subject: [PATCH 4/5] Add dependency to example providers in light switch as well --- examples/light-switch-app/efr32/BUILD.gn | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/light-switch-app/efr32/BUILD.gn b/examples/light-switch-app/efr32/BUILD.gn index a9e31ea0c88edf..0a1e68b0874082 100644 --- a/examples/light-switch-app/efr32/BUILD.gn +++ b/examples/light-switch-app/efr32/BUILD.gn @@ -185,6 +185,7 @@ efr32_executable("light_switch_app") { deps = [ ":sdk", "${chip_root}/examples/light-switch-app/light-switch-common", + "${chip_root}/examples/providers:device_info_provider", "${chip_root}/src/lib", "${chip_root}/src/setup_payload", ] From 4f20d48a1318a5bd59c966a5fe8c8fe18832fec1 Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Wed, 25 May 2022 17:01:38 -0400 Subject: [PATCH 5/5] Relocate the storage init configuration after server init in linux main --- examples/platform/linux/AppMain.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/platform/linux/AppMain.cpp b/examples/platform/linux/AppMain.cpp index 13c758f95ab67e..7d50fd5e2a8501 100644 --- a/examples/platform/linux/AppMain.cpp +++ b/examples/platform/linux/AppMain.cpp @@ -241,9 +241,6 @@ int ChipLinuxAppInit(int argc, char * const argv[], OptionSet * customOptions) SuccessOrExit(err); DeviceLayer::SetCommissionableDataProvider(&gCommissionableDataProvider); - gExampleDeviceInfoProvider.SetStorageDelegate(&chip::Server::GetInstance().GetPersistentStorage()); - DeviceLayer::SetDeviceInfoProvider(&gExampleDeviceInfoProvider); - err = chip::examples::InitConfigurationManager(reinterpret_cast(ConfigurationMgr()), LinuxDeviceOptions::GetInstance()); SuccessOrExit(err); @@ -355,6 +352,9 @@ void ChipLinuxAppMainLoop() // Init ZCL Data Model and CHIP App Server Server::GetInstance().Init(initParams); + gExampleDeviceInfoProvider.SetStorageDelegate(&chip::Server::GetInstance().GetPersistentStorage()); + DeviceLayer::SetDeviceInfoProvider(&gExampleDeviceInfoProvider); + // Now that the server has started and we are done with our startup logging, // log our discovery/onboarding information again so it's not lost in the // noise.