Skip to content

Commit

Permalink
[chip-tool] Update the template to allow chip-tool to issue wildcards…
Browse files Browse the repository at this point in the history
… commands (#14361)

* Update the template to allow chip-tool to issue wildcards commands

Replace templates for attributes/events read/reports by built-in classes

Replace cluster 0xffffffff by Any and replace 0xffffffff attribute/event name by a commmand name read/report-by-id that lets use an arbitratry id

* Update generated content
  • Loading branch information
vivien-apple authored Jan 27, 2022
1 parent 271f275 commit 40cc421
Show file tree
Hide file tree
Showing 12 changed files with 12,925 additions and 56,867 deletions.
90 changes: 90 additions & 0 deletions examples/chip-tool/commands/clusters/ClusterCommand.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
* Copyright (c) 2022 Project CHIP Authors
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

#pragma once

#include <app/CommandSender.h>

#include "DataModelLogger.h"
#include "ModelCommand.h"

class ClusterCommand : public ModelCommand, public chip::app::CommandSender::Callback
{
public:
ClusterCommand(const char * commandName) : ModelCommand(commandName)
{
AddArgument("timedInteractionTimeoutMs", 0, UINT16_MAX, &mTimedInteractionTimeoutMs);
}

~ClusterCommand() {}

/////////// CommandSender Callback Interface /////////
virtual void OnResponse(chip::app::CommandSender * client, const chip::app::ConcreteCommandPath & path,
const chip::app::StatusIB & status, chip::TLV::TLVReader * data) override
{
CHIP_ERROR error = status.ToChipError();
if (CHIP_NO_ERROR != error)
{
ChipLogError(chipTool, "Response Failure: %s", chip::ErrorStr(error));
SetCommandExitStatus(error);
return;
}

if (data != nullptr)
{
error = DataModelLogger::LogCommand(path, data);
if (CHIP_NO_ERROR != error)
{
ChipLogError(chipTool, "Response Failure: Can not decode Data");
SetCommandExitStatus(error);
return;
}
}
}

virtual void OnError(const chip::app::CommandSender * client, CHIP_ERROR error) override
{
ChipLogProgress(chipTool, "Error: %s", chip::ErrorStr(error));
SetCommandExitStatus(error);
}

virtual void OnDone(chip::app::CommandSender * client) override
{
mCommandSender.reset();
SetCommandExitStatus(CHIP_NO_ERROR);
}

template <class T>
CHIP_ERROR SendCommand(ChipDevice * device, chip::EndpointId endpointId, chip::ClusterId clusterId, chip::CommandId commandId,
const T & value)
{
chip::app::CommandPathParams commandPath = { endpointId, 0 /* groupId */, clusterId, commandId,
(chip::app::CommandPathFlags::kEndpointIdValid) };
mCommandSender =
std::make_unique<chip::app::CommandSender>(this, device->GetExchangeManager(), mTimedInteractionTimeoutMs.HasValue());
VerifyOrReturnError(mCommandSender != nullptr, CHIP_ERROR_NO_MEMORY);
ReturnErrorOnFailure(mCommandSender->AddRequestDataNoTimedCheck(commandPath, value, mTimedInteractionTimeoutMs));
ReturnErrorOnFailure(mCommandSender->SendCommandRequest(device->GetSecureSession().Value()));
return CHIP_NO_ERROR;
}

private:
chip::Optional<uint16_t> mTimedInteractionTimeoutMs;

std::unique_ptr<chip::app::CommandSender> mCommandSender;
};
10 changes: 9 additions & 1 deletion examples/chip-tool/commands/clusters/DataModelLogger.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,20 @@
#include <string>

#include <app-common/zap-generated/cluster-objects.h>
#include <app/ConcreteAttributePath.h>
#include <app/ConcreteCommandPath.h>
#include <app/EventHeader.h>
#include <app/data-model/DecodableList.h>
#include <lib/support/BytesToHex.h>

class DataModelLogger
{
public:
static CHIP_ERROR LogAttribute(const chip::app::ConcreteDataAttributePath & path, chip::TLV::TLVReader * data);
static CHIP_ERROR LogCommand(const chip::app::ConcreteCommandPath & path, chip::TLV::TLVReader * data);
static CHIP_ERROR LogEvent(const chip::app::EventHeader & header, chip::TLV::TLVReader * data);

private:
static CHIP_ERROR LogValue(const char * label, size_t indent, bool value)
{
DataModelLogger::LogString(label, indent, value ? "TRUE" : "FALSE");
Expand Down Expand Up @@ -139,7 +148,6 @@ class DataModelLogger

#include <zap-generated/cluster/logging/DataModelLogger.h>

private:
static void LogString(size_t indent, const std::string string) { LogString("", indent, string); }

static void LogString(const std::string label, size_t indent, const std::string string)
Expand Down
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 @@ -36,7 +36,6 @@ class ModelCommand : public CHIPCommand
{
AddArgument("node-id", 0, UINT64_MAX, &mNodeId);
AddArgument("endpoint-id", 0, UINT16_MAX, &mEndPointId);
AddArgument("timedInteractionTimeoutMs", 0, UINT16_MAX, &mTimedInteractionTimeoutMs);
}

/////////// CHIPCommand Interface /////////
Expand All @@ -45,9 +44,6 @@ class ModelCommand : public CHIPCommand

virtual CHIP_ERROR SendCommand(ChipDevice * device, chip::EndpointId endPointId) = 0;

protected:
chip::Optional<uint16_t> mTimedInteractionTimeoutMs;

private:
chip::NodeId mNodeId;
chip::EndpointId mEndPointId;
Expand Down
Loading

0 comments on commit 40cc421

Please sign in to comment.