updates
This commit is contained in:
parent
0822cb5503
commit
0293f6d5e6
12
golay.py
12
golay.py
@ -225,7 +225,7 @@ def decode_2087(_data):
|
|||||||
|
|
||||||
def encode_2087(_data):
|
def encode_2087(_data):
|
||||||
value = data[0]
|
value = data[0]
|
||||||
cksum = ENCODING_TABLE_2087[value]
|
cksum = ENCODE_2087[value]
|
||||||
data[1] = cksum & 0xFF
|
data[1] = cksum & 0xFF
|
||||||
data[2] = cksum >> 8
|
data[2] = cksum >> 8
|
||||||
return _data
|
return _data
|
||||||
@ -238,4 +238,12 @@ def encode_2087(_data):
|
|||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
||||||
from binascii import b2a_hex as h
|
from binascii import b2a_hex as h
|
||||||
from time import time
|
from time import time
|
||||||
|
|
||||||
|
# For testing the code
|
||||||
|
def print_hex(_list):
|
||||||
|
print('[{}]'.format(', '.join(hex(x) for x in _list)))
|
||||||
|
|
||||||
|
data = [0x12,0x23,0x45]
|
||||||
|
|
||||||
|
print_hex(encode_2087(data))
|
6
qr.py
6
qr.py
@ -72,14 +72,14 @@ def get_synd_1576(_pattern):
|
|||||||
def encode(_data):
|
def encode(_data):
|
||||||
value = (_data[0] >> 1) & 0x7F
|
value = (_data[0] >> 1) & 0x7F
|
||||||
cksum = ENCODE_1676[value]
|
cksum = ENCODE_1676[value]
|
||||||
data[0] = cksum >> 8
|
_data[0] = cksum >> 8
|
||||||
data[1] = cksum & 0xFF
|
_data[1] = cksum & 0xFF
|
||||||
return _data
|
return _data
|
||||||
|
|
||||||
def decode(_data):
|
def decode(_data):
|
||||||
code = (_data[0] << 7) + (_data[1] >> 1)
|
code = (_data[0] << 7) + (_data[1] >> 1)
|
||||||
syndrome = get_synd_1576(code)
|
syndrome = get_synd_1576(code)
|
||||||
error_pattern = DECODING_TABLE_1576[syndrome]
|
error_pattern = DECODE_1576[syndrome]
|
||||||
code ^= error_pattern
|
code ^= error_pattern
|
||||||
return code >> 7
|
return code >> 7
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user