diff options
Diffstat (limited to 'gr-blocks')
-rw-r--r-- | gr-blocks/include/gnuradio/blocks/CMakeLists.txt | 1 | ||||
-rw-r--r-- | gr-blocks/include/gnuradio/blocks/bin_statistics_f.h | 64 | ||||
-rw-r--r-- | gr-blocks/lib/CMakeLists.txt | 1 | ||||
-rw-r--r-- | gr-blocks/lib/bin_statistics_f_impl.cc | 152 | ||||
-rw-r--r-- | gr-blocks/lib/bin_statistics_f_impl.h | 69 | ||||
-rw-r--r-- | gr-blocks/python/blocks/qa_bin_statistics.py | 217 |
6 files changed, 0 insertions, 504 deletions
diff --git a/gr-blocks/include/gnuradio/blocks/CMakeLists.txt b/gr-blocks/include/gnuradio/blocks/CMakeLists.txt index 022fc1c61f..4721618ed7 100644 --- a/gr-blocks/include/gnuradio/blocks/CMakeLists.txt +++ b/gr-blocks/include/gnuradio/blocks/CMakeLists.txt @@ -62,7 +62,6 @@ install(FILES annotator_1to1.h annotator_alltoall.h annotator_raw.h - bin_statistics_f.h burst_tagger.h char_to_float.h char_to_short.h diff --git a/gr-blocks/include/gnuradio/blocks/bin_statistics_f.h b/gr-blocks/include/gnuradio/blocks/bin_statistics_f.h deleted file mode 100644 index 5eb95a2cfd..0000000000 --- a/gr-blocks/include/gnuradio/blocks/bin_statistics_f.h +++ /dev/null @@ -1,64 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2006,2013 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * SPDX-License-Identifier: GPL-3.0-or-later - * - */ - -#ifndef INCLUDED_GR_BIN_STATISTICS_F_H -#define INCLUDED_GR_BIN_STATISTICS_F_H - -#include <gnuradio/blocks/api.h> -#include <gnuradio/feval.h> -#include <gnuradio/msg_queue.h> -#include <gnuradio/sync_block.h> - -namespace gr { -namespace blocks { - -/*! - * \brief control scanning and record frequency domain statistics - * \ingroup misc_blk - */ -class BLOCKS_API bin_statistics_f : virtual public 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 std::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 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, - 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 45cf72b579..7a268f1522 100644 --- a/gr-blocks/lib/CMakeLists.txt +++ b/gr-blocks/lib/CMakeLists.txt @@ -62,7 +62,6 @@ add_library(gnuradio-blocks annotator_1to1_impl.cc annotator_alltoall_impl.cc annotator_raw_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 deleted file mode 100644 index dca2f868a5..0000000000 --- a/gr-blocks/lib/bin_statistics_f_impl.cc +++ /dev/null @@ -1,152 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2006,2010,2013 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * SPDX-License-Identifier: GPL-3.0-or-later - * - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "bin_statistics_f_impl.h" -#include <gnuradio/io_signature.h> -#include <string.h> - -namespace gr { -namespace blocks { - -bin_statistics_f::sptr bin_statistics_f::make(unsigned int vlen, - msg_queue::sptr msgq, - 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, - msg_queue::sptr msgq, - feval_dd* tune, - size_t tune_delay, - size_t dwell_delay) - : sync_block("bin_statistics_f", - io_signature::make(1, 1, sizeof(float) * vlen), - io_signature::make(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; - 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; - 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 - message::sptr msg = message::make(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 deleted file mode 100644 index 42a838f3cd..0000000000 --- a/gr-blocks/lib/bin_statistics_f_impl.h +++ /dev/null @@ -1,69 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2006,2013 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * SPDX-License-Identifier: GPL-3.0-or-later - * - */ - -#ifndef INCLUDED_GR_BIN_STATISTICS_F_IMPL_H -#define INCLUDED_GR_BIN_STATISTICS_F_IMPL_H - -#include <gnuradio/blocks/bin_statistics_f.h> -#include <gnuradio/feval.h> -#include <gnuradio/message.h> -#include <gnuradio/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 }; - - const size_t d_vlen; - msg_queue::sptr d_msgq; - feval_dd* d_tune; - const size_t d_tune_delay; - const 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; } - 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, - msg_queue::sptr msgq, - 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/blocks/qa_bin_statistics.py b/gr-blocks/python/blocks/qa_bin_statistics.py deleted file mode 100644 index c91e3fff99..0000000000 --- a/gr-blocks/python/blocks/qa_bin_statistics.py +++ /dev/null @@ -1,217 +0,0 @@ -#!/usr/bin/env python -# -# Copyright 2006,2007,2010,2013 Free Software Foundation, Inc. -# -# This file is part of GNU Radio -# -# SPDX-License-Identifier: GPL-3.0-or-later -# -# - -""" -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 -""" - -from __future__ import print_function - -import struct - -from gnuradio import gr, gr_unittest, blocks - - -class counter(gr.feval_dd): - def __init__(self, step_size=1): - gr.feval_dd.__init__(self) - self.step_size = step_size - self.count = 0 - - def eval(self, input): - #print "eval: self.count =", self.count - t = self.count - self.count = self.count + self.step_size - return t - - -class counter3(gr.feval_dd): - def __init__(self, f, step_size): - gr.feval_dd.__init__(self) - self.f = f - self.step_size = step_size - self.count = 0 - - def eval(self, input): - try: - #print "eval: self.count =", self.count - t = self.count - self.count = self.count + self.step_size - self.f(self.count) - except Exception as e: - print("Exception: ", e) - return t - -def foobar3(new_t): - #print "foobar3: new_t =", new_t - pass - - -class counter4(gr.feval_dd): - def __init__(self, obj_instance, step_size): - gr.feval_dd.__init__(self) - self.obj_instance = obj_instance - self.step_size = step_size - self.count = 0 - - def eval(self, input): - try: - #print "eval: self.count =", self.count - t = self.count - self.count = self.count + self.step_size - self.obj_instance.foobar4(self.count) - except Exception as e: - print("Exception: ", e) - return t - - -class parse_msg(object): - def __init__(self, msg): - self.center_freq = msg.arg1() - self.vlen = int(msg.arg2()) - assert(msg.length() == self.vlen * gr.sizeof_float) - self.data = struct.unpack(b'%df' % self.vlen, msg.to_string()) - - -class test_bin_statistics(gr_unittest.TestCase): - - def setUp(self): - self.tb = gr.top_block () - - def tearDown(self): - self.tb = None - - def test_001(self): - vlen = 4 - tune = counter(1) - tune_delay = 0 - dwell_delay = 1 - msgq = gr.msg_queue() - - src_data = tuple([float(x) for x in - ( 1, 2, 3, 4, - 5, 6, 7, 8, - 9, 10, 11, 12, - 13, 14, 15, 16 - )]) - - expected_results = tuple([float(x) for x in - ( 1, 2, 3, 4, - 5, 6, 7, 8, - 9, 10, 11, 12, - 13, 14, 15, 16 - )]) - - src = blocks.vector_source_f(src_data, False) - s2v = blocks.stream_to_vector(gr.sizeof_float, vlen) - 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()) - for i in range(4): - m = parse_msg(msgq.delete_head()) - #print "m =", m.center_freq, m.data - self.assertEqual(expected_results[vlen*i:vlen*i + vlen], m.data) - - def test_002(self): - vlen = 4 - tune = counter(1) - tune_delay = 1 - dwell_delay = 2 - msgq = gr.msg_queue() - - src_data = tuple([float(x) for x in - ( 1, 2, 3, 4, - 9, 6, 11, 8, - 5, 10, 7, 12, - 13, 14, 15, 16 - )]) - - expected_results = tuple([float(x) for x in - ( 9, 10, 11, 12)]) - - src = blocks.vector_source_f(src_data, False) - s2v = blocks.stream_to_vector(gr.sizeof_float, vlen) - 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()) - for i in range(1): - m = parse_msg(msgq.delete_head()) - #print "m =", m.center_freq, m.data - self.assertEqual(expected_results[vlen*i:vlen*i + vlen], m.data) - - - - def test_003(self): - vlen = 4 - tune = counter3(foobar3, 1) - tune_delay = 1 - dwell_delay = 2 - msgq = gr.msg_queue() - - src_data = tuple([float(x) for x in - ( 1, 2, 3, 4, - 9, 6, 11, 8, - 5, 10, 7, 12, - 13, 14, 15, 16 - )]) - - expected_results = tuple([float(x) for x in - ( 9, 10, 11, 12)]) - - src = blocks.vector_source_f(src_data, False) - s2v = blocks.stream_to_vector(gr.sizeof_float, vlen) - 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()) - for i in range(1): - m = parse_msg(msgq.delete_head()) - #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 test_004(self): - vlen = 4 - tune = counter4(self, 1) - tune_delay = 1 - dwell_delay = 2 - msgq = gr.msg_queue() - - src_data = tuple([float(x) for x in - ( 1, 2, 3, 4, - 9, 6, 11, 8, - 5, 10, 7, 12, - 13, 14, 15, 16 - )]) - - expected_results = tuple([float(x) for x in - ( 9, 10, 11, 12)]) - - src = blocks.vector_source_f(src_data, False) - s2v = blocks.stream_to_vector(gr.sizeof_float, vlen) - 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()) - for i in range(1): - m = parse_msg(msgq.delete_head()) - #print "m =", m.center_freq, m.data - self.assertEqual(expected_results[vlen*i:vlen*i + vlen], m.data) - - -if __name__ == '__main__': - gr_unittest.run(test_bin_statistics, "test_bin_statistics.xml") |