Skip to content

Commit

Permalink
[ICD] Trigger Check-In messages at boot (project-chip#31993)
Browse files Browse the repository at this point in the history
* Send Check-In message at boot

* Update reboot test

* update comment

* restyle

* refactor function so that it can be used outside of the reboot

* Remove unused define function

---------

Co-authored-by: Andrei Litvin <[email protected]>
  • Loading branch information
2 people authored and erwinpan1 committed Feb 12, 2024
1 parent 1b3f7cd commit 9069564
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 28 deletions.
14 changes: 14 additions & 0 deletions src/app/icd/server/ICDManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -544,5 +544,19 @@ bool ICDManager::CheckInMessagesWouldBeSent()
return false;
}

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

// Only trigger Check-In messages when we are in IdleMode.
// If we are already in ActiveMode, Check-In messages have already been sent.
VerifyOrReturn(mOperationalState == OperationalState::IdleMode);

// If we don't have any Check-In messages to send, do nothing
VerifyOrReturn(CheckInMessagesWouldBeSent());

UpdateOperationState(OperationalState::ActiveMode);
}

} // 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
10 changes: 10 additions & 0 deletions src/app/server/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,16 @@ 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 triggered once we join the network.
// We trigger Check-In messages before resuming subscriptions to avoid doing both.
if (!mFailSafeContext.IsFailSafeArmed())
{
mICDManager.TriggerCheckInMessages();
}
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER
#if CHIP_CONFIG_PERSIST_SUBSCRIPTIONS
ResumeSubscriptions();
#endif
Expand Down
65 changes: 37 additions & 28 deletions src/app/tests/suites/TestIcdManagementCluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,43 @@ tests:
},
]

- label: "Read ICDCounter"
command: "readAttribute"
attribute: "ICDCounter"
response:
constraints:
type: int32u
minValue: 0x0
maxValue: 0xFFFFFFFF
saveAs: beforeRebootICDCounter

- label: "Reboot target device"
cluster: "SystemCommands"
command: "Reboot"

- label: "Connect to the device again"
cluster: "DelayCommands"
command: "WaitForCommissionee"
arguments:
values:
- name: "nodeId"
value: nodeId

- label: "Wait for 1S"
cluster: "DelayCommands"
command: "WaitForMs"
arguments:
values:
- name: "ms"
value: 1000

# Verifies ICDCounter increment and Check-In message at reboot
- label: "Read ICDCounter after reboot"
command: "readAttribute"
attribute: "ICDCounter"
response:
value: beforeRebootICDCounter + 101

- label: "Unregister Client Registered During Commissioning"
command: "UnregisterClient"
arguments:
Expand Down Expand Up @@ -83,34 +120,6 @@ tests:
response:
value: 5000

- label: "Read ICDCounter"
command: "readAttribute"
attribute: "ICDCounter"
response:
constraints:
type: int32u
minValue: 0x0
maxValue: 0xFFFFFFFF
saveAs: beforeRebootICDCounter

- label: "Reboot target device"
cluster: "SystemCommands"
command: "Reboot"

- label: "Connect to the device again"
cluster: "DelayCommands"
command: "WaitForCommissionee"
arguments:
values:
- name: "nodeId"
value: nodeId

- label: "Read ICDCounter after reboot"
command: "readAttribute"
attribute: "ICDCounter"
response:
value: beforeRebootICDCounter + 100

- label: "Read UserActiveModeTriggerHint"
command: "readAttribute"
attribute: "UserActiveModeTriggerHint"
Expand Down

0 comments on commit 9069564

Please sign in to comment.