Refactored MATLAB client to use the Java client internally.
- Still need to implement selectDATA for all languages.
This commit is contained in:
@@ -1,15 +1,11 @@
|
||||
function [ status ] = sendDATA(data, varargin)
|
||||
function sendDATA(data, socket)
|
||||
% sendDATA Send X-Plane formatted DATA over UDP
|
||||
%
|
||||
% Inputs
|
||||
% data: X-Plane formatted data. Is a matlab structure with the following fields:
|
||||
% .h: Header array containing header numbers corresponding to values in the X-Plane UDP Data screen.
|
||||
% .d: 2-D Data array. Each row contains eight values corresponding to the header value (.h(1) corresponds to .d(1,:))
|
||||
% 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 interface.
|
||||
%
|
||||
% Outputs
|
||||
% status: 0: no error, <0: error
|
||||
% socket (optional): The client to use when sending the command.
|
||||
%
|
||||
% Use
|
||||
% 1. import XPlaneConnect.*;
|
||||
@@ -29,29 +25,22 @@ function [ status ] = sendDATA(data, varargin)
|
||||
|
||||
import XPlaneConnect.*
|
||||
|
||||
%% Handle Input
|
||||
p = inputParser;
|
||||
addRequired(p,'data');
|
||||
addOptional(p,'IP','127.0.0.1',@ischar);
|
||||
addOptional(p,'port',49009,@isnumeric);
|
||||
parse(p,data,varargin{:});
|
||||
|
||||
%% BODY
|
||||
|
||||
header = ['DATA'-0,0];
|
||||
dataStream = header;
|
||||
|
||||
for i=1:length(p.Results.data.h)
|
||||
dataStream = [dataStream, p.Results.data.h(i), 0, 0, 0, typecast(single(p.Results.data.d(i,1:8)),'uint8')]; %#ok<AGROW>
|
||||
%% Get client
|
||||
global clients;
|
||||
if ~exist('socket', 'var')
|
||||
assert(istrue(length(clients) < 2), '[sendDATA] ERROR: Multiple clients open. You must specify which client to use.');
|
||||
if isempty(clients)
|
||||
openUDP();
|
||||
end
|
||||
|
||||
% Send DATA
|
||||
if length(dataStream) > 5
|
||||
status = sendUDP(dataStream, p.Results.IP, p.Results.port);
|
||||
else
|
||||
disp('Warning in sendDATA: Sending empty dataStream')
|
||||
status = -2;
|
||||
end
|
||||
|
||||
socket = clients(1);
|
||||
end
|
||||
|
||||
%% Validate input
|
||||
javaData = [];
|
||||
for i = 1:length(data.h);
|
||||
javaData = [javaData; data.h(i) data.d(i, 1:8)];
|
||||
end
|
||||
|
||||
%% Send command
|
||||
socket.sendDATA(javaData);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user