From 366979e4ae9384b7ea3822c0088de91fdb9b46d2 Mon Sep 17 00:00:00 2001 From: Justin Wood Date: Fri, 26 Aug 2022 11:17:16 -0700 Subject: [PATCH] [Infineon] Fix for Door lock and Software Diagnostics Cluster (#22082) (#22169) Co-authored-by: Praveen Chandran --- examples/lock-app/p6/include/LockManager.h | 24 +++++- examples/lock-app/p6/src/LockManager.cpp | 85 ++++++++++--------- .../P6/DiagnosticDataProviderImpl.cpp | 53 ++++++++++++ src/platform/P6/DiagnosticDataProviderImpl.h | 4 +- third_party/p6/p6_sdk/configs/lwipopts.h | 2 +- 5 files changed, 122 insertions(+), 46 deletions(-) diff --git a/examples/lock-app/p6/include/LockManager.h b/examples/lock-app/p6/include/LockManager.h index 9fab16ec1e1cd4..1dbdf58d85487e 100644 --- a/examples/lock-app/p6/include/LockManager.h +++ b/examples/lock-app/p6/include/LockManager.h @@ -30,6 +30,24 @@ #include +struct WeekDaysScheduleInfo +{ + DlScheduleStatus status; + EmberAfPluginDoorLockWeekDaySchedule schedule; +}; + +struct YearDayScheduleInfo +{ + DlScheduleStatus status; + EmberAfPluginDoorLockYearDaySchedule schedule; +}; + +struct HolidayScheduleInfo +{ + DlScheduleStatus status; + EmberAfPluginDoorLockHolidaySchedule schedule; +}; + namespace P6DoorLock { namespace ResourceRanges { // Used to size arrays @@ -187,9 +205,9 @@ class LockManager EmberAfPluginDoorLockUserInfo mLockUsers[kMaxUsers]; EmberAfPluginDoorLockCredentialInfo mLockCredentials[kMaxCredentials]; - EmberAfPluginDoorLockWeekDaySchedule mWeekdaySchedule[kMaxUsers][kMaxWeekdaySchedulesPerUser]; - EmberAfPluginDoorLockYearDaySchedule mYeardaySchedule[kMaxUsers][kMaxYeardaySchedulesPerUser]; - EmberAfPluginDoorLockHolidaySchedule mHolidaySchedule[kMaxHolidaySchedules]; + WeekDaysScheduleInfo mWeekdaySchedule[kMaxUsers][kMaxWeekdaySchedulesPerUser]; + YearDayScheduleInfo mYeardaySchedule[kMaxUsers][kMaxYeardaySchedulesPerUser]; + HolidayScheduleInfo mHolidaySchedule[kMaxHolidaySchedules]; char mUserNames[ArraySize(mLockUsers)][DOOR_LOCK_MAX_USER_NAME_SIZE]; uint8_t mCredentialData[kMaxCredentials][kMaxCredentialSize]; diff --git a/examples/lock-app/p6/src/LockManager.cpp b/examples/lock-app/p6/src/LockManager.cpp index d83b984b789779..a7560baa98ad26 100644 --- a/examples/lock-app/p6/src/LockManager.cpp +++ b/examples/lock-app/p6/src/LockManager.cpp @@ -501,7 +501,13 @@ DlStatus LockManager::GetWeekdaySchedule(chip::EndpointId endpointId, uint8_t we VerifyOrReturnValue(IsValidWeekdayScheduleIndex(weekdayIndex), DlStatus::kFailure); VerifyOrReturnValue(IsValidUserIndex(userIndex), DlStatus::kFailure); - schedule = mWeekdaySchedule[userIndex][weekdayIndex]; + const auto & scheduleInStorage = mWeekdaySchedule[userIndex][weekdayIndex]; + if (DlScheduleStatus::kAvailable == scheduleInStorage.status) + { + return DlStatus::kNotFound; + } + + schedule = scheduleInStorage.schedule; return DlStatus::kSuccess; } @@ -522,11 +528,12 @@ DlStatus LockManager::SetWeekdaySchedule(chip::EndpointId endpointId, uint8_t we auto & scheduleInStorage = mWeekdaySchedule[userIndex][weekdayIndex]; - scheduleInStorage.daysMask = daysMask; - scheduleInStorage.startHour = startHour; - scheduleInStorage.startMinute = startMinute; - scheduleInStorage.endHour = endHour; - scheduleInStorage.endMinute = endMinute; + scheduleInStorage.schedule.daysMask = daysMask; + scheduleInStorage.schedule.startHour = startHour; + scheduleInStorage.schedule.startMinute = startMinute; + scheduleInStorage.schedule.endHour = endHour; + scheduleInStorage.schedule.endMinute = endMinute; + scheduleInStorage.status = status; // Save schedule information in NVM flash P6Config::WriteConfigValueBin(P6Config::kConfigKey_WeekDaySchedules, reinterpret_cast(mWeekdaySchedule), @@ -548,9 +555,13 @@ DlStatus LockManager::GetYeardaySchedule(chip::EndpointId endpointId, uint8_t ye VerifyOrReturnValue(IsValidYeardayScheduleIndex(yearDayIndex), DlStatus::kFailure); VerifyOrReturnValue(IsValidUserIndex(userIndex), DlStatus::kFailure); - auto & scheduleInStorage = mYeardaySchedule[userIndex][yearDayIndex]; + const auto & scheduleInStorage = mYeardaySchedule[userIndex][yearDayIndex]; + if (DlScheduleStatus::kAvailable == scheduleInStorage.status) + { + return DlStatus::kNotFound; + } - schedule = scheduleInStorage; + schedule = scheduleInStorage.schedule; return DlStatus::kSuccess; } @@ -569,8 +580,9 @@ DlStatus LockManager::SetYeardaySchedule(chip::EndpointId endpointId, uint8_t ye auto & scheduleInStorage = mYeardaySchedule[userIndex][yearDayIndex]; - scheduleInStorage.localStartTime = localStartTime; - scheduleInStorage.localEndTime = localEndTime; + scheduleInStorage.schedule.localStartTime = localStartTime; + scheduleInStorage.schedule.localEndTime = localEndTime; + scheduleInStorage.status = status; // Save schedule information in NVM flash P6Config::WriteConfigValueBin(P6Config::kConfigKey_YearDaySchedules, reinterpret_cast(mYeardaySchedule), @@ -589,9 +601,13 @@ DlStatus LockManager::GetHolidaySchedule(chip::EndpointId endpointId, uint8_t ho VerifyOrReturnValue(IsValidHolidayScheduleIndex(holidayIndex), DlStatus::kFailure); - auto & scheduleInStorage = mHolidaySchedule[holidayIndex]; + const auto & scheduleInStorage = mHolidaySchedule[holidayIndex]; + if (DlScheduleStatus::kAvailable == scheduleInStorage.status) + { + return DlStatus::kNotFound; + } - schedule = scheduleInStorage; + schedule = scheduleInStorage.schedule; return DlStatus::kSuccess; } @@ -607,9 +623,10 @@ DlStatus LockManager::SetHolidaySchedule(chip::EndpointId endpointId, uint8_t ho auto & scheduleInStorage = mHolidaySchedule[holidayIndex]; - scheduleInStorage.localStartTime = localStartTime; - scheduleInStorage.localEndTime = localEndTime; - scheduleInStorage.operatingMode = operatingMode; + scheduleInStorage.schedule.localStartTime = localStartTime; + scheduleInStorage.schedule.localEndTime = localEndTime; + scheduleInStorage.schedule.operatingMode = operatingMode; + scheduleInStorage.status = status; // Save schedule information in NVM flash P6Config::WriteConfigValueBin(P6Config::kConfigKey_HolidaySchedules, reinterpret_cast(&(mHolidaySchedule)), @@ -638,43 +655,29 @@ const char * LockManager::lockStateToString(DlLockState lockState) const bool LockManager::setLockState(chip::EndpointId endpointId, DlLockState lockState, const Optional & pin, DlOperationError & err) { - DlLockState curState = DlLockState::kLocked; - if (mState == kState_UnlockCompleted) - curState = DlLockState::kUnlocked; - if ((curState == lockState) && (curState == DlLockState::kLocked)) - { - ChipLogDetail(Zcl, "Door Lock App: door is already locked, ignoring command to set lock state to \"%s\" [endpointId=%d]", - lockStateToString(lockState), endpointId); - return true; - } - else if ((curState == lockState) && (curState == DlLockState::kUnlocked)) - { - ChipLogDetail(Zcl, - "Door Lock App: door is already unlocked, ignoring command to set unlock state to \"%s\" [endpointId=%d]", - lockStateToString(lockState), endpointId); - return true; - } - - // Check the RequirePINforRemoteOperation attribute - bool requirePin = false; - // chip::app::Clusters::DoorLock::Attributes::RequirePINforRemoteOperation::Get(endpointId, &requirePin); + // Assume pin is required until told otherwise + bool requirePin = true; + chip::app::Clusters::DoorLock::Attributes::RequirePINforRemoteOperation::Get(endpointId, &requirePin); // If a pin code is not given if (!pin.HasValue()) { - ChipLogDetail(Zcl, "Door Lock App: PIN code is not specified, but it is required [endpointId=%d]", mEndpointId); - curState = lockState; + ChipLogDetail(Zcl, "Door Lock App: PIN code is not specified [endpointId=%d]", endpointId); // If a pin code is not required if (!requirePin) { ChipLogDetail(Zcl, "Door Lock App: setting door lock state to \"%s\" [endpointId=%d]", lockStateToString(lockState), endpointId); - curState = lockState; + + DoorLockServer::Instance().SetLockState(endpointId, lockState); + return true; } + ChipLogError(Zcl, "Door Lock App: PIN code is not specified, but it is required [endpointId=%d]", endpointId); + return false; } @@ -691,9 +694,9 @@ bool LockManager::setLockState(chip::EndpointId endpointId, DlLockState lockStat { ChipLogDetail(Zcl, "Lock App: specified PIN code was found in the database, setting lock state to \"%s\" [endpointId=%d]", - lockStateToString(lockState), mEndpointId); + lockStateToString(lockState), endpointId); - curState = lockState; + DoorLockServer::Instance().SetLockState(endpointId, lockState); return true; } @@ -702,7 +705,7 @@ bool LockManager::setLockState(chip::EndpointId endpointId, DlLockState lockStat ChipLogDetail(Zcl, "Door Lock App: specified PIN code was not found in the database, ignoring command to set lock state to \"%s\" " "[endpointId=%d]", - lockStateToString(lockState), mEndpointId); + lockStateToString(lockState), endpointId); err = DlOperationError::kInvalidCredential; return false; diff --git a/src/platform/P6/DiagnosticDataProviderImpl.cpp b/src/platform/P6/DiagnosticDataProviderImpl.cpp index ae3efbcf091e80..c696d813d89320 100644 --- a/src/platform/P6/DiagnosticDataProviderImpl.cpp +++ b/src/platform/P6/DiagnosticDataProviderImpl.cpp @@ -544,6 +544,59 @@ CHIP_ERROR DiagnosticDataProviderImpl::WiFiCounters(WiFiStatsCountType type, uin return err; } +CHIP_ERROR DiagnosticDataProviderImpl::GetThreadMetrics(ThreadMetrics ** threadMetricsOut) +{ + /* Obtain all available task information */ + TaskStatus_t * taskStatusArray; + ThreadMetrics * head = nullptr; + unsigned long arraySize, x, dummy; + arraySize = uxTaskGetNumberOfTasks(); + + taskStatusArray = (TaskStatus_t *) pvPortMalloc(arraySize * sizeof(TaskStatus_t)); + + if (taskStatusArray != NULL) + { + /* Generate raw status information about each task. */ + arraySize = uxTaskGetSystemState(taskStatusArray, arraySize, &dummy); + /* For each populated position in the taskStatusArray array, + format the raw data as human readable ASCII data. */ + + for (x = 0; x < arraySize; x++) + { + ThreadMetrics * thread = (ThreadMetrics *) pvPortMalloc(sizeof(ThreadMetrics)); + + strncpy(thread->NameBuf, taskStatusArray[x].pcTaskName, kMaxThreadNameLength - 1); + thread->NameBuf[kMaxThreadNameLength] = '\0'; + thread->name.Emplace(CharSpan::fromCharString(thread->NameBuf)); + thread->id = taskStatusArray[x].xTaskNumber; + + thread->stackFreeMinimum.Emplace(taskStatusArray[x].usStackHighWaterMark); + /* Unsupported metrics */ + thread->stackSize.Emplace(0); + thread->stackFreeCurrent.Emplace(0); + + thread->Next = head; + head = thread; + } + + *threadMetricsOut = head; + /* The array is no longer needed, free the memory it consumes. */ + vPortFree(taskStatusArray); + } + + return CHIP_NO_ERROR; +} + +void DiagnosticDataProviderImpl::ReleaseThreadMetrics(ThreadMetrics * threadMetrics) +{ + while (threadMetrics) + { + ThreadMetrics * del = threadMetrics; + threadMetrics = threadMetrics->Next; + vPortFree(del); + } +} + DiagnosticDataProvider & GetDiagnosticDataProviderImpl() { return DiagnosticDataProviderImpl::GetDefaultInstance(); diff --git a/src/platform/P6/DiagnosticDataProviderImpl.h b/src/platform/P6/DiagnosticDataProviderImpl.h index cba4725b43eaf4..4e75009ead2278 100644 --- a/src/platform/P6/DiagnosticDataProviderImpl.h +++ b/src/platform/P6/DiagnosticDataProviderImpl.h @@ -55,7 +55,7 @@ namespace chip { namespace DeviceLayer { /** - * Concrete implementation of the PlatformManager singleton object for Linux platforms. + * Concrete implementation of the PlatformManager singleton object for Infineon PSoC6 platforms. */ class DiagnosticDataProviderImpl : public DiagnosticDataProvider { @@ -94,6 +94,8 @@ class DiagnosticDataProviderImpl : public DiagnosticDataProvider void ReadCounters(WiFiStatsCountType Counttype, uint64_t & count, wl_cnt_ver_30_t * cnt, wl_cnt_ge40mcst_v1_t * cnt_ge40); /* Function to update ipv4 and ipv6 off premise service capability bit */ void UpdateoffPremiseService(bool ipv4service, bool ipv6service); + CHIP_ERROR GetThreadMetrics(ThreadMetrics ** threadMetricsOut) override; + void ReleaseThreadMetrics(ThreadMetrics * threadMetrics) override; /* These variables will be set to 0 during start up and will be updated when reset-counts * zcl command is received. * These are considered as base for below attributes of WiFi Diagnostics Cluster: diff --git a/third_party/p6/p6_sdk/configs/lwipopts.h b/third_party/p6/p6_sdk/configs/lwipopts.h index 86e57369dcb1aa..e0701a2cd268ac 100644 --- a/third_party/p6/p6_sdk/configs/lwipopts.h +++ b/third_party/p6/p6_sdk/configs/lwipopts.h @@ -195,7 +195,7 @@ /** * PBUF_POOL_SIZE: the number of buffers in the pbuf pool. */ -#define PBUF_POOL_SIZE 24 +#define PBUF_POOL_SIZE 48 /** * MEMP_NUM_NETBUF: the number of struct netbufs.