Playback CANape log in SIMULINK

by

 

A crude mechanism to playback CANape generated logs in SIMULINK environment.

assignvartowsblocks.m
%Author: Nitin Skandan , 27-feb-2013 
%http://www.linkedin.com/in/nitinskandan %

clc ;

clear;

% Extrac relevant signal info%
fname = uigetfile('*.mat', 'Pick an Drive cycle Mat-file');
eval(['load ' fname]);
cont = whos ;
[a,canname] = xlsread('cannames.xls');
k = 1 ;
for i=1:length(cont)
    name1 = cont(i).name ;
    for j = 1:length(canname)
		%%%%%%%%%%GV = identifier for global variables CAN = indentifier for CAN message, modify as needed%%%%
        if (isempty (findstr(name1, 'GV'))== 0 && isempty (findstr(name1, 'CAN'))~= 0)
            msgname{k} = name1 ;
            k = k+1 ;            
            break;
        end
        %%%%%%%%%%Any exempt conditions can be appended to if condition below%%%%%%%%%%%
		%%%% The default condition check neglects log variable whose name contians 'CH2' or 'XX' or if its name is less than 6 characters%%
        if ((isempty (findstr(name1, 'CH2'))== 0)|| (length(name1) < 6)|| (isempty (findstr(name1, 'XX'))== 0))
            break;
        end
        if(findstr(name1, canname{j}))            
            msgname{k} = name1 ;
            k = k+1 ;
        end
    end
end

%Assign names to workspace blocks in simulation model%
fname = uigetfile('*.mdl', 'Pick the simulation framework mdl file');
ahnd = find_system(get_param(gcs,'Handle'),'BlockType', 'FromWorkspace');

for i=1:length(ahnd)
    
    bname = get_param(ahnd(i),'Name');
    bname = [bname '_'];
    set_param(ahnd(i),'BackGroundColor', 'Red');
    set_param(ahnd(i),'SampleTime', '0.01') ; 
    set_param(ahnd(i),'Interpolate', 'on');
    set_param(ahnd(i),'OutputAfterFinalValue', 'Extrapolation');
    set_param(ahnd(i), 'VariableName', '[0 0]') ; %Default is 0
    
    for j=1:length(msgname)
        if(findstr(bname, msgname{j}))
           undscorepos = findstr( msgname{j}, '_');
           tname = msgname{j}(undscorepos(end)+1:end);
           wsstr = ['[' tname ' ' msgname{j} ']'] ;
           set_param(ahnd(i), 'VariableName', wsstr) ;
           set_param(ahnd(i),'OutputAfterFinalValue', 'Holding final value');
           set_param(ahnd(i),'BackGroundColor', 'White');
           break ;
        end
    end
end

Contact us