uds.utilities.conversions ========================= .. py:module:: uds.utilities.conversions .. autoapi-nested-parse:: Module with various conversion functions. Classes ------- .. autoapisummary:: uds.utilities.conversions.TimeSync Functions --------- .. autoapisummary:: uds.utilities.conversions.bytes_to_hex uds.utilities.conversions.bytes_to_int uds.utilities.conversions.int_to_bytes uds.utilities.conversions.obd_dtc_to_int uds.utilities.conversions.int_to_obd_dtc uds.utilities.conversions.get_signed_value_decoding_formula uds.utilities.conversions.get_signed_value_encoding_formula Module Contents --------------- .. py:function:: bytes_to_hex(bytes_list) Convert a list of bytes to hex string. :param bytes_list: List of bytes to convert. :return: String with provided list of bytes presented as hexadecimal values. .. py:function:: bytes_to_int(bytes_list, endianness = Endianness.BIG_ENDIAN) Convert a list of bytes to integer value. :param bytes_list: List of bytes to convert. :param endianness: Order of bytes to use. :return: The integer value represented by provided list of bytes. .. py:function:: int_to_bytes(int_value, size = None, endianness = Endianness.BIG_ENDIAN) Convert integer value to a list of bytes. :param int_value: Integer value to convert. :param size: Number of bytes in the output. Use None to use the smallest possible number of bytes. :param endianness: Order of bytes to use. :raise TypeError: At least one provided value has invalid type. :raise ValueError: At least one provided value is out of range. :raise InconsistencyError: Provided value of `size` is too small to contain entire `int_value`. :return: The value of bytes list that represents the provided integer value. .. py:function:: obd_dtc_to_int(obd_dtc) Convert text with DTC in OBD format into integer value (DTC in UDS format). :param obd_dtc: Text with DTC in OBD format. :raise TypeError: Provided value is not str type. :raise ValueError: Provided value is not DTC in OBD format. :return: Integer value representation of this DTC in UDS format. .. py:function:: int_to_obd_dtc(dtc) Encode integer value (DTC in UDS format) into text with DTC in OBD format. :param dtc: Integer with DTC in UDS format. :raise TypeError: Provided value is not int type. :raise ValueError: Provided value is not DTC in OBD format. :return: Text value representation of this DTC in OBD format. .. py:function:: get_signed_value_decoding_formula(bit_length) Get formula for decoding signed integer value. :param bit_length: Number of bits used for signed integer value. :raise TypeError: Provided value is not int type. :raise ValueError: Provided value is out of range. :return: Formula for decoding singed integer value from unsigned integer value. .. py:function:: get_signed_value_encoding_formula(bit_length) Get formula for encoding signed integer value. :param bit_length: Number of bits used for signed integer value. :raise TypeError: Provided value is not int type. :raise ValueError: Provided value is out of range. :return: Formula for encoding singed integer value into unsinged integer value. .. py:class:: TimeSync(samples_number = None, sync_expiration = None) Synchronization between wall clock (`time.time()`) and performance counter (`time.perf_counter()`) values. Get time synchronization object. :param samples_number: Number of samples to use for synchronization. :param sync_expiration: Time in seconds after which synchronization is considered no longer up to date. .. warning:: Objects of this class are Singletons. .. py:attribute:: _instance :value: None Instance of this Singleton. .. py:attribute:: DEFAULT_SAMPLES_NUMBER :value: 20 Default number of samples collected during synchronization. .. py:attribute:: DEFAULT_SYNC_EXPIRATION_S :value: 10 Default expiration time (in seconds) of the offset calculated during last synchronization. .. py:property:: samples_number :type: int Get number of samples to take during synchronization. .. py:property:: sync_expiration :type: float Get time in seconds after which synchronization value is considered outdated. .. py:property:: last_sync_timestamp :type: Optional[float] Value of performance counter for the last synchronization point. .. py:property:: is_sync_outdated :type: bool Get flag whether the current sync value is outdated. .. py:property:: offset :type: Optional[float] Difference between wall clock and performance counter. .. py:method:: sync() Perform synchronization. .. py:method:: time_to_perf_counter(time_value, min_value = None, max_value = None) Convert wall clock time to performance counter. :param time_value: Wall clock time value to convert. :param min_value: The lowest possible result (an earlier value of performance counter). :param max_value: The highest possible result (a later value of performance counter). :return: An approximation of performance counter for given wall clock time value. .. py:method:: perf_counter_to_time(perf_counter_value, min_value = None, max_value = None) Convert performance counter to wall clock time. :param perf_counter_value: Performance counter value to convert. :param min_value: The lowest possible result (an earlier value of wall clock time). :param max_value: The highest possible result (a later value of wall clock time). :return: An approximation of wall clock time for given performance counter value.