wenet/rx/rx_tester.py

54 wiersze
1.2 KiB
Python

2016-03-05 10:06:28 +00:00
#!/usr/bin/env python
#
# Receiver Test Script.
# Feeds a list of test images into the receiver code, via stdout/stdin.
#
2016-12-05 11:19:05 +00:00
# Run using:
# python rx_tester.py | python rx_ssdv.py
#
2018-01-25 03:04:43 +00:00
# Copyright (C) 2018 Mark Jessop <vk5qi@rfhead.net>
# Released under GNU GPL v3 or later
2016-03-05 10:06:28 +00:00
#
import time, sys, os
2019-07-27 02:57:15 +00:00
# Check if we are running in Python 2 or 3
PY3 = sys.version_info[0] == 3
2016-03-05 10:06:28 +00:00
# Set to whatever resolution you want to test.
2019-07-26 14:00:02 +00:00
file_path = "../test_images/%d_800x608.bin" # _raw, _800x608, _640x480, _320x240
2019-07-27 02:57:15 +00:00
image_numbers = range(1,14)
2016-03-05 10:06:28 +00:00
print_as_hex = False
2016-03-05 10:06:28 +00:00
delay_time = 0.0239 # Approx time for one 256 byte packet at 115.2k baud
def print_file(filename):
file_size = os.path.getsize(filename)
if file_size % 256 > 0:
return
f = open(filename,'rb')
2019-07-27 02:57:15 +00:00
for x in range(file_size//256):
2016-03-05 10:06:28 +00:00
data = f.read(256)
if print_as_hex:
data = "".join("{:02x}".format(ord(c)) for c in data) + "\n"
2019-07-27 02:57:15 +00:00
if PY3:
# Python 3 doesn't let us write bytes to stdout directly.
sys.stdout.buffer.write(data)
else:
# Python 2 does..
sys.stdout.write(data)
2016-03-05 10:06:28 +00:00
sys.stdout.flush()
time.sleep(delay_time)
f.close()
for img in image_numbers:
filename = file_path % img
print_file(filename)