aboutsummaryrefslogtreecommitdiffstats
path: root/src/gr-fadingui
diff options
context:
space:
mode:
authorsara <sara.halter@gmx.ch>2021-12-14 18:57:29 +0100
committersara <sara.halter@gmx.ch>2021-12-14 18:57:29 +0100
commit75edb689e503769dcb1ab228e4a59ea2e0cf8d9e (patch)
treea964fa58a8a4044e0c10b75a2cd6a165cedeca6d /src/gr-fadingui
parentAvoid sending EVERY sample over UDP (diff)
downloadFading-75edb689e503769dcb1ab228e4a59ea2e0cf8d9e.tar.gz
Fading-75edb689e503769dcb1ab228e4a59ea2e0cf8d9e.zip
BER block angepasst
Diffstat (limited to 'src/gr-fadingui')
-rw-r--r--src/gr-fadingui/grc/fadingui_ber.block.yml4
-rw-r--r--src/gr-fadingui/python/ber.py34
-rw-r--r--src/gr-fadingui/python/logger.py2
3 files changed, 31 insertions, 9 deletions
diff --git a/src/gr-fadingui/grc/fadingui_ber.block.yml b/src/gr-fadingui/grc/fadingui_ber.block.yml
index 477f9ff..b0ec75c 100644
--- a/src/gr-fadingui/grc/fadingui_ber.block.yml
+++ b/src/gr-fadingui/grc/fadingui_ber.block.yml
@@ -5,7 +5,7 @@ category: '[fadingui]'
templates:
imports: import fadingui
make: fadingui.ber(vgl=${vgl}, vlen=${vlen},address=${address})
-
+
# 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)
@@ -21,7 +21,7 @@ parameters:
- id: address
label: Address
dtype: string
- default: "udp://localhost:31415"
+ default: "udp://localhost:31420"
# Make one 'inputs' list entry per input and one 'outputs' list entry per output.
diff --git a/src/gr-fadingui/python/ber.py b/src/gr-fadingui/python/ber.py
index 205dcd4..1c5debf 100644
--- a/src/gr-fadingui/python/ber.py
+++ b/src/gr-fadingui/python/ber.py
@@ -23,6 +23,7 @@ import socket
from urllib.parse import urlparse
import numpy as np
+from numpy_ringbuffer import RingBuffer
from gnuradio import gr
from fadingui.logger import get_logger
@@ -42,6 +43,9 @@ class ber(gr.sync_block):
self.vgl=vgl
self.vlen=vlen
+ self.ber_samples = RingBuffer(capacity=2000, dtype=int)
+ self.ber_samples.extend(np.zeros(self.ber_samples.maxlen))
+
# Create a socket and parse remote machine url
self.socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
self.url = urlparse(address)
@@ -65,14 +69,23 @@ class ber(gr.sync_block):
# FIXME: this could be (very) slow, is there a faster way with numpy?
# Maybe numpy.array2string
return bytes(str(data) + "\n", "ascii")
-
+
+ def ber_stats(self):
+ ber_max = np.max(self.ber_samples)
+ ber_min = np.min(self.ber_samples)
+ ber_avg = np.sum(self.ber_samples) / self.ber_samples.maxlen
+
+ return ber_max, ber_min, ber_avg
+
def work(self, input_items, output_items):
inp = input_items[0]
log.debug(f"Length: {len(inp)}")
- log.debug(f"Inp_vector:{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
@@ -81,11 +94,20 @@ class ber(gr.sync_block):
trueber = ber - 32
if trueber < 0:
trueber = 0
- log.debug(f"BER {trueber} in Paket {i}")
-
- self.send(self.encode(trueber))
+ # log.debug(f"BER {trueber} in Paket {i}")
+
+ self.ber_samples.appendleft(trueber)
- return len(inp)
+ 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))
+
+ return len(inp)
#return len(input_items[0])
diff --git a/src/gr-fadingui/python/logger.py b/src/gr-fadingui/python/logger.py
index a101b9e..a189aeb 100644
--- a/src/gr-fadingui/python/logger.py
+++ b/src/gr-fadingui/python/logger.py
@@ -10,5 +10,5 @@ def get_logger(module):
log.addHandler(stdout_handler)
stdout_handler.setFormatter(formatter)
- log.setLevel(logging.WARNING)
+ log.setLevel(logging.DEBUG)
return log