@@ -45,14 +45,26 @@ namespace DeviceLayer {
45
45
46
46
using namespace ::chip::DeviceLayer::Internal;
47
47
48
- // TODO: Define a Singleton instance of CHIP Group Key Store here (#1266)
49
-
50
48
ConfigurationManagerImpl & ConfigurationManagerImpl::GetDefaultInstance ()
51
49
{
52
50
static ConfigurationManagerImpl sInstance ;
53
51
return sInstance ;
54
52
}
55
53
54
+ uint32_t ConfigurationManagerImpl::mTotalOperationalHours = 0 ;
55
+
56
+ void ConfigurationManagerImpl::TotalOperationalHoursTimerCallback (TimerHandle_t timer)
57
+ {
58
+ mTotalOperationalHours ++;
59
+
60
+ CHIP_ERROR err = ConfigurationMgrImpl ().StoreTotalOperationalHours (mTotalOperationalHours );
61
+
62
+ if (err != CHIP_NO_ERROR)
63
+ {
64
+ ChipLogError (DeviceLayer, " Failed to store total operational hours: %" CHIP_ERROR_FORMAT, err.Format ());
65
+ }
66
+ }
67
+
56
68
CHIP_ERROR ConfigurationManagerImpl::Init ()
57
69
{
58
70
CHIP_ERROR err;
@@ -161,18 +173,34 @@ CHIP_ERROR ConfigurationManagerImpl::Init()
161
173
SuccessOrExit (err);
162
174
}
163
175
164
- if (! ESP32Config::ConfigValueExists (ESP32Config:: kCounterKey_TotalOperationalHours ))
176
+ if (CHIP_NO_ERROR != GetTotalOperationalHours ( mTotalOperationalHours ))
165
177
{
166
- err = StoreTotalOperationalHours (0 );
178
+ err = StoreTotalOperationalHours (mTotalOperationalHours );
167
179
SuccessOrExit (err);
168
180
}
169
181
182
+ {
183
+ // Start a timer which reloads every one hour and bumps the total operational hours
184
+ TickType_t reloadPeriod = (1000 * 60 * 60 ) / portTICK_PERIOD_MS;
185
+ TimerHandle_t timerHandle = xTimerCreate (" tOpHrs" , reloadPeriod, pdPASS, nullptr , TotalOperationalHoursTimerCallback);
186
+ if (timerHandle == nullptr )
187
+ {
188
+ err = CHIP_ERROR_NO_MEMORY;
189
+ ExitNow (ChipLogError (DeviceLayer, " total operational hours Timer creation failed" ));
190
+ }
191
+
192
+ BaseType_t timerStartStatus = xTimerStart (timerHandle, 0 );
193
+ if (timerStartStatus == pdFAIL)
194
+ {
195
+ err = CHIP_ERROR_INTERNAL;
196
+ ExitNow (ChipLogError (DeviceLayer, " total operational hours Timer start failed" ));
197
+ }
198
+ }
199
+
170
200
// Initialize the generic implementation base class.
171
201
err = Internal::GenericConfigurationManagerImpl<ESP32Config>::Init ();
172
202
SuccessOrExit (err);
173
203
174
- // TODO: Initialize the global GroupKeyStore object here (#1266)
175
-
176
204
err = CHIP_NO_ERROR;
177
205
178
206
exit :
0 commit comments