Skip to content

Commit 3fe8ec6

Browse files
[ICD] Trigger Check-In messages at boot (project-chip#31993)
* 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 <andy314@gmail.com>
1 parent 91670ba commit 3fe8ec6

File tree

4 files changed

+66
-28
lines changed

4 files changed

+66
-28
lines changed

src/app/icd/server/ICDManager.cpp

+14
Original file line numberDiff line numberDiff line change
@@ -544,5 +544,19 @@ bool ICDManager::CheckInMessagesWouldBeSent()
544544
return false;
545545
}
546546

547+
void ICDManager::TriggerCheckInMessages()
548+
{
549+
VerifyOrReturn(SupportsFeature(Feature::kCheckInProtocolSupport));
550+
551+
// Only trigger Check-In messages when we are in IdleMode.
552+
// If we are already in ActiveMode, Check-In messages have already been sent.
553+
VerifyOrReturn(mOperationalState == OperationalState::IdleMode);
554+
555+
// If we don't have any Check-In messages to send, do nothing
556+
VerifyOrReturn(CheckInMessagesWouldBeSent());
557+
558+
UpdateOperationState(OperationalState::ActiveMode);
559+
}
560+
547561
} // namespace app
548562
} // namespace chip

src/app/icd/server/ICDManager.h

+5
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,11 @@ class ICDManager : public ICDListener
108108
void OnICDManagementServerEvent(ICDManagementEvents event) override;
109109
void OnSubscriptionReport() override;
110110

111+
/**
112+
* @brief Trigger the ICDManager to send Check-In message if necessary
113+
*/
114+
void TriggerCheckInMessages();
115+
111116
protected:
112117
friend class TestICDManager;
113118

src/app/server/Server.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,16 @@ void Server::OnPlatformEvent(const DeviceLayer::ChipDeviceEvent & event)
436436
}
437437
break;
438438
case DeviceEventType::kServerReady:
439+
#if CHIP_CONFIG_ENABLE_ICD_SERVER
440+
// Only Trigger Check-In messages if we are not in the middle of a commissioning.
441+
// This check is only necessary for the first commissioiner since the kServerReady event
442+
// is triggered once we join the network.
443+
// We trigger Check-In messages before resuming subscriptions to avoid doing both.
444+
if (!mFailSafeContext.IsFailSafeArmed())
445+
{
446+
mICDManager.TriggerCheckInMessages();
447+
}
448+
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER
439449
#if CHIP_CONFIG_PERSIST_SUBSCRIPTIONS
440450
ResumeSubscriptions();
441451
#endif

src/app/tests/suites/TestIcdManagementCluster.yaml

+37-28
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,43 @@ tests:
5252
},
5353
]
5454

55+
- label: "Read ICDCounter"
56+
command: "readAttribute"
57+
attribute: "ICDCounter"
58+
response:
59+
constraints:
60+
type: int32u
61+
minValue: 0x0
62+
maxValue: 0xFFFFFFFF
63+
saveAs: beforeRebootICDCounter
64+
65+
- label: "Reboot target device"
66+
cluster: "SystemCommands"
67+
command: "Reboot"
68+
69+
- label: "Connect to the device again"
70+
cluster: "DelayCommands"
71+
command: "WaitForCommissionee"
72+
arguments:
73+
values:
74+
- name: "nodeId"
75+
value: nodeId
76+
77+
- label: "Wait for 1S"
78+
cluster: "DelayCommands"
79+
command: "WaitForMs"
80+
arguments:
81+
values:
82+
- name: "ms"
83+
value: 1000
84+
85+
# Verifies ICDCounter increment and Check-In message at reboot
86+
- label: "Read ICDCounter after reboot"
87+
command: "readAttribute"
88+
attribute: "ICDCounter"
89+
response:
90+
value: beforeRebootICDCounter + 101
91+
5592
- label: "Unregister Client Registered During Commissioning"
5693
command: "UnregisterClient"
5794
arguments:
@@ -83,34 +120,6 @@ tests:
83120
response:
84121
value: 5000
85122

86-
- label: "Read ICDCounter"
87-
command: "readAttribute"
88-
attribute: "ICDCounter"
89-
response:
90-
constraints:
91-
type: int32u
92-
minValue: 0x0
93-
maxValue: 0xFFFFFFFF
94-
saveAs: beforeRebootICDCounter
95-
96-
- label: "Reboot target device"
97-
cluster: "SystemCommands"
98-
command: "Reboot"
99-
100-
- label: "Connect to the device again"
101-
cluster: "DelayCommands"
102-
command: "WaitForCommissionee"
103-
arguments:
104-
values:
105-
- name: "nodeId"
106-
value: nodeId
107-
108-
- label: "Read ICDCounter after reboot"
109-
command: "readAttribute"
110-
attribute: "ICDCounter"
111-
response:
112-
value: beforeRebootICDCounter + 100
113-
114123
- label: "Read UserActiveModeTriggerHint"
115124
command: "readAttribute"
116125
attribute: "UserActiveModeTriggerHint"

0 commit comments

Comments
 (0)