diff options
4 files changed, 48 insertions, 95 deletions
diff --git a/smartdashboard/src/edu/wpi/first/smartdashboard/ArgParser.java b/smartdashboard/src/edu/wpi/first/smartdashboard/ArgParser.java deleted file mode 100644 index c3f2438..0000000 --- a/smartdashboard/src/edu/wpi/first/smartdashboard/ArgParser.java +++ /dev/null @@ -1,53 +0,0 @@ -package edu.wpi.first.smartdashboard;
-
-import java.util.*;
-
-public class ArgParser {
- private Map<String, String> argValues = new HashMap<String, String>();
- private Set<String> flags = new HashSet<String>();
- private final boolean ignoreLeadingDash;
- private final boolean ignoreCase;
- private String getProcessedName(String name){
- if(ignoreLeadingDash && name.startsWith("-"))
- name = name.substring(1);
- if(ignoreCase)
- name = name.toLowerCase();
- return name;
- }
- public ArgParser(String[] args, boolean ignoreLeadingDash, boolean ignoreCase, String[] valueArgs) {
- this.ignoreLeadingDash = ignoreLeadingDash;
- this.ignoreCase = ignoreCase;
-
- if(ignoreLeadingDash){
- for(int i = 0; i<valueArgs.length; ++i)
- valueArgs[i] = getProcessedName(valueArgs[i]);
- }
-
- argLoop: for (int i = 0; i < args.length; i++) {
- String arg = getProcessedName(args[i]);
-
- for (String possibleValueArg : valueArgs) {
- if (possibleValueArg.equals(arg)) {
- if (i < args.length - 1) {
- argValues.put(arg, args[i + 1]);
- ++i;
- } else
- argValues.put(arg, "");
- continue argLoop;
- }
- }
- flags.add(arg);
- }
- }
-
- public boolean hasFlag(String name){
- return flags.contains(getProcessedName(name));
- }
-
- public boolean hasValue(String name){
- return argValues.get(getProcessedName(name))!=null;
- }
- public String getValue(String name){
- return argValues.get(getProcessedName(name));
- }
-}
diff --git a/smartdashboard/src/edu/wpi/first/smartdashboard/gui/DashboardPrefs.java b/smartdashboard/src/edu/wpi/first/smartdashboard/gui/DashboardPrefs.java index 79d0d30..c7ed59a 100644 --- a/smartdashboard/src/edu/wpi/first/smartdashboard/gui/DashboardPrefs.java +++ b/smartdashboard/src/edu/wpi/first/smartdashboard/gui/DashboardPrefs.java @@ -25,6 +25,7 @@ public class DashboardPrefs implements PropertyHolder { private Map<String, Property> properties = new LinkedHashMap<String, Property>(); public final IntegerProperty team = new IntegerProperty(this, "Team Number", 0); + public final BooleanProperty usemDNS = new BooleanProperty(this, "Use mDNS (supported on roboRIO)", true); public final BooleanProperty hideMenu = new BooleanProperty(this, "Hide Menu", false); public final BooleanProperty autoShowWidgets = new BooleanProperty(this, "Automatically Show Widgets", true); public final IntegerListProperty grid_widths = new IntegerListProperty(this, "Grid Cell Width(s)", new int[] { 16 }); @@ -104,6 +105,8 @@ public class DashboardPrefs implements PropertyHolder { } else if (property == team) { Robot.setTeam(team.getValue()); frame.setTitle("SmartDashboard - " + team.getValue()); + } else if (property == usemDNS) { + Robot.setUseMDNS(usemDNS.getValue()); } else if (property == hideMenu) { frame.setShouldHideMenu(hideMenu.getValue()); } else if (property == logToCSV) { diff --git a/smartdashboard/src/edu/wpi/first/smartdashboard/main.java b/smartdashboard/src/edu/wpi/first/smartdashboard/main.java index 1bf0b8e..38582ff 100644 --- a/smartdashboard/src/edu/wpi/first/smartdashboard/main.java +++ b/smartdashboard/src/edu/wpi/first/smartdashboard/main.java @@ -63,15 +63,6 @@ public class main { // Search the filesystem for extensions (49%) FileSniffer.findExtensions(monitor, 0, 490); - - - ArgParser argParser = new ArgParser(args, true, true, new String[] { "ip" }); - inCompetition = argParser.hasFlag("competition"); - - - - - // Initialize GUI try { SwingUtilities.invokeAndWait(new Runnable() { @@ -82,38 +73,24 @@ public class main { ex.printStackTrace(); System.exit(2); } - - - - + IntegerProperty teamProp = frame.getPrefs().team; - if (argParser.hasValue("ip")) { - monitor.setProgress(650); - monitor.setNote("Connecting to robot at: "+argParser.getValue("ip")); - Robot.setHost(argParser.getValue("ip")); - } - else{ - monitor.setProgress(600); - monitor.setNote("Getting Team Number"); - int teamNumber = teamProp.getValue(); - teamNumberLoop: while (teamNumber <= 0) { - try{ - String input = JOptionPane.showInputDialog("Input Team Number"); - if(input==null){ - teamNumber = 0; - break teamNumberLoop; - } - teamNumber = Integer.parseInt(input); - } catch(Exception e){} - } - monitor.setProgress(650); - monitor.setNote("Connecting to robot of team: "+teamNumber); - teamProp.setValue(teamNumber); + monitor.setProgress(600); + monitor.setNote("Getting Team Number"); + int teamNumber = teamProp.getValue(); + teamNumberLoop: while (teamNumber <= 0) { + try{ + String input = JOptionPane.showInputDialog("Input Team Number"); + if(input==null){ + teamNumber = 0; + break teamNumberLoop; + } + teamNumber = Integer.parseInt(input); + } catch(Exception e){} } - - - - + monitor.setProgress(650); + monitor.setNote("Connecting to robot of team: "+teamNumber); + teamProp.setValue(teamNumber); try { SwingUtilities.invokeAndWait(new Runnable() { diff --git a/smartdashboard/src/edu/wpi/first/smartdashboard/robot/Robot.java b/smartdashboard/src/edu/wpi/first/smartdashboard/robot/Robot.java index 8db77a2..aa6173f 100644 --- a/smartdashboard/src/edu/wpi/first/smartdashboard/robot/Robot.java +++ b/smartdashboard/src/edu/wpi/first/smartdashboard/robot/Robot.java @@ -17,10 +17,11 @@ public class Robot { public static final String TABLE_NAME = "SmartDashboard"; public static final String LIVE_WINDOW_NAME = "LiveWindow"; public static final String PREFERENCES_NAME = "Preferences"; - private static volatile String _host = null; private static volatile int _port = NetworkTable.DEFAULT_PORT; + private static int _team; + private static boolean _usemDNS = true; private static final IOStreamFactory configurableFactory = new IOStreamFactory() { @Override public IOStream createStream() throws IOException { @@ -36,13 +37,38 @@ public class Robot { } public static void setTeam(int team) { - setHost("10." + (team / 100) + "." + (team % 100) + ".2"); + _team = team; + setHost(); + } + + /** + * Switch between using MDNS and a static IP to resolve the robot's + * hostname (mDNS is only supported on the roboRIO) + * @param useMDNS + */ + public static void setUseMDNS(boolean usemDNS) { + _usemDNS = usemDNS; + setHost(); } - public static void setHost(String host){ + + public static void setHost(){ + String host; + + if(_usemDNS) { + host = "roboRIO-" + _team + ".local"; + } else { + host = "10." + (_team / 100) + "." + (_team % 100) + ".2"; + } + _host = host; System.out.println("Host: "+host); client.close(); } + + public static String getHost() { + return _host; + } + public static void setPort(int port){ _port = port; client.close(); |