Skip to content

Commit

Permalink
Send Check-In message at boot
Browse files Browse the repository at this point in the history
  • Loading branch information
mkardous-silabs committed Feb 6, 2024
1 parent 473fa74 commit 8b79c4d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/app/icd/server/ICDManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ using namespace chip::app::Clusters;
using namespace chip::app::Clusters::IcdManagement;
using namespace System::Clock;

#define TOGGLE_STATE(state) ((state == OperationalState::IdleMode) ? OperationalState::ActiveMode : OperationalState::IdleMode)

static_assert(UINT8_MAX >= CHIP_CONFIG_MAX_EXCHANGE_CONTEXTS,
"ICDManager::mOpenExchangeContextCount cannot hold count for the max exchange count");

Expand Down Expand Up @@ -589,5 +591,16 @@ bool ICDManager::CheckInMessagesWouldBeSent()
return false;
}

void ICDManager::TriggerCheckInMessages()
{
VerifyOrReturn(SupportsFeature(Feature::kCheckInProtocolSupport));

// Check if we have any Check-In messages to send
// We have Check-In messages to send. Transition the device to active mode.
// We don't have any Check-In messages to send. Transition the device to idle mode.
mOperationalState = CheckInMessagesWouldBeSent() ? OperationalState::IdleMode : OperationalState::ActiveMode;
UpdateOperationState(TOGGLE_STATE(mOperationalState));
}

} // namespace app
} // namespace chip
5 changes: 5 additions & 0 deletions src/app/icd/server/ICDManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ class ICDManager : public ICDListener
void OnICDManagementServerEvent(ICDManagementEvents event) override;
void OnSubscriptionReport() override;

/**
* @brief Trigger the ICDManager to send Check-In message if necessary
*/
void TriggerCheckInMessages();

protected:
friend class TestICDManager;

Expand Down
9 changes: 9 additions & 0 deletions src/app/server/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,15 @@ void Server::OnPlatformEvent(const DeviceLayer::ChipDeviceEvent & event)
}
break;
case DeviceEventType::kServerReady:
#if CHIP_CONFIG_ENABLE_ICD_SERVER
// Only Trigger Check-In messages if we are not in the middle of a commissioning.
// This check is only necessary for the first commissioiner since the kServerReady event
// is called once we join the network.
if (!mFailSafeContext.IsFailSafeArmed())
{
mICDManager.TriggerCheckInMessages();
}
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER
#if CHIP_CONFIG_PERSIST_SUBSCRIPTIONS
ResumeSubscriptions();
#endif
Expand Down

0 comments on commit 8b79c4d

Please sign in to comment.