Skip to content
Open
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
25 changes: 24 additions & 1 deletion ntcore/src/generate/main/java/NetworkTableInstance.java.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -1028,6 +1028,30 @@ public final class NetworkTableInstance implements AutoCloseable {
NetworkTablesJNI.setServerTeam(m_handle, team, port);
}

/**
* Sets server addresses and port for client (without restarting client). Connects using commonly
* known robot addresses for the specified team, and an extra address. Changes the port to the
* default port.
*
* @param team team number
* @param extraAddress extra server address
*/
public void setServerTeamExtra(int team, String extraAddress) {
setServerTeamExtra(team, extraAddress, 0);
}

/**
* Sets server addresses and port for client (without restarting client). Connects using commonly
* known robot addresses for the specified team, and an extra address.
*
* @param team team number
* @param extraAddress extra server address
* @param port port to communicate over (0=default)
*/
public void setServerTeamExtra(int team, String extraAddress, int port) {
NetworkTablesJNI.setServerTeamExtra(m_handle, team, extraAddress, port);
}

/**
* Disconnects the client if it's running and connected. This will automatically start
* reconnection attempts to the current server list.
Expand Down Expand Up @@ -1268,4 +1292,3 @@ public final class NetworkTableInstance implements AutoCloseable {
private int m_handle;
private final ConcurrentMap<String, RawPublisher> m_schemas = new ConcurrentHashMap<>();
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the generated file check doesn't like the removal of EOL at EOF

12 changes: 11 additions & 1 deletion ntcore/src/generate/main/java/NetworkTablesJNI.java.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,17 @@ public final class NetworkTablesJNI {
*/
public static native void setServerTeam(int inst, int team, int port);

/**
* Sets server address and port for client (without restarting client). Connects using commonly
* known robot addresses for the specified team, with an extra address added to the list.
*
* @param inst NT instance handle.
* @param team team number
* @param extraAddress extra server address to add
* @param port port to communicate over
*/
public static native void setServerTeamExtra(int inst, int team, String extraAddress, int port);

/**
* Disconnects the client if it's running and connected. This will automatically start
* reconnection attempts to the current server list.
Expand Down Expand Up @@ -1088,4 +1099,3 @@ public final class NetworkTablesJNI {
/** Utility class. */
private NetworkTablesJNI() {}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions ntcore/src/main/native/cpp/jni/NetworkTablesJNI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1322,6 +1322,18 @@ Java_edu_wpi_first_networktables_NetworkTablesJNI_setServerTeam
nt::SetServerTeam(inst, team, port);
}

/*
* Class: edu_wpi_first_networktables_NetworkTablesJNI
* Method: setServerTeamExtra
* Signature: (IILjava/lang/String;I)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_networktables_NetworkTablesJNI_setServerTeamExtra
(JNIEnv* env, jclass, jint inst, jint team, jstring extraAddress, jint port)
{
nt::SetServerTeamExtra(inst, team, JStringRef{env, extraAddress}, port);
}

/*
* Class: edu_wpi_first_networktables_NetworkTablesJNI
* Method: disconnect
Expand Down
6 changes: 6 additions & 0 deletions ntcore/src/main/native/cpp/ntcore_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,12 @@ void NT_SetServerTeam(NT_Inst inst, unsigned int team, unsigned int port) {
nt::SetServerTeam(inst, team, port);
}

void NT_SetServerTeamExtra(NT_Inst inst, unsigned int team,
const struct WPI_String* extraAddress,
unsigned int port) {
nt::SetServerTeamExtra(inst, team, wpi::to_string_view(extraAddress), port);
}

void NT_Disconnect(NT_Inst inst) {
nt::Disconnect(inst);
}
Expand Down
12 changes: 11 additions & 1 deletion ntcore/src/main/native/cpp/ntcore_cpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -682,9 +682,14 @@ void SetServer(
}

void SetServerTeam(NT_Inst inst, unsigned int team, unsigned int port) {
SetServerTeamExtra(inst, team, {}, port);
}

void SetServerTeamExtra(NT_Inst inst, unsigned int team,
std::string_view extraAddress, unsigned int port) {
if (auto ii = InstanceImpl::GetTyped(inst, Handle::kInstance)) {
std::vector<std::pair<std::string, unsigned int>> servers;
servers.reserve(5);
servers.reserve(6);

// 10.te.am.2
servers.emplace_back(fmt::format("10.{}.{}.2", static_cast<int>(team / 100),
Expand All @@ -704,6 +709,11 @@ void SetServerTeam(NT_Inst inst, unsigned int team, unsigned int port) {
servers.emplace_back(fmt::format("roboRIO-{}-FRC.frc-field.local", team),
port);

if (!extraAddress.empty()) {
// robot.local
servers.emplace_back(extraAddress, port);
}

ii->SetServers(servers);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,20 @@ class NetworkTableInstance final {
::nt::SetServerTeam(m_handle, team, port);
}

/**
* Sets server addresses and port for client (without restarting client).
* Connects using commonly known robot addresses for the specified team,
* and an extra address.
*
* @param team team number
* @param extraAddress extra address to connect to
* @param port port to communicate over (0 = default)
*/
void SetServerTeamExtra(unsigned int team, std::string_view extraAddress,
unsigned int port = 0) {
::nt::SetServerTeamExtra(m_handle, team, extraAddress, port);
}

/**
* Disconnects the client if it's running and connected. This will
* automatically start reconnection attempts to the current server list.
Expand Down
14 changes: 14 additions & 0 deletions ntcore/src/main/native/include/ntcore_c.h
Original file line number Diff line number Diff line change
Expand Up @@ -1192,6 +1192,20 @@ void NT_SetServerMulti(NT_Inst inst, size_t count,
*/
void NT_SetServerTeam(NT_Inst inst, unsigned int team, unsigned int port);

/**
* Sets extra server address for client (without restarting client).
* Connects using commonly known robot addresses for the specified team,
* plus an extra address.
*
* @param inst instance handle
* @param team team number
* @param extraAddress extra server address
* @param port port to communicate over
*/
void NT_SetServerTeamExtra(NT_Inst inst, unsigned int team,
const struct WPI_String* extraAddress,
unsigned int port);

/**
* Disconnects the client if it's running and connected. This will automatically
* start reconnection attempts to the current server list.
Expand Down
13 changes: 13 additions & 0 deletions ntcore/src/main/native/include/ntcore_cpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -1126,6 +1126,19 @@ void SetServer(
*/
void SetServerTeam(NT_Inst inst, unsigned int team, unsigned int port);

/**
* Sets server addresses and port for client (without restarting client).
* Connects using commonly known robot addresses for the specified team,
* plus an extra custom address.
*
* @param inst instance handle
* @param team team number
* @param extraAddress extra address to connect to
* @param port port to communicate over
*/
void SetServerTeamExtra(NT_Inst inst, unsigned int team,
std::string_view extraAddress, unsigned int port);

/**
* Disconnects the client if it's running and connected. This will automatically
* start reconnection attempts to the current server list.
Expand Down
1 change: 1 addition & 0 deletions ntcoreffi/src/main/native/symbols.txt
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ NT_SetRaw
NT_SetServer
NT_SetServerMulti
NT_SetServerTeam
NT_SetServerTeamExtra
NT_SetString
NT_SetStringArray
NT_SetTopicCached
Expand Down
Loading