mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-04 03:11:43 +00:00
C++ NetworkTable: Provide SetPort() method.
This was previously only available in Java.
This commit is contained in:
@@ -20,6 +20,7 @@ class NetworkTable : public ITable {
|
|||||||
static std::string s_persistent_filename;
|
static std::string s_persistent_filename;
|
||||||
static bool s_client;
|
static bool s_client;
|
||||||
static bool s_running;
|
static bool s_running;
|
||||||
|
static unsigned int s_port;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
NetworkTable(llvm::StringRef path, const private_init&);
|
NetworkTable(llvm::StringRef path, const private_init&);
|
||||||
@@ -63,6 +64,12 @@ class NetworkTable : public ITable {
|
|||||||
*/
|
*/
|
||||||
static void SetIPAddress(llvm::StringRef address);
|
static void SetIPAddress(llvm::StringRef address);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param port the port number that network tables will connect to in client
|
||||||
|
* mode or listen to in server mode
|
||||||
|
*/
|
||||||
|
static void SetPort(unsigned int port);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the persistent filename.
|
* Sets the persistent filename.
|
||||||
* @param filename the filename that the network tables server uses for
|
* @param filename the filename that the network tables server uses for
|
||||||
|
|||||||
@@ -13,13 +13,14 @@ std::string NetworkTable::s_ip_address;
|
|||||||
std::string NetworkTable::s_persistent_filename = "networktables.ini";
|
std::string NetworkTable::s_persistent_filename = "networktables.ini";
|
||||||
bool NetworkTable::s_client = false;
|
bool NetworkTable::s_client = false;
|
||||||
bool NetworkTable::s_running = false;
|
bool NetworkTable::s_running = false;
|
||||||
|
unsigned int NetworkTable::s_port = NT_DEFAULT_PORT;
|
||||||
|
|
||||||
void NetworkTable::Initialize() {
|
void NetworkTable::Initialize() {
|
||||||
if (s_running) Shutdown();
|
if (s_running) Shutdown();
|
||||||
if (s_client)
|
if (s_client)
|
||||||
nt::StartClient(s_ip_address.c_str(), NT_DEFAULT_PORT);
|
nt::StartClient(s_ip_address.c_str(), s_port);
|
||||||
else
|
else
|
||||||
nt::StartServer(s_persistent_filename, "", NT_DEFAULT_PORT);
|
nt::StartServer(s_persistent_filename, "", s_port);
|
||||||
s_running = true;
|
s_running = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,6 +49,8 @@ void NetworkTable::SetTeam(int team) {
|
|||||||
|
|
||||||
void NetworkTable::SetIPAddress(StringRef address) { s_ip_address = address; }
|
void NetworkTable::SetIPAddress(StringRef address) { s_ip_address = address; }
|
||||||
|
|
||||||
|
void NetworkTable::SetPort(unsigned int port) { s_port = port; }
|
||||||
|
|
||||||
void NetworkTable::SetPersistentFilename(StringRef filename) {
|
void NetworkTable::SetPersistentFilename(StringRef filename) {
|
||||||
s_persistent_filename = filename;
|
s_persistent_filename = filename;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user