summaryrefslogtreecommitdiff
path: root/gr-howto-write-a-block
diff options
context:
space:
mode:
authorTom Rondeau <trondeau@vt.edu>2012-09-30 13:34:26 -0400
committerTom Rondeau <trondeau@vt.edu>2012-09-30 13:34:26 -0400
commit505bab9a6c43ef7fd3c815fa92bb90a05a9f2fac (patch)
treece4608fd61d7f9461e6f45620a6fc5cd7bf73ec8 /gr-howto-write-a-block
parent3283a40bef17d3b2579d8cfbd231dd384b27af41 (diff)
howto: updated howto-write-a-block to use new impl style.
Diffstat (limited to 'gr-howto-write-a-block')
-rw-r--r--gr-howto-write-a-block/CMakeLists.txt13
-rw-r--r--gr-howto-write-a-block/apps/howto_square.grc34
-rwxr-xr-xgr-howto-write-a-block/apps/howto_square.py35
-rw-r--r--gr-howto-write-a-block/apps/howto_square_qt.grc277
-rwxr-xr-xgr-howto-write-a-block/apps/howto_square_qt.py96
-rw-r--r--gr-howto-write-a-block/cmake/Modules/FindCppUnit.cmake36
-rw-r--r--gr-howto-write-a-block/docs/README.howto11
-rw-r--r--gr-howto-write-a-block/include/howto/CMakeLists.txt (renamed from gr-howto-write-a-block/include/CMakeLists.txt)8
-rw-r--r--gr-howto-write-a-block/include/howto/api.h (renamed from gr-howto-write-a-block/include/howto_api.h)0
-rw-r--r--gr-howto-write-a-block/include/howto/square2_ff.h68
-rw-r--r--gr-howto-write-a-block/include/howto/square_ff.h68
-rw-r--r--gr-howto-write-a-block/include/howto_square2_ff.h78
-rw-r--r--gr-howto-write-a-block/include/howto_square_ff.h82
-rw-r--r--gr-howto-write-a-block/lib/CMakeLists.txt16
-rw-r--r--gr-howto-write-a-block/lib/howto_square2_ff.cc92
-rw-r--r--gr-howto-write-a-block/lib/howto_square_ff.cc98
-rw-r--r--gr-howto-write-a-block/lib/qa_square2_ff.cc (renamed from gr-howto-write-a-block/lib/qa_howto_square_ff.cc)6
-rw-r--r--gr-howto-write-a-block/lib/qa_square_ff.cc (renamed from gr-howto-write-a-block/lib/qa_howto_square2_ff.cc)6
-rw-r--r--gr-howto-write-a-block/lib/square2_ff_impl.cc98
-rw-r--r--gr-howto-write-a-block/lib/square2_ff_impl.h51
-rw-r--r--gr-howto-write-a-block/lib/square_ff_impl.cc105
-rw-r--r--gr-howto-write-a-block/lib/square_ff_impl.h52
-rw-r--r--[-rwxr-xr-x]gr-howto-write-a-block/python/qa_howto.py50
-rw-r--r--gr-howto-write-a-block/swig/howto_swig.i13
24 files changed, 970 insertions, 423 deletions
diff --git a/gr-howto-write-a-block/CMakeLists.txt b/gr-howto-write-a-block/CMakeLists.txt
index 5d2477f893..6133c9a326 100644
--- a/gr-howto-write-a-block/CMakeLists.txt
+++ b/gr-howto-write-a-block/CMakeLists.txt
@@ -1,4 +1,4 @@
-# Copyright 2011 Free Software Foundation, Inc.
+# Copyright 2011,2012 Free Software Foundation, Inc.
#
# This file is part of GNU Radio
#
@@ -69,7 +69,7 @@ endif()
include(GrPlatform) #define LIB_SUFFIX
set(GR_RUNTIME_DIR bin)
set(GR_LIBRARY_DIR lib${LIB_SUFFIX})
-set(GR_INCLUDE_DIR include)
+set(GR_INCLUDE_DIR include/howto)
set(GR_DATA_DIR share)
set(GR_PKG_DATA_DIR ${GR_DATA_DIR}/${CMAKE_PROJECT_NAME})
set(GR_DOC_DIR ${GR_DATA_DIR}/doc)
@@ -85,6 +85,7 @@ set(GRC_BLOCKS_DIR ${GR_PKG_DATA_DIR}/grc/blocks)
########################################################################
find_package(Gruel)
find_package(GnuradioCore)
+find_package(CppUnit)
if(NOT GRUEL_FOUND)
message(FATAL_ERROR "Gruel required to compile howto")
@@ -94,6 +95,10 @@ if(NOT GNURADIO_CORE_FOUND)
message(FATAL_ERROR "GnuRadio Core required to compile howto")
endif()
+if(NOT CPPUNIT_FOUND)
+ message(FATAL_ERROR "CppUnit required to compile howto")
+endif()
+
########################################################################
# Setup the include and linker paths
########################################################################
@@ -101,12 +106,14 @@ include_directories(
${CMAKE_SOURCE_DIR}/include
${Boost_INCLUDE_DIRS}
${GRUEL_INCLUDE_DIRS}
+ ${CPPUNIT_INCLUDE_DIRS}
${GNURADIO_CORE_INCLUDE_DIRS}
)
link_directories(
${Boost_LIBRARY_DIRS}
${GRUEL_LIBRARY_DIRS}
+ ${CPPUNIT_LIBRARY_DIRS}
${GNURADIO_CORE_LIBRARY_DIRS}
)
@@ -129,7 +136,7 @@ add_custom_target(uninstall
########################################################################
# Add subdirectories
########################################################################
-add_subdirectory(include)
+add_subdirectory(include/howto)
add_subdirectory(lib)
add_subdirectory(swig)
add_subdirectory(python)
diff --git a/gr-howto-write-a-block/apps/howto_square.grc b/gr-howto-write-a-block/apps/howto_square.grc
index a8563698b8..98f73774e3 100644
--- a/gr-howto-write-a-block/apps/howto_square.grc
+++ b/gr-howto-write-a-block/apps/howto_square.grc
@@ -1,6 +1,6 @@
<?xml version='1.0' encoding='ASCII'?>
<flow_graph>
- <timestamp>Thu Nov 12 11:26:07 2009</timestamp>
+ <timestamp>Sun Sep 30 13:32:27 2012</timestamp>
<block>
<key>options</key>
<param>
@@ -44,6 +44,10 @@
<value>True</value>
</param>
<param>
+ <key>max_nouts</key>
+ <value>0</value>
+ </param>
+ <param>
<key>realtime_scheduling</key>
<value></value>
</param>
@@ -72,7 +76,7 @@
</param>
<param>
<key>_coordinate</key>
- <value>(10, 170)</value>
+ <value>(176, 11)</value>
</param>
<param>
<key>_rotation</key>
@@ -138,8 +142,16 @@
<value></value>
</param>
<param>
+ <key>trig_mode</key>
+ <value>gr.gr_TRIG_MODE_AUTO</value>
+ </param>
+ <param>
+ <key>y_axis_label</key>
+ <value>Counts</value>
+ </param>
+ <param>
<key>_coordinate</key>
- <value>(691, 222)</value>
+ <value>(645, 11)</value>
</param>
<param>
<key>_rotation</key>
@@ -158,7 +170,7 @@
</param>
<param>
<key>_coordinate</key>
- <value>(709, 344)</value>
+ <value>(484, 163)</value>
</param>
<param>
<key>_rotation</key>
@@ -189,7 +201,7 @@
</param>
<param>
<key>_coordinate</key>
- <value>(497, 340)</value>
+ <value>(272, 159)</value>
</param>
<param>
<key>_rotation</key>
@@ -224,7 +236,7 @@
</param>
<param>
<key>_coordinate</key>
- <value>(246, 332)</value>
+ <value>(21, 151)</value>
</param>
<param>
<key>_rotation</key>
@@ -290,8 +302,16 @@
<value></value>
</param>
<param>
+ <key>trig_mode</key>
+ <value>gr.gr_TRIG_MODE_AUTO</value>
+ </param>
+ <param>
+ <key>y_axis_label</key>
+ <value>Counts</value>
+ </param>
+ <param>
<key>_coordinate</key>
- <value>(869, 324)</value>
+ <value>(644, 150)</value>
</param>
<param>
<key>_rotation</key>
diff --git a/gr-howto-write-a-block/apps/howto_square.py b/gr-howto-write-a-block/apps/howto_square.py
index f14e28325d..0b293b882f 100755
--- a/gr-howto-write-a-block/apps/howto_square.py
+++ b/gr-howto-write-a-block/apps/howto_square.py
@@ -2,10 +2,9 @@
##################################################
# Gnuradio Python Flow Graph
# Title: Howto Square
-# Generated: Thu Nov 12 11:26:07 2009
+# Generated: Sun Sep 30 13:32:52 2012
##################################################
-import howto
from gnuradio import eng_notation
from gnuradio import gr
from gnuradio.eng_option import eng_option
@@ -13,6 +12,7 @@ from gnuradio.gr import firdes
from gnuradio.wxgui import scopesink2
from grc_gnuradio import wxgui as grc_wxgui
from optparse import OptionParser
+import howto
import wx
class howto_square(grc_wxgui.top_block_gui):
@@ -28,33 +28,37 @@ class howto_square(grc_wxgui.top_block_gui):
##################################################
# Blocks
##################################################
- self.sink = scopesink2.scope_sink_f(
+ self.thr = gr.throttle(gr.sizeof_float*1, samp_rate)
+ self.src = gr.vector_source_f(([float(n)-50 for n in range(100)]), True, 1)
+ self.sqr = howto.square_ff()
+ self.sink2 = scopesink2.scope_sink_f(
self.GetWin(),
- title="Input",
+ title="Output",
sample_rate=samp_rate,
- v_scale=20,
+ v_scale=0,
v_offset=0,
t_scale=0.002,
ac_couple=False,
xy_mode=False,
num_inputs=1,
+ trig_mode=gr.gr_TRIG_MODE_AUTO,
+ y_axis_label="Counts",
)
- self.Add(self.sink.win)
- self.sink2 = scopesink2.scope_sink_f(
+ self.Add(self.sink2.win)
+ self.sink = scopesink2.scope_sink_f(
self.GetWin(),
- title="Output",
+ title="Input",
sample_rate=samp_rate,
- v_scale=0,
+ v_scale=20,
v_offset=0,
t_scale=0.002,
ac_couple=False,
xy_mode=False,
num_inputs=1,
+ trig_mode=gr.gr_TRIG_MODE_AUTO,
+ y_axis_label="Counts",
)
- self.Add(self.sink2.win)
- self.sqr = howto.square_ff()
- self.src = gr.vector_source_f(([float(n)-50 for n in range(100)]), True, 1)
- self.thr = gr.throttle(gr.sizeof_float*1, samp_rate)
+ self.Add(self.sink.win)
##################################################
# Connections
@@ -64,6 +68,11 @@ class howto_square(grc_wxgui.top_block_gui):
self.connect((self.thr, 0), (self.sink, 0))
self.connect((self.sqr, 0), (self.sink2, 0))
+# QT sink close method reimplementation
+
+ def get_samp_rate(self):
+ return self.samp_rate
+
def set_samp_rate(self, samp_rate):
self.samp_rate = samp_rate
self.sink.set_sample_rate(self.samp_rate)
diff --git a/gr-howto-write-a-block/apps/howto_square_qt.grc b/gr-howto-write-a-block/apps/howto_square_qt.grc
new file mode 100644
index 0000000000..7e963f92b5
--- /dev/null
+++ b/gr-howto-write-a-block/apps/howto_square_qt.grc
@@ -0,0 +1,277 @@
+<?xml version='1.0' encoding='ASCII'?>
+<flow_graph>
+ <timestamp>Sun Sep 30 13:32:48 2012</timestamp>
+ <block>
+ <key>variable</key>
+ <param>
+ <key>id</key>
+ <value>samp_rate</value>
+ </param>
+ <param>
+ <key>_enabled</key>
+ <value>True</value>
+ </param>
+ <param>
+ <key>value</key>
+ <value>32000</value>
+ </param>
+ <param>
+ <key>_coordinate</key>
+ <value>(183, 12)</value>
+ </param>
+ <param>
+ <key>_rotation</key>
+ <value>0</value>
+ </param>
+ </block>
+ <block>
+ <key>gr_sig_source_x</key>
+ <param>
+ <key>id</key>
+ <value>gr_sig_source_x_0</value>
+ </param>
+ <param>
+ <key>_enabled</key>
+ <value>True</value>
+ </param>
+ <param>
+ <key>type</key>
+ <value>float</value>
+ </param>
+ <param>
+ <key>samp_rate</key>
+ <value>samp_rate</value>
+ </param>
+ <param>
+ <key>waveform</key>
+ <value>gr.GR_COS_WAVE</value>
+ </param>
+ <param>
+ <key>freq</key>
+ <value>1000</value>
+ </param>
+ <param>
+ <key>amp</key>
+ <value>1</value>
+ </param>
+ <param>
+ <key>offset</key>
+ <value>0</value>
+ </param>
+ <param>
+ <key>_coordinate</key>
+ <value>(19, 98)</value>
+ </param>
+ <param>
+ <key>_rotation</key>
+ <value>0</value>
+ </param>
+ </block>
+ <block>
+ <key>gr_throttle</key>
+ <param>
+ <key>id</key>
+ <value>gr_throttle_0</value>
+ </param>
+ <param>
+ <key>_enabled</key>
+ <value>True</value>
+ </param>
+ <param>
+ <key>type</key>
+ <value>float</value>
+ </param>
+ <param>
+ <key>samples_per_second</key>
+ <value>samp_rate</value>
+ </param>
+ <param>
+ <key>vlen</key>
+ <value>1</value>
+ </param>
+ <param>
+ <key>_coordinate</key>
+ <value>(212, 130)</value>
+ </param>
+ <param>
+ <key>_rotation</key>
+ <value>0</value>
+ </param>
+ </block>
+ <block>
+ <key>howto_square2_ff</key>
+ <param>
+ <key>id</key>
+ <value>howto_square2_ff_0</value>
+ </param>
+ <param>
+ <key>_enabled</key>
+ <value>True</value>
+ </param>
+ <param>
+ <key>_coordinate</key>
+ <value>(445, 100)</value>
+ </param>
+ <param>
+ <key>_rotation</key>
+ <value>0</value>
+ </param>
+ </block>
+ <block>
+ <key>howto_square_ff</key>
+ <param>
+ <key>id</key>
+ <value>howto_square_ff_0</value>
+ </param>
+ <param>
+ <key>_enabled</key>
+ <value>True</value>
+ </param>
+ <param>
+ <key>_coordinate</key>
+ <value>(445, 168)</value>
+ </param>
+ <param>
+ <key>_rotation</key>
+ <value>0</value>
+ </param>
+ </block>
+ <block>
+ <key>qtgui_time_sink_x</key>
+ <param>
+ <key>id</key>
+ <value>qtgui_time_sink_x_0</value>
+ </param>
+ <param>
+ <key>_enabled</key>
+ <value>True</value>
+ </param>
+ <param>
+ <key>type</key>
+ <value>float</value>
+ </param>
+ <param>
+ <key>name</key>
+ <value>QT GUI Plot</value>
+ </param>
+ <param>
+ <key>size</key>
+ <value>1024</value>
+ </param>
+ <param>
+ <key>bw</key>
+ <value>samp_rate</value>
+ </param>
+ <param>
+ <key>nconnections</key>
+ <value>3</value>
+ </param>
+ <param>
+ <key>gui_hint</key>
+ <value></value>
+ </param>
+ <param>
+ <key>_coordinate</key>
+ <value>(608, 100)</value>
+ </param>
+ <param>
+ <key>_rotation</key>
+ <value>0</value>
+ </param>
+ </block>
+ <block>
+ <key>options</key>
+ <param>
+ <key>id</key>
+ <value>howto_square_qt</value>
+ </param>
+ <param>
+ <key>_enabled</key>
+ <value>True</value>
+ </param>
+ <param>
+ <key>title</key>
+ <value></value>
+ </param>
+ <param>
+ <key>author</key>
+ <value></value>
+ </param>
+ <param>
+ <key>description</key>
+ <value></value>
+ </param>
+ <param>
+ <key>window_size</key>
+ <value>1280, 1024</value>
+ </param>
+ <param>
+ <key>generate_options</key>
+ <value>qt_gui</value>
+ </param>
+ <param>
+ <key>category</key>
+ <value>Custom</value>
+ </param>
+ <param>
+ <key>run_options</key>
+ <value>prompt</value>
+ </param>
+ <param>
+ <key>run</key>
+ <value>True</value>
+ </param>
+ <param>
+ <key>max_nouts</key>
+ <value>0</value>
+ </param>
+ <param>
+ <key>realtime_scheduling</key>
+ <value></value>
+ </param>
+ <param>
+ <key>_coordinate</key>
+ <value>(10, 10)</value>
+ </param>
+ <param>
+ <key>_rotation</key>
+ <value>0</value>
+ </param>
+ </block>
+ <connection>
+ <source_block_id>howto_square2_ff_0</source_block_id>
+ <sink_block_id>qtgui_time_sink_x_0</sink_block_id>
+ <source_key>0</source_key>
+ <sink_key>0</sink_key>
+ </connection>
+ <connection>
+ <source_block_id>gr_throttle_0</source_block_id>
+ <sink_block_id>howto_square2_ff_0</sink_block_id>
+ <source_key>0</source_key>
+ <sink_key>0</sink_key>
+ </connection>
+ <connection>
+ <source_block_id>gr_throttle_0</source_block_id>
+ <sink_block_id>howto_square_ff_0</sink_block_id>
+ <source_key>0</source_key>
+ <sink_key>0</sink_key>
+ </connection>
+ <connection>
+ <source_block_id>gr_sig_source_x_0</source_block_id>
+ <sink_block_id>gr_throttle_0</sink_block_id>
+ <source_key>0</source_key>
+ <sink_key>0</sink_key>
+ </connection>
+ <connection>
+ <source_block_id>gr_throttle_0</source_block_id>
+ <sink_block_id>qtgui_time_sink_x_0</sink_block_id>
+ <source_key>0</source_key>
+ <sink_key>1</sink_key>
+ </connection>
+ <connection>
+ <source_block_id>howto_square_ff_0</source_block_id>
+ <sink_block_id>qtgui_time_sink_x_0</sink_block_id>
+ <source_key>0</source_key>
+ <sink_key>2</sink_key>
+ </connection>
+</flow_graph>
diff --git a/gr-howto-write-a-block/apps/howto_square_qt.py b/gr-howto-write-a-block/apps/howto_square_qt.py
new file mode 100755
index 0000000000..1a3e6874c4
--- /dev/null
+++ b/gr-howto-write-a-block/apps/howto_square_qt.py
@@ -0,0 +1,96 @@
+#!/usr/bin/env python
+##################################################
+# Gnuradio Python Flow Graph
+# Title: Howto Square Qt
+# Generated: Sun Sep 30 13:32:52 2012
+##################################################
+
+from PyQt4 import Qt
+from gnuradio import eng_notation
+from gnuradio import gr
+from gnuradio import qtgui
+from gnuradio.eng_option import eng_option
+from gnuradio.gr import firdes
+from optparse import OptionParser
+import howto
+import sip
+import sys
+
+class howto_square_qt(gr.top_block, Qt.QWidget):
+
+ def __init__(self):
+ gr.top_block.__init__(self, "Howto Square Qt")
+ Qt.QWidget.__init__(self)
+ self.setWindowTitle("Howto Square Qt")
+ self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc'))
+ self.top_scroll_layout = Qt.QVBoxLayout()
+ self.setLayout(self.top_scroll_layout)
+ self.top_scroll = Qt.QScrollArea()
+ self.top_scroll.setFrameStyle(Qt.QFrame.NoFrame)
+ self.top_scroll_layout.addWidget(self.top_scroll)
+ self.top_scroll.setWidgetResizable(True)
+ self.top_widget = Qt.QWidget()
+ self.top_scroll.setWidget(self.top_widget)
+ self.top_layout = Qt.QVBoxLayout(self.top_widget)
+ self.top_grid_layout = Qt.QGridLayout()
+ self.top_layout.addLayout(self.top_grid_layout)
+
+ self.settings = Qt.QSettings("GNU Radio", "howto_square_qt")
+ self.restoreGeometry(self.settings.value("geometry").toByteArray())
+
+
+ ##################################################
+ # Variables
+ ##################################################
+ self.samp_rate = samp_rate = 32000
+
+ ##################################################
+ # Blocks
+ ##################################################
+ self.qtgui_time_sink_x_0 = qtgui.time_sink_f(
+ 1024, #size
+ samp_rate, #bw
+ "QT GUI Plot", #name
+ 3 #number of inputs
+ )
+ self._qtgui_time_sink_x_0_win = sip.wrapinstance(self.qtgui_time_sink_x_0.pyqwidget(), Qt.QWidget)
+ self.top_layout.addWidget(self._qtgui_time_sink_x_0_win)
+ self.howto_square_ff_0 = howto.square_ff()
+ self.howto_square2_ff_0 = howto.square2_ff()
+ self.gr_throttle_0 = gr.throttle(gr.sizeof_float*1, samp_rate)
+ self.gr_sig_source_x_0 = gr.sig_source_f(samp_rate, gr.GR_COS_WAVE, 1000, 1, 0)
+
+ ##################################################
+ # Connections
+ ##################################################
+ self.connect((self.howto_square2_ff_0, 0), (self.qtgui_time_sink_x_0, 0))
+ self.connect((self.gr_throttle_0, 0), (self.howto_square2_ff_0, 0))
+ self.connect((self.gr_throttle_0, 0), (self.howto_square_ff_0, 0))
+ self.connect((self.gr_sig_source_x_0, 0), (self.gr_throttle_0, 0))
+ self.connect((self.gr_throttle_0, 0), (self.qtgui_time_sink_x_0, 1))
+ self.connect((self.howto_square_ff_0, 0), (self.qtgui_time_sink_x_0, 2))
+
+# QT sink close method reimplementation
+ def closeEvent(self, event):
+ self.settings = Qt.QSettings("GNU Radio", "howto_square_qt")
+ self.settings.setValue("geometry", self.saveGeometry())
+ event.accept()
+
+ def get_samp_rate(self):
+ return self.samp_rate
+
+ def set_samp_rate(self, samp_rate):
+ self.samp_rate = samp_rate
+ self.gr_sig_source_x_0.set_sampling_freq(self.samp_rate)
+
+if __name__ == '__main__':
+ parser = OptionParser(option_class=eng_option, usage="%prog: [options]")
+ (options, args) = parser.parse_args()
+ qapp = Qt.QApplication(sys.argv)
+ tb = howto_square_qt()
+ tb.start()
+ tb.show()
+ qapp.exec_()
+ tb.stop()
+ tb = None #to clean up Qt widgets
+
diff --git a/gr-howto-write-a-block/cmake/Modules/FindCppUnit.cmake b/gr-howto-write-a-block/cmake/Modules/FindCppUnit.cmake
new file mode 100644
index 0000000000..9af308f84b
--- /dev/null
+++ b/gr-howto-write-a-block/cmake/Modules/FindCppUnit.cmake
@@ -0,0 +1,36 @@
+# http://www.cmake.org/pipermail/cmake/2006-October/011446.html
+# Modified to use pkg config and use standard var names
+
+#
+# Find the CppUnit includes and library
+#
+# This module defines
+# CPPUNIT_INCLUDE_DIR, where to find tiff.h, etc.
+# CPPUNIT_LIBRARIES, the libraries to link against to use CppUnit.
+# CPPUNIT_FOUND, If false, do not try to use CppUnit.
+
+INCLUDE(FindPkgConfig)
+PKG_CHECK_MODULES(PC_CPPUNIT "cppunit")
+
+FIND_PATH(CPPUNIT_INCLUDE_DIRS
+ NAMES cppunit/TestCase.h
+ HINTS ${PC_CPPUNIT_INCLUDE_DIR}
+ PATHS
+ /usr/local/include
+ /usr/include
+)
+
+FIND_LIBRARY(CPPUNIT_LIBRARIES
+ NAMES cppunit
+ HINTS ${PC_CPPUNIT_LIBDIR}
+ PATHS
+ ${CPPUNIT_INCLUDE_DIRS}/../lib
+ /usr/local/lib
+ /usr/lib
+)
+
+LIST(APPEND CPPUNIT_LIBRARIES ${CMAKE_DL_LIBS})
+
+INCLUDE(FindPackageHandleStandardArgs)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(CPPUNIT DEFAULT_MSG CPPUNIT_LIBRARIES CPPUNIT_INCLUDE_DIRS)
+MARK_AS_ADVANCED(CPPUNIT_LIBRARIES CPPUNIT_INCLUDE_DIRS)
diff --git a/gr-howto-write-a-block/docs/README.howto b/gr-howto-write-a-block/docs/README.howto
new file mode 100644
index 0000000000..a0a6c0f19d
--- /dev/null
+++ b/gr-howto-write-a-block/docs/README.howto
@@ -0,0 +1,11 @@
+This is the howto-write-a-block package meant as a guide to building
+out-of-tree packages. To use the howto blocks, the Python namespaces
+is in 'howto', which is imported as:
+
+ import howto
+
+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:
+
+ help(howto)
diff --git a/gr-howto-write-a-block/include/CMakeLists.txt b/gr-howto-write-a-block/include/howto/CMakeLists.txt
index 475cc73c65..7cd6325543 100644
--- a/gr-howto-write-a-block/include/CMakeLists.txt
+++ b/gr-howto-write-a-block/include/howto/CMakeLists.txt
@@ -1,4 +1,4 @@
-# Copyright 2011 Free Software Foundation, Inc.
+# Copyright 2011,2012 Free Software Foundation, Inc.
#
# This file is part of GNU Radio
#
@@ -21,8 +21,8 @@
# Install public header files
########################################################################
install(FILES
- howto_api.h
- howto_square_ff.h
- howto_square2_ff.h
+ api.h
+ square_ff.h
+ square2_ff.h
DESTINATION include/howto
)
diff --git a/gr-howto-write-a-block/include/howto_api.h b/gr-howto-write-a-block/include/howto/api.h
index 5263a1cf70..5263a1cf70 100644
--- a/gr-howto-write-a-block/include/howto_api.h
+++ b/gr-howto-write-a-block/include/howto/api.h
diff --git a/gr-howto-write-a-block/include/howto/square2_ff.h b/gr-howto-write-a-block/include/howto/square2_ff.h
new file mode 100644
index 0000000000..2e22bb7997
--- /dev/null
+++ b/gr-howto-write-a-block/include/howto/square2_ff.h
@@ -0,0 +1,68 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004,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.
+ */
+
+#ifndef INCLUDED_HOWTO_SQUARE2_FF_H
+#define INCLUDED_HOWTO_SQUARE2_FF_H
+
+#include <howto/api.h>
+#include <gr_sync_block.h>
+
+namespace gr {
+ namespace howto {
+
+ /*!
+ * \brief square2 a stream of floats.
+ * \ingroup block
+ *
+ * This uses the preferred technique: subclassing gr_sync_block.
+ */
+ class HOWTO_API square2_ff : virtual public gr_sync_block
+ {
+ public:
+ /*
+ * We use boost::shared_ptr's instead of raw pointers for all
+ * access to gr_blocks (and many other data structures). The
+ * shared_ptr gets us transparent reference counting, which
+ * greatly simplifies storage management issues. This is
+ * especially helpful in our hybrid C++ / Python system.
+ *
+ * See http://www.boost.org/libs/smart_ptr/smart_ptr.htm
+ *
+ * gr::howto::square2_ff::sptr
+ */
+ typedef boost::shared_ptr<square2_ff> sptr;
+
+ /*!
+ * \brief Return a shared_ptr to a new instance of howto::square2_ff.
+ *
+ * To avoid accidental use of raw pointers, howto::square2_ff's
+ * constructor is in a private implementation
+ * class. howto::square2_ff::make is the public interface for
+ * creating new instances.
+ */
+ static sptr make();
+ };
+
+ } // namespace howto
+} // namespace gr
+
+#endif /* INCLUDED_HOWTO_SQUARE2_FF_H */
diff --git a/gr-howto-write-a-block/include/howto/square_ff.h b/gr-howto-write-a-block/include/howto/square_ff.h
new file mode 100644
index 0000000000..ce971afb6b
--- /dev/null
+++ b/gr-howto-write-a-block/include/howto/square_ff.h
@@ -0,0 +1,68 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004,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.
+ */
+
+#ifndef INCLUDED_HOWTO_SQUARE_FF_H
+#define INCLUDED_HOWTO_SQUARE_FF_H
+
+#include <howto/api.h>
+#include <gr_block.h>
+
+namespace gr {
+ namespace howto {
+
+ /*!
+ * \brief square a stream of floats.
+ * \ingroup block
+ *
+ * \sa howto_square2_ff for a version that subclasses gr_sync_block.
+ */
+ class HOWTO_API square_ff : virtual public gr_block
+ {
+ public:
+ /*
+ * We use boost::shared_ptr's instead of raw pointers for all
+ * access to gr_blocks (and many other data structures). The
+ * shared_ptr gets us transparent reference counting, which
+ * greatly simplifies storage management issues. This is
+ * especially helpful in our hybrid C++ / Python system.
+ *
+ * See http://www.boost.org/libs/smart_ptr/smart_ptr.htm
+ *
+ * gr::howto::square_ff::sptr
+ */
+ typedef boost::shared_ptr<square_ff> sptr;
+
+ /*!
+ * \brief Return a shared_ptr to a new instance of howto::square_ff.
+ *
+ * To avoid accidental use of raw pointers, howto::square_ff's
+ * constructor is in a private implementation
+ * class. howto::square_ff::make is the public interface for
+ * creating new instances.
+ */
+ static sptr make();
+ };
+
+ } // namespace howto
+} // namespace gr
+
+#endif /* INCLUDED_HOWTO_SQUARE_FF_H */
diff --git a/gr-howto-write-a-block/include/howto_square2_ff.h b/gr-howto-write-a-block/include/howto_square2_ff.h
deleted file mode 100644
index 2d6c7938bd..0000000000
--- a/gr-howto-write-a-block/include/howto_square2_ff.h
+++ /dev/null
@@ -1,78 +0,0 @@
-/* -*- c++ -*- */
-/*
- * Copyright 2004 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.
- */
-#ifndef INCLUDED_HOWTO_SQUARE2_FF_H
-#define INCLUDED_HOWTO_SQUARE2_FF_H
-
-#include <howto_api.h>
-#include <gr_sync_block.h>
-
-class howto_square2_ff;
-
-/*
- * We use boost::shared_ptr's instead of raw pointers for all access
- * to gr_blocks (and many other data structures). The shared_ptr gets
- * us transparent reference counting, which greatly simplifies storage
- * management issues. This is especially helpful in our hybrid
- * C++ / Python system.
- *
- * See http://www.boost.org/libs/smart_ptr/smart_ptr.htm
- *
- * As a convention, the _sptr suffix indicates a boost::shared_ptr
- */
-typedef boost::shared_ptr<howto_square2_ff> howto_square2_ff_sptr;
-
-/*!
- * \brief Return a shared_ptr to a new instance of howto_square2_ff.
- *
- * To avoid accidental use of raw pointers, howto_square2_ff's
- * constructor is private. howto_make_square2_ff is the public
- * interface for creating new instances.
- */
-HOWTO_API howto_square2_ff_sptr howto_make_square2_ff ();
-
-/*!
- * \brief square2 a stream of floats.
- * \ingroup block
- *
- * This uses the preferred technique: subclassing gr_sync_block.
- */
-class HOWTO_API howto_square2_ff : public gr_sync_block
-{
-private:
- // The friend declaration allows howto_make_square2_ff to
- // access the private constructor.
-
- friend HOWTO_API howto_square2_ff_sptr howto_make_square2_ff ();
-
- howto_square2_ff (); // private constructor
-
- public:
- ~howto_square2_ff (); // public destructor
-
- // Where all the action really happens
-
- int work (int noutput_items,
- gr_vector_const_void_star &input_items,
- gr_vector_void_star &output_items);
-};
-
-#endif /* INCLUDED_HOWTO_SQUARE2_FF_H */
diff --git a/gr-howto-write-a-block/include/howto_square_ff.h b/gr-howto-write-a-block/include/howto_square_ff.h
deleted file mode 100644
index 2efc7fc714..0000000000
--- a/gr-howto-write-a-block/include/howto_square_ff.h
+++ /dev/null
@@ -1,82 +0,0 @@
-/* -*- c++ -*- */
-/*
- * Copyright 2004 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.
- */
-#ifndef INCLUDED_HOWTO_SQUARE_FF_H
-#define INCLUDED_HOWTO_SQUARE_FF_H
-
-#include <howto_api.h>
-#include <gr_block.h>
-
-class howto_square_ff;
-
-/*
- * We use boost::shared_ptr's instead of raw pointers for all access
- * to gr_blocks (and many other data structures). The shared_ptr gets
- * us transparent reference counting, which greatly simplifies storage
- * management issues. This is especially helpful in our hybrid
- * C++ / Python system.
- *
- * See http://www.boost.org/libs/smart_ptr/smart_ptr.htm
- *
- * As a convention, the _sptr suffix indicates a boost::shared_ptr
- */
-typedef boost::shared_ptr<howto_square_ff> howto_square_ff_sptr;
-
-/*!
- * \brief Return a shared_ptr to a new instance of howto_square_ff.
- *
- * To avoid accidental use of raw pointers, howto_square_ff's
- * constructor is private. howto_make_square_ff is the public
- * interface for creating new instances.
- */
-HOWTO_API howto_square_ff_sptr howto_make_square_ff ();
-
-/*!
- * \brief square a stream of floats.
- * \ingroup block
- *
- * \sa howto_square2_ff for a version that subclasses gr_sync_block.
- */
-class HOWTO_API howto_square_ff : public gr_block
-{
-private:
- // The friend declaration allows howto_make_square_ff to
- // access the private constructor.
-
- friend HOWTO_API howto_square_ff_sptr howto_make_square_ff ();
-
- /*!
- * \brief square a stream of floats.
- */
- howto_square_ff (); // private constructor
-
- public:
- ~howto_square_ff (); // public destructor
-
- // Where all the action really happens
-
- int general_work (int noutput_items,
- gr_vector_int &ninput_items,
- gr_vector_const_void_star &input_items,
- gr_vector_void_star &output_items);
-};
-
-#endif /* INCLUDED_HOWTO_SQUARE_FF_H */
diff --git a/gr-howto-write-a-block/lib/CMakeLists.txt b/gr-howto-write-a-block/lib/CMakeLists.txt
index 835ae02d60..83b510e3f9 100644
--- a/gr-howto-write-a-block/lib/CMakeLists.txt
+++ b/gr-howto-write-a-block/lib/CMakeLists.txt
@@ -1,4 +1,4 @@
-# Copyright 2011 Free Software Foundation, Inc.
+# Copyright 2011,2012 Free Software Foundation, Inc.
#
# This file is part of GNU Radio
#
@@ -22,7 +22,7 @@
########################################################################
include(GrPlatform) #define LIB_SUFFIX
-add_library(gnuradio-howto SHARED howto_square_ff.cc howto_square2_ff.cc)
+add_library(gnuradio-howto SHARED square_ff_impl.cc square2_ff_impl.cc)
target_link_libraries(gnuradio-howto ${Boost_LIBRARIES} ${GRUEL_LIBRARIES} ${GNURADIO_CORE_LIBRARIES})
set_target_properties(gnuradio-howto PROPERTIES DEFINE_SYMBOL "gnuradio_howto_EXPORTS")
@@ -45,10 +45,10 @@ set(GR_TEST_TARGET_DEPS gnuradio-howto)
#turn each test cpp file into an executable with an int main() function
add_definitions(-DBOOST_TEST_DYN_LINK -DBOOST_TEST_MAIN)
-add_executable(qa_howto_square_ff qa_howto_square_ff.cc)
-target_link_libraries(qa_howto_square_ff gnuradio-howto ${Boost_LIBRARIES})
-GR_ADD_TEST(qa_howto_square_ff qa_howto_square_ff)
+add_executable(qa_square_ff qa_square_ff.cc)
+target_link_libraries(qa_square_ff gnuradio-howto ${Boost_LIBRARIES})
+GR_ADD_TEST(qa_square_ff qa_square_ff)
-add_executable(qa_howto_square2_ff qa_howto_square2_ff.cc)
-target_link_libraries(qa_howto_square2_ff gnuradio-howto ${Boost_LIBRARIES})
-GR_ADD_TEST(qa_howto_square2_ff qa_howto_square2_ff)
+add_executable(qa_square2_ff qa_square2_ff.cc)
+target_link_libraries(qa_square2_ff gnuradio-howto ${Boost_LIBRARIES})
+GR_ADD_TEST(qa_square2_ff qa_square2_ff)
diff --git a/gr-howto-write-a-block/lib/howto_square2_ff.cc b/gr-howto-write-a-block/lib/howto_square2_ff.cc
deleted file mode 100644
index 3586559ffa..0000000000
--- a/gr-howto-write-a-block/lib/howto_square2_ff.cc
+++ /dev/null
@@ -1,92 +0,0 @@
-/* -*- c++ -*- */
-/*
- * Copyright 2004,2010 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.
- */
-
-/*
- * config.h is generated by configure. It contains the results
- * of probing for features, options etc. It should be the first
- * file included in your .cc file.
- */
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include <howto_square2_ff.h>
-#include <gr_io_signature.h>
-
-/*
- * Create a new instance of howto_square2_ff and return
- * a boost shared_ptr. This is effectively the public constructor.
- */
-howto_square2_ff_sptr
-howto_make_square2_ff ()
-{
- return gnuradio::get_initial_sptr(new howto_square2_ff ());
-}
-
-/*
- * Specify constraints on number of input and output streams.
- * This info is used to construct the input and output signatures
- * (2nd & 3rd args to gr_block's constructor). The input and
- * output signatures are used by the runtime system to
- * check that a valid number and type of inputs and outputs
- * are connected to this block. In this case, we accept
- * only 1 input and 1 output.
- */
-static const int MIN_IN = 1; // mininum number of input streams
-static const int MAX_IN = 1; // maximum number of input streams
-static const int MIN_OUT = 1; // minimum number of output streams
-static const int MAX_OUT = 1; // maximum number of output streams
-
-/*
- * The private constructor
- */
-howto_square2_ff::howto_square2_ff ()
- : gr_sync_block ("square2_ff",
- gr_make_io_signature (MIN_IN, MAX_IN, sizeof (float)),
- gr_make_io_signature (MIN_OUT, MAX_OUT, sizeof (float)))
-{
- // nothing else required in this example
-}
-
-/*
- * Our virtual destructor.
- */
-howto_square2_ff::~howto_square2_ff ()
-{
- // nothing else required in this example
-}
-
-int
-howto_square2_ff::work (int noutput_items,
- gr_vector_const_void_star &input_items,
- gr_vector_void_star &output_items)
-{
- const float *in = (const float *) input_items[0];
- float *out = (float *) output_items[0];
-
- for (int i = 0; i < noutput_items; i++){
- out[i] = in[i] * in[i];
- }
-
- // Tell runtime system how many output items we produced.
- return noutput_items;
-}
diff --git a/gr-howto-write-a-block/lib/howto_square_ff.cc b/gr-howto-write-a-block/lib/howto_square_ff.cc
deleted file mode 100644
index f0d2e1f869..0000000000
--- a/gr-howto-write-a-block/lib/howto_square_ff.cc
+++ /dev/null
@@ -1,98 +0,0 @@
-/* -*- c++ -*- */
-/*
- * Copyright 2004,2010 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.
- */
-
-/*
- * config.h is generated by configure. It contains the results
- * of probing for features, options etc. It should be the first
- * file included in your .cc file.
- */
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include <howto_square_ff.h>
-#include <gr_io_signature.h>
-
-/*
- * Create a new instance of howto_square_ff and return
- * a boost shared_ptr. This is effectively the public constructor.
- */
-howto_square_ff_sptr
-howto_make_square_ff ()
-{
- return gnuradio::get_initial_sptr(new howto_square_ff ());
-}
-
-/*
- * Specify constraints on number of input and output streams.
- * This info is used to construct the input and output signatures
- * (2nd & 3rd args to gr_block's constructor). The input and
- * output signatures are used by the runtime system to
- * check that a valid number and type of inputs and outputs
- * are connected to this block. In this case, we accept
- * only 1 input and 1 output.
- */
-static const int MIN_IN = 1; // mininum number of input streams
-static const int MAX_IN = 1; // maximum number of input streams
-static const int MIN_OUT = 1; // minimum number of output streams
-static const int MAX_OUT = 1; // maximum number of output streams
-
-/*
- * The private constructor
- */
-howto_square_ff::howto_square_ff ()
- : gr_block ("square_ff",
- gr_make_io_signature (MIN_IN, MAX_IN, sizeof (float)),
- gr_make_io_signature (MIN_OUT, MAX_OUT, sizeof (float)))
-{
- // nothing else required in this example
-}
-
-/*
- * Our virtual destructor.
- */
-howto_square_ff::~howto_square_ff ()
-{
- // nothing else required in this example
-}
-
-int
-howto_square_ff::general_work (int noutput_items,
- gr_vector_int &ninput_items,
- gr_vector_const_void_star &input_items,
- gr_vector_void_star &output_items)
-{
- const float *in = (const float *) input_items[0];
- float *out = (float *) output_items[0];
-
- for (int i = 0; i < noutput_items; i++){
- out[i] = in[i] * in[i];
- }
-
- // Tell runtime system how many input items we consumed on
- // each input stream.
-
- consume_each (noutput_items);
-
- // Tell runtime system how many output items we produced.
- return noutput_items;
-}
diff --git a/gr-howto-write-a-block/lib/qa_howto_square_ff.cc b/gr-howto-write-a-block/lib/qa_square2_ff.cc
index 98f6cc587c..fac704a6d5 100644
--- a/gr-howto-write-a-block/lib/qa_howto_square_ff.cc
+++ b/gr-howto-write-a-block/lib/qa_square2_ff.cc
@@ -1,6 +1,6 @@
/* -*- c++ -*- */
/*
- * Copyright 2011 Free Software Foundation, Inc.
+ * Copyright 2011,2012 Free Software Foundation, Inc.
*
* This file is part of GNU Radio
*
@@ -21,12 +21,12 @@
#include <boost/test/unit_test.hpp>
-BOOST_AUTO_TEST_CASE(qa_howto_square_ff_t1){
+BOOST_AUTO_TEST_CASE(qa_square2_ff_t1){
BOOST_CHECK_EQUAL(2 + 2, 4);
// TODO BOOST_* test macros here
}
-BOOST_AUTO_TEST_CASE(qa_howto_square_ff_t2){
+BOOST_AUTO_TEST_CASE(qa_square2_ff_t2){
BOOST_CHECK_EQUAL(2 + 2, 4);
// TODO BOOST_* test macros here
}
diff --git a/gr-howto-write-a-block/lib/qa_howto_square2_ff.cc b/gr-howto-write-a-block/lib/qa_square_ff.cc
index ff1e5d5b0a..bf474e7155 100644
--- a/gr-howto-write-a-block/lib/qa_howto_square2_ff.cc
+++ b/gr-howto-write-a-block/lib/qa_square_ff.cc
@@ -1,6 +1,6 @@
/* -*- c++ -*- */
/*
- * Copyright 2011 Free Software Foundation, Inc.
+ * Copyright 2011,2012 Free Software Foundation, Inc.
*
* This file is part of GNU Radio
*
@@ -21,12 +21,12 @@
#include <boost/test/unit_test.hpp>
-BOOST_AUTO_TEST_CASE(qa_howto_square2_ff_t1){
+BOOST_AUTO_TEST_CASE(qa_square_ff_t1){
BOOST_CHECK_EQUAL(2 + 2, 4);
// TODO BOOST_* test macros here
}
-BOOST_AUTO_TEST_CASE(qa_howto_square2_ff_t2){
+BOOST_AUTO_TEST_CASE(qa_square_ff_t2){
BOOST_CHECK_EQUAL(2 + 2, 4);
// TODO BOOST_* test macros here
}
diff --git a/gr-howto-write-a-block/lib/square2_ff_impl.cc b/gr-howto-write-a-block/lib/square2_ff_impl.cc
new file mode 100644
index 0000000000..f508a6e05b
--- /dev/null
+++ b/gr-howto-write-a-block/lib/square2_ff_impl.cc
@@ -0,0 +1,98 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004,2010,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.
+ */
+
+/*
+ * config.h is generated by configure. It contains the results
+ * of probing for features, options etc. It should be the first
+ * file included in your .cc file.
+ */
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "square2_ff_impl.h"
+#include <gr_io_signature.h>
+
+namespace gr {
+ namespace howto {
+
+ /*
+ * Create a new instance of howto_square2_ff and return a boost
+ * shared_ptr. This is effectively the public constructor.
+ */
+ square2_ff::sptr
+ square2_ff::make()
+ {
+ return gnuradio::get_initial_sptr
+ (new square2_ff_impl());
+ }
+
+ /*
+ * Specify constraints on number of input and output streams.
+ * This info is used to construct the input and output signatures
+ * (2nd & 3rd args to gr_block's constructor). The input and
+ * output signatures are used by the runtime system to check that
+ * a valid number and type of inputs and outputs are connected to
+ * this block. In this case, we accept only 1 input and 1 output.
+ */
+ static const int MIN_IN = 1; // mininum number of input streams
+ static const int MAX_IN = 1; // maximum number of input streams
+ static const int MIN_OUT = 1; // minimum number of output streams
+ static const int MAX_OUT = 1; // maximum number of output streams
+
+ /*
+ * The private constructor
+ */
+ square2_ff_impl::square2_ff_impl()
+ : gr_sync_block("square2_ff",
+ gr_make_io_signature(MIN_IN, MAX_IN, sizeof(float)),
+ gr_make_io_signature(MIN_OUT, MAX_OUT, sizeof(float)))
+ {
+ // nothing else required in this example
+ }
+
+ /*
+ * Our virtual destructor.
+ */
+ square2_ff_impl::~square2_ff_impl()
+ {
+ // nothing else required in this example
+ }
+
+ int
+ square2_ff_impl::work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+ {
+ const float *in = (const float*)input_items[0];
+ float *out = (float*)output_items[0];
+
+ for(int i = 0; i < noutput_items; i++) {
+ out[i] = in[i] * in[i];
+ }
+
+ // Tell runtime system how many output items we produced.
+ return noutput_items;
+ }
+
+ } /* namespace howto */
+} /* namespace gr */
diff --git a/gr-howto-write-a-block/lib/square2_ff_impl.h b/gr-howto-write-a-block/lib/square2_ff_impl.h
new file mode 100644
index 0000000000..1f7ca7ab37
--- /dev/null
+++ b/gr-howto-write-a-block/lib/square2_ff_impl.h
@@ -0,0 +1,51 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004,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.
+ */
+
+#ifndef INCLUDED_HOWTO_SQUARE2_FF_IMPL_H
+#define INCLUDED_HOWTO_SQUARE2_FF_IMPL_H
+
+#include <howto/square2_ff.h>
+#include <gr_sync_block.h>
+
+namespace gr {
+ namespace howto {
+
+ class square2_ff_impl : public square2_ff
+ {
+ private:
+ // Nothing to declare in this block.
+
+ public:
+ square2_ff_impl(); // implementation constructor
+ ~square2_ff_impl(); // implementation destructor
+
+ // Where all the action really happens
+
+ int work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+ };
+
+ } // namespace howto
+} // namespace gr
+
+#endif /* INCLUDED_HOWTO_SQUARE2_FF_IMPL_H */
diff --git a/gr-howto-write-a-block/lib/square_ff_impl.cc b/gr-howto-write-a-block/lib/square_ff_impl.cc
new file mode 100644
index 0000000000..d49f72da1e
--- /dev/null
+++ b/gr-howto-write-a-block/lib/square_ff_impl.cc
@@ -0,0 +1,105 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004,2010,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.
+ */
+
+/*
+ * config.h is generated by configure. It contains the results
+ * of probing for features, options etc. It should be the first
+ * file included in your .cc file.
+ */
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "square_ff_impl.h"
+#include <gr_io_signature.h>
+
+namespace gr {
+ namespace howto {
+
+ /*
+ * Create a new instance of howto_square_ff and return a boost
+ * shared_ptr. This is effectively the public constructor.
+ */
+ square_ff::sptr
+ square_ff::make()
+ {
+ return gnuradio::get_initial_sptr
+ (new square_ff_impl());
+ }
+
+ /*
+ * Specify constraints on number of input and output streams.
+ * This info is used to construct the input and output signatures
+ * (2nd & 3rd args to gr_block's constructor). The input and
+ * output signatures are used by the runtime system to
+ * check that a valid number and type of inputs and outputs
+ * are connected to this block. In this case, we accept
+ * only 1 input and 1 output.
+ */
+ static const int MIN_IN = 1; // mininum number of input streams
+ static const int MAX_IN = 1; // maximum number of input streams
+ static const int MIN_OUT = 1; // minimum number of output streams
+ static const int MAX_OUT = 1; // maximum number of output streams
+
+ /*
+ * The private constructor
+ */
+ square_ff_impl::square_ff_impl()
+ : gr_block("square_ff",
+ gr_make_io_signature(MIN_IN, MAX_IN, sizeof(float)),
+ gr_make_io_signature(MIN_OUT, MAX_OUT, sizeof(float)))
+ {
+ // nothing else required in this example
+ }
+
+ /*
+ * Our virtual destructor.
+ */
+ square_ff_impl::~square_ff_impl()
+ {
+ // nothing else required in this example
+ }
+
+ int
+ square_ff_impl::general_work(int noutput_items,
+ gr_vector_int &ninput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+ {
+ const float *in = (const float*)input_items[0];
+ float *out = (float*)output_items[0];
+
+ for(int i = 0; i < noutput_items; i++) {
+ out[i] = in[i] * in[i];
+ }
+
+ // Tell runtime system how many input items we consumed on
+ // each input stream.
+
+ consume_each(noutput_items);
+
+ // Tell runtime system how many output items we produced.
+ return noutput_items;
+ }
+
+ } /* namespace howto */
+} /* namespace gr */
diff --git a/gr-howto-write-a-block/lib/square_ff_impl.h b/gr-howto-write-a-block/lib/square_ff_impl.h
new file mode 100644
index 0000000000..2f0963423a
--- /dev/null
+++ b/gr-howto-write-a-block/lib/square_ff_impl.h
@@ -0,0 +1,52 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004,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.
+ */
+
+#ifndef INCLUDED_HOWTO_SQUARE_FF_IMPL_H
+#define INCLUDED_HOWTO_SQUARE_FF_IMPL_H
+
+#include <howto/square_ff.h>
+#include <gr_block.h>
+
+namespace gr {
+ namespace howto {
+
+ class square_ff_impl : public square_ff
+ {
+ private:
+ // Nothing to declare in this block.
+
+ public:
+ square_ff_impl(); // implementation constructor
+ ~square_ff_impl(); // implementation destructor
+
+ // Where all the action really happens
+
+ int general_work(int noutput_items,
+ gr_vector_int &ninput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+ };
+
+ } // namespace howto
+} // namespace gr
+
+#endif /* INCLUDED_HOWTO_SQUARE_FF_IMPL_H */
diff --git a/gr-howto-write-a-block/python/qa_howto.py b/gr-howto-write-a-block/python/qa_howto.py
index 7321941d5e..b0f534987b 100755..100644
--- a/gr-howto-write-a-block/python/qa_howto.py
+++ b/gr-howto-write-a-block/python/qa_howto.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python
#
-# Copyright 2004,2007 Free Software Foundation, Inc.
+# Copyright 2004,2007,2012 Free Software Foundation, Inc.
#
# This file is part of GNU Radio
#
@@ -21,39 +21,39 @@
#
from gnuradio import gr, gr_unittest
-import howto_swig
+import howto_swig as howto
-class qa_howto (gr_unittest.TestCase):
+class qa_howto(gr_unittest.TestCase):
- def setUp (self):
- self.tb = gr.top_block ()
+ def setUp(self):
+ self.tb = gr.top_block()
- def tearDown (self):
+ def tearDown(self):
self.tb = None
- def test_001_square_ff (self):
+ def test_001_square_ff(self):
src_data = (-3, 4, -5.5, 2, 3)
expected_result = (9, 16, 30.25, 4, 9)
- src = gr.vector_source_f (src_data)
- sqr = howto_swig.square_ff ()
- dst = gr.vector_sink_f ()
- self.tb.connect (src, sqr)
- self.tb.connect (sqr, dst)
- self.tb.run ()
- result_data = dst.data ()
- self.assertFloatTuplesAlmostEqual (expected_result, result_data, 6)
+ src = gr.vector_source_f(src_data)
+ sqr = howto.square_ff()
+ dst = gr.vector_sink_f()
+ self.tb.connect(src, sqr)
+ self.tb.connect(sqr, dst)
+ self.tb.run()
+ result_data = dst.data()
+ self.assertFloatTuplesAlmostEqual(expected_result, result_data, 6)
- def test_002_square2_ff (self):
+ def test_002_square2_ff(self):
src_data = (-3, 4, -5.5, 2, 3)
expected_result = (9, 16, 30.25, 4, 9)
- src = gr.vector_source_f (src_data)
- sqr = howto_swig.square2_ff ()
- dst = gr.vector_sink_f ()
- self.tb.connect (src, sqr)
- self.tb.connect (sqr, dst)
- self.tb.run ()
- result_data = dst.data ()
- self.assertFloatTuplesAlmostEqual (expected_result, result_data, 6)
+ src = gr.vector_source_f(src_data)
+ sqr = howto.square2_ff()
+ dst = gr.vector_sink_f()
+ self.tb.connect(src, sqr)
+ self.tb.connect(sqr, dst)
+ self.tb.run()
+ result_data = dst.data()
+ self.assertFloatTuplesAlmostEqual(expected_result, result_data, 6)
if __name__ == '__main__':
- gr_unittest.main ()
+ gr_unittest.run(qa_howto, "qa_howto.xml")
diff --git a/gr-howto-write-a-block/swig/howto_swig.i b/gr-howto-write-a-block/swig/howto_swig.i
index dd662b5e52..162bc6a901 100644
--- a/gr-howto-write-a-block/swig/howto_swig.i
+++ b/gr-howto-write-a-block/swig/howto_swig.i
@@ -7,14 +7,13 @@
//load generated python docstrings
%include "howto_swig_doc.i"
-
%{
-#include "howto_square_ff.h"
-#include "howto_square2_ff.h"
+#include "howto/square_ff.h"
+#include "howto/square2_ff.h"
%}
-GR_SWIG_BLOCK_MAGIC(howto,square_ff);
-%include "howto_square_ff.h"
+%include "howto/square_ff.h"
+%include "howto/square2_ff.h"
-GR_SWIG_BLOCK_MAGIC(howto,square2_ff);
-%include "howto_square2_ff.h"
+GR_SWIG_BLOCK_MAGIC2(howto, square_ff);
+GR_SWIG_BLOCK_MAGIC2(howto, square2_ff);