diff options
author | Tim O'Shea <tim.oshea753@gmail.com> | 2014-05-05 21:46:53 -0400 |
---|---|---|
committer | Tim O'Shea <tim.oshea753@gmail.com> | 2014-05-05 21:46:53 -0400 |
commit | 58d003bcdd0a4982941ccc700a6158aaa25a02d2 (patch) | |
tree | e07744f51605a57eed4e130fdd5dd69edf60184b | |
parent | 967489ad32b6235b61dd47890c2d6511e593df7b (diff) |
blocks: adding blocks.pdu_filter and blocks.pdu_set
-rw-r--r-- | gr-blocks/grc/blocks_block_tree.xml | 1 | ||||
-rw-r--r-- | gr-blocks/grc/blocks_pdu_filter.xml | 35 | ||||
-rw-r--r-- | gr-blocks/grc/blocks_pdu_set.xml | 35 | ||||
-rw-r--r-- | gr-blocks/include/gnuradio/blocks/CMakeLists.txt | 2 | ||||
-rw-r--r-- | gr-blocks/include/gnuradio/blocks/pdu_filter.h | 52 | ||||
-rw-r--r-- | gr-blocks/include/gnuradio/blocks/pdu_set.h | 52 | ||||
-rw-r--r-- | gr-blocks/lib/CMakeLists.txt | 2 | ||||
-rw-r--r-- | gr-blocks/lib/pdu_filter_impl.cc | 73 | ||||
-rw-r--r-- | gr-blocks/lib/pdu_filter_impl.h | 45 | ||||
-rw-r--r-- | gr-blocks/lib/pdu_set_impl.cc | 66 | ||||
-rw-r--r-- | gr-blocks/lib/pdu_set_impl.h | 45 | ||||
-rw-r--r-- | gr-blocks/swig/blocks_swig4.i | 6 |
12 files changed, 414 insertions, 0 deletions
diff --git a/gr-blocks/grc/blocks_block_tree.xml b/gr-blocks/grc/blocks_block_tree.xml index 22d0e5c7c8..7001d906ac 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 0000000000..a9565c9b9c --- /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 0000000000..1e7157fa8a --- /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 7b8a0d6dc4..4b5c04ac69 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 0000000000..5d0d2ed69a --- /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 0000000000..cfafc44bdd --- /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 0e7aab5e7c..ae56b177cd 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 0000000000..455c6c8ad9 --- /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 0000000000..86fa648f00 --- /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 0000000000..e84fe2125c --- /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 0000000000..b27315ef4d --- /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 2aa6af5408..364829101a 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); |