From f253c987ae5596f0d294c6ec894b13d89c21812c Mon Sep 17 00:00:00 2001 From: Jason Watkins Date: Mon, 6 Apr 2015 09:56:34 -0700 Subject: [PATCH] Added Java client example. --- .../BasicOperation/.idea/compiler.xml | 22 + .../.idea/copyright/profiles_settings.xml | 3 + .../BasicOperation/.idea/libraries/Java.xml | 9 + Java/Examples/BasicOperation/.idea/misc.xml | 12 + .../Examples/BasicOperation/.idea/modules.xml | 8 + Java/Examples/BasicOperation/.idea/vcs.xml | 6 + .../BasicOperation/.idea/workspace.xml | 396 ++++++++++++++++++ .../BasicOperation/BasicOperation.iml | 12 + Java/Examples/BasicOperation/src/Main.java | 107 +++++ 9 files changed, 575 insertions(+) create mode 100644 Java/Examples/BasicOperation/.idea/compiler.xml create mode 100644 Java/Examples/BasicOperation/.idea/copyright/profiles_settings.xml create mode 100644 Java/Examples/BasicOperation/.idea/libraries/Java.xml create mode 100644 Java/Examples/BasicOperation/.idea/misc.xml create mode 100644 Java/Examples/BasicOperation/.idea/modules.xml create mode 100644 Java/Examples/BasicOperation/.idea/vcs.xml create mode 100644 Java/Examples/BasicOperation/.idea/workspace.xml create mode 100644 Java/Examples/BasicOperation/BasicOperation.iml create mode 100644 Java/Examples/BasicOperation/src/Main.java diff --git a/Java/Examples/BasicOperation/.idea/compiler.xml b/Java/Examples/BasicOperation/.idea/compiler.xml new file mode 100644 index 0000000..96cc43e --- /dev/null +++ b/Java/Examples/BasicOperation/.idea/compiler.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Java/Examples/BasicOperation/.idea/copyright/profiles_settings.xml b/Java/Examples/BasicOperation/.idea/copyright/profiles_settings.xml new file mode 100644 index 0000000..e7bedf3 --- /dev/null +++ b/Java/Examples/BasicOperation/.idea/copyright/profiles_settings.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/Java/Examples/BasicOperation/.idea/libraries/Java.xml b/Java/Examples/BasicOperation/.idea/libraries/Java.xml new file mode 100644 index 0000000..154988b --- /dev/null +++ b/Java/Examples/BasicOperation/.idea/libraries/Java.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/Java/Examples/BasicOperation/.idea/misc.xml b/Java/Examples/BasicOperation/.idea/misc.xml new file mode 100644 index 0000000..5a65e9a --- /dev/null +++ b/Java/Examples/BasicOperation/.idea/misc.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/Java/Examples/BasicOperation/.idea/modules.xml b/Java/Examples/BasicOperation/.idea/modules.xml new file mode 100644 index 0000000..7843b1c --- /dev/null +++ b/Java/Examples/BasicOperation/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/Java/Examples/BasicOperation/.idea/vcs.xml b/Java/Examples/BasicOperation/.idea/vcs.xml new file mode 100644 index 0000000..6564d52 --- /dev/null +++ b/Java/Examples/BasicOperation/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Java/Examples/BasicOperation/.idea/workspace.xml b/Java/Examples/BasicOperation/.idea/workspace.xml new file mode 100644 index 0000000..b37a304 --- /dev/null +++ b/Java/Examples/BasicOperation/.idea/workspace.xml @@ -0,0 +1,396 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1.7 + + + + + + + + BasicOperation + + + + + + + + Java + + + + + + + + \ No newline at end of file diff --git a/Java/Examples/BasicOperation/BasicOperation.iml b/Java/Examples/BasicOperation/BasicOperation.iml new file mode 100644 index 0000000..ab60ab0 --- /dev/null +++ b/Java/Examples/BasicOperation/BasicOperation.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/Java/Examples/BasicOperation/src/Main.java b/Java/Examples/BasicOperation/src/Main.java new file mode 100644 index 0000000..76f8805 --- /dev/null +++ b/Java/Examples/BasicOperation/src/Main.java @@ -0,0 +1,107 @@ +package gov.nasa.xpc.ex; + +import gov.nasa.xpc.XPlaneConnect; + +import java.io.IOException; +import java.net.SocketException; +import java.util.Arrays; + +/** + * An example program demonstrating the basic features of the X-Plane Connect toolbox. + * + * @author Jason Watkins + * @version 1.0 + * @since 2015-04-06 + */ +public class Main +{ + public static void main(String[] args) + { + System.out.println("X-Plane Connect example program"); + System.out.println("Setting up simulation..."); + try(XPlaneConnect xpc = new XPlaneConnect()) + { + System.out.println("Setting inbound port"); + xpc.setCONN(49055); + + System.out.println("Setting player aircraft position"); + float[] posi = new float[] {37.524F, -122.06899F, 2500, 0, 0, 0, 1}; + xpc.sendPOSI(posi); + + System.out.println("Setting another aircraft position"); + posi[0] = 37.52465F; + posi[4] = 20; + xpc.sendPOSI(posi, 1); + + System.out.println("Setting rates"); + float[][] data = new float[3][9]; + for(float[] row : data) + { + Arrays.fill(row, -998); + } + data[0][0] = 18; //Alpha + data[0][1] = 0; + data[0][3] = 0; + + data[1][0] = 3; //Velocity + data[1][1] = 130; + data[1][2] = 130; + data[1][3] = 130; + data[1][4] = 130; + + data[2][0] = 16; //PQR + data[2][1] = 0; + data[2][2] = 0; + data[2][3] = 0; + + xpc.sendDATA(data); + + System.out.println("Setting controls"); + float[] ctrl = new float[4]; + ctrl[3] = 0.8F; + xpc.sendCTRL(ctrl); + + System.out.println("Pausing sim"); + xpc.pauseSim(true); + try { Thread.sleep(5000); } catch (InterruptedException ex) {} + System.out.println("Un-pausing"); + xpc.pauseSim(false); + + //Let sim run for 10 seconds + try { Thread.sleep(10000); } catch (InterruptedException ex) {} + + System.out.println("Stowing landing gear"); + xpc.sendDREF("sim/cockpit/switches/gear_handle_status", 1); + + //Let sim run for 10 seconds + try { Thread.sleep(10000); } catch (InterruptedException ex) {} + + System.out.println("Checking gear and sim status"); + String[] drefs = new String[] + { + "sim/cockpit/switches/gear_handle_status", + "sim/operation/override/override_planepath" + }; + float[][] results = xpc.requestDREFs(drefs); + + if(results[0][0] == 1) + { + System.out.println("Gear stowed."); + } + else + { + System.out.println("Error stowing gear"); + } + System.out.println("Example complete"); + } + catch (SocketException ex) + { + System.out.println("Unable to set up the connection. (Error message was '" + ex.getMessage() + "'.)"); + } + catch (IOException ex) + { + System.out.println("Something went wrong with one of the commands. (Error message was '" + ex.getMessage() + "'.)"); + } + System.out.println("Exiting"); + } +}