Main Content

Configure and Map AUTOSAR Component Programmatically

In Simulink®, as an alternative to graphical configuration, you can programmatically configure an AUTOSAR software component. The AUTOSAR property and map functions allow you to get, set, add, and remove the same component properties and mapping information displayed in the AUTOSAR Dictionary and Code Mappings editor views of the AUTOSAR component model.

AUTOSAR Property and Map Functions

You can use AUTOSAR property and map functions to programmatically configure the Simulink representation of an AUTOSAR software component. For example:

  • Use the AUTOSAR property functions to add AUTOSAR elements, find elements, get and set properties of elements, delete elements, and define ARXML packaging of elements.

  • Use the AUTOSAR map functions to map Simulink model elements to AUTOSAR elements and return AUTOSAR mapping information for model elements.

The AUTOSAR property and map functions also validate syntax and semantics for requested AUTOSAR property and mapping changes.

For a complete list of property and map functions, see the functions listed for Component Development.

For example scripts using these functions, see:

.

Note

For information about functions for creating or importing an AUTOSAR software component, see Component Creation.

Tree View of AUTOSAR Configuration

The following tree view of an AUTOSAR configuration shows the types of AUTOSAR elements to which you can apply AUTOSAR property and map functions. This view corresponds with the AUTOSAR Dictionary tree display, but includes elements that might not be present in every configuration. Names shown in italics are user-selected.

  • AUTOSAR

    • AtomicComponents

      • MyComponent

        • ReceiverPorts

        • SenderPorts

        • SenderReceiverPorts

        • ModeReceiverPorts

        • ModeSenderPorts

        • ClientPorts

        • ServerPorts

        • NvReceiverPorts

        • NvSenderPorts

        • NvSenderReceiverPorts

        • ParameterReceiverPorts

        • TriggerReceiverPorts

        • Runnables

        • IRV

        • Parameters

    • S-R Interfaces

      • SRInterface1

        • DataElements

    • M-S Interfaces

      • MSInterface1

    • C-S Interfaces

      • CSInterface1

        • Operations

          • operation1

            • Arguments

    • NV Interfaces

      • NVInterface1

        • DataElements

    • Parameter Interfaces

      • ParameterInterface1

        • DataElements

    • Trigger Interfaces

      • TriggerInterface1

        • Triggers

    • CompuMethods

    • XML Options

Properties of AUTOSAR Elements

The following table lists properties that are associated with AUTOSAR elements. For more information, see AUTOSAR Element Properties.

AUTOSAR Element ClassProperties
AtomicComponent
  • ReceiverPorts (add/delete)

  • SenderPorts (add/delete)

  • SenderReceiverPorts (add/delete)

  • ModeReceiverPorts (add/delete)

  • ClientPorts (add/delete)

  • ServerPorts (add/delete)

  • NvReceiverPorts (add/delete)

  • NvSenderPorts (add/delete)

  • NvSenderReceiverPorts (add/delete)

  • ParameterReceiverPorts (add/delete)

  • TriggerReceiverPorts (add/delete)

  • Behavior (add/delete)

  • Kind

  • Name

ApplicationComponentBehavior
  • Runnables (add/delete)

  • Events (add/delete)

  • PIM (add/delete)

  • IRV (add/delete)

  • Parameters (add/delete)

  • IncludedDataTypeSets

  • DataTypeMapping

  • Name

DataReceiverPort
DataSenderPort
DataSenderReceiverPort
ClientPort
ServerPort
ModeReceiverPort
NvDataReceiverPort
NvDataSenderPort
NvDataSenderReceiverPort
ParameterReceiverPort
TriggerReceiverPort
  • Interface

  • Name

Runnable
  • symbol

  • canBeInvokedConcurrently

  • SwAddrMethod

  • Name

TimingEvent
  • Period

  • StartOnEvent

  • DisabledMode

  • Name

DataReceivedEvent
DataReceiveErrorEvent
OperationInvokedEvent
  • Trigger

  • StartOnEvent

  • DisabledMode

  • Name

ModeSwitchEvent
  • Trigger

  • Activation

  • StartOnEvent

  • DisabledMode

  • Name

InitEvent
  • StartOnEvent

  • Name

IrvData
  • Type

  • SwAddrMethod

  • SwCalibrationAccess

  • DisplayFormat

  • SwAlignment

  • Name

ParameterData
  • Type

  • SwAddrMethod

  • SwCalibrationAccess

  • DisplayFormat

  • SwAlignment

  • Kind

  • Name

