aboutsummaryrefslogtreecommitdiffstats
path: root/src/gr-fadingui/python
diff options
context:
space:
mode:
authorsara <sara.halter@gmx.ch>2021-12-13 17:20:17 +0100
committersara <sara.halter@gmx.ch>2021-12-13 17:20:17 +0100
commit0f93582b8938e82fb82d826dd4ced119fe2532f1 (patch)
tree6f2cdfa15b5c30c953709a8f0f4e00e5bc74aae8 /src/gr-fadingui/python
parentSome doku change (diff)
downloadFading-0f93582b8938e82fb82d826dd4ced119fe2532f1.tar.gz
Fading-0f93582b8938e82fb82d826dd4ced119fe2532f1.zip
Ber block mit socket ergänzt
Diffstat (limited to 'src/gr-fadingui/python')
-rw-r--r--src/gr-fadingui/python/ber.py41
1 files changed, 37 insertions, 4 deletions
diff --git a/src/gr-fadingui/python/ber.py b/src/gr-fadingui/python/ber.py
index 5b71f35..205dcd4 100644
--- a/src/gr-fadingui/python/ber.py
+++ b/src/gr-fadingui/python/ber.py
@@ -19,6 +19,8 @@
# Boston, MA 02110-1301, USA.
#
+import socket
+from urllib.parse import urlparse
import numpy as np
from gnuradio import gr
@@ -32,7 +34,7 @@ class ber(gr.sync_block):
"""
docstring for block ber
"""
- def __init__(self, vgl, vlen):
+ def __init__(self, vgl, vlen, address):
gr.sync_block.__init__(self,
name="ber",
in_sig=[np.dtype(str(vlen) + "b")],
@@ -40,9 +42,34 @@ class ber(gr.sync_block):
self.vgl=vgl
self.vlen=vlen
+ # 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)
+
+
+ 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
+ """
+ # FIXME: this could be (very) slow, is there a faster way with numpy?
+ # Maybe numpy.array2string
+ return bytes(str(data) + "\n", "ascii")
+
+
def work(self, input_items, output_items):
-
inp = input_items[0]
+
log.debug(f"Length: {len(inp)}")
log.debug(f"Inp_vector:{inp}")
@@ -52,7 +79,13 @@ class ber(gr.sync_block):
ber = sum(np.unpackbits(v))
trueber = ber - 32
- log.debug(f"BER {trueber if trueber > 0 else 0} in Paket {i}")
+ if trueber < 0:
+ trueber = 0
+ log.debug(f"BER {trueber} in Paket {i}")
+
+ self.send(self.encode(trueber))
+
+ return len(inp)
- return len(input_items[0])
+ #return len(input_items[0])