-% Copyright (C) 2013-2014 Czech Technical University in Prague
+% RPP_GENERATE_LIB Generates rpp_lib.slx library for the current target.
+
+% Copyright (C) 2013-2015 Czech Technical University in Prague
%
% Authors:
% - Michal Horn <hornmich@fel.cvut.cz>
% http://www.mathworks.com/help/matlab/ref/mex.html
% http://www.mathworks.com/help/matlab/matlab_external/custom-building-mex-files.html
-function rpp_generate_lib(varargin)
+function rpp_generate_lib()
+ blocks = rpp_get_blocks();
d = fullfile(getpref('rpp', 'TargetRoot'), '..', 'blocks');
cd(d)
-
- if nargin > 1,
- resultLibName = 'rpp_lib';
- generate_lib(resultLibName, varargin{1}, varargin);
- else
- error('Not enough arguments for the function.');
- end
-end
-function generate_lib(resultLibName, target, blocks)
- disp(['Generating library for target: ', target]);
- libFilePath=[target, '/', resultLibName, '.slx'];
- load_system(libFilePath);
- set_param(resultLibName, 'Lock', 'off');
- oldBlocks = find_system(resultLibName, 'Type', 'block');
+ try,
+ load_system('rpp_lib.slx');
+ catch ME
+ new_system('rpp_lib', 'Library');
+ end
+ set_param('rpp_lib', 'Lock', 'off');
+ oldBlocks = find_system('rpp_lib', 'Type', 'block');
disp('Removing old blocks:');
for j=1:length(oldBlocks),
disp([' ', oldBlocks{j}]);
delete_block(oldBlocks{j});
end
disp('Adding new blocks:');
- for j=2:length(blocks),
+ for j=1:length(blocks),
blockFilePath=[blocks{j}, '.slx'];
disp([' from: ', blockFilePath, ':']);
load_system(blockFilePath)
newBlocks = find_system(blocks{j}, 'Type', 'block');
for k=1:length(newBlocks),
[tok, blockName] = strtok(newBlocks{k}, '/');
- blockName = [resultLibName, blockName];
+ blockName = ['rpp_lib', blockName];
disp([' ', newBlocks{k}, ' as ', blockName]);
- add_block(newBlocks{k}, blockName);
+
+ % Copy rather than link blocks to rpp_lib. This is
+ % because we don't want rpp_update_blocks_for_target
+ % below to modify the original blocks.
+ add_block(newBlocks{k}, blockName, 'LinkStatus', 'none');
end
close_system(blockFilePath, 0);
end
- disp(['Closing and saving file ', libFilePath]);
- set_param(resultLibName, 'Lock', 'on');
- close_system(libFilePath, 1);
+
+ % Set ForwardingTable
+ mv = 9999.9999; %get_param('rpp_lib', 'ModelVersion');
+ ft = {
+ {'rpp_lib/General Purpose Digital Input', ...
+ 'rpp_lib/General Purpose Digital Input', ...
+ 0, mv, 'rpp_block_transform' },
+ {'rpp_lib/General Purpose Digital Output', ...
+ 'rpp_lib/General Purpose Digital Output', ...
+ 0, mv, 'rpp_block_transform' },
+ };
+ set_param('rpp_lib', 'ForwardingTable', ft);
+
+ rpp_update_blocks_for_target()
+
+ disp(['Closing and saving file ', 'rpp_lib.slx']);
+ set_param('rpp_lib', 'Lock', 'on');
+ save_system('rpp_lib');
+ close_system('rpp_lib.slx', 1);
end