From 1452440b2230d1c67658ce3771d1d0c8b84b0eae Mon Sep 17 00:00:00 2001 From: Vivien Nicolas Date: Wed, 22 Feb 2023 15:52:06 +0100 Subject: [PATCH] [chip-tool] Add discover-once parameter to DiscoverCommissionablesCommand such that it only returns a single result by default to mimick what the test harness is doing (#25223) --- .../commands/discover/DiscoverCommissionablesCommand.cpp | 7 ++++++- .../commands/discover/DiscoverCommissionablesCommand.h | 8 +++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/examples/chip-tool/commands/discover/DiscoverCommissionablesCommand.cpp b/examples/chip-tool/commands/discover/DiscoverCommissionablesCommand.cpp index 0eeeb3a85f9edd..ad474039d07f65 100644 --- a/examples/chip-tool/commands/discover/DiscoverCommissionablesCommand.cpp +++ b/examples/chip-tool/commands/discover/DiscoverCommissionablesCommand.cpp @@ -26,7 +26,12 @@ void DiscoverCommissionablesCommandBase::OnDiscoveredDevice(const chip::Dnssd::D { nodeData.LogDetail(); LogErrorOnFailure(RemoteDataModelLogger::LogDiscoveredNodeData(nodeData)); - SetCommandExitStatus(CHIP_NO_ERROR); + + if (mDiscoverOnce.ValueOr(true)) + { + CurrentCommissioner().StopCommissionableDiscovery(); + SetCommandExitStatus(CHIP_NO_ERROR); + } } CHIP_ERROR DiscoverCommissionablesCommand::RunCommand() diff --git a/examples/chip-tool/commands/discover/DiscoverCommissionablesCommand.h b/examples/chip-tool/commands/discover/DiscoverCommissionablesCommand.h index 58ee5a0500ba1d..b0bff0e4e113e0 100644 --- a/examples/chip-tool/commands/discover/DiscoverCommissionablesCommand.h +++ b/examples/chip-tool/commands/discover/DiscoverCommissionablesCommand.h @@ -25,13 +25,19 @@ class DiscoverCommissionablesCommandBase : public CHIPCommand, public chip::Cont public: DiscoverCommissionablesCommandBase(const char * name, CredentialIssuerCommands * credsIssuerConfig) : CHIPCommand(name, credsIssuerConfig) - {} + { + AddArgument("discover-once", 0, 1, &mDiscoverOnce, + "Boolean indicating whether to stop discovery after the first result. Defaults to true."); + } /////////// DeviceDiscoveryDelegate Interface ///////// void OnDiscoveredDevice(const chip::Dnssd::DiscoveredNodeData & nodeData) override; /////////// CHIPCommand Interface ///////// chip::System::Clock::Timeout GetWaitDuration() const override { return chip::System::Clock::Seconds16(30); } + +private: + chip::Optional mDiscoverOnce; }; class DiscoverCommissionablesCommand : public DiscoverCommissionablesCommandBase