GNU Radio Manual and C++ API Reference  3.7.4.1
The Free & Open Software Radio Ecosystem
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 };
PMT_API pmt_t tuple_ref(const pmt_t &tuple, size_t k)
pmt::pmt_t value
the value of tag (as a PMT)
Definition: tags.h:40
Definition: tags.h:31
uint64_t offset
the item tag occurred at (as a uint64_t)
Definition: tags.h:34
std::vector< const void * > gr_vector_const_void_star
Definition: gnuradio-runtime/include/gnuradio/types.h:38
tag_sink_demo(void)
Definition: tag_sink_demo.h:33
uint64_t nitems_read(unsigned int which_input)
Return the number of items read on input stream which_input.
PMT_API pmt_t string_to_symbol(const std::string &s)
Return the symbol whose name is s.
std::vector< void * > gr_vector_void_star
Definition: gnuradio-runtime/include/gnuradio/types.h:37
PMT_API uint64_t to_uint64(pmt_t x)
Convert pmt to uint64 if possible.
unsigned __int64 uint64_t
Definition: stdint.h:90
synchronous 1:1 input to output with historyOverride work to provide the signal processing implementa...
Definition: sync_block.h:37
Definition: tag_sink_demo.h:29
PMT_API double to_double(pmt_t x)
Convert pmt to double if possible.
sync_block(void)
Definition: sync_block.h:40
void get_tags_in_range(std::vector< tag_t > &v, unsigned int which_input, uint64_t abs_start, uint64_t abs_end)
Given a [start,end), returns a vector of all tags in the range.
boost::intrusive_ptr< pmt_base > pmt_t
typedef for shared pointer (transparent reference counting). See http://www.boost.org/libs/smart_ptr/smart_ptr.htm
Definition: pmt.h:56
int work(int ninput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items)
just like gr::block::general_work, only this arranges to call consume_each for you ...
Definition: tag_sink_demo.h:43