From e5c39d460974a2819ace470d3f508a933cfdca93 Mon Sep 17 00:00:00 2001 From: krypton36 Date: Fri, 25 Mar 2022 21:01:08 -0700 Subject: [PATCH] Add Door Lock management to all clusters app. (#16687) --- examples/all-clusters-app/linux/BUILD.gn | 9 +- examples/door-lock-app/linux/BUILD.gn | 1 + examples/door-lock-app/linux/main.cpp | 93 ------------------- .../linux/src/ZCLDoorLockCallbacks.cpp | 91 ++++++++++++++++++ 4 files changed, 99 insertions(+), 95 deletions(-) create mode 100644 examples/door-lock-app/linux/src/ZCLDoorLockCallbacks.cpp diff --git a/examples/all-clusters-app/linux/BUILD.gn b/examples/all-clusters-app/linux/BUILD.gn index 36d3d0aa3c10a9..c2b386767c7f96 100644 --- a/examples/all-clusters-app/linux/BUILD.gn +++ b/examples/all-clusters-app/linux/BUILD.gn @@ -23,6 +23,9 @@ source_set("chip-all-clusters-common") { "${chip_root}/examples/all-clusters-app/all-clusters-common/src/binding-handler.cpp", "${chip_root}/examples/all-clusters-app/all-clusters-common/src/bridged-actions-stub.cpp", "${chip_root}/examples/all-clusters-app/all-clusters-common/src/static-supported-modes-manager.cpp", + "${chip_root}/examples/door-lock-app/linux/src/LockEndpoint.cpp", + "${chip_root}/examples/door-lock-app/linux/src/LockManager.cpp", + "${chip_root}/examples/door-lock-app/linux/src/ZCLDoorLockCallbacks.cpp", "include/tv-callbacks.cpp", "include/tv-callbacks.h", "main-common.cpp", @@ -34,8 +37,10 @@ source_set("chip-all-clusters-common") { "${chip_root}/src/lib", ] - include_dirs = - [ "${chip_root}/examples/all-clusters-app/all-clusters-common/include" ] + include_dirs = [ + "${chip_root}/examples/all-clusters-app/all-clusters-common/include", + "${chip_root}/examples/door-lock-app/linux/include", + ] cflags = [ "-Wconversion" ] diff --git a/examples/door-lock-app/linux/BUILD.gn b/examples/door-lock-app/linux/BUILD.gn index ff0f13d217d852..90dd96b3d23bb1 100644 --- a/examples/door-lock-app/linux/BUILD.gn +++ b/examples/door-lock-app/linux/BUILD.gn @@ -20,6 +20,7 @@ executable("chip-door-lock-app") { "main.cpp", "src/LockEndpoint.cpp", "src/LockManager.cpp", + "src/ZCLDoorLockCallbacks.cpp", ] deps = [ diff --git a/examples/door-lock-app/linux/main.cpp b/examples/door-lock-app/linux/main.cpp index 542d901191e5d2..5f7f27c7d9d96e 100644 --- a/examples/door-lock-app/linux/main.cpp +++ b/examples/door-lock-app/linux/main.cpp @@ -16,101 +16,8 @@ * limitations under the License. */ -#include -#include - -#include "LockManager.h" - #include "AppMain.h" -using namespace chip; -using namespace chip::app::Clusters; -using namespace chip::app::Clusters::DoorLock; - -// App handles physical aspects of locking but not locking logic. That is it -// should wait for door to be locked on lock command and return success) but -// door lock server should check pin before even calling the lock-door -// callback. -bool emberAfPluginDoorLockOnDoorLockCommand(chip::EndpointId endpointId, const Optional & pinCode, DlOperationError & err) -{ - return LockManager::Instance().Lock(endpointId, pinCode, err); -} - -bool emberAfPluginDoorLockOnDoorUnlockCommand(chip::EndpointId endpointId, const Optional & pinCode, - DlOperationError & err) -{ - return LockManager::Instance().Unlock(endpointId, pinCode, err); -} - -bool emberAfPluginDoorLockGetUser(chip::EndpointId endpointId, uint16_t userIndex, EmberAfPluginDoorLockUserInfo & user) -{ - return LockManager::Instance().GetUser(endpointId, userIndex, user); -} - -bool emberAfPluginDoorLockSetUser(chip::EndpointId endpointId, uint16_t userIndex, chip::FabricIndex creator, - chip::FabricIndex modifier, const chip::CharSpan & userName, uint32_t uniqueId, - DlUserStatus userStatus, DlUserType usertype, DlCredentialRule credentialRule, - const DlCredential * credentials, size_t totalCredentials) -{ - - return LockManager::Instance().SetUser(endpointId, userIndex, creator, modifier, userName, uniqueId, userStatus, usertype, - credentialRule, credentials, totalCredentials); -} - -bool emberAfPluginDoorLockGetCredential(chip::EndpointId endpointId, uint16_t credentialIndex, DlCredentialType credentialType, - EmberAfPluginDoorLockCredentialInfo & credential) -{ - return LockManager::Instance().GetCredential(endpointId, credentialIndex, credentialType, credential); -} - -bool emberAfPluginDoorLockSetCredential(chip::EndpointId endpointId, uint16_t credentialIndex, DlCredentialStatus credentialStatus, - DlCredentialType credentialType, const chip::ByteSpan & credentialData) -{ - return LockManager::Instance().SetCredential(endpointId, credentialIndex, credentialStatus, credentialType, credentialData); -} - -DlStatus emberAfPluginDoorLockGetSchedule(chip::EndpointId endpointId, uint8_t weekdayIndex, uint16_t userIndex, - EmberAfPluginDoorLockWeekDaySchedule & schedule) -{ - return LockManager::Instance().GetSchedule(endpointId, weekdayIndex, userIndex, 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) -{ - return LockManager::Instance().SetSchedule(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 LockManager::Instance().SetSchedule(endpointId, yearDayIndex, userIndex, status, localStartTime, localEndTime); -} - -DlStatus emberAfPluginDoorLockGetSchedule(chip::EndpointId endpointId, uint8_t yearDayIndex, uint16_t userIndex, - EmberAfPluginDoorLockYearDaySchedule & schedule) -{ - return LockManager::Instance().GetSchedule(endpointId, yearDayIndex, userIndex, schedule); -} - -void MatterPostAttributeChangeCallback(const chip::app::ConcreteAttributePath & attributePath, uint8_t mask, uint8_t type, - uint16_t size, uint8_t * value) -{ - // TODO: Watch for LockState, DoorState, Mode, etc changes and trigger appropriate action - if (attributePath.mClusterId == DoorLock::Id) - { - emberAfDoorLockClusterPrintln("Door Lock attribute changed"); - } -} - -void emberAfDoorLockClusterInitCallback(EndpointId endpoint) -{ - DoorLockServer::Instance().InitServer(endpoint); - LockManager::Instance().InitEndpoint(endpoint); -} - void ApplicationInit() {} int main(int argc, char * argv[]) diff --git a/examples/door-lock-app/linux/src/ZCLDoorLockCallbacks.cpp b/examples/door-lock-app/linux/src/ZCLDoorLockCallbacks.cpp new file mode 100644 index 00000000000000..24a17b8f1131a2 --- /dev/null +++ b/examples/door-lock-app/linux/src/ZCLDoorLockCallbacks.cpp @@ -0,0 +1,91 @@ +#include +#include + +#include "LockManager.h" + +using namespace chip; +using namespace chip::app::Clusters; +using namespace chip::app::Clusters::DoorLock; +// App handles physical aspects of locking but not locking logic. That is it +// should wait for door to be locked on lock command and return success) but +// door lock server should check pin before even calling the lock-door +// callback. +bool emberAfPluginDoorLockOnDoorLockCommand(chip::EndpointId endpointId, const Optional & pinCode, DlOperationError & err) +{ + return LockManager::Instance().Lock(endpointId, pinCode, err); +} + +bool emberAfPluginDoorLockOnDoorUnlockCommand(chip::EndpointId endpointId, const Optional & pinCode, + DlOperationError & err) +{ + return LockManager::Instance().Unlock(endpointId, pinCode, err); +} + +bool emberAfPluginDoorLockGetUser(chip::EndpointId endpointId, uint16_t userIndex, EmberAfPluginDoorLockUserInfo & user) +{ + return LockManager::Instance().GetUser(endpointId, userIndex, user); +} + +bool emberAfPluginDoorLockSetUser(chip::EndpointId endpointId, uint16_t userIndex, chip::FabricIndex creator, + chip::FabricIndex modifier, const chip::CharSpan & userName, uint32_t uniqueId, + DlUserStatus userStatus, DlUserType usertype, DlCredentialRule credentialRule, + const DlCredential * credentials, size_t totalCredentials) +{ + + return LockManager::Instance().SetUser(endpointId, userIndex, creator, modifier, userName, uniqueId, userStatus, usertype, + credentialRule, credentials, totalCredentials); +} + +bool emberAfPluginDoorLockGetCredential(chip::EndpointId endpointId, uint16_t credentialIndex, DlCredentialType credentialType, + EmberAfPluginDoorLockCredentialInfo & credential) +{ + return LockManager::Instance().GetCredential(endpointId, credentialIndex, credentialType, credential); +} + +bool emberAfPluginDoorLockSetCredential(chip::EndpointId endpointId, uint16_t credentialIndex, DlCredentialStatus credentialStatus, + DlCredentialType credentialType, const chip::ByteSpan & credentialData) +{ + return LockManager::Instance().SetCredential(endpointId, credentialIndex, credentialStatus, credentialType, credentialData); +} + +DlStatus emberAfPluginDoorLockGetSchedule(chip::EndpointId endpointId, uint8_t weekdayIndex, uint16_t userIndex, + EmberAfPluginDoorLockWeekDaySchedule & schedule) +{ + return LockManager::Instance().GetSchedule(endpointId, weekdayIndex, userIndex, 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) +{ + return LockManager::Instance().SetSchedule(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 LockManager::Instance().SetSchedule(endpointId, yearDayIndex, userIndex, status, localStartTime, localEndTime); +} + +DlStatus emberAfPluginDoorLockGetSchedule(chip::EndpointId endpointId, uint8_t yearDayIndex, uint16_t userIndex, + EmberAfPluginDoorLockYearDaySchedule & schedule) +{ + return LockManager::Instance().GetSchedule(endpointId, yearDayIndex, userIndex, schedule); +} + +void MatterPostAttributeChangeCallback(const chip::app::ConcreteAttributePath & attributePath, uint8_t mask, uint8_t type, + uint16_t size, uint8_t * value) +{ + // TODO: Watch for LockState, DoorState, Mode, etc changes and trigger appropriate action + if (attributePath.mClusterId == DoorLock::Id) + { + emberAfDoorLockClusterPrintln("Door Lock attribute changed"); + } +} + +void emberAfDoorLockClusterInitCallback(EndpointId endpoint) +{ + DoorLockServer::Instance().InitServer(endpoint); + LockManager::Instance().InitEndpoint(endpoint); +}