-
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.
RPC: Cleanup and add thread service (#14843)
* RPC: Refactor wifi RPC as common service - Move WiFi into a common rpc service like others. - Add WiFi RPC service to the all-clusters app * RPC: Add thread rpc service to efr and nrf - Add a Thread RPC service similar to others. - Add to NRF and EFR32 platforms - Add to efr/lighting RPC example app - Add to efr/lock RPC example app - Add to nfr/lighting RPC example app * RPC: Add get/set pairing state * RPC: Add OTCLI to EFR32 and NRF32 - Add the openthread cli as a new RPC service. - Add service to EFR32 and NRF32 platforms - Add to lighting/efr32 example - Add to lighting/nrf example * RPC: Refactor linux RPC into platform. Move common linux Rpc.* files into common platform to match refactoring done for other platforms. * RPC: Wake m5 display on RPC button press
- Loading branch information
Showing
28 changed files
with
691 additions
and
114 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
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,2 @@ | ||
chip.rpc.OtCliResponse.response max_size:128 | ||
chip.rpc.OtCliCommand.command max_size:128 |
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,18 @@ | ||
syntax = "proto3"; | ||
|
||
package chip.rpc; | ||
|
||
import 'pw_protobuf_protos/common.proto'; | ||
|
||
message OtCliResponse { | ||
string response = 1; | ||
} | ||
|
||
message OtCliCommand { | ||
string command = 1; | ||
} | ||
|
||
service OtCli { | ||
// Handle the command using the Open Thread CLI, and stream the reponses back. | ||
rpc Command(OtCliCommand) returns (stream OtCliResponse){} | ||
} |
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,2 @@ | ||
chip.rpc.ThreadNetworkInfo.network_name max_size:17 // Maximum size of the Thread Network Name field + 1 for null | ||
chip.rpc.ThreadNetworkInfo.extended_pan_id max_size:8 // Size of extended pan id in bytes |
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 @@ | ||
syntax = "proto3"; | ||
|
||
package chip.rpc; | ||
|
||
import 'pw_protobuf_protos/common.proto'; | ||
|
||
enum ThreadDeviceType { | ||
DEVICE_TYPE_NOT_SUPPORTED = 0; | ||
DEVICE_TYPE_ROUTER = 1; | ||
DEVICE_TYPE_FULL_END_DEVICE = 2; | ||
DEVICE_TYPE_MINIMAL_END_DEVICE = 3; | ||
DEVICE_TYPE_SLEEPY_END_DEVICE = 4; | ||
} | ||
|
||
message ThreadState { | ||
bool is_provisioned = 1; | ||
bool is_enabled = 2; | ||
bool is_attached = 3; | ||
ThreadDeviceType device_type = 4; | ||
} | ||
|
||
message ThreadNetworkInfo { | ||
uint32 pan_id = 1; | ||
string network_name = 2; | ||
uint32 channel = 3; | ||
bytes extended_pan_id = 4; | ||
} | ||
|
||
service Thread { | ||
rpc GetState(pw.protobuf.Empty) returns (ThreadState){} | ||
rpc GetNetworkInfo(pw.protobuf.Empty) returns (ThreadNetworkInfo){} | ||
} |
File renamed without changes.
File renamed without changes.
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
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,83 @@ | ||
/* | ||
* | ||
* 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 | ||
|
||
#if CHIP_ENABLE_OPENTHREAD | ||
#include <openthread/cli.h> | ||
#include <openthread/instance.h> | ||
|
||
static_assert(OPENTHREAD_API_VERSION >= 85, "Invalid Open Thread version"); | ||
#endif // CHIP_ENABLE_OPENTHREAD | ||
|
||
#include "ot_cli_service/ot_cli_service.rpc.pb.h" | ||
#include "platform/ConfigurationManager.h" | ||
#include "pw_log/log.h" | ||
|
||
namespace chip { | ||
namespace rpc { | ||
|
||
class OtCli : public pw_rpc::nanopb::OtCli::Service<OtCli> | ||
{ | ||
public: | ||
virtual ~OtCli() = default; | ||
|
||
virtual void Command(const ::chip_rpc_OtCliCommand & request, ServerWriter<::chip_rpc_OtCliResponse> & writer) | ||
{ | ||
#if CHIP_ENABLE_OPENTHREAD | ||
LazyInit(); | ||
rpc_writer = &writer; | ||
otCliInputLine(const_cast<char *>(request.command)); | ||
rpc_writer->Finish(); | ||
rpc_writer = nullptr; | ||
#endif // CHIP_ENABLE_OPENTHREAD | ||
} | ||
|
||
private: | ||
ServerWriter<::chip_rpc_OtCliResponse> * rpc_writer = nullptr; | ||
|
||
#if CHIP_ENABLE_OPENTHREAD | ||
bool mInitComplete = false; | ||
|
||
void LazyInit() | ||
{ | ||
if (mInitComplete) | ||
{ | ||
return; | ||
} | ||
otCliInit(otInstanceInitSingle(), &OnOtCliOutput, this); | ||
mInitComplete = true; | ||
} | ||
|
||
static int OnOtCliOutput(void * context, const char * format, va_list arguments) | ||
{ | ||
OtCli * ot_cli = reinterpret_cast<OtCli *>(context); | ||
if (ot_cli->rpc_writer) | ||
{ | ||
chip_rpc_OtCliResponse out; | ||
int rval = vsnprintf(out.response, sizeof(out.response), format, arguments); | ||
ot_cli->rpc_writer->Write(out); | ||
return rval; | ||
} | ||
return 0; | ||
} | ||
#endif // CHIP_ENABLE_OPENTHREAD | ||
}; | ||
|
||
} // namespace rpc | ||
} // namespace chip |
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,83 @@ | ||
/* | ||
* | ||
* 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 <platform/CHIPDeviceConfig.h> | ||
|
||
#include "platform/ConnectivityManager.h" | ||
#include "thread_service/thread_service.rpc.pb.h" | ||
|
||
#if CHIP_ENABLE_OPENTHREAD | ||
#include <openthread/dataset.h> | ||
#include <platform/ThreadStackManager.h> | ||
#endif | ||
|
||
namespace chip { | ||
namespace rpc { | ||
|
||
// Implementation class for chip.rpc.Thread. | ||
class Thread : public pw_rpc::nanopb::Thread::Service<Thread> | ||
{ | ||
public: | ||
::pw::Status GetState(const pw_protobuf_Empty & request, chip_rpc_ThreadState & response) | ||
{ | ||
response.is_provisioned = DeviceLayer::ConnectivityMgr().IsThreadProvisioned(); | ||
response.is_enabled = DeviceLayer::ConnectivityMgr().IsThreadEnabled(); | ||
response.is_attached = DeviceLayer::ConnectivityMgr().IsThreadAttached(); | ||
response.device_type = static_cast<chip_rpc_ThreadDeviceType>(DeviceLayer::ConnectivityMgr().GetThreadDeviceType()); | ||
return pw::OkStatus(); | ||
} | ||
|
||
::pw::Status GetNetworkInfo(const pw_protobuf_Empty & request, chip_rpc_ThreadNetworkInfo & response) | ||
{ | ||
#if CHIP_ENABLE_OPENTHREAD | ||
otInstance * otInst = DeviceLayer::ThreadStackMgrImpl().OTInstance(); | ||
otOperationalDataset data; | ||
if (OT_ERROR_NONE != otDatasetGetActive(otInst, &data)) | ||
{ | ||
return pw::Status::NotFound(); | ||
} | ||
|
||
if (data.mComponents.mIsPanIdPresent) | ||
{ | ||
response.pan_id = data.mPanId; | ||
} | ||
if (data.mComponents.mIsNetworkNamePresent) | ||
{ | ||
snprintf(response.network_name, sizeof(response.network_name), "%s", data.mNetworkName.m8); | ||
} | ||
if (data.mComponents.mIsChannelPresent) | ||
{ | ||
response.channel = data.mChannel; | ||
} | ||
if (data.mComponents.mIsExtendedPanIdPresent) | ||
{ | ||
size_t size = std::min(sizeof(response.extended_pan_id.bytes), sizeof(data.mExtendedPanId)); | ||
memcpy(response.extended_pan_id.bytes, data.mExtendedPanId.m8, size); | ||
response.extended_pan_id.size = size; | ||
} | ||
return pw::OkStatus(); | ||
#else // CHIP_ENABLE_OPENTHREAD | ||
return ::pw::Status::Unimplemented(); | ||
#endif // CHIP_ENABLE_OPENTHREAD | ||
} | ||
}; | ||
|
||
} // namespace rpc | ||
} // namespace chip |
Oops, something went wrong.