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

Restyle [EFR32] working schedules with nvm storage, nvm credentials fix, add comments #20045

Closed
wants to merge 3 commits into from
Closed
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
50 changes: 43 additions & 7 deletions examples/lock-app/efr32/include/LockManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,26 @@

using namespace ::chip;

// Currently up to 10 users are support on the EFR32 platform
// up to 10 users are supported on the EFR32 platform
#define DOOR_LOCK_MAX_USERS 10
// max credential size supported is 8
#define DOOR_LOCK_MAX_CREDENTIAL_SIZE 8
#define MININUM_USER_INDEX 1
#define MINIMUM_CREDENTIAL_INDEX 1
// up to 10 schedules of each type supported
#define DOOR_LOCK_MAX_SCHEDULES 10

// up to 10 credentials are supported per user
#define MAX_CREDENTIAL_PER_USER 10
#define MAX_CREDENTIALS 50

static constexpr size_t DOOR_LOCK_CREDENTIAL_INFO_MAX_DATA_SIZE = 20;
// up to 10 schedules are supported per user
#define MAX_SCHEDULE_PER_USER 10

// user, credential and schedule indices are 1-indexed
#define MIN_USER_INDEX 1
#define MIN_CREDENTIAL_INDEX 1
#define MIN_SCHEDULE_INDEX 1

// 10 users with 10 credentials each max
#define MAX_CREDENTIALS 100

class LockManager
{
Expand All @@ -61,7 +72,9 @@ class LockManager
} State;

CHIP_ERROR Init(chip::app::DataModel::Nullable<chip::app::Clusters::DoorLock::DlLockState> state,
uint8_t maxNumberOfCredentialsPerUser, uint16_t numberOfSupportedUsers);
uint8_t maxNumberOfCredentialsPerUser, uint16_t numberOfSupportedUsers,
uint8_t numberOfWeekdaySchedulesPerUserSupported, uint8_t numberOfYeardaySchedulesPerUserSupported,
uint8_t numberOfHolidaySchedulesPerUserSupported);
bool NextState();
bool IsActionInProgress();
bool InitiateAction(int32_t aActor, Action_t aAction);
Expand All @@ -84,6 +97,23 @@ class LockManager
bool SetCredential(chip::EndpointId endpointId, uint16_t credentialIndex, chip::FabricIndex creator, chip::FabricIndex modifier,
DlCredentialStatus credentialStatus, DlCredentialType credentialType, const chip::ByteSpan & credentialData);

DlStatus GetWeekdaySchedule(chip::EndpointId endpointId, uint8_t weekdayIndex, uint16_t userIndex,
EmberAfPluginDoorLockWeekDaySchedule & schedule);

DlStatus SetWeekdaySchedule(chip::EndpointId endpointId, uint8_t weekdayIndex, uint16_t userIndex, DlScheduleStatus status,
DlDaysMaskMap daysMask, uint8_t startHour, uint8_t startMinute, uint8_t endHour, uint8_t endMinute);

DlStatus GetYeardaySchedule(chip::EndpointId endpointId, uint8_t yearDayIndex, uint16_t userIndex,
EmberAfPluginDoorLockYearDaySchedule & schedule);

DlStatus SetYeardaySchedule(chip::EndpointId endpointId, uint8_t yearDayIndex, uint16_t userIndex, DlScheduleStatus status,
uint32_t localStartTime, uint32_t localEndTime);

DlStatus GetHolidaySchedule(chip::EndpointId endpointId, uint8_t holidayIndex, EmberAfPluginDoorLockHolidaySchedule & schedule);

DlStatus SetHolidaySchedule(chip::EndpointId endpointId, uint8_t holidayIndex, DlScheduleStatus status, uint32_t localStartTime,
uint32_t localEndTime, DlOperatingMode operatingMode);

