summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--smartdashboard/src/edu/wpi/first/smartdashboard/ArgParser.java53
-rw-r--r--smartdashboard/src/edu/wpi/first/smartdashboard/main.java47
-rw-r--r--smartdashboard/src/edu/wpi/first/smartdashboard/robot/Robot.java14
3 files changed, 90 insertions, 24 deletions
diff --git a/smartdashboard/src/edu/wpi/first/smartdashboard/ArgParser.java b/smartdashboard/src/edu/wpi/first/smartdashboard/ArgParser.java
new file mode 100644
index 0000000..787b8c4
--- /dev/null
+++ b/smartdashboard/src/edu/wpi/first/smartdashboard/ArgParser.java
@@ -0,0 +1,53 @@
+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/main.java b/smartdashboard/src/edu/wpi/first/smartdashboard/main.java
index 38582ff..2971495 100644
--- a/smartdashboard/src/edu/wpi/first/smartdashboard/main.java
+++ b/smartdashboard/src/edu/wpi/first/smartdashboard/main.java
@@ -62,6 +62,10 @@ public class main {
// Search the filesystem for extensions (49%)
FileSniffer.findExtensions(monitor, 0, 490);
+
+ // Parse arguments
+ ArgParser argParser = new ArgParser(args, true, true, new String[] { "ip" });
+ inCompetition = argParser.hasFlag("competition");
// Initialize GUI
try {
@@ -74,23 +78,32 @@ public class main {
System.exit(2);
}
- IntegerProperty teamProp = frame.getPrefs().team;
- 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){}
+ 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");
+ IntegerProperty teamProp = frame.getPrefs().team;
+ 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(650);
- monitor.setNote("Connecting to robot of team: "+teamNumber);
- teamProp.setValue(teamNumber);
try {
SwingUtilities.invokeAndWait(new Runnable() {
@@ -123,4 +136,4 @@ public class main {
System.exit(2);
}
}
-} \ No newline at end of file
+}
diff --git a/smartdashboard/src/edu/wpi/first/smartdashboard/robot/Robot.java b/smartdashboard/src/edu/wpi/first/smartdashboard/robot/Robot.java
index aa6173f..d2cf23e 100644
--- a/smartdashboard/src/edu/wpi/first/smartdashboard/robot/Robot.java
+++ b/smartdashboard/src/edu/wpi/first/smartdashboard/robot/Robot.java
@@ -38,7 +38,7 @@ public class Robot {
public static void setTeam(int team) {
_team = team;
- setHost();
+ setHost("");
}
/**
@@ -48,13 +48,13 @@ public class Robot {
*/
public static void setUseMDNS(boolean usemDNS) {
_usemDNS = usemDNS;
- setHost();
+ setHost("");
}
-
- public static void setHost(){
- String host;
-
- if(_usemDNS) {
+
+ public static void setHost(String host) {
+ if (host != "") {
+ // Use the given host
+ } else if (_usemDNS) {
host = "roboRIO-" + _team + ".local";
} else {
host = "10." + (_team / 100) + "." + (_team % 100) + ".2";