Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delay DSClient start to fix 'Disappearing Chooser problem #186

Closed
wants to merge 6 commits into from
Closed
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
63 changes: 36 additions & 27 deletions src/main/java/edu/wpi/first/smartdashboard/SmartDashboard.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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() {

Expand All @@ -144,7 +119,7 @@ public void run() {
frame.load(file.getPath());
}

monitor.setProgress(1000);
monitor.setProgress(750);

} catch (Exception e) {
e.printStackTrace();
Expand All @@ -157,5 +132,39 @@ public void run() {
ex.printStackTrace();
System.exit(2);
}


if (argParser.hasValue("ip")) {
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 {
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();

teamNumberLoop:
while (teamNumber.equals("0")) {
String input = JOptionPane.showInputDialog("Input Team Number\\Host");
if (input == null) {
break teamNumberLoop;
}
teamNumber = input;
}

monitor.setProgress(850);
monitor.setNote("Connecting to robot: " + teamNumber);
Robot.setHost(teamNumber);
teamProp.setValue(teamNumber);
monitor.setProgress(1000);
}
}
}
24 changes: 19 additions & 5 deletions src/main/java/edu/wpi/first/smartdashboard/robot/Robot.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
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;
import edu.wpi.first.wpilibj.tables.ITable;
Expand All @@ -21,6 +24,7 @@ public class Robot {
static {
NetworkTable.setClientMode();
NetworkTable.setNetworkIdentity(identity);
NetworkTable.setDSClientEnabled(false);
NetworkTable.initialize();
}

Expand Down Expand Up @@ -63,20 +67,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 final ConcurrentMap<String, ITable> tables = new ConcurrentHashMap<String, ITable>();

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
Expand Down