Skip to content

Commit

Permalink
Implement holiday schedules (#18711)
Browse files Browse the repository at this point in the history
* Enable holiday schedules in the lock-app and chip-tool

* Add draft server implementation of door lock holiday schedules

* Add draft linux app implementation of door lock holiday schedules

* Add tests for schedules

* Fix tests and failures found by tests in holiday schedules for the door lock

* Update auto-generated files
  • Loading branch information
Morozov-5F authored May 26, 2022
1 parent 0219efa commit b5a967c
Show file tree
Hide file tree
Showing 17 changed files with 5,250 additions and 1,061 deletions.
18 changes: 16 additions & 2 deletions examples/lock-app/linux/include/LockEndpoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,22 @@ struct LockUserInfo
struct LockCredentialInfo;
struct WeekDaysScheduleInfo;
struct YearDayScheduleInfo;
struct HolidayScheduleInfo;

static constexpr size_t DOOR_LOCK_CREDENTIAL_INFO_MAX_DATA_SIZE = 20;

class LockEndpoint
{
public:
LockEndpoint(chip::EndpointId endpointId, uint16_t numberOfLockUsersSupported, uint16_t numberOfCredentialsSupported,
uint8_t weekDaySchedulesPerUser, uint8_t yearDaySchedulesPerUser, uint8_t numberOfCredentialsPerUser) :
uint8_t weekDaySchedulesPerUser, uint8_t yearDaySchedulesPerUser, uint8_t numberOfCredentialsPerUser,
uint8_t numberOfHolidaySchedules) :
mEndpointId{ endpointId },
mLockState{ DlLockState::kLocked }, mLockUsers(numberOfLockUsersSupported),
mLockCredentials(numberOfCredentialsSupported + 1),
mWeekDaySchedules(numberOfLockUsersSupported, std::vector<WeekDaysScheduleInfo>(weekDaySchedulesPerUser)),
mYearDaySchedules(numberOfLockUsersSupported, std::vector<YearDayScheduleInfo>(yearDaySchedulesPerUser))
mYearDaySchedules(numberOfLockUsersSupported, std::vector<YearDayScheduleInfo>(yearDaySchedulesPerUser)),
mHolidaySchedules(numberOfHolidaySchedules)
{
for (auto & lockUser : mLockUsers)
{
Expand All @@ -74,10 +77,14 @@ class LockEndpoint

DlStatus GetSchedule(uint8_t weekDayIndex, uint16_t userIndex, EmberAfPluginDoorLockWeekDaySchedule & schedule);
DlStatus GetSchedule(uint8_t yearDayIndex, uint16_t userIndex, EmberAfPluginDoorLockYearDaySchedule & schedule);
DlStatus GetSchedule(uint8_t holidayIndex, EmberAfPluginDoorLockHolidaySchedule & schedule);

DlStatus SetSchedule(uint8_t weekDayIndex, uint16_t userIndex, DlScheduleStatus status, DlDaysMaskMap daysMask,
uint8_t startHour, uint8_t startMinute, uint8_t endHour, uint8_t endMinute);
DlStatus SetSchedule(uint8_t yearDayIndex, uint16_t userIndex, DlScheduleStatus status, uint32_t localStartTime,
uint32_t localEndTime);
DlStatus SetSchedule(uint8_t holidayIndex, DlScheduleStatus status, uint32_t localStartTime, uint32_t localEndTime,
DlOperatingMode operatingMode);

private:
bool setLockState(DlLockState lockState, const Optional<chip::ByteSpan> & pin, DlOperationError & err);
Expand All @@ -92,6 +99,7 @@ class LockEndpoint
std::vector<LockCredentialInfo> mLockCredentials;
std::vector<std::vector<WeekDaysScheduleInfo>> mWeekDaySchedules;
std::vector<std::vector<YearDayScheduleInfo>> mYearDaySchedules;
std::vector<HolidayScheduleInfo> mHolidaySchedules;
};

struct LockCredentialInfo
Expand All @@ -115,3 +123,9 @@ struct YearDayScheduleInfo
DlScheduleStatus status;
EmberAfPluginDoorLockYearDaySchedule schedule;
};

struct HolidayScheduleInfo
{
DlScheduleStatus status;
EmberAfPluginDoorLockHolidaySchedule schedule;
};
4 changes: 4 additions & 0 deletions examples/lock-app/linux/include/LockManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,14 @@ class LockManager
EmberAfPluginDoorLockWeekDaySchedule & schedule);
DlStatus GetSchedule(chip::EndpointId endpointId, uint8_t yearDayIndex, uint16_t userIndex,
EmberAfPluginDoorLockYearDaySchedule & schedule);
DlStatus GetSchedule(chip::EndpointId endpointId, uint8_t holidayIndex, EmberAfPluginDoorLockHolidaySchedule & schedule);

