diff --git a/C/monitorExample/main.c b/C/monitorExample/main.c index fc06679..b9f7c43 100644 --- a/C/monitorExample/main.c +++ b/C/monitorExample/main.c @@ -23,6 +23,7 @@ // IMMEDIATE, UNILATERAL TERMINATION OF THIS AGREEMENT. #include "../src/xplaneConnect.h" +#include #include "stdio.h" #ifdef WIN32 @@ -51,7 +52,6 @@ int waitForInput() int fdstdin = 0; fd_set fds; struct timeval tv; -tv.tv_usec = 100 * 1000; int waitForInput() { @@ -61,14 +61,13 @@ int waitForInput() 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; + tv.tv_usec = 100 * 1000; while (1) { float posi[7]; diff --git a/C/playbackExample/src/playback.c b/C/playbackExample/src/playback.c index e2de4e0..75ad523 100644 --- a/C/playbackExample/src/playback.c +++ b/C/playbackExample/src/playback.c @@ -42,7 +42,7 @@ void playbackSleep(int ms) #ifdef WIN32 Sleep(ms); #else - uSleep(ms * 1000); + usleep(ms * 1000); #endif } diff --git a/C/src/xplaneConnect.c b/C/src/xplaneConnect.c index 9969a57..24fb56e 100755 --- a/C/src/xplaneConnect.c +++ b/C/src/xplaneConnect.c @@ -116,7 +116,7 @@ XPCSocket aopenUDP(const char *xpIP, unsigned short xpPort, unsigned short port) #else struct timeval timeout; timeout.tv_sec = 0; - timeout.tv_usec = 100000; + timeout.tv_usec = 250000; #endif if (setsockopt(sock.sock, SOL_SOCKET, SO_RCVTIMEO, (char*)&timeout, sizeof(timeout)) < 0) { diff --git a/C/xpcExample/xpcExample/src/main.cpp b/C/xpcExample/xpcExample/src/main.cpp index 5792368..e9e645a 100644 --- a/C/xpcExample/xpcExample/src/main.cpp +++ b/C/xpcExample/xpcExample/src/main.cpp @@ -24,7 +24,7 @@ int main() const char* IP = "127.0.0.1"; //IP Address of computer running X-Plane XPCSocket sock = openUDP(IP); float tVal[1]; - int tSize; + int tSize = 1; if (getDREF(sock, "sim/test/test_float", tVal, &tSize) < 0) { printf("Error establishing connecting. Unable to read data from X-Plane."); diff --git a/Java/Examples/Playback/src/gov/nasa/xpc/Main.java b/Java/Examples/Playback/src/gov/nasa/xpc/Main.java index 5e64335..0e0b376 100644 --- a/Java/Examples/Playback/src/gov/nasa/xpc/Main.java +++ b/Java/Examples/Playback/src/gov/nasa/xpc/Main.java @@ -1,78 +1,83 @@ package gov.nasa.xpc; +import com.sun.javafx.scene.EnteredExitedHandler; + import java.io.*; import java.util.Scanner; public class Main { - public static void main(String[] args) + public static void main(String[] args) throws IOException { 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"); + System.out.println("X-Plane Connect Playback Example [Version 1.2.0.0]"); + System.out.println("(c) 2013-2015 United States Government as represented by the Administrator"); + System.out.println("of the National Aeronautics and Space Administration. All Rights Reserved."); 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; + switch(result) + { + case 1: + { + String path = getString("Enter a save file 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: + { + String path = getString("Enter path to saved playback file: "); + int interval = getInt("Enter interval between frames (milliseconds): "); + + playback(path, interval); + break; + } + case 3: + { + System.out.println("Exiting."); + return; + } + default: + { + System.out.println("Unrecognized menu option."); + break; + } + } + } } 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"); + System.out.println("+---------------------------------------------- +"); + System.out.println(String.format("| %1$-42s |", title)); + System.out.println("+---------------------------------------------- +"); 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(String.format("| %1$2d. %2$-40s |", i + 1, opts[i])); } - System.out.println("+---------------------------------------------- +\n"); - System.out.print("Please select an option: "); + System.out.println("+---------------------------------------------- +"); + return getInt("Please select an option: "); + } + + private static String getString(String prompt) throws IOException + { + System.out.print(prompt); + + BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); + return reader.readLine(); + } + + private static int getInt(String prompt) throws IOException + { + System.out.print(prompt); + BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); String result = reader.readLine(); @@ -114,6 +119,7 @@ public class Main { try(Scanner reader = new Scanner(new FileReader(path))) { + reader.useDelimiter("[\\s\\r\\n,]+"); System.out.println("Starting playback..."); try (XPlaneConnect xpc = new XPlaneConnect()) { @@ -122,8 +128,8 @@ public class Main float[] posi = new float[7]; for (int i = 0; i < 7; ++i) { - posi[i] = reader.nextFloat(); - reader.skip(", "); + String s = reader.next(); + posi[i] = Float.parseFloat(s); } reader.nextLine(); xpc.sendPOSI(posi); diff --git a/MATLAB/+XPlaneConnect/openUDP.m b/MATLAB/+XPlaneConnect/openUDP.m index b518cdb..2961598 100644 --- a/MATLAB/+XPlaneConnect/openUDP.m +++ b/MATLAB/+XPlaneConnect/openUDP.m @@ -26,7 +26,7 @@ p = inputParser; addOptional(p,'xpHost','127.0.0.1',@ischar); addOptional(p,'xpPort',49009,@isnumeric); addOptional(p,'port',0,@isnumeric); -addOptional(p,'timeout',0,@isnumeric); +addOptional(p,'timeout',100,@isnumeric); parse(p,varargin{:}); %% Create client diff --git a/MATLAB/MonitorExample/MonitorExample.m b/MATLAB/MonitorExample/MonitorExample.m index fa42115..ffbdc14 100644 --- a/MATLAB/MonitorExample/MonitorExample.m +++ b/MATLAB/MonitorExample/MonitorExample.m @@ -3,18 +3,17 @@ % Before running this script, ensure that the XPC plugin is installed and % X-Plane is running. %% Import XPC -clear all; +clear all addpath('../') import XPlaneConnect.* Socket = openUDP(); while 1 - posi = getPOSI(1, Socket); - ctrl = getCTRL(1, Socket); - + posi = getPOSI(0, Socket); + ctrl = getCTRL(0, 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)); - + 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/MATLAB/PlaybackExample/MyRecording.txt b/MATLAB/PlaybackExample/MyRecording.txt new file mode 100644 index 0000000..60c546a --- /dev/null +++ b/MATLAB/PlaybackExample/MyRecording.txt @@ -0,0 +1,100 @@ +37.184181, -120.793640, 3904.040771, 1.856917, 0.001644, 116.058609, 0.000000 +37.184143, -120.793541, 3903.825928, 2.172139, -0.034512, 115.875587, 0.000000 +37.184090, -120.793404, 3903.511719, 2.425995, -0.111958, 115.577911, 0.000000 +37.184040, -120.793282, 3903.230225, 2.497653, -0.205506, 115.289268, 0.000000 +37.183994, -120.793167, 3902.961914, 2.478850, -0.315117, 115.006279, 0.000000 +37.183949, -120.793053, 3902.683838, 2.412536, -0.447890, 114.716370, 0.000000 +37.183910, -120.792953, 3902.452881, 2.344441, -0.570747, 114.485756, 0.000000 +37.183857, -120.792824, 3902.137939, 2.253826, -0.752984, 114.194984, 0.000000 +37.183807, -120.792702, 3901.830566, 2.178489, -0.942979, 113.943779, 0.000000 +37.183765, -120.792595, 3901.561279, 2.125190, -1.116157, 113.754135, 0.000000 +37.183735, -120.792511, 3901.342773, 2.089507, -1.260052, 113.621834, 0.000000 +37.183693, -120.792404, 3901.058350, 2.051378, -1.449701, 113.479713, 0.000000 +37.183628, -120.792244, 3900.620361, 2.004393, -1.742637, 113.320374, 0.000000 +37.183571, -120.792107, 3900.232178, 1.969860, -1.999084, 113.234406, 0.000000 +37.183529, -120.791992, 3899.922852, 1.945357, -2.199157, 113.199463, 0.000000 +37.183487, -120.791885, 3899.607666, 1.922479, -2.397843, 113.190887, 0.000000 +37.183441, -120.791771, 3899.279297, 1.738008, -2.604320, 113.214371, 0.000000 +37.183395, -120.791649, 3898.942383, 1.172052, -2.819112, 113.280800, 0.000000 +37.183342, -120.791512, 3898.525879, 0.437769, -3.059577, 113.392952, 0.000000 +37.183292, -120.791389, 3898.116943, -0.110597, -3.260861, 113.510010, 0.000000 +37.183247, -120.791275, 3897.675293, -0.458939, -3.399007, 113.635101, 0.000000 +37.183220, -120.791206, 3897.409668, -0.495934, -3.425584, 113.706985, 0.000000 +37.183182, -120.791107, 3896.976318, -0.338542, -3.312644, 113.832870, 0.000000 +37.183128, -120.790962, 3896.313965, 0.088305, -2.812056, 114.069130, 0.000000 +37.183083, -120.790848, 3895.734863, 0.355302, -2.143086, 114.327766, 0.000000 +37.183033, -120.790718, 3895.112061, 0.345563, -1.171917, 114.668144, 0.000000 +37.182987, -120.790604, 3894.519043, 0.034761, -0.025642, 115.037415, 0.000000 +37.182941, -120.790489, 3893.926270, -0.549108, 1.265883, 115.421654, 0.000000 +37.182888, -120.790344, 3893.151611, -1.627703, 3.039703, 115.896240, 0.000000 +37.182831, -120.790199, 3892.313477, -2.879907, 4.868656, 116.325722, 0.000000 +37.182785, -120.790077, 3891.557129, -3.883288, 6.350969, 116.633751, 0.000000 +37.182743, -120.789970, 3890.766602, -4.752331, 7.729563, 116.888329, 0.000000 +37.182705, -120.789871, 3889.997314, -5.439554, 8.871016, 117.077042, 0.000000 +37.182659, -120.789749, 3888.965820, -6.164141, 10.014505, 117.239494, 0.000000 +37.182610, -120.789627, 3887.832031, -6.734039, 10.811956, 117.319382, 0.000000 +37.182560, -120.789505, 3886.558594, -7.134449, 11.245357, 117.313339, 0.000000 +37.182514, -120.789383, 3885.197510, -7.320403, 11.326477, 117.228592, 0.000000 +37.182465, -120.789261, 3883.700439, -7.264509, 11.086659, 117.071564, 0.000000 +37.182415, -120.789131, 3882.124023, -7.020517, 10.579235, 116.843575, 0.000000 +37.182365, -120.789009, 3880.477295, -6.698184, 9.864036, 116.538239, 0.000000 +37.182316, -120.788887, 3878.771973, -6.407937, 8.986709, 116.154274, 0.000000 +37.182266, -120.788765, 3877.028076, -6.217397, 7.992366, 115.705994, 0.000000 +37.182217, -120.788643, 3875.249023, -6.173934, 6.988136, 115.220467, 0.000000 +37.182167, -120.788521, 3873.432617, -6.285208, 6.050294, 114.729034, 0.000000 +37.182117, -120.788399, 3871.583496, -6.453388, 5.213163, 114.269440, 0.000000 +37.182068, -120.788269, 3869.689209, -6.484870, 4.480176, 113.873062, 0.000000 +37.182014, -120.788147, 3867.766357, -6.310386, 3.856612, 113.555290, 0.000000 +37.181965, -120.788025, 3865.820801, -6.021461, 3.327790, 113.311180, 0.000000 +37.181915, -120.787903, 3863.870361, -5.728759, 2.874094, 113.135651, 0.000000 +37.181866, -120.787781, 3861.910156, -5.480271, 2.475115, 113.025513, 0.000000 +37.181816, -120.787651, 3859.973145, -5.302026, 2.122235, 112.979225, 0.000000 +37.181767, -120.787529, 3858.042969, -5.182843, 1.808723, 112.993736, 0.000000 +37.181717, -120.787407, 3856.119629, -5.038956, 1.552066, 113.070557, 0.000000 +37.181667, -120.787285, 3854.215088, -4.828547, 1.368155, 113.206085, 0.000000 +37.181614, -120.787148, 3852.185059, -4.515563, 1.254129, 113.410904, 0.000000 +37.181557, -120.787010, 3850.030762, -4.132499, 1.210060, 113.681358, 0.000000 +37.181507, -120.786888, 3848.263916, -3.831450, 1.225745, 113.935280, 0.000000 +37.181458, -120.786766, 3846.475342, -3.528734, 1.284648, 114.214294, 0.000000 +37.181408, -120.786644, 3844.712158, -3.243377, 1.382594, 114.502975, 0.000000 +37.181358, -120.786522, 3842.987549, -2.982575, 1.515415, 114.790489, 0.000000 +37.181309, -120.786392, 3841.302246, -2.688687, 1.679037, 115.070442, 0.000000 +37.181259, -120.786270, 3839.659424, -2.305070, 1.869125, 115.338135, 0.000000 +37.181210, -120.786148, 3838.070068, -1.827937, 2.080883, 115.588036, 0.000000 +37.181156, -120.786018, 3836.515137, -1.326015, 2.315055, 115.817902, 0.000000 +37.181107, -120.785889, 3835.020508, -0.858468, 2.566000, 116.019691, 0.000000 +37.181053, -120.785767, 3833.605713, -0.446646, 2.827466, 116.188957, 0.000000 +37.181004, -120.785637, 3832.263672, -0.082390, 3.097450, 116.326546, 0.000000 +37.180950, -120.785515, 3830.996094, 0.248427, 3.372406, 116.433670, 0.000000 +37.180901, -120.785385, 3829.802734, 0.561189, 3.648955, 116.513596, 0.000000 +37.180847, -120.785263, 3828.686279, 0.901348, 3.909596, 116.570610, 0.000000 +37.180798, -120.785133, 3827.642090, 1.422296, 4.101938, 116.610832, 0.000000 +37.180744, -120.785011, 3826.675537, 2.124010, 4.216800, 116.636208, 0.000000 +37.180691, -120.784889, 3825.800049, 2.895841, 4.268193, 116.644135, 0.000000 +37.180641, -120.784767, 3825.024658, 3.647615, 4.264566, 116.632553, 0.000000 +37.180588, -120.784637, 3824.355469, 4.389325, 4.198403, 116.604164, 0.000000 +37.180538, -120.784523, 3823.797119, 5.116096, 4.063403, 116.559959, 0.000000 +37.180489, -120.784401, 3823.351562, 5.802851, 3.858843, 116.500069, 0.000000 +37.180435, -120.784279, 3823.021240, 6.434232, 3.583184, 116.425621, 0.000000 +37.180386, -120.784164, 3822.803223, 7.040646, 3.237821, 116.340439, 0.000000 +37.180336, -120.784042, 3822.697021, 7.629384, 2.839028, 116.249237, 0.000000 +37.180286, -120.783928, 3822.700195, 8.181519, 2.404881, 116.155312, 0.000000 +37.180244, -120.783821, 3822.798828, 8.596326, 1.981372, 116.066658, 0.000000 +37.180183, -120.783684, 3823.074219, 9.020256, 1.372200, 115.947289, 0.000000 +37.180126, -120.783554, 3823.453369, 9.331639, 0.798377, 115.847244, 0.000000 +37.180073, -120.783424, 3823.932129, 9.642418, 0.224538, 115.759720, 0.000000 +37.180019, -120.783302, 3824.521729, 9.962214, -0.365530, 115.680557, 0.000000 +37.179970, -120.783188, 3825.146240, 10.216949, -0.901261, 115.617035, 0.000000 +37.179928, -120.783081, 3825.777100, 10.420901, -1.378152, 115.566948, 0.000000 +37.179871, -120.782951, 3826.665283, 10.683296, -1.973540, 115.510689, 0.000000 +37.179817, -120.782829, 3827.599854, 10.932059, -2.526971, 115.463028, 0.000000 +37.179764, -120.782700, 3828.676758, 11.182608, -3.091355, 115.418022, 0.000000 +37.179710, -120.782570, 3829.791748, 11.405788, -3.608584, 115.379250, 0.000000 +37.179657, -120.782448, 3830.954102, 11.541166, -4.084742, 115.349564, 0.000000 +37.179604, -120.782326, 3832.230469, 11.431418, -4.526593, 115.343117, 0.000000 +37.179554, -120.782204, 3833.525391, 11.053594, -4.891589, 115.367775, 0.000000 +37.179501, -120.782082, 3834.855957, 10.596283, -5.199400, 115.407677, 0.000000 +37.179451, -120.781960, 3836.201660, 10.188977, -5.458726, 115.448441, 0.000000 +37.179401, -120.781837, 3837.573486, 9.879080, -5.681745, 115.481895, 0.000000 +37.179348, -120.781715, 3838.972656, 9.667299, -5.869191, 115.505310, 0.000000 +37.179298, -120.781593, 3840.342529, 9.507944, -5.992330, 115.524872, 0.000000 diff --git a/MATLAB/PlaybackExample/Playback.m b/MATLAB/PlaybackExample/Playback.m index e9f553b..f5ea2a5 100644 --- a/MATLAB/PlaybackExample/Playback.m +++ b/MATLAB/PlaybackExample/Playback.m @@ -1,4 +1,4 @@ -%% X-Plane Connect MATLAB Recording Example Script +%% X-Plane Connect MATLAB Playback 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 @@ -11,22 +11,26 @@ import XPlaneConnect.* % Create variables and open connection to X-Plane path = 'MyRecording.txt'; % File containing stored data interval = 0.1; % Time between snapshots in seconds +duration = 10; 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 +%% Start Playback count = floor(duration / interval); +pauseSim(1); for i = 1:count - posi = fscanf(fd, '%f, %f, %f, %f, %f, %f, %f\n'); + line = fgetl(fd); + posi = sscanf(line, '%f, %f, %f, %f, %f, %f, %f\n'); sendPOSI(posi); pause(interval); end %% Close connection and file +pauseSim(0); closeUDP(Socket); fclose(fd); -disp('Recording complete.'); \ No newline at end of file +disp('Playback complete.'); \ No newline at end of file diff --git a/MATLAB/PlaybackExample/Record.m b/MATLAB/PlaybackExample/Record.m index 7e95b00..8f0d0b0 100644 --- a/MATLAB/PlaybackExample/Record.m +++ b/MATLAB/PlaybackExample/Record.m @@ -16,12 +16,12 @@ 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); +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(); + posi = getPOSI(0, Socket); 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); diff --git a/Python/src/playbackExample.py b/Python/src/playbackExample.py index 3934b0e..dfa4f52 100644 --- a/Python/src/playbackExample.py +++ b/Python/src/playbackExample.py @@ -7,18 +7,18 @@ def record(path, interval = 0.1, duration = 60): 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: + 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)) + fd.write("{0}, {1}, {2}, {3}, {4}, {5}, {6}\n".format(*posi)) except: print "Error reading position" continue diff --git a/Python/xplaneConnect.pyproj b/Python/xplaneConnect.pyproj index 651c96f..446a9ff 100644 --- a/Python/xplaneConnect.pyproj +++ b/Python/xplaneConnect.pyproj @@ -25,6 +25,8 @@ + Code + Code diff --git a/TestScripts/C Tests/PosiTests.h b/TestScripts/C Tests/PosiTests.h index a46ca61..104e517 100644 --- a/TestScripts/C Tests/PosiTests.h +++ b/TestScripts/C Tests/PosiTests.h @@ -146,13 +146,13 @@ int testPOSI_NonPlayer() int testGetPOSI_Player() { float POSI[7] = { 37.524F, -122.06899F, 2500, 0, 0, 0, 1 }; - doGETPTest(POSI, 0, POSI); + return doGETPTest(POSI, 0, POSI); } int testGetPOSI_NonPlayer() { float POSI[7] = { 37.624F, -122.06899F, 1500, 0, 0, 0, 1 }; - doGETPTest(POSI, 3, POSI); + return doGETPTest(POSI, 3, POSI); } #endif \ No newline at end of file diff --git a/TestScripts/Python Tests/Tests.py b/TestScripts/Python Tests/Tests.py index 8a88d32..486803d 100644 --- a/TestScripts/Python Tests/Tests.py +++ b/TestScripts/Python Tests/Tests.py @@ -3,7 +3,7 @@ import unittest import imp import time -import xpc +xpc = imp.load_source('xpc', '../../Python/src/xpc.py') class XPCTests(unittest.TestCase): """Tests the functionality of the XPlaneConnect class.""" diff --git a/xpcPlugin/DataManager.cpp b/xpcPlugin/DataManager.cpp index eccb8c2..4571006 100644 --- a/xpcPlugin/DataManager.cpp +++ b/xpcPlugin/DataManager.cpp @@ -529,7 +529,7 @@ namespace XPC } XPLMDataTypeID dataType = XPLMGetDataRefTypes(xdref); - Log::FormatLine(LOG_INFO, "DMAN", "Setting DREF %s (x:%X) Type: %i", xdref, dataType); + Log::FormatLine(LOG_INFO, "DMAN", "Setting DREF %s (x:%X) Type: %i", dref.c_str(), xdref, dataType); if ((dataType & 2) == 2) // Float { XPLMSetDataf(xdref, values[0]); diff --git a/xpcPlugin/Message.cpp b/xpcPlugin/Message.cpp index 26dca40..3563a09 100644 --- a/xpcPlugin/Message.cpp +++ b/xpcPlugin/Message.cpp @@ -25,12 +25,6 @@ namespace XPC return m; } - unsigned long Message::GetMagicNumber() const - { - unsigned long val = size < 4 ? 0 : *((unsigned long*)buffer); - return val; - } - std::string Message::GetHead() const { std::string val = size < 4 ? "" : std::string((char*)buffer, 4); @@ -59,26 +53,22 @@ namespace XPC stringstream ss; // Dump raw bytes to string - ss << hex << setfill('0'); + ss << std::hex << setfill('0'); for (int i = 0; i < size; ++i) { ss << ' ' << setw(2) << static_cast(buffer[i]); } - Log::WriteLine(LOG_DEBUG, "DBUG", ss.str()); + Log::WriteLine(LOG_TRACE, "DBUG", ss.str()); + std::string head = GetHead(); ss.str(""); - ss << "Head: " << GetHead() << "(0x" << setw(8) << GetMagicNumber() << ")" << dec << " Size: " << GetSize(); - switch (GetMagicNumber()) // Binary version of head + ss << "Head: " << head << std::dec << " Size: " << GetSize(); + if (head == "CONN" || head == "WYPT" || head == "TEXT") { - case 0x4E4EF443: // CONN - case 0x54505957: // WYPT - case 0x54584554: // TEXT - { Log::WriteLine(LOG_DEBUG, "DBUG", ss.str()); - break; - } - case 0x4C525443: // CTRL - { + } + else if (head == "CTRL") + { // Parse message data float pitch = *((float*)(buffer + 5)); float roll = *((float*)(buffer + 9)); @@ -91,12 +81,11 @@ namespace XPC { aircraft = buffer[26]; } - ss << " Attitude:(" << pitch << " " << roll << " " << yaw << ")"; - ss << " Thr:" << thr << " Gear:" << (int)gear << " Flaps:" << flaps; - Log::WriteLine(LOG_DEBUG, "DBUG", ss.str()); - break; - } - case 0x41544144: // DATA + ss << " Attitude:(" << pitch << " " << roll << " " << yaw << ")"; + ss << " Thr:" << thr << " Gear:" << (int)gear << " Flaps:" << flaps; + Log::WriteLine(LOG_DEBUG, "DBUG", ss.str()); + } + else if (head == "DATA") { size_t numCols = (size - 5) / 36; float values[32][9]; @@ -107,19 +96,18 @@ namespace XPC } ss << " (" << numCols << " lines)"; Log::WriteLine(LOG_DEBUG, "DBUG", ss.str()); - for (int i = 0; i < numCols; ++i) - { - ss.str(""); + for (int i = 0; i < numCols; ++i) + { + ss.str(""); ss << " #" << values[i][0]; - for (int j = 1; j < 9; ++j) - { + for (int j = 1; j < 9; ++j) + { ss << " " << values[i][j]; } Log::WriteLine(LOG_DEBUG, "DBUG", ss.str()); - } - break; - } - case 0x46455244: // DREF + } + } + else if (head == "DREF") { Log::WriteLine(LOG_DEBUG, "DBUG", ss.str()); string dref((char*)buffer + 6, buffer[5]); @@ -132,9 +120,13 @@ namespace XPC ss << " " << *((float*)(buffer + values + 1 + sizeof(float) * i)); } Log::WriteLine(LOG_DEBUG, "DBUG", ss.str()); - break; } - case 0x44544547: // GETD + else if (head == "GETC" || head == "GETP") + { + ss << " Aircraft:" << (int)buffer[5]; + Log::WriteLine(LOG_DEBUG, "DBUG", ss.str()); + } + else if (head == "GETD") { Log::WriteLine(LOG_DEBUG, "DBUG", ss.str()); int cur = 6; @@ -145,9 +137,8 @@ namespace XPC i + 1, buffer[5], dref.length(), dref.c_str()); cur += 1 + buffer[cur]; } - break; } - case 0x49534F50: // POSI + else if (head == "POSI") { char aircraft = buffer[5]; float gear = *((float*)(buffer + 30)); @@ -160,20 +151,21 @@ namespace XPC ss << orient[3] << ' ' << orient[4] << ' ' << orient[5] << ") Gear:"; ss << gear; Log::WriteLine(LOG_DEBUG, "DBUG", ss.str()); - break; } - case 0x554D4953: // SIMU + else if (head == "SIMU") { ss << ' ' << (int)buffer[5]; Log::WriteLine(LOG_DEBUG, "DBUG", ss.str()); - break; - } - default: + } + else if (head == "VIEW") + { + ss << "Type:" << *((unsigned long*)(buffer + 5)); + Log::WriteLine(LOG_DEBUG, "DBUG", ss.str()); + } + else { ss << " UNKNOWN HEADER "; Log::WriteLine(LOG_DEBUG, "DBUG", ss.str()); - break; } - } } } diff --git a/xpcPlugin/XPCPlugin.cpp b/xpcPlugin/XPCPlugin.cpp index ac4d47a..f94b98a 100755 --- a/xpcPlugin/XPCPlugin.cpp +++ b/xpcPlugin/XPCPlugin.cpp @@ -91,7 +91,7 @@ static float XPCFlightLoopCallback(float inElapsedSinceLastCall, float inElapsed PLUGIN_API int XPluginStart(char* outName, char* outSig, char* outDesc) { - strcpy(outName, "X-Plane Connect [Version 1.1.1]"); + strcpy(outName, "X-Plane Connect [Version 1.2.0]"); strcpy(outSig, "NASA.XPlaneConnect"); strcpy(outDesc, "X Plane Communications Toolbox\nCopyright (c) 2013-2015 United States Government as represented by the Administrator of the National Aeronautics and Space Administration. All Rights Reserved."); diff --git a/xpcPlugin/XPlaneConnect/64/lin.xpl b/xpcPlugin/XPlaneConnect/64/lin.xpl index 9fe5127..476986c 100755 Binary files a/xpcPlugin/XPlaneConnect/64/lin.xpl and b/xpcPlugin/XPlaneConnect/64/lin.xpl differ diff --git a/xpcPlugin/XPlaneConnect/64/win.xpl b/xpcPlugin/XPlaneConnect/64/win.xpl index bdcf713..1328419 100644 Binary files a/xpcPlugin/XPlaneConnect/64/win.xpl and b/xpcPlugin/XPlaneConnect/64/win.xpl differ diff --git a/xpcPlugin/XPlaneConnect/lin.xpl b/xpcPlugin/XPlaneConnect/lin.xpl index 09f3158..a1780c7 100755 Binary files a/xpcPlugin/XPlaneConnect/lin.xpl and b/xpcPlugin/XPlaneConnect/lin.xpl differ diff --git a/xpcPlugin/XPlaneConnect/mac.xpl b/xpcPlugin/XPlaneConnect/mac.xpl index da391d2..aa4d819 100755 Binary files a/xpcPlugin/XPlaneConnect/mac.xpl and b/xpcPlugin/XPlaneConnect/mac.xpl differ diff --git a/xpcPlugin/XPlaneConnect/win.xpl b/xpcPlugin/XPlaneConnect/win.xpl index 3f76453..0813198 100644 Binary files a/xpcPlugin/XPlaneConnect/win.xpl and b/xpcPlugin/XPlaneConnect/win.xpl differ