classdef SCDclass_taskmdscheckbusnames < SCDclass_task % This is a special class which checks the names % of a Simulink bus against the list names given by the tdi expression % some rules apply: % 1) : in MDS+ fields are subsituted by _ % 2) check is performed up to the minimum number of elemes either if the % MDS+ node or in the simulink one. % if MDS+ begins with a number, a leading 's' is added to its name % if MDS+ name is empty the check is skipped (Q: is it safe ?, at least not on -1 shot!) % for being MARTe compatible the list of channels names are retrieved % from MDS+ with the TDI consolidate() function (which must be present % server side) and all names are transferred as a single long string properties modelbus nelems end methods function obj=SCDclass_taskmdscheckbusnames(id, varargin) obj@SCDclass_task(id, varargin); obj.cparser.addRequired('modelbus',@(x) ischar(x)); obj.cparser.addRequired('nelems',@(x) (isnumeric(x) && x>0)); obj=obj.parseconstructorcommon(id, varargin); obj.modelbus=obj.cparser.Results.modelbus; obj.nelems=obj.cparser.Results.nelems; obj.classname=mfilename; obj.marteclassname='MDSParBusChecker'; end function init(obj, shot) mdsconnect(obj.mdsserver); mdsopen(obj.mdstree, shot); [obj,value]=obj.getdata(shot); if obj.verbose==1 fprintf('Checking bus: ''%s'' <-> ''%s'' (%s, shot %d)\n', obj.modelbus, obj.tdiexprused, obj.classname, shot); end d=Simulink.data.dictionary.open(sprintf('%s',obj.datadictionary)); dd=getSection(d, 'Design Data'); busElems=dd.getEntry(obj.modelbus).getValue.Elements; %% MDS+ string cell array buildup from the consolidated full string mdsnamelength = numel(value) / obj.nelems; cnt=1; for ii=1:numel(obj.nelems) mdsnames{ii}=value(cnt:cnt+mdsnamelength-1); cnt=cnt+mdsnamelength; end %% Original version, not compatible with MARTe % (C++ MDS+ thin client used there desn't support the retrieval % of array of strings) %assert(numel(busElems)==numel(value), 'SCDclass_mdscheckbus: Number of elements must match.'); lastcheck=min(numel(busElems), numel(mdsnames)); for ii=1:lastcheck if numel(char(mdsnames{ii}))==0 || numel(strfind(char(mdsnames{ii}),' '))==numel(char(mdsnames{ii})) continue end strsrc=upper(deblank(strrep(char(mdsnames{ii}),':','_'))); if(isstrprop(strsrc(1),'digit')) strsrc=['S' strsrc]; end strdst=upper(deblank(busElems(ii).Name)); assert(strcmp(strsrc,strdst), 'SCDclass_mdscheckbus: names mismatching, MDS+ name: ''%s'', Bus name: ''%s''', strsrc, strdst); end end %function term(obj, shot) % %end function [obj, value] = getdata(obj,shot) obj=obj.actualizegetcmd('mdsvalue(''consolidate(%s)'')', shot); value=eval(obj.getcommand); end function printinfo(obj) obj.printinfocommon; fprintf(' Checked model bus: %s\n',obj.modelbus); end function entrystring = genMARTe2entry(obj, shot) mdsconnect(obj.mdsserver); mdsopen(obj.mdstree, shot); [obj,value]=obj.getdata(shot); entrystring=obj.genMARTe2entrycommon(shot); entrystring=[entrystring 'NElems = ' num2str(obj.nelems) ' ']; entrystring=[entrystring 'Against = "' value]; entrystring=[entrystring '" }']; end end methods(Access=private) end end