From 45c3fb2455458d1012c0f158f356c564ccd9ba2a Mon Sep 17 00:00:00 2001 From: Michael Rupp <95718139+mykrupp@users.noreply.github.com> Date: Fri, 24 Jun 2022 15:56:21 -0400 Subject: [PATCH 1/5] working schedules with nvm storage, nvm credentials fix, add comments --- examples/lock-app/efr32/include/LockManager.h | 48 +++- examples/lock-app/efr32/src/AppTask.cpp | 31 ++- examples/lock-app/efr32/src/LockManager.cpp | 260 ++++++++++++++++-- examples/lock-app/efr32/src/ZclCallbacks.cpp | 24 +- src/platform/EFR32/EFR32Config.h | 4 + 5 files changed, 322 insertions(+), 45 deletions(-) diff --git a/examples/lock-app/efr32/include/LockManager.h b/examples/lock-app/efr32/include/LockManager.h index a97d7f4bb3b8bf..28af6776d5c03f 100644 --- a/examples/lock-app/efr32/include/LockManager.h +++ b/examples/lock-app/efr32/include/LockManager.h @@ -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 { @@ -61,7 +72,8 @@ class LockManager } State; CHIP_ERROR Init(chip::app::DataModel::Nullable 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); @@ -84,6 +96,22 @@ 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 & pin, DlOperationError & err); const char * lockStateToString(DlLockState lockState) const; @@ -107,13 +135,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 mCredentials[MAX_CREDENTIAL_PER_USER]; + DlCredential mCredentials[DOOR_LOCK_MAX_USERS][MAX_CREDENTIAL_PER_USER]; static LockManager sLock; }; diff --git a/examples/lock-app/efr32/src/AppTask.cpp b/examples/lock-app/efr32/src/AppTask.cpp index d3cc7e9a6f17d6..d7e814067bcc5d 100644 --- a/examples/lock-app/efr32/src/AppTask.cpp +++ b/examples/lock-app/efr32/src/AppTask.cpp @@ -254,9 +254,38 @@ 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"); diff --git a/examples/lock-app/efr32/src/LockManager.cpp b/examples/lock-app/efr32/src/LockManager.cpp index 6398ff3f6f5483..33d47c68a11aa9 100644 --- a/examples/lock-app/efr32/src/LockManager.cpp +++ b/examples/lock-app/efr32/src/LockManager.cpp @@ -33,17 +33,9 @@ TimerHandle_t sLockTimer; using namespace ::chip::DeviceLayer::Internal; CHIP_ERROR LockManager::Init(chip::app::DataModel::Nullable state, - uint8_t maxNumberOfCredentialsPerUser, uint16_t numberOfSupportedUsers) + uint8_t maxNumberOfCredentialsPerUser, uint16_t numberOfSupportedUsers, uint8_t numberOfWeekdaySchedulesPerUserSupported, + uint8_t numberOfYeardaySchedulesPerUserSupported, uint8_t numberOfHolidaySchedulesSupported) { - for (uint8_t i = 0; i < ArraySize(mLockUsers); i++) - { - // Allocate buffer for credentials - if (!mCredentials[i].Alloc(maxNumberOfCredentialsPerUser)) - { - EFR32_LOG("Failed to allocate array for lock credentials"); - return APP_ERROR_ALLOCATION_FAILED; - } - } mMaxCredentialsPerUser = maxNumberOfCredentialsPerUser; @@ -55,6 +47,30 @@ CHIP_ERROR LockManager::Init(chip::app::DataModel::Nullable MAX_SCHEDULE_PER_USER) + { + EFR32_LOG("Max number of schedules is greater than %d, the maximum amount of schedules currently supported on this platform", + MAX_SCHEDULE_PER_USER); + return APP_ERROR_ALLOCATION_FAILED; + } + + mNumberOfYeardaySchedulesPerUserSupported = numberOfYeardaySchedulesPerUserSupported; + if (mNumberOfYeardaySchedulesPerUserSupported > MAX_SCHEDULE_PER_USER) + { + EFR32_LOG("Max number of schedules is greater than %d, the maximum amount of schedules currently supported on this platform", + MAX_SCHEDULE_PER_USER); + return APP_ERROR_ALLOCATION_FAILED; + } + + mNumberOfHolidaySchedulesSupported = numberOfHolidaySchedulesSupported; + if (mNumberOfHolidaySchedulesSupported > MAX_SCHEDULE_PER_USER) + { + EFR32_LOG("Max number of schedules is greater than %d, the maximum amount of schedules currently supported on this platform", + MAX_SCHEDULE_PER_USER); + return APP_ERROR_ALLOCATION_FAILED; + } + // Create FreeRTOS sw timer for lock timer. sLockTimer = xTimerCreate("lockTmr", // Just a text name, not used by the RTOS kernel 1, // == default timer period (mS) @@ -92,8 +108,17 @@ bool LockManager::ReadConfigValues() EFR32Config::ReadConfigValueBin(EFR32Config::kConfigKey_CredentialData, reinterpret_cast(mCredentialData), sizeof(mCredentialData), outLen); - EFR32Config::ReadConfigValueBin(EFR32Config::kConfigKey_UserCredentials, reinterpret_cast(mCredentials[0].Get()), - sizeof(DlCredential) * mMaxUsers * mMaxCredentialsPerUser, outLen); + EFR32Config::ReadConfigValueBin(EFR32Config::kConfigKey_UserCredentials, reinterpret_cast(mCredentials), + sizeof(DlCredential) * mMaxUsers * mMaxCredentialsPerUser, outLen); + + EFR32Config::ReadConfigValueBin(EFR32Config::kConfigKey_WeekDaySchedules, reinterpret_cast (mWeekdaySchedule), + sizeof(EmberAfPluginDoorLockWeekDaySchedule) * mNumberOfWeekdaySchedulesPerUserSupported * mMaxUsers, outLen); + + EFR32Config::ReadConfigValueBin(EFR32Config::kConfigKey_YearDaySchedules, reinterpret_cast (mYeardaySchedule), + sizeof(EmberAfPluginDoorLockYearDaySchedule) * mNumberOfYeardaySchedulesPerUserSupported * mMaxUsers, outLen); + + EFR32Config::ReadConfigValueBin(EFR32Config::kConfigKey_HolidaySchedules, reinterpret_cast (&(mHolidaySchedule)), + sizeof(EmberAfPluginDoorLockHolidaySchedule) * mNumberOfHolidaySchedulesSupported, outLen); return true; } @@ -230,11 +255,11 @@ bool LockManager::Unlock(chip::EndpointId endpointId, const Optional(mCredentials[adjustedUserIndex].Get(), userInDb.credentials.size()); + user.credentials = chip::Span(mCredentials[adjustedUserIndex], userInDb.credentials.size()); user.userUniqueId = userInDb.userUniqueId; user.userType = userInDb.userType; user.credentialRule = userInDb.credentialRule; @@ -278,9 +303,9 @@ bool LockManager::SetUser(chip::EndpointId endpointId, uint16_t userIndex, chip: endpointId, userIndex, creator, modifier, userName.data(), uniqueId, to_underlying(userStatus), to_underlying(usertype), to_underlying(credentialRule), credentials, totalCredentials); + // door-lock-server checks for valid credential index uint16_t adjustedUserIndex = userIndex - 1; - // door-lock-server checks for valid user index auto & userInStorage = mLockUsers[adjustedUserIndex]; if (userName.size() > DOOR_LOCK_MAX_USER_NAME_SIZE) @@ -312,15 +337,16 @@ bool LockManager::SetUser(chip::EndpointId endpointId, uint16_t userIndex, chip: mCredentials[adjustedUserIndex][i].CredentialIndex = i + 1; } - userInStorage.credentials = chip::Span(mCredentials[adjustedUserIndex].Get(), totalCredentials); + userInStorage.credentials = chip::Span(mCredentials[adjustedUserIndex], totalCredentials); // Save user information in NVM flash EFR32Config::WriteConfigValueBin(EFR32Config::kConfigKey_LockUser, reinterpret_cast(&mLockUsers), sizeof(EmberAfPluginDoorLockUserInfo) * mMaxUsers); EFR32Config::WriteConfigValueBin(EFR32Config::kConfigKey_UserCredentials, - reinterpret_cast(mCredentials[adjustedUserIndex].Get()), - sizeof(DlCredential) * totalCredentials); + reinterpret_cast(mCredentials), + sizeof(DlCredential) * mMaxUsers * mMaxCredentialsPerUser); + EFR32Config::WriteConfigValueBin(EFR32Config::kConfigKey_LockUserName, reinterpret_cast(mUserNames), sizeof(mUserNames)); @@ -333,13 +359,19 @@ bool LockManager::SetUser(chip::EndpointId endpointId, uint16_t userIndex, chip: bool LockManager::GetCredential(chip::EndpointId endpointId, uint16_t credentialIndex, DlCredentialType credentialType, EmberAfPluginDoorLockCredentialInfo & credential) const { + if((credentialIndex < MIN_CREDENTIAL_INDEX) || (credentialIndex > MAX_CREDENTIAL_PER_USER)) + { + ChipLogError(Zcl, "Cannot get credential - credential index is out of range [endpoint=%d,index=%d]", + endpointId, credentialIndex); + return false; + } + // door-lock-server checks for valid credential index uint16_t adjustedCredentialIndex = credentialIndex - 1; ChipLogProgress(Zcl, "Lock App: LockManager::GetCredential [credentialType=%u], credentialIndex=%d", to_underlying(credentialType), adjustedCredentialIndex); - // door-lock-server checks for valid credential index const auto & credentialInStorage = mLockCredentials[adjustedCredentialIndex]; credential.status = credentialInStorage.status; @@ -369,24 +401,24 @@ bool LockManager::SetCredential(chip::EndpointId endpointId, uint16_t credential chip::FabricIndex modifier, DlCredentialStatus credentialStatus, DlCredentialType credentialType, const chip::ByteSpan & credentialData) { + + if((credentialIndex < MIN_CREDENTIAL_INDEX) || (credentialIndex > MAX_CREDENTIAL_PER_USER)) + { + ChipLogError(Zcl, "Cannot set credential - credential index is out of range [endpoint=%d,index=%d]", + endpointId, credentialIndex); + return false; + } + ChipLogProgress(Zcl, "Door Lock App: LockManager::SetCredential " "[credentialStatus=%u,credentialType=%u,credentialDataSize=%u,creator=%d,modifier=%d]", to_underlying(credentialStatus), to_underlying(credentialType), credentialData.size(), creator, modifier); + // door-lock-server checks for valid credential index uint16_t adjustedCredentialIndex = credentialIndex - 1; - // door-lock-server checks for valid credential index auto & credentialInStorage = mLockCredentials[adjustedCredentialIndex]; - if (credentialData.size() > DOOR_LOCK_CREDENTIAL_INFO_MAX_DATA_SIZE) - { - ChipLogError(Zcl, - "Cannot get the credential - data size exceeds limit " - "[dataSize=%u,maxDataSize=%u]", - credentialData.size(), DOOR_LOCK_CREDENTIAL_INFO_MAX_DATA_SIZE); - return false; - } credentialInStorage.status = credentialStatus; credentialInStorage.credentialType = credentialType; credentialInStorage.createdBy = creator; @@ -404,9 +436,177 @@ bool LockManager::SetCredential(chip::EndpointId endpointId, uint16_t credential ChipLogProgress(Zcl, "Successfully set the credential [credentialType=%u]", to_underlying(credentialType)); + return true; } +DlStatus LockManager::GetWeekdaySchedule(chip::EndpointId endpointId, uint8_t weekdayIndex, uint16_t userIndex, + EmberAfPluginDoorLockWeekDaySchedule & schedule) +{ + if((weekdayIndex < MIN_SCHEDULE_INDEX) || (weekdayIndex > MAX_SCHEDULE_PER_USER)) + { + ChipLogError(Zcl, "Cannot get schedule - schedule index is out of range [endpoint=%d,index=%d]", + endpointId, weekdayIndex); + return DlStatus::kFailure; + } + if((userIndex < MIN_USER_INDEX) || (userIndex > DOOR_LOCK_MAX_USERS)) + { + ChipLogError(Zcl, "Cannot get schedule - user index is out of range [endpoint=%d,index=%d]", + endpointId, userIndex); + return DlStatus::kFailure; + } + + // doorlock server checks for valid indices + uint8_t adjustedWeekDayIndex = weekdayIndex - 1; + uint16_t adjustedUserIndex = userIndex - 1; + + auto & scheduleInStorage = mWeekdaySchedule[adjustedUserIndex][adjustedWeekDayIndex]; + + schedule = scheduleInStorage; + + return DlStatus::kSuccess; + +} + +DlStatus LockManager::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) +{ + if((weekdayIndex < MIN_SCHEDULE_INDEX) || (weekdayIndex > MAX_SCHEDULE_PER_USER)) + { + ChipLogError(Zcl, "Cannot set schedule - schedule index is out of range [endpoint=%d,index=%d]", + endpointId, weekdayIndex); + return DlStatus::kFailure; + } + if((userIndex < MIN_USER_INDEX) || (userIndex > DOOR_LOCK_MAX_USERS)) + { + ChipLogError(Zcl, "Cannot get schedule - user index is out of range [endpoint=%d,index=%d]", + endpointId, userIndex); + return DlStatus::kFailure; + } + + // doorlock server checks for valid indices + uint8_t adjustedWeekDayIndex = weekdayIndex - 1; + uint16_t adjustedUserIndex = userIndex - 1; + + auto & scheduleInStorage = mWeekdaySchedule[adjustedUserIndex][adjustedWeekDayIndex]; + + scheduleInStorage.daysMask = daysMask; + scheduleInStorage.startHour = startHour; + scheduleInStorage.startMinute = startMinute; + scheduleInStorage.endHour = endHour; + scheduleInStorage.endMinute = endMinute; + + EFR32Config::WriteConfigValueBin(EFR32Config::kConfigKey_WeekDaySchedules, reinterpret_cast (mWeekdaySchedule), + sizeof(EmberAfPluginDoorLockWeekDaySchedule) * mNumberOfWeekdaySchedulesPerUserSupported * mMaxUsers); + + return DlStatus::kSuccess; + +} + +DlStatus LockManager::GetYeardaySchedule(chip::EndpointId endpointId, uint8_t yearDayIndex, uint16_t userIndex, + EmberAfPluginDoorLockYearDaySchedule & schedule) +{ + if((yearDayIndex < MIN_SCHEDULE_INDEX) || (yearDayIndex > MAX_SCHEDULE_PER_USER)) + { + ChipLogError(Zcl, "Cannot set schedule - schedule index is out of range [endpoint=%d,index=%d]", + endpointId, yearDayIndex); + return DlStatus::kFailure; + } + if((userIndex < MIN_USER_INDEX) || (userIndex > DOOR_LOCK_MAX_USERS)) + { + ChipLogError(Zcl, "Cannot get schedule - user index is out of range [endpoint=%d,index=%d]", + endpointId, userIndex); + return DlStatus::kFailure; + } + + // doorlock server checks for valid indices + uint8_t adjustedYearDayIndex = yearDayIndex - 1; + uint16_t adjustedUserIndex = userIndex - 1; + + auto & scheduleInStorage = mYeardaySchedule[adjustedUserIndex][adjustedYearDayIndex]; + + schedule = scheduleInStorage; + + return DlStatus::kSuccess; +} + +DlStatus LockManager::SetYeardaySchedule(chip::EndpointId endpointId, uint8_t yearDayIndex, uint16_t userIndex, + DlScheduleStatus status, uint32_t localStartTime, uint32_t localEndTime) +{ + if((yearDayIndex < MIN_SCHEDULE_INDEX) || (yearDayIndex > MAX_SCHEDULE_PER_USER)) + { + ChipLogError(Zcl, "Cannot set schedule - schedule index is out of range [endpoint=%d,index=%d]", + endpointId, yearDayIndex); + return DlStatus::kFailure; + } + if((userIndex < MIN_USER_INDEX) || (userIndex > DOOR_LOCK_MAX_USERS)) + { + ChipLogError(Zcl, "Cannot get schedule - user index is out of range [endpoint=%d,index=%d]", + endpointId, userIndex); + return DlStatus::kFailure; + } + + // doorlock server checks for valid indices + uint8_t adjustedYearDayIndex = yearDayIndex - 1; + uint16_t adjustedUserIndex = userIndex - 1; + + auto & scheduleInStorage = mYeardaySchedule[adjustedUserIndex][adjustedYearDayIndex]; + + //scheduleInStorage.status = status; + scheduleInStorage.localStartTime = localStartTime; + scheduleInStorage.localEndTime = localEndTime; + + EFR32Config::WriteConfigValueBin(EFR32Config::kConfigKey_YearDaySchedules, reinterpret_cast (mYeardaySchedule), + sizeof(EmberAfPluginDoorLockYearDaySchedule) * mNumberOfYeardaySchedulesPerUserSupported * mMaxUsers); + + return DlStatus::kSuccess; +} + +DlStatus LockManager::GetHolidaySchedule(chip::EndpointId endpointId, uint8_t holidayIndex, EmberAfPluginDoorLockHolidaySchedule & schedule) +{ + if((holidayIndex < MIN_SCHEDULE_INDEX) || (holidayIndex > MAX_SCHEDULE_PER_USER)) + { + ChipLogError(Zcl, "Cannot set schedule - schedule index is out of range [endpoint=%d,index=%d]", + endpointId, holidayIndex); + return DlStatus::kFailure; + } + + // door-lock server checks for valid indices + uint8_t adjustedHolidayIndex = holidayIndex - 1; + + auto & scheduleInStorage = mHolidaySchedule[adjustedHolidayIndex]; + + schedule = scheduleInStorage; + + return DlStatus::kSuccess; +} + +DlStatus LockManager::SetHolidaySchedule(chip::EndpointId endpointId, uint8_t holidayIndex, DlScheduleStatus status, + uint32_t localStartTime, uint32_t localEndTime, DlOperatingMode operatingMode) +{ + if((holidayIndex < MIN_SCHEDULE_INDEX) || (holidayIndex > MAX_SCHEDULE_PER_USER)) + { + ChipLogError(Zcl, "Cannot set schedule - schedule index is out of range [endpoint=%d,index=%d]", + endpointId, holidayIndex); + return DlStatus::kFailure; + } + + // door-lock server checks for valid indices + uint8_t adjustedHolidayIndex = holidayIndex - 1; + + auto & scheduleInStorage = mHolidaySchedule[adjustedHolidayIndex]; + + scheduleInStorage.localStartTime = localStartTime; + scheduleInStorage.localEndTime = localEndTime; + scheduleInStorage.operatingMode = operatingMode; + + EFR32Config::WriteConfigValueBin(EFR32Config::kConfigKey_HolidaySchedules, reinterpret_cast (&(mHolidaySchedule)), + sizeof(EmberAfPluginDoorLockHolidaySchedule) * mNumberOfHolidaySchedulesSupported); + + return DlStatus::kSuccess; +} + const char * LockManager::lockStateToString(DlLockState lockState) const { switch (lockState) @@ -445,7 +645,7 @@ bool LockManager::setLockState(chip::EndpointId endpointId, DlLockState lockStat // Check the RequirePINforRemoteOperation attribute bool requirePin = false; - // chip::app::Clusters::DoorLock::Attributes::RequirePINforRemoteOperation::Get(endpointId, &requirePin); + chip::app::Clusters::DoorLock::Attributes::RequirePINforRemoteOperation::Get(endpointId, &requirePin); // If a pin code is not given if (!pin.HasValue()) @@ -466,7 +666,7 @@ bool LockManager::setLockState(chip::EndpointId endpointId, DlLockState lockStat } // Check the PIN code - for (uint8_t i = 0; i < mMaxCredentialsPerUser; i++) + for (uint8_t i = 0; i < MAX_CREDENTIALS; i++) { if (mLockCredentials[i].credentialType != DlCredentialType::kPin || mLockCredentials[i].status == DlCredentialStatus::kAvailable) diff --git a/examples/lock-app/efr32/src/ZclCallbacks.cpp b/examples/lock-app/efr32/src/ZclCallbacks.cpp index 8fb775956a4c30..aad3ebbfaea7fd 100644 --- a/examples/lock-app/efr32/src/ZclCallbacks.cpp +++ b/examples/lock-app/efr32/src/ZclCallbacks.cpp @@ -29,7 +29,6 @@ #include #include -using namespace ::chip; using namespace ::chip::app::Clusters; using namespace ::chip::DeviceLayer::Internal; @@ -57,7 +56,7 @@ void MatterPostAttributeChangeCallback(const chip::app::ConcreteAttributePath & */ void emberAfDoorLockClusterInitCallback(EndpointId endpoint) { - // TODO: implement any additional Cluster Server init actions + } bool emberAfPluginDoorLockOnDoorLockCommand(chip::EndpointId endpointId, const Optional & pinCode, DlOperationError & err) @@ -113,28 +112,39 @@ bool emberAfPluginDoorLockSetUser(chip::EndpointId endpointId, uint16_t userInde credentials, totalCredentials); } -// TODO: These functions will be supported by door-lock-server in the future. These are set to return failure until implemented. DlStatus emberAfPluginDoorLockGetSchedule(chip::EndpointId endpointId, uint8_t weekdayIndex, uint16_t userIndex, EmberAfPluginDoorLockWeekDaySchedule & schedule) { - return DlStatus::kFailure; + return LockMgr().GetWeekdaySchedule(endpointId, weekdayIndex, userIndex, schedule); } DlStatus emberAfPluginDoorLockGetSchedule(chip::EndpointId endpointId, uint8_t yearDayIndex, uint16_t userIndex, EmberAfPluginDoorLockYearDaySchedule & schedule) { - return DlStatus::kFailure; + return LockMgr().GetYeardaySchedule(endpointId, yearDayIndex, userIndex, schedule); +} + +DlStatus emberAfPluginDoorLockGetSchedule(chip::EndpointId endpointId, uint8_t holidayIndex, EmberAfPluginDoorLockHolidaySchedule & holidaySchedule) +{ + return LockMgr().GetHolidaySchedule(endpointId, holidayIndex, holidaySchedule); } DlStatus emberAfPluginDoorLockSetSchedule(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) { - return DlStatus::kFailure; + return LockMgr().SetWeekdaySchedule(endpointId, weekdayIndex, userIndex, status, daysMask, startHour, startMinute, endHour, endMinute); } DlStatus emberAfPluginDoorLockSetSchedule(chip::EndpointId endpointId, uint8_t yearDayIndex, uint16_t userIndex, DlScheduleStatus status, uint32_t localStartTime, uint32_t localEndTime) { - return DlStatus::kFailure; + return LockMgr().SetYeardaySchedule(endpointId, yearDayIndex, userIndex, + status, localStartTime, localEndTime); +} + +DlStatus emberAfPluginDoorLockSetSchedule(chip::EndpointId endpointId, uint8_t holidayIndex, DlScheduleStatus status, + uint32_t localStartTime, uint32_t localEndTime, DlOperatingMode operatingMode) +{ + return LockMgr().SetHolidaySchedule(endpointId, holidayIndex, status, localStartTime, localEndTime, operatingMode); } diff --git a/src/platform/EFR32/EFR32Config.h b/src/platform/EFR32/EFR32Config.h index 1095bb074a2bd1..de279b8fca9bc4 100644 --- a/src/platform/EFR32/EFR32Config.h +++ b/src/platform/EFR32/EFR32Config.h @@ -122,6 +122,10 @@ class EFR32Config static constexpr Key kConfigKey_LockUserName = EFR32ConfigKey(kMatterConfig_KeyBase, 0x12); static constexpr Key kConfigKey_CredentialData = EFR32ConfigKey(kMatterConfig_KeyBase, 0x13); static constexpr Key kConfigKey_UserCredentials = EFR32ConfigKey(kMatterConfig_KeyBase, 0x14); + static constexpr Key kConfigKey_WeekDaySchedules = EFR32ConfigKey(kMatterConfig_KeyBase, 0x15); + static constexpr Key kConfigKey_YearDaySchedules = EFR32ConfigKey(kMatterConfig_KeyBase, 0x16); + static constexpr Key kConfigKey_HolidaySchedules = EFR32ConfigKey(kMatterConfig_KeyBase, 0x17); + static constexpr Key kConfigKey_GroupKeyMax = EFR32ConfigKey(kMatterConfig_KeyBase, 0x1E); // Allows 16 Group Keys to be created. From bc55a4b0f3473e25d0fcfe134da4342ae316769e Mon Sep 17 00:00:00 2001 From: Michael Rupp <95718139+mykrupp@users.noreply.github.com> Date: Tue, 28 Jun 2022 11:21:30 -0400 Subject: [PATCH 2/5] restyle --- examples/lock-app/efr32/include/LockManager.h | 20 ++- examples/lock-app/efr32/src/AppTask.cpp | 29 ++-- examples/lock-app/efr32/src/LockManager.cpp | 163 +++++++++--------- examples/lock-app/efr32/src/ZclCallbacks.cpp | 14 +- src/platform/EFR32/EFR32Config.h | 1 - 5 files changed, 113 insertions(+), 114 deletions(-) diff --git a/examples/lock-app/efr32/include/LockManager.h b/examples/lock-app/efr32/include/LockManager.h index 28af6776d5c03f..db148043093018 100644 --- a/examples/lock-app/efr32/include/LockManager.h +++ b/examples/lock-app/efr32/include/LockManager.h @@ -72,8 +72,9 @@ class LockManager } State; CHIP_ERROR Init(chip::app::DataModel::Nullable state, - uint8_t maxNumberOfCredentialsPerUser, uint16_t numberOfSupportedUsers, uint8_t numberOfWeekdaySchedulesPerUserSupported, - uint8_t numberOfYeardaySchedulesPerUserSupported, uint8_t numberOfHolidaySchedulesPerUserSupported); + 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); @@ -97,20 +98,21 @@ class LockManager DlCredentialStatus credentialStatus, DlCredentialType credentialType, const chip::ByteSpan & credentialData); DlStatus GetWeekdaySchedule(chip::EndpointId endpointId, uint8_t weekdayIndex, uint16_t userIndex, - EmberAfPluginDoorLockWeekDaySchedule & schedule); + 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 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); + EmberAfPluginDoorLockYearDaySchedule & schedule); - DlStatus SetYeardaySchedule(chip::EndpointId endpointId, uint8_t yearDayIndex, uint16_t userIndex, DlScheduleStatus status, uint32_t localStartTime, uint32_t localEndTime); + 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); + 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 & pin, DlOperationError & err); diff --git a/examples/lock-app/efr32/src/AppTask.cpp b/examples/lock-app/efr32/src/AppTask.cpp index d7e814067bcc5d..47c18a7905028b 100644 --- a/examples/lock-app/efr32/src/AppTask.cpp +++ b/examples/lock-app/efr32/src/AppTask.cpp @@ -256,35 +256,40 @@ CHIP_ERROR AppTask::Init() } uint8_t numberOfWeekdaySchedulesPerUserSupported = 0; - if (!DoorLockServer::Instance().GetNumberOfWeekDaySchedulesPerUserSupported(endpointId, numberOfWeekdaySchedulesPerUserSupported)) + 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); + 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)) + 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); + 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); + 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, numberOfWeekdaySchedulesPerUserSupported, + err = LockMgr().Init(state, maxCredentialsPerUser, numberOfSupportedUsers, numberOfWeekdaySchedulesPerUserSupported, numberOfYeardaySchedulesPerUserSupported, numberOfHolidaySchedulesSupported); if (err != CHIP_NO_ERROR) { diff --git a/examples/lock-app/efr32/src/LockManager.cpp b/examples/lock-app/efr32/src/LockManager.cpp index 33d47c68a11aa9..d3728680eed7d0 100644 --- a/examples/lock-app/efr32/src/LockManager.cpp +++ b/examples/lock-app/efr32/src/LockManager.cpp @@ -33,8 +33,9 @@ TimerHandle_t sLockTimer; using namespace ::chip::DeviceLayer::Internal; CHIP_ERROR LockManager::Init(chip::app::DataModel::Nullable state, - uint8_t maxNumberOfCredentialsPerUser, uint16_t numberOfSupportedUsers, uint8_t numberOfWeekdaySchedulesPerUserSupported, - uint8_t numberOfYeardaySchedulesPerUserSupported, uint8_t numberOfHolidaySchedulesSupported) + uint8_t maxNumberOfCredentialsPerUser, uint16_t numberOfSupportedUsers, + uint8_t numberOfWeekdaySchedulesPerUserSupported, uint8_t numberOfYeardaySchedulesPerUserSupported, + uint8_t numberOfHolidaySchedulesSupported) { mMaxCredentialsPerUser = maxNumberOfCredentialsPerUser; @@ -50,24 +51,27 @@ CHIP_ERROR LockManager::Init(chip::app::DataModel::Nullable MAX_SCHEDULE_PER_USER) { - EFR32_LOG("Max number of schedules is greater than %d, the maximum amount of schedules currently supported on this platform", - MAX_SCHEDULE_PER_USER); + EFR32_LOG( + "Max number of schedules is greater than %d, the maximum amount of schedules currently supported on this platform", + MAX_SCHEDULE_PER_USER); return APP_ERROR_ALLOCATION_FAILED; } mNumberOfYeardaySchedulesPerUserSupported = numberOfYeardaySchedulesPerUserSupported; if (mNumberOfYeardaySchedulesPerUserSupported > MAX_SCHEDULE_PER_USER) { - EFR32_LOG("Max number of schedules is greater than %d, the maximum amount of schedules currently supported on this platform", - MAX_SCHEDULE_PER_USER); + EFR32_LOG( + "Max number of schedules is greater than %d, the maximum amount of schedules currently supported on this platform", + MAX_SCHEDULE_PER_USER); return APP_ERROR_ALLOCATION_FAILED; } mNumberOfHolidaySchedulesSupported = numberOfHolidaySchedulesSupported; if (mNumberOfHolidaySchedulesSupported > MAX_SCHEDULE_PER_USER) { - EFR32_LOG("Max number of schedules is greater than %d, the maximum amount of schedules currently supported on this platform", - MAX_SCHEDULE_PER_USER); + EFR32_LOG( + "Max number of schedules is greater than %d, the maximum amount of schedules currently supported on this platform", + MAX_SCHEDULE_PER_USER); return APP_ERROR_ALLOCATION_FAILED; } @@ -109,16 +113,18 @@ bool LockManager::ReadConfigValues() sizeof(mCredentialData), outLen); EFR32Config::ReadConfigValueBin(EFR32Config::kConfigKey_UserCredentials, reinterpret_cast(mCredentials), - sizeof(DlCredential) * mMaxUsers * mMaxCredentialsPerUser, outLen); + sizeof(DlCredential) * mMaxUsers * mMaxCredentialsPerUser, outLen); - EFR32Config::ReadConfigValueBin(EFR32Config::kConfigKey_WeekDaySchedules, reinterpret_cast (mWeekdaySchedule), - sizeof(EmberAfPluginDoorLockWeekDaySchedule) * mNumberOfWeekdaySchedulesPerUserSupported * mMaxUsers, outLen); + EFR32Config::ReadConfigValueBin( + EFR32Config::kConfigKey_WeekDaySchedules, reinterpret_cast(mWeekdaySchedule), + sizeof(EmberAfPluginDoorLockWeekDaySchedule) * mNumberOfWeekdaySchedulesPerUserSupported * mMaxUsers, outLen); - EFR32Config::ReadConfigValueBin(EFR32Config::kConfigKey_YearDaySchedules, reinterpret_cast (mYeardaySchedule), - sizeof(EmberAfPluginDoorLockYearDaySchedule) * mNumberOfYeardaySchedulesPerUserSupported * mMaxUsers, outLen); + EFR32Config::ReadConfigValueBin( + EFR32Config::kConfigKey_YearDaySchedules, reinterpret_cast(mYeardaySchedule), + sizeof(EmberAfPluginDoorLockYearDaySchedule) * mNumberOfYeardaySchedulesPerUserSupported * mMaxUsers, outLen); - EFR32Config::ReadConfigValueBin(EFR32Config::kConfigKey_HolidaySchedules, reinterpret_cast (&(mHolidaySchedule)), - sizeof(EmberAfPluginDoorLockHolidaySchedule) * mNumberOfHolidaySchedulesSupported, outLen); + EFR32Config::ReadConfigValueBin(EFR32Config::kConfigKey_HolidaySchedules, reinterpret_cast(&(mHolidaySchedule)), + sizeof(EmberAfPluginDoorLockHolidaySchedule) * mNumberOfHolidaySchedulesSupported, outLen); return true; } @@ -343,10 +349,8 @@ bool LockManager::SetUser(chip::EndpointId endpointId, uint16_t userIndex, chip: EFR32Config::WriteConfigValueBin(EFR32Config::kConfigKey_LockUser, reinterpret_cast(&mLockUsers), sizeof(EmberAfPluginDoorLockUserInfo) * mMaxUsers); - EFR32Config::WriteConfigValueBin(EFR32Config::kConfigKey_UserCredentials, - reinterpret_cast(mCredentials), - sizeof(DlCredential) * mMaxUsers * mMaxCredentialsPerUser); - + EFR32Config::WriteConfigValueBin(EFR32Config::kConfigKey_UserCredentials, reinterpret_cast(mCredentials), + sizeof(DlCredential) * mMaxUsers * mMaxCredentialsPerUser); EFR32Config::WriteConfigValueBin(EFR32Config::kConfigKey_LockUserName, reinterpret_cast(mUserNames), sizeof(mUserNames)); @@ -359,10 +363,10 @@ bool LockManager::SetUser(chip::EndpointId endpointId, uint16_t userIndex, chip: bool LockManager::GetCredential(chip::EndpointId endpointId, uint16_t credentialIndex, DlCredentialType credentialType, EmberAfPluginDoorLockCredentialInfo & credential) const { - if((credentialIndex < MIN_CREDENTIAL_INDEX) || (credentialIndex > MAX_CREDENTIAL_PER_USER)) + if ((credentialIndex < MIN_CREDENTIAL_INDEX) || (credentialIndex > MAX_CREDENTIAL_PER_USER)) { - ChipLogError(Zcl, "Cannot get credential - credential index is out of range [endpoint=%d,index=%d]", - endpointId, credentialIndex); + ChipLogError(Zcl, "Cannot get credential - credential index is out of range [endpoint=%d,index=%d]", endpointId, + credentialIndex); return false; } @@ -402,10 +406,10 @@ bool LockManager::SetCredential(chip::EndpointId endpointId, uint16_t credential const chip::ByteSpan & credentialData) { - if((credentialIndex < MIN_CREDENTIAL_INDEX) || (credentialIndex > MAX_CREDENTIAL_PER_USER)) + if ((credentialIndex < MIN_CREDENTIAL_INDEX) || (credentialIndex > MAX_CREDENTIAL_PER_USER)) { - ChipLogError(Zcl, "Cannot set credential - credential index is out of range [endpoint=%d,index=%d]", - endpointId, credentialIndex); + ChipLogError(Zcl, "Cannot set credential - credential index is out of range [endpoint=%d,index=%d]", endpointId, + credentialIndex); return false; } @@ -436,139 +440,130 @@ bool LockManager::SetCredential(chip::EndpointId endpointId, uint16_t credential ChipLogProgress(Zcl, "Successfully set the credential [credentialType=%u]", to_underlying(credentialType)); - return true; } DlStatus LockManager::GetWeekdaySchedule(chip::EndpointId endpointId, uint8_t weekdayIndex, uint16_t userIndex, - EmberAfPluginDoorLockWeekDaySchedule & schedule) + EmberAfPluginDoorLockWeekDaySchedule & schedule) { - if((weekdayIndex < MIN_SCHEDULE_INDEX) || (weekdayIndex > MAX_SCHEDULE_PER_USER)) + if ((weekdayIndex < MIN_SCHEDULE_INDEX) || (weekdayIndex > MAX_SCHEDULE_PER_USER)) { - ChipLogError(Zcl, "Cannot get schedule - schedule index is out of range [endpoint=%d,index=%d]", - endpointId, weekdayIndex); + ChipLogError(Zcl, "Cannot get schedule - schedule index is out of range [endpoint=%d,index=%d]", endpointId, weekdayIndex); return DlStatus::kFailure; } - if((userIndex < MIN_USER_INDEX) || (userIndex > DOOR_LOCK_MAX_USERS)) + if ((userIndex < MIN_USER_INDEX) || (userIndex > DOOR_LOCK_MAX_USERS)) { - ChipLogError(Zcl, "Cannot get schedule - user index is out of range [endpoint=%d,index=%d]", - endpointId, userIndex); + ChipLogError(Zcl, "Cannot get schedule - user index is out of range [endpoint=%d,index=%d]", endpointId, userIndex); return DlStatus::kFailure; } - + // doorlock server checks for valid indices uint8_t adjustedWeekDayIndex = weekdayIndex - 1; - uint16_t adjustedUserIndex = userIndex - 1; + uint16_t adjustedUserIndex = userIndex - 1; auto & scheduleInStorage = mWeekdaySchedule[adjustedUserIndex][adjustedWeekDayIndex]; schedule = scheduleInStorage; return DlStatus::kSuccess; - } DlStatus LockManager::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) + DlScheduleStatus status, DlDaysMaskMap daysMask, uint8_t startHour, uint8_t startMinute, + uint8_t endHour, uint8_t endMinute) { - if((weekdayIndex < MIN_SCHEDULE_INDEX) || (weekdayIndex > MAX_SCHEDULE_PER_USER)) + if ((weekdayIndex < MIN_SCHEDULE_INDEX) || (weekdayIndex > MAX_SCHEDULE_PER_USER)) { - ChipLogError(Zcl, "Cannot set schedule - schedule index is out of range [endpoint=%d,index=%d]", - endpointId, weekdayIndex); + ChipLogError(Zcl, "Cannot set schedule - schedule index is out of range [endpoint=%d,index=%d]", endpointId, weekdayIndex); return DlStatus::kFailure; } - if((userIndex < MIN_USER_INDEX) || (userIndex > DOOR_LOCK_MAX_USERS)) + if ((userIndex < MIN_USER_INDEX) || (userIndex > DOOR_LOCK_MAX_USERS)) { - ChipLogError(Zcl, "Cannot get schedule - user index is out of range [endpoint=%d,index=%d]", - endpointId, userIndex); + ChipLogError(Zcl, "Cannot get schedule - user index is out of range [endpoint=%d,index=%d]", endpointId, userIndex); return DlStatus::kFailure; } // doorlock server checks for valid indices uint8_t adjustedWeekDayIndex = weekdayIndex - 1; - uint16_t adjustedUserIndex = userIndex - 1; + uint16_t adjustedUserIndex = userIndex - 1; auto & scheduleInStorage = mWeekdaySchedule[adjustedUserIndex][adjustedWeekDayIndex]; - scheduleInStorage.daysMask = daysMask; - scheduleInStorage.startHour = startHour; + scheduleInStorage.daysMask = daysMask; + scheduleInStorage.startHour = startHour; scheduleInStorage.startMinute = startMinute; - scheduleInStorage.endHour = endHour; - scheduleInStorage.endMinute = endMinute; + scheduleInStorage.endHour = endHour; + scheduleInStorage.endMinute = endMinute; - EFR32Config::WriteConfigValueBin(EFR32Config::kConfigKey_WeekDaySchedules, reinterpret_cast (mWeekdaySchedule), - sizeof(EmberAfPluginDoorLockWeekDaySchedule) * mNumberOfWeekdaySchedulesPerUserSupported * mMaxUsers); + EFR32Config::WriteConfigValueBin(EFR32Config::kConfigKey_WeekDaySchedules, reinterpret_cast(mWeekdaySchedule), + sizeof(EmberAfPluginDoorLockWeekDaySchedule) * mNumberOfWeekdaySchedulesPerUserSupported * + mMaxUsers); return DlStatus::kSuccess; - } DlStatus LockManager::GetYeardaySchedule(chip::EndpointId endpointId, uint8_t yearDayIndex, uint16_t userIndex, - EmberAfPluginDoorLockYearDaySchedule & schedule) + EmberAfPluginDoorLockYearDaySchedule & schedule) { - if((yearDayIndex < MIN_SCHEDULE_INDEX) || (yearDayIndex > MAX_SCHEDULE_PER_USER)) + if ((yearDayIndex < MIN_SCHEDULE_INDEX) || (yearDayIndex > MAX_SCHEDULE_PER_USER)) { - ChipLogError(Zcl, "Cannot set schedule - schedule index is out of range [endpoint=%d,index=%d]", - endpointId, yearDayIndex); + ChipLogError(Zcl, "Cannot set schedule - schedule index is out of range [endpoint=%d,index=%d]", endpointId, yearDayIndex); return DlStatus::kFailure; } - if((userIndex < MIN_USER_INDEX) || (userIndex > DOOR_LOCK_MAX_USERS)) + if ((userIndex < MIN_USER_INDEX) || (userIndex > DOOR_LOCK_MAX_USERS)) { - ChipLogError(Zcl, "Cannot get schedule - user index is out of range [endpoint=%d,index=%d]", - endpointId, userIndex); + ChipLogError(Zcl, "Cannot get schedule - user index is out of range [endpoint=%d,index=%d]", endpointId, userIndex); return DlStatus::kFailure; } // doorlock server checks for valid indices uint8_t adjustedYearDayIndex = yearDayIndex - 1; - uint16_t adjustedUserIndex = userIndex - 1; + uint16_t adjustedUserIndex = userIndex - 1; auto & scheduleInStorage = mYeardaySchedule[adjustedUserIndex][adjustedYearDayIndex]; schedule = scheduleInStorage; - return DlStatus::kSuccess; + return DlStatus::kSuccess; } DlStatus LockManager::SetYeardaySchedule(chip::EndpointId endpointId, uint8_t yearDayIndex, uint16_t userIndex, - DlScheduleStatus status, uint32_t localStartTime, uint32_t localEndTime) + DlScheduleStatus status, uint32_t localStartTime, uint32_t localEndTime) { - if((yearDayIndex < MIN_SCHEDULE_INDEX) || (yearDayIndex > MAX_SCHEDULE_PER_USER)) + if ((yearDayIndex < MIN_SCHEDULE_INDEX) || (yearDayIndex > MAX_SCHEDULE_PER_USER)) { - ChipLogError(Zcl, "Cannot set schedule - schedule index is out of range [endpoint=%d,index=%d]", - endpointId, yearDayIndex); + ChipLogError(Zcl, "Cannot set schedule - schedule index is out of range [endpoint=%d,index=%d]", endpointId, yearDayIndex); return DlStatus::kFailure; } - if((userIndex < MIN_USER_INDEX) || (userIndex > DOOR_LOCK_MAX_USERS)) + if ((userIndex < MIN_USER_INDEX) || (userIndex > DOOR_LOCK_MAX_USERS)) { - ChipLogError(Zcl, "Cannot get schedule - user index is out of range [endpoint=%d,index=%d]", - endpointId, userIndex); + ChipLogError(Zcl, "Cannot get schedule - user index is out of range [endpoint=%d,index=%d]", endpointId, userIndex); return DlStatus::kFailure; } // doorlock server checks for valid indices uint8_t adjustedYearDayIndex = yearDayIndex - 1; - uint16_t adjustedUserIndex = userIndex - 1; + uint16_t adjustedUserIndex = userIndex - 1; auto & scheduleInStorage = mYeardaySchedule[adjustedUserIndex][adjustedYearDayIndex]; - //scheduleInStorage.status = status; + // scheduleInStorage.status = status; scheduleInStorage.localStartTime = localStartTime; - scheduleInStorage.localEndTime = localEndTime; + scheduleInStorage.localEndTime = localEndTime; - EFR32Config::WriteConfigValueBin(EFR32Config::kConfigKey_YearDaySchedules, reinterpret_cast (mYeardaySchedule), - sizeof(EmberAfPluginDoorLockYearDaySchedule) * mNumberOfYeardaySchedulesPerUserSupported * mMaxUsers); + EFR32Config::WriteConfigValueBin(EFR32Config::kConfigKey_YearDaySchedules, reinterpret_cast(mYeardaySchedule), + sizeof(EmberAfPluginDoorLockYearDaySchedule) * mNumberOfYeardaySchedulesPerUserSupported * + mMaxUsers); return DlStatus::kSuccess; } -DlStatus LockManager::GetHolidaySchedule(chip::EndpointId endpointId, uint8_t holidayIndex, EmberAfPluginDoorLockHolidaySchedule & schedule) +DlStatus LockManager::GetHolidaySchedule(chip::EndpointId endpointId, uint8_t holidayIndex, + EmberAfPluginDoorLockHolidaySchedule & schedule) { - if((holidayIndex < MIN_SCHEDULE_INDEX) || (holidayIndex > MAX_SCHEDULE_PER_USER)) + if ((holidayIndex < MIN_SCHEDULE_INDEX) || (holidayIndex > MAX_SCHEDULE_PER_USER)) { - ChipLogError(Zcl, "Cannot set schedule - schedule index is out of range [endpoint=%d,index=%d]", - endpointId, holidayIndex); + ChipLogError(Zcl, "Cannot set schedule - schedule index is out of range [endpoint=%d,index=%d]", endpointId, holidayIndex); return DlStatus::kFailure; } @@ -583,12 +578,11 @@ DlStatus LockManager::GetHolidaySchedule(chip::EndpointId endpointId, uint8_t ho } DlStatus LockManager::SetHolidaySchedule(chip::EndpointId endpointId, uint8_t holidayIndex, DlScheduleStatus status, - uint32_t localStartTime, uint32_t localEndTime, DlOperatingMode operatingMode) + uint32_t localStartTime, uint32_t localEndTime, DlOperatingMode operatingMode) { - if((holidayIndex < MIN_SCHEDULE_INDEX) || (holidayIndex > MAX_SCHEDULE_PER_USER)) + if ((holidayIndex < MIN_SCHEDULE_INDEX) || (holidayIndex > MAX_SCHEDULE_PER_USER)) { - ChipLogError(Zcl, "Cannot set schedule - schedule index is out of range [endpoint=%d,index=%d]", - endpointId, holidayIndex); + ChipLogError(Zcl, "Cannot set schedule - schedule index is out of range [endpoint=%d,index=%d]", endpointId, holidayIndex); return DlStatus::kFailure; } @@ -598,10 +592,11 @@ DlStatus LockManager::SetHolidaySchedule(chip::EndpointId endpointId, uint8_t ho auto & scheduleInStorage = mHolidaySchedule[adjustedHolidayIndex]; scheduleInStorage.localStartTime = localStartTime; - scheduleInStorage.localEndTime = localEndTime; - scheduleInStorage.operatingMode = operatingMode; + scheduleInStorage.localEndTime = localEndTime; + scheduleInStorage.operatingMode = operatingMode; - EFR32Config::WriteConfigValueBin(EFR32Config::kConfigKey_HolidaySchedules, reinterpret_cast (&(mHolidaySchedule)), + EFR32Config::WriteConfigValueBin(EFR32Config::kConfigKey_HolidaySchedules, + reinterpret_cast(&(mHolidaySchedule)), sizeof(EmberAfPluginDoorLockHolidaySchedule) * mNumberOfHolidaySchedulesSupported); return DlStatus::kSuccess; diff --git a/examples/lock-app/efr32/src/ZclCallbacks.cpp b/examples/lock-app/efr32/src/ZclCallbacks.cpp index aad3ebbfaea7fd..650aba7d2d73de 100644 --- a/examples/lock-app/efr32/src/ZclCallbacks.cpp +++ b/examples/lock-app/efr32/src/ZclCallbacks.cpp @@ -54,10 +54,7 @@ void MatterPostAttributeChangeCallback(const chip::app::ConcreteAttributePath & * @param endpoint Ver.: always * */ -void emberAfDoorLockClusterInitCallback(EndpointId endpoint) -{ - -} +void emberAfDoorLockClusterInitCallback(EndpointId endpoint) {} bool emberAfPluginDoorLockOnDoorLockCommand(chip::EndpointId endpointId, const Optional & pinCode, DlOperationError & err) { @@ -124,7 +121,8 @@ DlStatus emberAfPluginDoorLockGetSchedule(chip::EndpointId endpointId, uint8_t y return LockMgr().GetYeardaySchedule(endpointId, yearDayIndex, userIndex, schedule); } -DlStatus emberAfPluginDoorLockGetSchedule(chip::EndpointId endpointId, uint8_t holidayIndex, EmberAfPluginDoorLockHolidaySchedule & holidaySchedule) +DlStatus emberAfPluginDoorLockGetSchedule(chip::EndpointId endpointId, uint8_t holidayIndex, + EmberAfPluginDoorLockHolidaySchedule & holidaySchedule) { return LockMgr().GetHolidaySchedule(endpointId, holidayIndex, holidaySchedule); } @@ -133,14 +131,14 @@ DlStatus emberAfPluginDoorLockSetSchedule(chip::EndpointId endpointId, uint8_t w DlScheduleStatus status, DlDaysMaskMap daysMask, uint8_t startHour, uint8_t startMinute, uint8_t endHour, uint8_t endMinute) { - return LockMgr().SetWeekdaySchedule(endpointId, weekdayIndex, userIndex, status, daysMask, startHour, startMinute, endHour, endMinute); + return LockMgr().SetWeekdaySchedule(endpointId, weekdayIndex, userIndex, status, daysMask, startHour, startMinute, endHour, + endMinute); } DlStatus emberAfPluginDoorLockSetSchedule(chip::EndpointId endpointId, uint8_t yearDayIndex, uint16_t userIndex, DlScheduleStatus status, uint32_t localStartTime, uint32_t localEndTime) { - return LockMgr().SetYeardaySchedule(endpointId, yearDayIndex, userIndex, - status, localStartTime, localEndTime); + return LockMgr().SetYeardaySchedule(endpointId, yearDayIndex, userIndex, status, localStartTime, localEndTime); } DlStatus emberAfPluginDoorLockSetSchedule(chip::EndpointId endpointId, uint8_t holidayIndex, DlScheduleStatus status, diff --git a/src/platform/EFR32/EFR32Config.h b/src/platform/EFR32/EFR32Config.h index de279b8fca9bc4..09b07f6b240104 100644 --- a/src/platform/EFR32/EFR32Config.h +++ b/src/platform/EFR32/EFR32Config.h @@ -126,7 +126,6 @@ class EFR32Config static constexpr Key kConfigKey_YearDaySchedules = EFR32ConfigKey(kMatterConfig_KeyBase, 0x16); static constexpr Key kConfigKey_HolidaySchedules = EFR32ConfigKey(kMatterConfig_KeyBase, 0x17); - static constexpr Key kConfigKey_GroupKeyMax = EFR32ConfigKey(kMatterConfig_KeyBase, 0x1E); // Allows 16 Group Keys to be created. static constexpr Key kConfigKey_UniqueId = EFR32ConfigKey(kMatterFactory_KeyBase, 0x1F); From 9f9e906669a4caeccc6461b1e55bafd14e6a9edb Mon Sep 17 00:00:00 2001 From: Michael Rupp <95718139+mykrupp@users.noreply.github.com> Date: Tue, 28 Jun 2022 13:19:37 -0400 Subject: [PATCH 3/5] return true if programmingPin is given to GetCredential --- examples/lock-app/efr32/src/LockManager.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/examples/lock-app/efr32/src/LockManager.cpp b/examples/lock-app/efr32/src/LockManager.cpp index d3728680eed7d0..34b61d9215b834 100644 --- a/examples/lock-app/efr32/src/LockManager.cpp +++ b/examples/lock-app/efr32/src/LockManager.cpp @@ -363,12 +363,6 @@ bool LockManager::SetUser(chip::EndpointId endpointId, uint16_t userIndex, chip: bool LockManager::GetCredential(chip::EndpointId endpointId, uint16_t credentialIndex, DlCredentialType credentialType, EmberAfPluginDoorLockCredentialInfo & credential) const { - if ((credentialIndex < MIN_CREDENTIAL_INDEX) || (credentialIndex > MAX_CREDENTIAL_PER_USER)) - { - ChipLogError(Zcl, "Cannot get credential - credential index is out of range [endpoint=%d,index=%d]", endpointId, - credentialIndex); - return false; - } // door-lock-server checks for valid credential index uint16_t adjustedCredentialIndex = credentialIndex - 1; @@ -376,7 +370,15 @@ bool LockManager::GetCredential(chip::EndpointId endpointId, uint16_t credential ChipLogProgress(Zcl, "Lock App: LockManager::GetCredential [credentialType=%u], credentialIndex=%d", to_underlying(credentialType), adjustedCredentialIndex); + if(credentialType == DlCredentialType::kProgrammingPIN) + { + ChipLogError(Zcl, "Programming user not supported [credentialType=%u], credentialIndex=%d" , to_underlying(credentialType), adjustedCredentialIndex); + + return true; + } + const auto & credentialInStorage = mLockCredentials[adjustedCredentialIndex]; + credential.status = credentialInStorage.status; ChipLogDetail(Zcl, "CredentialStatus: %d, CredentialIndex: %d ", (int) credential.status, adjustedCredentialIndex); From 6849d6a451cf74eb0dff693ba7a71d4637221195 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Tue, 28 Jun 2022 17:19:57 +0000 Subject: [PATCH 4/5] Restyled by whitespace --- examples/lock-app/efr32/src/LockManager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/lock-app/efr32/src/LockManager.cpp b/examples/lock-app/efr32/src/LockManager.cpp index 34b61d9215b834..db293d9878b489 100644 --- a/examples/lock-app/efr32/src/LockManager.cpp +++ b/examples/lock-app/efr32/src/LockManager.cpp @@ -376,9 +376,9 @@ bool LockManager::GetCredential(chip::EndpointId endpointId, uint16_t credential return true; } - + const auto & credentialInStorage = mLockCredentials[adjustedCredentialIndex]; - + credential.status = credentialInStorage.status; ChipLogDetail(Zcl, "CredentialStatus: %d, CredentialIndex: %d ", (int) credential.status, adjustedCredentialIndex); From e3e9e9d196e6981ddbef1392016e0a39bc2f6cb7 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Tue, 28 Jun 2022 17:19:57 +0000 Subject: [PATCH 5/5] Restyled by clang-format --- examples/lock-app/efr32/src/LockManager.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/lock-app/efr32/src/LockManager.cpp b/examples/lock-app/efr32/src/LockManager.cpp index db293d9878b489..a73663680590d0 100644 --- a/examples/lock-app/efr32/src/LockManager.cpp +++ b/examples/lock-app/efr32/src/LockManager.cpp @@ -370,16 +370,16 @@ bool LockManager::GetCredential(chip::EndpointId endpointId, uint16_t credential ChipLogProgress(Zcl, "Lock App: LockManager::GetCredential [credentialType=%u], credentialIndex=%d", to_underlying(credentialType), adjustedCredentialIndex); - if(credentialType == DlCredentialType::kProgrammingPIN) + if (credentialType == DlCredentialType::kProgrammingPIN) { - ChipLogError(Zcl, "Programming user not supported [credentialType=%u], credentialIndex=%d" , to_underlying(credentialType), adjustedCredentialIndex); + ChipLogError(Zcl, "Programming user not supported [credentialType=%u], credentialIndex=%d", to_underlying(credentialType), + adjustedCredentialIndex); return true; } const auto & credentialInStorage = mLockCredentials[adjustedCredentialIndex]; - credential.status = credentialInStorage.status; ChipLogDetail(Zcl, "CredentialStatus: %d, CredentialIndex: %d ", (int) credential.status, adjustedCredentialIndex);