GNU Radio 3.7.3 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 <gnuradio/sync_block.h>
23 #include <gnuradio/io_signature.h>
24 #include <boost/foreach.hpp>
25 #include <boost/format.hpp>
26 #include <iostream>
27 #include <complex>
28 
30 {
31 public:
32 
34  sync_block(
35  "uhd tag sink demo",
36  gr::io_signature::make(1, 1, sizeof(std::complex<float>)),
37  gr::io_signature::make(0, 0, 0)
38  )
39  {
40  //NOP
41  }
42 
43  int work(
44  int ninput_items,
45  gr_vector_const_void_star &input_items,
46  gr_vector_void_star &output_items
47  ){
48  //grab all "rx time" tags in this work call
49  const uint64_t samp0_count = this->nitems_read(0);
50  std::vector<gr::tag_t> rx_time_tags;
51  get_tags_in_range(rx_time_tags, 0, samp0_count, samp0_count + ninput_items, pmt::string_to_symbol("rx_time"));
52 
53  //print all tags
54  BOOST_FOREACH(const gr::tag_t &rx_time_tag, rx_time_tags){
55  const uint64_t offset = rx_time_tag.offset;
56  const pmt::pmt_t &value = rx_time_tag.value;
57 
58  std::cout << boost::format("Full seconds %u, Frac seconds %f, abs sample offset %u")
59  % pmt::to_uint64(pmt::tuple_ref(value, 0))
60  % pmt::to_double(pmt::tuple_ref(value, 1))
61  % offset
62  << std::endl;
63  }
64 
65  return ninput_items;
66  }
67 };