Skip to content

Commit

Permalink
Make the IM command timeouts in chip-tool configurable. (#16122)
Browse files Browse the repository at this point in the history
Adds a --timeout optional command-line argument (to match the one that
test commands have).

Also changes the default timeout for read/subscribe from 10s to 30s,
because wildcard read/subscribe can take a while.

#16118
  • Loading branch information
bzbarsky-apple authored and pull[bot] committed Jun 23, 2023
1 parent 8dbb4e2 commit 339fec3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
6 changes: 5 additions & 1 deletion examples/chip-tool/commands/clusters/ModelCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,12 @@ class ModelCommand : public CHIPCommand
{
AddArgument("node-id/group-id", 0, UINT64_MAX, &mNodeId);
AddArgument("endpoint-id-ignored-for-group-commands", 0, UINT16_MAX, &mEndPointId);
AddArgument("timeout", 0, UINT16_MAX, &mTimeout);
}

/////////// CHIPCommand Interface /////////
CHIP_ERROR RunCommand() override;
chip::System::Clock::Timeout GetWaitDuration() const override { return chip::System::Clock::Seconds16(10); }
chip::System::Clock::Timeout GetWaitDuration() const override { return chip::System::Clock::Seconds16(mTimeout.ValueOr(10)); }

virtual CHIP_ERROR SendCommand(ChipDevice * device, std::vector<chip::EndpointId> endPointIds) = 0;

Expand All @@ -55,6 +56,9 @@ class ModelCommand : public CHIPCommand
mOnDeviceConnectionFailureCallback.Cancel();
}

protected:
chip::Optional<uint16_t> mTimeout;

private:
chip::NodeId mNodeId;
std::vector<chip::EndpointId> mEndPointId;
Expand Down
11 changes: 9 additions & 2 deletions examples/chip-tool/commands/clusters/ReportCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,13 @@ class ReportCommand : public ModelCommand, public chip::app::ReadClient::Callbac
return mReadClient->SendRequest(params);
}

// Use a 3x-longer-than-default timeout because wildcard reads can take a
// while.
chip::System::Clock::Timeout GetWaitDuration() const override
{
return mTimeout.HasValue() ? chip::System::Clock::Seconds16(mTimeout.Value()) : (ModelCommand::GetWaitDuration() * 3);
}

std::unique_ptr<chip::app::ReadClient> mReadClient;
chip::app::BufferedReadCallback mBufferedReadAdapter;

Expand Down Expand Up @@ -411,7 +418,7 @@ class SubscribeAttribute : public ReportCommand

chip::System::Clock::Timeout GetWaitDuration() const override
{
return chip::System::Clock::Seconds16(mWait ? UINT16_MAX : 10);
return mWait ? chip::System::Clock::Seconds16(UINT16_MAX) : ReportCommand::GetWaitDuration();
}

void OnAttributeSubscription() override
Expand Down Expand Up @@ -525,7 +532,7 @@ class SubscribeEvent : public ReportCommand

chip::System::Clock::Timeout GetWaitDuration() const override
{
return chip::System::Clock::Seconds16(mWait ? UINT16_MAX : 10);
return mWait ? chip::System::Clock::Seconds16(UINT16_MAX) : ReportCommand::GetWaitDuration();
}

void OnEventSubscription() override
Expand Down

0 comments on commit 339fec3

Please sign in to comment.