From e597750618c0511f6f952b78f485342e853da6c1 Mon Sep 17 00:00:00 2001 From: Junior Martinez Date: Mon, 24 Oct 2022 16:46:27 -0400 Subject: [PATCH 1/3] Make the relock callback weak, implement it on the app side and link our app ui --- examples/lock-app/efr32/src/ZclCallbacks.cpp | 13 ++++++++++++- .../clusters/door-lock-server/door-lock-server.cpp | 3 ++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/examples/lock-app/efr32/src/ZclCallbacks.cpp b/examples/lock-app/efr32/src/ZclCallbacks.cpp index 650aba7d2d73de..a8788e5e3528ee 100644 --- a/examples/lock-app/efr32/src/ZclCallbacks.cpp +++ b/examples/lock-app/efr32/src/ZclCallbacks.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include using namespace ::chip::app::Clusters; @@ -41,7 +42,9 @@ void MatterPostAttributeChangeCallback(const chip::app::ConcreteAttributePath & if (clusterId == DoorLock::Id && attributeId == DoorLock::Attributes::LockState::Id) { - ChipLogProgress(Zcl, "Door lock cluster: " ChipLogFormatMEI, ChipLogValueMEI(clusterId)); + DoorLock::DlLockState lockState = *(reinterpret_cast(value)); + ChipLogProgress(Zcl, "Door lock cluster: " ChipLogFormatMEI " state %d", ChipLogValueMEI(clusterId), + to_underlying(lockState)); } } @@ -146,3 +149,11 @@ DlStatus emberAfPluginDoorLockSetSchedule(chip::EndpointId endpointId, uint8_t h { return LockMgr().SetHolidaySchedule(endpointId, holidayIndex, status, localStartTime, localEndTime, operatingMode); } + +void emberAfPluginDoorLockOnAutoRelock(chip::EndpointId endpointId) +{ + emberAfDoorLockClusterPrintln("Door Auto relock timer expired. Locking..."); + emberEventControlSetInactive(&DoorLockServer::Instance().AutolockEvent); + DoorLockServer::Instance().SetLockState(endpointId, DlLockState::kLocked); + LockMgr().InitiateAction(AppEvent::kEventType_Lock, LockManager::LOCK_ACTION); +} diff --git a/src/app/clusters/door-lock-server/door-lock-server.cpp b/src/app/clusters/door-lock-server/door-lock-server.cpp index 1465f22809cb5d..c39545d48185b4 100644 --- a/src/app/clusters/door-lock-server/door-lock-server.cpp +++ b/src/app/clusters/door-lock-server/door-lock-server.cpp @@ -3751,8 +3751,9 @@ void MatterDoorLockClusterServerAttributeChangedCallback(const app::ConcreteAttr // Timer callbacks // ============================================================================= -void emberAfPluginDoorLockOnAutoRelock(chip::EndpointId endpointId) +void __attribute__((weak)) emberAfPluginDoorLockOnAutoRelock(chip::EndpointId endpointId) { + emberAfDoorLockClusterPrintln("Door Auto relock timer expired. Locking..."); emberEventControlSetInactive(&DoorLockServer::Instance().AutolockEvent); DoorLockServer::Instance().SetLockState(endpointId, DlLockState::kLocked, DlOperationSource::kAuto); } From d9fcef2fac54ea9ec8a708fd630cd95840adc5c8 Mon Sep 17 00:00:00 2001 From: Junior Martinez Date: Tue, 25 Oct 2022 17:37:50 -0400 Subject: [PATCH 2/3] address PR comments, Create a new functions that deal with the cluster and calls the application callback --- examples/lock-app/efr32/src/ZclCallbacks.cpp | 5 +---- .../door-lock-server/door-lock-server-callback.cpp | 2 ++ src/app/clusters/door-lock-server/door-lock-server.cpp | 7 ++++--- src/app/clusters/door-lock-server/door-lock-server.h | 9 ++++++++- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/examples/lock-app/efr32/src/ZclCallbacks.cpp b/examples/lock-app/efr32/src/ZclCallbacks.cpp index a8788e5e3528ee..9c1812a90c0a04 100644 --- a/examples/lock-app/efr32/src/ZclCallbacks.cpp +++ b/examples/lock-app/efr32/src/ZclCallbacks.cpp @@ -27,7 +27,6 @@ #include #include #include -#include #include using namespace ::chip::app::Clusters; @@ -152,8 +151,6 @@ DlStatus emberAfPluginDoorLockSetSchedule(chip::EndpointId endpointId, uint8_t h void emberAfPluginDoorLockOnAutoRelock(chip::EndpointId endpointId) { - emberAfDoorLockClusterPrintln("Door Auto relock timer expired. Locking..."); - emberEventControlSetInactive(&DoorLockServer::Instance().AutolockEvent); - DoorLockServer::Instance().SetLockState(endpointId, DlLockState::kLocked); + // Apply the relock state in the application control LockMgr().InitiateAction(AppEvent::kEventType_Lock, LockManager::LOCK_ACTION); } diff --git a/src/app/clusters/door-lock-server/door-lock-server-callback.cpp b/src/app/clusters/door-lock-server/door-lock-server-callback.cpp index 699c0d9c03a759..c9c38f3fb23b5d 100644 --- a/src/app/clusters/door-lock-server/door-lock-server-callback.cpp +++ b/src/app/clusters/door-lock-server/door-lock-server-callback.cpp @@ -61,6 +61,8 @@ emberAfPluginDoorLockOnDoorUnlockCommand(chip::EndpointId endpointId, const Opti return false; } +void __attribute__((weak)) emberAfPluginDoorLockOnAutoRelock(chip::EndpointId endpointId) {} + // ============================================================================= // 'Default' pre-change callbacks for cluster attributes // ============================================================================= diff --git a/src/app/clusters/door-lock-server/door-lock-server.cpp b/src/app/clusters/door-lock-server/door-lock-server.cpp index c39545d48185b4..1d4d4ebb8fd5c2 100644 --- a/src/app/clusters/door-lock-server/door-lock-server.cpp +++ b/src/app/clusters/door-lock-server/door-lock-server.cpp @@ -69,7 +69,7 @@ class DoorLockClusterFabricDelegate : public chip::FabricTable::Delegate }; static DoorLockClusterFabricDelegate gFabricDelegate; -void emberAfPluginDoorLockOnAutoRelock(chip::EndpointId endpointId); +void DoorLockOnAutoRelockCallback(chip::EndpointId endpointId); /********************************************************** * DoorLockServer public methods @@ -3380,7 +3380,7 @@ void DoorLockServer::ScheduleAutoRelock(chip::EndpointId endpointId, uint32_t ti emberEventControlSetInactive(&AutolockEvent); AutolockEvent.endpoint = endpointId; - AutolockEvent.callback = emberAfPluginDoorLockOnAutoRelock; + AutolockEvent.callback = DoorLockOnAutoRelockCallback; uint32_t timeoutMs = (DOOR_LOCK_MAX_LOCK_TIMEOUT_SEC >= timeoutSec) ? timeoutSec * MILLISECOND_TICKS_PER_SECOND : DOOR_LOCK_MAX_LOCK_TIMEOUT_SEC; @@ -3751,9 +3751,10 @@ void MatterDoorLockClusterServerAttributeChangedCallback(const app::ConcreteAttr // Timer callbacks // ============================================================================= -void __attribute__((weak)) emberAfPluginDoorLockOnAutoRelock(chip::EndpointId endpointId) +void DoorLockOnAutoRelockCallback(chip::EndpointId endpointId) { emberAfDoorLockClusterPrintln("Door Auto relock timer expired. Locking..."); emberEventControlSetInactive(&DoorLockServer::Instance().AutolockEvent); DoorLockServer::Instance().SetLockState(endpointId, DlLockState::kLocked, DlOperationSource::kAuto); + emberAfPluginDoorLockOnAutoRelock(endpointId); } diff --git a/src/app/clusters/door-lock-server/door-lock-server.h b/src/app/clusters/door-lock-server/door-lock-server.h index c0dc7aef6aa8f9..adc4ebd4ff4528 100644 --- a/src/app/clusters/door-lock-server/door-lock-server.h +++ b/src/app/clusters/door-lock-server/door-lock-server.h @@ -463,7 +463,7 @@ class DoorLockServer chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, const chip::app::Clusters::DoorLock::Commands::UnlockWithTimeout::DecodableType & commandData); - friend void emberAfPluginDoorLockOnAutoRelock(chip::EndpointId endpointId); + friend void DoorLockOnAutoRelockCallback(chip::EndpointId endpointId); friend bool emberAfDoorLockClusterSetHolidayScheduleCallback( chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, @@ -887,6 +887,13 @@ bool emberAfPluginDoorLockOnDoorLockCommand(chip::EndpointId endpointId, const O bool emberAfPluginDoorLockOnDoorUnlockCommand(chip::EndpointId endpointId, const Optional & pinCode, DlOperationError & err); +/** + * @brief This callback is called when the AutoRelock timer is expired. + * + * @param endpointId ID of the endpoint that contains the door lock to be relocked. + */ +void emberAfPluginDoorLockOnAutoRelock(chip::EndpointId endpointId); + /** * @brief This callback is called when Door Lock cluster needs to access the users database. * From e6997fabf968b7950513ae4080ae2ff386c609d6 Mon Sep 17 00:00:00 2001 From: Junior Martinez Date: Wed, 26 Oct 2022 13:50:09 -0400 Subject: [PATCH 3/3] Make DoorLockOnAutoRelockCallback a private member of the DoorLock class --- src/app/clusters/door-lock-server/door-lock-server.cpp | 4 +--- src/app/clusters/door-lock-server/door-lock-server.h | 4 ++-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/app/clusters/door-lock-server/door-lock-server.cpp b/src/app/clusters/door-lock-server/door-lock-server.cpp index 1d4d4ebb8fd5c2..4b46b80ffe6f5f 100644 --- a/src/app/clusters/door-lock-server/door-lock-server.cpp +++ b/src/app/clusters/door-lock-server/door-lock-server.cpp @@ -69,8 +69,6 @@ class DoorLockClusterFabricDelegate : public chip::FabricTable::Delegate }; static DoorLockClusterFabricDelegate gFabricDelegate; -void DoorLockOnAutoRelockCallback(chip::EndpointId endpointId); - /********************************************************** * DoorLockServer public methods *********************************************************/ @@ -3751,7 +3749,7 @@ void MatterDoorLockClusterServerAttributeChangedCallback(const app::ConcreteAttr // Timer callbacks // ============================================================================= -void DoorLockOnAutoRelockCallback(chip::EndpointId endpointId) +void DoorLockServer::DoorLockOnAutoRelockCallback(chip::EndpointId endpointId) { emberAfDoorLockClusterPrintln("Door Auto relock timer expired. Locking..."); emberEventControlSetInactive(&DoorLockServer::Instance().AutolockEvent); diff --git a/src/app/clusters/door-lock-server/door-lock-server.h b/src/app/clusters/door-lock-server/door-lock-server.h index adc4ebd4ff4528..c7ddf369f8871a 100644 --- a/src/app/clusters/door-lock-server/door-lock-server.h +++ b/src/app/clusters/door-lock-server/door-lock-server.h @@ -410,6 +410,8 @@ class DoorLockServer */ void ScheduleAutoRelock(chip::EndpointId endpointId, uint32_t timeoutSec); + static void DoorLockOnAutoRelockCallback(chip::EndpointId endpointId); + /** * @brief Send generic event * @@ -463,8 +465,6 @@ class DoorLockServer chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, const chip::app::Clusters::DoorLock::Commands::UnlockWithTimeout::DecodableType & commandData); - friend void DoorLockOnAutoRelockCallback(chip::EndpointId endpointId); - friend bool emberAfDoorLockClusterSetHolidayScheduleCallback( chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, const chip::app::Clusters::DoorLock::Commands::SetHolidaySchedule::DecodableType & commandData);