DlStatus SetSchedule(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 SetSchedule(chip::EndpointId endpointId, uint8_t yearDayIndex, uint16_t userIndex, DlScheduleStatus status,
uint32_t localStartTime, uint32_t localEndTime);
DlStatus SetSchedule(chip::EndpointId endpointId, uint8_t holidayIndex, DlScheduleStatus status, uint32_t localStartTime,
uint32_t localEndTime, DlOperatingMode operatingMode);

static LockManager & Instance();

Expand Down
34 changes: 34 additions & 0 deletions examples/lock-app/linux/src/LockEndpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,40 @@ DlStatus LockEndpoint::SetSchedule(uint8_t yearDayIndex, uint16_t userIndex, DlS
return DlStatus::kSuccess;
}

DlStatus LockEndpoint::GetSchedule(uint8_t holidayIndex, EmberAfPluginDoorLockHolidaySchedule & schedule)
{
if (0 == holidayIndex || holidayIndex > mHolidaySchedules.size())
{
return DlStatus::kFailure;
}

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

schedule = scheduleInStorage.schedule;
return DlStatus::kSuccess;
}

DlStatus LockEndpoint::SetSchedule(uint8_t holidayIndex, DlScheduleStatus status, uint32_t localStartTime, uint32_t localEndTime,
DlOperatingMode operatingMode)
{
if (0 == holidayIndex || holidayIndex > mHolidaySchedules.size())
{
return DlStatus::kFailure;
}

auto & scheduleInStorage = mHolidaySchedules[holidayIndex - 1];
scheduleInStorage.schedule.localStartTime = localStartTime;
scheduleInStorage.schedule.localEndTime = localEndTime;
scheduleInStorage.schedule.operatingMode = operatingMode;
scheduleInStorage.status = status;

return DlStatus::kSuccess;
}

bool LockEndpoint::setLockState(DlLockState lockState, const Optional<chip::ByteSpan> & pin, DlOperationError & err)
{
if (!pin.HasValue())
Expand Down
42 changes: 39 additions & 3 deletions examples/lock-app/linux/src/LockManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,25 @@ bool LockManager::InitEndpoint(chip::EndpointId endpointId)
numberOfYearDaySchedulesPerUser = 10;
}

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

mEndpoints.emplace_back(endpointId, numberOfSupportedUsers, numberOfSupportedCredentials, numberOfWeekDaySchedulesPerUser,
numberOfYearDaySchedulesPerUser, numberOfCredentialsSupportedPerUser);
numberOfYearDaySchedulesPerUser, numberOfCredentialsSupportedPerUser, numberOfHolidaySchedules);

ChipLogProgress(Zcl,
"Initialized new lock door endpoint "
"[id=%d,users=%d,credentials=%d,weekDaySchedulesPerUser=%d,yearDaySchedulesPerUser=%d,"
"numberOfCredentialsSupportedPerUser=%d]",
"numberOfCredentialsSupportedPerUser=%d,holidaySchedules=%d]",
endpointId, numberOfSupportedUsers, numberOfSupportedCredentials, numberOfWeekDaySchedulesPerUser,
numberOfYearDaySchedulesPerUser, numberOfCredentialsSupportedPerUser);
numberOfYearDaySchedulesPerUser, numberOfCredentialsSupportedPerUser, numberOfHolidaySchedules);

