GNU Radio 3.5.1 C++ API
tag_sink_demo.h
Go to the documentation of this file.
00001 /*
00002  * Copyright 2011 Free Software Foundation, Inc.
00003  * 
00004  * This file is part of GNU Radio
00005  * 
00006  * GNU Radio is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 3, or (at your option)
00009  * any later version.
00010  * 
00011  * GNU Radio is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  * 
00016  * You should have received a copy of the GNU General Public License
00017  * along with GNU Radio; see the file COPYING.  If not, write to
00018  * the Free Software Foundation, Inc., 51 Franklin Street,
00019  * Boston, MA 02110-1301, USA.
00020  */
00021 
00022 #include <gr_sync_block.h>
00023 #include <gr_io_signature.h>
00024 #include <boost/foreach.hpp>
00025 #include <boost/format.hpp>
00026 #include <iostream>
00027 #include <complex>
00028 
00029 class tag_sink_demo : public gr_sync_block{
00030 public:
00031 
00032     tag_sink_demo(void):
00033         gr_sync_block(
00034             "uhd tag sink demo",
00035             gr_make_io_signature(1, 1, sizeof(std::complex<float>)),
00036             gr_make_io_signature(0, 0, 0)
00037         )
00038     {
00039         //NOP
00040     }
00041 
00042     int work(
00043         int ninput_items,
00044         gr_vector_const_void_star &input_items,
00045         gr_vector_void_star &output_items
00046     ){
00047         //grab all "rx time" tags in this work call
00048         const uint64_t samp0_count = this->nitems_read(0);
00049         std::vector<gr_tag_t> rx_time_tags;
00050         get_tags_in_range(rx_time_tags, 0, samp0_count, samp0_count + ninput_items, pmt::pmt_string_to_symbol("rx_time"));
00051 
00052         //print all tags
00053         BOOST_FOREACH(const gr_tag_t &rx_time_tag, rx_time_tags){
00054             const uint64_t offset = rx_time_tag.offset;
00055             const pmt::pmt_t &value = rx_time_tag.value;
00056 
00057             std::cout << boost::format("Full seconds %u, Frac seconds %f, abs sample offset %u")
00058                 % pmt::pmt_to_uint64(pmt_tuple_ref(value, 0))
00059                 % pmt::pmt_to_double(pmt_tuple_ref(value, 1))
00060                 % offset
00061             << std::endl;
00062         }
00063 
00064         return ninput_items;
00065     }
00066 };