How to get information of Code mappings elements?

5 views (last 30 days)
Chuyen
Chuyen on 5 Feb 2025
Edited: Harsh on 28 May 2025
Hello everyone,
I am developing a script to assign "Shortname" field in Property Inspector of a block as below script and it worked for me. However, I do not want to make "Mapped to" fixed as 'ArTypedPerInstanceMemory' and I changed it as mappingObj.mapSynthesizedDataStore('','','Shortname', objName); or even mappingObj.mapSynthesizedDataStore('Shortname', objName);. But after I changed it, the "Shortname" could not be objName as below script returned. Do you know any solutions to resolve this issue, only apply for Shortname, or are there any APIs I can get the information from Code Mappings?
if strcmp(blkType,'myblock')
mappingObj = autosar.api.getSimulinkMapping(mdlName);
try
mappingObj.addSynthesizedDataStore(objName);
mappingObj.mapSynthesizedDataStore(objName,'ArTypedPerInstanceMemory','Shortname', objName);
end
end
Thank you so much!

Answers (1)

Harsh
Harsh on 28 May 2025
Edited: Harsh on 28 May 2025
You're trying to dynamically assign the "Shortname" property to a synthesized data store in an AUTOSAR model without hardcoding the "Mapped To" type (e.g., 'ArTypedPerInstanceMemory'). The issue arises because omitting the mapping type causes the "Shortname" assignment to fail.
The solution is to first retrieve the existing mapping type and then reapply the mapping with the desired "Shortname".
1. Get the Simulink to AUTOSAR mapping object - Use the "autosar.api.getSimulinkMapping" function to access the AUTOSAR mapping for your model.This object allows you to query and modify AUTOSAR properties for Simulink elements.
mappingObj = autosar.api.getSimulinkMapping(mdlName);
2. Retrieve the current AUTOSAR variable type for the data store - Use the "getDataStore" function to get the current mapping type (e.g., 'ArTypedPerInstanceMemory') for the synthesized data store "objName".This ensures you preserve the existing mapping configuration.
arVarType = getDataStore(mappingObj, objName);
3. Reapply the mapping with the existing type and set the "Shortname" - Use the "mapDataStore" function to reassign the data store with the retrieved type and update the "Shortname" field.This avoids hardcoding the mapping type while still allowing you to customize the "Shortname".
mapDataStore(mappingObj, objName, arVarType, 'Shortname', objName);
Refer to the following documentation pages for the APIs mentioned in above answer:

Categories

Find more on Simulink Coder in Help Center and File Exchange

Products


Release

R2024b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!