From 6883a6b4f18bd258cda547524aaae0c8b79f0161 Mon Sep 17 00:00:00 2001 From: Thomas Clark Date: Fri, 24 Oct 2014 11:18:06 -0400 Subject: Use mDNS Use mDNS to connect to the robot controller by default, removing the need to specify an IP. mDNS can be disabled in the dashboard preferences for use with the cRIO. Change-Id: I6b46487ce9ddea54ca4ab249d13186402aa61c91 --- .../edu/wpi/first/smartdashboard/ArgParser.java | 53 --------------------- .../first/smartdashboard/gui/DashboardPrefs.java | 3 ++ .../src/edu/wpi/first/smartdashboard/main.java | 55 +++++++--------------- .../edu/wpi/first/smartdashboard/robot/Robot.java | 32 +++++++++++-- 4 files changed, 48 insertions(+), 95 deletions(-) delete mode 100644 smartdashboard/src/edu/wpi/first/smartdashboard/ArgParser.java 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 argValues = new HashMap(); - private Set flags = new HashSet(); - 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 properties = new LinkedHashMap(); 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(); -- cgit v1.2.3-54-g00ecf