diff --git a/C/monitorExample/main.c b/C/monitorExample/main.c new file mode 100644 index 0000000..fc06679 --- /dev/null +++ b/C/monitorExample/main.c @@ -0,0 +1,102 @@ +// Copyright (c) 2013-2015 United States Government as represented by the Administrator of the +// National Aeronautics and Space Administration. All Rights Reserved. +// +// DISCLAIMERS +// No Warranty: THE SUBJECT SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY OF ANY KIND, +// EITHER EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, ANY WARRANTY THAT +// THE SUBJECT SOFTWARE WILL CONFORM TO SPECIFICATIONS, ANY IMPLIED WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR FREEDOM FROM INFRINGEMENT, ANY WARRANTY +// THAT THE SUBJECT SOFTWARE WILL BE ERROR FREE, OR ANY WARRANTY THAT DOCUMENTATION, IF PROVIDED, +// WILL CONFORM TO THE SUBJECT SOFTWARE. THIS AGREEMENT DOES NOT, IN ANY MANNER, CONSTITUTE AN +// ENDORSEMENT BY GOVERNMENT AGENCY OR ANY PRIOR RECIPIENT OF ANY RESULTS, RESULTING DESIGNS, +// HARDWARE, SOFTWARE PRODUCTS OR ANY OTHER APPLICATIONS RESULTING FROM USE OF THE SUBJECT +// SOFTWARE. FURTHER, GOVERNMENT AGENCY DISCLAIMS ALL WARRANTIES AND LIABILITIES REGARDING +// THIRD-PARTY SOFTWARE, IF PRESENT IN THE ORIGINAL SOFTWARE, AND DISTRIBUTES IT "AS IS." +// +// Waiver and Indemnity: RECIPIENT AGREES TO WAIVE ANY AND ALL CLAIMS AGAINST THE UNITED STATES +// GOVERNMENT, ITS CONTRACTORS AND SUBCONTRACTORS, AS WELL AS ANY PRIOR RECIPIENT. IF +// RECIPIENT'S USE OF THE SUBJECT SOFTWARE RESULTS IN ANY LIABILITIES, DEMANDS, DAMAGES, EXPENSES +// OR LOSSES ARISING FROM SUCH USE, INCLUDING ANY DAMAGES FROM PRODUCTS BASED ON, OR RESULTING +// FROM, RECIPIENT'S USE OF THE SUBJECT SOFTWARE, RECIPIENT SHALL INDEMNIFY AND HOLD HARMLESS THE +// UNITED STATES GOVERNMENT, ITS CONTRACTORS AND SUBCONTRACTORS, AS WELL AS ANY PRIOR RECIPIENT, +// TO THE EXTENT PERMITTED BY LAW. RECIPIENT'S SOLE REMEDY FOR ANY SUCH MATTER SHALL BE THE +// IMMEDIATE, UNILATERAL TERMINATION OF THIS AGREEMENT. + +#include "../src/xplaneConnect.h" +#include "stdio.h" + +#ifdef WIN32 +HANDLE hStdIn = NULL; +INPUT_RECORD buffer; +int waitForInput() +{ + if (hStdIn == NULL) + { + hStdIn = GetStdHandle(STD_INPUT_HANDLE); + } + FlushConsoleInputBuffer(hStdIn); + DWORD result = WaitForSingleObject(hStdIn, 100); + if (result == WAIT_OBJECT_0) + { + DWORD eventsRead; + PeekConsoleInput(hStdIn, &buffer, 1, &eventsRead); + if (eventsRead > 0) + { + return buffer.EventType == KEY_EVENT; + } + } + return FALSE; +} +#else +int fdstdin = 0; +fd_set fds; +struct timeval tv; +tv.tv_usec = 100 * 1000; + +int waitForInput() +{ + + FD_ZERO(&fds); + FD_SET(fdstdin, &fds); + select(1, &fds, NULL, NULL, &tv); + return FD_ISSET(fdstdin, &fds); +} + +#endif + +int main(void) +{ + + XPCSocket client = openUDP("127.0.0.1"); + const int aircraftNum = 0; + while (1) + { + float posi[7]; + int result = getPOSI(client, posi, aircraftNum); + if (result < 0) // Error in getPOSI + { + break; + } + + float ctrl[7]; + result = getCTRL(client, ctrl, aircraftNum); + if (result < 0) // Error in getCTRL + { + break; + } + + printf("Loc: (%4f, %4f, %4f) Aileron:%2f Elevator:%2f Rudder:%2f\n", + posi[0], posi[1], posi[2], ctrl[1], ctrl[0], ctrl[2]); + + // Check if any key has been pressed and break + if (waitForInput()) + { + break; + } + } + + + printf("\n\nPress Any Key to exit..."); + getchar(); + return 0; +} \ No newline at end of file diff --git a/C/monitorExample/monitorExample.sln b/C/monitorExample/monitorExample.sln new file mode 100644 index 0000000..11435f7 --- /dev/null +++ b/C/monitorExample/monitorExample.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2013 +VisualStudioVersion = 12.0.31101.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "monitorExample", "monitorExample.vcxproj", "{0F45204B-6910-46C7-BECD-273985390F75}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {0F45204B-6910-46C7-BECD-273985390F75}.Debug|Win32.ActiveCfg = Debug|Win32 + {0F45204B-6910-46C7-BECD-273985390F75}.Debug|Win32.Build.0 = Debug|Win32 + {0F45204B-6910-46C7-BECD-273985390F75}.Release|Win32.ActiveCfg = Release|Win32 + {0F45204B-6910-46C7-BECD-273985390F75}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/C/monitorExample/monitorExample.vcxproj b/C/monitorExample/monitorExample.vcxproj new file mode 100644 index 0000000..3be8e30 --- /dev/null +++ b/C/monitorExample/monitorExample.vcxproj @@ -0,0 +1,79 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + {0F45204B-6910-46C7-BECD-273985390F75} + monitorExample + + + + Application + true + v120 + MultiByte + + + Application + false + v120 + true + MultiByte + + + + + + + + + + + + + ../src;$(IncludePath) + + + ../src;$(IncludePath) + + + + Level3 + Disabled + true + _CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + + + true + + + + + Level3 + MaxSpeed + true + true + true + + + true + true + true + + + + + + + + + + \ No newline at end of file diff --git a/C/monitorExample/monitorExample.vcxproj.filters b/C/monitorExample/monitorExample.vcxproj.filters new file mode 100644 index 0000000..50a53c3 --- /dev/null +++ b/C/monitorExample/monitorExample.vcxproj.filters @@ -0,0 +1,25 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + Source Files + + + \ No newline at end of file diff --git a/Java/Examples/ContinuousOperation/.idea/.name b/Java/Examples/ContinuousOperation/.idea/.name new file mode 100644 index 0000000..9ac7aa6 --- /dev/null +++ b/Java/Examples/ContinuousOperation/.idea/.name @@ -0,0 +1 @@ +ContinuousOperation \ No newline at end of file diff --git a/Java/Examples/ContinuousOperation/.idea/compiler.xml b/Java/Examples/ContinuousOperation/.idea/compiler.xml new file mode 100644 index 0000000..96cc43e --- /dev/null +++ b/Java/Examples/ContinuousOperation/.idea/compiler.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Java/Examples/ContinuousOperation/.idea/copyright/profiles_settings.xml b/Java/Examples/ContinuousOperation/.idea/copyright/profiles_settings.xml new file mode 100644 index 0000000..e7bedf3 --- /dev/null +++ b/Java/Examples/ContinuousOperation/.idea/copyright/profiles_settings.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/Java/Examples/ContinuousOperation/.idea/libraries/XPlaneConnect.xml b/Java/Examples/ContinuousOperation/.idea/libraries/XPlaneConnect.xml new file mode 100644 index 0000000..da48fd9 --- /dev/null +++ b/Java/Examples/ContinuousOperation/.idea/libraries/XPlaneConnect.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/Java/Examples/ContinuousOperation/.idea/misc.xml b/Java/Examples/ContinuousOperation/.idea/misc.xml new file mode 100644 index 0000000..a61f7bc --- /dev/null +++ b/Java/Examples/ContinuousOperation/.idea/misc.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Java/Examples/ContinuousOperation/.idea/modules.xml b/Java/Examples/ContinuousOperation/.idea/modules.xml new file mode 100644 index 0000000..0a1c2fe --- /dev/null +++ b/Java/Examples/ContinuousOperation/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/Java/Examples/ContinuousOperation/.idea/vcs.xml b/Java/Examples/ContinuousOperation/.idea/vcs.xml new file mode 100644 index 0000000..6564d52 --- /dev/null +++ b/Java/Examples/ContinuousOperation/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Java/Examples/ContinuousOperation/ContinuousOperation.iml b/Java/Examples/ContinuousOperation/ContinuousOperation.iml new file mode 100644 index 0000000..6c4f0ab --- /dev/null +++ b/Java/Examples/ContinuousOperation/ContinuousOperation.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/Java/Examples/ContinuousOperation/libs/XPlaneConnect.jar b/Java/Examples/ContinuousOperation/libs/XPlaneConnect.jar new file mode 100644 index 0000000..eba5283 Binary files /dev/null and b/Java/Examples/ContinuousOperation/libs/XPlaneConnect.jar differ diff --git a/Java/Examples/ContinuousOperation/src/Main.java b/Java/Examples/ContinuousOperation/src/Main.java new file mode 100644 index 0000000..61a14eb --- /dev/null +++ b/Java/Examples/ContinuousOperation/src/Main.java @@ -0,0 +1,47 @@ +package gov.nasa.xpc.ex; + +import gov.nasa.xpc.XPlaneConnect; + +import java.io.IOException; + +/** + * An example program demonstrating the use of X-PlaneConnect in a continuous loop. + * + * @author Jason Watkins + * @version 1.0 + * @since 2015-06-19 + */ +public class Main +{ + public static void main(String[] args) + { + try (XPlaneConnect xpc = new XPlaneConnect()) + { + int aircraft = 0; + while(true) + { + float[] posi = xpc.getPOSI(aircraft); + float[] ctrl = xpc.getCTRL(aircraft); + + System.out.format("Loc: (%4f, %4f, %4f) Aileron:%2f Elevator:%2f Rudder:%2f\n", + posi[0], posi[1], posi[2], ctrl[1], ctrl[0], ctrl[2]); + + try + { + Thread.sleep(100); + } + catch (InterruptedException ex) {} + + if(System.in.available() > 0) + { + break; + } + } + } + catch(IOException ex) + { + System.out.println("Error:"); + System.out.println(ex.getMessage()); + } + } +} diff --git a/MATLAB/MonitorExample/MonitorExample.m b/MATLAB/MonitorExample/MonitorExample.m new file mode 100644 index 0000000..fa42115 --- /dev/null +++ b/MATLAB/MonitorExample/MonitorExample.m @@ -0,0 +1,20 @@ +%% X-Plane Connect MATLAB Example Script +% This script demonstrates how to read and write data to the XPC plugin. +% Before running this script, ensure that the XPC plugin is installed and +% X-Plane is running. +%% Import XPC +clear all; +addpath('../') +import XPlaneConnect.* + +Socket = openUDP(); +while 1 + posi = getPOSI(1, Socket); + ctrl = getCTRL(1, Socket); + + fprintf('Loc: (%4f, %4f, %4f) Aileron:%2f Elevator:%2f Rudder:%2f\n', ... + posi(1), posi(2), posi(3), ctrl(2), ctrl(1), ctrl(3)); + + pause(0.1); +end +closeUDP(Socket); \ No newline at end of file diff --git a/Python/src/monitorExample.py b/Python/src/monitorExample.py new file mode 100644 index 0000000..c4cdb48 --- /dev/null +++ b/Python/src/monitorExample.py @@ -0,0 +1,16 @@ +import sys + +import xpc + +def monitor(): + with xpc.XPlaneConnect() as client: + while True: + posi = client.getPOSI(); + ctrl = client.getCTRL(); + + print "Loc: (%4f, %4f, %4f) Aileron:%2f Elevator:%2f Rudder:%2f\n"\ + % (posi[0], posi[1], posi[2], ctrl[1], ctrl[0], ctrl[2]) + + +if __name__ == "__main__": + monitor() \ No newline at end of file diff --git a/Python/xplaneConnect.pyproj b/Python/xplaneConnect.pyproj index d66fa38..651c96f 100644 --- a/Python/xplaneConnect.pyproj +++ b/Python/xplaneConnect.pyproj @@ -5,7 +5,7 @@ 2.0 3c7a940d-17c8-4e91-882f-9bc8b1d2f54b . - src\playbackExample.py + src\basicExample.py . @@ -25,6 +25,7 @@ + Code