diff options
-rw-r--r-- | include/gnuradio/block.hpp | 15 | ||||
-rw-r--r-- | include/gnuradio/gr_block.h | 10 | ||||
-rw-r--r-- | include/gnuradio/gr_hier_block2.h | 5 | ||||
-rw-r--r-- | include/gnuradio/gr_sync_block.h | 1 | ||||
-rw-r--r-- | include/gnuradio/hier_block.hpp | 2 | ||||
-rw-r--r-- | lib/CMakeLists.txt | 10 | ||||
-rw-r--r-- | lib/block.cpp | 52 | ||||
-rw-r--r-- | lib/block_handlers.cpp | 2 | ||||
-rw-r--r-- | lib/element.cpp | 24 | ||||
-rw-r--r-- | lib/element_impl.hpp | 10 | ||||
-rw-r--r-- | lib/gr_block.cpp | 14 | ||||
-rw-r--r-- | lib/gr_hier_block2.cpp | 32 | ||||
-rw-r--r-- | lib/gr_sync_block.cpp | 32 | ||||
-rw-r--r-- | lib/hier_block.cpp | 45 |
14 files changed, 234 insertions, 20 deletions
diff --git a/include/gnuradio/block.hpp b/include/gnuradio/block.hpp index 2bfc5b6..418657f 100644 --- a/include/gnuradio/block.hpp +++ b/include/gnuradio/block.hpp @@ -71,13 +71,6 @@ struct GR_RUNTIME_API Block : Element 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. - * \param automatic true to call consume and forecast automatically - */ - void set_auto_consume(const bool automatic); - /******************************************************************* * Basic routines from basic block ******************************************************************/ @@ -108,7 +101,13 @@ struct GR_RUNTIME_API Block : Element void produce(const size_t which_output, const size_t how_many_items); - void set_fixed_rate(bool fixed_rate); + /*! + * Enable fixed rate logic. + * When enabled, relative rate is assumed to be set, + * and forecast is automatically called. + * Also, consume will be called automatically. + */ + void set_fixed_rate(const bool fixed_rate); /*! * The relative rate can be thought of as interpolation/decimation. diff --git a/include/gnuradio/gr_block.h b/include/gnuradio/gr_block.h index cdb5d4a..7418e3d 100644 --- a/include/gnuradio/gr_block.h +++ b/include/gnuradio/gr_block.h @@ -66,10 +66,12 @@ struct GR_RUNTIME_API gr_block : gnuradio::Block * general_work must call consume or consume_each to indicate how many items * were consumed on each input stream. */ - virtual int general_work (int noutput_items, - gr_vector_int &ninput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) = 0; + virtual int general_work( + int noutput_items, + gr_vector_int &ninput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items + ) = 0; }; #endif /*INCLUDED_GNURADIO_GR_BLOCK_H*/ diff --git a/include/gnuradio/gr_hier_block2.h b/include/gnuradio/gr_hier_block2.h index ec57749..dd8fdae 100644 --- a/include/gnuradio/gr_hier_block2.h +++ b/include/gnuradio/gr_hier_block2.h @@ -32,7 +32,10 @@ struct GR_RUNTIME_API gr_hier_block2 : gnuradio::HierBlock gr_io_signature_sptr output_signature ); - const Element &self(void); + const Element &self(void) const + { + return *this; + } }; diff --git a/include/gnuradio/gr_sync_block.h b/include/gnuradio/gr_sync_block.h index 4bfd4e0..2cff2f1 100644 --- a/include/gnuradio/gr_sync_block.h +++ b/include/gnuradio/gr_sync_block.h @@ -42,6 +42,7 @@ struct GR_RUNTIME_API gr_sync_block : gr_block } void set_alignment(const size_t alignment); + bool is_unaligned(void); /*! diff --git a/include/gnuradio/hier_block.hpp b/include/gnuradio/hier_block.hpp index e129f29..1518af5 100644 --- a/include/gnuradio/hier_block.hpp +++ b/include/gnuradio/hier_block.hpp @@ -28,6 +28,8 @@ struct GR_RUNTIME_API HierBlock : Element { HierBlock(void); + HierBlock(const std::string &name); + void connect(const Element &elem); void disconnect(const Element &elem); diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 5d82b09..115b01d 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -4,10 +4,6 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}) -if(LINUX) - list(APPEND gnuradio_core_libs numa) -endif() - ######################################################################## # Append gnuradio-core library sources ######################################################################## @@ -16,11 +12,13 @@ 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}/block_handlers.cpp ${CMAKE_CURRENT_SOURCE_DIR}/hier_block.cpp ${CMAKE_CURRENT_SOURCE_DIR}/gr_block.cpp ${CMAKE_CURRENT_SOURCE_DIR}/gr_sync_block.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/gr_hier_block2.cpp ) ######################################################################## @@ -47,3 +45,7 @@ link_directories(${TSBE_LIBRARY_DIRS}) list(APPEND gnuradio_core_libs ${TSBE_LIBRARIES} ) + +if(LINUX) + list(APPEND gnuradio_core_libs numa) +endif() diff --git a/lib/block.cpp b/lib/block.cpp index 1581266..2d5b4af 100644 --- a/lib/block.cpp +++ b/lib/block.cpp @@ -35,6 +35,7 @@ Block::Block(const std::string &name) (*this)->unique_id = ++unique_id_pool; this->set_history(0); this->set_output_multiple(1); + this->set_fixed_rate(true); this->set_relative_rate(1.0); this->set_tag_propagation_policy(TPP_ALL_TO_ALL); @@ -44,7 +45,6 @@ Block::Block(const std::string &name) //TODO other callbacks (*this)->block = tsbe::Block(config); - } @@ -120,6 +120,29 @@ void Block::set_output_multiple(const size_t multiple, const size_t which_output vector_set((*this)->output_multiple_items, multiple, which_output); } +void Block::consume(const size_t which_input, const size_t how_many_items) +{ + (*this)->consume_items[which_input] = how_many_items; +} + +void Block::consume_each(const size_t how_many_items) +{ + for (size_t i = 0; i < (*this)->consume_items.size(); i++) + { + (*this)->consume_items[i] = how_many_items; + } +} + +void Block::produce(const size_t which_output, const size_t how_many_items) +{ + (*this)->produce_items[which_output] = how_many_items; +} + +void Block::set_fixed_rate(const bool fixed_rate) +{ + (*this)->enble_fixed_rate = fixed_rate; +} + void Block::set_relative_rate(double relative_rate) { (*this)->relative_rate = relative_rate; @@ -209,3 +232,30 @@ void Block::get_tags_in_range( } } } + +static int mylround(double x) +{ + return int(x + 0.5); +} + +void Block::forecast( + int noutput_items, + std::vector<size_t> &ninput_items_required +){ + for (size_t i = 0; i < ninput_items_required.size(); i++) + { + ninput_items_required[i] = + (*this)->input_history_items[i] + + mylround((noutput_items/(*this)->relative_rate)); + } +} + +bool Block::start(void) +{ + return true; +} + +bool Block::stop(void) +{ + return true; +} diff --git a/lib/block_handlers.cpp b/lib/block_handlers.cpp index 7e44ab3..fa9a950 100644 --- a/lib/block_handlers.cpp +++ b/lib/block_handlers.cpp @@ -60,6 +60,8 @@ void ElementImpl::topology_update(const tsbe::TaskInterface &task_iface) this->work_ninput_items.resize(num_inputs); this->input_items.resize(num_inputs); this->output_items.resize(num_outputs); + this->consume_items.resize(num_inputs); + this->produce_items.resize(num_outputs); //resize tags vector to match sizes this->input_tags.resize(num_inputs); diff --git a/lib/element.cpp b/lib/element.cpp new file mode 100644 index 0000000..3c97675 --- /dev/null +++ b/lib/element.cpp @@ -0,0 +1,24 @@ +// +// 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 <gnuradio/element.hpp> + +using namespace gnuradio; + +Element::Element(void) +{ + //NOP +} diff --git a/lib/element_impl.hpp b/lib/element_impl.hpp index d765f6b..4add1e8 100644 --- a/lib/element_impl.hpp +++ b/lib/element_impl.hpp @@ -18,6 +18,7 @@ #define INCLUDED_LIBGNURADIO_ELEMENT_IMPL_HPP #include <tsbe/block.hpp> +#include <tsbe/topology.hpp> #include <gnuradio/element.hpp> #include <gnuradio/block.hpp> #include <gr_types.h> @@ -51,6 +52,8 @@ struct ElementImpl gr_vector_int work_ninput_items; Block::InputItems input_items; Block::OutputItems output_items; + std::vector<size_t> produce_items; + std::vector<size_t> consume_items; //tag tracking std::vector<std::vector<Tag> > input_tags; @@ -59,10 +62,17 @@ struct ElementImpl Block::tag_propagation_policy_t tag_prop_policy; tsbe::Block block; + tsbe::Topology topology; + const tsbe::Element &get_elem(void) + { + if (block) return block; + return topology; + } void handle_port_msg(const size_t, const tsbe::Wax &); void topology_update(const tsbe::TaskInterface &); + bool enble_fixed_rate; double relative_rate; }; diff --git a/lib/gr_block.cpp b/lib/gr_block.cpp index d15d9fb..b5e00a0 100644 --- a/lib/gr_block.cpp +++ b/lib/gr_block.cpp @@ -29,7 +29,7 @@ gr_block::gr_block( ): gnuradio::Block(name) { - this->set_auto_consume(false); + this->set_fixed_rate(false); this->set_input_signature(input_signature); this->set_output_signature(output_signature); } @@ -59,3 +59,15 @@ gr_io_signature_sptr gr_block::output_signature(void) const { return (*this)->output_signature; } + +int gr_block::work( + const InputItems &input_items, + const OutputItems &output_items +){ + return this->general_work( + (output_items.empty())? input_items[0].size() : output_items[0].size(), + (*this)->work_ninput_items, + (*this)->work_input_items, + (*this)->work_output_items + ); +} diff --git a/lib/gr_hier_block2.cpp b/lib/gr_hier_block2.cpp new file mode 100644 index 0000000..3756b9f --- /dev/null +++ b/lib/gr_hier_block2.cpp @@ -0,0 +1,32 @@ +// +// 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_hier_block2.h> + +gr_hier_block2::gr_hier_block2(void) +{ + //NOP +} + +gr_hier_block2::gr_hier_block2( + const std::string &name, + gr_io_signature_sptr, + gr_io_signature_sptr +): + gnuradio::HierBlock(name) +{ + //NOP +} diff --git a/lib/gr_sync_block.cpp b/lib/gr_sync_block.cpp index 1863997..a6a9c2b 100644 --- a/lib/gr_sync_block.cpp +++ b/lib/gr_sync_block.cpp @@ -30,7 +30,17 @@ gr_sync_block::gr_sync_block( ): gr_block(name, input_signature, output_signature) { - this->set_auto_consume(true); + this->set_fixed_rate(true); +} + +void gr_sync_block::set_alignment(const size_t alignment) +{ + //TODO +} + +bool gr_sync_block::is_unaligned(void) +{ + //TODO } gr_sync_interpolator::gr_sync_interpolator(void) @@ -49,6 +59,16 @@ gr_sync_interpolator::gr_sync_interpolator( this->set_interpolation(interp_rate); } +size_t gr_sync_interpolator::interpolation(void) +{ + return size_t(1.0*this->relative_rate()); +} + +void gr_sync_interpolator::set_interpolation(const size_t interp) +{ + this->set_relative_rate(1.0*interp); +} + gr_sync_decimator::gr_sync_decimator(void) { //NOP @@ -64,3 +84,13 @@ gr_sync_decimator::gr_sync_decimator( { this->set_decimation(decim_rate); } + +size_t gr_sync_decimator::decimation(void) +{ + return size_t(1.0/this->relative_rate()); +} + +void gr_sync_decimator::set_decimation(const size_t decim) +{ + this->set_relative_rate(1.0/decim); +} diff --git a/lib/hier_block.cpp b/lib/hier_block.cpp index 5d5c891..e915a23 100644 --- a/lib/hier_block.cpp +++ b/lib/hier_block.cpp @@ -14,6 +14,7 @@ // 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/hier_block.hpp> using namespace gnuradio; @@ -22,3 +23,47 @@ HierBlock::HierBlock(void) { //NOP } + +HierBlock::HierBlock(const std::string &name) +{ + this->reset(new ElementImpl()); + (*this)->name = name; + tsbe::TopologyConfig config; + (*this)->topology = tsbe::Topology(config); +} + +void HierBlock::connect(const Element &elem) +{ + (*this)->topology.add_topology(elem->topology); +} + +void HierBlock::disconnect(const Element &elem) +{ + (*this)->topology.remove_topology(elem->topology); +} + +void HierBlock::connect( + const Element &src, + const size_t src_index, + const Element &sink, + const size_t sink_index +){ + const tsbe::Connection conn( + tsbe::Port(src->get_elem(), src_index), + tsbe::Port(sink->get_elem(), sink_index) + ); + (*this)->topology.connect(conn); +} + +void HierBlock::disconnect( + const Element &src, + const size_t src_index, + const Element &sink, + const size_t sink_index +){ + const tsbe::Connection conn( + tsbe::Port(src->get_elem(), src_index), + tsbe::Port(sink->get_elem(), sink_index) + ); + (*this)->topology.disconnect(conn); +} |