ComponentType

XML tag

(abstract class)

Module

autosar.component

Inherits

autosar.element.Element

The ComponentType class is the base class for AtomicSoftwareComponent and CompositionComponent.

Attributes

Name

Type

Description

providePorts

list(:ref:`ar4_port_ProvidePort`)

Provide ports in this component

requirePorts

list(:ref:`ar4_port_RequirePort`)

Require ports in this componen

Public Methods

Method Description

find

ComponentType.find(ref: str)

Find port based in info in reference string.

参数

ref (str) – Reference string

createProvidePort

ComponentType.createProvidePort(name, portInterfaceRef, **kwargs)

Creates new ProvidePort on this component.

参数
  • name (str) – ShortName for the new port

  • portInterfaceRef (str) – Reference to port interface

  • kwargs – Additional arguments depending on port interface type (see below)

返回类型

RequirePort

createRequirePort

ComponentType.createRequirePort(name, portInterfaceRef, **kwargs)

Creates new RequirePort on this component.

参数
  • name (str) – ShortName for the new port

  • portInterfaceRef (str) – Reference to port interface

  • kwargs – Additional arguments depending on port interface type (see below)

返回类型

RequirePort

Additional arguments for SenderReceiverInterface

Parameter name

Type

Description

comspec

dict, list(dict)

Used primarily when port interface has multiple data elements

dataElement

str

Name of the data element this ComSpec refers to.

For single-element port interfaces this parameter is not required

initValue

int, float, str

Used to set an init value literal. Mutually exclusive to initValueRef.

initValueRef

str

Reference to existing constant specification Mutually exclusive to initValue.

aliveTimeout

int

Alive timeout setting (in seconds).

queueLength

int

