diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/gr-fadingui/python/ber.py | 10 | ||||
-rw-r--r-- | src/gr-fadingui/python/netsink.py | 36 | ||||
-rwxr-xr-x | src/gui/gui.py | 37 | ||||
-rw-r--r-- | src/gui/net.py | 46 | ||||
-rw-r--r-- | src/gui/res/pic/lena512color.png (renamed from src/gui/lena512color.png) | bin | 474775 -> 474775 bytes | |||
-rw-r--r-- | src/gui/res/pic/lena512color.tiff (renamed from src/gui/lena512color.tiff) | bin | 786572 -> 786572 bytes | |||
-rw-r--r-- | src/gui/res/ttf/Hack-Bold.ttf | bin | 0 -> 317628 bytes | |||
-rw-r--r-- | src/gui/res/ttf/Hack-BoldItalic.ttf | bin | 0 -> 322288 bytes | |||
-rw-r--r-- | src/gui/res/ttf/Hack-Italic.ttf | bin | 0 -> 316156 bytes | |||
-rw-r--r-- | src/gui/res/ttf/Hack-Regular.ttf | bin | 0 -> 309408 bytes |
10 files changed, 96 insertions, 33 deletions
diff --git a/src/gr-fadingui/python/ber.py b/src/gr-fadingui/python/ber.py index 1c5debf..664780f 100644 --- a/src/gr-fadingui/python/ber.py +++ b/src/gr-fadingui/python/ber.py @@ -43,7 +43,7 @@ class ber(gr.sync_block): self.vgl=vgl self.vlen=vlen - self.ber_samples = RingBuffer(capacity=2000, dtype=int) + self.ber_samples = RingBuffer(capacity=100, dtype=int) self.ber_samples.extend(np.zeros(self.ber_samples.maxlen)) # Create a socket and parse remote machine url @@ -84,8 +84,6 @@ class ber(gr.sync_block): log.debug(f"Length: {len(inp)}") # log.debug(f"Inp_vector:{inp}") - - for i in inp: i = np.array(i, dtype=np.uint8) v = np.array(self.vgl, dtype=np.uint8) ^ i @@ -102,11 +100,7 @@ class ber(gr.sync_block): ber_max, ber_min, ber_avg = self.ber_stats() log.debug(f"Statistics: {ber_max}, {ber_min}, {ber_avg}") - #self.send(self.encode(ber_max, ber_min, ber_avg)) - self.send(self.encode(trueber)) - self.send(self.encode(ber_max)) - self.send(self.encode(ber_min)) - self.send(self.encode(ber_avg)) + self.send(self.encode([trueber, ber_max, ber_avg])) return len(inp) #return len(input_items[0]) diff --git a/src/gr-fadingui/python/netsink.py b/src/gr-fadingui/python/netsink.py index 06e376c..8851fe9 100644 --- a/src/gr-fadingui/python/netsink.py +++ b/src/gr-fadingui/python/netsink.py @@ -3,12 +3,16 @@ # # Copyright 2021 Sara Cinzia Halter, Naoki Pross. +import os import socket from urllib.parse import urlparse import numpy as np from gnuradio import gr +from fadingui.logger import get_logger +log = get_logger("netsink") + class netsink(gr.sync_block): """ Sink that sends the data over the network using UDP. @@ -26,7 +30,6 @@ class netsink(gr.sync_block): dt = to_numpy[dtype] if vlen > 1: dt = np.dtype(dt, (vlen,)) - print(dt) gr.sync_block.__init__(self, name="Network Sink", @@ -34,9 +37,28 @@ class netsink(gr.sync_block): out_sig=None) # Create a socket and parse remote machine url - self.socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) self.url = urlparse(address) - self.srv = (self.url.hostname, self.url.port) + self.srv = None + + if self.url.scheme == "udp": + log.debug(f"Creating UDP socket to {self.srv}") + self.socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) + self.srv = (self.url.hostname, self.url.port) + self.socket.connect(self.srv) + + elif self.url.scheme == "file": + log.debug(f"Creating UNIX file socket to {self.url.path}") + self.socket = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM) + self.srv = self.url.path + try: + self.socket.connect(self.srv) + except FileNotFoundError: + log.error("Cannot find socket file, is the server (GUI) running?") + raise + + else: + raise NotImplemented + def send(self, data): """ @@ -46,7 +68,11 @@ class netsink(gr.sync_block): @return Number of bytes that were actually sent """ assert type(data) == bytes - return self.socket.sendto(data, self.srv) + try: + return self.socket.sendto(data, self.srv) + except socket.error as err: + log.warn(f"No data was sent: {err}") + return 0 def encode(self, data): """ @@ -62,7 +88,7 @@ class netsink(gr.sync_block): def work(self, input_items, output_items): # send only every k-th sample - inp = input_items[0][::3] + inp = input_items[0][::2] inp_len = len(inp) blocksize = 1024 diff --git a/src/gui/gui.py b/src/gui/gui.py index 5d86de1..7e2357b 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 @@ -88,11 +88,11 @@ plots_locked = True # Set up theme and looks # Font -# with font_registry(): -# # first argument ids the path to the .ttf or .otf file -# default_font = add_font("NotoSerifCJKjp-Medium.otf", 20) -# second_font = add_font("NotoSerifCJKjp-Medium.otf", 10) -# test = add_font("NotoSerifCJKjp-Medium.otf", 30) +with font_registry(): + # first argument ids the path to the .ttf or .otf file + default_font = add_font("res/ttf/Hack-Regular.ttf", 20) + # second_font = add_font("NotoSerifCJKjp-Medium.otf", 10) + # test = add_font("NotoSerifCJKjp-Medium.otf", 30) # Constellation diagrams with theme(tag="constellation_series_theme"): @@ -113,7 +113,7 @@ def exit(sender, data): with window(tag="primary_window"): # Grössere Schrifftart/ Grösse für das ganze Dokument definiert - # bind_font(default_font) + bind_font(default_font) with menu_bar(): with menu(label="Settings"): @@ -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], \ @@ -249,12 +249,18 @@ with window(label="Bit Error Rate ", width=300, height=150, pos=(200,875)) as be add_theme_color(mvThemeCol_Text,(0,0,0)) #Schwarz add_theme_style(mvStyleVar_FrameRounding, 5) - add_button(label="BER", height=60, width=150,pos=(75,60)) - bind_item_theme(last_item(),"button_ber") + add_button(label="BER", height=60, width=-1, tag="ber_value") + bind_item_theme(last_item(), "button_ber") # bind_item_theme(ber_window, "ber_window") # bind_item_font(ber_window, test) +def set_ber(values): + ber_curr, ber_max, ber_avg = values + configure_item("ber_value", label=f"Current: {ber_curr}, Max: {ber_max}, Avg: {ber_avg}") + +ber_value = net.network_value(url="udp://localhost:31420", dtype=float, refresh_func=set_ber) + #================================================ # Picture Window @@ -278,8 +284,9 @@ set_primary_window("primary_window", True) # Main loop while is_dearpygui_running(): - for plt in network_plots: - plt.refresh_series(plt.series_tag) + for plt, tag in network_plots.items(): + plt.refresh_series(tag) + ber_value.refresh() render_dearpygui_frame() diff --git a/src/gui/net.py b/src/gui/net.py index 121cc76..820bc84 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 @@ -12,19 +13,37 @@ class udpsource: """ Creates an UDP listening socket """ - def __init__(self, url, dtype, timeout=0.05): + def __init__(self, url, dtype, timeout=0.05, blocksize=1024): self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) self.url = urlparse(url) self.dtype = dtype self.timeout = timeout + self.blocksize = blocksize + + 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,8 +52,7 @@ class udpsource: return None # read from socket - blocksize = 1024 * 4 - string = ready[0].recv(nblocks * blocksize).decode("ascii") + string = ready[0].recv(nblocks * self.blocksize).decode("ascii") # decode string, remove empty values chunks = filter(None, re.split(r"\[(.+?)\]", string)) @@ -55,6 +73,24 @@ class udpsource: return values +class network_value(udpsource): + def __init__(self, url, dtype, refresh_func): + udpsource.__init__(self, url, dtype, blocksize=16) + + self._refresh = refresh_func + self.value = None + + self.bind() + + def read(self): + return udpsource.read(self, 1) + + def refresh(self): + self.value = self.read() + if self.value: + self._refresh(self.value) + + class network_plot(udpsource): """ Wraps a udpsource while at the same time intefacing with DearPyGUI as a plot element. diff --git a/src/gui/lena512color.png b/src/gui/res/pic/lena512color.png Binary files differindex 7d364e0..7d364e0 100644 --- a/src/gui/lena512color.png +++ b/src/gui/res/pic/lena512color.png diff --git a/src/gui/lena512color.tiff b/src/gui/res/pic/lena512color.tiff Binary files differindex ffe5c83..ffe5c83 100644 --- a/src/gui/lena512color.tiff +++ b/src/gui/res/pic/lena512color.tiff diff --git a/src/gui/res/ttf/Hack-Bold.ttf b/src/gui/res/ttf/Hack-Bold.ttf Binary files differnew file mode 100644 index 0000000..7ff4975 --- /dev/null +++ b/src/gui/res/ttf/Hack-Bold.ttf diff --git a/src/gui/res/ttf/Hack-BoldItalic.ttf b/src/gui/res/ttf/Hack-BoldItalic.ttf Binary files differnew file mode 100644 index 0000000..3b137d9 --- /dev/null +++ b/src/gui/res/ttf/Hack-BoldItalic.ttf diff --git a/src/gui/res/ttf/Hack-Italic.ttf b/src/gui/res/ttf/Hack-Italic.ttf Binary files differnew file mode 100644 index 0000000..d26198a --- /dev/null +++ b/src/gui/res/ttf/Hack-Italic.ttf diff --git a/src/gui/res/ttf/Hack-Regular.ttf b/src/gui/res/ttf/Hack-Regular.ttf Binary files differnew file mode 100644 index 0000000..92a90cb --- /dev/null +++ b/src/gui/res/ttf/Hack-Regular.ttf |