Documentation and Cleanup

This commit is contained in:
Cort Buffington 2016-09-15 08:18:17 -05:00
parent 223d54d790
commit 8713a62bce
2 changed files with 35 additions and 1 deletions

View File

@ -18,21 +18,29 @@ __license__ = 'Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unpo
__maintainer__ = 'Cort Buffington, N0MJS'
__email__ = 'n0mjs@me.com'
#------------------------------------------------------------------------------
# BPTC(196,96) Decoding routings
#------------------------------------------------------------------------------
# Converts a DMR frame using 98-68-98 (info-sync/EMB-info) into 196 bit array
def dec_get_binary_19696(_data):
_data = bytearray(_data)
_data = BitArray(_data)
return _data[:98] + _data[-98:]
# Applies interleave indecies de-interleave 196 bit array
def dec_deinterleave_19696(_data):
deint = BitArray(196)
for index in range(196):
deint[index] = _data[(index * 181) % 196]
return deint
# Applies BTPC error detection/correction routines (INCOMPLETE)
def dec_error_check_19696(_data):
checked = BitArray(196)
# Returns useable LC data - 9 bytes info + 3 bytes RS(12,9) ECC
def dec_get_data_19696(_data):
databits = BitArray()
databits.append(_data[4:12])
@ -45,7 +53,17 @@ def dec_get_data_19696(_data):
databits.append(_data[106:117])
databits.append(_data[121:132])
return databits.tobytes()
#------------------------------------------------------------------------------
# BPTC(196,96) Decoding routings
#------------------------------------------------------------------------------
# not yet implemented
#------------------------------------------------------------------------------
# Used to execute the module directly to run built-in tests
#------------------------------------------------------------------------------
if __name__ == '__main__':

View File

@ -19,6 +19,11 @@ __maintainer__ = 'Cort Buffington, N0MJS'
__email__ = 'n0mjs@me.com'
#------------------------------------------------------------------------------
# Hamming 15,11,3 routines
#------------------------------------------------------------------------------
# ENCODER- returns a BitArray object containing the hamming checksums
def enc_hamming_15113(_data):
csum = BitArray(4)
csum[0] = _data[0] ^ _data[1] ^ _data[2] ^ _data[3] ^ _data[5] ^ _data[7] ^ _data[8]
@ -27,6 +32,7 @@ def enc_hamming_15113(_data):
csum[3] = _data[0] ^ _data[1] ^ _data[2] ^ _data[4] ^ _data[6] ^ _data[7] ^ _data[10]
return csum
# DECODER - Returns a tuple of (decoded data, True if an error was corrected)
def dec_hamming_15113(_data):
chk0 = _data[0] ^ _data[1] ^ _data[2] ^ _data[3] ^ _data[5] ^ _data[7] ^ _data[8]
chk1 = _data[1] ^ _data[2] ^ _data[3] ^ _data[4] ^ _data[6] ^ _data[8] ^ _data[9]
@ -61,6 +67,11 @@ def dec_hamming_15113(_data):
return (_data, False)
#------------------------------------------------------------------------------
# Hamming 13,9,3 routines
#------------------------------------------------------------------------------
# ENCODER - returns a BitArray object containing the hamming checksums
def enc_hamming_1393(_data):
csum = BitArray(4)
csum[0] = _data[0] ^ _data[1] ^ _data[3] ^ _data[5] ^ _data[6]
@ -69,6 +80,7 @@ def enc_hamming_1393(_data):
csum[3] = _data[0] ^ _data[2] ^ _data[4] ^ _data[5] ^ _data[8]
return csum
# DECODER - Returns a tuple of (decoded data, True if an error was corrected)
def dec_hamming_1393(_data):
chk0 = _data[0] ^ _data[1] ^ _data[3] ^ _data[5] ^ _data[6]
chk1 = _data[0] ^ _data[1] ^ _data[2] ^ _data[4] ^ _data[6] ^ _data[7]
@ -101,6 +113,10 @@ def dec_hamming_1393(_data):
return (_data, False)
#------------------------------------------------------------------------------
# Used to execute the module directly to run built-in tests
#------------------------------------------------------------------------------
if __name__ == '__main__':
# Validation Example