kopia lustrzana https://github.com/projecthorus/wenet
Fixed rx_tester misconfiguration, added starts of a rx ssdv gui.
rodzic
93701e8f8d
commit
d5b2d548cc
|
@ -8,9 +8,11 @@ The transmit side is designed to run on a Raspberry Pi, and the UART (/dev/ttyAM
|
|||
* SSDV (https://github.com/fsphil/ssdv)
|
||||
* crcmod (pip install crcmod)
|
||||
* numpy (for debug output tests)
|
||||
* PyQt4 (for SSDV GUI)
|
||||
|
||||
## Main Programs
|
||||
* `rx_ssdv.py` - Reads in received packets (256 byte SSDV frames) via stdin, and decodes them to JPEGs. Also informs other processes (via UDP broadcast) of new data.
|
||||
* `rx_gui.py` - Displays last received image, as commanded by rx_ssdv.py via UDP.
|
||||
* `tx_picam.py` - TODO.
|
||||
|
||||
## Testing Scripts
|
||||
|
@ -22,4 +24,5 @@ The transmit side is designed to run on a Raspberry Pi, and the UART (/dev/ttyAM
|
|||
|
||||
### RX Testing
|
||||
* `rx_tester.py` produces a stream of packets on stdout, as would be received from the fsk_demod modem (from codec2 - still under development).
|
||||
* Run `python rx_tester.py | python rx_ssdv.py` to feed these test packets into the command-line ssdv rx script.
|
||||
* Run `python rx_tester.py | python rx_ssdv.py` to feed these test packets into the command-line ssdv rx script.
|
||||
* add `--partialupdate N` to the above command to have rx_gui.py update every N received packets.
|
|
@ -0,0 +1,105 @@
|
|||
#!/usr/bin/env python
|
||||
#-*- coding:utf-8 -*-
|
||||
|
||||
import sip, socket, Queue
|
||||
from threading import Thread
|
||||
sip.setapi('QString', 2)
|
||||
sip.setapi('QVariant', 2)
|
||||
|
||||
from PyQt4 import QtGui, QtCore
|
||||
from PyQt4.QtCore import Qt
|
||||
|
||||
# Auto-resizing Label.
|
||||
class Label(QtGui.QLabel):
|
||||
def __init__(self, img):
|
||||
super(Label, self).__init__()
|
||||
self.setFrameStyle(QtGui.QFrame.StyledPanel)
|
||||
self.pixmap = QtGui.QPixmap()
|
||||
|
||||
def paintEvent(self, event):
|
||||
size = self.size()
|
||||
painter = QtGui.QPainter(self)
|
||||
point = QtCore.QPoint(0,0)
|
||||
scaledPix = self.pixmap.scaled(size, Qt.KeepAspectRatio, transformMode = Qt.SmoothTransformation)
|
||||
# start painting the label from left upper corner
|
||||
point.setX((size.width() - scaledPix.width())/2)
|
||||
point.setY((size.height() - scaledPix.height())/2)
|
||||
#print point.x(), ' ', point.y()
|
||||
painter.drawPixmap(point, scaledPix)
|
||||
|
||||
class MyWindow(QtGui.QWidget):
|
||||
def __init__(self, parent=None):
|
||||
super(MyWindow, self).__init__(parent)
|
||||
self.label = Label(self)
|
||||
self.statusLabel = QtGui.QLabel("No Updates Yet...")
|
||||
self.statusLabel.setFixedHeight(30)
|
||||
self.layout = QtGui.QVBoxLayout(self)
|
||||
self.layout.addWidget(self.label)
|
||||
self.layout.addWidget(self.statusLabel)
|
||||
|
||||
self.rxqueue = Queue.Queue(16)
|
||||
|
||||
@QtCore.pyqtSlot(str)
|
||||
def changeImage(self, pathToImage):
|
||||
print(pathToImage)
|
||||
pixmap = QtGui.QPixmap(pathToImage)
|
||||
self.label.pixmap = pixmap
|
||||
self.label.repaint()
|
||||
self.statusLabel.setText(pathToImage)
|
||||
print("Repainted")
|
||||
|
||||
def read_queue(self):
|
||||
try:
|
||||
new_image = self.rxqueue.get_nowait()
|
||||
self.changeImage(new_image)
|
||||
except:
|
||||
pass
|
||||
|
||||
# UDP Listener
|
||||
udp_listener_running = False
|
||||
udp_callback = None
|
||||
def udp_rx():
|
||||
global udp_listener_running, udp_callback
|
||||
s = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
|
||||
s.settimeout(1)
|
||||
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||
s.bind(('',7890))
|
||||
print("Started UDP Listener Thread.")
|
||||
udp_listener_running = True
|
||||
while udp_listener_running:
|
||||
try:
|
||||
m = s.recvfrom(512)
|
||||
except socket.timeout:
|
||||
m = None
|
||||
|
||||
if m != None:
|
||||
print(m[0])
|
||||
udp_callback(m[0].rstrip())
|
||||
|
||||
print("Closing UDP Listener")
|
||||
s.close()
|
||||
|
||||
if __name__ == "__main__":
|
||||
import sys
|
||||
|
||||
app = QtGui.QApplication(sys.argv)
|
||||
app.setApplicationName('SSDV Viewer')
|
||||
|
||||
main = MyWindow()
|
||||
main.resize(800,600)
|
||||
|
||||
udp_callback = main.rxqueue.put_nowait
|
||||
t = Thread(target=udp_rx)
|
||||
t.start()
|
||||
|
||||
timer = QtCore.QTimer()
|
||||
timer.timeout.connect(main.read_queue)
|
||||
timer.start(100)
|
||||
|
||||
main.show()
|
||||
|
||||
app.exec_()
|
||||
|
||||
udp_listener_running = False
|
||||
|
||||
sys.exit()
|
18
rx_ssdv.py
18
rx_ssdv.py
|
@ -9,10 +9,11 @@
|
|||
#
|
||||
|
||||
|
||||
import os,sys, datetime, argparse
|
||||
import os,sys, datetime, argparse, socket
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--hex", action="store_true", help="Take Hex strings as input instead of raw data.")
|
||||
parser.add_argument("--partialupdate",default=0,help="Push partial updates every N packets to GUI.")
|
||||
args = parser.parse_args()
|
||||
|
||||
# Helper functions to extract data from SSDV packets.
|
||||
|
@ -44,6 +45,11 @@ def ssdv_packet_string(packet_info):
|
|||
return "SSDV: %s, Img:%d, Pkt:%d, %dx%d" % (packet_info['packet_type'],packet_info['image_id'],packet_info['packet_id'],packet_info['width'],packet_info['height'])
|
||||
|
||||
|
||||
def trigger_gui_update(filename):
|
||||
gui_socket = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
|
||||
gui_socket.sendto(filename,("127.0.0.1",7890))
|
||||
gui_socket.close()
|
||||
|
||||
# State variables
|
||||
current_image = -1
|
||||
current_packet_count = 0
|
||||
|
@ -82,6 +88,7 @@ while True:
|
|||
os.system("mv rxtemp.bin %s.ssdv" % current_packet_time)
|
||||
|
||||
# Update live displays here.
|
||||
trigger_gui_update("%s.jpg" % current_packet_time)
|
||||
|
||||
# Trigger upload to habhub here.
|
||||
else:
|
||||
|
@ -98,4 +105,13 @@ while True:
|
|||
else:
|
||||
# Write current packet into temp file.
|
||||
temp_f.write(data)
|
||||
current_packet_count += 1
|
||||
|
||||
if args.partialupdate != 0:
|
||||
if current_packet_count % int(args.partialupdate) == 0:
|
||||
# Run the SSDV decoder and push a partial update to the GUI.
|
||||
temp_f.flush()
|
||||
returncode = os.system("ssdv -d rxtemp.bin rxtemp.jpg")
|
||||
if returncode == 0:
|
||||
trigger_gui_update("rxtemp.jpg")
|
||||
|
||||
|
|
|
@ -9,10 +9,10 @@
|
|||
import time, sys, os
|
||||
|
||||
# Set to whatever resolution you want to test.
|
||||
file_path = "./test_images/%d_raw.ssdv" # _raw, _800x608, _640x480, _320x240
|
||||
file_path = "./test_images/%d_800x608.ssdv" # _raw, _800x608, _640x480, _320x240
|
||||
image_numbers = xrange(1,14)
|
||||
|
||||
print_as_hex = True
|
||||
print_as_hex = False
|
||||
|
||||
delay_time = 0.0239 # Approx time for one 256 byte packet at 115.2k baud
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue