Skip to content

Commit

Permalink
Pre-1.1: Optimizations/cleanup (FINAL)
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-lindau committed Jul 7, 2017
1 parent da8fd45 commit 637e3eb
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 64 deletions.
73 changes: 40 additions & 33 deletions SmartInterface/.idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified SmartInterface/out/production/SmartInterface/Client.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
43 changes: 30 additions & 13 deletions SmartInterface/src/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,18 @@ class Client extends Thread {
// Output stream
private PrintWriter output;

// Buffers for combined analog flight control values
private int aileron, elevator, rudder, tiller;

// Constructor
Client(String address, int port) {
try {
this.socket = new Socket(address, port);
this.input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
this.output = new PrintWriter(socket.getOutputStream(), true);
} catch (IOException ioe) {
String error = "Error connecting to PSX! Please ensure that a PSX" +
" server is running and that port 10747 is unrestricted.";
String error = "Error connecting to PSX! Please ensure that a PSX server " +
"is running and that port 10747 is unrestricted.";
JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),
error, "PSX SmartInterface Error",
JOptionPane.ERROR_MESSAGE);
Expand All @@ -39,24 +42,39 @@ class Client extends Thread {
public void run() {
try {
while(true) {
System.out.print("x");
SmartInterface.aileron = SmartInterface.combineAnalog(SmartInterface.aileronCpt, SmartInterface.aileronFo);
SmartInterface.elevator = SmartInterface.combineAnalog(SmartInterface.elevatorCpt, SmartInterface.elevatorFo);
SmartInterface.rudder = SmartInterface.combineAnalog(SmartInterface.rudderCpt, SmartInterface.rudderFo);
SmartInterface.tiller = SmartInterface.combineAnalog(SmartInterface.tillerCpt, SmartInterface.tillerFo);
//* Update combined analog flight controls
aileron = SmartInterface.combineAnalog(SmartInterface.aileronCpt,
SmartInterface.aileronFo);
elevator = SmartInterface.combineAnalog(SmartInterface.elevatorCpt,
SmartInterface.elevatorFo);
rudder = SmartInterface.combineAnalog(SmartInterface.rudderCpt,
SmartInterface.rudderFo);
tiller = SmartInterface.combineAnalog(SmartInterface.tillerCpt,
SmartInterface.tillerFo);
//*

// Receive to prevent PSX buffers filling
receive();

//* Update flight controls
if (SmartInterface.elevatorCpt != null || SmartInterface.elevatorFo != null ||
SmartInterface.aileronCpt != null || SmartInterface.aileronFo != null ||
SmartInterface.rudderCpt != null || SmartInterface.rudderFo != null)
send("Qs120=" + Integer.toString(SmartInterface.elevator) + ";" +
Integer.toString(SmartInterface.aileron) + ";" + Integer.toString(SmartInterface.rudder));
// Update tiller
send("Qs120=" + Integer.toString(elevator) + ";" + Integer.toString(aileron)
+ ";" + Integer.toString(rudder));
//*

//* Update tiller
if (SmartInterface.tillerCpt != null || SmartInterface.tillerFo != null)
send("Qh426=" + Integer.toString(SmartInterface.tiller));
send("Qh426=" + Integer.toString(tiller));
//*

// Delay to prevent network flooding
sleep(20);
}
} catch(Exception e) {

JOptionPane.showMessageDialog(JOptionPane.getRootFrame(), e.getMessage(),
"Error", JOptionPane.ERROR_MESSAGE);
}
}

Expand All @@ -65,7 +83,6 @@ void destroyConnection() {
try {
this.socket.close();
} catch (Exception e) {
System.out.println("Error detected while closing socket. Exiting!");
System.exit(1);
}

Expand Down
Loading

0 comments on commit 637e3eb

Please sign in to comment.