Refactored MATLAB client to use the Java client internally.

- Still need to implement selectDATA for all languages.
This commit is contained in:
Jason Watkins
2015-04-17 14:59:09 -07:00
parent 8e6819b80b
commit e191537bc9
20 changed files with 307 additions and 695 deletions

View File

@@ -1,9 +1,8 @@
function [ sensor ] = readDATA( socket )
function [ result ] = readDATA( socket )
% readDATA Reads UDP Socket and interprets data
%
% Inputs
% location: Either an opened UDP Socket or integer port number
%
% socket (optional): The client to read from.
% Outputs
% If data is X-Plane data format:
% data: Matlab X-Plane DATA Structure
@@ -30,62 +29,20 @@ function [ sensor ] = readDATA( socket )
% NOTE: sending in a port number instead of an opened socket clears the UDP buffer. This only works if the data is being sent at a fast rate. Sending in a UDP Socket reads the first packet in the buffer.
%
% Contributors
% [CT] Christopher Teubert (SGT, Inc.)
% christopher.a.teubert@nasa.gov
%
% To Do
% 1. Verify Input
%
% BEGIN CODE
% Christopher Teubert (SGT, Inc.) <christopher.a.teubert@nasa.gov>
% Jason Watkins <jason.w.watkins@nasa.gov>
import XPlaneConnect.*
import XPlaneConnect.*
%% Read UDP Socket
[ sensor.raw] = readUDP(socket);
%% Interpret Input
bits = size(sensor.raw);
if sensor.raw ~= -998 %If the signal exists
header = char(sensor.raw(1:4)');
if strcmp(header,'DATA') %DATA signal type
Values = floor((bits-5)/36);
sensor.d = [];
sensor.h = zeros(Values(1),1);
for i=1:Values(1)
sensor.h(i) = sensor.raw(6+(i-1)*36);
sensor.d = [sensor.d; typecast(uint8(sensor.raw(10+(i-1)*36:5+i*36))','single')];
end
elseif strcmp(header,'STRU') %STRU signal type
a = 6;
while a<length(sensor.raw)
strdim = sensor.raw(a);
if strdim == 0
break
end
fieldName = char(sensor.raw(a+1:a+strdim)');
a = a+strdim+1;
dim1 = sensor.raw(a);
dim2 = sensor.raw(a+1);
if dim1 == 0 %String
value = char(sensor.raw(a+2:a+1+dim2))';
a = a + dim2 + 2;
else
value = [];
for i=1:dim1
value(i,:) = typecast(uint8(sensor.raw(a+2+(i-1)*dim2*4:a+1+i*dim2*4))','single');
end
a = a + dim1*dim2*4+2;
end
sensor.(fieldName) = value;
end
elseif strcmp(header,'OTHR')
sensor.d = sensor.raw(6:end);
else %Other signal type
sensor.d = sensor.raw;
end
else %No Signal
sensor.d = -998;
%% 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
socket = clients(1);
end
%% Get data
result.raw = socket.readDATA();