uds.packet.can_packet

CAN bus specific implementation of UDS packets.

Module Contents

Classes

CanPacket

Definition of a CAN packet.

class uds.packet.can_packet.CanPacket(*, packet_type, addressing_format, addressing_type, can_id=None, target_address=None, source_address=None, address_extension=None, dlc=None, **packet_type_specific_kwargs)[source]

Bases: uds.packet.abstract_can_packet_container.AbstractCanPacketContainer, uds.packet.abstract_packet.AbstractUdsPacket

Inheritance diagram of uds.packet.can_packet.CanPacket

Definition of a CAN packet.

Objects of this class act as a storage for all relevant attributes of a CAN packet.

Create a storage for a single CAN packet.

Parameters:
  • packet_type (uds.packet.can_packet_type.CanPacketType) – Type of this CAN packet.

  • addressing_format (uds.can.CanAddressingFormat) – CAN addressing format that this CAN packet uses.

  • addressing_type (uds.transmission_attributes.AddressingType) – Addressing type for which this CAN packet is relevant.

  • can_id (Optional[int]) – CAN Identifier value that is used by this packet. Leave None if other arguments unambiguously determine CAN ID value.

  • target_address (Optional[int]) – Target Address value carried by this CAN Packet. Leave None if provided addressing_format does not use Target Address parameter or the value of Target Address was provided in can_id parameter.

  • source_address (Optional[int]) – Source Address value carried by this CAN packet. Leave None if provided addressing_format does not use Source Address parameter or the value of Source Address was provided in can_id parameter.

  • address_extension (Optional[int]) – Address Extension value carried by this CAN packet. Leave None if provided addressing_format does not use Address Extension parameter.

  • dlc (Optional[int]) –

    DLC value of a CAN frame that carries this CAN Packet.

    • None - use CAN Data Frame Optimization (CAN ID value will be automatically determined)

    • int type value - DLC value to set. CAN Data Padding will be used to fill unused data bytes.

    Warning

    You have to provide DLC value for packets of First Frame type.

  • packet_type_specific_kwargs (Any) –

    Arguments that are specific for provided CAN Packet Type.

    • parameter filler_byte:

      (optional for: SF, CF and FC) Filler Byte value to use for CAN Frame Data Padding.

    • parameter payload:

      (required for: SF, FF and CF) Payload of a diagnostic message that is carried by this CAN packet.

    • parameter data_length:

      (required for: FF) Number of payload bytes of a diagnostic message initiated by this First Frame packet.

    • parameter sequence_number:

      (required for: CF) Sequence number value of this Consecutive Frame.

    • parameter flow_status:

      (required for: FC) Flow status information carried by this Flow Control frame.

    • parameter block_size:

      (required for: FC with ContinueToSend Flow Status) Block size information carried by this Flow Control frame.

    • parameter st_min:

      (required for: FC with ContinueToSend Flow Status) Separation Time minimum information carried by this Flow Control frame.

property raw_frame_data: uds.utilities.RawBytesTupleAlias

Raw data bytes of a CAN frame that carries this CAN packet.

Return type:

uds.utilities.RawBytesTupleAlias

property can_id: int

CAN Identifier (CAN ID) of a CAN Frame that carries this CAN packet.

Return type:

int

property addressing_format: uds.can.CanAddressingFormat

CAN addressing format used by this CAN packet.

Return type:

uds.can.CanAddressingFormat

property addressing_type: uds.transmission_attributes.AddressingType

Addressing type for which this CAN packet is relevant.

Return type:

uds.transmission_attributes.AddressingType

property dlc: int

Value of Data Length Code (DLC) of a CAN Frame that carries this CAN packet.

Return type:

int

property packet_type: uds.packet.can_packet_type.CanPacketType

Type (N_PCI value) of this CAN packet.

Return type:

uds.packet.can_packet_type.CanPacketType

property target_address: int | None

Target Address (TA) value of this CAN Packet.

Target Address value is used with following addressing formats:

None in other cases.

Return type:

Optional[int]

property source_address: int | None

Source Address (SA) value of this CAN Packet.

Source Address value is used with following addressing formats:

None in other cases.

Return type:

Optional[int]

property address_extension: int | None

Address Extension (AE) value of this CAN Packet.

Address Extension is used with following addressing formats:

None in other cases.

Return type:

Optional[int]

set_address_information(*, addressing_format, addressing_type, can_id=None, target_address=None, source_address=None, address_extension=None)[source]

Change addressing information for this CAN packet.

This function enables to change an entire Network Address Information for a CAN packet.

