mirror of
https://github.com/Team4388/WPILib-Network-Tables-RoboPipe.git
synced 2026-06-09 00:38:01 -06:00
Minor IO Changes in Preparation for Public Release
This commit is contained in:
@@ -24,7 +24,7 @@ import edu.wpi.first.networktables.NetworkTableInstance;
|
|||||||
public class App {
|
public class App {
|
||||||
|
|
||||||
/// TODO: Always remember to set to false before building
|
/// TODO: Always remember to set to false before building
|
||||||
static boolean isEclipse = true;
|
static boolean isEclipse = false;
|
||||||
|
|
||||||
String[] robotValues;
|
String[] robotValues;
|
||||||
List<NetworkTableEntry> tableEntrys = new ArrayList<NetworkTableEntry>();
|
List<NetworkTableEntry> tableEntrys = new ArrayList<NetworkTableEntry>();
|
||||||
@@ -39,6 +39,7 @@ public class App {
|
|||||||
static boolean EXIT = false;
|
static boolean EXIT = false;
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
if (!isEclipse) {
|
||||||
// Thanks to Frezze98 bolalo on StackOverflow for the code to create a batch file
|
// Thanks to Frezze98 bolalo on StackOverflow for the code to create a batch file
|
||||||
// to start the program in a command window
|
// to start the program in a command window
|
||||||
Console console = System.console();
|
Console console = System.console();
|
||||||
@@ -64,7 +65,12 @@ public class App {
|
|||||||
while (!EXIT) {
|
while (!EXIT) {
|
||||||
new App().run();
|
new App().run();
|
||||||
}
|
}
|
||||||
EXIT = true;
|
}
|
||||||
|
} else {
|
||||||
|
System.out.println("Robopipe Start");
|
||||||
|
while (!EXIT) {
|
||||||
|
new App().run();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,17 +78,17 @@ public class App {
|
|||||||
try {
|
try {
|
||||||
NetworkTableInstance inst = NetworkTableInstance.getDefault();
|
NetworkTableInstance inst = NetworkTableInstance.getDefault();
|
||||||
NetworkTable table = inst.getTable("/SmartDashboard");
|
NetworkTable table = inst.getTable("/SmartDashboard");
|
||||||
System.out.println("Connecting to Unity local server...");
|
System.out.println("Connecting to local server on port " + PORT_NUMBER + "...");
|
||||||
//serverSocket = new ServerSocket(portNumber);
|
//serverSocket = new ServerSocket(portNumber);
|
||||||
clientSocket = new Socket("127.0.0.1", PORT_NUMBER);
|
clientSocket = new Socket("127.0.0.1", PORT_NUMBER);
|
||||||
os = clientSocket.getOutputStream();
|
os = clientSocket.getOutputStream();
|
||||||
in = clientSocket.getInputStream();
|
in = clientSocket.getInputStream();
|
||||||
System.out.println("Connected");
|
System.out.println("Connected, waiting for request...");
|
||||||
byte[] byteRequest = new byte[100];
|
byte[] byteRequest = new byte[1000];
|
||||||
in.read(byteRequest);
|
in.read(byteRequest);
|
||||||
String request = new String(byteRequest, StandardCharsets.UTF_8);
|
String request = new String(byteRequest, StandardCharsets.UTF_8);
|
||||||
robotValues = request.split(",");
|
robotValues = request.split(",");
|
||||||
System.out.println("Request Recieved: " + request + robotValues.length);
|
System.out.println("Request Recieved: " + request + " Length: " + robotValues.length);
|
||||||
for (String value : robotValues) {
|
for (String value : robotValues) {
|
||||||
tableEntrys.add(table.getEntry(value.trim()));
|
tableEntrys.add(table.getEntry(value.trim()));
|
||||||
}
|
}
|
||||||
@@ -90,26 +96,25 @@ public class App {
|
|||||||
inst.startDSClient();
|
inst.startDSClient();
|
||||||
|
|
||||||
while (!EXIT) {
|
while (!EXIT) {
|
||||||
toUnity();
|
toClient();
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void toUnity() throws IOException {
|
private void toClient() throws IOException {
|
||||||
output = "";
|
output = "";
|
||||||
for (NetworkTableEntry entry : tableEntrys) {
|
for (NetworkTableEntry entry : tableEntrys) {
|
||||||
output += round(entry.getDouble(0), 5);
|
output += round(entry.getDouble(0), 5);
|
||||||
output += "|";
|
output += ",";
|
||||||
System.out.println("'" + entry.getName() + "'");
|
System.out.println("'" + entry.getName() + "'");
|
||||||
}
|
}
|
||||||
|
|
||||||
output = output.substring(0, output.length() - 1);
|
output = output.substring(0, output.length() - 1);
|
||||||
byte[] byteOutput = output.getBytes(StandardCharsets.UTF_8);
|
byte[] byteOutput = output.getBytes(StandardCharsets.UTF_8);
|
||||||
System.out.println("Sending '" + output + "' of length: " + byteOutput.length + " to Unity...");
|
System.out.println("Sending '" + output + "' of length: " + byteOutput.length + " to local port...");
|
||||||
os.write(byteOutput);
|
os.write(byteOutput);
|
||||||
|
|
||||||
System.out.println("Waiting for Response...");
|
System.out.println("Waiting for Response...");
|
||||||
byte[] byteInput = new byte[4];
|
byte[] byteInput = new byte[4];
|
||||||
in.read(byteInput);
|
in.read(byteInput);
|
||||||
|
|||||||
Reference in New Issue
Block a user