]> rtime.felk.cvut.cz Git - jenkicar/rpp-simulink.git/blob - rpp/blocks/rpp_generate_lib.m
Don't modify original blocks in rpp_update_blocks_for_target
[jenkicar/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     mv = 9999.9999; %get_param('rpp_lib', 'ModelVersion');
59     ft = {
60             {'rpp_lib/General Purpose Digital Input', ...
61              'rpp_lib/General Purpose Digital Input', ...
62              0, mv, 'rpp_block_transform' },
63             {'rpp_lib/General Purpose Digital Output', ...
64              'rpp_lib/General Purpose Digital Output', ...
65              0, mv, 'rpp_block_transform' },
66          };
67         set_param('rpp_lib', 'ForwardingTable', ft);
68
69         rpp_update_blocks_for_target()
70
71         disp(['Closing and saving file ', 'rpp_lib.slx']);
72         set_param('rpp_lib', 'Lock', 'on');
73     save_system('rpp_lib');
74         close_system('rpp_lib.slx', 1);
75 end