@@ -223,6 +223,8 @@ const char * ReadClient::GetStateStr() const
223
223
return " AwaitingSubscribeResponse" ;
224
224
case ClientState::SubscriptionActive:
225
225
return " SubscriptionActive" ;
226
+ case ClientState::IdleSubscription:
227
+ return " IdleSubscription" ;
226
228
}
227
229
#endif // CHIP_DETAIL_LOGGING
228
230
return " N/A" ;
@@ -427,6 +429,31 @@ CHIP_ERROR ReadClient::GenerateDataVersionFilterList(DataVersionFilterIBs::Build
427
429
return CHIP_NO_ERROR;
428
430
}
429
431
432
+ CHIP_ERROR ReadClient::WakeUp ()
433
+ {
434
+ VerifyOrReturnError (IsIdle (), CHIP_ERROR_INCORRECT_STATE, " Not a valid subscription." );
435
+ VerifyOrReturnError (mPeerActivePeriod != System::Clock::kZero , CHIP_ERROR_INCORRECT_STATE, " The device should not sleep." );
436
+ MoveToState (ClientState::Idle);
437
+ Close (CHIP_ERROR_TIMEOUT);
438
+ return CHIP_NO_ERROR;
439
+ }
440
+
441
+ void ReadClient::UpdateActivePeriod (System::Clock::Timeout aActivePeriod)
442
+ {
443
+ mPeerActivePeriod = aActivePeriod;
444
+ }
445
+
446
+ CHIP_ERROR ReadClient::TouchPeerActiveTime (System::Clock::Timeout aActivePeriod)
447
+ {
448
+ System::Clock::Timestamp time ;
449
+
450
+ ReturnLogErrorOnFailure (System::SystemClock ().GetClock_RealTime (time ));
451
+
452
+ mPeerActiveUntilTimestamp = time + aActivePeriod;
453
+
454
+ return CHIP_NO_ERROR;
455
+ }
456
+
430
457
CHIP_ERROR ReadClient::OnMessageReceived (Messaging::ExchangeContext * apExchangeContext, const PayloadHeader & aPayloadHeader,
431
458
System::PacketBufferHandle && aPayload)
432
459
{
@@ -894,6 +921,24 @@ void ReadClient::OnLivenessTimeoutCallback(System::Layer * apSystemLayer, void *
894
921
" Subscription Liveness timeout with SubscriptionID = 0x%08" PRIx32 " , Peer = %02x:" ChipLogFormatX64,
895
922
_this->mSubscriptionId , _this->GetFabricIndex (), ChipLogValueX64 (_this->GetPeerNodeId ()));
896
923
924
+ if (mPeerActivePeriod != System::Clock::kZero )
925
+ {
926
+ // If device is sleeping, we mark the subscription as "IdleSubscription", and trigger resubscription on `WakeUp`.
927
+ System::Clock::Timestamp time ;
928
+ CHIP_ERROR error = System::SystemClock ().GetClock_RealTime (time );
929
+ if (error != CHIP_NO_ERROR)
930
+ {
931
+ ChipLogError (DataManagement, " Failed to get current time: %s" , ErrorStr (error));
932
+ _this->Close (error, false );
933
+ }
934
+ if (time > mPeerActiveUntilTimestamp )
935
+ {
936
+ ChipLogProgress (DataManagement, " Peer is not active now, mark the subscription as IdleSubscription." );
937
+ MoveToState (ClientState::IdleSubscription);
938
+ return ;
939
+ }
940
+ }
941
+
897
942
// We didn't get a message from the server on time; it's possible that it no
898
943
// longer has a useful CASE session to us. Mark defunct all sessions that
899
944
// have not seen peer activity in at least as long as our session.
@@ -998,6 +1043,18 @@ CHIP_ERROR ReadClient::SendSubscribeRequestImpl(const ReadPrepareParams & aReadP
998
1043
mReadPrepareParams .mSessionHolder = aReadPrepareParams.mSessionHolder ;
999
1044
}
1000
1045
1046
+ mPeerActivePeriod = aReadPrepareParams.mActivePeriod ;
1047
+ if (mPeerActivePeriod != System::Clock::kZero )
1048
+ {
1049
+ System::Clock::Timestamp time ;
1050
+ ReturnErrorOnFailure (System::SystemClock ().GetClock_RealTime (time ));
1051
+ mPeerActiveUntilTimestamp = mPeerActivePeriod ;
1052
+ }
1053
+ else
1054
+ {
1055
+ mPeerActiveUntilTimestamp = System::Clock::kZero ;
1056
+ }
1057
+
1001
1058
mMinIntervalFloorSeconds = aReadPrepareParams.mMinIntervalFloorSeconds ;
1002
1059
1003
1060
// Todo: Remove the below, Update span in ReadPrepareParams
0 commit comments