Refactored MATLAB client to use the Java client internally.
- Still need to implement selectDATA for all languages.
This commit is contained in:
@@ -1,41 +1,40 @@
|
||||
function [socket] = openUDP(port, varargin)
|
||||
%openUDP Script that opens an UDP Socket
|
||||
function [ socket ] = openUDP(varargin)
|
||||
%openUDP Initializes a new instance of the XPC client and returns it.
|
||||
%
|
||||
%Inputs
|
||||
% port: UDP Port for socket
|
||||
% xpHost: The network host on which X-Plane is running.
|
||||
% xpPort: The port on which the X-Plane Connect plugin is listening.
|
||||
% port: The local port to use when sending and receiving data from XPC.
|
||||
% timeout (optional): Optional parameter for time to UDP timeout (in ms)
|
||||
%Outputs
|
||||
% Socket: UDP Socket
|
||||
% socket: An instance of the XPC client.
|
||||
%
|
||||
% Use
|
||||
% 1. import XPlaneConnect.*;
|
||||
% 2. Socket = openUDP(49005); %Open socket at port 49005 with timeout=0.1 sec
|
||||
% 2. socket = openUDP(); % Open a socket using the default settings
|
||||
% or
|
||||
% 2. Socket = openUDP(49005); %Open socket at port 49005 with timeout=0.2 sec
|
||||
% 2. Socket = openUDP('127.0.0.1', 49008, 49005); % Open a socket to connect to X-Plane on the local machine and receive data on port 49005
|
||||
%
|
||||
% Contributors
|
||||
% [CT] Christopher Teubert (SGT, Inc.)
|
||||
% christopher.a.teubert@nasa.gov
|
||||
%
|
||||
% To Do
|
||||
% 1. Verify Input
|
||||
%
|
||||
% BEGIN CODE
|
||||
% [JW] Jason Watkins
|
||||
% jason.w.watkins@nasa.gov
|
||||
|
||||
import java.net.DatagramSocket
|
||||
%% Handle input
|
||||
p = inputParser;
|
||||
addOptional(p,'xpHost','127.0.0.1',@ischar);
|
||||
addOptional(p,'xpPort',49009,@isnumeric);
|
||||
addOptional(p,'port',0,@isnumeric);
|
||||
parse(p,varargin{:});
|
||||
|
||||
%% create socket
|
||||
socket = DatagramSocket(port);
|
||||
socket.setSoTimeout(100);
|
||||
socket.setReceiveBufferSize(2000);
|
||||
%% Create client
|
||||
javaaddpath('XPlaneConnect.jar');
|
||||
import gov.nasa.xpc.*;
|
||||
socket = XPlaneConnect(p.Results.xpHost, p.Results.xpPort, p.Results.port);
|
||||
|
||||
%% interpret input
|
||||
if ~isempty(varargin)
|
||||
if isnumeric(varargin(1))
|
||||
socket.setSoTimeout(varargin(1));
|
||||
end
|
||||
end
|
||||
%% Track open clients
|
||||
global clients;
|
||||
clients = [clients, socket];
|
||||
|
||||
assert(isequal(socket.isClosed(),0),'openUDP: Error- Could not open port');
|
||||
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user