19
19
#include < app-common/zap-generated/ids/Attributes.h>
20
20
#include < app-common/zap-generated/ids/Clusters.h>
21
21
#include < app/icd/ICDManager.h>
22
+ #include < app/icd/IcdMonitoringTable.h>
22
23
#include < lib/support/CodeUtils.h>
23
24
#include < lib/support/logging/CHIPLogging.h>
24
25
#include < platform/ConnectivityManager.h>
25
26
#include < platform/LockTracker.h>
26
27
#include < platform/internal/CHIPDeviceLayerInternal.h>
28
+ #include < stdlib.h>
27
29
28
30
namespace chip {
29
31
namespace app {
@@ -32,8 +34,13 @@ using namespace chip::app;
32
34
using namespace chip ::app::Clusters;
33
35
using namespace chip ::app::Clusters::IcdManagement;
34
36
35
- void ICDManager::ICDManager::Init ()
37
+ void ICDManager::ICDManager::Init (PersistentStorageDelegate * storage, FabricTable * fabricTable )
36
38
{
39
+ VerifyOrDie (storage != nullptr );
40
+ VerifyOrDie (fabricTable != nullptr );
41
+ mStorage = storage;
42
+ mFabricTable = fabricTable;
43
+
37
44
uint32_t activeModeInterval;
38
45
if (Attributes::ActiveModeInterval::Get (kRootEndpointId , &activeModeInterval) != EMBER_ZCL_STATUS_SUCCESS)
39
46
{
@@ -49,16 +56,17 @@ void ICDManager::ICDManager::Shutdown()
49
56
// cancel any running timer of the icd
50
57
DeviceLayer::SystemLayer ().CancelTimer (OnIdleModeDone, this );
51
58
DeviceLayer::SystemLayer ().CancelTimer (OnActiveModeDone, this );
52
- mIcdMode = ICDMode::SIT;
59
+ mICDMode = ICDMode::SIT;
53
60
mOperationalState = OperationalState::IdleMode;
61
+ mStorage = nullptr ;
62
+ mFabricTable = nullptr ;
54
63
}
55
64
56
65
bool ICDManager::SupportsCheckInProtocol ()
57
66
{
58
67
bool success;
59
68
uint32_t featureMap;
60
69
success = (Attributes::FeatureMap::Get (kRootEndpointId , &featureMap) == EMBER_ZCL_STATUS_SUCCESS);
61
-
62
70
return success ? ((featureMap & to_underlying (Feature::kCheckInProtocolSupport )) != 0 ) : false ;
63
71
}
64
72
@@ -68,25 +76,25 @@ void ICDManager::UpdateIcdMode()
68
76
69
77
ICDMode tempMode = ICDMode::SIT;
70
78
71
- // TODO ICD LIT FIX DEPENDENCY ISSUE with app/util/IcdMonitoringTable.h and app/server:server
72
79
// The Check In Protocol Feature is required and the slow polling interval shall also be greater than 15 seconds
73
80
// to run an ICD in LIT mode.
74
- // if (kSlowPollingInterval > kICDSitModePollingThreashold && SupportsCheckInProtocol())
75
- // {
76
- // // We can only get to LIT Mode, if at least one client is registered to the ICD device
77
- // const auto & fabricTable = Server::GetInstance().GetFabricTable();
78
- // for (const auto & fabricInfo : fabricTable)
79
- // {
80
- // PersistentStorageDelegate & storage = Server::GetInstance().GetPersistentStorage();
81
- // IcdMonitoringTable table(storage, fabricInfo.GetFabricIndex(), 1);
82
- // if (!table.IsEmpty())
83
- // {
84
- // tempMode = ICDMode::LIT;
85
- // break;
86
- // }
87
- // }
88
- // }
89
- mIcdMode = tempMode;
81
+ if (GetSlowPollingInterval () > GetSITPollingThreshold () && SupportsCheckInProtocol ())
82
+ {
83
+ VerifyOrDie (mStorage != nullptr );
84
+ VerifyOrDie (mFabricTable != nullptr );
85
+ // We can only get to LIT Mode, if at least one client is registered with the ICD device
86
+ for (const auto & fabricInfo : *mFabricTable )
87
+ {
88
+ // We only need 1 valid entry to ensure LIT compliance
89
+ IcdMonitoringTable table (*mStorage , fabricInfo.GetFabricIndex (), 1 /* Table entry limit*/ );
90
+ if (!table.IsEmpty ())
91
+ {
92
+ tempMode = ICDMode::LIT;
93
+ break ;
94
+ }
95
+ }
96
+ }
97
+ mICDMode = tempMode;
90
98
}
91
99
92
100
void ICDManager::UpdateOperationState (OperationalState state)
@@ -105,7 +113,17 @@ void ICDManager::UpdateOperationState(OperationalState state)
105
113
}
106
114
DeviceLayer::SystemLayer ().StartTimer (System::Clock::Timeout (idleModeInterval), OnIdleModeDone, this );
107
115
108
- CHIP_ERROR err = DeviceLayer::ConnectivityMgr ().SetPollingInterval (GetSlowPollingInterval ());
116
+ System::Clock::Milliseconds32 slowPollInterval = GetSlowPollingInterval ();
117
+ // When in SIT mode, the slow poll interval SHOULDN'T be greater than the SIT mode polling threshold, per spec.
118
+ if (mICDMode == ICDMode::SIT && slowPollInterval > GetSITPollingThreshold ())
119
+ {
120
+ ChipLogDetail (AppServer, " The Slow Polling Interval of an ICD in SIT mode should be <= %" PRIu32,
121
+ (GetSITPollingThreshold ().count () / 1000 ));
122
+ // TODO Spec to define this conformance as a SHALL
123
+ // slowPollInterval = GetSITPollingThreshold();
124
+ }
125
+
126
+ CHIP_ERROR err = DeviceLayer::ConnectivityMgr ().SetPollingInterval (slowPollInterval);
109
127
if (err != CHIP_NO_ERROR)
110
128
{
111
129
ChipLogError (AppServer, " Failed to set Polling Interval: err %" CHIP_ERROR_FORMAT, err.Format ());
0 commit comments