Skip to content

Commit

Permalink
Update src/app/tests/suites/commands/commissioner/CommissionerCommands.*
Browse files Browse the repository at this point in the history
  • Loading branch information
vivien-apple committed May 4, 2022
1 parent 4e5ae02 commit 1479476
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 16 deletions.
31 changes: 19 additions & 12 deletions src/app/tests/suites/commands/commissioner/CommissionerCommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,38 @@

constexpr uint16_t kPayloadMaxSize = 64;

CHIP_ERROR CommissionerCommands::PairWithQRCode(chip::NodeId nodeId, const chip::CharSpan payload)
CHIP_ERROR
CommissionerCommands::PairWithQRCode(const char * identity,
const chip::app::Clusters::CommissionerCommands::Commands::PairWithQRCode::Type & value)
{
VerifyOrReturnError(payload.size() > 0 && payload.size() < kPayloadMaxSize, CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(value.payload.size() > 0 && value.payload.size() < kPayloadMaxSize, CHIP_ERROR_INVALID_ARGUMENT);

GetCurrentCommissioner().RegisterPairingDelegate(this);
GetCommissioner(identity).RegisterPairingDelegate(this);

char qrCode[kPayloadMaxSize];
memcpy(qrCode, payload.data(), payload.size());
return GetCurrentCommissioner().PairDevice(nodeId, qrCode);
memset(qrCode, '\0', sizeof(qrCode));
memcpy(qrCode, value.payload.data(), value.payload.size());
ChipLogError(chipTool, "QRCode is %s", qrCode);
return GetCommissioner(identity).PairDevice(value.nodeId, qrCode);
}

CHIP_ERROR CommissionerCommands::PairWithManualCode(chip::NodeId nodeId, const chip::CharSpan payload)
CHIP_ERROR CommissionerCommands::PairWithManualCode(
const char * identity, const chip::app::Clusters::CommissionerCommands::Commands::PairWithManualCode::Type & value)
{
VerifyOrReturnError(payload.size() > 0 && payload.size() < kPayloadMaxSize, CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(value.payload.size() > 0 && value.payload.size() < kPayloadMaxSize, CHIP_ERROR_INVALID_ARGUMENT);

GetCurrentCommissioner().RegisterPairingDelegate(this);
GetCommissioner(identity).RegisterPairingDelegate(this);

char manualCode[kPayloadMaxSize];
memcpy(manualCode, payload.data(), payload.size());
return GetCurrentCommissioner().PairDevice(nodeId, manualCode);
memset(manualCode, '\0', sizeof(manualCode));
memcpy(manualCode, value.payload.data(), value.payload.size());
return GetCommissioner(identity).PairDevice(value.nodeId, manualCode);
}

CHIP_ERROR CommissionerCommands::Unpair(chip::NodeId nodeId)
CHIP_ERROR CommissionerCommands::Unpair(const char * identity,
const chip::app::Clusters::CommissionerCommands::Commands::Unpair::Type & value)
{
return GetCurrentCommissioner().UnpairDevice(nodeId);
return GetCommissioner(identity).UnpairDevice(value.nodeId);
}

chip::app::StatusIB ConvertToStatusIB(CHIP_ERROR err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#include <controller/CHIPDeviceController.h>
#include <lib/support/CodeUtils.h>

#include <app-common/zap-generated/tests/simulated-cluster-objects.h>

class CommissionerCommands : public chip::Controller::DevicePairingDelegate
{
public:
Expand All @@ -29,11 +31,13 @@ class CommissionerCommands : public chip::Controller::DevicePairingDelegate

virtual void OnResponse(const chip::app::StatusIB & status, chip::TLV::TLVReader * data) = 0;
virtual CHIP_ERROR ContinueOnChipMainThread(CHIP_ERROR err) = 0;
virtual chip::Controller::DeviceCommissioner & GetCurrentCommissioner() = 0;
virtual chip::Controller::DeviceCommissioner & GetCommissioner(const char * identity) = 0;

CHIP_ERROR PairWithQRCode(chip::NodeId nodeId, const chip::CharSpan payload);
CHIP_ERROR PairWithManualCode(chip::NodeId nodeId, const chip::CharSpan payload);
CHIP_ERROR Unpair(chip::NodeId nodeId);
CHIP_ERROR PairWithQRCode(const char * identity,
const chip::app::Clusters::CommissionerCommands::Commands::PairWithQRCode::Type & value);
CHIP_ERROR PairWithManualCode(const char * identity,
const chip::app::Clusters::CommissionerCommands::Commands::PairWithManualCode::Type & value);
CHIP_ERROR Unpair(const char * identity, const chip::app::Clusters::CommissionerCommands::Commands::Unpair::Type & value);

/////////// DevicePairingDelegate Interface /////////
void OnStatusUpdate(chip::Controller::DevicePairingDelegate::Status status) override;
Expand Down

0 comments on commit 1479476

Please sign in to comment.