Basic Concepts

This document describes the basic concepts of AUTOSAR and how you work with them from Python.

ARXML

An AUTOSAR XML file or ARXML for short is just a normal XML file with the file extension “.arxml”. The root XML element is called <AUTOSAR>. Inside the AUTOSAR (XML) element you will typically a collection of AUTOSAR packages each containing elements.

<AUTOSAR>
   <AR-PACKAGES>
      <PACKAGE>
         <SHORT-NAME>Package1</SHORT-NAME>
      </PACKAGE>
      <PACKAGE>
         <SHORT-NAME>Package2</SHORT-NAME>
      </PACKAGE>
   </AR-PACKAGES>
</AUTOSAR>

Workspace

The AUTOSAR workspace object is the root object that you use to create, load or save AUTOSAR XML files in Python. You create a new workspace instance by calling the autosar.workspace factory method.

import autosar

ws = autosar.workspace()

AUTOSAR Version

When you create your workspace you should specify which AUTOSAR version you intend to use. By default an AUTOSAR v3.0 workspace is created.

Example:

import autosar

ws = autosar.workspace("4.2.2") #Creates an AUTOSAR v4.2.2 workspace

When loading ARXML from file you do not need to manually set the version. The AUTOSAR version is read from the ARXML file.

Packages

An AUTOSAR Package is a container for your elements. It can also contain sub-packages. Packages offers a way to separate your elements into different categories such as SWC namespaces or by element types.

Use the Workspace.createPackage method to create new packages in your workspace.

Use the Package.createSubPackage mehod to create a new sub-package inside an existing Package.

Elements

Elements are what you create and place in your packages. There are different sub-packages in Python for different categories of elements:

  • Components

  • Constants

  • DataTypes

  • Modes

  • Ports

  • PortInterfaces

The Package class offers a wide range of Public Methods to create new elements. These are called factory methods.

Element classes derives from the class autosar.element.Element.

Short Name

Every package and element has a name attribute (or property). This corresponds to the inner text value of the <SHORT-NAME> tag of the underlying ARXML.

References

A reference is a string describing the objects absolute position within the XML hierarchy. This is similar in concept to XPath.

In the XML, the root reference is ‘/’. This corressponds to the outermost XML node called <AR-PACKAGES>. This is also the root of the workspace. Any direct child node that have an inner tag called <SHORT-NAME> can be accessed by adding that name to the root reference. Deeper nodes can be accessed by adding the ‘/’ character followed by the next child node which in turn contains an inner <SHORT-NAME> tag. Most Python objects that you will create will have two properties:

  • ref (str): Reference string of the object.

  • name (str): The name of this object. This corresponds to the inner value of the <SHORT-NAME> XML tag.

Example

import autosar

#Create some packages and data types
ws = autosar.workspace('4.2.2')
datatypes = ws.createPackage('DataTypes', role='DataType')
basetypes = datatypes.createSubPackage('BaseTypes')
u8Type = basetypes.createSwBaseType('uint8', 8, nativeDeclaration='uint8')
u16Type = basetypes.createSwBaseType('uint16', 16, nativeDeclaration='uint16')
u32Type = basetypes.createSwBaseType('uint32', 32, nativeDeclaration='uint32')
ws.saveXML('basetypes.arxml')

#Print reference and name for the created objects
print('u8Type.name: ' + u8Type.name)
print('u8Type.ref: ' + u8Type.ref)
print('u16Type.name: ' + u16Type.name)
print('u16Type.ref: ' + u16Type.ref)
print('u32Type.name: ' + u32Type.name)
print('u32Type.ref: ' + u32Type.ref)

Output:

u8Type.name: uint8
u8Type.ref: /DataTypes/BaseTypes/uint8
u16Type.name: uint16
u16Type.ref: /DataTypes/BaseTypes/uint16
u32Type.name: uint32
u32Type.ref: /DataTypes/BaseTypes/uint32

Package Roles

When you are using this Python module to programmatically create AUTOSAR elements it should be as easy to use as possible. For this purpose we use something called package roles as a hint to Python, telling it which package contain what type of elements. Package roles are usually set when you create the package but can also be assigned later.

To read more about how to use package roles, see the Package Roles guide page.

For a list of methods related to package roles see the Workspace class.

注解

Package roles are only used by the Python package which means it’s not stored anywhere in the XML itself.