mirror of
https://github.com/romanz/amodem.git
synced 2026-04-19 20:55:59 +08:00
test receiver error
This commit is contained in:
@@ -256,10 +256,12 @@ def main(args):
|
|||||||
size = 0
|
size = 0
|
||||||
signal, amplitude = detect(signal, config.Fc)
|
signal, amplitude = detect(signal, config.Fc)
|
||||||
bits = receive(signal, modem.freqs, gain=1.0/amplitude)
|
bits = receive(signal, modem.freqs, gain=1.0/amplitude)
|
||||||
|
success = False
|
||||||
try:
|
try:
|
||||||
for chunk in decode(bits):
|
for chunk in decode(bits):
|
||||||
args.output.write(chunk)
|
args.output.write(chunk)
|
||||||
size = size + len(chunk)
|
size = size + len(chunk)
|
||||||
|
success = True
|
||||||
except Exception:
|
except Exception:
|
||||||
log.exception('Decoding failed')
|
log.exception('Decoding failed')
|
||||||
|
|
||||||
@@ -279,6 +281,7 @@ def main(args):
|
|||||||
'$F_c = {} Hz$'.format(freq))
|
'$F_c = {} Hz$'.format(freq))
|
||||||
|
|
||||||
pylab.show()
|
pylab.show()
|
||||||
|
return success
|
||||||
|
|
||||||
|
|
||||||
def constellation(y, symbols, title):
|
def constellation(y, symbols, title):
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ class Args(object):
|
|||||||
self.__dict__.update(kwargs)
|
self.__dict__.update(kwargs)
|
||||||
|
|
||||||
|
|
||||||
def run(size, chan=None, df=0):
|
def run(size, chan=None, df=0, success=True):
|
||||||
tx_data = os.urandom(size)
|
tx_data = os.urandom(size)
|
||||||
tx_audio = BytesIO()
|
tx_audio = BytesIO()
|
||||||
send.main(Args(silence_start=1, silence_stop=1,
|
send.main(Args(silence_start=1, silence_stop=1,
|
||||||
@@ -38,16 +38,23 @@ def run(size, chan=None, df=0):
|
|||||||
rx_audio = BytesIO(data)
|
rx_audio = BytesIO(data)
|
||||||
|
|
||||||
rx_data = BytesIO()
|
rx_data = BytesIO()
|
||||||
recv.main(Args(skip=0, input=rx_audio, output=rx_data))
|
result = recv.main(Args(skip=0, input=rx_audio, output=rx_data))
|
||||||
rx_data = rx_data.getvalue()
|
rx_data = rx_data.getvalue()
|
||||||
|
|
||||||
assert rx_data == tx_data
|
assert result == success
|
||||||
|
if success:
|
||||||
|
assert rx_data == tx_data
|
||||||
|
|
||||||
|
|
||||||
def test_small():
|
def test_small():
|
||||||
run(1024, chan=lambda x: x)
|
run(1024, chan=lambda x: x)
|
||||||
|
|
||||||
|
|
||||||
|
def test_error():
|
||||||
|
skip = 1 * send.config.Fs # remove trailing silence
|
||||||
|
run(1024, chan=lambda x: x[:-skip], success=False)
|
||||||
|
|
||||||
|
|
||||||
def test_frequency_error():
|
def test_frequency_error():
|
||||||
for ppm in [0.1, 1, 10]:
|
for ppm in [0.1, 1, 10]:
|
||||||
for sign in [+1, -1]:
|
for sign in [+1, -1]:
|
||||||
@@ -78,4 +85,3 @@ def test_medium_noise():
|
|||||||
|
|
||||||
def test_large():
|
def test_large():
|
||||||
run(54321, chan=lambda x: x)
|
run(54321, chan=lambda x: x)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user