-% 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>
%
-% This document contains proprietary information belonging to Czech
-% Technical University in Prague. Passing on and copying of this
-% document, and communication of its contents is not permitted
-% without prior written authorization.
+% Permission is hereby granted, free of charge, to any person
+% obtaining a copy of this software and associated documentation
+% files (the "Software"), to deal in the Software without
+% restriction, including without limitation the rights to use,
+% copy, modify, merge, publish, distribute, sublicense, and/or sell
+% copies of the Software, and to permit persons to whom the
+% Software is furnished to do so, subject to the following
+% conditions:
+
+% The above copyright notice and this permission notice shall be
+% included in all copies or substantial portions of the Software.
+
+% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+% EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+% OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+% NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+% HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+% WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+% FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+% OTHER DEALINGS IN THE SOFTWARE.
%
% File : rpp_generate_lib.m
% Abstract:
% 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
+ ft = {
+ {'rpp_lib/General Purpose Digital Input', ...
+ 'rpp_lib/General Purpose Digital Input', ...
+ '0.0', '9999.9999', 'rpp_block_transform' },
+ {'rpp_lib/General Purpose Digital Output', ...
+ 'rpp_lib/General Purpose Digital Output', ...
+ '0.0', '9999.9999', '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