diff m-toolbox/sltpda/getIOblockCommands.m @ 0:f0afece42f48

Import.
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Wed, 23 Nov 2011 19:22:13 +0100
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/m-toolbox/sltpda/getIOblockCommands.m	Wed Nov 23 19:22:13 2011 +0100
@@ -0,0 +1,103 @@
+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
\ No newline at end of file