Skip to content

Commit

Permalink
adding stream_lambda block and variable_text_input block (with exampl…
Browse files Browse the repository at this point in the history
…e grc)
  • Loading branch information
osh committed May 25, 2015
1 parent f84f662 commit 9d3ab45
Show file tree
Hide file tree
Showing 8 changed files with 1,416 additions and 0 deletions.
1,175 changes: 1,175 additions & 0 deletions apps/test_stream_lambda.grc

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions grc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

install(FILES
pdu_lambda.xml
stream_lambda.xml
time_plot.xml
raster_plot.xml
time_hist.xml
Expand All @@ -30,6 +31,7 @@ install(FILES
cpower_plot.xml
pdu_meta_extract.xml
text_input.xml
variable_text_input.xml
range_input.xml
text_output.xml
meta_text_output.xml
Expand Down
106 changes: 106 additions & 0 deletions grc/stream_lambda.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<?xml version="1.0"?>
<block>
<name>Stream Lambda Block</name>
<key>pyqt_stream_lambda</key>
<category>pyqt</category>
<import>import pyqt</import>
<import>import numpy</import>
<make>pyqt.stream_lambda($fn,$n_streams_in*[$type_in.np],$n_streams_out*[$type_out.np])</make>

<callback>set_fn($fn)</callback>

<param>
<name>function</name>
<key>fn</key>
<value>lambda input_items, output_index: (input_items[output_index][::2]**2)*0.1</value>
<type>raw</type>
</param>

<param>
<name>Num Input Streams</name>
<key>n_streams_in</key>
<value>1</value>
<type>int</type>
</param>

<param>
<name>Num Output Streams</name>
<key>n_streams_out</key>
<value>1</value>
<type>int</type>
</param>

<param>
<name>Input Data Type</name>
<key>type_in</key>
<type>enum</type>
<option>
<name>Complex</name>
<key>complex</key>
<opt>np:numpy.complex64</opt>
</option>
<option>
<name>Float</name>
<key>float</key>
<opt>np:numpy.float32</opt>
</option>
<option>
<name>Int</name>
<key>int</key>
<opt>np:numpy.int32</opt>
</option>
<option>
<name>Short</name>
<key>short</key>
<opt>np:numpy.int16</opt>
</option>
<option>
<name>Byte</name>
<key>byte</key>
<opt>np:numpy.char</opt>
</option>
</param>

<param>
<name>Output Data Type</name>
<key>type_out</key>
<type>enum</type>
<option>
<name>Complex</name>
<key>complex</key>
<opt>np:numpy.complex64</opt>
</option>
<option>
<name>Float</name>
<key>float</key>
<opt>np:numpy.float32</opt>
</option>
<option>
<name>Int</name>
<key>int</key>
<opt>np:numpy.int32</opt>
</option>
<option>
<name>Short</name>
<key>short</key>
<opt>np:numpy.int16</opt>
</option>
<option>
<name>Byte</name>
<key>byte</key>
<opt>np:numpy.char</opt>
</option>
</param>

<sink>
<name>in</name>
<type>$type_in</type>
<nports>$n_streams_in</nports>
</sink>

<source>
<name>pdus</name>
<type>$type_out</type>
<nports>$n_streams_out</nports>
</source>
</block>
27 changes: 27 additions & 0 deletions grc/variable_text_input.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0"?>
<block>
<name>PyQT Text Input Variable</name>
<key>variable_pyqt_text_input</key>
<category>pyqt</category>
<import>import pyqt</import>
<var_make>self.$(id) = $(id) = $value</var_make>
<make>#set $win = 'self._%s_win'%$id
$(win) = pyqt.variable_text_input(self.set_$(id),"$(id)","$(value)","")
$(gui_hint()($win))</make>
<callback>self.set_$(id)($value)</callback>

<param>
<name>Default Value</name>
<key>value</key>
<value>lambda x: 10*x</value>
<type>raw</type>
</param>

<param>
<name>GUI Hint</name>
<key>gui_hint</key>
<value></value>
<type>gui_hint</type>
<hide>part</hide>
</param>
</block>
2 changes: 2 additions & 0 deletions python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ GR_PYTHON_INSTALL(
FILES
__init__.py
pdu_lambda.py
stream_lambda.py
const_plot.py
ctime_plot.py
raster_plot.py
Expand All @@ -44,6 +45,7 @@ GR_PYTHON_INSTALL(
plotter_base.py
pdu_meta_extract.py
text_input.py
variable_text_input.py
range_input.py
text_output.py
meta_text_output.py
Expand Down
2 changes: 2 additions & 0 deletions python/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#

from pdu_lambda import *;
from stream_lambda import *;
from plotter_base import *;
from const_plot import *;
from ctime_plot import *;
Expand All @@ -60,6 +61,7 @@
from cpower_plot import *;
from pdu_meta_extract import *;
from text_input import *;
from variable_text_input import *;
from range_input import *;
from text_output import *;
from meta_text_output import *;
Expand Down
49 changes: 49 additions & 0 deletions python/stream_lambda.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/bin/env python
#
# Copyright 2015 Tim O'Shea
#
# This file is part of GNU Radio
#
# GNU Radio is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option)
# any later version.
#
# GNU Radio is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Radio; see the file COPYING. If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.
#
import numpy
from gnuradio import gr;
import pmt

class stream_lambda(gr.sync_block):
def __init__(self, fn, insig=[numpy.complex64], outsig=[numpy.complex64]):
gr.sync_block.__init__(self,"stream_lambda",insig,outsig)
self.set_fn(fn)
self.lvars = {}

# signature should be: (output_stream_items) = lambda input_items, output_stream_index: ....
def set_fn(self,fn):
self.fn = fn

def work(self, input_items, output_items):
n_out = 0;
for i in range(0,len(output_items)):
o = self.fn(input_items, i)
output_items[i][0:len(o)] = o[:]
if(n_out == 0 or n_out == len(o)):
n_out = len(o)
else:
raise Exception("Streams must produce same lengths for now with the current stream lambda block interface!")
return n_out




53 changes: 53 additions & 0 deletions python/variable_text_input.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/env python
#
# Copyright 2014 Tim O'Shea
#
# This file is part of GNU Radio
#
# GNU Radio is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option)
# any later version.
#
# GNU Radio is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Radio; see the file COPYING. If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.
#
import numpy
from gnuradio import gr;
from scipy import signal
import pylab
import numpy
from PyQt4 import Qt, QtCore, QtGui
import pmt

class variable_text_input(gr.sync_block, QtGui.QLineEdit):
def __init__(self, fn_update=None, blkname="text_input", val="", label="", *args):
gr.sync_block.__init__(self,blkname,[],[])
QtGui.QLineEdit.__init__(self, *args)
self.returnPressed.connect(self.text_changed);
self.message_port_register_out(pmt.intern("pdus"));
self.fn_update = fn_update
self.setText(str(val))

def text_changed(self):
s = self.text().toUtf8();
#nvec = numpy.fromstring((s), dtype=numpy.uint8, count=len(s));
#vec = pmt.to_pmt(nvec);
print s
self.fn_update(eval(str(s)))
#self.message_port_pub(pmt.intern("pdus"), pmt.cons(pmt.PMT_NIL, vec));
#self.clear();

def work(self, input_items, output_items):
pass




0 comments on commit 9d3ab45

Please sign in to comment.