-
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] Move OpenCommissioningWindowCommand to a dedicated file (#…
- Loading branch information
1 parent
2a1c630
commit 1573345
Showing
7 changed files
with
140 additions
and
141 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
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
57 changes: 57 additions & 0 deletions
57
examples/chip-tool/commands/pairing/OpenCommissioningWindowCommand.cpp
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,57 @@ | ||
/* | ||
* Copyright (c) 2021 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 "OpenCommissioningWindowCommand.h" | ||
|
||
using namespace ::chip; | ||
|
||
CHIP_ERROR OpenCommissioningWindowCommand::RunCommand() | ||
{ | ||
return CurrentCommissioner().GetConnectedDevice(mNodeId, &mOnDeviceConnectedCallback, &mOnDeviceConnectionFailureCallback); | ||
} | ||
|
||
void OpenCommissioningWindowCommand::OnDeviceConnectedFn(void * context, chip::OperationalDeviceProxy * device) | ||
{ | ||
OpenCommissioningWindowCommand * command = reinterpret_cast<OpenCommissioningWindowCommand *>(context); | ||
VerifyOrReturn(command != nullptr, ChipLogError(chipTool, "OnDeviceConnectedFn: context is null")); | ||
command->OpenCommissioningWindow(); | ||
} | ||
void OpenCommissioningWindowCommand::OnDeviceConnectionFailureFn(void * context, NodeId remoteId, CHIP_ERROR err) | ||
{ | ||
LogErrorOnFailure(err); | ||
|
||
OpenCommissioningWindowCommand * command = reinterpret_cast<OpenCommissioningWindowCommand *>(context); | ||
VerifyOrReturn(command != nullptr, ChipLogError(chipTool, "OnDeviceConnectionFailureFn: context is null")); | ||
command->SetCommandExitStatus(err); | ||
} | ||
|
||
void OpenCommissioningWindowCommand::OnOpenCommissioningWindowResponse(void * context, NodeId remoteId, CHIP_ERROR err, | ||
chip::SetupPayload payload) | ||
{ | ||
LogErrorOnFailure(err); | ||
|
||
OpenCommissioningWindowCommand * command = reinterpret_cast<OpenCommissioningWindowCommand *>(context); | ||
VerifyOrReturn(command != nullptr, ChipLogError(chipTool, "OnOpenCommissioningWindowCommand: context is null")); | ||
command->SetCommandExitStatus(err); | ||
} | ||
|
||
CHIP_ERROR OpenCommissioningWindowCommand::OpenCommissioningWindow() | ||
{ | ||
return CurrentCommissioner().OpenCommissioningWindowWithCallback( | ||
mNodeId, mTimeout, mIteration, mDiscriminator, mCommissioningWindowOption, &mOnOpenCommissioningWindowCallback); | ||
} |
57 changes: 57 additions & 0 deletions
57
examples/chip-tool/commands/pairing/OpenCommissioningWindowCommand.h
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,57 @@ | ||
/* | ||
* Copyright (c) 2021 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" | ||
|
||
class OpenCommissioningWindowCommand : public CHIPCommand | ||
{ | ||
public: | ||
OpenCommissioningWindowCommand() : | ||
CHIPCommand("open-commissioning-window"), mOnDeviceConnectedCallback(OnDeviceConnectedFn, this), | ||
mOnDeviceConnectionFailureCallback(OnDeviceConnectionFailureFn, this), | ||
mOnOpenCommissioningWindowCallback(OnOpenCommissioningWindowResponse, this) | ||
{ | ||
AddArgument("node-id", 0, UINT64_MAX, &mNodeId); | ||
AddArgument("option", 0, UINT8_MAX, &mCommissioningWindowOption); | ||
AddArgument("timeout", 0, UINT16_MAX, &mTimeout); | ||
AddArgument("iteration", 0, UINT16_MAX, &mIteration); | ||
AddArgument("discriminator", 0, 4096, &mDiscriminator); | ||
} | ||
|
||
/////////// CHIPCommand Interface ///////// | ||
CHIP_ERROR RunCommand() override; | ||
chip::System::Clock::Timeout GetWaitDuration() const override { return chip::System::Clock::Seconds16(5); } | ||
|
||
private: | ||
NodeId mNodeId; | ||
uint8_t mCommissioningWindowOption; | ||
uint16_t mTimeout; | ||
uint16_t mIteration; | ||
uint16_t mDiscriminator; | ||
|
||
CHIP_ERROR OpenCommissioningWindow(); | ||
static void OnDeviceConnectedFn(void * context, chip::OperationalDeviceProxy * device); | ||
static void OnDeviceConnectionFailureFn(void * context, NodeId deviceId, CHIP_ERROR error); | ||
static void OnOpenCommissioningWindowResponse(void * context, NodeId deviceId, CHIP_ERROR status, chip::SetupPayload payload); | ||
|
||
chip::Callback::Callback<chip::OnDeviceConnected> mOnDeviceConnectedCallback; | ||
chip::Callback::Callback<chip::OnDeviceConnectionFailure> mOnDeviceConnectionFailureCallback; | ||
chip::Callback::Callback<chip::Controller::OnOpenCommissioningWindow> mOnOpenCommissioningWindowCallback; | ||
}; |
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.