commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] [gnuradio] 12/24: blocks: Adds a multiple (complex onl


From: git
Subject: [Commit-gnuradio] [gnuradio] 12/24: blocks: Adds a multiple (complex only) block that responds to tags.
Date: Tue, 14 Jun 2016 00:40:58 +0000 (UTC)

This is an automated email from the git hooks/post-receive script.

jcorgan pushed a commit to branch packet2
in repository gnuradio.

commit 2edaf4050e4feed2cf03f82ecbe8a50dacbd3de7
Author: Tom Rondeau <address@hidden>
Date:   Tue Apr 12 14:22:14 2016 -0400

    blocks: Adds a multiple (complex only) block that responds to tags.
    
    Multiplies input by 1 until a "tag_name" tag key is seen, then updates
    the multiplier factor based on the tag.
---
 gr-blocks/grc/blocks_block_tree.xml                |   1 +
 gr-blocks/grc/blocks_multiply_by_tag_value_cc.xml  |  32 ++++++
 gr-blocks/include/gnuradio/blocks/CMakeLists.txt   |   1 +
 .../gnuradio/blocks/multiply_by_tag_value_cc.h     |  69 +++++++++++
 gr-blocks/lib/CMakeLists.txt                       |   1 +
 gr-blocks/lib/multiply_by_tag_value_cc_impl.cc     | 128 +++++++++++++++++++++
 gr-blocks/lib/multiply_by_tag_value_cc_impl.h      |  56 +++++++++
 gr-blocks/swig/blocks_swig3.i                      |   3 +
 8 files changed, 291 insertions(+)

diff --git a/gr-blocks/grc/blocks_block_tree.xml 
b/gr-blocks/grc/blocks_block_tree.xml
index 4a60160..c4857f3 100644
--- a/gr-blocks/grc/blocks_block_tree.xml
+++ b/gr-blocks/grc/blocks_block_tree.xml
@@ -97,6 +97,7 @@
       <block>blocks_multiply_const_vxx</block>
       <block>blocks_multiply_conjugate_cc</block>
       <block>blocks_multiply_matrix_xx</block>
+      <block>blocks_multiply_by_tag_value_cc</block>
       <block>blocks_sub_xx</block>
       <block>blocks_conjugate_cc</block>
       <block>blocks_integrate_xx</block>
diff --git a/gr-blocks/grc/blocks_multiply_by_tag_value_cc.xml 
b/gr-blocks/grc/blocks_multiply_by_tag_value_cc.xml
new file mode 100644
index 0000000..cedca12
--- /dev/null
+++ b/gr-blocks/grc/blocks_multiply_by_tag_value_cc.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0"?>
+
+<block>
+  <name>Multiply by Tag Value</name>
+  <key>blocks_multiply_by_tag_value_cc</key>
+  <import>from gnuradio import blocks</import>
+  <make>blocks.multiply_by_tag_value_cc($tagname, $vlen)</make>
+
+  <param>
+    <name>Tag Name</name>
+    <key>tagname</key>
+    <type>string</type>
+  </param>
+
+  <param>
+    <name>Vec Length</name>
+    <key>vlen</key>
+    <value>1</value>
+    <type>int</type>
+  </param>
+
+  <sink>
+    <name>in</name>
+    <type>complex</type>
+  </sink>
+
+  <source>
+    <name>out</name>
+    <type>complex</type>
+  </source>
+
+</block>
diff --git a/gr-blocks/include/gnuradio/blocks/CMakeLists.txt 
b/gr-blocks/include/gnuradio/blocks/CMakeLists.txt
index 56f2c48..38c79d6 100644
--- a/gr-blocks/include/gnuradio/blocks/CMakeLists.txt
+++ b/gr-blocks/include/gnuradio/blocks/CMakeLists.txt
@@ -132,6 +132,7 @@ install(FILES
     multiply_const_vcc.h
     multiply_const_ff.h
     multiply_const_vff.h
+    multiply_by_tag_value_cc.h
     nlog10_ff.h
     nop.h
     null_sink.h
diff --git a/gr-blocks/include/gnuradio/blocks/multiply_by_tag_value_cc.h 
b/gr-blocks/include/gnuradio/blocks/multiply_by_tag_value_cc.h
new file mode 100644
index 0000000..f4aba9d
--- /dev/null
+++ b/gr-blocks/include/gnuradio/blocks/multiply_by_tag_value_cc.h
@@ -0,0 +1,69 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2016 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * This 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.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this software; see the file COPYING.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef INCLUDED_MULTIPLY_BY_TAG_VALUE_CC_H
+#define INCLUDED_MULTIPLY_BY_TAG_VALUE_CC_H
+
+#include <gnuradio/blocks/api.h>
+#include <gnuradio/sync_block.h>
+
+namespace gr {
+  namespace blocks {
+
+    /*!
+     * \brief output = input * complex constant
+     * \ingroup math_operators_blk
+     *
+     * \details
+     * The complex constant used by this block is found from a tag
+     * with the name specified by \p tag_name. The tag must contain a
+     * float/double or complex PMT value that will be converted into a
+     * gr_complex value. All input data is multiplied by this
+     * value until a new tag with an update value is found. The block
+     * starts with a value of '1.0' for the multiplier constant.
+     */
+    class BLOCKS_API multiply_by_tag_value_cc : virtual public sync_block
+    {
+    public:
+      // gr::blocks::multiply_by_tag_value_cc::sptr
+      typedef boost::shared_ptr<multiply_by_tag_value_cc> sptr;
+
+      /*!
+       * \brief Create an instance of multiply_by_tag_value_cc
+       * \param tag_name Tag's key that it will use to get the
+       *                 multiplicative constant.
+       * \param vlen Vector length of incoming stream
+       */
+      static sptr make(const std::string& tag_name,
+                       size_t vlen=1);
+
+      /*!
+       * Get the current multiplicative constant.
+       * This block does not allow external setters.
+       */
+      virtual gr_complex k() const = 0;
+    };
+
+  } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* INCLUDED_MULTIPLY_BY_TAG_VALUE_CC_H */
diff --git a/gr-blocks/lib/CMakeLists.txt b/gr-blocks/lib/CMakeLists.txt
index ecac1b4..643190c 100644
--- a/gr-blocks/lib/CMakeLists.txt
+++ b/gr-blocks/lib/CMakeLists.txt
@@ -154,6 +154,7 @@ list(APPEND gr_blocks_sources
     multiply_const_vff_impl.cc
     multiply_matrix_cc_impl.cc
     multiply_matrix_ff_impl.cc
+    multiply_by_tag_value_cc_impl.cc
     nlog10_ff_impl.cc
     nop_impl.cc
     null_sink_impl.cc
diff --git a/gr-blocks/lib/multiply_by_tag_value_cc_impl.cc 
b/gr-blocks/lib/multiply_by_tag_value_cc_impl.cc
new file mode 100644
index 0000000..456d57d
--- /dev/null
+++ b/gr-blocks/lib/multiply_by_tag_value_cc_impl.cc
@@ -0,0 +1,128 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2016 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 <multiply_by_tag_value_cc_impl.h>
+#include <gnuradio/io_signature.h>
+#include <volk/volk.h>
+
+namespace gr {
+  namespace blocks {
+
+    multiply_by_tag_value_cc::sptr
+    multiply_by_tag_value_cc::make(const std::string& tag_name,
+                                   size_t vlen)
+    {
+      return gnuradio::get_initial_sptr
+        (new multiply_by_tag_value_cc_impl(tag_name, vlen));
+    }
+
+    multiply_by_tag_value_cc_impl::multiply_by_tag_value_cc_impl(const 
std::string& tag_name,
+                                                                 size_t vlen)
+      : sync_block("multiply_by_tag_value_cc",
+                   io_signature::make (1, 1, sizeof (gr_complex)*vlen),
+                   io_signature::make (1, 1, sizeof (gr_complex)*vlen)),
+       d_vlen(vlen), d_k(gr_complex(1,0))
+    {
+      d_tag_key = pmt::intern(tag_name);
+
+      const int alignment_multiple =
+       volk_get_alignment() / sizeof(gr_complex);
+      set_alignment(std::max(1,alignment_multiple));
+    }
+
+    multiply_by_tag_value_cc_impl::~multiply_by_tag_value_cc_impl()
+    {
+    }
+
+    gr_complex
+    multiply_by_tag_value_cc_impl::k() const
+    {
+      return d_k;
+    }
+
+    int
+    multiply_by_tag_value_cc_impl::work(int noutput_items,
+                                        gr_vector_const_void_star &input_items,
+                                        gr_vector_void_star &output_items)
+    {
+      const gr_complex *in = (const gr_complex *) input_items[0];
+      gr_complex *out = (gr_complex *) output_items[0];
+
+      std::vector<tag_t> tags;
+      get_tags_in_window(tags, 0, 0, noutput_items, d_tag_key);
+
+      std::vector<tag_t>::iterator itag = tags.begin();
+
+      int start = 0, end;
+      while(itag != tags.end()) {
+        end = itag->offset - nitems_read(0);
+        end *= d_vlen;
+
+        // Multiply based on the current value of k from 'start' to 'end'
+        volk_32fc_s32fc_multiply_32fc(&out[start], &in[start], d_k, 
(end-start));
+        start = end;
+
+        // Extract new value of k
+        pmt::pmt_t k = itag->value;
+        if(pmt::is_complex(k)) {
+          d_k = pmt::to_complex(k);
+        }
+        else if(pmt::is_number(k)) {
+          d_k = gr_complex(pmt::to_double(k), 0);
+        }
+        else {
+          GR_LOG_WARN(d_logger,
+                      boost::format("Got key '%1%' with incompatible value of 
'%2%'") \
+                      % pmt::write_string(d_tag_key) % pmt::write_string(k));
+        }
+
+        itag++;
+      }
+
+      volk_32fc_s32fc_multiply_32fc(&out[start], &in[start], d_k,
+                                    (d_vlen*noutput_items-start));
+
+      return noutput_items;
+    }
+
+    void
+    multiply_by_tag_value_cc_impl::setup_rpc()
+    {
+#ifdef GR_CTRLPORT
+      add_rpc_variable(
+        rpcbasic_sptr(new rpcbasic_register_get<multiply_by_tag_value_cc, 
gr_complex>(
+         alias(), "Constant",
+         &multiply_by_tag_value_cc::k,
+         pmt::from_complex(-1024.0f, 0.0f),
+          pmt::from_complex(1024.0f, 0.0f),
+          pmt::from_complex(0.0f, 0.0f),
+         "", "Constant to multiply", RPC_PRIVLVL_MIN,
+          DISPTIME | DISPOPTCPLX | DISPOPTSTRIP)));
+#endif /* GR_CTRLPORT */
+    }
+
+  } /* namespace blocks */
+} /* namespace gr */
diff --git a/gr-blocks/lib/multiply_by_tag_value_cc_impl.h 
b/gr-blocks/lib/multiply_by_tag_value_cc_impl.h
new file mode 100644
index 0000000..23adcc9
--- /dev/null
+++ b/gr-blocks/lib/multiply_by_tag_value_cc_impl.h
@@ -0,0 +1,56 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2016 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_MULTIPLY_BY_TAG_VALUE_CC_IMPL_H
+#define INCLUDED_MULTIPLY_BY_TAG_VALUE_CC_IMPL_H
+
+#include <gnuradio/blocks/multiply_by_tag_value_cc.h>
+
+namespace gr {
+  namespace blocks {
+
+    class BLOCKS_API multiply_by_tag_value_cc_impl
+      : public multiply_by_tag_value_cc
+    {
+    private:
+      size_t d_vlen;
+      pmt::pmt_t d_tag_key;
+      gr_complex d_k;
+
+    public:
+      multiply_by_tag_value_cc_impl(const std::string& tag_name,
+                                    size_t vlen);
+      ~multiply_by_tag_value_cc_impl();
+
+      gr_complex k() const;
+
+      void setup_rpc();
+
+      int work(int noutput_items,
+              gr_vector_const_void_star &input_items,
+              gr_vector_void_star &output_items);
+    };
+
+  } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* INCLUDED_MULTIPLY_BY_TAG_VALUE_CC_IMPL_H */
diff --git a/gr-blocks/swig/blocks_swig3.i b/gr-blocks/swig/blocks_swig3.i
index 61a959b..629ada5 100644
--- a/gr-blocks/swig/blocks_swig3.i
+++ b/gr-blocks/swig/blocks_swig3.i
@@ -70,6 +70,7 @@
 #include "gnuradio/blocks/multiply_const_vcc.h"
 #include "gnuradio/blocks/multiply_matrix_cc.h"
 #include "gnuradio/blocks/multiply_matrix_ff.h"
+#include "gnuradio/blocks/multiply_by_tag_value_cc.h"
 #include "gnuradio/blocks/mute_ss.h"
 #include "gnuradio/blocks/mute_ii.h"
 #include "gnuradio/blocks/mute_ff.h"
@@ -118,6 +119,7 @@
 %include "gnuradio/blocks/multiply_const_vcc.h"
 %include "gnuradio/blocks/multiply_matrix_cc.h"
 %include "gnuradio/blocks/multiply_matrix_ff.h"
+%include "gnuradio/blocks/multiply_by_tag_value_cc.h"
 %include "gnuradio/blocks/mute_ss.h"
 %include "gnuradio/blocks/mute_ii.h"
 %include "gnuradio/blocks/mute_ff.h"
@@ -165,6 +167,7 @@ GR_SWIG_BLOCK_MAGIC2(blocks, multiply_const_vff);
 GR_SWIG_BLOCK_MAGIC2(blocks, multiply_const_vcc);
 GR_SWIG_BLOCK_MAGIC2(blocks, multiply_matrix_cc);
 GR_SWIG_BLOCK_MAGIC2(blocks, multiply_matrix_ff);
+GR_SWIG_BLOCK_MAGIC2(blocks, multiply_by_tag_value_cc);
 GR_SWIG_BLOCK_MAGIC2(blocks, mute_ss);
 GR_SWIG_BLOCK_MAGIC2(blocks, mute_ii);
 GR_SWIG_BLOCK_MAGIC2(blocks, mute_ff);



reply via email to

[Prev in Thread] Current Thread [Next in Thread]