diff options
author | Tom Rondeau | 2010-11-04 13:19:00 -0400 |
---|---|---|
committer | Tom Rondeau | 2010-11-04 13:19:00 -0400 |
commit | ef9ff4ce4ab97a557f08fa5dad091b0cf63d313f (patch) | |
tree | fe64ec8e9b9d59c56a4ea35f0eeda06185bc8743 /gnuradio-core/src | |
parent | d75b1bb7ae118e191ef31c5691d409b680f723df (diff) | |
download | gnuradio-ef9ff4ce4ab97a557f08fa5dad091b0cf63d313f.tar.gz gnuradio-ef9ff4ce4ab97a557f08fa5dad091b0cf63d313f.tar.bz2 gnuradio-ef9ff4ce4ab97a557f08fa5dad091b0cf63d313f.zip |
Making annotator block build up tags with the noutput_items as the value held. Simply prints info to stdout when tags are retreived.
Diffstat (limited to 'gnuradio-core/src')
-rw-r--r-- | gnuradio-core/src/lib/runtime/gr_random_annotator.cc | 23 | ||||
-rw-r--r-- | gnuradio-core/src/lib/runtime/qa_block_tags.cc | 45 |
2 files changed, 30 insertions, 38 deletions
diff --git a/gnuradio-core/src/lib/runtime/gr_random_annotator.cc b/gnuradio-core/src/lib/runtime/gr_random_annotator.cc index 25e7458e5..bd74f5b84 100644 --- a/gnuradio-core/src/lib/runtime/gr_random_annotator.cc +++ b/gnuradio-core/src/lib/runtime/gr_random_annotator.cc @@ -27,6 +27,7 @@ #include <gr_random_annotator.h> #include <gr_io_signature.h> #include <string.h> +#include <iostream> gr_random_annotator_sptr gr_make_random_annotator (size_t sizeof_stream_item) @@ -54,11 +55,33 @@ gr_random_annotator::work (int noutput_items, const float **in = (const float **) &input_items[0]; float **out = (float **) &output_items[0]; + gr_uint64 abs_N = nitems_written(0); + std::deque<pmt::pmt_t> all_tags = get_tags_in_range(0, (gr_uint64)0, abs_N); + std::deque<pmt::pmt_t>::iterator itr; + std::cout << std::endl << "Found " << all_tags.size() << " tags." << std::endl; + for(itr = all_tags.begin(); itr != all_tags.end(); itr++) { + gr_uint64 nitem = pmt::pmt_to_uint64(pmt::pmt_tuple_ref(*itr, 0)); + std::string srcid = pmt::pmt_symbol_to_string(pmt::pmt_tuple_ref(*itr, 1)); + std::string key = pmt::pmt_symbol_to_string(pmt::pmt_tuple_ref(*itr, 2)); + gr_uint64 value = pmt::pmt_to_uint64(pmt::pmt_tuple_ref(*itr, 3)); + + std::cout << "Tag at " << nitem << " from " << srcid + << " with key = \"" << key << "\" had value = " << value << std::endl; + } + // Work does nothing to the data stream; just copy all inputs to outputs int ninputs = input_items.size(); for (int i = 0; i < ninputs; i++){ memcpy(out[i], in[i], noutput_items * d_itemsize); } + // Storing the current noutput_items as the value to the "noutput_items" key + std::stringstream str; + str << name() << unique_id(); + pmt::pmt_t cur_N = pmt::pmt_from_uint64(noutput_items); + pmt::pmt_t srcid = pmt::pmt_string_to_symbol(str.str()); + pmt::pmt_t key = pmt::pmt_string_to_symbol("noutput_items"); + add_item_tag(0, abs_N, key, cur_N, srcid); + return noutput_items; } diff --git a/gnuradio-core/src/lib/runtime/qa_block_tags.cc b/gnuradio-core/src/lib/runtime/qa_block_tags.cc index 73faa6ca7..7fe1b4bfd 100644 --- a/gnuradio-core/src/lib/runtime/qa_block_tags.cc +++ b/gnuradio-core/src/lib/runtime/qa_block_tags.cc @@ -29,6 +29,7 @@ #include <gr_null_source.h> #include <gr_null_sink.h> #include <gr_head.h> +#include <gr_random_annotator.h> #include <gruel/pmt.h> @@ -68,51 +69,19 @@ qa_block_tags::t1 () { printf("\nqa_block_tags::t1\n"); - int N = 1000; + int N = 40000; gr_top_block_sptr tb = gr_make_top_block("top"); gr_block_sptr src (gr_make_null_source(sizeof(int))); gr_block_sptr head (gr_make_head(sizeof(int), N)); + gr_block_sptr ann0 (gr_make_random_annotator(sizeof(int))); + gr_block_sptr ann1 (gr_make_random_annotator(sizeof(int))); gr_block_sptr snk (gr_make_null_sink(sizeof(int))); tb->connect(src, 0, head, 0); - tb->connect(head, 0, snk, 0); + tb->connect(head, 0, ann0, 0); + tb->connect(ann0, 0, ann1, 0); + tb->connect(ann1, 0, snk, 0); tb->run(); - gr_uint64 W = src->nitems_written(0); - src->add_item_tag(0, N, - pmt::pmt_string_to_symbol("test1"), - pmt::pmt_from_double(1.234)); - - // Make sure we can't get duplicates - src->add_item_tag(0, N, - pmt::pmt_string_to_symbol("test1"), - pmt::pmt_from_double(1.234)); - - // Add new tag at another position - src->add_item_tag(0, W, - pmt::pmt_string_to_symbol("test2"), - pmt::pmt_from_double(2.345)); - - // Test how many tags we get for different ranges - // should be 1, 0, 0, and 2 - std::list<pmt::pmt_t> tags0, tags1, tags2, tags3; - tags0 = src->get_tags_in_range(0, N-10, N+10); - tags1 = src->get_tags_in_range(0, N-10, N- 1); - tags2 = src->get_tags_in_range(0, N+ 1, N+10); - tags3 = src->get_tags_in_range(0, 0, W); - - CPPUNIT_ASSERT(tags0.size() == 1); - CPPUNIT_ASSERT(tags1.size() == 0); - CPPUNIT_ASSERT(tags2.size() == 0); - CPPUNIT_ASSERT(tags3.size() == 2); - - // Check types and values are good - pmt::pmt_t tuple = tags0.front(); - pmt::pmt_t key = pmt::pmt_tuple_ref(tuple, 2); - double value = pmt::pmt_to_double(pmt::pmt_tuple_ref(tuple, 3)); - - CPPUNIT_ASSERT(pmt::pmt_is_tuple(tuple)); - CPPUNIT_ASSERT(pmt::pmt_eqv(key, pmt::pmt_string_to_symbol("test1"))); - CPPUNIT_ASSERT_EQUAL(value, 1.234); } |