From 9631848953181f1e047f04a1f4e8df889a780ce9 Mon Sep 17 00:00:00 2001 From: Yufeng Wang Date: Fri, 24 May 2024 21:54:33 -0700 Subject: [PATCH] Add bridge_enable_pw_rpc build flag --- examples/fabric-admin/BUILD.gn | 6 +- .../commands/fabric-sync/FabricSyncCommand.h | 2 +- examples/fabric-admin/rpc/RpcServer.cpp | 2 +- examples/fabric-bridge-app/linux/BUILD.gn | 76 +++++++++++-------- examples/fabric-bridge-app/linux/main.cpp | 6 ++ .../fabric-bridge-app/linux/with_pw_rpc.gni | 1 + 6 files changed, 55 insertions(+), 38 deletions(-) diff --git a/examples/fabric-admin/BUILD.gn b/examples/fabric-admin/BUILD.gn index c8a95a3c3925be..ecc218688a7db5 100644 --- a/examples/fabric-admin/BUILD.gn +++ b/examples/fabric-admin/BUILD.gn @@ -45,6 +45,8 @@ config("config") { defines += [ "CONFIG_USE_LOCAL_STORAGE" ] } + cflags = [ "-Wconversion" ] + if (chip_enable_pw_rpc) { defines += [ "PW_RPC_ENABLED" ] } @@ -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) { diff --git a/examples/fabric-admin/commands/fabric-sync/FabricSyncCommand.h b/examples/fabric-admin/commands/fabric-sync/FabricSyncCommand.h index 3b57e891db7723..cf739ccfb3a520 100644 --- a/examples/fabric-admin/commands/fabric-sync/FabricSyncCommand.h +++ b/examples/fabric-admin/commands/fabric-sync/FabricSyncCommand.h @@ -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; diff --git a/examples/fabric-admin/rpc/RpcServer.cpp b/examples/fabric-admin/rpc/RpcServer.cpp index ed3e6b0d59e077..769d430786199a 100644 --- a/examples/fabric-admin/rpc/RpcServer.cpp +++ b/examples/fabric-admin/rpc/RpcServer.cpp @@ -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(); diff --git a/examples/fabric-bridge-app/linux/BUILD.gn b/examples/fabric-bridge-app/linux/BUILD.gn index 60617f2c3b6728..eb9707b9715ce4 100644 --- a/examples/fabric-bridge-app/linux/BUILD.gn +++ b/examples/fabric-bridge-app/linux/BUILD.gn @@ -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", ] @@ -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 } diff --git a/examples/fabric-bridge-app/linux/main.cpp b/examples/fabric-bridge-app/linux/main.cpp index 7ac1e2b5052c50..5a1cefcfbffedd 100644 --- a/examples/fabric-bridge-app/linux/main.cpp +++ b/examples/fabric-bridge-app/linux/main.cpp @@ -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 #include @@ -88,6 +90,7 @@ void BridgePollingThread() ChipLogProgress(NotSpecified, "Exiting....."); exit(0); } +#if defined(PW_RPC_FABRIC_BRIDGE_SERVICE) else if (ch == 'o') { if (OpenCommissioningWindow(0x1234) != CHIP_NO_ERROR) @@ -95,6 +98,7 @@ void BridgePollingThread() ChipLogError(NotSpecified, "Failed to call OpenCommissioningWindow RPC"); } } +#endif continue; } @@ -295,6 +299,7 @@ void ApplicationInit() static_cast(emberAfEndpointFromIndex(static_cast(emberAfFixedEndpointCount() - 1))) + 1); gCurrentEndpointId = gFirstDynamicEndpointId; +#if defined(PW_RPC_FABRIC_BRIDGE_SERVICE) InitRpcServer(kFabricBridgeServerPort); while (true) @@ -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); diff --git a/examples/fabric-bridge-app/linux/with_pw_rpc.gni b/examples/fabric-bridge-app/linux/with_pw_rpc.gni index 054640f9ddae61..e1bd567cf22db2 100644 --- a/examples/fabric-bridge-app/linux/with_pw_rpc.gni +++ b/examples/fabric-bridge-app/linux/with_pw_rpc.gni @@ -39,3 +39,4 @@ pw_build_LINK_DEPS = [ ] chip_use_pw_logging = true +bridge_enable_pw_rpc = true