Fix efr32 app to return NotFound if no schedule exists (#21810)
* Fix efr32 app to return NotFound if no schedule exists
* rekick ci
diff --git a/examples/lock-app/efr32/include/LockManager.h b/examples/lock-app/efr32/include/LockManager.h
index 0e6a3d5..e2a6b7f 100644
--- a/examples/lock-app/efr32/include/LockManager.h
+++ b/examples/lock-app/efr32/include/LockManager.h
@@ -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
@@ -39,9 +57,6 @@
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
@@ -185,9 +200,9 @@
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];
diff --git a/examples/lock-app/efr32/src/LockManager.cpp b/examples/lock-app/efr32/src/LockManager.cpp
index 63ce72e..4e7e17b 100644
--- a/examples/lock-app/efr32/src/LockManager.cpp
+++ b/examples/lock-app/efr32/src/LockManager.cpp
@@ -497,7 +497,13 @@
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;
}
@@ -518,11 +524,12 @@
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),
@@ -544,9 +551,13 @@
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;
}
@@ -565,8 +576,9 @@
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),
@@ -585,9 +597,13 @@
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;
}
@@ -603,9 +619,10 @@
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,