GNU Radio 3.6.4 C++ API
tag_sink_demo.h
Go to the documentation of this file.
1 /*
2  * Copyright 2011 Free Software Foundation, Inc.
3  *
4  * This file is part of GNU Radio
5  *
6  * GNU Radio is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3, or (at your option)
9  * any later version.
10  *
11  * GNU Radio is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with GNU Radio; see the file COPYING. If not, write to
18  * the Free Software Foundation, Inc., 51 Franklin Street,
19  * Boston, MA 02110-1301, USA.
20  */
21 
22 #include <gr_sync_block.h>
23 #include <gr_io_signature.h>
24 #include <boost/foreach.hpp>
25 #include <boost/format.hpp>
26 #include <iostream>
27 #include <complex>
28 
30 public:
31 
34  "uhd tag sink demo",
35  gr_make_io_signature(1, 1, sizeof(std::complex<float>)),
36  gr_make_io_signature(0, 0, 0)
37  )
38  {
39  //NOP
40  }
41 
42  int work(
43  int ninput_items,
44  gr_vector_const_void_star &input_items,
45  gr_vector_void_star &output_items
46  ){
47  //grab all "rx time" tags in this work call
48  const uint64_t samp0_count = this->nitems_read(0);
49  std::vector<gr_tag_t> rx_time_tags;
50  get_tags_in_range(rx_time_tags, 0, samp0_count, samp0_count + ninput_items, pmt::pmt_string_to_symbol("rx_time"));
51 
52  //print all tags
53  BOOST_FOREACH(const gr_tag_t &rx_time_tag, rx_time_tags){
54  const uint64_t offset = rx_time_tag.offset;
55  const pmt::pmt_t &value = rx_time_tag.value;
56 
57  std::cout << boost::format("Full seconds %u, Frac seconds %f, abs sample offset %u")
60  % offset
61  << std::endl;
62  }
63 
64  return ninput_items;
65  }
66 };