diff options
-rw-r--r-- | docs/sphinx/source/gr/index.rst | 1 | ||||
-rw-r--r-- | docs/sphinx/source/gr/sink_blk.rst | 1 | ||||
-rw-r--r-- | gnuradio-core/src/lib/general/CMakeLists.txt | 1 | ||||
-rw-r--r-- | gnuradio-core/src/lib/general/general.i | 2 | ||||
-rw-r--r-- | gnuradio-core/src/lib/general/gr_bin_statistics_f.cc | 174 | ||||
-rw-r--r-- | gnuradio-core/src/lib/general/gr_bin_statistics_f.h | 100 | ||||
-rw-r--r-- | gnuradio-core/src/lib/general/gr_bin_statistics_f.i | 47 | ||||
-rw-r--r-- | gr-blocks/include/blocks/CMakeLists.txt | 1 | ||||
-rw-r--r-- | gr-blocks/include/blocks/bin_statistics_f.h | 76 | ||||
-rw-r--r-- | gr-blocks/lib/CMakeLists.txt | 1 | ||||
-rw-r--r-- | gr-blocks/lib/bin_statistics_f_impl.cc | 178 | ||||
-rw-r--r-- | gr-blocks/lib/bin_statistics_f_impl.h | 82 | ||||
-rwxr-xr-x | gr-blocks/python/qa_bin_statistics.py | 33 | ||||
-rw-r--r-- | gr-blocks/swig/blocks_swig.i | 3 | ||||
-rwxr-xr-x | gr-uhd/examples/python/usrp_spectrum_sense.py | 8 |
15 files changed, 359 insertions, 349 deletions
diff --git a/docs/sphinx/source/gr/index.rst b/docs/sphinx/source/gr/index.rst index 3372816eff..b1663a7e23 100644 --- a/docs/sphinx/source/gr/index.rst +++ b/docs/sphinx/source/gr/index.rst @@ -39,7 +39,6 @@ Signal Sinks .. autosummary:: :nosignatures: - gnuradio.gr.bin_statistics_f gnuradio.gr.check_counting_s gnuradio.gr.check_lfsr_32k_s gnuradio.gr.null_sink diff --git a/docs/sphinx/source/gr/sink_blk.rst b/docs/sphinx/source/gr/sink_blk.rst index 1be1130dce..56b29efff9 100644 --- a/docs/sphinx/source/gr/sink_blk.rst +++ b/docs/sphinx/source/gr/sink_blk.rst @@ -1,7 +1,6 @@ gnuradio.gr: Signal Sinks ========================= -.. autooldblock:: gnuradio.gr.bin_statistics_f .. autooldblock:: gnuradio.gr.check_counting_s .. autooldblock:: gnuradio.gr.check_lfsr_32k_s .. autooldblock:: gnuradio.gr.null_sink diff --git a/gnuradio-core/src/lib/general/CMakeLists.txt b/gnuradio-core/src/lib/general/CMakeLists.txt index bbc6a7612b..bca0583b59 100644 --- a/gnuradio-core/src/lib/general/CMakeLists.txt +++ b/gnuradio-core/src/lib/general/CMakeLists.txt @@ -140,7 +140,6 @@ endif(ENABLE_PYTHON) set(gr_core_general_triple_threats complex_vec_test gr_align_on_samplenumbers_ss - gr_bin_statistics_f gr_block_gateway gr_check_counting_s gr_check_lfsr_32k_s diff --git a/gnuradio-core/src/lib/general/general.i b/gnuradio-core/src/lib/general/general.i index f7f7942577..2712c4101c 100644 --- a/gnuradio-core/src/lib/general/general.i +++ b/gnuradio-core/src/lib/general/general.i @@ -43,7 +43,6 @@ #include <gr_test_types.h> #include <gr_test.h> #include <gr_feval.h> -#include <gr_bin_statistics_f.h> #include <gr_copy.h> #include <complex_vec_test.h> #include <gr_annotator_alltoall.h> @@ -73,7 +72,6 @@ %include "gr_test_types.h" %include "gr_test.i" %include "gr_feval.i" -%include "gr_bin_statistics_f.i" %include "gr_copy.i" %include "complex_vec_test.i" %include "gr_annotator_alltoall.i" diff --git a/gnuradio-core/src/lib/general/gr_bin_statistics_f.cc b/gnuradio-core/src/lib/general/gr_bin_statistics_f.cc deleted file mode 100644 index 3938f2b487..0000000000 --- a/gnuradio-core/src/lib/general/gr_bin_statistics_f.cc +++ /dev/null @@ -1,174 +0,0 @@ -/* -*- c++ -*- */ -/* - * 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. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include <gr_bin_statistics_f.h> -#include <gr_io_signature.h> -#include <string.h> - -gr_bin_statistics_f_sptr -gr_make_bin_statistics_f(unsigned int vlen, - gr_msg_queue_sptr msgq, - gr_feval_dd *tune, - size_t tune_delay, - size_t dwell_delay) -{ - return gnuradio::get_initial_sptr(new gr_bin_statistics_f(vlen, - msgq, - tune, - tune_delay, - dwell_delay)); -} - -gr_bin_statistics_f::gr_bin_statistics_f(unsigned int vlen, - gr_msg_queue_sptr msgq, - gr_feval_dd *tune, - size_t tune_delay, - size_t dwell_delay) - : gr_sync_block("bin_statistics_f", - gr_make_io_signature(1, 1, sizeof(float) * vlen), - gr_make_io_signature(0, 0, 0)), - d_vlen(vlen), d_msgq(msgq), d_tune(tune), - d_tune_delay(tune_delay), d_dwell_delay(dwell_delay), - d_center_freq(0), d_delay(0), - d_max(vlen) -{ - enter_init(); -} - -gr_bin_statistics_f::~gr_bin_statistics_f() -{ - // NOP -} - -void -gr_bin_statistics_f::enter_init() -{ - d_state = ST_INIT; - d_delay = 0; -} - -void -gr_bin_statistics_f::enter_tune_delay() -{ - d_state = ST_TUNE_DELAY; - d_delay = d_tune_delay; - d_center_freq = d_tune->calleval(0); -} - -void -gr_bin_statistics_f::enter_dwell_delay() -{ - d_state = ST_DWELL_DELAY; - d_delay = d_dwell_delay; - reset_stats(); -} - -void -gr_bin_statistics_f::leave_dwell_delay() -{ - send_stats(); -} - -int -gr_bin_statistics_f::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) -{ - const float *input = (const float *) input_items[0]; - size_t vlen = d_max.size(); - - int n = 0; - int t; - - while (n < noutput_items){ - switch (d_state){ - - case ST_INIT: - enter_tune_delay(); - break; - - case ST_TUNE_DELAY: - t = std::min(noutput_items - n, int(d_delay)); - n += t; - d_delay -= t; - assert(d_delay >= 0); - if (d_delay == 0) - enter_dwell_delay(); - break; - - case ST_DWELL_DELAY: - t = std::min(noutput_items - n, int(d_delay)); - for (int i = 0; i < t; i++){ - accrue_stats(&input[n * vlen]); - n++; - } - d_delay -= t; - assert(d_delay >= 0); - if (d_delay == 0){ - leave_dwell_delay(); - enter_tune_delay(); - } - break; - - default: - assert(0); - } - } - - return noutput_items; -} - -////////////////////////////////////////////////////////////////////////// -// virtual methods for gathering stats -////////////////////////////////////////////////////////////////////////// - -void -gr_bin_statistics_f::reset_stats() -{ - for (size_t i = 0; i < vlen(); i++){ - d_max[i] = 0; - } -} - -void -gr_bin_statistics_f::accrue_stats(const float *input) -{ - for (size_t i = 0; i < vlen(); i++){ - d_max[i] = std::max(d_max[i], input[i]); // compute per bin maxima - } -} - -void -gr_bin_statistics_f::send_stats() -{ - if (msgq()->full_p()) // if the queue is full, don't block, drop the data... - return; - - // build & send a message - gr_message_sptr msg = gr_make_message(0, center_freq(), vlen(), vlen() * sizeof(float)); - memcpy(msg->msg(), &d_max[0], vlen() * sizeof(float)); - msgq()->insert_tail(msg); -} diff --git a/gnuradio-core/src/lib/general/gr_bin_statistics_f.h b/gnuradio-core/src/lib/general/gr_bin_statistics_f.h deleted file mode 100644 index dd10759096..0000000000 --- a/gnuradio-core/src/lib/general/gr_bin_statistics_f.h +++ /dev/null @@ -1,100 +0,0 @@ -/* -*- 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_BIN_STATISTICS_F_H -#define INCLUDED_GR_BIN_STATISTICS_F_H - - -#include <gr_core_api.h> -#include <gr_sync_block.h> -#include <gr_feval.h> -#include <gr_message.h> -#include <gr_msg_queue.h> - -class gr_bin_statistics_f; -typedef boost::shared_ptr<gr_bin_statistics_f> gr_bin_statistics_f_sptr; - - -GR_CORE_API gr_bin_statistics_f_sptr -gr_make_bin_statistics_f(unsigned int vlen, // vector length - gr_msg_queue_sptr msgq, - gr_feval_dd *tune, // callback - size_t tune_delay, // samples - size_t dwell_delay); // samples - -/*! - * \brief control scanning and record frequency domain statistics - * \ingroup sink_blk - */ -class GR_CORE_API gr_bin_statistics_f : public gr_sync_block -{ - friend GR_CORE_API gr_bin_statistics_f_sptr - gr_make_bin_statistics_f(unsigned int vlen, // vector length - gr_msg_queue_sptr msgq, - gr_feval_dd *tune, // callback - size_t tune_delay, // samples - size_t dwell_delay); // samples - - enum state_t { ST_INIT, ST_TUNE_DELAY, ST_DWELL_DELAY }; - - size_t d_vlen; - gr_msg_queue_sptr d_msgq; - gr_feval_dd *d_tune; - size_t d_tune_delay; - size_t d_dwell_delay; - double d_center_freq; - - state_t d_state; - size_t d_delay; // nsamples remaining to state transition - - gr_bin_statistics_f(unsigned int vlen, - gr_msg_queue_sptr msgq, - gr_feval_dd *tune, - size_t tune_delay, - size_t dwell_delay); - - void enter_init(); - void enter_tune_delay(); - void enter_dwell_delay(); - void leave_dwell_delay(); - -protected: - std::vector<float> d_max; // per bin maxima - - size_t vlen() const { return d_vlen; } - double center_freq() const { return d_center_freq; } - gr_msg_queue_sptr msgq() const { return d_msgq; } - - virtual void reset_stats(); - virtual void accrue_stats(const float *input); - virtual void send_stats(); - -public: - ~gr_bin_statistics_f(); - - 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_bin_statistics_f.i b/gnuradio-core/src/lib/general/gr_bin_statistics_f.i deleted file mode 100644 index 94a3db69a2..0000000000 --- a/gnuradio-core/src/lib/general/gr_bin_statistics_f.i +++ /dev/null @@ -1,47 +0,0 @@ -/* -*- c++ -*- */ -/* - * 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 this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -// Directors are only supported in Python, Java and C#. gr_feval_dd uses directors -#ifdef SWIGPYTHON - -GR_SWIG_BLOCK_MAGIC(gr,bin_statistics_f); - -gr_bin_statistics_f_sptr -gr_make_bin_statistics_f(unsigned int vlen, // vector length - gr_msg_queue_sptr msgq, - gr_feval_dd *tune, // callback - size_t tune_delay, // samples - size_t dwell_delay); // samples - - -class gr_bin_statistics_f : public gr_sync_block -{ -private: - gr_bin_statistics_f(unsigned int vlen, - gr_msg_queue_sptr msgq, - gr_feval_dd *tune, - size_t tune_delay, - size_t dwell_delay); -public: - ~gr_bin_statistics_f(); -}; - -#endif diff --git a/gr-blocks/include/blocks/CMakeLists.txt b/gr-blocks/include/blocks/CMakeLists.txt index f93c4eceb9..24451903d0 100644 --- a/gr-blocks/include/blocks/CMakeLists.txt +++ b/gr-blocks/include/blocks/CMakeLists.txt @@ -102,6 +102,7 @@ install(FILES count_bits.h log2_const.h add_ff.h + bin_statistics_f.h burst_tagger.h char_to_float.h char_to_short.h diff --git a/gr-blocks/include/blocks/bin_statistics_f.h b/gr-blocks/include/blocks/bin_statistics_f.h new file mode 100644 index 0000000000..a73afc82d6 --- /dev/null +++ b/gr-blocks/include/blocks/bin_statistics_f.h @@ -0,0 +1,76 @@ +/* -*- c++ -*- */ +/* + * Copyright 2006,2013 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_BIN_STATISTICS_F_H +#define INCLUDED_GR_BIN_STATISTICS_F_H + +#include <blocks/api.h> +#include <gr_sync_block.h> +#include <gr_msg_queue.h> +#include <gr_feval.h> + +namespace gr { + namespace blocks { + + /*! + * \brief control scanning and record frequency domain statistics + * \ingroup sink_blk + */ + class BLOCKS_API bin_statistics_f : virtual public gr_sync_block + { + protected: + std::vector<float> d_max; // per bin maxima + + virtual size_t vlen() const = 0; + virtual double center_freq() const = 0; + virtual gr_msg_queue_sptr msgq() const = 0; + + virtual void reset_stats() = 0; + virtual void accrue_stats(const float *input) = 0; + virtual void send_stats() = 0; + + public: + // gr::blocks::bin_statistics_f::sptr + typedef boost::shared_ptr<bin_statistics_f> sptr; + + /*! + * Build a bin statistics block. See qa_bin_statistics.py and + * gr-uhd/examples/python/usrp_spectrum_sense.py for examples of + * its use, specifically how to use the callback function. + * + * \param vlen vector length + * \param msgq message queue + * \param tune a gr_feval_dd callback function + * \param tune_delay number of samples for the tune delay + * \param dwell_delay number of samples for the dwell delay + */ + static sptr make(unsigned int vlen, // vector length + gr_msg_queue_sptr msgq, + gr_feval_dd *tune, // callback + size_t tune_delay, // samples + size_t dwell_delay); // samples + }; + + } /* namespace blocks */ +} /* namespace gr */ + +#endif /* INCLUDED_GR_BIN_STATISTICS_F_H */ diff --git a/gr-blocks/lib/CMakeLists.txt b/gr-blocks/lib/CMakeLists.txt index aa798bbe7d..60603ca31e 100644 --- a/gr-blocks/lib/CMakeLists.txt +++ b/gr-blocks/lib/CMakeLists.txt @@ -143,6 +143,7 @@ list(APPEND gr_blocks_sources ${generated_sources} count_bits.cc add_ff_impl.cc + bin_statistics_f_impl.cc burst_tagger_impl.cc char_to_float_impl.cc char_to_short_impl.cc diff --git a/gr-blocks/lib/bin_statistics_f_impl.cc b/gr-blocks/lib/bin_statistics_f_impl.cc new file mode 100644 index 0000000000..014222a63d --- /dev/null +++ b/gr-blocks/lib/bin_statistics_f_impl.cc @@ -0,0 +1,178 @@ +/* -*- c++ -*- */ +/* + * Copyright 2006,2010,2013 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 "bin_statistics_f_impl.h" +#include <gr_io_signature.h> +#include <string.h> + +namespace gr { + namespace blocks { + + bin_statistics_f::sptr + bin_statistics_f::make(unsigned int vlen, + gr_msg_queue_sptr msgq, + gr_feval_dd *tune, + size_t tune_delay, + size_t dwell_delay) + { + return gnuradio::get_initial_sptr + (new bin_statistics_f_impl(vlen, msgq, tune, + tune_delay, dwell_delay)); + } + + bin_statistics_f_impl::bin_statistics_f_impl(unsigned int vlen, + gr_msg_queue_sptr msgq, + gr_feval_dd *tune, + size_t tune_delay, + size_t dwell_delay) + : gr_sync_block("bin_statistics_f", + gr_make_io_signature(1, 1, sizeof(float) * vlen), + gr_make_io_signature(0, 0, 0)), + d_vlen(vlen), d_msgq(msgq), d_tune(tune), + d_tune_delay(tune_delay), d_dwell_delay(dwell_delay), + d_center_freq(0), d_delay(0), + d_max(vlen) + { + enter_init(); + } + + bin_statistics_f_impl::~bin_statistics_f_impl() + { + } + + void + bin_statistics_f_impl::enter_init() + { + d_state = ST_INIT; + d_delay = 0; + } + + void + bin_statistics_f_impl::enter_tune_delay() + { + d_state = ST_TUNE_DELAY; + d_delay = d_tune_delay; + d_center_freq = d_tune->calleval(0); + } + + void + bin_statistics_f_impl::enter_dwell_delay() + { + d_state = ST_DWELL_DELAY; + d_delay = d_dwell_delay; + reset_stats(); + } + + void + bin_statistics_f_impl::leave_dwell_delay() + { + send_stats(); + } + + int + bin_statistics_f_impl::work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) + { + const float *input = (const float*)input_items[0]; + size_t vlen = d_max.size(); + + int n = 0; + int t; + + while(n < noutput_items) { + switch(d_state) { + + case ST_INIT: + enter_tune_delay(); + break; + + case ST_TUNE_DELAY: + t = std::min(noutput_items - n, int(d_delay)); + n += t; + d_delay -= t; + assert(d_delay >= 0); + if(d_delay == 0) + enter_dwell_delay(); + break; + + case ST_DWELL_DELAY: + t = std::min(noutput_items - n, int(d_delay)); + for(int i = 0; i < t; i++) { + accrue_stats(&input[n * vlen]); + n++; + } + d_delay -= t; + assert(d_delay >= 0); + if(d_delay == 0) { + leave_dwell_delay(); + enter_tune_delay(); + } + break; + + default: + assert(0); + } + } + + return noutput_items; + } + + ////////////////////////////////////////////////////////////////////////// + // virtual methods for gathering stats + ////////////////////////////////////////////////////////////////////////// + + void + bin_statistics_f_impl::reset_stats() + { + for (size_t i = 0; i < vlen(); i++){ + d_max[i] = 0; + } + } + + void + bin_statistics_f_impl::accrue_stats(const float *input) + { + for(size_t i = 0; i < vlen(); i++) { + d_max[i] = std::max(d_max[i], input[i]); // compute per bin maxima + } + } + + void + bin_statistics_f_impl::send_stats() + { + if(msgq()->full_p()) // if the queue is full, don't block, drop the data... + return; + + // build & send a message + gr_message_sptr msg = gr_make_message(0, center_freq(), vlen(), vlen() * sizeof(float)); + memcpy(msg->msg(), &d_max[0], vlen() * sizeof(float)); + msgq()->insert_tail(msg); + } + + } /* namespace blocks */ +} /* namespace gr */ + diff --git a/gr-blocks/lib/bin_statistics_f_impl.h b/gr-blocks/lib/bin_statistics_f_impl.h new file mode 100644 index 0000000000..0abb60ed38 --- /dev/null +++ b/gr-blocks/lib/bin_statistics_f_impl.h @@ -0,0 +1,82 @@ +/* -*- c++ -*- */ +/* + * Copyright 2006,2013 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_BIN_STATISTICS_F_IMPL_H +#define INCLUDED_GR_BIN_STATISTICS_F_IMPL_H + +#include <blocks/bin_statistics_f.h> +#include <gr_feval.h> +#include <gr_message.h> +#include <gr_msg_queue.h> + +namespace gr { + namespace blocks { + + class bin_statistics_f_impl : public bin_statistics_f + { + private: + enum state_t { ST_INIT, ST_TUNE_DELAY, ST_DWELL_DELAY }; + + size_t d_vlen; + gr_msg_queue_sptr d_msgq; + gr_feval_dd *d_tune; + size_t d_tune_delay; + size_t d_dwell_delay; + double d_center_freq; + + state_t d_state; + size_t d_delay; // nsamples remaining to state transition + + void enter_init(); + void enter_tune_delay(); + void enter_dwell_delay(); + void leave_dwell_delay(); + + protected: + std::vector<float> d_max; // per bin maxima + + size_t vlen() const { return d_vlen; } + double center_freq() const { return d_center_freq; } + gr_msg_queue_sptr msgq() const { return d_msgq; } + + virtual void reset_stats(); + virtual void accrue_stats(const float *input); + virtual void send_stats(); + + public: + bin_statistics_f_impl(unsigned int vlen, + gr_msg_queue_sptr msgq, + gr_feval_dd *tune, + size_t tune_delay, + size_t dwell_delay); + ~bin_statistics_f_impl(); + + int work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + + }; + + } /* namespace blocks */ +} /* namespace gr */ + +#endif /* INCLUDED_GR_BIN_STATISTICS_F_IMPL_H */ diff --git a/gr-blocks/python/qa_bin_statistics.py b/gr-blocks/python/qa_bin_statistics.py index 00fd58b600..666f7c0d68 100755 --- a/gr-blocks/python/qa_bin_statistics.py +++ b/gr-blocks/python/qa_bin_statistics.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -# Copyright 2006,2007,2010 Free Software Foundation, Inc. +# Copyright 2006,2007,2010,2013 Free Software Foundation, Inc. # # This file is part of GNU Radio # @@ -25,13 +25,10 @@ import blocks_swig as blocks import random import struct -#import os -#print "pid =", os.getpid() -#raw_input("Attach gdb and press return...") - """ -Note: The QA tests below have been disabled by renaming them from test_* -to xtest_*. See ticket:199 on http://gnuradio.org/trac/ticket/199 +Note: There has been an issue with this block in the past, see Issue +#199. This test is being enabled only on the 'next' branch for version +v3.7 for now. TWR """ class counter(gr.feval_dd): @@ -94,8 +91,7 @@ class parse_msg(object): assert(msg.length() == self.vlen * gr.sizeof_float) self.data = struct.unpack('%df' % (self.vlen,), msg.to_string()) -# FIXME: see ticket:199 -class xtest_bin_statistics(gr_unittest.TestCase): +class test_bin_statistics(gr_unittest.TestCase): def setUp(self): self.tb = gr.top_block () @@ -103,7 +99,7 @@ class xtest_bin_statistics(gr_unittest.TestCase): def tearDown(self): self.tb = None - def xtest_001(self): + def test_001(self): vlen = 4 tune = counter(1) tune_delay = 0 @@ -126,7 +122,7 @@ class xtest_bin_statistics(gr_unittest.TestCase): src = gr.vector_source_f(src_data, False) s2v = blocks.stream_to_vector(gr.sizeof_float, vlen) - stats = gr.bin_statistics_f(vlen, msgq, tune, tune_delay, dwell_delay) + stats = blocks.bin_statistics_f(vlen, msgq, tune, tune_delay, dwell_delay) self.tb.connect(src, s2v, stats) self.tb.run() self.assertEqual(4, msgq.count()) @@ -135,7 +131,7 @@ class xtest_bin_statistics(gr_unittest.TestCase): #print "m =", m.center_freq, m.data self.assertEqual(expected_results[vlen*i:vlen*i + vlen], m.data) - def xtest_002(self): + def test_002(self): vlen = 4 tune = counter(1) tune_delay = 1 @@ -154,7 +150,7 @@ class xtest_bin_statistics(gr_unittest.TestCase): src = gr.vector_source_f(src_data, False) s2v = blocks.stream_to_vector(gr.sizeof_float, vlen) - stats = gr.bin_statistics_f(vlen, msgq, tune, tune_delay, dwell_delay) + stats = blocks.bin_statistics_f(vlen, msgq, tune, tune_delay, dwell_delay) self.tb.connect(src, s2v, stats) self.tb.run() self.assertEqual(1, msgq.count()) @@ -165,7 +161,7 @@ class xtest_bin_statistics(gr_unittest.TestCase): - def xtest_003(self): + def test_003(self): vlen = 4 tune = counter3(foobar3, 1) tune_delay = 1 @@ -184,7 +180,7 @@ class xtest_bin_statistics(gr_unittest.TestCase): src = gr.vector_source_f(src_data, False) s2v = blocks.stream_to_vector(gr.sizeof_float, vlen) - stats = gr.bin_statistics_f(vlen, msgq, tune, tune_delay, dwell_delay) + stats = blocks.bin_statistics_f(vlen, msgq, tune, tune_delay, dwell_delay) self.tb.connect(src, s2v, stats) self.tb.run() self.assertEqual(1, msgq.count()) @@ -193,12 +189,11 @@ class xtest_bin_statistics(gr_unittest.TestCase): #print "m =", m.center_freq, m.data self.assertEqual(expected_results[vlen*i:vlen*i + vlen], m.data) - def foobar4(self, new_t): #print "foobar4: new_t =", new_t pass - def xtest_004(self): + def test_004(self): vlen = 4 tune = counter4(self, 1) tune_delay = 1 @@ -217,7 +212,7 @@ class xtest_bin_statistics(gr_unittest.TestCase): src = gr.vector_source_f(src_data, False) s2v = blocks.stream_to_vector(gr.sizeof_float, vlen) - stats = gr.bin_statistics_f(vlen, msgq, tune, tune_delay, dwell_delay) + stats = blocks.bin_statistics_f(vlen, msgq, tune, tune_delay, dwell_delay) self.tb.connect(src, s2v, stats) self.tb.run() self.assertEqual(1, msgq.count()) @@ -228,4 +223,4 @@ class xtest_bin_statistics(gr_unittest.TestCase): if __name__ == '__main__': - gr_unittest.run(xtest_bin_statistics, "test_bin_statistics.xml") + gr_unittest.run(test_bin_statistics, "test_bin_statistics.xml") diff --git a/gr-blocks/swig/blocks_swig.i b/gr-blocks/swig/blocks_swig.i index 94cebd1a46..52fd2b6422 100644 --- a/gr-blocks/swig/blocks_swig.i +++ b/gr-blocks/swig/blocks_swig.i @@ -52,6 +52,7 @@ #include "blocks/argmax_fs.h" #include "blocks/argmax_is.h" #include "blocks/argmax_ss.h" +#include "blocks/bin_statistics_f.h" #include "blocks/burst_tagger.h" #include "blocks/char_to_float.h" #include "blocks/char_to_short.h" @@ -204,6 +205,7 @@ %include "blocks/argmax_is.h" %include "blocks/argmax_ss.h" %include "blocks/char_to_float.h" +%include "blocks/bin_statistics_f.h" %include "blocks/burst_tagger.h" %include "blocks/char_to_short.h" %include "blocks/complex_to_interleaved_short.h" @@ -353,6 +355,7 @@ GR_SWIG_BLOCK_MAGIC2(blocks, and_const_ii); GR_SWIG_BLOCK_MAGIC2(blocks, argmax_fs); GR_SWIG_BLOCK_MAGIC2(blocks, argmax_is); GR_SWIG_BLOCK_MAGIC2(blocks, argmax_ss); +GR_SWIG_BLOCK_MAGIC2(blocks, bin_statistics_f); GR_SWIG_BLOCK_MAGIC2(blocks, burst_tagger); GR_SWIG_BLOCK_MAGIC2(blocks, char_to_float); GR_SWIG_BLOCK_MAGIC2(blocks, char_to_short); diff --git a/gr-uhd/examples/python/usrp_spectrum_sense.py b/gr-uhd/examples/python/usrp_spectrum_sense.py index 077365a916..39e85ab18a 100755 --- a/gr-uhd/examples/python/usrp_spectrum_sense.py +++ b/gr-uhd/examples/python/usrp_spectrum_sense.py @@ -49,7 +49,7 @@ class tune(gr.feval_dd): def eval(self, ignore): """ - This method is called from gr.bin_statistics_f when it wants + This method is called from blocks.bin_statistics_f when it wants to change the center frequency. This method tunes the front end to the new center frequency, and returns the new frequency as its result. @@ -183,9 +183,9 @@ class my_top_block(gr.top_block): self.msgq = gr.msg_queue(16) self._tune_callback = tune(self) # hang on to this to keep it from being GC'd - stats = gr.bin_statistics_f(self.fft_size, self.msgq, - self._tune_callback, tune_delay, - dwell_delay) + stats = blocks.bin_statistics_f(self.fft_size, self.msgq, + self._tune_callback, tune_delay, + dwell_delay) # FIXME leave out the log10 until we speed it up #self.connect(self.u, s2v, ffter, c2mag, log, stats) |