Skip to content

Commit

Permalink
Issue project-chip#30486 Add support to set custom RPC port number
Browse files Browse the repository at this point in the history
  • Loading branch information
adis-ikea committed Nov 21, 2023
1 parent a3c5d19 commit bd1ae3e
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 4 deletions.
2 changes: 1 addition & 1 deletion examples/platform/linux/AppMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ int ChipLinuxAppInit(int argc, char * const argv[], OptionSet * customOptions,
}

#if defined(PW_RPC_ENABLED)
rpc::Init();
rpc::Init(LinuxDeviceOptions::GetInstance().rpcServerPort);
ChipLogProgress(NotSpecified, "PW_RPC initialized.");
#endif // defined(PW_RPC_ENABLED)

Expand Down
15 changes: 15 additions & 0 deletions examples/platform/linux/Options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ enum
kCommissionerOption_FabricID = 0x1020,
kTraceTo = 0x1021,
kOptionSimulateNoInternalTime = 0x1022,
#if defined(PW_RPC_ENABLED)
kOptionRpcServerPort = 0x1023,
#endif
};

constexpr unsigned kAppUsageLength = 64;
Expand Down Expand Up @@ -138,6 +141,9 @@ OptionDef sDeviceOptionDefs[] = {
{ "trace-to", kArgumentRequired, kTraceTo },
#endif
{ "simulate-no-internal-time", kNoArgument, kOptionSimulateNoInternalTime },
#if PW_RPC_ENABLED
{ "rpc-server-port", kArgumentRequired, kOptionRpcServerPort },
#endif
{}
};

Expand Down Expand Up @@ -254,6 +260,10 @@ const char * sDeviceOptionHelp =
#endif
" --simulate-no-internal-time\n"
" Time cluster does not use internal platform time\n"
#if PW_RPC_ENABLED
" --rpc-server-port\n"
" Start RPC server on specified port\n"
#endif
"\n";

bool Base64ArgToVector(const char * arg, size_t maxSize, std::vector<uint8_t> & outVector)
Expand Down Expand Up @@ -507,6 +517,11 @@ bool HandleOption(const char * aProgram, OptionSet * aOptions, int aIdentifier,
case kOptionSimulateNoInternalTime:
LinuxDeviceOptions::GetInstance().mSimulateNoInternalTime = true;
break;
#if PW_RPC_ENABLED
case kOptionRpcServerPort:
LinuxDeviceOptions::GetInstance().rpcServerPort = static_cast<uint16_t>(atoi(aValue));
break;
#endif
default:
PrintArgError("%s: INTERNAL ERROR: Unhandled option: %s\n", aProgram, aName);
retval = false;
Expand Down
4 changes: 3 additions & 1 deletion examples/platform/linux/Options.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ struct LinuxDeviceOptions
chip::FabricId commissionerFabricId = chip::kUndefinedFabricId;
std::vector<std::string> traceTo;
bool mSimulateNoInternalTime = false;

#if defined(PW_RPC_ENABLED)
uint16_t rpcServerPort = 33000;
#endif
static LinuxDeviceOptions & GetInstance();
};

Expand Down
4 changes: 3 additions & 1 deletion examples/platform/linux/Rpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <thread>

Expand Down Expand Up @@ -116,9 +117,10 @@ void RunRpcService()
pw::rpc::system_server::Start();
}

int Init()
int Init(uint16_t rpcServerPort)
{
int err = 0;
pw::rpc::system_server::set_socket_port(rpcServerPort);
std::thread rpc_service(RunRpcService);
rpc_service.detach();
return err;
Expand Down
2 changes: 1 addition & 1 deletion examples/platform/linux/Rpc.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
namespace chip {
namespace rpc {

int Init();
int Init(uint16_t rpcServerPort);

} // namespace rpc
} // namespace chip

0 comments on commit bd1ae3e

Please sign in to comment.