From 77763cbc5b9fe4ef822438842985a86d609783e4 Mon Sep 17 00:00:00 2001 From: John Wang Date: Fri, 19 May 2023 10:16:08 +0800 Subject: [PATCH] Support --rpc-port to assign RPC port for examples. --- examples/platform/linux/AppMain.cpp | 1 + examples/platform/linux/CommonRpc.h | 1 + examples/platform/linux/Options.cpp | 8 ++++++++ examples/platform/linux/Options.h | 1 + examples/platform/linux/Rpc.cpp | 8 ++++++++ 5 files changed, 19 insertions(+) diff --git a/examples/platform/linux/AppMain.cpp b/examples/platform/linux/AppMain.cpp index 56b3478a01beec..5f341814b7d991 100644 --- a/examples/platform/linux/AppMain.cpp +++ b/examples/platform/linux/AppMain.cpp @@ -254,6 +254,7 @@ int ChipLinuxAppInit(int argc, char * const argv[], OptionSet * customOptions) } #if defined(PW_RPC_ENABLED) + rpc::SetPort(LinuxDeviceOptions::GetInstance().RpcPort); rpc::Init(); ChipLogProgress(NotSpecified, "PW_RPC initialized."); #endif // defined(PW_RPC_ENABLED) diff --git a/examples/platform/linux/CommonRpc.h b/examples/platform/linux/CommonRpc.h index 85495b2bf8fbaf..2fcd8729ee3f67 100644 --- a/examples/platform/linux/CommonRpc.h +++ b/examples/platform/linux/CommonRpc.h @@ -22,6 +22,7 @@ namespace chip { namespace rpc { int Init(); +int SetPort(uint16_t port); } // namespace rpc } // namespace chip diff --git a/examples/platform/linux/Options.cpp b/examples/platform/linux/Options.cpp index f0ef28de64b7a5..aaccddb28cb016 100644 --- a/examples/platform/linux/Options.cpp +++ b/examples/platform/linux/Options.cpp @@ -74,6 +74,7 @@ enum kDeviceOption_TestEventTriggerEnableKey = 0x101f, kCommissionerOption_FabricID = 0x1020, kDeviceOption_StorageSpace = 0x1021, + kDeviceOption_RpcPort = 0x1022, }; constexpr unsigned kAppUsageLength = 64; @@ -104,6 +105,7 @@ OptionDef sDeviceOptionDefs[] = { { "command", kArgumentRequired, kDeviceOption_Command }, { "PICS", kArgumentRequired, kDeviceOption_PICS }, { "storage-space", kArgumentRequired, kDeviceOption_StorageSpace }, + { "rpc-port", kArgumentRequired, kDeviceOption_RpcPort }, { "KVS", kArgumentRequired, kDeviceOption_KVS }, { "interface-id", kArgumentRequired, kDeviceOption_InterfaceId }, #if CHIP_CONFIG_TRANSPORT_TRACE_ENABLED @@ -197,6 +199,8 @@ const char * sDeviceOptionHelp = "\n" " --storage-space \n" " A folder to store factory data, configs, counters\n" + " --rpc-port \n" + " A 16-bit unsigned integer specifying the port to use for rpc communication (default is 33000).\n" "\n" " --KVS \n" " A file to store Key Value Store items.\n" @@ -410,6 +414,10 @@ bool HandleOption(const char * aProgram, OptionSet * aOptions, int aIdentifier, LinuxDeviceOptions::GetInstance().StorageSpace = aValue; break; + case kDeviceOption_RpcPort: + LinuxDeviceOptions::GetInstance().RpcPort = static_cast(atoi(aValue)); + break; + case kDeviceOption_KVS: LinuxDeviceOptions::GetInstance().KVS = aValue; break; diff --git a/examples/platform/linux/Options.h b/examples/platform/linux/Options.h index 58733cc2b90dcd..e8a0a226175c7f 100644 --- a/examples/platform/linux/Options.h +++ b/examples/platform/linux/Options.h @@ -45,6 +45,7 @@ struct LinuxDeviceOptions chip::Optional> spake2pSalt; uint32_t spake2pIterations = 0; // When not provided (0), will default elsewhere uint32_t mBleDevice = 0; + uint16_t RpcPort = 33000; bool mWiFi = false; bool mThread = false; uint32_t securedDevicePort = CHIP_PORT; diff --git a/examples/platform/linux/Rpc.cpp b/examples/platform/linux/Rpc.cpp index 5a731fbc1e511a..8104ebf2608900 100644 --- a/examples/platform/linux/Rpc.cpp +++ b/examples/platform/linux/Rpc.cpp @@ -18,6 +18,7 @@ #include "pw_rpc/server.h" #include "pw_rpc_system_server/rpc_server.h" +#include "pw_rpc_system_server/socket.h" #include @@ -124,5 +125,12 @@ int Init() return err; } +int SetPort(uint16_t port) +{ + int err = 0; + pw::rpc::system_server::set_socket_port(port); + return err; +} + } // namespace rpc } // namespace chip