From 30ea41c48215af4c50049aefb4ff0e59f14decfe Mon Sep 17 00:00:00 2001 From: Josh Blum <josh@joshknows.com> Date: Tue, 17 Apr 2012 22:14:05 -0700 Subject: this is squashed python blocks support --- gnuradio-core/src/lib/general/CMakeLists.txt | 1 + gnuradio-core/src/lib/general/general.i | 3 +- gnuradio-core/src/lib/general/gr_block_gateway.cc | 184 +++++++++++++++++++ gnuradio-core/src/lib/general/gr_block_gateway.h | 212 ++++++++++++++++++++++ gnuradio-core/src/lib/general/gr_block_gateway.i | 46 +++++ 5 files changed, 445 insertions(+), 1 deletion(-) create mode 100644 gnuradio-core/src/lib/general/gr_block_gateway.cc create mode 100644 gnuradio-core/src/lib/general/gr_block_gateway.h create mode 100644 gnuradio-core/src/lib/general/gr_block_gateway.i (limited to 'gnuradio-core/src/lib') diff --git a/gnuradio-core/src/lib/general/CMakeLists.txt b/gnuradio-core/src/lib/general/CMakeLists.txt index 207d85c4c4..038ac25078 100644 --- a/gnuradio-core/src/lib/general/CMakeLists.txt +++ b/gnuradio-core/src/lib/general/CMakeLists.txt @@ -186,6 +186,7 @@ set(gr_core_general_triple_threats gr_agc2_ff gr_align_on_samplenumbers_ss gr_bin_statistics_f + gr_block_gateway gr_bytes_to_syms gr_char_to_float gr_char_to_short diff --git a/gnuradio-core/src/lib/general/general.i b/gnuradio-core/src/lib/general/general.i index cd8c279c92..7e4e47d326 100644 --- a/gnuradio-core/src/lib/general/general.i +++ b/gnuradio-core/src/lib/general/general.i @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2004,2005,2006,2007,2008,2009,2010 Free Software Foundation, Inc. + * Copyright 2004-2012 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -254,3 +254,4 @@ %include "gr_cpm.i" %include "gr_correlate_access_code_tag_bb.i" %include "gr_add_ff.i" +%include "gr_block_gateway.i" diff --git a/gnuradio-core/src/lib/general/gr_block_gateway.cc b/gnuradio-core/src/lib/general/gr_block_gateway.cc new file mode 100644 index 0000000000..79b42803af --- /dev/null +++ b/gnuradio-core/src/lib/general/gr_block_gateway.cc @@ -0,0 +1,184 @@ +/* + * Copyright 2011-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 <gr_block_gateway.h> +#include <gr_io_signature.h> +#include <iostream> +#include <boost/bind.hpp> + +/*********************************************************************** + * Helper routines + **********************************************************************/ +template <typename OutType, typename InType> +void copy_pointers(OutType &out, const InType &in){ + out.resize(in.size()); + for (size_t i = 0; i < in.size(); i++){ + out[i] = (void *)(in[i]); + } +} + +/*********************************************************************** + * The gr_block gateway implementation class + **********************************************************************/ +class gr_block_gateway_impl : public gr_block_gateway{ +public: + gr_block_gateway_impl( + gr_feval_ll *handler, + const std::string &name, + gr_io_signature_sptr in_sig, + gr_io_signature_sptr out_sig, + const gr_block_gw_work_type work_type, + const unsigned factor + ): + gr_block(name, in_sig, out_sig), + _handler(handler), + _work_type(work_type) + { + switch(_work_type){ + case GR_BLOCK_GW_WORK_GENERAL: + _decim = 1; //not relevant, but set anyway + _interp = 1; //not relevant, but set anyway + break; + + case GR_BLOCK_GW_WORK_SYNC: + _decim = 1; + _interp = 1; + this->set_fixed_rate(true); + break; + + case GR_BLOCK_GW_WORK_DECIM: + _decim = factor; + _interp = 1; + break; + + case GR_BLOCK_GW_WORK_INTERP: + _decim = 1; + _interp = factor; + this->set_output_multiple(_interp); + break; + } + } + + /******************************************************************* + * Overloads for various scheduler-called functions + ******************************************************************/ + void forecast( + int noutput_items, + gr_vector_int &ninput_items_required + ){ + switch(_work_type){ + case GR_BLOCK_GW_WORK_GENERAL: + _message.action = gr_block_gw_message_type::ACTION_FORECAST; + _message.forecast_args_noutput_items = noutput_items; + _message.forecast_args_ninput_items_required = ninput_items_required; + _handler->calleval(0); + ninput_items_required = _message.forecast_args_ninput_items_required; + return; + + default: + unsigned ninputs = ninput_items_required.size(); + for (unsigned i = 0; i < ninputs; i++) + ninput_items_required[i] = fixed_rate_noutput_to_ninput(noutput_items); + return; + } + } + + int general_work( + int noutput_items, + gr_vector_int &ninput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items + ){ + switch(_work_type){ + case GR_BLOCK_GW_WORK_GENERAL: + _message.action = gr_block_gw_message_type::ACTION_GENERAL_WORK; + _message.general_work_args_noutput_items = noutput_items; + _message.general_work_args_ninput_items = ninput_items; + copy_pointers(_message.general_work_args_input_items, input_items); + _message.general_work_args_output_items = output_items; + _handler->calleval(0); + return _message.general_work_args_return_value; + + default: + int r = work (noutput_items, input_items, output_items); + if (r > 0) consume_each(r*_decim/_interp); + return r; + } + } + + int work( + int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items + ){ + _message.action = gr_block_gw_message_type::ACTION_WORK; + _message.work_args_ninput_items = fixed_rate_noutput_to_ninput(noutput_items); + if (_message.work_args_ninput_items == 0) return -1; + _message.work_args_noutput_items = noutput_items; + copy_pointers(_message.work_args_input_items, input_items); + _message.work_args_output_items = output_items; + _handler->calleval(0); + return _message.work_args_return_value; + } + + int fixed_rate_noutput_to_ninput(int noutput_items){ + return (noutput_items*_decim/_interp) + history() - 1; + } + + int fixed_rate_ninput_to_noutput(int ninput_items){ + return std::max(0, ninput_items - (int)history() + 1)*_interp/_decim; + } + + bool start(void){ + _message.action = gr_block_gw_message_type::ACTION_START; + _handler->calleval(0); + return _message.start_args_return_value; + } + + bool stop(void){ + _message.action = gr_block_gw_message_type::ACTION_STOP; + _handler->calleval(0); + return _message.stop_args_return_value; + } + + gr_block_gw_message_type &gr_block_message(void){ + return _message; + } + +private: + gr_feval_ll *_handler; + gr_block_gw_message_type _message; + const gr_block_gw_work_type _work_type; + unsigned _decim, _interp; +}; + +boost::shared_ptr<gr_block_gateway> gr_make_block_gateway( + gr_feval_ll *handler, + const std::string &name, + gr_io_signature_sptr in_sig, + gr_io_signature_sptr out_sig, + const gr_block_gw_work_type work_type, + const unsigned factor +){ + return boost::shared_ptr<gr_block_gateway>( + new gr_block_gateway_impl(handler, name, in_sig, out_sig, work_type, factor) + ); +} diff --git a/gnuradio-core/src/lib/general/gr_block_gateway.h b/gnuradio-core/src/lib/general/gr_block_gateway.h new file mode 100644 index 0000000000..ae91d41b59 --- /dev/null +++ b/gnuradio-core/src/lib/general/gr_block_gateway.h @@ -0,0 +1,212 @@ +/* + * Copyright 2011-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_GRBLOCK_GATEWAY_H +#define INCLUDED_GRBLOCK_GATEWAY_H + +#include <gr_core_api.h> +#include <gr_block.h> +#include <gr_feval.h> + +/*! + * The work type enum tells the gateway what kind of block to implement. + * The choices are familiar gnuradio block overloads (sync, decim, interp). + */ +enum gr_block_gw_work_type{ + GR_BLOCK_GW_WORK_GENERAL, + GR_BLOCK_GW_WORK_SYNC, + GR_BLOCK_GW_WORK_DECIM, + GR_BLOCK_GW_WORK_INTERP, +}; + +/*! + * Shared message structure between python and gateway. + * Each action type represents a scheduler-called function. + */ +struct gr_block_gw_message_type{ + enum action_type{ + ACTION_GENERAL_WORK, //dispatch work + ACTION_WORK, //dispatch work + ACTION_FORECAST, //dispatch forecast + ACTION_START, //dispatch start + ACTION_STOP, //dispatch stop + }; + + action_type action; + + int general_work_args_noutput_items; + std::vector<int> general_work_args_ninput_items; + std::vector<void *> general_work_args_input_items; //TODO this should be const void*, but swig cant int cast it right + std::vector<void *> general_work_args_output_items; + int general_work_args_return_value; + + int work_args_ninput_items; + int work_args_noutput_items; + std::vector<void *> work_args_input_items; //TODO this should be const void*, but swig cant int cast it right + std::vector<void *> work_args_output_items; + int work_args_return_value; + + int forecast_args_noutput_items; + std::vector<int> forecast_args_ninput_items_required; + + bool start_args_return_value; + + bool stop_args_return_value; +}; + +/*! + * The gateway block which performs all the magic. + * + * The gateway provides access to all the gr_block routines. + * The methods prefixed with gr_block__ are renamed + * to class methods without the prefix in python. + */ +class GR_CORE_API gr_block_gateway : virtual public gr_block{ +public: + //! Provide access to the shared message object + virtual gr_block_gw_message_type &gr_block_message(void) = 0; + + long gr_block__unique_id(void) const{ + return gr_block::unique_id(); + } + + std::string gr_block__name(void) const{ + return gr_block::name(); + } + + unsigned gr_block__history(void) const{ + return gr_block::history(); + } + + void gr_block__set_history(unsigned history){ + return gr_block::set_history(history); + } + + void gr_block__set_fixed_rate(bool fixed_rate){ + return gr_block::set_fixed_rate(fixed_rate); + } + + bool gr_block__fixed_rate(void) const{ + return gr_block::fixed_rate(); + } + + void gr_block__set_output_multiple(int multiple){ + return gr_block::set_output_multiple(multiple); + } + + int gr_block__output_multiple(void) const{ + return gr_block::output_multiple(); + } + + void gr_block__consume(int which_input, int how_many_items){ + return gr_block::consume(which_input, how_many_items); + } + + void gr_block__consume_each(int how_many_items){ + return gr_block::consume_each(how_many_items); + } + + void gr_block__produce(int which_output, int how_many_items){ + return gr_block::produce(which_output, how_many_items); + } + + void gr_block__set_relative_rate(double relative_rate){ + return gr_block::set_relative_rate(relative_rate); + } + + double gr_block__relative_rate(void) const{ + return gr_block::relative_rate(); + } + + uint64_t gr_block__nitems_read(unsigned int which_input){ + return gr_block::nitems_read(which_input); + } + + uint64_t gr_block__nitems_written(unsigned int which_output){ + return gr_block::nitems_written(which_output); + } + + gr_block::tag_propagation_policy_t gr_block__tag_propagation_policy(void){ + return gr_block::tag_propagation_policy(); + } + + void gr_block__set_tag_propagation_policy(gr_block::tag_propagation_policy_t p){ + return gr_block::set_tag_propagation_policy(p); + } + + void gr_block__add_item_tag( + unsigned int which_output, const gr_tag_t &tag + ){ + return gr_block::add_item_tag(which_output, tag); + } + + void gr_block__add_item_tag( + unsigned int which_output, + uint64_t abs_offset, + const pmt::pmt_t &key, + const pmt::pmt_t &value, + const pmt::pmt_t &srcid=pmt::PMT_F + ){ + return gr_block::add_item_tag(which_output, abs_offset, key, value, srcid); + } + + std::vector<gr_tag_t> gr_block__get_tags_in_range( + unsigned int which_input, + uint64_t abs_start, + uint64_t abs_end + ){ + std::vector<gr_tag_t> tags; + gr_block::get_tags_in_range(tags, which_input, abs_start, abs_end); + return tags; + } + + std::vector<gr_tag_t> gr_block__get_tags_in_range( + unsigned int which_input, + uint64_t abs_start, + uint64_t abs_end, + const pmt::pmt_t &key + ){ + std::vector<gr_tag_t> tags; + gr_block::get_tags_in_range(tags, which_input, abs_start, abs_end, key); + return tags; + } +}; + +/*! + * Make a new gateway block. + * \param handler the swig director object with callback + * \param name the name of the block (Ex: "Shirley") + * \param in_sig the input signature for this block + * \param out_sig the output signature for this block + * \param work_type the type of block overload to implement + * \param factor the decimation or interpolation factor + * \return a new gateway block + */ +GR_CORE_API boost::shared_ptr<gr_block_gateway> gr_make_block_gateway( + gr_feval_ll *handler, + const std::string &name, + gr_io_signature_sptr in_sig, + gr_io_signature_sptr out_sig, + const gr_block_gw_work_type work_type, + const unsigned factor +); + +#endif /* INCLUDED_GRBLOCK_GATEWAY_H */ diff --git a/gnuradio-core/src/lib/general/gr_block_gateway.i b/gnuradio-core/src/lib/general/gr_block_gateway.i new file mode 100644 index 0000000000..8adafdfea3 --- /dev/null +++ b/gnuradio-core/src/lib/general/gr_block_gateway.i @@ -0,0 +1,46 @@ +/* + * Copyright 2011-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. + */ + +//////////////////////////////////////////////////////////////////////// +// standard includes +//////////////////////////////////////////////////////////////////////// +%include <gnuradio.i> +%include <gr_tags.i> +%include <gr_feval.i> + +//////////////////////////////////////////////////////////////////////// +// block headers +//////////////////////////////////////////////////////////////////////// +%{ +#include <gr_block_gateway.h> +%} + +//////////////////////////////////////////////////////////////////////// +// data type support +//////////////////////////////////////////////////////////////////////// +%template(int_vector_t) std::vector<int>; +%template(void_star_vector_t) std::vector<void *>; + +//////////////////////////////////////////////////////////////////////// +// block magic +//////////////////////////////////////////////////////////////////////// +GR_SWIG_BLOCK_MAGIC(gr,block_gateway); +%include <gr_block_gateway.h> -- cgit v1.2.3 From 8e8335e2e4f20e3015956b30f05013913cb3fc54 Mon Sep 17 00:00:00 2001 From: Johnathan Corgan <jcorgan@corganenterprises.com> Date: Sat, 21 Apr 2012 09:05:56 -0700 Subject: core: add SWIG macro for namespaced blocks --- gnuradio-core/src/lib/swig/gnuradio.i | 3 +++ gnuradio-core/src/lib/swig/gr_swig_block_magic.i | 10 +++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) (limited to 'gnuradio-core/src/lib') diff --git a/gnuradio-core/src/lib/swig/gnuradio.i b/gnuradio-core/src/lib/swig/gnuradio.i index 2392238512..3a421ad5d6 100644 --- a/gnuradio-core/src/lib/swig/gnuradio.i +++ b/gnuradio-core/src/lib/swig/gnuradio.i @@ -20,6 +20,9 @@ * Boston, MA 02110-1301, USA. */ +// Disable warning about base class types +#pragma SWIG nowarn=401 + //////////////////////////////////////////////////////////////////////// // gnuradio.i // SWIG interface definition diff --git a/gnuradio-core/src/lib/swig/gr_swig_block_magic.i b/gnuradio-core/src/lib/swig/gr_swig_block_magic.i index cdc9fbe494..4016ae7727 100644 --- a/gnuradio-core/src/lib/swig/gr_swig_block_magic.i +++ b/gnuradio-core/src/lib/swig/gr_swig_block_magic.i @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2004,2010 Free Software Foundation, Inc. + * Copyright 2004,2010,2012 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -40,3 +40,11 @@ FULL_NAME ## _sptr.__repr__ = lambda self: "<gr_block %s (%d)>" % (self.name(), %} %enddef #endif + +%define GR_SWIG_BLOCK_MAGIC2(PKG, BASE_NAME) +%template(BASE_NAME ## _sptr) boost::shared_ptr<gr:: ## PKG ## :: ## BASE_NAME>; +%pythoncode %{ +BASE_NAME ## _sptr.__repr__ = lambda self: "<gr_block %s (%d)>" % (self.name(), self.unique_id()) +BASE_NAME = BASE_NAME.make; +%} +%enddef -- cgit v1.2.3 From 05b2c02f17d790df4896fcfb85c4020748f25747 Mon Sep 17 00:00:00 2001 From: Tom Rondeau <trondeau@vt.edu> Date: Thu, 3 May 2012 12:36:00 -0400 Subject: pfb: properly deleting d_fft to close some memory leaks. --- gnuradio-core/src/lib/filter/gr_pfb_channelizer_ccf.cc | 1 + gnuradio-core/src/lib/filter/gr_pfb_decimator_ccf.cc | 1 + gnuradio-core/src/lib/filter/gr_pfb_synthesizer_ccf.cc | 1 + 3 files changed, 3 insertions(+) (limited to 'gnuradio-core/src/lib') diff --git a/gnuradio-core/src/lib/filter/gr_pfb_channelizer_ccf.cc b/gnuradio-core/src/lib/filter/gr_pfb_channelizer_ccf.cc index cb7c939626..a8cb849e27 100644 --- a/gnuradio-core/src/lib/filter/gr_pfb_channelizer_ccf.cc +++ b/gnuradio-core/src/lib/filter/gr_pfb_channelizer_ccf.cc @@ -96,6 +96,7 @@ gr_pfb_channelizer_ccf::gr_pfb_channelizer_ccf (unsigned int numchans, gr_pfb_channelizer_ccf::~gr_pfb_channelizer_ccf () { + delete d_fft; delete [] d_idxlut; for(unsigned int i = 0; i < d_numchans; i++) { diff --git a/gnuradio-core/src/lib/filter/gr_pfb_decimator_ccf.cc b/gnuradio-core/src/lib/filter/gr_pfb_decimator_ccf.cc index c973daf829..e563daa513 100644 --- a/gnuradio-core/src/lib/filter/gr_pfb_decimator_ccf.cc +++ b/gnuradio-core/src/lib/filter/gr_pfb_decimator_ccf.cc @@ -69,6 +69,7 @@ gr_pfb_decimator_ccf::gr_pfb_decimator_ccf (unsigned int decim, gr_pfb_decimator_ccf::~gr_pfb_decimator_ccf () { + delete d_fft; for(unsigned int i = 0; i < d_rate; i++) { delete d_filters[i]; } diff --git a/gnuradio-core/src/lib/filter/gr_pfb_synthesizer_ccf.cc b/gnuradio-core/src/lib/filter/gr_pfb_synthesizer_ccf.cc index 9910a18510..cd01aaff5c 100644 --- a/gnuradio-core/src/lib/filter/gr_pfb_synthesizer_ccf.cc +++ b/gnuradio-core/src/lib/filter/gr_pfb_synthesizer_ccf.cc @@ -74,6 +74,7 @@ gr_pfb_synthesizer_ccf::gr_pfb_synthesizer_ccf gr_pfb_synthesizer_ccf::~gr_pfb_synthesizer_ccf () { + delete d_fft; for(unsigned int i = 0; i < d_twox*d_numchans; i++) { delete d_filters[i]; } -- cgit v1.2.3 From 3d8074ac37024c1d64f69a6539d07164e966c673 Mon Sep 17 00:00:00 2001 From: Tom Rondeau <trondeau@vt.edu> Date: Thu, 3 May 2012 12:36:00 -0400 Subject: pfb: properly deleting d_fft to close some memory leaks. --- gnuradio-core/src/lib/filter/gr_pfb_channelizer_ccf.cc | 1 + gnuradio-core/src/lib/filter/gr_pfb_decimator_ccf.cc | 1 + gnuradio-core/src/lib/filter/gr_pfb_synthesizer_ccf.cc | 1 + 3 files changed, 3 insertions(+) (limited to 'gnuradio-core/src/lib') diff --git a/gnuradio-core/src/lib/filter/gr_pfb_channelizer_ccf.cc b/gnuradio-core/src/lib/filter/gr_pfb_channelizer_ccf.cc index cb7c939626..a8cb849e27 100644 --- a/gnuradio-core/src/lib/filter/gr_pfb_channelizer_ccf.cc +++ b/gnuradio-core/src/lib/filter/gr_pfb_channelizer_ccf.cc @@ -96,6 +96,7 @@ gr_pfb_channelizer_ccf::gr_pfb_channelizer_ccf (unsigned int numchans, gr_pfb_channelizer_ccf::~gr_pfb_channelizer_ccf () { + delete d_fft; delete [] d_idxlut; for(unsigned int i = 0; i < d_numchans; i++) { diff --git a/gnuradio-core/src/lib/filter/gr_pfb_decimator_ccf.cc b/gnuradio-core/src/lib/filter/gr_pfb_decimator_ccf.cc index c973daf829..e563daa513 100644 --- a/gnuradio-core/src/lib/filter/gr_pfb_decimator_ccf.cc +++ b/gnuradio-core/src/lib/filter/gr_pfb_decimator_ccf.cc @@ -69,6 +69,7 @@ gr_pfb_decimator_ccf::gr_pfb_decimator_ccf (unsigned int decim, gr_pfb_decimator_ccf::~gr_pfb_decimator_ccf () { + delete d_fft; for(unsigned int i = 0; i < d_rate; i++) { delete d_filters[i]; } diff --git a/gnuradio-core/src/lib/filter/gr_pfb_synthesizer_ccf.cc b/gnuradio-core/src/lib/filter/gr_pfb_synthesizer_ccf.cc index 9910a18510..cd01aaff5c 100644 --- a/gnuradio-core/src/lib/filter/gr_pfb_synthesizer_ccf.cc +++ b/gnuradio-core/src/lib/filter/gr_pfb_synthesizer_ccf.cc @@ -74,6 +74,7 @@ gr_pfb_synthesizer_ccf::gr_pfb_synthesizer_ccf gr_pfb_synthesizer_ccf::~gr_pfb_synthesizer_ccf () { + delete d_fft; for(unsigned int i = 0; i < d_twox*d_numchans; i++) { delete d_filters[i]; } -- cgit v1.2.3 From ae75ab750c2210a880684c3ce82bc152dd591ab3 Mon Sep 17 00:00:00 2001 From: Ben Reynwar <ben@reynwar.net> Date: Thu, 17 May 2012 11:37:20 -0700 Subject: gr: Added vector_map block. --- gnuradio-core/src/lib/general/CMakeLists.txt | 1 + gnuradio-core/src/lib/general/general.i | 2 + gnuradio-core/src/lib/general/gr_vector_map.cc | 112 +++++++++++++++++++++ gnuradio-core/src/lib/general/gr_vector_map.h | 77 ++++++++++++++ gnuradio-core/src/lib/general/gr_vector_map.i | 28 ++++++ .../src/python/gnuradio/gr/qa_vector_map.py | 103 +++++++++++++++++++ 6 files changed, 323 insertions(+) create mode 100644 gnuradio-core/src/lib/general/gr_vector_map.cc create mode 100644 gnuradio-core/src/lib/general/gr_vector_map.h create mode 100644 gnuradio-core/src/lib/general/gr_vector_map.i create mode 100644 gnuradio-core/src/python/gnuradio/gr/qa_vector_map.py (limited to 'gnuradio-core/src/lib') diff --git a/gnuradio-core/src/lib/general/CMakeLists.txt b/gnuradio-core/src/lib/general/CMakeLists.txt index 207d85c4c4..0ad55e38a4 100644 --- a/gnuradio-core/src/lib/general/CMakeLists.txt +++ b/gnuradio-core/src/lib/general/CMakeLists.txt @@ -281,6 +281,7 @@ set(gr_core_general_triple_threats gr_transcendental gr_uchar_to_float gr_vco_f + gr_vector_map gr_vector_to_stream gr_vector_to_streams gr_unpack_k_bits_bb diff --git a/gnuradio-core/src/lib/general/general.i b/gnuradio-core/src/lib/general/general.i index cd8c279c92..54d9a8670b 100644 --- a/gnuradio-core/src/lib/general/general.i +++ b/gnuradio-core/src/lib/general/general.i @@ -137,6 +137,7 @@ #include <gr_cpm.h> #include <gr_correlate_access_code_tag_bb.h> #include <gr_add_ff.h> +#include <gr_vector_map.h> %} %include "gri_control_loop.i" @@ -254,3 +255,4 @@ %include "gr_cpm.i" %include "gr_correlate_access_code_tag_bb.i" %include "gr_add_ff.i" +%include "gr_vector_map.i" diff --git a/gnuradio-core/src/lib/general/gr_vector_map.cc b/gnuradio-core/src/lib/general/gr_vector_map.cc new file mode 100644 index 0000000000..361daa490c --- /dev/null +++ b/gnuradio-core/src/lib/general/gr_vector_map.cc @@ -0,0 +1,112 @@ +/* -*- c++ -*- */ +/* + * 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. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <gr_vector_map.h> +#include <gr_io_signature.h> +#include <string.h> + +std::vector<int> +get_in_sizeofs(size_t item_size, std::vector<size_t> in_vlens) { + std::vector<int> in_sizeofs; + for (unsigned int i; i < in_vlens.size(); i++) { + in_sizeofs.push_back(in_vlens[i]*item_size); + } + return in_sizeofs; +} + +std::vector<int> +get_out_sizeofs(size_t item_size, + std::vector< std::vector< std::vector<size_t> > > mapping) { + std::vector<int> out_sizeofs; + for (unsigned int i; i < mapping.size(); i++) { + out_sizeofs.push_back(mapping[i].size()*item_size); + } + return out_sizeofs; +} + +gr_vector_map_sptr +gr_make_vector_map (size_t item_size, std::vector<size_t> in_vlens, + std::vector< std::vector< std::vector<size_t> > > mapping) +{ + return gnuradio::get_initial_sptr(new gr_vector_map (item_size, in_vlens, mapping)); +} + +gr_vector_map::gr_vector_map (size_t item_size, std::vector<size_t> in_vlens, + std::vector< std::vector< std::vector<size_t> > > mapping) + : gr_sync_block ("vector_map", + gr_make_io_signaturev (in_vlens.size(), in_vlens.size(), + get_in_sizeofs(item_size, in_vlens)), + gr_make_io_signaturev (mapping.size(), mapping.size(), + get_out_sizeofs(item_size, mapping))), + d_item_size(item_size), d_in_vlens(in_vlens) +{ + set_mapping(mapping); +} + +void +gr_vector_map::set_mapping(std::vector< std::vector< std::vector<size_t> > > mapping) { + // Make sure the contents of the mapping vectors are possible. + for (unsigned int i=0; i<mapping.size(); i++) { + for (unsigned int j=0; j<mapping[i].size(); j++) { + if (mapping[i][j].size() != 2) { + throw std::runtime_error("Mapping must be of the form (out_mapping_stream1, out_mapping_stream2, ...), where out_mapping_stream1 is of the form (mapping_element1, mapping_element2, ...), where mapping_element1 is of the form (input_stream, input_element). This error is raised because a mapping_element vector does not contain exactly 2 items."); + } + unsigned int s = mapping[i][j][0]; + unsigned int index = mapping[i][j][1]; + if (s >= d_in_vlens.size()) { + throw std::runtime_error("Stream numbers in mapping must be less than the number of input streams."); + } + if ((index < 0) || (index >= d_in_vlens[s])) { + throw std::runtime_error ("Indices in mapping must be greater than 0 and less than the input vector lengths."); + } + } + } + gruel::scoped_lock guard(d_mutex); + d_mapping = mapping; +} + +int +gr_vector_map::work (int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) +{ + + const char **inv = (const char **) &input_items[0]; + char **outv = (char **) &output_items[0]; + + for (unsigned int n=0; n<(unsigned int)(noutput_items); n++) { + for (unsigned int i=0; i<d_mapping.size(); i++) { + unsigned int out_vlen = d_mapping[i].size(); + for (unsigned int j=0; j<out_vlen; j++) { + unsigned int s = d_mapping[i][j][0]; + unsigned int k = d_mapping[i][j][1]; + memcpy(outv[i] + out_vlen*d_item_size*n + d_item_size*j, inv[s] + d_in_vlens[s]*d_item_size*n + k*d_item_size, d_item_size); + } + } + } + + return noutput_items; +} diff --git a/gnuradio-core/src/lib/general/gr_vector_map.h b/gnuradio-core/src/lib/general/gr_vector_map.h new file mode 100644 index 0000000000..ccb05bc532 --- /dev/null +++ b/gnuradio-core/src/lib/general/gr_vector_map.h @@ -0,0 +1,77 @@ +/* -*- c++ -*- */ +/* + * 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. + */ + +#ifndef INCLUDED_GR_VECTOR_MAP_H +#define INCLUDED_GR_VECTOR_MAP_H + +#include <vector> +#include <gr_core_api.h> +#include <gr_sync_interpolator.h> +#include <gruel/thread.h> + +class gr_vector_map; +typedef boost::shared_ptr<gr_vector_map> gr_vector_map_sptr; + +GR_CORE_API gr_vector_map_sptr +gr_make_vector_map (size_t item_size, std::vector<size_t> in_vlens, + std::vector< std::vector< std::vector<size_t> > > mapping); + +/*! + * \brief Maps elements from a set of input vectors to a set of output vectors. + * + * If in[i] is the input vector in the i'th stream then the output vector in the j'th stream is: + * out[j][k] = in[mapping[j][k][0]][mapping[j][k][1]] + * That is mapping is of the form (out_stream1_mapping, out_stream2_mapping, ...) + * and out_stream1_mapping is of the form (element1_mapping, element2_mapping, ...) + * and element1_mapping is of the form (in_stream, in_element). + * + * \param item_size (integer) size of vector elements + * + * \param in_vlens (vector of integers) number of elements in each input vector + * + * \param mapping (vector of vectors of vectors of integers) how to map elements from input to output vectors + * + * \ingroup slicedice_blk + */ +class GR_CORE_API gr_vector_map : public gr_sync_block +{ + friend GR_CORE_API gr_vector_map_sptr + gr_make_vector_map (size_t item_size, std::vector<size_t> in_vlens, + std::vector< std::vector< std::vector<size_t> > > mapping); + size_t d_item_size; + std::vector<size_t> d_in_vlens; + std::vector< std::vector< std::vector<size_t> > > d_mapping; + gruel::mutex d_mutex; // mutex to protect set/work access + + protected: + gr_vector_map (size_t item_size, std::vector<size_t> in_vlens, + std::vector< std::vector< std::vector<size_t> > > mapping); + + public: + int work (int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + + void set_mapping(std::vector< std::vector< std::vector<size_t> > > mapping); +}; + +#endif /* INCLUDED_GR_VECTOR_MAP_H */ diff --git a/gnuradio-core/src/lib/general/gr_vector_map.i b/gnuradio-core/src/lib/general/gr_vector_map.i new file mode 100644 index 0000000000..e9fa3f27e5 --- /dev/null +++ b/gnuradio-core/src/lib/general/gr_vector_map.i @@ -0,0 +1,28 @@ +/* -*- c++ -*- */ +/* + * 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. + */ + +GR_SWIG_BLOCK_MAGIC(gr, vector_map); + +%template() std::vector<size_t>; +%template() std::vector< std::vector< std::vector<size_t> > >; + +%include "gr_vector_map.h" diff --git a/gnuradio-core/src/python/gnuradio/gr/qa_vector_map.py b/gnuradio-core/src/python/gnuradio/gr/qa_vector_map.py new file mode 100644 index 0000000000..684210a082 --- /dev/null +++ b/gnuradio-core/src/python/gnuradio/gr/qa_vector_map.py @@ -0,0 +1,103 @@ +#!/usr/bin/env python +# +# 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. +# + +from gnuradio import gr, gr_unittest +import math + +class test_vector_map(gr_unittest.TestCase): + + def setUp (self): + self.tb = gr.top_block () + + def tearDown (self): + self.tb = None + + def test_reversing(self): + # Chunk data in blocks of N and reverse the block contents. + N = 5 + src_data = range(0, 20) + expected_result = [] + for i in range(N-1, len(src_data), N): + for j in range(0, N): + expected_result.append(1.0*(i-j)) + mapping = [list(reversed([(0, i) for i in range(0, N)]))] + src = gr.vector_source_f(src_data, False, N) + vmap = gr.vector_map(gr.sizeof_float, (N, ), mapping) + dst = gr.vector_sink_f(N) + self.tb.connect(src, vmap, dst) + self.tb.run() + result_data = list(dst.data()) + self.assertEqual(expected_result, result_data) + + def test_vector_to_streams(self): + # Split an input vector into N streams. + N = 5 + M = 20 + src_data = range(0, M) + expected_results = [] + for n in range(0, N): + expected_results.append(range(n, M, N)) + mapping = [[(0, n)] for n in range(0, N)] + src = gr.vector_source_f(src_data, False, N) + vmap = gr.vector_map(gr.sizeof_float, (N, ), mapping) + dsts = [gr.vector_sink_f(1) for n in range(0, N)] + self.tb.connect(src, vmap) + for n in range(0, N): + self.tb.connect((vmap, n), dsts[n]) + self.tb.run() + for n in range(0, N): + result_data = list(dsts[n].data()) + self.assertEqual(expected_results[n], result_data) + + def test_interleaving(self): + # Takes 3 streams (a, b and c) + # Outputs 2 streams. + # First (d) is interleaving of a and b. + # Second (e) is interleaving of a and b and c. c is taken in chunks of 2 which are reversed. + A = (1, 2, 3, 4, 5) + B = (11, 12, 13, 14, 15) + C = (99, 98, 97, 96, 95, 94, 93, 92, 91, 90) + expected_D = (1, 11, 2, 12, 3, 13, 4, 14, 5, 15) + expected_E = (1, 11, 98, 99, 2, 12, 96, 97, 3, 13, 94, 95, 4, 14, 92, 93, 5, 15, 90, 91) + mapping = [[(0, 0), (1, 0)], # mapping to produce D + [(0, 0), (1, 0), (2, 1), (2, 0)], # mapping to produce E + ] + srcA = gr.vector_source_f(A, False, 1) + srcB = gr.vector_source_f(B, False, 1) + srcC = gr.vector_source_f(C, False, 2) + vmap = gr.vector_map(gr.sizeof_int, (1, 1, 2), mapping) + dstD = gr.vector_sink_f(2) + dstE = gr.vector_sink_f(4) + self.tb.connect(srcA, (vmap, 0)) + self.tb.connect(srcB, (vmap, 1)) + self.tb.connect(srcC, (vmap, 2)) + self.tb.connect((vmap, 0), dstD) + self.tb.connect((vmap, 1), dstE) + self.tb.run() + self.assertEqual(expected_D, dstD.data()) + self.assertEqual(expected_E, dstE.data()) + + + +if __name__ == '__main__': + gr_unittest.run(test_vector_map, "test_vector_map.xml") + -- cgit v1.2.3 From d4fe4377e72165d88fdf00f6c8d5a5b986b25955 Mon Sep 17 00:00:00 2001 From: Tom Rondeau <trondeau@vt.edu> Date: Mon, 21 May 2012 12:48:33 -0400 Subject: core: minor formatting changes to vector_map for style consistency. --- gnuradio-core/src/lib/general/gr_vector_map.cc | 93 ++++++++++++---------- gnuradio-core/src/lib/general/gr_vector_map.h | 34 ++++---- .../src/python/gnuradio/gr/qa_vector_map.py | 8 +- 3 files changed, 74 insertions(+), 61 deletions(-) (limited to 'gnuradio-core/src/lib') diff --git a/gnuradio-core/src/lib/general/gr_vector_map.cc b/gnuradio-core/src/lib/general/gr_vector_map.cc index 361daa490c..4cf2ed1187 100644 --- a/gnuradio-core/src/lib/general/gr_vector_map.cc +++ b/gnuradio-core/src/lib/general/gr_vector_map.cc @@ -29,39 +29,43 @@ #include <string.h> std::vector<int> -get_in_sizeofs(size_t item_size, std::vector<size_t> in_vlens) { +get_in_sizeofs(size_t item_size, std::vector<size_t> in_vlens) +{ std::vector<int> in_sizeofs; - for (unsigned int i; i < in_vlens.size(); i++) { - in_sizeofs.push_back(in_vlens[i]*item_size); + for(unsigned int i; i < in_vlens.size(); i++) { + in_sizeofs.push_back(in_vlens[i]*item_size); } return in_sizeofs; } std::vector<int> get_out_sizeofs(size_t item_size, - std::vector< std::vector< std::vector<size_t> > > mapping) { + std::vector< std::vector< std::vector<size_t> > > mapping) +{ std::vector<int> out_sizeofs; - for (unsigned int i; i < mapping.size(); i++) { - out_sizeofs.push_back(mapping[i].size()*item_size); + for(unsigned int i; i < mapping.size(); i++) { + out_sizeofs.push_back(mapping[i].size()*item_size); } return out_sizeofs; } gr_vector_map_sptr gr_make_vector_map (size_t item_size, std::vector<size_t> in_vlens, - std::vector< std::vector< std::vector<size_t> > > mapping) + std::vector< std::vector< std::vector<size_t> > > mapping) { - return gnuradio::get_initial_sptr(new gr_vector_map (item_size, in_vlens, mapping)); + return gnuradio::get_initial_sptr(new gr_vector_map(item_size, + in_vlens, + mapping)); } -gr_vector_map::gr_vector_map (size_t item_size, std::vector<size_t> in_vlens, - std::vector< std::vector< std::vector<size_t> > > mapping) - : gr_sync_block ("vector_map", - gr_make_io_signaturev (in_vlens.size(), in_vlens.size(), - get_in_sizeofs(item_size, in_vlens)), - gr_make_io_signaturev (mapping.size(), mapping.size(), - get_out_sizeofs(item_size, mapping))), - d_item_size(item_size), d_in_vlens(in_vlens) +gr_vector_map::gr_vector_map(size_t item_size, std::vector<size_t> in_vlens, + std::vector< std::vector< std::vector<size_t> > > mapping) + : gr_sync_block("vector_map", + gr_make_io_signaturev(in_vlens.size(), in_vlens.size(), + get_in_sizeofs(item_size, in_vlens)), + gr_make_io_signaturev(mapping.size(), mapping.size(), + get_out_sizeofs(item_size, mapping))), + d_item_size(item_size), d_in_vlens(in_vlens) { set_mapping(mapping); } @@ -69,43 +73,44 @@ gr_vector_map::gr_vector_map (size_t item_size, std::vector<size_t> in_vlens, void gr_vector_map::set_mapping(std::vector< std::vector< std::vector<size_t> > > mapping) { // Make sure the contents of the mapping vectors are possible. - for (unsigned int i=0; i<mapping.size(); i++) { - for (unsigned int j=0; j<mapping[i].size(); j++) { - if (mapping[i][j].size() != 2) { - throw std::runtime_error("Mapping must be of the form (out_mapping_stream1, out_mapping_stream2, ...), where out_mapping_stream1 is of the form (mapping_element1, mapping_element2, ...), where mapping_element1 is of the form (input_stream, input_element). This error is raised because a mapping_element vector does not contain exactly 2 items."); - } - unsigned int s = mapping[i][j][0]; - unsigned int index = mapping[i][j][1]; - if (s >= d_in_vlens.size()) { - throw std::runtime_error("Stream numbers in mapping must be less than the number of input streams."); - } - if ((index < 0) || (index >= d_in_vlens[s])) { - throw std::runtime_error ("Indices in mapping must be greater than 0 and less than the input vector lengths."); - } - } - } + for(unsigned int i=0; i<mapping.size(); i++) { + for(unsigned int j=0; j<mapping[i].size(); j++) { + if(mapping[i][j].size() != 2) { + throw std::runtime_error("Mapping must be of the form (out_mapping_stream1, out_mapping_stream2, ...), where out_mapping_stream1 is of the form (mapping_element1, mapping_element2, ...), where mapping_element1 is of the form (input_stream, input_element). This error is raised because a mapping_element vector does not contain exactly 2 items."); + } + unsigned int s = mapping[i][j][0]; + unsigned int index = mapping[i][j][1]; + if(s >= d_in_vlens.size()) { + throw std::runtime_error("Stream numbers in mapping must be less than the number of input streams."); + } + if((index < 0) || (index >= d_in_vlens[s])) { + throw std::runtime_error ("Indices in mapping must be greater than 0 and less than the input vector lengths."); + } + } + } gruel::scoped_lock guard(d_mutex); d_mapping = mapping; } int -gr_vector_map::work (int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) +gr_vector_map::work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) { - const char **inv = (const char **) &input_items[0]; char **outv = (char **) &output_items[0]; - for (unsigned int n=0; n<(unsigned int)(noutput_items); n++) { - for (unsigned int i=0; i<d_mapping.size(); i++) { - unsigned int out_vlen = d_mapping[i].size(); - for (unsigned int j=0; j<out_vlen; j++) { - unsigned int s = d_mapping[i][j][0]; - unsigned int k = d_mapping[i][j][1]; - memcpy(outv[i] + out_vlen*d_item_size*n + d_item_size*j, inv[s] + d_in_vlens[s]*d_item_size*n + k*d_item_size, d_item_size); - } - } + for(unsigned int n = 0; n < (unsigned int)(noutput_items); n++) { + for(unsigned int i = 0; i < d_mapping.size(); i++) { + unsigned int out_vlen = d_mapping[i].size(); + for(unsigned int j = 0; j < out_vlen; j++) { + unsigned int s = d_mapping[i][j][0]; + unsigned int k = d_mapping[i][j][1]; + memcpy(outv[i] + out_vlen*d_item_size*n + + d_item_size*j, inv[s] + d_in_vlens[s]*d_item_size*n + + k*d_item_size, d_item_size); + } + } } return noutput_items; diff --git a/gnuradio-core/src/lib/general/gr_vector_map.h b/gnuradio-core/src/lib/general/gr_vector_map.h index ccb05bc532..f5492b1e3a 100644 --- a/gnuradio-core/src/lib/general/gr_vector_map.h +++ b/gnuradio-core/src/lib/general/gr_vector_map.h @@ -33,43 +33,49 @@ typedef boost::shared_ptr<gr_vector_map> gr_vector_map_sptr; GR_CORE_API gr_vector_map_sptr gr_make_vector_map (size_t item_size, std::vector<size_t> in_vlens, - std::vector< std::vector< std::vector<size_t> > > mapping); + std::vector< std::vector< std::vector<size_t> > > mapping); /*! * \brief Maps elements from a set of input vectors to a set of output vectors. * - * If in[i] is the input vector in the i'th stream then the output vector in the j'th stream is: + * If in[i] is the input vector in the i'th stream then the output + * vector in the j'th stream is: + * * out[j][k] = in[mapping[j][k][0]][mapping[j][k][1]] - * That is mapping is of the form (out_stream1_mapping, out_stream2_mapping, ...) - * and out_stream1_mapping is of the form (element1_mapping, element2_mapping, ...) - * and element1_mapping is of the form (in_stream, in_element). + * + * That is mapping is of the form (out_stream1_mapping, + * out_stream2_mapping, ...) and out_stream1_mapping is of the form + * (element1_mapping, element2_mapping, ...) and element1_mapping is + * of the form (in_stream, in_element). * * \param item_size (integer) size of vector elements * - * \param in_vlens (vector of integers) number of elements in each input vector + * \param in_vlens (vector of integers) number of elements in each + * input vector * - * \param mapping (vector of vectors of vectors of integers) how to map elements from input to output vectors + * \param mapping (vector of vectors of vectors of integers) how to + * map elements from input to output vectors * * \ingroup slicedice_blk */ class GR_CORE_API gr_vector_map : public gr_sync_block { friend GR_CORE_API gr_vector_map_sptr - gr_make_vector_map (size_t item_size, std::vector<size_t> in_vlens, - std::vector< std::vector< std::vector<size_t> > > mapping); + gr_make_vector_map(size_t item_size, std::vector<size_t> in_vlens, + std::vector< std::vector< std::vector<size_t> > > mapping); size_t d_item_size; std::vector<size_t> d_in_vlens; std::vector< std::vector< std::vector<size_t> > > d_mapping; gruel::mutex d_mutex; // mutex to protect set/work access protected: - gr_vector_map (size_t item_size, std::vector<size_t> in_vlens, - std::vector< std::vector< std::vector<size_t> > > mapping); + gr_vector_map(size_t item_size, std::vector<size_t> in_vlens, + std::vector< std::vector< std::vector<size_t> > > mapping); public: - int work (int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); + int work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); void set_mapping(std::vector< std::vector< std::vector<size_t> > > mapping); }; diff --git a/gnuradio-core/src/python/gnuradio/gr/qa_vector_map.py b/gnuradio-core/src/python/gnuradio/gr/qa_vector_map.py index 684210a082..12f4be5898 100644 --- a/gnuradio-core/src/python/gnuradio/gr/qa_vector_map.py +++ b/gnuradio-core/src/python/gnuradio/gr/qa_vector_map.py @@ -26,7 +26,7 @@ import math class test_vector_map(gr_unittest.TestCase): def setUp (self): - self.tb = gr.top_block () + self.tb = gr.top_block() def tearDown (self): self.tb = None @@ -72,12 +72,14 @@ class test_vector_map(gr_unittest.TestCase): # Takes 3 streams (a, b and c) # Outputs 2 streams. # First (d) is interleaving of a and b. - # Second (e) is interleaving of a and b and c. c is taken in chunks of 2 which are reversed. + # Second (e) is interleaving of a and b and c. c is taken in + # chunks of 2 which are reversed. A = (1, 2, 3, 4, 5) B = (11, 12, 13, 14, 15) C = (99, 98, 97, 96, 95, 94, 93, 92, 91, 90) expected_D = (1, 11, 2, 12, 3, 13, 4, 14, 5, 15) - expected_E = (1, 11, 98, 99, 2, 12, 96, 97, 3, 13, 94, 95, 4, 14, 92, 93, 5, 15, 90, 91) + expected_E = (1, 11, 98, 99, 2, 12, 96, 97, 3, 13, 94, 95, + 4, 14, 92, 93, 5, 15, 90, 91) mapping = [[(0, 0), (1, 0)], # mapping to produce D [(0, 0), (1, 0), (2, 1), (2, 0)], # mapping to produce E ] -- cgit v1.2.3 From 52c64845bded42ddd8f0b33dab8907b045392b2c Mon Sep 17 00:00:00 2001 From: Donald Porges <Donald.Porges@analog.com> Date: Sun, 27 May 2012 09:56:06 -0400 Subject: core: patch for vector_map loop variable initialization. --- gnuradio-core/src/lib/general/gr_vector_map.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'gnuradio-core/src/lib') diff --git a/gnuradio-core/src/lib/general/gr_vector_map.cc b/gnuradio-core/src/lib/general/gr_vector_map.cc index 4cf2ed1187..2a13efb06d 100644 --- a/gnuradio-core/src/lib/general/gr_vector_map.cc +++ b/gnuradio-core/src/lib/general/gr_vector_map.cc @@ -32,7 +32,7 @@ std::vector<int> get_in_sizeofs(size_t item_size, std::vector<size_t> in_vlens) { std::vector<int> in_sizeofs; - for(unsigned int i; i < in_vlens.size(); i++) { + for(unsigned int i = 0; i < in_vlens.size(); i++) { in_sizeofs.push_back(in_vlens[i]*item_size); } return in_sizeofs; @@ -43,7 +43,7 @@ get_out_sizeofs(size_t item_size, std::vector< std::vector< std::vector<size_t> > > mapping) { std::vector<int> out_sizeofs; - for(unsigned int i; i < mapping.size(); i++) { + for(unsigned int i = 0; i < mapping.size(); i++) { out_sizeofs.push_back(mapping[i].size()*item_size); } return out_sizeofs; -- cgit v1.2.3 From f2ab263b6fc9c24adc88fb55f2c210dd88e9345a Mon Sep 17 00:00:00 2001 From: Tim O'Shea <tim.oshea753@gmail.com> Date: Sat, 7 Jan 2012 17:52:31 -0500 Subject: Block Modifications: digital.mpsk_receiver_cc: Set reasonable default parameter values for GRC definition digital.ofdm_insert_preamble: Expose enter_preamble() as public, to allow external state changes Cleanup of incorrect forecast behavior Make the flag port optional, incase external preamble triggers are preferred to in-band gr_vector_source: added set_data( data ) and rewind() public methods gr_head: added set_length(int) method to modify head length New Blocks Added: gr_keep_m_in_n: Allows periodic extraction of M items instead of 1 (in keep_1_in_n) gr_pack_k_bits: Complementary block fo gr_unpack_k_bits gr_vector_insert_x: Complement to the gr_head block, inserts a vector into a stream then becomes a pass through --- gnuradio-core/src/lib/general/CMakeLists.txt | 2 + gnuradio-core/src/lib/general/general.i | 4 + gnuradio-core/src/lib/general/gr_head.h | 1 + gnuradio-core/src/lib/general/gr_head.i | 1 + gnuradio-core/src/lib/general/gr_keep_m_in_n.cc | 85 ++++++++++++++++++ gnuradio-core/src/lib/general/gr_keep_m_in_n.h | 62 +++++++++++++ gnuradio-core/src/lib/general/gr_keep_m_in_n.i | 35 ++++++++ gnuradio-core/src/lib/general/gr_pack_k_bits_bb.cc | 69 ++++++++++++++ gnuradio-core/src/lib/general/gr_pack_k_bits_bb.h | 56 ++++++++++++ gnuradio-core/src/lib/general/gr_pack_k_bits_bb.i | 34 +++++++ gnuradio-core/src/lib/gengen/CMakeLists.txt | 1 + .../src/lib/gengen/gr_vector_insert_X.cc.t | 100 +++++++++++++++++++++ .../src/lib/gengen/gr_vector_insert_X.h.t | 61 +++++++++++++ .../src/lib/gengen/gr_vector_insert_X.i.t | 37 ++++++++ .../src/lib/gengen/gr_vector_source_X.h.t | 1 + .../src/lib/gengen/gr_vector_source_X.i.t | 3 +- .../src/python/gnuradio/gr/qa_vector_insert.py | 58 ++++++++++++ gr-digital/grc/digital_mpsk_receiver_cc.xml | 13 ++- gr-digital/grc/digital_ofdm_insert_preamble.xml | 6 ++ gr-digital/include/digital_ofdm_insert_preamble.h | 4 +- gr-digital/lib/digital_ofdm_insert_preamble.cc | 18 ++-- gr-digital/swig/digital_ofdm_insert_preamble.i | 2 + grc/blocks/block_tree.xml | 3 + grc/blocks/gr_keep_m_in_n.xml | 74 +++++++++++++++ grc/blocks/gr_pack_k_bits_bb.xml | 30 +++++++ grc/blocks/gr_vector_insert_x.xml | 80 +++++++++++++++++ 26 files changed, 831 insertions(+), 9 deletions(-) create mode 100644 gnuradio-core/src/lib/general/gr_keep_m_in_n.cc create mode 100644 gnuradio-core/src/lib/general/gr_keep_m_in_n.h create mode 100644 gnuradio-core/src/lib/general/gr_keep_m_in_n.i create mode 100644 gnuradio-core/src/lib/general/gr_pack_k_bits_bb.cc create mode 100644 gnuradio-core/src/lib/general/gr_pack_k_bits_bb.h create mode 100644 gnuradio-core/src/lib/general/gr_pack_k_bits_bb.i create mode 100644 gnuradio-core/src/lib/gengen/gr_vector_insert_X.cc.t create mode 100644 gnuradio-core/src/lib/gengen/gr_vector_insert_X.h.t create mode 100644 gnuradio-core/src/lib/gengen/gr_vector_insert_X.i.t create mode 100755 gnuradio-core/src/python/gnuradio/gr/qa_vector_insert.py create mode 100644 grc/blocks/gr_keep_m_in_n.xml create mode 100644 grc/blocks/gr_pack_k_bits_bb.xml create mode 100644 grc/blocks/gr_vector_insert_x.xml (limited to 'gnuradio-core/src/lib') diff --git a/gnuradio-core/src/lib/general/CMakeLists.txt b/gnuradio-core/src/lib/general/CMakeLists.txt index 0ad55e38a4..ab9b870aa3 100644 --- a/gnuradio-core/src/lib/general/CMakeLists.txt +++ b/gnuradio-core/src/lib/general/CMakeLists.txt @@ -228,6 +228,7 @@ set(gr_core_general_triple_threats gr_interleaved_short_to_complex gr_iqcomp_cc gr_keep_one_in_n + gr_keep_m_in_n gr_kludge_copy gr_lfsr_32k_source_s gr_map_bb @@ -285,6 +286,7 @@ set(gr_core_general_triple_threats gr_vector_to_stream gr_vector_to_streams gr_unpack_k_bits_bb + gr_pack_k_bits_bb gr_descrambler_bb gr_scrambler_bb gr_probe_density_b diff --git a/gnuradio-core/src/lib/general/general.i b/gnuradio-core/src/lib/general/general.i index 54d9a8670b..0696addbde 100644 --- a/gnuradio-core/src/lib/general/general.i +++ b/gnuradio-core/src/lib/general/general.i @@ -37,6 +37,7 @@ #include <gr_stream_to_vector.h> #include <gr_vector_to_stream.h> #include <gr_keep_one_in_n.h> +#include <gr_keep_m_in_n.h> #include <gr_fft_vcc.h> #include <gr_fft_vfc.h> #include <gr_float_to_int.h> @@ -100,6 +101,7 @@ #include <gr_test_types.h> #include <gr_test.h> #include <gr_unpack_k_bits_bb.h> +#include <gr_pack_k_bits_bb.h> #include <gr_diff_phasor_cc.h> #include <gr_diff_encoder_bb.h> #include <gr_diff_decoder_bb.h> @@ -155,6 +157,7 @@ %include "gr_stream_to_vector.i" %include "gr_vector_to_stream.i" %include "gr_keep_one_in_n.i" +%include "gr_keep_m_in_n.i" %include "gr_fft_vcc.i" %include "gr_fft_vfc.i" %include "gr_float_to_int.i" @@ -218,6 +221,7 @@ %include "gr_test_types.h" %include "gr_test.i" %include "gr_unpack_k_bits_bb.i" +%include "gr_pack_k_bits_bb.i" %include "gr_diff_phasor_cc.i" %include "gr_diff_encoder_bb.i" %include "gr_diff_decoder_bb.i" diff --git a/gnuradio-core/src/lib/general/gr_head.h b/gnuradio-core/src/lib/general/gr_head.h index 17dd737f0b..4471d75ea8 100644 --- a/gnuradio-core/src/lib/general/gr_head.h +++ b/gnuradio-core/src/lib/general/gr_head.h @@ -51,6 +51,7 @@ class GR_CORE_API gr_head : public gr_sync_block gr_vector_void_star &output_items); void reset() { d_ncopied_items = 0; } + void set_length(int nitems) { d_nitems = nitems; } }; GR_CORE_API gr_head_sptr diff --git a/gnuradio-core/src/lib/general/gr_head.i b/gnuradio-core/src/lib/general/gr_head.i index 73feaf181c..d59dd176a7 100644 --- a/gnuradio-core/src/lib/general/gr_head.i +++ b/gnuradio-core/src/lib/general/gr_head.i @@ -28,5 +28,6 @@ class gr_head : public gr_block { gr_head(); public: void reset(); + void set_length(int nitems); }; diff --git a/gnuradio-core/src/lib/general/gr_keep_m_in_n.cc b/gnuradio-core/src/lib/general/gr_keep_m_in_n.cc new file mode 100644 index 0000000000..f17c3e00d7 --- /dev/null +++ b/gnuradio-core/src/lib/general/gr_keep_m_in_n.cc @@ -0,0 +1,85 @@ +/* -*- 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. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <gr_keep_m_in_n.h> +#include <gr_io_signature.h> +#include <string.h> +#include <stdio.h> + +gr_keep_m_in_n_sptr +gr_make_keep_m_in_n (size_t item_size, int m, int n, int offset) +{ + return gnuradio::get_initial_sptr(new gr_keep_m_in_n (item_size, m, n, offset)); +} + + +/* +* +* offset = 0, starts with 0th item +* offset = 1, starts with 1st item, etc... +* +* we take m items out of each n +*/ +gr_keep_m_in_n::gr_keep_m_in_n (size_t item_size, int m, int n, int offset) + : gr_sync_block ("keep_m_in_n", + gr_make_io_signature (1, 1, n*item_size), + gr_make_io_signature (1, 1, m*item_size)), + d_n(n), + d_m(m), + d_offset( offset ) +{ + // sanity checking + assert(d_m > 0); + assert(d_n > 0); + assert(d_m <= d_n); + assert(d_offset <= (d_n-d_m)); +} + + +void gr_keep_m_in_n::set_offset(int offset){ + d_offset = offset; +} + + +int +gr_keep_m_in_n::work (int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) +{ + uint8_t* out = (uint8_t*) output_items[0]; + const uint8_t* in = (const uint8_t*) input_items[0]; + + int in_item( input_signature()->sizeof_stream_item(0) ); + int out_item( output_signature()->sizeof_stream_item(0) ); + int single_size = in_item/d_n; + + // iterate over data blocks of size {n, input : m, output} + for(int i=0; i<noutput_items; i++){ + memcpy( &out[out_item*i], &in[in_item*i + single_size*d_offset], out_item); + } + + return noutput_items; +} diff --git a/gnuradio-core/src/lib/general/gr_keep_m_in_n.h b/gnuradio-core/src/lib/general/gr_keep_m_in_n.h new file mode 100644 index 0000000000..f9d5a268bc --- /dev/null +++ b/gnuradio-core/src/lib/general/gr_keep_m_in_n.h @@ -0,0 +1,62 @@ +/* -*- 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_GR_KEEP_M_IN_N_H +#define INCLUDED_GR_KEEP_M_IN_N_H + +#include <gr_core_api.h> +#include <gr_sync_block.h> + +class gr_keep_m_in_n; +typedef boost::shared_ptr<gr_keep_m_in_n> gr_keep_m_in_n_sptr; + +GR_CORE_API gr_keep_m_in_n_sptr +gr_make_keep_m_in_n (size_t item_size, int m, int n, int offset); + + +/*! + * \brief decimate a stream, keeping one item out of every n. + * \ingroup slicedice_blk + */ +class GR_CORE_API gr_keep_m_in_n : public gr_sync_block +{ + friend GR_CORE_API gr_keep_m_in_n_sptr + gr_make_keep_m_in_n (size_t item_size, int m, int n, int offset); + + int d_n; + int d_m; + int d_count; + int d_offset; + + protected: + gr_keep_m_in_n (size_t item_size, int m, int n, int offset); + + public: + int work (int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + + void set_offset(int offset); + +}; + +#endif /* INCLUDED_GR_KEEP_M_IN_N_H */ diff --git a/gnuradio-core/src/lib/general/gr_keep_m_in_n.i b/gnuradio-core/src/lib/general/gr_keep_m_in_n.i new file mode 100644 index 0000000000..cb5c636835 --- /dev/null +++ b/gnuradio-core/src/lib/general/gr_keep_m_in_n.i @@ -0,0 +1,35 @@ +/* -*- 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. + */ + +GR_SWIG_BLOCK_MAGIC(gr,keep_m_in_n) + +gr_keep_m_in_n_sptr +gr_make_keep_m_in_n (size_t itemsize, int m, int n, int offset); + +class gr_keep_m_in_n : public gr_sync_block +{ + protected: + gr_keep_m_in_n (size_t itemsize, int m, int n, int offset); + public: + void set_offset(int offset); + +}; diff --git a/gnuradio-core/src/lib/general/gr_pack_k_bits_bb.cc b/gnuradio-core/src/lib/general/gr_pack_k_bits_bb.cc new file mode 100644 index 0000000000..0237a4d691 --- /dev/null +++ b/gnuradio-core/src/lib/general/gr_pack_k_bits_bb.cc @@ -0,0 +1,69 @@ +/* -*- c++ -*- */ +/* + * Copyright 2005,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. + */ + +#if HAVE_CONFIG_H +#include "config.h" +#endif + +#include <gr_pack_k_bits_bb.h> +#include <gr_io_signature.h> +#include <stdexcept> +#include <iostream> + +gr_pack_k_bits_bb_sptr gr_make_pack_k_bits_bb (unsigned k) +{ + return gnuradio::get_initial_sptr(new gr_pack_k_bits_bb (k)); +} + + +gr_pack_k_bits_bb::gr_pack_k_bits_bb (unsigned k) + : gr_sync_decimator ("pack_k_bits_bb", + gr_make_io_signature (1, 1, sizeof (unsigned char)), + gr_make_io_signature (1, 1, sizeof (unsigned char)), + k), + d_k (k) +{ + if (d_k == 0) + throw std::out_of_range ("interpolation must be > 0"); +} + +gr_pack_k_bits_bb::~gr_pack_k_bits_bb () +{ +} + +int +gr_pack_k_bits_bb::work (int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) +{ + const unsigned char *in = (const unsigned char *) input_items[0]; + unsigned char *out = (unsigned char *) output_items[0]; + + for (int i = 0; i < noutput_items; i++){ + out[i] = 0x00; + for (unsigned int j = 0; j < d_k; j++){ + out[i] |= (0x01 & in[i*d_k+j])<<j; + } + } + + return noutput_items; +} diff --git a/gnuradio-core/src/lib/general/gr_pack_k_bits_bb.h b/gnuradio-core/src/lib/general/gr_pack_k_bits_bb.h new file mode 100644 index 0000000000..00b8f8f13d --- /dev/null +++ b/gnuradio-core/src/lib/general/gr_pack_k_bits_bb.h @@ -0,0 +1,56 @@ +/* -*- c++ -*- */ +/* + * Copyright 2006 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_GR_PACK_K_BITS_BB_H +#define INCLUDED_GR_PACK_K_BITS_BB_H + +#include <gr_core_api.h> +#include <gr_sync_decimator.h> + +class gr_pack_k_bits_bb; +typedef boost::shared_ptr<gr_pack_k_bits_bb> gr_pack_k_bits_bb_sptr; +GR_CORE_API gr_pack_k_bits_bb_sptr gr_make_pack_k_bits_bb (unsigned k); + +class gr_pack_k_bits_bb; + +/*! + * \brief Converts a byte with k relevent bits to k output bytes with 1 bit in the LSB. + * \ingroup converter_blk + */ +class GR_CORE_API gr_pack_k_bits_bb : public gr_sync_decimator +{ + private: + friend GR_CORE_API gr_pack_k_bits_bb_sptr gr_make_pack_k_bits_bb (unsigned k); + + gr_pack_k_bits_bb (unsigned k); + + unsigned d_k; // number of relevent bits to pack from k input bytes + + public: + ~gr_pack_k_bits_bb (); + + int work (int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); +}; + +#endif diff --git a/gnuradio-core/src/lib/general/gr_pack_k_bits_bb.i b/gnuradio-core/src/lib/general/gr_pack_k_bits_bb.i new file mode 100644 index 0000000000..4711915d79 --- /dev/null +++ b/gnuradio-core/src/lib/general/gr_pack_k_bits_bb.i @@ -0,0 +1,34 @@ +/* -*- c++ -*- */ +/* + * Copyright 2006 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. + */ + +GR_SWIG_BLOCK_MAGIC(gr,pack_k_bits_bb) + +gr_pack_k_bits_bb_sptr gr_make_pack_k_bits_bb (int k) throw(std::exception); + +class gr_pack_k_bits_bb : public gr_sync_decimator +{ + private: + gr_pack_k_bits_bb (int k); + + public: + ~gr_pack_k_bits_bb (); +}; diff --git a/gnuradio-core/src/lib/gengen/CMakeLists.txt b/gnuradio-core/src/lib/gengen/CMakeLists.txt index d137769907..22ac1bc588 100644 --- a/gnuradio-core/src/lib/gengen/CMakeLists.txt +++ b/gnuradio-core/src/lib/gengen/CMakeLists.txt @@ -82,6 +82,7 @@ endmacro(expand_h_cc_i) # Invoke macro to generate various sources ######################################################################## expand_h_cc_i(gr_vector_source_X b s i f c) +expand_h_cc_i(gr_vector_insert_X b) expand_h_cc_i(gr_vector_sink_X b s i f c) expand_h_cc_i(gr_noise_source_X s i f c) expand_h_cc_i(gr_sig_source_X s i f c) diff --git a/gnuradio-core/src/lib/gengen/gr_vector_insert_X.cc.t b/gnuradio-core/src/lib/gengen/gr_vector_insert_X.cc.t new file mode 100644 index 0000000000..15e19edb02 --- /dev/null +++ b/gnuradio-core/src/lib/gengen/gr_vector_insert_X.cc.t @@ -0,0 +1,100 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004,2008,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. + */ + +// @WARNING@ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif +#include <@NAME@.h> +#include <algorithm> +#include <gr_io_signature.h> +#include <stdexcept> + +#include <stdio.h> + +@NAME@::@NAME@ (const std::vector<@TYPE@> &data, int periodicity, int offset) + : gr_block ("@BASE_NAME@", + gr_make_io_signature (1, 1, sizeof (@TYPE@)), + gr_make_io_signature (1, 1, sizeof (@TYPE@))), + d_data (data), + d_offset (offset), + d_periodicity (periodicity) +{ + //printf("INITIAL: periodicity = %d, offset = %d\n", periodicity, offset); + // some sanity checks + assert(offset < periodicity); + assert(offset >= 0); + assert(periodicity > data.size()); +} + +int +@NAME@::general_work (int noutput_items, + gr_vector_int &ninput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) +{ + @TYPE@ *out = (@TYPE@ *) output_items[0]; + const @TYPE@ *in = (const @TYPE@ *) input_items[0]; + + int ii(0), oo(0); + + while( (oo < noutput_items) && (ii < ninput_items[0]) ){ + + //printf("oo = %d, ii = %d, d_offset = %d, noutput_items = %d, ninput_items[0] = %d", oo, ii, d_offset, noutput_items, ninput_items[0]); + //printf(", d_periodicity = %d\n", d_periodicity); + + if( d_offset >= ((int)d_data.size()) ){ // if we are in the copy region + int max_copy = std::min( std::min( noutput_items - oo, ninput_items[0] - ii ), d_periodicity - d_offset ); + //printf("copy %d from input\n", max_copy); + memcpy( &out[oo], &in[ii], sizeof(@TYPE@)*max_copy ); + //printf(" * memcpy returned.\n"); + ii += max_copy; + oo += max_copy; + d_offset = (d_offset + max_copy)%d_periodicity; + + } else { // if we are in the insertion region + int max_copy = std::min( noutput_items - oo, ((int)d_data.size()) - d_offset ); + //printf("copy %d from d_data[%d] to out[%d]\n", max_copy, d_offset, oo); + memcpy( &out[oo], &d_data[d_offset], sizeof(@TYPE@)*max_copy ); + //printf(" * memcpy returned.\n"); + oo += max_copy; + d_offset = (d_offset + max_copy)%d_periodicity; + //printf(" ## (inelse) oo = %d, d_offset = %d\n", oo, d_offset); + } + + //printf(" # exit else, on to next loop.\n"); + } + //printf(" # got out of loop\n"); + + //printf("consume = %d, produce = %d\n", ii, oo); + consume_each(ii); + return oo; + +} + +@NAME@_sptr +gr_make_@BASE_NAME@ (const std::vector<@TYPE@> &data, int periodicity, int offset) +{ + return gnuradio::get_initial_sptr(new @NAME@ (data, periodicity, offset)); +} + diff --git a/gnuradio-core/src/lib/gengen/gr_vector_insert_X.h.t b/gnuradio-core/src/lib/gengen/gr_vector_insert_X.h.t new file mode 100644 index 0000000000..76c6b7a5dc --- /dev/null +++ b/gnuradio-core/src/lib/gengen/gr_vector_insert_X.h.t @@ -0,0 +1,61 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004,2008 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. + */ + +// @WARNING@ + +#ifndef @GUARD_NAME@ +#define @GUARD_NAME@ + +#include <gr_core_api.h> +#include <gr_block.h> + +class GR_CORE_API @NAME@; +typedef boost::shared_ptr<@NAME@> @NAME@_sptr; + +/*! + * \brief source of @TYPE@'s that gets its data from a vector + * \ingroup source_blk + */ + +class @NAME@ : public gr_block { + friend GR_CORE_API @NAME@_sptr + gr_make_@BASE_NAME@ (const std::vector<@TYPE@> &data, int periodicity, int offset); + + std::vector<@TYPE@> d_data; + int d_offset; + int d_periodicity; + + @NAME@ (const std::vector<@TYPE@> &data, int periodicity, int offset); + + public: + void rewind() {d_offset=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); + void set_data(const std::vector<@TYPE@> &data){ d_data = data; rewind(); } +}; + +GR_CORE_API @NAME@_sptr +gr_make_@BASE_NAME@ (const std::vector<@TYPE@> &data, int periodicity, int offset=0); + +#endif diff --git a/gnuradio-core/src/lib/gengen/gr_vector_insert_X.i.t b/gnuradio-core/src/lib/gengen/gr_vector_insert_X.i.t new file mode 100644 index 0000000000..ce951b3341 --- /dev/null +++ b/gnuradio-core/src/lib/gengen/gr_vector_insert_X.i.t @@ -0,0 +1,37 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004,2008 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. + */ + +// @WARNING@ + +GR_SWIG_BLOCK_MAGIC(gr,@BASE_NAME@); + +@NAME@_sptr +gr_make_@BASE_NAME@ (const std::vector<@TYPE@> &data, int periodicity, int offset = 0) + throw(std::invalid_argument); + +class @NAME@ : public gr_block { + public: + void rewind(); + void set_data(const std::vector<@TYPE@> &data); + private: + @NAME@ (const std::vector<@TYPE@> &data, int periodicity, int offset = 0); +}; diff --git a/gnuradio-core/src/lib/gengen/gr_vector_source_X.h.t b/gnuradio-core/src/lib/gengen/gr_vector_source_X.h.t index fe0a77f818..89f07721d5 100644 --- a/gnuradio-core/src/lib/gengen/gr_vector_source_X.h.t +++ b/gnuradio-core/src/lib/gengen/gr_vector_source_X.h.t @@ -52,6 +52,7 @@ class @NAME@ : public gr_sync_block { virtual int work (int noutput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items); + void set_data(const std::vector<@TYPE@> &data){ d_data = data; rewind(); } }; GR_CORE_API @NAME@_sptr diff --git a/gnuradio-core/src/lib/gengen/gr_vector_source_X.i.t b/gnuradio-core/src/lib/gengen/gr_vector_source_X.i.t index 6c20539ac8..c821e12fff 100644 --- a/gnuradio-core/src/lib/gengen/gr_vector_source_X.i.t +++ b/gnuradio-core/src/lib/gengen/gr_vector_source_X.i.t @@ -30,7 +30,8 @@ gr_make_@BASE_NAME@ (const std::vector<@TYPE@> &data, bool repeat = false, int v class @NAME@ : public gr_sync_block { public: - void rewind() {d_offset=0;} + void rewind(); + void set_data(const std::vector<@TYPE@> &data); private: @NAME@ (const std::vector<@TYPE@> &data, int vlen); }; diff --git a/gnuradio-core/src/python/gnuradio/gr/qa_vector_insert.py b/gnuradio-core/src/python/gnuradio/gr/qa_vector_insert.py new file mode 100755 index 0000000000..7ab8e701aa --- /dev/null +++ b/gnuradio-core/src/python/gnuradio/gr/qa_vector_insert.py @@ -0,0 +1,58 @@ +#!/usr/bin/env python +# +# Copyright 2008,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. +# + +from gnuradio import gr, gr_unittest +import math + +class test_vector_insert(gr_unittest.TestCase): + + def setUp (self): + self.tb = gr.top_block () + + def tearDown (self): + self.tb = None + + def test_001(self): + src_data = [float(x) for x in range(16)] + expected_result = tuple(src_data) + + period = 9177; + offset = 0; + + src = gr.null_source(1) + head = gr.head(1, 10000000); + ins = gr.vector_insert_b([1], period, offset); + dst = gr.vector_sink_b() + + self.tb.connect(src, head, ins, dst) + self.tb.run() + result_data = dst.data() + + for i in range(10000): + if(i%period == offset): + self.assertEqual(1, result_data[i]) + else: + self.assertEqual(0, result_data[i]) + +if __name__ == '__main__': + gr_unittest.run(test_vector_insert, "test_vector_insert.xml") + diff --git a/gr-digital/grc/digital_mpsk_receiver_cc.xml b/gr-digital/grc/digital_mpsk_receiver_cc.xml index ab7e5c2091..bd738fccc3 100644 --- a/gr-digital/grc/digital_mpsk_receiver_cc.xml +++ b/gr-digital/grc/digital_mpsk_receiver_cc.xml @@ -7,7 +7,7 @@ <block> <name>MPSK Receiver</name> <key>digital_mpsk_receiver_cc</key> - <import>from gnuradio import digital</import> + <import>from gnuradio import digital;import cmath</import> <make>digital.mpsk_receiver_cc($M, $theta, $w, $fmin, $fmax, $mu, $gain_mu, $omega, $gain_omega, $omega_relative_limit)</make> <callback>set_loop_bandwidth($w)</callback> <callback>set_mu($mu)</callback> @@ -17,51 +17,61 @@ <param> <name>M</name> <key>M</key> + <value>4</value> <type>int</type> </param> <param> <name>Theta</name> <key>theta</key> + <value>0</value> <type>real</type> </param> <param> <name>Loop Bandwidth</name> <key>w</key> + <value>cmath.pi/100.0</value> <type>real</type> </param> <param> <name>Min Freq</name> <key>fmin</key> + <value>-0.5</value> <type>real</type> </param> <param> <name>Max Freq</name> <key>fmax</key> + <value>0.5</value> <type>real</type> </param> <param> <name>Mu</name> <key>mu</key> + <value>0.25</value> <type>real</type> </param> <param> <name>Gain Mu</name> <key>gain_mu</key> + <value>0.01</value> <type>real</type> </param> <param> <name>Omega</name> <key>omega</key> + <value>2</value> <type>real</type> </param> <param> <name>Gain Omega</name> <key>gain_omega</key> + <value>0.001</value> <type>real</type> </param> <param> <name>Omega Relative Limit</name> <key>omega_relative_limit</key> + <value>0.001</value> <type>real</type> </param> <sink> @@ -72,4 +82,5 @@ <name>out</name> <type>complex</type> </source> + </block> diff --git a/gr-digital/grc/digital_ofdm_insert_preamble.xml b/gr-digital/grc/digital_ofdm_insert_preamble.xml index 33a93058f9..9ad8fa793b 100644 --- a/gr-digital/grc/digital_ofdm_insert_preamble.xml +++ b/gr-digital/grc/digital_ofdm_insert_preamble.xml @@ -48,10 +48,16 @@ <sink> <name>flag</name> <type>byte</type> + <optional>1</optional> </sink> <source> <name>out</name> <type>complex</type> <vlen>$fft_length</vlen> </source> + <source> + <name>flag</name> + <type>byte</type> + <optional>1</optional> + </source> </block> diff --git a/gr-digital/include/digital_ofdm_insert_preamble.h b/gr-digital/include/digital_ofdm_insert_preamble.h index 6f9dae5d6b..fa44558add 100644 --- a/gr-digital/include/digital_ofdm_insert_preamble.h +++ b/gr-digital/include/digital_ofdm_insert_preamble.h @@ -88,18 +88,20 @@ private: int d_pending_flag; void enter_idle(); - void enter_preamble(); void enter_first_payload(); void enter_payload(); public: ~digital_ofdm_insert_preamble(); + void enter_preamble(); 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_DIGITAL_OFDM_INSERT_PREAMBLE_H */ diff --git a/gr-digital/lib/digital_ofdm_insert_preamble.cc b/gr-digital/lib/digital_ofdm_insert_preamble.cc index a46133643d..d94425f315 100644 --- a/gr-digital/lib/digital_ofdm_insert_preamble.cc +++ b/gr-digital/lib/digital_ofdm_insert_preamble.cc @@ -41,7 +41,7 @@ digital_ofdm_insert_preamble::digital_ofdm_insert_preamble (int fft_length, const std::vector<std::vector<gr_complex> > &preamble) : gr_block("ofdm_insert_preamble", - gr_make_io_signature2(2, 2, + gr_make_io_signature2(1, 2, sizeof(gr_complex)*fft_length, sizeof(char)), gr_make_io_signature2(1, 2, @@ -67,15 +67,21 @@ digital_ofdm_insert_preamble::~digital_ofdm_insert_preamble() { } +void digital_ofdm_insert_preamble::forecast (int noutput_items, gr_vector_int &ninput_items_required){ + ninput_items_required[0] = noutput_items; +} + int digital_ofdm_insert_preamble::general_work (int noutput_items, gr_vector_int &ninput_items_v, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items) { - int ninput_items = std::min(ninput_items_v[0], ninput_items_v[1]); + int ninput_items = ninput_items_v.size()==2?std::min(ninput_items_v[0], ninput_items_v[1]):ninput_items_v[0]; const gr_complex *in_sym = (const gr_complex *) input_items[0]; - const unsigned char *in_flag = (const unsigned char *) input_items[1]; + const unsigned char *in_flag = 0; + if (input_items.size() == 2) + in_flag = (const unsigned char *) input_items[1]; gr_complex *out_sym = (gr_complex *) output_items[0]; unsigned char *out_flag = 0; @@ -97,14 +103,14 @@ digital_ofdm_insert_preamble::general_work (int noutput_items, while (no < noutput_items && ni < ninput_items){ switch(d_state){ case ST_IDLE: - if (in_flag[ni] & 0x1) // this is first symbol of new payload + if (in_flag && in_flag[ni] & 0x1) // this is first symbol of new payload enter_preamble(); else ni++; // eat one input symbol break; case ST_PREAMBLE: - assert(in_flag[ni] & 0x1); + assert(!in_flag || in_flag[ni] & 0x1); if (d_nsymbols_output >= (int) d_preamble.size()){ // we've output all the preamble enter_first_payload(); @@ -133,7 +139,7 @@ digital_ofdm_insert_preamble::general_work (int noutput_items, break; case ST_PAYLOAD: - if (in_flag[ni] & 0x1){ // this is first symbol of a new payload + if (in_flag && in_flag[ni] & 0x1){ // this is first symbol of a new payload enter_preamble(); break; } diff --git a/gr-digital/swig/digital_ofdm_insert_preamble.i b/gr-digital/swig/digital_ofdm_insert_preamble.i index 5f7b163698..0273c7fa75 100644 --- a/gr-digital/swig/digital_ofdm_insert_preamble.i +++ b/gr-digital/swig/digital_ofdm_insert_preamble.i @@ -32,4 +32,6 @@ class digital_ofdm_insert_preamble : public gr_block protected: digital_ofdm_insert_preamble(int fft_length, const std::vector<std::vector<gr_complex> > &preamble); + public: + void enter_preamble(); }; diff --git a/grc/blocks/block_tree.xml b/grc/blocks/block_tree.xml index 18bc050bac..0b0b6854ec 100644 --- a/grc/blocks/block_tree.xml +++ b/grc/blocks/block_tree.xml @@ -61,6 +61,7 @@ <block>gr_fft_vxx</block> <block>blks2_logpwrfft_x</block> + <block>gr_vector_insert_x</block> </cat> <cat> <name>Type Conversions</name> @@ -114,6 +115,7 @@ <block>gr_unpacked_to_packed_xx</block> <block>gr_packed_to_unpacked_xx</block> <block>gr_unpack_k_bits_bb</block> + <block>gr_pack_k_bits_bb</block> <block>gr_chunks_to_symbols_xx</block> <block>gr_map_bb</block> </cat> @@ -183,6 +185,7 @@ <block>blks2_rational_resampler_xxx</block> <block>gr_fractional_interpolator_xx</block> <block>gr_keep_one_in_n</block> + <block>gr_keep_m_in_n</block> <block>gr_moving_average_xx</block> <block>gr_iqcomp_cc</block> <block>gr_dc_blocker</block> diff --git a/grc/blocks/gr_keep_m_in_n.xml b/grc/blocks/gr_keep_m_in_n.xml new file mode 100644 index 0000000000..a63ef47a66 --- /dev/null +++ b/grc/blocks/gr_keep_m_in_n.xml @@ -0,0 +1,74 @@ +<?xml version="1.0"?> +<!-- +################################################### +##Keep M in N +################################################### + --> +<block> + <name>Keep M in N</name> + <key>gr_keep_m_in_n</key> + <import>from gnuradio import gr</import> + <make>gr.keep_m_in_n($type.size, $m, $n, $offset)</make> + <callback>set_offset($offset)</callback> + <param> + <name>Type</name> + <key>type</key> + <type>enum</type> + <option> + <name>Complex</name> + <key>complex</key> + <opt>size:gr.sizeof_gr_complex</opt> + </option> + <option> + <name>Float</name> + <key>float</key> + <opt>size:gr.sizeof_float</opt> + </option> + <option> + <name>Int</name> + <key>int</key> + <opt>size:gr.sizeof_int</opt> + </option> + <option> + <name>Short</name> + <key>short</key> + <opt>size:gr.sizeof_short</opt> + </option> + <option> + <name>Byte</name> + <key>byte</key> + <opt>size:gr.sizeof_char</opt> + </option> + </param> + <param> + <name>M</name> + <key>m</key> + <value>1</value> + <type>int</type> + </param> + <param> + <name>N</name> + <key>n</key> + <value>2</value> + <type>int</type> + </param> + <param> + <name>initial offset</name> + <key>offset</key> + <value>0</value> + <type>int</type> + </param> + <check>$n > 0</check> + <check>$m > 0</check> + <check>$m < $n</check> + <sink> + <name>in</name> + <type>$type</type> + <vlen>$n</vlen> + </sink> + <source> + <name>out</name> + <type>$type</type> + <vlen>$m</vlen> + </source> +</block> diff --git a/grc/blocks/gr_pack_k_bits_bb.xml b/grc/blocks/gr_pack_k_bits_bb.xml new file mode 100644 index 0000000000..34e64a5d96 --- /dev/null +++ b/grc/blocks/gr_pack_k_bits_bb.xml @@ -0,0 +1,30 @@ +<?xml version="1.0"?> +<!-- +################################################### +##Pack K Bits +################################################### + --> +<block> + <name>Pack K Bits</name> + <key>gr_pack_k_bits_bb</key> + <import>from gnuradio import gr</import> + <make>gr.pack_k_bits_bb($k)</make> + <param> + <name>K</name> + <key>k</key> + <type>int</type> + </param> + <sink> + <name>in</name> + <type>byte</type> + </sink> + <source> + <name>out</name> + <type>byte</type> + </source> + + <doc> + Pack K unpacked bits (one bit per byte) into a single packed byte containing k bits and 8 - k zeros. + </doc> + +</block> diff --git a/grc/blocks/gr_vector_insert_x.xml b/grc/blocks/gr_vector_insert_x.xml new file mode 100644 index 0000000000..f9ce1f6544 --- /dev/null +++ b/grc/blocks/gr_vector_insert_x.xml @@ -0,0 +1,80 @@ +<?xml version="1.0"?> +<!-- +################################################### +##Vector Source +################################################### + --> +<block> + <name>Vector Insert</name> + <key>gr_vector_insert_x</key> + <import>from gnuradio import gr</import> + <make>gr.vector_insert_$(type.fcn)($vector, $period, $offset)</make> + <param> + <name>Output Type</name> + <key>type</key> + <type>enum</type> + <option> + <name>Byte</name> + <key>byte</key> + <opt>fcn:b</opt> + <opt>vec_type:int_vector</opt> + </option> + <option> + <name>Complex</name> + <key>complex</key> + <opt>fcn:c</opt> + <opt>vec_type:complex_vector</opt> + </option> + <option> + <name>Float</name> + <key>float</key> + <opt>fcn:f</opt> + <opt>vec_type:real_vector</opt> + </option> + <option> + <name>Int</name> + <key>int</key> + <opt>fcn:i</opt> + <opt>vec_type:int_vector</opt> + </option> + <option> + <name>Short</name> + <key>short</key> + <opt>fcn:s</opt> + <opt>vec_type:int_vector</opt> + </option> + </param> + <param> + <name>Vector</name> + <key>vector</key> + <value>0, 0, 0</value> + <type>$type.vec_type</type> + </param> + <param> + <name>Periodicity</name> + <key>period</key> + <value>100</value> + <type>int</type> + </param> + <param> + <name>Offset</name> + <key>offset</key> + <value>0</value> + <type>int</type> + </param> + <sink> + <name>in</name> + <type>$type</type> + </sink> + <source> + <name>out</name> + <type>$type</type> + </source> + + <doc> + Periodicity, the length of the periodicity at which the vector should be inserted at the output. + (i.e. one vector for every N output items) + + Offset sepcifies where in the cycle period we should begin at. + </doc> +</block> -- cgit v1.2.3 From 9dc190127f3cc6f4688feaac514a0b887c531740 Mon Sep 17 00:00:00 2001 From: Tom Rondeau <trondeau@vt.edu> Date: Thu, 7 Jun 2012 16:43:10 -0400 Subject: Some really minor nits. --- gnuradio-core/src/lib/general/gr_keep_m_in_n.cc | 33 ++++++++--------- gnuradio-core/src/lib/general/gr_keep_m_in_n.h | 2 +- gnuradio-core/src/lib/general/gr_keep_m_in_n.i | 2 +- gnuradio-core/src/lib/general/gr_pack_k_bits_bb.cc | 34 +++++++++--------- gnuradio-core/src/lib/general/gr_pack_k_bits_bb.h | 2 +- .../src/lib/gengen/gr_vector_insert_X.cc.t | 42 +++++++++++----------- .../src/lib/gengen/gr_vector_insert_X.h.t | 16 ++++----- gr-digital/lib/digital_ofdm_insert_preamble.cc | 19 +++++----- 8 files changed, 76 insertions(+), 74 deletions(-) (limited to 'gnuradio-core/src/lib') diff --git a/gnuradio-core/src/lib/general/gr_keep_m_in_n.cc b/gnuradio-core/src/lib/general/gr_keep_m_in_n.cc index f17c3e00d7..56f5931fd5 100644 --- a/gnuradio-core/src/lib/general/gr_keep_m_in_n.cc +++ b/gnuradio-core/src/lib/general/gr_keep_m_in_n.cc @@ -30,9 +30,9 @@ #include <stdio.h> gr_keep_m_in_n_sptr -gr_make_keep_m_in_n (size_t item_size, int m, int n, int offset) +gr_make_keep_m_in_n(size_t item_size, int m, int n, int offset) { - return gnuradio::get_initial_sptr(new gr_keep_m_in_n (item_size, m, n, offset)); + return gnuradio::get_initial_sptr(new gr_keep_m_in_n(item_size, m, n, offset)); } @@ -40,16 +40,16 @@ gr_make_keep_m_in_n (size_t item_size, int m, int n, int offset) * * offset = 0, starts with 0th item * offset = 1, starts with 1st item, etc... -* +* * we take m items out of each n */ -gr_keep_m_in_n::gr_keep_m_in_n (size_t item_size, int m, int n, int offset) +gr_keep_m_in_n::gr_keep_m_in_n(size_t item_size, int m, int n, int offset) : gr_sync_block ("keep_m_in_n", - gr_make_io_signature (1, 1, n*item_size), - gr_make_io_signature (1, 1, m*item_size)), + gr_make_io_signature(1, 1, n*item_size), + gr_make_io_signature(1, 1, m*item_size)), d_n(n), d_m(m), - d_offset( offset ) + d_offset(offset) { // sanity checking assert(d_m > 0); @@ -59,27 +59,28 @@ gr_keep_m_in_n::gr_keep_m_in_n (size_t item_size, int m, int n, int offset) } -void gr_keep_m_in_n::set_offset(int offset){ +void gr_keep_m_in_n::set_offset(int offset) +{ d_offset = offset; } int -gr_keep_m_in_n::work (int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) +gr_keep_m_in_n::work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) { - uint8_t* out = (uint8_t*) output_items[0]; - const uint8_t* in = (const uint8_t*) input_items[0]; + uint8_t* out = (uint8_t*)output_items[0]; + const uint8_t* in = (const uint8_t*)input_items[0]; int in_item( input_signature()->sizeof_stream_item(0) ); int out_item( output_signature()->sizeof_stream_item(0) ); int single_size = in_item/d_n; // iterate over data blocks of size {n, input : m, output} - for(int i=0; i<noutput_items; i++){ - memcpy( &out[out_item*i], &in[in_item*i + single_size*d_offset], out_item); - } + for(int i = 0; i < noutput_items; i++) { + memcpy(&out[out_item*i], &in[in_item*i + single_size*d_offset], out_item); + } return noutput_items; } diff --git a/gnuradio-core/src/lib/general/gr_keep_m_in_n.h b/gnuradio-core/src/lib/general/gr_keep_m_in_n.h index f9d5a268bc..e627ca0ea4 100644 --- a/gnuradio-core/src/lib/general/gr_keep_m_in_n.h +++ b/gnuradio-core/src/lib/general/gr_keep_m_in_n.h @@ -29,7 +29,7 @@ class gr_keep_m_in_n; typedef boost::shared_ptr<gr_keep_m_in_n> gr_keep_m_in_n_sptr; -GR_CORE_API gr_keep_m_in_n_sptr +GR_CORE_API gr_keep_m_in_n_sptr gr_make_keep_m_in_n (size_t item_size, int m, int n, int offset); diff --git a/gnuradio-core/src/lib/general/gr_keep_m_in_n.i b/gnuradio-core/src/lib/general/gr_keep_m_in_n.i index cb5c636835..de89cec2ce 100644 --- a/gnuradio-core/src/lib/general/gr_keep_m_in_n.i +++ b/gnuradio-core/src/lib/general/gr_keep_m_in_n.i @@ -22,7 +22,7 @@ GR_SWIG_BLOCK_MAGIC(gr,keep_m_in_n) -gr_keep_m_in_n_sptr +gr_keep_m_in_n_sptr gr_make_keep_m_in_n (size_t itemsize, int m, int n, int offset); class gr_keep_m_in_n : public gr_sync_block diff --git a/gnuradio-core/src/lib/general/gr_pack_k_bits_bb.cc b/gnuradio-core/src/lib/general/gr_pack_k_bits_bb.cc index 0237a4d691..bd51c2ec5c 100644 --- a/gnuradio-core/src/lib/general/gr_pack_k_bits_bb.cc +++ b/gnuradio-core/src/lib/general/gr_pack_k_bits_bb.cc @@ -29,41 +29,41 @@ #include <stdexcept> #include <iostream> -gr_pack_k_bits_bb_sptr gr_make_pack_k_bits_bb (unsigned k) +gr_pack_k_bits_bb_sptr gr_make_pack_k_bits_bb(unsigned k) { - return gnuradio::get_initial_sptr(new gr_pack_k_bits_bb (k)); + return gnuradio::get_initial_sptr(new gr_pack_k_bits_bb(k)); } gr_pack_k_bits_bb::gr_pack_k_bits_bb (unsigned k) - : gr_sync_decimator ("pack_k_bits_bb", - gr_make_io_signature (1, 1, sizeof (unsigned char)), - gr_make_io_signature (1, 1, sizeof (unsigned char)), - k), + : gr_sync_decimator("pack_k_bits_bb", + gr_make_io_signature (1, 1, sizeof(unsigned char)), + gr_make_io_signature (1, 1, sizeof(unsigned char)), + k), d_k (k) { if (d_k == 0) - throw std::out_of_range ("interpolation must be > 0"); + throw std::out_of_range("interpolation must be > 0"); } -gr_pack_k_bits_bb::~gr_pack_k_bits_bb () +gr_pack_k_bits_bb::~gr_pack_k_bits_bb() { } int -gr_pack_k_bits_bb::work (int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) +gr_pack_k_bits_bb::work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) { - const unsigned char *in = (const unsigned char *) input_items[0]; - unsigned char *out = (unsigned char *) output_items[0]; + const unsigned char *in = (const unsigned char *)input_items[0]; + unsigned char *out = (unsigned char *)output_items[0]; - for (int i = 0; i < noutput_items; i++){ + for(int i = 0; i < noutput_items; i++) { out[i] = 0x00; - for (unsigned int j = 0; j < d_k; j++){ - out[i] |= (0x01 & in[i*d_k+j])<<j; + for(unsigned int j = 0; j < d_k; j++) { + out[i] |= (0x01 & in[i*d_k+j])<<j; } } - + return noutput_items; } diff --git a/gnuradio-core/src/lib/general/gr_pack_k_bits_bb.h b/gnuradio-core/src/lib/general/gr_pack_k_bits_bb.h index 00b8f8f13d..caf6d79925 100644 --- a/gnuradio-core/src/lib/general/gr_pack_k_bits_bb.h +++ b/gnuradio-core/src/lib/general/gr_pack_k_bits_bb.h @@ -33,7 +33,7 @@ GR_CORE_API gr_pack_k_bits_bb_sptr gr_make_pack_k_bits_bb (unsigned k); class gr_pack_k_bits_bb; /*! - * \brief Converts a byte with k relevent bits to k output bytes with 1 bit in the LSB. + * \brief Converts a stream of bytes with 1 bit in the LSB to a byte with k relevent bits. * \ingroup converter_blk */ class GR_CORE_API gr_pack_k_bits_bb : public gr_sync_decimator diff --git a/gnuradio-core/src/lib/gengen/gr_vector_insert_X.cc.t b/gnuradio-core/src/lib/gengen/gr_vector_insert_X.cc.t index 15e19edb02..75ed526adc 100644 --- a/gnuradio-core/src/lib/gengen/gr_vector_insert_X.cc.t +++ b/gnuradio-core/src/lib/gengen/gr_vector_insert_X.cc.t @@ -32,13 +32,13 @@ #include <stdio.h> -@NAME@::@NAME@ (const std::vector<@TYPE@> &data, int periodicity, int offset) - : gr_block ("@BASE_NAME@", - gr_make_io_signature (1, 1, sizeof (@TYPE@)), - gr_make_io_signature (1, 1, sizeof (@TYPE@))), - d_data (data), - d_offset (offset), - d_periodicity (periodicity) +@NAME@::@NAME@(const std::vector<@TYPE@> &data, int periodicity, int offset) + : gr_block("@BASE_NAME@", + gr_make_io_signature (1, 1, sizeof(@TYPE@)), + gr_make_io_signature (1, 1, sizeof(@TYPE@))), + d_data(data), + d_offset(offset), + d_periodicity(periodicity) { //printf("INITIAL: periodicity = %d, offset = %d\n", periodicity, offset); // some sanity checks @@ -48,22 +48,22 @@ } int -@NAME@::general_work (int noutput_items, +@NAME@::general_work(int noutput_items, gr_vector_int &ninput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items) { - @TYPE@ *out = (@TYPE@ *) output_items[0]; - const @TYPE@ *in = (const @TYPE@ *) input_items[0]; + @TYPE@ *out = (@TYPE@ *)output_items[0]; + const @TYPE@ *in = (const @TYPE@ *)input_items[0]; int ii(0), oo(0); - while( (oo < noutput_items) && (ii < ninput_items[0]) ){ + while((oo < noutput_items) && (ii < ninput_items[0])) { //printf("oo = %d, ii = %d, d_offset = %d, noutput_items = %d, ninput_items[0] = %d", oo, ii, d_offset, noutput_items, ninput_items[0]); //printf(", d_periodicity = %d\n", d_periodicity); - if( d_offset >= ((int)d_data.size()) ){ // if we are in the copy region + if(d_offset >= ((int)d_data.size())) { // if we are in the copy region int max_copy = std::min( std::min( noutput_items - oo, ninput_items[0] - ii ), d_periodicity - d_offset ); //printf("copy %d from input\n", max_copy); memcpy( &out[oo], &in[ii], sizeof(@TYPE@)*max_copy ); @@ -72,24 +72,24 @@ int oo += max_copy; d_offset = (d_offset + max_copy)%d_periodicity; - } else { // if we are in the insertion region + } + else { // if we are in the insertion region int max_copy = std::min( noutput_items - oo, ((int)d_data.size()) - d_offset ); //printf("copy %d from d_data[%d] to out[%d]\n", max_copy, d_offset, oo); memcpy( &out[oo], &d_data[d_offset], sizeof(@TYPE@)*max_copy ); //printf(" * memcpy returned.\n"); - oo += max_copy; + oo += max_copy; d_offset = (d_offset + max_copy)%d_periodicity; //printf(" ## (inelse) oo = %d, d_offset = %d\n", oo, d_offset); - } + } //printf(" # exit else, on to next loop.\n"); - } - //printf(" # got out of loop\n"); - - //printf("consume = %d, produce = %d\n", ii, oo); - consume_each(ii); - return oo; + } + //printf(" # got out of loop\n"); + //printf("consume = %d, produce = %d\n", ii, oo); + consume_each(ii); + return oo; } @NAME@_sptr diff --git a/gnuradio-core/src/lib/gengen/gr_vector_insert_X.h.t b/gnuradio-core/src/lib/gengen/gr_vector_insert_X.h.t index 76c6b7a5dc..a7de7831bb 100644 --- a/gnuradio-core/src/lib/gengen/gr_vector_insert_X.h.t +++ b/gnuradio-core/src/lib/gengen/gr_vector_insert_X.h.t @@ -37,25 +37,25 @@ typedef boost::shared_ptr<@NAME@> @NAME@_sptr; */ class @NAME@ : public gr_block { - friend GR_CORE_API @NAME@_sptr - gr_make_@BASE_NAME@ (const std::vector<@TYPE@> &data, int periodicity, int offset); + friend GR_CORE_API @NAME@_sptr + gr_make_@BASE_NAME@(const std::vector<@TYPE@> &data, int periodicity, int offset); std::vector<@TYPE@> d_data; int d_offset; int d_periodicity; - @NAME@ (const std::vector<@TYPE@> &data, int periodicity, int offset); + @NAME@(const std::vector<@TYPE@> &data, int periodicity, int offset); public: void rewind() {d_offset=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); + 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); void set_data(const std::vector<@TYPE@> &data){ d_data = data; rewind(); } }; GR_CORE_API @NAME@_sptr -gr_make_@BASE_NAME@ (const std::vector<@TYPE@> &data, int periodicity, int offset=0); +gr_make_@BASE_NAME@(const std::vector<@TYPE@> &data, int periodicity, int offset=0); #endif diff --git a/gr-digital/lib/digital_ofdm_insert_preamble.cc b/gr-digital/lib/digital_ofdm_insert_preamble.cc index d94425f315..e0449b50bd 100644 --- a/gr-digital/lib/digital_ofdm_insert_preamble.cc +++ b/gr-digital/lib/digital_ofdm_insert_preamble.cc @@ -54,8 +54,8 @@ digital_ofdm_insert_preamble::digital_ofdm_insert_preamble d_pending_flag(0) { // sanity check preamble symbols - for (size_t i = 0; i < d_preamble.size(); i++){ - if (d_preamble[i].size() != (size_t) d_fft_length) + for(size_t i = 0; i < d_preamble.size(); i++) { + if(d_preamble[i].size() != (size_t) d_fft_length) throw std::invalid_argument("digital_ofdm_insert_preamble: invalid length for preamble symbol"); } @@ -67,20 +67,21 @@ digital_ofdm_insert_preamble::~digital_ofdm_insert_preamble() { } -void digital_ofdm_insert_preamble::forecast (int noutput_items, gr_vector_int &ninput_items_required){ - ninput_items_required[0] = noutput_items; +void digital_ofdm_insert_preamble::forecast (int noutput_items, gr_vector_int &ninput_items_required) +{ + ninput_items_required[0] = noutput_items; } int -digital_ofdm_insert_preamble::general_work (int noutput_items, - gr_vector_int &ninput_items_v, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) +digital_ofdm_insert_preamble::general_work(int noutput_items, + gr_vector_int &ninput_items_v, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) { int ninput_items = ninput_items_v.size()==2?std::min(ninput_items_v[0], ninput_items_v[1]):ninput_items_v[0]; const gr_complex *in_sym = (const gr_complex *) input_items[0]; const unsigned char *in_flag = 0; - if (input_items.size() == 2) + if (input_items.size() == 2) in_flag = (const unsigned char *) input_items[1]; gr_complex *out_sym = (gr_complex *) output_items[0]; -- cgit v1.2.3 From 9038efc67028ac6bab05bfd60a8de7e6c2ba3fd7 Mon Sep 17 00:00:00 2001 From: Tom Rondeau <trondeau@vt.edu> Date: Thu, 7 Jun 2012 16:56:01 -0400 Subject: fixed copyright dates. --- gnuradio-core/src/lib/general/gr_head.h | 2 +- gnuradio-core/src/lib/general/gr_head.i | 2 +- gnuradio-core/src/lib/general/gr_keep_m_in_n.cc | 2 +- gnuradio-core/src/lib/general/gr_keep_m_in_n.h | 2 +- gnuradio-core/src/lib/general/gr_keep_m_in_n.i | 2 +- gnuradio-core/src/lib/general/gr_pack_k_bits_bb.cc | 2 +- gnuradio-core/src/lib/general/gr_pack_k_bits_bb.h | 2 +- gnuradio-core/src/lib/general/gr_pack_k_bits_bb.i | 2 +- gnuradio-core/src/lib/gengen/gr_vector_insert_X.cc.t | 2 +- gnuradio-core/src/lib/gengen/gr_vector_insert_X.h.t | 2 +- gnuradio-core/src/lib/gengen/gr_vector_insert_X.i.t | 2 +- gnuradio-core/src/lib/gengen/gr_vector_source_X.h.t | 2 +- gnuradio-core/src/lib/gengen/gr_vector_source_X.i.t | 2 +- gnuradio-core/src/python/gnuradio/gr/qa_vector_insert.py | 2 +- gr-digital/lib/digital_ofdm_insert_preamble.cc | 2 +- 15 files changed, 15 insertions(+), 15 deletions(-) (limited to 'gnuradio-core/src/lib') diff --git a/gnuradio-core/src/lib/general/gr_head.h b/gnuradio-core/src/lib/general/gr_head.h index 4471d75ea8..48415892dd 100644 --- a/gnuradio-core/src/lib/general/gr_head.h +++ b/gnuradio-core/src/lib/general/gr_head.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2004,2009 Free Software Foundation, Inc. + * Copyright 2004,2009,2012 Free Software Foundation, Inc. * * This file is part of GNU Radio * diff --git a/gnuradio-core/src/lib/general/gr_head.i b/gnuradio-core/src/lib/general/gr_head.i index d59dd176a7..11f3331d47 100644 --- a/gnuradio-core/src/lib/general/gr_head.i +++ b/gnuradio-core/src/lib/general/gr_head.i @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2004,2009 Free Software Foundation, Inc. + * Copyright 2004,2009,2012 Free Software Foundation, Inc. * * This file is part of GNU Radio * diff --git a/gnuradio-core/src/lib/general/gr_keep_m_in_n.cc b/gnuradio-core/src/lib/general/gr_keep_m_in_n.cc index 56f5931fd5..760a01c8c7 100644 --- a/gnuradio-core/src/lib/general/gr_keep_m_in_n.cc +++ b/gnuradio-core/src/lib/general/gr_keep_m_in_n.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2004,2010 Free Software Foundation, Inc. + * Copyright 2012 Free Software Foundation, Inc. * * This file is part of GNU Radio * diff --git a/gnuradio-core/src/lib/general/gr_keep_m_in_n.h b/gnuradio-core/src/lib/general/gr_keep_m_in_n.h index e627ca0ea4..4783aaba3a 100644 --- a/gnuradio-core/src/lib/general/gr_keep_m_in_n.h +++ b/gnuradio-core/src/lib/general/gr_keep_m_in_n.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2004 Free Software Foundation, Inc. + * Copyright 2012 Free Software Foundation, Inc. * * This file is part of GNU Radio * diff --git a/gnuradio-core/src/lib/general/gr_keep_m_in_n.i b/gnuradio-core/src/lib/general/gr_keep_m_in_n.i index de89cec2ce..f280c0248a 100644 --- a/gnuradio-core/src/lib/general/gr_keep_m_in_n.i +++ b/gnuradio-core/src/lib/general/gr_keep_m_in_n.i @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2004 Free Software Foundation, Inc. + * Copyright 2012 Free Software Foundation, Inc. * * This file is part of GNU Radio * diff --git a/gnuradio-core/src/lib/general/gr_pack_k_bits_bb.cc b/gnuradio-core/src/lib/general/gr_pack_k_bits_bb.cc index bd51c2ec5c..4bd7ca4bb5 100644 --- a/gnuradio-core/src/lib/general/gr_pack_k_bits_bb.cc +++ b/gnuradio-core/src/lib/general/gr_pack_k_bits_bb.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2005,2010 Free Software Foundation, Inc. + * Copyright 2012 Free Software Foundation, Inc. * * This file is part of GNU Radio * diff --git a/gnuradio-core/src/lib/general/gr_pack_k_bits_bb.h b/gnuradio-core/src/lib/general/gr_pack_k_bits_bb.h index caf6d79925..8e1508c78b 100644 --- a/gnuradio-core/src/lib/general/gr_pack_k_bits_bb.h +++ b/gnuradio-core/src/lib/general/gr_pack_k_bits_bb.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2006 Free Software Foundation, Inc. + * Copyright 2012 Free Software Foundation, Inc. * * This file is part of GNU Radio * diff --git a/gnuradio-core/src/lib/general/gr_pack_k_bits_bb.i b/gnuradio-core/src/lib/general/gr_pack_k_bits_bb.i index 4711915d79..6ae2095ec7 100644 --- a/gnuradio-core/src/lib/general/gr_pack_k_bits_bb.i +++ b/gnuradio-core/src/lib/general/gr_pack_k_bits_bb.i @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2006 Free Software Foundation, Inc. + * Copyright 2012 Free Software Foundation, Inc. * * This file is part of GNU Radio * diff --git a/gnuradio-core/src/lib/gengen/gr_vector_insert_X.cc.t b/gnuradio-core/src/lib/gengen/gr_vector_insert_X.cc.t index 75ed526adc..37963cdfee 100644 --- a/gnuradio-core/src/lib/gengen/gr_vector_insert_X.cc.t +++ b/gnuradio-core/src/lib/gengen/gr_vector_insert_X.cc.t @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2004,2008,2010 Free Software Foundation, Inc. + * Copyright 2012 Free Software Foundation, Inc. * * This file is part of GNU Radio * diff --git a/gnuradio-core/src/lib/gengen/gr_vector_insert_X.h.t b/gnuradio-core/src/lib/gengen/gr_vector_insert_X.h.t index a7de7831bb..26f851700d 100644 --- a/gnuradio-core/src/lib/gengen/gr_vector_insert_X.h.t +++ b/gnuradio-core/src/lib/gengen/gr_vector_insert_X.h.t @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2004,2008 Free Software Foundation, Inc. + * Copyright 2012 Free Software Foundation, Inc. * * This file is part of GNU Radio * diff --git a/gnuradio-core/src/lib/gengen/gr_vector_insert_X.i.t b/gnuradio-core/src/lib/gengen/gr_vector_insert_X.i.t index ce951b3341..f3341eec4f 100644 --- a/gnuradio-core/src/lib/gengen/gr_vector_insert_X.i.t +++ b/gnuradio-core/src/lib/gengen/gr_vector_insert_X.i.t @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2004,2008 Free Software Foundation, Inc. + * Copyright 2012 Free Software Foundation, Inc. * * This file is part of GNU Radio * diff --git a/gnuradio-core/src/lib/gengen/gr_vector_source_X.h.t b/gnuradio-core/src/lib/gengen/gr_vector_source_X.h.t index 89f07721d5..fe02c1346f 100644 --- a/gnuradio-core/src/lib/gengen/gr_vector_source_X.h.t +++ b/gnuradio-core/src/lib/gengen/gr_vector_source_X.h.t @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2004,2008 Free Software Foundation, Inc. + * Copyright 2004,2008,2012 Free Software Foundation, Inc. * * This file is part of GNU Radio * diff --git a/gnuradio-core/src/lib/gengen/gr_vector_source_X.i.t b/gnuradio-core/src/lib/gengen/gr_vector_source_X.i.t index c821e12fff..4986c68a35 100644 --- a/gnuradio-core/src/lib/gengen/gr_vector_source_X.i.t +++ b/gnuradio-core/src/lib/gengen/gr_vector_source_X.i.t @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2004,2008 Free Software Foundation, Inc. + * Copyright 2004,2008,2012 Free Software Foundation, Inc. * * This file is part of GNU Radio * diff --git a/gnuradio-core/src/python/gnuradio/gr/qa_vector_insert.py b/gnuradio-core/src/python/gnuradio/gr/qa_vector_insert.py index 7ab8e701aa..acc06dfded 100755 --- a/gnuradio-core/src/python/gnuradio/gr/qa_vector_insert.py +++ b/gnuradio-core/src/python/gnuradio/gr/qa_vector_insert.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -# Copyright 2008,2010 Free Software Foundation, Inc. +# Copyright 2012 Free Software Foundation, Inc. # # This file is part of GNU Radio # diff --git a/gr-digital/lib/digital_ofdm_insert_preamble.cc b/gr-digital/lib/digital_ofdm_insert_preamble.cc index e0449b50bd..72b9e82a82 100644 --- a/gr-digital/lib/digital_ofdm_insert_preamble.cc +++ b/gr-digital/lib/digital_ofdm_insert_preamble.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2007,2010,2011 Free Software Foundation, Inc. + * Copyright 2007,2010-2012 Free Software Foundation, Inc. * * This file is part of GNU Radio * -- cgit v1.2.3 From ec30d89449f48fdd2f88420b4c87aba2e1a5abd1 Mon Sep 17 00:00:00 2001 From: Tom Rondeau <trondeau@vt.edu> Date: Sun, 10 Jun 2012 12:43:06 -0400 Subject: volk: make sure the alignment call for a block passes at least 1. For machines with an alignment of 1, the blocks were truncating the aligment to 0. This makes sure that it gets set to a minimum of 1. --- docs/doxygen/other/volk_guide.dox | 2 +- gnuradio-core/src/lib/general/gr_add_ff.cc | 2 +- gnuradio-core/src/lib/general/gr_char_to_float.cc | 2 +- gnuradio-core/src/lib/general/gr_char_to_short.cc | 2 +- gnuradio-core/src/lib/general/gr_complex_to_xxx.cc | 12 ++++++------ gnuradio-core/src/lib/general/gr_conjugate_cc.cc | 2 +- gnuradio-core/src/lib/general/gr_float_to_char.cc | 2 +- gnuradio-core/src/lib/general/gr_float_to_int.cc | 2 +- gnuradio-core/src/lib/general/gr_float_to_short.cc | 2 +- gnuradio-core/src/lib/general/gr_int_to_float.cc | 2 +- gnuradio-core/src/lib/general/gr_multiply_cc.cc | 6 +++--- gnuradio-core/src/lib/general/gr_multiply_conjugate_cc.cc | 6 +++--- gnuradio-core/src/lib/general/gr_multiply_const_cc.cc | 6 +++--- gnuradio-core/src/lib/general/gr_multiply_const_ff.cc | 6 +++--- gnuradio-core/src/lib/general/gr_multiply_ff.cc | 2 +- gnuradio-core/src/lib/general/gr_short_to_char.cc | 2 +- gnuradio-core/src/lib/general/gr_short_to_float.cc | 2 +- 17 files changed, 30 insertions(+), 30 deletions(-) (limited to 'gnuradio-core/src/lib') diff --git a/docs/doxygen/other/volk_guide.dox b/docs/doxygen/other/volk_guide.dox index 24882ed1a6..0e444ebbaf 100644 --- a/docs/doxygen/other/volk_guide.dox +++ b/docs/doxygen/other/volk_guide.dox @@ -63,7 +63,7 @@ calls with: \code const int alignment_multiple = volk_get_alignment() / output_item_size; - set_alignment(alignment_multiple); + set_alignment(std::max(1,alignment_multiple)); \endcode The Volk function 'volk_get_alignment' provides the alignment of the diff --git a/gnuradio-core/src/lib/general/gr_add_ff.cc b/gnuradio-core/src/lib/general/gr_add_ff.cc index 2e45673d3b..5f6676bb7b 100644 --- a/gnuradio-core/src/lib/general/gr_add_ff.cc +++ b/gnuradio-core/src/lib/general/gr_add_ff.cc @@ -42,7 +42,7 @@ gr_add_ff::gr_add_ff (size_t vlen) { const int alignment_multiple = volk_get_alignment() / sizeof(float); - set_alignment(alignment_multiple); + set_alignment(std::max(1,alignment_multiple)); } int diff --git a/gnuradio-core/src/lib/general/gr_char_to_float.cc b/gnuradio-core/src/lib/general/gr_char_to_float.cc index aec7ad8522..f63aa5b169 100644 --- a/gnuradio-core/src/lib/general/gr_char_to_float.cc +++ b/gnuradio-core/src/lib/general/gr_char_to_float.cc @@ -42,7 +42,7 @@ gr_char_to_float::gr_char_to_float (size_t vlen, float scale) { const int alignment_multiple = volk_get_alignment() / sizeof(float); - set_alignment(alignment_multiple); + set_alignment(std::max(1,alignment_multiple)); } float diff --git a/gnuradio-core/src/lib/general/gr_char_to_short.cc b/gnuradio-core/src/lib/general/gr_char_to_short.cc index c20d6cd888..bb9bd8909e 100644 --- a/gnuradio-core/src/lib/general/gr_char_to_short.cc +++ b/gnuradio-core/src/lib/general/gr_char_to_short.cc @@ -42,7 +42,7 @@ gr_char_to_short::gr_char_to_short (size_t vlen) { const int alignment_multiple = volk_get_alignment() / sizeof(char); - set_alignment(alignment_multiple); + set_alignment(std::max(1,alignment_multiple)); } int diff --git a/gnuradio-core/src/lib/general/gr_complex_to_xxx.cc b/gnuradio-core/src/lib/general/gr_complex_to_xxx.cc index 3b1fbf9acd..cdf6d7f3a6 100644 --- a/gnuradio-core/src/lib/general/gr_complex_to_xxx.cc +++ b/gnuradio-core/src/lib/general/gr_complex_to_xxx.cc @@ -45,7 +45,7 @@ gr_complex_to_float::gr_complex_to_float (unsigned int vlen) { const int alignment_multiple = volk_get_alignment() / sizeof(float); - set_alignment(alignment_multiple); + set_alignment(std::max(1,alignment_multiple)); } int @@ -106,7 +106,7 @@ gr_complex_to_real::gr_complex_to_real (unsigned int vlen) { const int alignment_multiple = volk_get_alignment() / sizeof(float); - set_alignment(alignment_multiple); + set_alignment(std::max(1,alignment_multiple)); } int @@ -146,7 +146,7 @@ gr_complex_to_imag::gr_complex_to_imag (unsigned int vlen) { const int alignment_multiple = volk_get_alignment() / sizeof(float); - set_alignment(alignment_multiple); + set_alignment(std::max(1,alignment_multiple)); } int @@ -186,7 +186,7 @@ gr_complex_to_mag::gr_complex_to_mag (unsigned int vlen) { const int alignment_multiple = volk_get_alignment() / sizeof(float); - set_alignment(alignment_multiple); + set_alignment(std::max(1,alignment_multiple)); } int @@ -220,7 +220,7 @@ gr_complex_to_mag_squared::gr_complex_to_mag_squared (unsigned int vlen) { const int alignment_multiple = volk_get_alignment() / sizeof(float); - set_alignment(alignment_multiple); + set_alignment(std::max(1,alignment_multiple)); } int @@ -258,7 +258,7 @@ gr_complex_to_arg::gr_complex_to_arg (unsigned int vlen) { const int alignment_multiple = volk_get_alignment() / sizeof(float); - set_alignment(alignment_multiple); + set_alignment(std::max(1,alignment_multiple)); } int diff --git a/gnuradio-core/src/lib/general/gr_conjugate_cc.cc b/gnuradio-core/src/lib/general/gr_conjugate_cc.cc index aaa7f490c7..94ac3e162b 100644 --- a/gnuradio-core/src/lib/general/gr_conjugate_cc.cc +++ b/gnuradio-core/src/lib/general/gr_conjugate_cc.cc @@ -43,7 +43,7 @@ gr_conjugate_cc::gr_conjugate_cc () { const int alignment_multiple = volk_get_alignment() / sizeof(gr_complex); - set_alignment(alignment_multiple); + set_alignment(std::max(1,alignment_multiple)); } int diff --git a/gnuradio-core/src/lib/general/gr_float_to_char.cc b/gnuradio-core/src/lib/general/gr_float_to_char.cc index 3602ad7453..d67ded3ea6 100644 --- a/gnuradio-core/src/lib/general/gr_float_to_char.cc +++ b/gnuradio-core/src/lib/general/gr_float_to_char.cc @@ -42,7 +42,7 @@ gr_float_to_char::gr_float_to_char (size_t vlen, float scale) { const int alignment_multiple = volk_get_alignment() / sizeof(char); - set_alignment(alignment_multiple); + set_alignment(std::max(1,alignment_multiple)); } float diff --git a/gnuradio-core/src/lib/general/gr_float_to_int.cc b/gnuradio-core/src/lib/general/gr_float_to_int.cc index bd3cd6a3b3..43b8518956 100644 --- a/gnuradio-core/src/lib/general/gr_float_to_int.cc +++ b/gnuradio-core/src/lib/general/gr_float_to_int.cc @@ -43,7 +43,7 @@ gr_float_to_int::gr_float_to_int (size_t vlen, float scale) { const int alignment_multiple = volk_get_alignment() / sizeof(int); - set_alignment(alignment_multiple); + set_alignment(std::max(1,alignment_multiple)); } float diff --git a/gnuradio-core/src/lib/general/gr_float_to_short.cc b/gnuradio-core/src/lib/general/gr_float_to_short.cc index 07995c99aa..ab720168bf 100644 --- a/gnuradio-core/src/lib/general/gr_float_to_short.cc +++ b/gnuradio-core/src/lib/general/gr_float_to_short.cc @@ -42,7 +42,7 @@ gr_float_to_short::gr_float_to_short (size_t vlen, float scale) { const int alignment_multiple = volk_get_alignment() / sizeof(short); - set_alignment(alignment_multiple); + set_alignment(std::max(1,alignment_multiple)); } float diff --git a/gnuradio-core/src/lib/general/gr_int_to_float.cc b/gnuradio-core/src/lib/general/gr_int_to_float.cc index a284853055..a7fb24dc69 100644 --- a/gnuradio-core/src/lib/general/gr_int_to_float.cc +++ b/gnuradio-core/src/lib/general/gr_int_to_float.cc @@ -42,7 +42,7 @@ gr_int_to_float::gr_int_to_float (size_t vlen, float scale) { const int alignment_multiple = volk_get_alignment() / sizeof(float); - set_alignment(alignment_multiple); + set_alignment(std::max(1,alignment_multiple)); } int diff --git a/gnuradio-core/src/lib/general/gr_multiply_cc.cc b/gnuradio-core/src/lib/general/gr_multiply_cc.cc index 32c44a19e4..4a3751419f 100644 --- a/gnuradio-core/src/lib/general/gr_multiply_cc.cc +++ b/gnuradio-core/src/lib/general/gr_multiply_cc.cc @@ -40,9 +40,9 @@ gr_multiply_cc::gr_multiply_cc (size_t vlen) gr_make_io_signature (1, 1, sizeof (gr_complex)*vlen)), d_vlen(vlen) { - const int alignment_multiple = - volk_get_alignment() / sizeof(gr_complex); - set_alignment(alignment_multiple); + const int alignment_multiple = + volk_get_alignment() / sizeof(gr_complex); + set_alignment(std::max(1,alignment_multiple)); } int diff --git a/gnuradio-core/src/lib/general/gr_multiply_conjugate_cc.cc b/gnuradio-core/src/lib/general/gr_multiply_conjugate_cc.cc index 53ede2eeda..0c5fb4a926 100644 --- a/gnuradio-core/src/lib/general/gr_multiply_conjugate_cc.cc +++ b/gnuradio-core/src/lib/general/gr_multiply_conjugate_cc.cc @@ -40,9 +40,9 @@ gr_multiply_conjugate_cc::gr_multiply_conjugate_cc (size_t vlen) gr_make_io_signature (1, 1, sizeof (gr_complex)*vlen)), d_vlen(vlen) { - const int alignment_multiple = - volk_get_alignment() / sizeof(gr_complex); - set_alignment(alignment_multiple); + const int alignment_multiple = + volk_get_alignment() / sizeof(gr_complex); + set_alignment(std::max(1,alignment_multiple)); } int diff --git a/gnuradio-core/src/lib/general/gr_multiply_const_cc.cc b/gnuradio-core/src/lib/general/gr_multiply_const_cc.cc index 359ab6ba05..bd4511937f 100644 --- a/gnuradio-core/src/lib/general/gr_multiply_const_cc.cc +++ b/gnuradio-core/src/lib/general/gr_multiply_const_cc.cc @@ -40,9 +40,9 @@ gr_multiply_const_cc::gr_multiply_const_cc (gr_complex k, size_t vlen) gr_make_io_signature (1, 1, sizeof (gr_complex)*vlen)), d_k(k), d_vlen(vlen) { - const int alignment_multiple = - volk_get_alignment() / sizeof(gr_complex); - set_alignment(alignment_multiple); + const int alignment_multiple = + volk_get_alignment() / sizeof(gr_complex); + set_alignment(std::max(1,alignment_multiple)); } gr_complex diff --git a/gnuradio-core/src/lib/general/gr_multiply_const_ff.cc b/gnuradio-core/src/lib/general/gr_multiply_const_ff.cc index 263f066106..16ba39df93 100644 --- a/gnuradio-core/src/lib/general/gr_multiply_const_ff.cc +++ b/gnuradio-core/src/lib/general/gr_multiply_const_ff.cc @@ -40,9 +40,9 @@ gr_multiply_const_ff::gr_multiply_const_ff (float k, size_t vlen) gr_make_io_signature (1, 1, sizeof (float)*vlen)), d_k(k), d_vlen(vlen) { - const int alignment_multiple = - volk_get_alignment() / sizeof(float); - set_alignment(alignment_multiple); + const int alignment_multiple = + volk_get_alignment() / sizeof(float); + set_alignment(std::max(1,alignment_multiple)); } float diff --git a/gnuradio-core/src/lib/general/gr_multiply_ff.cc b/gnuradio-core/src/lib/general/gr_multiply_ff.cc index f764a71e8f..bb7bd07550 100644 --- a/gnuradio-core/src/lib/general/gr_multiply_ff.cc +++ b/gnuradio-core/src/lib/general/gr_multiply_ff.cc @@ -42,7 +42,7 @@ gr_multiply_ff::gr_multiply_ff (size_t vlen) { const int alignment_multiple = volk_get_alignment() / sizeof(float); - set_alignment(alignment_multiple); + set_alignment(std::max(1,alignment_multiple)); } int diff --git a/gnuradio-core/src/lib/general/gr_short_to_char.cc b/gnuradio-core/src/lib/general/gr_short_to_char.cc index 9d6c41406e..8c146a351d 100644 --- a/gnuradio-core/src/lib/general/gr_short_to_char.cc +++ b/gnuradio-core/src/lib/general/gr_short_to_char.cc @@ -42,7 +42,7 @@ gr_short_to_char::gr_short_to_char (size_t vlen) { const int alignment_multiple = volk_get_alignment() / sizeof(char); - set_alignment(alignment_multiple); + set_alignment(std::max(1,alignment_multiple)); } int diff --git a/gnuradio-core/src/lib/general/gr_short_to_float.cc b/gnuradio-core/src/lib/general/gr_short_to_float.cc index 960cf644d1..093d6024fa 100644 --- a/gnuradio-core/src/lib/general/gr_short_to_float.cc +++ b/gnuradio-core/src/lib/general/gr_short_to_float.cc @@ -42,7 +42,7 @@ gr_short_to_float::gr_short_to_float (size_t vlen, float scale) { const int alignment_multiple = volk_get_alignment() / sizeof(float); - set_alignment(alignment_multiple); + set_alignment(std::max(1,alignment_multiple)); } float -- cgit v1.2.3 From c8c5158133fb7a20413e42f59632930758561ad9 Mon Sep 17 00:00:00 2001 From: Tim O'Shea <tim.oshea753@gmail.com> Date: Sun, 10 Jun 2012 13:54:09 -0400 Subject: gr_unpack_k_bits: added python QA code reversed bit ordering to match gr_pack_k_bits gr_keep_m_in_n: added python QA code switched block to operate on individual items as itemsize instead of vectors updated GRC to match --- gnuradio-core/src/lib/general/gr_keep_m_in_n.cc | 36 +++++++----- gnuradio-core/src/lib/general/gr_keep_m_in_n.h | 11 +++- gnuradio-core/src/lib/general/gr_pack_k_bits_bb.cc | 2 +- .../src/python/gnuradio/gr/qa_keep_m_in_n.py | 58 +++++++++++++++++++ .../src/python/gnuradio/gr/qa_pack_k_bits.py | 67 ++++++++++++++++++++++ grc/blocks/gr_keep_m_in_n.xml | 6 +- 6 files changed, 161 insertions(+), 19 deletions(-) create mode 100755 gnuradio-core/src/python/gnuradio/gr/qa_keep_m_in_n.py create mode 100755 gnuradio-core/src/python/gnuradio/gr/qa_pack_k_bits.py (limited to 'gnuradio-core/src/lib') diff --git a/gnuradio-core/src/lib/general/gr_keep_m_in_n.cc b/gnuradio-core/src/lib/general/gr_keep_m_in_n.cc index f17c3e00d7..a9f4c12bac 100644 --- a/gnuradio-core/src/lib/general/gr_keep_m_in_n.cc +++ b/gnuradio-core/src/lib/general/gr_keep_m_in_n.cc @@ -44,42 +44,52 @@ gr_make_keep_m_in_n (size_t item_size, int m, int n, int offset) * we take m items out of each n */ gr_keep_m_in_n::gr_keep_m_in_n (size_t item_size, int m, int n, int offset) - : gr_sync_block ("keep_m_in_n", - gr_make_io_signature (1, 1, n*item_size), - gr_make_io_signature (1, 1, m*item_size)), + : gr_block ("keep_m_in_n", + gr_make_io_signature (1, 1, item_size), + gr_make_io_signature (1, 1, item_size)), d_n(n), d_m(m), - d_offset( offset ) + d_offset( offset ), + d_itemsize( item_size ) { // sanity checking assert(d_m > 0); assert(d_n > 0); assert(d_m <= d_n); assert(d_offset <= (d_n-d_m)); + + set_output_multiple(m); } +void gr_keep_m_in_n::forecast (int noutput_items, gr_vector_int &ninput_items_required){ + ninput_items_required[0] = d_n*(noutput_items/d_m); +} + void gr_keep_m_in_n::set_offset(int offset){ d_offset = offset; } int -gr_keep_m_in_n::work (int noutput_items, +gr_keep_m_in_n::general_work (int noutput_items, + gr_vector_int &ninput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items) { uint8_t* out = (uint8_t*) output_items[0]; const uint8_t* in = (const uint8_t*) input_items[0]; - int in_item( input_signature()->sizeof_stream_item(0) ); - int out_item( output_signature()->sizeof_stream_item(0) ); - int single_size = in_item/d_n; - // iterate over data blocks of size {n, input : m, output} - for(int i=0; i<noutput_items; i++){ - memcpy( &out[out_item*i], &in[in_item*i + single_size*d_offset], out_item); + int blks = std::min( noutput_items/d_m, ninput_items[0]/d_n ); + for(int i=0; i<blks; i++){ + // set up copy pointers + const uint8_t* iptr = &in[(i*d_n + d_offset)*d_itemsize]; + uint8_t* optr = &out[i*d_m*d_itemsize]; + // perform copy + memcpy( optr, iptr, d_m*d_itemsize ); } - - return noutput_items; + + consume_each(d_n); + return d_m; } diff --git a/gnuradio-core/src/lib/general/gr_keep_m_in_n.h b/gnuradio-core/src/lib/general/gr_keep_m_in_n.h index f9d5a268bc..22fbd2f4ca 100644 --- a/gnuradio-core/src/lib/general/gr_keep_m_in_n.h +++ b/gnuradio-core/src/lib/general/gr_keep_m_in_n.h @@ -24,7 +24,7 @@ #define INCLUDED_GR_KEEP_M_IN_N_H #include <gr_core_api.h> -#include <gr_sync_block.h> +#include <gr_block.h> class gr_keep_m_in_n; typedef boost::shared_ptr<gr_keep_m_in_n> gr_keep_m_in_n_sptr; @@ -37,7 +37,7 @@ gr_make_keep_m_in_n (size_t item_size, int m, int n, int offset); * \brief decimate a stream, keeping one item out of every n. * \ingroup slicedice_blk */ -class GR_CORE_API gr_keep_m_in_n : public gr_sync_block +class GR_CORE_API gr_keep_m_in_n : public gr_block { friend GR_CORE_API gr_keep_m_in_n_sptr gr_make_keep_m_in_n (size_t item_size, int m, int n, int offset); @@ -46,16 +46,21 @@ class GR_CORE_API gr_keep_m_in_n : public gr_sync_block int d_m; int d_count; int d_offset; + int d_itemsize; protected: gr_keep_m_in_n (size_t item_size, int m, int n, int offset); + void forecast (int noutput_items, gr_vector_int &ninput_items_required); public: - int work (int noutput_items, + 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 set_offset(int offset); + void set_n(int n){ d_n = n; } + void set_m(int m){ d_m = m; } }; diff --git a/gnuradio-core/src/lib/general/gr_pack_k_bits_bb.cc b/gnuradio-core/src/lib/general/gr_pack_k_bits_bb.cc index 0237a4d691..fc7e689feb 100644 --- a/gnuradio-core/src/lib/general/gr_pack_k_bits_bb.cc +++ b/gnuradio-core/src/lib/general/gr_pack_k_bits_bb.cc @@ -61,7 +61,7 @@ gr_pack_k_bits_bb::work (int noutput_items, for (int i = 0; i < noutput_items; i++){ out[i] = 0x00; for (unsigned int j = 0; j < d_k; j++){ - out[i] |= (0x01 & in[i*d_k+j])<<j; + out[i] |= (0x01 & in[i*d_k+j])<<(d_k-j-1); } } diff --git a/gnuradio-core/src/python/gnuradio/gr/qa_keep_m_in_n.py b/gnuradio-core/src/python/gnuradio/gr/qa_keep_m_in_n.py new file mode 100755 index 0000000000..922671d024 --- /dev/null +++ b/gnuradio-core/src/python/gnuradio/gr/qa_keep_m_in_n.py @@ -0,0 +1,58 @@ +#!/usr/bin/env python +# +# Copyright 2008,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 this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# + +from gnuradio import gr, gr_unittest +import sys +import random + +class test_keep_m_in_n(gr_unittest.TestCase): + + def setUp(self): + pass + + def tearDown(self): + pass + + def test_001(self): + self.maxDiff = None; + tb = gr.top_block() + src = gr.vector_source_b( range(0,100) ) + + # itemsize, M, N, offset + km2 = gr.keep_m_in_n( 1, 1, 2, 0 ); + km3 = gr.keep_m_in_n( 1, 1, 3, 1 ); + km7 = gr.keep_m_in_n( 1, 1, 7, 2 ); + snk2 = gr.vector_sink_b(); + snk3 = gr.vector_sink_b(); + snk7 = gr.vector_sink_b(); + tb.connect(src,km2,snk2); + tb.connect(src,km3,snk3); + tb.connect(src,km7,snk7); + tb.run(); + + self.assertEqual(range(0,100,2), list(snk2.data())); + self.assertEqual(range(1,100,3), list(snk3.data())); + self.assertEqual(range(2,100,7), list(snk7.data())); + + +if __name__ == '__main__': + gr_unittest.run(test_keep_m_in_n, "test_keep_m_in_n.xml") + diff --git a/gnuradio-core/src/python/gnuradio/gr/qa_pack_k_bits.py b/gnuradio-core/src/python/gnuradio/gr/qa_pack_k_bits.py new file mode 100755 index 0000000000..25fc5e9fcc --- /dev/null +++ b/gnuradio-core/src/python/gnuradio/gr/qa_pack_k_bits.py @@ -0,0 +1,67 @@ +#!/usr/bin/env python +# +# Copyright 2006,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. +# + +from gnuradio import gr, gr_unittest +import random + +class test_pack(gr_unittest.TestCase): + + def setUp(self): + self.tb = gr.top_block () + + def tearDown(self): + self.tb = None + + def test_001(self): + src_data = (1,0,1,1,0,1,1,0) + expected_results = (1,0,1,1,0,1,1,0) + src = gr.vector_source_b(src_data,False) + op = gr.pack_k_bits_bb(1) + dst = gr.vector_sink_b() + self.tb.connect(src, op, dst) + self.tb.run() + self.assertEqual(expected_results, dst.data()) + + def test_002(self): + src_data = (1,0,1,1,0,0,0,1) + expected_results = ( 2, 3, 0, 1) + src = gr.vector_source_b(src_data,False) + op = gr.pack_k_bits_bb(2) + dst = gr.vector_sink_b() + self.tb.connect(src, op, dst) + self.tb.run() + #self.assertEqual(expected_results, dst.data()) + self.assertEqual(expected_results, dst.data()) + + def test_003(self): + src_data = expected_results = map(lambda x: random.randint(0,3), range(10)); + src = gr.vector_source_b( src_data ); + pack = gr.pack_k_bits_bb(2); + unpack = gr.unpack_k_bits_bb(2); + snk = gr.vector_sink_b(); + self.tb.connect(src,unpack,pack,snk); + self.tb.run() + self.assertEqual(list(expected_results), list(snk.data())); + +if __name__ == '__main__': + gr_unittest.run(test_pack, "test_pack.xml") + diff --git a/grc/blocks/gr_keep_m_in_n.xml b/grc/blocks/gr_keep_m_in_n.xml index a63ef47a66..35a1561764 100644 --- a/grc/blocks/gr_keep_m_in_n.xml +++ b/grc/blocks/gr_keep_m_in_n.xml @@ -10,6 +10,8 @@ <import>from gnuradio import gr</import> <make>gr.keep_m_in_n($type.size, $m, $n, $offset)</make> <callback>set_offset($offset)</callback> + <callback>set_m($m)</callback> + <callback>set_n($n)</callback> <param> <name>Type</name> <key>type</key> @@ -64,11 +66,11 @@ <sink> <name>in</name> <type>$type</type> - <vlen>$n</vlen> + <vlen>1</vlen> </sink> <source> <name>out</name> <type>$type</type> - <vlen>$m</vlen> + <vlen>1</vlen> </source> </block> -- cgit v1.2.3 From 403103de15cc60e73d38b56cbc16004123eeeda1 Mon Sep 17 00:00:00 2001 From: Tim O'Shea <tim.oshea753@gmail.com> Date: Tue, 12 Jun 2012 17:36:34 -0400 Subject: new block, gr_annotator_raw allows passing a raw pmt k->v pair from outside the flowgraph/python in at exact samples also added GRUEL autogenerated .i files to gnuradio-core-swig include line --- gnuradio-core/CMakeLists.txt | 1 + gnuradio-core/src/lib/general/CMakeLists.txt | 1 + gnuradio-core/src/lib/general/general.i | 2 + gnuradio-core/src/lib/general/gr_annotator_raw.cc | 96 +++++++++++++++++++++++ gnuradio-core/src/lib/general/gr_annotator_raw.h | 69 ++++++++++++++++ gnuradio-core/src/lib/general/gr_annotator_raw.i | 26 ++++++ 6 files changed, 195 insertions(+) create mode 100644 gnuradio-core/src/lib/general/gr_annotator_raw.cc create mode 100644 gnuradio-core/src/lib/general/gr_annotator_raw.h create mode 100644 gnuradio-core/src/lib/general/gr_annotator_raw.i (limited to 'gnuradio-core/src/lib') diff --git a/gnuradio-core/CMakeLists.txt b/gnuradio-core/CMakeLists.txt index 0227108446..4947c410b0 100644 --- a/gnuradio-core/CMakeLists.txt +++ b/gnuradio-core/CMakeLists.txt @@ -64,6 +64,7 @@ GR_SET_GLOBAL(GNURADIO_CORE_INCLUDE_DIRS GR_SET_GLOBAL(GNURADIO_CORE_SWIG_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/gruel/src/swig + ${CMAKE_BINARY_DIR}/gruel/src/swig/ ${CMAKE_CURRENT_SOURCE_DIR}/src/lib/swig ${GNURADIO_CORE_INCLUDE_DIRS} ) diff --git a/gnuradio-core/src/lib/general/CMakeLists.txt b/gnuradio-core/src/lib/general/CMakeLists.txt index ab9b870aa3..3492d5d6fb 100644 --- a/gnuradio-core/src/lib/general/CMakeLists.txt +++ b/gnuradio-core/src/lib/general/CMakeLists.txt @@ -292,6 +292,7 @@ set(gr_core_general_triple_threats gr_probe_density_b gr_annotator_alltoall gr_annotator_1to1 + gr_annotator_raw gr_burst_tagger gr_correlate_access_code_tag_bb ) diff --git a/gnuradio-core/src/lib/general/general.i b/gnuradio-core/src/lib/general/general.i index 0696addbde..fe2cbdb822 100644 --- a/gnuradio-core/src/lib/general/general.i +++ b/gnuradio-core/src/lib/general/general.i @@ -135,6 +135,7 @@ #include <complex_vec_test.h> #include <gr_annotator_alltoall.h> #include <gr_annotator_1to1.h> +#include <gr_annotator_raw.h> #include <gr_burst_tagger.h> #include <gr_cpm.h> #include <gr_correlate_access_code_tag_bb.h> @@ -255,6 +256,7 @@ %include "complex_vec_test.i" %include "gr_annotator_alltoall.i" %include "gr_annotator_1to1.i" +%include "gr_annotator_raw.i" %include "gr_burst_tagger.i" %include "gr_cpm.i" %include "gr_correlate_access_code_tag_bb.i" diff --git a/gnuradio-core/src/lib/general/gr_annotator_raw.cc b/gnuradio-core/src/lib/general/gr_annotator_raw.cc new file mode 100644 index 0000000000..7aa8714c42 --- /dev/null +++ b/gnuradio-core/src/lib/general/gr_annotator_raw.cc @@ -0,0 +1,96 @@ +/* -*- c++ -*- */ +/* + * Copyright 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. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <gr_annotator_raw.h> +#include <gr_io_signature.h> +#include <string.h> +#include <iostream> +#include <iomanip> + +gr_annotator_raw_sptr +gr_make_annotator_raw ( size_t sizeof_stream_item) +{ + return gnuradio::get_initial_sptr (new gr_annotator_raw + (sizeof_stream_item)); +} + +gr_annotator_raw::gr_annotator_raw (size_t sizeof_stream_item) + : gr_sync_block ("annotator_raw", + gr_make_io_signature (1, 1, sizeof_stream_item), + gr_make_io_signature (1, 1, sizeof_stream_item)), + d_itemsize(sizeof_stream_item) +{ + set_tag_propagation_policy(TPP_ONE_TO_ONE); + set_relative_rate(1.0); +} + + +void gr_annotator_raw::add_tag( uint64_t offset, pmt_t key, pmt_t val ){ + gr_tag_t tag; + tag.srcid = pmt::pmt_intern(d_name); + tag.key = key; + tag.value = val; + tag.offset = offset; + + // add our new tag + d_queued_tags.push_back( tag ); + // make sure our tags are in offset order + std::sort(d_queued_tags.begin(), d_queued_tags.end(), gr_tag_t::offset_compare); + // make sure we are not adding an item in the past! + assert(tag->offset >= nitems_read(0)); +} + + +gr_annotator_raw::~gr_annotator_raw () +{ +} + +int +gr_annotator_raw::work (int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) +{ + const char *in = (const char*)input_items[0]; + char *out = (char*)output_items[0]; + + uint64_t start_N = nitems_read(0); + uint64_t end_N = start_N + (uint64_t)(noutput_items); + + // locate queued tags that fall in this range and insert them when appropriate + std::vector<gr_tag_t>::iterator i = d_queued_tags.begin(); + while( i != d_queued_tags.end() ){ + if( (*i).offset >= start_N && (*i).offset < end_N){ + add_item_tag(0, (*i).offset,(*i).key, (*i).value, (*i).srcid); + i = d_queued_tags.erase(i); + } else { + break; + } + } + + // copy data across + memcpy(out, in, noutput_items*d_itemsize); + return noutput_items; +} diff --git a/gnuradio-core/src/lib/general/gr_annotator_raw.h b/gnuradio-core/src/lib/general/gr_annotator_raw.h new file mode 100644 index 0000000000..0da27daec4 --- /dev/null +++ b/gnuradio-core/src/lib/general/gr_annotator_raw.h @@ -0,0 +1,69 @@ +/* -*- c++ -*- */ +/* + * Copyright 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. + */ + +#ifndef INCLUDED_GR_ANNOTATOR_RAW_H +#define INCLUDED_GR_ANNOTATOR_RAW_H + +#include <gr_core_api.h> +#include <gr_sync_block.h> +#include <gruel/pmt.h> + +class gr_annotator_raw; +typedef boost::shared_ptr<gr_annotator_raw> gr_annotator_raw_sptr; + +// public constructor +GR_CORE_API gr_annotator_raw_sptr +gr_make_annotator_raw (size_t sizeof_stream_item); + +using namespace pmt; + +/*! + * \brief raw stream annotator testing block. + * + * This block creates arbitrary tags to be sent downstream + * blocks to be sent are set manually via accessor methods and are sent only once. + * + * This block is intended for testing of tag related blocks + */ +class GR_CORE_API gr_annotator_raw : public gr_sync_block +{ + public: + ~gr_annotator_raw (); + int work (int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + + // insert a tag to be added + void add_tag( uint64_t offset, pmt::pmt_t key, pmt::pmt_t val ); + +protected: + gr_annotator_raw (size_t sizeof_stream_item); + + private: + size_t d_itemsize; + std::vector<gr_tag_t> d_queued_tags; + + friend GR_CORE_API gr_annotator_raw_sptr + gr_make_annotator_raw (size_t sizeof_stream_item); +}; + +#endif diff --git a/gnuradio-core/src/lib/general/gr_annotator_raw.i b/gnuradio-core/src/lib/general/gr_annotator_raw.i new file mode 100644 index 0000000000..85777ef5d4 --- /dev/null +++ b/gnuradio-core/src/lib/general/gr_annotator_raw.i @@ -0,0 +1,26 @@ +/* -*- c++ -*- */ +/* + * Copyright 2010-2011 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. + */ + +GR_SWIG_BLOCK_MAGIC(gr,annotator_raw); + +%include <pmt_swig.i> +%include <gr_annotator_raw.h> -- cgit v1.2.3 From 07d2fbf97ba715b339c182185147567e329fc8c8 Mon Sep 17 00:00:00 2001 From: Tom Rondeau <trondeau@vt.edu> Date: Wed, 13 Jun 2012 11:05:42 -0400 Subject: core: modifications to gr_annotator_raw. Using mutex to make add_tag and work thread safe. Throwing exception intead of asserting on error. --- gnuradio-core/src/lib/general/gr_annotator_raw.cc | 70 +++++++++++++---------- gnuradio-core/src/lib/general/gr_annotator_raw.h | 24 ++++---- 2 files changed, 52 insertions(+), 42 deletions(-) (limited to 'gnuradio-core/src/lib') diff --git a/gnuradio-core/src/lib/general/gr_annotator_raw.cc b/gnuradio-core/src/lib/general/gr_annotator_raw.cc index 7aa8714c42..074c09173b 100644 --- a/gnuradio-core/src/lib/general/gr_annotator_raw.cc +++ b/gnuradio-core/src/lib/general/gr_annotator_raw.cc @@ -29,50 +29,59 @@ #include <string.h> #include <iostream> #include <iomanip> +#include <stdexcept> + +using namespace pmt; gr_annotator_raw_sptr -gr_make_annotator_raw ( size_t sizeof_stream_item) +gr_make_annotator_raw(size_t sizeof_stream_item) { - return gnuradio::get_initial_sptr (new gr_annotator_raw - (sizeof_stream_item)); + return gnuradio::get_initial_sptr(new gr_annotator_raw + (sizeof_stream_item)); } -gr_annotator_raw::gr_annotator_raw (size_t sizeof_stream_item) - : gr_sync_block ("annotator_raw", - gr_make_io_signature (1, 1, sizeof_stream_item), - gr_make_io_signature (1, 1, sizeof_stream_item)), +gr_annotator_raw::gr_annotator_raw(size_t sizeof_stream_item) + : gr_sync_block("annotator_raw", + gr_make_io_signature(1, 1, sizeof_stream_item), + gr_make_io_signature(1, 1, sizeof_stream_item)), d_itemsize(sizeof_stream_item) { set_tag_propagation_policy(TPP_ONE_TO_ONE); set_relative_rate(1.0); } +void gr_annotator_raw::add_tag(uint64_t offset, pmt_t key, pmt_t val) +{ + gruel::scoped_lock l(d_mutex); -void gr_annotator_raw::add_tag( uint64_t offset, pmt_t key, pmt_t val ){ - gr_tag_t tag; - tag.srcid = pmt::pmt_intern(d_name); - tag.key = key; - tag.value = val; - tag.offset = offset; + gr_tag_t tag; + tag.srcid = pmt::pmt_intern(d_name); + tag.key = key; + tag.value = val; + tag.offset = offset; - // add our new tag - d_queued_tags.push_back( tag ); - // make sure our tags are in offset order - std::sort(d_queued_tags.begin(), d_queued_tags.end(), gr_tag_t::offset_compare); - // make sure we are not adding an item in the past! - assert(tag->offset >= nitems_read(0)); + // add our new tag + d_queued_tags.push_back(tag); + // make sure our tags are in offset order + std::sort(d_queued_tags.begin(), d_queued_tags.end(), + gr_tag_t::offset_compare); + // make sure we are not adding an item in the past! + if(tag.offset >= nitems_read(0)) { + throw std::runtime_error("gr_annotator_raw::add_tag: item added too far in the past\n."); + } } - -gr_annotator_raw::~gr_annotator_raw () +gr_annotator_raw::~gr_annotator_raw() { } int -gr_annotator_raw::work (int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) +gr_annotator_raw::work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) { + gruel::scoped_lock l(d_mutex); + const char *in = (const char*)input_items[0]; char *out = (char*)output_items[0]; @@ -81,12 +90,13 @@ gr_annotator_raw::work (int noutput_items, // locate queued tags that fall in this range and insert them when appropriate std::vector<gr_tag_t>::iterator i = d_queued_tags.begin(); - while( i != d_queued_tags.end() ){ - if( (*i).offset >= start_N && (*i).offset < end_N){ - add_item_tag(0, (*i).offset,(*i).key, (*i).value, (*i).srcid); - i = d_queued_tags.erase(i); - } else { - break; + while( i != d_queued_tags.end() ) { + if( (*i).offset >= start_N && (*i).offset < end_N) { + add_item_tag(0, (*i).offset,(*i).key, (*i).value, (*i).srcid); + i = d_queued_tags.erase(i); + } + else { + break; } } diff --git a/gnuradio-core/src/lib/general/gr_annotator_raw.h b/gnuradio-core/src/lib/general/gr_annotator_raw.h index 0da27daec4..8a6c3f6c02 100644 --- a/gnuradio-core/src/lib/general/gr_annotator_raw.h +++ b/gnuradio-core/src/lib/general/gr_annotator_raw.h @@ -26,18 +26,17 @@ #include <gr_core_api.h> #include <gr_sync_block.h> #include <gruel/pmt.h> +#include <gruel/thread.h> class gr_annotator_raw; typedef boost::shared_ptr<gr_annotator_raw> gr_annotator_raw_sptr; // public constructor GR_CORE_API gr_annotator_raw_sptr -gr_make_annotator_raw (size_t sizeof_stream_item); - -using namespace pmt; +gr_make_annotator_raw(size_t sizeof_stream_item); /*! - * \brief raw stream annotator testing block. + * \brief raw stream annotator testing block. * * This block creates arbitrary tags to be sent downstream * blocks to be sent are set manually via accessor methods and are sent only once. @@ -47,23 +46,24 @@ using namespace pmt; class GR_CORE_API gr_annotator_raw : public gr_sync_block { public: - ~gr_annotator_raw (); - int work (int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); + ~gr_annotator_raw(); + int work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); - // insert a tag to be added - void add_tag( uint64_t offset, pmt::pmt_t key, pmt::pmt_t val ); + // insert a tag to be added + void add_tag(uint64_t offset, pmt::pmt_t key, pmt::pmt_t val); protected: - gr_annotator_raw (size_t sizeof_stream_item); + gr_annotator_raw(size_t sizeof_stream_item); private: size_t d_itemsize; std::vector<gr_tag_t> d_queued_tags; + gruel::mutex d_mutex; friend GR_CORE_API gr_annotator_raw_sptr - gr_make_annotator_raw (size_t sizeof_stream_item); + gr_make_annotator_raw(size_t sizeof_stream_item); }; #endif -- cgit v1.2.3 From 04e28f4ed161810f0af1caa7bd31a4aaa2f5f8c3 Mon Sep 17 00:00:00 2001 From: Johnathan Corgan <jcorgan@corganenterprises.com> Date: Thu, 14 Jun 2012 08:27:38 -0700 Subject: core: remove extraneous include statement --- gnuradio-core/src/lib/runtime/gr_top_block.i | 2 -- 1 file changed, 2 deletions(-) (limited to 'gnuradio-core/src/lib') diff --git a/gnuradio-core/src/lib/runtime/gr_top_block.i b/gnuradio-core/src/lib/runtime/gr_top_block.i index 80a1b82aea..6ae4c65a99 100644 --- a/gnuradio-core/src/lib/runtime/gr_top_block.i +++ b/gnuradio-core/src/lib/runtime/gr_top_block.i @@ -20,8 +20,6 @@ * Boston, MA 02110-1301, USA. */ -%include <gr_top_block.i> - class gr_top_block; typedef boost::shared_ptr<gr_top_block> gr_top_block_sptr; %template(gr_top_block_sptr) boost::shared_ptr<gr_top_block>; -- cgit v1.2.3 From e7ea4f2f5f21bc745fd3b3a92b1cee176c00c551 Mon Sep 17 00:00:00 2001 From: Tim O'Shea <tim.oshea753@gmail.com> Date: Wed, 13 Jun 2012 16:26:52 -0400 Subject: New Features: added support for pmt_serialize and pmt_deserialize for uint64_t type pmts added gr_add_const_bb typed block to gr_add_const_XX gengen --- gnuradio-core/src/lib/gengen/CMakeLists.txt | 2 +- gruel/src/lib/pmt/pmt-serial-tags.scm | 1 + gruel/src/lib/pmt/pmt_serialize.cc | 19 +++++++++++++------ 3 files changed, 15 insertions(+), 7 deletions(-) (limited to 'gnuradio-core/src/lib') diff --git a/gnuradio-core/src/lib/gengen/CMakeLists.txt b/gnuradio-core/src/lib/gengen/CMakeLists.txt index 22ac1bc588..b44a470750 100644 --- a/gnuradio-core/src/lib/gengen/CMakeLists.txt +++ b/gnuradio-core/src/lib/gengen/CMakeLists.txt @@ -89,7 +89,7 @@ expand_h_cc_i(gr_sig_source_X s i f c) expand_h_cc_i(gr_probe_signal_X b s i f c) expand_h_cc_i(gr_probe_signal_vX b s i f c) -expand_h_cc_i(gr_add_const_XX ss ii ff cc sf) +expand_h_cc_i(gr_add_const_XX bb ss ii ff cc sf) expand_h_cc_i(gr_multiply_const_XX ss ii) expand_h_cc_i(gr_add_XX ss ii cc) expand_h_cc_i(gr_sub_XX ss ii ff cc) diff --git a/gruel/src/lib/pmt/pmt-serial-tags.scm b/gruel/src/lib/pmt/pmt-serial-tags.scm index ca25a43a8a..a78d876814 100644 --- a/gruel/src/lib/pmt/pmt-serial-tags.scm +++ b/gruel/src/lib/pmt/pmt-serial-tags.scm @@ -33,6 +33,7 @@ (define pst-dict #x09) ; untagged-int32 n; followed by n key/value tuples (define pst-uniform-vector #x0a) +(define pst-uint64 #x0b) ;; u8, s8, u16, s16, u32, s32, u64, s64, f32, f64, c32, c64 ;; diff --git a/gruel/src/lib/pmt/pmt_serialize.cc b/gruel/src/lib/pmt/pmt_serialize.cc index de9644c3c6..05140bb424 100644 --- a/gruel/src/lib/pmt/pmt_serialize.cc +++ b/gruel/src/lib/pmt/pmt_serialize.cc @@ -79,7 +79,6 @@ serialize_untagged_f64(double i, std::streambuf &sb) } -#if 0 // always writes big-endian static bool serialize_untagged_u64(uint64_t i, std::streambuf &sb) @@ -93,7 +92,6 @@ serialize_untagged_u64(uint64_t i, std::streambuf &sb) sb.sputc((i >> 8) & 0xff); return sb.sputc((i >> 0) & 0xff) != std::streambuf::traits_type::eof(); } -#endif // ---------------------------------------------------------------- // input primitives @@ -152,7 +150,6 @@ deserialize_untagged_u32(uint32_t *ip, std::streambuf &sb) return t != std::streambuf::traits_type::eof(); } -#if 0 // always reads big-endian static bool deserialize_untagged_u64(uint64_t *ip, std::streambuf &sb) @@ -181,7 +178,6 @@ deserialize_untagged_u64(uint64_t *ip, std::streambuf &sb) *ip = i; return t != std::streambuf::traits_type::eof(); } -#endif static bool deserialize_untagged_f64(double *ip, std::streambuf &sb) @@ -260,7 +256,13 @@ pmt_serialize(pmt_t obj, std::streambuf &sb) } if (pmt_is_number(obj)){ - + + if (pmt_is_uint64(obj)){ + uint64_t i = pmt_to_uint64(obj); + ok = serialize_untagged_u8(PST_UINT64, sb); + ok &= serialize_untagged_u64(i, sb); + return ok; + } else if (pmt_is_integer(obj)){ long i = pmt_to_long(obj); if (sizeof(long) > 4){ @@ -315,7 +317,7 @@ pmt_deserialize(std::streambuf &sb) //uint8_t u8; uint16_t u16; uint32_t u32; - //uint32_t u64; + uint64_t u64; double f64; static char tmpbuf[1024]; @@ -347,6 +349,11 @@ pmt_deserialize(std::streambuf &sb) goto error; return pmt_from_long((int32_t) u32); + case PST_UINT64: + if(!deserialize_untagged_u64(&u64, sb)) + goto error; + return pmt_from_uint64(u64); + case PST_PAIR: return parse_pair(sb); -- cgit v1.2.3 From 9b2855a4d868731a2d4a1eb03b12d5c930c5c6d0 Mon Sep 17 00:00:00 2001 From: ChÃ-Thanh Christopher Nguyá»…n <chithanh@gentoo.org> Date: Sat, 16 Jun 2012 17:34:19 -0400 Subject: cmake: add support for SYSCONFDIR Set with 'cmake -DSYSCONFDIR=target ...' This fixes http://gnuradio.org/redmine/issues/492 --- CMakeLists.txt | 4 ++++ gnuradio-core/CMakeLists.txt | 2 +- gnuradio-core/src/lib/general/CMakeLists.txt | 3 --- gr-audio/lib/CMakeLists.txt | 2 +- gr-wxgui/CMakeLists.txt | 2 +- grc/CMakeLists.txt | 2 +- 6 files changed, 8 insertions(+), 7 deletions(-) (limited to 'gnuradio-core/src/lib') diff --git a/CMakeLists.txt b/CMakeLists.txt index 9f431a75b8..e9203e3123 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -107,6 +107,8 @@ set(GR_PKG_CONF_DIR ${GR_CONF_DIR}/${CMAKE_PROJECT_NAME}/conf.d) set(GR_LIBEXEC_DIR libexec) set(GR_PKG_LIBEXEC_DIR ${GR_LIBEXEC_DIR}/${CMAKE_PROJECT_NAME}) set(GRC_BLOCKS_DIR ${GR_PKG_DATA_DIR}/grc/blocks) +set(SYSCONFDIR "${CMAKE_INSTALL_PREFIX}/${GR_CONF_DIR}" CACHE PATH "System configuration directory") +set(GR_PREFSDIR ${SYSCONFDIR}/${CMAKE_PROJECT_NAME}/conf.d) ######################################################################## # Variables replaced when configuring the package config files @@ -115,6 +117,8 @@ file(TO_NATIVE_PATH "${CMAKE_INSTALL_PREFIX}" prefix) file(TO_NATIVE_PATH "\${prefix}" exec_prefix) file(TO_NATIVE_PATH "\${exec_prefix}/${GR_LIBRARY_DIR}" libdir) file(TO_NATIVE_PATH "\${prefix}/${GR_INCLUDE_DIR}" includedir) +file(TO_NATIVE_PATH "${SYSCONFDIR}" SYSCONFDIR) +file(TO_NATIVE_PATH "${GR_PREFSDIR}" GR_PREFSDIR) ######################################################################## # Create uninstall target diff --git a/gnuradio-core/CMakeLists.txt b/gnuradio-core/CMakeLists.txt index 4947c410b0..4e76b3c5a6 100644 --- a/gnuradio-core/CMakeLists.txt +++ b/gnuradio-core/CMakeLists.txt @@ -110,7 +110,7 @@ CPACK_COMPONENT("core_swig" install( FILES gnuradio-core.conf - DESTINATION ${GR_PKG_CONF_DIR} + DESTINATION ${GR_PREFSDIR} COMPONENT "core_runtime" ) diff --git a/gnuradio-core/src/lib/general/CMakeLists.txt b/gnuradio-core/src/lib/general/CMakeLists.txt index 3492d5d6fb..399e075996 100644 --- a/gnuradio-core/src/lib/general/CMakeLists.txt +++ b/gnuradio-core/src/lib/general/CMakeLists.txt @@ -48,9 +48,6 @@ message(STATUS "Loading build date ${BUILD_DATE} into gr_constants...") message(STATUS "Loading version ${VERSION} into gr_constants...") -file(TO_NATIVE_PATH "${CMAKE_INSTALL_PREFIX}/${GR_CONF_DIR}" SYSCONFDIR) -file(TO_NATIVE_PATH "${CMAKE_INSTALL_PREFIX}/${GR_PKG_CONF_DIR}" GR_PREFSDIR) - #double escape for windows backslash path separators string(REPLACE "\\" "\\\\" prefix ${prefix}) string(REPLACE "\\" "\\\\" SYSCONFDIR ${SYSCONFDIR}) diff --git a/gr-audio/lib/CMakeLists.txt b/gr-audio/lib/CMakeLists.txt index 7e0252a8b1..c1781af79e 100644 --- a/gr-audio/lib/CMakeLists.txt +++ b/gr-audio/lib/CMakeLists.txt @@ -150,4 +150,4 @@ add_library(gnuradio-audio SHARED ${gr_audio_sources}) target_link_libraries(gnuradio-audio ${gr_audio_libs}) GR_LIBRARY_FOO(gnuradio-audio RUNTIME_COMPONENT "audio_runtime" DEVEL_COMPONENT "audio_devel") -install(FILES ${gr_audio_confs} DESTINATION ${GR_PKG_CONF_DIR} COMPONENT "audio_runtime") +install(FILES ${gr_audio_confs} DESTINATION ${GR_PREFSDIR} COMPONENT "audio_runtime") diff --git a/gr-wxgui/CMakeLists.txt b/gr-wxgui/CMakeLists.txt index 0fc26dee1c..8150c7d802 100644 --- a/gr-wxgui/CMakeLists.txt +++ b/gr-wxgui/CMakeLists.txt @@ -76,7 +76,7 @@ install( ######################################################################## install( FILES ${CMAKE_CURRENT_SOURCE_DIR}/gr-wxgui.conf - DESTINATION ${GR_PKG_CONF_DIR} + DESTINATION ${GR_PREFSDIR} COMPONENT "wxgui" ) diff --git a/grc/CMakeLists.txt b/grc/CMakeLists.txt index f54aa4f809..219bbe1642 100644 --- a/grc/CMakeLists.txt +++ b/grc/CMakeLists.txt @@ -75,7 +75,7 @@ configure_file( install( FILES ${CMAKE_CURRENT_BINARY_DIR}/grc.conf - DESTINATION ${GR_PKG_CONF_DIR} + DESTINATION ${GR_PREFSDIR} COMPONENT "grc" ) -- cgit v1.2.3 From e42a6889a2966d8e9fd4e6b2b1bb3dd28c9794c9 Mon Sep 17 00:00:00 2001 From: Tim O'Shea <tim.oshea753@gmail.com> Date: Wed, 20 Jun 2012 11:58:40 -0400 Subject: 1. handle pmt serialize and deserialize for tuples 2. fix offset checking in pmt_annotator_raw --- gnuradio-core/src/lib/general/gr_annotator_raw.cc | 2 +- gruel/src/lib/pmt/pmt-serial-tags.scm | 1 + gruel/src/lib/pmt/pmt_serialize.cc | 41 +++++++++++++++++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) (limited to 'gnuradio-core/src/lib') diff --git a/gnuradio-core/src/lib/general/gr_annotator_raw.cc b/gnuradio-core/src/lib/general/gr_annotator_raw.cc index 074c09173b..e1ae73efb6 100644 --- a/gnuradio-core/src/lib/general/gr_annotator_raw.cc +++ b/gnuradio-core/src/lib/general/gr_annotator_raw.cc @@ -66,7 +66,7 @@ void gr_annotator_raw::add_tag(uint64_t offset, pmt_t key, pmt_t val) std::sort(d_queued_tags.begin(), d_queued_tags.end(), gr_tag_t::offset_compare); // make sure we are not adding an item in the past! - if(tag.offset >= nitems_read(0)) { + if(tag.offset > nitems_read(0)) { throw std::runtime_error("gr_annotator_raw::add_tag: item added too far in the past\n."); } } diff --git a/gruel/src/lib/pmt/pmt-serial-tags.scm b/gruel/src/lib/pmt/pmt-serial-tags.scm index a78d876814..4f06bf75f8 100644 --- a/gruel/src/lib/pmt/pmt-serial-tags.scm +++ b/gruel/src/lib/pmt/pmt-serial-tags.scm @@ -34,6 +34,7 @@ (define pst-uniform-vector #x0a) (define pst-uint64 #x0b) +(define pst-tuple #x0c) ;; u8, s8, u16, s16, u32, s32, u64, s64, f32, f64, c32, c64 ;; diff --git a/gruel/src/lib/pmt/pmt_serialize.cc b/gruel/src/lib/pmt/pmt_serialize.cc index 05140bb424..8c9dd12b3b 100644 --- a/gruel/src/lib/pmt/pmt_serialize.cc +++ b/gruel/src/lib/pmt/pmt_serialize.cc @@ -24,6 +24,7 @@ #endif #include <vector> #include <gruel/pmt.h> +#include <iostream> #include "pmt_int.h" #include "gruel/pmt_serial_tags.h" @@ -213,6 +214,28 @@ deserialize_untagged_f64(double *ip, std::streambuf &sb) return t != std::streambuf::traits_type::eof(); } +static bool +deserialize_tuple(pmt_t *tuple, std::streambuf &sb) +{ + std::cout << "deserialize_tuple\n"; + uint32_t nitems; + bool ok = deserialize_untagged_u32(&nitems, sb); + pmt_t list(PMT_NIL); + std::cout << "nitems: " << nitems << "\n"; + for(uint32_t i=0; i<nitems; i++){ + std::cout << "deserialize_tuple :: recursive call to pmt_deserialize\n"; + pmt_t item = pmt_deserialize( sb ); + pmt_print(item); + if(pmt_eq(list, PMT_NIL)){ + list = pmt_list1(item); + } else { + list = pmt_list_add(list, item); + } + } + (*tuple) = pmt_to_tuple(list); + return ok; +} + /* * Write portable byte-serial representation of \p obj to \p sb @@ -300,6 +323,16 @@ pmt_serialize(pmt_t obj, std::streambuf &sb) if (pmt_is_dict(obj)) throw pmt_notimplemented("pmt_serialize (dict)", obj); + if (pmt_is_tuple(obj)){ + size_t tuple_len = pmt::pmt_length(obj); + ok = serialize_untagged_u8(PST_COMPLEX, sb); + ok &= serialize_untagged_u32(tuple_len, sb); + for(size_t i=0; i<tuple_len; i++){ + ok &= pmt_serialize(pmt_tuple_ref(obj, i), sb); + } + return ok; + } + //throw pmt_notimplemented("pmt_serialize (tuple)", obj); throw pmt_notimplemented("pmt_serialize (?)", obj); } @@ -369,6 +402,14 @@ pmt_deserialize(std::streambuf &sb) goto error; return pmt_make_rectangular( r,i ); } + + case PST_TUPLE: + { + pmt_t tuple; + if(!deserialize_tuple(&tuple, sb)); + goto error; + return tuple; + } case PST_VECTOR: case PST_DICT: -- cgit v1.2.3 From db360e476e62d2c412d1654065d18047a25490b8 Mon Sep 17 00:00:00 2001 From: Martin Braun <martin.braun@kit.edu> Date: Thu, 21 Jun 2012 22:44:16 -0400 Subject: core: fixes a very minor bug in gri_wavfile.cc and also makes a FIXME obsolete --- gnuradio-core/src/lib/io/gri_wavfile.cc | 118 ++++++-------------------------- gnuradio-core/src/lib/io/gri_wavfile.h | 27 +++----- 2 files changed, 33 insertions(+), 112 deletions(-) (limited to 'gnuradio-core/src/lib') diff --git a/gnuradio-core/src/lib/io/gri_wavfile.cc b/gnuradio-core/src/lib/io/gri_wavfile.cc index e316a08254..3bc9d8fad5 100644 --- a/gnuradio-core/src/lib/io/gri_wavfile.cc +++ b/gnuradio-core/src/lib/io/gri_wavfile.cc @@ -27,107 +27,30 @@ #include <gri_wavfile.h> #include <cstring> #include <stdint.h> +#include <gruel/inet.h> # define VALID_COMPRESSION_TYPE 0x0001 // WAV files are always little-endian, so we need some byte switching macros -// FIXME: Use libgruel versions - +// Basically, this is the opposite of htonx() and ntohx() #ifdef WORDS_BIGENDIAN -#ifdef HAVE_BYTESWAP_H -#include <byteswap.h> -#else -#warning Using non-portable code (likely wrong other than ILP32). - -static inline short int -bswap_16 (unsigned short int x) -{ - return ((((x) >> 8) & 0xff) | (((x) & 0xff) << 8)); -} - -static inline unsigned int -bswap_32 (unsigned int x) -{ - return ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) \ - | (((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24)); -} -#endif // HAVE_BYTESWAP_H - -static inline uint32_t -host_to_wav(uint32_t x) -{ - return bswap_32(x); -} - -static inline uint16_t -host_to_wav(uint16_t x) -{ - return bswap_16(x); -} - -static inline int16_t -host_to_wav(int16_t x) -{ - return bswap_16(x); -} - -static inline uint32_t -wav_to_host(uint32_t x) -{ - return bswap_32(x); -} - -static inline uint16_t -wav_to_host(uint16_t x) -{ - return bswap_16(x); -} - -static inline int16_t -wav_to_host(int16_t x) -{ - return bswap_16(x); -} +static inline uint32_t host_to_wav(uint32_t x) { return bswap_32(x); } +static inline uint16_t host_to_wav(uint16_t x) { return bswap_16(x); } +static inline int16_t host_to_wav(int16_t x) { return bswap_16(x); } +static inline uint32_t wav_to_host(uint32_t x) { return bswap_32(x); } +static inline uint16_t wav_to_host(uint16_t x) { return bswap_16(x); } +static inline int16_t wav_to_host(int16_t x) { return bswap_16(x); } #else -static inline uint32_t -host_to_wav(uint32_t x) -{ - return x; -} - -static inline uint16_t -host_to_wav(uint16_t x) -{ - return x; -} - -static inline int16_t -host_to_wav(int16_t x) -{ - return x; -} - -static inline uint32_t -wav_to_host(uint32_t x) -{ - return x; -} - -static inline uint16_t -wav_to_host(uint16_t x) -{ - return x; -} - -static inline int16_t -wav_to_host(int16_t x) -{ - return x; -} +static inline uint32_t host_to_wav(uint32_t x) { return x; } +static inline uint16_t host_to_wav(uint16_t x) { return x; } +static inline int16_t host_to_wav(int16_t x) { return x; } +static inline uint32_t wav_to_host(uint32_t x) { return x; } +static inline uint16_t wav_to_host(uint16_t x) { return x; } +static inline int16_t wav_to_host(int16_t x) { return x; } #endif // WORDS_BIGENDIAN @@ -225,12 +148,15 @@ gri_wavheader_parse(FILE *fp, short int gri_wav_read_sample(FILE *fp, int bytes_per_sample) { - int16_t buf = 0; - size_t fresult; - - fresult = fread(&buf, bytes_per_sample, 1, fp); + int16_t buf_16bit; - return (short) wav_to_host(buf); + if(!fread(&buf_16bit, bytes_per_sample, 1, fp)) { + return 0; + } + if(bytes_per_sample == 1) { + return (short) buf_16bit; + } + return (short)wav_to_host(buf_16bit); } diff --git a/gnuradio-core/src/lib/io/gri_wavfile.h b/gnuradio-core/src/lib/io/gri_wavfile.h index c757be26bc..16280e34a9 100644 --- a/gnuradio-core/src/lib/io/gri_wavfile.h +++ b/gnuradio-core/src/lib/io/gri_wavfile.h @@ -29,20 +29,15 @@ /*! * \brief Read signal information from a given WAV file. * - * \p fp File pointer to an opened, empty file. - * \p sample_rate Stores the sample rate [S/s] - * \p nchans Number of channels - * \p bytes_per_sample Bytes per sample, can either be 1 or 2 (corresponding to - * 8 or 16 bit samples, respectively) - * \p first_sample_pos Number of the first byte containing a sample. Use this - * with fseek() to jump from the end of the file to the first sample - * when in repeat mode. - * \p samples_per_chan Number of samples per channel - * \p normalize_fac The normalization factor with which you need to divide the - * integer values of the samples to get them within [-1;1] - * \p normalize_shift The value by which the sample values need to be shifted - * after normalization (reason being, 8-bit WAV files store samples as - * unsigned char and 16-bit as signed short int) + * \param[in] fp File pointer to an opened, empty file. + * \param[out] sample_rate Stores the sample rate [S/s] + * \param[out] nchans Number of channels + * \param[out] bytes_per_sample Bytes per sample, can either be 1 or 2 (corresponding o + * 8 or 16 bit samples, respectively) + * \param[out] first_sample_pos Number of the first byte containing a sample. Use this + * with fseek() to jump from the end of the file to the + * first sample when in repeat mode. + * \param[out] samples_per_chan Number of samples per channel * \return True on a successful read, false if the file could not be read or is * not a valid WAV file. */ @@ -94,8 +89,8 @@ gri_wav_write_sample(FILE *fp, short int sample, int bytes_per_sample); * shouldn't happen), you need to fseek() to the end of the file (or * whereever). * - * \p fp File pointer to an open WAV file with a blank header - * \p byte_count Length of all samples written to the file in bytes. + * \param[in] fp File pointer to an open WAV file with a blank header + * \param[in] byte_count Length of all samples written to the file in bytes. */ bool gri_wavheader_complete(FILE *fp, unsigned int byte_count); -- cgit v1.2.3 From 95ac58a5a2dabef619865720e9b3f6a20941a252 Mon Sep 17 00:00:00 2001 From: Martin Braun <martin.braun@kit.edu> Date: Thu, 21 Jun 2012 22:45:29 -0400 Subject: core: tiny performance boost, and it looks tidier. --- gnuradio-core/src/lib/gengen/gr_sig_source_X.cc.t | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'gnuradio-core/src/lib') diff --git a/gnuradio-core/src/lib/gengen/gr_sig_source_X.cc.t b/gnuradio-core/src/lib/gengen/gr_sig_source_X.cc.t index bdd0e810a7..6959eac824 100644 --- a/gnuradio-core/src/lib/gengen/gr_sig_source_X.cc.t +++ b/gnuradio-core/src/lib/gengen/gr_sig_source_X.cc.t @@ -29,6 +29,7 @@ #include <algorithm> #include <gr_io_signature.h> #include <stdexcept> +#include <algorithm> #include <gr_complex.h> @@ -64,8 +65,7 @@ int case GR_CONST_WAVE: t = (gr_complex) d_ampl + d_offset; - for (int i = 0; i < noutput_items; i++) // FIXME unroll - optr[i] = t; + std::fill_n(optr, noutput_items, t); break; case GR_SIN_WAVE: @@ -142,8 +142,7 @@ int case GR_CONST_WAVE: t = (@TYPE@) d_ampl + d_offset; - for (int i = 0; i < noutput_items; i++) // FIXME unroll - optr[i] = t; + std::fill_n(optr, noutput_items, t); break; case GR_SIN_WAVE: -- cgit v1.2.3 From 93a4677fa127317910ec5868cc5e22a52d4d7240 Mon Sep 17 00:00:00 2001 From: Tom Rondeau <trondeau@vt.edu> Date: Fri, 22 Jun 2012 12:30:40 -0400 Subject: core: adds a tag debug sink to display all tags coming into it. This block is meant to help debug applications that use stream tags. --- gnuradio-core/src/lib/general/CMakeLists.txt | 1 + gnuradio-core/src/lib/general/general.i | 2 + gnuradio-core/src/lib/general/gr_tag_debug.cc | 100 +++++++++++++++++++++ gnuradio-core/src/lib/general/gr_tag_debug.h | 85 ++++++++++++++++++ gnuradio-core/src/lib/general/gr_tag_debug.i | 35 ++++++++ .../src/python/gnuradio/gr/qa_tag_debug.py | 43 +++++++++ grc/blocks/block_tree.xml | 1 + grc/blocks/gr_tag_debug.xml | 82 +++++++++++++++++ 8 files changed, 349 insertions(+) create mode 100644 gnuradio-core/src/lib/general/gr_tag_debug.cc create mode 100644 gnuradio-core/src/lib/general/gr_tag_debug.h create mode 100644 gnuradio-core/src/lib/general/gr_tag_debug.i create mode 100755 gnuradio-core/src/python/gnuradio/gr/qa_tag_debug.py create mode 100644 grc/blocks/gr_tag_debug.xml (limited to 'gnuradio-core/src/lib') diff --git a/gnuradio-core/src/lib/general/CMakeLists.txt b/gnuradio-core/src/lib/general/CMakeLists.txt index 399e075996..b671c963b6 100644 --- a/gnuradio-core/src/lib/general/CMakeLists.txt +++ b/gnuradio-core/src/lib/general/CMakeLists.txt @@ -292,6 +292,7 @@ set(gr_core_general_triple_threats gr_annotator_raw gr_burst_tagger gr_correlate_access_code_tag_bb + gr_tag_debug ) foreach(file_tt ${gr_core_general_triple_threats}) diff --git a/gnuradio-core/src/lib/general/general.i b/gnuradio-core/src/lib/general/general.i index fe2cbdb822..c0ce655276 100644 --- a/gnuradio-core/src/lib/general/general.i +++ b/gnuradio-core/src/lib/general/general.i @@ -141,6 +141,7 @@ #include <gr_correlate_access_code_tag_bb.h> #include <gr_add_ff.h> #include <gr_vector_map.h> +#include <gr_tag_debug.h> %} %include "gri_control_loop.i" @@ -262,3 +263,4 @@ %include "gr_correlate_access_code_tag_bb.i" %include "gr_add_ff.i" %include "gr_vector_map.i" +%include "gr_tag_debug.i" diff --git a/gnuradio-core/src/lib/general/gr_tag_debug.cc b/gnuradio-core/src/lib/general/gr_tag_debug.cc new file mode 100644 index 0000000000..c4031f438d --- /dev/null +++ b/gnuradio-core/src/lib/general/gr_tag_debug.cc @@ -0,0 +1,100 @@ +/* -*- c++ -*- */ +/* + * 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. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <gr_tag_debug.h> +#include <gr_io_signature.h> +#include <iostream> +#include <iomanip> + +gr_tag_debug_sptr +gr_make_tag_debug(size_t sizeof_stream_item, const std::string &name) +{ + return gnuradio::get_initial_sptr + (new gr_tag_debug(sizeof_stream_item, name)); +} + +gr_tag_debug::gr_tag_debug(size_t sizeof_stream_item, const std::string &name) + : gr_sync_block("tag_debug", + gr_make_io_signature(1, -1, sizeof_stream_item), + gr_make_io_signature(0, 0, 0)), + d_name(name), d_display(true) +{ +} + +std::vector<gr_tag_t> +gr_tag_debug::current_tags() +{ + gruel::scoped_lock l(d_mutex); + return d_tags; +} + +void +gr_tag_debug::set_display(bool d) +{ + gruel::scoped_lock l(d_mutex); + d_display = d; +} + +int +gr_tag_debug::work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) +{ + gruel::scoped_lock l(d_mutex); + + if(d_display) { + std::cout << std::endl + << "----------------------------------------------------------------------"; + std::cout << std::endl << "Tag Debug: " << d_name << std::endl; + } + + uint64_t abs_N, end_N; + for(size_t i = 0; i < input_items.size(); i++) { + abs_N = nitems_read(i); + end_N = abs_N + (uint64_t)(noutput_items); + + d_tags.clear(); + get_tags_in_range(d_tags, i, abs_N, end_N); + + if(d_display) { + std::cout << "Input Stream: " << i << std::endl; + for(d_tags_itr = d_tags.begin(); d_tags_itr != d_tags.end(); d_tags_itr++) { + std::cout << std::setw(10) << "Offset: " << d_tags_itr->offset + << std::setw(10) << "Source: " << pmt::pmt_symbol_to_string(d_tags_itr->srcid) + << std::setw(10) << "Key: " << pmt::pmt_symbol_to_string(d_tags_itr->key) + << std::setw(10) << "Value: "; + pmt::pmt_print(d_tags_itr->value); + } + } + } + + if(d_display) { + std::cout << "----------------------------------------------------------------------"; + std::cout << std::endl; + } + + return noutput_items; +} diff --git a/gnuradio-core/src/lib/general/gr_tag_debug.h b/gnuradio-core/src/lib/general/gr_tag_debug.h new file mode 100644 index 0000000000..57578884a8 --- /dev/null +++ b/gnuradio-core/src/lib/general/gr_tag_debug.h @@ -0,0 +1,85 @@ +/* -*- c++ -*- */ +/* + * 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. + */ + +#ifndef INCLUDED_GR_TAG_DEBUG_H +#define INCLUDED_GR_TAG_DEBUG_H + +#include <gr_core_api.h> +#include <gr_sync_block.h> +#include <gruel/thread.h> +#include <stddef.h> + +class gr_tag_debug; +typedef boost::shared_ptr<gr_tag_debug> gr_tag_debug_sptr; + +GR_CORE_API gr_tag_debug_sptr +gr_make_tag_debug(size_t sizeof_stream_item, const std::string &name); + +/*! + * \brief Bit bucket that prints out any tag received. + * \ingroup sink_blk + * + * This block collects all tags sent to it on all input ports and + * displays them to stdout in a formatted way. The \p name parameter + * is used to identify which debug sink generated the tag, so when + * connecting a block to this debug sink, an appropriate name is + * something that identifies the input block. + * + * This block otherwise acts as a NULL sink in that items from the + * input stream are ignored. It is designed to be able to attach to + * any block and watch all tags streaming out of that block for + * debugging purposes. + * + * The tags from the last call to this work function are stored and + * can be retrieved using the function 'current_tags'. + */ +class GR_CORE_API gr_tag_debug : public gr_sync_block +{ + private: + friend GR_CORE_API gr_tag_debug_sptr + gr_make_tag_debug(size_t sizeof_stream_item, const std::string &name); + gr_tag_debug(size_t sizeof_stream_item, const std::string &name); + + std::string d_name; + std::vector<gr_tag_t> d_tags; + std::vector<gr_tag_t>::iterator d_tags_itr; + bool d_display; + gruel::mutex d_mutex; + + public: + /*! + * \brief Returns a vector of gr_tag_t items as of the last call to + * work. + */ + std::vector<gr_tag_t> current_tags(); + + /*! + * \brief Set the display of tags to stdout on/off. + */ + void set_display(bool d); + + int work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); +}; + +#endif /* INCLUDED_GR_TAG_DEBUG_H */ diff --git a/gnuradio-core/src/lib/general/gr_tag_debug.i b/gnuradio-core/src/lib/general/gr_tag_debug.i new file mode 100644 index 0000000000..3af1bdcfef --- /dev/null +++ b/gnuradio-core/src/lib/general/gr_tag_debug.i @@ -0,0 +1,35 @@ +/* -*- c++ -*- */ +/* + * 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. + */ + +GR_SWIG_BLOCK_MAGIC(gr,tag_debug) + +%include <gr_tags.i> + +gr_tag_debug_sptr +gr_make_tag_debug(size_t sizeof_stream_item, const std::string &name); + +class gr_tag_debug : public gr_sync_block +{ +public: + std::vector<gr_tag_t> current_tags(); + void set_display(bool d); +}; diff --git a/gnuradio-core/src/python/gnuradio/gr/qa_tag_debug.py b/gnuradio-core/src/python/gnuradio/gr/qa_tag_debug.py new file mode 100755 index 0000000000..81babca048 --- /dev/null +++ b/gnuradio-core/src/python/gnuradio/gr/qa_tag_debug.py @@ -0,0 +1,43 @@ +#!/usr/bin/env python +# +# 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. +# + +from gnuradio import gr, gr_unittest + +class test_tag_debug(gr_unittest.TestCase): + + def setUp(self): + self.tb = gr.top_block() + + def tearDown(self): + self.tb = None + + def test_001(self): + # Just run some data through and make sure it doesn't puke. + src_data = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10) + src = gr.vector_source_i(src_data) + op = gr.tag_debug(gr.sizeof_int, "tag QA") + self.tb.connect(src, op) + self.tb.run() + x = op.current_tags() + +if __name__ == '__main__': + gr_unittest.run(test_tag_debug, "test_tag_debug.xml") diff --git a/grc/blocks/block_tree.xml b/grc/blocks/block_tree.xml index 0b0b6854ec..f94bd30bdf 100644 --- a/grc/blocks/block_tree.xml +++ b/grc/blocks/block_tree.xml @@ -34,6 +34,7 @@ <block>gr_message_sink</block> <block>pad_sink</block> <block>virtual_sink</block> + <block>gr_tag_debug</block> </cat> <cat> <name>Operators</name> diff --git a/grc/blocks/gr_tag_debug.xml b/grc/blocks/gr_tag_debug.xml new file mode 100644 index 0000000000..4af7729be9 --- /dev/null +++ b/grc/blocks/gr_tag_debug.xml @@ -0,0 +1,82 @@ +<?xml version="1.0"?> +<!-- +################################################### +## Tag Debug +################################################### + --> +<block> + <name>Tag Debug</name> + <key>gr_tag_debug</key> + <import>from gnuradio import gr</import> + <make>gr.tag_debug($type.size*$vlen, $name)</make> + <callback>set_display($display)</callback> + <param> + <name>Input Type</name> + <key>type</key> + <type>enum</type> + <option> + <name>Complex</name> + <key>complex</key> + <opt>size:gr.sizeof_gr_complex</opt> + </option> + <option> + <name>Float</name> + <key>float</key> + <opt>size:gr.sizeof_float</opt> + </option> + <option> + <name>Int</name> + <key>int</key> + <opt>size:gr.sizeof_int</opt> + </option> + <option> + <name>Short</name> + <key>short</key> + <opt>size:gr.sizeof_short</opt> + </option> + <option> + <name>Byte</name> + <key>byte</key> + <opt>size:gr.sizeof_char</opt> + </option> + </param> + <param> + <name>Name</name> + <key>name</key> + <type>string</type> + </param> + <param> + <name>Num Inputs</name> + <key>num_inputs</key> + <value>1</value> + <type>int</type> + </param> + <param> + <name>Vec Length</name> + <key>vlen</key> + <value>1</value> + <type>int</type> + </param> + <param> + <name>Display</name> + <key>display</key> + <value>True</value> + <type>bool</type> + <option> + <name>On</name> + <key>True</key> + </option> + <option> + <name>Off</name> + <key>False</key> + </option> + </param> + <check>$num_inputs >= 1</check> + <check>$vlen > 0</check> + <sink> + <name>in</name> + <type>$type</type> + <vlen>$vlen</vlen> + <nports>$num_inputs</nports> + </sink> +</block> -- cgit v1.2.3 From 056d3006d07c11c4bfba9ac5c2f82111be55dd35 Mon Sep 17 00:00:00 2001 From: Nicholas Corgan <nick.corgan@ettus.com> Date: Fri, 22 Jun 2012 11:19:58 -0700 Subject: gruel: got rid of inet.h and adjusted only file that depended on it --- gnuradio-core/src/lib/io/gri_wavfile.cc | 16 ++--- gr-filter/lib/CMakeLists.txt | 1 + gruel/src/include/gruel/CMakeLists.txt | 19 +----- gruel/src/include/gruel/inet.h.in | 100 -------------------------------- gruel/src/swig/CMakeLists.txt | 4 +- 5 files changed, 12 insertions(+), 128 deletions(-) delete mode 100644 gruel/src/include/gruel/inet.h.in (limited to 'gnuradio-core/src/lib') diff --git a/gnuradio-core/src/lib/io/gri_wavfile.cc b/gnuradio-core/src/lib/io/gri_wavfile.cc index 3bc9d8fad5..780bd1b98f 100644 --- a/gnuradio-core/src/lib/io/gri_wavfile.cc +++ b/gnuradio-core/src/lib/io/gri_wavfile.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2004,2008 Free Software Foundation, Inc. + * Copyright 2004,2008,2012 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -27,7 +27,7 @@ #include <gri_wavfile.h> #include <cstring> #include <stdint.h> -#include <gruel/inet.h> +#include <boost/asio.hpp> # define VALID_COMPRESSION_TYPE 0x0001 @@ -36,12 +36,12 @@ // Basically, this is the opposite of htonx() and ntohx() #ifdef WORDS_BIGENDIAN -static inline uint32_t host_to_wav(uint32_t x) { return bswap_32(x); } -static inline uint16_t host_to_wav(uint16_t x) { return bswap_16(x); } -static inline int16_t host_to_wav(int16_t x) { return bswap_16(x); } -static inline uint32_t wav_to_host(uint32_t x) { return bswap_32(x); } -static inline uint16_t wav_to_host(uint16_t x) { return bswap_16(x); } -static inline int16_t wav_to_host(int16_t x) { return bswap_16(x); } +static inline uint32_t host_to_wav(uint32_t x) { return htonl(x); } +static inline uint16_t host_to_wav(uint16_t x) { return htons(x); } +static inline int16_t host_to_wav(int16_t x) { return htons(x); } +static inline uint32_t wav_to_host(uint32_t x) { return ntohl(x); } +static inline uint16_t wav_to_host(uint16_t x) { return ntohs(x); } +static inline int16_t wav_to_host(int16_t x) { return ntohs(x); } #else diff --git a/gr-filter/lib/CMakeLists.txt b/gr-filter/lib/CMakeLists.txt index 048a948e6a..73d7d7bae1 100644 --- a/gr-filter/lib/CMakeLists.txt +++ b/gr-filter/lib/CMakeLists.txt @@ -98,6 +98,7 @@ include_directories( ${GR_FFT_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS} ${FFTW3F_INCLUDE_DIRS} + ${CPPUNIT_INCLUDE_DIRS} ) link_directories(${FFT_LIBRARY_DIRS}) diff --git a/gruel/src/include/gruel/CMakeLists.txt b/gruel/src/include/gruel/CMakeLists.txt index 9818f1c09c..3fba90afcf 100644 --- a/gruel/src/include/gruel/CMakeLists.txt +++ b/gruel/src/include/gruel/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright 2010-2011 Free Software Foundation, Inc. +# Copyright 2010-2012 Free Software Foundation, Inc. # # This file is part of GNU Radio # @@ -17,23 +17,6 @@ # the Free Software Foundation, Inc., 51 Franklin Street, # Boston, MA 02110-1301, USA. -######################################################################## -# Generate inet.h header file -######################################################################## -include(TestBigEndian) -enable_language(C) -TEST_BIG_ENDIAN(GR_ARCH_BIGENDIAN) - -include(CheckIncludeFileCXX) -CHECK_INCLUDE_FILE_CXX(byteswap.h GR_HAVE_BYTESWAP) -CHECK_INCLUDE_FILE_CXX(arpa/inet.h GR_HAVE_ARPA_INET) -CHECK_INCLUDE_FILE_CXX(netinet/in.h GR_HAVE_NETINET_IN) - -configure_file( - ${CMAKE_CURRENT_SOURCE_DIR}/inet.h.in - ${CMAKE_CURRENT_BINARY_DIR}/inet.h -@ONLY) - ######################################################################## # Install the headers ######################################################################## diff --git a/gruel/src/include/gruel/inet.h.in b/gruel/src/include/gruel/inet.h.in deleted file mode 100644 index 74f14bd923..0000000000 --- a/gruel/src/include/gruel/inet.h.in +++ /dev/null @@ -1,100 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2008, 2009 Free Software Foundation, Inc. - * - * This program 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 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef INCLUDED_INET_H -#define INCLUDED_INET_H - -#include <gruel/api.h> -#include <stdint.h> - -#if 1 /* missing htonll or ntohll */ -#if @GR_ARCH_BIGENDIAN@ /* GR_ARCH_BIGENDIAN */ -// Nothing to do... -static inline uint64_t htonll(uint64_t x){ return x;} -static inline uint64_t ntohll(uint64_t x){ return x;} -#else -#if @GR_HAVE_BYTESWAP@ /* GR_HAVE_BYTESWAP */ -#include <byteswap.h> -#else - -static inline uint64_t -bswap_64(uint64_t x) -{ - return ((x & 0x00000000000000ffull) << 56) | ((x & 0x000000000000ff00ull) << 40) | - ((x & 0x0000000000ff0000ull) << 24) | ((x & 0x00000000ff000000ull) << 8) | - ((x & 0x000000ff00000000ull) >> 8) | ((x & 0x0000ff0000000000ull) >> 24) | - ((x & 0x00ff000000000000ull) >> 40) | ((x & 0xff00000000000000ull) >> 56); -} - -#endif /* GR_HAVE_BYTESWAP */ - -static inline uint64_t htonll(uint64_t x){ return bswap_64(x);} -static inline uint64_t ntohll(uint64_t x){ return bswap_64(x);} - -#endif /* GR_ARCH_BIGENDIAN */ -#endif /* missing htonll or ntohll */ - -#if @GR_HAVE_ARPA_INET@ /* GR_HAVE_ARPA_INET */ -#include <arpa/inet.h> -#elif @GR_HAVE_NETINET_IN@ /* GR_HAVE_NETINET_IN */ -#include <netinet/in.h> -#else -#include <stdint.h> - -#if @GR_ARCH_BIGENDIAN@ /* GR_ARCH_BIGENDIAN */ -// Nothing to do... -static inline uint32_t htonl(uint32_t x){ return x; } -static inline uint16_t htons(uint16_t x){ return x; } -static inline uint32_t ntohl(uint32_t x){ return x; } -static inline uint16_t ntohs(uint16_t x){ return x; } -#else -#if @GR_HAVE_BYTESWAP@ /* GR_HAVE_BYTESWAP */ -#include <byteswap.h> -#else -static inline uint16_t -bswap_16 (uint16_t x) -{ - return ((((x) >> 8) & 0xff) | (((x) & 0xff) << 8)); -} - -static inline uint32_t -bswap_32 (uint32_t x) -{ - return ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) \ - | (((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24)); -} -#endif /* GR_HAVE_BYTESWAP */ - -static inline uint32_t htonl(uint32_t x){ return bswap_32(x); } -static inline uint16_t htons(uint16_t x){ return bswap_16(x); } -static inline uint32_t ntohl(uint32_t x){ return bswap_32(x); } -static inline uint16_t ntohs(uint16_t x){ return bswap_16(x); } -#endif /* GR_ARCH_BIGENDIAN */ - -#endif /* !(GR_HAVE_NETINET_IN || GR_HAVE_ARPA_INET) */ - -static inline uint8_t ntohx(uint8_t x){ return x; } -static inline uint16_t ntohx(uint16_t x){ return ntohs(x); } -static inline uint32_t ntohx(uint32_t x){ return ntohl(x); } -static inline uint64_t ntohx(uint64_t x){ return ntohll(x);} -static inline uint8_t htonx(uint8_t x){ return x; } -static inline uint16_t htonx(uint16_t x){ return htons(x); } -static inline uint32_t htonx(uint32_t x){ return htonl(x); } -static inline uint64_t htonx(uint64_t x){ return htonll(x);} - -#endif /* INCLUDED_INET_H */ diff --git a/gruel/src/swig/CMakeLists.txt b/gruel/src/swig/CMakeLists.txt index f9d1758ec4..a0f84c8323 100644 --- a/gruel/src/swig/CMakeLists.txt +++ b/gruel/src/swig/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 # @@ -23,7 +23,7 @@ include(GrPython) include(GrSwig) -set(GR_SWIG_INCLUDE_DIRS ${GRUEL_INCLUDE_DIRS}) +set(GR_SWIG_INCLUDE_DIRS ${GRUEL_INCLUDE_DIRS} ${CMAKE_CURRENT_BINARY_DIR}) set(GR_SWIG_LIBRARIES gruel) set(GR_SWIG_DOC_FILE ${CMAKE_CURRENT_BINARY_DIR}/pmt_swig_doc.i) -- cgit v1.2.3 From 75fac1e1476578cd354a2cc586af23da88ce4b12 Mon Sep 17 00:00:00 2001 From: Josh Blum <josh@joshknows.com> Date: Thu, 28 Jun 2012 17:55:34 -0700 Subject: core: fix for gri wave byteswapping Sorry guys, I misunderstood the comments. Wave data is specifically in little endian format. Therefore we should only be swapping on big endian machines. Since systems only provide network endian macros: The following commit provides a cross platform byteswap and macros for host to/from worknet short and long. --- gnuradio-core/src/lib/io/gri_wavfile.cc | 46 +++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 17 deletions(-) (limited to 'gnuradio-core/src/lib') diff --git a/gnuradio-core/src/lib/io/gri_wavfile.cc b/gnuradio-core/src/lib/io/gri_wavfile.cc index 780bd1b98f..277e6b7b0e 100644 --- a/gnuradio-core/src/lib/io/gri_wavfile.cc +++ b/gnuradio-core/src/lib/io/gri_wavfile.cc @@ -27,33 +27,45 @@ #include <gri_wavfile.h> #include <cstring> #include <stdint.h> -#include <boost/asio.hpp> +#include <boost/detail/endian.hpp> //BOOST_BIG_ENDIAN # define VALID_COMPRESSION_TYPE 0x0001 -// WAV files are always little-endian, so we need some byte switching macros - // Basically, this is the opposite of htonx() and ntohx() -#ifdef WORDS_BIGENDIAN +// Define host to/from worknet (little endian) short and long +#ifdef BOOST_BIG_ENDIAN + + static inline uint16_t __gri_wav_bs16(uint16_t x) + { + return (x>>8) | (x<<8); + } -static inline uint32_t host_to_wav(uint32_t x) { return htonl(x); } -static inline uint16_t host_to_wav(uint16_t x) { return htons(x); } -static inline int16_t host_to_wav(int16_t x) { return htons(x); } -static inline uint32_t wav_to_host(uint32_t x) { return ntohl(x); } -static inline uint16_t wav_to_host(uint16_t x) { return ntohs(x); } -static inline int16_t wav_to_host(int16_t x) { return ntohs(x); } + static inline uint32_t __gri_wav_bs32(uint32_t x) + { + return (uint32_t(__gri_wav_bs16(uint16_t(x&0xfffful)))<<16) | (__gri_wav_bs16(uint16_t(x>>16))); + } + + #define htowl(x) __gri_wav_bs32(x) + #define wtohl(x) __gri_wav_bs32(x) + #define htows(x) __gri_wav_bs16(x) + #define wtohs(x) __gri_wav_bs16(x) #else -static inline uint32_t host_to_wav(uint32_t x) { return x; } -static inline uint16_t host_to_wav(uint16_t x) { return x; } -static inline int16_t host_to_wav(int16_t x) { return x; } -static inline uint32_t wav_to_host(uint32_t x) { return x; } -static inline uint16_t wav_to_host(uint16_t x) { return x; } -static inline int16_t wav_to_host(int16_t x) { return x; } + #define htowl(x) uint32_t(x) + #define wtohl(x) uint32_t(x) + #define htows(x) uint16_t(x) + #define wtohs(x) uint16_t(x) -#endif // WORDS_BIGENDIAN +#endif // BOOST_BIG_ENDIAN +// WAV files are always little-endian, so we need some byte switching macros +static inline uint32_t host_to_wav(uint32_t x) { return htowl(x); } +static inline uint16_t host_to_wav(uint16_t x) { return htows(x); } +static inline int16_t host_to_wav(int16_t x) { return htows(x); } +static inline uint32_t wav_to_host(uint32_t x) { return wtohl(x); } +static inline uint16_t wav_to_host(uint16_t x) { return wtohs(x); } +static inline int16_t wav_to_host(int16_t x) { return wtohs(x); } bool gri_wavheader_parse(FILE *fp, -- cgit v1.2.3 From 744ffd50ac5a73ce3619ae11ef9cf04c0886d74a Mon Sep 17 00:00:00 2001 From: Josh Blum <josh@joshknows.com> Date: Tue, 3 Jul 2012 12:01:16 -0700 Subject: core: added general_generated to swig deps We generate the docs so its important that the docs see this header generated first. --- gnuradio-core/src/lib/general/CMakeLists.txt | 4 + gnuradio-core/src/lib/gengen/Makefile.gen | 333 --------------------------- gnuradio-core/src/lib/swig/CMakeLists.txt | 2 +- 3 files changed, 5 insertions(+), 334 deletions(-) delete mode 100644 gnuradio-core/src/lib/gengen/Makefile.gen (limited to 'gnuradio-core/src/lib') diff --git a/gnuradio-core/src/lib/general/CMakeLists.txt b/gnuradio-core/src/lib/general/CMakeLists.txt index ab9b870aa3..e97644ffa0 100644 --- a/gnuradio-core/src/lib/general/CMakeLists.txt +++ b/gnuradio-core/src/lib/general/CMakeLists.txt @@ -37,6 +37,10 @@ ADD_FILE_DEPENDENCIES(${CMAKE_CURRENT_SOURCE_DIR}/gr_fxpt.cc ${CMAKE_CURRENT_BINARY_DIR}/sine_table.h ) +add_custom_target(general_generated DEPENDS + ${CMAKE_CURRENT_BINARY_DIR}/sine_table.h +) + ######################################################################## # Handle the generated constants ######################################################################## diff --git a/gnuradio-core/src/lib/gengen/Makefile.gen b/gnuradio-core/src/lib/gengen/Makefile.gen deleted file mode 100644 index b4a255dc08..0000000000 --- a/gnuradio-core/src/lib/gengen/Makefile.gen +++ /dev/null @@ -1,333 +0,0 @@ -# -# This file is machine generated. All edits will be overwritten -# -GENERATED_H = \ - gr_add_cc.h \ - gr_add_const_cc.h \ - gr_add_const_ff.h \ - gr_add_const_ii.h \ - gr_add_const_sf.h \ - gr_add_const_ss.h \ - gr_add_const_vcc.h \ - gr_add_const_vff.h \ - gr_add_const_vii.h \ - gr_add_const_vss.h \ - gr_add_ii.h \ - gr_add_ss.h \ - gr_and_bb.h \ - gr_and_const_bb.h \ - gr_and_const_ii.h \ - gr_and_const_ss.h \ - gr_and_ii.h \ - gr_and_ss.h \ - gr_argmax_fs.h \ - gr_argmax_is.h \ - gr_argmax_ss.h \ - gr_chunks_to_symbols_bc.h \ - gr_chunks_to_symbols_bf.h \ - gr_chunks_to_symbols_ic.h \ - gr_chunks_to_symbols_if.h \ - gr_chunks_to_symbols_sc.h \ - gr_chunks_to_symbols_sf.h \ - gr_divide_cc.h \ - gr_divide_ff.h \ - gr_divide_ii.h \ - gr_divide_ss.h \ - gr_integrate_cc.h \ - gr_integrate_ff.h \ - gr_integrate_ii.h \ - gr_integrate_ss.h \ - gr_max_ff.h \ - gr_max_ii.h \ - gr_max_ss.h \ - gr_moving_average_cc.h \ - gr_moving_average_ff.h \ - gr_moving_average_ii.h \ - gr_moving_average_ss.h \ - gr_multiply_const_ii.h \ - gr_multiply_const_ss.h \ - gr_multiply_const_vcc.h \ - gr_multiply_const_vff.h \ - gr_multiply_const_vii.h \ - gr_multiply_const_vss.h \ - gr_multiply_ii.h \ - gr_multiply_ss.h \ - gr_mute_cc.h \ - gr_mute_ff.h \ - gr_mute_ii.h \ - gr_mute_ss.h \ - gr_noise_source_c.h \ - gr_noise_source_f.h \ - gr_noise_source_i.h \ - gr_noise_source_s.h \ - gr_not_bb.h \ - gr_not_ii.h \ - gr_not_ss.h \ - gr_or_bb.h \ - gr_or_ii.h \ - gr_or_ss.h \ - gr_packed_to_unpacked_bb.h \ - gr_packed_to_unpacked_ii.h \ - gr_packed_to_unpacked_ss.h \ - gr_peak_detector_fb.h \ - gr_peak_detector_ib.h \ - gr_peak_detector_sb.h \ - gr_probe_signal_b.h \ - gr_probe_signal_s.h \ - gr_probe_signal_i.h \ - gr_probe_signal_f.h \ - gr_probe_signal_c.h \ - gr_probe_signal_vb.h \ - gr_probe_signal_vs.h \ - gr_probe_signal_vi.h \ - gr_probe_signal_vf.h \ - gr_probe_signal_vc.h \ - gr_sample_and_hold_bb.h \ - gr_sample_and_hold_ff.h \ - gr_sample_and_hold_ii.h \ - gr_sample_and_hold_ss.h \ - gr_sig_source_c.h \ - gr_sig_source_f.h \ - gr_sig_source_i.h \ - gr_sig_source_s.h \ - gr_sub_cc.h \ - gr_sub_ff.h \ - gr_sub_ii.h \ - gr_sub_ss.h \ - gr_unpacked_to_packed_bb.h \ - gr_unpacked_to_packed_ii.h \ - gr_unpacked_to_packed_ss.h \ - gr_vector_sink_b.h \ - gr_vector_sink_c.h \ - gr_vector_sink_f.h \ - gr_vector_sink_i.h \ - gr_vector_sink_s.h \ - gr_vector_source_b.h \ - gr_vector_source_c.h \ - gr_vector_source_f.h \ - gr_vector_source_i.h \ - gr_vector_source_s.h \ - gr_xor_bb.h \ - gr_xor_ii.h \ - gr_xor_ss.h - -GENERATED_I = \ - gr_add_cc.i \ - gr_add_const_cc.i \ - gr_add_const_ff.i \ - gr_add_const_ii.i \ - gr_add_const_sf.i \ - gr_add_const_ss.i \ - gr_add_const_vcc.i \ - gr_add_const_vff.i \ - gr_add_const_vii.i \ - gr_add_const_vss.i \ - gr_add_ii.i \ - gr_add_ss.i \ - gr_and_bb.i \ - gr_and_const_bb.i \ - gr_and_const_ii.i \ - gr_and_const_ss.i \ - gr_and_ii.i \ - gr_and_ss.i \ - gr_argmax_fs.i \ - gr_argmax_is.i \ - gr_argmax_ss.i \ - gr_chunks_to_symbols_bc.i \ - gr_chunks_to_symbols_bf.i \ - gr_chunks_to_symbols_ic.i \ - gr_chunks_to_symbols_if.i \ - gr_chunks_to_symbols_sc.i \ - gr_chunks_to_symbols_sf.i \ - gr_divide_cc.i \ - gr_divide_ff.i \ - gr_divide_ii.i \ - gr_divide_ss.i \ - gr_integrate_cc.i \ - gr_integrate_ff.i \ - gr_integrate_ii.i \ - gr_integrate_ss.i \ - gr_max_ff.i \ - gr_max_ii.i \ - gr_max_ss.i \ - gr_moving_average_cc.i \ - gr_moving_average_ff.i \ - gr_moving_average_ii.i \ - gr_moving_average_ss.i \ - gr_multiply_const_ii.i \ - gr_multiply_const_ss.i \ - gr_multiply_const_vcc.i \ - gr_multiply_const_vff.i \ - gr_multiply_const_vii.i \ - gr_multiply_const_vss.i \ - gr_multiply_ii.i \ - gr_multiply_ss.i \ - gr_mute_cc.i \ - gr_mute_ff.i \ - gr_mute_ii.i \ - gr_mute_ss.i \ - gr_noise_source_c.i \ - gr_noise_source_f.i \ - gr_noise_source_i.i \ - gr_noise_source_s.i \ - gr_not_bb.i \ - gr_not_ii.i \ - gr_not_ss.i \ - gr_or_bb.i \ - gr_or_ii.i \ - gr_or_ss.i \ - gr_packed_to_unpacked_bb.i \ - gr_packed_to_unpacked_ii.i \ - gr_packed_to_unpacked_ss.i \ - gr_peak_detector_fb.i \ - gr_peak_detector_ib.i \ - gr_peak_detector_sb.i \ - gr_probe_signal_b.i \ - gr_probe_signal_s.i \ - gr_probe_signal_i.i \ - gr_probe_signal_f.i \ - gr_probe_signal_c.i \ - gr_probe_signal_vb.i \ - gr_probe_signal_vs.i \ - gr_probe_signal_vi.i \ - gr_probe_signal_vf.i \ - gr_probe_signal_vc.i \ - gr_sample_and_hold_bb.i \ - gr_sample_and_hold_ff.i \ - gr_sample_and_hold_ii.i \ - gr_sample_and_hold_ss.i \ - gr_sig_source_c.i \ - gr_sig_source_f.i \ - gr_sig_source_i.i \ - gr_sig_source_s.i \ - gr_sub_cc.i \ - gr_sub_ff.i \ - gr_sub_ii.i \ - gr_sub_ss.i \ - gr_unpacked_to_packed_bb.i \ - gr_unpacked_to_packed_ii.i \ - gr_unpacked_to_packed_ss.i \ - gr_vector_sink_b.i \ - gr_vector_sink_c.i \ - gr_vector_sink_f.i \ - gr_vector_sink_i.i \ - gr_vector_sink_s.i \ - gr_vector_source_b.i \ - gr_vector_source_c.i \ - gr_vector_source_f.i \ - gr_vector_source_i.i \ - gr_vector_source_s.i \ - gr_xor_bb.i \ - gr_xor_ii.i \ - gr_xor_ss.i - -GENERATED_CC = \ - gr_add_cc.cc \ - gr_add_const_cc.cc \ - gr_add_const_ff.cc \ - gr_add_const_ii.cc \ - gr_add_const_sf.cc \ - gr_add_const_ss.cc \ - gr_add_const_vcc.cc \ - gr_add_const_vff.cc \ - gr_add_const_vii.cc \ - gr_add_const_vss.cc \ - gr_add_ii.cc \ - gr_add_ss.cc \ - gr_and_bb.cc \ - gr_and_const_bb.cc \ - gr_and_const_ii.cc \ - gr_and_const_ss.cc \ - gr_and_ii.cc \ - gr_and_ss.cc \ - gr_argmax_fs.cc \ - gr_argmax_is.cc \ - gr_argmax_ss.cc \ - gr_chunks_to_symbols_bc.cc \ - gr_chunks_to_symbols_bf.cc \ - gr_chunks_to_symbols_ic.cc \ - gr_chunks_to_symbols_if.cc \ - gr_chunks_to_symbols_sc.cc \ - gr_chunks_to_symbols_sf.cc \ - gr_divide_cc.cc \ - gr_divide_ff.cc \ - gr_divide_ii.cc \ - gr_divide_ss.cc \ - gr_integrate_cc.cc \ - gr_integrate_ff.cc \ - gr_integrate_ii.cc \ - gr_integrate_ss.cc \ - gr_max_ff.cc \ - gr_max_ii.cc \ - gr_max_ss.cc \ - gr_moving_average_cc.cc \ - gr_moving_average_ff.cc \ - gr_moving_average_ii.cc \ - gr_moving_average_ss.cc \ - gr_multiply_const_ii.cc \ - gr_multiply_const_ss.cc \ - gr_multiply_const_vcc.cc \ - gr_multiply_const_vff.cc \ - gr_multiply_const_vii.cc \ - gr_multiply_const_vss.cc \ - gr_multiply_ii.cc \ - gr_multiply_ss.cc \ - gr_mute_cc.cc \ - gr_mute_ff.cc \ - gr_mute_ii.cc \ - gr_mute_ss.cc \ - gr_noise_source_c.cc \ - gr_noise_source_f.cc \ - gr_noise_source_i.cc \ - gr_noise_source_s.cc \ - gr_not_bb.cc \ - gr_not_ii.cc \ - gr_not_ss.cc \ - gr_or_bb.cc \ - gr_or_ii.cc \ - gr_or_ss.cc \ - gr_packed_to_unpacked_bb.cc \ - gr_packed_to_unpacked_ii.cc \ - gr_packed_to_unpacked_ss.cc \ - gr_peak_detector_fb.cc \ - gr_peak_detector_ib.cc \ - gr_peak_detector_sb.cc \ - gr_probe_signal_b.cc \ - gr_probe_signal_s.cc \ - gr_probe_signal_i.cc \ - gr_probe_signal_f.cc \ - gr_probe_signal_c.cc \ - gr_probe_signal_vb.cc \ - gr_probe_signal_vs.cc \ - gr_probe_signal_vi.cc \ - gr_probe_signal_vf.cc \ - gr_probe_signal_vc.cc \ - gr_sample_and_hold_bb.cc \ - gr_sample_and_hold_ff.cc \ - gr_sample_and_hold_ii.cc \ - gr_sample_and_hold_ss.cc \ - gr_sig_source_c.cc \ - gr_sig_source_f.cc \ - gr_sig_source_i.cc \ - gr_sig_source_s.cc \ - gr_sub_cc.cc \ - gr_sub_ff.cc \ - gr_sub_ii.cc \ - gr_sub_ss.cc \ - gr_unpacked_to_packed_bb.cc \ - gr_unpacked_to_packed_ii.cc \ - gr_unpacked_to_packed_ss.cc \ - gr_vector_sink_b.cc \ - gr_vector_sink_c.cc \ - gr_vector_sink_f.cc \ - gr_vector_sink_i.cc \ - gr_vector_sink_s.cc \ - gr_vector_source_b.cc \ - gr_vector_source_c.cc \ - gr_vector_source_f.cc \ - gr_vector_source_i.cc \ - gr_vector_source_s.cc \ - gr_xor_bb.cc \ - gr_xor_ii.cc \ - gr_xor_ss.cc - diff --git a/gnuradio-core/src/lib/swig/CMakeLists.txt b/gnuradio-core/src/lib/swig/CMakeLists.txt index d3c381b4bc..565bfd691c 100644 --- a/gnuradio-core/src/lib/swig/CMakeLists.txt +++ b/gnuradio-core/src/lib/swig/CMakeLists.txt @@ -43,7 +43,7 @@ set(GR_SWIG_LIBRARIES gnuradio-core) # X86_64, g++'s resident set size was 650MB! # ---------------------------------------------------------------- -set(GR_SWIG_TARGET_DEPS gengen_generated filter_generated) +set(GR_SWIG_TARGET_DEPS general_generated gengen_generated filter_generated) foreach(what runtime general gengen filter io hier) SET(GR_SWIG_DOC_FILE ${CMAKE_CURRENT_BINARY_DIR}/${what}_swig_doc.i) -- cgit v1.2.3 From 76258270f53da9a7b6bdeed0b38dde735956012e Mon Sep 17 00:00:00 2001 From: Johnathan Corgan <jcorgan@corganenterprises.com> Date: Tue, 3 Jul 2012 14:21:05 -0700 Subject: swig: added additional swig dependencies gruel/core pmt swig gen depends upon the generated header core depends upon pmt swig custom target Conflicts: gruel/src/swig/CMakeLists.txt --- gnuradio-core/src/lib/swig/CMakeLists.txt | 5 ++++- gruel/src/lib/pmt/CMakeLists.txt | 4 +++- gruel/src/swig/CMakeLists.txt | 5 ++++- 3 files changed, 11 insertions(+), 3 deletions(-) (limited to 'gnuradio-core/src/lib') diff --git a/gnuradio-core/src/lib/swig/CMakeLists.txt b/gnuradio-core/src/lib/swig/CMakeLists.txt index 565bfd691c..5b740d916d 100644 --- a/gnuradio-core/src/lib/swig/CMakeLists.txt +++ b/gnuradio-core/src/lib/swig/CMakeLists.txt @@ -43,7 +43,7 @@ set(GR_SWIG_LIBRARIES gnuradio-core) # X86_64, g++'s resident set size was 650MB! # ---------------------------------------------------------------- -set(GR_SWIG_TARGET_DEPS general_generated gengen_generated filter_generated) +set(GR_SWIG_TARGET_DEPS general_generated gengen_generated filter_generated pmt_swig) foreach(what runtime general gengen filter io hier) SET(GR_SWIG_DOC_FILE ${CMAKE_CURRENT_BINARY_DIR}/${what}_swig_doc.i) @@ -61,8 +61,11 @@ foreach(what runtime general gengen filter io hier) DESTINATION ${GR_INCLUDE_DIR}/gnuradio/swig COMPONENT "core_swig" ) + list(APPEND core_swig_deps ${SWIG_MODULE_gnuradio_core_${what}_REAL_NAME}) endforeach(what) +add_custom_target(core_swig DEPENDS ${core_swig_deps}) + ######################################################################## # Install various files ######################################################################## diff --git a/gruel/src/lib/pmt/CMakeLists.txt b/gruel/src/lib/pmt/CMakeLists.txt index 72bd27a046..6ea616e107 100644 --- a/gruel/src/lib/pmt/CMakeLists.txt +++ b/gruel/src/lib/pmt/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright 2010 Free Software Foundation, Inc. +# Copyright 2010-2012 Free Software Foundation, Inc. # # This file is part of GNU Radio # @@ -53,6 +53,8 @@ ADD_FILE_DEPENDENCIES( ${PMT_SERIAL_TAGS_H} ) +add_custom_target(pmt_generated DEPENDS ${PMT_SERIAL_TAGS_H}) + ######################################################################## # Generate other pmt stuff ######################################################################## diff --git a/gruel/src/swig/CMakeLists.txt b/gruel/src/swig/CMakeLists.txt index f9d1758ec4..9686225874 100644 --- a/gruel/src/swig/CMakeLists.txt +++ b/gruel/src/swig/CMakeLists.txt @@ -23,7 +23,8 @@ include(GrPython) include(GrSwig) -set(GR_SWIG_INCLUDE_DIRS ${GRUEL_INCLUDE_DIRS}) +set(GR_SWIG_TARGET_DEPS pmt_generated) +set(GR_SWIG_INCLUDE_DIRS ${GRUEL_INCLUDE_DIRS} ${CMAKE_CURRENT_BINARY_DIR}) set(GR_SWIG_LIBRARIES gruel) set(GR_SWIG_DOC_FILE ${CMAKE_CURRENT_BINARY_DIR}/pmt_swig_doc.i) @@ -43,3 +44,5 @@ install( DESTINATION ${GR_INCLUDE_DIR}/gruel/swig COMPONENT "gruel_swig" ) + +add_custom_target(pmt_swig DEPENDS ${SWIG_MODULE_pmt_swig_REAL_NAME}) -- cgit v1.2.3 From a5cbf3b508bcdbfdc955a92dc752218359c5c88a Mon Sep 17 00:00:00 2001 From: Josh Blum <josh@joshknows.com> Date: Tue, 3 Jul 2012 12:04:00 -0700 Subject: core: moved VMCIRCBUF related code to runtime This build stuff should not be at the top level. --- CMakeLists.txt | 3 --- cmake/Modules/GrMiscUtils.cmake | 25 ------------------------- gnuradio-core/src/lib/runtime/CMakeLists.txt | 23 +++++++++++++++++++++++ 3 files changed, 23 insertions(+), 28 deletions(-) (limited to 'gnuradio-core/src/lib') diff --git a/CMakeLists.txt b/CMakeLists.txt index 5d0cbe2891..d4155ff3d8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -211,9 +211,6 @@ CPACK_COMPONENT("volk_devel" add_subdirectory(volk) endif(ENABLE_VOLK) - -GR_VMCIRCBUF() - ######################################################################## # Distribute the README file ######################################################################## diff --git a/cmake/Modules/GrMiscUtils.cmake b/cmake/Modules/GrMiscUtils.cmake index 189e97c7e2..a73e3e6d7e 100644 --- a/cmake/Modules/GrMiscUtils.cmake +++ b/cmake/Modules/GrMiscUtils.cmake @@ -208,28 +208,3 @@ function(GR_GEN_TARGET_DEPS name var) set(${var} "DEPENDS;${name};COMMAND;${name}" PARENT_SCOPE) endif() endfunction(GR_GEN_TARGET_DEPS) - - -######################################################################## -# Control availability of vmcircbuf methods. -# For now, only allows disabling of shm methods, which cause uncatchable -# segmentation faults on Cygwin with gcc 4.x (x <= 5) -# Usage: -# GR_VMCIRCBUF() -# -# Will set TRY_SHM_VMCIRCBUF to 1 by default except on Windows machines. -# Can manually set with -DTRY_SHM_VMCIRCBUF=0|1 -######################################################################## -function(GR_VMCIRCBUF) - if(WIN32) - OPTION(TRY_SHM_VMCIRCBUF "Try SHM VMCIRCBUF" OFF) - else(WIN32) - OPTION(TRY_SHM_VMCIRCBUF "Try SHM VMCIRCBUF" ON) - endif(WIN32) - - message(STATUS "TRY_SHM_VMCIRCBUF set to ${TRY_SHM_VMCIRCBUF}.") - - if(TRY_SHM_VMCIRCBUF) - add_definitions( -DTRY_SHM_VMCIRCBUF ) - endif(TRY_SHM_VMCIRCBUF) -endfunction(GR_VMCIRCBUF) diff --git a/gnuradio-core/src/lib/runtime/CMakeLists.txt b/gnuradio-core/src/lib/runtime/CMakeLists.txt index 1415ff4c6c..5f3672dde9 100644 --- a/gnuradio-core/src/lib/runtime/CMakeLists.txt +++ b/gnuradio-core/src/lib/runtime/CMakeLists.txt @@ -21,6 +21,29 @@ # This file included, use CMake directory variables ######################################################################## +######################################################################## +# Control availability of vmcircbuf methods. +# For now, only allows disabling of shm methods, which cause uncatchable +# segmentation faults on Cygwin with gcc 4.x (x <= 5) +# Usage: +# GR_VMCIRCBUF() +# +# Will set TRY_SHM_VMCIRCBUF to 1 by default except on Windows machines. +# Can manually set with -DTRY_SHM_VMCIRCBUF=0|1 +######################################################################## + + if(WIN32) + OPTION(TRY_SHM_VMCIRCBUF "Try SHM VMCIRCBUF" OFF) + else(WIN32) + OPTION(TRY_SHM_VMCIRCBUF "Try SHM VMCIRCBUF" ON) + endif(WIN32) + + message(STATUS "TRY_SHM_VMCIRCBUF set to ${TRY_SHM_VMCIRCBUF}.") + + if(TRY_SHM_VMCIRCBUF) + add_definitions( -DTRY_SHM_VMCIRCBUF ) + endif(TRY_SHM_VMCIRCBUF) + ######################################################################## # Append gnuradio-core library sources ######################################################################## -- cgit v1.2.3 From 3a142bebafdc018bccc80cf124a375b53db03581 Mon Sep 17 00:00:00 2001 From: Johnathan Corgan <jcorgan@corganenterprises.com> Date: Sat, 7 Jul 2012 08:34:38 -0700 Subject: Revert "Merge remote branch 'jblum-github/python_blocks2' into master" This reverts commit f8581fb475267e1a97eaab962e423559fb4bfce2, reversing changes made to 73800434abfb8c6efcf069222b5f0fea9c86870b. --- gnuradio-core/CMakeLists.txt | 4 +- gnuradio-core/src/lib/general/CMakeLists.txt | 1 - gnuradio-core/src/lib/general/general.i | 3 +- gnuradio-core/src/lib/general/gr_block_gateway.cc | 184 ---------------- gnuradio-core/src/lib/general/gr_block_gateway.h | 212 ------------------- gnuradio-core/src/lib/general/gr_block_gateway.i | 46 ---- .../src/python/gnuradio/gr/CMakeLists.txt | 3 - gnuradio-core/src/python/gnuradio/gr/__init__.py | 3 +- gnuradio-core/src/python/gnuradio/gr/gateway.py | 215 ------------------- .../src/python/gnuradio/gr/qa_block_gateway.py | 235 --------------------- 10 files changed, 4 insertions(+), 902 deletions(-) delete mode 100644 gnuradio-core/src/lib/general/gr_block_gateway.cc delete mode 100644 gnuradio-core/src/lib/general/gr_block_gateway.h delete mode 100644 gnuradio-core/src/lib/general/gr_block_gateway.i delete mode 100644 gnuradio-core/src/python/gnuradio/gr/gateway.py delete mode 100644 gnuradio-core/src/python/gnuradio/gr/qa_block_gateway.py (limited to 'gnuradio-core/src/lib') diff --git a/gnuradio-core/CMakeLists.txt b/gnuradio-core/CMakeLists.txt index 5f26216d35..4e76b3c5a6 100644 --- a/gnuradio-core/CMakeLists.txt +++ b/gnuradio-core/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright 2010-2012 Free Software Foundation, Inc. +# Copyright 2010-2011 Free Software Foundation, Inc. # # This file is part of GNU Radio # @@ -64,7 +64,7 @@ GR_SET_GLOBAL(GNURADIO_CORE_INCLUDE_DIRS GR_SET_GLOBAL(GNURADIO_CORE_SWIG_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/gruel/src/swig - ${CMAKE_BINARY_DIR}/gruel/src/swig + ${CMAKE_BINARY_DIR}/gruel/src/swig/ ${CMAKE_CURRENT_SOURCE_DIR}/src/lib/swig ${GNURADIO_CORE_INCLUDE_DIRS} ) diff --git a/gnuradio-core/src/lib/general/CMakeLists.txt b/gnuradio-core/src/lib/general/CMakeLists.txt index 53cb16d38f..5c7b0f3745 100644 --- a/gnuradio-core/src/lib/general/CMakeLists.txt +++ b/gnuradio-core/src/lib/general/CMakeLists.txt @@ -187,7 +187,6 @@ set(gr_core_general_triple_threats gr_agc2_ff gr_align_on_samplenumbers_ss gr_bin_statistics_f - gr_block_gateway gr_bytes_to_syms gr_char_to_float gr_char_to_short diff --git a/gnuradio-core/src/lib/general/general.i b/gnuradio-core/src/lib/general/general.i index 31acaefb8d..c0ce655276 100644 --- a/gnuradio-core/src/lib/general/general.i +++ b/gnuradio-core/src/lib/general/general.i @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2004-2012 Free Software Foundation, Inc. + * Copyright 2004,2005,2006,2007,2008,2009,2010 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -264,4 +264,3 @@ %include "gr_add_ff.i" %include "gr_vector_map.i" %include "gr_tag_debug.i" -%include "gr_block_gateway.i" diff --git a/gnuradio-core/src/lib/general/gr_block_gateway.cc b/gnuradio-core/src/lib/general/gr_block_gateway.cc deleted file mode 100644 index 79b42803af..0000000000 --- a/gnuradio-core/src/lib/general/gr_block_gateway.cc +++ /dev/null @@ -1,184 +0,0 @@ -/* - * Copyright 2011-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 <gr_block_gateway.h> -#include <gr_io_signature.h> -#include <iostream> -#include <boost/bind.hpp> - -/*********************************************************************** - * Helper routines - **********************************************************************/ -template <typename OutType, typename InType> -void copy_pointers(OutType &out, const InType &in){ - out.resize(in.size()); - for (size_t i = 0; i < in.size(); i++){ - out[i] = (void *)(in[i]); - } -} - -/*********************************************************************** - * The gr_block gateway implementation class - **********************************************************************/ -class gr_block_gateway_impl : public gr_block_gateway{ -public: - gr_block_gateway_impl( - gr_feval_ll *handler, - const std::string &name, - gr_io_signature_sptr in_sig, - gr_io_signature_sptr out_sig, - const gr_block_gw_work_type work_type, - const unsigned factor - ): - gr_block(name, in_sig, out_sig), - _handler(handler), - _work_type(work_type) - { - switch(_work_type){ - case GR_BLOCK_GW_WORK_GENERAL: - _decim = 1; //not relevant, but set anyway - _interp = 1; //not relevant, but set anyway - break; - - case GR_BLOCK_GW_WORK_SYNC: - _decim = 1; - _interp = 1; - this->set_fixed_rate(true); - break; - - case GR_BLOCK_GW_WORK_DECIM: - _decim = factor; - _interp = 1; - break; - - case GR_BLOCK_GW_WORK_INTERP: - _decim = 1; - _interp = factor; - this->set_output_multiple(_interp); - break; - } - } - - /******************************************************************* - * Overloads for various scheduler-called functions - ******************************************************************/ - void forecast( - int noutput_items, - gr_vector_int &ninput_items_required - ){ - switch(_work_type){ - case GR_BLOCK_GW_WORK_GENERAL: - _message.action = gr_block_gw_message_type::ACTION_FORECAST; - _message.forecast_args_noutput_items = noutput_items; - _message.forecast_args_ninput_items_required = ninput_items_required; - _handler->calleval(0); - ninput_items_required = _message.forecast_args_ninput_items_required; - return; - - default: - unsigned ninputs = ninput_items_required.size(); - for (unsigned i = 0; i < ninputs; i++) - ninput_items_required[i] = fixed_rate_noutput_to_ninput(noutput_items); - return; - } - } - - int general_work( - int noutput_items, - gr_vector_int &ninput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items - ){ - switch(_work_type){ - case GR_BLOCK_GW_WORK_GENERAL: - _message.action = gr_block_gw_message_type::ACTION_GENERAL_WORK; - _message.general_work_args_noutput_items = noutput_items; - _message.general_work_args_ninput_items = ninput_items; - copy_pointers(_message.general_work_args_input_items, input_items); - _message.general_work_args_output_items = output_items; - _handler->calleval(0); - return _message.general_work_args_return_value; - - default: - int r = work (noutput_items, input_items, output_items); - if (r > 0) consume_each(r*_decim/_interp); - return r; - } - } - - int work( - int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items - ){ - _message.action = gr_block_gw_message_type::ACTION_WORK; - _message.work_args_ninput_items = fixed_rate_noutput_to_ninput(noutput_items); - if (_message.work_args_ninput_items == 0) return -1; - _message.work_args_noutput_items = noutput_items; - copy_pointers(_message.work_args_input_items, input_items); - _message.work_args_output_items = output_items; - _handler->calleval(0); - return _message.work_args_return_value; - } - - int fixed_rate_noutput_to_ninput(int noutput_items){ - return (noutput_items*_decim/_interp) + history() - 1; - } - - int fixed_rate_ninput_to_noutput(int ninput_items){ - return std::max(0, ninput_items - (int)history() + 1)*_interp/_decim; - } - - bool start(void){ - _message.action = gr_block_gw_message_type::ACTION_START; - _handler->calleval(0); - return _message.start_args_return_value; - } - - bool stop(void){ - _message.action = gr_block_gw_message_type::ACTION_STOP; - _handler->calleval(0); - return _message.stop_args_return_value; - } - - gr_block_gw_message_type &gr_block_message(void){ - return _message; - } - -private: - gr_feval_ll *_handler; - gr_block_gw_message_type _message; - const gr_block_gw_work_type _work_type; - unsigned _decim, _interp; -}; - -boost::shared_ptr<gr_block_gateway> gr_make_block_gateway( - gr_feval_ll *handler, - const std::string &name, - gr_io_signature_sptr in_sig, - gr_io_signature_sptr out_sig, - const gr_block_gw_work_type work_type, - const unsigned factor -){ - return boost::shared_ptr<gr_block_gateway>( - new gr_block_gateway_impl(handler, name, in_sig, out_sig, work_type, factor) - ); -} diff --git a/gnuradio-core/src/lib/general/gr_block_gateway.h b/gnuradio-core/src/lib/general/gr_block_gateway.h deleted file mode 100644 index ae91d41b59..0000000000 --- a/gnuradio-core/src/lib/general/gr_block_gateway.h +++ /dev/null @@ -1,212 +0,0 @@ -/* - * Copyright 2011-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_GRBLOCK_GATEWAY_H -#define INCLUDED_GRBLOCK_GATEWAY_H - -#include <gr_core_api.h> -#include <gr_block.h> -#include <gr_feval.h> - -/*! - * The work type enum tells the gateway what kind of block to implement. - * The choices are familiar gnuradio block overloads (sync, decim, interp). - */ -enum gr_block_gw_work_type{ - GR_BLOCK_GW_WORK_GENERAL, - GR_BLOCK_GW_WORK_SYNC, - GR_BLOCK_GW_WORK_DECIM, - GR_BLOCK_GW_WORK_INTERP, -}; - -/*! - * Shared message structure between python and gateway. - * Each action type represents a scheduler-called function. - */ -struct gr_block_gw_message_type{ - enum action_type{ - ACTION_GENERAL_WORK, //dispatch work - ACTION_WORK, //dispatch work - ACTION_FORECAST, //dispatch forecast - ACTION_START, //dispatch start - ACTION_STOP, //dispatch stop - }; - - action_type action; - - int general_work_args_noutput_items; - std::vector<int> general_work_args_ninput_items; - std::vector<void *> general_work_args_input_items; //TODO this should be const void*, but swig cant int cast it right - std::vector<void *> general_work_args_output_items; - int general_work_args_return_value; - - int work_args_ninput_items; - int work_args_noutput_items; - std::vector<void *> work_args_input_items; //TODO this should be const void*, but swig cant int cast it right - std::vector<void *> work_args_output_items; - int work_args_return_value; - - int forecast_args_noutput_items; - std::vector<int> forecast_args_ninput_items_required; - - bool start_args_return_value; - - bool stop_args_return_value; -}; - -/*! - * The gateway block which performs all the magic. - * - * The gateway provides access to all the gr_block routines. - * The methods prefixed with gr_block__ are renamed - * to class methods without the prefix in python. - */ -class GR_CORE_API gr_block_gateway : virtual public gr_block{ -public: - //! Provide access to the shared message object - virtual gr_block_gw_message_type &gr_block_message(void) = 0; - - long gr_block__unique_id(void) const{ - return gr_block::unique_id(); - } - - std::string gr_block__name(void) const{ - return gr_block::name(); - } - - unsigned gr_block__history(void) const{ - return gr_block::history(); - } - - void gr_block__set_history(unsigned history){ - return gr_block::set_history(history); - } - - void gr_block__set_fixed_rate(bool fixed_rate){ - return gr_block::set_fixed_rate(fixed_rate); - } - - bool gr_block__fixed_rate(void) const{ - return gr_block::fixed_rate(); - } - - void gr_block__set_output_multiple(int multiple){ - return gr_block::set_output_multiple(multiple); - } - - int gr_block__output_multiple(void) const{ - return gr_block::output_multiple(); - } - - void gr_block__consume(int which_input, int how_many_items){ - return gr_block::consume(which_input, how_many_items); - } - - void gr_block__consume_each(int how_many_items){ - return gr_block::consume_each(how_many_items); - } - - void gr_block__produce(int which_output, int how_many_items){ - return gr_block::produce(which_output, how_many_items); - } - - void gr_block__set_relative_rate(double relative_rate){ - return gr_block::set_relative_rate(relative_rate); - } - - double gr_block__relative_rate(void) const{ - return gr_block::relative_rate(); - } - - uint64_t gr_block__nitems_read(unsigned int which_input){ - return gr_block::nitems_read(which_input); - } - - uint64_t gr_block__nitems_written(unsigned int which_output){ - return gr_block::nitems_written(which_output); - } - - gr_block::tag_propagation_policy_t gr_block__tag_propagation_policy(void){ - return gr_block::tag_propagation_policy(); - } - - void gr_block__set_tag_propagation_policy(gr_block::tag_propagation_policy_t p){ - return gr_block::set_tag_propagation_policy(p); - } - - void gr_block__add_item_tag( - unsigned int which_output, const gr_tag_t &tag - ){ - return gr_block::add_item_tag(which_output, tag); - } - - void gr_block__add_item_tag( - unsigned int which_output, - uint64_t abs_offset, - const pmt::pmt_t &key, - const pmt::pmt_t &value, - const pmt::pmt_t &srcid=pmt::PMT_F - ){ - return gr_block::add_item_tag(which_output, abs_offset, key, value, srcid); - } - - std::vector<gr_tag_t> gr_block__get_tags_in_range( - unsigned int which_input, - uint64_t abs_start, - uint64_t abs_end - ){ - std::vector<gr_tag_t> tags; - gr_block::get_tags_in_range(tags, which_input, abs_start, abs_end); - return tags; - } - - std::vector<gr_tag_t> gr_block__get_tags_in_range( - unsigned int which_input, - uint64_t abs_start, - uint64_t abs_end, - const pmt::pmt_t &key - ){ - std::vector<gr_tag_t> tags; - gr_block::get_tags_in_range(tags, which_input, abs_start, abs_end, key); - return tags; - } -}; - -/*! - * Make a new gateway block. - * \param handler the swig director object with callback - * \param name the name of the block (Ex: "Shirley") - * \param in_sig the input signature for this block - * \param out_sig the output signature for this block - * \param work_type the type of block overload to implement - * \param factor the decimation or interpolation factor - * \return a new gateway block - */ -GR_CORE_API boost::shared_ptr<gr_block_gateway> gr_make_block_gateway( - gr_feval_ll *handler, - const std::string &name, - gr_io_signature_sptr in_sig, - gr_io_signature_sptr out_sig, - const gr_block_gw_work_type work_type, - const unsigned factor -); - -#endif /* INCLUDED_GRBLOCK_GATEWAY_H */ diff --git a/gnuradio-core/src/lib/general/gr_block_gateway.i b/gnuradio-core/src/lib/general/gr_block_gateway.i deleted file mode 100644 index 8adafdfea3..0000000000 --- a/gnuradio-core/src/lib/general/gr_block_gateway.i +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2011-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. - */ - -//////////////////////////////////////////////////////////////////////// -// standard includes -//////////////////////////////////////////////////////////////////////// -%include <gnuradio.i> -%include <gr_tags.i> -%include <gr_feval.i> - -//////////////////////////////////////////////////////////////////////// -// block headers -//////////////////////////////////////////////////////////////////////// -%{ -#include <gr_block_gateway.h> -%} - -//////////////////////////////////////////////////////////////////////// -// data type support -//////////////////////////////////////////////////////////////////////// -%template(int_vector_t) std::vector<int>; -%template(void_star_vector_t) std::vector<void *>; - -//////////////////////////////////////////////////////////////////////// -// block magic -//////////////////////////////////////////////////////////////////////// -GR_SWIG_BLOCK_MAGIC(gr,block_gateway); -%include <gr_block_gateway.h> diff --git a/gnuradio-core/src/python/gnuradio/gr/CMakeLists.txt b/gnuradio-core/src/python/gnuradio/gr/CMakeLists.txt index 62f3d7e46d..3e75ead031 100644 --- a/gnuradio-core/src/python/gnuradio/gr/CMakeLists.txt +++ b/gnuradio-core/src/python/gnuradio/gr/CMakeLists.txt @@ -23,7 +23,6 @@ include(GrPython) GR_PYTHON_INSTALL(FILES __init__.py exceptions.py - gateway.py gr_threading.py gr_threading_23.py gr_threading_24.py @@ -44,8 +43,6 @@ 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) set(GR_TEST_PYTHON_DIRS - ${CMAKE_SOURCE_DIR}/gruel/src/python - ${CMAKE_BINARY_DIR}/gruel/src/swig ${CMAKE_BINARY_DIR}/gnuradio-core/src/python ${CMAKE_BINARY_DIR}/gnuradio-core/src/lib/swig ) diff --git a/gnuradio-core/src/python/gnuradio/gr/__init__.py b/gnuradio-core/src/python/gnuradio/gr/__init__.py index 5b9a6a32c7..602d1119fb 100644 --- a/gnuradio-core/src/python/gnuradio/gr/__init__.py +++ b/gnuradio-core/src/python/gnuradio/gr/__init__.py @@ -1,5 +1,5 @@ # -# Copyright 2003-2012 Free Software Foundation, Inc. +# Copyright 2003,2004,2006,2008,2009,2010 Free Software Foundation, Inc. # # This file is part of GNU Radio # @@ -44,7 +44,6 @@ from gnuradio_core import * from exceptions import * from hier_block2 import * from top_block import * -from gateway import basic_block, sync_block, decim_block, interp_block if _RTLD_GLOBAL != 0: sys.setdlopenflags(_dlopenflags) # Restore original flags diff --git a/gnuradio-core/src/python/gnuradio/gr/gateway.py b/gnuradio-core/src/python/gnuradio/gr/gateway.py deleted file mode 100644 index 244b8b5925..0000000000 --- a/gnuradio-core/src/python/gnuradio/gr/gateway.py +++ /dev/null @@ -1,215 +0,0 @@ -# -# Copyright 2011-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. -# - -import gnuradio_core as gr_core -from gnuradio_core import io_signature, io_signaturev -from gnuradio_core import gr_block_gw_message_type -from gnuradio_core import block_gateway -import numpy - -######################################################################## -# Magic to turn pointers into numpy arrays -# http://docs.scipy.org/doc/numpy/reference/arrays.interface.html -######################################################################## -def pointer_to_ndarray(addr, dtype, nitems): - class array_like: - __array_interface__ = { - 'data' : (int(addr), False), - 'typestr' : dtype.base.str, - 'descr' : dtype.base.descr, - 'shape' : (nitems,) + dtype.shape, - 'strides' : None, - 'version' : 3 - } - return numpy.asarray(array_like()).view(dtype.base) - -######################################################################## -# Handler that does callbacks from C++ -######################################################################## -class gateway_handler(gr_core.feval_ll): - - #dont put a constructor, it wont work - - def init(self, callback): - self._callback = callback - - def eval(self, arg): - try: self._callback() - except Exception as ex: - print("handler caught exception: %s"%ex) - import traceback; traceback.print_exc() - raise ex - return 0 - -######################################################################## -# The guts that make this into a gr block -######################################################################## -class gateway_block(object): - - def __init__(self, name, in_sig, out_sig, work_type, factor): - - #ensure that the sigs are iterable dtypes - def sig_to_dtype_sig(sig): - if sig is None: sig = () - return map(numpy.dtype, sig) - self.__in_sig = sig_to_dtype_sig(in_sig) - self.__out_sig = sig_to_dtype_sig(out_sig) - - #cache the ranges to iterate when dispatching work - self.__in_indexes = range(len(self.__in_sig)) - self.__out_indexes = range(len(self.__out_sig)) - - #convert the signatures into gr.io_signatures - def sig_to_gr_io_sigv(sig): - if not len(sig): return io_signature(0, 0, 0) - return io_signaturev(len(sig), len(sig), [s.itemsize for s in sig]) - gr_in_sig = sig_to_gr_io_sigv(self.__in_sig) - gr_out_sig = sig_to_gr_io_sigv(self.__out_sig) - - #create internal gateway block - self.__handler = gateway_handler() - self.__handler.init(self.__gr_block_handle) - self.__gateway = block_gateway( - self.__handler, name, gr_in_sig, gr_out_sig, work_type, factor) - self.__message = self.__gateway.gr_block_message() - - #register gr_block functions - prefix = 'gr_block__' - for attr in [x for x in dir(self.__gateway) if x.startswith(prefix)]: - setattr(self, attr.replace(prefix, ''), getattr(self.__gateway, attr)) - self.pop_msg_queue = lambda: gr_core.gr_block_gw_pop_msg_queue_safe(self.__gateway) - - def to_basic_block(self): - """ - Makes this block connectable by hier/top block python - """ - return self.__gateway.to_basic_block() - - def __gr_block_handle(self): - """ - Dispatch tasks according to the action type specified in the message. - """ - if self.__message.action == gr_block_gw_message_type.ACTION_GENERAL_WORK: - self.__message.general_work_args_return_value = self.general_work( - - input_items=[pointer_to_ndarray( - self.__message.general_work_args_input_items[i], - self.__in_sig[i], - self.__message.general_work_args_ninput_items[i] - ) for i in self.__in_indexes], - - output_items=[pointer_to_ndarray( - self.__message.general_work_args_output_items[i], - self.__out_sig[i], - self.__message.general_work_args_noutput_items - ) for i in self.__out_indexes], - ) - - elif self.__message.action == gr_block_gw_message_type.ACTION_WORK: - self.__message.work_args_return_value = self.work( - - input_items=[pointer_to_ndarray( - self.__message.work_args_input_items[i], - self.__in_sig[i], - self.__message.work_args_ninput_items - ) for i in self.__in_indexes], - - output_items=[pointer_to_ndarray( - self.__message.work_args_output_items[i], - self.__out_sig[i], - self.__message.work_args_noutput_items - ) for i in self.__out_indexes], - ) - - elif self.__message.action == gr_block_gw_message_type.ACTION_FORECAST: - self.forecast( - noutput_items=self.__message.forecast_args_noutput_items, - ninput_items_required=self.__message.forecast_args_ninput_items_required, - ) - - elif self.__message.action == gr_block_gw_message_type.ACTION_START: - self.__message.start_args_return_value = self.start() - - elif self.__message.action == gr_block_gw_message_type.ACTION_STOP: - self.__message.stop_args_return_value = self.stop() - - def forecast(self, noutput_items, ninput_items_required): - """ - forecast is only called from a general block - this is the default implementation - """ - for ninput_item in ninput_items_required: - ninput_item = noutput_items + self.history() - 1; - return - - def general_work(self, *args, **kwargs): - """general work to be overloaded in a derived class""" - raise NotImplementedError("general work not implemented") - - def work(self, *args, **kwargs): - """work to be overloaded in a derived class""" - raise NotImplementedError("work not implemented") - - def start(self): return True - def stop(self): return True - -######################################################################## -# Wrappers for the user to inherit from -######################################################################## -class basic_block(gateway_block): - def __init__(self, name, in_sig, out_sig): - gateway_block.__init__(self, - name=name, - in_sig=in_sig, - out_sig=out_sig, - work_type=gr_core.GR_BLOCK_GW_WORK_GENERAL, - factor=1, #not relevant factor - ) - -class sync_block(gateway_block): - def __init__(self, name, in_sig, out_sig): - gateway_block.__init__(self, - name=name, - in_sig=in_sig, - out_sig=out_sig, - work_type=gr_core.GR_BLOCK_GW_WORK_SYNC, - factor=1, - ) - -class decim_block(gateway_block): - def __init__(self, name, in_sig, out_sig, decim): - gateway_block.__init__(self, - name=name, - in_sig=in_sig, - out_sig=out_sig, - work_type=gr_core.GR_BLOCK_GW_WORK_DECIM, - factor=decim, - ) - -class interp_block(gateway_block): - def __init__(self, name, in_sig, out_sig, interp): - gateway_block.__init__(self, - name=name, - in_sig=in_sig, - out_sig=out_sig, - work_type=gr_core.GR_BLOCK_GW_WORK_INTERP, - factor=interp, - ) diff --git a/gnuradio-core/src/python/gnuradio/gr/qa_block_gateway.py b/gnuradio-core/src/python/gnuradio/gr/qa_block_gateway.py deleted file mode 100644 index 89eb8aed6e..0000000000 --- a/gnuradio-core/src/python/gnuradio/gr/qa_block_gateway.py +++ /dev/null @@ -1,235 +0,0 @@ -# -# Copyright 2011-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. -# - -from gnuradio import gr, gr_unittest -import pmt #from gruel import pmt -import numpy - -class add_2_f32_1_f32(gr.sync_block): - def __init__(self): - gr.sync_block.__init__( - self, - name = "add 2 f32", - in_sig = [numpy.float32, numpy.float32], - out_sig = [numpy.float32], - ) - - def work(self, input_items, output_items): - output_items[0][:] = input_items[0] + input_items[1] - return len(output_items[0]) - -class add_2_fc32_1_fc32(gr.sync_block): - def __init__(self): - gr.sync_block.__init__( - self, - name = "add 2 fc32", - in_sig = [numpy.complex64, numpy.complex64], - out_sig = [numpy.complex64], - ) - - def work(self, input_items, output_items): - output_items[0][:] = input_items[0] + input_items[1] - return len(output_items[0]) - -class convolve(gr.sync_block): - """ - A demonstration using block history to properly perform a convolution. - """ - def __init__(self): - gr.sync_block.__init__( - self, - name = "convolve", - in_sig = [numpy.float32], - out_sig = [numpy.float32] - ) - self._taps = [1, 0, 0, 0] - self.set_history(len(self._taps)) - - def work(self, input_items, output_items): - output_items[0][:] = numpy.convolve(input_items[0], self._taps, mode='valid') - return len(output_items[0]) - -class decim2x(gr.decim_block): - def __init__(self): - gr.decim_block.__init__( - self, - name = "decim2x", - in_sig = [numpy.float32], - out_sig = [numpy.float32], - decim = 2 - ) - - def work(self, input_items, output_items): - output_items[0][:] = input_items[0][::2] - return len(output_items[0]) - -class interp2x(gr.interp_block): - def __init__(self): - gr.interp_block.__init__( - self, - name = "interp2x", - in_sig = [numpy.float32], - out_sig = [numpy.float32], - interp = 2 - ) - - def work(self, input_items, output_items): - output_items[0][1::2] = input_items[0] - output_items[0][::2] = input_items[0] - return len(output_items[0]) - -class tag_source(gr.sync_block): - def __init__(self): - gr.sync_block.__init__( - self, - name = "tag source", - in_sig = None, - out_sig = [numpy.float32], - ) - - def work(self, input_items, output_items): - num_output_items = len(output_items[0]) - - #put code here to fill the output items... - - #make a new tag on the middle element every time work is called - count = self.nitems_written(0) + num_output_items/2 - key = pmt.pmt_string_to_symbol("example_key") - value = pmt.pmt_string_to_symbol("example_value") - self.add_item_tag(0, count, key, value) - - return num_output_items - -class tag_sink(gr.sync_block): - def __init__(self): - gr.sync_block.__init__( - self, - name = "tag sink", - in_sig = [numpy.float32], - out_sig = None, - ) - self.key = None - - def work(self, input_items, output_items): - num_input_items = len(input_items[0]) - - #put code here to process the input items... - - #print all the tags received in this work call - nread = self.nitems_read(0) - tags = self.get_tags_in_range(0, nread, nread+num_input_items) - for tag in tags: - print tag.offset - print pmt.pmt_symbol_to_string(tag.key) - print pmt.pmt_symbol_to_string(tag.value) - self.key = pmt.pmt_symbol_to_string(tag.key) - - return num_input_items - -class fc32_to_f32_2(gr.sync_block): - def __init__(self): - gr.sync_block.__init__( - self, - name = "fc32_to_f32_2", - in_sig = [numpy.complex64], - out_sig = [(numpy.float32, 2)], - ) - - def work(self, input_items, output_items): - output_items[0][::,0] = numpy.real(input_items[0]) - output_items[0][::,1] = numpy.imag(input_items[0]) - return len(output_items[0]) - -class test_block_gateway(gr_unittest.TestCase): - - def test_add_f32(self): - tb = gr.top_block() - src0 = gr.vector_source_f([1, 3, 5, 7, 9], False) - src1 = gr.vector_source_f([0, 2, 4, 6, 8], False) - adder = add_2_f32_1_f32() - sink = gr.vector_sink_f() - tb.connect((src0, 0), (adder, 0)) - tb.connect((src1, 0), (adder, 1)) - tb.connect(adder, sink) - tb.run() - self.assertEqual(sink.data(), (1, 5, 9, 13, 17)) - - def test_add_fc32(self): - tb = gr.top_block() - src0 = gr.vector_source_c([1, 3j, 5, 7j, 9], False) - src1 = gr.vector_source_c([0, 2j, 4, 6j, 8], False) - adder = add_2_fc32_1_fc32() - sink = gr.vector_sink_c() - tb.connect((src0, 0), (adder, 0)) - tb.connect((src1, 0), (adder, 1)) - tb.connect(adder, sink) - tb.run() - self.assertEqual(sink.data(), (1, 5j, 9, 13j, 17)) - - def test_convolve(self): - tb = gr.top_block() - src = gr.vector_source_f([1, 2, 3, 4, 5, 6, 7, 8], False) - cv = convolve() - sink = gr.vector_sink_f() - tb.connect(src, cv, sink) - tb.run() - self.assertEqual(sink.data(), (1, 2, 3, 4, 5, 6, 7, 8)) - - def test_decim2x(self): - tb = gr.top_block() - src = gr.vector_source_f([1, 2, 3, 4, 5, 6, 7, 8], False) - d2x = decim2x() - sink = gr.vector_sink_f() - tb.connect(src, d2x, sink) - tb.run() - self.assertEqual(sink.data(), (1, 3, 5, 7)) - - def test_interp2x(self): - tb = gr.top_block() - src = gr.vector_source_f([1, 3, 5, 7, 9], False) - i2x = interp2x() - sink = gr.vector_sink_f() - tb.connect(src, i2x, sink) - tb.run() - self.assertEqual(sink.data(), (1, 1, 3, 3, 5, 5, 7, 7, 9, 9)) - - def test_tags(self): - src = tag_source() - sink = tag_sink() - head = gr.head(gr.sizeof_float, 50000) #should be enough items to get a tag through - tb = gr.top_block() - tb.connect(src, head, sink) - tb.run() - self.assertEqual(sink.key, "example_key") - - def test_fc32_to_f32_2(self): - tb = gr.top_block() - src = gr.vector_source_c([1+2j, 3+4j, 5+6j, 7+8j, 9+10j], False) - convert = fc32_to_f32_2() - v2s = gr.vector_to_stream(gr.sizeof_float, 2) - sink = gr.vector_sink_f() - tb.connect(src, convert, v2s, sink) - tb.run() - self.assertEqual(sink.data(), (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)) - -if __name__ == '__main__': - gr_unittest.run(test_block_gateway, "test_block_gateway.xml") - -- cgit v1.2.3 From 494b13ab6e5b342e03e3e3202dea9c3a85ff46e1 Mon Sep 17 00:00:00 2001 From: Nick Foster <nick@ettus.com> Date: Thu, 19 Jul 2012 19:15:29 -0400 Subject: core: added message source that takes in tags for controlling bursts. --- gnuradio-core/src/lib/io/CMakeLists.txt | 1 + .../src/lib/io/gr_message_burst_source.cc | 144 +++++++++++++++++++++ gnuradio-core/src/lib/io/gr_message_burst_source.h | 71 ++++++++++ gnuradio-core/src/lib/io/gr_message_burst_source.i | 38 ++++++ gnuradio-core/src/lib/io/io.i | 2 + grc/blocks/block_tree.xml | 1 + 6 files changed, 257 insertions(+) create mode 100644 gnuradio-core/src/lib/io/gr_message_burst_source.cc create mode 100644 gnuradio-core/src/lib/io/gr_message_burst_source.h create mode 100644 gnuradio-core/src/lib/io/gr_message_burst_source.i (limited to 'gnuradio-core/src/lib') diff --git a/gnuradio-core/src/lib/io/CMakeLists.txt b/gnuradio-core/src/lib/io/CMakeLists.txt index af9d7583c3..3dea13396c 100644 --- a/gnuradio-core/src/lib/io/CMakeLists.txt +++ b/gnuradio-core/src/lib/io/CMakeLists.txt @@ -87,6 +87,7 @@ set(gr_core_io_triple_threats gr_file_descriptor_source gr_message_sink gr_message_source + gr_message_burst_source microtune_xxxx_eval_board microtune_4702_eval_board microtune_4937_eval_board diff --git a/gnuradio-core/src/lib/io/gr_message_burst_source.cc b/gnuradio-core/src/lib/io/gr_message_burst_source.cc new file mode 100644 index 0000000000..e9e2dfd4dc --- /dev/null +++ b/gnuradio-core/src/lib/io/gr_message_burst_source.cc @@ -0,0 +1,144 @@ +/* -*- c++ -*- */ +/* + * 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. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <gr_message_burst_source.h> +#include <gr_io_signature.h> +#include <cstdio> +#include <errno.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <stdexcept> +#include <string.h> +#include <gr_tags.h> + +// public constructor that returns a shared_ptr + +gr_message_burst_source_sptr +gr_make_message_burst_source(size_t itemsize, int msgq_limit) +{ + return gnuradio::get_initial_sptr(new gr_message_burst_source(itemsize, msgq_limit)); +} + +// public constructor that takes existing message queue +gr_message_burst_source_sptr +gr_make_message_burst_source(size_t itemsize, gr_msg_queue_sptr msgq) +{ + return gnuradio::get_initial_sptr(new gr_message_burst_source(itemsize, msgq)); +} + +gr_message_burst_source::gr_message_burst_source (size_t itemsize, int msgq_limit) + : gr_sync_block("message_burst_source", + gr_make_io_signature(0, 0, 0), + gr_make_io_signature(1, 1, itemsize)), + d_itemsize(itemsize), d_msgq(gr_make_msg_queue(msgq_limit)), d_msg_offset(0), d_eof(false) +{ + std::stringstream id; + id << name() << unique_id(); + d_me = pmt::pmt_string_to_symbol(id.str()); +} + +gr_message_burst_source::gr_message_burst_source (size_t itemsize, gr_msg_queue_sptr msgq) + : gr_sync_block("message_burst_source", + gr_make_io_signature(0, 0, 0), + gr_make_io_signature(1, 1, itemsize)), + d_itemsize(itemsize), d_msgq(msgq), d_msg_offset(0), d_eof(false) +{ + std::stringstream id; + id << name() << unique_id(); + d_me = pmt::pmt_string_to_symbol(id.str()); +} + +gr_message_burst_source::~gr_message_burst_source() +{ +} + +int +gr_message_burst_source::work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) +{ + char *out = (char *) output_items[0]; + int nn = 0; + + uint64_t abs_sample_count = nitems_written(0); + + while (nn < noutput_items){ + if (d_msg){ + // + // Consume whatever we can from the current message + // + + int mm = std::min(noutput_items - nn, (int)((d_msg->length() - d_msg_offset) / d_itemsize)); + memcpy (out, &(d_msg->msg()[d_msg_offset]), mm * d_itemsize); + + nn += mm; + out += mm * d_itemsize; + d_msg_offset += mm * d_itemsize; + assert(d_msg_offset <= d_msg->length()); + + if (d_msg_offset == d_msg->length()){ + if (d_msg->type() == 1) // type == 1 sets EOF + d_eof = true; + d_msg.reset(); + //tag end of burst + add_item_tag(0, //stream ID + abs_sample_count+nn-1, //sample number + pmt::pmt_string_to_symbol("tx_eob"), + pmt::pmt_from_bool(1), + d_me //block src id + ); + } + } + else { + // + // No current message + // + if (d_msgq->empty_p() && nn > 0){ // no more messages in the queue, return what we've got + break; + } + + if (d_eof) + return -1; + + d_msg = d_msgq->delete_head(); // block, waiting for a message + d_msg_offset = 0; + //tag start of burst + add_item_tag(0, //stream ID + abs_sample_count+nn, //sample number + pmt::pmt_string_to_symbol("tx_sob"), + pmt::pmt_from_bool(1), + d_me //block src id + ); + + + if ((d_msg->length() % d_itemsize) != 0) + throw std::runtime_error("msg length is not a multiple of d_itemsize"); + } + } + + return nn; +} diff --git a/gnuradio-core/src/lib/io/gr_message_burst_source.h b/gnuradio-core/src/lib/io/gr_message_burst_source.h new file mode 100644 index 0000000000..63e2201139 --- /dev/null +++ b/gnuradio-core/src/lib/io/gr_message_burst_source.h @@ -0,0 +1,71 @@ +/* -*- c++ -*- */ +/* + * 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. + */ + +#ifndef INCLUDED_GR_MESSAGE_BURST_SOURCE_H +#define INCLUDED_GR_MESSAGE_BURST_SOURCE_H + +#include <gr_core_api.h> +#include <gr_sync_block.h> +#include <gr_message.h> +#include <gr_msg_queue.h> + +class gr_message_burst_source; +typedef boost::shared_ptr<gr_message_burst_source> gr_message_burst_source_sptr; + +GR_CORE_API gr_message_burst_source_sptr gr_make_message_burst_source (size_t itemsize, int msgq_limit=0); +GR_CORE_API gr_message_burst_source_sptr gr_make_message_burst_source (size_t itemsize, gr_msg_queue_sptr msgq); + +/*! + * \brief Turn received messages into a stream and tag them for UHD to send. + * \ingroup source_blk + */ +class GR_CORE_API gr_message_burst_source : public gr_sync_block +{ + private: + size_t d_itemsize; + gr_msg_queue_sptr d_msgq; + gr_message_sptr d_msg; + unsigned d_msg_offset; + bool d_eof; + + pmt::pmt_t d_me; + + friend GR_CORE_API gr_message_burst_source_sptr + gr_make_message_burst_source(size_t itemsize, int msgq_limit); + friend GR_CORE_API gr_message_burst_source_sptr + gr_make_message_burst_source(size_t itemsize, gr_msg_queue_sptr msgq); + + protected: + gr_message_burst_source (size_t itemsize, int msgq_limit); + gr_message_burst_source (size_t itemsize, gr_msg_queue_sptr msgq); + + public: + ~gr_message_burst_source (); + + gr_msg_queue_sptr msgq() const { return d_msgq; } + + int work (int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); +}; + +#endif /* INCLUDED_gr_message_burst_source_H */ diff --git a/gnuradio-core/src/lib/io/gr_message_burst_source.i b/gnuradio-core/src/lib/io/gr_message_burst_source.i new file mode 100644 index 0000000000..f7ad840c22 --- /dev/null +++ b/gnuradio-core/src/lib/io/gr_message_burst_source.i @@ -0,0 +1,38 @@ +/* -*- c++ -*- */ +/* + * 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. + */ + +GR_SWIG_BLOCK_MAGIC(gr,message_burst_source); + +gr_message_burst_source_sptr gr_make_message_burst_source (size_t itemsize, int msgq_limit=0); +gr_message_burst_source_sptr gr_make_message_burst_source (size_t itemsize, gr_msg_queue_sptr msgq); + +class gr_message_burst_source : public gr_sync_block +{ + protected: + gr_message_burst_source (size_t itemsize, int msgq_limit); + gr_message_burst_source (size_t itemsize, gr_msg_queue_sptr msgq); + + public: + ~gr_message_burst_source (); + + gr_msg_queue_sptr msgq() const; +}; diff --git a/gnuradio-core/src/lib/io/io.i b/gnuradio-core/src/lib/io/io.i index eab1346f18..5cd352905d 100644 --- a/gnuradio-core/src/lib/io/io.i +++ b/gnuradio-core/src/lib/io/io.i @@ -38,6 +38,7 @@ #include <gr_oscope_sink_f.h> #include <ppio.h> #include <gr_message_source.h> +#include <gr_message_burst_source.h> #include <gr_message_sink.h> #include <gr_udp_sink.h> #include <gr_udp_source.h> @@ -59,6 +60,7 @@ %include "gr_oscope_sink.i" %include "ppio.i" %include "gr_message_source.i" +%include "gr_message_burst_source.i" %include "gr_message_sink.i" %include "gr_udp_sink.i" %include "gr_udp_source.i" diff --git a/grc/blocks/block_tree.xml b/grc/blocks/block_tree.xml index f94bd30bdf..3b5491a745 100644 --- a/grc/blocks/block_tree.xml +++ b/grc/blocks/block_tree.xml @@ -20,6 +20,7 @@ <block>gr_udp_source</block> <block>gr_wavfile_source</block> <block>gr_message_source</block> + <block>gr_message_burst_source</block> <block>pad_source</block> <block>virtual_source</block> </cat> -- cgit v1.2.3 From 9305abf4be93205cf240e99ce7136702f724c490 Mon Sep 17 00:00:00 2001 From: Jaroslav Skarvada <jskarvad@redhat.com> Date: Sun, 5 Aug 2012 18:26:33 -0400 Subject: arm: better support for ARM processors without NEON. --- gnuradio-core/src/lib/filter/CMakeLists.txt | 3 +++ gnuradio-core/src/lib/filter/dotprod_ccf_armv7_a.c | 2 +- gnuradio-core/src/lib/filter/dotprod_fff_armv7_a.c | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) (limited to 'gnuradio-core/src/lib') diff --git a/gnuradio-core/src/lib/filter/CMakeLists.txt b/gnuradio-core/src/lib/filter/CMakeLists.txt index facaff764d..088d3376d1 100644 --- a/gnuradio-core/src/lib/filter/CMakeLists.txt +++ b/gnuradio-core/src/lib/filter/CMakeLists.txt @@ -210,6 +210,9 @@ elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(powerpc|ppc)") ${CMAKE_CURRENT_SOURCE_DIR}/qa_dotprod_powerpc.cc ) elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^arm") + if(have_mfpu_neon) + add_definitions(-DHAVE_MFPU_NEON) + endif() list(APPEND gnuradio_core_sources ${CMAKE_CURRENT_SOURCE_DIR}/sysconfig_armv7_a.cc ${CMAKE_CURRENT_SOURCE_DIR}/gr_fir_sysconfig_armv7_a.cc diff --git a/gnuradio-core/src/lib/filter/dotprod_ccf_armv7_a.c b/gnuradio-core/src/lib/filter/dotprod_ccf_armv7_a.c index e7c6b266e3..c125b49b3c 100644 --- a/gnuradio-core/src/lib/filter/dotprod_ccf_armv7_a.c +++ b/gnuradio-core/src/lib/filter/dotprod_ccf_armv7_a.c @@ -37,7 +37,7 @@ gr_p2_round_down(size_t x, size_t pow2) } -#if 0 +#ifndef HAVE_MFPU_NEON void dotprod_ccf_armv7_a(const float *a, const float *b, float *res, size_t n) diff --git a/gnuradio-core/src/lib/filter/dotprod_fff_armv7_a.c b/gnuradio-core/src/lib/filter/dotprod_fff_armv7_a.c index 68c448b356..23bbef0338 100644 --- a/gnuradio-core/src/lib/filter/dotprod_fff_armv7_a.c +++ b/gnuradio-core/src/lib/filter/dotprod_fff_armv7_a.c @@ -37,7 +37,7 @@ gr_p2_round_down(size_t x, size_t pow2) } -#if 0 +#ifndef HAVE_MFPU_NEON float dotprod_fff_armv7_a(const float *a, const float *b, size_t n) -- cgit v1.2.3 From 0e2f0c6473530ef6823a27f4f294826c777afe06 Mon Sep 17 00:00:00 2001 From: Tim O'Shea <tim.oshea753@gmail.com> Date: Wed, 29 Aug 2012 20:27:18 -0400 Subject: adding gr_endian_swap block --- gnuradio-core/src/lib/general/CMakeLists.txt | 1 + gnuradio-core/src/lib/general/general.i | 2 + gnuradio-core/src/lib/general/gr_endian_swap.cc | 101 +++++++++++++++++++++ gnuradio-core/src/lib/general/gr_endian_swap.h | 57 ++++++++++++ gnuradio-core/src/lib/general/gr_endian_swap.i | 31 +++++++ .../src/python/gnuradio/gr/qa_endian_swap.py | 66 ++++++++++++++ grc/blocks/block_tree.xml | 2 + grc/blocks/gr_endian_swap.xml | 41 +++++++++ volk/include/volk/volk_32u_byteswap_u.h | 77 ++++++++++++++++ volk/include/volk/volk_64u_byteswap_u.h | 88 ++++++++++++++++++ 10 files changed, 466 insertions(+) create mode 100644 gnuradio-core/src/lib/general/gr_endian_swap.cc create mode 100644 gnuradio-core/src/lib/general/gr_endian_swap.h create mode 100644 gnuradio-core/src/lib/general/gr_endian_swap.i create mode 100644 gnuradio-core/src/python/gnuradio/gr/qa_endian_swap.py create mode 100644 grc/blocks/gr_endian_swap.xml create mode 100644 volk/include/volk/volk_32u_byteswap_u.h create mode 100644 volk/include/volk/volk_64u_byteswap_u.h (limited to 'gnuradio-core/src/lib') diff --git a/gnuradio-core/src/lib/general/CMakeLists.txt b/gnuradio-core/src/lib/general/CMakeLists.txt index 5c7b0f3745..3cf7f74e4c 100644 --- a/gnuradio-core/src/lib/general/CMakeLists.txt +++ b/gnuradio-core/src/lib/general/CMakeLists.txt @@ -207,6 +207,7 @@ set(gr_core_general_triple_threats gr_deinterleave gr_delay gr_encode_ccsds_27_bb + gr_endian_swap gr_fake_channel_coder_pp gr_feedforward_agc_cc gr_feval diff --git a/gnuradio-core/src/lib/general/general.i b/gnuradio-core/src/lib/general/general.i index c0ce655276..790549c4dd 100644 --- a/gnuradio-core/src/lib/general/general.i +++ b/gnuradio-core/src/lib/general/general.i @@ -60,6 +60,7 @@ #include <gr_complex_to_interleaved_short.h> #include <gr_interleaved_short_to_complex.h> //#include <gr_endianness.h> +#include <gr_endian_swap.h> #include <gr_firdes.h> #include <gr_interleave.h> #include <gr_deinterleave.h> @@ -181,6 +182,7 @@ %include "gr_complex_to_xxx.i" %include "gr_complex_to_interleaved_short.i" //%include "gr_endianness.i" +%include "gr_endian_swap.i" %include "gr_interleaved_short_to_complex.i" %include "gr_firdes.i" %include "gr_interleave.i" diff --git a/gnuradio-core/src/lib/general/gr_endian_swap.cc b/gnuradio-core/src/lib/general/gr_endian_swap.cc new file mode 100644 index 0000000000..d86da5aa72 --- /dev/null +++ b/gnuradio-core/src/lib/general/gr_endian_swap.cc @@ -0,0 +1,101 @@ +/* -*- 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. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <gr_endian_swap.h> +#include <gr_io_signature.h> +#include <volk/volk.h> + +gr_endian_swap_sptr +gr_make_endian_swap (size_t item_size_bytes) +{ + return gnuradio::get_initial_sptr(new gr_endian_swap (item_size_bytes)); +} + +gr_endian_swap::gr_endian_swap (size_t item_size_bytes) + : gr_sync_block ("gr_endian_swap", + gr_make_io_signature (1, 1, item_size_bytes), + gr_make_io_signature (1, 1, item_size_bytes)) +{ + const int alignment_multiple = volk_get_alignment(); + set_alignment(std::max(1,alignment_multiple)); +} + +int +gr_endian_swap::work (int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) +{ + const char *in = (const char *) input_items[0]; + char *out = (char *) output_items[0]; + + int nbytes( d_output_signature->sizeof_stream_item(0) ); + if(is_unaligned()) { + switch(nbytes){ + case 1: + memcpy(out,in,noutput_items); + break; + case 2: + memcpy(out,in,2*noutput_items); + volk_16u_byteswap_u((uint16_t*)out,noutput_items); + break; + case 4: + memcpy(out,in,4*noutput_items); + volk_32u_byteswap_u((uint32_t*)out,noutput_items); + break; + case 8: + memcpy(out,in,8*noutput_items); + volk_64u_byteswap_u((uint64_t*)out,noutput_items); + break; + default: + throw std::runtime_error("itemsize is not valid for gr_endian_swap!"); + } + } else { + switch(nbytes){ + case 1: + memcpy(out,in,noutput_items); + break; + case 2: + memcpy(out,in,2*noutput_items); + volk_16u_byteswap_a((uint16_t*)out,noutput_items); + break; + case 4: + memcpy(out,in,4*noutput_items); + volk_32u_byteswap_a((uint32_t*)out,noutput_items); + break; + case 8: + memcpy(out,in,8*noutput_items); + volk_64u_byteswap_a((uint64_t*)out,noutput_items); + break; + default: + throw std::runtime_error("itemsize is not valid for gr_endian_swap!"); + } + } + + return noutput_items; +} + + + diff --git a/gnuradio-core/src/lib/general/gr_endian_swap.h b/gnuradio-core/src/lib/general/gr_endian_swap.h new file mode 100644 index 0000000000..0baa3f3389 --- /dev/null +++ b/gnuradio-core/src/lib/general/gr_endian_swap.h @@ -0,0 +1,57 @@ +/* -*- 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_GR_ENDIAN_SWAP_H +#define INCLUDED_GR_ENDIAN_SWAP_H + +#include <gr_core_api.h> +#include <gr_sync_block.h> + +class gr_endian_swap; +typedef boost::shared_ptr<gr_endian_swap> gr_endian_swap_sptr; + +GR_CORE_API gr_endian_swap_sptr +gr_make_endian_swap (size_t item_size_bytes=1); + +/*! + * \brief Convert stream of items into thier byte swapped version + * + * \param item_size_bytes number of bytes per item, 1=no-op,2=uint16_t,4=uint32_t,8=uint64_t + */ + +class GR_CORE_API gr_endian_swap : public gr_sync_block +{ + private: + friend GR_CORE_API gr_endian_swap_sptr + gr_make_endian_swap (size_t item_size_bytes); + gr_endian_swap (size_t item_size_bytes); + + size_t item_size_bytes; + + public: + virtual int work (int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); +}; + + +#endif /* INCLUDED_GR_ENDIAN_SWAP_H */ diff --git a/gnuradio-core/src/lib/general/gr_endian_swap.i b/gnuradio-core/src/lib/general/gr_endian_swap.i new file mode 100644 index 0000000000..6058b9de77 --- /dev/null +++ b/gnuradio-core/src/lib/general/gr_endian_swap.i @@ -0,0 +1,31 @@ +/* -*- 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. + */ + +GR_SWIG_BLOCK_MAGIC(gr,endian_swap) + +gr_endian_swap_sptr +gr_make_endian_swap (size_t bytes_per_item=1); + +class gr_endian_swap : public gr_sync_block +{ +public: +}; diff --git a/gnuradio-core/src/python/gnuradio/gr/qa_endian_swap.py b/gnuradio-core/src/python/gnuradio/gr/qa_endian_swap.py new file mode 100644 index 0000000000..4d2555cc4d --- /dev/null +++ b/gnuradio-core/src/python/gnuradio/gr/qa_endian_swap.py @@ -0,0 +1,66 @@ +#!/usr/bin/env python +# +# Copyright 2011,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. +# + +from gnuradio import gr, gr_unittest +import ctypes + +class test_endian_swap (gr_unittest.TestCase): + + def setUp (self): + self.tb = gr.top_block () + + def tearDown (self): + self.tb = None + + def test_001(self): + + src_data = [1,2,3,4] + expected_result = [256, 512, 768, 1024]; + + src = gr.vector_source_s(src_data) + op = gr.endian_swap(2) + dst = gr.vector_sink_s() + + self.tb.connect(src, op, dst) + self.tb.run() + result_data = list(dst.data()) + + self.assertEqual(expected_result, result_data) + + def test_002(self): + + src_data = [1,2,3,4] + expected_result = [16777216, 33554432, 50331648, 67108864]; + + src = gr.vector_source_i(src_data) + op = gr.endian_swap(4) + dst = gr.vector_sink_i() + + self.tb.connect(src, op, dst) + self.tb.run() + result_data = list(dst.data()) + + self.assertEqual(expected_result, result_data) + +if __name__ == '__main__': + gr_unittest.run(test_endian_swap, "test_endian_swap.xml") + diff --git a/grc/blocks/block_tree.xml b/grc/blocks/block_tree.xml index 3b5491a745..d7ec82e4ab 100644 --- a/grc/blocks/block_tree.xml +++ b/grc/blocks/block_tree.xml @@ -64,6 +64,8 @@ <block>gr_fft_vxx</block> <block>blks2_logpwrfft_x</block> <block>gr_vector_insert_x</block> + + <block>gr_endian_swap</block> </cat> <cat> <name>Type Conversions</name> diff --git a/grc/blocks/gr_endian_swap.xml b/grc/blocks/gr_endian_swap.xml new file mode 100644 index 0000000000..aa564026cd --- /dev/null +++ b/grc/blocks/gr_endian_swap.xml @@ -0,0 +1,41 @@ +<?xml version="1.0"?> +<!-- +################################################### +##Add Block: +## all types, 1 output, 2 to inf inputs +################################################### + --> +<block> + <name>Endian Swap</name> + <key>gr_endian_swap</key> + <import>from gnuradio import gr</import> + <make>gr.endian_swap($type.size)</make> + <param> + <name>IO Type</name> + <key>type</key> + <type>enum</type> + <option> + <name>Complex</name> + <key>complex</key> + <opt>size:8</opt> + </option> + <option> + <name>Int</name> + <key>s32</key> + <opt>size:4</opt> + </option> + <option> + <name>Short</name> + <key>s16</key> + <opt>size:2</opt> + </option> + </param> + <sink> + <name>in</name> + <type>$type</type> + </sink> + <source> + <name>out</name> + <type>$type</type> + </source> +</block> diff --git a/volk/include/volk/volk_32u_byteswap_u.h b/volk/include/volk/volk_32u_byteswap_u.h new file mode 100644 index 0000000000..e27d1f03dd --- /dev/null +++ b/volk/include/volk/volk_32u_byteswap_u.h @@ -0,0 +1,77 @@ +#ifndef INCLUDED_volk_32u_byteswap_u_H +#define INCLUDED_volk_32u_byteswap_u_H + +#include <inttypes.h> +#include <stdio.h> + +#ifdef LV_HAVE_SSE2 +#include <emmintrin.h> + +/*! + \brief Byteswaps (in-place) an aligned vector of int32_t's. + \param intsToSwap The vector of data to byte swap + \param numDataPoints The number of data points +*/ +static inline void volk_32u_byteswap_u_sse2(uint32_t* intsToSwap, unsigned int num_points){ + unsigned int number = 0; + + uint32_t* inputPtr = intsToSwap; + __m128i input, byte1, byte2, byte3, byte4, output; + __m128i byte2mask = _mm_set1_epi32(0x00FF0000); + __m128i byte3mask = _mm_set1_epi32(0x0000FF00); + + const uint64_t quarterPoints = num_points / 4; + for(;number < quarterPoints; number++){ + // Load the 32t values, increment inputPtr later since we're doing it in-place. + input = _mm_loadu_si128((__m128i*)inputPtr); + // Do the four shifts + byte1 = _mm_slli_epi32(input, 24); + byte2 = _mm_slli_epi32(input, 8); + byte3 = _mm_srli_epi32(input, 8); + byte4 = _mm_srli_epi32(input, 24); + // Or bytes together + output = _mm_or_si128(byte1, byte4); + byte2 = _mm_and_si128(byte2, byte2mask); + output = _mm_or_si128(output, byte2); + byte3 = _mm_and_si128(byte3, byte3mask); + output = _mm_or_si128(output, byte3); + // Store the results + _mm_storeu_si128((__m128i*)inputPtr, output); + inputPtr += 4; + } + + // Byteswap any remaining points: + number = quarterPoints*4; + for(; number < num_points; number++){ + uint32_t outputVal = *inputPtr; + outputVal = (((outputVal >> 24) & 0xff) | ((outputVal >> 8) & 0x0000ff00) | ((outputVal << 8) & 0x00ff0000) | ((outputVal << 24) & 0xff000000)); + *inputPtr = outputVal; + inputPtr++; + } +} +#endif /* LV_HAVE_SSE2 */ + +#ifdef LV_HAVE_GENERIC +/*! + \brief Byteswaps (in-place) an aligned vector of int32_t's. + \param intsToSwap The vector of data to byte swap + \param numDataPoints The number of data points +*/ +static inline void volk_32u_byteswap_u_generic(uint32_t* intsToSwap, unsigned int num_points){ + uint32_t* inputPtr = intsToSwap; + + unsigned int point; + for(point = 0; point < num_points; point++){ + uint32_t output = *inputPtr; + output = (((output >> 24) & 0xff) | ((output >> 8) & 0x0000ff00) | ((output << 8) & 0x00ff0000) | ((output << 24) & 0xff000000)); + + *inputPtr = output; + inputPtr++; + } +} +#endif /* LV_HAVE_GENERIC */ + + + + +#endif /* INCLUDED_volk_32u_byteswap_u_H */ diff --git a/volk/include/volk/volk_64u_byteswap_u.h b/volk/include/volk/volk_64u_byteswap_u.h new file mode 100644 index 0000000000..41a4a3130f --- /dev/null +++ b/volk/include/volk/volk_64u_byteswap_u.h @@ -0,0 +1,88 @@ +#ifndef INCLUDED_volk_64u_byteswap_u_H +#define INCLUDED_volk_64u_byteswap_u_H + +#include <inttypes.h> +#include <stdio.h> + +#ifdef LV_HAVE_SSE2 +#include <emmintrin.h> + +/*! + \brief Byteswaps (in-place) an aligned vector of int64_t's. + \param intsToSwap The vector of data to byte swap + \param numDataPoints The number of data points +*/ +static inline void volk_64u_byteswap_u_sse2(uint64_t* intsToSwap, unsigned int num_points){ + uint32_t* inputPtr = (uint32_t*)intsToSwap; + __m128i input, byte1, byte2, byte3, byte4, output; + __m128i byte2mask = _mm_set1_epi32(0x00FF0000); + __m128i byte3mask = _mm_set1_epi32(0x0000FF00); + uint64_t number = 0; + const unsigned int halfPoints = num_points / 2; + for(;number < halfPoints; number++){ + // Load the 32t values, increment inputPtr later since we're doing it in-place. + input = _mm_loadu_si128((__m128i*)inputPtr); + + // Do the four shifts + byte1 = _mm_slli_epi32(input, 24); + byte2 = _mm_slli_epi32(input, 8); + byte3 = _mm_srli_epi32(input, 8); + byte4 = _mm_srli_epi32(input, 24); + // Or bytes together + output = _mm_or_si128(byte1, byte4); + byte2 = _mm_and_si128(byte2, byte2mask); + output = _mm_or_si128(output, byte2); + byte3 = _mm_and_si128(byte3, byte3mask); + output = _mm_or_si128(output, byte3); + + // Reorder the two words + output = _mm_shuffle_epi32(output, _MM_SHUFFLE(2, 3, 0, 1)); + + // Store the results + _mm_storeu_si128((__m128i*)inputPtr, output); + inputPtr += 4; + } + + // Byteswap any remaining points: + number = halfPoints*2; + for(; number < num_points; number++){ + uint32_t output1 = *inputPtr; + uint32_t output2 = inputPtr[1]; + + output1 = (((output1 >> 24) & 0xff) | ((output1 >> 8) & 0x0000ff00) | ((output1 << 8) & 0x00ff0000) | ((output1 << 24) & 0xff000000)); + + output2 = (((output2 >> 24) & 0xff) | ((output2 >> 8) & 0x0000ff00) | ((output2 << 8) & 0x00ff0000) | ((output2 << 24) & 0xff000000)); + + *inputPtr++ = output2; + *inputPtr++ = output1; + } +} +#endif /* LV_HAVE_SSE2 */ + +#ifdef LV_HAVE_GENERIC +/*! + \brief Byteswaps (in-place) an aligned vector of int64_t's. + \param intsToSwap The vector of data to byte swap + \param numDataPoints The number of data points +*/ +static inline void volk_64u_byteswap_u_generic(uint64_t* intsToSwap, unsigned int num_points){ + uint32_t* inputPtr = (uint32_t*)intsToSwap; + unsigned int point; + for(point = 0; point < num_points; point++){ + uint32_t output1 = *inputPtr; + uint32_t output2 = inputPtr[1]; + + output1 = (((output1 >> 24) & 0xff) | ((output1 >> 8) & 0x0000ff00) | ((output1 << 8) & 0x00ff0000) | ((output1 << 24) & 0xff000000)); + + output2 = (((output2 >> 24) & 0xff) | ((output2 >> 8) & 0x0000ff00) | ((output2 << 8) & 0x00ff0000) | ((output2 << 24) & 0xff000000)); + + *inputPtr++ = output2; + *inputPtr++ = output1; + } +} +#endif /* LV_HAVE_GENERIC */ + + + + +#endif /* INCLUDED_volk_64u_byteswap_u_H */ -- cgit v1.2.3