DataConstraint

XML tag <DATA-CONSTR>
Module autosar.datatype
Inherits autosar.element.Element

A DataConstraint is used to decorate other data types with one or more constraints. Use the dataConstraintRef property of the ApplicationDataType or ImplementationDataType classes to access the reference string.

Usage

import autosar

def setup():
    ws = autosar.workspace(version="4.2.2")
    package=ws.createPackage('ApplicationTypes', role='DataType')
    package.createSubPackage('DataConstrs', role='DataConstraint')
    return ws

ws = setup()
package = ws.findRolePackage('DataConstraint')
package.createInternalDataConstraint('uint8_DataConstraint', 0, 255)
ws.saveXML('DataTypes.arxml', filters=['/ApplicationTypes'])

Constructor

datatype.DataConstraint(name, rules[, constraintLevel = None][, parent = None][, adminData = None])
Parameters:
  • name (str) – Short name.
  • rules – Constraint rules
  • constraintLevel (None or int) – Optional constraint level.
  • parent (Package) – parent package.
  • adminData (None, AdminData.) – Optional AdminData.

The rule parameter should either be a dictionary or a list of dictionaries. Each dictionary in rules is expected to have three keys:

  • type: (‘internalConstraint’ or ‘physicalConstraint’).
  • lowerLimit: Lower limit of the constraint (int, float).
  • upperLimit: Lower limit of the constraint (int, float).
  • lowerLimitType: Type of lower limit ('OPEN', 'CLOSED').
  • upperLimitType: Type of lower limit ('OPEN', 'CLOSED').

Attributes

For inherited attributes see autosar.element.Element.

Name Type Description
level None, int <CONSTR-LEVEL>
rules list of InternalConstraint or PhysicalConstraint <DATA-CONSTR-RULE>

Public Properties

All properties are limited to situations where the constraint only has one internal rule. Multi-rule support will be added in a future release.

Name Type Access Type
constraintLevel int Get
lowerLimit int, float Get
upperLimit int, float Get
lowerLimitType str Get
upperLimitType str Get

Public Methods

Most methods are currently limited to situations where the constraint only has one internal rule. Multi-rule support will be added in a future release.

Method Description

checkValue

DataConstraint.checkValue(v)
Parameters:v (int, float) – Value.

Checks if value v is inside the limits of the data constraint. If the value is outside then a DataConstraintError will be raised.

findByType

DataConstraint.findByType(constraintType = 'internalConstraint')
Parameters:constraintType (str) – Constraint type ('internalConstraint', 'physicalConstraint').

Returns the first constraint rule that matches given constraint type.