From 147947644fa377ac8b02c1ca32415b3a64d4afec Mon Sep 17 00:00:00 2001 From: Vivien Nicolas Date: Tue, 3 May 2022 18:24:02 +0200 Subject: [PATCH] Update src/app/tests/suites/commands/commissioner/CommissionerCommands.* --- .../commissioner/CommissionerCommands.cpp | 31 ++++++++++++------- .../commissioner/CommissionerCommands.h | 12 ++++--- 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/src/app/tests/suites/commands/commissioner/CommissionerCommands.cpp b/src/app/tests/suites/commands/commissioner/CommissionerCommands.cpp index a16fd1ad2d596c..c64e4f39339d69 100644 --- a/src/app/tests/suites/commands/commissioner/CommissionerCommands.cpp +++ b/src/app/tests/suites/commands/commissioner/CommissionerCommands.cpp @@ -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) diff --git a/src/app/tests/suites/commands/commissioner/CommissionerCommands.h b/src/app/tests/suites/commands/commissioner/CommissionerCommands.h index b840665534b92d..163903c10a96dd 100644 --- a/src/app/tests/suites/commands/commissioner/CommissionerCommands.h +++ b/src/app/tests/suites/commands/commissioner/CommissionerCommands.h @@ -21,6 +21,8 @@ #include #include +#include + class CommissionerCommands : public chip::Controller::DevicePairingDelegate { public: @@ -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;