Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Infineon PSoC6] Fix for Door lock and Software Diagnostics Cluster #22169

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions examples/lock-app/p6/include/LockManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,24 @@

#include <lib/core/CHIPError.h>

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
Expand Down Expand Up @@ -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];
Expand Down
85 changes: 44 additions & 41 deletions examples/lock-app/p6/src/LockManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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<const uint8_t *>(mWeekdaySchedule),
Expand All @@ -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;
}
Expand All @@ -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<const uint8_t *>(mYeardaySchedule),
Expand All @@ -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;
}
Expand All @@ -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<const uint8_t *>(&(mHolidaySchedule)),
Expand Down Expand Up @@ -638,43 +655,29 @@ const char * LockManager::lockStateToString(DlLockState lockState) const
bool LockManager::setLockState(chip::EndpointId endpointId, DlLockState lockState, const Optional<chip::ByteSpan> & 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;
}

Expand All @@ -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;
}
Expand All @@ -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;
Expand Down
53 changes: 53 additions & 0 deletions src/platform/P6/DiagnosticDataProviderImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
woody-apple marked this conversation as resolved.
Show resolved Hide resolved

strncpy(thread->NameBuf, taskStatusArray[x].pcTaskName, kMaxThreadNameLength - 1);
woody-apple marked this conversation as resolved.
Show resolved Hide resolved
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;
woody-apple marked this conversation as resolved.
Show resolved Hide resolved
}

void DiagnosticDataProviderImpl::ReleaseThreadMetrics(ThreadMetrics * threadMetrics)
{
while (threadMetrics)
{
ThreadMetrics * del = threadMetrics;
threadMetrics = threadMetrics->Next;
vPortFree(del);
}
}

DiagnosticDataProvider & GetDiagnosticDataProviderImpl()
{
return DiagnosticDataProviderImpl::GetDefaultInstance();
Expand Down
4 changes: 3 additions & 1 deletion src/platform/P6/DiagnosticDataProviderImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion third_party/p6/p6_sdk/configs/lwipopts.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down