Module osyspyrt.util
General utility functions.
Functions
def bcd_bin_to_str(value)
-
Convert a BCD binary representation to a character string
Parameters
value
:bytes
orbytearray
Raises
ValueError if the not a valid TBCD binary representation.
def bcd_digit_to_char(digit)
-
Convert a BCD digit to char. 0xF is converted to empty string. ValueError is raised if digit is not between 0x0 and 0xE.
def bcd_str_to_bin(value)
-
Convert the given BCD character string to binary.
Returns
bytearray
def group(a, *ns)
def hexdump(data)
def is_integer(value)
-
Return true if the given string consists of one or more digits, 0-9. This differs from built-in functions which recognize other characters that Unicode designates as digits, and it does not allow for whitespace.
def join(a, *cs)
def lowest_set(val)
-
Return the lowest bit set in the given value.
Parameters
val
:int
- A value > 0.
Returns
int
- The lowest bit set. 0 for the least significant bit.
Raises
ValueError if val == 0
def plmnidentity_bin_to_str(plmnidentity)
-
Translates a PLMNidentity string (i.e., byte array) to ASCII strings for the MCC and the MNC. Refer to the description of PLMNidentity in plmnidentity_str_to_bin().
Parameters
plmnidentity: A PLMNidentity as a bytearray.
Raises
ValueError if the passed PLMNidentity is invalid.
Returns
A tuple in the format (mcc, mnc)
def plmnidentity_str_to_bin(mcc, mnc)
-
Translates ASCII Strings for MCC and MNC to a PLMNidentity. The PLMNidentity format is described in (for example) 3GPP TS 25.413. Each nibble represents a digit from 0 through 9 inclusive. The first 3 nibbles are the digits of the MCC. If the MNC is 2 digits long, the fourth nibble is a filler of 0xf. Otherwise, the fourth nibble is the first digit of the MNC. Then the remaining 2 nibbles are the remaining digits of the MNC.
Parameters
mcc: The source ASCII string for the MCC. mnc: The source ASCII string for the MNC.
Raises
ValueError if the mcc or mnc is invalid.
Returns
The PLMNidentity string as a bytearray.
def signed_bytes(value)
-
Return the minimal signed, 2's complement representation for the given value. For zero, this will be a bytes object of length 1.
Parameters
value
:int
Returns
bytes
def tbcd_bin_to_str(value)
-
Convert a TBCD binary representation to a TBCD character string, following 3GPP 29.002.
Parameters
value
:bytes
orbytearray
Raises
ValueError if the not a valid TBCD binary representation.
def tbcd_digit_to_char(digit)
-
Convert a TBCD digit to TBCD char, following 3GPP 29.002. 0xF is converted to empty string. ValueError is raised if digit is not between 0x0 and 0xF.
def tbcd_str_to_bin(value)
-
Convert the given TBCD character string to binary, following 3GPP 29.002.
Returns
bytearray
def unsigned_bytes(value)
-
Return the minimal unsigned representation for the given value. For zero, this will be a bytes object of length 1.
Parameters
value
:int
- A value >= 0
Returns
bytes