GNU Radio 3.7.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 <gnuradio/sync_block.h>
00023 #include <gnuradio/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 {
00031 public:
00032 
00033     tag_sink_demo(void):
00034         sync_block(
00035             "uhd tag sink demo",
00036             gr::io_signature::make(1, 1, sizeof(std::complex<float>)),
00037             gr::io_signature::make(0, 0, 0)
00038         )
00039     {
00040         //NOP
00041     }
00042 
00043     int work(
00044         int ninput_items,
00045         gr_vector_const_void_star &input_items,
00046         gr_vector_void_star &output_items
00047     ){
00048         //grab all "rx time" tags in this work call
00049         const uint64_t samp0_count = this->nitems_read(0);
00050         std::vector<gr::tag_t> rx_time_tags;
00051         get_tags_in_range(rx_time_tags, 0, samp0_count, samp0_count + ninput_items, pmt::string_to_symbol("rx_time"));
00052 
00053         //print all tags
00054         BOOST_FOREACH(const gr::tag_t &rx_time_tag, rx_time_tags){
00055             const uint64_t offset = rx_time_tag.offset;
00056             const pmt::pmt_t &value = rx_time_tag.value;
00057 
00058             std::cout << boost::format("Full seconds %u, Frac seconds %f, abs sample offset %u")
00059                 % pmt::to_uint64(pmt::tuple_ref(value, 0))
00060                 % pmt::to_double(pmt::tuple_ref(value, 1))
00061                 % offset
00062             << std::endl;
00063         }
00064 
00065         return ninput_items;
00066     }
00067 };