source: ResearchApps/PHY/WARPLAB/WARPLab7/M_Code_Reference/mex/wl_mex_udp_transport.m

Last change on this file was 4313, checked in by welsh, 6 years ago

Initial update to make the automatic compiler option more generic.

File size: 7.1 KB
Line 
1% WARPLab MEX UDP Transport
2%
3%     This function is a custom MEX UDP transport layer for WARPLab communication.
4%     It can be called with different options / commands to perform different
5%     functions.
6%
7% -----------------------------------------------------------------------------
8% Authors:  Chris Hunter (chunter [at] mangocomm.com)
9%           Patrick Murphy (murphpo [at] mangocomm.com)
10%           Erik Welsh (welsh [at] mangocomm.com)
11% License:  Copyright 2013, Mango Communications. All rights reserved.
12%           Distributed under the WARP license  (http://warpproject.org/license)
13% -----------------------------------------------------------------------------
14% Command Syntax
15%
16% Standard WARPLab transport functions:
17%     1.                  wl_mex_udp_transport('version')
18%     2. index          = wl_mex_udp_transport('init_socket')
19%     3.                  wl_mex_udp_transport('set_so_timeout', index, timeout)
20%     4.                  wl_mex_udp_transport('set_send_buf_size', index, size)
21%     5. size           = wl_mex_udp_transport('get_send_buf_size', index)
22%     6.                  wl_mex_udp_transport('set_rcvd_buf_size', index, size)
23%     7. size           = wl_mex_udp_transport('get_rcvd_buf_size', index)
24%     8.                  wl_mex_udp_transport('close', index)
25%     9. size           = wl_mex_udp_transport('send', index, buffer, length, ip_addr, port)
26%    10. [size, buffer] = wl_mex_udp_transport('receive', index, length )
27%
28% Additional WARPLab MEX UDP transport functions:
29%     1. [num_samples, cmds_used, samples]  = wl_mex_udp_transport('read_rssi' / 'read_iq',
30%                                                 index, buffer, length, ip_addr, port,
31%                                                 number_samples, buffer_id, start_sample)
32%     2. cmds_used                          = wl_mex_udp_transport('write_iq',
33%                                                 index, cmd_buffer, max_length, ip_addr, port,
34%                                                 number_samples, sample_buffer, buffer_id,
35%                                                 start_sample, num_pkts, max_samples, hw_ver)
36%
37% Please refer to comments within wl_mex_udp_transport.c for more information.
38%
39% -----------------------------------------------------------------------------
40% Compiling MEX
41%
42% Please see the on-line documentation for how to compile WARPLab MEX functions at:
43%    http://warpproject.org/trac/wiki/WARPLab/MEX
44%
45% The compile command within MATLAB is:
46%
47%    Windows:
48%        mex -g -O wl_mex_udp_transport.c -lwsock32 -lKernel32 -DWIN32
49%
50%    MAC / Unix:
51%        mex -g -O wl_mex_udp_transport.c
52%
53
54if ( ispc ) 
55
56    % Allow both manual and automatic compilation on Windows
57    %
58    fprintf('WARPLab wl_mex_udp_transport Setup\n');
59    fprintf('    Would you like [1] Manual (default) or [2] Automatic compilation?\n');
60    temp = input('    Selection: ');
61
62    if(isempty(temp))
63        temp = 1;
64    end
65
66    if( ( temp > 2 ) || ( temp < 1 ) )
67        temp = 1;
68        fprintf('Invalid selection.  Setting to Manual.\n\n'); 
69    end
70
71else
72   
73    % Only allow manual compilation on MAC / UNIX
74    %
75    temp = 1; 
76end
77
78switch( temp ) 
79    case 1
80
81        fprintf('\nManual Compilation Steps:  \n');
82        fprintf('    1) Please familiarize yourself with the process at: \n');
83        fprintf('         http://warpproject.org/trac/wiki/WARPLab/MEX \n');
84        fprintf('       to make sure your environment is set up properly. \n');
85        fprintf('    2) Set up mex to choose your compiler.  (mex -setup) \n');
86       
87        if ( ispc )
88            fprintf('         1. Select "Yes" to have mex locate installed compilers \n');
89            fprintf('         2. Select "Microsoft Visual C++ 2010 Express" \n');
90            fprintf('         3. Select "Yes" to verify your selections \n');
91        else
92            fprintf('         1. Select "/Applications/MATLAB_R2013a.app/bin/mexopts.sh : \n');
93            fprintf('                    Template Options file for building MEX-files" \n');
94            fprintf('         2. If necessary, overwrite:  /Users/<username>/.matlab/R2013a/mexopts.sh \n');
95        end
96       
97        fprintf('    3) Change directory to M_Code_Reference/mex (cd mex) \n');
98        fprintf('    4) Run the compile command: \n');
99       
100        if ( ispc )
101            fprintf('         mex -g -O wl_mex_udp_transport.c -lwsock32 -lKernel32 -DWIN32 \n');
102        else
103            fprintf('         mex -g -O wl_mex_udp_transport.c \n');
104        end
105       
106        fprintf('    5) Re-run wl_setup and make sure that "WARPLab Mex UDP" is an available transport. \n');
107        fprintf('\n');
108       
109    case 2
110        fprintf('\nRunning Automatic Setup procedure: ...');
111       
112        compiler_error = false;
113
114        % Procedure to compile mex
115        try 
116            cc = mex.getCompilerConfigurations('c');
117        catch ccError
118            compiler_error = true;
119        end
120
121        if ( ~compiler_error )       
122            fprintf('\nCompiling the WARPLab MEX UDP transport with compiler: \n    %s\n', cc.Name);
123       
124            % Since we are not guaranteed to be in the .../M_Code_Reference directory,
125            % save the current path and then cd using absolute paths
126            %
127            curr_path       = pwd;
128            [wl_path,ig,ig] = fileparts(which('wl_mex_udp_transport'));
129       
130            cd(sprintf('%s',wl_path));
131           
132            if ( ispc )
133                mex -g -O wl_mex_udp_transport.c -lwsock32 -lKernel32 -DWIN32
134            else
135                mex -g -O wl_mex_udp_transport.c
136            end
137           
138            cd(sprintf('%s',curr_path));
139           
140            clear
141            fprintf('Done. \n\n');
142            fprintf('***************************************************************\n');
143            fprintf('***************************************************************\n');
144            fprintf('Please re-run wl_setup to use your "WARPLab Mex UDP" transport.\n');
145            fprintf('***************************************************************\n');
146            fprintf('***************************************************************\n');
147        else
148            fprintf('\nMEX Compiler not found.  Running mex setup: \n');
149            mex -setup
150           
151            try
152                cc = mex.getCompilerConfigurations('c');
153            catch ccError           
154                error('Error with MEX compiler.\nSee http://warpproject.org/trac/wiki/WARPLab/MEX for more information');
155            end
156           
157            fprintf('******************************************************************************\n');
158            fprintf('******************************************************************************\n');
159            fprintf('Please re-run wl_mex_udp_transport to compile the "WARPLab Mex UDP" transport.\n');
160            fprintf('******************************************************************************\n');
161            fprintf('******************************************************************************\n');
162        end
163   
164    otherwise
165        error('Invalid selection.');
166end
Note: See TracBrowser for help on using the repository browser.