Line data Source code
1 : /*
2 : *
3 : * Copyright (c) 2023 Project CHIP Authors
4 : *
5 : * Licensed under the Apache License, Version 2.0 (the "License");
6 : * you may not use this file except in compliance with the License.
7 : * You may obtain a copy of the License at
8 : *
9 : * http://www.apache.org/licenses/LICENSE-2.0
10 : *
11 : * Unless required by applicable law or agreed to in writing, software
12 : * distributed under the License is distributed on an "AS IS" BASIS,
13 : * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 : * See the License for the specific language governing permissions and
15 : * limitations under the License.
16 : */
17 :
18 : #include "ICDConfigurationData.h"
19 : #include <lib/support/CodeUtils.h>
20 :
21 : namespace chip {
22 :
23 : ICDConfigurationData ICDConfigurationData::instance;
24 :
25 40 : System::Clock::Milliseconds32 ICDConfigurationData::GetSlowPollingInterval()
26 : {
27 : // When LIT capable device operates in SIT mode, it shall transition to use the mSITPollingInterval
28 : // if this one is shorter than the configured mLITPollingInterval.
29 : // Either way, the slow poll interval used SHALL NOT be greater than the SIT mode polling threshold, per spec.
30 : // This is important for ICD device configured for LIT operation but currently operating as a SIT
31 : // due to a lack of client registration
32 40 : if (mFeatureMap.Has(app::Clusters::IcdManagement::Feature::kLongIdleTimeSupport) && mICDMode == ICDMode::SIT)
33 : {
34 : // mSITPollingInterval cannot be configured to a value greater than kSITPollingThreshold.
35 : // The SIT slow polling interval compliance is therefore always respected by using the smallest
36 : // value from mLITPollingInterval or mSITPollingInterval;
37 3 : return std::min(mLITPollingInterval, mSITPollingInterval);
38 : }
39 :
40 37 : return mLITPollingInterval;
41 : }
42 :
43 6 : CHIP_ERROR ICDConfigurationData::SetSlowPollingInterval(System::Clock::Milliseconds32 slowPollInterval)
44 : {
45 6 : bool isLITSupported = mFeatureMap.Has(app::Clusters::IcdManagement::Feature::kLongIdleTimeSupport);
46 : // If LIT is not supported, the slow polling interval cannot be set higher than kSITPollingThreshold.
47 6 : VerifyOrReturnError((isLITSupported || slowPollInterval <= kSITPollingThreshold), CHIP_ERROR_INVALID_ARGUMENT);
48 :
49 5 : mLITPollingInterval = slowPollInterval;
50 5 : return CHIP_NO_ERROR;
51 : };
52 :
53 3 : CHIP_ERROR ICDConfigurationData::SetSITPollingInterval(System::Clock::Milliseconds32 pollingInterval)
54 : {
55 3 : VerifyOrReturnError(pollingInterval <= kSITPollingThreshold, CHIP_ERROR_INVALID_ARGUMENT);
56 2 : mSITPollingInterval = pollingInterval;
57 2 : return CHIP_NO_ERROR;
58 : }
59 :
60 9 : CHIP_ERROR ICDConfigurationData::SetModeDurations(Optional<System::Clock::Milliseconds32> activeModeDuration,
61 : Optional<System::Clock::Milliseconds32> idleModeDuration)
62 : {
63 9 : VerifyOrReturnError(activeModeDuration.HasValue() || idleModeDuration.HasValue(), CHIP_ERROR_INVALID_ARGUMENT);
64 :
65 : // Convert idleModeDuration to seconds for the correct precision
66 9 : System::Clock::Seconds32 tmpIdleModeDuration = idleModeDuration.HasValue()
67 3 : ? std::chrono::duration_cast<System::Clock::Seconds32>(idleModeDuration.Value())
68 9 : : mIdleModeDuration;
69 :
70 9 : System::Clock::Milliseconds32 tmpActiveModeDuration = activeModeDuration.ValueOr(mActiveModeDuration);
71 :
72 9 : VerifyOrReturnError(tmpActiveModeDuration <= tmpIdleModeDuration, CHIP_ERROR_INVALID_ARGUMENT);
73 8 : VerifyOrReturnError(tmpIdleModeDuration <= kMaxIdleModeDuration, CHIP_ERROR_INVALID_ARGUMENT);
74 8 : VerifyOrReturnError(tmpIdleModeDuration >= kMinIdleModeDuration, CHIP_ERROR_INVALID_ARGUMENT);
75 :
76 8 : mIdleModeDuration = tmpIdleModeDuration;
77 8 : mActiveModeDuration = tmpActiveModeDuration;
78 :
79 8 : return CHIP_NO_ERROR;
80 : }
81 :
82 : } // namespace chip
|