diff --git a/C/playbackExample/src/chrome.c b/C/playbackExample/src/chrome.c new file mode 100644 index 0000000..652de96 --- /dev/null +++ b/C/playbackExample/src/chrome.c @@ -0,0 +1,71 @@ +//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 "chrome.h" + +#include + +void displayStart(char* version) +{ + printf("X-Plane Connect Playback Example [Version %s]\n", version); + printf("(c) 2013-2015 United States Government as represented by the Administrator\n"); + printf("of the National Aeronautics and Space Administration. All Rights Reserved.\n"); +} + +int displayMenu(char* title, char* opts[], size_t count) +{ + printf("\n"); + printf("+---------------------------------------------- +\n"); + printf("| %-42s |\n", title); + printf("+---------------------------------------------- +\n"); + for (size_t i = 0; i < count; i++) + { + printf("| %2u. %-40s |\n", i + 1, opts[i]); + } + printf("+---------------------------------------------- +\n"); + printf("Please select an option: "); + + int opt; + scanf("%d", &opt); + return opt; +} + +void displayMsg(char* msg) +{ + printf("%s\n", msg); +} + +void getString(char* prompt, char buffer[255]) +{ + printf("%s: ", prompt); + scanf("%255s", buffer); +} + +int getInt(char* prompt) +{ + printf("%s: ", prompt); + int result; + scanf("%d", &result); + return result; +} \ No newline at end of file diff --git a/C/playbackExample/src/chrome.h b/C/playbackExample/src/chrome.h new file mode 100644 index 0000000..d0da842 --- /dev/null +++ b/C/playbackExample/src/chrome.h @@ -0,0 +1,40 @@ +//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. + +#ifndef XPC_PLAYBACKEX_CHROME_H_ +#define XPC_PLAYBACKEX_CHROME_H_ + +#include + +void displayStart(char* version); + +int displayMenu(char* title, char* opts[], size_t count); + +void displayMsg(char* msg); + +void getString(char* prompt, char buffer[255]); + +int getInt(char* prompt); + +#endif \ No newline at end of file diff --git a/C/playbackExample/src/main.c b/C/playbackExample/src/main.c new file mode 100644 index 0000000..c796edd --- /dev/null +++ b/C/playbackExample/src/main.c @@ -0,0 +1,70 @@ +//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 "chrome.h" +#include "playback.h" + +int main(void) +{ + char* mainOpts[3] = + { + "Record X-Plane", + "Playback File", + "Exit" + }; + char path[256] = { 0 }; + + displayStart("1.2.0.0"); + while (1) + { + switch (displayMenu("What would you like to do?", mainOpts, 3)) + { + case 1: + { + getString("Enter save file path", path); + int interval = getInt("Enter interval between frames (milliseconds)"); + int duration = getInt("Enter duration to record for (seconds)"); + + record(path, interval, duration); + break; + } + case 2: + { + getString("Enter path to saved playback file", path); + int interval = getInt("Enter interval between frames (milliseconds)"); + + playback(path, interval); + break; + } + case 3: + displayMsg("Exiting."); + return 0; + default: + displayMsg("Unrecognized option."); + break; + } + } + + return 0; +} \ No newline at end of file diff --git a/C/playbackExample/src/playback.c b/C/playbackExample/src/playback.c new file mode 100644 index 0000000..e2de4e0 --- /dev/null +++ b/C/playbackExample/src/playback.c @@ -0,0 +1,106 @@ +//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 "playback.h" + +#include "chrome.h" + +#include "xplaneConnect.h" + +#include +#include + +#ifdef WIN32 +#include +#else +#include +#endif + +void playbackSleep(int ms) +{ +#ifdef WIN32 + Sleep(ms); +#else + uSleep(ms * 1000); +#endif +} + +void record(char* path, int interval, int duration) +{ + FILE* fd = fopen(path, "w"); + int count = duration * 1000 / interval; + if (!fd) + { + displayMsg("Unable to open output file."); + return; + } + if (count < 1) + { + displayMsg("Duration is less than one iteration."); + return; + } + displayMsg("Recording..."); + + XPCSocket sock = openUDP("127.0.0.1"); + for (int i = 0; i < count; ++i) + { + float posi[7]; + int result = getPOSI(sock, posi, 0); + playbackSleep(interval); + if (result < 0) + { + continue; + } + fprintf(fd, "%f, %f, %f, %f, %f, %f, %f\n", posi[0], posi[1], posi[2], posi[3], posi[4], posi[5], posi[6]); + } + closeUDP(sock); + displayMsg("Recording Complete"); +} + +void playback(char* path, int interval) +{ + FILE* fd = fopen(path, "r"); + if (!fd) + { + displayMsg("Unable to open output file."); + return; + } + displayMsg("Starting Playback..."); + + XPCSocket sock = openUDP("127.0.0.1"); + float posi[7]; + while (!feof(fd) && !ferror(fd)) + { + int result = fscanf(fd, "%f, %f, %f, %f, %f, %f, %f\n", + &posi[0], &posi[1], &posi[2], &posi[3], &posi[4], &posi[5], &posi[6]); + playbackSleep(interval); + if (result != 7) + { + continue; + } + sendPOSI(sock, posi, 7, 0); + } + closeUDP(sock); + displayMsg("Playback Complete"); +} \ No newline at end of file diff --git a/C/playbackExample/src/playback.h b/C/playbackExample/src/playback.h new file mode 100644 index 0000000..e54a3b1 --- /dev/null +++ b/C/playbackExample/src/playback.h @@ -0,0 +1,32 @@ +//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. + +#ifndef XPC_PLAYBACKEX_PLAYBACK_H_ +#define XPC_PLAYBACKEX_PLAYBACK_H_ + +void record(char* path, int interval, int duration); + +void playback(char* path, int interval); + +#endif \ No newline at end of file diff --git a/C/playbackExample/win/playbackExample.sln b/C/playbackExample/win/playbackExample.sln new file mode 100644 index 0000000..18a4c81 --- /dev/null +++ b/C/playbackExample/win/playbackExample.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2013 +VisualStudioVersion = 12.0.40629.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "playbackExample", "playbackExample.vcxproj", "{40781C32-3EE6-4B3C-A94F-E128BD41E21C}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {40781C32-3EE6-4B3C-A94F-E128BD41E21C}.Debug|Win32.ActiveCfg = Debug|Win32 + {40781C32-3EE6-4B3C-A94F-E128BD41E21C}.Debug|Win32.Build.0 = Debug|Win32 + {40781C32-3EE6-4B3C-A94F-E128BD41E21C}.Release|Win32.ActiveCfg = Release|Win32 + {40781C32-3EE6-4B3C-A94F-E128BD41E21C}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/C/playbackExample/win/playbackExample.vcxproj b/C/playbackExample/win/playbackExample.vcxproj new file mode 100644 index 0000000..a8adf8a --- /dev/null +++ b/C/playbackExample/win/playbackExample.vcxproj @@ -0,0 +1,89 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + {40781C32-3EE6-4B3C-A94F-E128BD41E21C} + playbackExample + + + + Application + true + v120 + MultiByte + + + Application + false + v120 + true + MultiByte + + + + + + + + + + + + + ../../src;../src;$(IncludePath) + ../../src;../src;$(SourcePath) + + + ../../src;../src;$(IncludePath) + ../../src;../src;$(SourcePath) + + + + Level3 + Disabled + true + _CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + + + true + + + + + Level3 + MaxSpeed + true + true + true + _CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + + + true + true + true + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/C/playbackExample/win/playbackExample.vcxproj.filters b/C/playbackExample/win/playbackExample.vcxproj.filters new file mode 100644 index 0000000..6a83f74 --- /dev/null +++ b/C/playbackExample/win/playbackExample.vcxproj.filters @@ -0,0 +1,42 @@ + + + + + {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 + + + + + Header Files + + + Header Files + + + Header Files + + + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + \ No newline at end of file diff --git a/Java/Examples/Playback/.idea/compiler.xml b/Java/Examples/Playback/.idea/compiler.xml new file mode 100644 index 0000000..96cc43e --- /dev/null +++ b/Java/Examples/Playback/.idea/compiler.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Java/Examples/Playback/.idea/copyright/profiles_settings.xml b/Java/Examples/Playback/.idea/copyright/profiles_settings.xml new file mode 100644 index 0000000..e7bedf3 --- /dev/null +++ b/Java/Examples/Playback/.idea/copyright/profiles_settings.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/Java/Examples/Playback/.idea/description.html b/Java/Examples/Playback/.idea/description.html new file mode 100644 index 0000000..db5f129 --- /dev/null +++ b/Java/Examples/Playback/.idea/description.html @@ -0,0 +1 @@ +Simple Java application that includes a class with main() method \ No newline at end of file diff --git a/Java/Examples/Playback/.idea/libraries/XPlaneConnect.xml b/Java/Examples/Playback/.idea/libraries/XPlaneConnect.xml new file mode 100644 index 0000000..f0cda69 --- /dev/null +++ b/Java/Examples/Playback/.idea/libraries/XPlaneConnect.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/Java/Examples/Playback/.idea/misc.xml b/Java/Examples/Playback/.idea/misc.xml new file mode 100644 index 0000000..5a65e9a --- /dev/null +++ b/Java/Examples/Playback/.idea/misc.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/Java/Examples/Playback/.idea/modules.xml b/Java/Examples/Playback/.idea/modules.xml new file mode 100644 index 0000000..7ba8a90 --- /dev/null +++ b/Java/Examples/Playback/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/Java/Examples/Playback/.idea/project-template.xml b/Java/Examples/Playback/.idea/project-template.xml new file mode 100644 index 0000000..1f08b88 --- /dev/null +++ b/Java/Examples/Playback/.idea/project-template.xml @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/Java/Examples/Playback/.idea/vcs.xml b/Java/Examples/Playback/.idea/vcs.xml new file mode 100644 index 0000000..6564d52 --- /dev/null +++ b/Java/Examples/Playback/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Java/Examples/Playback/Playback.iml b/Java/Examples/Playback/Playback.iml new file mode 100644 index 0000000..6c4f0ab --- /dev/null +++ b/Java/Examples/Playback/Playback.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/Java/Examples/Playback/src/gov/nasa/xpc/Main.java b/Java/Examples/Playback/src/gov/nasa/xpc/Main.java new file mode 100644 index 0000000..5e64335 --- /dev/null +++ b/Java/Examples/Playback/src/gov/nasa/xpc/Main.java @@ -0,0 +1,141 @@ +package gov.nasa.xpc; + +import java.io.*; +import java.util.Scanner; + +public class Main +{ + + public static void main(String[] args) + { + String[] mainOpts = new String[] { "Record X-Plane", "Playback File", "Exit" }; + + System.out.println("X-Plane Connect Playback Example [Version 1.2.0.0]\n"); + System.out.println("(c) 2013-2015 United States Government as represented by the Administrator\n"); + System.out.println("of the National Aeronautics and Space Administration. All Rights Reserved.\n"); + while(true) + { + int result = displayMenu("What would you like to do?", mainOpts); + } +// char* mainOpts[3] = +// { +// "Record X-Plane", +// "Playback File", +// "Exit" +// }; +// char path[256] = { 0 }; +// +// displayStart("1.2.0.0"); +// while (1) +// { +// switch (displayMenu("What would you like to do?", mainOpts, 3)) +// { +// case 1: +// { +// getString("Enter save file path", path); +// int interval = getInt("Enter interval between frames (milliseconds)"); +// int duration = getInt("Enter duration to record for (seconds)"); +// +// record(path, interval, duration); +// break; +// } +// case 2: +// { +// getString("Enter path to saved playback file", path); +// int interval = getInt("Enter interval between frames (milliseconds)"); +// +// playback(path, interval); +// break; +// } +// case 3: +// displayMsg("Exiting."); +// return 0; +// default: +// displayMsg("Unrecognized option."); +// break; +// } +// } +// +// return 0; + + } + + private static int displayMenu(String title, String[] opts) throws IOException + { + System.out.println(); + System.out.println("+---------------------------------------------- +\n"); + System.out.println(String.format("| %1$-42s |\n", title)); + System.out.println("+---------------------------------------------- +\n"); + for(int i = 0; i < opts.length; ++i) + { + System.out.println(String.format("| %1$2d. %2$-40s |\n", i + 1, opts[i])); + + } + System.out.println("+---------------------------------------------- +\n"); + System.out.print("Please select an option: "); + BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); + String result = reader.readLine(); + + return Integer.parseInt(result); + } + + public static void record(String path, int interval, int duration) throws IOException + { + int count = duration * 1000 / interval; + if (count < 1) + { + throw new IllegalArgumentException("duration is less than one interval."); + } + + try (BufferedWriter writer = new BufferedWriter(new FileWriter(path))) + { + System.out.println("Recording..."); + try (XPlaneConnect xpc = new XPlaneConnect()) + { + for (int i = 0; i < count; ++i) + { + float[] posi = xpc.getPOSI(0); + writer.write(String.format("%1$f, %2$f, %3$f, %4$f, %5$f, %6$f, %7$f\n", + posi[0], posi[1], posi[2], posi[3], posi[4], posi[5], posi[6])); + try + { + Thread.sleep(interval); + } + catch (InterruptedException ex) + { + } + } + } + System.out.println("Recording Complete"); + } + } + + public static void playback(String path, int interval) throws IOException + { + try(Scanner reader = new Scanner(new FileReader(path))) + { + System.out.println("Starting playback..."); + try (XPlaneConnect xpc = new XPlaneConnect()) + { + while(reader.hasNextLine()) + { + float[] posi = new float[7]; + for (int i = 0; i < 7; ++i) + { + posi[i] = reader.nextFloat(); + reader.skip(", "); + } + reader.nextLine(); + xpc.sendPOSI(posi); + try + { + Thread.sleep(interval); + } + catch (InterruptedException ex) + { + } + } + } + } + } +} diff --git a/MATLAB/PlaybackExample/Playback.m b/MATLAB/PlaybackExample/Playback.m new file mode 100644 index 0000000..e9f553b --- /dev/null +++ b/MATLAB/PlaybackExample/Playback.m @@ -0,0 +1,32 @@ +%% X-Plane Connect MATLAB Recording Example Script +% This script demonstrates how to playback recorded data from X-Plane. +% (See Record.m) +% Before running this script, ensure that the XPC plugin is installed and +% X-Plane is running. +%% Import XPC +addpath('../') +import XPlaneConnect.* + +%% Setup +% Create variables and open connection to X-Plane +path = 'MyRecording.txt'; % File containing stored data +interval = 0.1; % Time between snapshots in seconds +Socket = openUDP(); % Open connection to X-Plane +fd = fopen(path, 'r'); % Open file + +disp('X-Plane Connect Playback Example Script'); +fprintf('Playing back ''%s'' in %fs increments.\n', path, interval); + +%% Start Recording +count = floor(duration / interval); +for i = 1:count + posi = fscanf(fd, '%f, %f, %f, %f, %f, %f, %f\n'); + sendPOSI(posi); + pause(interval); +end + +%% Close connection and file +closeUDP(Socket); +fclose(fd); + +disp('Recording complete.'); \ No newline at end of file diff --git a/MATLAB/PlaybackExample/Record.m b/MATLAB/PlaybackExample/Record.m new file mode 100644 index 0000000..7e95b00 --- /dev/null +++ b/MATLAB/PlaybackExample/Record.m @@ -0,0 +1,34 @@ +%% X-Plane Connect MATLAB Recording Example Script +% This script demonstrates how to record data from X-Plane that can later +% be played back. (See Playback.m) +% Before running this script, ensure that the XPC plugin is installed and +% X-Plane is running. +%% Import XPC +addpath('../') +import XPlaneConnect.* + +%% Setup +% Create variables and open connection to X-Plane +path = 'MyRecording.txt'; % File to save the data in +interval = 0.1; % Time between snapshots in seconds +duration = 10; % Time to record for in seconds +Socket = openUDP(); % Open connection to X-Plane +fd = fopen(path, 'w'); % Open file + +disp('X-Plane Connect Recording Example Script'); +fprintf('Recording to ''%s'' for $f seconds in %fs increments.\n', path, duration, interval); + +%% Start Recording +count = floor(duration / interval); +for i = 1:count + posi = getPOSI(); + fprintf(fd, '%f, %f, %f, %f, %f, %f, %f\n', ... + posi(1), posi(2), posi(3), posi(4), posi(5), posi(6), posi(7)); + pause(interval); +end + +%% Close connection and file +closeUDP(Socket); +fclose(fd); + +disp('Recording complete.'); \ No newline at end of file diff --git a/Python/src/example.py b/Python/src/basicExample.py similarity index 100% rename from Python/src/example.py rename to Python/src/basicExample.py diff --git a/Python/src/playbackExample.py b/Python/src/playbackExample.py new file mode 100644 index 0000000..3934b0e --- /dev/null +++ b/Python/src/playbackExample.py @@ -0,0 +1,82 @@ +from time import sleep +import xpc + +def record(path, interval = 0.1, duration = 60): + try: + fd = open(path, "w") + except: + print "Unable to open file." + return + + count = int(duration / interval) + if count < 1: + print "duration is less than a single frame." + return + + with xpc.XPlaneConnect("localhost", 49009, 0, 1000) as client: + print "Recording..." + for i in range(0, count): + try: + posi = client.getPOSI() + fd.write("{0}, {1}, {2}, {3}, {4}, {5}, {6}\n".format(posi)) + except: + print "Error reading position" + continue + sleep(interval); + print "Recording Complete" + fd.close() + +def playback(path, interval): + try: + fd = open(path, "r") + except: + print "Unable to open file." + return + + with xpc.XPlaneConnect("localhost", 49009, 0, 1000) as client: + print "Starting Playback..." + for line in fd: + try: + posi = [ float(x) for x in line.split(',') ] + posi = client.sendPOSI(posi) + except: + print "Error sending position" + continue + sleep(interval); + print "Playback Complete" + fd.close() + +def printMenu(title, opts): + print "\n+---------------------------------------------- +" + print "| {0:42} |\n".format(title) + print "+---------------------------------------------- +" + for i in range(0,len(opts)): + print "| {0:2}. {1:40} |".format(i + 1, opts[i]) + print "+---------------------------------------------- +" + return int(raw_input("Please select and option: ")) + +def ex(): + print "X-Plane Connect Playback Example [Version 1.2.0]" + print "(c) 2013-2015 United States Government as represented by the Administrator" + print "of the National Aeronautics and Space Administration. All Rights Reserved." + + mainOpts = [ "Record X-Plane", "Playback File", "Exit" ] + + while True: + opt = printMenu("What would you like to do?", mainOpts) + if opt == 1: + path = raw_input("Enter save file path: ") + interval = float(raw_input("Enter interval between frames (seconds): ")) + duration = float(raw_input("Enter duration to record for (seconds): ")) + record(path, interval, duration) + elif opt == 2: + path = raw_input("Enter save file path: ") + interval = float(raw_input("Enter interval between frames (seconds): ")) + playback(path, interval) + elif opt == 3: + return; + else: + print "Unrecognized option." + +if __name__ == "__main__": + ex() \ No newline at end of file diff --git a/Python/xplaneConnect.pyproj b/Python/xplaneConnect.pyproj index c288a9c..d66fa38 100644 --- a/Python/xplaneConnect.pyproj +++ b/Python/xplaneConnect.pyproj @@ -5,7 +5,7 @@ 2.0 3c7a940d-17c8-4e91-882f-9bc8b1d2f54b . - src\example.py + src\playbackExample.py . @@ -24,8 +24,11 @@ false + + Code + - + Code diff --git a/xpcPlugin/XPlaneConnect/64/win.xpl b/xpcPlugin/XPlaneConnect/64/win.xpl index a27a63b..bdcf713 100644 Binary files a/xpcPlugin/XPlaneConnect/64/win.xpl and b/xpcPlugin/XPlaneConnect/64/win.xpl differ diff --git a/xpcPlugin/XPlaneConnect/win.xpl b/xpcPlugin/XPlaneConnect/win.xpl index ce96503..3f76453 100644 Binary files a/xpcPlugin/XPlaneConnect/win.xpl and b/xpcPlugin/XPlaneConnect/win.xpl differ