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

[SL-UP] 917 static variable retention fix #79

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
22 changes: 15 additions & 7 deletions examples/lock-app/silabs/include/LockManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,12 @@ class LockManager
private:
struct UnlatchContext
{
static constexpr uint8_t kMaxPinLength = UINT8_MAX;
uint8_t mPinBuffer[kMaxPinLength];
uint8_t mPinLength;
chip::EndpointId mEndpointId;
Nullable<chip::FabricIndex> mFabricIdx;
Nullable<chip::NodeId> mNodeId;
Optional<chip::ByteSpan> mPin;
OperationErrorEnum mErr;

void Update(chip::EndpointId endpointId, const Nullable<chip::FabricIndex> & fabricIdx,
Expand All @@ -211,8 +213,18 @@ class LockManager
mEndpointId = endpointId;
mFabricIdx = fabricIdx;
mNodeId = nodeId;
mPin = pin;
mErr = err;

if (pin.HasValue())
{
memcpy(mPinBuffer, pin.Value().data(), pin.Value().size());
mPinLength = static_cast<uint8_t>(pin.Value().size());
}
else
{
memset(mPinBuffer, 0, kMaxPinLength);
mPinLength = 0;
}
}
};
UnlatchContext mUnlatchContext;
Expand Down Expand Up @@ -242,11 +254,7 @@ class LockManager
uint8_t mCredentialData[kNumCredentialTypes][kMaxCredentials][kMaxCredentialSize];
CredentialStruct mCredentials[kMaxUsers][kMaxCredentials];

static LockManager sLock;
EFR32DoorLock::LockInitParams::LockParam LockParams;
};

inline LockManager & LockMgr()
{
return LockManager::sLock;
}
LockManager & LockMgr();
13 changes: 10 additions & 3 deletions examples/lock-app/silabs/src/LockManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,18 @@
#include <cstring>
#include <lib/support/logging/CHIPLogging.h>

LockManager LockManager::sLock;

using namespace ::chip::DeviceLayer::Internal;
using namespace EFR32DoorLock::LockInitParams;

namespace {
LockManager sLock;
} // namespace

LockManager & LockMgr()
{
return sLock;
}

CHIP_ERROR LockManager::Init(chip::app::DataModel::Nullable<chip::app::Clusters::DoorLock::DlLockState> state, LockParam lockParam)
{

Expand Down Expand Up @@ -258,7 +265,7 @@ void LockManager::UnlockAfterUnlatch()
if (mUnlatchContext.mEndpointId != kInvalidEndpointId)
{
succes = setLockState(mUnlatchContext.mEndpointId, mUnlatchContext.mFabricIdx, mUnlatchContext.mNodeId,
DlLockState::kUnlocked, mUnlatchContext.mPin, mUnlatchContext.mErr);
DlLockState::kUnlocked, MakeOptional(chip::ByteSpan(mUnlatchContext.mPinBuffer, mUnlatchContext.mPinLength)), mUnlatchContext.mErr);
}

if (!succes)
Expand Down
Loading