[Infineon][SVE] Initialize CYW30739 OTA requestor after re-attaching to Thread network. (#21781)
diff --git a/examples/lighting-app/cyw30739/src/main.cpp b/examples/lighting-app/cyw30739/src/main.cpp
index 98b0095..3e5f413 100644
--- a/examples/lighting-app/cyw30739/src/main.cpp
+++ b/examples/lighting-app/cyw30739/src/main.cpp
@@ -47,8 +47,6 @@
static chip::DeviceLayer::DeviceInfoProviderImpl gExampleDeviceInfoProvider;
static void InitApp(intptr_t args);
-static void EventHandler(const ChipDeviceEvent * event, intptr_t arg);
-static void HandleThreadStateChangeEvent(const ChipDeviceEvent * event);
static void LightManagerCallback(LightingManager::Actor_t actor, LightingManager::Action_t action, uint8_t value);
static wiced_led_config_t chip_lighting_led_config = {
@@ -148,7 +146,6 @@
{
ConfigurationMgr().LogDeviceConfig();
- PlatformMgrImpl().AddEventHandler(EventHandler, 0);
// Print QR Code URL
PrintOnboardingCodes(chip::RendezvousInformationFlag(chip::RendezvousInformationFlag::kBLE));
/* Start CHIP datamodel server */
@@ -174,20 +171,6 @@
#endif
}
-void EventHandler(const ChipDeviceEvent * event, intptr_t arg)
-{
- switch (event->Type)
- {
- case DeviceEventType::kThreadStateChange:
- HandleThreadStateChangeEvent(event);
- break;
- default:
- break;
- }
-}
-
-void HandleThreadStateChangeEvent(const ChipDeviceEvent * event) {}
-
void LightManagerCallback(LightingManager::Actor_t actor, LightingManager::Action_t action, uint8_t level)
{
if (action == LightingManager::ON_ACTION)
diff --git a/examples/lock-app/cyw30739/src/main.cpp b/examples/lock-app/cyw30739/src/main.cpp
index e63bb34..3a7a0d8 100644
--- a/examples/lock-app/cyw30739/src/main.cpp
+++ b/examples/lock-app/cyw30739/src/main.cpp
@@ -60,8 +60,6 @@
static chip::DeviceLayer::DeviceInfoProviderImpl gExampleDeviceInfoProvider;
static void InitApp(intptr_t args);
-static void EventHandler(const ChipDeviceEvent * event, intptr_t arg);
-static void HandleThreadStateChangeEvent(const ChipDeviceEvent * event);
static void ActionInitiated(LockManager::Action_t aAction, int32_t aActor);
static void ActionCompleted(LockManager::Action_t aAction);
static void WriteClusterState(uint8_t value);
@@ -173,7 +171,6 @@
void InitApp(intptr_t args)
{
CHIP_ERROR err = CHIP_NO_ERROR;
- PlatformMgrImpl().AddEventHandler(EventHandler, 0);
// Print QR Code URL
PrintOnboardingCodes(chip::RendezvousInformationFlag(chip::RendezvousInformationFlag::kBLE));
/* Start CHIP datamodel server */
@@ -267,20 +264,6 @@
#endif
}
-void EventHandler(const ChipDeviceEvent * event, intptr_t arg)
-{
- switch (event->Type)
- {
- case DeviceEventType::kThreadStateChange:
- HandleThreadStateChangeEvent(event);
- break;
- default:
- break;
- }
-}
-
-void HandleThreadStateChangeEvent(const ChipDeviceEvent * event) {}
-
void ActionInitiated(LockManager::Action_t aAction, int32_t aActor)
{
// If the action has been initiated by the lock, update the bolt lock trait
diff --git a/examples/platform/cyw30739/OTAConfig.cpp b/examples/platform/cyw30739/OTAConfig.cpp
index cf3553d..05902c1 100644
--- a/examples/platform/cyw30739/OTAConfig.cpp
+++ b/examples/platform/cyw30739/OTAConfig.cpp
@@ -25,8 +25,13 @@
#include <app/server/Server.h>
#include <platform/CYW30739/OTAImageProcessorImpl.h>
+using namespace ::chip;
+using namespace ::chip::DeviceLayer;
+
namespace OTAConfig {
+constexpr uint32_t kInitOTARequestorDelaySec = 3;
+
// Global OTA objects
chip::DefaultOTARequestor gRequestorCore;
chip::DefaultOTARequestorStorage gRequestorStorage;
@@ -34,8 +39,34 @@
chip::BDXDownloader gDownloader;
chip::OTAImageProcessorImpl gImageProcessor;
+static void PlatformEventHandler(const ChipDeviceEvent * event, intptr_t arg);
+static void InitRequestor(System::Layer * systemLayer, void * appState);
+
void Init()
{
+ PlatformMgrImpl().AddEventHandler(PlatformEventHandler, 0);
+}
+
+void PlatformEventHandler(const ChipDeviceEvent * event, intptr_t arg)
+{
+ switch (event->Type)
+ {
+ case DeviceEventType::kThreadConnectivityChange:
+ if (event->ThreadConnectivityChange.Result == kConnectivity_Established)
+ SystemLayer().StartTimer(System::Clock::Seconds32(kInitOTARequestorDelaySec), InitRequestor, nullptr);
+ break;
+ default:
+ break;
+ }
+}
+
+void InitRequestor(System::Layer * systemLayer, void * appState)
+{
+ if (GetRequestorInstance() != nullptr)
+ return;
+
+ ChipLogProgress(SoftwareUpdate, "Initializing requestor");
+
// Initialize and interconnect the Requestor and Image Processor objects -- START
SetRequestorInstance(&gRequestorCore);