From cfeb01fc0277bbdb3789ec0f2b12a54436191708 Mon Sep 17 00:00:00 2001 From: Jason Watkins Date: Thu, 9 Apr 2015 12:15:59 -0700 Subject: [PATCH] Added MATLAB client support for WYPT command. --- MATLAB/+XPlaneConnect/sendWYPT.m | 53 +++++++++++++++++++++++++ TestScripts/MATLAB Tests/sendWYPTTest.m | 26 ++++++++++++ TestScripts/MATLAB Tests/tests.m | 1 + 3 files changed, 80 insertions(+) create mode 100644 MATLAB/+XPlaneConnect/sendWYPT.m create mode 100644 TestScripts/MATLAB Tests/sendWYPTTest.m diff --git a/MATLAB/+XPlaneConnect/sendWYPT.m b/MATLAB/+XPlaneConnect/sendWYPT.m new file mode 100644 index 0000000..ed64b04 --- /dev/null +++ b/MATLAB/+XPlaneConnect/sendWYPT.m @@ -0,0 +1,53 @@ +function [ status ] = sendWYPT( op, points, varargin ) +% sendWYPT Adds, removes, or clears a set of waypoints to be rendered in +% the simulator. +% +% Inputs +% msg: The string to be displayed +% x (optional): The distance from the left edge of the screen to display the message. +% y (optional): The distance from the bottom edge of the screen to display the message. +% IP Address (optional): IP Address of the machine that will receive the data as a character array. Default is '127.0.0.1' (local machine) +% port (optional): Port on the receiving machine where the data will be sent. Default is 49009 (XPlaneConnect). In general use 49009 to send to the plugin and 49005 to send to the x-plane udp +% +% Outputs +% status: 0 if successful, otherwise a negative value. +% +% Use +% 1. import XPlaneConnect.*; +% 2. #Set a message to be displayed near the top middle of the screen. +% 3. status = sendTEXT('Some text', 512, 600); +% +% Contributors +% Jason Watkins +% jason.w.watkins@nasa.gov +% +% To Do +% +% BEGIN CODE + +import XPlaneConnect.* +%% Handle Input +p = inputParser; +addRequired(p,'op'); +addRequired(p,'points'); +addOptional(p,'IP','127.0.0.1',@ischar); +addOptional(p,'port',49009,@isnumeric); +parse(p,op,points,varargin{:}); + +%% Validate Input +len = uint32(length(points)); +assert(op > 0 && op < 4); +assert(mod(len, 3) == 0); +assert(len / 3 < 20); + +%% Body +header = ['WYPT'-0,0]; +dataStream = [header,... + uint8(op),... + uint8(len / 3),... + typecast(single(points), 'uint8')]; + +% Send TEXT +status = sendUDP(dataStream, p.Results.IP, p.Results.port); +end + diff --git a/TestScripts/MATLAB Tests/sendWYPTTest.m b/TestScripts/MATLAB Tests/sendWYPTTest.m new file mode 100644 index 0000000..cbc4514 --- /dev/null +++ b/TestScripts/MATLAB Tests/sendWYPTTest.m @@ -0,0 +1,26 @@ +function sendWYPTTest() +%% Setup +addpath('../../MATLAB') +import XPlaneConnect.* + +points = [37.5245, -122.06899, 2500,... + 37.455397, -122.050037, 2500,... + 37.469567, -122.051411, 2500,... + 37.479376, -122.060509, 2300,... + 37.482237, -122.076130, 2100,... + 37.474881, -122.087288, 1900,... + 37.467660, -122.079391, 1700,... + 37.466298, -122.090549, 1500,... + 37.362562, -122.039223, 1000,... + 37.361448, -122.034416, 1000,... + 37.361994, -122.026348, 1000,... + 37.365541, -122.022572, 1000,... + 37.373727, -122.024803, 1000,... + 37.403869, -122.041283, 50,... + 37.418544, -122.049222, 6]; + +%% Test +sendWYPT(1, points); + + +end diff --git a/TestScripts/MATLAB Tests/tests.m b/TestScripts/MATLAB Tests/tests.m index 8788712..bfa45d9 100644 --- a/TestScripts/MATLAB Tests/tests.m +++ b/TestScripts/MATLAB Tests/tests.m @@ -18,6 +18,7 @@ theTests = {{@openCloseTest, 'Open/Close Test', 0},... {@DATATest,'DATA Test', 0},... {@CTRLTest,'CTRL Test', 0},... {@POSITest,'POSI Test', 0},... + {@sendWYPTTest,'WYPT Test', 0},... {@pauseTest,'Pause Test', 0},... {@struTest,'Struct Test', 0},... {@setConnTest, 'setConn Test', 0}};