uds.can.packet.can_packet

Implementation of CAN Packet.

Classes

CanPacket

Definition of a CAN Packet.

Module Contents

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

Bases: uds.can.packet.abstract_container.AbstractCanPacketContainer, uds.packet.AbstractPacket

Inheritance diagram of uds.can.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. Later on, such object might be transmitted. Once a packet is transmitted, its historic data would be stored in CanPacketRecord.

Create a storage for a single CAN packet.

Parameters:
  • addressing_format (uds.can.addressing.CanAddressingFormat) – CAN Addressing Format used.

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

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

  • can_id (Optional[int]) – CAN Identifier value that is used by this packet. You do not have to provide it 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. You do not have to provide it if can_id parameter unambiguously determine TARGET ADDRESS value.

  • source_address (Optional[int]) – Source Address value carried by this CAN packet. Leave None if provided addressing_format does not use Source Address parameter. You do not have to provide it if can_id parameter unambiguously determine SOURCE ADDRESS value.

  • 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.

__raw_frame_data: bytes = b''
property addressing_format: uds.can.addressing.CanAddressingFormat

CAN Addressing Format used by this CAN packet.

Return type:

uds.can.addressing.CanAddressingFormat

__str__()[source]

Present object in string format.

Return type:

str

property can_id: int

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

Return type:

int

property raw_frame_data: bytes

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

Return type:

bytes

property addressing_type: uds.addressing.AddressingType

Addressing type for which this CAN packet is relevant.

Return type:

uds.addressing.AddressingType

set_addressing_information(*, 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.

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

  • can_id (Optional[int]) – CAN Identifier value that is used by this packet. You do not have to provide it 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. You do not have to provide it if can_id parameter unambiguously determine TARGET ADDRESS value.

  • source_address (Optional[int]) – Source Address value carried by this CAN packet. Leave None if provided addressing_format does not use Source Address parameter. You do not have to provide it if can_id parameter unambiguously determine SOURCE ADDRESS value.

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

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.can.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.

Return type:

None