remove unused functions

This commit is contained in:
Junzi Sun 2019-10-28 16:24:15 +01:00
parent fb24d4f25c
commit b04a1bd49c
2 changed files with 7 additions and 28 deletions

View File

@ -15,32 +15,11 @@ def hex2int(hexstr):
return int(hexstr, 16) return int(hexstr, 16)
def int2hex(n):
"""Convert a integer to hexadecimal string."""
# strip 'L' for python 2
return hex(n)[2:].rjust(6, "0").upper().rstrip("L")
def bin2int(binstr): def bin2int(binstr):
"""Convert a binary string to integer.""" """Convert a binary string to integer."""
return int(binstr, 2) return int(binstr, 2)
def bin2hex(hexstr):
"""Convert a hexdecimal string to integer."""
return int2hex(bin2int(hexstr))
def bin2np(binstr):
"""Convert a binary string to numpy array."""
return np.array([int(i) for i in binstr])
def np2bin(npbin):
"""Convert a binary numpy array to string."""
return np.array2string(npbin, separator="")[1:-1]
def df(msg): def df(msg):
"""Decode Downlink Format vaule, bits 1 to 5.""" """Decode Downlink Format vaule, bits 1 to 5."""
dfbin = hex2bin(msg[:2]) dfbin = hex2bin(msg[:2])
@ -100,7 +79,7 @@ def crc_legacy(msg, encode=False):
) )
ng = len(generator) ng = len(generator)
msgnpbin = bin2np(hex2bin(msg)) msgnpbin = np.array([int(i) for i in hex2bin(msg)])
if encode: if encode:
msgnpbin[-24:] = [0] * 24 msgnpbin[-24:] = [0] * 24
@ -114,7 +93,9 @@ def crc_legacy(msg, encode=False):
msgnpbin[i : i + ng] = np.bitwise_xor(msgnpbin[i : i + ng], generator) msgnpbin[i : i + ng] = np.bitwise_xor(msgnpbin[i : i + ng], generator)
# last 24 bits # last 24 bits
reminder = bin2int(np2bin(msgnpbin[-24:])) msgbin = np.array2string(msgnpbin[-24:], separator="")[1:-1]
reminder = bin2int(msgbin)
return reminder return reminder
@ -146,7 +127,7 @@ def icao(msg):
addr = msg[2:8] addr = msg[2:8]
elif DF in (0, 4, 5, 16, 20, 21): elif DF in (0, 4, 5, 16, 20, 21):
c0 = crc(msg, encode=True) c0 = crc(msg, encode=True)
c1 = hex2int(msg[-6:]) c1 = int(msg[-6:], 16)
addr = "%06X" % (c0 ^ c1) addr = "%06X" % (c0 ^ c1)
else: else:
addr = None addr = None
@ -159,7 +140,7 @@ def is_icao_assigned(icao):
if (icao is None) or (not isinstance(icao, str)) or (len(icao) != 6): if (icao is None) or (not isinstance(icao, str)) or (len(icao) != 6):
return False return False
icaoint = hex2int(icao) icaoint = int(icao, 16)
if 0x200000 < icaoint < 0x27FFFF: if 0x200000 < icaoint < 0x27FFFF:
return False # AFI return False # AFI

View File

@ -3,8 +3,6 @@ from pyModeS import common
def test_conversions(): def test_conversions():
assert common.hex2bin("6E406B") == "011011100100000001101011" assert common.hex2bin("6E406B") == "011011100100000001101011"
assert common.bin2hex("011011100100000001101011") == "6E406B"
assert common.int2hex(11160538) == "AA4BDA"
def test_crc_decode(): def test_crc_decode():
@ -28,7 +26,7 @@ def test_crc_decode():
def test_crc_encode(): def test_crc_encode():
parity = common.crc("8D406B902015A678D4D220AA4BDA", encode=True) parity = common.crc("8D406B902015A678D4D220AA4BDA", encode=True)
assert common.int2hex(parity) == "AA4BDA" assert parity == 11160538
def test_icao(): def test_icao():