
%

%   Copyright 2012 The MathWorks, Inc.

classdef ParametersUDP < coder.rtiostreamtest.ParametersTCP
    %PARAMETERSUDP UDP parameters for use with
    %rtiostreamtest
    %   Sets the parameters required for testing a rtiostream connection
    %   over a UDP connection
    
    properties (GetAccess = 'public', SetAccess = 'private')
        lossDetection;
    end
    
    methods
        
        function this = ParametersUDP(host, ...
                port, lossDetection)
            % Initialize the rtiostream tcpip implementation on a specified
            % host and port. Set lossDetection to true to enable loss detection
            % mode.
            if nargin == 2
                lossDetection = false;
            end
            
            this = this@coder.rtiostreamtest.ParametersTCP(host, port);
            this.lossDetection = lossDetection;
        end
        
        function [library, parameters] = getSharedLibrary(this)
            
            % Get the library
            library = ['libmwrtiostreamtcpip' ...
                system_dependent('GetSharedLibExt')];
            
            % Get the parameters
            %                        
            % Run in 10ms blocking mode to avoid high CPU load without
            % affecting the buffer detection algorithm
            if this.lossDetection
                parameters =  {...
                    '-client', '1', ...
                    '-blocking', '1', '-recv_timeout_secs', '-3', ...
                    '-port', this.port, ...
                    '-hostname', this.host, ...
                    '-protocol', 'UDP_PACKET_LOSS_DETECTION' ...
                    };
            else
                parameters =  {...
                    '-client', '1', ...
                    '-blocking', '1', '-recv_timeout_secs', '-3', ...
                    '-port', this.port, ...
                    '-hostname', this.host, ...
                    '-protocol', 'UDP' ...
                    };
            end
        end
    end
    
    methods (Access = protected)
        
        function parameters = getSymmetricParameters(~)
            parameters = {'default_chunks', [1 4 16 128 512 2048 4096]};
        end
        
        function parameters = getBufferDetectionParameters(~)
            % Note: a smaller MATLAB sending size (pcSize) ends up
            % transmitting more UDP packets which take up extra socket
            % receive buffer space.   Therefore, we increase pcSize from
            % its default in order to reduce the socket receive overhead.
            %
            % The actual socket receive size of rtiostream_tcpip.c may be
            % platform dependent but should be ~256KB or higher.    Here,
            % we're only sending 100K, to make the test run relatively
            % quickly, so we expect to be told the buffer size is greater
            % than 100KB.
            parameters = {'sizeB', 100*1024, ...
                          'incrementalStart', false, ...
                          'pcSize', 1024};
        end
    end
    
end

