-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[chip-tool] Update the template to allow chip-tool to issue wildcards…
… 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
1 parent
271f275
commit 40cc421
Showing
12 changed files
with
12,925 additions
and
56,867 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.