Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SL-UP] Fix Wi-Fi Sleep Manager commissioning progress check from clean boot #167

Merged
merged 1 commit into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/platform/silabs/BaseApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -931,7 +931,7 @@ void BaseApplication::OnPlatformEvent(const ChipDeviceEvent * event, intptr_t)
#if SL_WIFI
chip::app::DnssdServer::Instance().StartServer();
#if CHIP_CONFIG_ENABLE_ICD_SERVER
WifiSleepManager::GetInstance().VerifyAndTransitionToLowPowerMode();
WifiSleepManager::GetInstance().VerifyAndTransitionToLowPowerMode(WifiSleepManager::PowerEvent::kConnectivityChange);
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER
#endif // SL_WIFI

Expand All @@ -946,7 +946,7 @@ void BaseApplication::OnPlatformEvent(const ChipDeviceEvent * event, intptr_t)

case DeviceEventType::kCommissioningComplete: {
#if SL_WIFI && CHIP_CONFIG_ENABLE_ICD_SERVER
WifiSleepManager::GetInstance().VerifyAndTransitionToLowPowerMode();
WifiSleepManager::GetInstance().VerifyAndTransitionToLowPowerMode(WifiSleepManager::PowerEvent::kCommissioningComplete);
#endif // SL_WIFI && CHIP_CONFIG_ENABLE_ICD_SERVER

// SL-Only
Expand Down
10 changes: 5 additions & 5 deletions examples/platform/silabs/wifi/icd/ApplicationSleepManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,17 @@ CHIP_ERROR ApplicationSleepManager::Init()
void ApplicationSleepManager::OnCommissioningWindowOpened()
{
mIsCommissionningWindowOpen = true;
#if ( ( defined(SLI_SI91X_MCU_INTERFACE) && SLI_SI91X_MCU_INTERFACE == 1 ) )
#if (defined(SLI_SI91X_MCU_INTERFACE) && SLI_SI91X_MCU_INTERFACE == 1)
mWifiSleepManager->VerifyAndTransitionToLowPowerMode();
#endif // ( ( defined(SLI_SI91X_MCU_INTERFACE) && SLI_SI91X_MCU_INTERFACE == 1 ) )
#endif // (defined(SLI_SI91X_MCU_INTERFACE) && SLI_SI91X_MCU_INTERFACE == 1)
}

void ApplicationSleepManager::OnCommissioningWindowClosed()
{
mIsCommissionningWindowOpen = false;
#if ( ( defined(SLI_SI91X_MCU_INTERFACE) && SLI_SI91X_MCU_INTERFACE == 1 ) )
#if (defined(SLI_SI91X_MCU_INTERFACE) && SLI_SI91X_MCU_INTERFACE == 1)
mWifiSleepManager->VerifyAndTransitionToLowPowerMode();
#endif // ( ( defined(SLI_SI91X_MCU_INTERFACE) && SLI_SI91X_MCU_INTERFACE == 1 ) )
#endif // (defined(SLI_SI91X_MCU_INTERFACE) && SLI_SI91X_MCU_INTERFACE == 1)
}

void ApplicationSleepManager::OnSubscriptionEstablished(chip::app::ReadHandler & aReadHandler)
Expand Down Expand Up @@ -103,7 +103,7 @@ bool ApplicationSleepManager::CanGoToLIBasedSleep()
canGoToLIBasedSleep = false;
break;
}
ChipLogProgress(AppServer, "All Fabrics have at least 1 active subscription!");
ChipLogProgress(AppServer, "Fabric index %u has an active subscriptions!", it->GetFabricIndex());
}
}

Expand Down
26 changes: 23 additions & 3 deletions src/platform/silabs/wifi/icd/WifiSleepManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ CHIP_ERROR WifiSleepManager::RequestHighPerformance()

mHighPerformanceRequestCounter++;

// We don't do the mHighPerformanceRequestCounter check here; the check is in TransitionToLowPowerMode function
// We don't do the mHighPerformanceRequestCounter check here; the check is in VerifyAndTransitionToLowPowerMode function
ReturnErrorOnFailure(VerifyAndTransitionToLowPowerMode());

return CHIP_NO_ERROR;
Expand All @@ -121,14 +121,34 @@ CHIP_ERROR WifiSleepManager::RemoveHighPerformanceRequest()

mHighPerformanceRequestCounter--;

// We don't do the mHighPerformanceRequestCounter check here; the check is in TransitionToLowPowerMode function
// We don't do the mHighPerformanceRequestCounter check here; the check is in VerifyAndTransitionToLowPowerMode function
ReturnErrorOnFailure(VerifyAndTransitionToLowPowerMode());

return CHIP_NO_ERROR;
}

CHIP_ERROR WifiSleepManager::VerifyAndTransitionToLowPowerMode()
CHIP_ERROR WifiSleepManager::HandlePowerEvent(PowerEvent event)
{
switch (event)
{
case PowerEvent::kCommissioningComplete:
ChipLogProgress(AppServer, "WifiSleepManager: Handling Commissioning Complete Event");
mIsCommissioningInProgress = false;
break;
case PowerEvent::kConnectivityChange:
case PowerEvent::kGenericEvent:
// No additional processing needed for these events at the moment
break;
default:
ChipLogError(AppServer, "Unknown Power Event");
return CHIP_ERROR_INVALID_ARGUMENT;
}
return CHIP_NO_ERROR;
}

CHIP_ERROR WifiSleepManager::VerifyAndTransitionToLowPowerMode(PowerEvent event)
{
ReturnErrorOnFailure(HandlePowerEvent(event));

#if SLI_SI917 // 917 SoC & NCP
if (mHighPerformanceRequestCounter > 0)
Expand Down
20 changes: 19 additions & 1 deletion src/platform/silabs/wifi/icd/WifiSleepManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ class WifiSleepManager

static WifiSleepManager & GetInstance() { return mInstance; }

enum class PowerEvent : uint8_t
{
kGenericEvent = 0,
kCommissioningComplete = 1,
kConnectivityChange = 2,
};

/**
* @brief Class implements the callbacks that the application can implement
* to alter the WifiSleepManager behaviors.
Expand Down Expand Up @@ -122,15 +129,26 @@ class WifiSleepManager
* 3. If no commissioning is in progress and the device is unprovisioned, configure deep sleep.
* 4. If the application callback allows, configure LI based sleep; otherwise, configure DTIM based sleep.
*
* @param event PowerEvent triggering the Verify and transition to low power mode processing
*
* @return CHIP_ERROR CHIP_NO_ERROR if the device was transitionned to low power
* CHIP_ERROR_INTERNAL if an error occured
*/
CHIP_ERROR VerifyAndTransitionToLowPowerMode();
CHIP_ERROR VerifyAndTransitionToLowPowerMode(PowerEvent event = PowerEvent::kGenericEvent);

private:
WifiSleepManager() = default;
~WifiSleepManager() = default;

/**
* @brief Function to handle the power events before transitionning the device to the appropriate low power mode.
*
* @param event PowerEvent to handle
* @return CHIP_ERROR CHIP_NO_ERROR if the event was handled successfully
* CHIP_ERROR_INVALID_ARGUMENT if the event is not supported
*/
CHIP_ERROR HandlePowerEvent(PowerEvent event);

static WifiSleepManager mInstance;

bool mIsCommissioningInProgress = false;
Expand Down
Loading