mirror of
https://github.com/Team4388/WPILib-Network-Tables-RoboPipe.git
synced 2026-06-08 16:28:01 -06:00
Do Things
This commit is contained in:
@@ -3,9 +3,13 @@
|
||||
*/
|
||||
package robopipe;
|
||||
|
||||
import java.awt.GraphicsEnvironment;
|
||||
import java.io.Console;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.PrintWriter;
|
||||
import java.math.BigDecimal;
|
||||
import java.net.ServerSocket;
|
||||
import java.net.Socket;
|
||||
@@ -28,18 +32,40 @@ public class App {
|
||||
double encoder, navX;
|
||||
NetworkTableEntry encoderEntry, encoderEntryR, encoderEntryL, navXEntry;
|
||||
ServerSocket serverSocket;
|
||||
int portNumber = 4388;
|
||||
static int PORT_NUMBER = 4388;
|
||||
Socket clientSocket;
|
||||
OutputStream os;
|
||||
InputStream in;
|
||||
static boolean EXIT = false;
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Robopipe Start");
|
||||
while (!EXIT) {
|
||||
new App().run();
|
||||
}
|
||||
EXIT = true;
|
||||
// Thanks to Frezze98 bolalo on StackOverflow for the code to create a batch file
|
||||
// to start the program in a command window
|
||||
Console console = System.console();
|
||||
if(console == null && !GraphicsEnvironment.isHeadless()) {
|
||||
String filename = new File(App.class.getProtectionDomain().getCodeSource().getLocation().getPath()).getName();
|
||||
try {
|
||||
File batch = new File("Launcher.bat");
|
||||
if(!batch.exists()){
|
||||
batch.createNewFile();
|
||||
PrintWriter writer = new PrintWriter(batch);
|
||||
writer.println("@echo off");
|
||||
writer.println("java -jar "+ filename + " " + args[0]);
|
||||
writer.println("exit");
|
||||
writer.flush();
|
||||
}
|
||||
Runtime.getRuntime().exec("cmd /c start \"\" "+batch.getPath());
|
||||
} catch(IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
PORT_NUMBER = Integer.parseInt(args[0]);
|
||||
System.out.println("Robopipe Start");
|
||||
while (!EXIT) {
|
||||
new App().run();
|
||||
}
|
||||
EXIT = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void run() {
|
||||
@@ -48,7 +74,7 @@ public class App {
|
||||
NetworkTable table = inst.getTable("/SmartDashboard");
|
||||
System.out.println("Connecting to Unity local server...");
|
||||
//serverSocket = new ServerSocket(portNumber);
|
||||
clientSocket = new Socket("127.0.0.1", portNumber);
|
||||
clientSocket = new Socket("127.0.0.1", PORT_NUMBER);
|
||||
os = clientSocket.getOutputStream();
|
||||
in = clientSocket.getInputStream();
|
||||
System.out.println("Connected");
|
||||
@@ -74,7 +100,7 @@ public class App {
|
||||
private void toUnity() throws IOException {
|
||||
output = "";
|
||||
for (NetworkTableEntry entry : tableEntrys) {
|
||||
output += round(entry.getDouble(69), 5);
|
||||
output += round(entry.getDouble(0), 5);
|
||||
output += "|";
|
||||
System.out.println("'" + entry.getName() + "'");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user