Main Content

Programmatically Manage AUTOSAR Architectural Data

This example shows how to share interfaces, data types, and constants across components and compositions modeled in Simulink® using the Architectural Data section of a data dictionary.

The Architectural Data section of a Simulink data dictionary enables interfaces, data types, constants and AUTOSAR-specific data to be authored, managed, and shared between AUTOSAR components and compositions modeled in Simulink. The Architectural Data section provides scalability for system-level and multicomponent designs by containing these shared elements in a central location.

You can programmatically configure architectural data and apply your changes to your model using this basic workflow:

  1. Create or open a data dictionary.

  2. Design interfaces, data types, and constants with the Simulink.dictionary.ArchitecturalData programmatic interfaces.

  3. Link the data dictionary containing architectural data to a Simulink or architecture model.

  4. Apply architectural data to a model programmatically.

Create or Open Simulink Data Dictionary Programmatically

To open data dictionary, use the Simulink.dictionary.archdata.open function.

dictName = "dataDict.sldd";
archDataObj = Simulink.dictionary.archdata.open(dictName);

To create a new data dictionary use the Simulink.dictionary.archdata.create function.

These functions return Architectural Data objects that you can edit using the Simulink.dictionary.ArchitecturalData programmatic interfaces.

Design Data Types, Interfaces, and Constants Programmatically

To programmatically create, configure, and manage architectural data in your data dictionary, use the programmatic interfaces for the Simulink.dictionary.ArchitecturalData object.

archDataObj = Simulink.dictionary.archdata.open(dictName);

Use type-specific functions to add alias types and enumerations to the data dictionary.

myAliasType1Obj = addAliasType(archDataObj,"aliasType",BaseType="single");
set(myAliasType1Obj,Name="myAliasType1")
set(myAliasType1Obj,BaseType = "fixdt(1,32,16)");
myAliasType2Obj = addAliasType(archDataObj,"myAliasType2");
set(myAliasType2Obj,BaseType = myAliasType1Obj);

myEnumType1Obj = addEnumType(archDataObj,"myColor");
% set(myEnumType1Obj,DefaultValue = "BLUE");
set(myEnumType1Obj,Description = "I am a Simulink Enumeration");
set(myEnumType1Obj,StorageType = "int16");

You can set the base type of the created alias type to be the created enumeration data type myColor.

myAliasType3Obj = addAliasType(archDataObj,"myAliasType3");
set(myAliasType3Obj,BaseType = myEnumType1Obj);

Use the addNumericType function to add numeric types to the data dictionary.

myNumericType1Obj = addNumericType(archDataObj,"myNumericType1");
set(myNumericType1Obj,DataTypeMode = "Single");

Use the addValueType to add value types to the data dictionary. You can also set the data type of the value types to be pre-existing data types or created enumeration data types.

myValueType1Obj = addValueType(archDataObj,"myValueType1");
set(myValueType1Obj,DataType = 'int32');
set(myValueType1Obj,Dimensions = '[2 3]');
set(myValueType1Obj,Description = "I am a Simulink ValueType");

Use the addStructType function to add struct types to the data dictionary.

myStructType1Obj = addStructType(archDataObj,"myStructType1");
structElement1 = addElement(myStructType1Obj,"Element1");
set(structElement1,Type='single');
set(structElement1,Dimensions="3");
structElement2 = addElement(myStructType1Obj,"Element2");
structElement3 = addElement(myStructType1Obj,"Element3");

You can set the data type of a struct element by using the data type object or by using the name of the data type, specified as a string scalar or character vector.

set(structElement2,Type = myValueType1Obj);
% or
set(structElement3,Type = "ValueType: myValueType1");

You can add constants using the addConstant function.

myConstantObj = addConstant(archDataObj, "myConst", Value=4);

You can add communication interfaces and their data elements using the functions of the Simulink.dictionary.archdata.DataInterface object.

nvInterface1 = addDataInterface(archDataObj,"NV1");

dataElm1 = addElement(nvInterface1,"DE1");
set(dataElm1,Type = myValueType1Obj);
dataElm2 = addElement(nvInterface1,"DE3");
% set(dataElm2,"Type",'single');
set(dataElm2,Dimensions = '10');
srInterface2 = addDataInterface(archDataObj,"SR1");

Add AUTOSAR Classic platform mapping using the addPlatformMapping function. You can get and set properties using the setPlatformProperty and getPlatformProperties functions.

platformMapping = addPlatformMapping(archDataObj,"AUTOSARClassic");
setPlatformProperty(platformMapping,nvInterface1,...
    "Package", "/Interface2", "InterfaceKind", "NvDataInterface");
[pNames, pValues] = getPlatformProperties(platformMapping,nvInterface1);

Programmatically manage AUTOSAR Classic platform related elements that do not have mappings to Simulink. See autosar.api.getAUTOSARProperties for information regarding related workflows.

arPropsObj = autosar.api.getAUTOSARProperties(dictName);
arPropsObj.addPackageableElement("SwAddrMethod","/SwAddressMethods","VAR1","SectionType","Var");
setPlatformProperty(platformMapping,dataElm1,...
    "SwAddrMethod","VAR1","SwCalibrationAccess","ReadWrite","DisplayFormat","%.3f");

Link Data Dictionary Programmatically

To link a dictionary to a model programmatically use the linkDictionary function.

Create or open a Simulink data dictionary. In this example you create a new data dictionary MyInterfaces.sldd.

dictName = "interfaces.sldd";
archDataObj = Simulink.dictionary.archdata.create(dictName);

Create an AUTOSAR architecture model and link it to a simulink data dictionary.

archModel = autosar.arch.createModel("topArchModel");
linkDictionary(archModel,dictName);

Apply Data Changes Programmatically

Once your data dictionary is linked to an architecture model, you can apply the changes to your modeled application programmatically by using the Simulink.dictionary.ArchitecturalData object.

Here, you link a dictionary with an AUTOSAR Classic platform mapping to an architecture model then map a SenderPort to an interface in that dictionary.

Create or open a Simulink data dictionary. In this example you create a new data dictionary MyInterfaces.sldd.

archDataObj = Simulink.dictionary.archdata.open(dictName);

Create an AUTOSAR architecture model.

archModel = autosar.arch.createModel('myTopComposition');

Add a data interface to the AUTOSAR architecture model.

srInterface2 = addDataInterface(archDataObj,'SR1');

Link a data dictionary to the AUTOSAR architecture model.

linkDictionary(archModel,dictName);

Add a port and set the interface of the port.

pport = addPort(archModel,"Sender",'PPort');
setInterface(pport,srInterface2);