Fix bit_to_samples for python 3.7

pull/221/head
Mark Jessop 2019-09-21 17:08:55 +09:30
rodzic 1f1e43f8a0
commit e10dc43bc7
1 zmienionych plików z 24 dodań i 6 usunięć

Wyświetl plik

@ -1,22 +1,40 @@
#!/usr/bin/env python #!/usr/bin/env python
#
# Convert one-byte-per-bit representation (i.e. from fsk_demod) to a pseudo-FM-demod representation.
#
import sys import sys
# Check if we are running in Python 2 or 3
PY3 = sys.version_info[0] == 3
_sample_rate = int(sys.argv[1]) _sample_rate = int(sys.argv[1])
_symbol_rate = int(sys.argv[2]) _symbol_rate = int(sys.argv[2])
_bit_length = _sample_rate // _symbol_rate _bit_length = _sample_rate // _symbol_rate
_zero = '\x00'*_bit_length if PY3:
_one = '\xFF'*_bit_length _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: while True:
_char = sys.stdin.read(1) _char = _in(1)
if _char == '':
if _char == '' or _char == b'':
sys.exit(0) sys.exit(0)
if _char == '\x00': if _char == '\x00':
sys.stdout.write(_zero) _out(_zero)
else: else:
sys.stdout.write(_one) _out(_one)
sys.stdout.flush() sys.stdout.flush()