Skip to content

Commit

Permalink
ICD manager Implemenation (#27283)
Browse files Browse the repository at this point in the history
* Add Events for ICD (WIP)

* Rename SED defines, Add some timer funcionality to Extend a existing timer. Implemented ICDModes and initial operationalState logic WIP

* Change SetFastPolling and SetSlowPolling to setPollingInterval with a param. Call is handled by ICD Manager. Replace the sed ifdef by icd for silabs platform WIP

* Fix a bunch of dependencies, includes and build issues WIP

* Use a init function instead of the constructor, as the attributes value aren't ready

* Add a Keep active mechanism for commisisoning window and failsafe

* cleanup, add app user wakeup

change #ifdef to #if

fix missing rename. add // nogncheck on some conditional include

Fix some error caught by the ci

* Addresses comments + conditional define for tests

* SetPollingInterval causes issue for apps that has both thread and wifi. Priority to the thread imp for now. Needs to be reworked

* Rebase, It brings updated system Apis, And addresse most of the comments

* Stay active when an exchange context expect a response.

* Update The message rx handling event naming. Move related ICD events to PublicEventTypes for the time being

* #if ICD_SERVER the icd related event posts

* Address comments and nits
  • Loading branch information
jmartinez-silabs authored and pull[bot] committed Aug 29, 2023
1 parent e0abf38 commit 1132596
Show file tree
Hide file tree
Showing 54 changed files with 707 additions and 185 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@
#define CHIP_CONFIG_MAX_FABRICS 5 // 5 is the minimum number of supported fabrics

#define CHIP_DEVICE_CONFIG_ENABLE_SED 1
#define CHIP_DEVICE_CONFIG_SED_IDLE_INTERVAL 1000_ms32
#define CHIP_DEVICE_CONFIG_SED_ACTIVE_INTERVAL 100_ms32
#define CHIP_DEVICE_CONFIG_ICD_SLOW_POLL_INTERVAL 1000_ms32
#define CHIP_DEVICE_CONFIG_ICD_FAST_POLL_INTERVAL 100_ms32
/**
* @def CHIP_IM_MAX_NUM_COMMAND_HANDLER
*
Expand Down
2 changes: 1 addition & 1 deletion examples/light-switch-app/silabs/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ void AppTask::AppTaskMain(void * pvParameter)
appError(err);
}

#if !(defined(CHIP_DEVICE_CONFIG_ENABLE_SED) && CHIP_DEVICE_CONFIG_ENABLE_SED)
#if !(defined(CHIP_CONFIG_ENABLE_ICD_SERVER) && CHIP_CONFIG_ENABLE_ICD_SERVER)
sAppTask.StartStatusLEDTimer();
#endif

Expand Down
2 changes: 1 addition & 1 deletion examples/lighting-app/silabs/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ void AppTask::AppTaskMain(void * pvParameter)
appError(err);
}

#if !(defined(CHIP_DEVICE_CONFIG_ENABLE_SED) && CHIP_DEVICE_CONFIG_ENABLE_SED)
#if !(defined(CHIP_CONFIG_ENABLE_ICD_SERVER) && CHIP_CONFIG_ENABLE_ICD_SERVER)
sAppTask.StartStatusLEDTimer();
#endif

Expand Down
4 changes: 2 additions & 2 deletions examples/lock-app/nxp/k32w/k32w0/include/CHIPProjectConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@
#define CHIP_CONFIG_MAX_FABRICS 5 // 5 is the minimum number of supported fabrics

#define CHIP_DEVICE_CONFIG_ENABLE_SED 1
#define CHIP_DEVICE_CONFIG_SED_IDLE_INTERVAL 1000_ms32
#define CHIP_DEVICE_CONFIG_SED_ACTIVE_INTERVAL 100_ms32
#define CHIP_DEVICE_CONFIG_ICD_SLOW_POLL_INTERVAL 1000_ms32
#define CHIP_DEVICE_CONFIG_ICD_FAST_POLL_INTERVAL 100_ms32

/**
* CHIP_CONFIG_EVENT_LOGGING_DEFAULT_IMPORTANCE
Expand Down
2 changes: 1 addition & 1 deletion examples/lock-app/silabs/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ void AppTask::AppTaskMain(void * pvParameter)
appError(err);
}

#if !(defined(CHIP_DEVICE_CONFIG_ENABLE_SED) && CHIP_DEVICE_CONFIG_ENABLE_SED)
#if !(defined(CHIP_CONFIG_ENABLE_ICD_SERVER) && CHIP_CONFIG_ENABLE_ICD_SERVER)
sAppTask.StartStatusLEDTimer();
#endif

Expand Down
2 changes: 1 addition & 1 deletion examples/platform/silabs/ICDSubscriptionCallback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ CHIP_ERROR ICDSubscriptionCallback::OnSubscriptionRequested(chip::app::ReadHandl
{
using namespace chip::System::Clock;

Seconds32 interval_s32 = std::chrono::duration_cast<Seconds32>(CHIP_DEVICE_CONFIG_SED_IDLE_INTERVAL);
Seconds32 interval_s32 = std::chrono::duration_cast<Seconds32>(CHIP_DEVICE_CONFIG_ICD_SLOW_POLL_INTERVAL);

if (interval_s32 > Seconds16::max())
{
Expand Down
26 changes: 13 additions & 13 deletions examples/platform/silabs/SiWx917/BaseApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,14 @@ app::Clusters::NetworkCommissioning::Instance
sWiFiNetworkCommissioningInstance(0 /* Endpoint Id */, &(NetworkCommissioning::SlWiFiDriver::GetInstance()));
#endif /* SL_WIFI */

