Skip to content

Commit a5da614

Browse files
committed
Update Chef Lock to enable user PIN and more
1 parent ac1ebc5 commit a5da614

9 files changed

+1800
-257
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
/*
2+
*
3+
* Copyright (c) 2020-2023 Project CHIP Authors
4+
* All rights reserved.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
#include <app/clusters/door-lock-server/door-lock-server.h>
20+
#include <app/data-model/Nullable.h>
21+
#include <app/util/af.h>
22+
#include <lib/core/DataModelTypes.h>
23+
24+
#include "chef-lock-manager.h"
25+
26+
using namespace chip;
27+
using namespace chip::app::Clusters;
28+
using namespace chip::app::Clusters::DoorLock;
29+
using chip::app::DataModel::Nullable;
30+
31+
// =============================================================================
32+
// 'Default' callbacks for cluster commands
33+
// =============================================================================
34+
35+
// App handles physical aspects of locking but not locking logic. That is it
36+
// should wait for door to be locked on lock command and return success) but
37+
// door lock server should check pin before even calling the lock-door
38+
// callback.
39+
bool emberAfPluginDoorLockOnDoorLockCommand(chip::EndpointId endpointId, const Nullable<chip::FabricIndex> & fabricIdx,
40+
const Nullable<chip::NodeId> & nodeId, const Optional<ByteSpan> & pinCode,
41+
OperationErrorEnum & err)
42+
{
43+
return LockManager::Instance().Lock(endpointId, fabricIdx, nodeId, pinCode, err, OperationSourceEnum::kRemote);
44+
}
45+
46+
bool emberAfPluginDoorLockOnDoorUnlockCommand(chip::EndpointId endpointId, const Nullable<chip::FabricIndex> & fabricIdx,
47+
const Nullable<chip::NodeId> & nodeId, const Optional<ByteSpan> & pinCode,
48+
OperationErrorEnum & err)
49+
{
50+
return LockManager::Instance().Unlock(endpointId, fabricIdx, nodeId, pinCode, err, OperationSourceEnum::kRemote);
51+
}
52+
53+
//UnlockWithTimeout
54+
55+
// =============================================================================
56+
// Users and credentials access callbacks
57+
// =============================================================================
58+
59+
// SetWeekDaySchedule
60+
DlStatus emberAfPluginDoorLockSetSchedule(chip::EndpointId endpointId, uint8_t weekdayIndex, uint16_t userIndex,
61+
DlScheduleStatus status, DaysMaskMap daysMask, uint8_t startHour, uint8_t startMinute,
62+
uint8_t endHour, uint8_t endMinute)
63+
{
64+
return LockManager::Instance().SetSchedule(endpointId, weekdayIndex, userIndex, status, daysMask, startHour, startMinute,
65+
endHour, endMinute);
66+
}
67+
68+
// GetWeekDaySchedule
69+
DlStatus emberAfPluginDoorLockGetSchedule(chip::EndpointId endpointId, uint8_t weekdayIndex, uint16_t userIndex,
70+
EmberAfPluginDoorLockWeekDaySchedule & schedule)
71+
{
72+
return LockManager::Instance().GetSchedule(endpointId, weekdayIndex, userIndex, schedule);
73+
}
74+
75+
// emberAfDoorLockClusterClearWeekDayScheduleCallback was handled in src/app/clusters/door-lock-server/door-lock-server.cpp
76+
// And finally call into emberAfPluginDoorLockSetSchedule
77+
78+
// SetYearDaySchedule
79+
DlStatus emberAfPluginDoorLockSetSchedule(chip::EndpointId endpointId, uint8_t yearDayIndex, uint16_t userIndex,
80+
DlScheduleStatus status, uint32_t localStartTime, uint32_t localEndTime)
81+
{
82+
return LockManager::Instance().SetSchedule(endpointId, yearDayIndex, userIndex, status, localStartTime, localEndTime);
83+
}
84+
85+
// GetYearDaySchedule
86+
DlStatus emberAfPluginDoorLockGetSchedule(chip::EndpointId endpointId, uint8_t yearDayIndex, uint16_t userIndex,
87+
EmberAfPluginDoorLockYearDaySchedule & schedule)
88+
{
89+
return LockManager::Instance().GetSchedule(endpointId, yearDayIndex, userIndex, schedule);
90+
}
91+
92+
// emberAfDoorLockClusterClearYearDayScheduleCallback was handled in src/app/clusters/door-lock-server/door-lock-server.cpp
93+
// And finally call into emberAfPluginDoorLockSetSchedule
94+
95+
// SetHolidaySchedule
96+
DlStatus emberAfPluginDoorLockSetSchedule(chip::EndpointId endpointId, uint8_t holidayIndex, DlScheduleStatus status,
97+
uint32_t localStartTime, uint32_t localEndTime, OperatingModeEnum operatingMode)
98+
{
99+
return LockManager::Instance().SetSchedule(endpointId, holidayIndex, status, localStartTime, localEndTime, operatingMode);
100+
}
101+
102+
// GetHolidaySchedule
103+
DlStatus emberAfPluginDoorLockGetSchedule(chip::EndpointId endpointId, uint8_t holidayIndex,
104+
EmberAfPluginDoorLockHolidaySchedule & schedule)
105+
{
106+
return LockManager::Instance().GetSchedule(endpointId, holidayIndex, schedule);
107+
}
108+
109+
// emberAfDoorLockClusterClearHolidayScheduleCallback was handled in src/app/clusters/door-lock-server/door-lock-server.cpp
110+
// And finally call into emberAfPluginDoorLockSetSchedule
111+
112+
// SetUser
113+
bool emberAfPluginDoorLockSetUser(chip::EndpointId endpointId, uint16_t userIndex, chip::FabricIndex creator,
114+
chip::FabricIndex modifier, const chip::CharSpan & userName, uint32_t uniqueId,
115+
UserStatusEnum userStatus, UserTypeEnum usertype, CredentialRuleEnum credentialRule,
116+
const CredentialStruct * credentials, size_t totalCredentials)
117+
{
118+
119+
return LockManager::Instance().SetUser(endpointId, userIndex, creator, modifier, userName, uniqueId, userStatus, usertype,
120+
credentialRule, credentials, totalCredentials);
121+
}
122+
123+
// GetUser
124+
bool emberAfPluginDoorLockGetUser(chip::EndpointId endpointId, uint16_t userIndex, EmberAfPluginDoorLockUserInfo & user)
125+
{
126+
return LockManager::Instance().GetUser(endpointId, userIndex, user);
127+
}
128+
129+
// emberAfDoorLockClusterClearUserCallback was handled in src/app/clusters/door-lock-server/door-lock-server.cpp
130+
// And finally call into emberAfPluginDoorLockSetCredential and emberAfPluginDoorLockSetUser
131+
132+
// SetCredential
133+
bool emberAfPluginDoorLockSetCredential(chip::EndpointId endpointId, uint16_t credentialIndex, chip::FabricIndex creator,
134+
chip::FabricIndex modifier, DlCredentialStatus credentialStatus,
135+
CredentialTypeEnum credentialType, const chip::ByteSpan & credentialData)
136+
{
137+
return LockManager::Instance().SetCredential(endpointId, credentialIndex, creator, modifier, credentialStatus, credentialType,
138+
credentialData);
139+
}
140+
141+
// GetCredential
142+
bool emberAfPluginDoorLockGetCredential(chip::EndpointId endpointId, uint16_t credentialIndex, CredentialTypeEnum credentialType,
143+
EmberAfPluginDoorLockCredentialInfo & credential)
144+
{
145+
return LockManager::Instance().GetCredential(endpointId, credentialIndex, credentialType, credential);
146+
}
147+
148+
// emberAfDoorLockClusterClearCredentialCallback was handled in src/app/clusters/door-lock-server/door-lock-server.cpp
149+
// And finally call into emberAfPluginDoorLockSetCredential and emberAfPluginDoorLockSetUser
150+
151+
// UnboltDoor
152+
bool emberAfPluginDoorLockOnDoorUnboltCommand(chip::EndpointId endpointId, const Nullable<chip::FabricIndex> & fabricIdx,
153+
const Nullable<chip::NodeId> & nodeId, const Optional<ByteSpan> & pinCode,
154+
OperationErrorEnum & err)
155+
{
156+
return LockManager::Instance().Unbolt(endpointId, fabricIdx, nodeId, pinCode, err, OperationSourceEnum::kRemote);
157+
}
158+
159+
void emberAfDoorLockClusterInitCallback(EndpointId endpoint)
160+
{
161+
DoorLockServer::Instance().InitServer(endpoint);
162+
LockManager::Instance().InitEndpoint(endpoint);
163+
}

0 commit comments

Comments
 (0)