diff options
author | Tom Rondeau <trondeau@vt.edu> | 2013-03-06 11:47:54 -0500 |
---|---|---|
committer | Tom Rondeau <trondeau@vt.edu> | 2013-03-06 11:47:54 -0500 |
commit | a08afb0b0166cab961982f174a5cf672393b5198 (patch) | |
tree | 6969d4fb69fe2e55775cc6a2e59ea31063d84102 | |
parent | 2e9de83a929192a65b827b964bd4452c20ef8756 (diff) | |
parent | 9cfd03bd98693e62c6898f18d90d5d08f4d5c102 (diff) |
Merge branch 'master' into next
Conflicts:
gr-blocks/grc/blocks_block_tree.xml
36 files changed, 2542 insertions, 1 deletions
diff --git a/gr-blocks/grc/blocks_block_tree.xml b/gr-blocks/grc/blocks_block_tree.xml index dff145c41a..62a5610a0c 100644 --- a/gr-blocks/grc/blocks_block_tree.xml +++ b/gr-blocks/grc/blocks_block_tree.xml @@ -34,11 +34,14 @@ <block>blocks_file_meta_source</block> <block>blocks_pdu_to_tagged_stream</block> <block>blocks_random_pdu</block> + <block>blocks_message_source</block> + <block>blocks_message_burst_source</block> </cat> <cat> <name>Sinks (New)</name> <block>blocks_file_meta_sink</block> <block>blocks_tagged_stream_to_pdu</block> + <block>blocks_message_sink</block> </cat> <cat> <name>Math Operations (New) </name> @@ -103,6 +106,7 @@ <block>blocks_vector_to_stream</block> <block>blocks_vector_to_streams</block> <block>blocks_stream_to_vector_decimator</block> + <block>blocks_peak_detector_xb</block> <block>blocks_peak_detector2_fb</block> <block>blocks_regenerate_bb</block> <block>blocks_stretch_ff</block> @@ -128,10 +132,16 @@ <name>Level Controls (New)</name> <block>blocks_mute_xx</block> <block>blocks_sample_and_hold_xx</block> + <block>blocks_moving_average_xx</block> </cat> <cat> <name>Probes (New)</name> <block>blocks_probe_signal_x</block> <block>blocks_probe_signal_vx</block> </cat> + <cat> + <name>Message Tools (New)</name> + <block>blocks_message_strobe</block> + <block>blocks_message_debug</block> + </cat> </cat> diff --git a/gr-blocks/grc/blocks_message_burst_source.xml b/gr-blocks/grc/blocks_message_burst_source.xml new file mode 100644 index 0000000000..208955e557 --- /dev/null +++ b/gr-blocks/grc/blocks_message_burst_source.xml @@ -0,0 +1,58 @@ +<?xml version="1.0"?> +<!-- +################################################### +##Message Burst Source (the sink port is a message) +################################################### + --> +<block> + <name>Message Burst Source</name> + <key>blocks_message_burst_source</key> + <import>from gnuradio import blocks</import> + <make>blocks.message_burst_source($type.size*$vlen, $(id)_msgq_in)</make> + <param> + <name>Output 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> + <check>$vlen > 0</check> + <sink> + <name>in</name> + <type>msg</type> + </sink> + <source> + <name>out</name> + <type>$type</type> + <vlen>$vlen</vlen> + </source> +</block> diff --git a/gr-blocks/grc/blocks_message_debug.xml b/gr-blocks/grc/blocks_message_debug.xml new file mode 100644 index 0000000000..c547c7542d --- /dev/null +++ b/gr-blocks/grc/blocks_message_debug.xml @@ -0,0 +1,27 @@ +<?xml version="1.0"?> +<!-- +################################################### +##Message Debug +################################################### + --> +<block> + <name>Message Debug</name> + <key>blocks_message_debug</key> + <import>from gnuradio import blocks</import> + <make>blocks.message_debug()</make> + <sink> + <name>print</name> + <type>message</type> + <optional>1</optional> + </sink> + <sink> + <name>store</name> + <type>message</type> + <optional>1</optional> + </sink> + <sink> + <name>print_pdu</name> + <type>message</type> + <optional>1</optional> + </sink> +</block> diff --git a/gr-blocks/grc/blocks_message_sink.xml b/gr-blocks/grc/blocks_message_sink.xml new file mode 100644 index 0000000000..c1f21f6521 --- /dev/null +++ b/gr-blocks/grc/blocks_message_sink.xml @@ -0,0 +1,72 @@ +<?xml version="1.0"?> +<!-- +################################################### +##Message Sink (the source port is a message) +################################################### + --> +<block> + <name>Message Sink</name> + <key>blocks_message_sink</key> + <import>from gnuradio import blocks</import> + <make>blocks.message_sink($type.size*$vlen, $(id)_msgq_out, $dont_block)</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>Don't Block</name> + <key>dont_block</key> + <value>False</value> + <type>enum</type> + <option> + <name>Don't Block</name> + <key>True</key> + </option> + <option> + <name>Block</name> + <key>False</key> + </option> + </param> + <param> + <name>Vec Length</name> + <key>vlen</key> + <value>1</value> + <type>int</type> + </param> + <check>$vlen > 0</check> + <sink> + <name>in</name> + <type>$type</type> + <vlen>$vlen</vlen> + </sink> + <source> + <name>out</name> + <type>msg</type> + </source> +</block> diff --git a/gr-blocks/grc/blocks_message_source.xml b/gr-blocks/grc/blocks_message_source.xml new file mode 100644 index 0000000000..12c6569606 --- /dev/null +++ b/gr-blocks/grc/blocks_message_source.xml @@ -0,0 +1,58 @@ +<?xml version="1.0"?> +<!-- +################################################### +##Message Source (the sink port is a message) +################################################### + --> +<block> + <name>Message Source</name> + <key>blocks_message_source</key> + <import>from gnuradio import blocks</import> + <make>blocks.message_source($type.size*$vlen, $(id)_msgq_in)</make> + <param> + <name>Output 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> + <check>$vlen > 0</check> + <sink> + <name>in</name> + <type>msg</type> + </sink> + <source> + <name>out</name> + <type>$type</type> + <vlen>$vlen</vlen> + </source> +</block> diff --git a/gr-blocks/grc/blocks_message_strobe.xml b/gr-blocks/grc/blocks_message_strobe.xml new file mode 100644 index 0000000000..25c98cd01c --- /dev/null +++ b/gr-blocks/grc/blocks_message_strobe.xml @@ -0,0 +1,35 @@ +<?xml version="1.0"?> +<!-- +################################################### +##Message Strobe +################################################### + --> +<block> + <name>Message Strobe</name> + <key>blocks_message_strobe</key> + <import>from gnuradio import blocks</import> + <import>from gruel import pmt</import> + <make>blocks.message_strobe($msg, $period)</make> + <param> + <name>Message PMT</name> + <key>msg</key> + <value>pmt.pmt_intern("TEST")</value> + <type>raw</type> + </param> + <param> + <name>Period (ms)</name> + <key>period</key> + <value>1000</value> + <type>real</type> + </param> + <sink> + <name>set_msg</name> + <type>message</type> + <optional>1</optional> + </sink> + <source> + <name>strobe</name> + <type>message</type> + <optional>1</optional> + </source> +</block> diff --git a/gr-blocks/grc/blocks_moving_average_xx.xml b/gr-blocks/grc/blocks_moving_average_xx.xml new file mode 100644 index 0000000000..e90903ad85 --- /dev/null +++ b/gr-blocks/grc/blocks_moving_average_xx.xml @@ -0,0 +1,68 @@ +<?xml version="1.0"?> +<!-- +################################################### +##Moving Average +################################################### + --> +<block> + <name>Moving Average</name> + <key>blocks_moving_average_xx</key> + <import>from gnuradio import blocks</import> + <make>blocks.moving_average_$(type.fcn)($length, $scale, $max_iter)</make> + <callback>set_length_and_scale($length, $scale)</callback> + <param> + <name>Type</name> + <key>type</key> + <type>enum</type> + <option> + <name>Complex</name> + <key>complex</key> + <opt>fcn:cc</opt> + <opt>scale:complex</opt> + </option> + <option> + <name>Float</name> + <key>float</key> + <opt>fcn:ff</opt> + <opt>scale:real</opt> + </option> + <option> + <name>Int</name> + <key>int</key> + <opt>fcn:ii</opt> + <opt>scale:int</opt> + </option> + <option> + <name>Short</name> + <key>short</key> + <opt>fcn:ss</opt> + <opt>scale:int</opt> + </option> + </param> + <param> + <name>Length</name> + <key>length</key> + <value>1000</value> + <type>int</type> + </param> + <param> + <name>Scale</name> + <key>scale</key> + <value>1</value> + <type>$type.scale</type> + </param> + <param> + <name>Max Iter</name> + <key>max_iter</key> + <value>4000</value> + <type>int</type> + </param> + <sink> + <name>in</name> + <type>$type</type> + </sink> + <source> + <name>out</name> + <type>$type</type> + </source> +</block> diff --git a/gr-blocks/grc/blocks_peak_detector_xb.xml b/gr-blocks/grc/blocks_peak_detector_xb.xml new file mode 100644 index 0000000000..1aabf89474 --- /dev/null +++ b/gr-blocks/grc/blocks_peak_detector_xb.xml @@ -0,0 +1,68 @@ +<?xml version="1.0"?> +<!-- +################################################### +##Peak Detector +################################################### + --> +<block> + <name>Peak Detector</name> + <key>blocks_peak_detector_xb</key> + <import>from gnuradio import blocks</import> + <make>blocks.peak_detector_$(type.fcn)b($threshold_factor_rise, $threshold_factor_fall, $look_ahead, $alpha)</make> + <callback>set_threshold_factor_rise($threshold_factor_rise)</callback> + <callback>set_threshold_factor_fall($threshold_factor_fall)</callback> + <callback>set_look_ahead($look_ahead)</callback> + <callback>set_alpha($alpha)</callback> + <param> + <name>Input Type</name> + <key>type</key> + <type>enum</type> + <option> + <name>Float</name> + <key>float</key> + <opt>fcn:f</opt> + </option> + <option> + <name>Int</name> + <key>int</key> + <opt>fcn:i</opt> + </option> + <option> + <name>Short</name> + <key>short</key> + <opt>fcn:s</opt> + </option> + </param> + <param> + <name>TH Factor Rise</name> + <key>threshold_factor_rise</key> + <value>0.25</value> + <type>real</type> + </param> + <param> + <name>TH Factor Fall</name> + <key>threshold_factor_fall</key> + <value>0.40</value> + <type>real</type> + </param> + <param> + <name>Look Ahead</name> + <key>look_ahead</key> + <value>10</value> + <type>int</type> + </param> + <param> + <name>Alpha</name> + <key>alpha</key> + <value>0.001</value> + <type>real</type> + </param> + <sink> + <name>in</name> + <type>$type</type> + </sink> + <source> + <name>out</name> + <type>byte</type> + </source> +</block> diff --git a/gr-blocks/include/blocks/CMakeLists.txt b/gr-blocks/include/blocks/CMakeLists.txt index ce493e64de..0da7a0e569 100644 --- a/gr-blocks/include/blocks/CMakeLists.txt +++ b/gr-blocks/include/blocks/CMakeLists.txt @@ -73,12 +73,14 @@ expand_h(argmax_XX fs is ss) expand_h(divide_XX ss ii ff cc) expand_h(integrate_XX ss ii ff cc) expand_h(max_XX ff ii ss) +expand_h(moving_average_XX ss ii ff cc) expand_h(multiply_XX ss ii) expand_h(multiply_const_XX ss ii) expand_h(multiply_const_vXX ss ii ff cc) expand_h(mute_XX ss ii ff cc) expand_h(not_XX bb ss ii) expand_h(or_XX bb ss ii) +expand_h(peak_detector_XX fb ib sb) expand_h(probe_signal_X b s i f c) expand_h(probe_signal_vX b s i f c) expand_h(sample_and_hold_XX bb ss ii ff) @@ -125,6 +127,11 @@ install(FILES interleaved_short_to_complex.h keep_m_in_n.h keep_one_in_n.h + message_debug.h + message_sink.h + message_source.h + message_strobe.h + message_burst_source.h multiply_cc.h multiply_ff.h multiply_conjugate_cc.h diff --git a/gr-blocks/include/blocks/message_burst_source.h b/gr-blocks/include/blocks/message_burst_source.h new file mode 100644 index 0000000000..864d43452f --- /dev/null +++ b/gr-blocks/include/blocks/message_burst_source.h @@ -0,0 +1,52 @@ +/* -*- c++ -*- */ +/* + * Copyright 2012-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_MESSAGE_BURST_SOURCE_H +#define INCLUDED_GR_MESSAGE_BURST_SOURCE_H + +#include <blocks/api.h> +#include <gr_sync_block.h> +#include <gr_msg_queue.h> + +namespace gr { + namespace blocks { + + /*! + * \brief Turn received messages into a stream and tag them for UHD to send. + * \ingroup source_blk + */ + class BLOCKS_API message_burst_source : virtual public gr_sync_block + { + public: + // gr::blocks::message_source::sptr + typedef boost::shared_ptr<message_burst_source> sptr; + + static sptr make(size_t itemsize, int msgq_limit); + static sptr make(size_t itemsize, gr_msg_queue_sptr msgq); + + virtual gr_msg_queue_sptr msgq() const = 0; + }; + + } /* namespace blocks */ +} /* namespace gr */ + +#endif /* INCLUDED_GR_MESSAGE_BURST_SOURCE_H */ diff --git a/gr-blocks/include/blocks/message_debug.h b/gr-blocks/include/blocks/message_debug.h new file mode 100644 index 0000000000..f0212331c2 --- /dev/null +++ b/gr-blocks/include/blocks/message_debug.h @@ -0,0 +1,85 @@ +/* -*- c++ -*- */ +/* + * Copyright 2005,2012-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_MESSAGE_DEBUG_H +#define INCLUDED_GR_MESSAGE_DEBUG_H + +#include <blocks/api.h> +#include <gr_block.h> + +namespace gr { + namespace blocks { + + /*! + * \brief Debug block for the message passing system. + * \ingroup sink_blk + * + * The message debug block is used to capture and print or store + * messages as they are received. Any block that generates a + * message may connect that message port to one or more of the + * three message input ports of this debug block. The message + * ports are: + * + * \li print: prints the message directly to standard out. + * \li store: stores the message in an internal vector. May be + * access using the get_message function. + * \li print_pdu: specifically designed to handle formatted PDUs + * (see pdu.h). + */ + class BLOCKS_API message_debug : virtual public gr_block + { + public: + // gr::blocks::message_debug::sptr + typedef boost::shared_ptr<message_debug> sptr; + + /*! + * \brief Build the message debug block. It takes no parameters + * and has three message ports: print, store, and + * print_pdu. + */ + static sptr make(); + + /*! + * \brief Reports the number of messages received by this block. + */ + virtual int num_messages() = 0; + + /*! + * \brief Get a message (as a PMT) from the message vector at index \p i. + * + * Messages passed to the 'store' port will be stored in a + * vector. This function retrieves those messages by index. They + * are index in order of when they were received (all messages + * are just pushed onto the back of a vector). This is mostly + * useful in debugging message passing graphs and in QA code. + * + * \param i The index in the vector for the message to retrieve. + * + * \return a message at index \p i as a pmt_t. + */ + virtual pmt::pmt_t get_message(int i) = 0; + }; + + } /* namespace blocks */ +} /* namespace gr */ + +#endif /* INCLUDED_GR_MESSAGE_DEBUG_H */ diff --git a/gr-blocks/include/blocks/message_sink.h b/gr-blocks/include/blocks/message_sink.h new file mode 100644 index 0000000000..5d14836dd4 --- /dev/null +++ b/gr-blocks/include/blocks/message_sink.h @@ -0,0 +1,49 @@ +/* -*- 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_MESSAGE_SINK_H +#define INCLUDED_GR_MESSAGE_SINK_H + +#include <blocks/api.h> +#include <gr_sync_block.h> +#include <gr_msg_queue.h> + +namespace gr { + namespace blocks { + + /*! + * \brief Gather received items into messages and insert into msgq + * \ingroup sink_blk + */ + class BLOCKS_API message_sink : virtual public gr_sync_block + { + public: + // gr::blocks::message_sink::sptr + typedef boost::shared_ptr<message_sink> sptr; + + static sptr make (size_t itemsize, gr_msg_queue_sptr msgq, bool dont_block); + }; + + } /* namespace blocks */ +} /* namespace gr */ + +#endif /* INCLUDED_GR_MESSAGE_SINK_H */ diff --git a/gr-blocks/include/blocks/message_source.h b/gr-blocks/include/blocks/message_source.h new file mode 100644 index 0000000000..5b55191880 --- /dev/null +++ b/gr-blocks/include/blocks/message_source.h @@ -0,0 +1,52 @@ +/* -*- 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_MESSAGE_SOURCE_H +#define INCLUDED_GR_MESSAGE_SOURCE_H + +#include <blocks/api.h> +#include <gr_sync_block.h> +#include <gr_msg_queue.h> + +namespace gr { + namespace blocks { + + /*! + * \brief Turn received messages into a stream + * \ingroup source_blk + */ + class BLOCKS_API message_source : virtual public gr_sync_block + { + public: + // gr::blocks::message_source::sptr + typedef boost::shared_ptr<message_source> sptr; + + static sptr make(size_t itemsize, int msgq_limit=0); + static sptr make(size_t itemsize, gr_msg_queue_sptr msgq); + + virtual gr_msg_queue_sptr msgq() const = 0; + }; + + } /* namespace blocks */ +} /* namespace gr */ + +#endif /* INCLUDED_GR_MESSAGE_SOURCE_H */ diff --git a/gr-blocks/include/blocks/message_strobe.h b/gr-blocks/include/blocks/message_strobe.h new file mode 100644 index 0000000000..6b427d539c --- /dev/null +++ b/gr-blocks/include/blocks/message_strobe.h @@ -0,0 +1,81 @@ +/* -*- c++ -*- */ +/* + * Copyright 2012-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_MESSAGE_STROBE_H +#define INCLUDED_GR_MESSAGE_STROBE_H + +#include <blocks/api.h> +#include <gr_block.h> + +namespace gr { + namespace blocks { + + /*! + * \brief Send message at defined interval + * \ingroup msg_blk + * + * Takes a PMT message and sends it out every \p period_ms + * milliseconds. Useful for testing/debugging the message system. + */ + class BLOCKS_API message_strobe : virtual public gr_block + { + public: + // gr::blocks::message_strobe::sptr + typedef boost::shared_ptr<message_strobe> sptr; + + /*! + * Make a message stobe block to send message \p msg every \p + * period_ms milliseconds. + * + * \param msg The message to send as a PMT. + * \param period_ms the time period in milliseconds in which to + * send \p msg. + */ + static sptr make(pmt::pmt_t msg, float period_ms); + + /*! + * Reset the message being sent. + * \param msg The message to send as a PMT. + */ + virtual void set_msg(pmt::pmt_t msg) = 0; + + /*! + * Get the value of the message being sent. + */ + virtual pmt::pmt_t msg() const = 0; + + /*! + * Reset the sending interval. + * \param period_ms the time period in milliseconds. + */ + virtual void set_period(float period_ms) = 0; + + /*! + * Get the time interval of the strobe. + */ + virtual float period() const = 0; + }; + + } /* namespace blocks */ +} /* namespace gr */ + +#endif /* INCLUDED_GR_MESSAGE_STROBE_H */ diff --git a/gr-blocks/include/blocks/moving_average_XX.h.t b/gr-blocks/include/blocks/moving_average_XX.h.t new file mode 100644 index 0000000000..6b7883fdd4 --- /dev/null +++ b/gr-blocks/include/blocks/moving_average_XX.h.t @@ -0,0 +1,84 @@ +/* -*- c++ -*- */ +/* + * Copyright 2008,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. + */ + +// @WARNING@ + +#ifndef @GUARD_NAME@ +#define @GUARD_NAME@ + +#include <blocks/api.h> +#include <gr_sync_block.h> + +namespace gr { + namespace blocks { + + /*! + * \brief output is the moving sum of the last N samples, scaled by the scale factor + * \ingroup filter_blk + */ + class BLOCKS_API @NAME@ : virtual public gr_sync_block + { + public: + // gr::blocks::@NAME@::sptr + typedef boost::shared_ptr<@NAME@> sptr; + + /*! + * Create a moving average block. + * + * \param length Number of samples to use in the average. + * \param scale scale factor for the result. + * \param max_iter limits how long we go without flushing the accumulator + * This is necessary to avoid numerical instability for float and complex. + */ + static sptr make(int length, @O_TYPE@ scale, + int max_iter = 4096); + + /*! + * Get the length used in the avaraging calculation. + */ + virtual int length() const = 0; + + /*! + * Get the scale factor being used. + */ + virtual @O_TYPE@ scale() const = 0; + + /*! + * Set both the length and the scale factor together. + */ + virtual void set_length_and_scale(int length, @O_TYPE@ scale) = 0; + + /*! + * Set the length. + */ + virtual void set_length(int length) = 0; + + /*! + * Set the scale factor. + */ + virtual void set_scale(@O_TYPE@ scale) = 0; + }; + + } /* namespace blocks */ +} /* namespace gr */ + +#endif /* @GUARD_NAME@ */ diff --git a/gr-blocks/include/blocks/peak_detector_XX.h.t b/gr-blocks/include/blocks/peak_detector_XX.h.t new file mode 100644 index 0000000000..1c8ba0652f --- /dev/null +++ b/gr-blocks/include/blocks/peak_detector_XX.h.t @@ -0,0 +1,117 @@ +/* -*- c++ -*- */ +/* + * Copyright 2007,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. + */ + +// @WARNING@ + +#ifndef @GUARD_NAME@ +#define @GUARD_NAME@ + +#include <blocks/api.h> +#include <gr_sync_block.h> + +namespace gr { + namespace blocks { + + /*! + * \brief Detect the peak of a signal + * \ingroup level_blk + * + * If a peak is detected, this block outputs a 1, + * or it outputs 0's. + */ + class GR_CORE_API @NAME@ : virtual public gr_sync_block + { + public: + // gr::blocks::@NAME@::sptr + typedef boost::shared_ptr<@NAME@> sptr; + + /*! + * Make a peak detector block. + * + * \param threshold_factor_rise The threshold factor determins + * when a peak has started. An average of the signal is + * calculated and when the value of the signal goes over + * threshold_factor_rise*average, we start looking for a + * peak. + * \param threshold_factor_fall The threshold factor determins + * when a peak has ended. An average of the signal is + * calculated and when the value of the signal goes + * bellow threshold_factor_fall*average, we stop looking + * for a peak. + * \param look_ahead The look-ahead value is used when the + * threshold is found to look if there another peak + * within this step range. If there is a larger value, + * we set that as the peak and look ahead again. This is + * continued until the highest point is found with This + * look-ahead range. + * \param alpha The gain value of a moving average filter + */ + static sptr make(float threshold_factor_rise = 0.25, + float threshold_factor_fall = 0.40, + int look_ahead = 10, + float alpha = 0.001); + + /*! \brief Set the threshold factor value for the rise time + * \param thr new threshold factor + */ + virtual void set_threshold_factor_rise(float thr) = 0; + + /*! \brief Set the threshold factor value for the fall time + * \param thr new threshold factor + */ + virtual void set_threshold_factor_fall(float thr) = 0; + + /*! \brief Set the look-ahead factor + * \param look new look-ahead factor + */ + virtual void set_look_ahead(int look) = 0; + + /*! \brief Set the running average alpha + * \param alpha new alpha for running average + */ + virtual void set_alpha(int alpha) = 0; + + /*! \brief Get the threshold factor value for the rise time + * \return threshold factor + */ + virtual float threshold_factor_rise() = 0; + + /*! \brief Get the threshold factor value for the fall time + * \return threshold factor + */ + virtual float threshold_factor_fall() = 0; + + /*! \brief Get the look-ahead factor value + * \return look-ahead factor + */ + virtual int look_ahead() = 0; + + /*! \brief Get the alpha value of the running average + * \return alpha + */ + virtual float alpha() = 0; + }; + + } /* namespace blocks */ +} /* namespace gr */ + +#endif /* @GUARD_NAME@ */ diff --git a/gr-blocks/lib/CMakeLists.txt b/gr-blocks/lib/CMakeLists.txt index eb7868dd42..d84d79de7d 100644 --- a/gr-blocks/lib/CMakeLists.txt +++ b/gr-blocks/lib/CMakeLists.txt @@ -99,12 +99,14 @@ expand_cc_h_impl(argmax_XX fs is ss) expand_cc_h_impl(divide_XX ss ii ff cc) expand_cc_h_impl(integrate_XX ss ii ff cc) expand_cc_h_impl(max_XX ff ii ss) +expand_cc_h_impl(moving_average_XX ss ii ff cc) expand_cc_h_impl(multiply_XX ss ii) expand_cc_h_impl(multiply_const_XX ss ii) expand_cc_h_impl(multiply_const_vXX ss ii ff cc) expand_cc_h_impl(mute_XX ss ii ff cc) expand_cc_h_impl(not_XX bb ss ii) expand_cc_h_impl(or_XX bb ss ii) +expand_cc_h_impl(peak_detector_XX fb ib sb) expand_cc_h_impl(probe_signal_X b s i f c) expand_cc_h_impl(probe_signal_vX b s i f c) expand_cc_h_impl(sample_and_hold_XX bb ss ii ff) @@ -169,6 +171,11 @@ list(APPEND gr_blocks_sources interleaved_short_to_complex_impl.cc keep_m_in_n_impl.cc keep_one_in_n_impl.cc + message_debug_impl.cc + message_sink_impl.cc + message_source_impl.cc + message_strobe_impl.cc + message_burst_source_impl.cc multiply_cc_impl.cc multiply_ff_impl.cc multiply_conjugate_cc_impl.cc diff --git a/gr-blocks/lib/message_burst_source_impl.cc b/gr-blocks/lib/message_burst_source_impl.cc new file mode 100644 index 0000000000..f3c90eda31 --- /dev/null +++ b/gr-blocks/lib/message_burst_source_impl.cc @@ -0,0 +1,149 @@ +/* -*- c++ -*- */ +/* + * Copyright 2012-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 "message_burst_source_impl.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> + +namespace gr { + namespace blocks { + + message_burst_source::sptr + message_burst_source::make(size_t itemsize, int msgq_limit) + { + return gnuradio::get_initial_sptr + (new message_burst_source_impl(itemsize, msgq_limit)); + } + + message_burst_source::sptr + message_burst_source::make(size_t itemsize, gr_msg_queue_sptr msgq) + { + return gnuradio::get_initial_sptr + (new message_burst_source_impl(itemsize, msgq)); + } + + message_burst_source_impl::message_burst_source_impl(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()); + } + + message_burst_source_impl::message_burst_source_impl(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()); + } + + message_burst_source_impl::~message_burst_source_impl() + { + } + + int + message_burst_source_impl::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; + } + + } /* namespace blocks */ +} /* namespace gr */ diff --git a/gr-blocks/lib/message_burst_source_impl.h b/gr-blocks/lib/message_burst_source_impl.h new file mode 100644 index 0000000000..2d5e6a974f --- /dev/null +++ b/gr-blocks/lib/message_burst_source_impl.h @@ -0,0 +1,58 @@ +/* -*- c++ -*- */ +/* + * Copyright 2012-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_MESSAGE_BURST_SOURCE_IMPL_H +#define INCLUDED_GR_MESSAGE_BURST_SOURCE_IMPL_H + +#include <blocks/message_burst_source.h> +#include <gr_message.h> + +namespace gr { + namespace blocks { + + class message_burst_source_impl : public message_burst_source + { + 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; + + public: + message_burst_source_impl(size_t itemsize, int msgq_limit); + message_burst_source_impl(size_t itemsize, gr_msg_queue_sptr msgq); + ~message_burst_source_impl(); + + 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); + }; + + } /* namespace blocks */ +} /* namespace gr */ + +#endif /* INCLUDED_GR_MESSAGE_BURST_SOURCE_IMPL_H */ diff --git a/gr-blocks/lib/message_debug_impl.cc b/gr-blocks/lib/message_debug_impl.cc new file mode 100644 index 0000000000..d7b1e5db09 --- /dev/null +++ b/gr-blocks/lib/message_debug_impl.cc @@ -0,0 +1,120 @@ +/* -*- c++ -*- */ +/* + * Copyright 2005,2010,2012-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 "message_debug_impl.h" +#include <gr_io_signature.h> +#include <cstdio> +#include <iostream> + +namespace gr { + namespace blocks { + + message_debug::sptr + message_debug::make() + { + return gnuradio::get_initial_sptr + (new message_debug_impl()); + } + + void + message_debug_impl::print(pmt::pmt_t msg) + { + std::cout << "******* MESSAGE DEBUG PRINT ********\n"; + pmt::pmt_print(msg); + std::cout << "************************************\n"; + } + + void + message_debug_impl::store(pmt::pmt_t msg) + { + gruel::scoped_lock guard(d_mutex); + d_messages.push_back(msg); + } + + void + message_debug_impl::print_pdu(pmt::pmt_t pdu) + { + pmt::pmt_t meta = pmt::pmt_car(pdu); + pmt::pmt_t vector = pmt::pmt_cdr(pdu); + std::cout << "* MESSAGE DEBUG PRINT PDU VERBOSE *\n"; + pmt::pmt_print(meta); + size_t len = pmt::pmt_length(vector); + std::cout << "pdu_length = " << len << std::endl; + std::cout << "contents = " << std::endl; + size_t offset(0); + const uint8_t* d = (const uint8_t*) pmt_uniform_vector_elements(vector, offset); + for(size_t i=0; i<len; i+=16){ + printf("%04x: ", ((unsigned int)i)); + for(size_t j=i; j<std::min(i+16,len); j++){ + printf("%02x ",d[j] ); + } + + std::cout << std::endl; + } + + std::cout << "***********************************\n"; + } + + int + message_debug_impl::num_messages() + { + return (int)d_messages.size(); + } + + pmt::pmt_t + message_debug_impl::get_message(int i) + { + gruel::scoped_lock guard(d_mutex); + + if((size_t)i >= d_messages.size()) { + throw std::runtime_error("message_debug: index for message out of bounds.\n"); + } + + return d_messages[i]; + } + + message_debug_impl::message_debug_impl() + : gr_block("message_debug", + gr_make_io_signature(0, 0, 0), + gr_make_io_signature(0, 0, 0)) + { + message_port_register_in(pmt::mp("print")); + set_msg_handler(pmt::mp("print"), boost::bind(&message_debug_impl::print, this, _1)); + + message_port_register_in(pmt::mp("store")); + set_msg_handler(pmt::mp("store"), boost::bind(&message_debug_impl::store, this, _1)); + + message_port_register_in(pmt::mp("print_pdu")); + set_msg_handler(pmt::mp("print_pdu"), boost::bind(&message_debug_impl::print_pdu, this, _1)); + } + + message_debug_impl::~message_debug_impl() + { + } + + } /* namespace blocks */ +} /* namespace gr */ + diff --git a/gr-blocks/lib/message_debug_impl.h b/gr-blocks/lib/message_debug_impl.h new file mode 100644 index 0000000000..c9d82bd561 --- /dev/null +++ b/gr-blocks/lib/message_debug_impl.h @@ -0,0 +1,89 @@ +/* -*- c++ -*- */ +/* + * Copyright 2005,2012-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_MESSAGE_DEBUG_IMPL_H +#define INCLUDED_GR_MESSAGE_DEBUG_IMPL_H + +#include <blocks/message_debug.h> +#include <gr_block.h> +#include <gruel/thread.h> +#include <gruel/pmt.h> + +namespace gr { + namespace blocks { + + class message_debug_impl : public message_debug + { + private: + + /*! + * \brief Messages received in this port are printed to stdout. + * + * This port receives messages from the scheduler's message + * handling mechanism and prints it to stdout. This message + * handler function is only meant to be used by the scheduler to + * handle messages posted to port 'print'. + * + * \param msg A pmt message passed from the scheduler's message handling. + */ + void print(pmt::pmt_t msg); + + /*! + * \brief PDU formatted messages received in this port are printed to stdout. + * + * This port receives messages from the scheduler's message + * handling mechanism and prints it to stdout. This message + * handler function is only meant to be used by the scheduler to + * handle messages posted to port 'print'. + * + * \param pdu A PDU message passed from the scheduler's message handling. + */ + void print_pdu(pmt::pmt_t pdu); + + /*! + * \brief Messages received in this port are stored in a vector. + * + * This port receives messages from the scheduler's message + * handling mechanism and stores it in a vector. Messages can be + * retrieved later using the 'get_message' function. This + * message handler function is only meant to be used by the + * scheduler to handle messages posted to port 'store'. + * + * \param msg A pmt message passed from the scheduler's message handling. + */ + void store(pmt::pmt_t msg); + + gruel::mutex d_mutex; + std::vector<pmt::pmt_t> d_messages; + + public: + message_debug_impl(); + ~message_debug_impl(); + + int num_messages(); + pmt::pmt_t get_message(int i); + }; + + } /* namespace blocks */ +} /* namespace gr */ + +#endif /* INCLUDED_GR_MESSAGE_DEBUG_IMPL_H */ diff --git a/gr-blocks/lib/message_sink_impl.cc b/gr-blocks/lib/message_sink_impl.cc new file mode 100644 index 0000000000..a8dbfb4c71 --- /dev/null +++ b/gr-blocks/lib/message_sink_impl.cc @@ -0,0 +1,83 @@ +/* -*- c++ -*- */ +/* + * Copyright 2005,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 "message_sink_impl.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> + +namespace gr { + namespace blocks { + + message_sink::sptr + message_sink::make(size_t itemsize, gr_msg_queue_sptr msgq, bool dont_block) + { + return gnuradio::get_initial_sptr + (new message_sink_impl(itemsize, msgq, dont_block)); + } + + message_sink_impl::message_sink_impl(size_t itemsize, gr_msg_queue_sptr msgq, bool dont_block) + : gr_sync_block("message_sink", + gr_make_io_signature(1, 1, itemsize), + gr_make_io_signature(0, 0, 0)), + d_itemsize(itemsize), d_msgq(msgq), d_dont_block(dont_block) + { + } + + message_sink_impl::~message_sink_impl() + { + } + + int + message_sink_impl::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]; + + // if we'd block, drop the data on the floor and say everything is OK + if(d_dont_block && d_msgq->full_p()) + return noutput_items; + + // build a message to hold whatever we've got + gr_message_sptr msg = gr_make_message(0, // msg type + d_itemsize, // arg1 for other end + noutput_items, // arg2 for other end (redundant) + noutput_items * d_itemsize); // len of msg + memcpy(msg->msg(), in, noutput_items * d_itemsize); + + d_msgq->handle(msg); // send it + + return noutput_items; + } + + } /* namespace blocks */ +} /* namespace gr */ diff --git a/gr-blocks/lib/message_sink_impl.h b/gr-blocks/lib/message_sink_impl.h new file mode 100644 index 0000000000..a3106bc058 --- /dev/null +++ b/gr-blocks/lib/message_sink_impl.h @@ -0,0 +1,50 @@ +/* -*- 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_MESSAGE_SINK_IMPL_H +#define INCLUDED_GR_MESSAGE_SINK_IMPL_H + +#include <blocks/message_sink.h> + +namespace gr { + namespace blocks { + + class message_sink_impl : public message_sink + { + private: + size_t d_itemsize; + gr_msg_queue_sptr d_msgq; + bool d_dont_block; + + public: + message_sink_impl(size_t itemsize, gr_msg_queue_sptr msgq, bool dont_block); + ~message_sink_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_MESSAGE_SINK_IMPL_H */ diff --git a/gr-blocks/lib/message_source_impl.cc b/gr-blocks/lib/message_source_impl.cc new file mode 100644 index 0000000000..cda4fc16c0 --- /dev/null +++ b/gr-blocks/lib/message_source_impl.cc @@ -0,0 +1,127 @@ +/* -*- c++ -*- */ +/* + * Copyright 2005,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 "message_source_impl.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> + +namespace gr { + namespace blocks { + + message_source::sptr + message_source::make(size_t itemsize, int msgq_limit) + { + return gnuradio::get_initial_sptr + (new message_source_impl(itemsize, msgq_limit)); + } + + message_source::sptr + message_source::make(size_t itemsize, gr_msg_queue_sptr msgq) + { + return gnuradio::get_initial_sptr + (new message_source_impl(itemsize, msgq)); + } + + message_source_impl::message_source_impl(size_t itemsize, int msgq_limit) + : gr_sync_block("message_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) + { + } + + message_source_impl::message_source_impl(size_t itemsize, gr_msg_queue_sptr msgq) + : gr_sync_block("message_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) + { + } + + message_source_impl::~message_source_impl() + { + } + + int + message_source_impl::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; + + 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(); + } + } + 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; + + if((d_msg->length() % d_itemsize) != 0) + throw std::runtime_error("msg length is not a multiple of d_itemsize"); + } + } + + return nn; + } + + } /* namespace blocks */ +} /* namespace gr */ diff --git a/gr-blocks/lib/message_source_impl.h b/gr-blocks/lib/message_source_impl.h new file mode 100644 index 0000000000..c420704478 --- /dev/null +++ b/gr-blocks/lib/message_source_impl.h @@ -0,0 +1,56 @@ +/* -*- 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_MESSAGE_SOURCE_IMPL_H +#define INCLUDED_GR_MESSAGE_SOURCE_IMPL_H + +#include <blocks/message_source.h> +#include <gr_message.h> + +namespace gr { + namespace blocks { + + class message_source_impl : public message_source + { + private: + size_t d_itemsize; + gr_msg_queue_sptr d_msgq; + gr_message_sptr d_msg; + unsigned d_msg_offset; + bool d_eof; + + public: + message_source_impl(size_t itemsize, int msgq_limit); + message_source_impl(size_t itemsize, gr_msg_queue_sptr msgq); + ~message_source_impl(); + + 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); + }; + + } /* namespace blocks */ +} /* namespace gr */ + +#endif /* INCLUDED_GR_MESSAGE_SOURCE_IMPL_H */ diff --git a/gr-blocks/lib/message_strobe_impl.cc b/gr-blocks/lib/message_strobe_impl.cc new file mode 100644 index 0000000000..c4b0e5d567 --- /dev/null +++ b/gr-blocks/lib/message_strobe_impl.cc @@ -0,0 +1,85 @@ +/* -*- c++ -*- */ +/* + * Copyright 2012-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 "message_strobe_impl.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 <iostream> + +namespace gr { + namespace blocks { + + message_strobe::sptr + message_strobe::make(pmt::pmt_t msg, float period_ms) + { + return gnuradio::get_initial_sptr + (new message_strobe_impl(msg, period_ms)); + } + + message_strobe_impl::message_strobe_impl(pmt::pmt_t msg, float period_ms) + : gr_block("message_strobe", + gr_make_io_signature(0, 0, 0), + gr_make_io_signature(0, 0, 0)), + d_finished(false), + d_period_ms(period_ms), + d_msg(msg) + { + message_port_register_out(pmt::mp("strobe")); + d_thread = boost::shared_ptr<boost::thread> + (new boost::thread(boost::bind(&message_strobe_impl::run, this))); + + message_port_register_in(pmt::mp("set_msg")); + set_msg_handler(pmt::mp("set_msg"), + boost::bind(&message_strobe_impl::set_msg, this, _1)); + } + + message_strobe_impl::~message_strobe_impl() + { + d_finished = true; + d_thread->interrupt(); + d_thread->join(); + } + + void message_strobe_impl::run() + { + while(!d_finished) { + boost::this_thread::sleep(boost::posix_time::milliseconds(d_period_ms)); + if(d_finished) { + return; + } + + message_port_pub(pmt::mp("strobe"), d_msg); + } + } + + } /* namespace blocks */ +} /* namespace gr */ diff --git a/gr-blocks/lib/message_strobe_impl.h b/gr-blocks/lib/message_strobe_impl.h new file mode 100644 index 0000000000..1b2edae593 --- /dev/null +++ b/gr-blocks/lib/message_strobe_impl.h @@ -0,0 +1,54 @@ +/* -*- c++ -*- */ +/* + * Copyright 2012-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_MESSAGE_STROBE_IMPL_H +#define INCLUDED_GR_MESSAGE_STROBE_IMPL_H + +#include <blocks/message_strobe.h> + +namespace gr { + namespace blocks { + + class BLOCKS_API message_strobe_impl : public message_strobe + { + private: + boost::shared_ptr<boost::thread> d_thread; + bool d_finished; + float d_period_ms; + pmt::pmt_t d_msg; + + void run(); + + public: + message_strobe_impl(pmt::pmt_t msg, float period_ms); + ~message_strobe_impl(); + + void set_msg(pmt::pmt_t msg) { d_msg = msg; } + pmt::pmt_t msg() const { return d_msg; } + void set_period(float period_ms) { d_period_ms = period_ms; } + float period() const { return d_period_ms; } + }; + + } /* namespace blocks */ +} /* namespace gr */ + +#endif /* INCLUDED_GR_MESSAGE_STROBE_IMPL_H */ diff --git a/gr-blocks/lib/moving_average_XX_impl.cc.t b/gr-blocks/lib/moving_average_XX_impl.cc.t new file mode 100644 index 0000000000..566deff116 --- /dev/null +++ b/gr-blocks/lib/moving_average_XX_impl.cc.t @@ -0,0 +1,114 @@ +/* -*- c++ -*- */ +/* + * Copyright 2008,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. + */ + +// @WARNING@ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "@NAME_IMPL@.h" +#include <gr_io_signature.h> + +namespace gr { + namespace blocks { + + @NAME@::sptr + @NAME@::make(int length, @O_TYPE@ scale, int max_iter) + { + return gnuradio::get_initial_sptr + (new @NAME_IMPL@(length, scale, max_iter)); + } + + @NAME_IMPL@::@NAME_IMPL@(int length, @O_TYPE@ scale, int max_iter) + : gr_sync_block("@NAME@", + gr_make_io_signature(1, 1, sizeof(@I_TYPE@)), + gr_make_io_signature(1, 1, sizeof(@O_TYPE@))), + d_length(length), + d_scale(scale), + d_max_iter(max_iter), + d_new_length(length), + d_new_scale(scale), + d_updated(false) + { + set_history(length); + } + + @NAME_IMPL@::~@NAME_IMPL@() + { + } + + void + @NAME_IMPL@::set_length_and_scale(int length, @O_TYPE@ scale) + { + d_new_length = length; + d_new_scale = scale; + d_updated = true; + } + + void + @NAME_IMPL@::set_length(int length) + { + d_new_length = length; + d_updated = true; + } + + void + @NAME_IMPL@::set_scale(@O_TYPE@ scale) + { + d_new_scale = scale; + d_updated = true; + } + + int + @NAME_IMPL@::work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) + { + if(d_updated) { + d_length = d_new_length; + d_scale = d_new_scale; + set_history(d_length); + d_updated = false; + return 0; // history requirements might have changed + } + + const @I_TYPE@ *in = (const @I_TYPE@ *)input_items[0]; + @O_TYPE@ *out = (@O_TYPE@ *)output_items[0]; + + @I_TYPE@ sum = 0; + int num_iter = (noutput_items>d_max_iter) ? d_max_iter : noutput_items; + for(int i = 0; i < d_length-1; i++) { + sum += in[i]; + } + + for(int i = 0; i < num_iter; i++) { + sum += in[i+d_length-1]; + out[i] = sum * d_scale; + sum -= in[i]; + } + + return num_iter; + } + + } /* namespace blocks */ +} /* namespace gr */ diff --git a/gr-blocks/lib/moving_average_XX_impl.h.t b/gr-blocks/lib/moving_average_XX_impl.h.t new file mode 100644 index 0000000000..7234cbe139 --- /dev/null +++ b/gr-blocks/lib/moving_average_XX_impl.h.t @@ -0,0 +1,65 @@ +/* -*- c++ -*- */ +/* + * Copyright 2008,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. + */ + +// @WARNING@ + +#ifndef @GUARD_NAME_IMPL@ +#define @GUARD_NAME_IMPL@ + +#include <blocks/@NAME@.h> + +namespace gr { + namespace blocks { + + class @NAME_IMPL@ : public @NAME@ + { + private: + int d_length; + @O_TYPE@ d_scale; + int d_max_iter; + + int d_new_length; + @O_TYPE@ d_new_scale; + bool d_updated; + + public: + @NAME_IMPL@(int length, @O_TYPE@ scale, + int max_iter = 4096); + ~@NAME_IMPL@(); + + int length() const { return d_new_length; } + @O_TYPE@ scale() const { return d_new_scale; } + + void set_length_and_scale(int length, @O_TYPE@ scale); + void set_length(int length); + void set_scale(@O_TYPE@ scale); + + int work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + + }; + + } /* namespace blocks */ +} /* namespace gr */ + +#endif /* @GUARD_NAME_IMPL@ */ diff --git a/gr-blocks/lib/peak_detector_XX_impl.cc.t b/gr-blocks/lib/peak_detector_XX_impl.cc.t new file mode 100644 index 0000000000..27518962f5 --- /dev/null +++ b/gr-blocks/lib/peak_detector_XX_impl.cc.t @@ -0,0 +1,122 @@ +/* -*- c++ -*- */ +/* + * Copyright 2007,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. + */ + +// @WARNING@ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "@NAME_IMPL@.h" +#include <gr_io_signature.h> +#include <string.h> + +namespace gr { + namespace blocks { + + @NAME@::sptr + @NAME@::make(float threshold_factor_rise, + float threshold_factor_fall, + int look_ahead, float alpha) + { + return gnuradio::get_initial_sptr + (new @NAME_IMPL@(threshold_factor_rise, + threshold_factor_fall, + look_ahead, alpha)); + } + + @NAME_IMPL@::@NAME_IMPL@(float threshold_factor_rise, + float threshold_factor_fall, + int look_ahead, float alpha) + : gr_sync_block("@BASE_NAME@", + gr_make_io_signature(1, 1, sizeof(@I_TYPE@)), + gr_make_io_signature(1, 1, sizeof(char))), + d_threshold_factor_rise(threshold_factor_rise), + d_threshold_factor_fall(threshold_factor_fall), + d_look_ahead(look_ahead), d_avg_alpha(alpha), d_avg(0), d_found(0) + { + } + + @NAME_IMPL@::~@NAME_IMPL@() + { + } + + int + @NAME_IMPL@::work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) + { + @I_TYPE@ *iptr = (@I_TYPE@*)input_items[0]; + char *optr = (char*)output_items[0]; + + memset(optr, 0, noutput_items*sizeof(char)); + + @I_TYPE@ peak_val = -(@I_TYPE@)INFINITY; + int peak_ind = 0; + unsigned char state = 0; + int i = 0; + + //printf("noutput_items %d\n",noutput_items); + while(i < noutput_items) { + if(state == 0) { // below threshold + if(iptr[i] > d_avg*d_threshold_factor_rise) { + state = 1; + } + else { + d_avg = (d_avg_alpha)*iptr[i] + (1-d_avg_alpha)*d_avg; + i++; + } + } + else if(state == 1) { // above threshold, have not found peak + //printf("Entered State 1: %f i: %d noutput_items: %d\n", iptr[i], i, noutput_items); + if(iptr[i] > peak_val) { + peak_val = iptr[i]; + peak_ind = i; + d_avg = (d_avg_alpha)*iptr[i] + (1-d_avg_alpha)*d_avg; + i++; + } + else if(iptr[i] > d_avg*d_threshold_factor_fall) { + d_avg = (d_avg_alpha)*iptr[i] + (1-d_avg_alpha)*d_avg; + i++; + } + else { + optr[peak_ind] = 1; + state = 0; + peak_val = -(@I_TYPE@)INFINITY; + //printf("Leaving State 1: Peak: %f Peak Ind: %d i: %d noutput_items: %d\n", + //peak_val, peak_ind, i, noutput_items); + } + } + } + + if(state == 0) { + //printf("Leave in State 0, produced %d\n",noutput_items); + return noutput_items; + } + else { // only return up to passing the threshold + //printf("Leave in State 1, only produced %d of %d\n",peak_ind,noutput_items); + return peak_ind+1; + } + } + + } /* namespace blocks */ +} /* namespace gr */ diff --git a/gr-blocks/lib/peak_detector_XX_impl.h.t b/gr-blocks/lib/peak_detector_XX_impl.h.t new file mode 100644 index 0000000000..ef52f0f744 --- /dev/null +++ b/gr-blocks/lib/peak_detector_XX_impl.h.t @@ -0,0 +1,66 @@ +/* -*- c++ -*- */ +/* + * Copyright 2007,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. + */ + +// @WARNING@ + +#ifndef @GUARD_NAME_IMPL@ +#define @GUARD_NAME_IMPL@ + +#include <blocks/@NAME@.h> + +namespace gr { + namespace blocks { + + class @NAME_IMPL@ : public @NAME@ + { + private: + float d_threshold_factor_rise; + float d_threshold_factor_fall; + int d_look_ahead; + float d_avg_alpha; + float d_avg; + unsigned char d_found; + + public: + @NAME_IMPL@(float threshold_factor_rise, + float threshold_factor_fall, + int look_ahead, float alpha); + ~@NAME_IMPL@(); + + void set_threshold_factor_rise(float thr) { d_threshold_factor_rise = thr; } + void set_threshold_factor_fall(float thr) { d_threshold_factor_fall = thr; } + void set_look_ahead(int look) { d_look_ahead = look; } + void set_alpha(int alpha) { d_avg_alpha = alpha; } + float threshold_factor_rise() { return d_threshold_factor_rise; } + float threshold_factor_fall() { return d_threshold_factor_fall; } + int look_ahead() { return d_look_ahead; } + float alpha() { return d_avg_alpha; } + + int work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + }; + + } /* namespace blocks */ +} /* namespace gr */ + +#endif /* @GUARD_NAME_IMPL@ */ diff --git a/gr-blocks/python/qa_message.py b/gr-blocks/python/qa_message.py new file mode 100755 index 0000000000..551fdd6259 --- /dev/null +++ b/gr-blocks/python/qa_message.py @@ -0,0 +1,149 @@ +#!/usr/bin/env python +# +# Copyright 2004,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. +# + +from gnuradio import gr, gr_unittest +import blocks_swig as blocks +import pmt +import time + +def all_counts(): + return (gr.block_ncurrently_allocated(), + gr.block_detail_ncurrently_allocated(), + gr.buffer_ncurrently_allocated(), + gr.buffer_reader_ncurrently_allocated(), + gr.message_ncurrently_allocated()) + + +class test_message(gr_unittest.TestCase): + + def setUp(self): + self.msgq = gr.msg_queue() + + def tearDown(self): + self.msgq = None + + def leak_check(self, fct): + begin = all_counts() + fct() + # tear down early so we can check for leaks + self.tearDown() + end = all_counts() + self.assertEqual(begin, end) + + def test_100(self): + msg = gr.message(0, 1.5, 2.3) + self.assertEquals(0, msg.type()) + self.assertAlmostEqual(1.5, msg.arg1()) + self.assertAlmostEqual(2.3, msg.arg2()) + self.assertEquals(0, msg.length()) + + def test_101(self): + s = 'This is a test' + msg = gr.message_from_string(s) + self.assertEquals(s, msg.to_string()) + + def test_200(self): + self.leak_check(self.body_200) + + def body_200(self): + self.msgq.insert_tail(gr.message(0)) + self.assertEquals(1, self.msgq.count()) + self.msgq.insert_tail(gr.message(1)) + self.assertEquals(2, self.msgq.count()) + msg0 = self.msgq.delete_head() + self.assertEquals(0, msg0.type()) + msg1 = self.msgq.delete_head() + self.assertEquals(1, msg1.type()) + self.assertEquals(0, self.msgq.count()) + + def test_201(self): + self.leak_check(self.body_201) + + def body_201(self): + self.msgq.insert_tail(gr.message(0)) + self.assertEquals(1, self.msgq.count()) + self.msgq.insert_tail(gr.message(1)) + self.assertEquals(2, self.msgq.count()) + + def test_202(self): + self.leak_check(self.body_202) + + def body_202(self): + # global msg + msg = gr.message(666) + + def test_300(self): + input_data = (0,1,2,3,4,5,6,7,8,9) + src = gr.vector_source_b(input_data) + dst = gr.vector_sink_b() + tb = gr.top_block() + tb.connect(src, dst) + tb.run() + self.assertEquals(input_data, dst.data()) + + def test_301(self): + # Use itemsize, limit constructor + src = blocks.message_source(gr.sizeof_char) + dst = gr.vector_sink_b() + tb = gr.top_block() + tb.connect(src, dst) + src.msgq().insert_tail(gr.message_from_string('01234')) + src.msgq().insert_tail(gr.message_from_string('5')) + src.msgq().insert_tail(gr.message_from_string('')) + src.msgq().insert_tail(gr.message_from_string('6789')) + src.msgq().insert_tail(gr.message(1)) # send EOF + tb.run() + self.assertEquals(tuple(map(ord, '0123456789')), dst.data()) + + def test_302(self): + # Use itemsize, msgq constructor + msgq = gr.msg_queue() + src = blocks.message_source(gr.sizeof_char, msgq) + dst = gr.vector_sink_b() + tb = gr.top_block() + tb.connect(src, dst) + src.msgq().insert_tail(gr.message_from_string('01234')) + src.msgq().insert_tail(gr.message_from_string('5')) + src.msgq().insert_tail(gr.message_from_string('')) + src.msgq().insert_tail(gr.message_from_string('6789')) + src.msgq().insert_tail(gr.message(1)) # send EOF + tb.run() + self.assertEquals(tuple(map(ord, '0123456789')), dst.data()) + + def test_debug_401(self): + msg = pmt.pmt_intern("TESTING") + src = blocks.message_strobe(msg, 500) + snk = blocks.message_debug() + + tb = gr.top_block() + tb.msg_connect(src, "strobe", snk, "store") + tb.start() + time.sleep(1) + tb.stop() + tb.wait() + + rec_msg = snk.get_message(0) + self.assertTrue(pmt.pmt_eqv(rec_msg, msg)) + + +if __name__ == '__main__': + gr_unittest.run(test_message, "test_message.xml") diff --git a/gr-blocks/python/qa_moving_average.py b/gr-blocks/python/qa_moving_average.py new file mode 100644 index 0000000000..169b4746c2 --- /dev/null +++ b/gr-blocks/python/qa_moving_average.py @@ -0,0 +1,91 @@ +#!/usr/bin/env python +# +# Copyright 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. +# + +from gnuradio import gr, gr_unittest +import blocks_swig as blocks +import math, random + +def make_random_complex_tuple(L, scale=1): + result = [] + for x in range(L): + result.append(scale*complex(2*random.random()-1, + 2*random.random()-1)) + return tuple(result) + +def make_random_float_tuple(L, scale=1): + result = [] + for x in range(L): + result.append(scale*(2*random.random()-1)) + return tuple(result) + +class test_moving_average(gr_unittest.TestCase): + + def setUp(self): + self.tb = gr.top_block() + + def tearDown(self): + self.tb = None + + def test_01(self): + tb = self.tb + + N = 10000 + seed = 0 + data = make_random_float_tuple(N, 1) + expected_result = N*[0,] + + src = gr.vector_source_f(data, False) + op = blocks.moving_average_ff(100, 0.001) + dst = gr.vector_sink_f() + + tb.connect(src, op) + tb.connect(op, dst) + tb.run() + + dst_data = dst.data() + + # make sure result is close to zero + self.assertFloatTuplesAlmostEqual(expected_result, dst_data, 1) + + def test_02(self): + tb = self.tb + + N = 10000 + seed = 0 + data = make_random_complex_tuple(N, 1) + expected_result = N*[0,] + + src = gr.vector_source_c(data, False) + op = blocks.moving_average_cc(100, 0.001) + dst = gr.vector_sink_c() + + tb.connect(src, op) + tb.connect(op, dst) + tb.run() + + dst_data = dst.data() + + # make sure result is close to zero + self.assertComplexTuplesAlmostEqual(expected_result, dst_data, 1) + +if __name__ == '__main__': + gr_unittest.run(test_moving_average, "test_moving_average.xml") diff --git a/gr-blocks/python/qa_peak_detector.py b/gr-blocks/python/qa_peak_detector.py new file mode 100644 index 0000000000..c3ff2548c4 --- /dev/null +++ b/gr-blocks/python/qa_peak_detector.py @@ -0,0 +1,98 @@ +#!/usr/bin/env python +# +# Copyright 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. +# + +from gnuradio import gr, gr_unittest +import blocks_swig as blocks + +class test_peak_detector(gr_unittest.TestCase): + + def setUp(self): + self.tb = gr.top_block() + + def tearDown(self): + self.tb = None + + def test_01(self): + tb = self.tb + + data = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, + 9, 8, 7, 6, 5, 4, 3, 2, 1, 0] + + expected_result = (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) + + src = gr.vector_source_f(data, False) + regen = blocks.peak_detector_fb() + dst = gr.vector_sink_b() + + tb.connect(src, regen) + tb.connect(regen, dst) + tb.run() + + dst_data = dst.data() + + self.assertEqual(expected_result, dst_data) + + def test_02(self): + tb = self.tb + + data = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, + 9, 8, 7, 6, 5, 4, 3, 2, 1, 0] + + expected_result = (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) + + src = gr.vector_source_i(data, False) + regen = blocks.peak_detector_ib() + dst = gr.vector_sink_b() + + tb.connect(src, regen) + tb.connect(regen, dst) + tb.run() + + dst_data = dst.data() + + self.assertEqual(expected_result, dst_data) + + def test_03(self): + tb = self.tb + + data = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, + 9, 8, 7, 6, 5, 4, 3, 2, 1, 0] + + expected_result = (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) + + src = gr.vector_source_s(data, False) + regen = blocks.peak_detector_sb() + dst = gr.vector_sink_b() + + tb.connect(src, regen) + tb.connect(regen, dst) + tb.run() + + dst_data = dst.data() + + self.assertEqual(expected_result, dst_data) + +if __name__ == '__main__': + gr_unittest.run(test_peak_detector, "test_peak_detector.xml") diff --git a/gr-blocks/python/qa_peak_detector2.py b/gr-blocks/python/qa_peak_detector2.py index 4b864e4d70..b2d8e318dd 100644 --- a/gr-blocks/python/qa_peak_detector2.py +++ b/gr-blocks/python/qa_peak_detector2.py @@ -50,7 +50,6 @@ class test_peak_detector2(gr_unittest.TestCase): tb.run() dst_data = dst.data() - print dst_data self.assertEqual(expected_result, dst_data) diff --git a/gr-blocks/swig/blocks_swig.i b/gr-blocks/swig/blocks_swig.i index cc1e4ef17c..560cd87802 100644 --- a/gr-blocks/swig/blocks_swig.i +++ b/gr-blocks/swig/blocks_swig.i @@ -88,6 +88,15 @@ #include "blocks/max_ff.h" #include "blocks/max_ii.h" #include "blocks/max_ss.h" +#include "blocks/message_debug.h" +#include "blocks/message_sink.h" +#include "blocks/message_source.h" +#include "blocks/message_strobe.h" +#include "blocks/message_burst_source.h" +#include "blocks/moving_average_cc.h" +#include "blocks/moving_average_ff.h" +#include "blocks/moving_average_ii.h" +#include "blocks/moving_average_ss.h" #include "blocks/multiply_ss.h" #include "blocks/multiply_ii.h" #include "blocks/multiply_ff.h" @@ -115,6 +124,9 @@ #include "blocks/packed_to_unpacked_ss.h" #include "blocks/packed_to_unpacked_ii.h" #include "blocks/pdu_to_tagged_stream.h" +#include "blocks/peak_detector_fb.h" +#include "blocks/peak_detector_ib.h" +#include "blocks/peak_detector_sb.h" #include "blocks/peak_detector2_fb.h" #include "blocks/probe_signal_b.h" #include "blocks/probe_signal_s.h" @@ -225,6 +237,15 @@ %include "blocks/max_ff.h" %include "blocks/max_ii.h" %include "blocks/max_ss.h" +%include "blocks/message_debug.h" +%include "blocks/message_sink.h" +%include "blocks/message_source.h" +%include "blocks/message_strobe.h" +%include "blocks/message_burst_source.h" +%include "blocks/moving_average_cc.h" +%include "blocks/moving_average_ff.h" +%include "blocks/moving_average_ii.h" +%include "blocks/moving_average_ss.h" %include "blocks/multiply_ss.h" %include "blocks/multiply_ii.h" %include "blocks/multiply_ff.h" @@ -265,6 +286,9 @@ %include "blocks/packed_to_unpacked_ii.h" %include "blocks/patterned_interleaver.h" %include "blocks/pdu_to_tagged_stream.h" +%include "blocks/peak_detector_fb.h" +%include "blocks/peak_detector_ib.h" +%include "blocks/peak_detector_sb.h" %include "blocks/peak_detector2_fb.h" %include "blocks/random_pdu.h" %include "blocks/regenerate_bb.h" @@ -361,6 +385,15 @@ GR_SWIG_BLOCK_MAGIC2(blocks, keep_one_in_n); GR_SWIG_BLOCK_MAGIC2(blocks, max_ff); GR_SWIG_BLOCK_MAGIC2(blocks, max_ii); GR_SWIG_BLOCK_MAGIC2(blocks, max_ss); +GR_SWIG_BLOCK_MAGIC2(blocks, message_debug); +GR_SWIG_BLOCK_MAGIC2(blocks, message_sink); +GR_SWIG_BLOCK_MAGIC2(blocks, message_source); +GR_SWIG_BLOCK_MAGIC2(blocks, message_strobe); +GR_SWIG_BLOCK_MAGIC2(blocks, message_burst_source); +GR_SWIG_BLOCK_MAGIC2(blocks, moving_average_cc); +GR_SWIG_BLOCK_MAGIC2(blocks, moving_average_ff); +GR_SWIG_BLOCK_MAGIC2(blocks, moving_average_ii); +GR_SWIG_BLOCK_MAGIC2(blocks, moving_average_ss); GR_SWIG_BLOCK_MAGIC2(blocks, multiply_ss); GR_SWIG_BLOCK_MAGIC2(blocks, multiply_ii); GR_SWIG_BLOCK_MAGIC2(blocks, multiply_ff); @@ -387,6 +420,9 @@ GR_SWIG_BLOCK_MAGIC2(blocks, pack_k_bits_bb); GR_SWIG_BLOCK_MAGIC2(blocks, packed_to_unpacked_bb); GR_SWIG_BLOCK_MAGIC2(blocks, packed_to_unpacked_ss); GR_SWIG_BLOCK_MAGIC2(blocks, packed_to_unpacked_ii); +GR_SWIG_BLOCK_MAGIC2(blocks, peak_detector_fb); +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, or_bb); |