mirror of
https://github.com/romanz/amodem.git
synced 2026-04-21 05:36:42 +08:00
fix ecc indentation
This commit is contained in:
8
ecc.py
8
ecc.py
@@ -10,6 +10,7 @@ BLOCK_SIZE = 255
|
|||||||
|
|
||||||
LEN_FMT = '<I'
|
LEN_FMT = '<I'
|
||||||
|
|
||||||
|
|
||||||
def encode(data, nsym=DEFAULT_NSYM):
|
def encode(data, nsym=DEFAULT_NSYM):
|
||||||
log.debug('Encoded {} bytes'.format(len(data)))
|
log.debug('Encoded {} bytes'.format(len(data)))
|
||||||
data = bytearray(struct.pack(LEN_FMT, len(data)) + data)
|
data = bytearray(struct.pack(LEN_FMT, len(data)) + data)
|
||||||
@@ -24,6 +25,7 @@ def encode(data, nsym=DEFAULT_NSYM):
|
|||||||
|
|
||||||
return enc
|
return enc
|
||||||
|
|
||||||
|
|
||||||
def decode(data, nsym=DEFAULT_NSYM):
|
def decode(data, nsym=DEFAULT_NSYM):
|
||||||
data = bytearray(data)
|
data = bytearray(data)
|
||||||
dec = bytearray()
|
dec = bytearray()
|
||||||
@@ -31,7 +33,8 @@ def decode(data, nsym=DEFAULT_NSYM):
|
|||||||
chunk = data[i:i+BLOCK_SIZE]
|
chunk = data[i:i+BLOCK_SIZE]
|
||||||
try:
|
try:
|
||||||
dec.extend(rs_correct_msg(chunk, nsym))
|
dec.extend(rs_correct_msg(chunk, nsym))
|
||||||
log.debug('Decoded %d blocks = %d bytes', (i+1) / BLOCK_SIZE, len(dec))
|
log.debug('Decoded %d blocks = %d bytes',
|
||||||
|
(i+1) / BLOCK_SIZE, len(dec))
|
||||||
except ReedSolomonError as e:
|
except ReedSolomonError as e:
|
||||||
log.debug('Decoding stopped: %s', e)
|
log.debug('Decoding stopped: %s', e)
|
||||||
break
|
break
|
||||||
@@ -41,7 +44,8 @@ def decode(data, nsym=DEFAULT_NSYM):
|
|||||||
|
|
||||||
overhead = (i - len(dec)) / float(i)
|
overhead = (i - len(dec)) / float(i)
|
||||||
blocks = i / BLOCK_SIZE
|
blocks = i / BLOCK_SIZE
|
||||||
log.debug('Decoded %d blocks = %d bytes (ECC overhead %.1f%%)', blocks, len(dec), overhead * 100)
|
log.debug('Decoded %d blocks = %d bytes (ECC overhead %.1f%%)',
|
||||||
|
blocks, len(dec), overhead * 100)
|
||||||
|
|
||||||
n = struct.calcsize(LEN_FMT)
|
n = struct.calcsize(LEN_FMT)
|
||||||
payload, length = dec[n:], dec[:n]
|
payload, length = dec[n:], dec[:n]
|
||||||
|
|||||||
Reference in New Issue
Block a user