view m-toolbox/sltpda/getIOblockCommands.m @ 4:e3c5468b1bfe database-connection-manager

Integrate with LTPDAPreferences
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Mon, 05 Dec 2011 16:20:06 +0100
parents f0afece42f48
children
line wrap: on
line source

function cmds = getIOblockCommands(blocks)

% GETIOBLOCKCOMMANDS get a set of commands from a set of sLTPDA blocks.
% 
% M Hewitson 27-03-07
% 

disp('   + compiling IO block list');

cmds = [];

for j=1:length(blocks)
  
  b = blocks(j);
  
  blocktype  = get(b, 'blocktype');
  name       = get(b, 'Name');
  masktype   = get(b, 'MaskType');
  parent      = get(b, 'Parent');

  % split parent name to get block name
  idx = findstr('/', parent);
  blockname = strrep(parent(max(idx)+1:end), ' ', '_');
  
  % get my port number
  pn = get(b, 'Port');
  
  fcn = name;  
  fcn = sltpda_fixvar(fcn);
  
  % If I am an output port, map my line src to blockname_portnum
  switch blocktype
    case 'Outport'
            
      if ~isempty(blockname)
        l = get(b, 'LineHandles');
        l = get(l.Inport, 'Handle');
        % get src block name
        srcblock = get(l, 'SrcBlockHandle');
        sbname   = get(srcblock, 'Name');

        % get src port number
        srcport = get(l, 'SrcPortHandle');
        spn     = get(srcport, 'PortNumber');
        % Src variable
        svar = [ sbname '_out_' num2str(spn)];
        svar = [parent ' ' svar];
        svar = sltpda_reduceVarName(svar);
        svar = sltpda_fixvar(svar);
%         dvar = [ blockname '_out_' num2str(pn)];
        dvar = [ parent '_out_' num2str(pn)];
        dvar = sltpda_reduceVarName(dvar);
        dvar = sltpda_fixvar(dvar);
        cmd  = [dvar ' = ' svar ';'];

        % store info
        info.fcn    = '';
        info.params = [];
        info.plist  = plist();
        info.ins    = cellstr(svar);
        info.outs   = cellstr(dvar);
        info.outsUsed = [];
        info.cmd    = cmd;
        info.name   = get(b, 'Name');
        info.handle = get(b, 'Handle');
        info.ranges = [];

        cmds = [cmds info];
      end
    % If I am an input port, map my output to parent_name_in_N
    case 'Inport'
      
      svar = [ name '_out_' num2str(1)];
      svar = [parent ' ' svar];
      svar = sltpda_reduceVarName(svar);
      svar = sltpda_fixvar(svar);
      
      l = get(b, 'LineHandles');
      l = get(l.Inport, 'Handle');
      dvar = [ parent '_in_' num2str(pn)];      
      dvar = sltpda_reduceVarName(dvar);
      dvar = sltpda_fixvar(dvar);
      cmd = [svar ' = ' dvar ';'];

      % store info
      info.fcn    = '';
      info.params = [];
      info.plist  = plist();
      info.ins    = cellstr(dvar);
      info.outs   = cellstr(svar);
      info.outsUsed = [];
      info.cmd    = cmd;
      info.name   = get(b, 'Name');
      info.handle = get(b, 'Handle');
      info.ranges = [];

      cmds = [cmds info];
     
    otherwise
      warning('### Unknown block type');
  end
 
end