Skip to content

Commit

Permalink
[Group] Added Group Invoke command (#12366)
Browse files Browse the repository at this point in the history
* Added InvokeCommand for group command

* Added test for group command
  • Loading branch information
mkardous-silabs authored and pull[bot] committed Jan 5, 2022
1 parent 61be6de commit 2658498
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 2 deletions.
47 changes: 46 additions & 1 deletion examples/chip-tool/commands/common/CommandInvoker.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class CommandInvoker final : public ResponseReceiver<typename RequestType::Respo

CHIP_ERROR InvokeCommand(DeviceProxy * aDevice, EndpointId aEndpoint, const RequestType & aRequestData)
{
app::CommandPathParams commandPath = { aEndpoint, 0, RequestType::GetClusterId(), RequestType::GetCommandId(),
app::CommandPathParams commandPath = { aEndpoint, 0 /* groupId */, RequestType::GetClusterId(), RequestType::GetCommandId(),
(app::CommandPathFlags::kEndpointIdValid) };
auto commandSender = Platform::MakeUnique<app::CommandSender>(this, aDevice->GetExchangeManager());
VerifyOrReturnError(commandSender != nullptr, CHIP_ERROR_NO_MEMORY);
Expand All @@ -96,6 +96,38 @@ class CommandInvoker final : public ResponseReceiver<typename RequestType::Respo
commandSender.release();
return CHIP_NO_ERROR;
}

CHIP_ERROR InvokeGroupCommand(DeviceProxy * aDevice, GroupId groupId, const RequestType & aRequestData)
{
app::CommandPathParams commandPath = { 0 /* endpoint */, groupId, RequestType::GetClusterId(), RequestType::GetCommandId(),
(app::CommandPathFlags::kGroupIdValid) };

auto commandSender = Platform::MakeUnique<app::CommandSender>(this, aDevice->GetExchangeManager());
VerifyOrReturnError(commandSender != nullptr, CHIP_ERROR_NO_MEMORY);

ReturnErrorOnFailure(commandSender->AddRequestData(commandPath, aRequestData));

if (aDevice->GetSecureSession().HasValue())
{
SessionHandle session = aDevice->GetSecureSession().Value();
session.SetGroupId(groupId);

if (!session.IsGroupSession())
{
return CHIP_ERROR_INCORRECT_STATE;
}

ReturnErrorOnFailure(commandSender->SendCommandRequest(session));
}
else
{
// something fishy is going on
return CHIP_ERROR_INCORRECT_STATE;
}

commandSender.release();
return CHIP_NO_ERROR;
}
};

template <typename ResponseType>
Expand Down Expand Up @@ -162,5 +194,18 @@ CHIP_ERROR InvokeCommand(DeviceProxy * aDevice, void * aContext,
return CHIP_NO_ERROR;
}

template <typename RequestType>
CHIP_ERROR InvokeGroupCommand(DeviceProxy * aDevice, void * aContext,
typename detail::CommandInvoker<RequestType>::SuccessCallback aSuccessCallback,
typename detail::CommandInvoker<RequestType>::FailureCallback aFailureCallback, GroupId groupId,
const RequestType & aRequestData)
{
auto invoker = detail::CommandInvoker<RequestType>::Alloc(aContext, aSuccessCallback, aFailureCallback);
VerifyOrReturnError(invoker != nullptr, CHIP_ERROR_NO_MEMORY);
ReturnErrorOnFailure(invoker->InvokeGroupCommand(aDevice, groupId, aRequestData));
invoker.release();
return CHIP_NO_ERROR;
}

} // namespace Controller
} // namespace chip
2 changes: 1 addition & 1 deletion examples/chip-tool/templates/partials/test_cluster.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ class {{filename}}: public TestCommand
(static_cast<{{filename}} *>(context))->OnFailureResponse_{{index}}(status);
};

ReturnErrorOnFailure(chip::Controller::InvokeCommand(mDevice, this, success, failure, endpoint, request));
ReturnErrorOnFailure(chip::Controller::{{#if isGroupCommand}}InvokeGroupCommand{{else}}InvokeCommand{{/if}}(mDevice, this, success, failure, {{#if isGroupCommand}}groupId{{else}}endpoint{{/if}}, request));
{{#unless async}}return CHIP_NO_ERROR;{{/unless}}
{{else}}
chip::Controller::{{asUpperCamelCase cluster}}ClusterTest cluster;
Expand Down
14 changes: 14 additions & 0 deletions src/app/tests/suites/TestGroupMessaging.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,17 @@ tests:
attribute: "location"
response:
value: ""

- label: "Turn On the light to see attribute change"
cluster: "On/Off"
command: "On"
groupId: "1234"
disabled: true

- label: "Check on/off attribute value is true after on command"
cluster: "On/Off"
command: "readAttribute"
attribute: "OnOff"
disabled: true
response:
value: 1
4 changes: 4 additions & 0 deletions src/app/zap-templates/common/ClusterTestGeneration.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ function setDefaultTypeForCommand(test)
default:
test.commandName = test.command;
test.isCommand = true;
if ((kGroupId in test)) {
test.isGroupCommand = true;
test.groupId = parseInt(test[kGroupId], 10);
}
break;
}

Expand Down

0 comments on commit 2658498

Please sign in to comment.