Skip to content

Commit

Permalink
[SL-ONLY] Add business logic for the selective listening impl (projec…
Browse files Browse the repository at this point in the history
…t-chip#139)

Co-authored-by: lpbeliveau-silabs <[email protected]>
  • Loading branch information
mkardous-silabs and lpbeliveau-silabs authored Nov 28, 2024
1 parent e4c96d0 commit 43891a3
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 15 deletions.
16 changes: 16 additions & 0 deletions examples/platform/silabs/BaseApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@
#include <platform/silabs/tracing/SilabsTracing.h>
#endif // MATTER_TRACING_ENABLED

// sl-only
#if SL_MATTER_ENABLE_APP_SLEEP_MANAGER
#include <ApplicationSleepManager.h>
#endif // SL_MATTER_ENABLE_APP_SLEEP_MANAGER

/**********************************************************
* Defines and Constants
*********************************************************/
Expand Down Expand Up @@ -213,8 +218,19 @@ void BaseApplicationDelegate::OnCommissioningSessionStopped()
#endif // SL_WIFI && CHIP_CONFIG_ENABLE_ICD_SERVER
}

void BaseApplicationDelegate::OnCommissioningWindowOpened()
{
#if SL_MATTER_ENABLE_APP_SLEEP_MANAGER
app::Silabs::ApplicationSleepManager::GetInstance().OnCommissioningWindowOpened();
#endif // SL_MATTER_ENABLE_APP_SLEEP_MANAGER
}

