Building Controls Virtual Test Bed
compile.m
Go to the documentation of this file.
1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2 % This file compiles the BSD socket interface for Simulink.
3 % It is called by ant.
4 %
5 % On Windows, it requires the Microsoft compiler
6 %
7 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8 % Note: We set the number of outputs to 1024, since matlab requires the
9 % size of output arrays to be fixed.
10 % If more elements are required,
11 % - change the entry y4[1024] in the assignment of 'funSpe' below,
12 % - change NDBLMAX=1024 in the file exchangeDoublesWithSocket.m,
13 % and
14 % - change the entry #define NDBLMAX 1024 in the file lib/defines.h
15 %
16 % Then, compile the matlab files by opening a development console.
17 % On Windows, this can be done by double-clicking the file
18 % bcvtb/bin/setDevelopmentEnvironment.bat. On Linux and Mac,
19 % this can be done by starting a terminal window and typing
20 % source bin/setDevelopmentEnvironment.sh
21 % from the BCVTB root directory. Next, type
22 % cd lib
23 % cd matlab
24 % ant clean all
25 % This will recompile all required files.
26 %
27 %
28 % Compile matlab library
29 % This creates a file bcvtb.m with the function prototypes.
30 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31 os=deblank(getenv('BCVTB_OS'));
32 if (strcmp(os,'windows')) % have Windows
33  LIBBCVTB='..\util\bcvtb';
34 elseif (strcmp(os,'mac'))
35  LIBBCVTB='../util/libbcvtb.dylib';
36 else
37  LIBBCVTB='../util/libbcvtb.so';
38 end
39 incPat = [pwd, '/..'];
40 loadlibrary(LIBBCVTB, ...
41  'matlabSocket.h', ...
42  'includepath', './..', ...
43  'mfilename', 'bcvtb.m')
44 
45 % -------------------------------------------------------------------
46 % Check if Simulink is installed on this system. If Simulink is
47 % is not installed, exit. Otherwise, continue and compile
48 % simulink libraries.
49 retVal=which('simulink');
50 if strcmp(retVal, '')
51  disp('Simulink is not installed on this computer.')
52  disp('The Simulink library will not be compiled.')
53 else
54 
55  makeSBlock=false;
56  modelName = 'BSDSocket';
57 
58  def=legacy_code('initialize');
59  def.SourceFiles={'simulinkSocket.c'};
60  def.HeaderFiles={'simulinkSocket.h'};
61  def.SampleTime = 'inherited';
62 
63  funNam = {'establishBSDSocket', 'exchangeDoublesWithBSDSocket', 'closeBSDSocket'};
64  funSpe = {'int16 y1 = establishBSDSocket(int16 u1[1])', ...
65  'int16 y1 = exchangeDoublesWithBSDSocket(int16 u1[1], int16 u2[1], int16 y2[1], int16 u3[1], double u4[1], double u5[], double y3[1], double y4[1024])', ...
66  'int16 y1 = closeBSDSocket(int16 u1[1], int16 u2[1])'};
67 
68 
69  for i=1:3
70  def.SFunctionName = char(funNam(i));
71  def.OutputFcnSpec = char(funSpe(i));
72  disp('*** Generating mex file')
73  legacy_code('sfcn_cmex_generate', def)
74  disp('*** Compiling code')
75  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
76  %%%%%%%%%%% fix from Mathworks (email from 2/7/08)
77  fschange('');
78  %% FSCHANGE is a Mathworks internal function that is used
79  %% for troubleshooting purposes. It takes the name of a directory
80  %% as an input and forces the MATLAB path manager to
81  %% recheck the contents of the directory to check for
82  %% new (or deleted) files. When an empty string is
83  %% passed as an input the entire path is rechecked.
84  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
85  try
86  % Compilation for Windows
87  if (strcmp(os, 'windows')) % have Windows
88  disp('*** Compiling MATLAB interface for Windows')
89  legacy_code('compile', def, {'../util/bcvtb.lib', '-I../util', '-I..'})
90  else
91  % Compilation for Mac OS X and Linux
92  disp('*** Compiling MATLAB interface for Mac OS X or Linux')
93 
94  legacy_code('compile', def, {'-lxml2', '-I..', '-L../util', '-lbcvtb'})
95  end
96  catch ME
97  disp('*** Error when compiling MATLAB interface ***')
98  disp(getReport(ME, 'extended'))
99  disp('*** Exit with error.')
100  exit(1)
101  end
102 
103  disp('*** Returned from legacy_code')
104  if makeSBlock
105  disp('*** Generating Simulink block')
106  try
107  legacy_code('slblock_generate', def, modelName)
108  catch ME
109  disp('*** Error when generating Simulink interface ***')
110  disp(getReport(ME, 'extended'))
111  disp('*** Exit with error.')
112  exit(1)
113  end
114  end
115  % delete the files that we no longer need
116  fn = [char(funNam(i)), '.c'];
117  delete(fn)
118  end
119 end
120 exit;
for i
Definition: compile.m:69
exchanges data with the BCVTB The input arguments are
getenv('BCVTB_OS' deblank()
loadlibrary(LIBBCVTB,... 'matlabSocket.h',... 'includepath', './..',... 'mfilename', 'bcvtb.m')%-------------------------------------------------------------------%Check if Simulink is installed on this system.If Simulink is%is not installed
funNam
Definition: compile.m:63
def
Definition: compile.m:58
function sockfd will be a positive integer for the socket file descriptor In case of error
elseif(strcmp(os,'mac')) LIBBCVTB
FSCHANGE is a Mathworks internal function that is used for troubleshooting purposes It takes the name of a directory as an input and forces the MATLAB path manager to recheck the contents of the directory to check for new(or deleted) files.When an empty string is%%passed as an input the entire path is rechecked.%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%Compilation for Windows if(strcmp(os
This file compiles the BSD socket interface for Simulink It is called by ant On it requires the Microsoft compiler Note
Definition: compile.m:5
end Establish the socket connection if and(libisloaded(BCVTBLIB),(status==1)) sockfd
static void XMLCALL end(void *data, const char *el)
Call back functions that will be used by the expat xml parser.
Definition: util/utilXml.c:707
This file compiles the BSD socket interface for Simulink It is called by ant On it requires the Microsoft compiler since matlab requires the size of output arrays to be fixed If more elements are required
Definition: compile.m:5
if(strcmp(os,'windows'))%have Windows LIBBCVTB
else LIBBCVTB
Definition: compile.m:37
exit Otherwise
Definition: compile.m:47
This file compiles the BSD socket interface for Simulink It is called by ant On Windows
Definition: compile.m:5
funSpe
Definition: compile.m:64
modelName
Definition: compile.m:56
exit continue and compile simulink libraries retVal
Definition: compile.m:49
#define NDBLMAX
Maximum number of double values that can be exchanged by Simulink.
Definition: defines.h:33
function[retVal, flaRea, simTimRea, dblValRea]
function if the BCVTB library can be loaded and if sockfd is not a negative number
Definition: processError.m:1
delete(fn) end end exit
def SourceFiles
Definition: compile.m:59
FSCHANGE is a Mathworks internal function that is used for troubleshooting purposes It takes the name of a directory as an input and forces the MATLAB path manager to recheck the contents of the directory to check for windows have Windows c
Definition: compile.m:89
end incPat
Definition: compile.m:39
int source
flag for function /c getepvariables 0=EnergyPlus, 1=Ptolemy
Definition: util/utilXml.h:158
disp('***Generating mex file') legacy_code('sfcn_cmex_generate'
if strcmp(retVal, '') disp('Simulink is not installed on this computer.') disp('The Simulink library will not be compiled.') else makeSBlock