From 324438b65f3a2c58227fb0a304ba36e57a8a1b01 Mon Sep 17 00:00:00 2001 From: manojgudi Date: Thu, 30 Jan 2014 22:34:00 +0530 Subject: gr-serial block --- CMakeLists.txt | 1 + gr-serial/CMakeLists.txt | 55 ++++++++++++++++++++ gr-serial/doc/CMakeLists.txt | 23 +++++++++ gr-serial/doc/README.serial | 2 + gr-serial/doc/serial.dox | 29 +++++++++++ gr-serial/grc/CMakeLists.txt | 24 +++++++++ gr-serial/grc/serial.xml | 110 ++++++++++++++++++++++++++++++++++++++++ gr-serial/python/CMakeLists.txt | 55 ++++++++++++++++++++ gr-serial/python/__init__.py | 53 +++++++++++++++++++ gr-serial/python/gr_serial.py | 45 ++++++++++++++++ 10 files changed, 397 insertions(+) create mode 100644 gr-serial/CMakeLists.txt create mode 100644 gr-serial/doc/CMakeLists.txt create mode 100644 gr-serial/doc/README.serial create mode 100644 gr-serial/doc/serial.dox create mode 100644 gr-serial/grc/CMakeLists.txt create mode 100644 gr-serial/grc/serial.xml create mode 100644 gr-serial/python/CMakeLists.txt create mode 100644 gr-serial/python/__init__.py create mode 100644 gr-serial/python/gr_serial.py 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 @@ + + + + serial + gr_serial + serial + + from gnuradio import gr_ser + gr_ser.ser() +self.$(id).set_parameters($port, $baud, $bytesize, $parity, $stopbits) + + + IO Type + type + enum + + + + + + + Num Inputs + num_inputs + 1 + int + + + + Vec Length + vlen + 1 + int + + + + + + Port + port + /dev/ttyUSB0 + string + + + + Baud + baud + 9600 + int + + + + Byte Size + bytesize + 8 + int + + + + parity + parity + N + string + + + + Stop Bits + stopbits + 1 + int + + + + + + + $num_inputs > 0 + $vlen > 0 + + + in + $(str($type).split('_')[0]) + $vlen + $num_inputs + + + + out + $(str($type).split('_')[1]) + $vlen + + + +Generic Serial Block implemented using pyserial + +> Port +> Baud +> Byte Size +> Parity +> Stop Bits + + + 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 + -- cgit