ECC for BPTC 196,96 working correctly.
This commit is contained in:
parent
83d195b183
commit
8e87c4abbe
21
RS129.py
21
RS129.py
@ -95,32 +95,32 @@ def encode(_msg):
|
|||||||
parity[0] = log_mult(POLY[0], dbyte)
|
parity[0] = log_mult(POLY[0], dbyte)
|
||||||
return [parity[2], parity[1], parity[0]]
|
return [parity[2], parity[1], parity[0]]
|
||||||
|
|
||||||
# Apply DMR XOR LC start MASK
|
# Apply DMR XOR LC Header MASK
|
||||||
def lc_start_mask(_parity):
|
def lc_header_mask(_parity):
|
||||||
xor = [0,0,0]
|
xor = [0,0,0]
|
||||||
for i in range(len(_parity)):
|
for i in range(len(_parity)):
|
||||||
xor[i] = _parity[i] ^ START_MASK[i]
|
xor[i] = _parity[i] ^ START_MASK[i]
|
||||||
return xor
|
return xor
|
||||||
|
|
||||||
# Apply DMR XOR LC end MASK
|
# Apply DMR XOR LC Terminator MASK
|
||||||
def lc_end_mask(_parity):
|
def lc_terminator_mask(_parity):
|
||||||
xor = [0,0,0]
|
xor = [0,0,0]
|
||||||
for i in range(len(_parity)):
|
for i in range(len(_parity)):
|
||||||
xor[i] = _parity[i] ^ END_MASK[i]
|
xor[i] = _parity[i] ^ END_MASK[i]
|
||||||
return xor
|
return xor
|
||||||
|
|
||||||
# All Inclusive function to take an LC string and provide the RS129 string to append
|
# All Inclusive function to take an LC string and provide the RS129 string to append
|
||||||
def lc_start_encode(_message):
|
def lc_header_encode(_message):
|
||||||
bin_message = bytearray(_message)
|
bin_message = bytearray(_message)
|
||||||
parity = encode(bin_message)
|
parity = encode(bin_message)
|
||||||
masked_parity = lc_start_mask(parity)
|
masked_parity = lc_header_mask(parity)
|
||||||
return chr(masked_parity[0]) + chr(masked_parity[1]) + chr(masked_parity[2])
|
return chr(masked_parity[0]) + chr(masked_parity[1]) + chr(masked_parity[2])
|
||||||
|
|
||||||
# All Inclusive function to take an LC string and provide the RS129 string to append
|
# All Inclusive function to take an LC string and provide the RS129 string to append
|
||||||
def lc_end_encode(_message):
|
def lc_terminator_encode(_message):
|
||||||
bin_message = bytearray(_message)
|
bin_message = bytearray(_message)
|
||||||
parity = encode(bin_message)
|
parity = encode(bin_message)
|
||||||
masked_parity = lc_end_mask(parity)
|
masked_parity = lc_terminator_mask(parity)
|
||||||
return chr(masked_parity[0]) + chr(masked_parity[1]) + chr(masked_parity[2])
|
return chr(masked_parity[0]) + chr(masked_parity[1]) + chr(masked_parity[2])
|
||||||
|
|
||||||
|
|
||||||
@ -133,7 +133,10 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
# Validation Example
|
# Validation Example
|
||||||
message = '\x00\x10\x20\x00\x0c\x30\x2f\x9b\xe5'
|
message = '\x00\x10\x20\x00\x0c\x30\x2f\x9b\xe5'
|
||||||
|
message = bytearray(message)
|
||||||
parity_should_be = '\xda\x4d\x5a'
|
parity_should_be = '\xda\x4d\x5a'
|
||||||
parity = lc_start_encode(message)
|
print('Original Message: {}'.format(h(message)))
|
||||||
print('Masked Parity Should be: {}'.format(h(parity_should_be)))
|
print('Masked Parity Should be: {}'.format(h(parity_should_be)))
|
||||||
|
|
||||||
|
parity = lc_header_encode(message)
|
||||||
print('Calculated Masked Parity is: {}'.format(h(parity)))
|
print('Calculated Masked Parity is: {}'.format(h(parity)))
|
||||||
|
40
bptc19696.py
40
bptc19696.py
@ -50,20 +50,38 @@ def deinterleave_19696(_data):
|
|||||||
|
|
||||||
# Applies BTPC error detection/correction routines (INCOMPLETE)
|
# Applies BTPC error detection/correction routines (INCOMPLETE)
|
||||||
def error_check_19696(_data):
|
def error_check_19696(_data):
|
||||||
errors = False
|
|
||||||
count = 0
|
count = 0
|
||||||
column = bitarray(13)
|
column = bitarray(13)
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
|
errors = False
|
||||||
for col in xrange(15):
|
for col in xrange(15):
|
||||||
pos = col + 1
|
pos = col + 1
|
||||||
for index in xrange(13):
|
for index in xrange(13):
|
||||||
column[index] = _data[pos]
|
column[index] = _data[pos]
|
||||||
pos += 15
|
pos += 15
|
||||||
|
|
||||||
if hamming.dec_1393(col)
|
result_1393 = hamming.dec_1393(column)
|
||||||
if not errors or count < 5: break
|
if result_1393[1]:
|
||||||
return _data
|
pos = col + 1
|
||||||
|
for index in xrange(13):
|
||||||
|
_data[pos] = result_1393[0][index]
|
||||||
|
pos += 15
|
||||||
|
errors = True
|
||||||
|
print('fixing error in column {}'.format(col))
|
||||||
|
|
||||||
|
for index in xrange(9):
|
||||||
|
pos = (index*15) + 1
|
||||||
|
result_15113 = hamming.dec_15113(_data[pos:(pos+15)])
|
||||||
|
if result_15113[1]:
|
||||||
|
errors = True
|
||||||
|
_data[pos:(pos+15)] = result_15113[0]
|
||||||
|
print('fixing error in row {}'.format(index))
|
||||||
|
|
||||||
|
count += 1
|
||||||
|
print('pass count is {}'.format(count))
|
||||||
|
if not errors or count > 4: break
|
||||||
|
return (_data, (errors))
|
||||||
|
|
||||||
# Returns useable LC data - 9 bytes info + 3 bytes RS(12,9) ECC
|
# Returns useable LC data - 9 bytes info + 3 bytes RS(12,9) ECC
|
||||||
def to_bytes_19696(_data):
|
def to_bytes_19696(_data):
|
||||||
@ -87,14 +105,16 @@ if __name__ == '__main__':
|
|||||||
from time import time
|
from time import time
|
||||||
|
|
||||||
# Validation Example
|
# Validation Example
|
||||||
data = '\x44\x4d\x52\x44\x00\x2f\x9b\xe5\x00\x0c\x30\x00\x04\xc2\xc4\xa1\xa1\x99\x48\x6e\x2b\x60\x04\x10\x1f\x84\x2d\xd0\x0d\xf0\x7d\x41\x04\x6d\xff\x57\xd7\x5d\xf5\xde\x30\x15\x2e\x20\x70\xb2\x0f\x80\x3f\x88\xc6\x95\xe2\x00\x00'
|
data = '\x2b\x60\x04\x10\x1f\x84\x2d\xd0\x0d\xf0\x7d\x41\x04\x6d\xff\x57\xd7\x5d\xf5\xde\x30\x15\x2e\x20\x70\xb2\x0f\x80\x3f\x88\xc6\x95\xe2'
|
||||||
data = data[20:53]
|
data = '\x2b\x60\x04\x10\x1f\x84\x2d\xd0\x0d\xf0\x7d\x41\x04\x6d\xff\x57\xd7\x5d\xf5\xde\x30\x15\x2e\x20\x70\xb2\x0f\x80\x3f\x88\xc6\x95\xe2'
|
||||||
|
|
||||||
t0 = time()
|
t0 = time()
|
||||||
bin_data = to_binary_19696(data)
|
bin_data = to_binary_19696(data)
|
||||||
deint_data = deinterleave_19696(bin_data)
|
deint_data = deinterleave_19696(bin_data)
|
||||||
err_corrected = error_check_19696(deint_data)
|
err_corrected = error_check_19696(deint_data)
|
||||||
ext_data = to_bytes_19696(deint_data)
|
if err_corrected[1]:
|
||||||
|
print('WARNING DATA COULD NOT BE CORRECTED')
|
||||||
|
ext_data = to_bytes_19696(err_corrected[0])
|
||||||
t1 = time()
|
t1 = time()
|
||||||
print('TIME: ', t1-t0, '\n')
|
print('TIME: ', t1-t0, '\n')
|
||||||
|
|
||||||
@ -114,6 +134,6 @@ if __name__ == '__main__':
|
|||||||
print(h(deint_data.tobytes()))
|
print(h(deint_data.tobytes()))
|
||||||
print()
|
print()
|
||||||
|
|
||||||
print('decoded hex data')
|
print('decoded hex data should be: 001020000c302f9be5dad45a')
|
||||||
print(len(ext_data), 'bytes')
|
print('decoded data is: ', h(ext_data))
|
||||||
print(h(ext_data))
|
print(len(ext_data), 'bytes')
|
Loading…
x
Reference in New Issue
Block a user