SenderReceiverInterface
NvDataInterface
ParameterInterface
  • DataElements (add/delete)

  • IsService

  • Name

FlowData
  • Type

  • SwAddrMethod

  • SwCalibrationAccess

  • DisplayFormat

  • SwAlignment

  • Name

ModeSwitchInterface
  • ModeGroup (add/delete)

  • IsService

  • Name

ModeDeclarationGroupElement
  • ModeGroup

  • SwCalibrationAccess

  • Name

ClientServerInterface
  • Operations (add/delete)

  • IsService

  • Name

TriggerInterface
  • Triggers (add/delete)

  • IsService

  • Name

Programmatically Configure AUTOSAR Software Component

This example shows how to configure an AUTOSAR software component. You can find AUTOSAR software components present in a model using the find function.

Configure AUTOSAR Software Component Name and Type

Open the example model autosar_swc_expfcns and create the autosar.api.getAUTOSARProperties object.

hModel = "autosar_swc_expfcns";
open_system(hModel);
arProps = autosar.api.getAUTOSARProperties(hModel);

Find AUTOSAR software components.

aswcPaths = find(arProps,[],"AtomicComponent","PathType","FullyQualified");

Loop through components and list the Name and Kind property values.

for ii=1:length(aswcPaths)
    aswcPath = aswcPaths{ii};
    swcName = get(arProps,aswcPath,"Name");
    swcKind = get(arProps,aswcPath,"Kind");
    fprintf("Component %s: Name %s, Kind %s\n",aswcPath,swcName,swcKind);
end
Component /pkg/swc/ASWC: Name ASWC, Kind Application

Modify the Name and Kind property values.

aswcName = 'mySwc';
aswcKind = 'SensorActuator';
set(arProps,aswcPaths{1},'Name',aswcName);
aswcPaths = find(arProps,[],'AtomicComponent','PathType','FullyQualified');
set(arProps,aswcPaths{1},'Kind',aswcKind);
swcName = get(arProps,aswcPaths{1},'Name');
swcKind = get(arProps,aswcPaths{1},'Kind');
fprintf('Component %s: Name %s, Kind %s\n',aswcPaths{1},swcName,swcKind);
Component /pkg/swc/mySwc: Name mySwc, Kind SensorActuator

Specify AUTOSAR Element Location

The AUTOSAR property functions typically require you to specify the name and location of an element. The location of an AUTOSAR element within a hierarchy of AUTOSAR packages and objects can be uniquely specified using a fully qualified path. A fully qualified path might include a package hierarchy and the element location within the object hierarchy, for example:

/pkgLevel1/pkgLevel2/pkgLevel3/grandParentName/parentName/childName

For AUTOSAR property functions other than addPackageableElement, you can specify a partially-qualified path that does not include the package hierarchy, for example:

grandParentName/parentName/childName

The following code sets the IsService property for the Sender-Receiver Interface located at path Interface1 in the example model autosar_swc_expfcns to true. In this case, specifying the name Interface1 is enough to locate the element.

hModel = 'autosar_swc_expfcns';
openExample(hModel);
arProps = autosar.api.getAUTOSARProperties(hModel);
set(arProps,'Interface1','IsService',true);

Here is the resulting display in the S-R Interfaces view in the AUTOSAR Dictionary.

If you added a Sender-Receiver Interface to a component package, you would specify a fully qualified path, for example:

hModel = 'autosar_swc_expfcns';
openExample(hModel);
arProps = autosar.api.getAUTOSARProperties(hModel);
addPackageableElement(arProps,'SenderReceiverInterface','/pkg/if','Interface3',...
   'IsService',true);

A potential advantage of using a partially qualified path rather than a fully-qualified path is that it is easier to construct a partially qualified path from looking at the AUTOSAR Dictionary view of the AUTOSAR component. A potential disadvantage is that a partially qualified path could refer to more than one element in the AUTOSAR configuration. For example, the path s/r conceivably might designate both a data element of a Sender-Receiver Interface and a runnable of a component. When a conflict occurs, the software displays an error and lists the fully-qualified paths.

Most AUTOSAR elements have properties that are made up of multiple parts (composite). For example, an atomic software component has composite properties such as ReceiverPorts, SenderPorts, and InternalBehavior. For elements that have composite properties that you can manipulate, such as property ReceiverPorts of a component, child elements are named and are uniquely defined within the parent element. To locate a child element within a composite property, use the parent element path and the child name, without the property name. For example, if the qualified path of a parent atomic software component is /A/B/SWC, and a child receiver port is named RPort1, the location of the receiver port is /A/B/SWC/RPort1.