Parameters:
  • addressing_format (uds.can.CanAddressingFormat) – CAN addressing format that this CAN packet uses.

  • addressing_type (uds.transmission_attributes.AddressingType) – Addressing type for which this CAN packet is relevant.

  • can_id (Optional[int]) – CAN Identifier value that is used by this packet. Leave None if other arguments unambiguously determine CAN ID value.

  • target_address (Optional[int]) – Target Address value carried by this CAN Packet. Leave None if provided addressing_format does not use Target Address parameter or the value of Target Address was provided in can_id parameter.

  • source_address (Optional[int]) – Source Address value carried by this CAN packet. Leave None if provided addressing_format does not use Source Address parameter or the value of Source Address was provided in can_id parameter.

  • address_extension (Optional[int]) – Address Extension value carried by this CAN packet. Leave None if provided addressing_format does not use Address Extension parameter.

Raises:

NotImplementedError – There is missing implementation for the provided Addressing Format. Please create an issue in our Issues Tracking System with detailed description if you face this error.

Return type:

None

set_address_information_normal_11bit(addressing_type, can_id)[source]

Change addressing information for this CAN packet to use Normal 11-bit Addressing format.

Parameters:
  • addressing_type (uds.transmission_attributes.AddressingType) – Addressing type for which this CAN packet is relevant.

  • can_id (int) – CAN Identifier value that is used by this packet.

Return type:

None

set_address_information_normal_fixed(addressing_type, can_id=None, target_address=None, source_address=None)[source]

Change addressing information for this CAN packet to use Normal Fixed Addressing format.

Parameters:
  • addressing_type (uds.transmission_attributes.AddressingType) – Addressing type for which this CAN packet is relevant.

  • can_id (Optional[int]) – CAN Identifier value that is used by this packet. Leave None if the values of target_address and source_address parameters are provided.

  • target_address (Optional[int]) – Target Address value carried by this CAN Packet. Leave None if the value of can_id parameter is provided.

  • source_address (Optional[int]) – Source Address value carried by this CAN packet. Leave None if the value of can_id parameter is provided.

Return type:

None

set_address_information_extended(addressing_type, can_id, target_address)[source]

Change addressing information for this CAN packet to use Extended Addressing format.

Parameters:
  • addressing_type (uds.transmission_attributes.AddressingType) – Addressing type for which this CAN packet is relevant.

  • can_id (int) – CAN Identifier value that is used by this packet.

  • target_address (int) – Target Address value carried by this CAN Packet.

Return type:

None

set_address_information_mixed_11bit(addressing_type, can_id, address_extension)[source]

Change addressing information for this CAN packet to use Mixed 11-bit Addressing format.

Parameters:
  • addressing_type (uds.transmission_attributes.AddressingType) – Addressing type for which this CAN packet is relevant.

  • can_id (int) – CAN Identifier value that is used by this packet.

  • address_extension (int) – Address Extension value carried by this CAN packet.

Return type:

None

set_address_information_mixed_29bit(addressing_type, address_extension, can_id=None, target_address=None, source_address=None)[source]

Change addressing information for this CAN packet to use Mixed 29-bit Addressing format.

Parameters:
  • addressing_type (uds.transmission_attributes.AddressingType) – Addressing type for which this CAN packet is relevant.

  • can_id (Optional[int]) – CAN Identifier value that is used by this packet. Leave None if the values of target_address and source_address parameters are provided.

  • target_address (Optional[int]) – Target Address value carried by this CAN Packet. Leave None if the value of can_id parameter is provided.

  • source_address (Optional[int]) – Source Address value carried by this CAN packet. Leave None if the value of can_id parameter is provided.

  • address_extension (int) – Address Extension value carried by this CAN packet.

Return type:

None

set_packet_data(*, packet_type, dlc=None, **packet_type_specific_kwargs)[source]

Change packet type and data field of this CAN packet.

This function enables to change an entire Network Data Field and Network Protocol Control Information for a CAN packet.

