From f08d1103f338deb770420d3e3b17cc9f07b6084c Mon Sep 17 00:00:00 2001 From: Nao Pross Date: Tue, 14 Dec 2021 19:52:22 +0100 Subject: Attempt to use UNIX sockets for better performance --- src/gui/gui.py | 10 +++++----- src/gui/net.py | 25 +++++++++++++++++++++---- 2 files changed, 26 insertions(+), 9 deletions(-) (limited to 'src/gui') diff --git a/src/gui/gui.py b/src/gui/gui.py index 9f63452..b298fd8 100755 --- a/src/gui/gui.py +++ b/src/gui/gui.py @@ -45,13 +45,13 @@ show_debug() time_plot = net.network_plot(url="udp://localhost:31415", dtype=float, \ nsamples=500, tag="time_plot", label="Time plot") channel_plot = net.network_constellation_plot(url="udp://localhost:31416", \ - nsamples=200, tag="channel_plot", label="Channel") + nsamples=512, tag="channel_plot", label="Channel") synchronized_plot = net.network_constellation_plot(url="udp://localhost:31417", \ - nsamples=200, tag="synchronized_plot", label="Synchronized") + nsamples=512, tag="synchronized_plot", label="Synchronized") equalized_plot = net.network_constellation_plot(url="udp://localhost:31418", \ - nsamples=200, tag="equalized_plot", label="Equalized") + nsamples=512, tag="equalized_plot", label="Equalized") locked_plot = net.network_constellation_plot(url="udp://localhost:31419", \ - nsamples=200, tag="locked_plot", label="Locked") + nsamples=512, tag="locked_plot", label="Locked") constellation_plots = [channel_plot, synchronized_plot, equalized_plot, locked_plot] network_plots = [time_plot] + constellation_plots @@ -195,7 +195,7 @@ with window(label="RX DSP Flow Graph", width=800, height=400, pos=(0,25), tag="r # Network plots def make_constellation_plot_window(plot, label): - with window(label=label, no_collapse=True, + with window(label=label, no_collapse=True, no_close=True, \ width=plot_window_sizes[plot][0], \ height=plot_window_sizes[plot][1], \ pos=plot_window_positions[plot], \ diff --git a/src/gui/net.py b/src/gui/net.py index 121cc76..1ddb1d0 100644 --- a/src/gui/net.py +++ b/src/gui/net.py @@ -1,3 +1,4 @@ +import os import select import socket from urllib.parse import urlparse @@ -13,18 +14,34 @@ class udpsource: Creates an UDP listening socket """ def __init__(self, url, dtype, timeout=0.05): - self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) self.url = urlparse(url) self.dtype = dtype self.timeout = timeout + if self.url.scheme == "udp": + self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) + elif self.url.scheme == "file": + try: + os.unlink(self.url.path) + except OSError: + if os.path.exists(self.url.path): + raise + + self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM) + else: + raise NotImplemented + def __del__(self): self.sock.close() def bind(self): self.sock.setblocking(False) - self.sock.bind((self.url.hostname, self.url.port)) - # self.sock.listen() + if self.url.scheme == "udp": + self.sock.bind((self.url.hostname, self.url.port)) + elif self.url.scheme == "file": + self.sock.bind(self.url.path) + + # self.sock.listen(1) def read(self, nblocks): # TODO: run in a separate thread (it will be painful to implement) @@ -33,7 +50,7 @@ class udpsource: return None # read from socket - blocksize = 1024 * 4 + blocksize = 1024 string = ready[0].recv(nblocks * blocksize).decode("ascii") # decode string, remove empty values -- cgit v1.2.1