uds.can.consecutive_frame

Implementation specific for Consecutive Frame CAN packets.

This module contains implementation specific for Consecutive Frame packets - that includes Sequence Number (SN) parameter.

Module Contents

Classes

CanConsecutiveFrameHandler

Helper class that provides utilities for Consecutive Frame CAN Packets.

class uds.can.consecutive_frame.CanConsecutiveFrameHandler[source]

Helper class that provides utilities for Consecutive Frame CAN Packets.

CONSECUTIVE_FRAME_N_PCI: int = 2

Consecutive Frame N_PCI value.

SN_BYTES_USED: int = 1

Number of CAN Frame data bytes used to carry CAN Packet Type and Sequence Number in Consecutive Frame.

classmethod create_valid_frame_data(*, addressing_format, payload, sequence_number, dlc=None, filler_byte=DEFAULT_FILLER_BYTE, target_address=None, address_extension=None)[source]

Create a data field of a CAN frame that carries a valid Consecutive Frame packet.

Note

This method can only be used to create a valid (compatible with ISO 15765 - Diagnostic on CAN) output. Use create_any_frame_data() to create data bytes for a Consecutive Frame with any (also incompatible with ISO 15765) parameters values.

Parameters:
  • addressing_format (uds.can.addressing_format.CanAddressingFormat) – CAN addressing format used by a considered Consecutive Frame.

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

  • sequence_number (int) – Value of Sequence Number parameter.

  • dlc (Optional[int]) –

    DLC value of a CAN frame that carries a considered 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 the unused data bytes.

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

  • target_address (Optional[int]) – Target Address value carried by this CAN Packet. The value must only be provided if addressing_format uses Target Address parameter.

  • address_extension (Optional[int]) – Address Extension value carried by this CAN packet. The value must only be provided if addressing_format uses Address Extension parameter.

Raises:

InconsistentArgumentsError – Provided payload contains invalid number of bytes to fit it into a properly defined Consecutive Frame data field.

Returns:

Raw bytes of CAN frame data for the provided Consecutive Frame packet information.

Return type:

uds.utilities.RawBytesListAlias

classmethod create_any_frame_data(*, addressing_format, payload, sequence_number, dlc, filler_byte=DEFAULT_FILLER_BYTE, target_address=None, address_extension=None)[source]

Create a data field of a CAN frame that carries a Consecutive Frame packet.

Note

You can use this method to create Consecutive Frame data bytes with any (also inconsistent with ISO 15765) parameters values. It is recommended to use create_valid_frame_data() to create data bytes for a Consecutive Frame with valid (compatible with ISO 15765) parameters values.

Parameters:
  • addressing_format (uds.can.addressing_format.CanAddressingFormat) – CAN addressing format used by a considered Consecutive Frame.

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

  • sequence_number (int) – Value of Sequence Number parameter.

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

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

  • target_address (Optional[int]) – Target Address value carried by this CAN Packet. The value must only be provided if addressing_format uses Target Address parameter.

  • address_extension (Optional[int]) – Address Extension value carried by this CAN packet. The value must only be provided if addressing_format uses Address Extension parameter.

Raises:

InconsistentArgumentsError – Provided payload contains too many bytes to fit it into a Consecutive Frame data field.

Returns:

Raw bytes of CAN frame data for the provided Consecutive Frame packet information.

Return type:

uds.utilities.RawBytesListAlias

classmethod is_consecutive_frame(addressing_format, raw_frame_data)[source]

Check if provided data bytes encodes a Consecutive Frame packet.

Warning

The method does not validate the content of the provided frame data bytes. Only, CAN Packet Type (N_PCI) parameter is checked whether contain Consecutive Frame N_PCI value.

Parameters:
Returns:

True if provided data bytes carries Consecutive Frame, False otherwise.

Return type:

bool

classmethod decode_payload(addressing_format, raw_frame_data)[source]

Extract diagnostic message payload from Consecutive Frame data bytes.

Warning

The output might contain additional filler bytes (they are not part of diagnostic message payload) that were added during CAN Frame Data Padding. The presence of filler bytes in Consecutive Frame cannot be determined basing solely on the information contained in a Consecutive Frame data bytes.

Warning

The method does not validate the content of the provided frame data bytes. There is no guarantee of the proper output when frame data in invalid format (incompatible with ISO 15765) is provided.

Parameters:
Raises:

ValueError – Provided frame data of a CAN frames does not carry a Consecutive Frame CAN packet.

Returns:

Payload bytes (with potential Filler Bytes) of a diagnostic message carried by a considered Consecutive Frame.

Return type:

uds.utilities.RawBytesListAlias

classmethod decode_sequence_number(addressing_format, raw_frame_data)[source]

Extract a value of Sequence Number from Consecutive Frame data bytes.

Warning

The method does not validate the content of the provided frame data bytes. There is no guarantee of the proper output when frame data in invalid format (incompatible with ISO 15765) is provided.

Parameters:
Raises:

ValueError – Provided frame data of a CAN frames does not carry a Consecutive Frame CAN packet.

Returns:

Extracted value of Sequence Number.

Return type:

int

classmethod get_min_dlc(addressing_format, payload_length=1)[source]

Get the minimum value of a CAN frame DLC to carry a Consecutive Frame packet.

Parameters:
Raises:
  • TypeError – Provided value of Payload Length is not integer value.

  • ValueError – Provided value of Payload Length is out of range.

  • InconsistentArgumentsError – Provided Addressing Format and Payload Length values cannot be used together.

Returns:

The lowest value of DLC that enables to fit in provided Consecutive Frame packet data.

Return type:

int

classmethod get_max_payload_size(addressing_format=None, dlc=None)[source]

Get the maximum size of a payload that can fit into Consecutive Frame data bytes.

Parameters:
  • addressing_format (Optional[uds.can.addressing_format.CanAddressingFormat]) – CAN addressing format that considered CAN packet uses. Leave None to get the result for CAN addressing format that does not use data bytes for carrying addressing information.

  • dlc (Optional[int]) – DLC value of a CAN frame that carries a considered CAN Packet. Leave None to get the result for the greatest possible DLC value.

Raises:

InconsistentArgumentsError – Consecutive Frame packet cannot use provided attributes according to ISO 15765.

Returns:

The maximum number of payload bytes that could fit into a considered Consecutive Frame.

Return type:

int

classmethod validate_frame_data(addressing_format, raw_frame_data)[source]

Validate whether data field of a CAN Packet carries a properly encoded Consecutive Frame.

Parameters:
Raises:
  • ValueError – Provided frame data of a CAN frames does not carry a Consecutive Frame CAN packet.

  • InconsistentArgumentsError – Provided frame data of a CAN frames does not carry a properly encoded Consecutive Frame CAN packet.

Return type:

None

classmethod __encode_sn(sequence_number)

Create Consecutive Frame data bytes with CAN Packet Type and Sequence Number parameters.

Parameters:

sequence_number (int) – Value of the sequence number parameter.

Returns:

Consecutive Frame data bytes containing CAN Packet Type and Sequence Number parameters.

Return type:

uds.utilities.RawBytesListAlias