diff options
author | Tim O'Shea <tim.oshea753@gmail.com> | 2013-03-01 09:14:44 -0500 |
---|---|---|
committer | Tom Rondeau <trondeau@vt.edu> | 2013-03-13 15:20:39 -0400 |
commit | 3cf9ea682c7286ef25df1346bc9c9528a74c3469 (patch) | |
tree | 11d5cf563d258fe3345d3de0f64363286cacb056 | |
parent | e247d2c1f5e6023b4094465f740d1c48332ae672 (diff) |
blocks: adding probe_rate block
Conflicts:
gr-blocks/include/blocks/CMakeLists.txt
gr-blocks/lib/CMakeLists.txt
gr-blocks/swig/blocks_swig.i
-rw-r--r-- | gr-blocks/grc/blocks_block_tree.xml | 1 | ||||
-rw-r--r-- | gr-blocks/grc/blocks_probe_rate.xml | 66 | ||||
-rw-r--r-- | gr-blocks/include/blocks/CMakeLists.txt | 4 | ||||
-rw-r--r-- | gr-blocks/include/blocks/probe_rate.h | 60 | ||||
-rw-r--r-- | gr-blocks/lib/CMakeLists.txt | 1 | ||||
-rw-r--r-- | gr-blocks/lib/probe_rate_impl.cc | 119 | ||||
-rw-r--r-- | gr-blocks/lib/probe_rate_impl.h | 63 | ||||
-rw-r--r-- | gr-blocks/swig/blocks_swig.i | 3 |
8 files changed, 314 insertions, 3 deletions
diff --git a/gr-blocks/grc/blocks_block_tree.xml b/gr-blocks/grc/blocks_block_tree.xml index 5e2c5c8afc..7b04737d4e 100644 --- a/gr-blocks/grc/blocks_block_tree.xml +++ b/gr-blocks/grc/blocks_block_tree.xml @@ -131,6 +131,7 @@ <cat> <name>Misc (New) </name> <block>blocks_throttle</block> + <block>blocks_probe_rate</block> </cat> <cat> <name>Networking</name> diff --git a/gr-blocks/grc/blocks_probe_rate.xml b/gr-blocks/grc/blocks_probe_rate.xml new file mode 100644 index 0000000000..08df23e0d2 --- /dev/null +++ b/gr-blocks/grc/blocks_probe_rate.xml @@ -0,0 +1,66 @@ +<?xml version="1.0"?> +<!-- +################################################### +##Probe Rate +################################################### + --> +<block> + <name>Probe Rate</name> + <key>blocks_probe_rate</key> + <import>from gnuradio import blocks</import> + <make>blocks.probe_rate($type.size*$vlen, $mintime, $alpha)</make> + <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>Vec Length</name> + <key>vlen</key> + <value>1</value> + <type>int</type> + </param> + <param> + <name>Min Update Time (ms)</name> + <key>mintime</key> + <value>500.0</value> + <type>real</type> + </param> + <param> + <name>Update Alpha</name> + <key>alpha</key> + <value>0.15</value> + <type>real</type> + </param> + <check>$vlen >= 1</check> + <sink> + <name>in</name> + <type>$type</type> + <vlen>$vlen</vlen> + </sink> +</block> diff --git a/gr-blocks/include/blocks/CMakeLists.txt b/gr-blocks/include/blocks/CMakeLists.txt index 111feef4f1..c7b3cb918e 100644 --- a/gr-blocks/include/blocks/CMakeLists.txt +++ b/gr-blocks/include/blocks/CMakeLists.txt @@ -124,9 +124,6 @@ install(FILES conjugate_cc.h deinterleave.h delay.h - file_descriptor_sink.h - file_descriptor_source.h - file_sink.h file_source.h file_meta_sink.h file_meta_source.h @@ -156,6 +153,7 @@ install(FILES pdu.h pdu_to_tagged_stream.h peak_detector2_fb.h + probe_rate.h regenerate_bb.h repeat.h rms_cf.h diff --git a/gr-blocks/include/blocks/probe_rate.h b/gr-blocks/include/blocks/probe_rate.h new file mode 100644 index 0000000000..e08a9dce06 --- /dev/null +++ b/gr-blocks/include/blocks/probe_rate.h @@ -0,0 +1,60 @@ +/* -*- c++ -*- */ +/* + * Copyright 2005,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_BLOCKS_PROBE_RATE_H +#define INCLUDED_BLOCKS_PROBE_RATE_H + +#include <blocks/api.h> +#include <gr_sync_block.h> + +namespace gr { + namespace blocks { + + /*! + * \brief throughput measurement + */ + class BLOCKS_API probe_rate : virtual public gr_sync_block + { + public: + // gr::blocks::probe_rate::sptr + typedef boost::shared_ptr<probe_rate> sptr; + + /*! + * \brief Make a throughput measurement block + * \param itemsize size of each stream item + * \param update_rate_sec minimum update time in seconds + * \param alpha gain for running average filter + */ + static sptr make(size_t itemsize, double update_rate_ms = 500.0, double alpha = 0.0001); + + virtual void set_alpha(double alpha) = 0; + + virtual double rate() = 0; + + virtual bool start() = 0; + virtual bool stop() = 0; + }; + + } /* namespace blocks */ +} /* namespace gr */ + +#endif /* INCLUDED_BLOCKS_PROBE_RATE_H */ diff --git a/gr-blocks/lib/CMakeLists.txt b/gr-blocks/lib/CMakeLists.txt index b65c262989..d64287c749 100644 --- a/gr-blocks/lib/CMakeLists.txt +++ b/gr-blocks/lib/CMakeLists.txt @@ -192,6 +192,7 @@ list(APPEND gr_blocks_sources tag_debug_impl.cc pdu_to_tagged_stream_impl.cc peak_detector2_fb_impl.cc + probe_rate_impl.cc regenerate_bb_impl.cc repeat_impl.cc rms_cf_impl.cc diff --git a/gr-blocks/lib/probe_rate_impl.cc b/gr-blocks/lib/probe_rate_impl.cc new file mode 100644 index 0000000000..37749c85e3 --- /dev/null +++ b/gr-blocks/lib/probe_rate_impl.cc @@ -0,0 +1,119 @@ +/* -*- c++ -*- */ +/* + * Copyright 2005,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 "probe_rate_impl.h" +#include <gr_io_signature.h> + +namespace gr { + namespace blocks { + + probe_rate::sptr + probe_rate::make(size_t itemsize, double update_rate_ms, double alpha) + { + return gnuradio::get_initial_sptr + (new probe_rate_impl(itemsize,update_rate_ms,alpha)); + } + + probe_rate_impl::probe_rate_impl(size_t itemsize, double update_rate_ms, double alpha) : + gr_sync_block("probe_rate", + gr_make_io_signature(1,1,itemsize), + gr_make_io_signature(0,0,itemsize)), + d_alpha(alpha), + d_beta(1.0-alpha), + d_avg(0), + d_min_update_time(update_rate_ms), + d_lastthru(0), + d_itemsize(itemsize) + { + } + + probe_rate_impl::~probe_rate_impl(){} + + int probe_rate_impl::work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items){ + d_lastthru += noutput_items; + boost::posix_time::ptime now(boost::posix_time::microsec_clock::local_time()); + boost::posix_time::time_duration diff = now - d_last_update; + double diff_ms = diff.total_milliseconds(); + if(diff_ms >= d_min_update_time){ + double rate_this_update = d_lastthru *1e3 / diff_ms; + d_lastthru = 0; + d_last_update = now; + if(d_avg == 0){ + d_avg = rate_this_update; + } else { + d_avg = rate_this_update*d_alpha + d_avg*d_beta; + } + } + return noutput_items; + } + + void probe_rate_impl::setup_rpc(){ +#ifdef GR_CTRLPORT + add_rpc_variable( + rpcbasic_sptr(new rpcbasic_register_get<probe_rate_impl, double >( + alias(), "rate_items", + &probe_rate_impl::rate, + pmt::mp(0), pmt::mp(1e6), pmt::mp(1), + "items/sec", "Item rate", + RPC_PRIVLVL_MIN, DISPTIME | DISPOPTSTRIP))); + add_rpc_variable( + rpcbasic_sptr(new rpcbasic_register_get<probe_rate_impl, double >( + alias(), "timesincelast", + &probe_rate_impl::timesincelast, + pmt::mp(0), pmt::mp(d_min_update_time*2), pmt::mp(0), + "ms", "Time since last update", + RPC_PRIVLVL_MIN, DISPTIME | DISPOPTSTRIP))); +#endif + } + + void probe_rate_impl::set_alpha(double alpha){ d_alpha = alpha; } + + double probe_rate_impl::rate(){ return d_avg; } + + double probe_rate_impl::timesincelast(){ + boost::posix_time::ptime now(boost::posix_time::microsec_clock::local_time()); + boost::posix_time::time_duration diff = now - d_last_update; + return diff.total_milliseconds(); + } + + bool probe_rate_impl::start(){ + d_avg = 0; + d_lastthru = 0; + d_last_update = boost::posix_time::microsec_clock::local_time(); + return true; + } + + bool probe_rate_impl::stop(){ + return true; + } + + + + } /* namespace blocks */ +} /* namespace gr */ + diff --git a/gr-blocks/lib/probe_rate_impl.h b/gr-blocks/lib/probe_rate_impl.h new file mode 100644 index 0000000000..81f7b4e138 --- /dev/null +++ b/gr-blocks/lib/probe_rate_impl.h @@ -0,0 +1,63 @@ +/* -*- c++ -*- */ +/* + * Copyright 2005,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_PROBE_RATE_IMPL_H +#define INCLUDED_GR_PROBE_RATE_IMPL_H + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <blocks/probe_rate.h> + +namespace gr { + namespace blocks { + + class probe_rate_impl : public probe_rate + { + private: + double d_alpha, d_beta, d_avg; + double d_min_update_time; + boost::posix_time::ptime d_last_update; + uint64_t d_lastthru; + size_t d_itemsize; + void setup_rpc(); + + public: + probe_rate_impl(size_t itemsize, double update_rate_ms, double alpha = 0.0001); + ~probe_rate_impl(); + void set_alpha(double alpha); + double rate(); + double timesincelast(); + bool start(); + bool stop(); + + int work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + + }; // end class + + } /* namespace blocks */ +} /* namespace gr */ + +#endif diff --git a/gr-blocks/swig/blocks_swig.i b/gr-blocks/swig/blocks_swig.i index 9d9caa29fc..646cdd1e9e 100644 --- a/gr-blocks/swig/blocks_swig.i +++ b/gr-blocks/swig/blocks_swig.i @@ -134,6 +134,7 @@ #include "blocks/peak_detector_ib.h" #include "blocks/peak_detector_sb.h" #include "blocks/peak_detector2_fb.h" +#include "blocks/probe_rate.h" #include "blocks/probe_signal_b.h" #include "blocks/probe_signal_s.h" #include "blocks/probe_signal_i.h" @@ -309,6 +310,7 @@ %include "blocks/peak_detector_ib.h" %include "blocks/peak_detector_sb.h" %include "blocks/peak_detector2_fb.h" +%include "blocks/probe_rate.h" %include "blocks/regenerate_bb.h" %include "blocks/repeat.h" %include "blocks/rms_cf.h" @@ -454,6 +456,7 @@ GR_SWIG_BLOCK_MAGIC2(blocks, peak_detector_ib); GR_SWIG_BLOCK_MAGIC2(blocks, peak_detector_sb); GR_SWIG_BLOCK_MAGIC2(blocks, peak_detector2_fb); GR_SWIG_BLOCK_MAGIC2(blocks, pdu_to_tagged_stream); +GR_SWIG_BLOCK_MAGIC2(blocks, probe_rate); GR_SWIG_BLOCK_MAGIC2(blocks, or_bb); GR_SWIG_BLOCK_MAGIC2(blocks, or_ss); GR_SWIG_BLOCK_MAGIC2(blocks, or_ii); |