Skip to content

Commit

Permalink
[Silabs][SiWx917] Matter shell support for the SiWx917 (#24726)
Browse files Browse the repository at this point in the history
* lock application enum changes and logging fix

* Matter shell support for SiWx917

* Restyled by clang-format

* Restyled by gn

* addressed review comments

---------

Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
2 people authored and pull[bot] committed Nov 15, 2023
1 parent 1cb54d2 commit 047a68c
Show file tree
Hide file tree
Showing 12 changed files with 181 additions and 100 deletions.
2 changes: 1 addition & 1 deletion examples/lock-app/silabs/SiWx917/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ efr32_executable("lock_app") {

if (chip_enable_pw_rpc || chip_build_libshell || enable_openthread_cli ||
use_wf200 || use_SiWx917) {
#sources += [ "${examples_plat_dir}/uart.cpp" ]
sources += [ "${examples_plat_dir}/uart.cpp" ]
}

if (chip_build_libshell) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ class EventData
class AlarmEventData : public EventData
{
public:
DlAlarmCode alarmCode;
AlarmCodeEnum alarmCode;
};

class DoorStateEventData : public EventData
{
public:
DlDoorState doorState;
DoorStateEnum doorState;
};

CHIP_ERROR RegisterLockEvents();
Expand Down
23 changes: 12 additions & 11 deletions examples/lock-app/silabs/SiWx917/include/LockManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,25 +141,26 @@ class LockManager
typedef void (*Callback_fn_completed)(Action_t);
void SetCallbacks(Callback_fn_initiated aActionInitiated_CB, Callback_fn_completed aActionCompleted_CB);

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 Lock(chip::EndpointId endpointId, const Optional<chip::ByteSpan> & pin, OperationErrorEnum & err);
bool Unlock(chip::EndpointId endpointId, const Optional<chip::ByteSpan> & pin, OperationErrorEnum & 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,
const chip::CharSpan & userName, uint32_t uniqueId, DlUserStatus userStatus, DlUserType usertype,
DlCredentialRule credentialRule, const DlCredential * credentials, size_t totalCredentials);
const chip::CharSpan & userName, uint32_t uniqueId, UserStatusEnum userStatus, UserTypeEnum usertype,
CredentialRuleEnum credentialRule, const CredentialStruct * credentials, size_t totalCredentials);

bool GetCredential(chip::EndpointId endpointId, uint16_t credentialIndex, DlCredentialType credentialType,
bool GetCredential(chip::EndpointId endpointId, uint16_t credentialIndex, CredentialTypeEnum credentialType,
EmberAfPluginDoorLockCredentialInfo & credential);

bool SetCredential(chip::EndpointId endpointId, uint16_t credentialIndex, chip::FabricIndex creator, chip::FabricIndex modifier,
DlCredentialStatus credentialStatus, DlCredentialType credentialType, const chip::ByteSpan & credentialData);
DlCredentialStatus credentialStatus, CredentialTypeEnum credentialType,
const chip::ByteSpan & credentialData);

DlStatus GetWeekdaySchedule(chip::EndpointId endpointId, uint8_t weekdayIndex, uint16_t userIndex,
EmberAfPluginDoorLockWeekDaySchedule & schedule);

DlStatus SetWeekdaySchedule(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);
DaysMaskMap daysMask, uint8_t startHour, uint8_t startMinute, uint8_t endHour, uint8_t endMinute);

DlStatus GetYeardaySchedule(chip::EndpointId endpointId, uint8_t yearDayIndex, uint16_t userIndex,
EmberAfPluginDoorLockYearDaySchedule & schedule);
Expand All @@ -170,16 +171,16 @@ class LockManager
DlStatus GetHolidaySchedule(chip::EndpointId endpointId, uint8_t holidayIndex, EmberAfPluginDoorLockHolidaySchedule & schedule);

DlStatus SetHolidaySchedule(chip::EndpointId endpointId, uint8_t holidayIndex, DlScheduleStatus status, uint32_t localStartTime,
uint32_t localEndTime, DlOperatingMode operatingMode);
uint32_t localEndTime, OperatingModeEnum operatingMode);

