uds.can.flow_control ==================== .. py:module:: uds.can.flow_control .. autoapi-nested-parse:: Implementation specific for Flow Control CAN packets. This module contains implementation of :ref:`Flow Control CAN packet ` attributes: - :ref:`Flow Status ` - :ref:`Block Size ` - :ref:`Separation Time minimum (STmin) ` Attributes ---------- .. autoapisummary:: uds.can.flow_control.FlowControlParametersAlias Exceptions ---------- .. autoapisummary:: uds.can.flow_control.UnrecognizedSTminWarning Classes ------- .. autoapisummary:: uds.can.flow_control.CanFlowStatus uds.can.flow_control.CanSTminTranslator uds.can.flow_control.CanFlowControlHandler uds.can.flow_control.AbstractFlowControlParametersGenerator uds.can.flow_control.DefaultFlowControlParametersGenerator Module Contents --------------- .. py:exception:: UnrecognizedSTminWarning Bases: :py:obj:`Warning` .. autoapi-inheritance-diagram:: uds.can.flow_control.UnrecognizedSTminWarning :parts: 1 :private-bases: Warning about STmin value that is reserved and therefore not implemented. .. note:: If you have a documentation that defines a meaning of :ref:`STmin ` value for which this warning was raised, please create a request in `issues management system `_ and provide this documentation for us. Initialize self. See help(type(self)) for accurate signature. .. py:class:: CanFlowStatus Bases: :py:obj:`uds.utilities.ValidatedEnum`, :py:obj:`uds.utilities.NibbleEnum` .. autoapi-inheritance-diagram:: uds.can.flow_control.CanFlowStatus :parts: 1 :private-bases: Definition of Flow Status values. :ref:`Flow Status (FS) ` is a 4-bit value that enables controlling Consecutive Frames transmission. Initialize self. See help(type(self)) for accurate signature. .. py:attribute:: ContinueToSend :type: CanFlowStatus :value: 0 Asks to resume Consecutive Frames transmission. .. py:attribute:: Wait :type: CanFlowStatus :value: 1 Asks to pause Consecutive Frames transmission. .. py:attribute:: Overflow :type: CanFlowStatus :value: 2 Asks to abort transmission of a diagnostic message. .. py:class:: CanSTminTranslator Helper class that provides STmin values mapping. :ref:`Separation Time minimum (STmin) ` informs about minimum time gap between a transmission of two following Consecutive Frames. .. py:attribute:: MAX_STMIN_TIME :type: uds.utilities.TimeMillisecondsAlias :value: 127 Maximal time value (in milliseconds) of STmin. .. py:attribute:: MIN_VALUE_MS_RANGE :type: int :value: 0 Minimal value of STmin in milliseconds range (raw value and time value in milliseconds are equal). .. py:attribute:: MAX_VALUE_MS_RANGE :type: int :value: 127 Maximal value of STmin in milliseconds range (raw value and time value in milliseconds are equal). .. py:attribute:: MIN_RAW_VALUE_100US_RANGE :type: int :value: 241 Minimal raw value of STmin in 100 microseconds range. .. py:attribute:: MAX_RAW_VALUE_100US_RANGE :type: int :value: 249 Maximal raw value of STmin in 100 microseconds range. .. py:attribute:: MIN_TIME_VALUE_100US_RANGE :type: uds.utilities.TimeMillisecondsAlias :value: 0.1 Minimal time value (in milliseconds) of STmin in 100 microseconds range. .. py:attribute:: MAX_TIME_VALUE_100US_RANGE :type: uds.utilities.TimeMillisecondsAlias :value: 0.9 Maximal time value (in milliseconds) of STmin in 100 microseconds range. .. py:attribute:: __FLOATING_POINT_ACCURACY :type: int :value: 10 Accuracy used for floating point values (rounding is necessary due to float operation in python). .. py:method:: decode(raw_value) :classmethod: Map raw value of STmin into time value. .. note:: According to ISO 15765-2, if a raw value of STmin that is not recognized by its recipient, then the longest STmin time value (0x7F = 127 ms) shall be used instead. :param raw_value: Raw value of STmin. :return: STmin time in milliseconds. .. py:method:: encode(time_value) :classmethod: Map time value of STmin into raw value. :param time_value: STmin time in milliseconds. :raise TypeError: Provided value is not int or flow type. :raise ValueError: Value out of supported range. :return: Raw value of STmin. .. py:method:: is_time_value(value) :classmethod: Check if provided value is a valid time value of STmin. :param value: Value to check. :return: True if provided value is a valid time value of STmin, False otherwise. .. py:method:: _is_ms_value(value) :classmethod: Check if provided argument is STmin time value in milliseconds. :param value: Value to check. :return: True if provided valid value of STmin time in milliseconds, False otherwise. .. py:method:: _is_100us_value(value) :classmethod: Check if provided argument is STmin time value in 100 microseconds. :param value: Value to check. :return: True if provided valid value of STmin time in 100 microseconds, False otherwise. .. py:class:: CanFlowControlHandler Helper class that provides utilities for Flow Control CAN Packets. .. py:attribute:: FLOW_CONTROL_N_PCI :type: int :value: 3 N_PCI value of Flow Control. .. py:attribute:: FS_BYTES_USED :type: int :value: 3 Number of CAN Frame data bytes used to carry CAN Packet Type, Flow Status, Block Size and STmin. .. py:attribute:: BS_BYTE_POSITION :type: int :value: 1 Position of a data byte with :ref:`Block Size ` parameter. .. py:attribute:: STMIN_BYTE_POSITION :type: int :value: 2 Position of a data byte with :ref:`STmin ` parameter. .. py:method:: create_valid_frame_data(*, addressing_format, flow_status, block_size = None, st_min = None, 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 Flow Control packet. .. note:: This method can only be used to create a valid (compatible with ISO 15765 - Diagnostic on CAN) output. Use :meth:`~uds.can.flow_control.FlowControlHandler.create_any_frame_data` to create data bytes for a Flow Control with any (also incompatible with ISO 15765) parameters values. :param addressing_format: CAN addressing format used by a considered Flow Control. :param flow_status: Value of Flow Status parameter. :param block_size: Value of Block Size parameter. This parameter is only required with ContinueToSend Flow Status, leave None otherwise. :param st_min: Value of Separation Time minimum (STmin) parameter. This parameter is only required with ContinueToSend Flow Status, leave None otherwise. :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: Invalid DLC value was provided. :return: Raw bytes of CAN frame data for the provided Flow Control packet information. .. py:method:: create_any_frame_data(*, addressing_format, flow_status, dlc, block_size = None, st_min = None, filler_byte = DEFAULT_FILLER_BYTE, target_address = None, address_extension = None) :classmethod: Create a data field of a CAN frame that carries a Flow Control packet. .. note:: You can use this method to create Flow Control data bytes with any (also inconsistent with ISO 15765) parameters values. It is recommended to use :meth:`~uds.can.flow_control.FlowControlHandler.create_valid_frame_data` to create data bytes for a Flow Control with valid (compatible with ISO 15765) parameters values. :param addressing_format: CAN addressing format used by a considered Flow Control. :param flow_status: Value of Flow Status parameter. :param st_min: Value of Separation Time minimum (STmin) parameter. Leave None to not insert this parameter in a Flow Control data bytes. :param block_size: Value of Block Size parameter. Leave None to not insert this parameter in a Flow Control data bytes. :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: DLC value is too small. :return: Raw bytes of CAN frame data for the provided Flow Control packet information. .. py:method:: is_flow_control(addressing_format, raw_frame_data) :classmethod: Check if provided data bytes encodes a Flow Control 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 Flow Control 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 Flow Control, False otherwise. .. py:method:: decode_flow_status(addressing_format, raw_frame_data) :classmethod: Extract Flow Status value from Flow Control 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 Flow Control CAN packet. :return: Flow Status value carried by a considered Flow Control. .. py:method:: decode_block_size(addressing_format, raw_frame_data) :classmethod: Extract Block Size value from Flow Control 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 Flow Control CAN packet with Continue To Send Flow Status. :return: Block Size value carried by a considered Flow Control. .. py:method:: decode_st_min(addressing_format, raw_frame_data) :classmethod: Extract STmin value from Flow Control 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 Flow Control CAN packet with Continue To Send Flow Status. :return: Separation Time minimum (STmin) value carried by a considered Flow Control. .. py:method:: get_min_dlc(addressing_format) :classmethod: Get the minimum value of a CAN frame DLC to carry a Flow Control packet. :param addressing_format: CAN addressing format that considered CAN packet uses. :return: The lowest value of DLC that enables to fit in provided Flow Control packet data. .. py:method:: validate_frame_data(addressing_format, raw_frame_data) :classmethod: Validate whether data field of a CAN Packet carries a properly encoded Flow Control. :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 properly encoded Flow Control CAN packet. .. py:method:: __encode_valid_flow_status(flow_status, block_size = None, st_min = None, filler_byte = DEFAULT_FILLER_BYTE) :classmethod: Create Flow Control data bytes with CAN Packet Type and Flow Status, Block Size and STmin parameters. .. note:: This method can only be used to create a valid (compatible with ISO 15765 - Diagnostic on CAN) output. :param flow_status: Value of Flow Status parameter. :param block_size: Value of Block Size parameter. This parameter is only required with ContinueToSend Flow Status, leave None otherwise. :param st_min: Value of Separation Time minimum (STmin) parameter. This parameter is only required with ContinueToSend Flow Status, leave None otherwise. :param filler_byte: Filler Byte value to use for CAN Frame Data Padding. :return: Flow Control data bytes with CAN Packet Type and Flow Status, Block Size and STmin parameters. .. py:method:: __encode_any_flow_status(flow_status, block_size = None, st_min = None) :classmethod: Create Flow Control data bytes with CAN Packet Type and Flow Status, Block Size and STmin parameters. .. note:: This method can be used to create any (also incompatible with ISO 15765 - Diagnostic on CAN) output. :param flow_status: Value of Flow Status parameter. :param block_size: Value of Block Size parameter. Leave None to skip the Block Size byte in the output. :param st_min: Value of Separation Time minimum (STmin) parameter. Leave None to skip the STmin byte in the output. :return: Flow Control data bytes with CAN Packet Type and Flow Status, Block Size and STmin parameters. Some of the parameters might be missing if certain arguments were provided. .. py:data:: FlowControlParametersAlias Alias of :ref:`Flow Control ` parameters which contains: - :ref:`Flow Status ` - :ref:`Block Size ` - :ref:`Separation Time minimum ` .. py:class:: AbstractFlowControlParametersGenerator Bases: :py:obj:`abc.ABC` .. autoapi-inheritance-diagram:: uds.can.flow_control.AbstractFlowControlParametersGenerator :parts: 1 :private-bases: Definition of Flow Control parameters generator. .. py:method:: __iter__() Get iterator object - called on each First Frame reception. .. py:method:: __next__() :abstractmethod: Generate next set of Flow Control parameters - called on each Flow Control message building. :return: Tuple with values of Flow Control parameters (Flow Status, Block Size, ST min). .. py:class:: DefaultFlowControlParametersGenerator(block_size = 0, st_min = 0, wait_count = 0, repeat_wait = False) Bases: :py:obj:`AbstractFlowControlParametersGenerator` .. autoapi-inheritance-diagram:: uds.can.flow_control.DefaultFlowControlParametersGenerator :parts: 1 :private-bases: Default (recommended to use) Flow Control parameters generator. Every generated Flow Control parameters will contain the same (valid) values. Set values of Block Size and Separation Time minimum parameters to use. :param block_size: Value of :ref:`Block Size ` parameter to use. :param st_min: Value of :ref:`Separation Time minimum ` parameter to use. :param wait_count: Number of Flow Control packets to send with :ref:`Flow Status ` equal 1 (wait). :param repeat_wait: How to send Flow Control packets with WAIT Flow Status: - True - send them before every Flow Control packet with Flow Status=0 (continue to send) - False - send them only once before the first Flow Control packet with Flow Status=0 (continue to send) .. py:property:: block_size :type: int Value of :ref:`Block Size ` parameter. .. py:property:: st_min :type: int Value of :ref:`Separation Time minimum ` parameter. .. py:property:: wait_count :type: int Get number of Flow Control packets to send with WAIT :ref:`Flow Status `. .. py:property:: repeat_wait :type: bool Flag informing how to send Flow Control packets with WAIT Flow Status. - True - send them before every Flow Control packet with Flow Status=0 (continue to send) - False - send them only once before the first Flow Control packet with Flow Status=0 (continue to send) .. py:attribute:: _remaining_wait :type: Optional[int] :value: None .. py:method:: __iter__() Get iterator object. .. py:method:: __next__() Generate next set of Flow Control parameters. :return: Tuple with values of Flow Control parameters: - :ref:`Flow Status ` - :ref:`Block Size ` - :ref:`Separation Time minimum `