%****************************************************************************************
% 脚本声明:用于应用层软件架构关于AutoSar代码生成的配置。
%****************************************************************************************
clear;
%选择并打开模型
disp('请选择.slx文件...')
[filename,pathname] = uigetfile({'*.slx'},'Select the Model');
if isequal(filename,0)
disp('取消操作')
return
else
disp(['数据文件路径:',fullfile(pathname,filename)])
end
%模型名字确认
model = replace(filename,'.slx','');
open_system(model);
%打开模型的配置
activeConfigObj = getActiveConfigSet(model);
%调用函数,执行模型配置(为了生成A2L文件,先调用一些基础配置)
SBW_AutoSAR_config(activeConfigObj);
% activeConfigObj.set_param('GenerateASAP2', 'on'); % ASAP2
disp([model,'配置成功!'])
%% 修改结构体在.c.h文件中打包的配置
% slMap = autosar.api.getSimulinkMapping(model);
% setInternalDataPackaging(slMap,'Default');
%% 添加新的SwAddrMethod类型
% arProps = autosar.api.getAUTOSARProperties(model);
% SwAddrMethod = find(arProps,[],'SwAddrMethod');
% if ~isempty(SwAddrMethod)
% delete(arProps,'/DataTypes/SwAddrMethods');
% end
% addPackageableElement(arProps,'SwAddrMethod','/DataTypes/SwAddrMethods','CALIB_BOOLEAN','SectionType','CalibrationVariables');
% addPackageableElement(arProps,'SwAddrMethod','/DataTypes/SwAddrMethods','CALIB_8','SectionType','CalibrationVariables');
% addPackageableElement(arProps,'SwAddrMethod','/DataTypes/SwAddrMethods','CALIB_16','SectionType','CalibrationVariables');
% addPackageableElement(arProps,'SwAddrMethod','/DataTypes/SwAddrMethods','CALIB_32','SectionType','CalibrationVariables');
% addPackageableElement(arProps,'SwAddrMethod','/DataTypes/SwAddrMethods','VAR_INIT_BOOLEAN','SectionType','Var');
% addPackageableElement(arProps,'SwAddrMethod','/DataTypes/SwAddrMethods','VAR_NIT_8','SectionType','Var');
% addPackageableElement(arProps,'SwAddrMethod','/DataTypes/SwAddrMethods','VAR_INIT_16','SectionType','Var');
% addPackageableElement(arProps,'SwAddrMethod','/DataTypes/SwAddrMethods','VAR_INIT_32','SectionType','Var');
% %addPackageableElement(arProps,'SwAddrMethod','/DataTypes/SwAddrMethods','VAR_INIT_BOOLEAN','SectionType','Var');
% addPackageableElement(arProps,'SwAddrMethod','/DataTypes/SwAddrMethods','CODE','SectionType','Code');
% disp([model,'SwAddrMethod类型添加成功!'])
%% 分配Runnable的代码段
% slMap = autosar.api.getSimulinkMapping(model);
% Runable1Name = [model(1:4),'_1ms'];
% Runable2Name = [model,'_Init'];
% mapFunction(slMap,Runable1Name,Runable1Name,'SwAddrMethod','CODE')
% mapFunction(slMap,'InitializeFunction',Runable2Name,'SwAddrMethod','CODE')
% disp([model,'Runnable的代码段分配成功!'])
%% 修改Event触发方式
% System_object = find_system(gcs,'SearchDepth',3,'findall','on','type','block', 'BlockType', 'TriggerPort');
% set_param(System_object(1),"SampleTimeType", 'periodic');
% set_param(System_object(1),"SampleTime", '-1');
%运行模型
sim(model);
disp([model,'运行成功!'])
%保存模型
save_system(model);
disp([model,'已保存!'])
%关闭模型
close_system(model);
clear;
msgbox('AutoSAR相关配置已完成!');%输出弹窗
%****************************************************************************************
% 脚本声明:用于生成模型测试框架,进行框架测试。
%****************************************************************************************
clear;
%% 选择并读取sldd
disp('请选择sldd文件...')
[slddfilename,slddpathname] = uigetfile({'*.sldd'},'Select the Data Dictionary');
if isequal(slddfilename,0)
disp('取消操作')
return
else
disp(['数据文件路径:',fullfile(slddpathname,slddfilename)])
end
%定义数据字典的名字
sldd_file = slddfilename;
%% 选择并读取Model
disp('请选择slx文件...')
[slxfilename,slxpathname] = uigetfile({'*.slx'},'Select the Model');
if isequal(slxfilename,0)
disp('取消操作')
return
else
disp(['数据文件路径:',fullfile(slxpathname,slxfilename)])
end
ModelName = replace(slxfilename, '.slx', '');
SubsystemName = [ModelName(1:4),'_1ms_sys'];
%% 打开数据字典
myDictionaryObj = Simulink.data.dictionary.open(sldd_file);
dDataSectObj = getSection(myDictio