#if !(defined(CHIP_DEVICE_CONFIG_ENABLE_SED) && CHIP_DEVICE_CONFIG_ENABLE_SED)
#if !(defined(CHIP_CONFIG_ENABLE_ICD_SERVER) && CHIP_CONFIG_ENABLE_ICD_SERVER)

bool sIsProvisioned = false;
bool sIsEnabled = false;
bool sIsAttached = false;
bool sHaveBLEConnections = false;

#endif // CHIP_DEVICE_CONFIG_ENABLE_SED
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER

uint8_t sAppEventQueueBuffer[APP_EVENT_QUEUE_SIZE * sizeof(AppEvent)];
StaticQueue_t sAppEventQueueStruct;
Expand Down Expand Up @@ -257,9 +257,9 @@ void BaseApplication::FunctionFactoryReset(void)
// Actually trigger Factory Reset
mFunction = kFunction_NoneSelected;

#if CHIP_DEVICE_CONFIG_ENABLE_SED == 1
#if CHIP_CONFIG_ENABLE_ICD_SERVER == 1
StopStatusLEDTimer();
#endif // CHIP_DEVICE_CONFIG_ENABLE_SED
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER

chip::Server::GetInstance().ScheduleFactoryReset();
}
Expand Down Expand Up @@ -314,7 +314,7 @@ bool BaseApplication::ActivateStatusLedPatterns()
}
#endif // EMBER_AF_PLUGIN_IDENTIFY_SERVER

#if !(defined(CHIP_DEVICE_CONFIG_ENABLE_SED) && CHIP_DEVICE_CONFIG_ENABLE_SED)
#if !(defined(CHIP_CONFIG_ENABLE_ICD_SERVER) && CHIP_CONFIG_ENABLE_ICD_SERVER)
// Identify Patterns have priority over Status patterns
if (!isPatternSet)
{
Expand All @@ -340,7 +340,7 @@ bool BaseApplication::ActivateStatusLedPatterns()
}
isPatternSet = true;
}
#endif // CHIP_DEVICE_CONFIG_ENABLE_SED
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER
#endif // ENABLE_WSTK_LEDS) && SL_CATALOG_SIMPLE_LED_LED1_PRESENT
return isPatternSet;
}
Expand All @@ -352,7 +352,7 @@ void BaseApplication::LightEventHandler()
// locked while these values are queried. However we use a non-blocking
// lock request (TryLockCHIPStack()) to avoid blocking other UI activities
// when the CHIP task is busy (e.g. with a long crypto operation).
#if !(defined(CHIP_DEVICE_CONFIG_ENABLE_SED) && CHIP_DEVICE_CONFIG_ENABLE_SED)
#if !(defined(CHIP_CONFIG_ENABLE_ICD_SERVER) && CHIP_CONFIG_ENABLE_ICD_SERVER)
if (PlatformMgr().TryLockChipStack())
{
#ifdef SL_WIFI
Expand All @@ -368,7 +368,7 @@ void BaseApplication::LightEventHandler()
sHaveBLEConnections = (ConnectivityMgr().NumBLEConnections() != 0);
PlatformMgr().UnlockChipStack();
}
#endif // CHIP_DEVICE_CONFIG_ENABLE_SED
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER

// Update the status LED if factory reset has not been initiated.
//
Expand Down Expand Up @@ -441,7 +441,7 @@ void BaseApplication::ButtonHandler(AppEvent * aEvent)
{
mFunction = kFunction_NoneSelected;

#if CHIP_DEVICE_CONFIG_ENABLE_SED == 1
#if CHIP_CONFIG_ENABLE_ICD_SERVER == 1
StopStatusLEDTimer();
#endif

Expand Down Expand Up @@ -514,7 +514,7 @@ void BaseApplication::OnIdentifyStart(Identify * identify)
{
ChipLogProgress(Zcl, "onIdentifyStart");

#if CHIP_DEVICE_CONFIG_ENABLE_SED == 1
#if CHIP_CONFIG_ENABLE_ICD_SERVER == 1
StartStatusLEDTimer();
#endif
}
Expand All @@ -523,7 +523,7 @@ void BaseApplication::OnIdentifyStop(Identify * identify)
{
ChipLogProgress(Zcl, "onIdentifyStop");

#if CHIP_DEVICE_CONFIG_ENABLE_SED == 1
#if CHIP_CONFIG_ENABLE_ICD_SERVER == 1
StopStatusLEDTimer();
#endif
}
Expand All @@ -533,7 +533,7 @@ void BaseApplication::OnTriggerIdentifyEffectCompleted(chip::System::Layer * sys
ChipLogProgress(Zcl, "Trigger Identify Complete");
sIdentifyEffect = Clusters::Identify::EffectIdentifierEnum::kStopEffect;

#if CHIP_DEVICE_CONFIG_ENABLE_SED == 1
#if CHIP_CONFIG_ENABLE_ICD_SERVER == 1
StopStatusLEDTimer();
#endif
}
Expand All @@ -547,7 +547,7 @@ void BaseApplication::OnTriggerIdentifyEffect(Identify * identify)
ChipLogDetail(AppServer, "Identify Effect Variant unsupported. Using default");
}

#if CHIP_DEVICE_CONFIG_ENABLE_SED == 1
#if CHIP_CONFIG_ENABLE_ICD_SERVER == 1
StartStatusLEDTimer();
#endif

Expand Down
3 changes: 2 additions & 1 deletion examples/platform/silabs/efr32/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import("//build_overrides/chip.gni")
import("//build_overrides/efr32_sdk.gni")
import("${chip_root}/examples/common/pigweed/pigweed_rpcs.gni")
import("${chip_root}/src/app/icd/icd.gni")
import("${chip_root}/src/lib/lib.gni")
import("${chip_root}/src/platform/device.gni")
import("${efr32_sdk_build_root}/efr32_sdk.gni")
Expand All @@ -40,7 +41,7 @@ declare_args() {
chip_default_wifi_psk = ""

# Use default handler to negotiate subscription max interval
chip_config_use_icd_subscription_callbacks = enable_sleepy_device
chip_config_use_icd_subscription_callbacks = chip_enable_icd_server

# Enable TestEventTrigger in GeneralDiagnostics cluster
silabs_test_event_trigger_enabled = false
Expand Down
42 changes: 26 additions & 16 deletions examples/platform/silabs/efr32/BaseApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,11 @@ app::Clusters::NetworkCommissioning::Instance

bool sIsProvisioned = false;

#if !(defined(CHIP_DEVICE_CONFIG_ENABLE_SED) && CHIP_DEVICE_CONFIG_ENABLE_SED)
#if !(defined(CHIP_CONFIG_ENABLE_ICD_SERVER) && CHIP_CONFIG_ENABLE_ICD_SERVER)
bool sIsEnabled = false;
bool sIsAttached = false;
bool sHaveBLEConnections = false;
#endif // CHIP_DEVICE_CONFIG_ENABLE_SED
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER

uint8_t sAppEventQueueBuffer[APP_EVENT_QUEUE_SIZE * sizeof(AppEvent)];
StaticQueue_t sAppEventQueueStruct;
Expand Down Expand Up @@ -273,9 +273,9 @@ void BaseApplication::FunctionEventHandler(AppEvent * aEvent)
// cancel, if required.
StartFunctionTimer(FACTORY_RESET_CANCEL_WINDOW_TIMEOUT);

#if CHIP_DEVICE_CONFIG_ENABLE_SED == 1
#if CHIP_CONFIG_ENABLE_ICD_SERVER == 1
StartStatusLEDTimer();
#endif // CHIP_DEVICE_CONFIG_ENABLE_SED
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER

mFunction = kFunction_FactoryReset;

Expand All @@ -291,9 +291,9 @@ void BaseApplication::FunctionEventHandler(AppEvent * aEvent)
// Actually trigger Factory Reset
mFunction = kFunction_NoneSelected;

#if CHIP_DEVICE_CONFIG_ENABLE_SED == 1
#if CHIP_CONFIG_ENABLE_ICD_SERVER == 1
StopStatusLEDTimer();
#endif // CHIP_DEVICE_CONFIG_ENABLE_SED
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER

ScheduleFactoryReset();
}
Expand Down Expand Up @@ -349,7 +349,7 @@ bool BaseApplication::ActivateStatusLedPatterns()
}
#endif // EMBER_AF_PLUGIN_IDENTIFY_SERVER

