Skip to content

Commit

Permalink
RPC: SetPairingState open CommissioningWindow (#23622)
Browse files Browse the repository at this point in the history
If the commissioning window isn't already open open a basic one
when SetPairingState is true. Similarily close the commissioining
window if SetPairingState is false.
  • Loading branch information
rgoliver authored Nov 18, 2022
1 parent 54d8dd0 commit 287c1b5
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions examples/common/pigweed/rpc_services/Device.h
Original file line number Diff line number Diff line change
Expand Up @@ -270,14 +270,22 @@ class Device : public pw_rpc::nanopb::Device::Service<Device>

virtual pw::Status SetPairingState(const chip_rpc_PairingState & request, pw_protobuf_Empty & response)
{
if (request.pairing_enabled)
if (request.pairing_enabled && !chip::Server::GetInstance().GetCommissioningWindowManager().IsCommissioningWindowOpen())
{
DeviceLayer::ConnectivityMgr().SetBLEAdvertisingEnabled(true);
DeviceLayer::ConnectivityMgr().SetBLEAdvertisingMode(DeviceLayer::ConnectivityMgr().kFastAdvertising);
DeviceLayer::StackLock lock;
chip::ChipError err = chip::Server::GetInstance().GetCommissioningWindowManager().OpenBasicCommissioningWindow();
if (err != CHIP_NO_ERROR)
{
ChipLogError(NotSpecified, "RPC SetPairingState failed to open commissioning window: %" CHIP_ERROR_FORMAT,
err.Format());
return pw::Status::Internal();
}
}
else
else if (!request.pairing_enabled &&
chip::Server::GetInstance().GetCommissioningWindowManager().IsCommissioningWindowOpen())
{
DeviceLayer::ConnectivityMgr().SetBLEAdvertisingEnabled(false);
DeviceLayer::StackLock lock;
chip::Server::GetInstance().GetCommissioningWindowManager().CloseCommissioningWindow();
}
return pw::OkStatus();
}
Expand Down

0 comments on commit 287c1b5

Please sign in to comment.