From 6068a3222b38e81c3319eadca924337be6bb5c37 Mon Sep 17 00:00:00 2001 From: Carl Hauser Date: Tue, 5 Sep 2023 09:53:07 -0700 Subject: [PATCH 1/5] Disable DSClient to fix 'Disappearing Chooser problem --- src/main/java/edu/wpi/first/smartdashboard/robot/Robot.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/edu/wpi/first/smartdashboard/robot/Robot.java b/src/main/java/edu/wpi/first/smartdashboard/robot/Robot.java index f277d25..5a34291 100644 --- a/src/main/java/edu/wpi/first/smartdashboard/robot/Robot.java +++ b/src/main/java/edu/wpi/first/smartdashboard/robot/Robot.java @@ -21,6 +21,7 @@ public class Robot { static { NetworkTable.setClientMode(); NetworkTable.setNetworkIdentity(identity); + NetworkTable.setDSClientEnabled(false); NetworkTable.initialize(); } From 33469b7576fb257484f87ebe8608d098677eaf7c Mon Sep 17 00:00:00 2001 From: Carl Hauser Date: Tue, 5 Sep 2023 11:27:56 -0700 Subject: [PATCH 2/5] Enable DSClient after loading save.xml --- .../first/smartdashboard/SmartDashboard.java | 54 ++++++++++--------- 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/src/main/java/edu/wpi/first/smartdashboard/SmartDashboard.java b/src/main/java/edu/wpi/first/smartdashboard/SmartDashboard.java index 98fe10d..3dd14cb 100644 --- a/src/main/java/edu/wpi/first/smartdashboard/SmartDashboard.java +++ b/src/main/java/edu/wpi/first/smartdashboard/SmartDashboard.java @@ -1,5 +1,6 @@ package edu.wpi.first.smartdashboard; +import edu.wpi.first.wpilibj.networktables.NetworkTable; import edu.wpi.first.networktables.NetworkTablesJNI; import edu.wpi.first.smartdashboard.extensions.FileSniffer; import edu.wpi.first.smartdashboard.gui.DashboardFrame; @@ -101,32 +102,6 @@ public void run() { System.exit(2); } - if (argParser.hasValue("ip")) { - monitor.setProgress(650); - monitor.setNote("Connecting to robot at: " + argParser.getValue("ip")); - Robot.setHost(argParser.getValue("ip")); - System.out.println("IP: " + argParser.getValue("ip")); - } else { - monitor.setProgress(600); - monitor.setNote("Getting Team Number"); - StringProperty teamProp = frame.getPrefs().team; - String teamNumber = teamProp.getValue(); - - teamNumberLoop: - while (teamNumber.equals("0")) { - String input = JOptionPane.showInputDialog("Input Team Number\\Host"); - if (input == null) { - break teamNumberLoop; - } - teamNumber = input; - } - - monitor.setProgress(650); - monitor.setNote("Connecting to robot: " + teamNumber); - Robot.setHost(teamNumber); - teamProp.setValue(teamNumber); - } - try { SwingUtilities.invokeAndWait(new Runnable() { @@ -157,5 +132,32 @@ public void run() { ex.printStackTrace(); System.exit(2); } + + NetworkTable.setDSClientEnabled(true); + if (argParser.hasValue("ip")) { + monitor.setProgress(650); + monitor.setNote("Connecting to robot at: " + argParser.getValue("ip")); + Robot.setHost(argParser.getValue("ip")); + System.out.println("IP: " + argParser.getValue("ip")); + } else { + monitor.setProgress(600); + monitor.setNote("Getting Team Number"); + StringProperty teamProp = frame.getPrefs().team; + String teamNumber = teamProp.getValue(); + + teamNumberLoop: + while (teamNumber.equals("0")) { + String input = JOptionPane.showInputDialog("Input Team Number\\Host"); + if (input == null) { + break teamNumberLoop; + } + teamNumber = input; + } + + monitor.setProgress(650); + monitor.setNote("Connecting to robot: " + teamNumber); + Robot.setHost(teamNumber); + teamProp.setValue(teamNumber); + } } } From 3bb28eeb3cb72f67075bb632e20a131c3dc2ae11 Mon Sep 17 00:00:00 2001 From: Carl Hauser Date: Tue, 5 Sep 2023 12:28:18 -0700 Subject: [PATCH 3/5] Fix formatting errors --- .../first/smartdashboard/SmartDashboard.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/main/java/edu/wpi/first/smartdashboard/SmartDashboard.java b/src/main/java/edu/wpi/first/smartdashboard/SmartDashboard.java index 3dd14cb..e57bddf 100644 --- a/src/main/java/edu/wpi/first/smartdashboard/SmartDashboard.java +++ b/src/main/java/edu/wpi/first/smartdashboard/SmartDashboard.java @@ -119,7 +119,7 @@ public void run() { frame.load(file.getPath()); } - monitor.setProgress(1000); + monitor.setProgress(750); } catch (Exception e) { e.printStackTrace(); @@ -133,14 +133,20 @@ public void run() { System.exit(2); } - NetworkTable.setDSClientEnabled(true); + if (argParser.hasValue("ip")) { - monitor.setProgress(650); + monitor.setProgress(1000); monitor.setNote("Connecting to robot at: " + argParser.getValue("ip")); Robot.setHost(argParser.getValue("ip")); System.out.println("IP: " + argParser.getValue("ip")); } else { - monitor.setProgress(600); + NetworkTable.setDSClientEnabled(true); + try { + Thread.sleep(500); + } catch (InterruptedException e) { + // No harm if the sleep is interrupted + } + monitor.setProgress(800); monitor.setNote("Getting Team Number"); StringProperty teamProp = frame.getPrefs().team; String teamNumber = teamProp.getValue(); @@ -154,10 +160,11 @@ public void run() { teamNumber = input; } - monitor.setProgress(650); + monitor.setProgress(850); monitor.setNote("Connecting to robot: " + teamNumber); Robot.setHost(teamNumber); teamProp.setValue(teamNumber); + monitor.setProgress(1000); } } } From 3f372d5753d901fa8cf766d64e0516bf441166c5 Mon Sep 17 00:00:00 2001 From: Carl Hauser Date: Wed, 6 Sep 2023 14:34:01 -0700 Subject: [PATCH 4/5] Arrange that NetworkTables acquired in Robot.java are unique --- .../wpi/first/smartdashboard/robot/Robot.java | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/main/java/edu/wpi/first/smartdashboard/robot/Robot.java b/src/main/java/edu/wpi/first/smartdashboard/robot/Robot.java index f277d25..396c351 100644 --- a/src/main/java/edu/wpi/first/smartdashboard/robot/Robot.java +++ b/src/main/java/edu/wpi/first/smartdashboard/robot/Robot.java @@ -1,5 +1,7 @@ package edu.wpi.first.smartdashboard.robot; +import java.util.concurrent.ConcurrentHashMap; + import edu.wpi.first.wpilibj.networktables.NetworkTable; import edu.wpi.first.wpilibj.tables.IRemoteConnectionListener; import edu.wpi.first.wpilibj.tables.ITable; @@ -63,20 +65,30 @@ public static void setPort(int port) { NetworkTable.initialize(); } - public static ITable getTable(String tableName) { - return NetworkTable.getTable(tableName); + // NetworkTable.getTable() returns a new table every time it's called. + // We need to make sure there is only one table for each table name. + private static ConcurrentHashMap tables = new ConcurrentHashMap(); + + public static synchronized ITable getTable(String tableName) { + if (tables.containsKey(tableName)) { + return tables.get(tableName); + } else { + ITable newTable = NetworkTable.getTable(tableName); + tables.put(tableName, newTable); + return newTable; + } } public static ITable getTable() { - return NetworkTable.getTable(TABLE_NAME); + return getTable(TABLE_NAME); } public static ITable getPreferences() { - return NetworkTable.getTable(PREFERENCES_NAME); + return getTable(PREFERENCES_NAME); } public static ITable getLiveWindow() { - return NetworkTable.getTable(LIVE_WINDOW_NAME); + return getTable(LIVE_WINDOW_NAME); } public static void addConnectionListener(IRemoteConnectionListener listener, boolean From 409bc81fec327aad72aadc1d4712dccfbbd36fa6 Mon Sep 17 00:00:00 2001 From: Carl Hauser Date: Fri, 8 Sep 2023 19:05:38 -0700 Subject: [PATCH 5/5] Improve unique tables implementation --- src/main/java/edu/wpi/first/smartdashboard/robot/Robot.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/edu/wpi/first/smartdashboard/robot/Robot.java b/src/main/java/edu/wpi/first/smartdashboard/robot/Robot.java index e552fc2..5cd8a90 100644 --- a/src/main/java/edu/wpi/first/smartdashboard/robot/Robot.java +++ b/src/main/java/edu/wpi/first/smartdashboard/robot/Robot.java @@ -1,6 +1,7 @@ package edu.wpi.first.smartdashboard.robot; import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; import edu.wpi.first.wpilibj.networktables.NetworkTable; import edu.wpi.first.wpilibj.tables.IRemoteConnectionListener; @@ -68,7 +69,7 @@ public static void setPort(int port) { // NetworkTable.getTable() returns a new table every time it's called. // We need to make sure there is only one table for each table name. - private static ConcurrentHashMap tables = new ConcurrentHashMap(); + private static final ConcurrentMap tables = new ConcurrentHashMap(); public static synchronized ITable getTable(String tableName) { if (tables.containsKey(tableName)) {