Skip to content

Commit

Permalink
[Ameba] Read General Diagnostic attributes from platform at runtime (#…
Browse files Browse the repository at this point in the history
…11476)

* [Ameba] Read General Diagnostic attributes from platform at runtime

* [Ameba] Read WiFi Network Diagnostics attributes from platform at runtime
  • Loading branch information
pankore authored and pull[bot] committed Nov 24, 2021
1 parent c5bd93d commit 1276783
Show file tree
Hide file tree
Showing 9 changed files with 384 additions and 100 deletions.
6 changes: 6 additions & 0 deletions src/platform/Ameba/AmebaConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ const AmebaConfig::Key AmebaConfig::kConfigKey_RegulatoryLocation = { k
const AmebaConfig::Key AmebaConfig::kConfigKey_CountryCode = { kConfigNamespace_ChipConfig, "country-code" };
const AmebaConfig::Key AmebaConfig::kConfigKey_Breadcrumb = { kConfigNamespace_ChipConfig, "breadcrumb" };

// Keys stored in the Chip-counters namespace
const AmebaConfig::Key AmebaConfig::kCounterKey_RebootCount = { kConfigNamespace_ChipCounters, "reboot-count" };
const AmebaConfig::Key AmebaConfig::kCounterKey_UpTime = { kConfigNamespace_ChipCounters, "up-time" };
const AmebaConfig::Key AmebaConfig::kCounterKey_TotalOperationalHours = { kConfigNamespace_ChipCounters, "total-hours" };
const AmebaConfig::Key AmebaConfig::kCounterKey_BootReason = { kConfigNamespace_ChipCounters, "boot-reason" };

CHIP_ERROR AmebaConfig::ReadConfigValue(Key key, bool & val)
{
uint32_t intVal;
Expand Down
4 changes: 4 additions & 0 deletions src/platform/Ameba/AmebaConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ class AmebaConfig
static const Key kConfigKey_RegulatoryLocation;
static const Key kConfigKey_CountryCode;
static const Key kConfigKey_Breadcrumb;
static const Key kCounterKey_RebootCount;
static const Key kCounterKey_UpTime;
static const Key kCounterKey_TotalOperationalHours;
static const Key kCounterKey_BootReason;

static const char kGroupKeyNamePrefix[];

Expand Down
58 changes: 58 additions & 0 deletions src/platform/Ameba/ConfigurationManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ ConfigurationManagerImpl ConfigurationManagerImpl::sInstance;
CHIP_ERROR ConfigurationManagerImpl::Init()
{
CHIP_ERROR err;
uint32_t rebootCount;
bool failSafeArmed;

// Force initialization of NVS namespaces if they doesn't already exist.
Expand All @@ -53,6 +54,33 @@ CHIP_ERROR ConfigurationManagerImpl::Init()
err = EnsureNamespace(kConfigNamespace_ChipCounters);
SuccessOrExit(err);

if (ConfigValueExists(kCounterKey_RebootCount))
{
err = GetRebootCount(rebootCount);
SuccessOrExit(err);

err = StoreRebootCount(rebootCount + 1);
SuccessOrExit(err);
}
else
{
// The first boot after factory reset of the Node.
err = StoreRebootCount(1);
SuccessOrExit(err);
}

if (!ConfigValueExists(kCounterKey_TotalOperationalHours))
{
err = StoreTotalOperationalHours(0);
SuccessOrExit(err);
}

if (!ConfigValueExists(kCounterKey_BootReason))
{
err = StoreBootReasons(EMBER_ZCL_BOOT_REASON_TYPE_UNSPECIFIED);
SuccessOrExit(err);
}

// Initialize the generic implementation base class.
err = Internal::GenericConfigurationManagerImpl<ConfigurationManagerImpl>::Init();
SuccessOrExit(err);
Expand All @@ -69,6 +97,36 @@ CHIP_ERROR ConfigurationManagerImpl::Init()
return err;
}

CHIP_ERROR ConfigurationManagerImpl::GetRebootCount(uint32_t & rebootCount)
{
return ReadConfigValue(kCounterKey_RebootCount, rebootCount);
}

CHIP_ERROR ConfigurationManagerImpl::StoreRebootCount(uint32_t rebootCount)
{
return WriteConfigValue(kCounterKey_RebootCount, rebootCount);
}

CHIP_ERROR ConfigurationManagerImpl::GetTotalOperationalHours(uint32_t & totalOperationalHours)
{
return ReadConfigValue(kCounterKey_TotalOperationalHours, totalOperationalHours);
}

CHIP_ERROR ConfigurationManagerImpl::StoreTotalOperationalHours(uint32_t totalOperationalHours)
{
return WriteConfigValue(kCounterKey_TotalOperationalHours, totalOperationalHours);
}

CHIP_ERROR ConfigurationManagerImpl::GetBootReasons(uint32_t & bootReasons)
{
return ReadConfigValue(kCounterKey_BootReason, bootReasons);
}

CHIP_ERROR ConfigurationManagerImpl::StoreBootReasons(uint32_t bootReasons)
{
return WriteConfigValue(kCounterKey_BootReason, bootReasons);
}

CHIP_ERROR ConfigurationManagerImpl::GetPrimaryWiFiMACAddress(uint8_t * buf)
{
char temp[32];
Expand Down
10 changes: 9 additions & 1 deletion src/platform/Ameba/ConfigurationManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,19 @@ namespace DeviceLayer {
class ConfigurationManagerImpl final : public Internal::GenericConfigurationManagerImpl<ConfigurationManagerImpl>,
private Internal::AmebaConfig
{
public:
CHIP_ERROR GetRebootCount(uint32_t & rebootCount);
CHIP_ERROR StoreRebootCount(uint32_t rebootCount);
CHIP_ERROR GetTotalOperationalHours(uint32_t & totalOperationalHours);
CHIP_ERROR StoreTotalOperationalHours(uint32_t totalOperationalHours);
CHIP_ERROR GetBootReasons(uint32_t & bootReasons);
CHIP_ERROR StoreBootReasons(uint32_t bootReasons);

private:
// Allow the ConfigurationManager interface class to delegate method calls to
// the implementation methods provided by this class.
friend class ConfigurationManager;

private:
// Allow the GenericConfigurationManagerImpl base class to access helper methods and types
// defined on this class.
#ifndef DOXYGEN_SHOULD_SKIP_THIS
Expand Down
Loading

0 comments on commit 1276783

Please sign in to comment.