Completed Preliminary MATLAB Test Scripts
This commit is contained in:
@@ -23,4 +23,6 @@ function [socket] = closeUDP(socket)
|
||||
|
||||
socket.close;
|
||||
|
||||
assert(isequal(socket.isClosed(),1),'closeUDP: Error- Could not close socket');
|
||||
|
||||
end
|
||||
@@ -36,4 +36,6 @@ if ~isempty(varargin)
|
||||
end
|
||||
end
|
||||
|
||||
assert(isequal(socket.isClosed(),0),'openUDP: Error- Could not open port');
|
||||
|
||||
end
|
||||
|
||||
@@ -67,7 +67,7 @@ function [ sensor ] = readDATA( socket )
|
||||
dim1 = sensor.raw(a);
|
||||
dim2 = sensor.raw(a+1);
|
||||
if dim1 == 0 %String
|
||||
value = char(sensor.raw(a+2:a+1+dim2));
|
||||
value = char(sensor.raw(a+2:a+1+dim2))';
|
||||
a = a + dim2 + 2;
|
||||
else
|
||||
value = [];
|
||||
|
||||
@@ -50,7 +50,7 @@ function [ data ] = readUDP( input )
|
||||
data = int16(data);
|
||||
data(data(:)<0) = uint8(data(data(:)<0) + 256); %fix signed issue
|
||||
size = int16(data(5)); %size of data stream
|
||||
|
||||
|
||||
%% trim trailing data
|
||||
for i=1:floor(length(data)/256)+1
|
||||
if data(size+1:end)==0
|
||||
|
||||
@@ -36,7 +36,7 @@ import XPlaneConnect.*
|
||||
|
||||
%% Handle Input
|
||||
% Optional parameters
|
||||
if ~exist('IP','var'), IP = "127.0.0.1"; end
|
||||
if ~exist('IP','var'), IP = '127.0.0.1'; end
|
||||
if ~exist('port','var'), port = 49009; end
|
||||
if ~exist('acft','var'), acft = 0; end
|
||||
|
||||
@@ -44,7 +44,7 @@ import XPlaneConnect.*
|
||||
|
||||
%%BODY
|
||||
header = ['CTRL'-0,0];
|
||||
dataStream = [header, acft];
|
||||
dataStream = header; %TODO-ADD ACFT
|
||||
|
||||
% Deal with position update
|
||||
control = [0, 0, 0, 0.8, 0, 1];
|
||||
@@ -55,7 +55,7 @@ import XPlaneConnect.*
|
||||
dataStream = [dataStream, typecast(single(control),'uint8')];
|
||||
|
||||
% Send DATA
|
||||
status = sendUDP(IP, port, dataStream);
|
||||
|
||||
status = sendUDP(dataStream, IP, port);
|
||||
|
||||
end
|
||||
|
||||
|
||||
@@ -42,16 +42,8 @@ function [ status ] = sendUDP( data, IP, port )
|
||||
end
|
||||
end
|
||||
|
||||
try
|
||||
IP = InetAddress.getByName(IP);
|
||||
packet = DatagramPacket(data, length(data), IP, port); %create packet
|
||||
socket.send(packet);
|
||||
catch err
|
||||
status = 1;
|
||||
disp(err)
|
||||
end
|
||||
|
||||
|
||||
|
||||
IP = InetAddress.getByName(IP);
|
||||
packet = DatagramPacket(data, length(data), IP, port); %create packet
|
||||
socket.send(packet);
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user