Skip to content

Commit

Permalink
[chip-tool] Add Optional endpoint id for the test command (#11740)
Browse files Browse the repository at this point in the history
* [chip-tool] Add optional endpoint id for the test command

* Update generated content
  • Loading branch information
vivien-apple authored and pull[bot] committed Dec 16, 2022
1 parent cafd04a commit 1380541
Show file tree
Hide file tree
Showing 7 changed files with 1,997 additions and 1,107 deletions.
4 changes: 0 additions & 4 deletions examples/chip-tool/commands/clusters/ModelCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@
#include <controller/ExampleOperationalCredentialsIssuer.h>
#include <lib/core/CHIPEncoding.h>

// Limits on endpoint values.
#define CHIP_ZCL_ENDPOINT_MIN 0x00
#define CHIP_ZCL_ENDPOINT_MAX 0xF0

class ModelCommand : public CHIPCommand
{
public:
Expand Down
20 changes: 10 additions & 10 deletions examples/chip-tool/commands/common/Command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ bool Command::InitArgument(size_t argIndex, char * argValue)

case ArgumentType::OctetString: {
if (arg.optional)
arg.value = &(reinterpret_cast<chip::Optional<chip::ByteSpan *> *>(arg.value))->Emplace();
arg.value = &(reinterpret_cast<chip::Optional<chip::ByteSpan> *>(arg.value))->Emplace();
auto * value = static_cast<chip::ByteSpan *>(arg.value);
// We support two ways to pass an octet string argument. If it happens
// to be all-ASCII, you can just pass it in. Otherwise you can pass in
Expand Down Expand Up @@ -189,7 +189,7 @@ bool Command::InitArgument(size_t argIndex, char * argValue)
case ArgumentType::Boolean:
case ArgumentType::Number_uint8: {
if (arg.optional)
arg.value = &(reinterpret_cast<chip::Optional<uint8_t *> *>(arg.value))->Emplace();
arg.value = &(reinterpret_cast<chip::Optional<uint8_t> *>(arg.value))->Emplace();
uint8_t * value = reinterpret_cast<uint8_t *>(arg.value);

// stringstream treats uint8_t as char, which is not what we want here.
Expand All @@ -214,7 +214,7 @@ bool Command::InitArgument(size_t argIndex, char * argValue)

case ArgumentType::Number_uint16: {
if (arg.optional)
arg.value = &(reinterpret_cast<chip::Optional<uint16_t *> *>(arg.value))->Emplace();
arg.value = &(reinterpret_cast<chip::Optional<uint16_t> *>(arg.value))->Emplace();
uint16_t * value = reinterpret_cast<uint16_t *>(arg.value);
std::stringstream ss;
isHexNotation ? ss << std::hex << argValue : ss << argValue;
Expand All @@ -228,7 +228,7 @@ bool Command::InitArgument(size_t argIndex, char * argValue)

case ArgumentType::Number_uint32: {
if (arg.optional)
arg.value = &(reinterpret_cast<chip::Optional<uint32_t *> *>(arg.value))->Emplace();
arg.value = &(reinterpret_cast<chip::Optional<uint32_t> *>(arg.value))->Emplace();
uint32_t * value = reinterpret_cast<uint32_t *>(arg.value);
std::stringstream ss;
isHexNotation ? ss << std::hex << argValue : ss << argValue;
Expand All @@ -242,7 +242,7 @@ bool Command::InitArgument(size_t argIndex, char * argValue)

case ArgumentType::Number_uint64: {
if (arg.optional)
arg.value = &(reinterpret_cast<chip::Optional<uint64_t *> *>(arg.value))->Emplace();
arg.value = &(reinterpret_cast<chip::Optional<uint64_t> *>(arg.value))->Emplace();
uint64_t * value = reinterpret_cast<uint64_t *>(arg.value);
std::stringstream ss;
isHexNotation ? ss << std::hex << argValue : ss << argValue;
Expand All @@ -256,7 +256,7 @@ bool Command::InitArgument(size_t argIndex, char * argValue)

case ArgumentType::Number_int8: {
if (arg.optional)
arg.value = &(reinterpret_cast<chip::Optional<int8_t *> *>(arg.value))->Emplace();
arg.value = &(reinterpret_cast<chip::Optional<int8_t> *>(arg.value))->Emplace();
int8_t * value = reinterpret_cast<int8_t *>(arg.value);

// stringstream treats int8_t as char, which is not what we want here.
Expand All @@ -281,7 +281,7 @@ bool Command::InitArgument(size_t argIndex, char * argValue)

case ArgumentType::Number_int16: {
if (arg.optional)
arg.value = &(reinterpret_cast<chip::Optional<int16_t *> *>(arg.value))->Emplace();
arg.value = &(reinterpret_cast<chip::Optional<int16_t> *>(arg.value))->Emplace();
int16_t * value = reinterpret_cast<int16_t *>(arg.value);
std::stringstream ss;
isHexNotation ? ss << std::hex << argValue : ss << argValue;
Expand All @@ -295,7 +295,7 @@ bool Command::InitArgument(size_t argIndex, char * argValue)

case ArgumentType::Number_int32: {
if (arg.optional)
arg.value = &(reinterpret_cast<chip::Optional<int32_t *> *>(arg.value))->Emplace();
arg.value = &(reinterpret_cast<chip::Optional<int32_t> *>(arg.value))->Emplace();
int32_t * value = reinterpret_cast<int32_t *>(arg.value);
std::stringstream ss;
isHexNotation ? ss << std::hex << argValue : ss << argValue;
Expand All @@ -309,7 +309,7 @@ bool Command::InitArgument(size_t argIndex, char * argValue)

case ArgumentType::Number_int64: {
if (arg.optional)
arg.value = &(reinterpret_cast<chip::Optional<int64_t *> *>(arg.value))->Emplace();
arg.value = &(reinterpret_cast<chip::Optional<int64_t> *>(arg.value))->Emplace();
int64_t * value = reinterpret_cast<int64_t *>(arg.value);
std::stringstream ss;
isHexNotation ? ss << std::hex << argValue : ss << argValue;
Expand All @@ -323,7 +323,7 @@ bool Command::InitArgument(size_t argIndex, char * argValue)

case ArgumentType::Address: {
if (arg.optional)
arg.value = &(reinterpret_cast<chip::Optional<AddressWithInterface *> *>(arg.value))->Emplace();
arg.value = &(reinterpret_cast<chip::Optional<AddressWithInterface> *>(arg.value))->Emplace();
AddressWithInterface * value = reinterpret_cast<AddressWithInterface *>(arg.value);
isValidArgument = ParseAddressWithInterface(argValue, value);
break;
Expand Down
4 changes: 4 additions & 0 deletions examples/chip-tool/commands/common/Command.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@

class Command;

// Limits on endpoint values.
#define CHIP_ZCL_ENDPOINT_MIN 0x00
#define CHIP_ZCL_ENDPOINT_MAX 0xF0

template <typename T, typename... Args>
std::unique_ptr<Command> make_unique(Args &&... args)
{
Expand Down
4 changes: 0 additions & 4 deletions examples/chip-tool/commands/reporting/ReportingCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@

#include <controller/ExampleOperationalCredentialsIssuer.h>

// Limits on endpoint values.
#define CHIP_ZCL_ENDPOINT_MIN 0x00
#define CHIP_ZCL_ENDPOINT_MAX 0xF0

class ReportingCommand : public CHIPCommand
{
public:
Expand Down
2 changes: 2 additions & 0 deletions examples/chip-tool/commands/tests/TestCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class TestCommand : public CHIPCommand
{
AddArgument("node-id", 0, UINT64_MAX, &mNodeId);
AddArgument("delayInMs", 0, UINT64_MAX, &mDelayInMs);
AddArgument("endpoint-id", CHIP_ZCL_ENDPOINT_MIN, CHIP_ZCL_ENDPOINT_MAX, &mEndpointId);
AddArgument("PICS", &mPICSFilePath);
}

Expand Down Expand Up @@ -228,5 +229,6 @@ class TestCommand : public CHIPCommand
};
chip::Optional<uint64_t> mDelayInMs;
chip::Optional<char *> mPICSFilePath;
chip::Optional<chip::EndpointId> mEndpointId;
chip::Optional<std::map<std::string, bool>> PICS;
};
10 changes: 6 additions & 4 deletions examples/chip-tool/templates/partials/test_cluster.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,12 @@ class {{filename}}: public TestCommand
{{else if isWait}}
CHIP_ERROR {{>testCommand}}()
{
ChipLogError(chipTool, "[Endpoint: {{endpoint}} Cluster: {{cluster}} {{#if isAttribute}}Attribute: {{attribute}}{{else}}Command: {{wait}}{{/if}}] {{label}}");
const chip::EndpointId endpoint = mEndpointId.HasValue() ? mEndpointId.Value() : {{endpoint}};
ChipLogError(chipTool, "[Endpoint: 0x%08x Cluster: {{cluster}} {{#if isAttribute}}Attribute: {{attribute}}{{else}}Command: {{wait}}{{/if}}] {{label}}", endpoint);
{{#*inline "waitForTypeName"}}{{#if isAttribute}}Attribute{{else}}Command{{/if}}{{/inline}}
{{#*inline "waitForTypeId"}}chip::app::Clusters::{{asUpperCamelCase cluster}}::{{#if isAttribute}}Attributes::{{attribute}}{{else}}Commands::{{wait}}{{/if}}::Id{{/inline}}
ClearAttributeAndCommandPaths();
m{{>waitForTypeName}}Path = chip::app::Concrete{{>waitForTypeName}}Path({{endpoint}}, chip::app::Clusters::{{asUpperCamelCase cluster}}::Id, {{>waitForTypeId}});
m{{>waitForTypeName}}Path = chip::app::Concrete{{>waitForTypeName}}Path(endpoint, chip::app::Clusters::{{asUpperCamelCase cluster}}::Id, {{>waitForTypeId}});
return CHIP_NO_ERROR;
}
{{else}}
Expand All @@ -137,6 +138,7 @@ class {{filename}}: public TestCommand

CHIP_ERROR {{>testCommand}}()
{
const chip::EndpointId endpoint = mEndpointId.HasValue() ? mEndpointId.Value() : {{endpoint}};
{{#if isCommand}}
using RequestType = chip::app::Clusters::{{asUpperCamelCase cluster}}::Commands::{{asUpperCamelCase command}}::Type;

Expand All @@ -153,11 +155,11 @@ class {{filename}}: public TestCommand
(static_cast<{{filename}} *>(context))->OnFailureResponse_{{index}}(status);
};

ReturnErrorOnFailure(chip::Controller::InvokeCommand(mDevice, this, success, failure, {{endpoint}}, request));
ReturnErrorOnFailure(chip::Controller::InvokeCommand(mDevice, this, success, failure, endpoint, request));
{{#unless async}}return CHIP_NO_ERROR;{{/unless}}
{{else}}
chip::Controller::{{asUpperCamelCase cluster}}ClusterTest cluster;
cluster.Associate(mDevice, {{endpoint}});
cluster.Associate(mDevice, endpoint);

{{#chip_tests_item_parameters}}
{{zapTypeToEncodableClusterObjectType type ns=parent.cluster}} {{asLowerCamelCase name}}Argument;
Expand Down
Loading

0 comments on commit 1380541

Please sign in to comment.