return true;
}
Expand Down Expand Up @@ -227,6 +237,32 @@ DlStatus LockManager::SetSchedule(chip::EndpointId endpointId, uint8_t yearDayIn
return lockEndpoint->SetSchedule(yearDayIndex, userIndex, status, localStartTime, localEndTime);
}

DlStatus LockManager::GetSchedule(chip::EndpointId endpointId, uint8_t holidayIndex,
EmberAfPluginDoorLockHolidaySchedule & schedule)
{
auto lockEndpoint = getEndpoint(endpointId);
if (nullptr == lockEndpoint)
{
ChipLogError(Zcl, "Unable to get the holiday schedule - endpoint does not exist or not initialized [endpointId=%d]",
endpointId);
return DlStatus::kFailure;
}
return lockEndpoint->GetSchedule(holidayIndex, schedule);
}

DlStatus LockManager::SetSchedule(chip::EndpointId endpointId, uint8_t holidayIndex, DlScheduleStatus status,
uint32_t localStartTime, uint32_t localEndTime, DlOperatingMode operatingMode)
{
auto lockEndpoint = getEndpoint(endpointId);
if (nullptr == lockEndpoint)
{
ChipLogError(Zcl, "Unable to set the holiday schedule - endpoint does not exist or not initialized [endpointId=%d]",
endpointId);
return DlStatus::kFailure;
}
return lockEndpoint->SetSchedule(holidayIndex, status, localStartTime, localEndTime, operatingMode);
}

LockEndpoint * LockManager::getEndpoint(chip::EndpointId endpointId)
{
for (auto & mEndpoint : mEndpoints)
Expand Down
12 changes: 12 additions & 0 deletions examples/lock-app/linux/src/ZCLDoorLockCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ DlStatus emberAfPluginDoorLockGetSchedule(chip::EndpointId endpointId, uint8_t w
return LockManager::Instance().GetSchedule(endpointId, weekdayIndex, userIndex, schedule);
}

DlStatus emberAfPluginDoorLockGetSchedule(chip::EndpointId endpointId, uint8_t holidayIndex,
EmberAfPluginDoorLockHolidaySchedule & schedule)
{
return LockManager::Instance().GetSchedule(endpointId, holidayIndex, schedule);
}

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)
Expand All @@ -76,6 +82,12 @@ DlStatus emberAfPluginDoorLockGetSchedule(chip::EndpointId endpointId, uint8_t y
return LockManager::Instance().GetSchedule(endpointId, yearDayIndex, userIndex, schedule);
}

DlStatus emberAfPluginDoorLockSetSchedule(chip::EndpointId endpointId, uint8_t holidayIndex, DlScheduleStatus status,
uint32_t localStartTime, uint32_t localEndTime, DlOperatingMode operatingMode)
{
return LockManager::Instance().SetSchedule(endpointId, holidayIndex, status, localStartTime, localEndTime, operatingMode);
}

