aboutsummaryrefslogtreecommitdiffstats
path: root/src/gr-fadingui
diff options
context:
space:
mode:
authorNao Pross <np@0hm.ch>2021-12-14 19:52:22 +0100
committerNao Pross <np@0hm.ch>2021-12-14 19:52:22 +0100
commitf08d1103f338deb770420d3e3b17cc9f07b6084c (patch)
tree80dd2ec341ba33037d9bc900933530e675061014 /src/gr-fadingui
parentAdd (disabled) power squelch (diff)
downloadFading-f08d1103f338deb770420d3e3b17cc9f07b6084c.tar.gz
Fading-f08d1103f338deb770420d3e3b17cc9f07b6084c.zip
Attempt to use UNIX sockets for better performance
Diffstat (limited to 'src/gr-fadingui')
-rw-r--r--src/gr-fadingui/python/netsink.py36
1 files changed, 31 insertions, 5 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