summaryrefslogtreecommitdiff
path: root/smartdashboard/src/edu/wpi/first/smartdashboard/robot/Robot.java
diff options
context:
space:
mode:
Diffstat (limited to 'smartdashboard/src/edu/wpi/first/smartdashboard/robot/Robot.java')
-rw-r--r--smartdashboard/src/edu/wpi/first/smartdashboard/robot/Robot.java49
1 files changed, 26 insertions, 23 deletions
diff --git a/smartdashboard/src/edu/wpi/first/smartdashboard/robot/Robot.java b/smartdashboard/src/edu/wpi/first/smartdashboard/robot/Robot.java
index 3d2a6c8..cb7a67b 100644
--- a/smartdashboard/src/edu/wpi/first/smartdashboard/robot/Robot.java
+++ b/smartdashboard/src/edu/wpi/first/smartdashboard/robot/Robot.java
@@ -3,8 +3,6 @@ package edu.wpi.first.smartdashboard.robot;
import java.io.*;
import edu.wpi.first.wpilibj.networktables.*;
-import edu.wpi.first.wpilibj.networktables2.client.*;
-import edu.wpi.first.wpilibj.networktables2.stream.*;
import edu.wpi.first.wpilibj.tables.*;
/**
@@ -17,23 +15,14 @@ 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";
+ public static final String identity = "SmartDashboard";
- private static volatile String _host = null;
+ private static volatile String _host = "";
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 {
- if(_host==null)
- return null;
- return new SocketStream(_host, _port);
- }
- };
- public static final NetworkTableClient client = new NetworkTableClient(configurableFactory);
- private static final NetworkTableProvider provider = new NetworkTableProvider(client);
static{
- NetworkTable.setTableProvider(provider);
+ NetworkTable.setClientMode();
}
public static void setTeam(int team) {
@@ -59,10 +48,16 @@ public class Robot {
} else {
host = "10." + (_team / 100) + "." + (_team % 100) + ".2";
}
-
+ if (_host.equals(host)) return;
_host = host;
System.out.println("Host: "+host);
- client.close();
+ try {
+ NetworkTable.shutdown();
+ } catch (IllegalStateException ex) {
+ }
+ NetworkTable.setIPAddress(host);
+ NetworkTable.setNetworkIdentity(identity);
+ NetworkTable.initialize();
}
public static String getHost() {
@@ -70,30 +65,38 @@ public class Robot {
}
public static void setPort(int port){
+ if (_port == port) return;
_port = port;
- client.close();
+ try {
+ NetworkTable.shutdown();
+ } catch (IllegalStateException ex) {
+ }
+ NetworkTable.setPort(port);
+ NetworkTable.initialize();
}
public static ITable getTable(String tableName) {
- return provider.getRootTable().getSubTable(tableName);
+ return NetworkTable.getTable(tableName);
}
public static ITable getTable() {
- return provider.getRootTable().getSubTable(TABLE_NAME);
+ return NetworkTable.getTable(TABLE_NAME);
}
public static ITable getPreferences() {
- return provider.getRootTable().getSubTable(PREFERENCES_NAME);
+ return NetworkTable.getTable(PREFERENCES_NAME);
}
public static ITable getLiveWindow() {
- return provider.getRootTable().getSubTable(LIVE_WINDOW_NAME);
+ return NetworkTable.getTable(LIVE_WINDOW_NAME);
}
public static void addConnectionListener(IRemoteConnectionListener listener, boolean immediateNotify) {
- client.addConnectionListener(listener, immediateNotify);
+ System.out.println("Adding connection listener");
+ NetworkTable.getTable(TABLE_NAME).addConnectionListener(listener, immediateNotify);
}
public static void removeConnectionListener(IRemoteConnectionListener listener) {
- client.removeConnectionListener(listener);
+ System.out.println("Removing connection listener");
+ NetworkTable.getTable(TABLE_NAME).removeConnectionListener(listener);
}
}