uds.can.frame

Implementation for CAN frame fields that are influenced by UDS.

Handlers for CAN Frame fields:
  • CAN Identifier

  • DLC

  • Data

Attributes

DEFAULT_FILLER_BYTE

Default value of Filler Byte.

Classes

CanVersion

Versions of CAN bus.

CanIdHandler

Helper class that provides utilities for CAN Identifier field.

CanDlcHandler

Helper class that provides utilities for CAN Data Length Code field.

Module Contents

uds.can.frame.DEFAULT_FILLER_BYTE: int = 204

Default value of Filler Byte. Filler Bytes are used for CAN Frame Data Padding. .. note:: The value is specified by ISO 15765-2:2016 (chapter 10.4.2.1).

class uds.can.frame.CanVersion[source]

Bases: uds.utilities.ValidatedEnum

Inheritance diagram of uds.can.frame.CanVersion

Versions of CAN bus.

CLASSIC_CAN: CanVersion = 'Classic CAN'

Classic CAN 2.0

CAN_FD: CanVersion = 'CAN FD'

CAN FD

class uds.can.frame.CanIdHandler[source]

Helper class that provides utilities for CAN Identifier field.

CAN Identifier (CAN ID) is a CAN frame field that informs about a sender and a content of CAN frames.

CAN bus supports two formats of CAN ID:
  • Standard (11-bit Identifier)

  • Extended (29-bit Identifier)

MIN_STANDARD_VALUE: int = 0

Minimum value of Standard (11-bit) CAN ID.

MAX_STANDARD_VALUE: int = 2047

Maximum value of Standard (11-bit) CAN ID.

MIN_EXTENDED_VALUE: int = 2048

Minimum value of Extended (29-bit) CAN ID.

MAX_EXTENDED_VALUE: int = 536870911

Maximum value of Extended (29-bit) CAN ID.

ADDRESSING_MASK: int = 67043328

CAN ID mask for bits enforced by SAE J1939 (Normal Fixed of Mixed 29bit addressing formats).

NORMAL_FIXED_PHYSICAL_ADDRESSING_MASKED_VALUE: int = 14286848

Masked value of physically addressed CAN ID in Normal Fixed Addressing format.

NORMAL_FIXED_FUNCTIONAL_ADDRESSING_MASKED_VALUE: int = 14352384

Masked value of functionally addressed CAN ID in Normal Fixed Addressing format.

MIXED_29BIT_PHYSICAL_ADDRESSING_MASKED_VALUE: int = 13500416

Masked value of physically addressed CAN ID in Mixed 29-bit Addressing format.

MIXED_29BIT_FUNCTIONAL_ADDRESSING_MASKED_VALUE: int = 13434880

Masked value of functionally addressed CAN ID in Mixed 29-bit Addressing format.

TARGET_ADDRESS_BIT_OFFSET: int = 8

Bit offset of Target Address parameter in CAN Identifier.

SOURCE_ADDRESS_BIT_OFFSET: int = 0

Bit offset of Source Address parameter.

PRIORITY_BIT_OFFSET: int = 26

Bit offset of Priority parameter defined by SAE J1939.

DEFAULT_PRIORITY_VALUE: int = 6

Default value of Priority parameter defined by SAE J1939.

MIN_PRIORITY_VALUE: int = 0

Minimal value of Priority parameter defined by SAE J1939.

MAX_PRIORITY_VALUE: int = 7

Maximal value of Priority parameter defined by SAE J1939.

classmethod is_can_id(value)[source]

Check if the provided value is either Standard (11-bit) or Extended (29-bit) CAN ID.

Parameters:

value (int) – Value to check.

Returns:

True if value is a valid CAN ID, False otherwise.

Return type:

bool

classmethod is_standard_can_id(can_id)[source]

Check if the provided value is Standard (11-bit) CAN ID.

Parameters:

can_id (int) – Value to check.

Returns:

True if value is a valid 11-bit CAN ID, False otherwise.

Return type:

bool

classmethod is_extended_can_id(can_id)[source]

Check if the provided value is Extended (29-bit) CAN ID.

Parameters:

can_id (int) – Value to check.

Returns:

True if value is a valid 29-bit CAN ID, False otherwise.

Return type:

bool

classmethod validate_can_id(value, extended_can_id=None)[source]

