From dca1b408f270abf5a970f1b4e16328b73d0f5364 Mon Sep 17 00:00:00 2001 From: Doug Wegscheid Date: Tue, 24 Jan 2023 15:10:37 -0500 Subject: [PATCH 1/7] Allow specifying NT server address by ip. Still need to fix the UI! --- .../common/configuration/NetworkConfig.java | 7 ++++--- .../networktables/NetworkTablesManager.java | 21 ++++++++++++++----- .../common/networking/NetworkManager.java | 2 +- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/photon-core/src/main/java/org/photonvision/common/configuration/NetworkConfig.java b/photon-core/src/main/java/org/photonvision/common/configuration/NetworkConfig.java index cae9c92aa8..d6e6706257 100644 --- a/photon-core/src/main/java/org/photonvision/common/configuration/NetworkConfig.java +++ b/photon-core/src/main/java/org/photonvision/common/configuration/NetworkConfig.java @@ -17,6 +17,7 @@ package org.photonvision.common.configuration; +import com.fasterxml.jackson.annotation.JsonAlias; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonGetter; import com.fasterxml.jackson.annotation.JsonIgnore; @@ -30,7 +31,7 @@ import org.photonvision.common.util.file.JacksonUtils; public class NetworkConfig { - public int teamNumber = 0; + public String ntServerAddress = "0"; public NetworkMode connectionType = NetworkMode.DHCP; public String staticIp = ""; public String hostname = "photonvision"; @@ -54,7 +55,7 @@ public NetworkConfig() { @JsonCreator public NetworkConfig( - @JsonProperty("teamNumber") int teamNumber, + @JsonProperty("ntServerAddress") @JsonAlias({"ntServerAddress", "teamNumber"}) String ntServerAddress, @JsonProperty("connectionType") NetworkMode connectionType, @JsonProperty("staticIp") String staticIp, @JsonProperty("hostname") String hostname, @@ -64,7 +65,7 @@ public NetworkConfig( @JsonProperty("physicalInterface") String physicalInterface, @JsonProperty("setStaticCommand") String setStaticCommand, @JsonProperty("setDHCPcommand") String setDHCPcommand) { - this.teamNumber = teamNumber; + this.ntServerAddress = ntServerAddress; this.connectionType = connectionType; this.staticIp = staticIp; this.hostname = hostname; diff --git a/photon-core/src/main/java/org/photonvision/common/dataflow/networktables/NetworkTablesManager.java b/photon-core/src/main/java/org/photonvision/common/dataflow/networktables/NetworkTablesManager.java index fb31adc96e..41efbfb6ff 100644 --- a/photon-core/src/main/java/org/photonvision/common/dataflow/networktables/NetworkTablesManager.java +++ b/photon-core/src/main/java/org/photonvision/common/dataflow/networktables/NetworkTablesManager.java @@ -66,7 +66,12 @@ public void accept(NetworkTableEvent event) { getInstance().broadcastConnectedStatus(); } else if (event.logMessage.message.contains("connected") && System.currentTimeMillis() - lastConnectMessageMillis > 125) { - logger.info("NT Connected!"); + String connectionDescription = "(unknown)"; + var connections = getInstance().ntInstance.getConnections(); + if (connections.length > 0) { + connectionDescription = connections[0].remote_ip + ":" + connections[0].remote_port; + } + logger.info("NT Connected to " + connectionDescription + "!"); hasReportedConnectionFailure = false; lastConnectMessageMillis = System.currentTimeMillis(); ScriptManager.queueEvent(ScriptEventType.kNTConnected); @@ -107,16 +112,22 @@ public void setConfig(NetworkConfig config) { if (config.runNTServer) { setServerMode(); } else { - setClientMode(config.teamNumber); + setClientMode(config.ntServerAddress); } broadcastVersion(); } - private void setClientMode(int teamNumber) { - if (!isRetryingConnection) logger.info("Starting NT Client"); + private void setClientMode(String ntServerAddress) { ntInstance.stopServer(); ntInstance.startClient4("photonvision"); - ntInstance.setServerTeam(teamNumber); + try { + Integer t = Integer.parseInt(ntServerAddress); + if (!isRetryingConnection) logger.info("Starting NT Client, server team is " + t); + ntInstance.setServerTeam(t); + } catch (NumberFormatException e) { + if (!isRetryingConnection) logger.info("Starting NT Client, server IP is \"" + ntServerAddress + "\""); + ntInstance.setServer(ntServerAddress); + } ntInstance.startDSClient(); broadcastVersion(); } diff --git a/photon-core/src/main/java/org/photonvision/common/networking/NetworkManager.java b/photon-core/src/main/java/org/photonvision/common/networking/NetworkManager.java index 505dc33a90..0a76b093c6 100644 --- a/photon-core/src/main/java/org/photonvision/common/networking/NetworkManager.java +++ b/photon-core/src/main/java/org/photonvision/common/networking/NetworkManager.java @@ -46,7 +46,7 @@ public void initialize(boolean shouldManage) { } var config = ConfigManager.getInstance().getConfig().getNetworkConfig(); - logger.info("Setting " + config.connectionType + " with team team " + config.teamNumber); + logger.info("Setting " + config.connectionType + " with team " + config.ntServerAddress); if (Platform.isLinux()) { if (!Platform.isRoot()) { logger.error("Cannot manage hostname without root!"); From 4f084f9fe11587693b9b0138ca824e7dbf39c082 Mon Sep 17 00:00:00 2001 From: Doug Wegscheid Date: Tue, 24 Jan 2023 23:50:09 -0500 Subject: [PATCH 2/7] Get basic UI working for arbitrary NT addresses. Need to get validation working! --- photon-client/src/App.vue | 4 ++-- photon-client/src/store/index.js | 2 +- photon-client/src/views/PipelineView.vue | 2 +- .../src/views/SettingsViews/Networking.vue | 22 +++++++++---------- photon-server/netTest.json | 2 +- 5 files changed, 15 insertions(+), 17 deletions(-) diff --git a/photon-client/src/App.vue b/photon-client/src/App.vue index 99a9416fee..c0cf83c2a0 100644 --- a/photon-client/src/App.vue +++ b/photon-client/src/App.vue @@ -81,7 +81,7 @@ - Team number is {{ $store.state.settings.networkSettings.teamNumber }} + NT server is {{ $store.state.settings.networkSettings.ntServerAddress }} @@ -151,7 +151,7 @@ export default { computed: { needsTeamNumberSet: { get() { - return this.$store.state.settings.networkSettings.teamNumber < 1 + return this.$store.state.settings.networkSettings.ntServerAddress == "" && this.teamNumberDialog && this.$store.state.backendConnected && !this.$route.name.toLowerCase().includes("settings"); } diff --git a/photon-client/src/store/index.js b/photon-client/src/store/index.js index b0e4755695..52e29e524d 100644 --- a/photon-client/src/store/index.js +++ b/photon-client/src/store/index.js @@ -135,7 +135,7 @@ export default new Vuex.Store({ hardwarePlatform: "Unknown", }, networkSettings: { - teamNumber: 0, + ntServerAddress: "", supported: true, // Below options are only configurable if supported is true diff --git a/photon-client/src/views/PipelineView.vue b/photon-client/src/views/PipelineView.vue index a6f7ef4891..910642a1f1 100644 --- a/photon-client/src/views/PipelineView.vue +++ b/photon-client/src/views/PipelineView.vue @@ -475,7 +475,7 @@ export default { }, showNTWarning: { get() { - return (!this.$store.state.ntConnectionInfo.connected || this.$store.state.settings.networkSettings.runNTServer) && this.$store.state.settings.networkSettings.teamNumber > 0 && this.$store.state.backendConnected && !this.hideNTWarning; + return (!this.$store.state.ntConnectionInfo.connected || this.$store.state.settings.networkSettings.runNTServer) && this.$store.state.settings.networkSettings.ntServerAddress != "" && this.$store.state.backendConnected && !this.hideNTWarning; } }, }, diff --git a/photon-client/src/views/SettingsViews/Networking.vue b/photon-client/src/views/SettingsViews/Networking.vue index 38ed868fb4..d03c2b61bf 100644 --- a/photon-client/src/views/SettingsViews/Networking.vue +++ b/photon-client/src/views/SettingsViews/Networking.vue @@ -4,21 +4,21 @@ ref="form" v-model="valid" > - - Team number is unset or invalid. NetworkTables will not be able to connect. + "Team Number or NetworkTablesIP" is unset or invalid. NetworkTables will not be able to connect.