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 33 : System::Clock::Milliseconds32 ICDConfigurationData::GetSlowPollingInterval()
26 : {
27 : #if CHIP_CONFIG_ENABLE_ICD_LIT
28 : // When in SIT mode, the slow poll interval SHALL NOT be greater than the SIT mode polling threshold, per spec.
29 : // This is important for ICD device configured for LIT operation but currently operating as a SIT
30 : // due to a lack of client registration
31 : if (mICDMode == ICDMode::SIT && mSlowPollingInterval > kSITPollingThreshold)
32 : {
33 : return kSITPollingThreshold;
34 : }
35 : #endif // CHIP_CONFIG_ENABLE_ICD_LIT
36 :
37 33 : return mSlowPollingInterval;
38 : }
39 :
40 6 : CHIP_ERROR ICDConfigurationData::SetModeDurations(Optional<System::Clock::Milliseconds32> activeModeDuration,
41 : Optional<System::Clock::Milliseconds32> idleModeDuration)
42 : {
43 6 : VerifyOrReturnError(activeModeDuration.HasValue() || idleModeDuration.HasValue(), CHIP_ERROR_INVALID_ARGUMENT);
44 :
45 : // Convert idleModeDuration to seconds for the correct precision
46 6 : System::Clock::Seconds32 tmpIdleModeDuration = idleModeDuration.HasValue()
47 0 : ? std::chrono::duration_cast<System::Clock::Seconds32>(idleModeDuration.Value())
48 6 : : mIdleModeDuration;
49 :
50 6 : System::Clock::Milliseconds32 tmpActiveModeDuration = activeModeDuration.ValueOr(mActiveModeDuration);
51 :
52 6 : VerifyOrReturnError(tmpActiveModeDuration <= tmpIdleModeDuration, CHIP_ERROR_INVALID_ARGUMENT);
53 6 : VerifyOrReturnError(tmpIdleModeDuration <= kMaxIdleModeDuration, CHIP_ERROR_INVALID_ARGUMENT);
54 6 : VerifyOrReturnError(tmpIdleModeDuration >= kMinIdleModeDuration, CHIP_ERROR_INVALID_ARGUMENT);
55 :
56 6 : mIdleModeDuration = tmpIdleModeDuration;
57 6 : mActiveModeDuration = tmpActiveModeDuration;
58 :
59 6 : return CHIP_NO_ERROR;
60 : }
61 :
62 : } // namespace chip
|