@@ -33,7 +33,6 @@ using namespace CYW30739DoorLock::LockInitParams;
33
33
CHIP_ERROR LockManager::Init (chip::app::DataModel::Nullable<chip::app::Clusters::DoorLock::DlLockState> state, LockParam lockParam)
34
34
{
35
35
LockParams = lockParam;
36
-
37
36
if (LockParams.numberOfUsers > kMaxUsers )
38
37
{
39
38
ChipLogError (Zcl,
@@ -448,7 +447,6 @@ bool LockManager::SetCredential(chip::EndpointId endpointId, uint16_t credential
448
447
chip::FabricIndex modifier, DlCredentialStatus credentialStatus, DlCredentialType credentialType,
449
448
const chip::ByteSpan & credentialData)
450
449
{
451
-
452
450
VerifyOrReturnValue (credentialIndex > 0 , false ); // indices are one-indexed
453
451
454
452
credentialIndex--;
@@ -495,7 +493,13 @@ DlStatus LockManager::GetWeekdaySchedule(chip::EndpointId endpointId, uint8_t we
495
493
VerifyOrReturnValue (IsValidWeekdayScheduleIndex (weekdayIndex), DlStatus::kFailure );
496
494
VerifyOrReturnValue (IsValidUserIndex (userIndex), DlStatus::kFailure );
497
495
498
- schedule = mWeekdaySchedule [userIndex][weekdayIndex];
496
+ const auto & scheduleInStorage = mWeekdaySchedule [userIndex][weekdayIndex];
497
+ if (DlScheduleStatus::kAvailable == scheduleInStorage.status )
498
+ {
499
+ return DlStatus::kNotFound ;
500
+ }
501
+
502
+ schedule = scheduleInStorage.schedule ;
499
503
500
504
return DlStatus::kSuccess ;
501
505
}
@@ -516,11 +520,12 @@ DlStatus LockManager::SetWeekdaySchedule(chip::EndpointId endpointId, uint8_t we
516
520
517
521
auto & scheduleInStorage = mWeekdaySchedule [userIndex][weekdayIndex];
518
522
519
- scheduleInStorage.daysMask = daysMask;
520
- scheduleInStorage.startHour = startHour;
521
- scheduleInStorage.startMinute = startMinute;
522
- scheduleInStorage.endHour = endHour;
523
- scheduleInStorage.endMinute = endMinute;
523
+ scheduleInStorage.schedule .daysMask = daysMask;
524
+ scheduleInStorage.schedule .startHour = startHour;
525
+ scheduleInStorage.schedule .startMinute = startMinute;
526
+ scheduleInStorage.schedule .endHour = endHour;
527
+ scheduleInStorage.schedule .endMinute = endMinute;
528
+ scheduleInStorage.status = status;
524
529
525
530
// Save schedule information in NVM flash
526
531
CYW30739Config::WriteConfigValueBin (
@@ -542,9 +547,13 @@ DlStatus LockManager::GetYeardaySchedule(chip::EndpointId endpointId, uint8_t ye
542
547
VerifyOrReturnValue (IsValidYeardayScheduleIndex (yearDayIndex), DlStatus::kFailure );
543
548
VerifyOrReturnValue (IsValidUserIndex (userIndex), DlStatus::kFailure );
544
549
545
- auto & scheduleInStorage = mYeardaySchedule [userIndex][yearDayIndex];
550
+ const auto & scheduleInStorage = mYeardaySchedule [userIndex][yearDayIndex];
551
+ if (DlScheduleStatus::kAvailable == scheduleInStorage.status )
552
+ {
553
+ return DlStatus::kNotFound ;
554
+ }
546
555
547
- schedule = scheduleInStorage;
556
+ schedule = scheduleInStorage. schedule ;
548
557
549
558
return DlStatus::kSuccess ;
550
559
}
@@ -563,8 +572,9 @@ DlStatus LockManager::SetYeardaySchedule(chip::EndpointId endpointId, uint8_t ye
563
572
564
573
auto & scheduleInStorage = mYeardaySchedule [userIndex][yearDayIndex];
565
574
566
- scheduleInStorage.localStartTime = localStartTime;
567
- scheduleInStorage.localEndTime = localEndTime;
575
+ scheduleInStorage.schedule .localStartTime = localStartTime;
576
+ scheduleInStorage.schedule .localEndTime = localEndTime;
577
+ scheduleInStorage.status = status;
568
578
569
579
// Save schedule information in NVM flash
570
580
CYW30739Config::WriteConfigValueBin (
@@ -583,9 +593,13 @@ DlStatus LockManager::GetHolidaySchedule(chip::EndpointId endpointId, uint8_t ho
583
593
584
594
VerifyOrReturnValue (IsValidHolidayScheduleIndex (holidayIndex), DlStatus::kFailure );
585
595
586
- auto & scheduleInStorage = mHolidaySchedule [holidayIndex];
596
+ const auto & scheduleInStorage = mHolidaySchedule [holidayIndex];
597
+ if (DlScheduleStatus::kAvailable == scheduleInStorage.status )
598
+ {
599
+ return DlStatus::kNotFound ;
600
+ }
587
601
588
- schedule = scheduleInStorage;
602
+ schedule = scheduleInStorage. schedule ;
589
603
590
604
return DlStatus::kSuccess ;
591
605
}
@@ -601,9 +615,10 @@ DlStatus LockManager::SetHolidaySchedule(chip::EndpointId endpointId, uint8_t ho
601
615
602
616
auto & scheduleInStorage = mHolidaySchedule [holidayIndex];
603
617
604
- scheduleInStorage.localStartTime = localStartTime;
605
- scheduleInStorage.localEndTime = localEndTime;
606
- scheduleInStorage.operatingMode = operatingMode;
618
+ scheduleInStorage.schedule .localStartTime = localStartTime;
619
+ scheduleInStorage.schedule .localEndTime = localEndTime;
620
+ scheduleInStorage.schedule .operatingMode = operatingMode;
621
+ scheduleInStorage.status = status;
607
622
608
623
// Save schedule information in NVM flash
609
624
CYW30739Config::WriteConfigValueBin (CYW30739Config::kConfigKey_HolidaySchedules ,
@@ -633,43 +648,28 @@ const char * LockManager::lockStateToString(DlLockState lockState) const
633
648
bool LockManager::setLockState (chip::EndpointId endpointId, DlLockState lockState, const Optional<chip::ByteSpan> & pin,
634
649
DlOperationError & err)
635
650
{
636
- DlLockState curState = DlLockState::kLocked ;
637
- if (mState == kState_UnlockCompleted )
638
- curState = DlLockState::kUnlocked ;
639
-
640
- if ((curState == lockState) && (curState == DlLockState::kLocked ))
641
- {
642
- ChipLogDetail (Zcl, " Door Lock App: door is already locked, ignoring command to set lock state to \" %s\" [endpointId=%d]" ,
643
- lockStateToString (lockState), endpointId);
644
- return true ;
645
- }
646
- else if ((curState == lockState) && (curState == DlLockState::kUnlocked ))
647
- {
648
- ChipLogDetail (Zcl,
649
- " Door Lock App: door is already unlocked, ignoring command to set unlock state to \" %s\" [endpointId=%d]" ,
650
- lockStateToString (lockState), endpointId);
651
- return true ;
652
- }
653
-
654
651
// Assume pin is required until told otherwise
655
652
bool requirePin = true ;
656
653
chip::app::Clusters::DoorLock::Attributes::RequirePINforRemoteOperation::Get (endpointId, &requirePin);
657
654
658
655
// If a pin code is not given
659
656
if (!pin.HasValue ())
660
657
{
661
- ChipLogDetail (Zcl, " Door Lock App: PIN code is not specified, but it is required [endpointId=%d]" , mEndpointId );
662
- curState = lockState;
658
+ ChipLogDetail (Zcl, " Door Lock App: PIN code is not specified [endpointId=%d]" , endpointId);
663
659
664
660
// If a pin code is not required
665
661
if (!requirePin)
666
662
{
667
663
ChipLogDetail (Zcl, " Door Lock App: setting door lock state to \" %s\" [endpointId=%d]" , lockStateToString (lockState),
668
664
endpointId);
669
- curState = lockState;
665
+
666
+ DoorLockServer::Instance ().SetLockState (endpointId, lockState);
667
+
670
668
return true ;
671
669
}
672
670
671
+ ChipLogError (Zcl, " Door Lock App: PIN code is not specified, but it is required [endpointId=%d]" , endpointId);
672
+
673
673
return false ;
674
674
}
675
675
@@ -686,9 +686,9 @@ bool LockManager::setLockState(chip::EndpointId endpointId, DlLockState lockStat
686
686
{
687
687
ChipLogDetail (Zcl,
688
688
" Lock App: specified PIN code was found in the database, setting lock state to \" %s\" [endpointId=%d]" ,
689
- lockStateToString (lockState), mEndpointId );
689
+ lockStateToString (lockState), endpointId );
690
690
691
- curState = lockState;
691
+ DoorLockServer::Instance (). SetLockState (endpointId, lockState) ;
692
692
693
693
return true ;
694
694
}
@@ -697,8 +697,21 @@ bool LockManager::setLockState(chip::EndpointId endpointId, DlLockState lockStat
697
697
ChipLogDetail (Zcl,
698
698
" Door Lock App: specified PIN code was not found in the database, ignoring command to set lock state to \" %s\" "
699
699
" [endpointId=%d]" ,
700
- lockStateToString (lockState), mEndpointId );
700
+ lockStateToString (lockState), endpointId );
701
701
702
702
err = DlOperationError::kInvalidCredential ;
703
703
return false ;
704
704
}
705
+
706
+ bool LockManager::SetDoorState (chip::EndpointId endpointId, DlDoorState newState)
707
+ {
708
+ if (mDoorState != newState)
709
+ {
710
+ ChipLogProgress (Zcl, " Changing the door state to: %d [endpointId=%d,previousState=%d]" , to_underlying (newState), endpointId,
711
+ to_underlying (mDoorState ));
712
+
713
+ mDoorState = newState;
714
+ return DoorLockServer::Instance ().SetDoorState (endpointId, mDoorState );
715
+ }
716
+ return true ;
717
+ }
0 commit comments