uds.can.consecutive_frame ========================= .. py:module:: uds.can.consecutive_frame .. autoapi-nested-parse:: Implementation specific for Consecutive Frame CAN packets. This module contains implementation specific for :ref:`Consecutive Frame ` packets - that includes :ref:`Sequence Number (SN) ` parameter. Classes ------- .. autoapisummary:: uds.can.consecutive_frame.CanConsecutiveFrameHandler Module Contents --------------- .. py:class:: CanConsecutiveFrameHandler Helper class that provides utilities for Consecutive Frame CAN Packets. .. py:attribute:: CONSECUTIVE_FRAME_N_PCI :type: int :value: 2 Consecutive Frame N_PCI value. .. py:attribute:: SN_BYTES_USED :type: int :value: 1 Number of CAN Frame data bytes used to carry CAN Packet Type and Sequence Number in Consecutive Frame. .. py:method:: create_valid_frame_data(*, addressing_format, payload, sequence_number, dlc = None, filler_byte = DEFAULT_FILLER_BYTE, target_address = None, address_extension = None) :classmethod: 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 :meth:`~uds.can.consecutive_frame.CanConsecutiveFrameHandler.create_any_frame_data` to create data bytes for a Consecutive Frame with any (also incompatible with ISO 15765) parameters values. :param addressing_format: CAN addressing format used by a considered Consecutive Frame. :param payload: Payload of a diagnostic message that is carried by a considered CAN packet. :param sequence_number: Value of Sequence Number parameter. :param dlc: 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. :param filler_byte: Filler Byte value to use for CAN Frame Data Padding. :param target_address: Target Address value carried by this CAN Packet. The value must only be provided if `addressing_format` uses Target Address parameter. :param address_extension: Address Extension value carried by this CAN packet. The value must only be provided if `addressing_format` uses Address Extension parameter. :raise InconsistentArgumentsError: Provided `payload` contains invalid number of bytes to fit it into a properly defined Consecutive Frame data field. :return: Raw bytes of CAN frame data for the provided Consecutive Frame packet information. .. py:method:: create_any_frame_data(*, addressing_format, payload, sequence_number, dlc, filler_byte = DEFAULT_FILLER_BYTE, target_address = None, address_extension = None) :classmethod: 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 :meth:`~uds.can.consecutive_frame.CanConsecutiveFrameHandler.create_valid_frame_data` to create data bytes for a Consecutive Frame with valid (compatible with ISO 15765) parameters values. :param addressing_format: CAN addressing format used by a considered Consecutive Frame. :param payload: Payload of a diagnostic message that is carried by a considered CAN packet. :param sequence_number: Value of Sequence Number parameter. :param dlc: DLC value of a CAN frame that carries a considered CAN Packet. :param filler_byte: Filler Byte value to use for CAN Frame Data Padding. :param target_address: Target Address value carried by this CAN Packet. The value must only be provided if `addressing_format` uses Target Address parameter. :param address_extension: Address Extension value carried by this CAN packet. The value must only be provided if `addressing_format` uses Address Extension parameter. :raise InconsistentArgumentsError: Provided `payload` contains too many bytes to fit it into a Consecutive Frame data field. :return: Raw bytes of CAN frame data for the provided Consecutive Frame packet information. .. py:method:: is_consecutive_frame(addressing_format, raw_frame_data) :classmethod: 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, :ref:`CAN Packet Type (N_PCI) ` parameter is checked whether contain Consecutive Frame N_PCI value. :param addressing_format: CAN Addressing Format used. :param raw_frame_data: Raw data bytes of a CAN frame to check. :return: True if provided data bytes carries Consecutive Frame, False otherwise. .. py:method:: decode_payload(addressing_format, raw_frame_data) :classmethod: 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 :ref:`CAN Frame Data Padding `. The presence of filler bytes in :ref:`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. :param addressing_format: CAN Addressing Format used. :param raw_frame_data: Raw data bytes of a considered CAN frame. :raise ValueError: Provided frame data of a CAN frames does not carry a Consecutive Frame CAN packet. :return: Payload bytes (with potential Filler Bytes) of a diagnostic message carried by a considered Consecutive Frame. .. py:method:: decode_sequence_number(addressing_format, raw_frame_data) :classmethod: 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. :param addressing_format: CAN Addressing Format used. :param raw_frame_data: Raw data bytes of a considered CAN frame. :raise ValueError: Provided frame data of a CAN frames does not carry a Consecutive Frame CAN packet. :return: Extracted value of Sequence Number. .. py:method:: get_min_dlc(addressing_format, payload_length = 1) :classmethod: Get the minimum value of a CAN frame DLC to carry a Consecutive Frame packet. :param addressing_format: CAN addressing format that considered CAN packet uses. :param payload_length: Number of payload bytes that considered CAN packet carries. :raise TypeError: Provided value of Payload Length is not int type. :raise ValueError: Provided value of Payload Length is out of range (1 <= value <= MAX Payload Length). :raise InconsistentArgumentsError: Provided Addressing Format and Payload Length values cannot be used together. :return: The lowest value of DLC that enables to fit in provided Consecutive Frame packet data. .. py:method:: get_max_payload_size(addressing_format = None, dlc = None) :classmethod: Get the maximum size of a payload that can fit into Consecutive Frame data bytes. :param addressing_format: 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. :param dlc: DLC value of a CAN frame that carries a considered CAN Packet. Leave None to get the result for the greatest possible DLC value. :raise InconsistentArgumentsError: Consecutive Frame packet cannot use provided attributes according to ISO 15765. :return: The maximum number of payload bytes that could fit into a considered Consecutive Frame. .. py:method:: validate_frame_data(addressing_format, raw_frame_data) :classmethod: Validate whether data field of a CAN Packet carries a properly encoded Consecutive Frame. :param addressing_format: CAN Addressing Format used. :param raw_frame_data: Raw data bytes of a CAN frame to validate. :raise ValueError: Provided frame data of a CAN frames does not carry a Consecutive Frame CAN packet. :raise InconsistentArgumentsError: Provided frame data of a CAN frames does not carry a properly encoded Consecutive Frame CAN packet. .. py:method:: __encode_sn(sequence_number) :classmethod: Create Consecutive Frame data bytes with CAN Packet Type and Sequence Number parameters. :param sequence_number: Value of the sequence number parameter. :return: Consecutive Frame data bytes containing CAN Packet Type and Sequence Number parameters.