From 20749652c52ddd9ad63052db343f208cea336bde Mon Sep 17 00:00:00 2001 From: Vivien Nicolas Date: Thu, 2 Jun 2022 15:58:35 +0200 Subject: [PATCH] [chip-tool] Add --repeat-count and --repeat-delay-ms to write commands (#18999) --- .../commands/clusters/WriteAttributeCommand.h | 6 ++- .../interaction_model/InteractionModel.h | 49 ++++++++++++------- 2 files changed, 36 insertions(+), 19 deletions(-) diff --git a/examples/chip-tool/commands/clusters/WriteAttributeCommand.h b/examples/chip-tool/commands/clusters/WriteAttributeCommand.h index 231526453775ed..93ca6d167fc41b 100644 --- a/examples/chip-tool/commands/clusters/WriteAttributeCommand.h +++ b/examples/chip-tool/commands/clusters/WriteAttributeCommand.h @@ -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 @@ -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(); } @@ -122,4 +124,6 @@ class WriteAttribute : public InteractionModelWriter, public ModelCommand, publi chip::Optional mDataVersion = chip::NullOptional; chip::Optional mSuppressResponse; CustomArgument mAttributeValue; + chip::Optional mRepeatCount; + chip::Optional mRepeatDelayInMs; }; diff --git a/src/app/tests/suites/commands/interaction_model/InteractionModel.h b/src/app/tests/suites/commands/interaction_model/InteractionModel.h index b7b983fe550185..7ce5e03c398c7d 100644 --- a/src/app/tests/suites/commands/interaction_model/InteractionModel.h +++ b/src/app/tests/suites/commands/interaction_model/InteractionModel.h @@ -174,30 +174,43 @@ class InteractionModelWriter chip::AttributeId attributeId, const T & value, const chip::Optional & timedInteractionTimeoutMs = chip::NullOptional, const chip::Optional & suppressResponse = chip::NullOptional, - const chip::Optional & dataVersion = chip::NullOptional) + const chip::Optional & dataVersion = chip::NullOptional, + const chip::Optional & repeatCount = chip::NullOptional, + const chip::Optional & 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(device->GetExchangeManager(), &mChunkedWriteCallback, + timedInteractionTimeoutMs, suppressResponse.ValueOr(false)); + VerifyOrReturnError(mWriteClient != nullptr, CHIP_ERROR_NO_MEMORY); - mWriteClient = std::make_unique(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