Fixed setConn function in MATLAB client

This commit is contained in:
Jason Watkins
2015-03-30 16:36:00 -07:00
parent c37256de51
commit 22cbf903b5
4 changed files with 24 additions and 13 deletions

View File

@@ -1,4 +1,4 @@
function [ data ] = readUDP( input )
function [ data ] = readUDP( varargin )
%readUDP Read Array from UDP Socket
%
% Inputs
@@ -36,9 +36,20 @@ function [ data ] = readUDP( input )
bits = 2000;
%% Interpret Input
socket = input;
if isnumeric(input)
socket=openUDP(input);
global udpReadPort;
if isempty(varargin)
if isempty(udpReadPort)
udpReadPort = 49008;
end
socket = openUDP(udpReadPort);
ownSocket = 1;
else
socket = varargin{1};
ownSocket = 0;
if isnumeric(varargin{1})
socket=openUDP(varargin{1});
ownSocket = 1;
end
end
%% Try reading packet
@@ -65,7 +76,7 @@ function [ data ] = readUDP( input )
end
%% Close Port (if opened in code)
if isnumeric(input)
if ownSocket
socket.close()
end
end

View File

@@ -24,7 +24,6 @@ import XPlaneConnect.*
message = zeros(1,6);
len = 7;
socket = openUDP(49008);
status = -1; %#ok<NASGU> % no data
%% Handle Input
@@ -51,7 +50,7 @@ parse(p,DREFArray,varargin{:});
% Look for response
for i=1:40
data = readUDP(socket);
data = readUDP();
if length(data) > 1 % Received Data
status = 0;
counter = 7;
@@ -66,6 +65,5 @@ parse(p,DREFArray,varargin{:});
else
result = cell(0,1);
end
end
closeUDP(socket);
end
end

View File

@@ -25,7 +25,7 @@ function status = setConn( recvPort, IP, port )
import XPlaneConnect.*
status = 0;
message = zeros(1,9);
message = zeros(1,7);
%% Handle Input
% Optional parameters
@@ -39,9 +39,12 @@ function status = setConn( recvPort, IP, port )
message(1:4) = 'CONN'-0;
% RecvPort
message(6:9) = typecast(uint32(recvPort),'uint8');
message(6:7) = typecast(uint16(recvPort),'uint8');
% Send
sendUDP(IP,port,message);
sendUDP(message,IP,port);
global udpReadPort;
udpReadPort = recvPort;
end

View File

@@ -1,6 +1,5 @@
function setConnTest( )
disp('Not Functional Yet!')
%setConnTest Summary of this function goes here
% Detailed explanation goes here
addpath('../../MATLAB')