Skip to content

Commit

Permalink
Bump build timeout on k32w. (project-chip#25116)
Browse files Browse the repository at this point in the history
We keep hitting the timeout, even at 50 minutes.
  • Loading branch information
bzbarsky-apple authored and krypton36 committed Feb 17, 2023
1 parent e08d4e5 commit 9f1db7e
Showing 1 changed file with 228 additions and 0 deletions.
228 changes: 228 additions & 0 deletions examples/lock-app/linux/src/LockAppCommandDelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include "LockAppCommandDelegate.h"
#include <platform/PlatformManager.h>
#include <lib/support/BytesToHex.h>

#include <LockManager.h>
#include <utility>
Expand Down Expand Up @@ -131,6 +132,233 @@ void LockAppCommandHandler::HandleCommand(intptr_t context)
alarmCode));
LockManager::Instance().SendLockAlarm(endpointId, static_cast<AlarmCodeEnum>(alarmCode));
}
else if (self->mCommandName == "Lock")
{
OperationErrorEnum error = OperationErrorEnum::kUnspecified;
VerifyOrExit(
params.isMember("CredentialData"),
ChipLogError(NotSpecified, "Lock App: Unable to execute command to send lock: CredentialData is missing in command"));

VerifyOrExit(
params["CredentialData"].isString(),
ChipLogError(NotSpecified, "Lock App: Unable to execute command to send lock: invalid type for CredentialData"));


size_t size = strlen(params["CredentialData"].asCString());
VerifyOrExit(size % 2 == 0, CHIP_ERROR_INVALID_STRING_LENGTH);

chip::Platform::ScopedMemoryBuffer<uint8_t> buffer;
VerifyOrExit(buffer.Calloc(size / 2), CHIP_ERROR_NO_MEMORY);
size_t octetCount = chip::Encoding::HexToBytes(params["CredentialData"].asCString(), size,
buffer.Get(), size / 2);
Optional<chip::ByteSpan> credentialData(chip::ByteSpan(buffer.Get(), octetCount));
ChipLogProgress(NotSpecified, "Recevied Lock: %s", params["CredentialData"].asCString());
LockManager::Instance().Lock(endpointId, credentialData, error, OperationSourceEnum::kUnspecified);
VerifyOrExit(
error != OperationErrorEnum::kUnspecified,
ChipLogError(NotSpecified, "Lock App: Lock error received: %hhu", to_underlying(error)));
}
else if (self->mCommandName == "Unlock")
{
OperationErrorEnum error = OperationErrorEnum::kUnspecified;
VerifyOrExit(
params.isMember("CredentialData"),
ChipLogError(NotSpecified, "Lock App: Unable to execute command to send unlock: CredentialData is missing in command"));

VerifyOrExit(
params["CredentialData"].isString(),
ChipLogError(NotSpecified, "Lock App: Unable to execute command to send unlock: invalid type for CredentialData"));


size_t size = strlen(params["CredentialData"].asCString());
VerifyOrExit(size % 2 == 0, CHIP_ERROR_INVALID_STRING_LENGTH);

chip::Platform::ScopedMemoryBuffer<uint8_t> buffer;
VerifyOrExit(buffer.Calloc(size / 2), CHIP_ERROR_NO_MEMORY);
size_t octetCount = chip::Encoding::HexToBytes(params["CredentialData"].asCString(), size,
buffer.Get(), size / 2);
Optional<chip::ByteSpan> credentialData;
credentialData.SetValue(chip::ByteSpan(buffer.Get(), octetCount));
ChipLogProgress(NotSpecified, "Recevied Unlock: %s", params["CredentialData"].asCString());
LockManager::Instance().Unlock(endpointId, credentialData, error, OperationSourceEnum::kUnspecified);
VerifyOrExit(
error != OperationErrorEnum::kUnspecified,
ChipLogError(NotSpecified, "Lock App: Unlock error received: %hhu", to_underlying(error)));
}
else if (self->mCommandName == "SetCredential")
{
VerifyOrExit(
params.isMember("CredentialIndex"),
ChipLogError(NotSpecified, "Lock App: Unable to execute command to set credential: CredentialIndex is missing in command"));

VerifyOrExit(
params["CredentialIndex"].isUInt(),
ChipLogError(NotSpecified, "Lock App: Unable to execute command to set credential: invalid type for CredentialData"));
auto credentialIndex = params["CredentialIndex"].asUInt();

VerifyOrExit(
params.isMember("Creator"),
ChipLogError(NotSpecified, "Lock App: Unable to execute command to set credential: Creator is missing in command"));

VerifyOrExit(
params["Creator"].isUInt(),
ChipLogError(NotSpecified, "Lock App: Unable to execute command to set credential: invalid type for Creator"));

auto creator = params["Creator"].asUInt();

VerifyOrExit(
params.isMember("Modifier"),
ChipLogError(NotSpecified, "Lock App: Unable to execute command to send unlock: Modifier is missing in command"));

VerifyOrExit(
params["Modifier"].isUInt(),
ChipLogError(NotSpecified, "Lock App: Unable to execute command to set credential: invalid type for Modifier"));

auto modifier = params["Modifier"].asUInt();

VerifyOrExit(
params.isMember("CredentialStatus"),
ChipLogError(NotSpecified, "Lock App: Unable to execute command to set credential: CredentialStatus is missing in command"));

VerifyOrExit(
params["CredentialStatus"].isUInt(),
ChipLogError(NotSpecified, "Lock App: Unable to execute command to set credential: invalid type for CredentialStatus"));
auto credentialStatus = params["CredentialStatus"].asUInt();
VerifyOrExit(
credentialStatus <= to_underlying(DlCredentialStatus::kOccupied),
ChipLogError(NotSpecified,
"Lock App: Unable to execute command to set credential: CredentialStatus is out of range [credentialStatus=%u]",
credentialStatus));

VerifyOrExit(
params.isMember("CredentialType"),
ChipLogError(NotSpecified, "Lock App: Unable to execute command to set credential: CredentialType is missing in command"));

VerifyOrExit(
params["CredentialType"].isUInt(),
ChipLogError(NotSpecified, "Lock App: Unable to execute command to set credential: invalid type for CredentialType"));
auto credentialType = params["CredentialType"].asUInt();
VerifyOrExit(
credentialType < to_underlying(CredentialTypeEnum::kUnknownEnumValue),
ChipLogError(NotSpecified,
"Lock App: Unable to execute command to set credential: CredentialType is out of range [credentialType=%u]",
credentialType));

if (params.isMember("Remove")) {
VerifyOrExit(
params["Remove"].isBool(),
ChipLogError(NotSpecified, "Lock App: Unable to set credential: invalid type for Remove"));
}
if (params.isMember("Remove") && params["Remove"].asBool() == true) {
LockManager::Instance().SetCredential(endpointId, static_cast<uint16_t>(credentialIndex), static_cast<chip::FabricIndex>(creator), static_cast<chip::FabricIndex>(modifier), static_cast<DlCredentialStatus>(credentialStatus), static_cast<CredentialTypeEnum>(credentialType),
chip::ByteSpan());
} else {
VerifyOrExit(
params.isMember("CredentialData"),
ChipLogError(NotSpecified, "Lock App: Unable set credential: CredentialData is missing in command"));

VerifyOrExit(
params["CredentialData"].isString(),
ChipLogError(NotSpecified, "Lock App: Unable to set credential: invalid type for CredentialData"));


size_t size = strlen(params["CredentialData"].asCString());
VerifyOrExit(size % 2 == 0, CHIP_ERROR_INVALID_STRING_LENGTH);
VerifyOrExit(size > 0, CHIP_ERROR_INVALID_STRING_LENGTH);

chip::Platform::ScopedMemoryBuffer<uint8_t> buffer;
VerifyOrExit(buffer.Calloc(size / 2), CHIP_ERROR_NO_MEMORY);
size_t octetCount = chip::Encoding::HexToBytes(params["CredentialData"].asCString(), size,
buffer.Get(), size / 2);
chip::ByteSpan credentialData(chip::ByteSpan(buffer.Get(), octetCount));
LockManager::Instance().SetCredential(endpointId, static_cast<uint16_t>(credentialIndex), static_cast<chip::FabricIndex>(creator), static_cast<chip::FabricIndex>(modifier), static_cast<DlCredentialStatus>(credentialStatus), static_cast<CredentialTypeEnum>(credentialType),
credentialData);
}
}
else if (self->mCommandName == "GetCredential")
{
VerifyOrExit(
params.isMember("CredentialIndex"),
ChipLogError(NotSpecified, "Lock App: Unable to get credential: CredentialIndex is missing in command"));

VerifyOrExit(
params["CredentialIndex"].isUInt(),
ChipLogError(NotSpecified, "Lock App: Unable to get credential: invalid type for CredentialData"));
auto credentialIndex = params["CredentialIndex"].asUInt();

VerifyOrExit(
params.isMember("CredentialType"),
ChipLogError(NotSpecified, "Lock App: Unable get credential: CredentialType is missing in command"));

VerifyOrExit(
params["CredentialType"].isUInt(),
ChipLogError(NotSpecified, "Lock App: Unable get credential: invalid type for CredentialType"));
auto credentialType = params["CredentialType"].asUInt();
VerifyOrExit(
credentialType < to_underlying(CredentialTypeEnum::kUnknownEnumValue),
ChipLogError(NotSpecified,
"Lock App: Unable to get credential: CredentialType is out of range [credentialType=%u]",
credentialType));

EmberAfPluginDoorLockCredentialInfo credentialData;
bool result = LockManager::Instance().GetCredential(endpointId, static_cast<uint16_t>(credentialIndex), static_cast<CredentialTypeEnum>(credentialType),
credentialData);

if (result) {
char dest_hex_str [500];
chip::Encoding::BytesToHex(credentialData.credentialData.data(), credentialData.credentialData.size(), dest_hex_str, 500, chip::Encoding::HexFlags::kUppercaseAndNullTerminate);
ChipLogProgress(NotSpecified, "CredentialInfo: {\"status\":%s,\"type\":%s,\"data\":\"%s\",\"creator\":%s,\"modifier\":%s}",
std::to_string(chip::to_underlying(credentialData.status)).c_str(),
std::to_string(chip::to_underlying(credentialData.credentialType)).c_str(),
dest_hex_str,
std::to_string(credentialData.createdBy).c_str(),
std::to_string(credentialData.lastModifiedBy).c_str());
}
}
else if (self->mCommandName == "GetUser")
{
VerifyOrExit(
params.isMember("UserIndex"),
ChipLogError(NotSpecified, "Lock App: Unable to get User. UserIndex not passed in."));

VerifyOrExit(
params["UserIndex"].isUInt(),
ChipLogError(NotSpecified, "Lock App: Unable to get user. Invalid param."));
auto userIndex = params["UserIndex"].asUInt();


EmberAfPluginDoorLockUserInfo userInfo;
bool result = LockManager::Instance().GetUser(endpointId, static_cast<uint16_t>(userIndex), userInfo);

if (result) {
std::string credentialStringDict;
size_t credentialsCount = 0;
credentialStringDict += "[";
size_t last = userInfo.credentials.size();
for (const auto & c : userInfo.credentials)
{
credentialStringDict += "{";
credentialStringDict += "\"credentialType\":" + std::to_string(chip::to_underlying(c.credentialType)) + ",";
credentialStringDict += "\"credentialIndex\":" + std::to_string(c.credentialIndex);
credentialStringDict += "}";
credentialsCount++;
if (last != credentialsCount) {
credentialStringDict += ",";
}
}
credentialStringDict += "]";

ChipLogProgress(NotSpecified, "UserInfo: {\"userName\":\"%s\",\"credentials\":%s,\"uniqueID\":\"%s\",\"userStatus\":%s,\"userType\":%s,\"credentialRule\":%s,\"creator\":%s,\"modifier\":%s}",
userInfo.userName.data(),
credentialStringDict.c_str(),
std::to_string(userInfo.userUniqueId).c_str(),
std::to_string(chip::to_underlying(userInfo.userStatus)).c_str(),
std::to_string(chip::to_underlying(userInfo.userType)).c_str(),
std::to_string(chip::to_underlying(userInfo.credentialRule)).c_str(),
std::to_string(userInfo.createdBy).c_str(),
std::to_string(userInfo.lastModifiedBy).c_str());
}
}
else
{
ChipLogError(NotSpecified, "Lock App: Unable to execute command \"%s\": command not supported", self->mCommandName.c_str());
Expand Down

0 comments on commit 9f1db7e

Please sign in to comment.