Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support --rpc-port to assign RPC port for examples. #7

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/platform/linux/AppMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions examples/platform/linux/CommonRpc.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ namespace chip {
namespace rpc {

int Init();
int SetPort(uint16_t port);

} // namespace rpc
} // namespace chip
8 changes: 8 additions & 0 deletions examples/platform/linux/Options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ enum
kDeviceOption_TestEventTriggerEnableKey = 0x101f,
kCommissionerOption_FabricID = 0x1020,
kDeviceOption_StorageSpace = 0x1021,
kDeviceOption_RpcPort = 0x1022,
};

constexpr unsigned kAppUsageLength = 64;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -197,6 +199,8 @@ const char * sDeviceOptionHelp =
"\n"
" --storage-space <dirpath>\n"
" A folder to store factory data, configs, counters\n"
" --rpc-port <port>\n"
" A 16-bit unsigned integer specifying the port to use for rpc communication (default is 33000).\n"
"\n"
" --KVS <filepath>\n"
" A file to store Key Value Store items.\n"
Expand Down Expand Up @@ -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<uint16_t>(atoi(aValue));
break;

case kDeviceOption_KVS:
LinuxDeviceOptions::GetInstance().KVS = aValue;
break;
Expand Down
1 change: 1 addition & 0 deletions examples/platform/linux/Options.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ struct LinuxDeviceOptions
chip::Optional<std::vector<uint8_t>> 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;
Expand Down
8 changes: 8 additions & 0 deletions 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 @@ -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