Skip to content

Commit

Permalink
Fix efr32 app to return NotFound if no schedule exists (#21810)
Browse files Browse the repository at this point in the history
* Fix efr32 app to return NotFound if no schedule exists

* rekick ci
  • Loading branch information
mykrupp authored and pull[bot] committed Aug 21, 2023
1 parent 4b1d884 commit c109be2
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 21 deletions.
27 changes: 21 additions & 6 deletions examples/lock-app/efr32/include/LockManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,24 @@

#include <lib/core/CHIPError.h>

struct WeekDaysScheduleInfo
{
DlScheduleStatus status;
EmberAfPluginDoorLockWeekDaySchedule schedule;
};

struct YearDayScheduleInfo
{
DlScheduleStatus status;
EmberAfPluginDoorLockYearDaySchedule schedule;
};

struct HolidayScheduleInfo
{
DlScheduleStatus status;
EmberAfPluginDoorLockHolidaySchedule schedule;
};

namespace EFR32DoorLock {
namespace ResourceRanges {
// Used to size arrays
Expand All @@ -39,9 +57,6 @@ static constexpr uint8_t kMaxYeardaySchedulesPerUser = 10;
static constexpr uint8_t kMaxHolidaySchedules = 10;
static constexpr uint8_t kMaxCredentialSize = 8;

// Indices received for user/credential/schedules are 1-indexed
static constexpr uint8_t kStartIndexValue = 1;

static constexpr uint8_t kMaxCredentials = kMaxUsers * kMaxCredentialsPerUser;
} // namespace ResourceRanges

Expand Down Expand Up @@ -185,9 +200,9 @@ class LockManager

EmberAfPluginDoorLockUserInfo mLockUsers[kMaxUsers];
EmberAfPluginDoorLockCredentialInfo mLockCredentials[kMaxCredentials];
EmberAfPluginDoorLockWeekDaySchedule mWeekdaySchedule[kMaxUsers][kMaxWeekdaySchedulesPerUser];
EmberAfPluginDoorLockYearDaySchedule mYeardaySchedule[kMaxUsers][kMaxYeardaySchedulesPerUser];
EmberAfPluginDoorLockHolidaySchedule mHolidaySchedule[kMaxHolidaySchedules];
WeekDaysScheduleInfo mWeekdaySchedule[kMaxUsers][kMaxWeekdaySchedulesPerUser];
YearDayScheduleInfo mYeardaySchedule[kMaxUsers][kMaxYeardaySchedulesPerUser];
HolidayScheduleInfo mHolidaySchedule[kMaxHolidaySchedules];

char mUserNames[ArraySize(mLockUsers)][DOOR_LOCK_MAX_USER_NAME_SIZE];
uint8_t mCredentialData[kMaxCredentials][kMaxCredentialSize];
Expand Down
47 changes: 32 additions & 15 deletions examples/lock-app/efr32/src/LockManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,13 @@ DlStatus LockManager::GetWeekdaySchedule(chip::EndpointId endpointId, uint8_t we
VerifyOrReturnValue(IsValidWeekdayScheduleIndex(weekdayIndex), DlStatus::kFailure);
VerifyOrReturnValue(IsValidUserIndex(userIndex), DlStatus::kFailure);

schedule = mWeekdaySchedule[userIndex][weekdayIndex];
const auto & scheduleInStorage = mWeekdaySchedule[userIndex][weekdayIndex];
if (DlScheduleStatus::kAvailable == scheduleInStorage.status)
{
return DlStatus::kNotFound;
}

schedule = scheduleInStorage.schedule;

return DlStatus::kSuccess;
}
Expand All @@ -518,11 +524,12 @@ DlStatus LockManager::SetWeekdaySchedule(chip::EndpointId endpointId, uint8_t we

auto & scheduleInStorage = mWeekdaySchedule[userIndex][weekdayIndex];

scheduleInStorage.daysMask = daysMask;
scheduleInStorage.startHour = startHour;
scheduleInStorage.startMinute = startMinute;
scheduleInStorage.endHour = endHour;
scheduleInStorage.endMinute = endMinute;
scheduleInStorage.schedule.daysMask = daysMask;
scheduleInStorage.schedule.startHour = startHour;
scheduleInStorage.schedule.startMinute = startMinute;
scheduleInStorage.schedule.endHour = endHour;
scheduleInStorage.schedule.endMinute = endMinute;
scheduleInStorage.status = status;

// Save schedule information in NVM flash
EFR32Config::WriteConfigValueBin(EFR32Config::kConfigKey_WeekDaySchedules, reinterpret_cast<const uint8_t *>(mWeekdaySchedule),
Expand All @@ -544,9 +551,13 @@ DlStatus LockManager::GetYeardaySchedule(chip::EndpointId endpointId, uint8_t ye
VerifyOrReturnValue(IsValidYeardayScheduleIndex(yearDayIndex), DlStatus::kFailure);
VerifyOrReturnValue(IsValidUserIndex(userIndex), DlStatus::kFailure);

auto & scheduleInStorage = mYeardaySchedule[userIndex][yearDayIndex];
const auto & scheduleInStorage = mYeardaySchedule[userIndex][yearDayIndex];
if (DlScheduleStatus::kAvailable == scheduleInStorage.status)
{
return DlStatus::kNotFound;
}

schedule = scheduleInStorage;
schedule = scheduleInStorage.schedule;

return DlStatus::kSuccess;
}
Expand All @@ -565,8 +576,9 @@ DlStatus LockManager::SetYeardaySchedule(chip::EndpointId endpointId, uint8_t ye

auto & scheduleInStorage = mYeardaySchedule[userIndex][yearDayIndex];

scheduleInStorage.localStartTime = localStartTime;
scheduleInStorage.localEndTime = localEndTime;
scheduleInStorage.schedule.localStartTime = localStartTime;
scheduleInStorage.schedule.localEndTime = localEndTime;
scheduleInStorage.status = status;

// Save schedule information in NVM flash
EFR32Config::WriteConfigValueBin(EFR32Config::kConfigKey_YearDaySchedules, reinterpret_cast<const uint8_t *>(mYeardaySchedule),
Expand All @@ -585,9 +597,13 @@ DlStatus LockManager::GetHolidaySchedule(chip::EndpointId endpointId, uint8_t ho

VerifyOrReturnValue(IsValidHolidayScheduleIndex(holidayIndex), DlStatus::kFailure);

auto & scheduleInStorage = mHolidaySchedule[holidayIndex];
const auto & scheduleInStorage = mHolidaySchedule[holidayIndex];
if (DlScheduleStatus::kAvailable == scheduleInStorage.status)
{
return DlStatus::kNotFound;
}

schedule = scheduleInStorage;
schedule = scheduleInStorage.schedule;

return DlStatus::kSuccess;
}
Expand All @@ -603,9 +619,10 @@ DlStatus LockManager::SetHolidaySchedule(chip::EndpointId endpointId, uint8_t ho

auto & scheduleInStorage = mHolidaySchedule[holidayIndex];

scheduleInStorage.localStartTime = localStartTime;
scheduleInStorage.localEndTime = localEndTime;
scheduleInStorage.operatingMode = operatingMode;
scheduleInStorage.schedule.localStartTime = localStartTime;
scheduleInStorage.schedule.localEndTime = localEndTime;
scheduleInStorage.schedule.operatingMode = operatingMode;
scheduleInStorage.status = status;

// Save schedule information in NVM flash
EFR32Config::WriteConfigValueBin(EFR32Config::kConfigKey_HolidaySchedules,
Expand Down

0 comments on commit c109be2

Please sign in to comment.