void BaseApplicationDelegate::OnCommissioningWindowClosed()
{
#if SL_MATTER_ENABLE_APP_SLEEP_MANAGER
app::Silabs::ApplicationSleepManager::GetInstance().OnCommissioningWindowClosed();
#endif // SL_MATTER_ENABLE_APP_SLEEP_MANAGER

if (BaseApplication::GetProvisionStatus())
{
// After the device is provisioned and the commissioning passed
Expand Down
1 change: 1 addition & 0 deletions examples/platform/silabs/BaseApplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class BaseApplicationDelegate : public AppDelegate, public chip::FabricTable::De
void OnCommissioningSessionStarted() override;
void OnCommissioningSessionStopped() override;
void OnCommissioningWindowClosed() override;
void OnCommissioningWindowOpened() override;

// FabricTable::Delegate
void OnFabricCommitted(const chip::FabricTable & fabricTable, chip::FabricIndex fabricIndex) override;
Expand Down
1 change: 0 additions & 1 deletion examples/platform/silabs/MatterConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,6 @@ CHIP_ERROR SilabsMatterConfig::InitMatter(const char * appName)
err = app::Silabs::ApplicationSleepManager::GetInstance()
.SetFabricTable(&Server::GetInstance().GetFabricTable())
.SetSubscriptionInfoProvider(app::InteractionModelEngine::GetInstance())
.SetCommissioningWindowManager(&Server::GetInstance().GetCommissioningWindowManager())
.SetWifiSleepManager(&WifiSleepManager::GetInstance())
.Init();
VerifyOrReturnError(err == CHIP_NO_ERROR, err, ChipLogError(DeviceLayer, "ApplicationSleepManager init failed"));
Expand Down
38 changes: 33 additions & 5 deletions examples/platform/silabs/wifi/icd/ApplicationSleepManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ CHIP_ERROR ApplicationSleepManager::Init()
VerifyOrReturnError(mFabricTable != nullptr, CHIP_ERROR_INVALID_ARGUMENT, ChipLogError(AppServer, "FabricTable is null"));
VerifyOrReturnError(mSubscriptionsInfoProvider != nullptr, CHIP_ERROR_INVALID_ARGUMENT,
ChipLogError(AppServer, "SubscriptionsInfoProvider is null"));
VerifyOrReturnError(mCommissioningWindowManager != nullptr, CHIP_ERROR_INVALID_ARGUMENT,
ChipLogError(AppServer, "CommissioningWindowManager is null"));
VerifyOrReturnError(mWifiSleepManager != nullptr, CHIP_ERROR_INVALID_ARGUMENT,
ChipLogError(AppServer, "WifiSleepManager is null"));

Expand All @@ -42,6 +40,18 @@ CHIP_ERROR ApplicationSleepManager::Init()
return CHIP_NO_ERROR;
}

void ApplicationSleepManager::OnCommissioningWindowOpened()
{
mIsCommissionningWindowOpen = true;
mWifiSleepManager->VerifyAndTransitionToLowPowerMode();
}

void ApplicationSleepManager::OnCommissioningWindowClosed()
{
mIsCommissionningWindowOpen = false;
mWifiSleepManager->VerifyAndTransitionToLowPowerMode();
}

void ApplicationSleepManager::OnSubscriptionEstablished(chip::app::ReadHandler & aReadHandler)
{
mWifiSleepManager->VerifyAndTransitionToLowPowerMode();
Expand Down Expand Up @@ -71,10 +81,28 @@ void ApplicationSleepManager::OnFabricCommitted(const chip::FabricTable & fabric

bool ApplicationSleepManager::CanGoToLIBasedSleep()
{
// TODO: Implement your logic here
bool canGoToLIBasedSleep = true;

if (mIsCommissionningWindowOpen)
{
ChipLogProgress(AppServer, "Commissioning Window is Open - Cannot go to LI based sleep");
canGoToLIBasedSleep = false;
}
else
{
for (auto it = mFabricTable->begin(); it != mFabricTable->end(); ++it)
{
if (!mSubscriptionsInfoProvider->FabricHasAtLeastOneActiveSubscription(it->GetFabricIndex()))
{
ChipLogProgress(AppServer, "Fabric index %u has no active subscriptions - Cannot go to LI based sleep",
it->GetFabricIndex());
canGoToLIBasedSleep = false;
break;
}
}
}

ChipLogProgress(AppServer, "CanGoToLIBasedSleep was called!");
return false;
return canGoToLIBasedSleep;
}

} // namespace Silabs
Expand Down
32 changes: 23 additions & 9 deletions examples/platform/silabs/wifi/icd/ApplicationSleepManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,26 @@ class ApplicationSleepManager : public chip::app::ReadHandler::ApplicationCallba
return *this;
}

ApplicationSleepManager & SetCommissioningWindowManager(chip::CommissioningWindowManager * commissioningWindowManager)
{
mCommissioningWindowManager = commissioningWindowManager;
return *this;
}

ApplicationSleepManager & SetWifiSleepManager(chip::DeviceLayer::Silabs::WifiSleepManager * wifiSleepManager)
{
mWifiSleepManager = wifiSleepManager;
return *this;
}

/**
* @brief Sets the commissioning window state to open and calls the WifiSleepManager VerifyAndTransitionToLowPowerMode.
* The VerifyAndTransitionToLowPowerMode function is responsible of then queriyng the ApplicationSleepManager to
* determine in which low power state the Wi-Fi device can transition to.
*/
void OnCommissioningWindowOpened();

/**
* @brief Sets the commissioning window state to open and calls the WifiSleepManager VerifyAndTransitionToLowPowerMode.
* The VerifyAndTransitionToLowPowerMode function is responsible of then queriyng the ApplicationSleepManager to
* determine in which low power state the Wi-Fi device can transition to.
*/
void OnCommissioningWindowClosed();

// ReadHandler::ApplicationCallback implementation

/**
Expand All @@ -94,10 +102,14 @@ class ApplicationSleepManager : public chip::app::ReadHandler::ApplicationCallba
// WifiSleepManager::ApplicationCallback implementation

/**
* @brief TODO
* @brief Function encapsulates the application logic to determine if the Wi-Fi device can go into LI based sleep.
*
* @return true
* @return false
* - 1. Check if the commissioning window is open. If it is open, the Wi-Fi device cannot go to LI based sleep.
* - 2. Check if all Fabrics have at least 1 subscription. If there is at least one fabric without a subscription, the
* Wi-Fi cannot go to LI based sleep.
*
* @return true if the device can go to LI sleep
* false if the device cannot go to LI sleep
*/
bool CanGoToLIBasedSleep() override;

Expand Down Expand Up @@ -131,6 +143,8 @@ class ApplicationSleepManager : public chip::app::ReadHandler::ApplicationCallba
chip::app::SubscriptionsInfoProvider * mSubscriptionsInfoProvider = nullptr;
chip::CommissioningWindowManager * mCommissioningWindowManager = nullptr;
chip::DeviceLayer::Silabs::WifiSleepManager * mWifiSleepManager = nullptr;

bool mIsCommissionningWindowOpen = false;
};

} // namespace Silabs
Expand Down

0 comments on commit 43891a3

Please sign in to comment.