diff options
Diffstat (limited to 'gr-input/python')
-rw-r--r-- | gr-input/python/CMakeLists.txt | 77 | ||||
-rw-r--r-- | gr-input/python/__init__.py | 53 | ||||
-rw-r--r-- | gr-input/python/gr_ramp_source.py | 46 | ||||
-rw-r--r-- | gr-input/python/gr_step_source.py | 43 | ||||
-rw-r--r-- | gr-input/python/ramp_hierblock.py | 19 | ||||
-rw-r--r-- | gr-input/python/step_hierblock.py | 22 |
6 files changed, 260 insertions, 0 deletions
diff --git a/gr-input/python/CMakeLists.txt b/gr-input/python/CMakeLists.txt new file mode 100644 index 000000000..992012646 --- /dev/null +++ b/gr-input/python/CMakeLists.txt @@ -0,0 +1,77 @@ +# Copyright 2012 Free Software Foundation, Inc. +# +# 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. + +######################################################################## +include(GrPython) + +GR_PYTHON_INSTALL( + FILES + __init__.py + DESTINATION ${GR_PYTHON_DIR}/gnuradio/input + COMPONENT "input_python" +) + +GR_PYTHON_INSTALL( + FILES + gr_ramp_source.py + DESTINATION ${GR_PYTHON_DIR}/gnuradio/input + COMPONENT "input_python" +) + +GR_PYTHON_INSTALL( + FILES + gr_step_source.py + DESTINATION ${GR_PYTHON_DIR}/gnuradio/input + COMPONENT "input_python" +) + +GR_PYTHON_INSTALL( + FILES + ramp_hierblock.py + DESTINATION ${GR_PYTHON_DIR}/gnuradio/input + COMPONENT "input_python" +) + +GR_PYTHON_INSTALL( + FILES + step_hierblock.py + DESTINATION ${GR_PYTHON_DIR}/gnuradio/input + COMPONENT "input_python" +) + + + + +######################################################################## +# Handle the unit tests +######################################################################## +if(ENABLE_TESTING) + +list(APPEND GR_TEST_PYTHON_DIRS + ${CMAKE_BINARY_DIR}/gr-input/python +) +list(APPEND GR_TEST_TARGET_DEPS gnuradio-input) + +include(GrTest) +file(GLOB py_qa_test_files "qa_*.py") +foreach(py_qa_test_file ${py_qa_test_files}) + get_filename_component(py_qa_test_name ${py_qa_test_file} NAME_WE) + GR_ADD_TEST(${py_qa_test_name} ${PYTHON_EXECUTABLE} ${PYTHON_DASH_B} ${py_qa_test_file}) +endforeach(py_qa_test_file) +endif(ENABLE_TESTING) diff --git a/gr-input/python/__init__.py b/gr-input/python/__init__.py new file mode 100644 index 000000000..6e8ef1f55 --- /dev/null +++ b/gr-input/python/__init__.py @@ -0,0 +1,53 @@ +# +# Copyright 2008,2009 Free Software Foundation, Inc. +# +# This application 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. +# +# This application 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 this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# + +# The presence of this file turns this directory into a Python package + +''' +This is the GNU Radio SCIGEN module. Place your Python package +description here (python/__init__.py). +''' + +# ---------------------------------------------------------------- +# Temporary workaround for ticket:181 (swig+python problem) +import sys +_RTLD_GLOBAL = 0 +try: + from dl import RTLD_GLOBAL as _RTLD_GLOBAL +except ImportError: + try: + from DLFCN import RTLD_GLOBAL as _RTLD_GLOBAL + except ImportError: + pass + +if _RTLD_GLOBAL != 0: + _dlopenflags = sys.getdlopenflags() + sys.setdlopenflags(_dlopenflags|_RTLD_GLOBAL) +# ---------------------------------------------------------------- + + +# import any pure python here +import serial + +# + +# ---------------------------------------------------------------- +# Tail of workaround +if _RTLD_GLOBAL != 0: + sys.setdlopenflags(_dlopenflags) # Restore original flags +# ---------------------------------------------------------------- diff --git a/gr-input/python/gr_ramp_source.py b/gr-input/python/gr_ramp_source.py new file mode 100644 index 000000000..687ffb957 --- /dev/null +++ b/gr-input/python/gr_ramp_source.py @@ -0,0 +1,46 @@ +#!/usr/bin/python + +import gras +import numpy +# Serial is imported in __init__ +class ramp(gras.Block): + + + def __init__(self): + gras.Block.__init__(self, + name="ser", + in_sig=[numpy.float32], + out_sig=[numpy.float32]) + self.i = 0 + self.flag=True + + def set_parameters(self, ramp_slope, height_Offset, width_Offset): + self.slope = ramp_slope + self.width = width_Offset + self.offset = height_Offset + + def work(self, input_items, output_items): + + out = output_items[0][0] + input_stream = input_items[0][0] + + if self.flag: + for j in range(self.width): + out = self.offset + print "OUT", out + + self.produce(0,1) # Produce from port 0 output_items + self.consume(0,1) # Consume from port 0 input_items + + self.flag = False + + else: + + self.i = self.i + 1 + out =self.offset + self.i*input_stream*self.slope + + print "OUT", out + + self.produce(0,1) # Produce from port 0 output_items + self.consume(0,1) # Consume from port 0 input_items + diff --git a/gr-input/python/gr_step_source.py b/gr-input/python/gr_step_source.py new file mode 100644 index 000000000..904f89292 --- /dev/null +++ b/gr-input/python/gr_step_source.py @@ -0,0 +1,43 @@ +#!/usr/bin/python + +import gras +import numpy +# Serial is imported in __init__ +class step(gras.Block): + + + def __init__(self): + gras.Block.__init__(self, + name="ser", + in_sig=[numpy.float32], + out_sig=[numpy.float32]) + self.flag=True + + def set_parameters(self, step_size, offset, width): + self.step_size = step_size + self.width = width + self.offset = offset + + def work(self, input_items, output_items): + + out = output_items[0][0:1] + input_stream = input_items[0][0] + + if self.flag: + for i in range(self.width): + out[:1] = self.offset + print "OUT", out + + self.produce(0,1) # Produce from port 0 output_items + self.consume(0,1) # Consume from port 0 input_items + + self.flag = False + + else: + out[:1] = self.offset + input_stream*self.step_size + + print "OUT", out + + self.produce(0,1) # Produce from port 0 output_items + self.consume(0,1) # Consume from port 0 input_items + diff --git a/gr-input/python/ramp_hierblock.py b/gr-input/python/ramp_hierblock.py new file mode 100644 index 000000000..950615142 --- /dev/null +++ b/gr-input/python/ramp_hierblock.py @@ -0,0 +1,19 @@ +import gras +import numpy +from gnuradio import gr +from gnuradio import blocks + +# Source block1 import +import gr_ramp_source +from gnuradio import blocks + +class HierBlock(gr.hier_block2): + def __init__(self,ramp_slope, height_Offset, width_Offset): + gr.hier_block2.__init__(self,"HierBlock",gr.io_signature(1,1,gr.sizeof_float), gr.io_signature(1,2,gr.sizeof_float)) + #constant_block initialized + self.constant_block = gr.sig_source_f(0,gr.GR_CONST_WAVE,0,0,1) + #ramp_source block initialized + self.ramp_source=gr_ramp_source.ramp() + self.ramp_source.set_parameters(ramp_slope, height_Offset, width_Offset) + self.connect(self,(self.constant_block,0),(self.ramp_source,0),self) + diff --git a/gr-input/python/step_hierblock.py b/gr-input/python/step_hierblock.py new file mode 100644 index 000000000..4243606d6 --- /dev/null +++ b/gr-input/python/step_hierblock.py @@ -0,0 +1,22 @@ +import gras +import numpy +from gnuradio import gr +from gnuradio import blocks + +# Source block1 import +import gr_step_source +from gnuradio import blocks + +class HierBlock(gr.hier_block2): + def __init__(self, step_size, H_Off, W_Off): + gr.hier_block2.__init__(self, "HierBlock", + gr.io_signature(1,1,gr.sizeof_float), + gr.io_signature(1,2,gr.sizeof_float)) + + # constant_block initialized + self.constant_block = gr.sig_source_f(0, gr.GR_CONST_WAVE,0,0,1) + # step_source block initialized + self.step_source = gr_step_source.step() + self.step_source.set_parameters(step_size, H_Off, W_Off) + self.connect(self, (self.constant_block,0) , (self.step_source,0), self) + |