aboutsummaryrefslogtreecommitdiffstats
path: root/src/gr-fadingui/python
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/gr-fadingui/python/ber.py10
-rw-r--r--src/gr-fadingui/python/netsink.py36
2 files changed, 33 insertions, 13 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