commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] [gnuradio] 01/02: blocks: adding blocks.pdu_filter and


From: git
Subject: [Commit-gnuradio] [gnuradio] 01/02: blocks: adding blocks.pdu_filter and blocks.pdu_set
Date: Tue, 6 May 2014 15:07:20 +0000 (UTC)

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

jcorgan pushed a commit to branch master
in repository gnuradio.

commit 58d003bcdd0a4982941ccc700a6158aaa25a02d2
Author: Tim O'Shea <address@hidden>
Date:   Mon May 5 21:46:53 2014 -0400

    blocks: adding blocks.pdu_filter and blocks.pdu_set
---
 gr-blocks/grc/blocks_block_tree.xml              |  1 +
 gr-blocks/grc/blocks_pdu_filter.xml              | 35 ++++++++++++
 gr-blocks/grc/blocks_pdu_set.xml                 | 35 ++++++++++++
 gr-blocks/include/gnuradio/blocks/CMakeLists.txt |  2 +
 gr-blocks/include/gnuradio/blocks/pdu_filter.h   | 52 +++++++++++++++++
 gr-blocks/include/gnuradio/blocks/pdu_set.h      | 52 +++++++++++++++++
 gr-blocks/lib/CMakeLists.txt                     |  2 +
 gr-blocks/lib/pdu_filter_impl.cc                 | 73 ++++++++++++++++++++++++
 gr-blocks/lib/pdu_filter_impl.h                  | 45 +++++++++++++++
 gr-blocks/lib/pdu_set_impl.cc                    | 66 +++++++++++++++++++++
 gr-blocks/lib/pdu_set_impl.h                     | 45 +++++++++++++++
 gr-blocks/swig/blocks_swig4.i                    |  6 ++
 12 files changed, 414 insertions(+)

diff --git a/gr-blocks/grc/blocks_block_tree.xml 
b/gr-blocks/grc/blocks_block_tree.xml
index 22d0e5c..7001d90 100644
--- a/gr-blocks/grc/blocks_block_tree.xml
+++ b/gr-blocks/grc/blocks_block_tree.xml
@@ -121,6 +121,7 @@
                <block>blocks_message_burst_source</block>
                 <block>blocks_message_strobe</block>
                <block>blocks_message_debug</block>
+               <block>blocks_pdu_filter</block>
                <block>blocks_pdu_to_tagged_stream</block>
                <block>blocks_tagged_stream_multiply_length</block>
                <block>blocks_tagged_stream_to_pdu</block>
