aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/gr-fadingui/python/netsink.py36
-rwxr-xr-xsrc/gui/gui.py267
-rw-r--r--src/gui/net.py32
-rw-r--r--src/gui/res/pic/lena512color.png (renamed from src/gui/lena512color.png)bin474775 -> 474775 bytes
-rw-r--r--src/gui/res/pic/lena512color.tiff (renamed from src/gui/lena512color.tiff)bin786572 -> 786572 bytes
-rw-r--r--src/gui/res/ttf/Hack-Bold.ttfbin0 -> 317628 bytes
-rw-r--r--src/gui/res/ttf/Hack-BoldItalic.ttfbin0 -> 322288 bytes
-rw-r--r--src/gui/res/ttf/Hack-Italic.ttfbin0 -> 316156 bytes
-rw-r--r--src/gui/res/ttf/Hack-Regular.ttfbin0 -> 309408 bytes
9 files changed, 196 insertions, 139 deletions
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 9ac69f7..7e2357b 100755
--- a/src/gui/gui.py
+++ b/src/gui/gui.py
@@ -39,14 +39,60 @@ show_demo()
show_debug()
#================================================
+# Globl variables
+
+# Network Plots
+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=512, tag="channel_plot", label="Channel")
+synchronized_plot = net.network_constellation_plot(url="udp://localhost:31417", \
+ nsamples=512, tag="synchronized_plot", label="Synchronized")
+equalized_plot = net.network_constellation_plot(url="udp://localhost:31418", \
+ nsamples=512, tag="equalized_plot", label="Equalized")
+locked_plot = net.network_constellation_plot(url="udp://localhost:31419", \
+ nsamples=512, tag="locked_plot", label="Locked")
+
+constellation_plots = [channel_plot, synchronized_plot, equalized_plot, locked_plot]
+network_plots = [time_plot] + constellation_plots
+
+const_plots_start = (800, 25)
+const_plot_win_width = 560
+const_plot_win_height = 560
+
+# size of the plot windows
+plot_window_sizes = {
+ time_plot: (800, 400),
+ channel_plot: (const_plot_win_width, const_plot_win_height),
+ synchronized_plot: (const_plot_win_width, const_plot_win_height),
+ equalized_plot: (const_plot_win_width, const_plot_win_height),
+ locked_plot: (const_plot_win_width, const_plot_win_height),
+}
+
+# Where to place the network plot windows
+plot_window_positions = {
+ time_plot: (0, 425),
+ channel_plot: (const_plots_start),
+ synchronized_plot: (const_plots_start[0] + const_plot_win_width, \
+ const_plots_start[1]),
+ equalized_plot: (const_plots_start[0], \
+ const_plots_start[1] + const_plot_win_height),
+ locked_plot: (const_plots_start[0] + const_plot_win_width, \
+ const_plots_start[1] + const_plot_win_height),
+}
+
+# Wheter contellation plots axes are locked
+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"):
@@ -62,50 +108,59 @@ with theme(tag="constellation_series_theme"):
def exit(sender, data):
stop_dearpygui()
-# Flow graph window
-def on_rx_node_link(sender, app_data):
- link_id_1, link_id_2 = app_data
- add_node_link(link_id_1, link_id_2, parent=sender)
-
-def on_rx_node_delink(sender, app_data):
- link_id = app_data
- # do nothing
- # delete_item(link_id)
-
-# add and load images
-def add_and_load_image(image_path):
- width, height, channels, data = load_image(image_path)
-
- with texture_registry() as reg_id:
- texture_id = add_static_texture(width, height, data, parent=reg_id)
-
- return add_image(texture_id)
-
-
#================================================
# Primary Window
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"):
- add_menu_item(label="Toggle Fullscreen",callback=toggle_viewport_fullscreen)
- add_menu_item(label="Minimize",callback=minimize_viewport)
- add_menu_item(label="Close", callback=exit)
+ add_menu_item(label="Toggle Fullscreen", callback=toggle_viewport_fullscreen)
+ add_menu_item(label="Minimize", callback=minimize_viewport)
+ add_menu_item(label="Close", callback=exit, tag="menu_settings_close")
with theme(tag="close"):
with theme_component():
add_theme_color(mvThemeCol_Text,(255, 64, 64))
add_theme_style(mvStyleVar_Alpha, 5)
- bind_item_theme(last_item(),"close")
+ bind_item_theme("menu_settings_close", "close")
+
+ with menu(label="Windows"):
+ def restore_windows():
+ global plot_window_sizes, plot_window_positions
+
+ for plot in network_plots:
+ configure_item(plot.window_tag,
+ width=plot_window_sizes[plot][0],
+ height=plot_window_sizes[plot][1],
+ pos=plot_window_positions[plot])
+
+ add_menu_item(label="Restore Default Positions", callback=restore_windows)
+
+ def unlock_plots():
+ global plots_locked
+ if plots_locked:
+ for plot in constellation_plots:
+ set_axis_limits_auto(plot.xaxis_tag)
+ set_axis_limits_auto(plot.yaxis_tag)
+ else:
+ for plot in constellation_plots:
+ set_axis_limits(plot.xaxis_tag, -2, 2)
+ set_axis_limits(plot.yaxis_tag, -2, 2)
+
+ plots_locked = not plots_locked
+
+ add_menu_item(label="Unlocked plots", callback=unlock_plots, check=True)
+
+
#================================================
# Flow Graph Window
with window(label="RX DSP Flow Graph", width=800, height=400, pos=(0,25), tag="rx_win"):
- with node_editor(callback=on_rx_node_link, delink_callback=on_rx_node_delink):
+ with node_editor():
with node(label="USRP Source", pos=(20,100)):
with node_attribute(tag="src_out", attribute_type=mvNode_Attr_Output):
add_text("Signal from antenna")
@@ -139,118 +194,59 @@ with window(label="RX DSP Flow Graph", width=800, height=400, pos=(0,25), tag="r
#================================================
# Network plots
-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")
-synchronized_plot = net.network_constellation_plot(url="udp://localhost:31417", \
- nsamples=200, tag="synchronized_plot", label="Synchronized")
-equalized_plot = net.network_constellation_plot(url="udp://localhost:31418", \
- nsamples=200, tag="equalized_plot", label="Equalized")
-locked_plot = net.network_constellation_plot(url="udp://localhost:31419", \
- nsamples=200, tag="locked_plot", label="Locked")
-
-network_plots = {
- time_plot: "time_plot_series",
- channel_plot: "channel_plot_series",
- synchronized_plot: "synchronized_plot_series",
- equalized_plot: "equalized_plot_series",
- locked_plot: "locked_plot_series",
-}
-
-with window(label="Time domain", width=800, height=350, pos=(0,425)):
+def make_constellation_plot_window(plot, label):
+ 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], \
+ tag=plot.window_tag):
+ with plot:
+ # Fit to width of window
+ configure_item(plot.tag, width=-1, height=-1)
+
+ # Create and configure axis
+ add_plot_axis(mvXAxis, label="In-Phase", tag=plot.xaxis_tag)
+ add_plot_axis(mvYAxis, label="Quadrature", tag=plot.yaxis_tag)
+
+ add_plot_legend()
+ set_axis_limits(plot.xaxis_tag, -2, 2)
+ set_axis_limits(plot.yaxis_tag, -2, 2)
+
+ # Add series from network
+ add_scatter_series(plot.xdata, plot.ydata, \
+ label=label, parent=plot.xaxis_tag, tag=plot.series_tag)
+ bind_item_theme(plot.series_tag, "constellation_series_theme")
+
+make_constellation_plot_window(channel_plot, "Channel")
+make_constellation_plot_window(synchronized_plot, "Synchronized")
+make_constellation_plot_window(equalized_plot, "Equalized")
+make_constellation_plot_window(locked_plot, "Locked")
+
+with window(label="Time domain", width=800, height=400, pos=(0,425), tag=time_plot.window_tag):
with time_plot:
- configure_item("time_plot", width=-1, height=-1)
-
- add_plot_axis(mvXAxis, label="Time", tag="xaxis_time")
- add_plot_axis(mvYAxis, label="Amplitude", tag="yaxis_time")
- add_line_series(time_plot.xdata, time_plot.ydata, parent="yaxis_time", tag=network_plots[time_plot])
-
-with window(label="Channel", width=560, height=400, pos=(800,25)):
- with channel_plot:
- configure_item("channel_plot", width=-1, height=-1)
-
- add_plot_axis(mvXAxis, label="In-Phase", tag="inphase_channel")
- add_plot_axis(mvYAxis, label="Quadrature", tag="quadrature_channel")
-
- add_plot_legend()
- set_axis_limits("inphase_channel", -2.5, 2.5)
- set_axis_limits("quadrature_channel", -2.5, 2.5)
-
- series_tag = network_plots[channel_plot]
- add_scatter_series(channel_plot.xdata, channel_plot.ydata, \
- label = "Channel", parent="inphase_channel", tag=series_tag)
- bind_item_theme(series_tag, "constellation_series_theme")
-
-with window(label="Synchronized", width=560, height=400, pos=(1360,25)):
- with synchronized_plot:
- configure_item("synchronized_plot", width=-1, height=-1)
+ configure_item(time_plot.tag, width=-1, height=-1)
- add_plot_axis(mvXAxis, label="In-Phase", tag="inphase_synchronized")
- add_plot_axis(mvYAxis, label="Quadrature", tag="quadrature_synchronized")
-
- add_plot_legend()
- set_axis_limits("inphase_synchronized", -2.5, 2.5)
- set_axis_limits("quadrature_synchronized", -2.5, 2.5)
-
- series_tag = network_plots[synchronized_plot]
- add_scatter_series(synchronized_plot.xdata, synchronized_plot.ydata, \
- label="Synchronized", parent="inphase_synchronized", tag=series_tag)
- bind_item_theme(series_tag, "constellation_series_theme")
-
-with window(label="Equalized", width=560, height=400, pos=(800,425)):
- with equalized_plot:
- configure_item("equalized_plot", width=-1, height=-1)
-
- add_plot_legend()
- add_plot_axis(mvXAxis, label="In-Phase", tag="inphase_equalized")
- add_plot_axis(mvYAxis, label="Quadrature", tag="quadrature_equalized")
-
- add_plot_legend()
- set_axis_limits("inphase_equalized", -1.5, 1.5)
- set_axis_limits("quadrature_equalized", -1.5, 1.5)
-
- series_tag = network_plots[equalized_plot]
- add_scatter_series(equalized_plot.xdata, equalized_plot.ydata, \
- label="Equalized", parent="inphase_equalized", tag=series_tag)
- bind_item_theme(series_tag, "constellation_series_theme")
-
-with window(label="Locked", width=560, height=400, pos=(1360,425)):
- with locked_plot:
- configure_item("locked_plot", width=-1, height=-1)
-
- add_plot_legend()
- add_plot_axis(mvXAxis, label="In-Phase", tag="inphase_locked")
- add_plot_axis(mvYAxis, label="Quadrature", tag="quadrature_locked")
-
- add_plot_legend()
- set_axis_limits("inphase_locked", -1.5, 1.5)
- set_axis_limits("quadrature_locked", -1.5, 1.5)
-
- series_tag = network_plots[locked_plot]
- add_scatter_series(locked_plot.xdata, locked_plot.ydata, \
- label="Locked", parent="inphase_locked", tag=series_tag)
- bind_item_theme(series_tag, "constellation_series_theme")
+ add_plot_axis(mvXAxis, label="Time", tag=time_plot.xaxis_tag)
+ add_plot_axis(mvYAxis, label="Amplitude", tag=time_plot.yaxis_tag)
+ add_line_series(time_plot.xdata, time_plot.ydata, parent=time_plot.xaxis_tag, tag=time_plot.series_tag)
#================================================
# Bit Error Rate Window
#TO DO:BER von GNU Radio anzeigen
-with theme(tag= "ber_window"):
+with theme(tag="ber_window"):
with theme_component(mvAll):
add_theme_style(mvStyleVar_WindowTitleAlign, 0.5)
add_theme_style(mvStyleVar_WindowRounding, 5)
add_theme_style(mvStyleVar_WindowBorderSize, 1)#Rad ein und aus Schalten
-with window(label="Bit Error Rate ", width=300, height=150, pos=(1200,875), no_title_bar = True, no_move=True, no_collapse= True) as ber_window :
-
- add_text("The Bit Error Rate is:", pos=(35,10))
-
- with theme(tag= "button_ber"):
+with window(label="Bit Error Rate ", width=300, height=150, pos=(200,875)) as ber_window:
+ add_text("The Bit Error Rate is:")
+ with theme(tag="button_ber"):
with theme_component(mvButton):
- add_theme_color(mvThemeCol_Button,(135, 206, 255))#Blau
- add_theme_color(mvThemeCol_Text,(0,0,0))#Schwarz
+ add_theme_color(mvThemeCol_Button,(135, 206, 255)) #Blau
+ add_theme_color(mvThemeCol_Text,(0,0,0)) #Schwarz
add_theme_style(mvStyleVar_FrameRounding, 5)
add_button(label="BER", height=60, width=-1, tag="ber_value")
@@ -267,8 +263,17 @@ ber_value = net.network_value(url="udp://localhost:31420", dtype=float, refresh_
#================================================
# Picture Window
-with window(label="Picture", width=400, height=300, pos=(0,825)) as picture_window :
- add_and_load_image("lena512color.png") #TO DO Problem lösen
+
+# def add_and_load_image(image_path):
+# width, height, channels, data = load_image(image_path)
+#
+# with texture_registry() as reg_id:
+# texture_id = add_static_texture(width, height, data, parent=reg_id)
+#
+# return add_image(texture_id)
+#
+# with window(label="Picture", width=400, height=300, pos=(0,825)) as picture_window :
+# add_and_load_image("lena512color.png") #TO DO Problem lösen
#================================================
# Start GUI and main loop
diff --git a/src/gui/net.py b/src/gui/net.py
index f836f42..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
@@ -19,13 +20,30 @@ class udpsource:
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)
@@ -77,7 +95,7 @@ class network_plot(udpsource):
"""
Wraps a udpsource while at the same time intefacing with DearPyGUI as a plot element.
"""
- def __init__(self, url, dtype, nsamples , **kwargs):
+ def __init__(self, url, dtype, nsamples, **kwargs):
udpsource.__init__(self, url, dtype)
self.nsamples = nsamples
@@ -96,6 +114,14 @@ class network_plot(udpsource):
self.yvalues.extend(np.zeros(self.nsamples))
def _init_dpg_plot(self, **kwargs):
+ if "tag" in kwargs:
+ self.tag = kwargs["tag"]
+
+ self.series_tag = f"{self.tag}_series"
+ self.xaxis_tag = f"{self.tag}_xaxis"
+ self.yaxis_tag = f"{self.tag}_yaxis"
+ self.window_tag = f"window_{self.tag}"
+
self.plot = dpg.plot(**kwargs)
# Map `with' expressions to the underlying plot
diff --git a/src/gui/lena512color.png b/src/gui/res/pic/lena512color.png
index 7d364e0..7d364e0 100644
--- a/src/gui/lena512color.png
+++ b/src/gui/res/pic/lena512color.png
Binary files differ
diff --git a/src/gui/lena512color.tiff b/src/gui/res/pic/lena512color.tiff
index ffe5c83..ffe5c83 100644
--- a/src/gui/lena512color.tiff
+++ b/src/gui/res/pic/lena512color.tiff
Binary files differ
diff --git a/src/gui/res/ttf/Hack-Bold.ttf b/src/gui/res/ttf/Hack-Bold.ttf
new file mode 100644
index 0000000..7ff4975
--- /dev/null
+++ b/src/gui/res/ttf/Hack-Bold.ttf
Binary files differ
diff --git a/src/gui/res/ttf/Hack-BoldItalic.ttf b/src/gui/res/ttf/Hack-BoldItalic.ttf
new file mode 100644
index 0000000..3b137d9
--- /dev/null
+++ b/src/gui/res/ttf/Hack-BoldItalic.ttf
Binary files differ
diff --git a/src/gui/res/ttf/Hack-Italic.ttf b/src/gui/res/ttf/Hack-Italic.ttf
new file mode 100644
index 0000000..d26198a
--- /dev/null
+++ b/src/gui/res/ttf/Hack-Italic.ttf
Binary files differ
diff --git a/src/gui/res/ttf/Hack-Regular.ttf b/src/gui/res/ttf/Hack-Regular.ttf
new file mode 100644
index 0000000..92a90cb
--- /dev/null
+++ b/src/gui/res/ttf/Hack-Regular.ttf
Binary files differ