void MatterPostAttributeChangeCallback(const chip::app::ConcreteAttributePath & attributePath, uint8_t type, uint16_t size,
uint8_t * value)
{
Expand Down
28 changes: 28 additions & 0 deletions examples/lock-app/lock-common/lock-app.matter
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,7 @@ server cluster DoorLock = 257 {
readonly attribute int16u numberOfRFIDUsersSupported = 19;
readonly attribute int8u numberOfWeekDaySchedulesSupportedPerUser = 20;
readonly attribute int8u numberOfYearDaySchedulesSupportedPerUser = 21;
readonly attribute int8u numberOfHolidaySchedulesSupported = 22;
readonly attribute int8u maxPINCodeLength = 23;
readonly attribute int8u minPINCodeLength = 24;
readonly attribute int8u maxRFIDCodeLength = 25;
Expand Down Expand Up @@ -656,6 +657,21 @@ server cluster DoorLock = 257 {
INT16U userIndex = 1;
}

request struct SetHolidayScheduleRequest {
INT8U holidayIndex = 0;
epoch_s localStartTime = 1;
epoch_s localEndTime = 2;
DlOperatingMode operatingMode = 3;
}

request struct GetHolidayScheduleRequest {
INT8U holidayIndex = 0;
}

request struct ClearHolidayScheduleRequest {
INT8U holidayIndex = 0;
}

request struct SetUserRequest {
DlDataOperationType operationType = 0;
INT16U userIndex = 1;
Expand Down Expand Up @@ -710,6 +726,14 @@ server cluster DoorLock = 257 {
optional epoch_s localEndTime = 4;
}

response struct GetHolidayScheduleResponse = 18 {
INT8U holidayIndex = 0;
DlStatus status = 1;
optional epoch_s localStartTime = 2;
optional epoch_s localEndTime = 3;
optional DlOperatingMode operatingMode = 4;
}

response struct GetUserResponse = 28 {
INT16U userIndex = 0;
nullable CHAR_STRING userName = 1;
Expand Down Expand Up @@ -746,6 +770,9 @@ server cluster DoorLock = 257 {
command access(invoke: administer) SetYearDaySchedule(SetYearDayScheduleRequest): DefaultSuccess = 14;
command access(invoke: administer) GetYearDaySchedule(GetYearDayScheduleRequest): GetYearDayScheduleResponse = 15;
command access(invoke: administer) ClearYearDaySchedule(ClearYearDayScheduleRequest): DefaultSuccess = 16;
command access(invoke: administer) SetHolidaySchedule(SetHolidayScheduleRequest): DefaultSuccess = 17;
command access(invoke: administer) GetHolidaySchedule(GetHolidayScheduleRequest): GetHolidayScheduleResponse = 18;
command access(invoke: administer) ClearHolidaySchedule(ClearHolidayScheduleRequest): DefaultSuccess = 19;
timed command access(invoke: administer) SetUser(SetUserRequest): DefaultSuccess = 26;
command access(invoke: administer) GetUser(GetUserRequest): GetUserResponse = 27;
timed command access(invoke: administer) ClearUser(ClearUserRequest): DefaultSuccess = 29;
Expand Down Expand Up @@ -2144,6 +2171,7 @@ endpoint 1 {
ram attribute numberOfRFIDUsersSupported default = 10;
ram attribute numberOfWeekDaySchedulesSupportedPerUser default = 10;
ram attribute numberOfYearDaySchedulesSupportedPerUser default = 10;
ram attribute numberOfHolidaySchedulesSupported default = 10;
ram attribute maxPINCodeLength default = 8;
ram attribute minPINCodeLength default = 6;
ram attribute maxRFIDCodeLength default = 20;
Expand Down
39 changes: 36 additions & 3 deletions examples/lock-app/lock-common/lock-app.zap
Original file line number Diff line number Diff line change
Expand Up @@ -7133,6 +7133,30 @@
"incoming": 1,
"outgoing": 0
},
{
"name": "SetHolidaySchedule",
"code": 17,
"mfgCode": null,
"source": "client",
"incoming": 1,
"outgoing": 0
},
{
"name": "GetHolidaySchedule",
"code": 18,
"mfgCode": null,
"source": "client",
"incoming": 1,
"outgoing": 0
},
{
"name": "ClearHolidaySchedule",
"code": 19,
"mfgCode": null,
"source": "client",
"incoming": 1,
"outgoing": 0
},
{
"name": "SetUser",
"code": 26,
Expand Down Expand Up @@ -7225,6 +7249,14 @@
"incoming": 0,
"outgoing": 1
},
{
"name": "GetHolidayScheduleResponse",
"code": 18,
"mfgCode": null,
"source": "server",
"incoming": 0,
"outgoing": 1
},
{
"name": "GetUserResponse",
"code": 28,
Expand Down Expand Up @@ -7465,11 +7497,11 @@
"mfgCode": null,
"side": "server",
"type": "int8u",
"included": 0,
"included": 1,
"storageOption": "RAM",
"singleton": 0,
"bounded": 0,
"defaultValue": "0",
"defaultValue": "10",
"reportable": 1,
"minInterval": 1,
"maxInterval": 65534,
Expand Down Expand Up @@ -8193,5 +8225,6 @@
"endpointVersion": 1,
"deviceIdentifier": 10
}
]
],
"log": []
}
Loading

0 comments on commit b5a967c

Please sign in to comment.