Validate whether provided value is either Standard or Extended CAN ID.

Parameters:
  • value (int) – Value to validate.

  • extended_can_id (Optional[bool]) –

    Flag whether to perform consistency check with CAN ID format.

    • None - does not check the format of the value

    • True - verify that the value uses Extended (29-bit) CAN ID format

    • False - verify that the value uses Standard (11-bit) CAN ID format

Raises:
  • TypeError – Provided value is not int type.

  • ValueError – Provided value is out of CAN Identifier values range.

Return type:

None

classmethod validate_priority(value)[source]

Validate whether provided priority value is in line with SAE J1939 definition.

Parameters:

value (int) – Value to validate.

Raises:
  • TypeError – Provided value is not int type.

  • ValueError – Provided value is out of Priority values range.

Return type:

None

class uds.can.frame.CanDlcHandler[source]

Helper class that provides utilities for CAN Data Length Code field.

CAN Data Length Code (DLC) is a CAN frame field that informs about number of data bytes carried by CAN frames.

CAN DLC supports two values ranges:
  • 0x0-0x8 - linear range which is supported by CLASSICAL CAN and CAN FD

  • 0x9-0xF - discrete range which is supported by CAN FD only

__DLC_VALUES: Tuple[int, Ellipsis]
__DATA_BYTES_NUMBERS: Tuple[int, Ellipsis] = (0, 1, 2, 3, 4, 5, 6, 7, 8, 12, 16, 20, 24, 32, 48, 64)
__DLC_MAPPING: Dict[int, int]
__DATA_BYTES_NUMBER_MAPPING: Dict[int, int]
__DLC_SPECIFIC_FOR_CAN_FD: Set[int]
MIN_DATA_BYTES_NUMBER: int

Minimum number of data bytes in a CAN frame.

MAX_DATA_BYTES_NUMBER: int

Maximum number of data bytes in a CAN frame.

MIN_DLC_VALUE: int

Minimum value of DLC parameter.

MAX_DLC_VALUE: int

Maximum value of DLC parameter.

MIN_BASE_UDS_DLC: int = 8

Minimum CAN DLC value that can be used for UDS communication. Lower values of DLC are only allowed when CAN Frame Data Optimization is used.

classmethod decode_dlc(dlc)[source]

Map a value of CAN DLC into a number of data bytes.

Parameters:

dlc (int) – Value of CAN DLC.

Returns:

Number of data bytes in a CAN frame that is represented by provided DLC value.

Return type:

int

classmethod encode_dlc(data_bytes_number)[source]

Map a number of data bytes in a CAN frame into DLC value.

Parameters:

data_bytes_number (int) – Number of data bytes in a CAN frame.

Returns:

DLC value of a CAN frame that represents provided number of data bytes.

Return type:

int

classmethod get_min_dlc(data_bytes_number)[source]

Get a minimum value of CAN DLC that is required to carry the provided number of data bytes in a CAN frame.

Parameters:

data_bytes_number (int) – Number of data bytes in a CAN frame.

Returns:

Minimum CAN DLC value that is required to carry provided number of data bytes in a CAN frame.

Return type:

int

classmethod is_can_fd_specific_dlc(dlc)[source]

Check whether the provided DLC value is CAN FD specific.

Parameters:

dlc (int) – Value of DLC to check.

Returns:

True if provided DLC value is CAN FD specific, False otherwise.

Return type:

bool

classmethod validate_dlc(value)[source]

Validate whether the provided value is a valid value of CAN DLC.

Parameters:

value (int) – Value to validate.

Raises:
  • TypeError – Provided values is not int type.

  • ValueError – Provided value is not a valid DLC value.

Return type:

None

classmethod validate_data_bytes_number(value, exact_value=True)[source]

Validate whether the provided number of data bytes might be carried in a CAN frame.

Parameters:
  • value (int) – Value to validate.

  • exact_value (bool) –

    Informs whether the value must be the exact number of data bytes in a CAN frame.

    • True - provided value must be the exact number of data bytes to be carried by a CAN frame.

    • False - provided value must be a number of data bytes that could be carried by a CAN frame (CAN Frame Data Padding is allowed).

Raises:
  • TypeError – Provided values is not int type.

  • ValueError – Provided value is not number of data bytes that matches the criteria.

Return type:

None