diff options
-rw-r--r-- | CMakeLists.txt | 1 | ||||
-rw-r--r-- | gr-serial/CMakeLists.txt | 55 | ||||
-rw-r--r-- | gr-serial/doc/CMakeLists.txt | 23 | ||||
-rw-r--r-- | gr-serial/doc/README.serial | 2 | ||||
-rw-r--r-- | gr-serial/doc/serial.dox | 29 | ||||
-rw-r--r-- | gr-serial/grc/CMakeLists.txt | 24 | ||||
-rw-r--r-- | gr-serial/grc/serial.xml | 110 | ||||
-rw-r--r-- | gr-serial/python/CMakeLists.txt | 55 | ||||
-rw-r--r-- | gr-serial/python/__init__.py | 53 | ||||
-rw-r--r-- | gr-serial/python/gr_serial.py | 45 |
10 files changed, 397 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index f75bc086e..ef2ae40cf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -264,6 +264,7 @@ add_subdirectory(gr-blocks) add_subdirectory(gr-scigen) add_subdirectory(gr-controls) add_subdirectory(gr-sbhs) +add_subdirectory(gr-serial) #finalize cpack after subdirs processed include(GrPackage) diff --git a/gr-serial/CMakeLists.txt b/gr-serial/CMakeLists.txt new file mode 100644 index 000000000..b4feb6042 --- /dev/null +++ b/gr-serial/CMakeLists.txt @@ -0,0 +1,55 @@ +# 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. + +######################################################################## +# Setup dependencies +######################################################################## +#include(GrBoost) + +#find_package(SCIGENW3f) + +######################################################################## +# Register component +######################################################################## +include(GrComponent) + +GR_REGISTER_COMPONENT("gr-serial" ENABLE_GR_SCIGEN + ENABLE_GRUEL + ENABLE_VOLK + Boost_FOUND + ENABLE_GR_CORE +) + +######################################################################## +# Begin conditional configuration +######################################################################## +if(ENABLE_GR_SCIGEN) + +######################################################################## +# Add subdirectories +######################################################################## +if(ENABLE_PYTHON) + add_subdirectory(python) + add_subdirectory(grc) +endif(ENABLE_PYTHON) +#add_subdirectory(examples) +add_subdirectory(doc) + + +endif(ENABLE_GR_SCIGEN) diff --git a/gr-serial/doc/CMakeLists.txt b/gr-serial/doc/CMakeLists.txt new file mode 100644 index 000000000..b932e6428 --- /dev/null +++ b/gr-serial/doc/CMakeLists.txt @@ -0,0 +1,23 @@ +# 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. + +install( + FILES README.serial + DESTINATION ${GR_PKG_DOC_DIR} +) diff --git a/gr-serial/doc/README.serial b/gr-serial/doc/README.serial new file mode 100644 index 000000000..1bd326897 --- /dev/null +++ b/gr-serial/doc/README.serial @@ -0,0 +1,2 @@ +Serial Python block + diff --git a/gr-serial/doc/serial.dox b/gr-serial/doc/serial.dox new file mode 100644 index 000000000..8843d0560 --- /dev/null +++ b/gr-serial/doc/serial.dox @@ -0,0 +1,29 @@ +/*! \page page_fft FFT Signal Processing Blocks + +\section Introduction + +This is the gr-scigen package. It contains signal processing blocks to +perform FFTs and FFT-related functionality. + +The Python namespace is in gnuradio.fft, which would be normally +imported as: + +\code + from gnuradio import scigen +\endcode + +See the Doxygen documentation for details about the blocks available +in this package. A quick listing of the details can be found in Python +after importing by using: + +\code + help(scigen) +\endcode + +\section Dependencies + +The scigen blocks require the following dependencies. + +\li fftw3f (>= 3.0) http://www.fftw.org/download.html + +*/ diff --git a/gr-serial/grc/CMakeLists.txt b/gr-serial/grc/CMakeLists.txt new file mode 100644 index 000000000..89e6e9ce7 --- /dev/null +++ b/gr-serial/grc/CMakeLists.txt @@ -0,0 +1,24 @@ +# 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. + +install(FILES + serial.xml + DESTINATION ${GRC_BLOCKS_DIR} + COMPONENT "serial_python" +) diff --git a/gr-serial/grc/serial.xml b/gr-serial/grc/serial.xml new file mode 100644 index 000000000..239b4ae88 --- /dev/null +++ b/gr-serial/grc/serial.xml @@ -0,0 +1,110 @@ +<?xml version="1.0"?> +<!-- +################################################### +##Add Block: +## all types, 1 output, 2 to inf inputs +################################################### + --> +<block> + <name>serial</name> + <key>gr_serial</key> + <category>serial</category> + + <import>from gnuradio import gr_ser</import> + <make>gr_ser.ser() +self.$(id).set_parameters($port, $baud, $bytesize, $parity, $stopbits) + </make> + <param> + <name>IO Type</name> + <key>type</key> + <type>enum</type> + <option><name>F32_F32</name><key>f32_f32</key></option> + <option><name>S32_S32</name><key>s32_s32</key></option> + <option><name>S16_S16</name><key>s16_s16</key></option> + <option><name>S8_S8</name><key>s8_s8</key></option> + </param> + <param> + <name>Num Inputs</name> + <key>num_inputs</key> + <value>1</value> + <type>int</type> + </param> + + <param> + <name>Vec Length</name> + <key>vlen</key> + <value>1</value> + <type>int</type> + </param> + + + <!-- Serial Port options --> + <param> + <name>Port</name> + <key>port</key> + <value>/dev/ttyUSB0</value> + <type>string</type> + </param> + + <param> + <name>Baud</name> + <key>baud</key> + <value>9600</value> + <type>int</type> + </param> + + <param> + <name>Byte Size</name> + <key>bytesize</key> + <value>8</value> + <type>int</type> + </param> + + <param> + <name>parity</name> + <key>parity</key> + <value>N</value> + <type>string</type> + </param> + + <param> + <name>Stop Bits</name> + <key>stopbits</key> + <value>1</value> + <type>int</type> + </param> + + + + + <!-- + Check if number of inputs are greater than 0, and if vector length + is greater than 0. + --> + <check>$num_inputs > 0</check> + <check>$vlen > 0</check> + + <sink> + <name>in</name> + <type>$(str($type).split('_')[0])</type> + <vlen>$vlen</vlen> + <nports>$num_inputs</nports> + </sink> + + <source> + <name>out</name> + <type>$(str($type).split('_')[1])</type> + <vlen>$vlen</vlen> + </source> + <doc> + +Generic Serial Block implemented using pyserial + +> Port +> Baud +> Byte Size +> Parity +> Stop Bits + + </doc> +</block> diff --git a/gr-serial/python/CMakeLists.txt b/gr-serial/python/CMakeLists.txt new file mode 100644 index 000000000..e0f33d9b1 --- /dev/null +++ b/gr-serial/python/CMakeLists.txt @@ -0,0 +1,55 @@ +# 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/serial + COMPONENT "serial_python" +) + +GR_PYTHON_INSTALL( + FILES + gr_serial.py + DESTINATION ${GR_PYTHON_DIR}/gnuradio/serial + COMPONENT "serial_python" +) + + + +######################################################################## +# Handle the unit tests +######################################################################## +if(ENABLE_TESTING) + +list(APPEND GR_TEST_PYTHON_DIRS + ${CMAKE_BINARY_DIR}/gr-serial/python +) +list(APPEND GR_TEST_TARGET_DEPS gnuradio-serial) + +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-serial/python/__init__.py b/gr-serial/python/__init__.py new file mode 100644 index 000000000..6e8ef1f55 --- /dev/null +++ b/gr-serial/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-serial/python/gr_serial.py b/gr-serial/python/gr_serial.py new file mode 100644 index 000000000..00b70c0d8 --- /dev/null +++ b/gr-serial/python/gr_serial.py @@ -0,0 +1,45 @@ +#!/usr/bin/python + +import gras +import numpy +# Serial is imported in __init__ +class ser(gras.Block): + + + def __init__(self): + gras.Block.__init__(self, + name="ser", + in_sig=[numpy.float32], + out_sig=[numpy.float32]) + self.n = 1 + def set_parameters(self, port, baud, bytesize, parity, stopbits): + + try: + print port + self.ser_obj = serial.Serial(port, baud, bytesize, parity, stopbits) + print("serial found on " + port ) + self.ser_obj.open() + except: + print "Couldn't Open Serial Port " + port + " Failed" + + + def work(self, input_items, output_items): + + self.n = input_items[0][0] + out = output_items[0][:self.n] + # Input is size of output_items to be returned + + for i in range(self.n): + + # Try catch block to avoid Error + # ValueError: invalid literal for int() with base 10: '\xfe354\r\n' + try: + out[i] = int(self.ser_obj.readline()) + except: + pass + + print "OUT", out[:self.n] + + self.produce(0,len(out)) # Produce from port 0 output_items + self.consume(0,1) # Consume from port 0 input_items + |