bool IsValidUserIndex(uint16_t userIndex);
bool IsValidCredentialIndex(uint16_t credentialIndex, DlCredentialType type);
bool IsValidCredentialIndex(uint16_t credentialIndex, CredentialTypeEnum type);
bool IsValidWeekdayScheduleIndex(uint8_t scheduleIndex);
bool IsValidYeardayScheduleIndex(uint8_t scheduleIndex);
bool IsValidHolidayScheduleIndex(uint8_t scheduleIndex);

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

bool ReadConfigValues();
Expand All @@ -206,7 +207,7 @@ class LockManager

char mUserNames[ArraySize(mLockUsers)][DOOR_LOCK_MAX_USER_NAME_SIZE];
uint8_t mCredentialData[kMaxCredentials][kMaxCredentialSize];
DlCredential mCredentials[kMaxUsers][kMaxCredentialsPerUser];
CredentialStruct mCredentials[kMaxUsers][kMaxCredentialsPerUser];

static LockManager sLock;
SI917DoorLock::LockInitParams::LockParam LockParams;
Expand Down
6 changes: 3 additions & 3 deletions examples/lock-app/silabs/SiWx917/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@
#endif // ENABLE_WSTK_LEDS

using chip::app::Clusters::DoorLock::DlLockState;
using chip::app::Clusters::DoorLock::DlOperationError;
using chip::app::Clusters::DoorLock::DlOperationSource;
using chip::app::Clusters::DoorLock::OperationErrorEnum;
using chip::app::Clusters::DoorLock::OperationSourceEnum;

using namespace chip;
using namespace ::chip::DeviceLayer;
Expand Down Expand Up @@ -423,7 +423,7 @@ void AppTask::UpdateClusterState(intptr_t context)
bool unlocked = LockMgr().NextState();
DlLockState newState = unlocked ? DlLockState::kUnlocked : DlLockState::kLocked;

DlOperationSource source = DlOperationSource::kUnspecified;
OperationSourceEnum source = OperationSourceEnum::kUnspecified;

// write the new lock value
EmberAfStatus status =
Expand Down
4 changes: 2 additions & 2 deletions examples/lock-app/silabs/SiWx917/src/EventHandlerLibShell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ CHIP_ERROR AlarmEventHandler(int argc, char ** argv)

AlarmEventData * data = Platform::New<AlarmEventData>();
data->eventId = Events::DoorLockAlarm::Id;
data->alarmCode = static_cast<DlAlarmCode>(atoi(argv[0]));
data->alarmCode = static_cast<AlarmCodeEnum>(atoi(argv[0]));

DeviceLayer::PlatformMgr().ScheduleWork(EventWorkerFunction, reinterpret_cast<intptr_t>(data));

Expand Down Expand Up @@ -136,7 +136,7 @@ CHIP_ERROR DoorStateEventHandler(int argc, char ** argv)

DoorStateEventData * data = Platform::New<DoorStateEventData>();
data->eventId = Events::DoorStateChange::Id;
data->doorState = static_cast<DlDoorState>(atoi(argv[0]));
data->doorState = static_cast<DoorStateEnum>(atoi(argv[0]));

DeviceLayer::PlatformMgr().ScheduleWork(EventWorkerFunction, reinterpret_cast<intptr_t>(data));

Expand Down
40 changes: 20 additions & 20 deletions examples/lock-app/silabs/SiWx917/src/LockManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ bool LockManager::IsValidUserIndex(uint16_t userIndex)
return (userIndex < kMaxUsers);
}

bool LockManager::IsValidCredentialIndex(uint16_t credentialIndex, DlCredentialType type)
bool LockManager::IsValidCredentialIndex(uint16_t credentialIndex, CredentialTypeEnum type)
{
if (DlCredentialType::kProgrammingPIN == type)
if (CredentialTypeEnum::kProgrammingPIN == type)
{
return (0 == credentialIndex); // 0 is required index for Programming PIN
}
Expand Down Expand Up @@ -144,7 +144,7 @@ bool LockManager::ReadConfigValues()
sizeof(mCredentialData), outLen);

