uds.can.frame
Implementation for CAN frame fields that are influenced by UDS.
- Handlers for CAN Frame fields:
CAN Identifier
DLC
Data
Attributes
Default value of Filler Byte. |
Classes
Helper class that provides utilities for CAN Identifier field. |
|
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
- CLASSIC_CAN: CanVersion = 'Classic CAN'
Classic CAN 2.0
- CAN_FD: CanVersion = '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)
- 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.
- classmethod is_can_id(value)[source]
Check if the provided value is either Standard (11-bit) or Extended (29-bit) CAN ID.
- classmethod is_standard_can_id(can_id)[source]
Check if the provided value is Standard (11-bit) CAN ID.
- classmethod is_extended_can_id(can_id)[source]
Check if the provided value is Extended (29-bit) CAN ID.
- 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
- __DATA_BYTES_NUMBERS: Tuple[int, Ellipsis] = (0, 1, 2, 3, 4, 5, 6, 7, 8, 12, 16, 20, 24, 32, 48, 64)
- 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 encode_dlc(data_bytes_number)[source]
Map a number of data bytes in a CAN frame into DLC value.
- 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.
- classmethod is_can_fd_specific_dlc(dlc)[source]
Check whether the provided DLC value is CAN FD specific.
- 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