Skip to content

Commit

Permalink
[chip-tool] Add --repeat-count and --repeat-delay-ms to write commands (
Browse files Browse the repository at this point in the history
  • Loading branch information
vivien-apple authored and pull[bot] committed Oct 16, 2023
1 parent b61394c commit 2074965
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 19 deletions.
6 changes: 5 additions & 1 deletion examples/chip-tool/commands/clusters/WriteAttributeCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class WriteAttribute : public InteractionModelWriter, public ModelCommand, publi
ChipLogProgress(chipTool, "Sending WriteAttribute to cluster " ChipLogFormatMEI " on endpoint %u",
ChipLogValueMEI(clusterId), endpointId);
return InteractionModelWriter::WriteAttribute(device, endpointId, clusterId, attributeId, value, mTimedInteractionTimeoutMs,
mSuppressResponse, mDataVersion);
mSuppressResponse, mDataVersion, mRepeatCount, mRepeatDelayInMs);
}

template <class T>
Expand All @@ -111,6 +111,8 @@ class WriteAttribute : public InteractionModelWriter, public ModelCommand, publi
"If provided, do a timed write with the given timed interaction timeout.");
AddArgument("data-version", 0, UINT32_MAX, &mDataVersion);
AddArgument("suppressResponse", 0, 1, &mSuppressResponse);
AddArgument("repeat-count", 1, UINT16_MAX, &mRepeatCount);
AddArgument("repeat-delay-ms", 0, UINT16_MAX, &mRepeatDelayInMs);
ModelCommand::AddArguments();
}

Expand All @@ -122,4 +124,6 @@ class WriteAttribute : public InteractionModelWriter, public ModelCommand, publi
chip::Optional<chip::DataVersion> mDataVersion = chip::NullOptional;
chip::Optional<bool> mSuppressResponse;
CustomArgument mAttributeValue;
chip::Optional<uint16_t> mRepeatCount;
chip::Optional<uint16_t> mRepeatDelayInMs;
};
49 changes: 31 additions & 18 deletions src/app/tests/suites/commands/interaction_model/InteractionModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,30 +174,43 @@ class InteractionModelWriter
chip::AttributeId attributeId, const T & value,
const chip::Optional<uint16_t> & timedInteractionTimeoutMs = chip::NullOptional,
const chip::Optional<bool> & suppressResponse = chip::NullOptional,
const chip::Optional<chip::DataVersion> & dataVersion = chip::NullOptional)
const chip::Optional<chip::DataVersion> & dataVersion = chip::NullOptional,
const chip::Optional<uint16_t> & repeatCount = chip::NullOptional,
const chip::Optional<uint16_t> & repeatDelayInMs = chip::NullOptional)
{
chip::app::AttributePathParams attributePathParams;
if (endpointId != chip::kInvalidEndpointId)
uint16_t repeat = repeatCount.ValueOr(1);
while (repeat--)
{
attributePathParams.mEndpointId = endpointId;
}
chip::app::AttributePathParams attributePathParams;
if (endpointId != chip::kInvalidEndpointId)
{
attributePathParams.mEndpointId = endpointId;
}

if (clusterId != chip::kInvalidClusterId)
{
attributePathParams.mClusterId = clusterId;
}
if (clusterId != chip::kInvalidClusterId)
{
attributePathParams.mClusterId = clusterId;
}

if (attributeId != chip::kInvalidAttributeId)
{
attributePathParams.mAttributeId = attributeId;
}
if (attributeId != chip::kInvalidAttributeId)
{
attributePathParams.mAttributeId = attributeId;
}

mWriteClient = std::make_unique<chip::app::WriteClient>(device->GetExchangeManager(), &mChunkedWriteCallback,
timedInteractionTimeoutMs, suppressResponse.ValueOr(false));
VerifyOrReturnError(mWriteClient != nullptr, CHIP_ERROR_NO_MEMORY);

mWriteClient = std::make_unique<chip::app::WriteClient>(device->GetExchangeManager(), &mChunkedWriteCallback,
timedInteractionTimeoutMs, suppressResponse.ValueOr(false));
VerifyOrReturnError(mWriteClient != nullptr, CHIP_ERROR_NO_MEMORY);
ReturnErrorOnFailure(mWriteClient->EncodeAttribute(attributePathParams, value, dataVersion));
ReturnErrorOnFailure(mWriteClient->SendWriteRequest(device->GetSecureSession().Value()));

ReturnErrorOnFailure(mWriteClient->EncodeAttribute(attributePathParams, value, dataVersion));
return mWriteClient->SendWriteRequest(device->GetSecureSession().Value());
if (repeatDelayInMs.HasValue())
{
chip::test_utils::SleepMillis(repeatDelayInMs.Value());
}
}

return CHIP_NO_ERROR;
}

template <class T>
Expand Down

0 comments on commit 2074965

Please sign in to comment.