]> rtime.felk.cvut.cz Git - pes-rpp/rpp-simulink.git/blob - rpp/blocks/rpp_generate_lib.m
dd899552f90bdb1aa5e51488af072a05d86160d7
[pes-rpp/rpp-simulink.git] / rpp / blocks / rpp_generate_lib.m
1 % RPP_GENERATE_LIB  Generates rpp_lib.slx library for the current target.
2
3 % Copyright (C) 2013-2015 Czech Technical University in Prague
4 %
5 % Authors:
6 %     - Michal Horn <hornmich@fel.cvut.cz>
7 %
8 % This document contains proprietary information belonging to Czech
9 % Technical University in Prague. Passing on and copying of this
10 % document, and communication of its contents is not permitted
11 % without prior written authorization.
12 %
13 % File : rpp_generate_lib.m
14 % Abstract:
15 %     Generates library rpp_lib.slx for targets
16 %
17 % References:
18 %     http://www.mathworks.com/help/matlab/ref/mex.html
19 %     http://www.mathworks.com/help/matlab/matlab_external/custom-building-mex-files.html
20
21 function rpp_generate_lib()
22     blocks = rpp_get_blocks();
23         d = fullfile(getpref('rpp', 'TargetRoot'), '..', 'blocks');
24         cd(d)
25
26     try,
27         load_system('rpp_lib.slx');
28     catch ME
29         new_system('rpp_lib', 'Library');
30     end
31         set_param('rpp_lib', 'Lock', 'off');
32         oldBlocks = find_system('rpp_lib', 'Type', 'block');
33         disp('Removing old blocks:');
34         for j=1:length(oldBlocks),
35                 disp(['    ', oldBlocks{j}]);
36                 delete_block(oldBlocks{j});
37         end
38         disp('Adding new blocks:');
39         for j=1:length(blocks),
40                 blockFilePath=[blocks{j}, '.slx'];
41                 disp(['    from: ', blockFilePath, ':']);
42                 load_system(blockFilePath)
43                 newBlocks = find_system(blocks{j}, 'Type', 'block');
44                 for k=1:length(newBlocks),
45                         [tok, blockName] = strtok(newBlocks{k}, '/');
46                         blockName = ['rpp_lib', blockName];
47                         disp(['        ', newBlocks{k}, ' as ', blockName]);
48
49                         % Copy rather than link blocks to rpp_lib. This is
50                         % because we don't want rpp_update_blocks_for_target
51                         % below to modify the original blocks.
52                         add_block(newBlocks{k}, blockName, 'LinkStatus', 'none');
53                 end
54                 close_system(blockFilePath, 0);
55         end
56
57     % Set ForwardingTable
58     ft = {
59             {'rpp_lib/General Purpose Digital Input', ...
60              'rpp_lib/General Purpose Digital Input', ...
61              '0.0', '9999.9999', 'rpp_block_transform' },
62             {'rpp_lib/General Purpose Digital Output', ...
63              'rpp_lib/General Purpose Digital Output', ...
64              '0.0', '9999.9999', 'rpp_block_transform' },
65          };
66         set_param('rpp_lib', 'ForwardingTable', ft);
67
68         rpp_update_blocks_for_target()
69
70         disp(['Closing and saving file ', 'rpp_lib.slx']);
71         set_param('rpp_lib', 'Lock', 'on');
72     save_system('rpp_lib');
73         close_system('rpp_lib.slx', 1);
74 end