CompuMethod

XML tag

<COMPU-METHOD>

Module

autosar.datatype

Inherits

autosar.element.Element

A CompuMethod or computation method is used to decorate other data types with additional information. The compuMethodRef attribute of the ApplicationDataType or ImplementationDataType is used to associate a data type with a certain CompuMethod.

Primary uses for CompuMethods are:

  • Scaling (rational/linear)

  • ValueTables/Enumerations

  • Bit masks

Usage

import autosar

def setup():
    ws = autosar.workspace(version="4.2.2")
    package=ws.createPackage('DataTypes', role='DataType')
    package.createSubPackage('DataConstrs', role='DataConstraint')
    package.createSubPackage('CompuMethods', role='CompuMethod')
    package.createSubPackage('Units', role='Unit')
    return ws

ws = setup()
package = ws.findRolePackage('CompuMethod')

#Rational scaling computation
package.createCompuMethodRational('VehicleSpeed_CompuMethod', scaling=1/64, offset=0, unit="Km_per_h", forceFloat=True)

#Enumeration computation
package.createCompuMethodConst('OnOff_CompuMethod',
    ['OnOff_Off', 'OnOff_On', 'OnOff_Error', 'OnOff_NotAvailable'], defaultValue='OnOff_NotAvailable')
ws.saveXML('DataTypes.arxml', filters=['/DataTypes'])

Factory Methods

CompuMethods can be implictly created while creating ApplicationDataType or ImplementationDataType but they can also be explicitly created using the package API:

To allow Python to implictly create CompuMethods while creating data types you must first assign the compuMethod and the unit roles on packages or sub-packages in your workspace. For more information about package roles, see Package Roles.

Constructor

datatype.CompuMethod(name, useIntToPhys, usePhysToInt[, unitRef = None][, category = None][, parent = None][, adminData = None])
参数
  • name (str) – Short name.

  • useIntToPhys (bool) – Uses internal to physical computation (False, True).

  • usePhysToInt (bool) – Uses physical to internal computation (False, True).

  • unitRef (None, str) – Optional reference to Unit.

  • category – Category string.

  • parent (None, Package) – parent package.

  • adminData (None, AdminData.) – Optional AdminData.

Attributes

For inherited attributes see autosar.element.Element.

Name

Type

Tag

unitRef

None or str

<UNIT-REF>

intToPhys

None or Computation

<COMPU-INTERNAL-TO-PHYS>

physToInt

None or Computation

<COMPU-PHYS-TO-INTERNAL>