Skip to content

Commit 7fb40ab

Browse files
committed
lock storage refactor
1 parent 78e5932 commit 7fb40ab

File tree

3 files changed

+368
-140
lines changed

3 files changed

+368
-140
lines changed

examples/lock-app/silabs/include/LockManager.h

+43-12
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@
2727
#include <cmsis_os2.h>
2828
#include <lib/core/CHIPError.h>
2929

30-
struct WeekDaysScheduleInfo
30+
#include <lib/support/DefaultStorageKeyAllocator.h>
31+
32+
struct WeekDayScheduleInfo
3133
{
3234
DlScheduleStatus status;
3335
EmberAfPluginDoorLockWeekDaySchedule schedule;
@@ -112,6 +114,30 @@ class ParamBuilder
112114
using namespace ::chip;
113115
using namespace EFR32DoorLock::ResourceRanges;
114116

117+
struct LockUserInfo
118+
{
119+
char userName[DOOR_LOCK_USER_NAME_BUFFER_SIZE];
120+
size_t userNameSize;
121+
uint32_t userUniqueId;
122+
UserStatusEnum userStatus;
123+
UserTypeEnum userType;
124+
CredentialRuleEnum credentialRule;
125+
chip::EndpointId endpointId;
126+
chip::FabricIndex createdBy;
127+
chip::FabricIndex lastModifiedBy;
128+
uint16_t currentCredentialCount;
129+
};
130+
131+
struct LockCredentialInfo
132+
{
133+
DlCredentialStatus status;
134+
CredentialTypeEnum credentialType;
135+
chip::FabricIndex createdBy;
136+
chip::FabricIndex lastModifiedBy;
137+
uint8_t credentialData[kMaxCredentialSize];
138+
size_t credentialDataSize;
139+
};
140+
115141
class LockManager
116142
{
117143
public:
@@ -192,8 +218,6 @@ class LockManager
192218
OperationErrorEnum & err);
193219
const char * lockStateToString(DlLockState lockState) const;
194220

195-
bool ReadConfigValues();
196-
197221
void UnlockAfterUnlatch();
198222

199223
private:
@@ -244,17 +268,24 @@ class LockManager
244268
static void ActuatorMovementTimerEventHandler(AppEvent * aEvent);
245269

246270
osTimerId_t mLockTimer;
247-
EmberAfPluginDoorLockUserInfo mLockUsers[kMaxUsers];
248-
EmberAfPluginDoorLockCredentialInfo mLockCredentials[kNumCredentialTypes][kMaxCredentials];
249-
WeekDaysScheduleInfo mWeekdaySchedule[kMaxUsers][kMaxWeekdaySchedulesPerUser];
250-
YearDayScheduleInfo mYeardaySchedule[kMaxUsers][kMaxYeardaySchedulesPerUser];
251-
HolidayScheduleInfo mHolidaySchedule[kMaxHolidaySchedules];
252-
253-
char mUserNames[MATTER_ARRAY_SIZE(mLockUsers)][DOOR_LOCK_MAX_USER_NAME_SIZE];
254-
uint8_t mCredentialData[kNumCredentialTypes][kMaxCredentials][kMaxCredentialSize];
255-
CredentialStruct mCredentials[kMaxUsers][kMaxCredentials];
256271

257272
EFR32DoorLock::LockInitParams::LockParam LockParams;
273+
274+
static StorageKeyName LockUserEndpoint(uint16_t userIndex, chip::EndpointId endpoint) { return StorageKeyName::Formatted("g/lu/%x/e/%x", userIndex, endpoint); }
275+
static StorageKeyName LockCredentialEndpoint(uint16_t credentialIndex, chip::EndpointId endpoint) { return StorageKeyName::Formatted("g/lc/%x/e/%x", credentialIndex, endpoint); }
276+
static StorageKeyName LockUserCredentialMap(uint16_t userIndex) { return StorageKeyName::Formatted("g/lu/%x/lc", userIndex); } // Stores all the credential indices that belong to a user
277+
static StorageKeyName LockUserWeekDayScheduleEndpoint(uint16_t userIndex, uint16_t scheduleIndex, chip::EndpointId endpoint) { return StorageKeyName::Formatted("g/lu/%x/lw/%x/e/%x", userIndex, scheduleIndex, endpoint); }
278+
static StorageKeyName LockUserYearDayScheduleEndpoint(uint16_t userIndex, uint16_t scheduleIndex, chip::EndpointId endpoint) { return StorageKeyName::Formatted("g/lu/%x/ly/%x/e/%x", userIndex, scheduleIndex, endpoint); }
279+
static StorageKeyName LockHolidayScheduleEndpoint(uint16_t scheduleIndex, chip::EndpointId endpoint) { return StorageKeyName::Formatted("g/lh/%x/e/%x", scheduleIndex, endpoint); }
280+
281+
LockUserInfo userInStorage;
282+
LockCredentialInfo credentialInStorage;
283+
WeekDayScheduleInfo weekDayScheduleInStorage;
284+
YearDayScheduleInfo yearDayScheduleInStorage;
285+
HolidayScheduleInfo holidayScheduleInStorage;
286+
CredentialStruct mCredential;
287+
CredentialStruct mCredentials[kMaxCredentialsPerUser];
288+
258289
};
259290

260291
LockManager & LockMgr();

examples/lock-app/silabs/src/AppTask.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@
3737
#include <app-common/zap-generated/cluster-objects.h>
3838

3939
#include <app/clusters/door-lock-server/door-lock-server.h>
40+
#include <setup_payload/OnboardingCodesUtil.h>
4041
#include <app/server/Server.h>
4142
#include <app/util/attribute-storage.h>
42-
#include <setup_payload/OnboardingCodesUtil.h>
4343

4444
#include <assert.h>
4545

@@ -266,8 +266,6 @@ void AppTask::AppTaskMain(void * pvParameter)
266266

267267
SILABS_LOG("App Task started");
268268

269-
// Users and credentials should be checked once from nvm flash on boot
270-
LockMgr().ReadConfigValues();
271269

272270
while (true)
273271
{
@@ -412,3 +410,4 @@ void AppTask::UpdateClusterState(intptr_t context)
412410
SILABS_LOG("ERR: updating lock state %x", to_underlying(status));
413411
}
414412
}
413+

0 commit comments

Comments
 (0)