Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit a208dd2

Browse files
committedMay 25, 2024
Add the RPC support between Fabric_Admin and Fabric_Bridge
1 parent 6aee3fd commit a208dd2

25 files changed

+1067
-11
lines changed
 

‎examples/common/pigweed/BUILD.gn

+14
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,20 @@ pw_proto_library("button_service") {
7272
prefix = "button_service"
7373
}
7474

75+
pw_proto_library("fabric_admin_service") {
76+
sources = [ "protos/fabric_admin_service.proto" ]
77+
deps = [ "$dir_pw_protobuf:common_protos" ]
78+
strip_prefix = "protos"
79+
prefix = "fabric_admin_service"
80+
}
81+
82+
pw_proto_library("fabric_bridge_service") {
83+
sources = [ "protos/fabric_bridge_service.proto" ]
84+
deps = [ "$dir_pw_protobuf:common_protos" ]
85+
strip_prefix = "protos"
86+
prefix = "fabric_bridge_service"
87+
}
88+
7589
pw_proto_library("lighting_service") {
7690
sources = [ "protos/lighting_service.proto" ]
7791
deps = [ "$dir_pw_protobuf:common_protos" ]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
syntax = "proto3";
2+
3+
import 'pw_protobuf_protos/common.proto';
4+
5+
package chip.rpc;
6+
7+
// Define the message for a synchronized end device with necessary fields
8+
message DeviceInfo {
9+
uint64 node_id = 1;
10+
}
11+
12+
// Define the response message to convey the status of the operation
13+
message OperationStatus {
14+
bool success = 1;
15+
}
16+
17+
service FabricAdmin {
18+
rpc OpenCommissioningWindow(DeviceInfo) returns (OperationStatus){}
19+
}
20+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
syntax = "proto3";
2+
3+
import 'pw_protobuf_protos/common.proto';
4+
5+
package chip.rpc;
6+
7+
// Define the message for a synchronized end device with necessary fields
8+
message SynchronizedDevice {
9+
uint64 node_id = 1;
10+
}
11+
12+
service FabricBridge {
13+
rpc AddSynchronizedDevice(SynchronizedDevice) returns (pw.protobuf.Empty){}
14+
}
15+

‎examples/common/pigweed/rpc_console/py/BUILD.gn

+2
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ pw_python_package("chip_rpc") {
4545
"${chip_root}/examples/common/pigweed:descriptor_service.python",
4646
"${chip_root}/examples/common/pigweed:device_service.python",
4747
"${chip_root}/examples/common/pigweed:echo_service.python",
48+
"${chip_root}/examples/common/pigweed:fabric_admin_service.python",
49+
"${chip_root}/examples/common/pigweed:fabric_bridge_service.python",
4850
"${chip_root}/examples/common/pigweed:lighting_service.python",
4951
"${chip_root}/examples/common/pigweed:locking_service.python",
5052
"${chip_root}/examples/common/pigweed:ot_cli_service.python",

‎examples/common/pigweed/rpc_console/py/chip_rpc/console.py

+4
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@
5252
from descriptor_service import descriptor_service_pb2
5353
from device_service import device_service_pb2
5454
from echo_service import echo_pb2
55+
from fabric_admin_service import fabric_admin_service_pb2
56+
from fabric_bridge_service import fabric_bridge_service_pb2
5557
from lighting_service import lighting_service_pb2
5658
from locking_service import locking_service_pb2
5759
from ot_cli_service import ot_cli_service_pb2
@@ -134,6 +136,8 @@ def show_console(device: str, baudrate: int,
134136
descriptor_service_pb2,
135137
device_service_pb2,
136138
echo_pb2,
139+
fabric_admin_service_pb2,
140+
fabric_bridge_service_pb2,
137141
lighting_service_pb2,
138142
locking_service_pb2,
139143
ot_cli_service_pb2,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
*
3+
* Copyright (c) 2024 Project CHIP Authors
4+
* All rights reserved.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
#pragma once
20+
21+
#include "app/util/attribute-storage.h"
22+
#include "fabric_admin_service/fabric_admin_service.rpc.pb.h"
23+
#include "pigweed/rpc_services/internal/StatusUtils.h"
24+
#include <app-common/zap-generated/attributes/Accessors.h>
25+
#include <app-common/zap-generated/ids/Attributes.h>
26+
#include <app-common/zap-generated/ids/Clusters.h>
27+
#include <platform/PlatformManager.h>
28+
29+
namespace chip {
30+
namespace rpc {
31+
32+
class FabricAdmin : public pw_rpc::nanopb::FabricAdmin::Service<FabricAdmin>
33+
{
34+
public:
35+
virtual ~FabricAdmin() = default;
36+
37+
virtual pw::Status OpenCommissioningWindow(const chip_rpc_DeviceInfo & request, chip_rpc_OperationStatus & response)
38+
{
39+
return pw::Status::Unimplemented();
40+
}
41+
};
42+
43+
} // namespace rpc
44+
} // namespace chip
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
*
3+
* Copyright (c) 2024 Project CHIP Authors
4+
* All rights reserved.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
#pragma once
20+
21+
#include "app/util/attribute-storage.h"
22+
#include "fabric_bridge_service/fabric_bridge_service.rpc.pb.h"
23+
#include "pigweed/rpc_services/internal/StatusUtils.h"
24+
#include <app-common/zap-generated/attributes/Accessors.h>
25+
#include <app-common/zap-generated/ids/Attributes.h>
26+
#include <app-common/zap-generated/ids/Clusters.h>
27+
#include <platform/PlatformManager.h>
28+
29+
namespace chip {
30+
namespace rpc {
31+
32+
class FabricBridge : public pw_rpc::nanopb::FabricBridge::Service<FabricBridge>
33+
{
34+
public:
35+
virtual ~FabricBridge() = default;
36+
37+
virtual pw::Status AddSynchronizedDevice(const chip_rpc_SynchronizedDevice & request, pw_protobuf_Empty & response)
38+
{
39+
return pw::Status::Unimplemented();
40+
}
41+
};
42+
43+
} // namespace rpc
44+
} // namespace chip

‎examples/fabric-admin/BUILD.gn

+47-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ import("${chip_root}/src/lib/core/core.gni")
2222

2323
assert(chip_build_tools)
2424

25+
import("${chip_root}/examples/common/pigweed/pigweed_rpcs.gni")
26+
27+
if (chip_enable_pw_rpc) {
28+
import("//build_overrides/pigweed.gni")
29+
import("$dir_pw_build/target_types.gni")
30+
}
31+
2532
config("config") {
2633
include_dirs = [
2734
".",
@@ -38,7 +45,9 @@ config("config") {
3845
defines += [ "CONFIG_USE_LOCAL_STORAGE" ]
3946
}
4047

41-
cflags = [ "-Wconversion" ]
48+
if (chip_enable_pw_rpc) {
49+
defines += [ "PW_RPC_ENABLED" ]
50+
}
4251
}
4352

4453
static_library("fabric-admin-utils") {
@@ -59,6 +68,7 @@ static_library("fabric-admin-utils") {
5968
"commands/common/HexConversion.h",
6069
"commands/common/RemoteDataModelLogger.cpp",
6170
"commands/common/RemoteDataModelLogger.h",
71+
"commands/fabric-sync/FabricSyncCommand.cpp",
6272
"commands/pairing/OpenCommissioningWindowCommand.cpp",
6373
"commands/pairing/OpenCommissioningWindowCommand.h",
6474
"commands/pairing/PairingCommand.cpp",
@@ -95,6 +105,42 @@ static_library("fabric-admin-utils") {
95105

96106
public_configs = [ ":config" ]
97107

108+
if (chip_enable_pw_rpc) {
109+
defines = [
110+
"PW_RPC_FABRIC_ADMIN_SERVICE=1",
111+
"PW_RPC_FABRIC_BRIDGE_SERVICE=1",
112+
]
113+
114+
sources += [
115+
"${chip_root}/examples/platform/linux/system_rpc_server.cc",
116+
"rpc/RpcClient.cpp",
117+
"rpc/RpcClient.h",
118+
"rpc/RpcServer.cpp",
119+
"rpc/RpcServer.h",
120+
]
121+
122+
deps += [
123+
"$dir_pw_hdlc:default_addresses",
124+
"$dir_pw_hdlc:rpc_channel_output",
125+
"$dir_pw_log",
126+
"$dir_pw_rpc:server",
127+
"$dir_pw_rpc/system_server:facade",
128+
"$dir_pw_rpc/system_server:socket",
129+
"$dir_pw_stream:socket_stream",
130+
"$dir_pw_sync:mutex",
131+
"${chip_root}/config/linux/lib/pw_rpc:pw_rpc",
132+
"${chip_root}/examples/common/pigweed:fabric_admin_service.nanopb_rpc",
133+
"${chip_root}/examples/common/pigweed:fabric_bridge_service.nanopb_rpc",
134+
"${chip_root}/examples/common/pigweed:rpc_services",
135+
]
136+
137+
deps += pw_build_LINK_DEPS
138+
} else {
139+
# The system_rpc_server.cc file is in pigweed and doesn't compile with
140+
# -Wconversion, remove check for RPC build only.
141+
cflags = [ "-Wconversion" ]
142+
}
143+
98144
if (chip_enable_transport_trace) {
99145
public_deps +=
100146
[ "${chip_root}/examples/common/tracing:trace_handlers_decoder" ]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright (c) 2021 Project CHIP Authors
3+
* All rights reserved.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*
17+
*/
18+
19+
#pragma once
20+
21+
#include <commands/common/Commands.h>
22+
#include <commands/fabric-sync/FabricSyncCommand.h>
23+
24+
void registerCommandsFabricSync(Commands & commands, CredentialIssuerCommands * credsIssuerConfig)
25+
{
26+
const char * clusterName = "FabricSync";
27+
28+
commands_list clusterCommands = {
29+
make_unique<FabricSyncAddDeviceCommand>(credsIssuerConfig),
30+
};
31+
32+
commands.RegisterCommandSet(clusterName, clusterCommands, "Commands for fabric synchronization.");
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright (c) 2024 Project CHIP Authors
3+
* All rights reserved.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*
17+
*/
18+
19+
#include "FabricSyncCommand.h"
20+
#include <commands/common/RemoteDataModelLogger.h>
21+
#include <thread>
22+
#include <unistd.h>
23+
24+
#if defined(PW_RPC_ENABLED)
25+
#include "pw_assert/check.h"
26+
#include "pw_hdlc/decoder.h"
27+
#include "pw_hdlc/default_addresses.h"
28+
#include "pw_hdlc/rpc_channel.h"
29+
#include "pw_rpc/client.h"
30+
#include "pw_stream/socket_stream.h"
31+
32+
#include <rpc/RpcClient.h>
33+
#endif
34+
35+
using namespace ::chip;
36+
37+
CHIP_ERROR FabricSyncAddDeviceCommand::RunCommand(NodeId remoteId)
38+
{
39+
#if defined(PW_RPC_ENABLED)
40+
AddSynchronizedDevice(remoteId);
41+
return CHIP_NO_ERROR;
42+
#else
43+
return CHIP_ERROR_NOT_IMPLEMENTED;
44+
#endif
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright (c) 2024 Project CHIP Authors
3+
* All rights reserved.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*
17+
*/
18+
19+
#pragma once
20+
21+
#include <commands/common/CHIPCommand.h>
22+
23+
class FabricSyncAddDeviceCommand : public CHIPCommand
24+
{
25+
public:
26+
FabricSyncAddDeviceCommand(CredentialIssuerCommands * credIssuerCommands) : CHIPCommand("add-device", credIssuerCommands)
27+
{
28+
AddArgument("nodeid", 0, UINT64_MAX, &mNodeId);
29+
}
30+
31+
/////////// CHIPCommand Interface /////////
32+
CHIP_ERROR RunCommand() override { return RunCommand(mNodeId); }
33+
34+
chip::System::Clock::Timeout GetWaitDuration() const override { return chip::System::Clock::Seconds16(30); }
35+
36+
private:
37+
chip::NodeId mNodeId;
38+
39+
CHIP_ERROR RunCommand(NodeId remoteId);
40+
};

‎examples/fabric-admin/main.cpp

+32
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,43 @@
1818

1919
#include <commands/clusters/SubscriptionsCommands.h>
2020
#include <commands/common/Commands.h>
21+
#include <commands/fabric-sync/Commands.h>
2122
#include <commands/interactive/Commands.h>
2223
#include <commands/pairing/Commands.h>
2324
#include <zap-generated/cluster/Commands.h>
2425

2526
#include <iostream>
2627
#include <string>
28+
#include <thread>
2729
#include <vector>
2830

31+
#if defined(PW_RPC_ENABLED)
32+
#include <rpc/RpcClient.h>
33+
#include <rpc/RpcServer.h>
34+
#endif
35+
36+
#define RETRY_INTERVAL_S (3)
37+
38+
void ApplicationInit()
39+
{
40+
#if defined(PW_RPC_ENABLED)
41+
InitRpcServer(kFabricAdminServerPort);
42+
ChipLogProgress(NotSpecified, "PW_RPC initialized.");
43+
44+
while (true)
45+
{
46+
if (InitRpcClient(kFabricBridgeServerPort) == CHIP_NO_ERROR)
47+
{
48+
ChipLogProgress(NotSpecified, "Connected to Fabric-Bridge");
49+
break;
50+
}
51+
52+
ChipLogError(NotSpecified, "Failed to connect to Fabric-Bridge, retry in %d seconds....", RETRY_INTERVAL_S);
53+
std::this_thread::sleep_for(std::chrono::seconds(RETRY_INTERVAL_S));
54+
}
55+
#endif
56+
}
57+
2958
// ================================================================================
3059
// Main Code
3160
// ================================================================================
@@ -45,6 +74,7 @@ int main(int argc, char * argv[])
4574
ExampleCredentialIssuerCommands credIssuerCommands;
4675
Commands commands;
4776

77+
registerCommandsFabricSync(commands, &credIssuerCommands);
4878
registerCommandsInteractive(commands, &credIssuerCommands);
4979
registerCommandsPairing(commands, &credIssuerCommands);
5080
registerClusters(commands, &credIssuerCommands);
@@ -56,5 +86,7 @@ int main(int argc, char * argv[])
5686
c_args.push_back(const_cast<char *>(arg.c_str()));
5787
}
5888

89+
ApplicationInit();
90+
5991
return commands.Run(static_cast<int>(c_args.size()), c_args.data());
6092
}
+168
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
/*
2+
*
3+
* Copyright (c) 2024 Project CHIP Authors
4+
* All rights reserved.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
#include "RpcClient.h"
20+
21+
#include <string>
22+
#include <thread>
23+
#include <unistd.h>
24+
25+
#include "fabric_bridge_service/fabric_bridge_service.rpc.pb.h"
26+
#include "pw_assert/check.h"
27+
#include "pw_hdlc/decoder.h"
28+
#include "pw_hdlc/default_addresses.h"
29+
#include "pw_hdlc/rpc_channel.h"
30+
#include "pw_rpc/client.h"
31+
#include "pw_stream/socket_stream.h"
32+
33+
namespace {
34+
35+
constexpr size_t kMaxTransmissionUnit = 256;
36+
constexpr uint32_t kRpcTimeoutMs = 1000;
37+
const char * rpcServerAddress = "127.0.0.1";
38+
39+
pw::stream::SocketStream rpcSocketStream;
40+
41+
// Set up the output channel for the pw_rpc client to use.
42+
pw::hdlc::RpcChannelOutput hdlc_channel_output(rpcSocketStream, pw::hdlc::kDefaultRpcAddress, "HDLC channel");
43+
44+
// An array of RPC channels (channels) is created, each associated with an HDLC channel output.
45+
// This sets up the communication channels for RPC calls.
46+
pw::rpc::Channel channels[] = { pw::rpc::Channel::Create<1>(&hdlc_channel_output) };
47+
48+
// Initialize the RPC client with the channels.
49+
pw::rpc::Client client(channels);
50+
51+
// Generated clients are namespaced with their proto library.
52+
using FabricBridgeClient = chip::rpc::pw_rpc::nanopb::FabricBridge::Client;
53+
54+
// RPC channel ID on which to make client calls. RPC calls cannot be made on
55+
// channel 0 (Channel::kUnassignedChannelId).
56+
constexpr uint32_t kDefaultChannelId = 1;
57+
58+
// Function to process incoming packets
59+
void ProcessPackets()
60+
{
61+
std::array<std::byte, kMaxTransmissionUnit> inputBuf;
62+
pw::hdlc::Decoder decoder(inputBuf);
63+
64+
while (true)
65+
{
66+
std::array<std::byte, kMaxTransmissionUnit> data;
67+
auto ret = rpcSocketStream.Read(data);
68+
if (!ret.ok())
69+
{
70+
if (ret.status() == pw::Status::OutOfRange())
71+
{
72+
// Handle remote disconnect
73+
rpcSocketStream.Close();
74+
return;
75+
}
76+
continue;
77+
}
78+
79+
for (std::byte byte : ret.value())
80+
{
81+
auto result = decoder.Process(byte);
82+
if (!result.ok())
83+
{
84+
// Wait for more bytes that form a complete packet
85+
continue;
86+
}
87+
pw::hdlc::Frame & frame = result.value();
88+
if (frame.address() != pw::hdlc::kDefaultRpcAddress)
89+
{
90+
// Wrong address; ignore the packet
91+
continue;
92+
}
93+
94+
client.ProcessPacket(frame.data()).IgnoreError();
95+
}
96+
}
97+
}
98+
99+
template <typename CallType>
100+
CHIP_ERROR WaitForResponse(CallType & call)
101+
{
102+
if (!call.active())
103+
{
104+
return CHIP_ERROR_INTERNAL;
105+
}
106+
107+
// Wait for the response or timeout
108+
uint32_t elapsedTimeMs = 0;
109+
const uint32_t sleepTimeMs = 100;
110+
111+
while (call.active() && elapsedTimeMs < kRpcTimeoutMs)
112+
{
113+
usleep(sleepTimeMs * 1000);
114+
elapsedTimeMs += sleepTimeMs;
115+
}
116+
117+
if (elapsedTimeMs >= kRpcTimeoutMs)
118+
{
119+
fprintf(stderr, "RPC Response timed out!");
120+
return CHIP_ERROR_TIMEOUT;
121+
}
122+
123+
return CHIP_NO_ERROR;
124+
}
125+
126+
void AddDeviceResponse(const pw_protobuf_Empty & response, pw::Status status)
127+
{
128+
if (status.ok())
129+
{
130+
printf("RPC call succeeded\n");
131+
}
132+
else
133+
{
134+
printf("RPC call failed with status: %d\n", status.code());
135+
}
136+
}
137+
138+
} // namespace
139+
140+
CHIP_ERROR InitRpcClient(uint16_t rpcServerPort)
141+
{
142+
if (rpcSocketStream.Connect(rpcServerAddress, rpcServerPort) != PW_STATUS_OK)
143+
{
144+
ChipLogError(NotSpecified, "Failed to connect the Fabric-Admin");
145+
return CHIP_ERROR_NOT_CONNECTED;
146+
}
147+
148+
ChipLogProgress(NotSpecified, "Connectted to the Fabric-Admin\n");
149+
150+
// Start a thread to process incoming packets
151+
std::thread packet_processor(ProcessPackets);
152+
packet_processor.detach();
153+
154+
return CHIP_NO_ERROR;
155+
}
156+
157+
CHIP_ERROR AddSynchronizedDevice(chip::NodeId nodeId)
158+
{
159+
ChipLogProgress(NotSpecified, "AddSynchronizedDevice");
160+
161+
FabricBridgeClient fabric_bridge_client(client, kDefaultChannelId);
162+
chip_rpc_SynchronizedDevice device;
163+
device.node_id = nodeId;
164+
165+
// The RPC will remain active as long as `call` is alive.
166+
auto call = fabric_bridge_client.AddSynchronizedDevice(device, AddDeviceResponse);
167+
return WaitForResponse(call);
168+
}

‎examples/fabric-admin/rpc/RpcClient.h

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
*
3+
* Copyright (c) 2024 Project CHIP Authors
4+
* All rights reserved.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
#pragma once
20+
21+
#include <platform/CHIPDeviceLayer.h>
22+
23+
constexpr uint16_t kFabricBridgeServerPort = 33002;
24+
25+
CHIP_ERROR InitRpcClient(uint16_t rpcServerPort);
26+
27+
CHIP_ERROR AddSynchronizedDevice(chip::NodeId nodeId);
+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
*
3+
* Copyright (c) 2024 Project CHIP Authors
4+
* All rights reserved.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
#include "pw_rpc/server.h"
20+
#include "pw_rpc_system_server/rpc_server.h"
21+
#include "pw_rpc_system_server/socket.h"
22+
23+
#include <system/SystemClock.h>
24+
#include <thread>
25+
26+
#if defined(PW_RPC_FABRIC_ADMIN_SERVICE) && PW_RPC_FABRIC_ADMIN_SERVICE
27+
#include "pigweed/rpc_services/FabricAdmin.h"
28+
#endif
29+
30+
namespace {
31+
32+
#if defined(PW_RPC_FABRIC_ADMIN_SERVICE) && PW_RPC_FABRIC_ADMIN_SERVICE
33+
class FabricAdmin final : public chip::rpc::FabricAdmin
34+
{
35+
public:
36+
pw::Status OpenCommissioningWindow(const chip_rpc_DeviceInfo & request, chip_rpc_OperationStatus & response) override
37+
{
38+
chip::NodeId nodeId = request.node_id;
39+
printf("Received OpenCommissioningWindow request: 0x%" PRIx64 "\n", nodeId);
40+
response.success = false;
41+
42+
return pw::OkStatus();
43+
}
44+
};
45+
46+
FabricAdmin fabric_admin_service;
47+
#endif // defined(PW_RPC_FABRIC_ADMIN_SERVICE) && PW_RPC_FABRIC_ADMIN_SERVICE
48+
49+
void RegisterServices(pw::rpc::Server & server)
50+
{
51+
#if defined(PW_RPC_FABRIC_ADMIN_SERVICE) && PW_RPC_FABRIC_ADMIN_SERVICE
52+
server.RegisterService(fabric_admin_service);
53+
#endif
54+
}
55+
56+
} // namespace
57+
58+
void RunRpcService()
59+
{
60+
pw::rpc::system_server::Init();
61+
RegisterServices(pw::rpc::system_server::Server());
62+
pw::rpc::system_server::Start();
63+
}
64+
65+
void InitRpcServer(uint16_t rpcServerPort)
66+
{
67+
pw::rpc::system_server::set_socket_port(rpcServerPort);
68+
std::thread rpc_service(RunRpcService);
69+
rpc_service.detach();
70+
}

‎examples/fabric-admin/rpc/RpcServer.h

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
*
3+
* Copyright (c) 2024 Project CHIP Authors
4+
* All rights reserved.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
#pragma once
20+
21+
constexpr uint16_t kFabricAdminServerPort = 33001;
22+
23+
void InitRpcServer(uint16_t rpcServerPort);

‎examples/fabric-admin/with_pw_rpc.gni

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Copyright (c) 2024 Project CHIP Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# add this gni as import in your build args to use pigweed in the example
16+
# 'import("//with_pw_rpc.gni")'
17+
18+
import("//build_overrides/chip.gni")
19+
20+
import("${chip_root}/config/standalone/args.gni")
21+
22+
import("//build_overrides/pigweed.gni")
23+
24+
pw_log_BACKEND = "$dir_pw_log_basic"
25+
pw_assert_BACKEND = "$dir_pw_assert_log:check_backend"
26+
pw_sys_io_BACKEND = "$dir_pw_sys_io_stdio"
27+
pw_trace_BACKEND = "$dir_pw_trace_tokenized"
28+
pw_unit_test_MAIN = "$dir_pw_unit_test:logging_main"
29+
pw_rpc_system_server_BACKEND = "${chip_root}/config/linux/lib/pw_rpc:pw_rpc"
30+
dir_pw_third_party_nanopb = "${chip_root}/third_party/nanopb/repo"
31+
pw_chrono_SYSTEM_CLOCK_BACKEND = "$dir_pw_chrono_stl:system_clock"
32+
pw_sync_MUTEX_BACKEND = "$dir_pw_sync_stl:mutex_backend"
33+
pw_thread_YIELD_BACKEND = "$dir_pw_thread_stl:yield"
34+
pw_thread_SLEEP_BACKEND = "$dir_pw_thread_stl:sleep"
35+
36+
pw_build_LINK_DEPS = [
37+
"$dir_pw_assert:impl",
38+
"$dir_pw_log:impl",
39+
]
40+
41+
chip_enable_pw_rpc = true
42+
chip_use_pw_logging = true

‎examples/fabric-bridge-app/linux/BUILD.gn

+34
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,19 @@ import("${chip_root}/build/chip/tools.gni")
1818

1919
assert(chip_build_tools)
2020

21+
import("//build_overrides/pigweed.gni")
22+
import("$dir_pw_build/target_types.gni")
23+
import("${chip_root}/examples/common/pigweed/pigweed_rpcs.gni")
24+
2125
executable("fabric-bridge-app") {
2226
sources = [
2327
"${chip_root}/examples/fabric-bridge-app/fabric-bridge-common/include/CHIPProjectAppConfig.h",
2428
"Device.cpp",
29+
"RpcClient.cpp",
30+
"RpcServer.cpp",
2531
"include/Device.h",
32+
"include/RpcClient.h",
33+
"include/RpcServer.h",
2634
"main.cpp",
2735
]
2836

@@ -36,6 +44,32 @@ executable("fabric-bridge-app") {
3644

3745
include_dirs = [ "include" ]
3846

47+
defines = [
48+
"PW_RPC_FABRIC_ADMIN_SERVICE=1",
49+
"PW_RPC_FABRIC_BRIDGE_SERVICE=1",
50+
]
51+
52+
sources += [ "${chip_root}/examples/platform/linux/system_rpc_server.cc" ]
53+
54+
deps += [
55+
"$dir_pw_hdlc:default_addresses",
56+
"$dir_pw_hdlc:rpc_channel_output",
57+
"$dir_pw_log",
58+
"$dir_pw_rpc:server",
59+
"$dir_pw_rpc/system_server:facade",
60+
"$dir_pw_rpc/system_server:socket",
61+
"$dir_pw_stream:socket_stream",
62+
"$dir_pw_sync:mutex",
63+
"${chip_root}/config/linux/lib/pw_rpc:pw_rpc",
64+
"${chip_root}/examples/common/pigweed:fabric_admin_service.nanopb_rpc",
65+
"${chip_root}/examples/common/pigweed:fabric_bridge_service.nanopb_rpc",
66+
"${chip_root}/examples/common/pigweed:rpc_services",
67+
]
68+
69+
deps += pw_build_LINK_DEPS
70+
71+
include_dirs += [ "${chip_root}/examples/common" ]
72+
3973
output_dir = root_out_dir
4074
}
4175

‎examples/fabric-bridge-app/linux/Device.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ void Device::SetReachable(bool aReachable)
4646

4747
if (aReachable)
4848
{
49-
ChipLogProgress(DeviceLayer, "Device[%s]: ONLINE", mName);
49+
ChipLogProgress(NotSpecified, "Device[%s]: ONLINE", mName);
5050
}
5151
else
5252
{
53-
ChipLogProgress(DeviceLayer, "Device[%s]: OFFLINE", mName);
53+
ChipLogProgress(NotSpecified, "Device[%s]: OFFLINE", mName);
5454
}
5555

5656
if (changed)
@@ -63,7 +63,7 @@ void Device::SetName(const char * szName)
6363
{
6464
bool changed = (strncmp(mName, szName, sizeof(mName)) != 0);
6565

66-
ChipLogProgress(DeviceLayer, "Device[%s]: New Name=\"%s\"", mName, szName);
66+
ChipLogProgress(NotSpecified, "Device[%s]: New Name=\"%s\"", mName, szName);
6767

6868
chip::Platform::CopyString(mName, szName);
6969

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
/*
2+
*
3+
* Copyright (c) 2024 Project CHIP Authors
4+
* All rights reserved.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
#include "RpcClient.h"
20+
21+
#include <string>
22+
#include <thread>
23+
#include <unistd.h>
24+
25+
#include "fabric_admin_service/fabric_admin_service.rpc.pb.h"
26+
#include "pw_assert/check.h"
27+
#include "pw_hdlc/decoder.h"
28+
#include "pw_hdlc/default_addresses.h"
29+
#include "pw_hdlc/rpc_channel.h"
30+
#include "pw_rpc/client.h"
31+
#include "pw_stream/socket_stream.h"
32+
33+
namespace {
34+
35+
constexpr size_t kMaxTransmissionUnit = 256;
36+
constexpr uint32_t kRpcTimeoutMs = 1000;
37+
const char * rpcServerAddress = "127.0.0.1";
38+
39+
pw::stream::SocketStream rpcSocketStream;
40+
41+
// Set up the output channel for the pw_rpc client to use.
42+
pw::hdlc::RpcChannelOutput hdlc_channel_output(rpcSocketStream, pw::hdlc::kDefaultRpcAddress, "HDLC channel");
43+
44+
// An array of RPC channels (channels) is created, each associated with an HDLC channel output.
45+
// This sets up the communication channels for RPC calls.
46+
pw::rpc::Channel channels[] = { pw::rpc::Channel::Create<1>(&hdlc_channel_output) };
47+
48+
// Initialize the RPC client with the channels.
49+
pw::rpc::Client client(channels);
50+
51+
// Generated clients are namespaced with their proto library.
52+
using FabricAdminClient = chip::rpc::pw_rpc::nanopb::FabricAdmin::Client;
53+
54+
// RPC channel ID on which to make client calls. RPC calls cannot be made on
55+
// channel 0 (Channel::kUnassignedChannelId).
56+
constexpr uint32_t kDefaultChannelId = 1;
57+
58+
// Function to process incoming packets
59+
void ProcessPackets()
60+
{
61+
std::array<std::byte, kMaxTransmissionUnit> inputBuf;
62+
pw::hdlc::Decoder decoder(inputBuf);
63+
64+
while (true)
65+
{
66+
std::array<std::byte, kMaxTransmissionUnit> data;
67+
auto ret = rpcSocketStream.Read(data);
68+
if (!ret.ok())
69+
{
70+
if (ret.status() == pw::Status::OutOfRange())
71+
{
72+
// Handle remote disconnect
73+
rpcSocketStream.Close();
74+
return;
75+
}
76+
continue;
77+
}
78+
79+
for (std::byte byte : ret.value())
80+
{
81+
auto result = decoder.Process(byte);
82+
if (!result.ok())
83+
{
84+
// Wait for more bytes that form a complete packet
85+
continue;
86+
}
87+
pw::hdlc::Frame & frame = result.value();
88+
if (frame.address() != pw::hdlc::kDefaultRpcAddress)
89+
{
90+
// Wrong address; ignore the packet
91+
continue;
92+
}
93+
94+
client.ProcessPacket(frame.data()).IgnoreError();
95+
}
96+
}
97+
}
98+
99+
template <typename CallType>
100+
CHIP_ERROR WaitForResponse(CallType & call)
101+
{
102+
if (!call.active())
103+
{
104+
return CHIP_ERROR_INTERNAL;
105+
}
106+
107+
// Wait for the response or timeout
108+
uint32_t elapsedTimeMs = 0;
109+
const uint32_t sleepTimeMs = 100;
110+
111+
while (call.active() && elapsedTimeMs < kRpcTimeoutMs)
112+
{
113+
usleep(sleepTimeMs * 1000);
114+
elapsedTimeMs += sleepTimeMs;
115+
}
116+
117+
if (elapsedTimeMs >= kRpcTimeoutMs)
118+
{
119+
ChipLogError(NotSpecified, "RPC Response timed out!");
120+
return CHIP_ERROR_TIMEOUT;
121+
}
122+
123+
return CHIP_NO_ERROR;
124+
}
125+
126+
void OperationStatusResponse(const chip_rpc_OperationStatus & response, pw::Status status)
127+
{
128+
if (status.ok())
129+
{
130+
ChipLogProgress(NotSpecified, "Received operation status: %d", response.success);
131+
}
132+
else
133+
{
134+
ChipLogProgress(NotSpecified, "RPC call failed with status: %d\n", status.code());
135+
}
136+
}
137+
138+
} // namespace
139+
140+
CHIP_ERROR InitRpcClient(uint16_t rpcServerPort)
141+
{
142+
if (rpcSocketStream.Connect(rpcServerAddress, rpcServerPort) != PW_STATUS_OK)
143+
{
144+
ChipLogError(NotSpecified, "Failed to connect the Fabric-Admin");
145+
return CHIP_ERROR_NOT_CONNECTED;
146+
}
147+
148+
ChipLogProgress(NotSpecified, "Connectted to the Fabric-Admin\n");
149+
150+
// Start a thread to process incoming packets
151+
std::thread packet_processor(ProcessPackets);
152+
packet_processor.detach();
153+
154+
return CHIP_NO_ERROR;
155+
}
156+
157+
CHIP_ERROR OpenCommissioningWindow(chip::NodeId nodeId)
158+
{
159+
ChipLogProgress(NotSpecified, "OpenCommissioningWindow\n");
160+
161+
FabricAdminClient fabric_admin_client(client, kDefaultChannelId);
162+
chip_rpc_DeviceInfo device;
163+
164+
device.node_id = nodeId;
165+
166+
// The RPC will remain active as long as `call` is alive.
167+
auto call = fabric_admin_client.OpenCommissioningWindow(device, OperationStatusResponse);
168+
return WaitForResponse(call);
169+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
*
3+
* Copyright (c) 2024 Project CHIP Authors
4+
* All rights reserved.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
#include "pw_rpc/server.h"
20+
#include "pw_rpc_system_server/rpc_server.h"
21+
#include "pw_rpc_system_server/socket.h"
22+
23+
#include <system/SystemClock.h>
24+
#include <thread>
25+
26+
#if defined(PW_RPC_FABRIC_BRIDGE_SERVICE) && PW_RPC_FABRIC_BRIDGE_SERVICE
27+
#include "pigweed/rpc_services/FabricBridge.h"
28+
#endif
29+
30+
namespace {
31+
32+
#if defined(PW_RPC_FABRIC_BRIDGE_SERVICE) && PW_RPC_FABRIC_BRIDGE_SERVICE
33+
class FabricBridge final : public chip::rpc::FabricBridge
34+
{
35+
public:
36+
pw::Status AddSynchronizedDevice(const chip_rpc_SynchronizedDevice & request, pw_protobuf_Empty & response) override
37+
{
38+
chip::NodeId nodeId = request.node_id;
39+
ChipLogProgress(NotSpecified, "Received AddSynchronizedDevice: " ChipLogFormatX64, ChipLogValueX64(nodeId));
40+
return pw::OkStatus();
41+
}
42+
};
43+
44+
FabricBridge fabric_bridge_service;
45+
#endif // defined(PW_RPC_FABRIC_BRIDGE_SERVICE) && PW_RPC_FABRIC_BRIDGE_SERVICE
46+
47+
void RegisterServices(pw::rpc::Server & server)
48+
{
49+
#if defined(PW_RPC_FABRIC_BRIDGE_SERVICE) && PW_RPC_FABRIC_BRIDGE_SERVICE
50+
server.RegisterService(fabric_bridge_service);
51+
#endif
52+
}
53+
54+
} // namespace
55+
56+
void RunRpcService()
57+
{
58+
pw::rpc::system_server::Init();
59+
RegisterServices(pw::rpc::system_server::Server());
60+
pw::rpc::system_server::Start();
61+
}
62+
63+
void InitRpcServer(uint16_t rpcServerPort)
64+
{
65+
pw::rpc::system_server::set_socket_port(rpcServerPort);
66+
std::thread rpc_service(RunRpcService);
67+
rpc_service.detach();
68+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
*
3+
* Copyright (c) 2024 Project CHIP Authors
4+
* All rights reserved.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
#pragma once
20+
21+
#include <platform/CHIPDeviceLayer.h>
22+
23+
constexpr uint16_t kFabricAdminServerPort = 33001;
24+
25+
CHIP_ERROR InitRpcClient(uint16_t rpcServerPort);
26+
27+
CHIP_ERROR OpenCommissioningWindow(chip::NodeId nodeId);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
*
3+
* Copyright (c) 2024 Project CHIP Authors
4+
* All rights reserved.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
#pragma once
20+
21+
constexpr uint16_t kFabricBridgeServerPort = 33002;
22+
23+
void InitRpcServer(uint16_t rpcServerPort);

‎examples/fabric-bridge-app/linux/main.cpp

+32-7
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,11 @@
4242

4343
#include "CommissionableInit.h"
4444
#include "Device.h"
45+
#include "RpcClient.h"
46+
#include "RpcServer.h"
4547

4648
#include <cassert>
49+
#include <chrono>
4750
#include <iostream>
4851
#include <string>
4952
#include <sys/ioctl.h>
@@ -58,6 +61,7 @@ using namespace chip::DeviceLayer;
5861
using namespace chip::app::Clusters;
5962

6063
#define POLL_INTERVAL_MS (100)
64+
#define RETRY_INTERVAL_S (3)
6165

6266
namespace {
6367

@@ -81,9 +85,16 @@ void BridgePollingThread()
8185
int ch = getchar();
8286
if (ch == 'e')
8387
{
84-
ChipLogProgress(DeviceLayer, "Exiting.....");
88+
ChipLogProgress(NotSpecified, "Exiting.....");
8589
exit(0);
8690
}
91+
else if (ch == 'o')
92+
{
93+
if (OpenCommissioningWindow(0x1234) != CHIP_NO_ERROR)
94+
{
95+
ChipLogError(NotSpecified, "Failed to call OpenCommissioningWindow RPC");
96+
}
97+
}
8798
continue;
8899
}
89100

@@ -124,7 +135,7 @@ int AddDeviceEndpoint(Device * dev, EmberAfEndpointType * ep, const Span<const E
124135
emberAfSetDynamicEndpoint(index, gCurrentEndpointId, ep, dataVersionStorage, deviceTypeList, parentEndpointId);
125136
if (err == CHIP_NO_ERROR)
126137
{
127-
ChipLogProgress(DeviceLayer, "Added device %s to dynamic endpoint %d (index=%d)", dev->GetName(),
138+
ChipLogProgress(NotSpecified, "Added device %s to dynamic endpoint %d (index=%d)", dev->GetName(),
128139
gCurrentEndpointId, index);
129140
return index;
130141
}
@@ -139,12 +150,12 @@ int AddDeviceEndpoint(Device * dev, EmberAfEndpointType * ep, const Span<const E
139150
}
140151
retryCount++;
141152
}
142-
ChipLogError(DeviceLayer, "Failed to add dynamic endpoint after %d retries", maxRetries);
153+
ChipLogError(NotSpecified, "Failed to add dynamic endpoint after %d retries", maxRetries);
143154
return -1; // Return error as all retries are exhausted
144155
}
145156
index++;
146157
}
147-
ChipLogProgress(DeviceLayer, "Failed to add dynamic endpoint: No endpoints available!");
158+
ChipLogProgress(NotSpecified, "Failed to add dynamic endpoint: No endpoints available!");
148159
return -1;
149160
}
150161

@@ -160,7 +171,7 @@ int RemoveDeviceEndpoint(Device * dev)
160171
// disabled.
161172
[[maybe_unused]] EndpointId ep = emberAfClearDynamicEndpoint(index);
162173
gDevices[index] = nullptr;
163-
ChipLogProgress(DeviceLayer, "Removed device %s from dynamic endpoint %d (index=%d)", dev->GetName(), ep, index);
174+
ChipLogProgress(NotSpecified, "Removed device %s from dynamic endpoint %d (index=%d)", dev->GetName(), ep, index);
164175
return index;
165176
}
166177
index++;
@@ -201,7 +212,7 @@ Protocols::InteractionModel::Status HandleReadBridgedDeviceBasicAttribute(Device
201212
{
202213
using namespace BridgedDeviceBasicInformation::Attributes;
203214

204-
ChipLogProgress(DeviceLayer, "HandleReadBridgedDeviceBasicAttribute: attrId=%d, maxReadLength=%d", attributeId, maxReadLength);
215+
ChipLogProgress(NotSpecified, "HandleReadBridgedDeviceBasicAttribute: attrId=%d, maxReadLength=%d", attributeId, maxReadLength);
205216

206217
if ((attributeId == Reachable::Id) && (maxReadLength == 1))
207218
{
@@ -265,7 +276,7 @@ Protocols::InteractionModel::Status emberAfExternalAttributeWriteCallback(Endpoi
265276

266277
if (dev->IsReachable())
267278
{
268-
ChipLogProgress(DeviceLayer, "emberAfExternalAttributeWriteCallback: ep=%d, clusterId=%d", endpoint, clusterId);
279+
ChipLogProgress(NotSpecified, "emberAfExternalAttributeWriteCallback: ep=%d, clusterId=%d", endpoint, clusterId);
269280
ret = Protocols::InteractionModel::Status::Success;
270281
}
271282
}
@@ -284,6 +295,20 @@ void ApplicationInit()
284295
static_cast<int>(emberAfEndpointFromIndex(static_cast<uint16_t>(emberAfFixedEndpointCount() - 1))) + 1);
285296
gCurrentEndpointId = gFirstDynamicEndpointId;
286297

298+
InitRpcServer(kFabricBridgeServerPort);
299+
300+
while (true)
301+
{
302+
if (InitRpcClient(kFabricAdminServerPort) == CHIP_NO_ERROR)
303+
{
304+
ChipLogProgress(NotSpecified, "Connected to Fabric-Admin");
305+
break;
306+
}
307+
308+
ChipLogError(NotSpecified, "Failed to connect to Fabric-Admin, retry in %d seconds....", RETRY_INTERVAL_S);
309+
std::this_thread::sleep_for(std::chrono::seconds(RETRY_INTERVAL_S));
310+
}
311+
287312
// Start a thread for bridge polling
288313
std::thread pollingThread(BridgePollingThread);
289314
pollingThread.detach();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Copyright (c) 2024 Project CHIP Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# add this gni as import in your build args to use pigweed in the example
16+
# 'import("//with_pw_rpc.gni")'
17+
18+
import("//build_overrides/chip.gni")
19+
20+
import("${chip_root}/config/standalone/args.gni")
21+
22+
import("//build_overrides/pigweed.gni")
23+
24+
pw_log_BACKEND = "$dir_pw_log_basic"
25+
pw_assert_BACKEND = "$dir_pw_assert_log:check_backend"
26+
pw_sys_io_BACKEND = "$dir_pw_sys_io_stdio"
27+
pw_trace_BACKEND = "$dir_pw_trace_tokenized"
28+
pw_unit_test_MAIN = "$dir_pw_unit_test:logging_main"
29+
pw_rpc_system_server_BACKEND = "${chip_root}/config/linux/lib/pw_rpc:pw_rpc"
30+
dir_pw_third_party_nanopb = "${chip_root}/third_party/nanopb/repo"
31+
pw_chrono_SYSTEM_CLOCK_BACKEND = "$dir_pw_chrono_stl:system_clock"
32+
pw_sync_MUTEX_BACKEND = "$dir_pw_sync_stl:mutex_backend"
33+
pw_thread_YIELD_BACKEND = "$dir_pw_thread_stl:yield"
34+
pw_thread_SLEEP_BACKEND = "$dir_pw_thread_stl:sleep"
35+
36+
pw_build_LINK_DEPS = [
37+
"$dir_pw_assert:impl",
38+
"$dir_pw_log:impl",
39+
]
40+
41+
chip_use_pw_logging = true

0 commit comments

Comments
 (0)
Please sign in to comment.