diff --git a/gr-blocks/grc/blocks_pdu_filter.xml 
b/gr-blocks/grc/blocks_pdu_filter.xml
new file mode 100644
index 0000000..a9565c9
--- /dev/null
+++ b/gr-blocks/grc/blocks_pdu_filter.xml
@@ -0,0 +1,35 @@
+<?xml version="1.0"?>
+<!--
+###################################################
+## PDU Filter
+###################################################
+ -->
+<block>
+       <name>PDU Filter</name>
+       <key>blocks_pdu_filter</key>
+       <import>from gnuradio import blocks</import>
+       <import>import pmt</import>
+       <make>blocks.pdu_filter($k, $v)</make>
+       <param>
+               <name>Key</name>
+               <key>k</key>
+               <value>pmt.intern("key")</value>
+               <type>raw</type>
+       </param>
+       <param>
+               <name>Value</name>
+               <key>v</key>
+               <value>pmt.intern("value")</value>
+               <type>raw</type>
+       </param>
+       <sink>
+               <name>pdus</name>
+               <type>message</type>
+        <optional>1</optional>
+       </sink>
+       <source>
+               <name>pdus</name>
+               <type>message</type>
+        <optional>1</optional>
+       </source>
+</block>
diff --git a/gr-blocks/grc/blocks_pdu_set.xml b/gr-blocks/grc/blocks_pdu_set.xml
new file mode 100644
index 0000000..1e7157f
--- /dev/null
+++ b/gr-blocks/grc/blocks_pdu_set.xml
@@ -0,0 +1,35 @@
+<?xml version="1.0"?>
+<!--
+###################################################
+## PDU Set
+###################################################
+ -->
+<block>
+       <name>PDU Set</name>
+       <key>blocks_pdu_set</key>
+       <import>from gnuradio import blocks</import>
+       <import>import pmt</import>
+       <make>blocks.pdu_set($k, $v)</make>
+       <param>
+               <name>Key</name>
+               <key>k</key>
+               <value>pmt.intern("key")</value>
+               <type>raw</type>
+       </param>
+       <param>
+               <name>Value</name>
+               <key>v</key>
+               <value>pmt.intern("value")</value>
+               <type>raw</type>
+       </param>
+       <sink>
+               <name>pdus</name>
+               <type>message</type>
+        <optional>1</optional>
+       </sink>
+       <source>
+               <name>pdus</name>
+               <type>message</type>
+        <optional>1</optional>
+       </source>
+</block>
diff --git a/gr-blocks/include/gnuradio/blocks/CMakeLists.txt 
b/gr-blocks/include/gnuradio/blocks/CMakeLists.txt
index 7b8a0d6..4b5c04a 100644
--- a/gr-blocks/include/gnuradio/blocks/CMakeLists.txt
+++ b/gr-blocks/include/gnuradio/blocks/CMakeLists.txt
@@ -169,6 +169,8 @@ install(FILES
     pack_k_bits_bb.h
     patterned_interleaver.h
     pdu.h
+    pdu_filter.h
+    pdu_set.h
     pdu_to_tagged_stream.h
     peak_detector2_fb.h
     random_pdu.h
diff --git a/gr-blocks/include/gnuradio/blocks/pdu_filter.h 
b/gr-blocks/include/gnuradio/blocks/pdu_filter.h
new file mode 100644
index 0000000..5d0d2ed
--- /dev/null
+++ b/gr-blocks/include/gnuradio/blocks/pdu_filter.h
@@ -0,0 +1,52 @@
+/* -*- c++ -*- */
+/*
+ * 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.
+ */
+
+#ifndef INCLUDED_BLOCKS_PDU_FILTER_H
+#define INCLUDED_BLOCKS_PDU_FILTER_H
+
+#include <gnuradio/blocks/api.h>
+#include <gnuradio/block.h>
+
+namespace gr {
+  namespace blocks {
+
+    /*!
+     * \brief Propagates only pdus containing k=>v in meta
+     * \ingroup message_tools_blk
+     * \ingroup debug_tools_blk
+     */
+    class BLOCKS_API pdu_filter : virtual public block
+    {
+    public:
+      // gr::blocks::pdu_filter::sptr
+      typedef boost::shared_ptr<pdu_filter> sptr;
+
+      /*!
+       * \brief Construct a PDU filter
+       */
+      static sptr make(pmt::pmt_t k, pmt::pmt_t v);
+    };
+
+  } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* INCLUDED_BLOCKS_PDU_FILTER_H */
diff --git a/gr-blocks/include/gnuradio/blocks/pdu_set.h 
b/gr-blocks/include/gnuradio/blocks/pdu_set.h
new file mode 100644
index 0000000..cfafc44
--- /dev/null
+++ b/gr-blocks/include/gnuradio/blocks/pdu_set.h
@@ -0,0 +1,52 @@
+/* -*- c++ -*- */
+/*
+ * 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.
+ */
+
+#ifndef INCLUDED_BLOCKS_PDU_SET_H
+#define INCLUDED_BLOCKS_PDU_SET_H
+
+#include <gnuradio/blocks/api.h>
+#include <gnuradio/block.h>
+
+namespace gr {
+  namespace blocks {
+
+    /*!
+     * \brief Set k=>v in pdu's meta field and pass on
+     * \ingroup message_tools_blk
+     * \ingroup debug_tools_blk
+     */
+    class BLOCKS_API pdu_set : virtual public block
+    {
+    public:
+      // gr::blocks::pdu_set::sptr
+      typedef boost::shared_ptr<pdu_set> sptr;
+
+      /*!
+       * \brief Construct a PDU meta set block
+       */
+      static sptr make(pmt::pmt_t k, pmt::pmt_t v);
+    };
+
+  } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* INCLUDED_BLOCKS_PDU_SET_H */
diff --git a/gr-blocks/lib/CMakeLists.txt b/gr-blocks/lib/CMakeLists.txt
index 0e7aab5..ae56b17 100644
--- a/gr-blocks/lib/CMakeLists.txt
+++ b/gr-blocks/lib/CMakeLists.txt
@@ -210,6 +210,8 @@ list(APPEND gr_blocks_sources
     patterned_interleaver_impl.cc
     pdu.cc
     tag_debug_impl.cc
+    pdu_filter_impl.cc
+    pdu_set_impl.cc
     pdu_to_tagged_stream_impl.cc
     peak_detector2_fb_impl.cc
     random_pdu_impl.cc
diff --git a/gr-blocks/lib/pdu_filter_impl.cc b/gr-blocks/lib/pdu_filter_impl.cc
new file mode 100644
index 0000000..455c6c8
--- /dev/null
+++ b/gr-blocks/lib/pdu_filter_impl.cc
@@ -0,0 +1,73 @@
+/* -*- c++ -*- */
+/*
+ * 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.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "pdu_filter_impl.h"
+#include <gnuradio/io_signature.h>
+#include <gnuradio/blocks/pdu.h>
+
+namespace gr {
+  namespace blocks {
+
+    pdu_filter::sptr
+    pdu_filter::make(pmt::pmt_t k, pmt::pmt_t v)
+    {
+      return gnuradio::get_initial_sptr(new pdu_filter_impl(k,v));
+    }
+
+    pdu_filter_impl::pdu_filter_impl(pmt::pmt_t k, pmt::pmt_t v)
+      :        block("pdu_filter",
+                io_signature::make (0, 0, 0),
+                io_signature::make (0, 0, 0)),
+    d_k(k), d_v(v)
+    {
+      message_port_register_out(pmt::mp("pdus"));
+      message_port_register_in(pmt::mp("pdus"));
+      set_msg_handler(pmt::mp("pdus"), 
boost::bind(&pdu_filter_impl::handle_msg, this, _1));
+    }
+
+    void 
+    pdu_filter_impl::handle_msg(pmt::pmt_t pdu)
+    {
+      pmt::pmt_t meta = pmt::car(pdu);
+
+      // discard if meta is not a dict
+      if(!pmt::is_dict(meta))
+        return;
+
+      // make sure the dict has the target key
+      if(!dict_has_key(meta, d_k))
+        return;
+
+      // validate the value matches
+      if(!pmt::eqv(pmt::dict_ref(meta,d_k,pmt::PMT_NIL), d_v))
+        return;
+
+      // if all tests pass, propagate the pdu
+      message_port_pub(pmt::mp("pdus"), pdu);
+    }
+      
+  } /* namespace blocks */
+}/* namespace gr */
diff --git a/gr-blocks/lib/pdu_filter_impl.h b/gr-blocks/lib/pdu_filter_impl.h
new file mode 100644
index 0000000..86fa648
--- /dev/null
+++ b/gr-blocks/lib/pdu_filter_impl.h
@@ -0,0 +1,45 @@
+/* -*- c++ -*- */
+/*
+ * 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.
+ */
+
+#ifndef INCLUDED_BLOCKS_PDU_FILTER_IMPL_H
+#define INCLUDED_BLOCKS_PDU_FILTER_IMPL_H
+
+#include <gnuradio/blocks/pdu_filter.h>
+
+namespace gr {
+  namespace blocks {
+
+    class pdu_filter_impl : public pdu_filter
+    {
+    private:
+      pmt::pmt_t d_k;
+      pmt::pmt_t d_v;
+
+    public:
+      pdu_filter_impl(pmt::pmt_t k, pmt::pmt_t v);
+      void handle_msg(pmt::pmt_t msg);
+    };
+
+  } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* INCLUDED_BLOCKS_PDU_FILTER_IMPL_H */
diff --git a/gr-blocks/lib/pdu_set_impl.cc b/gr-blocks/lib/pdu_set_impl.cc
new file mode 100644
index 0000000..e84fe21
--- /dev/null
+++ b/gr-blocks/lib/pdu_set_impl.cc
@@ -0,0 +1,66 @@
+/* -*- c++ -*- */
+/*
+ * 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.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "pdu_set_impl.h"
+#include <gnuradio/io_signature.h>
+#include <gnuradio/blocks/pdu.h>
+
+namespace gr {
+  namespace blocks {
+
+    pdu_set::sptr
+    pdu_set::make(pmt::pmt_t k, pmt::pmt_t v)
+    {
+      return gnuradio::get_initial_sptr(new pdu_set_impl(k,v));
+    }
+
+    pdu_set_impl::pdu_set_impl(pmt::pmt_t k, pmt::pmt_t v)
+      :        block("pdu_set",
+                io_signature::make (0, 0, 0),
+                io_signature::make (0, 0, 0)),
+    d_k(k), d_v(v)
+    {
+      message_port_register_out(pmt::mp("pdus"));
+      message_port_register_in(pmt::mp("pdus"));
+      set_msg_handler(pmt::mp("pdus"), boost::bind(&pdu_set_impl::handle_msg, 
this, _1));
+    }
+
+    void 
+    pdu_set_impl::handle_msg(pmt::pmt_t pdu)
+    {
+      // add the field and publish
+      pmt::pmt_t meta = pmt::car(pdu);
+      if(pmt::is_null(meta)){
+        meta = pmt::make_dict();
+        } else if(!pmt::is_dict(meta)){
+        throw std::runtime_error("pdu_set received non PDU input");
+        }
+      meta = pmt::dict_add(meta, d_k, d_v);
+      message_port_pub(pmt::mp("pdus"), pmt::cons(meta, pmt::cdr(pdu)));
+    }
+      
+  } /* namespace blocks */
+}/* namespace gr */
diff --git a/gr-blocks/lib/pdu_set_impl.h b/gr-blocks/lib/pdu_set_impl.h
new file mode 100644
index 0000000..b27315e
--- /dev/null
+++ b/gr-blocks/lib/pdu_set_impl.h
@@ -0,0 +1,45 @@
+/* -*- c++ -*- */
+/*
+ * 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.
+ */
+
+#ifndef INCLUDED_BLOCKS_PDU_SET_IMPL_H
+#define INCLUDED_BLOCKS_PDU_SET_IMPL_H
+
+#include <gnuradio/blocks/pdu_set.h>
+
+namespace gr {
+  namespace blocks {
+
+    class pdu_set_impl : public pdu_set
+    {
+    private:
+      pmt::pmt_t d_k;
+      pmt::pmt_t d_v;
+
+    public:
+      pdu_set_impl(pmt::pmt_t k, pmt::pmt_t v);
+      void handle_msg(pmt::pmt_t msg);
+    };
+
+  } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* INCLUDED_BLOCKS_PDU_SET_IMPL_H */
diff --git a/gr-blocks/swig/blocks_swig4.i b/gr-blocks/swig/blocks_swig4.i
index 2aa6af5..3648291 100644
--- a/gr-blocks/swig/blocks_swig4.i
+++ b/gr-blocks/swig/blocks_swig4.i
@@ -40,6 +40,8 @@
 #include "gnuradio/blocks/packed_to_unpacked_bb.h"
 #include "gnuradio/blocks/packed_to_unpacked_ss.h"
 #include "gnuradio/blocks/packed_to_unpacked_ii.h"
+#include "gnuradio/blocks/pdu_filter.h"
+#include "gnuradio/blocks/pdu_set.h"
 #include "gnuradio/blocks/pdu_to_tagged_stream.h"
 #include "gnuradio/blocks/peak_detector_fb.h"
 #include "gnuradio/blocks/peak_detector_ib.h"
@@ -84,6 +86,8 @@
 %include "gnuradio/blocks/packed_to_unpacked_ss.h"
 %include "gnuradio/blocks/packed_to_unpacked_ii.h"
 %include "gnuradio/blocks/patterned_interleaver.h"
+%include "gnuradio/blocks/pdu_filter.h"
+%include "gnuradio/blocks/pdu_set.h"
 %include "gnuradio/blocks/pdu_to_tagged_stream.h"
 %include "gnuradio/blocks/peak_detector_fb.h"
 %include "gnuradio/blocks/peak_detector_ib.h"
@@ -106,6 +110,8 @@ 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, plateau_detector_fb);
+GR_SWIG_BLOCK_MAGIC2(blocks, pdu_filter);
+GR_SWIG_BLOCK_MAGIC2(blocks, pdu_set);
 GR_SWIG_BLOCK_MAGIC2(blocks, pdu_to_tagged_stream);
 GR_SWIG_BLOCK_MAGIC2(blocks, probe_rate);
 GR_SWIG_BLOCK_MAGIC2(blocks, or_bb);



reply via email to

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