kopia lustrzana https://github.com/projecthorus/wenet
Add uploader status text to GUI.
rodzic
7a1dd8e042
commit
9db7f533f1
71
rx/rx_gui.py
71
rx/rx_gui.py
|
@ -6,22 +6,30 @@
|
|||
# Released under GNU GPL v3 or later
|
||||
#
|
||||
|
||||
import logging
|
||||
import json
|
||||
import socket
|
||||
import time
|
||||
from WenetPackets import *
|
||||
import sip, socket, Queue, json
|
||||
from threading import Thread
|
||||
sip.setapi('QString', 2)
|
||||
sip.setapi('QVariant', 2)
|
||||
from PyQt5 import QtGui, QtCore, QtWidgets
|
||||
from PyQt5.QtCore import Qt
|
||||
|
||||
from PyQt4 import QtGui, QtCore
|
||||
from PyQt4.QtCore import Qt
|
||||
try:
|
||||
# Python 2
|
||||
from Queue import Queue
|
||||
except ImportError:
|
||||
# Python 3
|
||||
from queue import Queue
|
||||
|
||||
# Auto-resizing Widget, to contain displayed image.
|
||||
class Label(QtGui.QLabel):
|
||||
class Label(QtWidgets.QLabel):
|
||||
def __init__(self, img):
|
||||
super(Label, self).__init__()
|
||||
self.setFrameStyle(QtGui.QFrame.StyledPanel)
|
||||
self.setFrameStyle(QtWidgets.QFrame.StyledPanel)
|
||||
self.pixmap = QtGui.QPixmap()
|
||||
|
||||
|
||||
def paintEvent(self, event):
|
||||
size = self.size()
|
||||
painter = QtGui.QPainter(self)
|
||||
|
@ -30,41 +38,58 @@ class Label(QtGui.QLabel):
|
|||
# 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):
|
||||
|
||||
class MyWindow(QtWidgets.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.statusLabel = QtWidgets.QLabel("SSDV: No data yet.")
|
||||
self.statusLabel.setFixedHeight(20)
|
||||
self.uploaderLabel = QtWidgets.QLabel("Uploader: No Data Yet.")
|
||||
self.uploaderLabel.setFixedHeight(20)
|
||||
self.layout = QtWidgets.QVBoxLayout(self)
|
||||
self.layout.addWidget(self.label)
|
||||
self.layout.addWidget(self.statusLabel)
|
||||
self.layout.addWidget(self.uploaderLabel)
|
||||
self.rxqueue = Queue(32)
|
||||
|
||||
self.rxqueue = Queue.Queue(16)
|
||||
|
||||
@QtCore.pyqtSlot(str)
|
||||
def changeImage(self, pathToImage, text_message):
|
||||
print(pathToImage)
|
||||
""" Load and display the supplied image, and update the status text field. """
|
||||
logging.debug("New image: %s" % pathToImage)
|
||||
pixmap = QtGui.QPixmap(pathToImage)
|
||||
self.label.pixmap = pixmap
|
||||
self.label.repaint()
|
||||
self.statusLabel.setText(text_message)
|
||||
print("Repainted")
|
||||
self.label.repaint()
|
||||
logging.debug("Re-painted GUI.")
|
||||
|
||||
|
||||
@QtCore.pyqtSlot(str)
|
||||
def update_upload_status(self, queued, uploaded, discarded):
|
||||
self.uploaderLabel.setText("Uploader: %d queued, %d uploaded, %d discarded." % (queued, uploaded, discarded))
|
||||
|
||||
|
||||
def read_queue(self):
|
||||
""" This function is called every 100ms in the QtGui thread. """
|
||||
try:
|
||||
new_packet = self.rxqueue.get_nowait()
|
||||
packet_data = json.loads(new_packet)
|
||||
self.changeImage(packet_data['filename'],packet_data['text'])
|
||||
if 'filename' in packet_data:
|
||||
self.changeImage(packet_data['filename'],packet_data['text'])
|
||||
elif 'uploader_status' in packet_data:
|
||||
self.update_upload_status(packet_data['queued'], packet_data['uploaded'], packet_data['discarded'])
|
||||
except:
|
||||
# If there is nothing in the queue we will get a queue.Empty error, so we just return.
|
||||
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)
|
||||
|
@ -80,15 +105,23 @@ def udp_rx():
|
|||
m = None
|
||||
|
||||
if m != None:
|
||||
udp_callback(m[0])
|
||||
try:
|
||||
udp_callback(m[0])
|
||||
except Exception as e:
|
||||
pass
|
||||
|
||||
|
||||
|
||||
print("Closing UDP Listener")
|
||||
s.close()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import sys
|
||||
|
||||
app = QtGui.QApplication(sys.argv)
|
||||
logging.basicConfig(format='%(asctime)s %(levelname)s: %(message)s', level=logging.DEBUG)
|
||||
|
||||
app = QtWidgets.QApplication(sys.argv)
|
||||
app.setApplicationName('SSDV Viewer')
|
||||
|
||||
main = MyWindow()
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
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.bin" # _raw, _800x608, _640x480, _320x240
|
||||
image_numbers = xrange(1,14)
|
||||
|
||||
print_as_hex = False
|
||||
|
|
|
@ -12,9 +12,11 @@
|
|||
import argparse
|
||||
import datetime
|
||||
import logging
|
||||
import json
|
||||
import os
|
||||
import glob
|
||||
import requests
|
||||
import socket
|
||||
import sys
|
||||
import time
|
||||
import traceback
|
||||
|
@ -27,6 +29,8 @@ except ImportError:
|
|||
# Python 3
|
||||
from queue import Queue
|
||||
|
||||
WENET_IMAGE_UDP_PORT = 7890
|
||||
|
||||
|
||||
class SSDVUploader(object):
|
||||
"""
|
||||
|
@ -39,8 +43,6 @@ class SSDVUploader(object):
|
|||
|
||||
SSDV_URL = "http://ssdv.habhub.org/api/v0/packets"
|
||||
|
||||
SSDV_URL = "http://localhost:6000/api/v0/packets"
|
||||
|
||||
def __init__(self,
|
||||
uploader_callsign = "N0CALL",
|
||||
enable_file_watch = True,
|
||||
|
@ -323,10 +325,22 @@ class SSDVUploader(object):
|
|||
|
||||
|
||||
|
||||
def telemetry_gui_update(queue, uploaded, discarded):
|
||||
def telemetry_gui_update(queued, uploaded, discarded):
|
||||
""" Update the SSDV Receiver GUI with information on how many packets have been uploader """
|
||||
message = {'uploader_status': 'running',
|
||||
'queued': queued,
|
||||
'uploaded': uploaded,
|
||||
'discarded': discarded
|
||||
}
|
||||
|
||||
try:
|
||||
gui_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
gui_socket.sendto(json.dumps(message).encode('ascii'), ("127.0.0.1", WENET_IMAGE_UDP_PORT))
|
||||
gui_socket.close()
|
||||
|
||||
except Exception as e:
|
||||
logging.error("Error updating GUI with uploader status: %s" % str(e))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -362,8 +376,9 @@ if __name__ == "__main__":
|
|||
|
||||
try:
|
||||
while True:
|
||||
time.sleep(10)
|
||||
logging.info("%d packets in uploader queue, %d packets uploaded, %d packets discarded." % (_uploader.get_queue_size(), _uploader.get_upload_count(), _uploader.get_discard_count()))
|
||||
time.sleep(5)
|
||||
logging.debug("%d packets in uploader queue, %d packets uploaded, %d packets discarded." % (_uploader.get_queue_size(), _uploader.get_upload_count(), _uploader.get_discard_count()))
|
||||
telemetry_gui_update(_uploader.get_queue_size(), _uploader.get_upload_count(), _uploader.get_discard_count())
|
||||
except KeyboardInterrupt:
|
||||
_uploader.close()
|
||||
|
||||
|
|
|
@ -35,4 +35,4 @@ new_sizes.append("raw")
|
|||
|
||||
for x in image_numbers:
|
||||
for size in new_sizes:
|
||||
os.system("ssdv -e -n -q 6 -c %s -i %d %d_%s.jpg %d_%s.ssdv" % (callsign,x,x,size,x,size))
|
||||
os.system("ssdv -e -n -q 6 -c %s -i %d %d_%s.jpg %d_%s.bin" % (callsign,x,x,size,x,size))
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
import PacketTX, sys, os, argparse
|
||||
|
||||
# Set to whatever resolution you want to test.
|
||||
file_path = "../test_images/%d_raw.ssdv" # _raw, _800x608, _640x480, _320x240
|
||||
file_path = "../test_images/%d_raw.bin" # _raw, _800x608, _640x480, _320x240
|
||||
image_numbers = xrange(1,14)
|
||||
|
||||
debug_output = False # If True, packet bits are saved to debug.bin as one char per bit.
|
||||
|
|
Ładowanie…
Reference in New Issue