uds.can.packet.flow_control =========================== .. py:module:: uds.can.packet.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.packet.flow_control.FLOW_CONTROL_N_PCI uds.can.packet.flow_control.FS_BYTES_USED uds.can.packet.flow_control.BS_BYTE_POSITION uds.can.packet.flow_control.ST_MIN_BYTE_POSITION uds.can.packet.flow_control.FlowControlParametersAlias Exceptions ---------- .. autoapisummary:: uds.can.packet.flow_control.UnrecognizedSTminWarning Classes ------- .. autoapisummary:: uds.can.packet.flow_control.CanFlowStatus uds.can.packet.flow_control.CanSTminTranslator uds.can.packet.flow_control.AbstractFlowControlParametersGenerator uds.can.packet.flow_control.DefaultFlowControlParametersGenerator Functions --------- .. autoapisummary:: uds.can.packet.flow_control.is_flow_control uds.can.packet.flow_control.validate_flow_control_data uds.can.packet.flow_control.create_flow_control_data uds.can.packet.flow_control.generate_flow_control_data uds.can.packet.flow_control.extract_flow_status uds.can.packet.flow_control.extract_block_size uds.can.packet.flow_control.extract_st_min uds.can.packet.flow_control.get_flow_control_min_dlc uds.can.packet.flow_control.encode_flow_status uds.can.packet.flow_control.generate_flow_status Module Contents --------------- .. py:data:: FLOW_CONTROL_N_PCI :type: int :value: 3 N_PCI value of Flow Control. .. py:data:: 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:data:: BS_BYTE_POSITION :type: int :value: 1 Position of a data byte with :ref:`Block Size ` parameter. .. py:data:: ST_MIN_BYTE_POSITION :type: int :value: 2 Position of a data byte with :ref:`STmin ` parameter. .. py:exception:: UnrecognizedSTminWarning Bases: :py:obj:`Warning` .. autoapi-inheritance-diagram:: uds.can.packet.flow_control.UnrecognizedSTminWarning :parts: 1 :private-bases: Warning about STmin value that is reserved for future definition in ISO 15765 and therefore not implemented. 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.packet.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 float 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:function:: is_flow_control(addressing_format, raw_frame_data) Check if provided data bytes contain a Flow Control packet. .. warning:: The method does not validate the content of the provided frame data bytes. It only checks :ref:`CAN Packet Type (N_PCI) ` parameter for 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:function:: validate_flow_control_data(addressing_format, raw_frame_data) 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: The value of N_PCI in provided data is not Flow Control N_PCI. :raise InconsistencyError: Provided data does not carry all Flow Control parameters. .. py:function:: create_flow_control_data(addressing_format, flow_status, block_size = None, st_min = None, dlc = None, filler_byte = DEFAULT_FILLER_BYTE, target_address = None, address_extension = None) 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 :func:`~uds.can.packet.flow_control.generate_flow_control_data` to generate data bytes with any (also incompatible with ISO 15765) parameters values. :param addressing_format: CAN addressing format used. :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` requires CAN frame data field to contain Target Address parameter. :param address_extension: Address Extension value carried by this CAN packet. The value must only be provided if `addressing_format` requires CAN frame data field to contain Address Extension parameter. :raise InconsistencyError: Invalid DLC value was provided. :return: Raw data bytes of a CAN frame. .. py:function:: generate_flow_control_data(addressing_format, flow_status, dlc, block_size = None, st_min = None, filler_byte = DEFAULT_FILLER_BYTE, target_address = None, address_extension = None) Generate CAN frame data field that carries any combination of Flow Control packet data parameters. .. note:: Crosscheck of provided values is not performed so you might use this function to create data fields that are not compatible with Diagnostic on CAN standard (ISO 15765). :param addressing_format: CAN addressing format used. :param flow_status: Value of Flow Status parameter. :param dlc: DLC value of a CAN frame. :param block_size: Value of Block Size parameter. Leave None to skip this parameter in a Flow Control data bytes. :param st_min: Value of Separation Time minimum (STmin) parameter. Leave None to skip this parameter in a Flow Control 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` requires CAN frame data field to contain Target Address parameter. :param address_extension: Address Extension value carried by this CAN packet. The value must only be provided if `addressing_format` requires CAN frame data field to contain Address Extension parameter. :raise InconsistencyError: Provided DLC value is too small. :return: Raw data bytes of a CAN frame. .. py:function:: extract_flow_status(addressing_format, raw_frame_data) 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 CAN frame. :return: Flow Status value carried by the provided Flow Control data. .. py:function:: extract_block_size(addressing_format, raw_frame_data) 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 CAN frame. :return: Block Size value carried by the provided Flow Control data. .. py:function:: extract_st_min(addressing_format, raw_frame_data) 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 CAN frame. :return: Separation Time minimum (STmin) value carried by the provided Flow Control data. .. py:function:: get_flow_control_min_dlc(addressing_format) Get the minimum value of a CAN frame DLC to carry a Flow Control packet. :param addressing_format: CAN addressing format used. :return: The lowest value of DLC for a Flow Control. .. py:function:: encode_flow_status(flow_status) Create valid Flow Control data bytes that contain Flow Status and N_PCI values. :param flow_status: Value of Flow Status parameter. :return: Flow Control data bytes containing CAN Packet Type and Flow Status parameters. .. py:function:: generate_flow_status(flow_status) Create Flow Control bytes containing Flow Status and N_PCI values. .. 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. :return: Flow Control data bytes containing CAN Packet Type and Flow Status parameters. .. py:data:: FlowControlParametersAlias Alias of :ref:`Flow Control ` parameters which contain: - :ref:`Flow Status ` - :ref:`Block Size ` - :ref:`Separation Time minimum ` .. py:class:: AbstractFlowControlParametersGenerator Bases: :py:obj:`abc.ABC` .. autoapi-inheritance-diagram:: uds.can.packet.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.packet.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 `