diff --git a/recv.py b/recv.py index 406a325..5265172 100755 --- a/recv.py +++ b/recv.py @@ -186,7 +186,8 @@ def main(fname): f.write(data) if __name__ == '__main__': + import sys logging.basicConfig(level=logging.INFO, format='%(asctime)s %(levelname)-12s %(message)s') - main('rx.int16') + main(fname=sys.argv[1]) if pylab: pylab.show() diff --git a/send.py b/send.py index c09a033..4aeb270 100755 --- a/send.py +++ b/send.py @@ -42,11 +42,11 @@ def modulate(sig, bits): if all(symbols == 0): break -def main(): +def main(fname): import ecc log.info('Running MODEM @ {:.1f} kbps'.format(sigproc.modem_bps / 1e3)) - with open('tx.int16', 'wb') as fd: + with open(fname, 'wb') as fd: start(fd, sym.carrier[carrier_index]) for c in sym.carrier: training(fd, c) @@ -55,5 +55,6 @@ def main(): modulate(fd, bits) if __name__ == '__main__': - logging.basicConfig(level=logging.DEBUG, format='%(message)s') - main() + import sys + logging.basicConfig(level=logging.INFO, format='%(asctime)s %(levelname)-12s %(message)s') + main(fname=sys.argv[1]) diff --git a/test.sh b/test.sh index 09f7f42..2ba37fc 100755 --- a/test.sh +++ b/test.sh @@ -3,17 +3,18 @@ set -u set -e dd if=/dev/urandom of=data.send bs=1024 count=1 -./send.py +./send.py tx.int16 + +killall arecord aplay || true ./wave.py record rx.int16 & -PID=$! - ./wave.py play tx.int16 sleep 1 -kill -INT $PID -./recv.py +killall arecord aplay || true + +./recv.py rx.int16 ./errors.py data.* if [ -z $? ]; then ./show.py tx.int16 rx.int16 -fi \ No newline at end of file +fi diff --git a/wave.py b/wave.py index c5402ea..af6f6d2 100755 --- a/wave.py +++ b/wave.py @@ -7,13 +7,15 @@ import logging log = logging.getLogger(__name__) from common import Fs -Fs = int(Fs) +Fs = int(Fs) # sampling rate +bits_per_sample = 16 +audio_format = 'S{}_LE'.format(bits_per_sample) # PCM signed little endian def play(fname, **kwargs): - return launch('aplay', fname, '-q', '-f', 'S16_LE', '-c', '1', '-r', Fs, **kwargs) + return launch('aplay', fname, '-q', '-f', audio_format, '-c', '1', '-r', Fs, **kwargs) def record(fname, **kwargs): - return launch('arecord', fname, '-q', '-f', 'S16_LE', '-c', '1', '-r', Fs, **kwargs) + return launch('arecord', fname, '-q', '-f', audio_format, '-c', '1', '-r', Fs, **kwargs) def launch(*args, **kwargs): args = map(str, args) @@ -41,4 +43,11 @@ if __name__ == '__main__': p = args.func(args.filename) import sys - sys.exit(p.wait()) + exitcode = 0 + try: + exitcode = p.wait() + except KeyboardInterrupt: + p.kill() + exitcode = p.wait() + + sys.exit(exitcode)