#if !(defined(CHIP_DEVICE_CONFIG_ENABLE_SED) && CHIP_DEVICE_CONFIG_ENABLE_SED)
#if !(defined(CHIP_CONFIG_ENABLE_ICD_SERVER) && CHIP_CONFIG_ENABLE_ICD_SERVER)
// Identify Patterns have priority over Status patterns
if (!isPatternSet)
{
Expand All @@ -375,7 +375,7 @@ bool BaseApplication::ActivateStatusLedPatterns()
}
isPatternSet = true;
}
#endif // CHIP_DEVICE_CONFIG_ENABLE_SED
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER
#endif // ENABLE_WSTK_LEDS) && SL_CATALOG_SIMPLE_LED_LED1_PRESENT
return isPatternSet;
}
Expand All @@ -387,7 +387,7 @@ void BaseApplication::LightEventHandler()
// locked while these values are queried. However we use a non-blocking
// lock request (TryLockCHIPStack()) to avoid blocking other UI activities
// when the CHIP task is busy (e.g. with a long crypto operation).
#if !(defined(CHIP_DEVICE_CONFIG_ENABLE_SED) && CHIP_DEVICE_CONFIG_ENABLE_SED)
#if !(defined(CHIP_CONFIG_ENABLE_ICD_SERVER) && CHIP_CONFIG_ENABLE_ICD_SERVER)
if (PlatformMgr().TryLockChipStack())
{
#ifdef SL_WIFI
Expand All @@ -402,7 +402,7 @@ void BaseApplication::LightEventHandler()
sHaveBLEConnections = (ConnectivityMgr().NumBLEConnections() != 0);
PlatformMgr().UnlockChipStack();
}
#endif // CHIP_DEVICE_CONFIG_ENABLE_SED
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER

#if defined(ENABLE_WSTK_LEDS) && defined(SL_CATALOG_SIMPLE_LED_LED1_PRESENT)
// Update the status LED if factory reset has not been initiated.
Expand Down Expand Up @@ -472,13 +472,23 @@ void BaseApplication::ButtonHandler(AppEvent * aEvent)
SILABS_LOG("Failed to open the Basic Commissioning Window");
}
}
else { SILABS_LOG("Network is already provisioned, Ble advertissement not enabled"); }
else
{
SILABS_LOG("Network is already provisioned, Ble advertissement not enabled");
DeviceLayer::ChipDeviceEvent event;
event.Type = DeviceLayer::DeviceEventType::kAppWakeUpEvent;
CHIP_ERROR err = DeviceLayer::PlatformMgr().PostEvent(&event);
if (err != CHIP_NO_ERROR)
{
ChipLogError(AppServer, "Failed to post App wake up Event event %" CHIP_ERROR_FORMAT, err.Format());
}
}
}
else if (mFunctionTimerActive && mFunction == kFunction_FactoryReset)
{
CancelFunctionTimer();

#if CHIP_DEVICE_CONFIG_ENABLE_SED == 1
#if CHIP_CONFIG_ENABLE_ICD_SERVER == 1
StopStatusLEDTimer();
#endif

Expand Down Expand Up @@ -548,7 +558,7 @@ void BaseApplication::OnIdentifyStart(Identify * identify)
{
ChipLogProgress(Zcl, "onIdentifyStart");

#if CHIP_DEVICE_CONFIG_ENABLE_SED == 1
#if CHIP_CONFIG_ENABLE_ICD_SERVER == 1
StartStatusLEDTimer();
#endif
}
Expand All @@ -557,7 +567,7 @@ void BaseApplication::OnIdentifyStop(Identify * identify)
{
ChipLogProgress(Zcl, "onIdentifyStop");

#if CHIP_DEVICE_CONFIG_ENABLE_SED == 1
#if CHIP_CONFIG_ENABLE_ICD_SERVER == 1
StopStatusLEDTimer();
#endif
}
Expand All @@ -567,7 +577,7 @@ void BaseApplication::OnTriggerIdentifyEffectCompleted(chip::System::Layer * sys
ChipLogProgress(Zcl, "Trigger Identify Complete");
sIdentifyEffect = Clusters::Identify::EffectIdentifierEnum::kStopEffect;

#if CHIP_DEVICE_CONFIG_ENABLE_SED == 1
#if CHIP_CONFIG_ENABLE_ICD_SERVER == 1
StopStatusLEDTimer();
#endif
}
Expand All @@ -581,7 +591,7 @@ void BaseApplication::OnTriggerIdentifyEffect(Identify * identify)
ChipLogDetail(AppServer, "Identify Effect Variant unsupported. Using default");
}

