Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v1.3][ESP32] Support total operational hours (#35425) #35501

Merged
merged 2 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 34 additions & 6 deletions src/platform/ESP32/ConfigurationManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,26 @@ namespace DeviceLayer {

using namespace ::chip::DeviceLayer::Internal;

// TODO: Define a Singleton instance of CHIP Group Key Store here (#1266)

ConfigurationManagerImpl & ConfigurationManagerImpl::GetDefaultInstance()
{
static ConfigurationManagerImpl sInstance;
return sInstance;
}

uint32_t ConfigurationManagerImpl::mTotalOperationalHours = 0;

void ConfigurationManagerImpl::TotalOperationalHoursTimerCallback(TimerHandle_t timer)
{
mTotalOperationalHours++;

CHIP_ERROR err = ConfigurationMgrImpl().StoreTotalOperationalHours(mTotalOperationalHours);

if (err != CHIP_NO_ERROR)
{
ChipLogError(DeviceLayer, "Failed to store total operational hours: %" CHIP_ERROR_FORMAT, err.Format());
}
}

CHIP_ERROR ConfigurationManagerImpl::Init()
{
CHIP_ERROR err;
Expand Down Expand Up @@ -161,18 +173,34 @@ CHIP_ERROR ConfigurationManagerImpl::Init()
SuccessOrExit(err);
}

if (!ESP32Config::ConfigValueExists(ESP32Config::kCounterKey_TotalOperationalHours))
if (CHIP_NO_ERROR != GetTotalOperationalHours(mTotalOperationalHours))
{
err = StoreTotalOperationalHours(0);
err = StoreTotalOperationalHours(mTotalOperationalHours);
SuccessOrExit(err);
}

{
// Start a timer which reloads every one hour and bumps the total operational hours
TickType_t reloadPeriod = (1000 * 60 * 60) / portTICK_PERIOD_MS;
dhrishi marked this conversation as resolved.
Show resolved Hide resolved
TimerHandle_t timerHandle = xTimerCreate("tOpHrs", reloadPeriod, pdPASS, nullptr, TotalOperationalHoursTimerCallback);
if (timerHandle == nullptr)
{
err = CHIP_ERROR_NO_MEMORY;
ExitNow(ChipLogError(DeviceLayer, "total operational hours Timer creation failed"));
}

BaseType_t timerStartStatus = xTimerStart(timerHandle, 0);
if (timerStartStatus == pdFAIL)
{
err = CHIP_ERROR_INTERNAL;
ExitNow(ChipLogError(DeviceLayer, "total operational hours Timer start failed"));
}
}

// Initialize the generic implementation base class.
err = Internal::GenericConfigurationManagerImpl<ESP32Config>::Init();
SuccessOrExit(err);

// TODO: Initialize the global GroupKeyStore object here (#1266)

err = CHIP_NO_ERROR;

exit:
Expand Down
6 changes: 6 additions & 0 deletions src/platform/ESP32/ConfigurationManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@

#include <platform/ESP32/ESP32Config.h>

#include <freertos/FreeRTOS.h>
#include <freertos/timers.h>

namespace chip {
namespace DeviceLayer {

Expand Down Expand Up @@ -96,6 +99,9 @@ class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImp
// ===== Private members reserved for use by this class only.

static void DoFactoryReset(intptr_t arg);

static uint32_t mTotalOperationalHours;
static void TotalOperationalHoursTimerCallback(TimerHandle_t timer);
};

/**
Expand Down
1 change: 1 addition & 0 deletions src/test_driver/esp32/sdkconfig.defaults
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ CONFIG_ESP_MAIN_TASK_STACK_SIZE=32768

#enable BT
CONFIG_BT_ENABLED=y
CONFIG_BT_NIMBLE_ENABLED=y
dhrishi marked this conversation as resolved.
Show resolved Hide resolved

#enable HKDF in mbedtls
CONFIG_MBEDTLS_HKDF_C=y
Expand Down
Loading