Skip to content

Commit

Permalink
[chip-tool] Add support for multiple reads/subscribes into a single e…
Browse files Browse the repository at this point in the history
…xchange (project-chip#15787)

* [chip-tool] Add support for multiple reads/subscribes into a single exchange

* Update generated content
  • Loading branch information
vivien-apple authored and krypton36 committed Mar 3, 2022
1 parent 6d4e8ee commit 4ecf576
Show file tree
Hide file tree
Showing 8 changed files with 1,613 additions and 1,409 deletions.
4 changes: 2 additions & 2 deletions examples/chip-tool/commands/clusters/ClusterCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ class ClusterCommand : public ModelCommand, public chip::app::CommandSender::Cal

~ClusterCommand() {}

CHIP_ERROR SendCommand(ChipDevice * device, chip::EndpointId endpointId) override
CHIP_ERROR SendCommand(ChipDevice * device, std::vector<chip::EndpointId> endpointIds) override
{
return ClusterCommand::SendCommand(device, endpointId, mClusterId, mCommandId, mPayload);
return ClusterCommand::SendCommand(device, endpointIds.at(0), mClusterId, mCommandId, mPayload);
}

CHIP_ERROR SendGroupCommand(chip::GroupId groupId, chip::FabricIndex fabricIndex, chip::NodeId senderNodeId) override
Expand Down
4 changes: 2 additions & 2 deletions examples/chip-tool/commands/clusters/ModelCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class ModelCommand : public CHIPCommand
CHIP_ERROR RunCommand() override;
chip::System::Clock::Timeout GetWaitDuration() const override { return chip::System::Clock::Seconds16(10); }

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

virtual CHIP_ERROR SendGroupCommand(chip::GroupId groupId, chip::FabricIndex fabricIndex, chip::NodeId senderNodeId)
{
Expand All @@ -51,7 +51,7 @@ class ModelCommand : public CHIPCommand

private:
chip::NodeId mNodeId;
chip::EndpointId mEndPointId;
std::vector<chip::EndpointId> mEndPointId;

static void OnDeviceConnectedFn(void * context, ChipDevice * device);
static void OnDeviceConnectionFailureFn(void * context, PeerId peerId, CHIP_ERROR error);
Expand Down
261 changes: 196 additions & 65 deletions examples/chip-tool/commands/clusters/ReportCommand.h

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions examples/chip-tool/commands/clusters/WriteAttributeCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ class WriteAttribute : public ModelCommand, public chip::app::WriteClient::Callb

~WriteAttribute() {}

CHIP_ERROR SendCommand(ChipDevice * device, chip::EndpointId endpointId) override
CHIP_ERROR SendCommand(ChipDevice * device, std::vector<chip::EndpointId> endpointIds) override
{
return WriteAttribute::SendCommand(device, endpointId, mClusterId, mAttributeId, mAttributeValue);
return WriteAttribute::SendCommand(device, endpointIds.at(0), mClusterId, mAttributeId, mAttributeValue);
}

CHIP_ERROR SendGroupCommand(chip::GroupId groupId, chip::FabricIndex fabricIndex, chip::NodeId senderNodeId) override
Expand Down
68 changes: 68 additions & 0 deletions examples/chip-tool/commands/common/Command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,48 @@ bool Command::InitArgument(size_t argIndex, char * argValue)
return CHIP_NO_ERROR == customArgument->Parse(arg.name, argValue);
}

case ArgumentType::Vector16:
case ArgumentType::Vector32: {
std::vector<uint64_t> values;
uint64_t min = chip::CanCastTo<uint64_t>(arg.min) ? static_cast<uint64_t>(arg.min) : 0;
uint64_t max = arg.max;

std::stringstream ss(argValue);
while (ss.good())
{
std::string valueAsString;
getline(ss, valueAsString, ',');
isHexNotation = strncmp(valueAsString.c_str(), "0x", 2) == 0 || strncmp(valueAsString.c_str(), "0X", 2) == 0;

std::stringstream subss;
isHexNotation ? subss << std::hex << valueAsString : subss << valueAsString;

uint64_t value;
subss >> value;
VerifyOrReturnError(!subss.fail() && subss.eof() && value >= min && value <= max, false);
values.push_back(value);
}

if (arg.type == ArgumentType::Vector16)
{
auto vectorArgument = static_cast<std::vector<uint16_t> *>(arg.value);
for (uint64_t v : values)
{
vectorArgument->push_back(static_cast<uint16_t>(v));
}
}
else
{
auto vectorArgument = static_cast<std::vector<uint32_t> *>(arg.value);
for (uint64_t v : values)
{
vectorArgument->push_back(static_cast<uint32_t>(v));
}
}

return true;
}

case ArgumentType::Attribute: {
if (arg.isOptional() || arg.isNullable())
{
Expand Down Expand Up @@ -489,6 +531,32 @@ size_t Command::AddArgument(const char * name, AddressWithInterface * out, uint8
return AddArgumentToList(std::move(arg));
}

size_t Command::AddArgument(const char * name, int64_t min, uint64_t max, std::vector<uint16_t> * value)
{
Argument arg;
arg.type = ArgumentType::Vector16;
arg.name = name;
arg.value = static_cast<void *>(value);
arg.min = min;
arg.max = max;
arg.flags = 0;

return AddArgumentToList(std::move(arg));
}

size_t Command::AddArgument(const char * name, int64_t min, uint64_t max, std::vector<uint32_t> * value)
{
Argument arg;
arg.type = ArgumentType::Vector32;
arg.name = name;
arg.value = static_cast<void *>(value);
arg.min = min;
arg.max = max;
arg.flags = 0;

return AddArgumentToList(std::move(arg));
}

size_t Command::AddArgument(const char * name, ComplexArgument * value)
{
Argument arg;
Expand Down
7 changes: 6 additions & 1 deletion examples/chip-tool/commands/common/Command.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ enum ArgumentType
Attribute,
Address,
Complex,
Custom
Custom,
Vector16,
Vector32,
};

struct Argument
Expand Down Expand Up @@ -170,6 +172,9 @@ class Command
size_t AddArgument(const char * name, float min, float max, float * out, uint8_t flags = 0);
size_t AddArgument(const char * name, double min, double max, double * out, uint8_t flags = 0);

size_t AddArgument(const char * name, int64_t min, uint64_t max, std::vector<uint16_t> * value);
size_t AddArgument(const char * name, int64_t min, uint64_t max, std::vector<uint32_t> * value);

template <typename T, typename = std::enable_if_t<std::is_enum<T>::value>>
size_t AddArgument(const char * name, int64_t min, uint64_t max, T * out, uint8_t flags = 0)
{
Expand Down
10 changes: 5 additions & 5 deletions examples/chip-tool/templates/commands.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ public:
ClusterCommand::AddArguments();
}

CHIP_ERROR SendCommand(ChipDevice * device, chip::EndpointId endpointId) override
CHIP_ERROR SendCommand(ChipDevice * device, std::vector<chip::EndpointId> endpointIds) override
{
ChipLogProgress(chipTool, "Sending cluster ({{asHex parent.code 8}}) command ({{asHex code 8}}) on endpoint %" PRIu16, endpointId);
ChipLogProgress(chipTool, "Sending cluster ({{asHex parent.code 8}}) command ({{asHex code 8}}) on endpoint %" PRIu16, endpointIds.at(0));

return ClusterCommand::SendCommand(device, endpointId, {{asHex parent.code 8}}, {{asHex code 8}}, mRequest);
return ClusterCommand::SendCommand(device, endpointIds.at(0), {{asHex parent.code 8}}, {{asHex code 8}}, mRequest);
}

CHIP_ERROR SendGroupCommand(chip::GroupId groupId, chip::FabricIndex fabricIndex, chip::NodeId senderNodeId) override
Expand Down Expand Up @@ -83,9 +83,9 @@ public:

~Write{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}() {}

CHIP_ERROR SendCommand(ChipDevice * device, chip::EndpointId endpointId) override
CHIP_ERROR SendCommand(ChipDevice * device, std::vector<chip::EndpointId> endpointIds) override
{
return WriteAttribute::SendCommand(device, endpointId, {{asHex parent.code 8}}, {{asHex code 8}}, mValue);
return WriteAttribute::SendCommand(device, endpointIds.at(0), {{asHex parent.code 8}}, {{asHex code 8}}, mValue);
}

CHIP_ERROR SendGroupCommand(chip::GroupId groupId, chip::FabricIndex fabricIndex, chip::NodeId senderNodeId) override
Expand Down
Loading

0 comments on commit 4ecf576

Please sign in to comment.