Skip to content

Commit

Permalink
DoorLock clusters events support (#14492)
Browse files Browse the repository at this point in the history
1. Supported events: DoorStateChange, LockOperation, LockOperationError
2. Refactored commands: LockDoor, UnlockDoor, UnlockWithTimeout - implemented common logic for remote locking/unlocking
   and appropriate events sending.
  • Loading branch information
truebiker authored Feb 4, 2022
1 parent c5437aa commit a5920db
Show file tree
Hide file tree
Showing 7 changed files with 326 additions and 142 deletions.
6 changes: 3 additions & 3 deletions examples/door-lock-app/linux/include/LockEndpoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ class LockEndpoint

inline chip::EndpointId GetEndpointId() { return mEndpointId; }

bool Lock(const Optional<chip::ByteSpan> & pin);
bool Unlock(const Optional<chip::ByteSpan> & pin);
bool Lock(const Optional<chip::ByteSpan> & pin, DlOperationError & err);
bool Unlock(const Optional<chip::ByteSpan> & pin, DlOperationError & err);

bool GetUser(uint16_t userIndex, EmberAfPluginDoorLockUserInfo & user) const;
bool SetUser(uint16_t userIndex, chip::FabricIndex creator, chip::FabricIndex modifier, const chip::CharSpan & userName,
Expand All @@ -64,7 +64,7 @@ class LockEndpoint
uint32_t localEndTime);

private:
bool setLockState(DlLockState lockState, const Optional<chip::ByteSpan> & pin);
bool setLockState(DlLockState lockState, const Optional<chip::ByteSpan> & pin, DlOperationError & err);
const char * lockStateToString(DlLockState lockState) const;

chip::EndpointId mEndpointId;
Expand Down
4 changes: 2 additions & 2 deletions examples/door-lock-app/linux/include/LockManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ class LockManager

bool InitEndpoint(chip::EndpointId endpointId);

bool Lock(chip::EndpointId endpointId, const Optional<chip::ByteSpan> & pin);
bool Unlock(chip::EndpointId endpointId, const Optional<chip::ByteSpan> & pin);
bool Lock(chip::EndpointId endpointId, const Optional<chip::ByteSpan> & pin, DlOperationError & err);
bool Unlock(chip::EndpointId endpointId, const Optional<chip::ByteSpan> & pin, DlOperationError & err);

bool GetUser(chip::EndpointId endpointId, uint16_t userIndex, EmberAfPluginDoorLockUserInfo & user);
bool SetUser(chip::EndpointId endpointId, uint16_t userIndex, chip::FabricIndex creator, chip::FabricIndex modifier,
Expand Down
9 changes: 5 additions & 4 deletions examples/door-lock-app/linux/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,15 @@ using namespace chip::app::Clusters::DoorLock;
// 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<ByteSpan> & pinCode)
bool emberAfPluginDoorLockOnDoorLockCommand(chip::EndpointId endpointId, const Optional<ByteSpan> & pinCode, DlOperationError & err)
{
return LockManager::Instance().Lock(endpointId, pinCode);
return LockManager::Instance().Lock(endpointId, pinCode, err);
}

bool emberAfPluginDoorLockOnDoorUnlockCommand(chip::EndpointId endpointId, const Optional<ByteSpan> & pinCode)
bool emberAfPluginDoorLockOnDoorUnlockCommand(chip::EndpointId endpointId, const Optional<ByteSpan> & pinCode,
DlOperationError & err)
{
return LockManager::Instance().Unlock(endpointId, pinCode);
return LockManager::Instance().Unlock(endpointId, pinCode, err);
}

bool emberAfPluginDoorLockGetUser(chip::EndpointId endpointId, uint16_t userIndex, EmberAfPluginDoorLockUserInfo & user)
Expand Down
11 changes: 6 additions & 5 deletions examples/door-lock-app/linux/src/LockEndpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@

using chip::to_underlying;

bool LockEndpoint::Lock(const Optional<chip::ByteSpan> & pin)
bool LockEndpoint::Lock(const Optional<chip::ByteSpan> & pin, DlOperationError & err)
{
return setLockState(DlLockState::kLocked, pin);
return setLockState(DlLockState::kLocked, pin, err);
}

bool LockEndpoint::Unlock(const Optional<chip::ByteSpan> & pin)
bool LockEndpoint::Unlock(const Optional<chip::ByteSpan> & pin, DlOperationError & err)
{
return setLockState(DlLockState::kUnlocked, pin);
return setLockState(DlLockState::kUnlocked, pin, err);
}

bool LockEndpoint::GetUser(uint16_t userIndex, EmberAfPluginDoorLockUserInfo & user) const
Expand Down Expand Up @@ -286,7 +286,7 @@ DlStatus LockEndpoint::SetSchedule(uint8_t yearDayIndex, uint16_t userIndex, DlS
return DlStatus::kSuccess;
}

bool LockEndpoint::setLockState(DlLockState lockState, const Optional<chip::ByteSpan> & pin)
bool LockEndpoint::setLockState(DlLockState lockState, const Optional<chip::ByteSpan> & pin, DlOperationError & err)
{
if (mLockState == lockState)
{
Expand Down Expand Up @@ -329,6 +329,7 @@ bool LockEndpoint::setLockState(DlLockState lockState, const Optional<chip::Byte
"[endpointId=%d]",
lockStateToString(lockState), mEndpointId);

err = DlOperationError::kInvalidCredential;
return false;
}

Expand Down
8 changes: 4 additions & 4 deletions examples/door-lock-app/linux/src/LockManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,26 +91,26 @@ bool LockManager::InitEndpoint(chip::EndpointId endpointId)
return true;
}

bool LockManager::Lock(chip::EndpointId endpointId, const Optional<chip::ByteSpan> & pin)
bool LockManager::Lock(chip::EndpointId endpointId, const Optional<chip::ByteSpan> & pin, DlOperationError & err)
{
auto lockEndpoint = getEndpoint(endpointId);
if (nullptr == lockEndpoint)
{
ChipLogError(Zcl, "Unable to lock the door - endpoint does not exist or not initialized [endpointId=%d]", endpointId);
return false;
}
return lockEndpoint->Lock(pin);
return lockEndpoint->Lock(pin, err);
}

bool LockManager::Unlock(chip::EndpointId endpointId, const Optional<chip::ByteSpan> & pin)
bool LockManager::Unlock(chip::EndpointId endpointId, const Optional<chip::ByteSpan> & pin, DlOperationError & err)
{
auto lockEndpoint = getEndpoint(endpointId);
if (nullptr == lockEndpoint)
{
ChipLogError(Zcl, "Unable to unlock the door - endpoint does not exist or not initialized [endpointId=%d]", endpointId);
return false;
}
return lockEndpoint->Unlock(pin);
return lockEndpoint->Unlock(pin, err);
}

bool LockManager::GetUser(chip::EndpointId endpointId, uint16_t userIndex, EmberAfPluginDoorLockUserInfo & user)
Expand Down
Loading

0 comments on commit a5920db

Please sign in to comment.