- PostCodeGenCommand - https://www.mathworks.com/help/releases/R2024a/rtw/ug/customizing-post-code-generation-build-processing.html
- STF_make_rtw_hook - https://www.mathworks.com/help/releases/R2024a/rtw/ug/customizing-the-target-build-process-with-the-stf-make-rtw-hook-file.html
How to determine if code is generated for PIL in PostCodeGenCommand or hook?
1 view (last 30 days)
Show older comments
Hello,
we have a custom code generation target that also includes PIL functionality.
We use the PostCodeGenCommand to add some additional includes to the buildInfo object.
Is there a way to determine in the PostCodeGenCommand or in the STF_make_rtw_hook if a code generation was triggered for a PIL simulation? I would like to use this information to add different include files for PIL vs a "normal" production code generation.
Thank you for your help.
0 Comments
Answers (1)
Malay Agarwal
on 24 Dec 2024
Edited: Malay Agarwal
on 24 Dec 2024
You can access the SimulationMode parameter of the model to determine if the code generation was triggered with PIL.
You can use either of PostCodeGenCommand or STF_make_rtw_hook to achieve this.
Refer to the example below, which uses STF_make_rtw_hook (due to simplicity):
% Note: Please change the function name according to your target
% For example, if you are using grt.tlc, the name should be grt_make_rtw_hook
% This will work for custom TLC files as well
function ert_make_rtw_hook(hookMethod, modelName, rtwRoot, templateMakefile, buildOpts, buildArgs, buildInfo)
switch hookMethod
case "entry"
simulationMode = get_param(modelName, 'SimulationMode');
if strcmpi(simulationMode, 'Processor-in-the-Loop (PIL)')
disp('PIL simulation detected. Modifying build options for PIL.');
% Modify build options here
else
disp("Normal code generation. Using default build options.");
end
end
end
Note that using SFT_make_rtw_hook will affect all models which use, for example, ert.tlc to generate code.
The benefit of using PostCodeGenCommand would be that the customization would affect only the model the command has been set for instead of all models.
Please refer to the following resources for more information on using PostCodeGenCommand and STF_make_rtw_hook:
Hope this helps!
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!