work in progress

This commit is contained in:
Junzi Sun
2015-09-17 20:24:32 +02:00
parent 52a6bcd637
commit 2b55f8a5df

View File

@@ -8,6 +8,24 @@ Date : March 2015
import math
MODES_CHECKSUM_TABLE = [
0x3935ea, 0x1c9af5, 0xf1b77e, 0x78dbbf, 0xc397db, 0x9e31e9, 0xb0e2f0, 0x587178,
0x2c38bc, 0x161c5e, 0x0b0e2f, 0xfa7d13, 0x82c48d, 0xbe9842, 0x5f4c21, 0xd05c14,
0x682e0a, 0x341705, 0xe5f186, 0x72f8c3, 0xc68665, 0x9cb936, 0x4e5c9b, 0xd8d449,
0x939020, 0x49c810, 0x24e408, 0x127204, 0x093902, 0x049c81, 0xfdb444, 0x7eda22,
0x3f6d11, 0xe04c8c, 0x702646, 0x381323, 0xe3f395, 0x8e03ce, 0x4701e7, 0xdc7af7,
0x91c77f, 0xb719bb, 0xa476d9, 0xadc168, 0x56e0b4, 0x2b705a, 0x15b82d, 0xf52612,
0x7a9309, 0xc2b380, 0x6159c0, 0x30ace0, 0x185670, 0x0c2b38, 0x06159c, 0x030ace,
0x018567, 0xff38b7, 0x80665f, 0xbfc92b, 0xa01e91, 0xaff54c, 0x57faa6, 0x2bfd53,
0xea04ad, 0x8af852, 0x457c29, 0xdd4410, 0x6ea208, 0x375104, 0x1ba882, 0x0dd441,
0xf91024, 0x7c8812, 0x3e4409, 0xe0d800, 0x706c00, 0x383600, 0x1c1b00, 0x0e0d80,
0x0706c0, 0x038360, 0x01c1b0, 0x00e0d8, 0x00706c, 0x003836, 0x001c1b, 0xfff409,
0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000
]
def hex2bin(hexstr):
"""Convert a hexdecimal string to binary string, with zero fillings. """
length = len(hexstr) * 4
@@ -19,6 +37,38 @@ def hex2bin(hexstr):
def bin2int(msgbin):
return int(msgbin, 2)
def checksum(msg):
nbits = len(msg)
if nbits == 28:
offset = 0
elif nbits == 14:
offset = 112-56
else:
# raise exception
return False
print msg
msgbin = hex2bin(msg)
checksumhex = msg[22:28]
checksum = int(checksumhex, 16)
crc = 0
for i in xrange(nbits):
if int(msgbin[i]):
crc ^= MODES_CHECKSUM_TABLE[i+offset]
print bin(crc)
print bin(checksum)
print
if crc == checksum:
return True
else:
return False
def get_df(msg):
"""Decode Downlink Format vaule, bits 1 to 5."""
msgbin = hex2bin(msg)