#if CHIP_DEVICE_CONFIG_ENABLE_SED == 1
#if CHIP_CONFIG_ENABLE_ICD_SERVER == 1
StartStatusLEDTimer();
#endif

Expand Down
6 changes: 3 additions & 3 deletions examples/platform/silabs/efr32/matter_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,11 @@ CHIP_ERROR SilabsMatterConfig::InitOpenThread(void)
#if CHIP_DEVICE_CONFIG_THREAD_FTD
ReturnErrorOnFailure(ConnectivityMgr().SetThreadDeviceType(ConnectivityManager::kThreadDeviceType_Router));
#else // CHIP_DEVICE_CONFIG_THREAD_FTD
#if CHIP_DEVICE_CONFIG_ENABLE_SED
#if CHIP_CONFIG_ENABLE_ICD_SERVER
ReturnErrorOnFailure(ConnectivityMgr().SetThreadDeviceType(ConnectivityManager::kThreadDeviceType_SleepyEndDevice));
#else // CHIP_DEVICE_CONFIG_ENABLE_SED
#else // CHIP_CONFIG_ENABLE_ICD_SERVER
ReturnErrorOnFailure(ConnectivityMgr().SetThreadDeviceType(ConnectivityManager::kThreadDeviceType_MinimalEndDevice));
#endif // CHIP_DEVICE_CONFIG_ENABLE_SED
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER
#endif // CHIP_DEVICE_CONFIG_THREAD_FTD

SILABS_LOG("Starting OpenThread task");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
// Enable use of external heap allocator (calloc/free) for OpenThread.
#define OPENTHREAD_CONFIG_HEAP_EXTERNAL_ENABLE 1

#if CHIP_DEVICE_CONFIG_ENABLE_SED
#if CHIP_CONFIG_ENABLE_ICD_SERVER

#define OPENTHREAD_CONFIG_PARENT_SEARCH_ENABLE 0

Expand All @@ -46,7 +46,7 @@
// Timeout after 2 missed checkin or 4 mins if sleep interval is too short.
#define OPENTHREAD_CONFIG_MLE_CHILD_TIMEOUT_DEFAULT ((SL_MLE_TIMEOUT_s < 120) ? 240 : ((SL_MLE_TIMEOUT_s * 2) + 1))

#endif // CHIP_DEVICE_CONFIG_ENABLE_SED
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER

/****Uncomment below section for OpenThread Debug logs*/
// #define OPENTHREAD_CONFIG_LOG_LEVEL OT_LOG_LEVEL_DEBG
Expand Down
4 changes: 2 additions & 2 deletions examples/platform/silabs/efr32/rs911x/rsi_if.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ int32_t wfx_rsi_disconnect()
return status;
}

#if CHIP_DEVICE_CONFIG_ENABLE_SED
#if CHIP_CONFIG_ENABLE_ICD_SERVER
/******************************************************************
* @fn wfx_rsi_power_save()
* @brief
Expand Down Expand Up @@ -215,7 +215,7 @@ int32_t wfx_rsi_power_save()
SILABS_LOG("Powersave Config Success");
return status;
}
#endif /* CHIP_DEVICE_CONFIG_ENABLE_SED */
#endif /* CHIP_CONFIG_ENABLE_ICD_SERVER */

/******************************************************************
* @fn wfx_rsi_join_cb(uint16_t status, const uint8_t *buf, const uint16_t len)
Expand Down
4 changes: 2 additions & 2 deletions examples/platform/silabs/efr32/rs911x/wfx_rsi.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ int32_t wfx_rsi_get_ap_info(wfx_wifi_scan_result_t * ap);
int32_t wfx_rsi_get_ap_ext(wfx_wifi_scan_ext_t * extra_info);
int32_t wfx_rsi_reset_count();
int32_t wfx_rsi_disconnect();
#if CHIP_DEVICE_CONFIG_ENABLE_SED
#if CHIP_CONFIG_ENABLE_ICD_SERVER
int32_t wfx_rsi_power_save();
#endif /* CHIP_DEVICE_CONFIG_ENABLE_SED */
#endif /* CHIP_CONFIG_ENABLE_ICD_SERVER */

#ifdef __cplusplus
}
Expand Down
Loading

0 comments on commit 1132596

Please sign in to comment.