summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/gnuradio/block.hpp31
-rw-r--r--include/gnuradio/gr_block.h2
-rw-r--r--include/gnuradio/gr_sync_block.h13
-rw-r--r--include/gnuradio/gr_sync_decimator.h7
-rw-r--r--include/gnuradio/gr_sync_interpolator.h18
-rw-r--r--lib/CMakeLists.txt9
-rw-r--r--lib/block.cpp94
-rw-r--r--lib/element_impl.hpp54
-rw-r--r--lib/gr_block.cpp34
-rw-r--r--lib/gr_sync_block.cpp66
-rw-r--r--lib/hier_block.cpp (renamed from lib/element.cpp)9
11 files changed, 290 insertions, 47 deletions
diff --git a/include/gnuradio/block.hpp b/include/gnuradio/block.hpp
index 2ec2a59..87ebb33 100644
--- a/include/gnuradio/block.hpp
+++ b/include/gnuradio/block.hpp
@@ -22,6 +22,7 @@
#include <gnuradio/tags.hpp>
#include <gruel/pmt.h>
#include <vector>
+#include <string>
namespace gnuradio
{
@@ -68,6 +69,8 @@ struct GR_RUNTIME_API Block : Element
Block(void);
+ Block(const std::string &name);
+
/*!
* Set the block's work mode (how it produces and consumes, and the ratio).
* When automatic, consume is automatically called, and forecast handled.
@@ -83,19 +86,21 @@ struct GR_RUNTIME_API Block : Element
std::string name(void) const;
- unsigned history(void) const;
+ size_t history(const size_t which_input = 0) const;
+
+ void set_history(const size_t history, const size_t which_input = 0);
- void set_history(unsigned history);
+ void set_output_multiple(const size_t multiple, const size_t which_input = 0);
- void set_output_multiple(int multiple);
+ size_t output_multiple(const size_t which_input = 0) const;
- int output_multiple(void) const;
+ void consume(const size_t which_input, const size_t how_many_items);
- void consume(int which_input, int how_many_items);
+ void consume_each(const size_t how_many_items);
- void consume_each(int how_many_items);
+ void produce(const size_t which_output, const size_t how_many_items);
- void produce(int which_output, int how_many_items);
+ void set_fixed_rate(bool fixed_rate);
/*!
* The relative rate can be thought of as interpolation/decimation.
@@ -109,20 +114,20 @@ struct GR_RUNTIME_API Block : Element
* Tag related routines from basic block
******************************************************************/
- uint64_t nitems_read(unsigned int which_input);
+ uint64_t nitems_read(const size_t which_input);
- uint64_t nitems_written(unsigned int which_output);
+ uint64_t nitems_written(const size_t which_output);
tag_propagation_policy_t tag_propagation_policy(void);
void set_tag_propagation_policy(tag_propagation_policy_t p);
void add_item_tag(
- unsigned int which_output, const Tag &tag
+ const size_t which_output, const Tag &tag
);
void add_item_tag(
- unsigned int which_output,
+ const size_t which_output,
uint64_t abs_offset,
const pmt::pmt_t &key,
const pmt::pmt_t &value,
@@ -131,14 +136,14 @@ struct GR_RUNTIME_API Block : Element
void get_tags_in_range(
std::vector<Tag> &tags,
- unsigned int which_input,
+ const size_t which_input,
uint64_t abs_start,
uint64_t abs_end
);
void get_tags_in_range(
std::vector<Tag> &tags,
- unsigned int which_input,
+ const size_t which_input,
uint64_t abs_start,
uint64_t abs_end,
const pmt::pmt_t &key
diff --git a/include/gnuradio/gr_block.h b/include/gnuradio/gr_block.h
index ef27199..4c9b5c2 100644
--- a/include/gnuradio/gr_block.h
+++ b/include/gnuradio/gr_block.h
@@ -46,8 +46,6 @@ struct GR_RUNTIME_API gr_block : gnuradio::Block
gr_io_signature_sptr output_signature(void);
- void set_fixed_rate(bool fixed_rate);
-
//! implements work -> calls general work
int work(
const InputItems &input_items,
diff --git a/include/gnuradio/gr_sync_block.h b/include/gnuradio/gr_sync_block.h
index 335840e..4bfd4e0 100644
--- a/include/gnuradio/gr_sync_block.h
+++ b/include/gnuradio/gr_sync_block.h
@@ -32,11 +32,14 @@ struct GR_RUNTIME_API gr_sync_block : gr_block
);
//! implements work -> calls work
- int general_work (int noutput_items,
- gr_vector_int &ninput_items,
- gr_vector_const_void_star &input_items,
- gr_vector_void_star &output_items);
- void forecast (int noutput_items, gr_vector_int &ninput_items_required);
+ inline int general_work(
+ int noutput_items,
+ gr_vector_int &ninput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items
+ ){
+ return this->work(noutput_items, input_items, output_items);
+ }
void set_alignment(const size_t alignment);
bool is_unaligned(void);
diff --git a/include/gnuradio/gr_sync_decimator.h b/include/gnuradio/gr_sync_decimator.h
index 08983ce..33dd4d4 100644
--- a/include/gnuradio/gr_sync_decimator.h
+++ b/include/gnuradio/gr_sync_decimator.h
@@ -35,13 +35,6 @@ struct GR_RUNTIME_API gr_sync_decimator : gr_sync_block
size_t decimation(void);
void set_decimation(const size_t decim);
- //! implements work -> calls work
- int general_work (int noutput_items,
- gr_vector_int &ninput_items,
- gr_vector_const_void_star &input_items,
- gr_vector_void_star &output_items);
- void forecast (int noutput_items, gr_vector_int &ninput_items_required);
-
};
#endif /*INCLUDED_GNURADIO_GR_SYNC_DECIMATOR_H*/
diff --git a/include/gnuradio/gr_sync_interpolator.h b/include/gnuradio/gr_sync_interpolator.h
index 3cac3ed..ad5181e 100644
--- a/include/gnuradio/gr_sync_interpolator.h
+++ b/include/gnuradio/gr_sync_interpolator.h
@@ -35,24 +35,6 @@ struct GR_RUNTIME_API gr_sync_interpolator : gr_sync_block
size_t interpolation(void);
void set_interpolation(const size_t interp);
- //! implements work -> calls work
- int general_work (int noutput_items,
- gr_vector_int &ninput_items,
- gr_vector_const_void_star &input_items,
- gr_vector_void_star &output_items);
- void forecast (int noutput_items, gr_vector_int &ninput_items_required);
-
- /*!
- * \brief just like gr_block::general_work, only this arranges to call consume_each for you
- *
- * The user must override work to define the signal processing code
- */
- virtual int work(
- int noutput_items,
- gr_vector_const_void_star &input_items,
- gr_vector_void_star &output_items
- ) = 0;
-
};
#endif /*INCLUDED_GNURADIO_GR_SYNC_INTERPOLATOR_H*/
diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt
index d065b53..c4129ef 100644
--- a/lib/CMakeLists.txt
+++ b/lib/CMakeLists.txt
@@ -4,6 +4,10 @@
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
+if(LINUX)
+ list(APPEND gnuradio_core_libs numa)
+endif()
+
########################################################################
# Append gnuradio-core library sources
########################################################################
@@ -12,7 +16,10 @@ list(APPEND gnuradio_core_sources
${CMAKE_CURRENT_SOURCE_DIR}/gr_message.cc
${CMAKE_CURRENT_SOURCE_DIR}/gr_msg_queue.cc
${CMAKE_CURRENT_SOURCE_DIR}/gr_msg_handler.cc
- ${CMAKE_CURRENT_SOURCE_DIR}/element.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/block.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/hier_block.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/gr_block.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/gr_sync_block.cpp
)
########################################################################
diff --git a/lib/block.cpp b/lib/block.cpp
new file mode 100644
index 0000000..c120a97
--- /dev/null
+++ b/lib/block.cpp
@@ -0,0 +1,94 @@
+//
+// Copyright 2012 Josh Blum
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Lesser General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program 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 Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with io_sig program. If not, see <http://www.gnu.org/licenses/>.
+
+#include "element_impl.hpp"
+#include <gnuradio/block.hpp>
+#include <boost/detail/atomic_count.hpp>
+
+using namespace gnuradio;
+
+static boost::detail::atomic_count unique_id_pool(0);
+
+Block::Block(void)
+{
+ //NOP
+}
+
+Block::Block(const std::string &name)
+{
+ this->reset(new ElementImpl());
+ (*this)->name = name;
+ (*this)->unique_id = ++unique_id_pool; //not really thread safe but ok
+ (*this)->input_history_items.push_back(0);
+ (*this)->output_multiple_items.push_back(1);
+ this->set_relative_rate(1.0);
+}
+
+long Block::unique_id(void) const
+{
+ return (*this)->unique_id;
+}
+
+std::string Block::name(void) const
+{
+ return (*this)->name;
+}
+
+size_t Block::history(const size_t which_input) const
+{
+ if ((*this)->input_history_items.size() <= which_input)
+ {
+ return (*this)->input_history_items[0];
+ }
+ return (*this)->input_history_items[which_input];
+}
+
+void Block::set_history(const size_t history, const size_t which_input)
+{
+ if ((*this)->input_history_items.size() <= which_input)
+ {
+ (*this)->input_history_items.resize(which_input+1, history);
+ }
+ (*this)->input_history_items[which_input] = history;
+}
+
+size_t Block::output_multiple(const size_t which_input) const
+{
+ if ((*this)->output_multiple_items.size() <= which_input)
+ {
+ return (*this)->output_multiple_items[0];
+ }
+ return (*this)->output_multiple_items[which_input];
+}
+
+void Block::set_output_multiple(const size_t multiple, const size_t which_input)
+{
+ if ((*this)->output_multiple_items.size() <= which_input)
+ {
+ (*this)->output_multiple_items.resize(which_input+1, multiple);
+ }
+ (*this)->output_multiple_items[which_input] = multiple;
+}
+
+void Block::set_relative_rate(double relative_rate)
+{
+ (*this)->relative_rate = relative_rate;
+}
+
+double Block::relative_rate(void) const
+{
+ return (*this)->relative_rate;
+}
diff --git a/lib/element_impl.hpp b/lib/element_impl.hpp
new file mode 100644
index 0000000..cd718c8
--- /dev/null
+++ b/lib/element_impl.hpp
@@ -0,0 +1,54 @@
+//
+// Copyright 2012 Josh Blum
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Lesser General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program 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 Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with io_sig program. If not, see <http://www.gnu.org/licenses/>.
+
+#ifndef INCLUDED_LIBGNURADIO_ELEMENT_IMPL_HPP
+#define INCLUDED_LIBGNURADIO_ELEMENT_IMPL_HPP
+
+#include <tsbe/block.hpp>
+#include <gnuradio/element.hpp>
+#include <gnuradio/block.hpp>
+#include <gr_types.h>
+#include <vector>
+
+namespace gnuradio
+{
+
+struct ElementImpl
+{
+ //stuff for when its a block
+ std::string name;
+ long unique_id;
+
+ std::vector<size_t> input_items_sizes;
+ std::vector<size_t> output_items_sizes;
+ std::vector<size_t> input_history_items;
+ std::vector<size_t> output_multiple_items;
+
+ //work buffers
+ gr_vector_const_void_star work_input_items;
+ gr_vector_void_star work_output_items;
+ gr_vector_int work_ninput_items;
+ Block::InputItems input_items;
+ Block::OutputItems output_items;
+
+ tsbe::Block block;
+
+ double relative_rate;
+};
+
+} //namespace gnuradio
+
+#endif /*INCLUDED_LIBGNURADIO_ELEMENT_IMPL_HPP*/
diff --git a/lib/gr_block.cpp b/lib/gr_block.cpp
new file mode 100644
index 0000000..c0f9e16
--- /dev/null
+++ b/lib/gr_block.cpp
@@ -0,0 +1,34 @@
+//
+// Copyright 2012 Josh Blum
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Lesser General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program 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 Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with io_sig program. If not, see <http://www.gnu.org/licenses/>.
+
+#include <gr_block.h>
+
+gr_block::gr_block(void)
+{
+ //NOP
+}
+
+gr_block::gr_block(
+ const std::string &name,
+ gr_io_signature_sptr input_signature,
+ gr_io_signature_sptr output_signature
+):
+ gnuradio::Block(name)
+{
+ this->set_auto_consume(false);
+ this->set_input_signature(input_signature);
+ this->set_output_signature(output_signature);
+}
diff --git a/lib/gr_sync_block.cpp b/lib/gr_sync_block.cpp
new file mode 100644
index 0000000..1863997
--- /dev/null
+++ b/lib/gr_sync_block.cpp
@@ -0,0 +1,66 @@
+//
+// Copyright 2012 Josh Blum
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Lesser General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program 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 Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with io_sig program. If not, see <http://www.gnu.org/licenses/>.
+
+#include <gr_sync_block.h>
+#include <gr_sync_interpolator.h>
+#include <gr_sync_decimator.h>
+
+gr_sync_block::gr_sync_block(void)
+{
+ //NOP
+}
+
+gr_sync_block::gr_sync_block(
+ const std::string &name,
+ gr_io_signature_sptr input_signature,
+ gr_io_signature_sptr output_signature
+):
+ gr_block(name, input_signature, output_signature)
+{
+ this->set_auto_consume(true);
+}
+
+gr_sync_interpolator::gr_sync_interpolator(void)
+{
+ //NOP
+}
+
+gr_sync_interpolator::gr_sync_interpolator(
+ const std::string &name,
+ gr_io_signature_sptr input_signature,
+ gr_io_signature_sptr output_signature,
+ const size_t interp_rate
+):
+ gr_sync_block(name, input_signature, output_signature)
+{
+ this->set_interpolation(interp_rate);
+}
+
+gr_sync_decimator::gr_sync_decimator(void)
+{
+ //NOP
+}
+
+gr_sync_decimator::gr_sync_decimator(
+ const std::string &name,
+ gr_io_signature_sptr input_signature,
+ gr_io_signature_sptr output_signature,
+ const size_t decim_rate
+):
+ gr_sync_block(name, input_signature, output_signature)
+{
+ this->set_decimation(decim_rate);
+}
diff --git a/lib/element.cpp b/lib/hier_block.cpp
index 705cbf2..5d5c891 100644
--- a/lib/element.cpp
+++ b/lib/hier_block.cpp
@@ -14,4 +14,11 @@
// You should have received a copy of the GNU Lesser General Public License
// along with io_sig program. If not, see <http://www.gnu.org/licenses/>.
-#include <gnuradio/element.hpp>
+#include <gnuradio/hier_block.hpp>
+
+using namespace gnuradio;
+
+HierBlock::HierBlock(void)
+{
+ //NOP
+}