Parameters:
  • packet_type (uds.packet.can_packet_type.CanPacketType) – Type of this CAN packet.

  • dlc (Optional[int]) –

    DLC value of a CAN frame that carries this CAN Packet.

    • None - use CAN Data Frame Optimization (CAN ID value will be automatically determined)

    • int type value - DLC value to set. CAN Data Padding will be used to fill unused data bytes.

    Warning

    You have to provide DLC value for packets of First Frame type.

  • packet_type_specific_kwargs (Any) –

    Arguments that are specific for provided CAN Packet Type.

    • parameter filler_byte:

      (optional for: SF, CF and FC) Filler Byte value to use for CAN Frame Data Padding.

    • parameter payload:

      (required for: SF, FF and CF) Payload of a diagnostic message that is carried by this CAN packet.

    • parameter data_length:

      (required for: FF) Number of payload bytes of a diagnostic message initiated by this First Frame packet.

    • parameter sequence_number:

      (required for: CF) Sequence number value of this Consecutive Frame.

    • parameter flow_status:

      (required for: FC) Flow status information carried by this Flow Control frame.

    • parameter block_size:

      (required for: FC with ContinueToSend Flow Status) Block size information carried by this Flow Control frame.

    • parameter st_min:

      (required for: FC with ContinueToSend Flow Status) Separation Time minimum information carried by this Flow Control frame.

Raises:

NotImplementedError

There is missing implementation for the provided CAN Packet Type. Please create an issue in our Issues Tracking System with detailed description if you face this error.

Return type:

None

set_single_frame_data(payload, dlc=None, filler_byte=DEFAULT_FILLER_BYTE)[source]

Change packet type (to Single Frame) and data field of this CAN packet.

This function enables to change an entire Network Data Field and Network Protocol Control Information for a Single Frame.

Parameters:
  • payload (uds.utilities.RawBytesAlias) – Payload of a diagnostic message that is carried by this CAN packet.

  • dlc (Optional[int]) –

    DLC value of a CAN frame that carries this CAN Packet.

    • None - use CAN Data Frame Optimization (CAN ID value will be automatically determined)

    • int type value - DLC value to set. CAN Data Padding will be used to fill unused data bytes.

  • filler_byte (int) – Filler Byte value to use for CAN Frame Data Padding.

Return type:

None

set_first_frame_data(dlc, payload, data_length)[source]

Change packet type (to First Frame) and data field of this CAN packet.

This function enables to change an entire Network Data Field and Network Protocol Control Information for a First Frame.

Parameters:
  • dlc (int) – DLC value of a CAN frame that carries this CAN Packet.

  • payload (uds.utilities.RawBytesAlias) – Payload of a diagnostic message that is carried by this CAN packet.

  • data_length (int) – Number of payload bytes of a diagnostic message initiated by this First Frame packet.

Return type:

None

set_consecutive_frame_data(payload, sequence_number, dlc=None, filler_byte=DEFAULT_FILLER_BYTE)[source]

Change packet type (to Consecutive Frame) and data field of this CAN packet.

This function enables to change an entire Network Data Field and Network Protocol Control Information for a Consecutive Frame.

Parameters:
  • payload (uds.utilities.RawBytesAlias) – Payload of a diagnostic message that is carried by this CAN packet.

  • sequence_number (int) – Sequence number value of this Consecutive Frame.

  • dlc (Optional[int]) –

    DLC value of a CAN frame that carries this CAN Packet.

    • None - use CAN Data Frame Optimization (CAN ID value will be automatically determined)

    • int type value - DLC value to set. CAN Data Padding will be used to fill unused data bytes.

  • filler_byte (int) – Filler Byte value to use for CAN Frame Data Padding.

Return type:

None

set_flow_control_data(flow_status, block_size=None, st_min=None, dlc=None, filler_byte=DEFAULT_FILLER_BYTE)[source]

Change packet type (to Flow Control) and data field of this CAN packet.

This function enables to change an entire Network Data Field and Network Protocol Control Information for a Flow Control.

Parameters:
  • flow_status (uds.can.CanFlowStatus) – Flow status information carried by this Flow Control frame.

  • block_size (Optional[int]) – Block size information carried by this Flow Control frame.

  • st_min (Optional[int]) – Separation Time minimum information carried by this Flow Control frame.

  • dlc (Optional[int]) –

    DLC value of a CAN frame that carries this CAN Packet.

    • None - use CAN Data Frame Optimization (CAN ID value will be automatically determined)

    • int type value - DLC value to set. CAN Data Padding will be used to fill unused data bytes.

  • filler_byte (int) – Filler Byte value to use for CAN Frame Data Padding.

Return type:

None

__validate_unambiguous_ai_change(addressing_format)

Validate whether CAN Addressing Format change to provided value is ambiguous.

Parameters:

addressing_format (uds.can.CanAddressingFormat) – Desired value of CAN Addressing Format.

Raises:

AmbiguityError – Cannot change value because the operation is ambiguous.

Return type:

None

__update_ai_data_byte()

Update the value of raw_frame_data attribute after Addressing Information change.

Return type:

None