uds.utilities.conversions
Module with various conversion functions.
Classes
Synchronization between wall clock (time.time()) and performance counter (time.perf_counter()) values. |
Functions
|
Convert a list of bytes to hex string. |
|
Convert a list of bytes to integer value. |
|
Convert integer value to a list of bytes. |
|
Convert text with DTC in OBD format into integer value (DTC in UDS format). |
|
Encode integer value (DTC in UDS format) into text with DTC in OBD format. |
|
Get formula for decoding signed integer value. |
|
Get formula for encoding signed integer value. |
Module Contents
- uds.utilities.conversions.bytes_to_hex(bytes_list)[source]
Convert a list of bytes to hex string.
- Parameters:
bytes_list (uds.utilities.common_types.RawBytesAlias) – List of bytes to convert.
- Returns:
String with provided list of bytes presented as hexadecimal values.
- Return type:
- uds.utilities.conversions.bytes_to_int(bytes_list, endianness=Endianness.BIG_ENDIAN)[source]
Convert a list of bytes to integer value.
- Parameters:
bytes_list (uds.utilities.common_types.RawBytesAlias) – List of bytes to convert.
endianness (uds.utilities.enums.Endianness) – Order of bytes to use.
- Returns:
The integer value represented by provided list of bytes.
- Return type:
- uds.utilities.conversions.int_to_bytes(int_value, size=None, endianness=Endianness.BIG_ENDIAN)[source]
Convert integer value to a list of bytes.
- Parameters:
int_value (int) – Integer value to convert.
size (Optional[int]) – Number of bytes in the output. Use None to use the smallest possible number of bytes.
endianness (uds.utilities.enums.Endianness) – Order of bytes to use.
- Raises:
TypeError – At least one provided value has invalid type.
ValueError – At least one provided value is out of range.
InconsistencyError – Provided value of size is too small to contain entire int_value.
- Returns:
The value of bytes list that represents the provided integer value.
- Return type:
- uds.utilities.conversions.obd_dtc_to_int(obd_dtc)[source]
Convert text with DTC in OBD format into integer value (DTC in UDS format).
- Parameters:
obd_dtc (str) – Text with DTC in OBD format.
- Raises:
TypeError – Provided value is not str type.
ValueError – Provided value is not DTC in OBD format.
- Returns:
Integer value representation of this DTC in UDS format.
- Return type:
- uds.utilities.conversions.int_to_obd_dtc(dtc)[source]
Encode integer value (DTC in UDS format) into text with DTC in OBD format.
- Parameters:
dtc (int) – Integer with DTC in UDS format.
- Raises:
TypeError – Provided value is not int type.
ValueError – Provided value is not DTC in OBD format.
- Returns:
Text value representation of this DTC in OBD format.
- Return type:
- uds.utilities.conversions.get_signed_value_decoding_formula(bit_length)[source]
Get formula for decoding signed integer value.
- Parameters:
bit_length (int) – Number of bits used for signed integer value.
- Raises:
TypeError – Provided value is not int type.
ValueError – Provided value is out of range.
- Returns:
Formula for decoding singed integer value from unsigned integer value.
- Return type:
- uds.utilities.conversions.get_signed_value_encoding_formula(bit_length)[source]
Get formula for encoding signed integer value.
- Parameters:
bit_length (int) – Number of bits used for signed integer value.
- Raises:
TypeError – Provided value is not int type.
ValueError – Provided value is out of range.
- Returns:
Formula for encoding singed integer value into unsinged integer value.
- Return type:
- class uds.utilities.conversions.TimeSync(samples_number=None, sync_expiration=None)[source]
Synchronization between wall clock (time.time()) and performance counter (time.perf_counter()) values.
Get time synchronization object.
- Parameters:
Warning
Objects of this class are Singletons.
- _instance = None
Instance of this Singleton.
- DEFAULT_SAMPLES_NUMBER = 100
Default number of samples collected during synchronization.
- DEFAULT_SYNC_EXPIRATION_S = 1
Default expiration time (in seconds) of the offset calculated during last synchronization.
- property sync_expiration: float
Get time in seconds after which synchronization value is considered outdated.
- Return type:
- property last_sync_timestamp: float | None
Value of performance counter for the last synchronization point.
- Return type:
Optional[float]
- property offset: float | None
Difference between wall clock and performance counter.
- Return type:
Optional[float]
- time_to_perf_counter(time_value, min_value=None, max_value=None)[source]
Convert wall clock time to performance counter.
- Parameters:
- Returns:
An approximation of performance counter for given wall clock time value.
- Return type: