-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Fabric-Sync] Implement pair-device command (#36508)
* [Fabric-Sync] Port pair-device command from fabric-admin * Update examples/fabric-sync/shell/ShellCommands.cpp Co-authored-by: Terence Hampson <[email protected]> --------- Co-authored-by: Terence Hampson <[email protected]>
- Loading branch information
1 parent
c39a06f
commit ba33cf2
Showing
4 changed files
with
155 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,79 @@ | ||
/* | ||
* Copyright (c) 2024 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 "PairDeviceCommand.h" | ||
|
||
#include <admin/DeviceManager.h> | ||
#include <lib/shell/streamer.h> | ||
|
||
using namespace ::chip; | ||
|
||
namespace commands { | ||
|
||
PairDeviceCommand::PairDeviceCommand(chip::NodeId nodeId, const char * payload) : mNodeId(nodeId), mPayload(payload) {} | ||
|
||
void PairDeviceCommand::OnCommissioningComplete(NodeId deviceId, CHIP_ERROR err) | ||
{ | ||
if (mNodeId != deviceId) | ||
{ | ||
if (err != CHIP_NO_ERROR) | ||
{ | ||
ChipLogError(NotSpecified, | ||
"Failed to pair non-specified device (0x:" ChipLogFormatX64 ") with error: %" CHIP_ERROR_FORMAT, | ||
ChipLogValueX64(deviceId), err.Format()); | ||
} | ||
else | ||
{ | ||
ChipLogProgress(NotSpecified, "Commissioning complete for non-specified device: NodeId: " ChipLogFormatX64, | ||
ChipLogValueX64(deviceId)); | ||
} | ||
return; | ||
} | ||
|
||
if (err == CHIP_NO_ERROR) | ||
{ | ||
ChipLogProgress(NotSpecified, "Successfully paired device: NodeId: " ChipLogFormatX64, ChipLogValueX64(mNodeId)); | ||
|
||
admin::DeviceManager::Instance().UpdateLastUsedNodeId(mNodeId); | ||
} | ||
else | ||
{ | ||
ChipLogError(NotSpecified, "Failed to pair device (0x:" ChipLogFormatX64 ") with error: %" CHIP_ERROR_FORMAT, | ||
ChipLogValueX64(deviceId), err.Format()); | ||
} | ||
|
||
CommandRegistry::Instance().ResetActiveCommand(); | ||
} | ||
|
||
CHIP_ERROR PairDeviceCommand::RunCommand() | ||
{ | ||
if (admin::DeviceManager::Instance().IsCurrentBridgeDevice(mNodeId)) | ||
{ | ||
// print to console | ||
fprintf(stderr, "The specified node ID has been reserved by the Fabric Bridge.\n"); | ||
return CHIP_ERROR_INVALID_ARGUMENT; | ||
} | ||
|
||
ChipLogProgress(NotSpecified, "Running PairDeviceCommand with Node ID: %lu, Code: %s", mNodeId, mPayload); | ||
|
||
admin::PairingManager::Instance().SetPairingDelegate(this); | ||
|
||
return admin::PairingManager::Instance().PairDeviceWithCode(mNodeId, mPayload); | ||
} | ||
|
||
} // namespace commands |
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,38 @@ | ||
/* | ||
* Copyright (c) 2024 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 <CommandRegistry.h> | ||
#include <admin/PairingManager.h> | ||
|
||
namespace commands { | ||
|
||
class PairDeviceCommand : public Command, public admin::PairingDelegate | ||
{ | ||
public: | ||
PairDeviceCommand(chip::NodeId nodeId, const char * payload); | ||
void OnCommissioningComplete(chip::NodeId deviceId, CHIP_ERROR err) override; | ||
CHIP_ERROR RunCommand() override; | ||
|
||
private: | ||
chip::NodeId mNodeId; | ||
const char * mPayload; | ||
}; | ||
|
||
} // namespace commands |
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