Add FRC Driver Station connection support.

The 2017 FRC Driver Station supports getting the robot IP via a TCP
connection that returns JSON.  Use this to support overriding the
server IP address used for client connections.

Default to using this approach for client connections in the NetworkTable
interfaces.

Add support for setting the server address without stopping and
restarting the client.

SetTeam now also round-robins by default.
This commit is contained in:
Peter Johnson
2016-11-04 16:01:42 -07:00
parent 34acd9d47c
commit 77edf1e103
15 changed files with 538 additions and 66 deletions

View File

@@ -29,6 +29,7 @@ class NetworkTable : public ITable {
static std::vector<std::string> s_ip_addresses;
static std::string s_persistent_filename;
static bool s_client;
static bool s_enable_ds;
static bool s_running;
static unsigned int s_port;
@@ -86,6 +87,12 @@ class NetworkTable : public ITable {
*/
static void SetPort(unsigned int port);
/**
* @param enabled whether to enable the connection to the local DS to get
* the robot IP address (defaults to enabled)
*/
static void SetDSClientEnabled(bool enabled);
/**
* Sets the persistent filename.
* @param filename the filename that the network tables server uses for

View File

@@ -362,6 +362,11 @@ void NT_StartServer(const char* persist_filename, const char* listen_address,
*/
void NT_StopServer(void);
/** Starts Client
* Starts a client. Use NT_SetServer to set the server name and port.
*/
void NT_StartClientNone(void);
/** Starts Client
* Starts a client using the specified server and port
*
@@ -389,6 +394,37 @@ void NT_StartClientMulti(size_t count, const char** server_names,
*/
void NT_StopClient(void);
/** Sets server address for client (without restarting client).
*
* @param server_name server name (UTF-8 string, null terminated)
* @param port port to communicate over
*
*/
void NT_SetServer(const char* server_name, unsigned int port);
/** Sets server addresses for client (without restarting client).
* The client will attempt to connect to each server in round robin fashion.
*
* @param count length of the server_names and ports arrays
* @param server_names array of server names (each a UTF-8 string, null
* terminated)
* @param ports array of ports to communicate over (one for each server)
*
*/
void NT_SetServerMulti(size_t count, const char** server_names,
const unsigned int* ports);
/** Starts requesting server address from Driver Station.
* This connects to the Driver Station running on localhost to obtain the
* server IP address.
*
* @param port server port to use in combination with IP from DS
*/
void NT_StartDSClient(unsigned int port);
/** Stops requesting server address from Driver Station. */
void NT_StopDSClient(void);
/** Stop Rpc Server
* Stops the Rpc server if it is running.
*/

View File

@@ -255,9 +255,14 @@ void SetNetworkIdentity(StringRef name);
void StartServer(StringRef persist_filename, const char* listen_address,
unsigned int port);
void StopServer();
void StartClient();
void StartClient(const char* server_name, unsigned int port);
void StartClient(ArrayRef<std::pair<StringRef, unsigned int>> servers);
void StopClient();
void SetServer(const char* server_name, unsigned int port);
void SetServer(ArrayRef<std::pair<StringRef, unsigned int>> servers);
void StartDSClient(unsigned int port);
void StopDSClient();
void StopRpcServer();
void StopNotifier();
void SetUpdateRate(double interval);