SILABSConfig::ReadConfigValueBin(SILABSConfig::kConfigKey_UserCredentials, reinterpret_cast<uint8_t *>(mCredentials),
sizeof(DlCredential) * LockParams.numberOfUsers * LockParams.numberOfCredentialsPerUser,
sizeof(CredentialStruct) * LockParams.numberOfUsers * LockParams.numberOfCredentialsPerUser,
outLen);

SILABSConfig::ReadConfigValueBin(SILABSConfig::kConfigKey_WeekDaySchedules, reinterpret_cast<uint8_t *>(mWeekdaySchedule),
Expand Down Expand Up @@ -283,12 +283,12 @@ void LockManager::ActuatorMovementTimerEventHandler(AppEvent * aEvent)
}
}

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

bool LockManager::Unlock(chip::EndpointId endpointId, const Optional<chip::ByteSpan> & pin, DlOperationError & err)
bool LockManager::Unlock(chip::EndpointId endpointId, const Optional<chip::ByteSpan> & pin, OperationErrorEnum & err)
{
return setLockState(endpointId, DlLockState::kUnlocked, pin, err);
}
Expand All @@ -306,14 +306,14 @@ bool LockManager::GetUser(chip::EndpointId endpointId, uint16_t userIndex, Ember
const auto & userInDb = mLockUsers[userIndex];

user.userStatus = userInDb.userStatus;
if (DlUserStatus::kAvailable == user.userStatus)
if (UserStatusEnum::kAvailable == user.userStatus)
{
ChipLogDetail(Zcl, "Found unoccupied user [endpoint=%d]", endpointId);
return true;
}

user.userName = chip::CharSpan(userInDb.userName.data(), userInDb.userName.size());
user.credentials = chip::Span<const DlCredential>(mCredentials[userIndex], userInDb.credentials.size());
user.credentials = chip::Span<const CredentialStruct>(mCredentials[userIndex], userInDb.credentials.size());
user.userUniqueId = userInDb.userUniqueId;
user.userType = userInDb.userType;
user.credentialRule = userInDb.credentialRule;
Expand All @@ -336,8 +336,8 @@ bool LockManager::GetUser(chip::EndpointId endpointId, uint16_t userIndex, Ember
}

bool LockManager::SetUser(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)
const chip::CharSpan & userName, uint32_t uniqueId, UserStatusEnum userStatus, UserTypeEnum usertype,
CredentialRuleEnum credentialRule, const CredentialStruct * credentials, size_t totalCredentials)
{
ChipLogProgress(Zcl,
"Door Lock App: LockManager::SetUser "
Expand Down Expand Up @@ -383,14 +383,14 @@ bool LockManager::SetUser(chip::EndpointId endpointId, uint16_t userIndex, chip:
mCredentials[userIndex][i].CredentialIndex = i + 1;
}

userInStorage.credentials = chip::Span<const DlCredential>(mCredentials[userIndex], totalCredentials);
userInStorage.credentials = chip::Span<const CredentialStruct>(mCredentials[userIndex], totalCredentials);

// Save user information in NVM flash
SILABSConfig::WriteConfigValueBin(SILABSConfig::kConfigKey_LockUser, reinterpret_cast<const uint8_t *>(&mLockUsers),
sizeof(EmberAfPluginDoorLockUserInfo) * LockParams.numberOfUsers);

SILABSConfig::WriteConfigValueBin(SILABSConfig::kConfigKey_UserCredentials, reinterpret_cast<const uint8_t *>(mCredentials),
sizeof(DlCredential) * LockParams.numberOfUsers * LockParams.numberOfCredentialsPerUser);
sizeof(CredentialStruct) * LockParams.numberOfUsers * LockParams.numberOfCredentialsPerUser);

SILABSConfig::WriteConfigValueBin(SILABSConfig::kConfigKey_LockUserName, reinterpret_cast<const uint8_t *>(mUserNames),
sizeof(mUserNames));
Expand All @@ -400,11 +400,11 @@ bool LockManager::SetUser(chip::EndpointId endpointId, uint16_t userIndex, chip:
return true;
}

bool LockManager::GetCredential(chip::EndpointId endpointId, uint16_t credentialIndex, DlCredentialType credentialType,
bool LockManager::GetCredential(chip::EndpointId endpointId, uint16_t credentialIndex, CredentialTypeEnum credentialType,
EmberAfPluginDoorLockCredentialInfo & credential)
{

if (DlCredentialType::kProgrammingPIN == credentialType)
if (CredentialTypeEnum::kProgrammingPIN == credentialType)
{
VerifyOrReturnValue(IsValidCredentialIndex(credentialIndex, credentialType),
false); // programming pin index is only index allowed to contain 0
Expand Down Expand Up @@ -443,11 +443,11 @@ bool LockManager::GetCredential(chip::EndpointId endpointId, uint16_t credential
}

bool LockManager::SetCredential(chip::EndpointId endpointId, uint16_t credentialIndex, chip::FabricIndex creator,
chip::FabricIndex modifier, DlCredentialStatus credentialStatus, DlCredentialType credentialType,
chip::FabricIndex modifier, DlCredentialStatus credentialStatus, CredentialTypeEnum credentialType,
const chip::ByteSpan & credentialData)
{

if (DlCredentialType::kProgrammingPIN == credentialType)
if (CredentialTypeEnum::kProgrammingPIN == credentialType)
{
VerifyOrReturnValue(IsValidCredentialIndex(credentialIndex, credentialType),
false); // programming pin index is only index allowed to contain 0
Expand Down Expand Up @@ -509,7 +509,7 @@ DlStatus LockManager::GetWeekdaySchedule(chip::EndpointId endpointId, uint8_t we
}

DlStatus LockManager::SetWeekdaySchedule(chip::EndpointId endpointId, uint8_t weekdayIndex, uint16_t userIndex,
DlScheduleStatus status, DlDaysMaskMap daysMask, uint8_t startHour, uint8_t startMinute,
DlScheduleStatus status, DaysMaskMap daysMask, uint8_t startHour, uint8_t startMinute,
uint8_t endHour, uint8_t endMinute)
{

Expand Down Expand Up @@ -609,7 +609,7 @@ DlStatus LockManager::GetHolidaySchedule(chip::EndpointId endpointId, uint8_t ho
}

DlStatus LockManager::SetHolidaySchedule(chip::EndpointId endpointId, uint8_t holidayIndex, DlScheduleStatus status,
uint32_t localStartTime, uint32_t localEndTime, DlOperatingMode operatingMode)
uint32_t localStartTime, uint32_t localEndTime, OperatingModeEnum operatingMode)
{
VerifyOrReturnValue(holidayIndex > 0, DlStatus::kFailure); // indices are one-indexed

Expand Down Expand Up @@ -650,7 +650,7 @@ const char * LockManager::lockStateToString(DlLockState lockState) const
}

bool LockManager::setLockState(chip::EndpointId endpointId, DlLockState lockState, const Optional<chip::ByteSpan> & pin,
DlOperationError & err)
OperationErrorEnum & err)
{

// Assume pin is required until told otherwise
Expand Down Expand Up @@ -681,7 +681,7 @@ bool LockManager::setLockState(chip::EndpointId endpointId, DlLockState lockStat
// Check the PIN code
for (uint8_t i = 0; i < kMaxCredentials; i++)
{
if (mLockCredentials[i].credentialType != DlCredentialType::kPin ||
if (mLockCredentials[i].credentialType != CredentialTypeEnum::kPin ||
mLockCredentials[i].status == DlCredentialStatus::kAvailable)
{
continue;
Expand All @@ -704,6 +704,6 @@ bool LockManager::setLockState(chip::EndpointId endpointId, DlLockState lockStat
"[endpointId=%d]",
lockStateToString(lockState), endpointId);

err = DlOperationError::kInvalidCredential;
err = OperationErrorEnum::kInvalidCredential;
return false;
}
17 changes: 9 additions & 8 deletions examples/lock-app/silabs/SiWx917/src/ZclCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ void MatterPostAttributeChangeCallback(const chip::app::ConcreteAttributePath &
*/
void emberAfDoorLockClusterInitCallback(EndpointId endpoint) {}

bool emberAfPluginDoorLockOnDoorLockCommand(chip::EndpointId endpointId, const Optional<ByteSpan> & pinCode, DlOperationError & err)
bool emberAfPluginDoorLockOnDoorLockCommand(chip::EndpointId endpointId, const Optional<ByteSpan> & pinCode,
OperationErrorEnum & err)
{
ChipLogProgress(Zcl, "Door Lock App: Lock Command endpoint=%d", endpointId);
bool status = LockMgr().Lock(endpointId, pinCode, err);
Expand All @@ -70,7 +71,7 @@ bool emberAfPluginDoorLockOnDoorLockCommand(chip::EndpointId endpointId, const O
}

bool emberAfPluginDoorLockOnDoorUnlockCommand(chip::EndpointId endpointId, const Optional<ByteSpan> & pinCode,
DlOperationError & err)
OperationErrorEnum & err)
{
ChipLogProgress(Zcl, "Door Lock App: Unlock Command endpoint=%d", endpointId);
bool status = LockMgr().Unlock(endpointId, pinCode, err);
Expand All @@ -82,15 +83,15 @@ bool emberAfPluginDoorLockOnDoorUnlockCommand(chip::EndpointId endpointId, const
return status;
}

bool emberAfPluginDoorLockGetCredential(chip::EndpointId endpointId, uint16_t credentialIndex, DlCredentialType credentialType,
bool emberAfPluginDoorLockGetCredential(chip::EndpointId endpointId, uint16_t credentialIndex, CredentialTypeEnum credentialType,
EmberAfPluginDoorLockCredentialInfo & credential)
{
return LockMgr().GetCredential(endpointId, credentialIndex, credentialType, credential);
}

bool emberAfPluginDoorLockSetCredential(chip::EndpointId endpointId, uint16_t credentialIndex, chip::FabricIndex creator,
chip::FabricIndex modifier, DlCredentialStatus credentialStatus,
DlCredentialType credentialType, const chip::ByteSpan & credentialData)
CredentialTypeEnum credentialType, const chip::ByteSpan & credentialData)
{
return LockMgr().SetCredential(endpointId, credentialIndex, creator, modifier, credentialStatus, credentialType,
credentialData);
Expand All @@ -103,8 +104,8 @@ bool emberAfPluginDoorLockGetUser(chip::EndpointId endpointId, uint16_t userInde

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)
UserStatusEnum userStatus, UserTypeEnum usertype, CredentialRuleEnum credentialRule,
const CredentialStruct * credentials, size_t totalCredentials)
{

return LockMgr().SetUser(endpointId, userIndex, creator, modifier, userName, uniqueId, userStatus, usertype, credentialRule,
Expand All @@ -130,7 +131,7 @@ DlStatus emberAfPluginDoorLockGetSchedule(chip::EndpointId endpointId, uint8_t h
}

DlStatus emberAfPluginDoorLockSetSchedule(chip::EndpointId endpointId, uint8_t weekdayIndex, uint16_t userIndex,
DlScheduleStatus status, DlDaysMaskMap daysMask, uint8_t startHour, uint8_t startMinute,
DlScheduleStatus status, DaysMaskMap daysMask, uint8_t startHour, uint8_t startMinute,
uint8_t endHour, uint8_t endMinute)
{
return LockMgr().SetWeekdaySchedule(endpointId, weekdayIndex, userIndex, status, daysMask, startHour, startMinute, endHour,
Expand All @@ -144,7 +145,7 @@ DlStatus emberAfPluginDoorLockSetSchedule(chip::EndpointId endpointId, uint8_t y
}

DlStatus emberAfPluginDoorLockSetSchedule(chip::EndpointId endpointId, uint8_t holidayIndex, DlScheduleStatus status,
uint32_t localStartTime, uint32_t localEndTime, DlOperatingMode operatingMode)
uint32_t localStartTime, uint32_t localEndTime, OperatingModeEnum operatingMode)
{
return LockMgr().SetHolidaySchedule(endpointId, holidayIndex, status, localStartTime, localEndTime, operatingMode);
}
Expand Down
Loading

0 comments on commit 047a68c

Please sign in to comment.