/* -*- c++ -*- */ /* * Copyright 2019 gr-gohm author. * * 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 "rtag_impl.h" namespace gr { namespace gohm { rtag::sptr rtag::make(const std::string &lengthtagname) { return gnuradio::get_initial_sptr (new rtag_impl(lengthtagname)); } /* * The private constructor */ rtag_impl::rtag_impl(const std::string &lengthtagname) : gr::block("rtag", gr::io_signature::make(1, -1, sizeof(gr_complex)), gr::io_signature::make(1, -1, sizeof(gr_complex))), d_lengthtagname(lengthtagname), d_total_offset(0) { set_tag_propagation_policy(TPP_DONT); set_min_noutput_items(1000); expand_minmax_buffer(0); } /* * Our virtual destructor. */ rtag_impl::~rtag_impl() { } void rtag_impl::forecast (int noutput_items, gr_vector_int &ninput_items_required) { //ninput_items_required[0] = 100*noutput_items; //ninput_items_required[1] = 100*noutput_items; } int rtag_impl::general_work (int noutput_items, gr_vector_int &ninput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items) { /*const <+ITYPE+> *in = (const <+ITYPE+> *) input_items[0]; <+OTYPE+> *out = (<+OTYPE+> *) output_items[0]; // Do <+signal processing+> // Tell runtime system how many input items we consumed on // each input stream. */ unsigned char *out = (unsigned char *) output_items[0]; std::cout << boost::format("ninput_items[0]: %d, nitems_read[0]: %d, nitems_written(0): %d, noutput_items: %d") % ninput_items[0] % nitems_read(0) % nitems_written(0) % noutput_items << std::endl; int n_produced[2] = {0}; //std::cout << "----------------------------------------------------------" << std::endl; uint64_t abs_N, end_N; for (unsigned int i = 0; i < input_items.size(); i++) { const unsigned char *in = (const unsigned char *) input_items[i]; //abs_N = nitems_read(i); //end_N = abs_N + (uint64_t)(noutput_items); //std::cout << boost::format("ninput_items[%d]: %d, nitems_read[%d]: %d, nitems_written(0): %d, noutput_items: %d") % i % ninput_items[i] %i % nitems_read(i) % nitems_written(0) % noutput_items << std::endl; //std::cout << boost::format("Input Port %d - Tag %d -> Key: %s, Value: %d, Offset: %d") % i % j % tags[j].key % tags[j].value % tags[j].offset << std::endl; std::vector tags; get_tags_in_range(tags, i, nitems_read(i), nitems_read(i)+ninput_items[i]); for (unsigned int j = 0; j < tags.size(); j++) { if ((ninput_items[i] - n_produced[i]) < pmt::to_long(tags[j].value)){ if (n_produced[i] == 0){ consume (i, 0); } break; } //uint64_t offset = tags[j].offset - nitems_read(i) + nitems_written(0) + total_produced; add_item_tag(0, d_total_offset, tags[j].key, tags[j].value); d_total_offset += pmt::to_long(tags[j].value); n_produced[i] += pmt::to_long(tags[j].value); memcpy((void *) out, (const void *) in, pmt::to_long(tags[j].value) * sizeof(gr_complex)); out += pmt::to_long(tags[j].value) * sizeof(gr_complex); } consume (i, n_produced[i]); } // Tell runtime system how many output items we produced. return n_produced[0]+n_produced[1]; } } /* namespace gohm */ } /* namespace gr */