diff --git a/auto_rx/test/bit_to_samples.py b/auto_rx/test/bit_to_samples.py index be86894..891fab8 100644 --- a/auto_rx/test/bit_to_samples.py +++ b/auto_rx/test/bit_to_samples.py @@ -1,22 +1,40 @@ #!/usr/bin/env python +# +# Convert one-byte-per-bit representation (i.e. from fsk_demod) to a pseudo-FM-demod representation. +# import sys +# Check if we are running in Python 2 or 3 +PY3 = sys.version_info[0] == 3 + _sample_rate = int(sys.argv[1]) _symbol_rate = int(sys.argv[2]) _bit_length = _sample_rate // _symbol_rate -_zero = '\x00'*_bit_length -_one = '\xFF'*_bit_length +if PY3: + _zero = b'\x00'*_bit_length + _one = b'\xFF'*_bit_length + + _in = sys.stdin.read + _out = sys.stdout.buffer.write + +else: + _zero = '\x00'*_bit_length + _one = '\xFF'*_bit_length + + _in = sys.stdin.read + _out = sys.stdout.write while True: - _char = sys.stdin.read(1) - if _char == '': + _char = _in(1) + + if _char == '' or _char == b'': sys.exit(0) if _char == '\x00': - sys.stdout.write(_zero) + _out(_zero) else: - sys.stdout.write(_one) + _out(_one) sys.stdout.flush()