
%

%   Copyright 2012 The MathWorks, Inc.

classdef ParametersSerial < coder.rtiostreamtest.Parameters
    %PARAMETERSSERIAL Serial communication parameters for
    %use with rtiostreamtest
    %   Sets the parameters required for testing a rtiostream connection
    %   over a serial connection
    
    properties (GetAccess = 'public', SetAccess = 'private')
        baud;
        COM;
    end
    
    methods
        
        function this = ParametersSerial(COM, baud)
        % Initialize the rtiostream implementation on a specified
        % com port with a specific baud-rate
        
            assert(ischar(COM), coder.rtiostreamtest.Test.message('ErrorPortNameNotChar'));
            
            % If it is a string, covert so it could be checked
            if ischar(baud)
                baud = str2double(baud);
                assert(~isnan(baud), coder.rtiostreamtest.Test.message('ErrorBaudRateString'));
            end
            
            % Convert the number back to string after checking
            if isnumeric(baud)
                assert(baud > 0 && baud == round(baud), ...
                    coder.rtiostreamtest.Test.message('ErrorBaudrateInvalid'));
                baud = num2str(baud);
            end
            
            % Make sure it is a string by the time we reach here
            assert(ischar(baud), coder.rtiostreamtest.Test.message('ErrorBaudrateInvalid'));
            
            % Assign for further usage
            this.COM = COM;
            this.baud = baud;
        end
        
        function [library, parameters] = getSharedLibrary(this)
            
            % Get the library
            library = ['libmwrtiostreamserial' ...
                system_dependent('GetSharedLibExt')];
            
            % Get the parameters
            parameters =  {'-port', this.COM, '-baud', this.baud};
            if isunix
                parameters = [parameters, '-postOpenPause', '3', '-verbose', '1'];
            end
        end
    end
    
end

