Skip to content

Commit

Permalink
Add bridge_enable_pw_rpc build flag
Browse files Browse the repository at this point in the history
  • Loading branch information
yufengwangca committed May 30, 2024
1 parent d046d91 commit 9631848
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 38 deletions.
6 changes: 2 additions & 4 deletions examples/fabric-admin/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ config("config") {
defines += [ "CONFIG_USE_LOCAL_STORAGE" ]
}

cflags = [ "-Wconversion" ]

if (chip_enable_pw_rpc) {
defines += [ "PW_RPC_ENABLED" ]
}
Expand Down Expand Up @@ -135,10 +137,6 @@ static_library("fabric-admin-utils") {
]

deps += pw_build_LINK_DEPS
} else {
# The system_rpc_server.cc file is in pigweed and doesn't compile with
# -Wconversion, remove check for RPC build only.
cflags = [ "-Wconversion" ]
}

if (chip_enable_transport_trace) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class FabricSyncAddDeviceCommand : public CHIPCommand
/////////// CHIPCommand Interface /////////
CHIP_ERROR RunCommand() override { return RunCommand(mNodeId); }

chip::System::Clock::Timeout GetWaitDuration() const override { return chip::System::Clock::Seconds16(30); }
chip::System::Clock::Timeout GetWaitDuration() const override { return chip::System::Clock::Seconds16(1); }

private:
chip::NodeId mNodeId;
Expand Down
2 changes: 1 addition & 1 deletion examples/fabric-admin/rpc/RpcServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class FabricAdmin final : public chip::rpc::FabricAdmin
pw::Status OpenCommissioningWindow(const chip_rpc_DeviceInfo & request, chip_rpc_OperationStatus & response) override
{
chip::NodeId nodeId = request.node_id;
printf("Received OpenCommissioningWindow request: 0x%" PRIx64 "\n", nodeId);
printf("Received OpenCommissioningWindow request: 0x%llx\n", nodeId);
response.success = false;

return pw::OkStatus();
Expand Down
76 changes: 44 additions & 32 deletions examples/fabric-bridge-app/linux/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,25 @@ import("//build_overrides/chip.gni")

import("${chip_root}/build/chip/tools.gni")

import("//with_pw_rpc.gni")

assert(chip_build_tools)

import("//build_overrides/pigweed.gni")
import("$dir_pw_build/target_types.gni")
import("${chip_root}/examples/common/pigweed/pigweed_rpcs.gni")
declare_args() {
bridge_enable_pw_rpc = false
}

if (bridge_enable_pw_rpc) {
import("//build_overrides/pigweed.gni")
import("$dir_pw_build/target_types.gni")
import("${chip_root}/examples/common/pigweed/pigweed_rpcs.gni")
}

executable("fabric-bridge-app") {
sources = [
"${chip_root}/examples/fabric-bridge-app/fabric-bridge-common/include/CHIPProjectAppConfig.h",
"Device.cpp",
"RpcClient.cpp",
"RpcServer.cpp",
"include/Device.h",
"include/RpcClient.h",
"include/RpcServer.h",
"main.cpp",
]

Expand All @@ -44,31 +48,39 @@ executable("fabric-bridge-app") {

include_dirs = [ "include" ]

defines = [
"PW_RPC_FABRIC_ADMIN_SERVICE=1",
"PW_RPC_FABRIC_BRIDGE_SERVICE=1",
]

sources += [ "${chip_root}/examples/platform/linux/system_rpc_server.cc" ]

deps += [
"$dir_pw_hdlc:default_addresses",
"$dir_pw_hdlc:rpc_channel_output",
"$dir_pw_log",
"$dir_pw_rpc:server",
"$dir_pw_rpc/system_server:facade",
"$dir_pw_rpc/system_server:socket",
"$dir_pw_stream:socket_stream",
"$dir_pw_sync:mutex",
"${chip_root}/config/linux/lib/pw_rpc:pw_rpc",
"${chip_root}/examples/common/pigweed:fabric_admin_service.nanopb_rpc",
"${chip_root}/examples/common/pigweed:fabric_bridge_service.nanopb_rpc",
"${chip_root}/examples/common/pigweed:rpc_services",
]

deps += pw_build_LINK_DEPS

include_dirs += [ "${chip_root}/examples/common" ]
if (bridge_enable_pw_rpc) {
defines = [
"PW_RPC_FABRIC_ADMIN_SERVICE=1",
"PW_RPC_FABRIC_BRIDGE_SERVICE=1",
]

sources += [
"${chip_root}/examples/platform/linux/system_rpc_server.cc",
"RpcClient.cpp",
"RpcServer.cpp",
"include/RpcClient.h",
"include/RpcServer.h",
]

deps += [
"$dir_pw_hdlc:default_addresses",
"$dir_pw_hdlc:rpc_channel_output",
"$dir_pw_log",
"$dir_pw_rpc:server",
"$dir_pw_rpc/system_server:facade",
"$dir_pw_rpc/system_server:socket",
"$dir_pw_stream:socket_stream",
"$dir_pw_sync:mutex",
"${chip_root}/config/linux/lib/pw_rpc:pw_rpc",
"${chip_root}/examples/common/pigweed:fabric_admin_service.nanopb_rpc",
"${chip_root}/examples/common/pigweed:fabric_bridge_service.nanopb_rpc",
"${chip_root}/examples/common/pigweed:rpc_services",
]

deps += pw_build_LINK_DEPS

include_dirs += [ "${chip_root}/examples/common" ]
}

output_dir = root_out_dir
}
Expand Down
6 changes: 6 additions & 0 deletions examples/fabric-bridge-app/linux/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@

#include "CommissionableInit.h"
#include "Device.h"
#if defined(PW_RPC_FABRIC_BRIDGE_SERVICE)
#include "RpcClient.h"
#include "RpcServer.h"
#endif

#include <cassert>
#include <chrono>
Expand Down Expand Up @@ -88,13 +90,15 @@ void BridgePollingThread()
ChipLogProgress(NotSpecified, "Exiting.....");
exit(0);
}
#if defined(PW_RPC_FABRIC_BRIDGE_SERVICE)
else if (ch == 'o')
{
if (OpenCommissioningWindow(0x1234) != CHIP_NO_ERROR)
{
ChipLogError(NotSpecified, "Failed to call OpenCommissioningWindow RPC");
}
}
#endif
continue;
}

Expand Down Expand Up @@ -295,6 +299,7 @@ void ApplicationInit()
static_cast<int>(emberAfEndpointFromIndex(static_cast<uint16_t>(emberAfFixedEndpointCount() - 1))) + 1);
gCurrentEndpointId = gFirstDynamicEndpointId;

#if defined(PW_RPC_FABRIC_BRIDGE_SERVICE)
InitRpcServer(kFabricBridgeServerPort);

while (true)
Expand All @@ -308,6 +313,7 @@ void ApplicationInit()
ChipLogError(NotSpecified, "Failed to connect to Fabric-Admin, retry in %d seconds....", RETRY_INTERVAL_S);
std::this_thread::sleep_for(std::chrono::seconds(RETRY_INTERVAL_S));
}
#endif

// Start a thread for bridge polling
std::thread pollingThread(BridgePollingThread);
Expand Down
1 change: 1 addition & 0 deletions examples/fabric-bridge-app/linux/with_pw_rpc.gni
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,4 @@ pw_build_LINK_DEPS = [
]

chip_use_pw_logging = true
bridge_enable_pw_rpc = true

0 comments on commit 9631848

Please sign in to comment.