From 2d02a9787d3bbd7320f23a3c65ee8e8ed0369c1e Mon Sep 17 00:00:00 2001 From: Nao Pross Date: Fri, 3 Dec 2021 22:19:57 +0100 Subject: Replace DearPyGui Sink with Network Sink --- src/gr-fadingui/grc/CMakeLists.txt | 4 +- .../grc/fadingui_dearpygui_sink.block.yml | 38 -------------- src/gr-fadingui/grc/fadingui_netsink.block.yml | 48 ++++++++++++++++++ src/gr-fadingui/python/CMakeLists.txt | 4 +- src/gr-fadingui/python/__init__.py | 3 +- src/gr-fadingui/python/dearpygui_sink.py | 36 ------------- src/gr-fadingui/python/netsink.py | 59 ++++++++++++++++++++++ 7 files changed, 113 insertions(+), 79 deletions(-) delete mode 100644 src/gr-fadingui/grc/fadingui_dearpygui_sink.block.yml create mode 100644 src/gr-fadingui/grc/fadingui_netsink.block.yml delete mode 100644 src/gr-fadingui/python/dearpygui_sink.py create mode 100644 src/gr-fadingui/python/netsink.py (limited to 'src') diff --git a/src/gr-fadingui/grc/CMakeLists.txt b/src/gr-fadingui/grc/CMakeLists.txt index 297ae8d..79c1a31 100644 --- a/src/gr-fadingui/grc/CMakeLists.txt +++ b/src/gr-fadingui/grc/CMakeLists.txt @@ -19,9 +19,9 @@ # Boston, MA 02110-1301, USA. install(FILES fadingui_datasource.block.yml - fadingui_dearpygui_sink.block.yml fadingui_deframer.block.yml fadingui_frame_obj.block.yml fadingui_multipath_fading.block.yml - fadingui_ber.block.yml DESTINATION share/gnuradio/grc/blocks + fadingui_ber.block.yml + fadingui_netsink.block.yml DESTINATION share/gnuradio/grc/blocks ) diff --git a/src/gr-fadingui/grc/fadingui_dearpygui_sink.block.yml b/src/gr-fadingui/grc/fadingui_dearpygui_sink.block.yml deleted file mode 100644 index dbe6198..0000000 --- a/src/gr-fadingui/grc/fadingui_dearpygui_sink.block.yml +++ /dev/null @@ -1,38 +0,0 @@ -id: fadingui_dearpygui_sink -label: UI Sink -category: '[fadingui]' - -templates: - imports: import fadingui - make: fadingui.dearpygui_sink(sock_addr=${sock_addr}, ui_element_id=${ui_element_id}) - -# Make one 'parameters' list entry for every parameter you want settable from the GUI. -# Keys include: -# * id (makes the value accessible as \$keyname, e.g. in the make entry) -# * label (label shown in the GUI) -# * dtype (e.g. int, float, complex, byte, short, xxx_vector, ...) -parameters: -- id: sock_addr - label: Socket address - dtype: string - default: udp:// - -- id: ui_element_id - label: UI element ID - dtype: raw - - -# Make one 'inputs' list entry per input and one 'outputs' list entry per output. -# Keys include: -# * label (an identifier for the GUI) -# * domain (optional - stream or message. Default is stream) -# * dtype (e.g. int, float, complex, byte, short, xxx_vector, ...) -# * vlen (optional - data stream vector length. Default is 1) -# * optional (optional - set to 1 for optional inputs. Default is 0) -inputs: -- label: in - dtype: complex - -# 'file_format' specifies the version of the GRC yml format used in the file -# and should usually not be changed. -file_format: 1 diff --git a/src/gr-fadingui/grc/fadingui_netsink.block.yml b/src/gr-fadingui/grc/fadingui_netsink.block.yml new file mode 100644 index 0000000..4e5b01b --- /dev/null +++ b/src/gr-fadingui/grc/fadingui_netsink.block.yml @@ -0,0 +1,48 @@ +id: fadingui_netsink +label: Network Sink +category: '[fadingui]' +flags: [ python ] + +templates: + imports: import fadingui + make: fadingui.netsink(${address}, ${dtype}, ${vlen}) + +# Make one 'parameters' list entry for every parameter you want settable from the GUI. +# Keys include: +# * id (makes the value accessible as \$keyname, e.g. in the make entry) +# * label (label shown in the GUI) +# * dtype (e.g. int, float, complex, byte, short, xxx_vector, ...) +parameters: +- id: dtype + label: Type + dtype: enum + options: [complex, float, int, short, byte] + option_attributes: + size: [gr.sizeof_gr_complex, gr.sizeof_floar, gr.sizeof_int, gr.sizeof_short, gr.sizeof_char ] + hide: part +- id: vlen + label: Vec Length + dtype: int + default: 1 + hide: ${ 'part' if vlen == 1 else 'none' } +- id: address + label: Address + dtype: string + default: "udp://localhost:31415" + +# Make one 'inputs' list entry per input and one 'outputs' list entry per output. +# Keys include: +# * label (an identifier for the GUI) +# * domain (optional - stream or message. Default is stream) +# * dtype (e.g. int, float, complex, byte, short, xxx_vector, ...) +# * vlen (optional - data stream vector length. Default is 1) +# * optional (optional - set to 1 for optional inputs. Default is 0) +inputs: +- label: in + domain: stream + dtype: ${dtype} + vlen: ${vlen} + +# 'file_format' specifies the version of the GRC yml format used in the file +# and should usually not be changed. +file_format: 1 diff --git a/src/gr-fadingui/python/CMakeLists.txt b/src/gr-fadingui/python/CMakeLists.txt index e04eb5b..bf484cc 100644 --- a/src/gr-fadingui/python/CMakeLists.txt +++ b/src/gr-fadingui/python/CMakeLists.txt @@ -34,11 +34,11 @@ GR_PYTHON_INSTALL( __init__.py logger.py datasource.py - dearpygui_sink.py deframer.py frame_obj.py multipath_fading.py - ber.py DESTINATION ${GR_PYTHON_DIR}/fadingui + ber.py + netsink.py DESTINATION ${GR_PYTHON_DIR}/fadingui ) ######################################################################## diff --git a/src/gr-fadingui/python/__init__.py b/src/gr-fadingui/python/__init__.py index 9fe45d5..56dbdd3 100644 --- a/src/gr-fadingui/python/__init__.py +++ b/src/gr-fadingui/python/__init__.py @@ -33,11 +33,12 @@ except ImportError: # import any pure python here from .datasource import datasource -from .dearpygui_sink import dearpygui_sink + from .deframer import deframer from .frame_obj import frame_obj from .multipath_fading import multipath_fading from .ber import ber +from .netsink import netsink # diff --git a/src/gr-fadingui/python/dearpygui_sink.py b/src/gr-fadingui/python/dearpygui_sink.py deleted file mode 100644 index 6153611..0000000 --- a/src/gr-fadingui/python/dearpygui_sink.py +++ /dev/null @@ -1,36 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -# -# Copyright 2021 Naoki Pross. - -import socket -from urllib.parse import urlparse - -import numpy as np -from gnuradio import gr - -class dearpygui_sink(gr.sync_block): - """ - DearPyGUI Sink - """ - def __init__(self, sock_addr, ui_element_id): - gr.sync_block.__init__(self, - name="dearpygui_sink", - in_sig=[np.complex64], - out_sig=None) - - # sockets - self.socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) - self.srv = urlparse(sock_addr) - - def send(self, value): - data = value.tobytes() - sent = self.socket.sendto(data, (self.srv.hostname, self.srv.port)) - - return len(data) == sent - - def work(self, input_items, output_items): - in0 = input_items[0] - self.send(in0) - return len(input_items[0]) - diff --git a/src/gr-fadingui/python/netsink.py b/src/gr-fadingui/python/netsink.py new file mode 100644 index 0000000..9df81f5 --- /dev/null +++ b/src/gr-fadingui/python/netsink.py @@ -0,0 +1,59 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# Copyright 2021 Sara Cinzia Halter, Naoki Pross. + +import socket +from urllib.parse import urlparse + +import numpy as np +from gnuradio import gr + +class netsink(gr.sync_block): + """ + Sink that sends the data over the network using UDP. + Keep in mind that is quite slow. + """ + def __init__(self, address, dtype, vlen): + gr.sync_block.__init__(self, + name="Network Sink", + in_sig=[], + out_sig=None) + + # Create a socket and parse remote machine url + self.socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) + self.url = urlparse(sock_addr) + self.srv = (self.srv.hostname, self.srv.port) + + def send(self, data): + """ + Send the data to self.srv + + @param data Data as python bytes + @return Number of bytes that were actually sent + """ + assert type(data) == bytes + return self.socket.sendto(data, self.srv) + + def encode(self, data): + """ + Encode the data into a dead simple format + + @param data Array like type + @return Bytes of ASCII encoded comma separated string of numbers + """ + # no data (what are you doing?) + if not data: + return bytes() + + values = "[" + ",".join(map(str, data)) + "]" + return bytes(values, "ascii") + + def work(self, input_items, output_items): + inp = input_items[0] + + # TODO: Check that inp has a reasonable size + self.send(self.encode(inp)) + + return len(input_items[0]) + -- cgit v1.2.1