diff options
author | Tom Rondeau <trondeau@vt.edu> | 2013-03-06 22:00:36 -0500 |
---|---|---|
committer | Tom Rondeau <trondeau@vt.edu> | 2013-03-06 22:00:36 -0500 |
commit | 6e5dfe1a3e2613df24fd1b47f5eb764eaf3dbd9f (patch) | |
tree | 6b6ced438fef13284a9eb0fc870c15367971c777 /gr-blocks/lib | |
parent | 64d8f82c531a477262304bf93b98c2de4eb83d35 (diff) |
blocks: moved burst_tagger to gr-blocks.
Diffstat (limited to 'gr-blocks/lib')
-rw-r--r-- | gr-blocks/lib/CMakeLists.txt | 1 | ||||
-rw-r--r-- | gr-blocks/lib/burst_tagger_impl.cc | 116 | ||||
-rw-r--r-- | gr-blocks/lib/burst_tagger_impl.h | 59 |
3 files changed, 176 insertions, 0 deletions
diff --git a/gr-blocks/lib/CMakeLists.txt b/gr-blocks/lib/CMakeLists.txt index 27b4e233a6..8afc77822f 100644 --- a/gr-blocks/lib/CMakeLists.txt +++ b/gr-blocks/lib/CMakeLists.txt @@ -138,6 +138,7 @@ list(APPEND gr_blocks_sources ${generated_sources} count_bits.cc add_ff_impl.cc + burst_tagger_impl.cc char_to_float_impl.cc char_to_short_impl.cc complex_to_interleaved_short_impl.cc diff --git a/gr-blocks/lib/burst_tagger_impl.cc b/gr-blocks/lib/burst_tagger_impl.cc new file mode 100644 index 0000000000..5d0691bde6 --- /dev/null +++ b/gr-blocks/lib/burst_tagger_impl.cc @@ -0,0 +1,116 @@ +/* -*- c++ -*- */ +/* + * Copyright 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 "burst_tagger_impl.h" +#include <gr_io_signature.h> +#include <string.h> + +namespace gr { + namespace blocks { + + burst_tagger::sptr + burst_tagger::make(size_t itemsize) + { + return gnuradio::get_initial_sptr + (new burst_tagger_impl(itemsize)); + } + + burst_tagger_impl::burst_tagger_impl(size_t itemsize) + : gr_sync_block("burst_tagger", + gr_make_io_signature2(2, 2, itemsize, sizeof(short)), + gr_make_io_signature(1, 1, itemsize)), + d_itemsize(itemsize), d_state(false) + { + std::stringstream str; + str << name() << unique_id(); + + d_true_key = pmt::pmt_string_to_symbol("burst"); + d_true_value = pmt::PMT_T; + + d_false_key = pmt::pmt_string_to_symbol("burst"); + d_false_value = pmt::PMT_F; + + d_id = pmt::pmt_string_to_symbol(str.str()); + } + + burst_tagger_impl::~burst_tagger_impl() + { + } + + void + burst_tagger_impl::set_true_tag(const std::string &key, bool value) + { + d_true_key = pmt::pmt_string_to_symbol(key); + if(value == true) { + d_true_value = pmt::PMT_T; + } + else { + d_true_value = pmt::PMT_F; + } + } + + void + burst_tagger_impl::set_false_tag (const std::string &key, bool value) + { + d_false_key = pmt::pmt_string_to_symbol(key); + if(value == true) { + d_false_value = pmt::PMT_T; + } + else { + d_false_value = pmt::PMT_F; + } + } + + int + burst_tagger_impl::work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) + { + const char *signal = (const char*)input_items[0]; + const short *trigger = (const short*)input_items[1]; + char *out = (char*)output_items[0]; + + memcpy(out, signal, noutput_items * d_itemsize); + + for(int i = 0; i < noutput_items; i++) { + if(trigger[i] > 0) { + if(d_state == false) { + d_state = true; + add_item_tag(0, nitems_written(0)+i, d_true_key, d_true_value, d_id); + } + } + else { + if(d_state == true) { + d_state = false; + add_item_tag(0, nitems_written(0)+i, d_false_key, d_false_value, d_id); + } + } + } + return noutput_items; + } + + } /* namespace blocks */ +} /* namespace gr */ diff --git a/gr-blocks/lib/burst_tagger_impl.h b/gr-blocks/lib/burst_tagger_impl.h new file mode 100644 index 0000000000..80bdec12fb --- /dev/null +++ b/gr-blocks/lib/burst_tagger_impl.h @@ -0,0 +1,59 @@ +/* -*- c++ -*- */ +/* + * Copyright 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. + */ + +#ifndef INCLUDED_GR_BURST_TAGGER_IMPL_H +#define INCLUDED_GR_BURST_TAGGER_IMPL_H + +#include <blocks/burst_tagger.h> + +namespace gr { + namespace blocks { + + class burst_tagger_impl : public burst_tagger + { + private: + size_t d_itemsize; + bool d_state; + pmt::pmt_t d_true_key; + pmt::pmt_t d_true_value; + + pmt::pmt_t d_false_key; + pmt::pmt_t d_false_value; + + pmt::pmt_t d_id; + + public: + burst_tagger_impl(size_t itemsize); + ~burst_tagger_impl(); + + void set_true_tag(const std::string &key, bool value); + void set_false_tag(const std::string &key, bool value); + + 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_BURST_TAGGER_IMPL_H */ |