Skip to content

Commit 9559046

Browse files
committed
Update configuration manager implementation
Add reboot count, uptime, total operational hours keys Implement get/set reboot count functions Implement get/set reboot total operational hours Improve init function - add generic class initalization
1 parent 34f92ad commit 9559046

File tree

4 files changed

+66
-1
lines changed

4 files changed

+66
-1
lines changed

src/platform/mbed/ConfigurationManagerImpl.cpp

+50-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,56 @@ ConfigurationManagerImpl & ConfigurationManagerImpl::GetDefaultInstance()
5151

5252
CHIP_ERROR ConfigurationManagerImpl::Init()
5353
{
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);
55104
}
56105

57106
CHIP_ERROR ConfigurationManagerImpl::GetPrimaryWiFiMACAddress(uint8_t * buf)

src/platform/mbed/ConfigurationManagerImpl.h

+5
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImp
3939
// This returns an instance of this class.
4040
static ConfigurationManagerImpl & GetDefaultInstance();
4141

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+
4247
private:
4348
// ===== Members that implement the ConfigurationManager public interface.
4449

src/platform/mbed/MbedConfig.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ namespace Internal {
5555

5656
#define FACTORY_KEY(key) CHIP_CONFIG_KV_STORE_PARTITION CHIP_CONFIG_FACTORY_PREFIX key
5757
#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
5859

5960
const char MbedConfig::kConfigNamespace_ChipFactory[] = CHIP_CONFIG_KV_STORE_PARTITION CHIP_CONFIG_FACTORY_PREFIX;
6061
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("
8586
const MbedConfig::Key MbedConfig::kConfigKey_CountryCode = { CONFIG_KEY("country-code") };
8687
const MbedConfig::Key MbedConfig::kConfigKey_UniqueId = { CONFIG_KEY("unique-id") };
8788

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+
8894
CHIP_ERROR MbedConfig::ReadConfigValue(Key key, bool & val)
8995
{
9096
if (!ConfigValueExists(key))

src/platform/mbed/MbedConfig.h

+5
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ class MbedConfig
7373
static const Key kConfigKey_Spake2pSalt;
7474
static const Key kConfigKey_Spake2pVerifier;
7575

76+
// CHIP Counter keys
77+
static const Key kCounterKey_RebootCount;
78+
static const Key kCounterKey_UpTime;
79+
static const Key kCounterKey_TotalOperationalHours;
80+
7681
// Config value accessors.
7782
static CHIP_ERROR ReadConfigValue(Key key, bool & val);
7883
static CHIP_ERROR ReadConfigValue(Key key, uint32_t & val);

0 commit comments

Comments
 (0)