uds.can.single_frame ==================== .. py:module:: uds.can.single_frame .. autoapi-nested-parse:: Implementation specific for Single Frame CAN packets. This module contains implementation specific for :ref:`Single Frame ` packets - that includes :ref:`Single Frame Data Length (SF_DL) ` parameter. Classes ------- .. autoapisummary:: uds.can.single_frame.CanSingleFrameHandler Module Contents --------------- .. py:class:: CanSingleFrameHandler Helper class that provides utilities for Single Frame CAN Packets. .. py:attribute:: SINGLE_FRAME_N_PCI :type: int :value: 0 N_PCI value of Single Frame. .. py:attribute:: MAX_DLC_VALUE_SHORT_SF_DL :type: int :value: 8 Maximum value of DLC for which short :ref:`Single Frame Data Length ` format shall be used. .. py:attribute:: SHORT_SF_DL_BYTES_USED :type: int :value: 1 Number of CAN Frame data bytes used to carry CAN Packet Type and Single Frame Data Length (SF_DL). This value is valid only for the short format using DLC <= 8. .. py:attribute:: LONG_SF_DL_BYTES_USED :type: int :value: 2 Number of CAN Frame data bytes used to carry CAN Packet Type and Single Frame Data Length (SF_DL). This value is valid only for the long format using DLC > 8. .. py:method:: create_valid_frame_data(*, addressing_format, payload, 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 Single 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.single_frame.CanSingleFrameHandler.create_any_frame_data` to create data bytes for a Single Frame with any (also incompatible with ISO 15765) parameters values. :param addressing_format: CAN addressing format used by a considered Single Frame. :param payload: Payload of a diagnostic message that is carried by a considered CAN packet. :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 Single Frame data field. :return: Raw bytes of CAN frame data for the provided Single Frame packet information. .. py:method:: create_any_frame_data(*, addressing_format, payload, dlc, sf_dl_short, sf_dl_long = None, filler_byte = DEFAULT_FILLER_BYTE, target_address = None, address_extension = None) :classmethod: Create a data field of a CAN frame that carries a Single Frame packet. .. note:: You can use this method to create Single Frame data bytes with any (also inconsistent with ISO 15765) parameters values. It is recommended to use :meth:`~uds.can.single_frame.CanSingleFrameHandler.create_valid_frame_data` to create data bytes for a Single Frame with valid (compatible with ISO 15765) parameters values. :param addressing_format: CAN addressing format used by a considered Single Frame. :param payload: Payload of a diagnostic message that is carried by a considered CAN packet. :param dlc: DLC value of a CAN frame that carries a considered CAN Packet. :param sf_dl_short: Value to put into a slot of Single Frame Data Length in short format. :param sf_dl_long: Value to put into a slot of Single Frame Data Length in long format. Leave None to use short (1-byte-long) format of Single Frame Data Length. :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 Single Frame data field. :return: Raw bytes of CAN frame data for the provided Single Frame packet information. .. py:method:: is_single_frame(addressing_format, raw_frame_data) :classmethod: Check if provided data bytes encodes a Single Frame packet. .. warning:: The method does not validate the content (e.g. SF_DL parameter) of the provided frame data bytes. Only, :ref:`CAN Packet Type (N_PCI) ` parameter is checked whether contain Single 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 Single Frame, False otherwise. .. py:method:: decode_payload(addressing_format, raw_frame_data) :classmethod: Extract diagnostic message payload from Single 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. :return: Payload bytes of a diagnostic message carried by a considered Single Frame. .. py:method:: decode_sf_dl(addressing_format, raw_frame_data) :classmethod: Extract a value of Single Frame Data Length from Single 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 NotImplementedError: There is missing implementation for the provided Single Frame Data Length format. Please create an issue in our `Issues Tracking System `_ with detailed description if you face this error. :return: Extracted value of Single Frame Data Length. .. py:method:: get_min_dlc(addressing_format, payload_length) :classmethod: Get the minimum value of a CAN frame DLC to carry a Single 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. :return: The lowest value of DLC that enables to fit in provided Single 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 Single 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: Single Frame packet cannot use provided attributes according to ISO 15765. :return: The maximum number of payload bytes that could fit into a considered Single Frame. .. py:method:: get_sf_dl_bytes_number(dlc) :classmethod: Get number of data bytes used for carrying CAN Packet Type and Single Frame Data Length parameters. :param dlc: DLC value of a considered CAN frame. :return: The number of bytes used for carrying CAN Packet Type and Single Frame Data Length parameters. .. py:method:: validate_frame_data(addressing_format, raw_frame_data) :classmethod: Validate whether data field of a CAN Packet carries a properly encoded Single 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 Single Frame CAN packet. :raise InconsistentArgumentsError: Provided frame data of a CAN frames does not carry a properly encoded Single Frame CAN packet. .. py:method:: validate_sf_dl(sf_dl, dlc, addressing_format = None) :classmethod: Validate a value of Single Frame Data Length. :param sf_dl: Single Frame Data Length value to validate. :param dlc: DLC value to validate. :param addressing_format: Value of CAN Addressing Format to use for Single Frame Data Length value validation. Leave None if you do not want to validate whether payload can fit into a CAN Frame with considered DLC. :raise TypeError: Provided value of Single Frame Data Length is not int type. :raise ValueError: Provided value of Single Frame Data Length is too small. :raise InconsistentArgumentsError: It is impossible for a Single Frame with provided DLC to contain as many payload bytes as the provided value of Single Frame Data Length. .. py:method:: __validate_payload_length(payload_length, ai_data_bytes_number) :classmethod: Validate value of payload length. :param payload_length: Value to validate. :param ai_data_bytes_number: Number of data byte that carry Addressing Information. :raise TypeError: Provided value of payload length is not int type. :raise ValueError: Provided value of payload length is less or equal to 0. :raise InconsistentArgumentsError: Provided value of payload length is greater than maximum value. .. py:method:: __extract_sf_dl_data_bytes(addressing_format, raw_frame_data) :classmethod: Extract data bytes that carries CAN Packet Type and Single Frame Data Length parameters. .. warning:: This method does not check whether provided `raw_frame_data` actually contains Single Frame. :param addressing_format: CAN Addressing Format used. :param raw_frame_data: Raw data bytes of a considered CAN frame. :return: Extracted data bytes with CAN Packet Type and Single Frame Data Length parameters. .. py:method:: __encode_valid_sf_dl(sf_dl, dlc, addressing_format) :classmethod: Create Single Frame data bytes with CAN Packet Type and Single Frame Data Length parameters. .. note:: This method can only be used to create a valid (compatible with ISO 15765 - Diagnostic on CAN) output. :param sf_dl: Number of payload bytes carried by a considered Single Frame. :param dlc: DLC value of a CAN Frame to carry this information. :param addressing_format: Value of CAN Addressing Format to use for Single Frame Data Length value validation. :return: Single Frame data bytes containing CAN Packet Type and Single Frame Data Length parameters. .. py:method:: __encode_any_sf_dl(sf_dl_short = 0, sf_dl_long = None) :classmethod: Create Single Frame data bytes with CAN Packet Type and Single Frame Data Length parameters. .. note:: This method can be used to create any (also incompatible with ISO 15765 - Diagnostic on CAN) output. :param sf_dl_short: Value to put into a slot of Single Frame Data Length in short format. :param sf_dl_long: Value to put into a slot of Single Frame Data Length in long format. Leave None to use short (1-byte-long) format of Single Frame Data Length. :return: Single Frame data bytes containing CAN Packet Type and Single Frame Data Length parameters.