Length of queue (only applicable for queued port interfaces

Examples — SenderReceiverInterface

Port interface with single data element
import autosar

def create_workspace_and_packages():
    ws = autosar.workspace(version="4.2.2")
    package = ws.createPackage('DataTypes', role='DataType')
    package.createSubPackage('CompuMethods', role='CompuMethod')
    package.createSubPackage('DataConstrs', role='DataConstraint')
    package.createSubPackage('BaseTypes')
    package.createSubPackage('ImplementationTypes')
    ws.createPackage('PortInterfaces', role='PortInterface')
    ws.createPackage('ComponentTypes', role='ComponentType')
    return ws

def create_data_types(ws):
    baseTypes = ws.find('/DataTypes/BaseTypes')
    baseTypes.createSwBaseType('uint8', 8, nativeDeclaration='uint8')
    implTypes = ws.find('/DataTypes/ImplementationTypes')
    implTypes.createImplementationDataType('uint8', lowerLimit=0, upperLimit=255,
                            baseTypeRef='/DataTypes/BaseTypes/uint8', typeEmitter='Platform_Type')
    implTypes.createImplementationDataTypeRef('OffOn_T',
                            implementationTypeRef = '/DataTypes/ImplementationTypes/uint8',
                            valueTable = ['OffOn_Off',
                                           'OffOn_On',
                                           'OffOn_Error',
                                           'OffOn_NotAvailable'
                                        ])

def create_port_interfaces(ws):
    package = ws.find('/PortInterfaces')
    package.createSenderReceiverInterface('HeaterPwrStat_I',
        autosar.element.DataElement('HeaterPwrStat',
                                    '/DataTypes/ImplementationTypes/OffOn_T'))

def create_components(ws):
    package = ws.find('/ComponentTypes')
    comp1 = package.createApplicationSoftwareComponent('Component1')
    comp1.createProvidePort('HeaterPwrStat', 'HeaterPwrStat_I', initValue='OffOn_NotAvailable')

    comp2 = package.createApplicationSoftwareComponent('Component2')
    comp2.createRequirePort('HeaterPwrStat', 'HeaterPwrStat_I', initValue='OffOn_NotAvailable', aliveTimeout = 30)

ws = create_workspace_and_packages()
create_data_types(ws)
create_port_interfaces(ws)
create_components(ws)
ws.saveXML('Component1.arxml', filters=['/ComponentTypes/Component1'])
ws.saveXML('Component2.arxml', filters=['/ComponentTypes/Component2'])
ws.saveXML('DataTypes.arxml', filters=['/DataTypes'])
ws.saveXML('PortInterfaces.arxml', filters = ["/PortInterfaces"])
Port interface with multiple data elements
import autosar

def create_workspace_and_packages():
    ws = autosar.workspace(version="4.2.2")
    package = ws.createPackage('DataTypes', role='DataType')
    package.createSubPackage('CompuMethods', role='CompuMethod')
    package.createSubPackage('DataConstrs', role='DataConstraint')
    package.createSubPackage('Units', role='Unit')
    package.createSubPackage('BaseTypes')
    package.createSubPackage('ImplementationTypes')
    ws.createPackage('PortInterfaces', role='PortInterface')
    ws.createPackage('ComponentTypes', role='ComponentType')
    return ws

def create_data_types(ws):
    baseTypes = ws.find('/DataTypes/BaseTypes')
    baseTypes.createSwBaseType('uint8', 8, nativeDeclaration='uint8')
    baseTypes.createSwBaseType('uint16', 16, nativeDeclaration='uint16')
    implTypes = ws.find('/DataTypes/ImplementationTypes')
    implTypes.createImplementationDataType('uint16', lowerLimit=0, upperLimit=65535,
                                baseTypeRef='/DataTypes/BaseTypes/uint16', typeEmitter='Platform_Type')
    implTypes.createImplementationDataType('uint8', lowerLimit=0, upperLimit=255,
                                baseTypeRef='/DataTypes/BaseTypes/uint8', typeEmitter='Platform_Type')
    implTypes.createImplementationDataTypeRef('PercentLevel_T', lowerLimit=0, upperLimit = 255,
                                implementationTypeRef = '/DataTypes/ImplementationTypes/uint8',
                                offset=0, scaling=0.4, unit='Percent', forceFloat=True)
    implTypes.createImplementationDataTypeRef('VoltageLevel_T', lowerLimit=0, upperLimit = 65535,
                                implementationTypeRef = '/DataTypes/ImplementationTypes/uint16',
                                offset=0, scaling=1/64, unit='Volt', forceFloat=True)

def create_port_interfaces(ws):
    package = ws.find('/PortInterfaces')
    package.createSenderReceiverInterface('BatteryStat_I',
        [
            autosar.element.DataElement('ChargeLevel', '/DataTypes/ImplementationTypes/PercentLevel_T'),
            autosar.element.DataElement('VoltageLevel', '/DataTypes/ImplementationTypes/VoltageLevel_T')
        ])

def create_components(ws):
    package = ws.find('/ComponentTypes')
    comp1 = package.createApplicationSoftwareComponent('Component1')
    comp1.createProvidePort('BatteryStat', 'BatteryStat_I', comspec =
        [
            {'dataElement': 'ChargeLevel', 'initValue': 255},
            {'dataElement': 'VoltageLevel', 'initValue': 65535}
        ])


    comp2 = package.createApplicationSoftwareComponent('Component2')
    comp2.createRequirePort('BatteryStat', 'BatteryStat_I', comspec =
        [
            {'dataElement': 'ChargeLevel', 'initValue': 255, 'aliveTimeout': 30},
            {'dataElement': 'VoltageLevel', 'initValue': 65535, 'aliveTimeout': 30}
        ])

ws = create_workspace_and_packages()
create_data_types(ws)
create_port_interfaces(ws)
create_components(ws)
ws.saveXML('Component1.arxml', filters=['/ComponentTypes/Component1'])
ws.saveXML('Component2.arxml', filters=['/ComponentTypes/Component2'])
ws.saveXML('DataTypes.arxml', filters=['/DataTypes'])
ws.saveXML('PortInterfaces.arxml', filters = ["/PortInterfaces"])

Additional arguments for ClientServerInterface

Parameter name

Type

Description

comspec

dict, list(dict)

Used primarily when port interface has multiple operations

operation

int, float, str

Used to set an init value literal. Mutually exclusive to initValueRef.

queueLength

int

Length of queue

Examples — ClientServerInterface

import autosar

def create_platform_types(ws):
    ws.pushRoles()
    package = ws.createPackage('AUTOSAR_Platform')
    baseTypes = package.createSubPackage('BaseTypes', role = 'DataType')
    package.createSubPackage('CompuMethods', role = 'CompuMethod')
    package.createSubPackage('DataConstrs', role = 'DataConstraint')
    baseTypes.createSwBaseType('dtRef_const_VOID', 1, encoding = 'VOID', nativeDeclaration = 'void')
    baseTypes.createSwBaseType('dtRef_VOID', 1, encoding = 'VOID', nativeDeclaration = 'void')
    baseTypes.createSwBaseType('boolean', 8, encoding = 'BOOLEAN', nativeDeclaration='boolean')
    baseTypes.createSwBaseType('uint8', 8, nativeDeclaration='uint8')
    implTypes = package.createSubPackage('ImplementationDataTypes')
    implTypes.createImplementationDataType('boolean', '/AUTOSAR_Platform/BaseTypes/boolean',
        valueTable=['FALSE', 'TRUE'], typeEmitter='Platform_Type')
    implTypes.createImplementationDataTypePtr('dtRef_const_VOID',
        '/AUTOSAR_Platform/BaseTypes/dtRef_const_VOID', swImplPolicy = 'CONST')
    implTypes.createImplementationDataTypePtr('dtRef_VOID', '/AUTOSAR_Platform/BaseTypes/dtRef_VOID')
    ws.popRoles()
    ws.pushRoles()
    package = ws.createPackage('Predefined_DEV')
    package.createSubPackage('CompuMethods', role = 'CompuMethod')
    package.createSubPackage('DataConstrs', role = 'DataConstraint')
    implTypes = package.createSubPackage('ImplementationDataTypes')
    implTypes.createImplementationDataType('NvM_RequestResultType', '/AUTOSAR_Platform/BaseTypes/uint8',
        valueTable=[
                'NVM_REQ_OK',
                'NVM_REQ_NOT_OK',
                'NVM_REQ_PENDING',
                'NVM_REQ_INTEGRITY_FAILED',
                'NVM_REQ_BLOCK_SKIPPED',
                'NVM_REQ_NV_INVALIDATED'])
    ws.popRoles()

def create_port_interfaces(ws):
    package = ws.createPackage('PortInterfaces', role='PortInterface')
    portInterface=package.createClientServerInterface("NvM_RequestResult",
        errors = autosar.ApplicationError("E_NOT_OK", 1),
        isService=True, operations = [
            "EraseBlock",
            "GetErrorStatus",
            "InvalidateNvBlock",
            "ReadBlock",
            "SetRamBlockStatus",
            "WriteBlock"])
    NvM_RequestResultType_ref = "/Predefined_DEV/ImplementationDataTypes/NvM_RequestResultType"
    boolean_ref = "/AUTOSAR_Platform/ImplementationDataTypes/boolean"
    dtRef_const_VOID_ref = "/AUTOSAR_Platform/ImplementationDataTypes/dtRef_const_VOID"
    dtRef_VOID_ref = "/AUTOSAR_Platform/ImplementationDataTypes/dtRef_VOID"
    portInterface["EraseBlock"].possibleErrors = "E_NOT_OK"
    portInterface["GetErrorStatus"].createOutArgument("ErrorStatus", NvM_RequestResultType_ref,
        "NOT-ACCESSIBLE", "USE-ARGUMENT-TYPE")
    portInterface["GetErrorStatus"].possibleErrors = "E_NOT_OK"
    portInterface["InvalidateNvBlock"].possibleErrors = "E_NOT_OK"
    portInterface["ReadBlock"].createInArgument("DstPtr", dtRef_VOID_ref, "NOT-ACCESSIBLE", "USE-ARGUMENT-TYPE")
    portInterface["ReadBlock"].possibleErrors = "E_NOT_OK"
    portInterface["SetRamBlockStatus"].createInArgument("RamBlockStatus", boolean_ref, "NOT-ACCESSIBLE", "USE-ARGUMENT-TYPE")
    portInterface["SetRamBlockStatus"].possibleErrors = "E_NOT_OK"
    portInterface["WriteBlock"].createInArgument("SrcPtr", dtRef_const_VOID_ref, "NOT-ACCESSIBLE", "USE-ARGUMENT-TYPE")
    portInterface["WriteBlock"].possibleErrors = "E_NOT_OK"


def create_components(ws):
    package = ws.createPackage('ComponentTypes', role='ComponentType')
    comp1 = package.createServiceComponent('ServerComponent')
    comp1.createProvidePort('Nvm_PersonalSettings', 'NvM_RequestResult')

    comp2 = package.createApplicationSoftwareComponent('ClientComponent')
    comp2.createRequirePort('Nvm_PersonalSettings', 'NvM_RequestResult')

ws = autosar.workspace(version="4.2.2")
create_platform_types(ws)
create_port_interfaces(ws)
create_components(ws)
ws.saveXML('ServerComponent.arxml', filters=['/ComponentTypes/ServerComponent'])
ws.saveXML('ClientComponent.arxml', filters=['/ComponentTypes/ClientComponent'])
ws.saveXML('Platform.arxml', filters=['/AUTOSAR_Platform', '/Predefined_DEV'])
ws.saveXML('PortInterfaces.arxml', filters = ["/PortInterfaces"])

Additional arguments for ParameterInterface

Parameter name

Type

Description

comspec

dict, list(dict)

Used primarily when port interface has multiple parameters

parameter

str

Specifices which parameter this ComSpec is for.

Not required when port interface has a single parameter.

initValue

int, float, str

Used to set an init value literal.

Additional arguments for ModeSwitchInterface

Provide Ports:

Parameter name

Type

Description

comspec

dict, list(dict)

Used primarily when port interface has multiple parameters

modeGroup

str

Specifices the mode group name

enhancedMode

bool

Enhanced mode enable/disable

queueLength

int

Queue length

modeSwitchAckTimeout

int

Acknowledgement timeout in milliseconds

Require Ports:

Parameter name

Type

Description

comspec

dict, list(dict)

Used primarily when port interface has multiple parameters

modeGroup

str

Specifices the mode group name

enhancedMode

bool

Enhanced mode enable/disable

supportAsync

bool

Asynchronous support enable/disable

Additional arguments for NvDataInterface

Provide Ports:

Parameter name

Type

Description

comspec

dict, list(dict)

Used primarily when port interface has multiple parameters

nvData

str

Specifices the name of the data element.

Not required when port interface only has one element.

ramBlockInitValue

int, float, str

Init value literal for RAM block

ramBlockInitValueRef

str

Used when you want an existing constant as init value

romBlockInitValue

int, float, str

Init value literal for ROM block

romBlockInitValueRef

str

Used when you want an existing constant as init value

Require Ports:

Parameter name

Type

Description

comspec

dict, list(dict)

Used primarily when port interface has multiple parameters

nvData

str

Specifices the name of the data element.

Not required when port interface only has one element.

InitValue

int, float, str

Init value literal for RAM block

InittValueRef

str

Used when you want an existing constant as init value