Fixed setConn function in MATLAB client
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
function [ data ] = readUDP( input )
|
function [ data ] = readUDP( varargin )
|
||||||
%readUDP Read Array from UDP Socket
|
%readUDP Read Array from UDP Socket
|
||||||
%
|
%
|
||||||
% Inputs
|
% Inputs
|
||||||
@@ -36,9 +36,20 @@ function [ data ] = readUDP( input )
|
|||||||
bits = 2000;
|
bits = 2000;
|
||||||
|
|
||||||
%% Interpret Input
|
%% Interpret Input
|
||||||
socket = input;
|
global udpReadPort;
|
||||||
if isnumeric(input)
|
if isempty(varargin)
|
||||||
socket=openUDP(input);
|
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
|
end
|
||||||
|
|
||||||
%% Try reading packet
|
%% Try reading packet
|
||||||
@@ -65,7 +76,7 @@ function [ data ] = readUDP( input )
|
|||||||
end
|
end
|
||||||
|
|
||||||
%% Close Port (if opened in code)
|
%% Close Port (if opened in code)
|
||||||
if isnumeric(input)
|
if ownSocket
|
||||||
socket.close()
|
socket.close()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ import XPlaneConnect.*
|
|||||||
|
|
||||||
message = zeros(1,6);
|
message = zeros(1,6);
|
||||||
len = 7;
|
len = 7;
|
||||||
socket = openUDP(49008);
|
|
||||||
status = -1; %#ok<NASGU> % no data
|
status = -1; %#ok<NASGU> % no data
|
||||||
|
|
||||||
%% Handle Input
|
%% Handle Input
|
||||||
@@ -51,7 +50,7 @@ parse(p,DREFArray,varargin{:});
|
|||||||
|
|
||||||
% Look for response
|
% Look for response
|
||||||
for i=1:40
|
for i=1:40
|
||||||
data = readUDP(socket);
|
data = readUDP();
|
||||||
if length(data) > 1 % Received Data
|
if length(data) > 1 % Received Data
|
||||||
status = 0;
|
status = 0;
|
||||||
counter = 7;
|
counter = 7;
|
||||||
@@ -66,6 +65,5 @@ parse(p,DREFArray,varargin{:});
|
|||||||
else
|
else
|
||||||
result = cell(0,1);
|
result = cell(0,1);
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
closeUDP(socket);
|
|
||||||
end
|
end
|
||||||
@@ -25,7 +25,7 @@ function status = setConn( recvPort, IP, port )
|
|||||||
import XPlaneConnect.*
|
import XPlaneConnect.*
|
||||||
|
|
||||||
status = 0;
|
status = 0;
|
||||||
message = zeros(1,9);
|
message = zeros(1,7);
|
||||||
|
|
||||||
%% Handle Input
|
%% Handle Input
|
||||||
% Optional parameters
|
% Optional parameters
|
||||||
@@ -39,9 +39,12 @@ function status = setConn( recvPort, IP, port )
|
|||||||
message(1:4) = 'CONN'-0;
|
message(1:4) = 'CONN'-0;
|
||||||
|
|
||||||
% RecvPort
|
% RecvPort
|
||||||
message(6:9) = typecast(uint32(recvPort),'uint8');
|
message(6:7) = typecast(uint16(recvPort),'uint8');
|
||||||
|
|
||||||
% Send
|
% Send
|
||||||
sendUDP(IP,port,message);
|
sendUDP(message,IP,port);
|
||||||
|
|
||||||
|
global udpReadPort;
|
||||||
|
udpReadPort = recvPort;
|
||||||
|
|
||||||
end
|
end
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
function setConnTest( )
|
function setConnTest( )
|
||||||
|
|
||||||
disp('Not Functional Yet!')
|
|
||||||
%setConnTest Summary of this function goes here
|
%setConnTest Summary of this function goes here
|
||||||
% Detailed explanation goes here
|
% Detailed explanation goes here
|
||||||
addpath('../../MATLAB')
|
addpath('../../MATLAB')
|
||||||
|
|||||||
Reference in New Issue
Block a user