File tree 4 files changed +66
-1
lines changed
4 files changed +66
-1
lines changed Original file line number Diff line number Diff line change @@ -51,7 +51,56 @@ ConfigurationManagerImpl & ConfigurationManagerImpl::GetDefaultInstance()
51
51
52
52
CHIP_ERROR ConfigurationManagerImpl::Init ()
53
53
{
54
- return CHIP_NO_ERROR;
54
+ CHIP_ERROR err;
55
+ uint32_t rebootCount;
56
+
57
+ if (MbedConfig::ConfigValueExists (MbedConfig::kCounterKey_RebootCount ))
58
+ {
59
+ err = GetRebootCount (rebootCount);
60
+ SuccessOrExit (err);
61
+
62
+ err = StoreRebootCount (rebootCount + 1 );
63
+ SuccessOrExit (err);
64
+ }
65
+ else
66
+ {
67
+ // The first boot after factory reset of the Node.
68
+ err = StoreRebootCount (1 );
69
+ SuccessOrExit (err);
70
+ }
71
+
72
+ if (!MbedConfig::ConfigValueExists (MbedConfig::kCounterKey_TotalOperationalHours ))
73
+ {
74
+ err = StoreTotalOperationalHours (0 );
75
+ SuccessOrExit (err);
76
+ }
77
+
78
+ // Initialize the generic implementation base class.
79
+ err = Internal::GenericConfigurationManagerImpl<MbedConfig>::Init ();
80
+ SuccessOrExit (err);
81
+
82
+ exit :
83
+ return err;
84
+ }
85
+
86
+ CHIP_ERROR ConfigurationManagerImpl::GetRebootCount (uint32_t & rebootCount)
87
+ {
88
+ return ReadConfigValue (MbedConfig::kCounterKey_RebootCount , rebootCount);
89
+ }
90
+
91
+ CHIP_ERROR ConfigurationManagerImpl::StoreRebootCount (uint32_t rebootCount)
92
+ {
93
+ return WriteConfigValue (MbedConfig::kCounterKey_RebootCount , rebootCount);
94
+ }
95
+
96
+ CHIP_ERROR ConfigurationManagerImpl::GetTotalOperationalHours (uint32_t & totalOperationalHours)
97
+ {
98
+ return ReadConfigValue (MbedConfig::kCounterKey_TotalOperationalHours , totalOperationalHours);
99
+ }
100
+
101
+ CHIP_ERROR ConfigurationManagerImpl::StoreTotalOperationalHours (uint32_t totalOperationalHours)
102
+ {
103
+ return WriteConfigValue (MbedConfig::kCounterKey_TotalOperationalHours , totalOperationalHours);
55
104
}
56
105
57
106
CHIP_ERROR ConfigurationManagerImpl::GetPrimaryWiFiMACAddress (uint8_t * buf)
Original file line number Diff line number Diff line change @@ -39,6 +39,11 @@ class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImp
39
39
// This returns an instance of this class.
40
40
static ConfigurationManagerImpl & GetDefaultInstance ();
41
41
42
+ CHIP_ERROR GetRebootCount (uint32_t & rebootCount) override ;
43
+ CHIP_ERROR StoreRebootCount (uint32_t rebootCount) override ;
44
+ CHIP_ERROR GetTotalOperationalHours (uint32_t & totalOperationalHours) override ;
45
+ CHIP_ERROR StoreTotalOperationalHours (uint32_t totalOperationalHours) override ;
46
+
42
47
private:
43
48
// ===== Members that implement the ConfigurationManager public interface.
44
49
Original file line number Diff line number Diff line change @@ -55,6 +55,7 @@ namespace Internal {
55
55
56
56
#define FACTORY_KEY (key ) CHIP_CONFIG_KV_STORE_PARTITION CHIP_CONFIG_FACTORY_PREFIX key
57
57
#define CONFIG_KEY (key ) CHIP_CONFIG_KV_STORE_PARTITION CHIP_CONFIG_CONFIG_PREFIX key
58
+ #define COUNTER_KEY (key ) CHIP_CONFIG_KV_STORE_PARTITION CHIP_CONFIG_COUNTER_PREFIX key
58
59
59
60
const char MbedConfig::kConfigNamespace_ChipFactory [] = CHIP_CONFIG_KV_STORE_PARTITION CHIP_CONFIG_FACTORY_PREFIX;
60
61
const char MbedConfig::kConfigNamespace_ChipConfig [] = CHIP_CONFIG_KV_STORE_PARTITION CHIP_CONFIG_CONFIG_PREFIX;
@@ -85,6 +86,11 @@ const MbedConfig::Key MbedConfig::kConfigKey_RegulatoryLocation = { CONFIG_KEY("
85
86
const MbedConfig::Key MbedConfig::kConfigKey_CountryCode = { CONFIG_KEY (" country-code" ) };
86
87
const MbedConfig::Key MbedConfig::kConfigKey_UniqueId = { CONFIG_KEY (" unique-id" ) };
87
88
89
+ // Keys stored in the Chip-counters namespace
90
+ const MbedConfig::Key MbedConfig::kCounterKey_RebootCount = { COUNTER_KEY (" reboot-count" ) };
91
+ const MbedConfig::Key MbedConfig::kCounterKey_UpTime = { COUNTER_KEY (" up-time" ) };
92
+ const MbedConfig::Key MbedConfig::kCounterKey_TotalOperationalHours = { COUNTER_KEY (" total-hours" ) };
93
+
88
94
CHIP_ERROR MbedConfig::ReadConfigValue (Key key, bool & val)
89
95
{
90
96
if (!ConfigValueExists (key))
Original file line number Diff line number Diff line change @@ -73,6 +73,11 @@ class MbedConfig
73
73
static const Key kConfigKey_Spake2pSalt ;
74
74
static const Key kConfigKey_Spake2pVerifier ;
75
75
76
+ // CHIP Counter keys
77
+ static const Key kCounterKey_RebootCount ;
78
+ static const Key kCounterKey_UpTime ;
79
+ static const Key kCounterKey_TotalOperationalHours ;
80
+
76
81
// Config value accessors.
77
82
static CHIP_ERROR ReadConfigValue (Key key, bool & val);
78
83
static CHIP_ERROR ReadConfigValue (Key key, uint32_t & val);
You can’t perform that action at this time.
0 commit comments