aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/gr-fadingui/grc/fadingui_netsink.block.yml23
-rw-r--r--src/gr-fadingui/python/netsink.py35
2 files changed, 38 insertions, 20 deletions
diff --git a/src/gr-fadingui/grc/fadingui_netsink.block.yml b/src/gr-fadingui/grc/fadingui_netsink.block.yml
index 4e5b01b..a23dc52 100644
--- a/src/gr-fadingui/grc/fadingui_netsink.block.yml
+++ b/src/gr-fadingui/grc/fadingui_netsink.block.yml
@@ -4,8 +4,10 @@ category: '[fadingui]'
flags: [ python ]
templates:
- imports: import fadingui
- make: fadingui.netsink(${address}, ${dtype}, ${vlen})
+ imports: |-
+ import fadingui
+ import numpy as np
+ make: fadingui.netsink(address=${address}, dtype=${type}, vlen=${veclen})
# Make one 'parameters' list entry for every parameter you want settable from the GUI.
# Keys include:
@@ -13,18 +15,19 @@ templates:
# * label (label shown in the GUI)
# * dtype (e.g. int, float, complex, byte, short, xxx_vector, ...)
parameters:
-- id: dtype
+- id: type
label: Type
dtype: enum
- options: [complex, float, int, short, byte]
+ options: [complex, float, int, np.short, np.byte]
+ option_labels: [complex, float, int, short, byte]
option_attributes:
- size: [gr.sizeof_gr_complex, gr.sizeof_floar, gr.sizeof_int, gr.sizeof_short, gr.sizeof_char ]
+ size: [gr.sizeof_gr_complex, gr.sizeof_float, gr.sizeof_int, gr.sizeof_short, gr.sizeof_char]
hide: part
-- id: vlen
+- id: veclen
label: Vec Length
dtype: int
- default: 1
- hide: ${ 'part' if vlen == 1 else 'none' }
+ default: '1'
+ hide: ${ 'part' if veclen == 1 else 'none' }
- id: address
label: Address
dtype: string
@@ -40,8 +43,8 @@ parameters:
inputs:
- label: in
domain: stream
- dtype: ${dtype}
- vlen: ${vlen}
+ dtype: ${type}
+ vlen: ${veclen}
# 'file_format' specifies the version of the GRC yml format used in the file
# and should usually not be changed.
diff --git a/src/gr-fadingui/python/netsink.py b/src/gr-fadingui/python/netsink.py
index 9df81f5..d2dfc92 100644
--- a/src/gr-fadingui/python/netsink.py
+++ b/src/gr-fadingui/python/netsink.py
@@ -15,15 +15,18 @@ class netsink(gr.sync_block):
Keep in mind that is quite slow.
"""
def __init__(self, address, dtype, vlen):
+ dt = np.dtype(dtype, (vlen,)) if vlen > 1 else dtype
+ print(dt)
+
gr.sync_block.__init__(self,
name="Network Sink",
- in_sig=[],
+ in_sig=[dt],
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)
+ self.url = urlparse(address)
+ self.srv = (self.url.hostname, self.url.port)
def send(self, data):
"""
@@ -42,18 +45,30 @@ class netsink(gr.sync_block):
@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()
-
+ # FIXME: this could be (very) slow, is there a faster way with numpy?
values = "[" + ",".join(map(str, data)) + "]"
return bytes(values, "ascii")
def work(self, input_items, output_items):
+ # FIXME: it is probably better NOT to send *every* sample
inp = input_items[0]
+ inp_len = len(inp)
+ blocksize = 1024
+
+ # Check that the packet is not huge
+ if len(inp) < blocksize:
+ self.send(self.encode(inp))
+ else:
+ # compute how to split inp into blocks
+ nblocks = inp_len // blocksize
+ index = blocksize * nblocks
- # TODO: Check that inp has a reasonable size
- self.send(self.encode(inp))
+ # send blocks
+ blocks = np.array(inp[:index]).reshape((blocksize, nblocks))
+ for block in blocks:
+ self.send(self.encode(block))
- return len(input_items[0])
+ # sent the rest
+ self.send(self.encode(inp[index:]))
+ return len(inp)