diff --git a/gr-hamnet70/grc/CMakeLists.txt b/gr-hamnet70/grc/CMakeLists.txt index df31b4d..74a04b7 100644 --- a/gr-hamnet70/grc/CMakeLists.txt +++ b/gr-hamnet70/grc/CMakeLists.txt @@ -21,5 +21,6 @@ install(FILES hamnet70_correct_phase_from_tag.xml hamnet70_correct_frequency.xml hamnet70_freq_est_lr.xml - hamnet70_pid_controller.xml DESTINATION share/gnuradio/grc/blocks + hamnet70_pid_controller.xml + hamnet70_insert_delayed_tag.xml DESTINATION share/gnuradio/grc/blocks ) diff --git a/gr-hamnet70/grc/hamnet70_insert_delayed_tag.xml b/gr-hamnet70/grc/hamnet70_insert_delayed_tag.xml new file mode 100644 index 0000000..e818c1b --- /dev/null +++ b/gr-hamnet70/grc/hamnet70_insert_delayed_tag.xml @@ -0,0 +1,33 @@ + + + Insert Delayed Tag + hamnet70_insert_delayed_tag + [hamnet70] + import hamnet70 + hamnet70.insert_delayed_tag($trigger_tag, $insert_tag, $delay) + + Trigger Tag Name + trigger_tag + string + + + Inserted Tag Name + insert_tag + string + + + Delay + delay + int + + + + in + complex + + + + out + complex + + diff --git a/gr-hamnet70/include/hamnet70/CMakeLists.txt b/gr-hamnet70/include/hamnet70/CMakeLists.txt index ff38db1..1c7e214 100644 --- a/gr-hamnet70/include/hamnet70/CMakeLists.txt +++ b/gr-hamnet70/include/hamnet70/CMakeLists.txt @@ -26,5 +26,6 @@ install(FILES correct_phase_from_tag.h correct_frequency.h freq_est_lr.h - pid_controller.h DESTINATION include/hamnet70 + pid_controller.h + insert_delayed_tag.h DESTINATION include/hamnet70 ) diff --git a/gr-hamnet70/include/hamnet70/insert_delayed_tag.h b/gr-hamnet70/include/hamnet70/insert_delayed_tag.h new file mode 100644 index 0000000..b130829 --- /dev/null +++ b/gr-hamnet70/include/hamnet70/insert_delayed_tag.h @@ -0,0 +1,56 @@ +/* -*- c++ -*- */ +/* + * Copyright 2019 Thomas Kolb. + * + * 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_HAMNET70_INSERT_DELAYED_TAG_H +#define INCLUDED_HAMNET70_INSERT_DELAYED_TAG_H + +#include +#include + +namespace gr { + namespace hamnet70 { + + /*! + * \brief <+description of block+> + * \ingroup hamnet70 + * + */ + class HAMNET70_API insert_delayed_tag : virtual public gr::sync_block + { + public: + typedef boost::shared_ptr sptr; + + /*! + * \brief Return a shared_ptr to a new instance of hamnet70::insert_delayed_tag. + * + * To avoid accidental use of raw pointers, hamnet70::insert_delayed_tag's + * constructor is in a private implementation + * class. hamnet70::insert_delayed_tag::make is the public interface for + * creating new instances. + */ + static sptr make(const std::string &trigger_tag, const std::string &insert_tag, size_t delay); + }; + + } // namespace hamnet70 +} // namespace gr + +#endif /* INCLUDED_HAMNET70_INSERT_DELAYED_TAG_H */ + diff --git a/gr-hamnet70/lib/CMakeLists.txt b/gr-hamnet70/lib/CMakeLists.txt index e558405..39e9829 100644 --- a/gr-hamnet70/lib/CMakeLists.txt +++ b/gr-hamnet70/lib/CMakeLists.txt @@ -30,6 +30,7 @@ list(APPEND hamnet70_sources correct_frequency_impl.cc freq_est_lr_impl.cc pid_controller_impl.cc + insert_delayed_tag_impl.cc ) set(hamnet70_sources "${hamnet70_sources}" PARENT_SCOPE) diff --git a/gr-hamnet70/lib/insert_delayed_tag_impl.cc b/gr-hamnet70/lib/insert_delayed_tag_impl.cc new file mode 100644 index 0000000..1501ef7 --- /dev/null +++ b/gr-hamnet70/lib/insert_delayed_tag_impl.cc @@ -0,0 +1,95 @@ +/* -*- c++ -*- */ +/* + * Copyright 2019 Thomas Kolb. + * + * 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. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include "insert_delayed_tag_impl.h" + +namespace gr { + namespace hamnet70 { + + insert_delayed_tag::sptr + insert_delayed_tag::make(const std::string &trigger_tag, const std::string &insert_tag, size_t delay) + { + return gnuradio::get_initial_sptr + (new insert_delayed_tag_impl(trigger_tag, insert_tag, delay)); + } + + /* + * The private constructor + */ + insert_delayed_tag_impl::insert_delayed_tag_impl(const std::string &trigger_tag, const std::string &insert_tag, size_t delay) + : gr::sync_block("insert_delayed_tag", + gr::io_signature::make(1, 1, sizeof(gr_complex)), + gr::io_signature::make(1, 1, sizeof(gr_complex))), + d_triggerTagName(pmt::intern(trigger_tag)), + d_insertTagName(pmt::intern(insert_tag)), + d_delay(delay), + d_countdownToTag(-1) + {} + + /* + * Our virtual destructor. + */ + insert_delayed_tag_impl::~insert_delayed_tag_impl() + { + } + + int + insert_delayed_tag_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 tags; + get_tags_in_window(tags, 0, 0, noutput_items, pmt::intern("corr_est")); // FIXME: make name variable + size_t tagidx = 0; + + for(size_t i = 0; i < noutput_items; i++) { + if((tagidx < tags.size()) && (tags[tagidx].offset == nitems_read(0) + i)) { + d_countdownToTag = static_cast(d_delay); + tagidx++; + } + + if(d_countdownToTag >= 0) { + d_countdownToTag--; + + if(d_countdownToTag == 0) { + add_item_tag(0, nitems_read(0) + i, d_insertTagName, pmt::PMT_NIL); + } + } + + *out = *in; + out++; + in++; + } + + // Tell runtime system how many output items we produced. + return noutput_items; + } + + } /* namespace hamnet70 */ +} /* namespace gr */ + diff --git a/gr-hamnet70/lib/insert_delayed_tag_impl.h b/gr-hamnet70/lib/insert_delayed_tag_impl.h new file mode 100644 index 0000000..bd17076 --- /dev/null +++ b/gr-hamnet70/lib/insert_delayed_tag_impl.h @@ -0,0 +1,51 @@ +/* -*- c++ -*- */ +/* + * Copyright 2019 Thomas Kolb. + * + * 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_HAMNET70_INSERT_DELAYED_TAG_IMPL_H +#define INCLUDED_HAMNET70_INSERT_DELAYED_TAG_IMPL_H + +#include + +namespace gr { + namespace hamnet70 { + + class insert_delayed_tag_impl : public insert_delayed_tag + { + private: + pmt::pmt_t d_triggerTagName; + pmt::pmt_t d_insertTagName; + size_t d_delay; + int d_countdownToTag; + + public: + insert_delayed_tag_impl(const std::string &trigger_tag, const std::string &insert_tag, size_t delay); + ~insert_delayed_tag_impl(); + + // Where all the action really happens + int work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + }; + + } // namespace hamnet70 +} // namespace gr + +#endif /* INCLUDED_HAMNET70_INSERT_DELAYED_TAG_IMPL_H */ + diff --git a/gr-hamnet70/python/CMakeLists.txt b/gr-hamnet70/python/CMakeLists.txt index 1a9a074..bf7a130 100644 --- a/gr-hamnet70/python/CMakeLists.txt +++ b/gr-hamnet70/python/CMakeLists.txt @@ -46,3 +46,4 @@ set(GR_TEST_PYTHON_DIRS ${CMAKE_BINARY_DIR}/swig) ##GR_ADD_TEST(qa_correct_frequency ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/qa_correct_frequency.py) #GR_ADD_TEST(qa_freq_est_lr ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/qa_freq_est_lr.py) #GR_ADD_TEST(qa_pid_controller ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/qa_pid_controller.py) +#GR_ADD_TEST(qa_insert_delayed_tag ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/qa_insert_delayed_tag.py) diff --git a/gr-hamnet70/python/qa_insert_delayed_tag.py b/gr-hamnet70/python/qa_insert_delayed_tag.py new file mode 100755 index 0000000..eb08b8a --- /dev/null +++ b/gr-hamnet70/python/qa_insert_delayed_tag.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# Copyright 2019 Thomas Kolb. +# +# 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. +# + +from gnuradio import gr, gr_unittest +from gnuradio import blocks +import hamnet70_swig as hamnet70 + +class qa_insert_delayed_tag (gr_unittest.TestCase): + + def setUp (self): + self.tb = gr.top_block () + + def tearDown (self): + self.tb = None + + def test_001_t (self): + # set up fg + self.tb.run () + # check data + + +if __name__ == '__main__': + gr_unittest.run(qa_insert_delayed_tag, "qa_insert_delayed_tag.xml") diff --git a/gr-hamnet70/swig/hamnet70_swig.i b/gr-hamnet70/swig/hamnet70_swig.i index ac1eef6..8929e8b 100644 --- a/gr-hamnet70/swig/hamnet70_swig.i +++ b/gr-hamnet70/swig/hamnet70_swig.i @@ -12,6 +12,7 @@ #include "hamnet70/correct_frequency.h" #include "hamnet70/freq_est_lr.h" #include "hamnet70/pid_controller.h" +#include "hamnet70/insert_delayed_tag.h" %} @@ -24,3 +25,5 @@ GR_SWIG_BLOCK_MAGIC2(hamnet70, correct_frequency); GR_SWIG_BLOCK_MAGIC2(hamnet70, freq_est_lr); %include "hamnet70/pid_controller.h" GR_SWIG_BLOCK_MAGIC2(hamnet70, pid_controller); +%include "hamnet70/insert_delayed_tag.h" +GR_SWIG_BLOCK_MAGIC2(hamnet70, insert_delayed_tag);