% 参数配置
%模型名称
modelName='BIC_Sample';
%excel表格的地址
excelFileName='D:\Workspace\04_软件接口表\ASW_Interfaces_C1_0_1.xlsx';
% 表格列表属性
sheetName='Port interface ';
portName='Port Name';
portType='Port Type';
dataType='DataType';
dimension='Dimensions';
[~,~,raw]=xlsread(excelFileName,sheetName);
rawSize =size(raw);
clearvars sheetName excelFileName;
%识别模块以及属性所在的列
for i=1:rawSize(2)
if strfind(raw{2,i},modelName)
ModelNameIndex=i;
end
if strcmp(raw{1,i},portName)
PortNameIndex=i;
end
if strcmp(raw{1,i},portType)
PortTypeIndex=i;
end
if strcmp(raw{1,i},dataType)
DataTypeIndex=i;
end
if strcmp(raw{1,i},dimension)
DimenIndex=i;
end
end
clearvars portName portType dataType dimension;
%Excel获取输入S/R接口
ExcelSRInput{1,1}='Excel信号名称';
ExcelSRInput{1,2}='Excel信号数据类型';
ExcelSRInput{1,3}='Excel信号数据维度';
Num=2;
for i=3:rawSize(1)
if strcmp(raw{i,ModelNameIndex},'I') && strcmp(raw{i,PortTypeIndex},'SR')
ExcelSRInput{Num,1}=raw{i,PortNameIndex};
ExcelSRInput{Num,2}=raw{i,DataTypeIndex};
ExcelSRInput{Num,3}=raw{i,DimenIndex};
Num=Num+1;
end
end
%Excel获取输出S/R接口
ExcelSROutput{1,1}='Excel信号名称';
ExcelSROutput{1,2}='Excel信号数据类型';
ExcelSROutput{1,3}='Excel信号数据维度';
Num=2;
for i=3:rawSize(1)
if strcmp(raw{i,ModelNameIndex},'O') && strcmp(raw{i,PortTypeIndex},'SR')
ExcelSROutput{Num,1}=raw{i,PortNameIndex};
ExcelSROutput{Num,2}=raw{i,DataTypeIndex};
ExcelSROutput{Num,3}=raw{i,DimenIndex};
Num=Num+1;
end
end
%Excel获取输出C/S接口
ExcelCSPort{1,1}='Excel信号名称';
ExcelCSPort{1,2}='Excel信号数据类型';
ExcelCSPort{1,3}='Excel信号数据维度';
Num=2;
for i=3:rawSize(1)
if (strcmp(raw{i,ModelNameIndex},'I')||strcmp(raw{i,ModelNameIndex},'O')) && strcmp(raw{i,PortTypeIndex},'CS')
ExcelCSPort{Num,1}=raw{i,PortNameIndex};
ExcelCSPort{Num,2}=raw{i,DataTypeIndex};
ExcelCSPort{Num,3}=raw{i,DimenIndex};
Num=Num+1;
end
end
clearvars ModelNameIndex PortNameIndex DataTypeIndex DimenIndex PortTypeIndex raw rawSize;
% 获取模型
load_system(modelName);
%获取SR输入接口
SRInpath=find_system(modelName,'SearchDepth',1,'BlockType','Inport');
SRInName=get_param(SRInpath,'Name');
SRInDataType=get_param(SRInpath,'OutDataTypeStr');
SRInDimensions=get_param(SRInpath,'PortDimensions');
SRInFunctioncall=get_param(SRInpath,'OutputFunctionCall');
ModelSRInput{1,1}='SRInPortName';
ModelSRInput{1,2}='DataType';
ModelSRInput{1,3}='PortDimensions';
ModelSRInput{1,4}='OutputFunctionCall';
Num=2;
for i=1:length(SRInpath)
if strcmp(SRInFunctioncall{i},'on')
continue;
end
blockNameArray=char(SRInName{i});
ModelSRInput{Num,1}=blockNameArray(1:(length(blockNameArray)-1)/2);
ModelSRInput{Num,2}=SRInDataType{i};
ModelSRInput{Num,3}=SRInDimensions{i};
ModelSRInput{Num,4}=SRInFunctioncall{i};
Num=Num+1;
end
clearvars SRInpath SRInName SRInDataType SRInDimensions SRInFunctioncall;
%获取SR输出接口
SROutPath=find_system(modelName,'SearchDepth',1,'BlockType','Outport');
SROutName=get_param(SROutPath,'Name');
SROutDataType=get_param(SROutPath,'OutDataTypeStr');
SROutDimensions=get_param(SROutPath,'PortDimensions');
ModelSROnput{1,1}='SROutPortName';
ModelSROnput{1,2}='DataType';
ModelSROnput{1,3}='PortDimensions';
Num=2;
for i=1:length(SROutPath)
blockNameArray=char(SROutName{i});
ModelSROnput{Num,1}=blockNameArray(1:(length(blockNameArray)-1)/2);
ModelSROnput{Num,2}=SROutDataType{i};
ModelSROnput{Num,3}=SROutDimensions{i};
Num=Num+1;
end
clearvars SROutPath SROutName SROutDataType SROutDimensions;
%获取CS输出接口
CSPath=find_system(modelName,'FindAll','on','BlockType','FunctionCaller');
CSName=get_param(CSPath,'Name');
ModelCSPort{1,1}='SROutPortName';
Num=2;
for i=1:length(CSPath)
ModelCSPort{Num,1}=CSName{i};
Num=Num+1;
end
clearvars CSPath CSName modelName;
% Excel表格和模型的对比
% 测试报告
TestResultSummary{1,1}='接口名称';
TestResultSummary{1,2}='数据类型';
TestResultSummary{1,3}='维度';
TestResultSummary{1,4}='接口类型';
TestResultSummary{1,5}='测试结果';
TestResultSummary{1,6}='差异项';
Num=2;
ExcelSRinputSize=size(ExcelSRInput);
ModelSRinputSize=size(ModelSRInput);
%SR输入接口的对比
for i=2:ExcelSRinputSize(1)
CheckSameFlag=0;
for j=2:ModelSRinputSize(1)
if ~strcmp(ModelSRInput{j,1},ExcelSRInput{i,1})
continue;
elseif strcmp(ExcelSRInput{i,2},ModelSRInput{j,2})&&strcmp(num2str(ExcelSRInput{i,3}),ModelSRInput{j,3})
CheckSameFlag=1;
break;
else
break;
end
end
TestResultSummary{Num,1}=ExcelSRInput{i,1};
TestResultSummary{Num,2}=ExcelSRInput{i,2};
TestResultSummary{Num,3}=num2str(ExcelSRInput{i,3});
TestResultSummary{Num,4}='SR';
if CheckSameFlag
TestResultSummary{Num,5}='Passed';
TestResultSummary{Num,6}='NA';
else
TestResultSummary{Num,5}='Failed';
if isempty(strfind(ModelSRInput{j,1},ExcelSRInput{i,1}))
TestResultSummary{Num,6}='模型不存在接口';
elseif ~strcmp(ExcelSRInput{i,2},ModelSRInput{j,2})
TestResultSummary{Num,6}=['数据类型差异:',ModelSRInput{j,2}];
elseif ~strcmp(num2str(ExcelSRInput{i,3}),ModelSRInput{j,3})
TestResultSummary{Num,6}=['数据维度差异:',ModelSRInput{j,3}];
end
end
Num=Num+1;
end
clearvars ModelSRInput ExcelSRInput ExcelSRinputSize ModelSRinputSize;
%SR输出接口的对比
ExcelSRoutputSize=size(ExcelSROutput);
ModelSRoutputSize=size(ModelSROnput);
for i=2:ExcelSRoutputSize(1)
CheckSameFlag=0;
for j=2:ModelSRoutputSize(1)
if ~strcmp(ModelSROnput{j,1},ExcelSROutput{i,1})
continue;
elseif strcmp(ExcelSROutput{i,2},ModelSROnput{j,2})&&strcmp(num2str(ExcelSROutput{i,3}),ModelSROnput{j,3})
CheckSameFlag=1;
break;
else
break;
end
end
TestResultSummary{Num,1}=ExcelSROutput{i,1};
TestResultSummary{Num,2}=ExcelSROutput{i,2};
TestResultSummary{Num,3}=num2str(ExcelSROutput{i,3});
TestResultSummary{Num,4}='SR';
if CheckSameFlag
TestResultSummary{Num,5}='Passed';
TestResultSummary{Num,6}='NA';
else
TestResultSummary{Num,5}='Failed';
if isempty(strfind(ModelSROnput{j,1},ExcelSROutput{i,1}))
TestResultSummary{Num,6}='模型不存在接口';
elseif ~strcmp(ExcelSROutput{i,2},ModelSROnput{j,2})
TestResultSummary{Num,6}=['数据类型差异:',ModelSROnput{j,2}];
elseif ~strcmp(num2str(ExcelSROutput{i,3}),ModelSROnput{j,3})
TestResultSummary{Num,6}=['数据维度差异:',ModelSROnput{j,3}];
end
end
Num=Num+1;
end
clearvars ExcelSRoutputSize ModelSRoutputSize ExcelSROutput ModelSROnput;
%CS输出接口的对比
ExcelCSPortSize=size(ExcelCSPort);
ModelCSPortSize=size(ModelCSPort);
for i=2:ExcelCSPortSize(1)
CheckSameFlag=0;
DTCFlag=0;
if strfind(ExcelCSPort{i,1},'DTC')
ExcelPortName=ExcelCSPort{i,1};
ExcelDID=ExcelPortName(8:end);
DTCFlag=1;
end
for j=2:ModelCSPortSize(1)
if DTCFlag&&~isempty(strfind(ModelCSPort{j,1},ExcelDID))
CheckSameFlag=1;
break;
elseif ~isempty(strfind(ModelCSPort{j,1},ExcelCSPort{i,1}))
CheckSameFlag=1;
break;
end
end
TestResultSummary{Num,1}=ExcelCSPort{i,1};
TestResultSummary{Num,2}='NA';
TestResultSummary{Num,3}='NA';
TestResultSummary{Num,4}='CS';
if CheckSameFlag
TestResultSummary{Num,5}='Passed';
TestResultSummary{Num,6}='NA';
else
TestResultSummary{Num,5}='Failed';
if isempty(strfind(ModelCSPort{j,1},ExcelCSPort{i,1}))
TestResultSummary{Num,6}='模型不存在接口';
end
end
Num=Num+1;
end
clearvars ExcelCSPortSize ModelCSPortSize ExcelCSPort ModelCSPort DTCFlag ExcelDID ExcelPortName;
clearvars CheckSameFlag i j Num;
simulink比较模型与excel差异
于 2023-12-07 11:04:17 首次发布