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

[Ameba] Restructure PersistentStorage #17047

Merged
merged 3 commits into from
Apr 20, 2022
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
8 changes: 4 additions & 4 deletions examples/all-clusters-app/ameba/main/chipinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,6 @@ static void InitOTARequestor(void)

static void InitServer(intptr_t context)
{
#if CONFIG_ENABLE_OTA_REQUESTOR
InitOTARequestor();
#endif

// Init ZCL Data Model and CHIP App Server
static chip::CommonCaseDeviceServerInitParams initParams;
initParams.InitializeStaticResourcesBeforeServerInit();
Expand All @@ -164,6 +160,10 @@ static void InitServer(intptr_t context)
SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider());
NetWorkCommissioningInstInit();

#if CONFIG_ENABLE_OTA_REQUESTOR
InitOTARequestor();
#endif

if (RTW_SUCCESS != wifi_is_connected_to_ap())
{
// QR code will be used with CHIP Tool
Expand Down
8 changes: 4 additions & 4 deletions examples/lighting-app/ameba/main/chipinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,6 @@ static Identify gIdentify1 = {

static void InitServer(intptr_t context)
{
#if CONFIG_ENABLE_OTA_REQUESTOR
InitOTARequestor();
#endif

// Init ZCL Data Model and CHIP App Server
static chip::CommonCaseDeviceServerInitParams initParams;
(void) initParams.InitializeStaticResourcesBeforeServerInit();
Expand All @@ -185,6 +181,10 @@ static void InitServer(intptr_t context)
SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider());
NetWorkCommissioningInstInit();

#if CONFIG_ENABLE_OTA_REQUESTOR
InitOTARequestor();
#endif

if (RTW_SUCCESS != wifi_is_connected_to_ap())
{
// QR code will be used with CHIP Tool
Expand Down
4 changes: 2 additions & 2 deletions examples/ota-requestor-app/ameba/main/chipinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,6 @@ static void InitOTARequestor(void)

static void InitServer(intptr_t context)
{
InitOTARequestor();

// Init ZCL Data Model and CHIP App Server
static chip::CommonCaseDeviceServerInitParams initParams;
(void) initParams.InitializeStaticResourcesBeforeServerInit();
Expand All @@ -144,6 +142,8 @@ static void InitServer(intptr_t context)
// Initialize device attestation config
SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider());
NetWorkCommissioningInstInit();

InitOTARequestor();
}

extern "C" void ChipTest(void)
Expand Down
31 changes: 28 additions & 3 deletions src/platform/Ameba/AmebaConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,21 @@ namespace Internal {
// *** CAUTION ***: Changing the names or namespaces of these values will *break* existing devices.

// NVS namespaces used to store device configuration information.
const char AmebaConfig::kConfigNamespace_ChipFactory[] = "chip-factory";
const char AmebaConfig::kConfigNamespace_ChipConfig[] = "chip-config";
const char AmebaConfig::kConfigNamespace_ChipCounters[] = "chip-counters";
const char AmebaConfig::kConfigNamespace_ChipFactory[] = "chip-factory";
const char AmebaConfig::kConfigNamespace_ChipConfig[] = "chip-config";
const char AmebaConfig::kConfigNamespace_ChipCounters[] = "chip-counters";
const char AmebaConfig::kConfigNamespace_ChipFabric1[] = "chip-fabric-1";
const char AmebaConfig::kConfigNamespace_ChipFabric2[] = "chip-fabric-2";
const char AmebaConfig::kConfigNamespace_ChipFabric3[] = "chip-fabric-3";
const char AmebaConfig::kConfigNamespace_ChipFabric4[] = "chip-fabric-4";
const char AmebaConfig::kConfigNamespace_ChipFabric5[] = "chip-fabric-5";
const char AmebaConfig::kConfigNamespace_ChipACL[] = "chip-acl";
const char AmebaConfig::kConfigNamespace_ChipGroupMsgCounters[] = "chip-groupmsgcounters";
const char AmebaConfig::kConfigNamespace_ChipAttributes[] = "chip-attributes";
const char AmebaConfig::kConfigNamespace_ChipBindingTable[] = "chip-bindingtable";
const char AmebaConfig::kConfigNamespace_ChipOTA[] = "chip-ota";
const char AmebaConfig::kConfigNamespace_ChipDNS[] = "chip-dns";
const char AmebaConfig::kConfigNamespace_ChipOthers[] = "chip-others";

// Keys stored in the chip-factory namespace
const AmebaConfig::Key AmebaConfig::kConfigKey_SerialNum = { kConfigNamespace_ChipFactory, "serial-num" };
Expand Down Expand Up @@ -271,6 +283,19 @@ CHIP_ERROR AmebaConfig::EnsureNamespace(const char * ns)
return CHIP_NO_ERROR;
}

CHIP_ERROR AmebaConfig::EnsureNamespace2(const char * ns)
{
int32_t success = -1;

success = registerPref2(ns);
if (success != 0)
{
ChipLogError(DeviceLayer, "dct_register_module2 failed\n");
}

return CHIP_NO_ERROR;
}

CHIP_ERROR AmebaConfig::ClearNamespace(const char * ns)
{
int32_t success = -1;
Expand Down
13 changes: 13 additions & 0 deletions src/platform/Ameba/AmebaConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,18 @@ class AmebaConfig
static const char kConfigNamespace_ChipFactory[];
static const char kConfigNamespace_ChipConfig[];
static const char kConfigNamespace_ChipCounters[];
static const char kConfigNamespace_ChipFabric1[];
static const char kConfigNamespace_ChipFabric2[];
static const char kConfigNamespace_ChipFabric3[];
static const char kConfigNamespace_ChipFabric4[];
static const char kConfigNamespace_ChipFabric5[];
static const char kConfigNamespace_ChipACL[];
static const char kConfigNamespace_ChipGroupMsgCounters[];
static const char kConfigNamespace_ChipAttributes[];
static const char kConfigNamespace_ChipBindingTable[];
static const char kConfigNamespace_ChipOTA[];
static const char kConfigNamespace_ChipDNS[];
static const char kConfigNamespace_ChipOthers[];

// Key definitions for well-known keys.
static const Key kConfigKey_SerialNum;
Expand Down Expand Up @@ -96,6 +108,7 @@ class AmebaConfig
static bool ConfigValueExists(Key key);

static CHIP_ERROR EnsureNamespace(const char * ns);
static CHIP_ERROR EnsureNamespace2(const char * ns);
static CHIP_ERROR ClearNamespace(const char * ns);

static void RunConfigUnitTest(void);
Expand Down
24 changes: 24 additions & 0 deletions src/platform/Ameba/ConfigurationManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,30 @@ CHIP_ERROR ConfigurationManagerImpl::Init()
SuccessOrExit(err);
err = AmebaConfig::EnsureNamespace(AmebaConfig::kConfigNamespace_ChipCounters);
SuccessOrExit(err);
err = AmebaConfig::EnsureNamespace2(AmebaConfig::kConfigNamespace_ChipFabric1);
SuccessOrExit(err);
err = AmebaConfig::EnsureNamespace2(AmebaConfig::kConfigNamespace_ChipFabric2);
SuccessOrExit(err);
err = AmebaConfig::EnsureNamespace2(AmebaConfig::kConfigNamespace_ChipFabric3);
SuccessOrExit(err);
err = AmebaConfig::EnsureNamespace2(AmebaConfig::kConfigNamespace_ChipFabric4);
SuccessOrExit(err);
err = AmebaConfig::EnsureNamespace2(AmebaConfig::kConfigNamespace_ChipFabric5);
SuccessOrExit(err);
err = AmebaConfig::EnsureNamespace(AmebaConfig::kConfigNamespace_ChipACL);
SuccessOrExit(err);
err = AmebaConfig::EnsureNamespace(AmebaConfig::kConfigNamespace_ChipGroupMsgCounters);
SuccessOrExit(err);
err = AmebaConfig::EnsureNamespace(AmebaConfig::kConfigNamespace_ChipAttributes);
SuccessOrExit(err);
err = AmebaConfig::EnsureNamespace(AmebaConfig::kConfigNamespace_ChipBindingTable);
SuccessOrExit(err);
err = AmebaConfig::EnsureNamespace(AmebaConfig::kConfigNamespace_ChipOTA);
SuccessOrExit(err);
err = AmebaConfig::EnsureNamespace(AmebaConfig::kConfigNamespace_ChipDNS);
SuccessOrExit(err);
err = AmebaConfig::EnsureNamespace(AmebaConfig::kConfigNamespace_ChipOthers);
SuccessOrExit(err);

if (AmebaConfig::ConfigValueExists(AmebaConfig::kCounterKey_RebootCount))
{
Expand Down
4 changes: 2 additions & 2 deletions src/platform/Ameba/NetworkCommissioningWiFiDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ CHIP_ERROR AmebaWiFiDriver::Init(NetworkStatusChangeCallback *)

err = PersistedStorage::KeyValueStoreMgr().Get(kWiFiCredentialsKeyName, mSavedNetwork.credentials,
sizeof(mSavedNetwork.credentials), &credentialsLen);
if (err == CHIP_ERROR_NOT_FOUND)
if (err == CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND)
{
return CHIP_NO_ERROR;
}

err = PersistedStorage::KeyValueStoreMgr().Get(kWiFiSSIDKeyName, mSavedNetwork.ssid, sizeof(mSavedNetwork.ssid), &ssidLen);
if (err == CHIP_ERROR_NOT_FOUND)
if (err == CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND)
{
return CHIP_NO_ERROR;
}
Expand Down