powertrain-build 1.13.1__py3-none-any.whl → 1.13.3.dev3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- powertrain_build/__init__.py +40 -40
- powertrain_build/__main__.py +6 -6
- powertrain_build/a2l.py +582 -582
- powertrain_build/a2l_merge.py +650 -650
- powertrain_build/a2l_templates.py +717 -717
- powertrain_build/build.py +985 -985
- powertrain_build/build_defs.py +309 -309
- powertrain_build/build_proj_config.py +690 -690
- powertrain_build/check_interface.py +575 -575
- powertrain_build/cli.py +141 -141
- powertrain_build/config.py +542 -542
- powertrain_build/core.py +395 -395
- powertrain_build/core_dummy.py +343 -343
- powertrain_build/create_conversion_table.py +73 -73
- powertrain_build/dids.py +916 -916
- powertrain_build/dummy.py +157 -157
- powertrain_build/dummy_spm.py +252 -252
- powertrain_build/environmentcheck.py +52 -52
- powertrain_build/ext_dbg.py +255 -255
- powertrain_build/ext_var.py +327 -327
- powertrain_build/feature_configs.py +301 -301
- powertrain_build/gen_allsysteminfo.py +227 -227
- powertrain_build/gen_label_split.py +449 -449
- powertrain_build/handcode_replacer.py +124 -124
- powertrain_build/html_report.py +133 -133
- powertrain_build/interface/__init__.py +4 -4
- powertrain_build/interface/application.py +511 -511
- powertrain_build/interface/base.py +500 -500
- powertrain_build/interface/csp_api.py +490 -490
- powertrain_build/interface/device_proxy.py +677 -677
- powertrain_build/interface/ems.py +67 -67
- powertrain_build/interface/export_global_vars.py +121 -121
- powertrain_build/interface/generate_adapters.py +132 -132
- powertrain_build/interface/generate_hi_interface.py +87 -87
- powertrain_build/interface/generate_service.py +69 -69
- powertrain_build/interface/generate_wrappers.py +147 -147
- powertrain_build/interface/generation_utils.py +142 -142
- powertrain_build/interface/hal.py +194 -194
- powertrain_build/interface/model_yaml_verification.py +348 -348
- powertrain_build/interface/service.py +296 -296
- powertrain_build/interface/simulink.py +249 -249
- powertrain_build/interface/update_call_sources.py +180 -180
- powertrain_build/interface/update_model_yaml.py +186 -186
- powertrain_build/interface/zone_controller.py +362 -362
- powertrain_build/lib/__init__.py +4 -4
- powertrain_build/lib/helper_functions.py +127 -127
- powertrain_build/lib/logger.py +55 -55
- powertrain_build/matlab_scripts/CodeGen/BuildAutomationPyBuild.m +78 -78
- powertrain_build/matlab_scripts/CodeGen/Generate_A2L.m +154 -154
- powertrain_build/matlab_scripts/CodeGen/generateTLUnit.m +239 -239
- powertrain_build/matlab_scripts/CodeGen/getAsilClassification.m +28 -28
- powertrain_build/matlab_scripts/CodeGen/modelConfiguredForTL.m +28 -28
- powertrain_build/matlab_scripts/CodeGen/moveDefOutports.m +88 -88
- powertrain_build/matlab_scripts/CodeGen/parseCalMeasData.m +410 -410
- powertrain_build/matlab_scripts/CodeGen/parseCoreIdentifiers.m +139 -139
- powertrain_build/matlab_scripts/CodeGen/parseDIDs.m +141 -141
- powertrain_build/matlab_scripts/CodeGen/parseInPorts.m +106 -106
- powertrain_build/matlab_scripts/CodeGen/parseIncludeConfigs.m +25 -25
- powertrain_build/matlab_scripts/CodeGen/parseModelInfo.m +38 -38
- powertrain_build/matlab_scripts/CodeGen/parseNVM.m +81 -81
- powertrain_build/matlab_scripts/CodeGen/parseOutPorts.m +120 -120
- powertrain_build/matlab_scripts/CodeGen/parsePreProcBlks.m +23 -23
- powertrain_build/matlab_scripts/CodeGen/struct2JSON.m +128 -128
- powertrain_build/matlab_scripts/CodeGen/updateCodeSwConfig.m +31 -31
- powertrain_build/matlab_scripts/Init_PyBuild.m +91 -91
- powertrain_build/matlab_scripts/__init__.py +2 -2
- powertrain_build/matlab_scripts/helperFunctions/Get_Full_Name.m +46 -46
- powertrain_build/matlab_scripts/helperFunctions/Get_SrcLines.m +12 -12
- powertrain_build/matlab_scripts/helperFunctions/Init_Models.m +78 -78
- powertrain_build/matlab_scripts/helperFunctions/Init_Projects.m +67 -67
- powertrain_build/matlab_scripts/helperFunctions/Read_Units.m +34 -34
- powertrain_build/matlab_scripts/helperFunctions/SetProjectTimeSamples.m +26 -26
- powertrain_build/matlab_scripts/helperFunctions/Strip_Suffix.m +16 -16
- powertrain_build/matlab_scripts/helperFunctions/followLink.m +118 -118
- powertrain_build/matlab_scripts/helperFunctions/getCodeSwitches.m +50 -50
- powertrain_build/matlab_scripts/helperFunctions/getConsumerBlocks.m +30 -30
- powertrain_build/matlab_scripts/helperFunctions/getDefBlock.m +39 -39
- powertrain_build/matlab_scripts/helperFunctions/getDefOutport.m +58 -58
- powertrain_build/matlab_scripts/helperFunctions/getDstBlocks.m +19 -19
- powertrain_build/matlab_scripts/helperFunctions/getDstLines.m +13 -13
- powertrain_build/matlab_scripts/helperFunctions/getInterfaceSignals.m +37 -37
- powertrain_build/matlab_scripts/helperFunctions/getName.m +37 -37
- powertrain_build/matlab_scripts/helperFunctions/getPath.m +6 -6
- powertrain_build/matlab_scripts/helperFunctions/getProperValue.m +21 -21
- powertrain_build/matlab_scripts/helperFunctions/getSrcBlocks.m +19 -19
- powertrain_build/matlab_scripts/helperFunctions/getSrcLines.m +13 -13
- powertrain_build/matlab_scripts/helperFunctions/loadLibraries.m +10 -10
- powertrain_build/matlab_scripts/helperFunctions/loadjson.m +6 -6
- powertrain_build/matlab_scripts/helperFunctions/modifyEnumStructField.m +21 -21
- powertrain_build/matlab_scripts/helperFunctions/removeConfigDuplicates.m +31 -31
- powertrain_build/matlab_scripts/helperFunctions/sortSystemByClass.m +26 -26
- powertrain_build/matlab_scripts/helperFunctions/tl_getfast.m +89 -89
- powertrain_build/matlab_scripts/helperFunctions/topLevelSystem.m +20 -20
- powertrain_build/matlab_scripts/helperFunctions/updateModels.m +131 -131
- powertrain_build/memory_section.py +224 -224
- powertrain_build/nvm_def.py +729 -729
- powertrain_build/problem_logger.py +86 -86
- powertrain_build/pt_matlab.py +430 -430
- powertrain_build/pt_win32.py +144 -144
- powertrain_build/replace_compu_tab_ref.py +105 -105
- powertrain_build/rte_dummy.py +254 -254
- powertrain_build/sched_funcs.py +209 -207
- powertrain_build/signal.py +7 -7
- powertrain_build/signal_if_html_rep.py +221 -221
- powertrain_build/signal_if_html_rep_all.py +302 -302
- powertrain_build/signal_incons_html_rep.py +180 -180
- powertrain_build/signal_incons_html_rep_all.py +366 -366
- powertrain_build/signal_incons_html_rep_base.py +168 -168
- powertrain_build/signal_inconsistency_check.py +641 -641
- powertrain_build/signal_interfaces.py +864 -864
- powertrain_build/templates/Index_SigCheck_All.html +22 -22
- powertrain_build/templates/Index_SigIf_All.html +19 -19
- powertrain_build/types.py +218 -218
- powertrain_build/unit_configs.py +419 -419
- powertrain_build/user_defined_types.py +660 -660
- powertrain_build/versioncheck.py +66 -66
- powertrain_build/wrapper.py +512 -512
- powertrain_build/xlrd_csv.py +87 -87
- powertrain_build/zone_controller/__init__.py +4 -4
- powertrain_build/zone_controller/calibration.py +176 -176
- powertrain_build/zone_controller/composition_yaml.py +880 -878
- {powertrain_build-1.13.1.dist-info → powertrain_build-1.13.3.dev3.dist-info}/METADATA +100 -100
- powertrain_build-1.13.3.dev3.dist-info/RECORD +130 -0
- {powertrain_build-1.13.1.dist-info → powertrain_build-1.13.3.dev3.dist-info}/WHEEL +1 -1
- {powertrain_build-1.13.1.dist-info → powertrain_build-1.13.3.dev3.dist-info}/licenses/LICENSE +202 -202
- powertrain_build-1.13.3.dev3.dist-info/pbr.json +1 -0
- powertrain_build-1.13.1.dist-info/RECORD +0 -130
- powertrain_build-1.13.1.dist-info/pbr.json +0 -1
- {powertrain_build-1.13.1.dist-info → powertrain_build-1.13.3.dev3.dist-info}/entry_points.txt +0 -0
- {powertrain_build-1.13.1.dist-info → powertrain_build-1.13.3.dev3.dist-info}/licenses/AUTHORS +0 -0
- {powertrain_build-1.13.1.dist-info → powertrain_build-1.13.3.dev3.dist-info}/licenses/NOTICE +0 -0
- {powertrain_build-1.13.1.dist-info → powertrain_build-1.13.3.dev3.dist-info}/top_level.txt +0 -0
|
@@ -1,239 +1,239 @@
|
|
|
1
|
-
% Copyright 2024 Volvo Car Corporation
|
|
2
|
-
% Licensed under Apache 2.0.
|
|
3
|
-
|
|
4
|
-
function res = generateTLUnit(RootFolder, model, SSP)
|
|
5
|
-
%Generates c and config files for a unit based on a TL-model
|
|
6
|
-
%TODO: Why does this generate TLSim and sfunctions?
|
|
7
|
-
commonFolder = [RootFolder '/Models/Common/pybuild_src'];
|
|
8
|
-
% TODO: When we deploy pybuild we should replace Common/pybuild_src with Common
|
|
9
|
-
% TODO: Write a matlab config reader to get these values
|
|
10
|
-
baseFolder = [RootFolder '/Models/' SSP '/' model];
|
|
11
|
-
srcFolder = [baseFolder '/pybuild_src'];
|
|
12
|
-
srcFolderTmp = [srcFolder '/Tmp'];
|
|
13
|
-
cfgFolder = [baseFolder '/pybuild_cfg'];
|
|
14
|
-
tmpMdlFolder = [baseFolder '/tmpMdl'];
|
|
15
|
-
|
|
16
|
-
%run par file again, just to be sure the set values are used
|
|
17
|
-
global Vc;
|
|
18
|
-
oldVc = Vc;
|
|
19
|
-
par_f_path = [model '_par.m'];
|
|
20
|
-
run(par_f_path);
|
|
21
|
-
if ~isequal(oldVc, Vc)
|
|
22
|
-
warning('Vc has been updated.')
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
%create folders if they are missing
|
|
26
|
-
folders = {srcFolder srcFolderTmp cfgFolder tmpMdlFolder commonFolder};
|
|
27
|
-
for i=1:length(folders)
|
|
28
|
-
folder = folders{i};
|
|
29
|
-
% isdir check needed, rmdir may fail due to permissions
|
|
30
|
-
if ~isdir(folder)
|
|
31
|
-
mkdir(folder);
|
|
32
|
-
end
|
|
33
|
-
fprintf('Created folder %s\n', folder);
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
% Add matlab_src and c_src folders to the path if they exist
|
|
37
|
-
matlabSrcFldr = [baseFolder '/matlab_src'];
|
|
38
|
-
if isdir(matlabSrcFldr)
|
|
39
|
-
addpath(matlabSrcFldr)
|
|
40
|
-
end
|
|
41
|
-
cSrcFldr = [baseFolder '/c_src'];
|
|
42
|
-
if isdir(cSrcFldr)
|
|
43
|
-
addpath(cSrcFldr)
|
|
44
|
-
fprintf('\nCopy c_src files to src folder\n');
|
|
45
|
-
copyfile([cSrcFldr '/*.*'], srcFolder);
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
% Load libraries
|
|
49
|
-
% block_libraries = dir(include_folder, '**\*.slx');
|
|
50
|
-
% for i=1:length(block_libraries)
|
|
51
|
-
% block_library = block_libraries(i);
|
|
52
|
-
% load_system(block_library.name);
|
|
53
|
-
% end
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
%diary([baseFolder '/' model '.log']);
|
|
57
|
-
fp= fopen([baseFolder '/' model '.log'], 'w');
|
|
58
|
-
unitCfg = [cfgFolder '/config_' model '.json'];
|
|
59
|
-
fprintf('\nStart generation of temporary unitCfg %s for model %s\n', unitCfg, model);
|
|
60
|
-
info = parseModelInfo(RootFolder, model, cfgFolder);
|
|
61
|
-
struct2JSON(info, unitCfg);
|
|
62
|
-
fprintf('\nFinished generation of temporary unitCfg for model %s\n', model);
|
|
63
|
-
|
|
64
|
-
% Do this in better way to control where the model is stored
|
|
65
|
-
fprintf('\nStart temp model generation for model %s\n', model);
|
|
66
|
-
load_system(model)
|
|
67
|
-
tmpMdl = [model '_OPortMvd'];
|
|
68
|
-
save_system(model, [tmpMdlFolder '/' tmpMdl '.mdl']);
|
|
69
|
-
subsystem = regexprep(model, '([A-Za-z0-9]+)(__\w+){0,1}','$1');
|
|
70
|
-
moveDefOutports([tmpMdl '/' subsystem '/Subsystem/' subsystem]);
|
|
71
|
-
configSet = getActiveConfigSet(tmpMdl);
|
|
72
|
-
% Set sample times to a constant, to avoid problems when the ts
|
|
73
|
-
% variable for the model isn't set (happens as this script is run
|
|
74
|
-
% over all models, not only the ones currently in the project)
|
|
75
|
-
set_param(configSet, 'SolverType', 'Fixed-step');
|
|
76
|
-
set_param(configSet, 'FixedStep', '0.01');
|
|
77
|
-
fnc_g = find_system(tmpMdl, 'FindAll', 'on', 'LookUnderMasks', 'all', ...
|
|
78
|
-
'SearchDepth', '1', ...
|
|
79
|
-
'MaskType', 'Function-Call Generator');
|
|
80
|
-
set_param(fnc_g, 'sample_time', '0.01');
|
|
81
|
-
fprintf('\nFinished temp model generation for model %s\n', model);
|
|
82
|
-
|
|
83
|
-
%Generate code
|
|
84
|
-
currDir = pwd;
|
|
85
|
-
cd(srcFolderTmp);
|
|
86
|
-
MILSystem=find_system(get_param(tmpMdl, 'handle'), 'lookundermasks', 'on', 'tag', 'MIL Subsystem');
|
|
87
|
-
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
88
|
-
%%% TL has a name length limitation on define file names (10 chars).
|
|
89
|
-
%%% Define special IDs for debug models such that their
|
|
90
|
-
%%% tl_defines_-files get unique names and don't overwrite each other.
|
|
91
|
-
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
92
|
-
CurrentFunctionName = model;
|
|
93
|
-
CodeGenConfigPath = [RootFolder '/ConfigDocuments/matlab_script_config/CodeGen_config.json'];
|
|
94
|
-
if isfile(CodeGenConfigPath)
|
|
95
|
-
CodeGenConfig = loadjson(CodeGenConfigPath);
|
|
96
|
-
ProblemModels = CodeGenConfig.problem_models_id_map;
|
|
97
|
-
else
|
|
98
|
-
warning('Found no config file: %s.', CodeGenConfigPath)
|
|
99
|
-
ProblemModels = struct();
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
if isfield(ProblemModels, CurrentFunctionName)
|
|
103
|
-
ModelID = ProblemModels.(CurrentFunctionName);
|
|
104
|
-
warning('There are multiple models with the same ID (character 3-12 of the model name)')
|
|
105
|
-
ModelsString = join(fieldnames(ProblemModels), ', ');
|
|
106
|
-
disp(['This is one of: ' ModelsString{1}])
|
|
107
|
-
else
|
|
108
|
-
ModelID = CurrentFunctionName(3:min(end,12));
|
|
109
|
-
end
|
|
110
|
-
set_tlsystemID(MILSystem, ModelID);
|
|
111
|
-
|
|
112
|
-
% Default code generation settings
|
|
113
|
-
tl_set(...
|
|
114
|
-
tmpMdl, ...
|
|
115
|
-
'codeopt.cleancode', 1, ...
|
|
116
|
-
'codeopt.sections', 1, ...
|
|
117
|
-
'codeopt.optimization', 1, ...
|
|
118
|
-
'codeopt.sfbitfields', 1, ...
|
|
119
|
-
'codeopt.globalbitfields', 0, ...
|
|
120
|
-
'codeopt.optimizedbooltype', 1, ...
|
|
121
|
-
'codeopt.functionsfor64bitops', 0, ...
|
|
122
|
-
'codeopt.limidentlength', 1, ...
|
|
123
|
-
'codeopt.noinitstozero', 0, ...
|
|
124
|
-
'codeopt.sharefunctions', 1 ...
|
|
125
|
-
);
|
|
126
|
-
|
|
127
|
-
% Custom code generation settings
|
|
128
|
-
CCodeStyleSheetPath = [RootFolder '/ConfigDocuments/TL4_3_settings/CodeConfig/cconfig.xml'];
|
|
129
|
-
if exist(CCodeStyleSheetPath, 'file')
|
|
130
|
-
fprintf('\nUsing custom C code style sheet %s\n', CCodeStyleSheetPath);
|
|
131
|
-
tl_set(tmpMdl, 'codeopt.outputstylefile', CCodeStyleSheetPath);
|
|
132
|
-
end
|
|
133
|
-
|
|
134
|
-
fprintf('\nStart code generation of %s\n', tmpMdl);
|
|
135
|
-
warning('off', 'all')
|
|
136
|
-
ds_error_set('BatchMode', 'on');
|
|
137
|
-
ds_error_display('PrintMessage','off');
|
|
138
|
-
ds_error_set('DefaultExcludedMessages', [17291 17001 17218 20281 19611 15229 15365 19001 15550]);
|
|
139
|
-
tl_generate_code('Model', tmpMdl, 'SimMode', 'none')
|
|
140
|
-
warning('on', 'all')
|
|
141
|
-
ds_error_set('BatchMode', 'off');
|
|
142
|
-
% print to stdout so the errors are displayed in the diary
|
|
143
|
-
msgs = ds_error_get('AllMessages');
|
|
144
|
-
for i=1:length(msgs)
|
|
145
|
-
msg = msgs(i);
|
|
146
|
-
fprintf(fp, '%s(%d) = %s\n',msg.type,msg.number,msg.msg);
|
|
147
|
-
end
|
|
148
|
-
if tl_error_check
|
|
149
|
-
close_system(tmpMdl, 1);
|
|
150
|
-
close_system(model, 0);
|
|
151
|
-
error('Errors detected');
|
|
152
|
-
end
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
fprintf('\nFinished code generation of %s\n', tmpMdl)
|
|
156
|
-
% print all messages
|
|
157
|
-
chdir(srcFolder);
|
|
158
|
-
A2lStylesheetName = [RootFolder '/ConfigDocuments/a2l_export_nd.xsl'];
|
|
159
|
-
Generate_A2L(tmpMdl, A2lStylesheetName, '');
|
|
160
|
-
close_system(tmpMdl, 1);
|
|
161
|
-
process_generated_code(commonFolder, srcFolderTmp, srcFolder, subsystem, tmpMdl, model)
|
|
162
|
-
fprintf('\nStart updating unitCfg %s based on generated code', unitCfg);
|
|
163
|
-
updateCodeSwConfig(RootFolder, [baseFolder '/' model '.mdl'])
|
|
164
|
-
fprintf('\nFinished updating unitCfg %s based on generated code', unitCfg);
|
|
165
|
-
fclose(fp);
|
|
166
|
-
close_system(model, 0);
|
|
167
|
-
chdir(currDir);
|
|
168
|
-
end
|
|
169
|
-
|
|
170
|
-
function process_generated_code(commonFolder, srcFolderTmp, srcFolder, subsystem, tmpMdl, model)
|
|
171
|
-
force_movefile = 'f';
|
|
172
|
-
force_rmdir = 's';
|
|
173
|
-
subsystem = regexprep(model, '([A-Za-z0-9]+)(__\w+){0,1}','$1');
|
|
174
|
-
generated_files = dir([srcFolderTmp '/TLProj/' subsystem '/*.*']);
|
|
175
|
-
for generated_file = generated_files'
|
|
176
|
-
file_path = [generated_file.folder '/' generated_file.name];
|
|
177
|
-
if isdir(file_path)
|
|
178
|
-
disp([file_path ' is a directory. Skipping.'])
|
|
179
|
-
elseif isfile([commonFolder '/' generated_file.name])
|
|
180
|
-
disp([file_path ' is a common file. Skipping.'])
|
|
181
|
-
elseif strcmp(generated_file.name, 'a2lexport.log')
|
|
182
|
-
disp([file_path ' is a log file. Skipping.'])
|
|
183
|
-
else
|
|
184
|
-
post_process_source_file(file_path)
|
|
185
|
-
if is_common_name(generated_file)
|
|
186
|
-
disp(['Moving from ' file_path ' to ' commonFolder])
|
|
187
|
-
movefile(file_path, commonFolder, force_movefile);
|
|
188
|
-
else
|
|
189
|
-
disp(['Moving from ' file_path ' to ' srcFolder])
|
|
190
|
-
movefile(file_path, srcFolder, force_movefile);
|
|
191
|
-
end
|
|
192
|
-
end
|
|
193
|
-
end
|
|
194
|
-
fprintf('\nMoved src code to %s\n', srcFolder);
|
|
195
|
-
%TODO: remove the A2L-generation log & dd files
|
|
196
|
-
rmdir(srcFolderTmp, force_rmdir);
|
|
197
|
-
movefile([srcFolder '/' tmpMdl '.a2l'], [srcFolder '/' model '.a2l'], force_movefile);
|
|
198
|
-
end
|
|
199
|
-
|
|
200
|
-
function post_process_source_file(file_path)
|
|
201
|
-
disp('Starting source file post-process')
|
|
202
|
-
file_contents = fileread(file_path);
|
|
203
|
-
post_process_functions = {@remove_unsupported_comments};
|
|
204
|
-
for function_index = 1:length(post_process_functions)
|
|
205
|
-
file_contents = post_process_functions{function_index}(file_contents);
|
|
206
|
-
end
|
|
207
|
-
disp(['Updating file contents of file: "' file_path '"'])
|
|
208
|
-
write_file(file_path, file_contents)
|
|
209
|
-
end
|
|
210
|
-
|
|
211
|
-
function updated_file_content = remove_unsupported_comments(file_content)
|
|
212
|
-
disp('Replacing C++ style comments "//" with C style comments "/**/" for Green Hills compatibility')
|
|
213
|
-
file_lines = splitlines(file_content);
|
|
214
|
-
expression = '//(.*)$';
|
|
215
|
-
replace_with = '/*$1*/';
|
|
216
|
-
updated_file_lines = regexprep(file_lines, expression, replace_with);
|
|
217
|
-
updated_file_content = strjoin(updated_file_lines, newline);
|
|
218
|
-
end
|
|
219
|
-
|
|
220
|
-
function write_file(file_path, file_content)
|
|
221
|
-
file_id = fopen(file_path, 'w');
|
|
222
|
-
fprintf(file_id, '%s\n', file_content);
|
|
223
|
-
fclose(file_id);
|
|
224
|
-
end
|
|
225
|
-
|
|
226
|
-
function common = is_common_name(generated_file)
|
|
227
|
-
% common = is_common(generated_file)
|
|
228
|
-
%
|
|
229
|
-
% Check if the file should be located in the common folder
|
|
230
|
-
common = false;
|
|
231
|
-
% TODO: Find more common files and add to this function
|
|
232
|
-
if strncmp(generated_file.name, 'Tab', 3)
|
|
233
|
-
common = true;
|
|
234
|
-
elseif strcmp(generated_file.name, 'tl_basetypes.h')
|
|
235
|
-
common = true;
|
|
236
|
-
elseif strcmp(generated_file.name, 'tl_types.h')
|
|
237
|
-
common = true;
|
|
238
|
-
end
|
|
239
|
-
end
|
|
1
|
+
% Copyright 2024 Volvo Car Corporation
|
|
2
|
+
% Licensed under Apache 2.0.
|
|
3
|
+
|
|
4
|
+
function res = generateTLUnit(RootFolder, model, SSP)
|
|
5
|
+
%Generates c and config files for a unit based on a TL-model
|
|
6
|
+
%TODO: Why does this generate TLSim and sfunctions?
|
|
7
|
+
commonFolder = [RootFolder '/Models/Common/pybuild_src'];
|
|
8
|
+
% TODO: When we deploy pybuild we should replace Common/pybuild_src with Common
|
|
9
|
+
% TODO: Write a matlab config reader to get these values
|
|
10
|
+
baseFolder = [RootFolder '/Models/' SSP '/' model];
|
|
11
|
+
srcFolder = [baseFolder '/pybuild_src'];
|
|
12
|
+
srcFolderTmp = [srcFolder '/Tmp'];
|
|
13
|
+
cfgFolder = [baseFolder '/pybuild_cfg'];
|
|
14
|
+
tmpMdlFolder = [baseFolder '/tmpMdl'];
|
|
15
|
+
|
|
16
|
+
%run par file again, just to be sure the set values are used
|
|
17
|
+
global Vc;
|
|
18
|
+
oldVc = Vc;
|
|
19
|
+
par_f_path = [model '_par.m'];
|
|
20
|
+
run(par_f_path);
|
|
21
|
+
if ~isequal(oldVc, Vc)
|
|
22
|
+
warning('Vc has been updated.')
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
%create folders if they are missing
|
|
26
|
+
folders = {srcFolder srcFolderTmp cfgFolder tmpMdlFolder commonFolder};
|
|
27
|
+
for i=1:length(folders)
|
|
28
|
+
folder = folders{i};
|
|
29
|
+
% isdir check needed, rmdir may fail due to permissions
|
|
30
|
+
if ~isdir(folder)
|
|
31
|
+
mkdir(folder);
|
|
32
|
+
end
|
|
33
|
+
fprintf('Created folder %s\n', folder);
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
% Add matlab_src and c_src folders to the path if they exist
|
|
37
|
+
matlabSrcFldr = [baseFolder '/matlab_src'];
|
|
38
|
+
if isdir(matlabSrcFldr)
|
|
39
|
+
addpath(matlabSrcFldr)
|
|
40
|
+
end
|
|
41
|
+
cSrcFldr = [baseFolder '/c_src'];
|
|
42
|
+
if isdir(cSrcFldr)
|
|
43
|
+
addpath(cSrcFldr)
|
|
44
|
+
fprintf('\nCopy c_src files to src folder\n');
|
|
45
|
+
copyfile([cSrcFldr '/*.*'], srcFolder);
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
% Load libraries
|
|
49
|
+
% block_libraries = dir(include_folder, '**\*.slx');
|
|
50
|
+
% for i=1:length(block_libraries)
|
|
51
|
+
% block_library = block_libraries(i);
|
|
52
|
+
% load_system(block_library.name);
|
|
53
|
+
% end
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
%diary([baseFolder '/' model '.log']);
|
|
57
|
+
fp= fopen([baseFolder '/' model '.log'], 'w');
|
|
58
|
+
unitCfg = [cfgFolder '/config_' model '.json'];
|
|
59
|
+
fprintf('\nStart generation of temporary unitCfg %s for model %s\n', unitCfg, model);
|
|
60
|
+
info = parseModelInfo(RootFolder, model, cfgFolder);
|
|
61
|
+
struct2JSON(info, unitCfg);
|
|
62
|
+
fprintf('\nFinished generation of temporary unitCfg for model %s\n', model);
|
|
63
|
+
|
|
64
|
+
% Do this in better way to control where the model is stored
|
|
65
|
+
fprintf('\nStart temp model generation for model %s\n', model);
|
|
66
|
+
load_system(model)
|
|
67
|
+
tmpMdl = [model '_OPortMvd'];
|
|
68
|
+
save_system(model, [tmpMdlFolder '/' tmpMdl '.mdl']);
|
|
69
|
+
subsystem = regexprep(model, '([A-Za-z0-9]+)(__\w+){0,1}','$1');
|
|
70
|
+
moveDefOutports([tmpMdl '/' subsystem '/Subsystem/' subsystem]);
|
|
71
|
+
configSet = getActiveConfigSet(tmpMdl);
|
|
72
|
+
% Set sample times to a constant, to avoid problems when the ts
|
|
73
|
+
% variable for the model isn't set (happens as this script is run
|
|
74
|
+
% over all models, not only the ones currently in the project)
|
|
75
|
+
set_param(configSet, 'SolverType', 'Fixed-step');
|
|
76
|
+
set_param(configSet, 'FixedStep', '0.01');
|
|
77
|
+
fnc_g = find_system(tmpMdl, 'FindAll', 'on', 'LookUnderMasks', 'all', ...
|
|
78
|
+
'SearchDepth', '1', ...
|
|
79
|
+
'MaskType', 'Function-Call Generator');
|
|
80
|
+
set_param(fnc_g, 'sample_time', '0.01');
|
|
81
|
+
fprintf('\nFinished temp model generation for model %s\n', model);
|
|
82
|
+
|
|
83
|
+
%Generate code
|
|
84
|
+
currDir = pwd;
|
|
85
|
+
cd(srcFolderTmp);
|
|
86
|
+
MILSystem=find_system(get_param(tmpMdl, 'handle'), 'lookundermasks', 'on', 'tag', 'MIL Subsystem');
|
|
87
|
+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
88
|
+
%%% TL has a name length limitation on define file names (10 chars).
|
|
89
|
+
%%% Define special IDs for debug models such that their
|
|
90
|
+
%%% tl_defines_-files get unique names and don't overwrite each other.
|
|
91
|
+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
92
|
+
CurrentFunctionName = model;
|
|
93
|
+
CodeGenConfigPath = [RootFolder '/ConfigDocuments/matlab_script_config/CodeGen_config.json'];
|
|
94
|
+
if isfile(CodeGenConfigPath)
|
|
95
|
+
CodeGenConfig = loadjson(CodeGenConfigPath);
|
|
96
|
+
ProblemModels = CodeGenConfig.problem_models_id_map;
|
|
97
|
+
else
|
|
98
|
+
warning('Found no config file: %s.', CodeGenConfigPath)
|
|
99
|
+
ProblemModels = struct();
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
if isfield(ProblemModels, CurrentFunctionName)
|
|
103
|
+
ModelID = ProblemModels.(CurrentFunctionName);
|
|
104
|
+
warning('There are multiple models with the same ID (character 3-12 of the model name)')
|
|
105
|
+
ModelsString = join(fieldnames(ProblemModels), ', ');
|
|
106
|
+
disp(['This is one of: ' ModelsString{1}])
|
|
107
|
+
else
|
|
108
|
+
ModelID = CurrentFunctionName(3:min(end,12));
|
|
109
|
+
end
|
|
110
|
+
set_tlsystemID(MILSystem, ModelID);
|
|
111
|
+
|
|
112
|
+
% Default code generation settings
|
|
113
|
+
tl_set(...
|
|
114
|
+
tmpMdl, ...
|
|
115
|
+
'codeopt.cleancode', 1, ...
|
|
116
|
+
'codeopt.sections', 1, ...
|
|
117
|
+
'codeopt.optimization', 1, ...
|
|
118
|
+
'codeopt.sfbitfields', 1, ...
|
|
119
|
+
'codeopt.globalbitfields', 0, ...
|
|
120
|
+
'codeopt.optimizedbooltype', 1, ...
|
|
121
|
+
'codeopt.functionsfor64bitops', 0, ...
|
|
122
|
+
'codeopt.limidentlength', 1, ...
|
|
123
|
+
'codeopt.noinitstozero', 0, ...
|
|
124
|
+
'codeopt.sharefunctions', 1 ...
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
% Custom code generation settings
|
|
128
|
+
CCodeStyleSheetPath = [RootFolder '/ConfigDocuments/TL4_3_settings/CodeConfig/cconfig.xml'];
|
|
129
|
+
if exist(CCodeStyleSheetPath, 'file')
|
|
130
|
+
fprintf('\nUsing custom C code style sheet %s\n', CCodeStyleSheetPath);
|
|
131
|
+
tl_set(tmpMdl, 'codeopt.outputstylefile', CCodeStyleSheetPath);
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
fprintf('\nStart code generation of %s\n', tmpMdl);
|
|
135
|
+
warning('off', 'all')
|
|
136
|
+
ds_error_set('BatchMode', 'on');
|
|
137
|
+
ds_error_display('PrintMessage','off');
|
|
138
|
+
ds_error_set('DefaultExcludedMessages', [17291 17001 17218 20281 19611 15229 15365 19001 15550]);
|
|
139
|
+
tl_generate_code('Model', tmpMdl, 'SimMode', 'none')
|
|
140
|
+
warning('on', 'all')
|
|
141
|
+
ds_error_set('BatchMode', 'off');
|
|
142
|
+
% print to stdout so the errors are displayed in the diary
|
|
143
|
+
msgs = ds_error_get('AllMessages');
|
|
144
|
+
for i=1:length(msgs)
|
|
145
|
+
msg = msgs(i);
|
|
146
|
+
fprintf(fp, '%s(%d) = %s\n',msg.type,msg.number,msg.msg);
|
|
147
|
+
end
|
|
148
|
+
if tl_error_check
|
|
149
|
+
close_system(tmpMdl, 1);
|
|
150
|
+
close_system(model, 0);
|
|
151
|
+
error('Errors detected');
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
fprintf('\nFinished code generation of %s\n', tmpMdl)
|
|
156
|
+
% print all messages
|
|
157
|
+
chdir(srcFolder);
|
|
158
|
+
A2lStylesheetName = [RootFolder '/ConfigDocuments/a2l_export_nd.xsl'];
|
|
159
|
+
Generate_A2L(tmpMdl, A2lStylesheetName, '');
|
|
160
|
+
close_system(tmpMdl, 1);
|
|
161
|
+
process_generated_code(commonFolder, srcFolderTmp, srcFolder, subsystem, tmpMdl, model)
|
|
162
|
+
fprintf('\nStart updating unitCfg %s based on generated code', unitCfg);
|
|
163
|
+
updateCodeSwConfig(RootFolder, [baseFolder '/' model '.mdl'])
|
|
164
|
+
fprintf('\nFinished updating unitCfg %s based on generated code', unitCfg);
|
|
165
|
+
fclose(fp);
|
|
166
|
+
close_system(model, 0);
|
|
167
|
+
chdir(currDir);
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
function process_generated_code(commonFolder, srcFolderTmp, srcFolder, subsystem, tmpMdl, model)
|
|
171
|
+
force_movefile = 'f';
|
|
172
|
+
force_rmdir = 's';
|
|
173
|
+
subsystem = regexprep(model, '([A-Za-z0-9]+)(__\w+){0,1}','$1');
|
|
174
|
+
generated_files = dir([srcFolderTmp '/TLProj/' subsystem '/*.*']);
|
|
175
|
+
for generated_file = generated_files'
|
|
176
|
+
file_path = [generated_file.folder '/' generated_file.name];
|
|
177
|
+
if isdir(file_path)
|
|
178
|
+
disp([file_path ' is a directory. Skipping.'])
|
|
179
|
+
elseif isfile([commonFolder '/' generated_file.name])
|
|
180
|
+
disp([file_path ' is a common file. Skipping.'])
|
|
181
|
+
elseif strcmp(generated_file.name, 'a2lexport.log')
|
|
182
|
+
disp([file_path ' is a log file. Skipping.'])
|
|
183
|
+
else
|
|
184
|
+
post_process_source_file(file_path)
|
|
185
|
+
if is_common_name(generated_file)
|
|
186
|
+
disp(['Moving from ' file_path ' to ' commonFolder])
|
|
187
|
+
movefile(file_path, commonFolder, force_movefile);
|
|
188
|
+
else
|
|
189
|
+
disp(['Moving from ' file_path ' to ' srcFolder])
|
|
190
|
+
movefile(file_path, srcFolder, force_movefile);
|
|
191
|
+
end
|
|
192
|
+
end
|
|
193
|
+
end
|
|
194
|
+
fprintf('\nMoved src code to %s\n', srcFolder);
|
|
195
|
+
%TODO: remove the A2L-generation log & dd files
|
|
196
|
+
rmdir(srcFolderTmp, force_rmdir);
|
|
197
|
+
movefile([srcFolder '/' tmpMdl '.a2l'], [srcFolder '/' model '.a2l'], force_movefile);
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
function post_process_source_file(file_path)
|
|
201
|
+
disp('Starting source file post-process')
|
|
202
|
+
file_contents = fileread(file_path);
|
|
203
|
+
post_process_functions = {@remove_unsupported_comments};
|
|
204
|
+
for function_index = 1:length(post_process_functions)
|
|
205
|
+
file_contents = post_process_functions{function_index}(file_contents);
|
|
206
|
+
end
|
|
207
|
+
disp(['Updating file contents of file: "' file_path '"'])
|
|
208
|
+
write_file(file_path, file_contents)
|
|
209
|
+
end
|
|
210
|
+
|
|
211
|
+
function updated_file_content = remove_unsupported_comments(file_content)
|
|
212
|
+
disp('Replacing C++ style comments "//" with C style comments "/**/" for Green Hills compatibility')
|
|
213
|
+
file_lines = splitlines(file_content);
|
|
214
|
+
expression = '//(.*)$';
|
|
215
|
+
replace_with = '/*$1*/';
|
|
216
|
+
updated_file_lines = regexprep(file_lines, expression, replace_with);
|
|
217
|
+
updated_file_content = strjoin(updated_file_lines, newline);
|
|
218
|
+
end
|
|
219
|
+
|
|
220
|
+
function write_file(file_path, file_content)
|
|
221
|
+
file_id = fopen(file_path, 'w');
|
|
222
|
+
fprintf(file_id, '%s\n', file_content);
|
|
223
|
+
fclose(file_id);
|
|
224
|
+
end
|
|
225
|
+
|
|
226
|
+
function common = is_common_name(generated_file)
|
|
227
|
+
% common = is_common(generated_file)
|
|
228
|
+
%
|
|
229
|
+
% Check if the file should be located in the common folder
|
|
230
|
+
common = false;
|
|
231
|
+
% TODO: Find more common files and add to this function
|
|
232
|
+
if strncmp(generated_file.name, 'Tab', 3)
|
|
233
|
+
common = true;
|
|
234
|
+
elseif strcmp(generated_file.name, 'tl_basetypes.h')
|
|
235
|
+
common = true;
|
|
236
|
+
elseif strcmp(generated_file.name, 'tl_types.h')
|
|
237
|
+
common = true;
|
|
238
|
+
end
|
|
239
|
+
end
|
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
% Copyright 2024 Volvo Car Corporation
|
|
2
|
-
% Licensed under Apache 2.0.
|
|
3
|
-
|
|
4
|
-
function level = getAsilClassification(rootFolder, model)
|
|
5
|
-
% Function which defines the ASIL level given a model.
|
|
6
|
-
% Specific ASIL levels must be specified in a configuration file.
|
|
7
|
-
% rootFolder: The root folder of the project.
|
|
8
|
-
% model: Model name.
|
|
9
|
-
|
|
10
|
-
% Struct which defines the ASIL level for dependability models.
|
|
11
|
-
% These models will be converted to use TL ASIL classes, in order
|
|
12
|
-
% to allocate them to the correct memory area.
|
|
13
|
-
codeGenConfigPath = [rootFolder '/ConfigDocuments/matlab_script_config/CodeGen_config.json'];
|
|
14
|
-
if isfile(codeGenConfigPath)
|
|
15
|
-
CodeGenConfig = loadjson(codeGenConfigPath);
|
|
16
|
-
depMdls = CodeGenConfig.dependability_model_asil_class;
|
|
17
|
-
else
|
|
18
|
-
warning('Found no config file: %s.', codeGenConfigPath)
|
|
19
|
-
depMdls = struct();
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
model_wo_suffix = regexprep(model, '(\w+)__.*', '$1');
|
|
23
|
-
if isfield(depMdls, model_wo_suffix)
|
|
24
|
-
level = depMdls.(model_wo_suffix);
|
|
25
|
-
else
|
|
26
|
-
level = 'QM';
|
|
27
|
-
end
|
|
28
|
-
end
|
|
1
|
+
% Copyright 2024 Volvo Car Corporation
|
|
2
|
+
% Licensed under Apache 2.0.
|
|
3
|
+
|
|
4
|
+
function level = getAsilClassification(rootFolder, model)
|
|
5
|
+
% Function which defines the ASIL level given a model.
|
|
6
|
+
% Specific ASIL levels must be specified in a configuration file.
|
|
7
|
+
% rootFolder: The root folder of the project.
|
|
8
|
+
% model: Model name.
|
|
9
|
+
|
|
10
|
+
% Struct which defines the ASIL level for dependability models.
|
|
11
|
+
% These models will be converted to use TL ASIL classes, in order
|
|
12
|
+
% to allocate them to the correct memory area.
|
|
13
|
+
codeGenConfigPath = [rootFolder '/ConfigDocuments/matlab_script_config/CodeGen_config.json'];
|
|
14
|
+
if isfile(codeGenConfigPath)
|
|
15
|
+
CodeGenConfig = loadjson(codeGenConfigPath);
|
|
16
|
+
depMdls = CodeGenConfig.dependability_model_asil_class;
|
|
17
|
+
else
|
|
18
|
+
warning('Found no config file: %s.', codeGenConfigPath)
|
|
19
|
+
depMdls = struct();
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
model_wo_suffix = regexprep(model, '(\w+)__.*', '$1');
|
|
23
|
+
if isfield(depMdls, model_wo_suffix)
|
|
24
|
+
level = depMdls.(model_wo_suffix);
|
|
25
|
+
else
|
|
26
|
+
level = 'QM';
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
% Copyright 2024 Volvo Car Corporation
|
|
2
|
-
% Licensed under Apache 2.0.
|
|
3
|
-
|
|
4
|
-
function TF = modelConfiguredForTL(rootFolder, modelFolder, modelName)
|
|
5
|
-
% Function that checks if model is configured for TargetLink
|
|
6
|
-
% rootFolder: The root folder of the project
|
|
7
|
-
% modelName: Name of model
|
|
8
|
-
% ssp: project name
|
|
9
|
-
|
|
10
|
-
curr_dir = pwd;
|
|
11
|
-
|
|
12
|
-
cd([rootFolder '/' modelFolder]);
|
|
13
|
-
run(['./' modelName '_par.m']);
|
|
14
|
-
load_system(modelName);
|
|
15
|
-
|
|
16
|
-
TLDefineBlock = find_system(modelName, 'SearchDepth', 1, ...
|
|
17
|
-
'Name', 'TargetLink Main Dialog');
|
|
18
|
-
|
|
19
|
-
if isempty(TLDefineBlock)
|
|
20
|
-
TF = false;
|
|
21
|
-
else
|
|
22
|
-
TF = true;
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
% Close system without saving
|
|
26
|
-
close_system(modelName, 0)
|
|
27
|
-
cd(curr_dir);
|
|
28
|
-
end
|
|
1
|
+
% Copyright 2024 Volvo Car Corporation
|
|
2
|
+
% Licensed under Apache 2.0.
|
|
3
|
+
|
|
4
|
+
function TF = modelConfiguredForTL(rootFolder, modelFolder, modelName)
|
|
5
|
+
% Function that checks if model is configured for TargetLink
|
|
6
|
+
% rootFolder: The root folder of the project
|
|
7
|
+
% modelName: Name of model
|
|
8
|
+
% ssp: project name
|
|
9
|
+
|
|
10
|
+
curr_dir = pwd;
|
|
11
|
+
|
|
12
|
+
cd([rootFolder '/' modelFolder]);
|
|
13
|
+
run(['./' modelName '_par.m']);
|
|
14
|
+
load_system(modelName);
|
|
15
|
+
|
|
16
|
+
TLDefineBlock = find_system(modelName, 'SearchDepth', 1, ...
|
|
17
|
+
'Name', 'TargetLink Main Dialog');
|
|
18
|
+
|
|
19
|
+
if isempty(TLDefineBlock)
|
|
20
|
+
TF = false;
|
|
21
|
+
else
|
|
22
|
+
TF = true;
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
% Close system without saving
|
|
26
|
+
close_system(modelName, 0)
|
|
27
|
+
cd(curr_dir);
|
|
28
|
+
end
|