bool setLockState(chip::EndpointId endpointId, DlLockState lockState, const Optional<chip::ByteSpan> & pin,
DlOperationError & err);
const char * lockStateToString(DlLockState lockState) const;
Expand All @@ -107,13 +137,19 @@ class LockManager

EmberAfPluginDoorLockUserInfo mLockUsers[DOOR_LOCK_MAX_USERS];
EmberAfPluginDoorLockCredentialInfo mLockCredentials[MAX_CREDENTIALS];
EmberAfPluginDoorLockWeekDaySchedule mWeekdaySchedule[DOOR_LOCK_MAX_USERS][DOOR_LOCK_MAX_SCHEDULES];
EmberAfPluginDoorLockYearDaySchedule mYeardaySchedule[DOOR_LOCK_MAX_USERS][DOOR_LOCK_MAX_SCHEDULES];
EmberAfPluginDoorLockHolidaySchedule mHolidaySchedule[DOOR_LOCK_MAX_SCHEDULES];

uint8_t mMaxCredentialsPerUser;
uint16_t mMaxUsers;
uint8_t mNumberOfWeekdaySchedulesPerUserSupported;
uint8_t mNumberOfYeardaySchedulesPerUserSupported;
uint8_t mNumberOfHolidaySchedulesSupported;

char mUserNames[ArraySize(mLockUsers)][DOOR_LOCK_MAX_USER_NAME_SIZE];
uint8_t mCredentialData[MAX_CREDENTIALS][DOOR_LOCK_MAX_CREDENTIAL_SIZE];
chip::Platform::ScopedMemoryBuffer<DlCredential> mCredentials[MAX_CREDENTIAL_PER_USER];
DlCredential mCredentials[DOOR_LOCK_MAX_USERS][MAX_CREDENTIAL_PER_USER];

static LockManager sLock;
};
Expand Down
36 changes: 35 additions & 1 deletion examples/lock-app/efr32/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,43 @@ CHIP_ERROR AppTask::Init()
endpointId);
numberOfSupportedUsers = 10;
}

uint8_t numberOfWeekdaySchedulesPerUserSupported = 0;
if (!DoorLockServer::Instance().GetNumberOfWeekDaySchedulesPerUserSupported(endpointId,
numberOfWeekdaySchedulesPerUserSupported))
{
ChipLogError(
Zcl,
"Unable to get number of supported weekday schedules when initializing lock endpoint, defaulting to 10 [endpointId=%d]",
endpointId);
numberOfWeekdaySchedulesPerUserSupported = 10;
}

uint8_t numberOfYeardaySchedulesPerUserSupported = 0;
if (!DoorLockServer::Instance().GetNumberOfYearDaySchedulesPerUserSupported(endpointId,
numberOfYeardaySchedulesPerUserSupported))
{
ChipLogError(
Zcl,
"Unable to get number of supported yearday schedules when initializing lock endpoint, defaulting to 10 [endpointId=%d]",
endpointId);
numberOfYeardaySchedulesPerUserSupported = 10;
}

uint8_t numberOfHolidaySchedulesSupported = 0;
if (!DoorLockServer::Instance().GetNumberOfHolidaySchedulesSupported(endpointId, numberOfHolidaySchedulesSupported))
{
ChipLogError(
Zcl,
"Unable to get number of supported holiday schedules when initializing lock endpoint, defaulting to 10 [endpointId=%d]",
endpointId);
numberOfHolidaySchedulesSupported = 10;
}

chip::DeviceLayer::PlatformMgr().UnlockChipStack();

err = LockMgr().Init(state, maxCredentialsPerUser, numberOfSupportedUsers);
err = LockMgr().Init(state, maxCredentialsPerUser, numberOfSupportedUsers, numberOfWeekdaySchedulesPerUserSupported,
numberOfYeardaySchedulesPerUserSupported, numberOfHolidaySchedulesSupported);
if (err != CHIP_NO_ERROR)
{
EFR32_LOG("LockMgr().Init() failed");
Expand Down
Loading