forked from project-chip/connectedhomeip
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[chip-tool] Add delay commands module to chip-tool with busy-wait com…
…mand (project-chip#24063) Co-authored-by: Andrei Litvin <[email protected]>
- Loading branch information
1 parent
e627a00
commit 16d7c21
Showing
5 changed files
with
117 additions
and
0 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
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,32 @@ | ||
/* | ||
* 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 "commands/common/Commands.h" | ||
#include "commands/delay/SleepCommand.h" | ||
|
||
void registerCommandsDelay(Commands & commands, CredentialIssuerCommands * credsIssuerConfig) | ||
{ | ||
const char * clusterName = "Delay"; | ||
commands_list clusterCommands = { | ||
make_unique<SleepCommand>(credsIssuerConfig), // | ||
}; | ||
|
||
commands.Register(clusterName, clusterCommands); | ||
} |
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,28 @@ | ||
/* | ||
* 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. | ||
* | ||
*/ | ||
|
||
#include "SleepCommand.h" | ||
#include <chrono> | ||
#include <thread> | ||
|
||
CHIP_ERROR SleepCommand::RunCommand() | ||
{ | ||
std::this_thread::sleep_for(std::chrono::milliseconds(mDurationInMs)); | ||
SetCommandExitStatus(CHIP_NO_ERROR); | ||
return CHIP_NO_ERROR; | ||
} |
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,54 @@ | ||
/* | ||
* 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 "../common/CHIPCommand.h" | ||
|
||
/** | ||
* This command blocks the event loop processing for a given amount of time. | ||
* | ||
* For example when the event loop is blocked the messages coming-in will not be acked, | ||
* forcing a retransmission on the other side. | ||
* | ||
*/ | ||
|
||
class SleepCommand : public CHIPCommand | ||
{ | ||
public: | ||
SleepCommand(CredentialIssuerCommands * credIssuerCommands) : CHIPCommand("sleep", credIssuerCommands) | ||
{ | ||
AddArgument("duration-in-ms", 0, UINT32_MAX, &mDurationInMs, | ||
"Block the event loop processing for duration-in-ms milliseconds."); | ||
} | ||
|
||
/////////// CHIPCommand Interface ///////// | ||
CHIP_ERROR RunCommand() override; | ||
chip::System::Clock::Timeout GetWaitDuration() const override | ||
{ | ||
// The allowed duration of this method is at least as long as the time specified for blocking the | ||
// event loop. In order to not fail on some small delays in processing some extra time before | ||
// failing is added. | ||
constexpr uint16_t mExtraTimeForFailure = 1000; | ||
|
||
return chip::System::Clock::Milliseconds32(mDurationInMs + mExtraTimeForFailure); | ||
} | ||
|
||
private: | ||
uint32_t mDurationInMs; | ||
}; |
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