Diagnostic Configuration

The Diagnostic Configuration module provides a mechanism for describing the conditions under which an ECU supports diagnostic messages. It allows applications to model ECU operating states and define the availability of diagnostic functions depending on the current state.

The implementation is located in the uds.diagnostic_configuration package and consists of the following components:

State

The State class represents a single ECU state that may affect the availability of diagnostic functions. A state has a name, a predefined set of allowed values, and a current value representing the ECU’s current operating condition.

Attributes:

Example code:

import uds

# create an example state describing the active diagnostic session
session = uds.diagnostic_configuration.State(name="Diagnostic Session",
                                             possible_values={"Default", "Programming", "Extended"})

# change the current session
session.current_value = "Default"

# mark the current session as undefined
session.current_value = None

States Definitions

The uds.diagnostic_configuration.state_definitions module provides predefined State objects representing the most common ECU states used in UDS diagnostic communication. These definitions can be used directly or serve as a starting point for creating custom diagnostic configurations.

The following state definitions are provided:

ECU Diagnostic Configuration

The EcuDiagnosticConfiguration class is the central component of the Diagnostic Configuration module. It stores the ECU states relevant for diagnostic communication together with the restrictions that determine when diagnostic services, sub-functions, DID and RID are available.

Restrictions can be defined at multiple levels of specificity:

  • Service Identifier (SID)

  • Sub-function (for a given SID)

  • Data Identifier (DID, for a given SID)

  • Routine Identifier (RID, for a given SID)

More specific restrictions complement or override the restrictions defined at higher levels.

Attributes:

Methods:

Example code:

import uds

# create an example (simplified) ECU Configuration
ecu_config = uds.diagnostic_configuration.EcuDiagnosticConfiguration(
    states=(uds.diagnostic_configuration.DEFAULT_DIAGNOSTIC_SESSION_STATE,
            uds.diagnostic_configuration.DEFAULT_SECURITY_ACCESS_STATE,
            uds.diagnostic_configuration.DEFAULT_ADDRESSING_TYPE_STATE),
    sid_restrictions={
        0x22: {
            "Session": {0x03},
            }},
    did_restrictions={
        0x22: {
            0xF190: {
                "Session": {0x03},
                "SecurityAccess": {0x01},
                "AddressingType": {uds.addressing.AddressingType.PHYSICAL}}
                }},
    rid_restrictions={},
    subfunction_restrictions={})

# Restrictions for ReadDataByIdentifier (0x22)
ecu_config.sid_restrictions[0x22]

# Restrictions for 22 (ReadDataByIdentifier) F1 90 (DID 0xF190) message
ecu_config.get_restrictions([0x22, 0xF1, 0x90])