From 2c544567f5f9322b51b26a32bdb6280ee12f16de Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Tue, 19 Oct 2010 16:33:40 -0400 Subject: Adding vectors to gr_block_detail that keep track of the number of samples read and written from each block's input. Accessor functions allow query of values through gr_block. Had to add gr_uint64 typedef to SWIG for it to understand how to handle the type. --- gnuradio-core/src/lib/runtime/gr_block.cc | 10 ++++++++++ gnuradio-core/src/lib/runtime/gr_block.h | 6 ++++++ gnuradio-core/src/lib/runtime/gr_block.i | 3 +++ gnuradio-core/src/lib/runtime/gr_block_detail.cc | 23 ++++++++++++++++++----- gnuradio-core/src/lib/runtime/gr_block_detail.h | 16 ++++++++++++++++ gnuradio-core/src/lib/swig/gnuradio.i | 1 + 6 files changed, 54 insertions(+), 5 deletions(-) (limited to 'gnuradio-core/src') diff --git a/gnuradio-core/src/lib/runtime/gr_block.cc b/gnuradio-core/src/lib/runtime/gr_block.cc index 8915f3360..83cc58738 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_block.cc @@ -117,6 +117,16 @@ gr_block::fixed_rate_noutput_to_ninput(int noutput) throw std::runtime_error("Unimplemented"); } +gr_uint64 +gr_block::n_items_read(unsigned int which_input) { + return d_detail->n_items_read(which_input); +} + +gr_uint64 +gr_block::n_items_written(unsigned int which_output) { + return d_detail->n_items_written(which_output); +} + std::ostream& operator << (std::ostream& os, const gr_block *m) { diff --git a/gnuradio-core/src/lib/runtime/gr_block.h b/gnuradio-core/src/lib/runtime/gr_block.h index b6f724dde..22e60da57 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.h +++ b/gnuradio-core/src/lib/runtime/gr_block.h @@ -198,6 +198,12 @@ class gr_block : public gr_basic_block { */ virtual int fixed_rate_noutput_to_ninput(int noutput); + // Return the number of items read on input stream which_input + gr_uint64 n_items_read(unsigned int which_input); + + // Return the number of items written on output stream which_output + gr_uint64 n_items_written(unsigned int which_output); + // ---------------------------------------------------------------------------- private: diff --git a/gnuradio-core/src/lib/runtime/gr_block.i b/gnuradio-core/src/lib/runtime/gr_block.i index c2e2aa4b8..d70a5854a 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.i +++ b/gnuradio-core/src/lib/runtime/gr_block.i @@ -49,6 +49,9 @@ class gr_block : public gr_basic_block { bool start(); bool stop(); + gr_uint64 n_items_read(unsigned int which_input); + gr_uint64 n_items_written(unsigned int which_output); + // internal use gr_block_detail_sptr detail () const { return d_detail; } void set_detail (gr_block_detail_sptr detail) { d_detail = detail; } diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.cc b/gnuradio-core/src/lib/runtime/gr_block_detail.cc index 38d4a13ca..1f80fe2d4 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.cc @@ -39,6 +39,7 @@ gr_block_detail::gr_block_detail (unsigned int ninputs, unsigned int noutputs) : d_produce_or(0), d_ninputs (ninputs), d_noutputs (noutputs), d_input (ninputs), d_output (noutputs), + d_n_items_read(ninputs, 0), d_n_items_written(noutputs, 0), d_done (false) { s_ncurrently_allocated++; @@ -88,16 +89,25 @@ gr_block_detail::set_done (bool done) void gr_block_detail::consume (int which_input, int how_many_items) { - if (how_many_items > 0) + if (how_many_items > 0) { input (which_input)->update_read_pointer (how_many_items); + + // Carefull here; we check that which_input exists above + // is this good enough protection that we don't get here? + d_n_items_read[which_input] += how_many_items; + } } + void gr_block_detail::consume_each (int how_many_items) { - if (how_many_items > 0) - for (int i = 0; i < ninputs (); i++) + if (how_many_items > 0) { + for (int i = 0; i < ninputs (); i++) { d_input[i]->update_read_pointer (how_many_items); + d_n_items_read[i] += how_many_items; + } + } } void @@ -105,6 +115,7 @@ gr_block_detail::produce (int which_output, int how_many_items) { if (how_many_items > 0){ d_output[which_output]->update_write_pointer (how_many_items); + d_n_items_written[which_output] += how_many_items; d_produce_or |= how_many_items; } } @@ -112,9 +123,11 @@ gr_block_detail::produce (int which_output, int how_many_items) void gr_block_detail::produce_each (int how_many_items) { - if (how_many_items > 0){ - for (int i = 0; i < noutputs (); i++) + if (how_many_items > 0) { + for (int i = 0; i < noutputs (); i++) { d_output[i]->update_write_pointer (how_many_items); + d_n_items_written[i] += how_many_items; + } d_produce_or |= how_many_items; } } diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.h b/gnuradio-core/src/lib/runtime/gr_block_detail.h index c5787a5ad..e830ddd47 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.h +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.h @@ -88,6 +88,20 @@ class gr_block_detail { */ void _post(pmt::pmt_t msg); + // Return the number of items read on input stream which_input + gr_uint64 n_items_read(unsigned int which_input) { + if(which_input >= d_ninputs) + throw std::invalid_argument ("gr_block_detail::n_input_items"); + return d_n_items_read[which_input]; + } + + // Return the number of items written on output stream which_output + gr_uint64 n_items_written(unsigned int which_output) { + if(which_output >= d_noutputs) + throw std::invalid_argument ("gr_block_detail::n_output_items"); + return d_n_items_written[which_output]; + } + gr_tpb_detail d_tpb; // used by thread-per-block scheduler int d_produce_or; @@ -98,6 +112,8 @@ class gr_block_detail { unsigned int d_noutputs; std::vector d_input; std::vector d_output; + std::vector d_n_items_read; + std::vector d_n_items_written; bool d_done; diff --git a/gnuradio-core/src/lib/swig/gnuradio.i b/gnuradio-core/src/lib/swig/gnuradio.i index 7d0241f1c..60cbf0d58 100644 --- a/gnuradio-core/src/lib/swig/gnuradio.i +++ b/gnuradio-core/src/lib/swig/gnuradio.i @@ -46,6 +46,7 @@ typedef std::complex gr_complex; typedef std::complex gr_complexd; +typedef unsigned long long gr_uint64; // instantiate the required template specializations -- cgit From b22efee47c7d891a8c10b1493f20976534fdb751 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Tue, 26 Oct 2010 19:59:42 -0400 Subject: Giving gr_block_detail a list of pmt tuples to hold item tagging information. Adds ability to add new tags from a block. --- gnuradio-core/src/lib/runtime/gr_block.cc | 8 ++++++++ gnuradio-core/src/lib/runtime/gr_block.h | 5 +++++ gnuradio-core/src/lib/runtime/gr_block_detail.cc | 18 ++++++++++++++++++ gnuradio-core/src/lib/runtime/gr_block_detail.h | 7 +++++++ 4 files changed, 38 insertions(+) (limited to 'gnuradio-core/src') diff --git a/gnuradio-core/src/lib/runtime/gr_block.cc b/gnuradio-core/src/lib/runtime/gr_block.cc index 83cc58738..ed848e3ed 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_block.cc @@ -127,6 +127,14 @@ gr_block::n_items_written(unsigned int which_output) { return d_detail->n_items_written(which_output); } +void +gr_block::add_item_tag(unsigned int which_output, + uint64_t offset, + const pmt::pmt_t &key, const pmt::pmt_t &value) +{ + d_detail->add_item_tag(which_output, offset, key, value); +} + std::ostream& operator << (std::ostream& os, const gr_block *m) { diff --git a/gnuradio-core/src/lib/runtime/gr_block.h b/gnuradio-core/src/lib/runtime/gr_block.h index 22e60da57..c4d639314 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.h +++ b/gnuradio-core/src/lib/runtime/gr_block.h @@ -204,6 +204,11 @@ class gr_block : public gr_basic_block { // Return the number of items written on output stream which_output gr_uint64 n_items_written(unsigned int which_output); + void add_item_tag(unsigned int which_output, + uint64_t offset, + const pmt::pmt_t &key, const pmt::pmt_t &value); + + // ---------------------------------------------------------------------------- private: diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.cc b/gnuradio-core/src/lib/runtime/gr_block_detail.cc index 1f80fe2d4..656cdb13a 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.cc @@ -138,3 +138,21 @@ gr_block_detail::_post(pmt::pmt_t msg) { d_tpb.insert_tail(msg); } + +void +gr_block_detail::add_item_tag(unsigned int which_output, + uint64_t offset, + const pmt::pmt_t &key, const pmt::pmt_t &value) +{ + if(pmt::pmt_is_symbol(key) == false) { + throw pmt::pmt_wrong_type("gr_block_detail::set_item_tag key", key); + } + else { + pmt::pmt_t nitem = pmt::pmt_from_uint64(offset); + pmt::pmt_t stream = pmt::pmt_string_to_symbol("NULL"); + pmt::pmt_t tuple = pmt::pmt_make_tuple(nitem, stream, key, value); + d_item_tags.push_back(tuple); + + // need to add prunning routing + } +} diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.h b/gnuradio-core/src/lib/runtime/gr_block_detail.h index e830ddd47..6a8d94c72 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.h +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.h @@ -101,6 +101,12 @@ class gr_block_detail { throw std::invalid_argument ("gr_block_detail::n_output_items"); return d_n_items_written[which_output]; } + + // Add an item tag tuple to list of tags + // -> is this just based on output stream? how to handle this... + void add_item_tag(unsigned int which_output, + uint64_t offset, + const pmt::pmt_t &key, const pmt::pmt_t &value); gr_tpb_detail d_tpb; // used by thread-per-block scheduler int d_produce_or; @@ -114,6 +120,7 @@ class gr_block_detail { std::vector d_output; std::vector d_n_items_read; std::vector d_n_items_written; + std::list d_item_tags; bool d_done; -- cgit From d07a944f0c327b255285a8fef4604b65fa8fd7c8 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Tue, 26 Oct 2010 21:01:22 -0400 Subject: First stab at adding get functions for item tags in a given range. --- gnuradio-core/src/lib/runtime/gr_block.cc | 17 ++++++++++- gnuradio-core/src/lib/runtime/gr_block.h | 9 +++++- gnuradio-core/src/lib/runtime/gr_block_detail.cc | 38 +++++++++++++++++++++++- gnuradio-core/src/lib/runtime/gr_block_detail.h | 9 +++++- 4 files changed, 69 insertions(+), 4 deletions(-) (limited to 'gnuradio-core/src') diff --git a/gnuradio-core/src/lib/runtime/gr_block.cc b/gnuradio-core/src/lib/runtime/gr_block.cc index ed848e3ed..a2b495867 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_block.cc @@ -129,12 +129,27 @@ gr_block::n_items_written(unsigned int which_output) { void gr_block::add_item_tag(unsigned int which_output, - uint64_t offset, + gr_uint64 offset, const pmt::pmt_t &key, const pmt::pmt_t &value) { d_detail->add_item_tag(which_output, offset, key, value); } +std::list +gr_block::get_tags_in_range(unsigned int which_output, + gr_uint64 start, gr_uint64 end) +{ + return d_detail->get_tags_in_range(which_output, start, end); +} + +std::list +gr_block::get_tags_in_range(unsigned int which_output, + gr_uint64 start, gr_uint64 end, + const pmt::pmt_t &key) +{ + return d_detail->get_tags_in_range(which_output, start, end, key); +} + std::ostream& operator << (std::ostream& os, const gr_block *m) { diff --git a/gnuradio-core/src/lib/runtime/gr_block.h b/gnuradio-core/src/lib/runtime/gr_block.h index c4d639314..888ca811a 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.h +++ b/gnuradio-core/src/lib/runtime/gr_block.h @@ -24,6 +24,7 @@ #define INCLUDED_GR_BLOCK_H #include +#include /*! * \brief The abstract base class for all 'terminal' processing blocks. @@ -205,9 +206,15 @@ class gr_block : public gr_basic_block { gr_uint64 n_items_written(unsigned int which_output); void add_item_tag(unsigned int which_output, - uint64_t offset, + gr_uint64 offset, const pmt::pmt_t &key, const pmt::pmt_t &value); + std::list get_tags_in_range(unsigned int which_output, + gr_uint64 start, gr_uint64 end); + + std::list get_tags_in_range(unsigned int which_output, + gr_uint64 start, gr_uint64 end, + const pmt::pmt_t &key); // ---------------------------------------------------------------------------- diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.cc b/gnuradio-core/src/lib/runtime/gr_block_detail.cc index 656cdb13a..dbe49f37c 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.cc @@ -141,7 +141,7 @@ gr_block_detail::_post(pmt::pmt_t msg) void gr_block_detail::add_item_tag(unsigned int which_output, - uint64_t offset, + gr_uint64 offset, const pmt::pmt_t &key, const pmt::pmt_t &value) { if(pmt::pmt_is_symbol(key) == false) { @@ -156,3 +156,39 @@ gr_block_detail::add_item_tag(unsigned int which_output, // need to add prunning routing } } + +std::list +gr_block_detail::get_tags_in_range(unsigned int which_output, + gr_uint64 start, gr_uint64 end) +{ + std::list found_items; + std::list::iterator itr = d_item_tags.begin(); + + gr_uint64 item_time = pmt::pmt_to_uint64(pmt::pmt_tuple_ref(*itr, 0)); + while(itr != d_item_tags.end()) { + if((item_time < start) && (item_time < end)) { + found_items.push_back(*itr); + } + + itr++; + item_time = pmt::pmt_to_uint64(pmt::pmt_tuple_ref(*itr, 0)); + + // items are pushed onto list in sequential order; stop if we're past end + if(item_time > end) { + break; + } + } + + return found_items; +} + +std::list +gr_block_detail::get_tags_in_range(unsigned int which_output, + gr_uint64 start, gr_uint64 end, + const pmt::pmt_t &key) +{ + std::list found_items; + std::list::iterator itr = d_item_tags.begin(); + + return found_items; +} diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.h b/gnuradio-core/src/lib/runtime/gr_block_detail.h index 6a8d94c72..cb590cec9 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.h +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.h @@ -105,9 +105,16 @@ class gr_block_detail { // Add an item tag tuple to list of tags // -> is this just based on output stream? how to handle this... void add_item_tag(unsigned int which_output, - uint64_t offset, + gr_uint64 offset, const pmt::pmt_t &key, const pmt::pmt_t &value); + std::list get_tags_in_range(unsigned int which_output, + gr_uint64 start, gr_uint64 end); + + std::list get_tags_in_range(unsigned int which_output, + gr_uint64 start, gr_uint64 end, + const pmt::pmt_t &key); + gr_tpb_detail d_tpb; // used by thread-per-block scheduler int d_produce_or; -- cgit From e3b866883186ed2fbf125964a7ca3a3a3022675c Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sun, 31 Oct 2010 17:02:10 -0400 Subject: Fix to get_tags_in_range. Returns proper list and handles times when list is empty. --- gnuradio-core/src/lib/runtime/gr_block.cc | 6 ++++-- gnuradio-core/src/lib/runtime/gr_block_detail.cc | 13 +++++++------ 2 files changed, 11 insertions(+), 8 deletions(-) (limited to 'gnuradio-core/src') diff --git a/gnuradio-core/src/lib/runtime/gr_block.cc b/gnuradio-core/src/lib/runtime/gr_block.cc index a2b495867..f3e0ecc91 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_block.cc @@ -118,12 +118,14 @@ gr_block::fixed_rate_noutput_to_ninput(int noutput) } gr_uint64 -gr_block::n_items_read(unsigned int which_input) { +gr_block::n_items_read(unsigned int which_input) +{ return d_detail->n_items_read(which_input); } gr_uint64 -gr_block::n_items_written(unsigned int which_output) { +gr_block::n_items_written(unsigned int which_output) +{ return d_detail->n_items_written(which_output); } diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.cc b/gnuradio-core/src/lib/runtime/gr_block_detail.cc index dbe49f37c..6a920f7c0 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.cc @@ -164,19 +164,20 @@ gr_block_detail::get_tags_in_range(unsigned int which_output, std::list found_items; std::list::iterator itr = d_item_tags.begin(); - gr_uint64 item_time = pmt::pmt_to_uint64(pmt::pmt_tuple_ref(*itr, 0)); + gr_uint64 item_time; while(itr != d_item_tags.end()) { - if((item_time < start) && (item_time < end)) { - found_items.push_back(*itr); - } - - itr++; item_time = pmt::pmt_to_uint64(pmt::pmt_tuple_ref(*itr, 0)); // items are pushed onto list in sequential order; stop if we're past end if(item_time > end) { break; } + + if((item_time > start) && (item_time < end)) { + found_items.push_back(*itr); + } + + itr++; } return found_items; -- cgit From e6dedf7fb1075e22e8ea46c9c8d456ba92f92df1 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sun, 31 Oct 2010 17:11:34 -0400 Subject: Adds functional ability to call get_tags_in_range with a specified key. --- gnuradio-core/src/lib/runtime/gr_block_detail.cc | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'gnuradio-core/src') diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.cc b/gnuradio-core/src/lib/runtime/gr_block_detail.cc index 6a920f7c0..18f3601fc 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.cc @@ -191,5 +191,23 @@ gr_block_detail::get_tags_in_range(unsigned int which_output, std::list found_items; std::list::iterator itr = d_item_tags.begin(); + gr_uint64 item_time; + pmt::pmt_t itemkey; + while(itr != d_item_tags.end()) { + item_time = pmt::pmt_to_uint64(pmt::pmt_tuple_ref(*itr, 0)); + + // items are pushed onto list in sequential order; stop if we're past end + if(item_time > end) { + break; + } + + itemkey = pmt::pmt_tuple_ref(*itr, 2); + if((item_time > start) && (item_time < end) && (key == itemkey)) { + found_items.push_back(*itr); + } + + itr++; + } + return found_items; } -- cgit From 246c0b96f22b3eb945fb1cef1aafd32bbb7cd815 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sun, 31 Oct 2010 17:13:36 -0400 Subject: get_tags_in_range now gets items between start and end INCLUSIVELY. --- gnuradio-core/src/lib/runtime/gr_block_detail.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'gnuradio-core/src') diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.cc b/gnuradio-core/src/lib/runtime/gr_block_detail.cc index 18f3601fc..69f65f0d0 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.cc @@ -173,7 +173,7 @@ gr_block_detail::get_tags_in_range(unsigned int which_output, break; } - if((item_time > start) && (item_time < end)) { + if((item_time >= start) && (item_time <= end)) { found_items.push_back(*itr); } @@ -202,7 +202,7 @@ gr_block_detail::get_tags_in_range(unsigned int which_output, } itemkey = pmt::pmt_tuple_ref(*itr, 2); - if((item_time > start) && (item_time < end) && (key == itemkey)) { + if((item_time >= start) && (item_time <= end) && (key == itemkey)) { found_items.push_back(*itr); } -- cgit From 13f00f0ad96ee54a98751f9dceca005078850c93 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sun, 31 Oct 2010 18:06:39 -0400 Subject: Checks for duplicate entry when adding a new tag. add_item_tag looks at the last tag entered with the given key and tests if the value is the same. If it is the same value, then don't do add a new item. If the value is different, add a new tag of that key to the list. --- gnuradio-core/src/lib/runtime/gr_block_detail.cc | 32 +++++++++++++++++++----- 1 file changed, 26 insertions(+), 6 deletions(-) (limited to 'gnuradio-core/src') diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.cc b/gnuradio-core/src/lib/runtime/gr_block_detail.cc index 69f65f0d0..1007f13ef 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.cc @@ -142,18 +142,38 @@ gr_block_detail::_post(pmt::pmt_t msg) void gr_block_detail::add_item_tag(unsigned int which_output, gr_uint64 offset, - const pmt::pmt_t &key, const pmt::pmt_t &value) + const pmt::pmt_t &key, + const pmt::pmt_t &value) { if(pmt::pmt_is_symbol(key) == false) { throw pmt::pmt_wrong_type("gr_block_detail::set_item_tag key", key); } else { - pmt::pmt_t nitem = pmt::pmt_from_uint64(offset); - pmt::pmt_t stream = pmt::pmt_string_to_symbol("NULL"); - pmt::pmt_t tuple = pmt::pmt_make_tuple(nitem, stream, key, value); - d_item_tags.push_back(tuple); + bool duplicate = false; + + // Search through list of tags to see if new tag is a duplicate + std::list::reverse_iterator itr = d_item_tags.rbegin(); + while(itr != d_item_tags.rend()) { + // find the last item with this key if there is one + if(pmt::pmt_eqv(pmt::pmt_tuple_ref(*itr, 2), key)) { + // check if this value is the same as last; its a duplicate if yes + if(pmt::pmt_eqv(pmt::pmt_tuple_ref(*itr, 3), value)) { + duplicate = true; + } + break; // only looking for the last item of this key + } + itr++; + } + + // It not a duplicate, add new tag to the list + if(!duplicate) { + pmt::pmt_t nitem = pmt::pmt_from_uint64(offset); + pmt::pmt_t stream = pmt::pmt_string_to_symbol("NULL"); + pmt::pmt_t tuple = pmt::pmt_make_tuple(nitem, stream, key, value); + d_item_tags.push_back(tuple); + } - // need to add prunning routing + // need to add prunning routine } } -- cgit From 0bc7116e5227f95b7a5de944bc65c5a8b55e0ed5 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sun, 31 Oct 2010 18:09:19 -0400 Subject: Using pmt_eqv for key testing instead of == to make sure typing is worked out properly. --- gnuradio-core/src/lib/runtime/gr_block_detail.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gnuradio-core/src') diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.cc b/gnuradio-core/src/lib/runtime/gr_block_detail.cc index 1007f13ef..effaf5269 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.cc @@ -222,7 +222,7 @@ gr_block_detail::get_tags_in_range(unsigned int which_output, } itemkey = pmt::pmt_tuple_ref(*itr, 2); - if((item_time >= start) && (item_time <= end) && (key == itemkey)) { + if((item_time >= start) && (item_time <= end) && pmt::pmt_eqv(key, itemkey)) { found_items.push_back(*itr); } -- cgit From 428ccb2218464a33923b3e576ad42af21468c82d Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Tue, 2 Nov 2010 15:59:51 -0400 Subject: Adding some protection to the nitems read/written accessors. Should this return 0 or throw? --- gnuradio-core/src/lib/runtime/gr_block.cc | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'gnuradio-core/src') diff --git a/gnuradio-core/src/lib/runtime/gr_block.cc b/gnuradio-core/src/lib/runtime/gr_block.cc index f3e0ecc91..e0a223135 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_block.cc @@ -120,13 +120,25 @@ gr_block::fixed_rate_noutput_to_ninput(int noutput) gr_uint64 gr_block::n_items_read(unsigned int which_input) { - return d_detail->n_items_read(which_input); + if(d_detail) { + return d_detail->n_items_read(which_input); + } + else { + //throw std::runtime_error("No block_detail associated with block yet"); + return 0; + } } gr_uint64 gr_block::n_items_written(unsigned int which_output) { - return d_detail->n_items_written(which_output); + if(d_detail) { + return d_detail->n_items_written(which_output); + } + else { + //throw std::runtime_error("No block_detail associated with block yet"); + return 0; + } } void -- cgit From 1c7119f52792da359fc5638a589b8cc8fa959864 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Tue, 2 Nov 2010 16:00:51 -0400 Subject: Adding QA code to perform some tests on tags. Setting and getting items read/written; testing adding and retrieving tags. --- gnuradio-core/src/lib/runtime/Makefile.am | 2 + gnuradio-core/src/lib/runtime/qa_block_tags.cc | 118 +++++++++++++++++++++++++ gnuradio-core/src/lib/runtime/qa_block_tags.h | 44 +++++++++ gnuradio-core/src/lib/runtime/qa_runtime.cc | 2 + 4 files changed, 166 insertions(+) create mode 100644 gnuradio-core/src/lib/runtime/qa_block_tags.cc create mode 100644 gnuradio-core/src/lib/runtime/qa_block_tags.h (limited to 'gnuradio-core/src') diff --git a/gnuradio-core/src/lib/runtime/Makefile.am b/gnuradio-core/src/lib/runtime/Makefile.am index abd789a1d..4c52f3ab0 100644 --- a/gnuradio-core/src/lib/runtime/Makefile.am +++ b/gnuradio-core/src/lib/runtime/Makefile.am @@ -79,6 +79,7 @@ libruntime_qa_la_SOURCES = \ qa_gr_top_block.cc \ qa_gr_io_signature.cc \ qa_gr_vmcircbuf.cc \ + qa_block_tags.cc \ qa_runtime.cc grinclude_HEADERS = \ @@ -136,6 +137,7 @@ noinst_HEADERS = \ qa_gr_io_signature.h \ qa_gr_top_block.h \ qa_gr_vmcircbuf.h \ + qa_block_tags.h \ qa_runtime.h if PYTHON diff --git a/gnuradio-core/src/lib/runtime/qa_block_tags.cc b/gnuradio-core/src/lib/runtime/qa_block_tags.cc new file mode 100644 index 000000000..c9ec788b0 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/qa_block_tags.cc @@ -0,0 +1,118 @@ +/* -*- c++ -*- */ +/* + * Copyright 2010 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include +#endif +#include +#include +#include +#include +#include +#include +#include + + +// ---------------------------------------------------------------- + + +void +qa_block_tags::t0 () +{ + printf("\nqa_block_tags::t0\n"); + + unsigned int N = 1000; + 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 snk (gr_make_null_sink(sizeof(int))); + + tb->connect(src, 0, head, 0); + tb->connect(head, 0, snk, 0); + + //CPPUNIT_ASSERT_THROW(src->n_items_read(0), std::runtime_error); + //CPPUNIT_ASSERT_THROW(src->n_items_written(0), std::runtime_error); + CPPUNIT_ASSERT_EQUAL(src->n_items_read(0), (gr_uint64)0); + CPPUNIT_ASSERT_EQUAL(src->n_items_written(0), (gr_uint64)0); + + tb->run(); + + CPPUNIT_ASSERT_THROW(src->n_items_read(0), std::invalid_argument); + CPPUNIT_ASSERT(src->n_items_written(0) >= N); + CPPUNIT_ASSERT_EQUAL(snk->n_items_read(0), (gr_uint64)1000); + CPPUNIT_ASSERT_THROW(snk->n_items_written(0), std::invalid_argument); +} + + +void +qa_block_tags::t1 () +{ + printf("\nqa_block_tags::t1\n"); + + int N = 1000; + 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 snk (gr_make_null_sink(sizeof(int))); + + tb->connect(src, 0, head, 0); + tb->connect(head, 0, snk, 0); + tb->run(); + + gr_uint64 W = src->n_items_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 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); +} + diff --git a/gnuradio-core/src/lib/runtime/qa_block_tags.h b/gnuradio-core/src/lib/runtime/qa_block_tags.h new file mode 100644 index 000000000..b7388885f --- /dev/null +++ b/gnuradio-core/src/lib/runtime/qa_block_tags.h @@ -0,0 +1,44 @@ +/* -*- c++ -*- */ +/* + * Copyright 2010 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_QA_BLOCK_TAGS_H +#define INCLUDED_QA_BLOCK_TAGS_H + +#include +#include +#include + +class qa_block_tags : public CppUnit::TestCase { + + CPPUNIT_TEST_SUITE (qa_block_tags); + CPPUNIT_TEST (t0); + CPPUNIT_TEST (t1); + CPPUNIT_TEST_SUITE_END (); + + private: + void t0 (); + void t1 (); + +}; + + +#endif /* INCLUDED_QA_BLOCK_TAGS_H */ diff --git a/gnuradio-core/src/lib/runtime/qa_runtime.cc b/gnuradio-core/src/lib/runtime/qa_runtime.cc index 31e3a82d6..967d4bfa8 100644 --- a/gnuradio-core/src/lib/runtime/qa_runtime.cc +++ b/gnuradio-core/src/lib/runtime/qa_runtime.cc @@ -38,6 +38,7 @@ #include #include #include +#include CppUnit::TestSuite * qa_runtime::suite () @@ -52,6 +53,7 @@ qa_runtime::suite () s->addTest (qa_gr_hier_block2::suite ()); s->addTest (qa_gr_hier_block2_derived::suite ()); s->addTest (qa_gr_buffer::suite ()); + s->addTest (qa_block_tags::suite ()); return s; } -- cgit From e70f8a0d50474784c1f1b64b94907feb9b913a2b Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Tue, 2 Nov 2010 19:57:24 -0400 Subject: Moved number items read/written from gr_block_detail into gr_buffer (abs_written_offset) and gr_buffer_reader (abs_read_offset). Keeps the API exposed in gr_blocks for now. --- gnuradio-core/src/lib/runtime/gr_block.cc | 4 ++-- gnuradio-core/src/lib/runtime/gr_block_detail.cc | 24 ++++++++++++++++-------- gnuradio-core/src/lib/runtime/gr_block_detail.h | 14 ++------------ gnuradio-core/src/lib/runtime/gr_buffer.cc | 5 +++-- gnuradio-core/src/lib/runtime/gr_buffer.h | 10 +++++++++- 5 files changed, 32 insertions(+), 25 deletions(-) (limited to 'gnuradio-core/src') diff --git a/gnuradio-core/src/lib/runtime/gr_block.cc b/gnuradio-core/src/lib/runtime/gr_block.cc index e0a223135..c00a034de 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_block.cc @@ -121,7 +121,7 @@ gr_uint64 gr_block::n_items_read(unsigned int which_input) { if(d_detail) { - return d_detail->n_items_read(which_input); + return d_detail->nitems_read(which_input); } else { //throw std::runtime_error("No block_detail associated with block yet"); @@ -133,7 +133,7 @@ gr_uint64 gr_block::n_items_written(unsigned int which_output) { if(d_detail) { - return d_detail->n_items_written(which_output); + return d_detail->nitems_written(which_output); } else { //throw std::runtime_error("No block_detail associated with block yet"); diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.cc b/gnuradio-core/src/lib/runtime/gr_block_detail.cc index effaf5269..d12d808e9 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.cc @@ -39,7 +39,6 @@ gr_block_detail::gr_block_detail (unsigned int ninputs, unsigned int noutputs) : d_produce_or(0), d_ninputs (ninputs), d_noutputs (noutputs), d_input (ninputs), d_output (noutputs), - d_n_items_read(ninputs, 0), d_n_items_written(noutputs, 0), d_done (false) { s_ncurrently_allocated++; @@ -91,10 +90,6 @@ gr_block_detail::consume (int which_input, int how_many_items) { if (how_many_items > 0) { input (which_input)->update_read_pointer (how_many_items); - - // Carefull here; we check that which_input exists above - // is this good enough protection that we don't get here? - d_n_items_read[which_input] += how_many_items; } } @@ -105,7 +100,6 @@ gr_block_detail::consume_each (int how_many_items) if (how_many_items > 0) { for (int i = 0; i < ninputs (); i++) { d_input[i]->update_read_pointer (how_many_items); - d_n_items_read[i] += how_many_items; } } } @@ -115,7 +109,6 @@ gr_block_detail::produce (int which_output, int how_many_items) { if (how_many_items > 0){ d_output[which_output]->update_write_pointer (how_many_items); - d_n_items_written[which_output] += how_many_items; d_produce_or |= how_many_items; } } @@ -126,7 +119,6 @@ gr_block_detail::produce_each (int how_many_items) if (how_many_items > 0) { for (int i = 0; i < noutputs (); i++) { d_output[i]->update_write_pointer (how_many_items); - d_n_items_written[i] += how_many_items; } d_produce_or |= how_many_items; } @@ -139,6 +131,22 @@ gr_block_detail::_post(pmt::pmt_t msg) d_tpb.insert_tail(msg); } +gr_uint64 +gr_block_detail::nitems_read(unsigned int which_input) +{ + if(which_input >= d_ninputs) + throw std::invalid_argument ("gr_block_detail::n_input_items"); + return d_input[which_input]->nitems_read(); +} + +gr_uint64 +gr_block_detail::nitems_written(unsigned int which_output) +{ + if(which_output >= d_noutputs) + throw std::invalid_argument ("gr_block_detail::n_output_items"); + return d_output[which_output]->nitems_written(); +} + void gr_block_detail::add_item_tag(unsigned int which_output, gr_uint64 offset, diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.h b/gnuradio-core/src/lib/runtime/gr_block_detail.h index cb590cec9..ee226a349 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.h +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.h @@ -89,18 +89,10 @@ class gr_block_detail { void _post(pmt::pmt_t msg); // Return the number of items read on input stream which_input - gr_uint64 n_items_read(unsigned int which_input) { - if(which_input >= d_ninputs) - throw std::invalid_argument ("gr_block_detail::n_input_items"); - return d_n_items_read[which_input]; - } + gr_uint64 nitems_read(unsigned int which_input); // Return the number of items written on output stream which_output - gr_uint64 n_items_written(unsigned int which_output) { - if(which_output >= d_noutputs) - throw std::invalid_argument ("gr_block_detail::n_output_items"); - return d_n_items_written[which_output]; - } + gr_uint64 nitems_written(unsigned int which_output); // Add an item tag tuple to list of tags // -> is this just based on output stream? how to handle this... @@ -125,8 +117,6 @@ class gr_block_detail { unsigned int d_noutputs; std::vector d_input; std::vector d_output; - std::vector d_n_items_read; - std::vector d_n_items_written; std::list d_item_tags; bool d_done; diff --git a/gnuradio-core/src/lib/runtime/gr_buffer.cc b/gnuradio-core/src/lib/runtime/gr_buffer.cc index db2db5d6d..42d00e06f 100644 --- a/gnuradio-core/src/lib/runtime/gr_buffer.cc +++ b/gnuradio-core/src/lib/runtime/gr_buffer.cc @@ -80,7 +80,7 @@ minimum_buffer_items (long type_size, long page_size) gr_buffer::gr_buffer (int nitems, size_t sizeof_item, gr_block_sptr link) : d_base (0), d_bufsize (0), d_vmcircbuf (0), d_sizeof_item (sizeof_item), d_link(link), - d_write_index (0), d_done (false) + d_write_index (0), d_abs_write_offset(0), d_done (false) { if (!allocate_buffer (nitems, sizeof_item)) throw std::bad_alloc (); @@ -225,7 +225,7 @@ gr_buffer_ncurrently_allocated () gr_buffer_reader::gr_buffer_reader(gr_buffer_sptr buffer, unsigned int read_index, gr_block_sptr link) - : d_buffer(buffer), d_read_index(read_index), d_link(link) + : d_buffer(buffer), d_read_index(read_index), d_abs_read_offset(0), d_link(link) { s_buffer_reader_count++; } @@ -253,6 +253,7 @@ gr_buffer_reader::update_read_pointer (int nitems) { gruel::scoped_lock guard(*mutex()); d_read_index = d_buffer->index_add (d_read_index, nitems); + d_abs_read_offset += nitems; } long diff --git a/gnuradio-core/src/lib/runtime/gr_buffer.h b/gnuradio-core/src/lib/runtime/gr_buffer.h index 207bfe7c5..8af72741a 100644 --- a/gnuradio-core/src/lib/runtime/gr_buffer.h +++ b/gnuradio-core/src/lib/runtime/gr_buffer.h @@ -88,6 +88,8 @@ class gr_buffer { gruel::mutex *mutex() { return &d_mutex; } + gr_uint64 nitems_written() { return d_abs_write_offset; } + // ------------------------------------------------------------------------- private: @@ -106,10 +108,13 @@ class gr_buffer { boost::weak_ptr d_link; // block that writes to this buffer // - // The mutex protects d_write_index, d_done and the d_read_index's in the buffer readers. + // The mutex protects d_write_index, d_abs_write_offset, d_done and the d_read_index's + // and d_abs_read_offset's in the buffer readers. // gruel::mutex d_mutex; unsigned int d_write_index; // in items [0,d_bufsize) + gr_uint64 d_abs_write_offset; // num items written since the start + //deq tag_tuples bool d_done; unsigned @@ -220,6 +225,8 @@ class gr_buffer_reader { gruel::mutex *mutex() { return d_buffer->mutex(); } + gr_uint64 nitems_read() { return d_abs_read_offset; } + /*! * \brief Return the block that reads via this reader. */ @@ -236,6 +243,7 @@ class gr_buffer_reader { gr_buffer_sptr d_buffer; unsigned int d_read_index; // in items [0,d->buffer.d_bufsize) + gr_uint64 d_abs_read_offset; // num items seen since the start boost::weak_ptr d_link; // block that reads via this buffer reader //! constructor is private. Use gr_buffer::add_reader to create instances -- cgit From c3725a7269a7e96252a957b6d078686352365de6 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Thu, 4 Nov 2010 11:38:27 -0400 Subject: Fixing buffer to update abs_write_offset counter. Keeping access to counters exposed through gr_block for now, just remaining to nitem_*. --- gnuradio-core/src/lib/runtime/gr_block.cc | 4 ++-- gnuradio-core/src/lib/runtime/gr_block.h | 4 ++-- gnuradio-core/src/lib/runtime/gr_block.i | 4 ++-- gnuradio-core/src/lib/runtime/gr_buffer.cc | 1 + gnuradio-core/src/lib/runtime/qa_block_tags.cc | 18 +++++++++--------- 5 files changed, 16 insertions(+), 15 deletions(-) (limited to 'gnuradio-core/src') diff --git a/gnuradio-core/src/lib/runtime/gr_block.cc b/gnuradio-core/src/lib/runtime/gr_block.cc index c00a034de..13035aa96 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_block.cc @@ -118,7 +118,7 @@ gr_block::fixed_rate_noutput_to_ninput(int noutput) } gr_uint64 -gr_block::n_items_read(unsigned int which_input) +gr_block::nitems_read(unsigned int which_input) { if(d_detail) { return d_detail->nitems_read(which_input); @@ -130,7 +130,7 @@ gr_block::n_items_read(unsigned int which_input) } gr_uint64 -gr_block::n_items_written(unsigned int which_output) +gr_block::nitems_written(unsigned int which_output) { if(d_detail) { return d_detail->nitems_written(which_output); diff --git a/gnuradio-core/src/lib/runtime/gr_block.h b/gnuradio-core/src/lib/runtime/gr_block.h index 888ca811a..7564acd87 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.h +++ b/gnuradio-core/src/lib/runtime/gr_block.h @@ -200,10 +200,10 @@ class gr_block : public gr_basic_block { virtual int fixed_rate_noutput_to_ninput(int noutput); // Return the number of items read on input stream which_input - gr_uint64 n_items_read(unsigned int which_input); + gr_uint64 nitems_read(unsigned int which_input); // Return the number of items written on output stream which_output - gr_uint64 n_items_written(unsigned int which_output); + gr_uint64 nitems_written(unsigned int which_output); void add_item_tag(unsigned int which_output, gr_uint64 offset, diff --git a/gnuradio-core/src/lib/runtime/gr_block.i b/gnuradio-core/src/lib/runtime/gr_block.i index d70a5854a..4684bd2f2 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.i +++ b/gnuradio-core/src/lib/runtime/gr_block.i @@ -49,8 +49,8 @@ class gr_block : public gr_basic_block { bool start(); bool stop(); - gr_uint64 n_items_read(unsigned int which_input); - gr_uint64 n_items_written(unsigned int which_output); + gr_uint64 nitems_read(unsigned int which_input); + gr_uint64 nitems_written(unsigned int which_output); // internal use gr_block_detail_sptr detail () const { return d_detail; } diff --git a/gnuradio-core/src/lib/runtime/gr_buffer.cc b/gnuradio-core/src/lib/runtime/gr_buffer.cc index 42d00e06f..89db99b69 100644 --- a/gnuradio-core/src/lib/runtime/gr_buffer.cc +++ b/gnuradio-core/src/lib/runtime/gr_buffer.cc @@ -177,6 +177,7 @@ gr_buffer::update_write_pointer (int nitems) { gruel::scoped_lock guard(*mutex()); d_write_index = index_add (d_write_index, nitems); + d_abs_write_offset += nitems; } void diff --git a/gnuradio-core/src/lib/runtime/qa_block_tags.cc b/gnuradio-core/src/lib/runtime/qa_block_tags.cc index c9ec788b0..73faa6ca7 100644 --- a/gnuradio-core/src/lib/runtime/qa_block_tags.cc +++ b/gnuradio-core/src/lib/runtime/qa_block_tags.cc @@ -49,17 +49,17 @@ qa_block_tags::t0 () tb->connect(src, 0, head, 0); tb->connect(head, 0, snk, 0); - //CPPUNIT_ASSERT_THROW(src->n_items_read(0), std::runtime_error); - //CPPUNIT_ASSERT_THROW(src->n_items_written(0), std::runtime_error); - CPPUNIT_ASSERT_EQUAL(src->n_items_read(0), (gr_uint64)0); - CPPUNIT_ASSERT_EQUAL(src->n_items_written(0), (gr_uint64)0); + //CPPUNIT_ASSERT_THROW(src->nitems_read(0), std::runtime_error); + //CPPUNIT_ASSERT_THROW(src->nitems_written(0), std::runtime_error); + CPPUNIT_ASSERT_EQUAL(src->nitems_read(0), (gr_uint64)0); + CPPUNIT_ASSERT_EQUAL(src->nitems_written(0), (gr_uint64)0); tb->run(); - CPPUNIT_ASSERT_THROW(src->n_items_read(0), std::invalid_argument); - CPPUNIT_ASSERT(src->n_items_written(0) >= N); - CPPUNIT_ASSERT_EQUAL(snk->n_items_read(0), (gr_uint64)1000); - CPPUNIT_ASSERT_THROW(snk->n_items_written(0), std::invalid_argument); + CPPUNIT_ASSERT_THROW(src->nitems_read(0), std::invalid_argument); + CPPUNIT_ASSERT(src->nitems_written(0) >= N); + CPPUNIT_ASSERT_EQUAL(snk->nitems_read(0), (gr_uint64)1000); + CPPUNIT_ASSERT_THROW(snk->nitems_written(0), std::invalid_argument); } @@ -78,7 +78,7 @@ qa_block_tags::t1 () tb->connect(head, 0, snk, 0); tb->run(); - gr_uint64 W = src->n_items_written(0); + 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)); -- cgit From 779f498c46175bb12828c9db4643eada3e364b16 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Thu, 4 Nov 2010 12:31:18 -0400 Subject: Moves gr_block functions dealing with tags into protected space. Adds documentation to functions in header. Adds a "srcid" parameter to the add_item_tag function. --- gnuradio-core/src/lib/runtime/gr_block.cc | 12 +++-- gnuradio-core/src/lib/runtime/gr_block.h | 83 +++++++++++++++++++++++++------ gnuradio-core/src/lib/runtime/gr_block.i | 2 +- 3 files changed, 76 insertions(+), 21 deletions(-) (limited to 'gnuradio-core/src') diff --git a/gnuradio-core/src/lib/runtime/gr_block.cc b/gnuradio-core/src/lib/runtime/gr_block.cc index 13035aa96..eb377953d 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_block.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2004,2009 Free Software Foundation, Inc. + * Copyright 2004,2009,2010 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -144,19 +144,21 @@ gr_block::nitems_written(unsigned int which_output) void gr_block::add_item_tag(unsigned int which_output, gr_uint64 offset, - const pmt::pmt_t &key, const pmt::pmt_t &value) + const pmt::pmt_t &key, + const pmt::pmt_t &value, + const pmt::pmt_t &srcid) { - d_detail->add_item_tag(which_output, offset, key, value); + d_detail->add_item_tag(which_output, offset, key, value, srcid); } -std::list +std::deque gr_block::get_tags_in_range(unsigned int which_output, gr_uint64 start, gr_uint64 end) { return d_detail->get_tags_in_range(which_output, start, end); } -std::list +std::deque gr_block::get_tags_in_range(unsigned int which_output, gr_uint64 start, gr_uint64 end, const pmt::pmt_t &key) diff --git a/gnuradio-core/src/lib/runtime/gr_block.h b/gnuradio-core/src/lib/runtime/gr_block.h index 7564acd87..25886eb10 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.h +++ b/gnuradio-core/src/lib/runtime/gr_block.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2004,2007,2009 Free Software Foundation, Inc. + * Copyright 2004,2007,2009,2010 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -24,7 +24,7 @@ #define INCLUDED_GR_BLOCK_H #include -#include +#include /*! * \brief The abstract base class for all 'terminal' processing blocks. @@ -199,23 +199,16 @@ class gr_block : public gr_basic_block { */ virtual int fixed_rate_noutput_to_ninput(int noutput); - // Return the number of items read on input stream which_input + /*! + * \brief Return the number of items read on input stream which_input + */ gr_uint64 nitems_read(unsigned int which_input); - // Return the number of items written on output stream which_output + /*! + * \brief Return the number of items written on output stream which_output + */ gr_uint64 nitems_written(unsigned int which_output); - void add_item_tag(unsigned int which_output, - gr_uint64 offset, - const pmt::pmt_t &key, const pmt::pmt_t &value); - - std::list get_tags_in_range(unsigned int which_output, - gr_uint64 start, gr_uint64 end); - - std::list get_tags_in_range(unsigned int which_output, - gr_uint64 start, gr_uint64 end, - const pmt::pmt_t &key); - // ---------------------------------------------------------------------------- private: @@ -234,6 +227,66 @@ class gr_block : public gr_basic_block { void set_fixed_rate(bool fixed_rate){ d_fixed_rate = fixed_rate; } + + /*! + * \brief Adds a new tag to the deque of tags on a given buffer. + * + * This is a call-through method to gr_block_detail to add the new tag. + * gr_block_detail takes care of formatting the tuple from the inputs here, + * it then calls gr_buffer::add_item_tag(pmt::pmt_t t), which appends the + * tag onto its deque of tags. + * + * \param which_ouput an integer of which output stream to attach the tag + * \param abs_offset a uint64 number of the absolute item number + * assicated with the tag. Can get from nitems_written. + * \param key a PMT symbol holding the key name (i.e., a string) + * \param value any PMT holding any value for the given key + * \param srcid optional source ID specifier; defauls to string "NA" + */ + void add_item_tag(unsigned int which_output, + gr_uint64 abs_offset, + const pmt::pmt_t &key, + const pmt::pmt_t &value, + const pmt::pmt_t &srcid=pmt::pmt_string_to_symbol("NA")); + + /*! + * \brief Given a [start,end), returns a deque copy of all tags in the range. + * + * Pass-through function to gr_block_detail. Range of counts is from + * start to end-1. + * + * Tags are tuples of: + * (item count, source id, key, value) + * + * \param which_input an integer of which input stream to pull from + * \param abs_start a uint64 count of the start of the range of interest + * \param abs_end a uint64 count of the end of the range of interest + */ + std::deque get_tags_in_range(unsigned int which_input, + gr_uint64 abs_start, + gr_uint64 abs_end); + + /*! + * \brief Given a [start,end), returns a deque copy of all tags in the range + * with a given key. + * + * Pass-through function to gr_block_detail. Range of counts is from + * start to end-1. + * + * Tags are tuples of: + * (item count, source id, key, value) + * + * \param which_input an integer of which input stream to pull from + * \param abs_start a uint64 count of the start of the range of interest + * \param abs_end a uint64 count of the end of the range of interest + * \param key a PMT symbol key to filter only tags of this key + */ + std::deque get_tags_in_range(unsigned int which_input, + gr_uint64 abs_start, + gr_uint64 abs_end, + const pmt::pmt_t &key); + + // These are really only for internal use, but leaving them public avoids // having to work up an ever-varying list of friends diff --git a/gnuradio-core/src/lib/runtime/gr_block.i b/gnuradio-core/src/lib/runtime/gr_block.i index 4684bd2f2..e6ea06060 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.i +++ b/gnuradio-core/src/lib/runtime/gr_block.i @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2004 Free Software Foundation, Inc. + * Copyright 2004,2010 Free Software Foundation, Inc. * * This file is part of GNU Radio * -- cgit From 309b05cbb38125a910b6199f7adc4ff93bc98064 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Thu, 4 Nov 2010 12:33:20 -0400 Subject: Changing API to match changes to gr_block, including adding "srcid" param to add_item_tag. Added documentation to header file. Changing to deque from list. Still holding the deque locally in block_detail, but will be moved to gr_buffer. Adding tag just builds the tag tuple and appends it; doesn't worry about duplications. --- gnuradio-core/src/lib/runtime/gr_block_detail.cc | 61 +++++++------------- gnuradio-core/src/lib/runtime/gr_block_detail.h | 72 ++++++++++++++++++++---- 2 files changed, 81 insertions(+), 52 deletions(-) (limited to 'gnuradio-core/src') diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.cc b/gnuradio-core/src/lib/runtime/gr_block_detail.cc index d12d808e9..2ab762a30 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2004,2009 Free Software Foundation, Inc. + * Copyright 2004,2009,2010 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -149,59 +149,39 @@ gr_block_detail::nitems_written(unsigned int which_output) void gr_block_detail::add_item_tag(unsigned int which_output, - gr_uint64 offset, + gr_uint64 abs_offset, const pmt::pmt_t &key, - const pmt::pmt_t &value) + const pmt::pmt_t &value, + const pmt::pmt_t &srcid) { if(pmt::pmt_is_symbol(key) == false) { throw pmt::pmt_wrong_type("gr_block_detail::set_item_tag key", key); } else { - bool duplicate = false; - - // Search through list of tags to see if new tag is a duplicate - std::list::reverse_iterator itr = d_item_tags.rbegin(); - while(itr != d_item_tags.rend()) { - // find the last item with this key if there is one - if(pmt::pmt_eqv(pmt::pmt_tuple_ref(*itr, 2), key)) { - // check if this value is the same as last; its a duplicate if yes - if(pmt::pmt_eqv(pmt::pmt_tuple_ref(*itr, 3), value)) { - duplicate = true; - } - break; // only looking for the last item of this key - } - itr++; - } - - // It not a duplicate, add new tag to the list - if(!duplicate) { - pmt::pmt_t nitem = pmt::pmt_from_uint64(offset); - pmt::pmt_t stream = pmt::pmt_string_to_symbol("NULL"); - pmt::pmt_t tuple = pmt::pmt_make_tuple(nitem, stream, key, value); - d_item_tags.push_back(tuple); - } - - // need to add prunning routine + pmt::pmt_t nitem = pmt::pmt_from_uint64(abs_offset); + pmt::pmt_t tuple = pmt::pmt_make_tuple(nitem, srcid, key, value); + d_item_tags.push_back(tuple); } } -std::list +std::deque gr_block_detail::get_tags_in_range(unsigned int which_output, - gr_uint64 start, gr_uint64 end) + gr_uint64 abs_start, + gr_uint64 abs_end) { - std::list found_items; - std::list::iterator itr = d_item_tags.begin(); + std::deque found_items; + std::deque::iterator itr = d_item_tags.begin(); gr_uint64 item_time; while(itr != d_item_tags.end()) { item_time = pmt::pmt_to_uint64(pmt::pmt_tuple_ref(*itr, 0)); // items are pushed onto list in sequential order; stop if we're past end - if(item_time > end) { + if(item_time > abs_end) { break; } - if((item_time >= start) && (item_time <= end)) { + if((item_time >= abs_start) && (item_time <= abs_end)) { found_items.push_back(*itr); } @@ -211,13 +191,14 @@ gr_block_detail::get_tags_in_range(unsigned int which_output, return found_items; } -std::list +std::deque gr_block_detail::get_tags_in_range(unsigned int which_output, - gr_uint64 start, gr_uint64 end, + gr_uint64 abs_start, + gr_uint64 abs_end, const pmt::pmt_t &key) { - std::list found_items; - std::list::iterator itr = d_item_tags.begin(); + std::deque found_items; + std::deque::iterator itr = d_item_tags.begin(); gr_uint64 item_time; pmt::pmt_t itemkey; @@ -225,12 +206,12 @@ gr_block_detail::get_tags_in_range(unsigned int which_output, item_time = pmt::pmt_to_uint64(pmt::pmt_tuple_ref(*itr, 0)); // items are pushed onto list in sequential order; stop if we're past end - if(item_time > end) { + if(item_time > abs_end) { break; } itemkey = pmt::pmt_tuple_ref(*itr, 2); - if((item_time >= start) && (item_time <= end) && pmt::pmt_eqv(key, itemkey)) { + if((item_time >= abs_start) && (item_time <= abs_end) && pmt::pmt_eqv(key, itemkey)) { found_items.push_back(*itr); } diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.h b/gnuradio-core/src/lib/runtime/gr_block_detail.h index ee226a349..547d7c22f 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.h +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2004,2009 Free Software Foundation, Inc. + * Copyright 2004,2009,2010 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -94,18 +94,66 @@ class gr_block_detail { // Return the number of items written on output stream which_output gr_uint64 nitems_written(unsigned int which_output); - // Add an item tag tuple to list of tags - // -> is this just based on output stream? how to handle this... - void add_item_tag(unsigned int which_output, - gr_uint64 offset, - const pmt::pmt_t &key, const pmt::pmt_t &value); - std::list get_tags_in_range(unsigned int which_output, - gr_uint64 start, gr_uint64 end); + /*! + * \brief Adds a new tag to the deque of tags on a given buffer. + * + * Adds a new tag to deque of tags on a given buffer. This takes the input + * parameters and builds a PMT tuple from it. It then calls + * gr_buffer::add_item_tag(pmt::pmt_t t), which appends the + * tag onto its deque of tags. + * + * \param which_ouput an integer of which output stream to attach the tag + * \param abs_offset a uint64 number of the absolute item number + * assicated with the tag. Can get from nitems_written. + * \param key a PMT symbol holding the key name (i.e., a string) + * \param value any PMT holding any value for the given key + * \param srcid a PMT source ID specifier + */ + void add_item_tag(unsigned int which_output, + gr_uint64 abs_offset, + const pmt::pmt_t &key, + const pmt::pmt_t &value, + const pmt::pmt_t &srcid); + + /*! + * \brief Given a [start,end), returns a deque copy of all tags in the range. + * + * Pass-through function to gr_buffer to get a deque of tags in given range. + * Range of counts is from start to end-1. + * + * Tags are tuples of: + * (item count, source id, key, value) + * + * \param which_input an integer of which input stream to pull from + * \param abs_start a uint64 count of the start of the range of interest + * \param abs_end a uint64 count of the end of the range of interest + */ + std::deque get_tags_in_range(unsigned int which_input, + gr_uint64 abs_start, + gr_uint64 abs_end); - std::list get_tags_in_range(unsigned int which_output, - gr_uint64 start, gr_uint64 end, - const pmt::pmt_t &key); + /*! + * \brief Given a [start,end), returns a deque copy of all tags in the range + * with a given key. + * + * Calls get_tags_in_range(which_input, abs_start, abs_end) to get a deque of + * tags from the buffers. This function then provides a secondary filter to + * the tags to extract only tags with the given 'key'. Returns a dequeu + * of these tags. + * + * Tags are tuples of: + * (item count, source id, key, value) + * + * \param which_input an integer of which input stream to pull from + * \param abs_start a uint64 count of the start of the range of interest + * \param abs_end a uint64 count of the end of the range of interest + * \param key a PMT symbol key to filter only tags of this key + */ + std::deque get_tags_in_range(unsigned int which_input, + gr_uint64 abs_start, + gr_uint64 abs_end, + const pmt::pmt_t &key); gr_tpb_detail d_tpb; // used by thread-per-block scheduler int d_produce_or; @@ -117,7 +165,7 @@ class gr_block_detail { unsigned int d_noutputs; std::vector d_input; std::vector d_output; - std::list d_item_tags; + std::deque d_item_tags; bool d_done; -- cgit From 54803ebc0450e9ee46e66b15d3b29249e44c55ed Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Thu, 4 Nov 2010 12:38:52 -0400 Subject: Adding shell block for a random annotator. This will be used only for testing the stream tags, which is why its sitting in runtime. --- gnuradio-core/src/lib/runtime/Makefile.am | 3 ++ .../src/lib/runtime/gr_random_annotator.cc | 53 ++++++++++++++++++++++ .../src/lib/runtime/gr_random_annotator.h | 51 +++++++++++++++++++++ .../src/lib/runtime/gr_random_annotator.i | 32 +++++++++++++ gnuradio-core/src/lib/runtime/runtime.i | 2 + 5 files changed, 141 insertions(+) create mode 100644 gnuradio-core/src/lib/runtime/gr_random_annotator.cc create mode 100644 gnuradio-core/src/lib/runtime/gr_random_annotator.h create mode 100644 gnuradio-core/src/lib/runtime/gr_random_annotator.i (limited to 'gnuradio-core/src') diff --git a/gnuradio-core/src/lib/runtime/Makefile.am b/gnuradio-core/src/lib/runtime/Makefile.am index 4c52f3ab0..1af91d80d 100644 --- a/gnuradio-core/src/lib/runtime/Makefile.am +++ b/gnuradio-core/src/lib/runtime/Makefile.am @@ -49,6 +49,7 @@ libruntime_la_SOURCES = \ gr_msg_queue.cc \ gr_pagesize.cc \ gr_preferences.cc \ + gr_random_annotator.cc \ gr_realtime.cc \ gr_scheduler.cc \ gr_scheduler_sts.cc \ @@ -103,6 +104,7 @@ grinclude_HEADERS = \ gr_msg_queue.h \ gr_pagesize.h \ gr_preferences.h \ + gr_random_annotator.h \ gr_realtime.h \ gr_runtime_types.h \ gr_scheduler.h \ @@ -153,6 +155,7 @@ swiginclude_HEADERS = \ gr_message.i \ gr_msg_handler.i \ gr_msg_queue.i \ + gr_random_annotator.i \ gr_realtime.i \ gr_single_threaded_scheduler.i \ gr_sync_block.i \ diff --git a/gnuradio-core/src/lib/runtime/gr_random_annotator.cc b/gnuradio-core/src/lib/runtime/gr_random_annotator.cc new file mode 100644 index 000000000..85995fde1 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_random_annotator.cc @@ -0,0 +1,53 @@ +/* -*- c++ -*- */ +/* + * Copyright 2010 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include + +gr_random_annotator::gr_random_annotator (size_t sizeof_stream_item) + : gr_sync_block ("random_annotator", + gr_make_io_signature (1, 1, sizeof_stream_item), + gr_make_io_signature (1, 1, sizeof_stream_item)) +{ +} + +gr_random_annotator::~gr_random_annotator () +{ +} + +gr_random_annotator_sptr +gr_make_random_annotator (size_t sizeof_stream_item) +{ + return gnuradio::get_initial_sptr (new gr_random_annotator (sizeof_stream_item)); +} + +int +gr_random_annotator::work (int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) +{ + return noutput_items; +} diff --git a/gnuradio-core/src/lib/runtime/gr_random_annotator.h b/gnuradio-core/src/lib/runtime/gr_random_annotator.h new file mode 100644 index 000000000..cf894c640 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_random_annotator.h @@ -0,0 +1,51 @@ +/* -*- c++ -*- */ +/* + * Copyright 2010 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_GR_RANDOM_ANNOTATOR_H +#define INCLUDED_GR_RANDOM_ANNOTATOR_H + +#include + +class gr_random_annotator; +typedef boost::shared_ptr gr_random_annotator_sptr; + +// public constructor +gr_random_annotator_sptr +gr_make_random_annotator (size_t sizeof_stream_item); + +class gr_random_annotator : public gr_sync_block +{ + public: + ~gr_random_annotator (); + int work (int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + +protected: + gr_random_annotator (size_t sizeof_stream_item); + + private: + friend gr_random_annotator_sptr + gr_make_random_annotator (size_t sizeof_stream_item); +}; + +#endif diff --git a/gnuradio-core/src/lib/runtime/gr_random_annotator.i b/gnuradio-core/src/lib/runtime/gr_random_annotator.i new file mode 100644 index 000000000..f8765a294 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_random_annotator.i @@ -0,0 +1,32 @@ +/* -*- c++ -*- */ +/* + * Copyright 2010 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +GR_SWIG_BLOCK_MAGIC(gr,random_annotator); + +gr_random_annotator_sptr gr_make_random_annotator (size_t sizeof_stream_item); + +class gr_random_annotator : public gr_sync_block +{ +private: + gr_random_annotator (size_t sizeof_stream_item); +}; + diff --git a/gnuradio-core/src/lib/runtime/runtime.i b/gnuradio-core/src/lib/runtime/runtime.i index 20cf68a03..51b32de17 100644 --- a/gnuradio-core/src/lib/runtime/runtime.i +++ b/gnuradio-core/src/lib/runtime/runtime.i @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -53,6 +54,7 @@ %include %include %include +%include %include %include %include -- cgit From d75b1bb7ae118e191ef31c5691d409b680f723df Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Thu, 4 Nov 2010 12:55:51 -0400 Subject: Makding random_annotator simply copy input to output streams; fixes IO signatures. --- .../src/lib/runtime/gr_random_annotator.cc | 27 +++++++++++++++------- .../src/lib/runtime/gr_random_annotator.h | 2 ++ 2 files changed, 21 insertions(+), 8 deletions(-) (limited to 'gnuradio-core/src') diff --git a/gnuradio-core/src/lib/runtime/gr_random_annotator.cc b/gnuradio-core/src/lib/runtime/gr_random_annotator.cc index 85995fde1..25e7458e5 100644 --- a/gnuradio-core/src/lib/runtime/gr_random_annotator.cc +++ b/gnuradio-core/src/lib/runtime/gr_random_annotator.cc @@ -26,22 +26,24 @@ #include #include +#include -gr_random_annotator::gr_random_annotator (size_t sizeof_stream_item) - : gr_sync_block ("random_annotator", - gr_make_io_signature (1, 1, sizeof_stream_item), - gr_make_io_signature (1, 1, sizeof_stream_item)) +gr_random_annotator_sptr +gr_make_random_annotator (size_t sizeof_stream_item) { + return gnuradio::get_initial_sptr (new gr_random_annotator (sizeof_stream_item)); } -gr_random_annotator::~gr_random_annotator () +gr_random_annotator::gr_random_annotator (size_t sizeof_stream_item) + : gr_sync_block ("random_annotator", + gr_make_io_signature (1, -1, sizeof_stream_item), + gr_make_io_signature (1, -1, sizeof_stream_item)), + d_itemsize(sizeof_stream_item) { } -gr_random_annotator_sptr -gr_make_random_annotator (size_t sizeof_stream_item) +gr_random_annotator::~gr_random_annotator () { - return gnuradio::get_initial_sptr (new gr_random_annotator (sizeof_stream_item)); } int @@ -49,5 +51,14 @@ gr_random_annotator::work (int noutput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items) { + const float **in = (const float **) &input_items[0]; + float **out = (float **) &output_items[0]; + + // 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); + } + return noutput_items; } diff --git a/gnuradio-core/src/lib/runtime/gr_random_annotator.h b/gnuradio-core/src/lib/runtime/gr_random_annotator.h index cf894c640..7f200eff7 100644 --- a/gnuradio-core/src/lib/runtime/gr_random_annotator.h +++ b/gnuradio-core/src/lib/runtime/gr_random_annotator.h @@ -44,6 +44,8 @@ protected: gr_random_annotator (size_t sizeof_stream_item); private: + size_t d_itemsize; + friend gr_random_annotator_sptr gr_make_random_annotator (size_t sizeof_stream_item); }; -- cgit From ef9ff4ce4ab97a557f08fa5dad091b0cf63d313f Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Thu, 4 Nov 2010 13:19:00 -0400 Subject: Making annotator block build up tags with the noutput_items as the value held. Simply prints info to stdout when tags are retreived. --- .../src/lib/runtime/gr_random_annotator.cc | 23 +++++++++++ gnuradio-core/src/lib/runtime/qa_block_tags.cc | 45 ++++------------------ 2 files changed, 30 insertions(+), 38 deletions(-) (limited to 'gnuradio-core/src') 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 #include #include +#include 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 all_tags = get_tags_in_range(0, (gr_uint64)0, abs_N); + std::deque::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 #include #include +#include #include @@ -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 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); } -- cgit From 70ca24e7cc6ba744589e3d5fb8077f706e813d28 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Thu, 4 Nov 2010 18:16:26 -0400 Subject: Moving add_item_tag into gr_buffer and get_tags_in_range to gr_buffer_reader. gr_block_detail takes care of the high-level adding and retrieving tags via the buffers/readers; also takes care of filtering tags by key. Tags are now added to the gr_buffers on 'which_output' while they are retrieved from the gr_buffer_reader based on 'which_input." --- gnuradio-core/src/lib/runtime/gr_block_detail.cc | 61 +++++++++--------------- gnuradio-core/src/lib/runtime/gr_block_detail.h | 5 +- gnuradio-core/src/lib/runtime/gr_buffer.cc | 35 +++++++++++++- gnuradio-core/src/lib/runtime/gr_buffer.h | 36 +++++++++++++- 4 files changed, 93 insertions(+), 44 deletions(-) (limited to 'gnuradio-core/src') diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.cc b/gnuradio-core/src/lib/runtime/gr_block_detail.cc index 2ab762a30..85b663ac6 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.cc @@ -158,65 +158,48 @@ gr_block_detail::add_item_tag(unsigned int which_output, throw pmt::pmt_wrong_type("gr_block_detail::set_item_tag key", key); } else { + // build tag tuple pmt::pmt_t nitem = pmt::pmt_from_uint64(abs_offset); pmt::pmt_t tuple = pmt::pmt_make_tuple(nitem, srcid, key, value); - d_item_tags.push_back(tuple); + + // Add tag to gr_buffer's deque tags + d_output[which_output]->add_item_tag(tuple); } } std::deque -gr_block_detail::get_tags_in_range(unsigned int which_output, +gr_block_detail::get_tags_in_range(unsigned int which_input, gr_uint64 abs_start, gr_uint64 abs_end) { - std::deque found_items; - std::deque::iterator itr = d_item_tags.begin(); - - gr_uint64 item_time; - while(itr != d_item_tags.end()) { - item_time = pmt::pmt_to_uint64(pmt::pmt_tuple_ref(*itr, 0)); - - // items are pushed onto list in sequential order; stop if we're past end - if(item_time > abs_end) { - break; - } - - if((item_time >= abs_start) && (item_time <= abs_end)) { - found_items.push_back(*itr); - } - - itr++; - } - - return found_items; + // get from gr_buffer_reader's deque of tags + return d_input[which_input]->get_tags_in_range(which_input, + abs_start, + abs_end); } std::deque -gr_block_detail::get_tags_in_range(unsigned int which_output, +gr_block_detail::get_tags_in_range(unsigned int which_input, gr_uint64 abs_start, gr_uint64 abs_end, const pmt::pmt_t &key) { - std::deque found_items; - std::deque::iterator itr = d_item_tags.begin(); - - gr_uint64 item_time; - pmt::pmt_t itemkey; - while(itr != d_item_tags.end()) { - item_time = pmt::pmt_to_uint64(pmt::pmt_tuple_ref(*itr, 0)); + std::deque found_items, found_items_by_key; - // items are pushed onto list in sequential order; stop if we're past end - if(item_time > abs_end) { - break; - } + // get from gr_buffer_reader's deque of tags + found_items = d_input[which_input]->get_tags_in_range(which_input, + abs_start, + abs_end); + // Filter further by key name + pmt::pmt_t itemkey; + std::deque::iterator itr; + for(itr = found_items.begin(); itr != found_items.end(); itr++) { itemkey = pmt::pmt_tuple_ref(*itr, 2); - if((item_time >= abs_start) && (item_time <= abs_end) && pmt::pmt_eqv(key, itemkey)) { - found_items.push_back(*itr); + if(pmt::pmt_eqv(key, itemkey)) { + found_items_by_key.push_back(*itr); } - - itr++; } - return found_items; + return found_items_by_key; } diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.h b/gnuradio-core/src/lib/runtime/gr_block_detail.h index 547d7c22f..ada807f68 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.h +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.h @@ -119,8 +119,8 @@ class gr_block_detail { /*! * \brief Given a [start,end), returns a deque copy of all tags in the range. * - * Pass-through function to gr_buffer to get a deque of tags in given range. - * Range of counts is from start to end-1. + * Pass-through function to gr_buffer_reader to get a deque of tags + * in given range. Range of counts is from start to end-1. * * Tags are tuples of: * (item count, source id, key, value) @@ -165,7 +165,6 @@ class gr_block_detail { unsigned int d_noutputs; std::vector d_input; std::vector d_output; - std::deque d_item_tags; bool d_done; diff --git a/gnuradio-core/src/lib/runtime/gr_buffer.cc b/gnuradio-core/src/lib/runtime/gr_buffer.cc index 89db99b69..da7866f48 100644 --- a/gnuradio-core/src/lib/runtime/gr_buffer.cc +++ b/gnuradio-core/src/lib/runtime/gr_buffer.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2004,2009 Free Software Foundation, Inc. + * Copyright 2004,2009,2010 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -216,6 +216,12 @@ gr_buffer::drop_reader (gr_buffer_reader *reader) d_readers.erase (result); } +void +gr_buffer::add_item_tag(const pmt::pmt_t &tag) +{ + d_item_tags.push_back(tag); +} + long gr_buffer_ncurrently_allocated () { @@ -257,6 +263,33 @@ gr_buffer_reader::update_read_pointer (int nitems) d_abs_read_offset += nitems; } +std::deque +gr_buffer_reader::get_tags_in_range(unsigned int which_output, + gr_uint64 abs_start, + gr_uint64 abs_end) +{ + std::deque found_items; + std::deque::iterator itr = d_item_tags.begin(); + + gr_uint64 item_time; + while(itr != d_item_tags.end()) { + item_time = pmt::pmt_to_uint64(pmt::pmt_tuple_ref(*itr, 0)); + + // items are pushed onto list in sequential order; stop if we're past end + if(item_time > abs_end) { + break; + } + + if((item_time >= abs_start) && (item_time <= abs_end)) { + found_items.push_back(*itr); + } + + itr++; + } + + return found_items; +} + long gr_buffer_reader_ncurrently_allocated () { diff --git a/gnuradio-core/src/lib/runtime/gr_buffer.h b/gnuradio-core/src/lib/runtime/gr_buffer.h index 8af72741a..e50f638b5 100644 --- a/gnuradio-core/src/lib/runtime/gr_buffer.h +++ b/gnuradio-core/src/lib/runtime/gr_buffer.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2004,2009 Free Software Foundation, Inc. + * Copyright 2004,2009,2010 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -26,6 +26,7 @@ #include #include #include +#include class gr_vmcircbuf; @@ -90,6 +91,19 @@ class gr_buffer { gr_uint64 nitems_written() { return d_abs_write_offset; } + + /*! + * \brief Adds a new tag to the deque of tags on a given buffer. + * + * Adds a new tag to deque of tags on a given buffer. This takes the input + * parameters and builds a PMT tuple from it. It then calls + * gr_buffer::add_item_tag(pmt::pmt_t t), which appends the + * tag onto its deque of tags. + * + * \param tag a PMT tuple containing the new tag + */ + void add_item_tag(const pmt::pmt_t &tag); + // ------------------------------------------------------------------------- private: @@ -107,6 +121,8 @@ class gr_buffer { std::vector d_readers; boost::weak_ptr d_link; // block that writes to this buffer + std::deque d_item_tags; + // // The mutex protects d_write_index, d_abs_write_offset, d_done and the d_read_index's // and d_abs_read_offset's in the buffer readers. @@ -232,6 +248,23 @@ class gr_buffer_reader { */ gr_block_sptr link() { return gr_block_sptr(d_link); } + + /*! + * \brief Given a [start,end), returns a deque copy of all tags in the range. + * + * Get a deque of tags in given range. Range of counts is from start to end-1. + * + * Tags are tuples of: + * (item count, source id, key, value) + * + * \param which_input an integer of which input stream to pull from + * \param abs_start a uint64 count of the start of the range of interest + * \param abs_end a uint64 count of the end of the range of interest + */ + std::deque get_tags_in_range(unsigned int which_input, + gr_uint64 abs_start, + gr_uint64 abs_end); + // ------------------------------------------------------------------------- private: @@ -245,6 +278,7 @@ class gr_buffer_reader { unsigned int d_read_index; // in items [0,d->buffer.d_bufsize) gr_uint64 d_abs_read_offset; // num items seen since the start boost::weak_ptr d_link; // block that reads via this buffer reader + std::deque d_item_tags; //! constructor is private. Use gr_buffer::add_reader to create instances gr_buffer_reader (gr_buffer_sptr buffer, unsigned int read_index, gr_block_sptr link); -- cgit From 7f6f2a377bf8bca6880ecc030792202e09b631a7 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Thu, 4 Nov 2010 18:30:17 -0400 Subject: gr_buffer_reader doesn't need to know which input it is. --- gnuradio-core/src/lib/runtime/gr_buffer.cc | 3 +-- gnuradio-core/src/lib/runtime/gr_buffer.h | 4 +--- 2 files changed, 2 insertions(+), 5 deletions(-) (limited to 'gnuradio-core/src') diff --git a/gnuradio-core/src/lib/runtime/gr_buffer.cc b/gnuradio-core/src/lib/runtime/gr_buffer.cc index da7866f48..58cffe495 100644 --- a/gnuradio-core/src/lib/runtime/gr_buffer.cc +++ b/gnuradio-core/src/lib/runtime/gr_buffer.cc @@ -264,8 +264,7 @@ gr_buffer_reader::update_read_pointer (int nitems) } std::deque -gr_buffer_reader::get_tags_in_range(unsigned int which_output, - gr_uint64 abs_start, +gr_buffer_reader::get_tags_in_range(gr_uint64 abs_start, gr_uint64 abs_end) { std::deque found_items; diff --git a/gnuradio-core/src/lib/runtime/gr_buffer.h b/gnuradio-core/src/lib/runtime/gr_buffer.h index e50f638b5..6498ee296 100644 --- a/gnuradio-core/src/lib/runtime/gr_buffer.h +++ b/gnuradio-core/src/lib/runtime/gr_buffer.h @@ -257,12 +257,10 @@ class gr_buffer_reader { * Tags are tuples of: * (item count, source id, key, value) * - * \param which_input an integer of which input stream to pull from * \param abs_start a uint64 count of the start of the range of interest * \param abs_end a uint64 count of the end of the range of interest */ - std::deque get_tags_in_range(unsigned int which_input, - gr_uint64 abs_start, + std::deque get_tags_in_range(gr_uint64 abs_start, gr_uint64 abs_end); // ------------------------------------------------------------------------- -- cgit From bf079e66e50f4aff775175c288e952b6325ea71c Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Thu, 4 Nov 2010 18:36:05 -0400 Subject: Fixing api call to gr_buffer_reader that no longer takes in which_input. --- gnuradio-core/src/lib/runtime/gr_block_detail.cc | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'gnuradio-core/src') diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.cc b/gnuradio-core/src/lib/runtime/gr_block_detail.cc index 85b663ac6..de4fb2196 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.cc @@ -173,9 +173,7 @@ gr_block_detail::get_tags_in_range(unsigned int which_input, gr_uint64 abs_end) { // get from gr_buffer_reader's deque of tags - return d_input[which_input]->get_tags_in_range(which_input, - abs_start, - abs_end); + return d_input[which_input]->get_tags_in_range(abs_start, abs_end); } std::deque @@ -187,9 +185,7 @@ gr_block_detail::get_tags_in_range(unsigned int which_input, std::deque found_items, found_items_by_key; // get from gr_buffer_reader's deque of tags - found_items = d_input[which_input]->get_tags_in_range(which_input, - abs_start, - abs_end); + found_items = d_input[which_input]->get_tags_in_range(abs_start, abs_end); // Filter further by key name pmt::pmt_t itemkey; -- cgit From d58d250c82ff8b106aec02f5222cea385b74d729 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sat, 6 Nov 2010 13:03:28 -0400 Subject: buffer_reader does not hold its own tags but looks upstream to the associated buffer to get them. --- gnuradio-core/src/lib/runtime/gr_buffer.cc | 4 ++-- gnuradio-core/src/lib/runtime/gr_buffer.h | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) (limited to 'gnuradio-core/src') diff --git a/gnuradio-core/src/lib/runtime/gr_buffer.cc b/gnuradio-core/src/lib/runtime/gr_buffer.cc index 58cffe495..9048d57a4 100644 --- a/gnuradio-core/src/lib/runtime/gr_buffer.cc +++ b/gnuradio-core/src/lib/runtime/gr_buffer.cc @@ -268,10 +268,10 @@ gr_buffer_reader::get_tags_in_range(gr_uint64 abs_start, gr_uint64 abs_end) { std::deque found_items; - std::deque::iterator itr = d_item_tags.begin(); + std::deque::iterator itr = d_buffer->get_tags_begin(); gr_uint64 item_time; - while(itr != d_item_tags.end()) { + while(itr != d_buffer->get_tags_end()) { item_time = pmt::pmt_to_uint64(pmt::pmt_tuple_ref(*itr, 0)); // items are pushed onto list in sequential order; stop if we're past end diff --git a/gnuradio-core/src/lib/runtime/gr_buffer.h b/gnuradio-core/src/lib/runtime/gr_buffer.h index 6498ee296..8174b7e67 100644 --- a/gnuradio-core/src/lib/runtime/gr_buffer.h +++ b/gnuradio-core/src/lib/runtime/gr_buffer.h @@ -104,6 +104,9 @@ class gr_buffer { */ void add_item_tag(const pmt::pmt_t &tag); + std::deque::iterator get_tags_begin() { return d_item_tags.begin(); } + std::deque::iterator get_tags_end() { return d_item_tags.end(); } + // ------------------------------------------------------------------------- private: @@ -121,7 +124,7 @@ class gr_buffer { std::vector d_readers; boost::weak_ptr d_link; // block that writes to this buffer - std::deque d_item_tags; + std::deque d_item_tags; // temp. store tags until moved to reader // // The mutex protects d_write_index, d_abs_write_offset, d_done and the d_read_index's @@ -276,7 +279,6 @@ class gr_buffer_reader { unsigned int d_read_index; // in items [0,d->buffer.d_bufsize) gr_uint64 d_abs_read_offset; // num items seen since the start boost::weak_ptr d_link; // block that reads via this buffer reader - std::deque d_item_tags; //! constructor is private. Use gr_buffer::add_reader to create instances gr_buffer_reader (gr_buffer_sptr buffer, unsigned int read_index, gr_block_sptr link); -- cgit From 6cc6925ec231897a2e46f3d7bfb52ba3aecfc492 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sat, 6 Nov 2010 13:18:32 -0400 Subject: Better formatting of tag information to make info more readable. --- gnuradio-core/src/lib/runtime/gr_random_annotator.cc | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'gnuradio-core/src') diff --git a/gnuradio-core/src/lib/runtime/gr_random_annotator.cc b/gnuradio-core/src/lib/runtime/gr_random_annotator.cc index bd74f5b84..d9ad15a55 100644 --- a/gnuradio-core/src/lib/runtime/gr_random_annotator.cc +++ b/gnuradio-core/src/lib/runtime/gr_random_annotator.cc @@ -28,6 +28,7 @@ #include #include #include +#include gr_random_annotator_sptr gr_make_random_annotator (size_t sizeof_stream_item) @@ -55,18 +56,27 @@ gr_random_annotator::work (int noutput_items, const float **in = (const float **) &input_items[0]; float **out = (float **) &output_items[0]; + std::stringstream str; + str << name() << unique_id(); + gr_uint64 abs_N = nitems_written(0); std::deque all_tags = get_tags_in_range(0, (gr_uint64)0, abs_N); std::deque::iterator itr; std::cout << std::endl << "Found " << all_tags.size() << " tags." << std::endl; + + std::cout.setf(std::ios::left); + std::cout << std::setw(25) << "Receiver" << std::setw(25) << "Sender" + << std::setw(10) << "nitem" << std::setw(20) << "key" + << std::setw(10) << "value" << 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; + std::cout << std::setw(25) << str.str() << std::setw(25) << srcid + << std::setw(10) << nitem << std::setw(20) << key + << std::setw(10) << value << std::endl; } // Work does nothing to the data stream; just copy all inputs to outputs @@ -76,8 +86,6 @@ gr_random_annotator::work (int noutput_items, } // 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"); -- cgit From 20adc2d657d189cd07f9585aeb4cb213ffe0bb07 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sat, 6 Nov 2010 14:17:04 -0400 Subject: Because tags can be appended from upstream, they are not consecutive in time, so we need to cycle through them all. --- gnuradio-core/src/lib/runtime/gr_buffer.cc | 5 ----- 1 file changed, 5 deletions(-) (limited to 'gnuradio-core/src') diff --git a/gnuradio-core/src/lib/runtime/gr_buffer.cc b/gnuradio-core/src/lib/runtime/gr_buffer.cc index 9048d57a4..8387a3168 100644 --- a/gnuradio-core/src/lib/runtime/gr_buffer.cc +++ b/gnuradio-core/src/lib/runtime/gr_buffer.cc @@ -274,11 +274,6 @@ gr_buffer_reader::get_tags_in_range(gr_uint64 abs_start, while(itr != d_buffer->get_tags_end()) { item_time = pmt::pmt_to_uint64(pmt::pmt_tuple_ref(*itr, 0)); - // items are pushed onto list in sequential order; stop if we're past end - if(item_time > abs_end) { - break; - } - if((item_time >= abs_start) && (item_time <= abs_end)) { found_items.push_back(*itr); } -- cgit From 8b184fda9da4e7fdf08ddfd4d973d5d8d83be308 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sat, 6 Nov 2010 14:18:32 -0400 Subject: Adding call in scheduler to handle tag movements between blocks and some helper functions to get access and keep track of tags. --- gnuradio-core/src/lib/runtime/gr_block.cc | 7 +++++++ gnuradio-core/src/lib/runtime/gr_block.h | 9 +++++++++ gnuradio-core/src/lib/runtime/gr_block_detail.cc | 19 ++++++++++++++++++- gnuradio-core/src/lib/runtime/gr_block_detail.h | 9 +++++++++ gnuradio-core/src/lib/runtime/gr_buffer.h | 18 +++++++++++++++++- gnuradio-core/src/lib/runtime/gr_tpb_thread_body.cc | 2 ++ 6 files changed, 62 insertions(+), 2 deletions(-) (limited to 'gnuradio-core/src') diff --git a/gnuradio-core/src/lib/runtime/gr_block.cc b/gnuradio-core/src/lib/runtime/gr_block.cc index eb377953d..51eb5b498 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_block.cc @@ -166,6 +166,13 @@ gr_block::get_tags_in_range(unsigned int which_output, return d_detail->get_tags_in_range(which_output, start, end, key); } +void +gr_block::handle_tags() +{ + d_detail->handle_tags(); +} + + std::ostream& operator << (std::ostream& os, const gr_block *m) { diff --git a/gnuradio-core/src/lib/runtime/gr_block.h b/gnuradio-core/src/lib/runtime/gr_block.h index 25886eb10..89d762847 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.h +++ b/gnuradio-core/src/lib/runtime/gr_block.h @@ -209,6 +209,15 @@ class gr_block : public gr_basic_block { */ gr_uint64 nitems_written(unsigned int which_output); + + /*! + * \brief Function to move tags downstream + * + * The default behavior proxies to gr_block_detail, which just moves all tags + * from input to output and flows them all downstream. + */ + virtual void handle_tags(); + // ---------------------------------------------------------------------------- private: diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.cc b/gnuradio-core/src/lib/runtime/gr_block_detail.cc index de4fb2196..7994919d4 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.cc @@ -39,7 +39,8 @@ gr_block_detail::gr_block_detail (unsigned int ninputs, unsigned int noutputs) : d_produce_or(0), d_ninputs (ninputs), d_noutputs (noutputs), d_input (ninputs), d_output (noutputs), - d_done (false) + d_done (false), + d_last_tag(0) { s_ncurrently_allocated++; } @@ -199,3 +200,19 @@ gr_block_detail::get_tags_in_range(unsigned int which_input, return found_items_by_key; } + +void +gr_block_detail::handle_tags() +{ + for(unsigned int i = 0; i < d_ninputs; i++) { + pmt::pmt_t tuple; + while(d_input[i]->get_tag(d_last_tag, tuple)) { + d_last_tag++; + if(!sink_p()) { + for(unsigned int o = 0; o < d_noutputs; o++) { + d_output[o]->add_item_tag(tuple); + } + } + } + } +} diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.h b/gnuradio-core/src/lib/runtime/gr_block_detail.h index ada807f68..cbb59a689 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.h +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.h @@ -155,6 +155,14 @@ class gr_block_detail { gr_uint64 abs_end, const pmt::pmt_t &key); + /*! + * \brief Default tag handler; moves all tags downstream + * + * Move all tags from input to output and flows them all downstream. Each input + * stream's tags get appended to each output streams tags. + */ + void handle_tags(); + gr_tpb_detail d_tpb; // used by thread-per-block scheduler int d_produce_or; @@ -167,6 +175,7 @@ class gr_block_detail { std::vector d_output; bool d_done; + size_t d_last_tag; // keep track of which tags we've already received from upstream gr_block_detail (unsigned int ninputs, unsigned int noutputs); diff --git a/gnuradio-core/src/lib/runtime/gr_buffer.h b/gnuradio-core/src/lib/runtime/gr_buffer.h index 8174b7e67..6dcbff0b9 100644 --- a/gnuradio-core/src/lib/runtime/gr_buffer.h +++ b/gnuradio-core/src/lib/runtime/gr_buffer.h @@ -107,6 +107,17 @@ class gr_buffer { std::deque::iterator get_tags_begin() { return d_item_tags.begin(); } std::deque::iterator get_tags_end() { return d_item_tags.end(); } + bool get_tag(size_t n, pmt::pmt_t &t) + { + if(n < d_item_tags.size()) { + t = d_item_tags[n]; + return true; + } + else { + return false; + } + } + // ------------------------------------------------------------------------- private: @@ -265,7 +276,12 @@ class gr_buffer_reader { */ std::deque get_tags_in_range(gr_uint64 abs_start, gr_uint64 abs_end); - + + bool get_tag(size_t n, pmt::pmt_t &t) + { + return d_buffer->get_tag(n, t); + } + // ------------------------------------------------------------------------- private: diff --git a/gnuradio-core/src/lib/runtime/gr_tpb_thread_body.cc b/gnuradio-core/src/lib/runtime/gr_tpb_thread_body.cc index 03eef17d9..6a84f4be8 100644 --- a/gnuradio-core/src/lib/runtime/gr_tpb_thread_body.cc +++ b/gnuradio-core/src/lib/runtime/gr_tpb_thread_body.cc @@ -45,6 +45,8 @@ gr_tpb_thread_body::gr_tpb_thread_body(gr_block_sptr block) while ((msg = d->d_tpb.delete_head_nowait())) block->handle_msg(msg); + block->handle_tags(); + d->d_tpb.clear_changed(); s = d_exec.run_one_iteration(); -- cgit From cafe83aa6bd47f8e05bd347cc4495d3662b5440f Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sat, 6 Nov 2010 14:24:19 -0400 Subject: Don't directly output tag info to screen from gr_random_annotator; instead, store the stream and write it to stdout when block is being destroyed. This avoids issues of the muliple threads writing simultaneously to screen. --- gnuradio-core/src/lib/runtime/gr_random_annotator.cc | 20 +++++++++++--------- gnuradio-core/src/lib/runtime/gr_random_annotator.h | 1 + gnuradio-core/src/lib/runtime/qa_block_tags.cc | 4 +++- 3 files changed, 15 insertions(+), 10 deletions(-) (limited to 'gnuradio-core/src') diff --git a/gnuradio-core/src/lib/runtime/gr_random_annotator.cc b/gnuradio-core/src/lib/runtime/gr_random_annotator.cc index d9ad15a55..93d9aa793 100644 --- a/gnuradio-core/src/lib/runtime/gr_random_annotator.cc +++ b/gnuradio-core/src/lib/runtime/gr_random_annotator.cc @@ -46,6 +46,7 @@ gr_random_annotator::gr_random_annotator (size_t sizeof_stream_item) gr_random_annotator::~gr_random_annotator () { + std::cout << d_sout.str(); } int @@ -62,21 +63,22 @@ gr_random_annotator::work (int noutput_items, gr_uint64 abs_N = nitems_written(0); std::deque all_tags = get_tags_in_range(0, (gr_uint64)0, abs_N); std::deque::iterator itr; - std::cout << std::endl << "Found " << all_tags.size() << " tags." << std::endl; - std::cout.setf(std::ios::left); - std::cout << std::setw(25) << "Receiver" << std::setw(25) << "Sender" - << std::setw(10) << "nitem" << std::setw(20) << "key" - << std::setw(10) << "value" << std::endl; + d_sout << std::endl << "Found " << all_tags.size() << " tags." << std::endl; + d_sout.setf(std::ios::left); + d_sout << std::setw(25) << "Receiver" << std::setw(25) << "Sender" + << std::setw(10) << "nitem" << std::setw(20) << "key" + << std::setw(10) << "value" << 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 << std::setw(25) << str.str() << std::setw(25) << srcid - << std::setw(10) << nitem << std::setw(20) << key - << std::setw(10) << value << std::endl; + d_sout << std::setw(25) << str.str() << std::setw(25) << srcid + << std::setw(10) << nitem << std::setw(20) << key + << std::setw(10) << value << std::endl; } // Work does nothing to the data stream; just copy all inputs to outputs @@ -86,7 +88,7 @@ gr_random_annotator::work (int noutput_items, } // Storing the current noutput_items as the value to the "noutput_items" key - pmt::pmt_t cur_N = pmt::pmt_from_uint64(noutput_items); + pmt::pmt_t cur_N = pmt::pmt_from_uint64(random()); 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); diff --git a/gnuradio-core/src/lib/runtime/gr_random_annotator.h b/gnuradio-core/src/lib/runtime/gr_random_annotator.h index 7f200eff7..3f21b71ad 100644 --- a/gnuradio-core/src/lib/runtime/gr_random_annotator.h +++ b/gnuradio-core/src/lib/runtime/gr_random_annotator.h @@ -45,6 +45,7 @@ protected: private: size_t d_itemsize; + std::stringstream d_sout; friend gr_random_annotator_sptr gr_make_random_annotator (size_t sizeof_stream_item); diff --git a/gnuradio-core/src/lib/runtime/qa_block_tags.cc b/gnuradio-core/src/lib/runtime/qa_block_tags.cc index 7fe1b4bfd..ab3db6653 100644 --- a/gnuradio-core/src/lib/runtime/qa_block_tags.cc +++ b/gnuradio-core/src/lib/runtime/qa_block_tags.cc @@ -75,12 +75,14 @@ qa_block_tags::t1 () 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 ann2 (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, ann0, 0); tb->connect(ann0, 0, ann1, 0); - tb->connect(ann1, 0, snk, 0); + tb->connect(ann1, 0, ann2, 0); + tb->connect(ann2, 0, snk, 0); tb->run(); } -- cgit From 95eaad323daecbd2c4c0a7aaf5176f9a1b33eec0 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sun, 7 Nov 2010 16:05:08 -0500 Subject: Cleaning up. Better use of PMTs; comment mods; returning vectors when getting tags. --- gnuradio-core/src/lib/runtime/gr_block.cc | 14 +++--- gnuradio-core/src/lib/runtime/gr_block.h | 38 ++++++++-------- gnuradio-core/src/lib/runtime/gr_block.i | 4 +- gnuradio-core/src/lib/runtime/gr_block_detail.cc | 50 +++++++++++----------- gnuradio-core/src/lib/runtime/gr_block_detail.h | 42 +++++++++--------- gnuradio-core/src/lib/runtime/gr_buffer.cc | 10 ++--- gnuradio-core/src/lib/runtime/gr_buffer.h | 23 ++++------ .../src/lib/runtime/gr_random_annotator.cc | 20 ++++----- gnuradio-core/src/lib/runtime/qa_block_tags.cc | 6 +-- 9 files changed, 98 insertions(+), 109 deletions(-) (limited to 'gnuradio-core/src') diff --git a/gnuradio-core/src/lib/runtime/gr_block.cc b/gnuradio-core/src/lib/runtime/gr_block.cc index 51eb5b498..73a86e38b 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_block.cc @@ -117,7 +117,7 @@ gr_block::fixed_rate_noutput_to_ninput(int noutput) throw std::runtime_error("Unimplemented"); } -gr_uint64 +uint64_t gr_block::nitems_read(unsigned int which_input) { if(d_detail) { @@ -129,7 +129,7 @@ gr_block::nitems_read(unsigned int which_input) } } -gr_uint64 +uint64_t gr_block::nitems_written(unsigned int which_output) { if(d_detail) { @@ -143,7 +143,7 @@ gr_block::nitems_written(unsigned int which_output) void gr_block::add_item_tag(unsigned int which_output, - gr_uint64 offset, + uint64_t offset, const pmt::pmt_t &key, const pmt::pmt_t &value, const pmt::pmt_t &srcid) @@ -151,16 +151,16 @@ gr_block::add_item_tag(unsigned int which_output, d_detail->add_item_tag(which_output, offset, key, value, srcid); } -std::deque +std::vector gr_block::get_tags_in_range(unsigned int which_output, - gr_uint64 start, gr_uint64 end) + uint64_t start, uint64_t end) { return d_detail->get_tags_in_range(which_output, start, end); } -std::deque +std::vector gr_block::get_tags_in_range(unsigned int which_output, - gr_uint64 start, gr_uint64 end, + uint64_t start, uint64_t end, const pmt::pmt_t &key) { return d_detail->get_tags_in_range(which_output, start, end, key); diff --git a/gnuradio-core/src/lib/runtime/gr_block.h b/gnuradio-core/src/lib/runtime/gr_block.h index 89d762847..4d1d6f875 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.h +++ b/gnuradio-core/src/lib/runtime/gr_block.h @@ -24,7 +24,6 @@ #define INCLUDED_GR_BLOCK_H #include -#include /*! * \brief The abstract base class for all 'terminal' processing blocks. @@ -202,12 +201,12 @@ class gr_block : public gr_basic_block { /*! * \brief Return the number of items read on input stream which_input */ - gr_uint64 nitems_read(unsigned int which_input); + uint64_t nitems_read(unsigned int which_input); /*! * \brief Return the number of items written on output stream which_output */ - gr_uint64 nitems_written(unsigned int which_output); + uint64_t nitems_written(unsigned int which_output); /*! @@ -238,28 +237,25 @@ class gr_block : public gr_basic_block { /*! - * \brief Adds a new tag to the deque of tags on a given buffer. + * \brief Adds a new tag onto the given output buffer. * - * This is a call-through method to gr_block_detail to add the new tag. - * gr_block_detail takes care of formatting the tuple from the inputs here, - * it then calls gr_buffer::add_item_tag(pmt::pmt_t t), which appends the - * tag onto its deque of tags. + * This is a call-through method to gr_block_detail. * * \param which_ouput an integer of which output stream to attach the tag * \param abs_offset a uint64 number of the absolute item number * assicated with the tag. Can get from nitems_written. - * \param key a PMT symbol holding the key name (i.e., a string) + * \param key a PMT symbol holding the key name * \param value any PMT holding any value for the given key - * \param srcid optional source ID specifier; defauls to string "NA" + * \param srcid optional source ID specifier; defaults to PMT_F */ void add_item_tag(unsigned int which_output, - gr_uint64 abs_offset, + uint64_t abs_offset, const pmt::pmt_t &key, const pmt::pmt_t &value, - const pmt::pmt_t &srcid=pmt::pmt_string_to_symbol("NA")); + const pmt::pmt_t &srcid=pmt::PMT_F); /*! - * \brief Given a [start,end), returns a deque copy of all tags in the range. + * \brief Given a [start,end), returns a vector of all tags in the range. * * Pass-through function to gr_block_detail. Range of counts is from * start to end-1. @@ -271,12 +267,12 @@ class gr_block : public gr_basic_block { * \param abs_start a uint64 count of the start of the range of interest * \param abs_end a uint64 count of the end of the range of interest */ - std::deque get_tags_in_range(unsigned int which_input, - gr_uint64 abs_start, - gr_uint64 abs_end); + std::vector get_tags_in_range(unsigned int which_input, + uint64_t abs_start, + uint64_t abs_end); /*! - * \brief Given a [start,end), returns a deque copy of all tags in the range + * \brief Given a [start,end), returns a vector of all tags in the range * with a given key. * * Pass-through function to gr_block_detail. Range of counts is from @@ -290,10 +286,10 @@ class gr_block : public gr_basic_block { * \param abs_end a uint64 count of the end of the range of interest * \param key a PMT symbol key to filter only tags of this key */ - std::deque get_tags_in_range(unsigned int which_input, - gr_uint64 abs_start, - gr_uint64 abs_end, - const pmt::pmt_t &key); + std::vector get_tags_in_range(unsigned int which_input, + uint64_t abs_start, + uint64_t abs_end, + const pmt::pmt_t &key); // These are really only for internal use, but leaving them public avoids diff --git a/gnuradio-core/src/lib/runtime/gr_block.i b/gnuradio-core/src/lib/runtime/gr_block.i index e6ea06060..2de354878 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.i +++ b/gnuradio-core/src/lib/runtime/gr_block.i @@ -49,8 +49,8 @@ class gr_block : public gr_basic_block { bool start(); bool stop(); - gr_uint64 nitems_read(unsigned int which_input); - gr_uint64 nitems_written(unsigned int which_output); + uint64_t nitems_read(unsigned int which_input); + uint64_t nitems_written(unsigned int which_output); // internal use gr_block_detail_sptr detail () const { return d_detail; } diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.cc b/gnuradio-core/src/lib/runtime/gr_block_detail.cc index 7994919d4..b3d1a7194 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.cc @@ -27,6 +27,8 @@ #include #include +using namespace pmt; + static long s_ncurrently_allocated = 0; long @@ -127,12 +129,12 @@ gr_block_detail::produce_each (int how_many_items) void -gr_block_detail::_post(pmt::pmt_t msg) +gr_block_detail::_post(pmt_t msg) { d_tpb.insert_tail(msg); } -gr_uint64 +uint64_t gr_block_detail::nitems_read(unsigned int which_input) { if(which_input >= d_ninputs) @@ -140,7 +142,7 @@ gr_block_detail::nitems_read(unsigned int which_input) return d_input[which_input]->nitems_read(); } -gr_uint64 +uint64_t gr_block_detail::nitems_written(unsigned int which_output) { if(which_output >= d_noutputs) @@ -150,50 +152,50 @@ gr_block_detail::nitems_written(unsigned int which_output) void gr_block_detail::add_item_tag(unsigned int which_output, - gr_uint64 abs_offset, - const pmt::pmt_t &key, - const pmt::pmt_t &value, - const pmt::pmt_t &srcid) + uint64_t abs_offset, + const pmt_t &key, + const pmt_t &value, + const pmt_t &srcid) { - if(pmt::pmt_is_symbol(key) == false) { - throw pmt::pmt_wrong_type("gr_block_detail::set_item_tag key", key); + if(!pmt_is_symbol(key)) { + throw pmt_wrong_type("gr_block_detail::set_item_tag key", key); } else { // build tag tuple - pmt::pmt_t nitem = pmt::pmt_from_uint64(abs_offset); - pmt::pmt_t tuple = pmt::pmt_make_tuple(nitem, srcid, key, value); + pmt_t nitem = pmt_from_uint64(abs_offset); + pmt_t tuple = pmt_make_tuple(nitem, srcid, key, value); // Add tag to gr_buffer's deque tags d_output[which_output]->add_item_tag(tuple); } } -std::deque +std::vector gr_block_detail::get_tags_in_range(unsigned int which_input, - gr_uint64 abs_start, - gr_uint64 abs_end) + uint64_t abs_start, + uint64_t abs_end) { // get from gr_buffer_reader's deque of tags return d_input[which_input]->get_tags_in_range(abs_start, abs_end); } -std::deque +std::vector gr_block_detail::get_tags_in_range(unsigned int which_input, - gr_uint64 abs_start, - gr_uint64 abs_end, - const pmt::pmt_t &key) + uint64_t abs_start, + uint64_t abs_end, + const pmt_t &key) { - std::deque found_items, found_items_by_key; + std::vector found_items, found_items_by_key; // get from gr_buffer_reader's deque of tags found_items = d_input[which_input]->get_tags_in_range(abs_start, abs_end); // Filter further by key name - pmt::pmt_t itemkey; - std::deque::iterator itr; + pmt_t itemkey; + std::vector::iterator itr; for(itr = found_items.begin(); itr != found_items.end(); itr++) { - itemkey = pmt::pmt_tuple_ref(*itr, 2); - if(pmt::pmt_eqv(key, itemkey)) { + itemkey = pmt_tuple_ref(*itr, 2); + if(pmt_eqv(key, itemkey)) { found_items_by_key.push_back(*itr); } } @@ -205,7 +207,7 @@ void gr_block_detail::handle_tags() { for(unsigned int i = 0; i < d_ninputs; i++) { - pmt::pmt_t tuple; + pmt_t tuple; while(d_input[i]->get_tag(d_last_tag, tuple)) { d_last_tag++; if(!sink_p()) { diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.h b/gnuradio-core/src/lib/runtime/gr_block_detail.h index cbb59a689..3a2b82190 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.h +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.h @@ -89,19 +89,18 @@ class gr_block_detail { void _post(pmt::pmt_t msg); // Return the number of items read on input stream which_input - gr_uint64 nitems_read(unsigned int which_input); + uint64_t nitems_read(unsigned int which_input); // Return the number of items written on output stream which_output - gr_uint64 nitems_written(unsigned int which_output); + uint64_t nitems_written(unsigned int which_output); /*! - * \brief Adds a new tag to the deque of tags on a given buffer. + * \brief Adds a new tag to the given output stream. * - * Adds a new tag to deque of tags on a given buffer. This takes the input - * parameters and builds a PMT tuple from it. It then calls - * gr_buffer::add_item_tag(pmt::pmt_t t), which appends the - * tag onto its deque of tags. + * This takes the input parameters and builds a PMT tuple + * from it. It then calls gr_buffer::add_item_tag(pmt::pmt_t t), + * which appends the tag onto its deque. * * \param which_ouput an integer of which output stream to attach the tag * \param abs_offset a uint64 number of the absolute item number @@ -111,15 +110,15 @@ class gr_block_detail { * \param srcid a PMT source ID specifier */ void add_item_tag(unsigned int which_output, - gr_uint64 abs_offset, + uint64_t abs_offset, const pmt::pmt_t &key, const pmt::pmt_t &value, const pmt::pmt_t &srcid); /*! - * \brief Given a [start,end), returns a deque copy of all tags in the range. + * \brief Given a [start,end), returns a vector of all tags in the range. * - * Pass-through function to gr_buffer_reader to get a deque of tags + * Pass-through function to gr_buffer_reader to get a vector of tags * in given range. Range of counts is from start to end-1. * * Tags are tuples of: @@ -129,18 +128,17 @@ class gr_block_detail { * \param abs_start a uint64 count of the start of the range of interest * \param abs_end a uint64 count of the end of the range of interest */ - std::deque get_tags_in_range(unsigned int which_input, - gr_uint64 abs_start, - gr_uint64 abs_end); + std::vector get_tags_in_range(unsigned int which_input, + uint64_t abs_start, + uint64_t abs_end); /*! - * \brief Given a [start,end), returns a deque copy of all tags in the range + * \brief Given a [start,end), returns a vector of all tags in the range * with a given key. * - * Calls get_tags_in_range(which_input, abs_start, abs_end) to get a deque of + * Calls get_tags_in_range(which_input, abs_start, abs_end) to get a vector of * tags from the buffers. This function then provides a secondary filter to - * the tags to extract only tags with the given 'key'. Returns a dequeu - * of these tags. + * the tags to extract only tags with the given 'key'. * * Tags are tuples of: * (item count, source id, key, value) @@ -148,12 +146,12 @@ class gr_block_detail { * \param which_input an integer of which input stream to pull from * \param abs_start a uint64 count of the start of the range of interest * \param abs_end a uint64 count of the end of the range of interest - * \param key a PMT symbol key to filter only tags of this key + * \param key a PMT symbol key to select only tags of this key */ - std::deque get_tags_in_range(unsigned int which_input, - gr_uint64 abs_start, - gr_uint64 abs_end, - const pmt::pmt_t &key); + std::vector get_tags_in_range(unsigned int which_input, + uint64_t abs_start, + uint64_t abs_end, + const pmt::pmt_t &key); /*! * \brief Default tag handler; moves all tags downstream diff --git a/gnuradio-core/src/lib/runtime/gr_buffer.cc b/gnuradio-core/src/lib/runtime/gr_buffer.cc index 8387a3168..862d92b81 100644 --- a/gnuradio-core/src/lib/runtime/gr_buffer.cc +++ b/gnuradio-core/src/lib/runtime/gr_buffer.cc @@ -263,14 +263,14 @@ gr_buffer_reader::update_read_pointer (int nitems) d_abs_read_offset += nitems; } -std::deque -gr_buffer_reader::get_tags_in_range(gr_uint64 abs_start, - gr_uint64 abs_end) +std::vector +gr_buffer_reader::get_tags_in_range(uint64_t abs_start, + uint64_t abs_end) { - std::deque found_items; + std::vector found_items; std::deque::iterator itr = d_buffer->get_tags_begin(); - gr_uint64 item_time; + uint64_t item_time; while(itr != d_buffer->get_tags_end()) { item_time = pmt::pmt_to_uint64(pmt::pmt_tuple_ref(*itr, 0)); diff --git a/gnuradio-core/src/lib/runtime/gr_buffer.h b/gnuradio-core/src/lib/runtime/gr_buffer.h index 6dcbff0b9..5b8f21c94 100644 --- a/gnuradio-core/src/lib/runtime/gr_buffer.h +++ b/gnuradio-core/src/lib/runtime/gr_buffer.h @@ -89,17 +89,12 @@ class gr_buffer { gruel::mutex *mutex() { return &d_mutex; } - gr_uint64 nitems_written() { return d_abs_write_offset; } + uint64_t nitems_written() { return d_abs_write_offset; } /*! - * \brief Adds a new tag to the deque of tags on a given buffer. + * \brief Adds a new tag to the buffer. * - * Adds a new tag to deque of tags on a given buffer. This takes the input - * parameters and builds a PMT tuple from it. It then calls - * gr_buffer::add_item_tag(pmt::pmt_t t), which appends the - * tag onto its deque of tags. - * * \param tag a PMT tuple containing the new tag */ void add_item_tag(const pmt::pmt_t &tag); @@ -143,7 +138,7 @@ class gr_buffer { // gruel::mutex d_mutex; unsigned int d_write_index; // in items [0,d_bufsize) - gr_uint64 d_abs_write_offset; // num items written since the start + uint64_t d_abs_write_offset; // num items written since the start //deq tag_tuples bool d_done; @@ -255,7 +250,7 @@ class gr_buffer_reader { gruel::mutex *mutex() { return d_buffer->mutex(); } - gr_uint64 nitems_read() { return d_abs_read_offset; } + uint64_t nitems_read() { return d_abs_read_offset; } /*! * \brief Return the block that reads via this reader. @@ -264,9 +259,9 @@ class gr_buffer_reader { /*! - * \brief Given a [start,end), returns a deque copy of all tags in the range. + * \brief Given a [start,end), returns a vector all tags in the range. * - * Get a deque of tags in given range. Range of counts is from start to end-1. + * Get a vector of tags in given range. Range of counts is from start to end-1. * * Tags are tuples of: * (item count, source id, key, value) @@ -274,8 +269,8 @@ class gr_buffer_reader { * \param abs_start a uint64 count of the start of the range of interest * \param abs_end a uint64 count of the end of the range of interest */ - std::deque get_tags_in_range(gr_uint64 abs_start, - gr_uint64 abs_end); + std::vector get_tags_in_range(uint64_t abs_start, + uint64_t abs_end); bool get_tag(size_t n, pmt::pmt_t &t) { @@ -293,7 +288,7 @@ class gr_buffer_reader { gr_buffer_sptr d_buffer; unsigned int d_read_index; // in items [0,d->buffer.d_bufsize) - gr_uint64 d_abs_read_offset; // num items seen since the start + uint64_t d_abs_read_offset; // num items seen since the start boost::weak_ptr d_link; // block that reads via this buffer reader //! constructor is private. Use gr_buffer::add_reader to create instances diff --git a/gnuradio-core/src/lib/runtime/gr_random_annotator.cc b/gnuradio-core/src/lib/runtime/gr_random_annotator.cc index 93d9aa793..d360c13a5 100644 --- a/gnuradio-core/src/lib/runtime/gr_random_annotator.cc +++ b/gnuradio-core/src/lib/runtime/gr_random_annotator.cc @@ -60,9 +60,9 @@ gr_random_annotator::work (int noutput_items, std::stringstream str; str << name() << unique_id(); - gr_uint64 abs_N = nitems_written(0); - std::deque all_tags = get_tags_in_range(0, (gr_uint64)0, abs_N); - std::deque::iterator itr; + uint64_t abs_N = nitems_written(0); + std::vector all_tags = get_tags_in_range(0, (uint64_t)0, abs_N); + std::vector::iterator itr; d_sout << std::endl << "Found " << all_tags.size() << " tags." << std::endl; d_sout.setf(std::ios::left); @@ -71,14 +71,12 @@ gr_random_annotator::work (int noutput_items, << std::setw(10) << "value" << 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)); - - d_sout << std::setw(25) << str.str() << std::setw(25) << srcid - << std::setw(10) << nitem << std::setw(20) << key - << std::setw(10) << value << std::endl; + d_sout << std::setw(25) << str.str() + << std::setw(25) << pmt::pmt_tuple_ref(*itr, 1) + << std::setw(10) << pmt::pmt_tuple_ref(*itr, 0) + << std::setw(20) << pmt::pmt_tuple_ref(*itr, 2) + << std::setw(10) << pmt::pmt_tuple_ref(*itr, 3) + << std::endl; } // Work does nothing to the data stream; just copy all inputs to outputs diff --git a/gnuradio-core/src/lib/runtime/qa_block_tags.cc b/gnuradio-core/src/lib/runtime/qa_block_tags.cc index ab3db6653..2fedb28fd 100644 --- a/gnuradio-core/src/lib/runtime/qa_block_tags.cc +++ b/gnuradio-core/src/lib/runtime/qa_block_tags.cc @@ -52,14 +52,14 @@ qa_block_tags::t0 () //CPPUNIT_ASSERT_THROW(src->nitems_read(0), std::runtime_error); //CPPUNIT_ASSERT_THROW(src->nitems_written(0), std::runtime_error); - CPPUNIT_ASSERT_EQUAL(src->nitems_read(0), (gr_uint64)0); - CPPUNIT_ASSERT_EQUAL(src->nitems_written(0), (gr_uint64)0); + CPPUNIT_ASSERT_EQUAL(src->nitems_read(0), (uint64_t)0); + CPPUNIT_ASSERT_EQUAL(src->nitems_written(0), (uint64_t)0); tb->run(); CPPUNIT_ASSERT_THROW(src->nitems_read(0), std::invalid_argument); CPPUNIT_ASSERT(src->nitems_written(0) >= N); - CPPUNIT_ASSERT_EQUAL(snk->nitems_read(0), (gr_uint64)1000); + CPPUNIT_ASSERT_EQUAL(snk->nitems_read(0), (uint64_t)1000); CPPUNIT_ASSERT_THROW(snk->nitems_written(0), std::invalid_argument); } -- cgit From 3bf4a8423acded7743470adffcd9dcc57b049560 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sun, 7 Nov 2010 17:30:59 -0500 Subject: Moving tags downstream is moved into gr_block_executor. Predefined three methods of moving tags that are selectable by a gr_block. --- gnuradio-core/src/lib/runtime/gr_block.cc | 11 ++++-- gnuradio-core/src/lib/runtime/gr_block.h | 10 +---- gnuradio-core/src/lib/runtime/gr_block_detail.cc | 28 +++++++------- gnuradio-core/src/lib/runtime/gr_block_detail.h | 19 +++++----- gnuradio-core/src/lib/runtime/gr_block_executor.cc | 43 ++++++++++++++++++++++ .../src/lib/runtime/gr_tpb_thread_body.cc | 2 - 6 files changed, 77 insertions(+), 36 deletions(-) (limited to 'gnuradio-core/src') diff --git a/gnuradio-core/src/lib/runtime/gr_block.cc b/gnuradio-core/src/lib/runtime/gr_block.cc index 73a86e38b..1fb4633e5 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_block.cc @@ -166,12 +166,17 @@ gr_block::get_tags_in_range(unsigned int which_output, return d_detail->get_tags_in_range(which_output, start, end, key); } -void -gr_block::handle_tags() +int +gr_block::tag_handling_method() { - d_detail->handle_tags(); + return d_detail->tag_handling_method(); } +void +gr_block::set_tag_handling_method(int m) +{ + set_tag_handling_method(m); +} std::ostream& operator << (std::ostream& os, const gr_block *m) diff --git a/gnuradio-core/src/lib/runtime/gr_block.h b/gnuradio-core/src/lib/runtime/gr_block.h index 4d1d6f875..4b246884e 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.h +++ b/gnuradio-core/src/lib/runtime/gr_block.h @@ -208,14 +208,8 @@ class gr_block : public gr_basic_block { */ uint64_t nitems_written(unsigned int which_output); - - /*! - * \brief Function to move tags downstream - * - * The default behavior proxies to gr_block_detail, which just moves all tags - * from input to output and flows them all downstream. - */ - virtual void handle_tags(); + int tag_handling_method(); + void set_tag_handling_method(int m); // ---------------------------------------------------------------------------- diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.cc b/gnuradio-core/src/lib/runtime/gr_block_detail.cc index b3d1a7194..b7dc52a60 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.cc @@ -42,7 +42,7 @@ gr_block_detail::gr_block_detail (unsigned int ninputs, unsigned int noutputs) d_ninputs (ninputs), d_noutputs (noutputs), d_input (ninputs), d_output (noutputs), d_done (false), - d_last_tag(0) + d_tag_handling_method(gr_block_detail::TAGS_ALL_TO_ALL) { s_ncurrently_allocated++; } @@ -203,18 +203,18 @@ gr_block_detail::get_tags_in_range(unsigned int which_input, return found_items_by_key; } -void -gr_block_detail::handle_tags() -{ - for(unsigned int i = 0; i < d_ninputs; i++) { - pmt_t tuple; - while(d_input[i]->get_tag(d_last_tag, tuple)) { - d_last_tag++; - if(!sink_p()) { - for(unsigned int o = 0; o < d_noutputs; o++) { - d_output[o]->add_item_tag(tuple); - } - } - } +int +gr_block_detail::tag_handling_method() +{ + return d_tag_handling_method; +} + +void +gr_block_detail::set_tag_handling_method(int m) +{ + if((m == TAGS_ONE_TO_ONE) && (ninputs() != noutputs())) { + throw std::invalid_argument ("gr_block_detail::set_handling method to ONE-TO-ONE requires ninputs == noutputs"); } + + d_tag_handling_method = m; } diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.h b/gnuradio-core/src/lib/runtime/gr_block_detail.h index 3a2b82190..711f59cf0 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.h +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.h @@ -37,6 +37,13 @@ */ class gr_block_detail { public: + + enum { + TAGS_NONE = 0, + TAGS_ALL_TO_ALL = 1, + TAGS_ONE_TO_ONE = 2 + }; + ~gr_block_detail (); int ninputs () const { return d_ninputs; } @@ -153,13 +160,8 @@ class gr_block_detail { uint64_t abs_end, const pmt::pmt_t &key); - /*! - * \brief Default tag handler; moves all tags downstream - * - * Move all tags from input to output and flows them all downstream. Each input - * stream's tags get appended to each output streams tags. - */ - void handle_tags(); + int tag_handling_method(); + void set_tag_handling_method(int m); gr_tpb_detail d_tpb; // used by thread-per-block scheduler int d_produce_or; @@ -172,8 +174,7 @@ class gr_block_detail { std::vector d_input; std::vector d_output; bool d_done; - - size_t d_last_tag; // keep track of which tags we've already received from upstream + int d_tag_handling_method; gr_block_detail (unsigned int ninputs, unsigned int noutputs); diff --git a/gnuradio-core/src/lib/runtime/gr_block_executor.cc b/gnuradio-core/src/lib/runtime/gr_block_executor.cc index 2c21a0b0f..f201c3937 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_executor.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_executor.cc @@ -294,12 +294,55 @@ gr_block_executor::run_one_iteration() for (int i = 0; i < d->noutputs (); i++) d_output_items[i] = d->output(i)->write_pointer(); + // store number of items consumed so far on in stream + std::vector start_count; + for (int i = 0; i < d->ninputs(); i++) + start_count.push_back(d->nitems_read(i)); + // Do the actual work of the block int n = m->general_work (noutput_items, d_ninput_items, d_input_items, d_output_items); LOG(*d_log << " general_work: noutput_items = " << noutput_items << " result = " << n << std::endl); + // store number of items consumed after work + std::vector end_count; + for (int i = 0; i < d->ninputs (); i++) + end_count.push_back(d->nitems_read(i)); + + // Move tags downstream + // if a sink, we don't need to move downstream; + // and do not bother if block uses TAGS_NONE attribute + if(!d->sink_p() && (d->tag_handling_method() != gr_block_detail::TAGS_NONE)) { + + // every tag on every input propogates to everyone downstream + if(d->tag_handling_method() == gr_block_detail::TAGS_ALL_TO_ALL) { + for(int i = 0; i < d->ninputs(); i++) { + std::vector tuple = d->get_tags_in_range(i, start_count[i], end_count[i]); + std::vector::iterator t; + for(t = tuple.begin(); t != tuple.end(); t++ ) { + for(int o = 0; o < d->noutputs(); o++) + d->output(o)->add_item_tag(*t); + } + } + } + + // tags from input i only go to output i + // this requires d->ninputs() == d->noutputs; this is checked when this + // type of tag-handling system is selected in gr_block_detail + else if(d->tag_handling_method() == gr_block_detail::TAGS_ONE_TO_ONE) { + for(int i = 0; i < d->ninputs(); i++) { + std::vector tuple = d->get_tags_in_range(i, start_count[i], end_count[i]); + std::vector::iterator t; + for(t = tuple.begin(); t != tuple.end(); t++ ) { + d->output(i)->add_item_tag(*t); + } + } + } + + // else ; do nothing + } + if (n == gr_block::WORK_DONE) goto were_done; diff --git a/gnuradio-core/src/lib/runtime/gr_tpb_thread_body.cc b/gnuradio-core/src/lib/runtime/gr_tpb_thread_body.cc index 6a84f4be8..03eef17d9 100644 --- a/gnuradio-core/src/lib/runtime/gr_tpb_thread_body.cc +++ b/gnuradio-core/src/lib/runtime/gr_tpb_thread_body.cc @@ -45,8 +45,6 @@ gr_tpb_thread_body::gr_tpb_thread_body(gr_block_sptr block) while ((msg = d->d_tpb.delete_head_nowait())) block->handle_msg(msg); - block->handle_tags(); - d->d_tpb.clear_changed(); s = d_exec.run_one_iteration(); -- cgit From 23285af07c88890daea3c9da011f983ae0e0da2d Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sun, 7 Nov 2010 18:39:15 -0500 Subject: Moving tag handling setup back into gr_block so it can be set in the constructor of a derived block. --- gnuradio-core/src/lib/runtime/gr_block.cc | 15 +++++++++++---- gnuradio-core/src/lib/runtime/gr_block.h | 15 ++++++++++++++- gnuradio-core/src/lib/runtime/gr_block_detail.cc | 19 +------------------ gnuradio-core/src/lib/runtime/gr_block_detail.h | 11 ----------- gnuradio-core/src/lib/runtime/gr_block_executor.cc | 20 ++++++++++++-------- 5 files changed, 38 insertions(+), 42 deletions(-) (limited to 'gnuradio-core/src') diff --git a/gnuradio-core/src/lib/runtime/gr_block.cc b/gnuradio-core/src/lib/runtime/gr_block.cc index 1fb4633e5..94cf23103 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_block.cc @@ -36,7 +36,8 @@ gr_block::gr_block (const std::string &name, d_output_multiple (1), d_relative_rate (1.0), d_history(1), - d_fixed_rate(false) + d_fixed_rate(false), + d_tag_handling_method(TAGS_ALL_TO_ALL) { } @@ -166,16 +167,22 @@ gr_block::get_tags_in_range(unsigned int which_output, return d_detail->get_tags_in_range(which_output, start, end, key); } -int +int gr_block::tag_handling_method() { - return d_detail->tag_handling_method(); + return d_tag_handling_method; } void gr_block::set_tag_handling_method(int m) { - set_tag_handling_method(m); + /* + if((m == TAGS_ONE_TO_ONE) && (ninputs() != noutputs())) { + throw std::invalid_argument ("gr_block::set_handling method to ONE-TO-ONE requires ninputs == noutputs"); + } + */ + + d_tag_handling_method = m; } std::ostream& diff --git a/gnuradio-core/src/lib/runtime/gr_block.h b/gnuradio-core/src/lib/runtime/gr_block.h index 4b246884e..e278e8e9c 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.h +++ b/gnuradio-core/src/lib/runtime/gr_block.h @@ -25,6 +25,12 @@ #include +enum { + TAGS_NONE = 0, + TAGS_ALL_TO_ALL = 1, + TAGS_ONE_TO_ONE = 2 +}; + /*! * \brief The abstract base class for all 'terminal' processing blocks. * \ingroup base_blk @@ -208,7 +214,14 @@ class gr_block : public gr_basic_block { */ uint64_t nitems_written(unsigned int which_output); + /*! + * \brief Asks for the method used by the scheduler to moved tags downstream. + */ int tag_handling_method(); + + /*! + * \brief Used by the scheduler to determine how tags are moved downstream. + */ void set_tag_handling_method(int m); // ---------------------------------------------------------------------------- @@ -220,6 +233,7 @@ class gr_block : public gr_basic_block { gr_block_detail_sptr d_detail; // implementation details unsigned d_history; bool d_fixed_rate; + int d_tag_handling_method; protected: @@ -285,7 +299,6 @@ class gr_block : public gr_basic_block { uint64_t abs_end, const pmt::pmt_t &key); - // These are really only for internal use, but leaving them public avoids // having to work up an ever-varying list of friends diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.cc b/gnuradio-core/src/lib/runtime/gr_block_detail.cc index b7dc52a60..1888b8839 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.cc @@ -41,8 +41,7 @@ gr_block_detail::gr_block_detail (unsigned int ninputs, unsigned int noutputs) : d_produce_or(0), d_ninputs (ninputs), d_noutputs (noutputs), d_input (ninputs), d_output (noutputs), - d_done (false), - d_tag_handling_method(gr_block_detail::TAGS_ALL_TO_ALL) + d_done (false) { s_ncurrently_allocated++; } @@ -202,19 +201,3 @@ gr_block_detail::get_tags_in_range(unsigned int which_input, return found_items_by_key; } - -int -gr_block_detail::tag_handling_method() -{ - return d_tag_handling_method; -} - -void -gr_block_detail::set_tag_handling_method(int m) -{ - if((m == TAGS_ONE_TO_ONE) && (ninputs() != noutputs())) { - throw std::invalid_argument ("gr_block_detail::set_handling method to ONE-TO-ONE requires ninputs == noutputs"); - } - - d_tag_handling_method = m; -} diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.h b/gnuradio-core/src/lib/runtime/gr_block_detail.h index 711f59cf0..929e36fc8 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.h +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.h @@ -37,13 +37,6 @@ */ class gr_block_detail { public: - - enum { - TAGS_NONE = 0, - TAGS_ALL_TO_ALL = 1, - TAGS_ONE_TO_ONE = 2 - }; - ~gr_block_detail (); int ninputs () const { return d_ninputs; } @@ -160,9 +153,6 @@ class gr_block_detail { uint64_t abs_end, const pmt::pmt_t &key); - int tag_handling_method(); - void set_tag_handling_method(int m); - gr_tpb_detail d_tpb; // used by thread-per-block scheduler int d_produce_or; @@ -174,7 +164,6 @@ class gr_block_detail { std::vector d_input; std::vector d_output; bool d_done; - int d_tag_handling_method; gr_block_detail (unsigned int ninputs, unsigned int noutputs); diff --git a/gnuradio-core/src/lib/runtime/gr_block_executor.cc b/gnuradio-core/src/lib/runtime/gr_block_executor.cc index f201c3937..3fc536845 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_executor.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_executor.cc @@ -313,10 +313,10 @@ gr_block_executor::run_one_iteration() // Move tags downstream // if a sink, we don't need to move downstream; // and do not bother if block uses TAGS_NONE attribute - if(!d->sink_p() && (d->tag_handling_method() != gr_block_detail::TAGS_NONE)) { + if(!d->sink_p() && (m->tag_handling_method() != TAGS_NONE)) { // every tag on every input propogates to everyone downstream - if(d->tag_handling_method() == gr_block_detail::TAGS_ALL_TO_ALL) { + if(m->tag_handling_method() == TAGS_ALL_TO_ALL) { for(int i = 0; i < d->ninputs(); i++) { std::vector tuple = d->get_tags_in_range(i, start_count[i], end_count[i]); std::vector::iterator t; @@ -330,14 +330,18 @@ gr_block_executor::run_one_iteration() // tags from input i only go to output i // this requires d->ninputs() == d->noutputs; this is checked when this // type of tag-handling system is selected in gr_block_detail - else if(d->tag_handling_method() == gr_block_detail::TAGS_ONE_TO_ONE) { - for(int i = 0; i < d->ninputs(); i++) { - std::vector tuple = d->get_tags_in_range(i, start_count[i], end_count[i]); - std::vector::iterator t; - for(t = tuple.begin(); t != tuple.end(); t++ ) { - d->output(i)->add_item_tag(*t); + else if(m->tag_handling_method() == TAGS_ONE_TO_ONE) { + if(d->ninputs() != d->noutputs()) { + for(int i = 0; i < d->ninputs(); i++) { + std::vector tuple = d->get_tags_in_range(i, start_count[i], end_count[i]); + std::vector::iterator t; + for(t = tuple.begin(); t != tuple.end(); t++ ) { + d->output(i)->add_item_tag(*t); + } } } + else + throw std::invalid_argument ("handling method 'ONE-TO-ONE' requires ninputs == noutputs"); } // else ; do nothing -- cgit From 75c9c767079868b1c938fbb9a8c5522a60f28c96 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Mon, 8 Nov 2010 19:20:19 -0500 Subject: cleaning up; comments, naming, typos, excess code, etc. Moving to make gr_block_executor more readable. --- gnuradio-core/src/lib/runtime/gr_block.cc | 2 +- gnuradio-core/src/lib/runtime/gr_block.h | 22 +++++++++------------- gnuradio-core/src/lib/runtime/gr_block_detail.cc | 2 +- gnuradio-core/src/lib/runtime/gr_block_detail.h | 4 ++-- gnuradio-core/src/lib/runtime/gr_block_executor.cc | 22 +++++++++------------- gnuradio-core/src/lib/runtime/gr_buffer.h | 19 ++----------------- .../src/lib/runtime/gr_random_annotator.cc | 2 +- 7 files changed, 25 insertions(+), 48 deletions(-) (limited to 'gnuradio-core/src') diff --git a/gnuradio-core/src/lib/runtime/gr_block.cc b/gnuradio-core/src/lib/runtime/gr_block.cc index 94cf23103..b3e6b0edc 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_block.cc @@ -37,7 +37,7 @@ gr_block::gr_block (const std::string &name, d_relative_rate (1.0), d_history(1), d_fixed_rate(false), - d_tag_handling_method(TAGS_ALL_TO_ALL) + d_tag_handling_method(TPP_ALL_TO_ALL) { } diff --git a/gnuradio-core/src/lib/runtime/gr_block.h b/gnuradio-core/src/lib/runtime/gr_block.h index e278e8e9c..be39a7b95 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.h +++ b/gnuradio-core/src/lib/runtime/gr_block.h @@ -25,12 +25,6 @@ #include -enum { - TAGS_NONE = 0, - TAGS_ALL_TO_ALL = 1, - TAGS_ONE_TO_ONE = 2 -}; - /*! * \brief The abstract base class for all 'terminal' processing blocks. * \ingroup base_blk @@ -69,6 +63,12 @@ class gr_block : public gr_basic_block { WORK_DONE = -1 }; + enum TAG_PROPOGATION_POLICY { + TPP_DONT = 0, + TPP_ALL_TO_ALL = 1, + TPP_ONE_TO_ONE = 2 + }; + virtual ~gr_block (); /*! @@ -247,12 +247,10 @@ class gr_block : public gr_basic_block { /*! * \brief Adds a new tag onto the given output buffer. * - * This is a call-through method to gr_block_detail. - * * \param which_ouput an integer of which output stream to attach the tag * \param abs_offset a uint64 number of the absolute item number * assicated with the tag. Can get from nitems_written. - * \param key a PMT symbol holding the key name + * \param key the tag key as a PMT symbol * \param value any PMT holding any value for the given key * \param srcid optional source ID specifier; defaults to PMT_F */ @@ -265,8 +263,7 @@ class gr_block : public gr_basic_block { /*! * \brief Given a [start,end), returns a vector of all tags in the range. * - * Pass-through function to gr_block_detail. Range of counts is from - * start to end-1. + * Range of counts is from start to end-1. * * Tags are tuples of: * (item count, source id, key, value) @@ -283,8 +280,7 @@ class gr_block : public gr_basic_block { * \brief Given a [start,end), returns a vector of all tags in the range * with a given key. * - * Pass-through function to gr_block_detail. Range of counts is from - * start to end-1. + * Range of counts is from start to end-1. * * Tags are tuples of: * (item count, source id, key, value) diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.cc b/gnuradio-core/src/lib/runtime/gr_block_detail.cc index 1888b8839..4f3ffc8dc 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.cc @@ -157,7 +157,7 @@ gr_block_detail::add_item_tag(unsigned int which_output, const pmt_t &srcid) { if(!pmt_is_symbol(key)) { - throw pmt_wrong_type("gr_block_detail::set_item_tag key", key); + throw pmt_wrong_type("gr_block_detail::add_item_tag key", key); } else { // build tag tuple diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.h b/gnuradio-core/src/lib/runtime/gr_block_detail.h index 929e36fc8..5902d1559 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.h +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.h @@ -105,7 +105,7 @@ class gr_block_detail { * \param which_ouput an integer of which output stream to attach the tag * \param abs_offset a uint64 number of the absolute item number * assicated with the tag. Can get from nitems_written. - * \param key a PMT symbol holding the key name (i.e., a string) + * \param key the tag key as a PMT symbol * \param value any PMT holding any value for the given key * \param srcid a PMT source ID specifier */ @@ -146,7 +146,7 @@ class gr_block_detail { * \param which_input an integer of which input stream to pull from * \param abs_start a uint64 count of the start of the range of interest * \param abs_end a uint64 count of the end of the range of interest - * \param key a PMT symbol key to select only tags of this key + * \param key a PMT symbol to select only tags of this key */ std::vector get_tags_in_range(unsigned int which_input, uint64_t abs_start, diff --git a/gnuradio-core/src/lib/runtime/gr_block_executor.cc b/gnuradio-core/src/lib/runtime/gr_block_executor.cc index 3fc536845..c43f22895 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_executor.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_executor.cc @@ -295,9 +295,10 @@ gr_block_executor::run_one_iteration() d_output_items[i] = d->output(i)->write_pointer(); // store number of items consumed so far on in stream - std::vector start_count; + std::vector d_start_nitems_read; + d_start_nitems_read.resize(d->ninputs()); for (int i = 0; i < d->ninputs(); i++) - start_count.push_back(d->nitems_read(i)); + d_start_nitems_read[i] = d->nitems_read(i); // Do the actual work of the block int n = m->general_work (noutput_items, d_ninput_items, @@ -305,20 +306,15 @@ gr_block_executor::run_one_iteration() LOG(*d_log << " general_work: noutput_items = " << noutput_items << " result = " << n << std::endl); - // store number of items consumed after work - std::vector end_count; - for (int i = 0; i < d->ninputs (); i++) - end_count.push_back(d->nitems_read(i)); - // Move tags downstream // if a sink, we don't need to move downstream; // and do not bother if block uses TAGS_NONE attribute - if(!d->sink_p() && (m->tag_handling_method() != TAGS_NONE)) { + if(!d->sink_p() && (m->tag_handling_method() != gr_block::TPP_DONT)) { // every tag on every input propogates to everyone downstream - if(m->tag_handling_method() == TAGS_ALL_TO_ALL) { + if(m->tag_handling_method() == gr_block::TPP_ALL_TO_ALL) { for(int i = 0; i < d->ninputs(); i++) { - std::vector tuple = d->get_tags_in_range(i, start_count[i], end_count[i]); + std::vector tuple = d->get_tags_in_range(i, d_start_nitems_read[i], d->nitems_read(i)); std::vector::iterator t; for(t = tuple.begin(); t != tuple.end(); t++ ) { for(int o = 0; o < d->noutputs(); o++) @@ -330,10 +326,10 @@ gr_block_executor::run_one_iteration() // tags from input i only go to output i // this requires d->ninputs() == d->noutputs; this is checked when this // type of tag-handling system is selected in gr_block_detail - else if(m->tag_handling_method() == TAGS_ONE_TO_ONE) { - if(d->ninputs() != d->noutputs()) { + else if(m->tag_handling_method() == gr_block::TPP_ONE_TO_ONE) { + if(d->ninputs() == d->noutputs()) { for(int i = 0; i < d->ninputs(); i++) { - std::vector tuple = d->get_tags_in_range(i, start_count[i], end_count[i]); + std::vector tuple = d->get_tags_in_range(i, d_start_nitems_read[i], d->nitems_read(i)); std::vector::iterator t; for(t = tuple.begin(); t != tuple.end(); t++ ) { d->output(i)->add_item_tag(*t); diff --git a/gnuradio-core/src/lib/runtime/gr_buffer.h b/gnuradio-core/src/lib/runtime/gr_buffer.h index 5b8f21c94..5f11b4581 100644 --- a/gnuradio-core/src/lib/runtime/gr_buffer.h +++ b/gnuradio-core/src/lib/runtime/gr_buffer.h @@ -102,17 +102,6 @@ class gr_buffer { std::deque::iterator get_tags_begin() { return d_item_tags.begin(); } std::deque::iterator get_tags_end() { return d_item_tags.end(); } - bool get_tag(size_t n, pmt::pmt_t &t) - { - if(n < d_item_tags.size()) { - t = d_item_tags[n]; - return true; - } - else { - return false; - } - } - // ------------------------------------------------------------------------- private: @@ -130,7 +119,8 @@ class gr_buffer { std::vector d_readers; boost::weak_ptr d_link; // block that writes to this buffer - std::deque d_item_tags; // temp. store tags until moved to reader + std::deque d_item_tags; + // // The mutex protects d_write_index, d_abs_write_offset, d_done and the d_read_index's @@ -272,11 +262,6 @@ class gr_buffer_reader { std::vector get_tags_in_range(uint64_t abs_start, uint64_t abs_end); - bool get_tag(size_t n, pmt::pmt_t &t) - { - return d_buffer->get_tag(n, t); - } - // ------------------------------------------------------------------------- private: diff --git a/gnuradio-core/src/lib/runtime/gr_random_annotator.cc b/gnuradio-core/src/lib/runtime/gr_random_annotator.cc index d360c13a5..08589984e 100644 --- a/gnuradio-core/src/lib/runtime/gr_random_annotator.cc +++ b/gnuradio-core/src/lib/runtime/gr_random_annotator.cc @@ -60,7 +60,7 @@ gr_random_annotator::work (int noutput_items, std::stringstream str; str << name() << unique_id(); - uint64_t abs_N = nitems_written(0); + uint64_t abs_N = nitems_read(0) + noutput_items; std::vector all_tags = get_tags_in_range(0, (uint64_t)0, abs_N); std::vector::iterator itr; -- cgit From 0a2cb50b6b7e50bb69df9478e49db4d77599c324 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Mon, 8 Nov 2010 19:30:54 -0500 Subject: Renaming "handling_method" to "propagation_policy". --- gnuradio-core/src/lib/runtime/gr_block.cc | 16 +++++----------- gnuradio-core/src/lib/runtime/gr_block.h | 12 ++++++------ gnuradio-core/src/lib/runtime/gr_block_executor.cc | 10 +++++----- 3 files changed, 16 insertions(+), 22 deletions(-) (limited to 'gnuradio-core/src') diff --git a/gnuradio-core/src/lib/runtime/gr_block.cc b/gnuradio-core/src/lib/runtime/gr_block.cc index b3e6b0edc..e595b60b8 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_block.cc @@ -37,7 +37,7 @@ gr_block::gr_block (const std::string &name, d_relative_rate (1.0), d_history(1), d_fixed_rate(false), - d_tag_handling_method(TPP_ALL_TO_ALL) + d_tag_propagation_policy(TPP_ALL_TO_ALL) { } @@ -168,21 +168,15 @@ gr_block::get_tags_in_range(unsigned int which_output, } int -gr_block::tag_handling_method() +gr_block::tag_propagation_policy() { - return d_tag_handling_method; + return d_tag_propagation_policy; } void -gr_block::set_tag_handling_method(int m) +gr_block::set_tag_propagation_policy(TAG_PROPAGATION_POLICY p) { - /* - if((m == TAGS_ONE_TO_ONE) && (ninputs() != noutputs())) { - throw std::invalid_argument ("gr_block::set_handling method to ONE-TO-ONE requires ninputs == noutputs"); - } - */ - - d_tag_handling_method = m; + d_tag_propagation_policy = p; } std::ostream& diff --git a/gnuradio-core/src/lib/runtime/gr_block.h b/gnuradio-core/src/lib/runtime/gr_block.h index be39a7b95..e2f00bb6f 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.h +++ b/gnuradio-core/src/lib/runtime/gr_block.h @@ -63,7 +63,7 @@ class gr_block : public gr_basic_block { WORK_DONE = -1 }; - enum TAG_PROPOGATION_POLICY { + enum TAG_PROPAGATION_POLICY { TPP_DONT = 0, TPP_ALL_TO_ALL = 1, TPP_ONE_TO_ONE = 2 @@ -215,14 +215,14 @@ class gr_block : public gr_basic_block { uint64_t nitems_written(unsigned int which_output); /*! - * \brief Asks for the method used by the scheduler to moved tags downstream. + * \brief Asks for the policy used by the scheduler to moved tags downstream. */ - int tag_handling_method(); + int tag_propagation_policy(); /*! - * \brief Used by the scheduler to determine how tags are moved downstream. + * \brief Set the policy by the scheduler to determine how tags are moved downstream. */ - void set_tag_handling_method(int m); + void set_tag_propagation_policy(TAG_PROPAGATION_POLICY p); // ---------------------------------------------------------------------------- @@ -233,7 +233,7 @@ class gr_block : public gr_basic_block { gr_block_detail_sptr d_detail; // implementation details unsigned d_history; bool d_fixed_rate; - int d_tag_handling_method; + TAG_PROPAGATION_POLICY d_tag_propagation_policy; // policy for moving tags downstream protected: diff --git a/gnuradio-core/src/lib/runtime/gr_block_executor.cc b/gnuradio-core/src/lib/runtime/gr_block_executor.cc index c43f22895..35aa8cf1e 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_executor.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_executor.cc @@ -309,10 +309,10 @@ gr_block_executor::run_one_iteration() // Move tags downstream // if a sink, we don't need to move downstream; // and do not bother if block uses TAGS_NONE attribute - if(!d->sink_p() && (m->tag_handling_method() != gr_block::TPP_DONT)) { + if(!d->sink_p() && (m->tag_propagation_policy() != gr_block::TPP_DONT)) { // every tag on every input propogates to everyone downstream - if(m->tag_handling_method() == gr_block::TPP_ALL_TO_ALL) { + if(m->tag_propagation_policy() == gr_block::TPP_ALL_TO_ALL) { for(int i = 0; i < d->ninputs(); i++) { std::vector tuple = d->get_tags_in_range(i, d_start_nitems_read[i], d->nitems_read(i)); std::vector::iterator t; @@ -325,8 +325,8 @@ gr_block_executor::run_one_iteration() // tags from input i only go to output i // this requires d->ninputs() == d->noutputs; this is checked when this - // type of tag-handling system is selected in gr_block_detail - else if(m->tag_handling_method() == gr_block::TPP_ONE_TO_ONE) { + // type of tag-propagation system is selected in gr_block_detail + else if(m->tag_propagation_policy() == gr_block::TPP_ONE_TO_ONE) { if(d->ninputs() == d->noutputs()) { for(int i = 0; i < d->ninputs(); i++) { std::vector tuple = d->get_tags_in_range(i, d_start_nitems_read[i], d->nitems_read(i)); @@ -337,7 +337,7 @@ gr_block_executor::run_one_iteration() } } else - throw std::invalid_argument ("handling method 'ONE-TO-ONE' requires ninputs == noutputs"); + throw std::invalid_argument ("propagation_policy 'ONE-TO-ONE' requires ninputs == noutputs"); } // else ; do nothing -- cgit From 4cb301dec845778e468c73dac5eb04a9dfccb14a Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Mon, 8 Nov 2010 19:46:32 -0500 Subject: Made propagate_tags a function to be called from block_executor to move tags downstream. Also made d_start_nitems_read a member of gr_block_executor to better handle allocation. --- gnuradio-core/src/lib/runtime/gr_block.cc | 2 +- gnuradio-core/src/lib/runtime/gr_block.h | 2 +- gnuradio-core/src/lib/runtime/gr_block_executor.cc | 88 ++++++++++++---------- gnuradio-core/src/lib/runtime/gr_block_executor.h | 1 + 4 files changed, 53 insertions(+), 40 deletions(-) (limited to 'gnuradio-core/src') diff --git a/gnuradio-core/src/lib/runtime/gr_block.cc b/gnuradio-core/src/lib/runtime/gr_block.cc index e595b60b8..778344769 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_block.cc @@ -167,7 +167,7 @@ gr_block::get_tags_in_range(unsigned int which_output, return d_detail->get_tags_in_range(which_output, start, end, key); } -int +gr_block::TAG_PROPAGATION_POLICY gr_block::tag_propagation_policy() { return d_tag_propagation_policy; diff --git a/gnuradio-core/src/lib/runtime/gr_block.h b/gnuradio-core/src/lib/runtime/gr_block.h index e2f00bb6f..a717946d2 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.h +++ b/gnuradio-core/src/lib/runtime/gr_block.h @@ -217,7 +217,7 @@ class gr_block : public gr_basic_block { /*! * \brief Asks for the policy used by the scheduler to moved tags downstream. */ - int tag_propagation_policy(); + TAG_PROPAGATION_POLICY tag_propagation_policy(); /*! * \brief Set the policy by the scheduler to determine how tags are moved downstream. diff --git a/gnuradio-core/src/lib/runtime/gr_block_executor.cc b/gnuradio-core/src/lib/runtime/gr_block_executor.cc index 35aa8cf1e..7d19f44ab 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_executor.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_executor.cc @@ -87,7 +87,53 @@ min_available_space (gr_block_detail *d, int output_multiple) return min_space; } +static void +propagate_tags(gr_block::TAG_PROPAGATION_POLICY policy, gr_block_detail *d, + const std::vector &start_nitems_read) +{ + // Move tags downstream + // if a sink, we don't need to move downstream; + // and do not bother if block uses TAGS_NONE attribute + if(!d->sink_p()) { + return; + } + switch(policy) { + case(gr_block::TPP_DONT): + return; + break; + case(gr_block::TPP_ALL_TO_ALL): + // every tag on every input propogates to everyone downstream + for(int i = 0; i < d->ninputs(); i++) { + std::vector tuple = d->get_tags_in_range(i, start_nitems_read[i], d->nitems_read(i)); + std::vector::iterator t; + for(t = tuple.begin(); t != tuple.end(); t++ ) { + for(int o = 0; o < d->noutputs(); o++) + d->output(o)->add_item_tag(*t); + } + } + break; + case(gr_block::TPP_ONE_TO_ONE): + // tags from input i only go to output i + // this requires d->ninputs() == d->noutputs; this is checked when this + // type of tag-propagation system is selected in gr_block_detail + if(d->ninputs() == d->noutputs()) { + for(int i = 0; i < d->ninputs(); i++) { + std::vector tuple = d->get_tags_in_range(i, start_nitems_read[i], d->nitems_read(i)); + std::vector::iterator t; + for(t = tuple.begin(); t != tuple.end(); t++ ) { + d->output(i)->add_item_tag(*t); + } + } + } + else + throw std::invalid_argument ("propagation_policy 'ONE-TO-ONE' requires ninputs == noutputs"); + + break; + default: + return; + } +} gr_block_executor::gr_block_executor (gr_block_sptr block) : d_block(block), d_log(0) @@ -134,6 +180,7 @@ gr_block_executor::run_one_iteration() d_input_items.resize (0); d_input_done.resize(0); d_output_items.resize (d->noutputs ()); + d_start_nitems_read.resize(0); // determine the minimum available output space noutput_items = min_available_space (d, m->output_multiple ()); @@ -155,6 +202,7 @@ gr_block_executor::run_one_iteration() d_input_items.resize (d->ninputs ()); d_input_done.resize(d->ninputs()); d_output_items.resize (0); + d_start_nitems_read.resize(d->ninputs()); LOG(*d_log << " sink\n"); max_items_avail = 0; @@ -198,6 +246,7 @@ gr_block_executor::run_one_iteration() d_input_items.resize (d->ninputs ()); d_input_done.resize(d->ninputs()); d_output_items.resize (d->noutputs ()); + d_start_nitems_read.resize(d->ninputs()); max_items_avail = 0; for (int i = 0; i < d->ninputs (); i++){ @@ -295,8 +344,6 @@ gr_block_executor::run_one_iteration() d_output_items[i] = d->output(i)->write_pointer(); // store number of items consumed so far on in stream - std::vector d_start_nitems_read; - d_start_nitems_read.resize(d->ninputs()); for (int i = 0; i < d->ninputs(); i++) d_start_nitems_read[i] = d->nitems_read(i); @@ -306,42 +353,7 @@ gr_block_executor::run_one_iteration() LOG(*d_log << " general_work: noutput_items = " << noutput_items << " result = " << n << std::endl); - // Move tags downstream - // if a sink, we don't need to move downstream; - // and do not bother if block uses TAGS_NONE attribute - if(!d->sink_p() && (m->tag_propagation_policy() != gr_block::TPP_DONT)) { - - // every tag on every input propogates to everyone downstream - if(m->tag_propagation_policy() == gr_block::TPP_ALL_TO_ALL) { - for(int i = 0; i < d->ninputs(); i++) { - std::vector tuple = d->get_tags_in_range(i, d_start_nitems_read[i], d->nitems_read(i)); - std::vector::iterator t; - for(t = tuple.begin(); t != tuple.end(); t++ ) { - for(int o = 0; o < d->noutputs(); o++) - d->output(o)->add_item_tag(*t); - } - } - } - - // tags from input i only go to output i - // this requires d->ninputs() == d->noutputs; this is checked when this - // type of tag-propagation system is selected in gr_block_detail - else if(m->tag_propagation_policy() == gr_block::TPP_ONE_TO_ONE) { - if(d->ninputs() == d->noutputs()) { - for(int i = 0; i < d->ninputs(); i++) { - std::vector tuple = d->get_tags_in_range(i, d_start_nitems_read[i], d->nitems_read(i)); - std::vector::iterator t; - for(t = tuple.begin(); t != tuple.end(); t++ ) { - d->output(i)->add_item_tag(*t); - } - } - } - else - throw std::invalid_argument ("propagation_policy 'ONE-TO-ONE' requires ninputs == noutputs"); - } - - // else ; do nothing - } + propagate_tags(m->tag_propagation_policy(), d, d_start_nitems_read); if (n == gr_block::WORK_DONE) goto were_done; diff --git a/gnuradio-core/src/lib/runtime/gr_block_executor.h b/gnuradio-core/src/lib/runtime/gr_block_executor.h index 41b5ede7c..22b782883 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_executor.h +++ b/gnuradio-core/src/lib/runtime/gr_block_executor.h @@ -47,6 +47,7 @@ protected: gr_vector_const_void_star d_input_items; std::vector d_input_done; gr_vector_void_star d_output_items; + std::vector d_start_nitems_read; //stores where tag counts are before work public: gr_block_executor(gr_block_sptr block); -- cgit From ab8c921bf73b61c19305bc0bf1fc4d26b110779e Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Mon, 8 Nov 2010 19:52:50 -0500 Subject: Adding mutex protection around adding and getting tags from buffers. --- gnuradio-core/src/lib/runtime/gr_buffer.cc | 3 +++ gnuradio-core/src/lib/runtime/gr_buffer.h | 10 ++++------ 2 files changed, 7 insertions(+), 6 deletions(-) (limited to 'gnuradio-core/src') diff --git a/gnuradio-core/src/lib/runtime/gr_buffer.cc b/gnuradio-core/src/lib/runtime/gr_buffer.cc index 862d92b81..1d67470ec 100644 --- a/gnuradio-core/src/lib/runtime/gr_buffer.cc +++ b/gnuradio-core/src/lib/runtime/gr_buffer.cc @@ -219,6 +219,7 @@ gr_buffer::drop_reader (gr_buffer_reader *reader) void gr_buffer::add_item_tag(const pmt::pmt_t &tag) { + gruel::scoped_lock guard(*mutex()); d_item_tags.push_back(tag); } @@ -267,6 +268,8 @@ std::vector gr_buffer_reader::get_tags_in_range(uint64_t abs_start, uint64_t abs_end) { + gruel::scoped_lock guard(*mutex()); + std::vector found_items; std::deque::iterator itr = d_buffer->get_tags_begin(); diff --git a/gnuradio-core/src/lib/runtime/gr_buffer.h b/gnuradio-core/src/lib/runtime/gr_buffer.h index 5f11b4581..d6d5564e8 100644 --- a/gnuradio-core/src/lib/runtime/gr_buffer.h +++ b/gnuradio-core/src/lib/runtime/gr_buffer.h @@ -119,18 +119,16 @@ class gr_buffer { std::vector d_readers; boost::weak_ptr d_link; // block that writes to this buffer - std::deque d_item_tags; - - // - // The mutex protects d_write_index, d_abs_write_offset, d_done and the d_read_index's - // and d_abs_read_offset's in the buffer readers. + // The mutex protects d_write_index, d_abs_write_offset, d_done, d_item_tags + // and the d_read_index's and d_abs_read_offset's in the buffer readers. // gruel::mutex d_mutex; unsigned int d_write_index; // in items [0,d_bufsize) uint64_t d_abs_write_offset; // num items written since the start - //deq tag_tuples bool d_done; + std::deque d_item_tags; + unsigned index_add (unsigned a, unsigned b) -- cgit From ec79e6f688c0ef94e66c938eba24c8b95e9856ba Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Mon, 8 Nov 2010 20:03:21 -0500 Subject: Burned by another copy-paste error. Correctly checking and acting if its a sink. --- gnuradio-core/src/lib/runtime/gr_block_executor.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gnuradio-core/src') diff --git a/gnuradio-core/src/lib/runtime/gr_block_executor.cc b/gnuradio-core/src/lib/runtime/gr_block_executor.cc index 7d19f44ab..804c9e197 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_executor.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_executor.cc @@ -94,7 +94,7 @@ propagate_tags(gr_block::TAG_PROPAGATION_POLICY policy, gr_block_detail *d, // Move tags downstream // if a sink, we don't need to move downstream; // and do not bother if block uses TAGS_NONE attribute - if(!d->sink_p()) { + if(d->sink_p()) { return; } -- cgit From d46b800b882724c07975f1dc897f8166d45150fb Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Mon, 8 Nov 2010 00:47:10 -0500 Subject: Fixing signed/unsigned warnings. --- gnuradio-core/src/lib/filter/gr_pfb_arb_resampler_ccf.cc | 11 +++++------ gnuradio-core/src/lib/filter/gr_pfb_interpolator_ccf.cc | 2 +- gnuradio-core/src/lib/general/gr_float_to_complex.cc | 4 ++-- gnuradio-core/src/lib/gengen/gr_add_XX.cc.t | 2 +- gnuradio-core/src/lib/gengen/gr_divide_XX.cc.t | 4 ++-- gnuradio-core/src/lib/gengen/gr_multiply_XX.cc.t | 2 +- gnuradio-core/src/lib/gengen/gr_sub_XX.cc.t | 4 ++-- 7 files changed, 14 insertions(+), 15 deletions(-) (limited to 'gnuradio-core/src') diff --git a/gnuradio-core/src/lib/filter/gr_pfb_arb_resampler_ccf.cc b/gnuradio-core/src/lib/filter/gr_pfb_arb_resampler_ccf.cc index 399632003..59b76a6f0 100644 --- a/gnuradio-core/src/lib/filter/gr_pfb_arb_resampler_ccf.cc +++ b/gnuradio-core/src/lib/filter/gr_pfb_arb_resampler_ccf.cc @@ -71,7 +71,7 @@ gr_pfb_arb_resampler_ccf::gr_pfb_arb_resampler_ccf (float rate, // Create an FIR filter for each channel and zero out the taps std::vector vtaps(0, d_int_rate); - for(int i = 0; i < d_int_rate; i++) { + for(unsigned int i = 0; i < d_int_rate; i++) { d_filters[i] = gr_fir_util::create_gr_fir_ccf(vtaps); d_diff_filters[i] = gr_fir_util::create_gr_fir_ccf(vtaps); } @@ -97,8 +97,6 @@ gr_pfb_arb_resampler_ccf::create_taps (const std::vector &newtaps, std::vector< std::vector > &ourtaps, std::vector &ourfilter) { - int i,j; - unsigned int ntaps = newtaps.size(); d_taps_per_filter = (unsigned int)ceil((double)ntaps/(double)d_int_rate); @@ -114,10 +112,10 @@ gr_pfb_arb_resampler_ccf::create_taps (const std::vector &newtaps, } // Partition the filter - for(i = 0; i < d_int_rate; i++) { + for(unsigned int i = 0; i < d_int_rate; i++) { // Each channel uses all d_taps_per_filter with 0's if not enough taps to fill out ourtaps[d_int_rate-1-i] = std::vector(d_taps_per_filter, 0); - for(j = 0; j < d_taps_per_filter; j++) { + for(unsigned int j = 0; j < d_taps_per_filter; j++) { ourtaps[d_int_rate - 1 - i][j] = tmp_taps[i + j*d_int_rate]; } @@ -173,7 +171,8 @@ gr_pfb_arb_resampler_ccf::general_work (int noutput_items, return 0; // history requirements may have changed. } - int i = 0, j, count = d_start_index; + int i = 0, count = d_start_index; + unsigned int j; gr_complex o0, o1; // Restore the last filter position diff --git a/gnuradio-core/src/lib/filter/gr_pfb_interpolator_ccf.cc b/gnuradio-core/src/lib/filter/gr_pfb_interpolator_ccf.cc index 8a0ad1c4c..e20bc38bb 100644 --- a/gnuradio-core/src/lib/filter/gr_pfb_interpolator_ccf.cc +++ b/gnuradio-core/src/lib/filter/gr_pfb_interpolator_ccf.cc @@ -132,7 +132,7 @@ gr_pfb_interpolator_ccf::work (int noutput_items, int i = 0, count = 0; while(i < noutput_items) { - for(int j = 0; j < d_rate; j++) { + for(unsigned int j = 0; j < d_rate; j++) { out[i] = d_filters[j]->filter(&in[count]); i++; } diff --git a/gnuradio-core/src/lib/general/gr_float_to_complex.cc b/gnuradio-core/src/lib/general/gr_float_to_complex.cc index 89ef18869..a392abd06 100644 --- a/gnuradio-core/src/lib/general/gr_float_to_complex.cc +++ b/gnuradio-core/src/lib/general/gr_float_to_complex.cc @@ -52,12 +52,12 @@ gr_float_to_complex::work (int noutput_items, switch (input_items.size ()){ case 1: - for (int j = 0; j < noutput_items*d_vlen; j++) + for (size_t j = 0; j < noutput_items*d_vlen; j++) out[j] = gr_complex (r[j], 0); break; case 2: - for (int j = 0; j < noutput_items*d_vlen; j++) + for (size_t j = 0; j < noutput_items*d_vlen; j++) out[j] = gr_complex (r[j], i[j]); break; diff --git a/gnuradio-core/src/lib/gengen/gr_add_XX.cc.t b/gnuradio-core/src/lib/gengen/gr_add_XX.cc.t index 58a25325a..0e8b23ee1 100644 --- a/gnuradio-core/src/lib/gengen/gr_add_XX.cc.t +++ b/gnuradio-core/src/lib/gengen/gr_add_XX.cc.t @@ -52,7 +52,7 @@ int int ninputs = input_items.size (); - for (int i = 0; i < noutput_items*d_vlen; i++){ + for (size_t i = 0; i < noutput_items*d_vlen; i++){ @I_TYPE@ acc = ((@I_TYPE@ *) input_items[0])[i]; for (int j = 1; j < ninputs; j++) acc += ((@I_TYPE@ *) input_items[j])[i]; diff --git a/gnuradio-core/src/lib/gengen/gr_divide_XX.cc.t b/gnuradio-core/src/lib/gengen/gr_divide_XX.cc.t index 1200145fa..ea245b57b 100644 --- a/gnuradio-core/src/lib/gengen/gr_divide_XX.cc.t +++ b/gnuradio-core/src/lib/gengen/gr_divide_XX.cc.t @@ -53,13 +53,13 @@ int int ninputs = input_items.size (); if (ninputs == 1){ // compute reciprocal - for (int i = 0; i < noutput_items*d_vlen; i++) + for (size_t i = 0; i < noutput_items*d_vlen; i++) *optr++ = (@O_TYPE@) ((@O_TYPE@) 1 / ((@I_TYPE@ *) input_items[0])[i]); } else { - for (int i = 0; i < noutput_items*d_vlen; i++){ + for (size_t i = 0; i < noutput_items*d_vlen; i++){ @I_TYPE@ acc = ((@I_TYPE@ *) input_items[0])[i]; for (int j = 1; j < ninputs; j++) acc /= ((@I_TYPE@ *) input_items[j])[i]; diff --git a/gnuradio-core/src/lib/gengen/gr_multiply_XX.cc.t b/gnuradio-core/src/lib/gengen/gr_multiply_XX.cc.t index 13ec0c8b3..5d270c763 100644 --- a/gnuradio-core/src/lib/gengen/gr_multiply_XX.cc.t +++ b/gnuradio-core/src/lib/gengen/gr_multiply_XX.cc.t @@ -52,7 +52,7 @@ int int ninputs = input_items.size (); - for (int i = 0; i < noutput_items*d_vlen; i++){ + for (size_t i = 0; i < noutput_items*d_vlen; i++){ @I_TYPE@ acc = ((@I_TYPE@ *) input_items[0])[i]; for (int j = 1; j < ninputs; j++) acc *= ((@I_TYPE@ *) input_items[j])[i]; diff --git a/gnuradio-core/src/lib/gengen/gr_sub_XX.cc.t b/gnuradio-core/src/lib/gengen/gr_sub_XX.cc.t index f0ed75217..1dcdf81ad 100644 --- a/gnuradio-core/src/lib/gengen/gr_sub_XX.cc.t +++ b/gnuradio-core/src/lib/gengen/gr_sub_XX.cc.t @@ -53,12 +53,12 @@ int int ninputs = input_items.size (); if (ninputs == 1){ // negate - for (int i = 0; i < noutput_items*d_vlen; i++) + for (size_t i = 0; i < noutput_items*d_vlen; i++) *optr++ = (@O_TYPE@) -((@I_TYPE@ *) input_items[0])[i]; } else { - for (int i = 0; i < noutput_items*d_vlen; i++){ + for (size_t i = 0; i < noutput_items*d_vlen; i++){ @I_TYPE@ acc = ((@I_TYPE@ *) input_items[0])[i]; for (int j = 1; j < ninputs; j++) acc -= ((@I_TYPE@ *) input_items[j])[i]; -- cgit From 8e64eed7ed9680db139a84e2370135cf619534bf Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Mon, 8 Nov 2010 00:47:33 -0500 Subject: Fixed warning re defining GNU_SOURCE. Can probably just remove it since it's defined in config, but this won't hurt anyone. --- gnuradio-core/src/lib/filter/gr_sincos.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'gnuradio-core/src') diff --git a/gnuradio-core/src/lib/filter/gr_sincos.c b/gnuradio-core/src/lib/filter/gr_sincos.c index 240a84852..3543ebfde 100644 --- a/gnuradio-core/src/lib/filter/gr_sincos.c +++ b/gnuradio-core/src/lib/filter/gr_sincos.c @@ -24,7 +24,9 @@ #include "config.h" #endif +#ifndef _GNU_SOURCE #define _GNU_SOURCE // ask for GNU extensions if available +#endif #include #include -- cgit From ee02e4e66a291685ce6399d7871b98ffccbdca54 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Mon, 8 Nov 2010 01:34:53 -0500 Subject: Fixing copyright date. --- gnuradio-core/src/lib/filter/gr_sincos.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gnuradio-core/src') diff --git a/gnuradio-core/src/lib/filter/gr_sincos.c b/gnuradio-core/src/lib/filter/gr_sincos.c index 3543ebfde..57b26b22f 100644 --- a/gnuradio-core/src/lib/filter/gr_sincos.c +++ b/gnuradio-core/src/lib/filter/gr_sincos.c @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2004 Free Software Foundation, Inc. + * Copyright 2004,2010 Free Software Foundation, Inc. * * This file is part of GNU Radio * -- cgit From 9eeb6dbaa1398946229db780f2eb1ca4e9eae04b Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Mon, 8 Nov 2010 01:44:16 -0500 Subject: Adding a bit more checking on file operations. --- gnuradio-core/src/lib/general/gr_circular_file.cc | 7 +++++-- gnuradio-core/src/lib/runtime/gr_preferences.cc | 24 +++++++++++++++++++---- 2 files changed, 25 insertions(+), 6 deletions(-) (limited to 'gnuradio-core/src') diff --git a/gnuradio-core/src/lib/general/gr_circular_file.cc b/gnuradio-core/src/lib/general/gr_circular_file.cc index 468b49a10..c9222597a 100644 --- a/gnuradio-core/src/lib/general/gr_circular_file.cc +++ b/gnuradio-core/src/lib/general/gr_circular_file.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2002 Free Software Foundation, Inc. + * Copyright 2002,2010 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -66,7 +66,10 @@ gr_circular_file::gr_circular_file (const char *filename, exit (1); } #ifdef HAVE_MMAP /* FIXME */ - ftruncate (d_fd, size + HEADER_SIZE); + if(ftruncate (d_fd, size + HEADER_SIZE) != 0) { + perror (filename); + exit (1); + } #endif } else { diff --git a/gnuradio-core/src/lib/runtime/gr_preferences.cc b/gnuradio-core/src/lib/runtime/gr_preferences.cc index e0be2db62..5f7412248 100644 --- a/gnuradio-core/src/lib/runtime/gr_preferences.cc +++ b/gnuradio-core/src/lib/runtime/gr_preferences.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2003 Free Software Foundation, Inc. + * Copyright 2003,2010 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -77,11 +77,20 @@ gr_preferences::get (const char *key) static char buf[1024]; FILE *fp = fopen (pathname (key), "r"); - if (fp == 0) + if (fp == 0) { + perror (pathname (key)); return 0; + } memset (buf, 0, sizeof (buf)); - fread (buf, 1, sizeof (buf) - 1, fp); + size_t ret = fread (buf, 1, sizeof (buf) - 1, fp); + if(ret == 0) { + if(ferror(fp) != 0) { + perror (pathname (key)); + fclose (fp); + return 0; + } + } fclose (fp); return buf; } @@ -97,6 +106,13 @@ gr_preferences::set (const char *key, const char *value) return; } - fwrite (value, 1, strlen (value), fp); + size_t ret = fwrite (value, 1, strlen (value), fp); + if(ret == 0) { + if(ferror(fp) != 0) { + perror (pathname (key)); + fclose (fp); + return; + } + } fclose (fp); }; -- cgit From c204913321f0618ac131738088dab23065bdfa80 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Thu, 11 Nov 2010 14:19:02 -0500 Subject: Fixed small bug in how tags are propagated downstream. Also using seq. numbers in annotator test block to better keep track. --- gnuradio-core/src/lib/runtime/gr_block_executor.cc | 4 ++-- gnuradio-core/src/lib/runtime/gr_random_annotator.cc | 7 ++++++- gnuradio-core/src/lib/runtime/gr_random_annotator.h | 1 + 3 files changed, 9 insertions(+), 3 deletions(-) (limited to 'gnuradio-core/src') diff --git a/gnuradio-core/src/lib/runtime/gr_block_executor.cc b/gnuradio-core/src/lib/runtime/gr_block_executor.cc index 804c9e197..840cf8e5c 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_executor.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_executor.cc @@ -343,9 +343,9 @@ gr_block_executor::run_one_iteration() for (int i = 0; i < d->noutputs (); i++) d_output_items[i] = d->output(i)->write_pointer(); - // store number of items consumed so far on in stream + // determine where to start looking for new tags as 1 past nitems read for (int i = 0; i < d->ninputs(); i++) - d_start_nitems_read[i] = d->nitems_read(i); + d_start_nitems_read[i] = d->nitems_read(i)+1; // Do the actual work of the block int n = m->general_work (noutput_items, d_ninput_items, diff --git a/gnuradio-core/src/lib/runtime/gr_random_annotator.cc b/gnuradio-core/src/lib/runtime/gr_random_annotator.cc index 08589984e..366130984 100644 --- a/gnuradio-core/src/lib/runtime/gr_random_annotator.cc +++ b/gnuradio-core/src/lib/runtime/gr_random_annotator.cc @@ -42,6 +42,11 @@ gr_random_annotator::gr_random_annotator (size_t sizeof_stream_item) gr_make_io_signature (1, -1, sizeof_stream_item)), d_itemsize(sizeof_stream_item) { + //set_tag_propagation_policy(TPP_DONT); + set_tag_propagation_policy(TPP_ALL_TO_ALL); + //set_tag_propagation_policy(TPP_ONE_TO_ONE); + + d_tag_counter = 0; } gr_random_annotator::~gr_random_annotator () @@ -86,7 +91,7 @@ gr_random_annotator::work (int noutput_items, } // Storing the current noutput_items as the value to the "noutput_items" key - pmt::pmt_t cur_N = pmt::pmt_from_uint64(random()); + pmt::pmt_t cur_N = pmt::pmt_from_uint64(d_tag_counter++); 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); diff --git a/gnuradio-core/src/lib/runtime/gr_random_annotator.h b/gnuradio-core/src/lib/runtime/gr_random_annotator.h index 3f21b71ad..5fca53830 100644 --- a/gnuradio-core/src/lib/runtime/gr_random_annotator.h +++ b/gnuradio-core/src/lib/runtime/gr_random_annotator.h @@ -46,6 +46,7 @@ protected: private: size_t d_itemsize; std::stringstream d_sout; + uint64_t d_tag_counter; friend gr_random_annotator_sptr gr_make_random_annotator (size_t sizeof_stream_item); -- cgit From 9aaf98cff5e03ec2821da492f3857780a767258f Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Thu, 11 Nov 2010 15:55:04 -0500 Subject: Renaming random_annotator to annotator_1toall that moves tags from single input to all outputs. --- gnuradio-core/src/lib/general/Makefile.am | 11 ++- gnuradio-core/src/lib/general/general.i | 4 + .../src/lib/general/gr_annotator_1toall.cc | 99 ++++++++++++++++++++ .../src/lib/general/gr_annotator_1toall.h | 55 ++++++++++++ .../src/lib/general/gr_annotator_1toall.i | 32 +++++++ gnuradio-core/src/lib/runtime/Makefile.am | 3 - .../src/lib/runtime/gr_random_annotator.cc | 100 --------------------- .../src/lib/runtime/gr_random_annotator.h | 55 ------------ .../src/lib/runtime/gr_random_annotator.i | 32 ------- gnuradio-core/src/lib/runtime/qa_block_tags.cc | 23 +++-- gnuradio-core/src/lib/runtime/runtime.i | 2 - 11 files changed, 213 insertions(+), 203 deletions(-) create mode 100644 gnuradio-core/src/lib/general/gr_annotator_1toall.cc create mode 100644 gnuradio-core/src/lib/general/gr_annotator_1toall.h create mode 100644 gnuradio-core/src/lib/general/gr_annotator_1toall.i delete mode 100644 gnuradio-core/src/lib/runtime/gr_random_annotator.cc delete mode 100644 gnuradio-core/src/lib/runtime/gr_random_annotator.h delete mode 100644 gnuradio-core/src/lib/runtime/gr_random_annotator.i (limited to 'gnuradio-core/src') diff --git a/gnuradio-core/src/lib/general/Makefile.am b/gnuradio-core/src/lib/general/Makefile.am index 3d8a42805..a58461165 100644 --- a/gnuradio-core/src/lib/general/Makefile.am +++ b/gnuradio-core/src/lib/general/Makefile.am @@ -175,7 +175,9 @@ libgeneral_la_SOURCES = \ gr_descrambler_bb.cc \ gr_scrambler_bb.cc \ gr_probe_mpsk_snr_c.cc \ - gr_probe_density_b.cc + gr_probe_density_b.cc \ + gr_annotator_1toall.cc \ + gr_annotator_1to1.cc libgeneral_qa_la_SOURCES = \ qa_general.cc \ @@ -344,7 +346,8 @@ grinclude_HEADERS = \ gr_descrambler_bb.h \ gr_scrambler_bb.h \ gr_probe_mpsk_snr_c.h \ - gr_probe_density_b.h + gr_probe_density_b.h \ + gr_annotator_1toall.h noinst_HEADERS = \ qa_general.h \ @@ -484,5 +487,7 @@ swiginclude_HEADERS = \ gr_descrambler_bb.i \ gr_scrambler_bb.i \ gr_probe_mpsk_snr_c.i \ - gr_probe_density_b.i + gr_probe_density_b.i \ + gr_annotator_1toall.i \ + gr_annotator_1to1.i endif diff --git a/gnuradio-core/src/lib/general/general.i b/gnuradio-core/src/lib/general/general.i index 68cafce2e..0dce5f68d 100644 --- a/gnuradio-core/src/lib/general/general.i +++ b/gnuradio-core/src/lib/general/general.i @@ -141,6 +141,8 @@ #include #include #include +#include +#include %} %include "gr_nop.i" @@ -262,3 +264,5 @@ %include "gr_copy.i" %include "gr_fll_band_edge_cc.i" %include "gr_additive_scrambler_bb.i" +%include "gr_annotator_1toall.i" +%include "gr_annotator_1to1.i" diff --git a/gnuradio-core/src/lib/general/gr_annotator_1toall.cc b/gnuradio-core/src/lib/general/gr_annotator_1toall.cc new file mode 100644 index 000000000..34574c9e5 --- /dev/null +++ b/gnuradio-core/src/lib/general/gr_annotator_1toall.cc @@ -0,0 +1,99 @@ +/* -*- c++ -*- */ +/* + * Copyright 2010 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include +#include + +gr_annotator_1toall_sptr +gr_make_annotator_1toall (size_t sizeof_stream_item) +{ + return gnuradio::get_initial_sptr (new gr_annotator_1toall (sizeof_stream_item)); +} + +gr_annotator_1toall::gr_annotator_1toall (size_t sizeof_stream_item) + : gr_sync_block ("annotator_1toall", + gr_make_io_signature (1, 1, sizeof_stream_item), + gr_make_io_signature (1, -1, sizeof_stream_item)), + d_itemsize(sizeof_stream_item) +{ + set_tag_propagation_policy(TPP_ALL_TO_ALL); + + d_tag_counter = 0; +} + +gr_annotator_1toall::~gr_annotator_1toall () +{ + std::cout << d_sout.str(); +} + +int +gr_annotator_1toall::work (int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) +{ + const float **in = (const float **) &input_items[0]; + float **out = (float **) &output_items[0]; + + std::stringstream str; + str << name() << unique_id(); + + uint64_t abs_N = nitems_read(0) + noutput_items; + std::vector all_tags = get_tags_in_range(0, (uint64_t)0, abs_N); + std::vector::iterator itr; + + d_sout << std::endl << "Found " << all_tags.size() << " tags." << std::endl; + d_sout.setf(std::ios::left); + d_sout << std::setw(25) << "Receiver" << std::setw(25) << "Sender" + << std::setw(10) << "nitem" << std::setw(20) << "key" + << std::setw(10) << "value" << std::endl; + + for(itr = all_tags.begin(); itr != all_tags.end(); itr++) { + d_sout << std::setw(25) << str.str() + << std::setw(25) << pmt::pmt_tuple_ref(*itr, 1) + << std::setw(10) << pmt::pmt_tuple_ref(*itr, 0) + << std::setw(20) << pmt::pmt_tuple_ref(*itr, 2) + << std::setw(10) << pmt::pmt_tuple_ref(*itr, 3) + << std::endl; + } + + + // Storing the current noutput_items as the value to the "noutput_items" key + pmt::pmt_t cur_N = pmt::pmt_from_uint64(d_tag_counter++); + pmt::pmt_t srcid = pmt::pmt_string_to_symbol(str.str()); + pmt::pmt_t key = pmt::pmt_string_to_symbol("seq"); + + // Work does nothing to the data stream; just copy all inputs to outputs + int noutputs = output_items.size(); + for (int i = 0; i < noutputs; i++) { + memcpy(out[i], in[0], noutput_items * d_itemsize); + add_item_tag(i, abs_N, key, cur_N, srcid); + } + + return noutput_items; +} diff --git a/gnuradio-core/src/lib/general/gr_annotator_1toall.h b/gnuradio-core/src/lib/general/gr_annotator_1toall.h new file mode 100644 index 000000000..4417e8c54 --- /dev/null +++ b/gnuradio-core/src/lib/general/gr_annotator_1toall.h @@ -0,0 +1,55 @@ +/* -*- c++ -*- */ +/* + * Copyright 2010 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_GR_ANNOTATOR_1TOALL_H +#define INCLUDED_GR_ANNOTATOR_1TOALL_H + +#include + +class gr_annotator_1toall; +typedef boost::shared_ptr gr_annotator_1toall_sptr; + +// public constructor +gr_annotator_1toall_sptr +gr_make_annotator_1toall (size_t sizeof_stream_item); + +class gr_annotator_1toall : public gr_sync_block +{ + public: + ~gr_annotator_1toall (); + int work (int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + +protected: + gr_annotator_1toall (size_t sizeof_stream_item); + + private: + size_t d_itemsize; + std::stringstream d_sout; + uint64_t d_tag_counter; + + friend gr_annotator_1toall_sptr + gr_make_annotator_1toall (size_t sizeof_stream_item); +}; + +#endif diff --git a/gnuradio-core/src/lib/general/gr_annotator_1toall.i b/gnuradio-core/src/lib/general/gr_annotator_1toall.i new file mode 100644 index 000000000..a8f1de3e0 --- /dev/null +++ b/gnuradio-core/src/lib/general/gr_annotator_1toall.i @@ -0,0 +1,32 @@ +/* -*- c++ -*- */ +/* + * Copyright 2010 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +GR_SWIG_BLOCK_MAGIC(gr,annotator_1toall); + +gr_annotator_1toall_sptr gr_make_annotator_1toall (size_t sizeof_stream_item); + +class gr_annotator_1toall : public gr_sync_block +{ +private: + gr_annotator_1toall (size_t sizeof_stream_item); +}; + diff --git a/gnuradio-core/src/lib/runtime/Makefile.am b/gnuradio-core/src/lib/runtime/Makefile.am index 1af91d80d..4c52f3ab0 100644 --- a/gnuradio-core/src/lib/runtime/Makefile.am +++ b/gnuradio-core/src/lib/runtime/Makefile.am @@ -49,7 +49,6 @@ libruntime_la_SOURCES = \ gr_msg_queue.cc \ gr_pagesize.cc \ gr_preferences.cc \ - gr_random_annotator.cc \ gr_realtime.cc \ gr_scheduler.cc \ gr_scheduler_sts.cc \ @@ -104,7 +103,6 @@ grinclude_HEADERS = \ gr_msg_queue.h \ gr_pagesize.h \ gr_preferences.h \ - gr_random_annotator.h \ gr_realtime.h \ gr_runtime_types.h \ gr_scheduler.h \ @@ -155,7 +153,6 @@ swiginclude_HEADERS = \ gr_message.i \ gr_msg_handler.i \ gr_msg_queue.i \ - gr_random_annotator.i \ gr_realtime.i \ gr_single_threaded_scheduler.i \ gr_sync_block.i \ diff --git a/gnuradio-core/src/lib/runtime/gr_random_annotator.cc b/gnuradio-core/src/lib/runtime/gr_random_annotator.cc deleted file mode 100644 index 366130984..000000000 --- a/gnuradio-core/src/lib/runtime/gr_random_annotator.cc +++ /dev/null @@ -1,100 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2010 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3, or (at your option) - * any later version. - * - * GNU Radio is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include -#include -#include - -gr_random_annotator_sptr -gr_make_random_annotator (size_t sizeof_stream_item) -{ - return gnuradio::get_initial_sptr (new gr_random_annotator (sizeof_stream_item)); -} - -gr_random_annotator::gr_random_annotator (size_t sizeof_stream_item) - : gr_sync_block ("random_annotator", - gr_make_io_signature (1, -1, sizeof_stream_item), - gr_make_io_signature (1, -1, sizeof_stream_item)), - d_itemsize(sizeof_stream_item) -{ - //set_tag_propagation_policy(TPP_DONT); - set_tag_propagation_policy(TPP_ALL_TO_ALL); - //set_tag_propagation_policy(TPP_ONE_TO_ONE); - - d_tag_counter = 0; -} - -gr_random_annotator::~gr_random_annotator () -{ - std::cout << d_sout.str(); -} - -int -gr_random_annotator::work (int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) -{ - const float **in = (const float **) &input_items[0]; - float **out = (float **) &output_items[0]; - - std::stringstream str; - str << name() << unique_id(); - - uint64_t abs_N = nitems_read(0) + noutput_items; - std::vector all_tags = get_tags_in_range(0, (uint64_t)0, abs_N); - std::vector::iterator itr; - - d_sout << std::endl << "Found " << all_tags.size() << " tags." << std::endl; - d_sout.setf(std::ios::left); - d_sout << std::setw(25) << "Receiver" << std::setw(25) << "Sender" - << std::setw(10) << "nitem" << std::setw(20) << "key" - << std::setw(10) << "value" << std::endl; - - for(itr = all_tags.begin(); itr != all_tags.end(); itr++) { - d_sout << std::setw(25) << str.str() - << std::setw(25) << pmt::pmt_tuple_ref(*itr, 1) - << std::setw(10) << pmt::pmt_tuple_ref(*itr, 0) - << std::setw(20) << pmt::pmt_tuple_ref(*itr, 2) - << std::setw(10) << pmt::pmt_tuple_ref(*itr, 3) - << 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 - pmt::pmt_t cur_N = pmt::pmt_from_uint64(d_tag_counter++); - 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/gr_random_annotator.h b/gnuradio-core/src/lib/runtime/gr_random_annotator.h deleted file mode 100644 index 5fca53830..000000000 --- a/gnuradio-core/src/lib/runtime/gr_random_annotator.h +++ /dev/null @@ -1,55 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2010 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3, or (at your option) - * any later version. - * - * GNU Radio is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - */ - -#ifndef INCLUDED_GR_RANDOM_ANNOTATOR_H -#define INCLUDED_GR_RANDOM_ANNOTATOR_H - -#include - -class gr_random_annotator; -typedef boost::shared_ptr gr_random_annotator_sptr; - -// public constructor -gr_random_annotator_sptr -gr_make_random_annotator (size_t sizeof_stream_item); - -class gr_random_annotator : public gr_sync_block -{ - public: - ~gr_random_annotator (); - int work (int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - -protected: - gr_random_annotator (size_t sizeof_stream_item); - - private: - size_t d_itemsize; - std::stringstream d_sout; - uint64_t d_tag_counter; - - friend gr_random_annotator_sptr - gr_make_random_annotator (size_t sizeof_stream_item); -}; - -#endif diff --git a/gnuradio-core/src/lib/runtime/gr_random_annotator.i b/gnuradio-core/src/lib/runtime/gr_random_annotator.i deleted file mode 100644 index f8765a294..000000000 --- a/gnuradio-core/src/lib/runtime/gr_random_annotator.i +++ /dev/null @@ -1,32 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2010 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3, or (at your option) - * any later version. - * - * GNU Radio is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - */ - -GR_SWIG_BLOCK_MAGIC(gr,random_annotator); - -gr_random_annotator_sptr gr_make_random_annotator (size_t sizeof_stream_item); - -class gr_random_annotator : public gr_sync_block -{ -private: - gr_random_annotator (size_t sizeof_stream_item); -}; - diff --git a/gnuradio-core/src/lib/runtime/qa_block_tags.cc b/gnuradio-core/src/lib/runtime/qa_block_tags.cc index 2fedb28fd..a845f70dc 100644 --- a/gnuradio-core/src/lib/runtime/qa_block_tags.cc +++ b/gnuradio-core/src/lib/runtime/qa_block_tags.cc @@ -29,7 +29,7 @@ #include #include #include -#include +#include #include @@ -73,17 +73,24 @@ qa_block_tags::t1 () 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 ann2 (gr_make_random_annotator(sizeof(int))); - gr_block_sptr snk (gr_make_null_sink(sizeof(int))); + gr_block_sptr ann0 (gr_make_annotator_1toall(sizeof(int))); + gr_block_sptr ann1 (gr_make_annotator_1toall(sizeof(int))); + gr_block_sptr ann2 (gr_make_annotator_1toall(sizeof(int))); + gr_block_sptr ann3 (gr_make_annotator_1toall(sizeof(int))); + gr_block_sptr ann4 (gr_make_annotator_1toall(sizeof(int))); + gr_block_sptr snk0 (gr_make_null_sink(sizeof(int))); + gr_block_sptr snk1 (gr_make_null_sink(sizeof(int))); tb->connect(src, 0, head, 0); tb->connect(head, 0, ann0, 0); + tb->connect(ann0, 0, ann1, 0); - tb->connect(ann1, 0, ann2, 0); - tb->connect(ann2, 0, snk, 0); - tb->run(); + tb->connect(ann0, 1, ann2, 0); + tb->connect(ann1, 0, ann3, 0); + tb->connect(ann2, 0, ann4, 0); + tb->connect(ann1, 0, snk0, 0); + tb->connect(ann2, 0, snk1, 0); + tb->run(); } diff --git a/gnuradio-core/src/lib/runtime/runtime.i b/gnuradio-core/src/lib/runtime/runtime.i index 51b32de17..20cf68a03 100644 --- a/gnuradio-core/src/lib/runtime/runtime.i +++ b/gnuradio-core/src/lib/runtime/runtime.i @@ -33,7 +33,6 @@ #include #include #include -#include #include #include #include @@ -54,7 +53,6 @@ %include %include %include -%include %include %include %include -- cgit From 0952d5a28a898309f3b7a11a27fff27b52731b53 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Thu, 11 Nov 2010 15:55:58 -0500 Subject: Adding an annotator block that moves tags using 1-to-1 policy. --- gnuradio-core/src/lib/general/gr_annotator_1to1.cc | 101 +++++++++++++++++++++ gnuradio-core/src/lib/general/gr_annotator_1to1.h | 55 +++++++++++ gnuradio-core/src/lib/general/gr_annotator_1to1.i | 32 +++++++ gnuradio-core/src/lib/runtime/qa_block_tags.cc | 5 +- 4 files changed, 191 insertions(+), 2 deletions(-) create mode 100644 gnuradio-core/src/lib/general/gr_annotator_1to1.cc create mode 100644 gnuradio-core/src/lib/general/gr_annotator_1to1.h create mode 100644 gnuradio-core/src/lib/general/gr_annotator_1to1.i (limited to 'gnuradio-core/src') diff --git a/gnuradio-core/src/lib/general/gr_annotator_1to1.cc b/gnuradio-core/src/lib/general/gr_annotator_1to1.cc new file mode 100644 index 000000000..315285e41 --- /dev/null +++ b/gnuradio-core/src/lib/general/gr_annotator_1to1.cc @@ -0,0 +1,101 @@ +/* -*- c++ -*- */ +/* + * Copyright 2010 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include +#include + +gr_annotator_1to1_sptr +gr_make_annotator_1to1 (size_t sizeof_stream_item) +{ + return gnuradio::get_initial_sptr (new gr_annotator_1to1 (sizeof_stream_item)); +} + +gr_annotator_1to1::gr_annotator_1to1 (size_t sizeof_stream_item) + : gr_sync_block ("annotator_1to1", + gr_make_io_signature (1, -1, sizeof_stream_item), + gr_make_io_signature (1, -1, sizeof_stream_item)), + d_itemsize(sizeof_stream_item) +{ + set_tag_propagation_policy(TPP_ONE_TO_ONE); + + d_tag_counter = 0; +} + +gr_annotator_1to1::~gr_annotator_1to1 () +{ + std::cout << d_sout.str(); +} + +int +gr_annotator_1to1::work (int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) +{ + const float **in = (const float **) &input_items[0]; + float **out = (float **) &output_items[0]; + + std::stringstream str; + str << name() << unique_id(); + + uint64_t abs_N = nitems_read(0) + noutput_items; + std::vector all_tags = get_tags_in_range(0, (uint64_t)0, abs_N); + std::vector::iterator itr; + + d_sout << std::endl << "Found " << all_tags.size() << " tags." << std::endl; + d_sout.setf(std::ios::left); + d_sout << std::setw(25) << "Receiver" << std::setw(25) << "Sender" + << std::setw(10) << "nitem" << std::setw(20) << "key" + << std::setw(10) << "value" << std::endl; + + for(itr = all_tags.begin(); itr != all_tags.end(); itr++) { + d_sout << std::setw(25) << str.str() + << std::setw(25) << pmt::pmt_tuple_ref(*itr, 1) + << std::setw(10) << pmt::pmt_tuple_ref(*itr, 0) + << std::setw(20) << pmt::pmt_tuple_ref(*itr, 2) + << std::setw(10) << pmt::pmt_tuple_ref(*itr, 3) + << std::endl; + } + + + // Storing the current noutput_items as the value to the "noutput_items" key + pmt::pmt_t srcid = pmt::pmt_string_to_symbol(str.str()); + pmt::pmt_t key = pmt::pmt_string_to_symbol("seq"); + pmt::pmt_t value; + + // Work does nothing to the data stream; just copy all inputs to outputs + int noutputs = output_items.size(); + int ninputs = input_items.size(); + for (int i = 0; i < noutputs; i++) { + value = pmt::pmt_from_uint64(d_tag_counter++); + memcpy(out[i], in[i], noutput_items * d_itemsize); + add_item_tag(i, abs_N, key, value, srcid); + } + + return noutput_items; +} diff --git a/gnuradio-core/src/lib/general/gr_annotator_1to1.h b/gnuradio-core/src/lib/general/gr_annotator_1to1.h new file mode 100644 index 000000000..d40135be7 --- /dev/null +++ b/gnuradio-core/src/lib/general/gr_annotator_1to1.h @@ -0,0 +1,55 @@ +/* -*- c++ -*- */ +/* + * Copyright 2010 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_GR_ANNOTATOR_1TO1_H +#define INCLUDED_GR_ANNOTATOR_1TO1_H + +#include + +class gr_annotator_1to1; +typedef boost::shared_ptr gr_annotator_1to1_sptr; + +// public constructor +gr_annotator_1to1_sptr +gr_make_annotator_1to1 (size_t sizeof_stream_item); + +class gr_annotator_1to1 : public gr_sync_block +{ + public: + ~gr_annotator_1to1 (); + int work (int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + +protected: + gr_annotator_1to1 (size_t sizeof_stream_item); + + private: + size_t d_itemsize; + std::stringstream d_sout; + uint64_t d_tag_counter; + + friend gr_annotator_1to1_sptr + gr_make_annotator_1to1 (size_t sizeof_stream_item); +}; + +#endif diff --git a/gnuradio-core/src/lib/general/gr_annotator_1to1.i b/gnuradio-core/src/lib/general/gr_annotator_1to1.i new file mode 100644 index 000000000..9fba558b7 --- /dev/null +++ b/gnuradio-core/src/lib/general/gr_annotator_1to1.i @@ -0,0 +1,32 @@ +/* -*- c++ -*- */ +/* + * Copyright 2010 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +GR_SWIG_BLOCK_MAGIC(gr,annotator_1to1); + +gr_annotator_1to1_sptr gr_make_annotator_1to1 (size_t sizeof_stream_item); + +class gr_annotator_1to1 : public gr_sync_block +{ +private: + gr_annotator_1to1 (size_t sizeof_stream_item); +}; + diff --git a/gnuradio-core/src/lib/runtime/qa_block_tags.cc b/gnuradio-core/src/lib/runtime/qa_block_tags.cc index a845f70dc..0c96052e3 100644 --- a/gnuradio-core/src/lib/runtime/qa_block_tags.cc +++ b/gnuradio-core/src/lib/runtime/qa_block_tags.cc @@ -89,8 +89,9 @@ qa_block_tags::t1 () tb->connect(ann1, 0, ann3, 0); tb->connect(ann2, 0, ann4, 0); - tb->connect(ann1, 0, snk0, 0); - tb->connect(ann2, 0, snk1, 0); + tb->connect(ann3, 0, snk0, 0); + tb->connect(ann4, 0, snk1, 0); + tb->run(); } -- cgit From 3f6ebc2be1636a4727b6df9f336b3cb024031c67 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Thu, 11 Nov 2010 19:40:06 -0500 Subject: Modifying the all-to-all stream annotator for better use in testing. It now add tags at pre-determined points in the stream and also grabs all tags that flow past and stores them locally. These tags are to be used for testing that the correct tags are coming through. --- .../src/lib/general/gr_annotator_1toall.cc | 66 +++++++++++----------- .../src/lib/general/gr_annotator_1toall.h | 42 +++++++++++--- .../src/lib/general/gr_annotator_1toall.i | 11 +++- 3 files changed, 74 insertions(+), 45 deletions(-) (limited to 'gnuradio-core/src') diff --git a/gnuradio-core/src/lib/general/gr_annotator_1toall.cc b/gnuradio-core/src/lib/general/gr_annotator_1toall.cc index 34574c9e5..1410b8b94 100644 --- a/gnuradio-core/src/lib/general/gr_annotator_1toall.cc +++ b/gnuradio-core/src/lib/general/gr_annotator_1toall.cc @@ -31,69 +31,69 @@ #include gr_annotator_1toall_sptr -gr_make_annotator_1toall (size_t sizeof_stream_item) +gr_make_annotator_1toall (size_t sizeof_stream_item, float rel_rate) { - return gnuradio::get_initial_sptr (new gr_annotator_1toall (sizeof_stream_item)); + return gnuradio::get_initial_sptr (new gr_annotator_1toall (sizeof_stream_item, rel_rate)); } -gr_annotator_1toall::gr_annotator_1toall (size_t sizeof_stream_item) - : gr_sync_block ("annotator_1toall", - gr_make_io_signature (1, 1, sizeof_stream_item), - gr_make_io_signature (1, -1, sizeof_stream_item)), - d_itemsize(sizeof_stream_item) +gr_annotator_1toall::gr_annotator_1toall (size_t sizeof_stream_item, float rel_rate) + : gr_block ("annotator_1toall", + gr_make_io_signature (1, 1, sizeof_stream_item), + gr_make_io_signature (1, -1, sizeof_stream_item)), + d_itemsize(sizeof_stream_item), d_rel_rate(rel_rate) { set_tag_propagation_policy(TPP_ALL_TO_ALL); d_tag_counter = 0; + set_relative_rate(d_rel_rate); } gr_annotator_1toall::~gr_annotator_1toall () { - std::cout << d_sout.str(); } int -gr_annotator_1toall::work (int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) +gr_annotator_1toall::general_work (int noutput_items, + gr_vector_int &ninput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) { - const float **in = (const float **) &input_items[0]; - float **out = (float **) &output_items[0]; + const float *in = (const float *) input_items[0]; + float *out = (float *) output_items[0]; std::stringstream str; str << name() << unique_id(); - uint64_t abs_N = nitems_read(0) + noutput_items; - std::vector all_tags = get_tags_in_range(0, (uint64_t)0, abs_N); + uint64_t abs_N = nitems_read(0); + std::vector all_tags = get_tags_in_range(0, abs_N, abs_N + noutput_items); std::vector::iterator itr; - d_sout << std::endl << "Found " << all_tags.size() << " tags." << std::endl; - d_sout.setf(std::ios::left); - d_sout << std::setw(25) << "Receiver" << std::setw(25) << "Sender" - << std::setw(10) << "nitem" << std::setw(20) << "key" - << std::setw(10) << "value" << std::endl; - for(itr = all_tags.begin(); itr != all_tags.end(); itr++) { - d_sout << std::setw(25) << str.str() - << std::setw(25) << pmt::pmt_tuple_ref(*itr, 1) - << std::setw(10) << pmt::pmt_tuple_ref(*itr, 0) - << std::setw(20) << pmt::pmt_tuple_ref(*itr, 2) - << std::setw(10) << pmt::pmt_tuple_ref(*itr, 3) - << std::endl; + d_stored_tags.push_back(*itr); } - - // Storing the current noutput_items as the value to the "noutput_items" key - pmt::pmt_t cur_N = pmt::pmt_from_uint64(d_tag_counter++); + // Source ID and key for any tag that might get applied from this block pmt::pmt_t srcid = pmt::pmt_string_to_symbol(str.str()); pmt::pmt_t key = pmt::pmt_string_to_symbol("seq"); // Work does nothing to the data stream; just copy all inputs to outputs + // Adds a new tag when the number of items read is a multiple of N + uint64_t N = 10000; int noutputs = output_items.size(); - for (int i = 0; i < noutputs; i++) { - memcpy(out[i], in[0], noutput_items * d_itemsize); - add_item_tag(i, abs_N, key, cur_N, srcid); + for(int j = 0; j < noutput_items; j++) { + abs_N++; + + for(int i = 0; i < noutputs; i++) { + if(abs_N % N == 0) { + pmt::pmt_t value = pmt::pmt_from_uint64(d_tag_counter++); + add_item_tag(i, abs_N, key, value, srcid); + } + + out = (float*)output_items[i]; + out[j] = in[j]; + } } + consume_each(noutput_items); return noutput_items; } diff --git a/gnuradio-core/src/lib/general/gr_annotator_1toall.h b/gnuradio-core/src/lib/general/gr_annotator_1toall.h index 4417e8c54..e118fd7a0 100644 --- a/gnuradio-core/src/lib/general/gr_annotator_1toall.h +++ b/gnuradio-core/src/lib/general/gr_annotator_1toall.h @@ -23,33 +23,57 @@ #ifndef INCLUDED_GR_ANNOTATOR_1TOALL_H #define INCLUDED_GR_ANNOTATOR_1TOALL_H -#include +#include class gr_annotator_1toall; typedef boost::shared_ptr gr_annotator_1toall_sptr; // public constructor gr_annotator_1toall_sptr -gr_make_annotator_1toall (size_t sizeof_stream_item); +gr_make_annotator_1toall (size_t sizeof_stream_item, float rel_rate=1.0); -class gr_annotator_1toall : public gr_sync_block +/*! + * \brief All-to-all stream annotator testing block. FOR TESTING PURPOSES ONLY. + * + * This block creates tags to be sent downstream every 10,000 items it sees. The + * tags contain the name and ID of the instantiated block, use "seq" as a key, + * and have a counter that increments by 1 for every tag produced that is used + * as the tag's value. The tags are propagated using the all-to-all policy. + * + * It also stores a copy of all tags it sees flow past it. These tags can be + * recalled externally with the data() member. + * + * This block is only meant for testing and showing how to use the tags. + */ +class gr_annotator_1toall : public gr_block { public: ~gr_annotator_1toall (); - int work (int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); + int general_work (int noutput_items, + gr_vector_int &ninput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + + void set_rel_rate(float rrate) { d_rel_rate = rrate; set_relative_rate(d_rel_rate); } + float rel_rate() { return d_rel_rate; } + + + std::vector data() const + { + return d_stored_tags; + } protected: - gr_annotator_1toall (size_t sizeof_stream_item); + gr_annotator_1toall (size_t sizeof_stream_item, float rel_rate); private: size_t d_itemsize; - std::stringstream d_sout; + float d_rel_rate; uint64_t d_tag_counter; + std::vector d_stored_tags; friend gr_annotator_1toall_sptr - gr_make_annotator_1toall (size_t sizeof_stream_item); + gr_make_annotator_1toall (size_t sizeof_stream_item, float rel_rate); }; #endif diff --git a/gnuradio-core/src/lib/general/gr_annotator_1toall.i b/gnuradio-core/src/lib/general/gr_annotator_1toall.i index a8f1de3e0..02f79bf7e 100644 --- a/gnuradio-core/src/lib/general/gr_annotator_1toall.i +++ b/gnuradio-core/src/lib/general/gr_annotator_1toall.i @@ -22,11 +22,16 @@ GR_SWIG_BLOCK_MAGIC(gr,annotator_1toall); -gr_annotator_1toall_sptr gr_make_annotator_1toall (size_t sizeof_stream_item); +gr_annotator_1toall_sptr gr_make_annotator_1toall (size_t sizeof_stream_item, float rel_rate); -class gr_annotator_1toall : public gr_sync_block +class gr_annotator_1toall : public gr_block { +public: + void set_rel_rate(float rrate) { d_rel_rate = rrate; set_relative_rate(d_rel_rate); } + float rel_rate() { return d_rel_rate; } + std::vector data() const; + private: - gr_annotator_1toall (size_t sizeof_stream_item); + gr_annotator_1toall (size_t sizeof_stream_item, float rel_rate); }; -- cgit From 54b396764a9fad91cbfd10f618e4faed1c8bafa2 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Thu, 11 Nov 2010 19:41:46 -0500 Subject: Switches to using the new annotator block with a known graph structure to run tests against the all-to-all tag propagation policy to make sure the tags are flowing downstream properly. Adding stub for testing the 1-to-1 tag propagation policy. --- gnuradio-core/src/lib/runtime/qa_block_tags.cc | 83 +++++++++++++++++++++++++- gnuradio-core/src/lib/runtime/qa_block_tags.h | 2 + 2 files changed, 84 insertions(+), 1 deletion(-) (limited to 'gnuradio-core/src') diff --git a/gnuradio-core/src/lib/runtime/qa_block_tags.cc b/gnuradio-core/src/lib/runtime/qa_block_tags.cc index 0c96052e3..4dc096f27 100644 --- a/gnuradio-core/src/lib/runtime/qa_block_tags.cc +++ b/gnuradio-core/src/lib/runtime/qa_block_tags.cc @@ -30,11 +30,13 @@ #include #include #include +#include #include // ---------------------------------------------------------------- +using namespace pmt; void qa_block_tags::t0 () @@ -73,7 +75,85 @@ qa_block_tags::t1 () 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_annotator_1toall(sizeof(int))); + gr_annotator_1toall_sptr ann0 (gr_make_annotator_1toall(sizeof(int))); + gr_annotator_1toall_sptr ann1 (gr_make_annotator_1toall(sizeof(int))); + gr_annotator_1toall_sptr ann2 (gr_make_annotator_1toall(sizeof(int))); + gr_annotator_1toall_sptr ann3 (gr_make_annotator_1toall(sizeof(int))); + gr_annotator_1toall_sptr ann4 (gr_make_annotator_1toall(sizeof(int))); + gr_block_sptr snk0 (gr_make_null_sink(sizeof(int))); + gr_block_sptr snk1 (gr_make_null_sink(sizeof(int))); + + tb->connect(src, 0, head, 0); + tb->connect(head, 0, ann0, 0); + + tb->connect(ann0, 0, ann1, 0); + tb->connect(ann0, 1, ann2, 0); + tb->connect(ann1, 0, ann3, 0); + tb->connect(ann2, 0, ann4, 0); + + tb->connect(ann3, 0, snk0, 0); + tb->connect(ann4, 0, snk1, 0); + + tb->run(); + + // Kludge together the tags that we know should result from the above graph + std::stringstream str0, str1, str2; + str0 << ann0->name() << ann0->unique_id(); + str1 << ann1->name() << ann1->unique_id(); + str2 << ann2->name() << ann2->unique_id(); + + pmt_t expected_tags3[8]; + expected_tags3[0] = mp(pmt_from_uint64(10000), mp(str1.str()), mp("seq"), mp(0)); + expected_tags3[1] = mp(pmt_from_uint64(10000), mp(str0.str()), mp("seq"), mp(0)); + expected_tags3[2] = mp(pmt_from_uint64(20000), mp(str1.str()), mp("seq"), mp(1)); + expected_tags3[3] = mp(pmt_from_uint64(20000), mp(str0.str()), mp("seq"), mp(2)); + expected_tags3[4] = mp(pmt_from_uint64(30000), mp(str1.str()), mp("seq"), mp(2)); + expected_tags3[5] = mp(pmt_from_uint64(30000), mp(str0.str()), mp("seq"), mp(4)); + expected_tags3[6] = mp(pmt_from_uint64(40000), mp(str1.str()), mp("seq"), mp(3)); + expected_tags3[7] = mp(pmt_from_uint64(40000), mp(str0.str()), mp("seq"), mp(6)); + + pmt_t expected_tags4[8]; + expected_tags4[0] = mp(pmt_from_uint64(10000), mp(str2.str()), mp("seq"), mp(0)); + expected_tags4[1] = mp(pmt_from_uint64(10000), mp(str0.str()), mp("seq"), mp(1)); + expected_tags4[2] = mp(pmt_from_uint64(20000), mp(str2.str()), mp("seq"), mp(1)); + expected_tags4[3] = mp(pmt_from_uint64(20000), mp(str0.str()), mp("seq"), mp(3)); + expected_tags4[4] = mp(pmt_from_uint64(30000), mp(str2.str()), mp("seq"), mp(2)); + expected_tags4[5] = mp(pmt_from_uint64(30000), mp(str0.str()), mp("seq"), mp(5)); + expected_tags4[6] = mp(pmt_from_uint64(40000), mp(str2.str()), mp("seq"), mp(3)); + expected_tags4[7] = mp(pmt_from_uint64(40000), mp(str0.str()), mp("seq"), mp(7)); + + std::vector tags0 = ann0->data(); + std::vector tags3 = ann3->data(); + std::vector tags4 = ann4->data(); + + // The first annotator does not receive any tags from the null sink upstream + CPPUNIT_ASSERT_EQUAL(tags0.size(), (size_t)0); + + // For annotator 3, we know it gets tags from ann0 and ann1, test this + for(size_t i = 0; i < tags3.size(); i++) { + std::cout << "tags3[" << i << "] = " << tags3[i] << "\t\t" << expected_tags3[i] << std::endl; + //pmt_equal(tags3[i], expected_tags3[i]) + CPPUNIT_ASSERT_EQUAL(pmt_write_string(tags3[i]), pmt_write_string(expected_tags3[i])); + } + + // For annotator 4, we know it gets tags from ann0 and ann2, test this + for(size_t i = 0; i < tags4.size(); i++) { + std::cout << "tags4[" << i << "] = " << tags4[i] << "\t\t" << expected_tags4[i] << std::endl; + CPPUNIT_ASSERT_EQUAL(pmt_write_string(tags4[i]), pmt_write_string(expected_tags4[i])); + } +} + + +void +qa_block_tags::t2 () +{ + printf("\nqa_block_tags::t2\n"); + + 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_annotator_1to1(sizeof(int))); gr_block_sptr ann1 (gr_make_annotator_1toall(sizeof(int))); gr_block_sptr ann2 (gr_make_annotator_1toall(sizeof(int))); gr_block_sptr ann3 (gr_make_annotator_1toall(sizeof(int))); @@ -83,6 +163,7 @@ qa_block_tags::t1 () tb->connect(src, 0, head, 0); tb->connect(head, 0, ann0, 0); + tb->connect(head, 0, ann0, 1); tb->connect(ann0, 0, ann1, 0); tb->connect(ann0, 1, ann2, 0); diff --git a/gnuradio-core/src/lib/runtime/qa_block_tags.h b/gnuradio-core/src/lib/runtime/qa_block_tags.h index b7388885f..69bc0480c 100644 --- a/gnuradio-core/src/lib/runtime/qa_block_tags.h +++ b/gnuradio-core/src/lib/runtime/qa_block_tags.h @@ -32,11 +32,13 @@ class qa_block_tags : public CppUnit::TestCase { CPPUNIT_TEST_SUITE (qa_block_tags); CPPUNIT_TEST (t0); CPPUNIT_TEST (t1); + //CPPUNIT_TEST (t2); CPPUNIT_TEST_SUITE_END (); private: void t0 (); void t1 (); + void t2 (); }; -- cgit From 4a63bc91ddceaa8ce9d14a3f714bd0cdc3e85128 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Thu, 11 Nov 2010 20:04:44 -0500 Subject: Reworked 1-to-1 annotator block to better testing purposes. --- gnuradio-core/src/lib/general/gr_annotator_1to1.cc | 69 +++++++++++----------- gnuradio-core/src/lib/general/gr_annotator_1to1.h | 42 ++++++++++--- gnuradio-core/src/lib/general/gr_annotator_1to1.i | 11 +++- .../src/lib/general/gr_annotator_1toall.cc | 2 +- .../src/lib/general/gr_annotator_1toall.i | 4 +- gnuradio-core/src/lib/runtime/qa_block_tags.cc | 58 ++++++++++++++++-- gnuradio-core/src/lib/runtime/qa_block_tags.h | 2 +- 7 files changed, 132 insertions(+), 56 deletions(-) (limited to 'gnuradio-core/src') diff --git a/gnuradio-core/src/lib/general/gr_annotator_1to1.cc b/gnuradio-core/src/lib/general/gr_annotator_1to1.cc index 315285e41..7ecadcd2c 100644 --- a/gnuradio-core/src/lib/general/gr_annotator_1to1.cc +++ b/gnuradio-core/src/lib/general/gr_annotator_1to1.cc @@ -31,71 +31,70 @@ #include gr_annotator_1to1_sptr -gr_make_annotator_1to1 (size_t sizeof_stream_item) +gr_make_annotator_1to1 (size_t sizeof_stream_item, float rel_rate) { - return gnuradio::get_initial_sptr (new gr_annotator_1to1 (sizeof_stream_item)); + return gnuradio::get_initial_sptr (new gr_annotator_1to1 (sizeof_stream_item, rel_rate)); } -gr_annotator_1to1::gr_annotator_1to1 (size_t sizeof_stream_item) - : gr_sync_block ("annotator_1to1", - gr_make_io_signature (1, -1, sizeof_stream_item), - gr_make_io_signature (1, -1, sizeof_stream_item)), - d_itemsize(sizeof_stream_item) +gr_annotator_1to1::gr_annotator_1to1 (size_t sizeof_stream_item, float rel_rate) + : gr_block ("annotator_1to1", + gr_make_io_signature (1, -1, sizeof_stream_item), + gr_make_io_signature (1, -1, sizeof_stream_item)), + d_itemsize(sizeof_stream_item), d_rel_rate(rel_rate) { set_tag_propagation_policy(TPP_ONE_TO_ONE); d_tag_counter = 0; + set_relative_rate(d_rel_rate); } gr_annotator_1to1::~gr_annotator_1to1 () { - std::cout << d_sout.str(); } int -gr_annotator_1to1::work (int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) +gr_annotator_1to1::general_work (int noutput_items, + gr_vector_int &ninput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) { - const float **in = (const float **) &input_items[0]; - float **out = (float **) &output_items[0]; + const float *in = (const float*)input_items[0]; + float *out = (float*)output_items[0]; std::stringstream str; str << name() << unique_id(); - uint64_t abs_N = nitems_read(0) + noutput_items; - std::vector all_tags = get_tags_in_range(0, (uint64_t)0, abs_N); - std::vector::iterator itr; - - d_sout << std::endl << "Found " << all_tags.size() << " tags." << std::endl; - d_sout.setf(std::ios::left); - d_sout << std::setw(25) << "Receiver" << std::setw(25) << "Sender" - << std::setw(10) << "nitem" << std::setw(20) << "key" - << std::setw(10) << "value" << std::endl; + uint64_t abs_N = nitems_read(0); + std::vector all_tags = get_tags_in_range(0, abs_N, abs_N + noutput_items); + std::vector::iterator itr; for(itr = all_tags.begin(); itr != all_tags.end(); itr++) { - d_sout << std::setw(25) << str.str() - << std::setw(25) << pmt::pmt_tuple_ref(*itr, 1) - << std::setw(10) << pmt::pmt_tuple_ref(*itr, 0) - << std::setw(20) << pmt::pmt_tuple_ref(*itr, 2) - << std::setw(10) << pmt::pmt_tuple_ref(*itr, 3) - << std::endl; + d_stored_tags.push_back(*itr); } - // Storing the current noutput_items as the value to the "noutput_items" key pmt::pmt_t srcid = pmt::pmt_string_to_symbol(str.str()); pmt::pmt_t key = pmt::pmt_string_to_symbol("seq"); - pmt::pmt_t value; // Work does nothing to the data stream; just copy all inputs to outputs + // Adds a new tag when the number of items read is a multiple of N + uint64_t N = 10000; int noutputs = output_items.size(); - int ninputs = input_items.size(); - for (int i = 0; i < noutputs; i++) { - value = pmt::pmt_from_uint64(d_tag_counter++); - memcpy(out[i], in[i], noutput_items * d_itemsize); - add_item_tag(i, abs_N, key, value, srcid); + for(int j = 0; j < noutput_items; j++) { + abs_N++; + + for(int i = 0; i < noutputs; i++) { + if(abs_N % N == 0) { + pmt::pmt_t value = pmt::pmt_from_uint64(d_tag_counter++); + add_item_tag(i, abs_N, key, value, srcid); + } + + in = (const float*)input_items[i]; + out = (float*)output_items[i]; + out[j] = in[j]; + } } + consume_each(noutput_items); return noutput_items; } diff --git a/gnuradio-core/src/lib/general/gr_annotator_1to1.h b/gnuradio-core/src/lib/general/gr_annotator_1to1.h index d40135be7..99a4e98c7 100644 --- a/gnuradio-core/src/lib/general/gr_annotator_1to1.h +++ b/gnuradio-core/src/lib/general/gr_annotator_1to1.h @@ -23,33 +23,57 @@ #ifndef INCLUDED_GR_ANNOTATOR_1TO1_H #define INCLUDED_GR_ANNOTATOR_1TO1_H -#include +#include class gr_annotator_1to1; typedef boost::shared_ptr gr_annotator_1to1_sptr; // public constructor gr_annotator_1to1_sptr -gr_make_annotator_1to1 (size_t sizeof_stream_item); +gr_make_annotator_1to1 (size_t sizeof_stream_item, float rel_rate=1.0); -class gr_annotator_1to1 : public gr_sync_block +/*! + * \brief 1-to-1 stream annotator testing block. FOR TESTING PURPOSES ONLY. + * + * This block creates tags to be sent downstream every 10,000 items it sees. The + * tags contain the name and ID of the instantiated block, use "seq" as a key, + * and have a counter that increments by 1 for every tag produced that is used + * as the tag's value. The tags are propagated using the 1-to-1 policy. + * + * It also stores a copy of all tags it sees flow past it. These tags can be + * recalled externally with the data() member. + * + * This block is only meant for testing and showing how to use the tags. + */ +class gr_annotator_1to1 : public gr_block { public: ~gr_annotator_1to1 (); - int work (int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); + int general_work (int noutput_items, + gr_vector_int &ninput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + + void set_rel_rate(float rrate) { d_rel_rate = rrate; set_relative_rate(d_rel_rate); } + float rel_rate() { return d_rel_rate; } + + + std::vector data() const + { + return d_stored_tags; + } protected: - gr_annotator_1to1 (size_t sizeof_stream_item); + gr_annotator_1to1 (size_t sizeof_stream_item, float rel_rate); private: size_t d_itemsize; - std::stringstream d_sout; + float d_rel_rate; uint64_t d_tag_counter; + std::vector d_stored_tags; friend gr_annotator_1to1_sptr - gr_make_annotator_1to1 (size_t sizeof_stream_item); + gr_make_annotator_1to1 (size_t sizeof_stream_item, float rel_rate); }; #endif diff --git a/gnuradio-core/src/lib/general/gr_annotator_1to1.i b/gnuradio-core/src/lib/general/gr_annotator_1to1.i index 9fba558b7..f2342af55 100644 --- a/gnuradio-core/src/lib/general/gr_annotator_1to1.i +++ b/gnuradio-core/src/lib/general/gr_annotator_1to1.i @@ -22,11 +22,16 @@ GR_SWIG_BLOCK_MAGIC(gr,annotator_1to1); -gr_annotator_1to1_sptr gr_make_annotator_1to1 (size_t sizeof_stream_item); +gr_annotator_1to1_sptr gr_make_annotator_1to1 (size_t sizeof_stream_item, float rel_rate); -class gr_annotator_1to1 : public gr_sync_block +class gr_annotator_1to1 : public gr_block { +public: + void set_rel_rate(float rrate); + float rel_rate(); + std::vector data() const; + private: - gr_annotator_1to1 (size_t sizeof_stream_item); + gr_annotator_1to1 (size_t sizeof_stream_item, float rel_rate); }; diff --git a/gnuradio-core/src/lib/general/gr_annotator_1toall.cc b/gnuradio-core/src/lib/general/gr_annotator_1toall.cc index 1410b8b94..47002e3c9 100644 --- a/gnuradio-core/src/lib/general/gr_annotator_1toall.cc +++ b/gnuradio-core/src/lib/general/gr_annotator_1toall.cc @@ -66,8 +66,8 @@ gr_annotator_1toall::general_work (int noutput_items, uint64_t abs_N = nitems_read(0); std::vector all_tags = get_tags_in_range(0, abs_N, abs_N + noutput_items); - std::vector::iterator itr; + std::vector::iterator itr; for(itr = all_tags.begin(); itr != all_tags.end(); itr++) { d_stored_tags.push_back(*itr); } diff --git a/gnuradio-core/src/lib/general/gr_annotator_1toall.i b/gnuradio-core/src/lib/general/gr_annotator_1toall.i index 02f79bf7e..a6bd01017 100644 --- a/gnuradio-core/src/lib/general/gr_annotator_1toall.i +++ b/gnuradio-core/src/lib/general/gr_annotator_1toall.i @@ -27,8 +27,8 @@ gr_annotator_1toall_sptr gr_make_annotator_1toall (size_t sizeof_stream_item, fl class gr_annotator_1toall : public gr_block { public: - void set_rel_rate(float rrate) { d_rel_rate = rrate; set_relative_rate(d_rel_rate); } - float rel_rate() { return d_rel_rate; } + void set_rel_rate(float rrate); + float rel_rate(); std::vector data() const; private: diff --git a/gnuradio-core/src/lib/runtime/qa_block_tags.cc b/gnuradio-core/src/lib/runtime/qa_block_tags.cc index 4dc096f27..ee16ec108 100644 --- a/gnuradio-core/src/lib/runtime/qa_block_tags.cc +++ b/gnuradio-core/src/lib/runtime/qa_block_tags.cc @@ -137,6 +137,7 @@ qa_block_tags::t1 () } // For annotator 4, we know it gets tags from ann0 and ann2, test this + std::cout << std::endl; for(size_t i = 0; i < tags4.size(); i++) { std::cout << "tags4[" << i << "] = " << tags4[i] << "\t\t" << expected_tags4[i] << std::endl; CPPUNIT_ASSERT_EQUAL(pmt_write_string(tags4[i]), pmt_write_string(expected_tags4[i])); @@ -153,11 +154,11 @@ qa_block_tags::t2 () 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_annotator_1to1(sizeof(int))); - gr_block_sptr ann1 (gr_make_annotator_1toall(sizeof(int))); - gr_block_sptr ann2 (gr_make_annotator_1toall(sizeof(int))); - gr_block_sptr ann3 (gr_make_annotator_1toall(sizeof(int))); - gr_block_sptr ann4 (gr_make_annotator_1toall(sizeof(int))); + gr_annotator_1to1_sptr ann0 (gr_make_annotator_1to1(sizeof(int))); + gr_annotator_1toall_sptr ann1 (gr_make_annotator_1toall(sizeof(int))); + gr_annotator_1toall_sptr ann2 (gr_make_annotator_1toall(sizeof(int))); + gr_annotator_1to1_sptr ann3 (gr_make_annotator_1to1(sizeof(int))); + gr_annotator_1to1_sptr ann4 (gr_make_annotator_1to1(sizeof(int))); gr_block_sptr snk0 (gr_make_null_sink(sizeof(int))); gr_block_sptr snk1 (gr_make_null_sink(sizeof(int))); @@ -174,5 +175,52 @@ qa_block_tags::t2 () tb->connect(ann4, 0, snk1, 0); tb->run(); + + // Kludge together the tags that we know should result from the above graph + std::stringstream str0, str1, str2; + str0 << ann0->name() << ann0->unique_id(); + str1 << ann1->name() << ann1->unique_id(); + str2 << ann2->name() << ann2->unique_id(); + + pmt_t expected_tags3[8]; + expected_tags3[0] = mp(pmt_from_uint64(10000), mp(str1.str()), mp("seq"), mp(0)); + expected_tags3[1] = mp(pmt_from_uint64(10000), mp(str0.str()), mp("seq"), mp(0)); + expected_tags3[2] = mp(pmt_from_uint64(20000), mp(str1.str()), mp("seq"), mp(1)); + expected_tags3[3] = mp(pmt_from_uint64(20000), mp(str0.str()), mp("seq"), mp(2)); + expected_tags3[4] = mp(pmt_from_uint64(30000), mp(str1.str()), mp("seq"), mp(2)); + expected_tags3[5] = mp(pmt_from_uint64(30000), mp(str0.str()), mp("seq"), mp(4)); + expected_tags3[6] = mp(pmt_from_uint64(40000), mp(str1.str()), mp("seq"), mp(3)); + expected_tags3[7] = mp(pmt_from_uint64(40000), mp(str0.str()), mp("seq"), mp(6)); + + pmt_t expected_tags4[8]; + expected_tags4[0] = mp(pmt_from_uint64(10000), mp(str2.str()), mp("seq"), mp(0)); + expected_tags4[1] = mp(pmt_from_uint64(10000), mp(str0.str()), mp("seq"), mp(1)); + expected_tags4[2] = mp(pmt_from_uint64(20000), mp(str2.str()), mp("seq"), mp(1)); + expected_tags4[3] = mp(pmt_from_uint64(20000), mp(str0.str()), mp("seq"), mp(3)); + expected_tags4[4] = mp(pmt_from_uint64(30000), mp(str2.str()), mp("seq"), mp(2)); + expected_tags4[5] = mp(pmt_from_uint64(30000), mp(str0.str()), mp("seq"), mp(5)); + expected_tags4[6] = mp(pmt_from_uint64(40000), mp(str2.str()), mp("seq"), mp(3)); + expected_tags4[7] = mp(pmt_from_uint64(40000), mp(str0.str()), mp("seq"), mp(7)); + + std::vector tags0 = ann0->data(); + std::vector tags3 = ann3->data(); + std::vector tags4 = ann4->data(); + + // The first annotator does not receive any tags from the null sink upstream + CPPUNIT_ASSERT_EQUAL(tags0.size(), (size_t)0); + + // For annotator 3, we know it gets tags from ann0 and ann1, test this + for(size_t i = 0; i < tags3.size(); i++) { + std::cout << "tags3[" << i << "] = " << tags3[i] << "\t\t" << expected_tags3[i] << std::endl; + //pmt_equal(tags3[i], expected_tags3[i]) + CPPUNIT_ASSERT_EQUAL(pmt_write_string(tags3[i]), pmt_write_string(expected_tags3[i])); + } + + // For annotator 4, we know it gets tags from ann0 and ann2, test this + std::cout << std::endl; + for(size_t i = 0; i < tags4.size(); i++) { + std::cout << "tags4[" << i << "] = " << tags4[i] << "\t\t" << expected_tags4[i] << std::endl; + CPPUNIT_ASSERT_EQUAL(pmt_write_string(tags4[i]), pmt_write_string(expected_tags4[i])); + } } diff --git a/gnuradio-core/src/lib/runtime/qa_block_tags.h b/gnuradio-core/src/lib/runtime/qa_block_tags.h index 69bc0480c..44bef9fac 100644 --- a/gnuradio-core/src/lib/runtime/qa_block_tags.h +++ b/gnuradio-core/src/lib/runtime/qa_block_tags.h @@ -32,7 +32,7 @@ class qa_block_tags : public CppUnit::TestCase { CPPUNIT_TEST_SUITE (qa_block_tags); CPPUNIT_TEST (t0); CPPUNIT_TEST (t1); - //CPPUNIT_TEST (t2); + CPPUNIT_TEST (t2); CPPUNIT_TEST_SUITE_END (); private: -- cgit From 7ca96ad8b48b3426b470e87042c8e982664f3b9b Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sat, 13 Nov 2010 14:26:39 -0500 Subject: Renamed annotator block that goes all-to-all now so that it can take in arbitrary number of inputs and pass tags on that way. --- gnuradio-core/src/lib/general/Makefile.am | 7 +- gnuradio-core/src/lib/general/general.i | 4 +- .../src/lib/general/gr_annotator_alltoall.cc | 108 +++++++++++++++++++++ .../src/lib/general/gr_annotator_alltoall.h | 79 +++++++++++++++ .../src/lib/general/gr_annotator_alltoall.i | 38 ++++++++ 5 files changed, 231 insertions(+), 5 deletions(-) create mode 100644 gnuradio-core/src/lib/general/gr_annotator_alltoall.cc create mode 100644 gnuradio-core/src/lib/general/gr_annotator_alltoall.h create mode 100644 gnuradio-core/src/lib/general/gr_annotator_alltoall.i (limited to 'gnuradio-core/src') diff --git a/gnuradio-core/src/lib/general/Makefile.am b/gnuradio-core/src/lib/general/Makefile.am index a58461165..2e52d88f3 100644 --- a/gnuradio-core/src/lib/general/Makefile.am +++ b/gnuradio-core/src/lib/general/Makefile.am @@ -176,7 +176,7 @@ libgeneral_la_SOURCES = \ gr_scrambler_bb.cc \ gr_probe_mpsk_snr_c.cc \ gr_probe_density_b.cc \ - gr_annotator_1toall.cc \ + gr_annotator_alltoall.cc \ gr_annotator_1to1.cc libgeneral_qa_la_SOURCES = \ @@ -347,7 +347,8 @@ grinclude_HEADERS = \ gr_scrambler_bb.h \ gr_probe_mpsk_snr_c.h \ gr_probe_density_b.h \ - gr_annotator_1toall.h + gr_annotator_alltoall.h \ + gr_annotator_1to1.h noinst_HEADERS = \ qa_general.h \ @@ -488,6 +489,6 @@ swiginclude_HEADERS = \ gr_scrambler_bb.i \ gr_probe_mpsk_snr_c.i \ gr_probe_density_b.i \ - gr_annotator_1toall.i \ + gr_annotator_alltoall.i \ gr_annotator_1to1.i endif diff --git a/gnuradio-core/src/lib/general/general.i b/gnuradio-core/src/lib/general/general.i index 0dce5f68d..400f0b9b6 100644 --- a/gnuradio-core/src/lib/general/general.i +++ b/gnuradio-core/src/lib/general/general.i @@ -141,7 +141,7 @@ #include #include #include -#include +#include #include %} @@ -264,5 +264,5 @@ %include "gr_copy.i" %include "gr_fll_band_edge_cc.i" %include "gr_additive_scrambler_bb.i" -%include "gr_annotator_1toall.i" +%include "gr_annotator_alltoall.i" %include "gr_annotator_1to1.i" diff --git a/gnuradio-core/src/lib/general/gr_annotator_alltoall.cc b/gnuradio-core/src/lib/general/gr_annotator_alltoall.cc new file mode 100644 index 000000000..f1fb8bc31 --- /dev/null +++ b/gnuradio-core/src/lib/general/gr_annotator_alltoall.cc @@ -0,0 +1,108 @@ +/* -*- c++ -*- */ +/* + * Copyright 2010 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include +#include + +gr_annotator_alltoall_sptr +gr_make_annotator_alltoall (size_t sizeof_stream_item, float rel_rate) +{ + return gnuradio::get_initial_sptr (new gr_annotator_alltoall (sizeof_stream_item, rel_rate)); +} + +gr_annotator_alltoall::gr_annotator_alltoall (size_t sizeof_stream_item, float rel_rate) + : gr_block ("annotator_alltoall", + gr_make_io_signature (1, -1, sizeof_stream_item), + gr_make_io_signature (1, -1, sizeof_stream_item)), + d_itemsize(sizeof_stream_item), d_rel_rate(rel_rate) +{ + set_tag_propagation_policy(TPP_ALL_TO_ALL); + + d_tag_counter = 0; + set_relative_rate(d_rel_rate); +} + +gr_annotator_alltoall::~gr_annotator_alltoall () +{ +} + +int +gr_annotator_alltoall::general_work (int noutput_items, + gr_vector_int &ninput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) +{ + const float *in = (const float *) input_items[0]; + float *out = (float *) output_items[0]; + + std::stringstream str; + str << name() << unique_id(); + + uint64_t abs_N = 0; + int ninputs = input_items.size(); + for(int i = 0; i < ninputs; i++) { + abs_N = nitems_read(i); + std::vector all_tags = get_tags_in_range(i, abs_N, abs_N + noutput_items); + + std::vector::iterator itr; + for(itr = all_tags.begin(); itr != all_tags.end(); itr++) { + d_stored_tags.push_back(*itr); + } + } + + // Source ID and key for any tag that might get applied from this block + pmt::pmt_t srcid = pmt::pmt_string_to_symbol(str.str()); + pmt::pmt_t key = pmt::pmt_string_to_symbol("seq"); + + // Work does nothing to the data stream; just copy all inputs to outputs + // Adds a new tag when the number of items read is a multiple of N + uint64_t N = 10000; + int noutputs = output_items.size(); + for(int j = 0; j < noutput_items; j++) { + abs_N++; + + for(int i = 0; i < noutputs; i++) { + if(abs_N % N == 0) { + pmt::pmt_t value = pmt::pmt_from_uint64(d_tag_counter++); + add_item_tag(i, abs_N, key, value, srcid); + } + + // Sum all of the inputs together for each output. Just 'cause. + out = (float*)output_items[i]; + out[j] = 0; + for(int ins = 0; ins < ninputs; ins++) { + in = (const float*)input_items[ins]; + out[j] += in[j]; + } + } + } + + consume_each(noutput_items); + return noutput_items; +} diff --git a/gnuradio-core/src/lib/general/gr_annotator_alltoall.h b/gnuradio-core/src/lib/general/gr_annotator_alltoall.h new file mode 100644 index 000000000..30480e1ef --- /dev/null +++ b/gnuradio-core/src/lib/general/gr_annotator_alltoall.h @@ -0,0 +1,79 @@ +/* -*- c++ -*- */ +/* + * Copyright 2010 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_GR_ANNOTATOR_ALLTOALL_H +#define INCLUDED_GR_ANNOTATOR_ALLTOALL_H + +#include + +class gr_annotator_alltoall; +typedef boost::shared_ptr gr_annotator_alltoall_sptr; + +// public constructor +gr_annotator_alltoall_sptr +gr_make_annotator_alltoall (size_t sizeof_stream_item, float rel_rate=1.0); + +/*! + * \brief All-to-all stream annotator testing block. FOR TESTING PURPOSES ONLY. + * + * This block creates tags to be sent downstream every 10,000 items it sees. The + * tags contain the name and ID of the instantiated block, use "seq" as a key, + * and have a counter that increments by 1 for every tag produced that is used + * as the tag's value. The tags are propagated using the all-to-all policy. + * + * It also stores a copy of all tags it sees flow past it. These tags can be + * recalled externally with the data() member. + * + * This block is only meant for testing and showing how to use the tags. + */ +class gr_annotator_alltoall : public gr_block +{ + public: + ~gr_annotator_alltoall (); + int general_work (int noutput_items, + gr_vector_int &ninput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + + void set_rel_rate(float rrate) { d_rel_rate = rrate; set_relative_rate(d_rel_rate); } + float rel_rate() { return d_rel_rate; } + + + std::vector data() const + { + return d_stored_tags; + } + +protected: + gr_annotator_alltoall (size_t sizeof_stream_item, float rel_rate); + + private: + size_t d_itemsize; + float d_rel_rate; + uint64_t d_tag_counter; + std::vector d_stored_tags; + + friend gr_annotator_alltoall_sptr + gr_make_annotator_alltoall (size_t sizeof_stream_item, float rel_rate); +}; + +#endif diff --git a/gnuradio-core/src/lib/general/gr_annotator_alltoall.i b/gnuradio-core/src/lib/general/gr_annotator_alltoall.i new file mode 100644 index 000000000..e7ae0b204 --- /dev/null +++ b/gnuradio-core/src/lib/general/gr_annotator_alltoall.i @@ -0,0 +1,38 @@ +/* -*- c++ -*- */ +/* + * Copyright 2010 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +GR_SWIG_BLOCK_MAGIC(gr,annotator_alltoall); + +gr_annotator_alltoall_sptr gr_make_annotator_alltoall (size_t sizeof_stream_item, + float rel_rate); + +class gr_annotator_alltoall : public gr_block +{ +public: + void set_rel_rate(float rrate); + float rel_rate(); + std::vector data() const; + +private: + gr_annotator_alltoall (size_t sizeof_stream_item, float rel_rate); +}; + -- cgit From 74d17ff495c97fbb9eb3bd3cacf08a8dcdf677b6 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sat, 13 Nov 2010 14:27:54 -0500 Subject: Fixing how 1-to-1 annotator handles inputs to better test propagataion method. --- gnuradio-core/src/lib/general/gr_annotator_1to1.cc | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'gnuradio-core/src') diff --git a/gnuradio-core/src/lib/general/gr_annotator_1to1.cc b/gnuradio-core/src/lib/general/gr_annotator_1to1.cc index 7ecadcd2c..273f684ed 100644 --- a/gnuradio-core/src/lib/general/gr_annotator_1to1.cc +++ b/gnuradio-core/src/lib/general/gr_annotator_1to1.cc @@ -64,12 +64,16 @@ gr_annotator_1to1::general_work (int noutput_items, std::stringstream str; str << name() << unique_id(); - uint64_t abs_N = nitems_read(0); - std::vector all_tags = get_tags_in_range(0, abs_N, abs_N + noutput_items); + uint64_t abs_N = 0; + int ninputs = ninput_items.size(); + for(int i = 0; i < ninputs; i++) { + abs_N = nitems_read(i); + std::vector all_tags = get_tags_in_range(i, abs_N, abs_N + noutput_items); - std::vector::iterator itr; - for(itr = all_tags.begin(); itr != all_tags.end(); itr++) { - d_stored_tags.push_back(*itr); + std::vector::iterator itr; + for(itr = all_tags.begin(); itr != all_tags.end(); itr++) { + d_stored_tags.push_back(*itr); + } } // Storing the current noutput_items as the value to the "noutput_items" key @@ -78,12 +82,16 @@ gr_annotator_1to1::general_work (int noutput_items, // Work does nothing to the data stream; just copy all inputs to outputs // Adds a new tag when the number of items read is a multiple of N + abs_N = nitems_read(0); uint64_t N = 10000; int noutputs = output_items.size(); for(int j = 0; j < noutput_items; j++) { abs_N++; - for(int i = 0; i < noutputs; i++) { + // the min() is a hack to make sure this doesn't segfault if there are a + // different number of ins and outs. This is specifically designed to test + // the 1-to-1 propagation policy. + for(int i = 0; i < std::min(noutputs, ninputs); i++) { if(abs_N % N == 0) { pmt::pmt_t value = pmt::pmt_from_uint64(d_tag_counter++); add_item_tag(i, abs_N, key, value, srcid); -- cgit From 3fb01df05227913c2cc8cde6cb651dc1c9a81ff9 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sat, 13 Nov 2010 14:28:37 -0500 Subject: Block executor propagation method returns an error indicator to stop the flowgraph in an error instead of throwing. --- gnuradio-core/src/lib/runtime/gr_block_executor.cc | 24 ++++++++++++++-------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'gnuradio-core/src') diff --git a/gnuradio-core/src/lib/runtime/gr_block_executor.cc b/gnuradio-core/src/lib/runtime/gr_block_executor.cc index 840cf8e5c..86d10f81b 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_executor.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_executor.cc @@ -87,7 +87,7 @@ min_available_space (gr_block_detail *d, int output_multiple) return min_space; } -static void +static int propagate_tags(gr_block::TAG_PROPAGATION_POLICY policy, gr_block_detail *d, const std::vector &start_nitems_read) { @@ -95,17 +95,18 @@ propagate_tags(gr_block::TAG_PROPAGATION_POLICY policy, gr_block_detail *d, // if a sink, we don't need to move downstream; // and do not bother if block uses TAGS_NONE attribute if(d->sink_p()) { - return; + return 0; } switch(policy) { case(gr_block::TPP_DONT): - return; + return 0; break; case(gr_block::TPP_ALL_TO_ALL): // every tag on every input propogates to everyone downstream for(int i = 0; i < d->ninputs(); i++) { - std::vector tuple = d->get_tags_in_range(i, start_nitems_read[i], d->nitems_read(i)); + std::vector tuple = d->get_tags_in_range(i, start_nitems_read[i], + d->nitems_read(i)); std::vector::iterator t; for(t = tuple.begin(); t != tuple.end(); t++ ) { for(int o = 0; o < d->noutputs(); o++) @@ -119,20 +120,24 @@ propagate_tags(gr_block::TAG_PROPAGATION_POLICY policy, gr_block_detail *d, // type of tag-propagation system is selected in gr_block_detail if(d->ninputs() == d->noutputs()) { for(int i = 0; i < d->ninputs(); i++) { - std::vector tuple = d->get_tags_in_range(i, start_nitems_read[i], d->nitems_read(i)); + std::vector tuple = d->get_tags_in_range(i, start_nitems_read[i], + d->nitems_read(i)); std::vector::iterator t; for(t = tuple.begin(); t != tuple.end(); t++ ) { d->output(i)->add_item_tag(*t); } } } - else - throw std::invalid_argument ("propagation_policy 'ONE-TO-ONE' requires ninputs == noutputs"); + else { + std::cerr << "Error: propagation_policy 'ONE-TO-ONE' requires ninputs == noutputs" << std::endl; + return -1; + } break; default: - return; + return 0; } + return 0; } gr_block_executor::gr_block_executor (gr_block_sptr block) @@ -353,7 +358,8 @@ gr_block_executor::run_one_iteration() LOG(*d_log << " general_work: noutput_items = " << noutput_items << " result = " << n << std::endl); - propagate_tags(m->tag_propagation_policy(), d, d_start_nitems_read); + if(propagate_tags(m->tag_propagation_policy(), d, d_start_nitems_read) == -1) + goto were_done; if (n == gr_block::WORK_DONE) goto were_done; -- cgit From 77d778896b72379676d2b00e591f9bbb5f6fcc44 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sat, 13 Nov 2010 14:29:11 -0500 Subject: More test methods. Better testing of the all-to-all policy and more tests for the 1-to-1. --- .../src/lib/general/gr_annotator_1toall.cc | 99 --------------- .../src/lib/general/gr_annotator_1toall.h | 79 ------------ .../src/lib/general/gr_annotator_1toall.i | 37 ------ gnuradio-core/src/lib/runtime/qa_block_tags.cc | 139 +++++++++++++++++++-- gnuradio-core/src/lib/runtime/qa_block_tags.h | 4 + 5 files changed, 134 insertions(+), 224 deletions(-) delete mode 100644 gnuradio-core/src/lib/general/gr_annotator_1toall.cc delete mode 100644 gnuradio-core/src/lib/general/gr_annotator_1toall.h delete mode 100644 gnuradio-core/src/lib/general/gr_annotator_1toall.i (limited to 'gnuradio-core/src') diff --git a/gnuradio-core/src/lib/general/gr_annotator_1toall.cc b/gnuradio-core/src/lib/general/gr_annotator_1toall.cc deleted file mode 100644 index 47002e3c9..000000000 --- a/gnuradio-core/src/lib/general/gr_annotator_1toall.cc +++ /dev/null @@ -1,99 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2010 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3, or (at your option) - * any later version. - * - * GNU Radio is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include -#include -#include - -gr_annotator_1toall_sptr -gr_make_annotator_1toall (size_t sizeof_stream_item, float rel_rate) -{ - return gnuradio::get_initial_sptr (new gr_annotator_1toall (sizeof_stream_item, rel_rate)); -} - -gr_annotator_1toall::gr_annotator_1toall (size_t sizeof_stream_item, float rel_rate) - : gr_block ("annotator_1toall", - gr_make_io_signature (1, 1, sizeof_stream_item), - gr_make_io_signature (1, -1, sizeof_stream_item)), - d_itemsize(sizeof_stream_item), d_rel_rate(rel_rate) -{ - set_tag_propagation_policy(TPP_ALL_TO_ALL); - - d_tag_counter = 0; - set_relative_rate(d_rel_rate); -} - -gr_annotator_1toall::~gr_annotator_1toall () -{ -} - -int -gr_annotator_1toall::general_work (int noutput_items, - gr_vector_int &ninput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) -{ - const float *in = (const float *) input_items[0]; - float *out = (float *) output_items[0]; - - std::stringstream str; - str << name() << unique_id(); - - uint64_t abs_N = nitems_read(0); - std::vector all_tags = get_tags_in_range(0, abs_N, abs_N + noutput_items); - - std::vector::iterator itr; - for(itr = all_tags.begin(); itr != all_tags.end(); itr++) { - d_stored_tags.push_back(*itr); - } - - // Source ID and key for any tag that might get applied from this block - pmt::pmt_t srcid = pmt::pmt_string_to_symbol(str.str()); - pmt::pmt_t key = pmt::pmt_string_to_symbol("seq"); - - // Work does nothing to the data stream; just copy all inputs to outputs - // Adds a new tag when the number of items read is a multiple of N - uint64_t N = 10000; - int noutputs = output_items.size(); - for(int j = 0; j < noutput_items; j++) { - abs_N++; - - for(int i = 0; i < noutputs; i++) { - if(abs_N % N == 0) { - pmt::pmt_t value = pmt::pmt_from_uint64(d_tag_counter++); - add_item_tag(i, abs_N, key, value, srcid); - } - - out = (float*)output_items[i]; - out[j] = in[j]; - } - } - - consume_each(noutput_items); - return noutput_items; -} diff --git a/gnuradio-core/src/lib/general/gr_annotator_1toall.h b/gnuradio-core/src/lib/general/gr_annotator_1toall.h deleted file mode 100644 index e118fd7a0..000000000 --- a/gnuradio-core/src/lib/general/gr_annotator_1toall.h +++ /dev/null @@ -1,79 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2010 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3, or (at your option) - * any later version. - * - * GNU Radio is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - */ - -#ifndef INCLUDED_GR_ANNOTATOR_1TOALL_H -#define INCLUDED_GR_ANNOTATOR_1TOALL_H - -#include - -class gr_annotator_1toall; -typedef boost::shared_ptr gr_annotator_1toall_sptr; - -// public constructor -gr_annotator_1toall_sptr -gr_make_annotator_1toall (size_t sizeof_stream_item, float rel_rate=1.0); - -/*! - * \brief All-to-all stream annotator testing block. FOR TESTING PURPOSES ONLY. - * - * This block creates tags to be sent downstream every 10,000 items it sees. The - * tags contain the name and ID of the instantiated block, use "seq" as a key, - * and have a counter that increments by 1 for every tag produced that is used - * as the tag's value. The tags are propagated using the all-to-all policy. - * - * It also stores a copy of all tags it sees flow past it. These tags can be - * recalled externally with the data() member. - * - * This block is only meant for testing and showing how to use the tags. - */ -class gr_annotator_1toall : public gr_block -{ - public: - ~gr_annotator_1toall (); - int general_work (int noutput_items, - gr_vector_int &ninput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - - void set_rel_rate(float rrate) { d_rel_rate = rrate; set_relative_rate(d_rel_rate); } - float rel_rate() { return d_rel_rate; } - - - std::vector data() const - { - return d_stored_tags; - } - -protected: - gr_annotator_1toall (size_t sizeof_stream_item, float rel_rate); - - private: - size_t d_itemsize; - float d_rel_rate; - uint64_t d_tag_counter; - std::vector d_stored_tags; - - friend gr_annotator_1toall_sptr - gr_make_annotator_1toall (size_t sizeof_stream_item, float rel_rate); -}; - -#endif diff --git a/gnuradio-core/src/lib/general/gr_annotator_1toall.i b/gnuradio-core/src/lib/general/gr_annotator_1toall.i deleted file mode 100644 index a6bd01017..000000000 --- a/gnuradio-core/src/lib/general/gr_annotator_1toall.i +++ /dev/null @@ -1,37 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2010 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3, or (at your option) - * any later version. - * - * GNU Radio is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - */ - -GR_SWIG_BLOCK_MAGIC(gr,annotator_1toall); - -gr_annotator_1toall_sptr gr_make_annotator_1toall (size_t sizeof_stream_item, float rel_rate); - -class gr_annotator_1toall : public gr_block -{ -public: - void set_rel_rate(float rrate); - float rel_rate(); - std::vector data() const; - -private: - gr_annotator_1toall (size_t sizeof_stream_item, float rel_rate); -}; - diff --git a/gnuradio-core/src/lib/runtime/qa_block_tags.cc b/gnuradio-core/src/lib/runtime/qa_block_tags.cc index ee16ec108..2560b7860 100644 --- a/gnuradio-core/src/lib/runtime/qa_block_tags.cc +++ b/gnuradio-core/src/lib/runtime/qa_block_tags.cc @@ -29,7 +29,7 @@ #include #include #include -#include +#include #include #include @@ -75,11 +75,11 @@ qa_block_tags::t1 () 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_annotator_1toall_sptr ann0 (gr_make_annotator_1toall(sizeof(int))); - gr_annotator_1toall_sptr ann1 (gr_make_annotator_1toall(sizeof(int))); - gr_annotator_1toall_sptr ann2 (gr_make_annotator_1toall(sizeof(int))); - gr_annotator_1toall_sptr ann3 (gr_make_annotator_1toall(sizeof(int))); - gr_annotator_1toall_sptr ann4 (gr_make_annotator_1toall(sizeof(int))); + gr_annotator_alltoall_sptr ann0 (gr_make_annotator_alltoall(sizeof(int))); + gr_annotator_alltoall_sptr ann1 (gr_make_annotator_alltoall(sizeof(int))); + gr_annotator_alltoall_sptr ann2 (gr_make_annotator_alltoall(sizeof(int))); + gr_annotator_alltoall_sptr ann3 (gr_make_annotator_alltoall(sizeof(int))); + gr_annotator_alltoall_sptr ann4 (gr_make_annotator_alltoall(sizeof(int))); gr_block_sptr snk0 (gr_make_null_sink(sizeof(int))); gr_block_sptr snk1 (gr_make_null_sink(sizeof(int))); @@ -144,19 +144,112 @@ qa_block_tags::t1 () } } - void qa_block_tags::t2 () { printf("\nqa_block_tags::t2\n"); + 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_annotator_alltoall_sptr ann0 (gr_make_annotator_alltoall(sizeof(int))); + gr_annotator_alltoall_sptr ann1 (gr_make_annotator_alltoall(sizeof(int))); + gr_annotator_alltoall_sptr ann2 (gr_make_annotator_alltoall(sizeof(int))); + gr_annotator_alltoall_sptr ann3 (gr_make_annotator_alltoall(sizeof(int))); + gr_annotator_alltoall_sptr ann4 (gr_make_annotator_alltoall(sizeof(int))); + gr_block_sptr snk0 (gr_make_null_sink(sizeof(int))); + gr_block_sptr snk1 (gr_make_null_sink(sizeof(int))); + gr_block_sptr snk2 (gr_make_null_sink(sizeof(int))); + + tb->connect(src, 0, head, 0); + tb->connect(head, 0, ann0, 0); + + tb->connect(ann0, 0, ann1, 0); + tb->connect(ann0, 1, ann1, 1); + tb->connect(ann1, 0, ann2, 0); + tb->connect(ann1, 1, ann3, 0); + tb->connect(ann1, 2, ann4, 0); + + tb->connect(ann2, 0, snk0, 0); + tb->connect(ann3, 0, snk1, 0); + tb->connect(ann4, 0, snk2, 0); + + tb->run(); + + // Kludge together the tags that we know should result from the above graph + std::stringstream str0, str1; + str0 << ann0->name() << ann0->unique_id(); + str1 << ann1->name() << ann1->unique_id(); + + pmt_t expected_tags2[12]; + expected_tags2[0] = mp(pmt_from_uint64(10000), mp(str1.str()), mp("seq"), mp(0)); + expected_tags2[1] = mp(pmt_from_uint64(10000), mp(str0.str()), mp("seq"), mp(0)); + expected_tags2[2] = mp(pmt_from_uint64(10000), mp(str0.str()), mp("seq"), mp(1)); + expected_tags2[3] = mp(pmt_from_uint64(20000), mp(str1.str()), mp("seq"), mp(3)); + expected_tags2[4] = mp(pmt_from_uint64(20000), mp(str0.str()), mp("seq"), mp(2)); + expected_tags2[5] = mp(pmt_from_uint64(20000), mp(str0.str()), mp("seq"), mp(3)); + expected_tags2[6] = mp(pmt_from_uint64(30000), mp(str1.str()), mp("seq"), mp(6)); + expected_tags2[7] = mp(pmt_from_uint64(30000), mp(str0.str()), mp("seq"), mp(4)); + expected_tags2[8] = mp(pmt_from_uint64(30000), mp(str0.str()), mp("seq"), mp(5)); + expected_tags2[9] = mp(pmt_from_uint64(40000), mp(str1.str()), mp("seq"), mp(9)); + expected_tags2[10] = mp(pmt_from_uint64(40000), mp(str0.str()), mp("seq"), mp(6)); + expected_tags2[11] = mp(pmt_from_uint64(40000), mp(str0.str()), mp("seq"), mp(7)); + + pmt_t expected_tags4[12]; + expected_tags4[0] = mp(pmt_from_uint64(10000), mp(str1.str()), mp("seq"), mp(2)); + expected_tags4[1] = mp(pmt_from_uint64(10000), mp(str0.str()), mp("seq"), mp(0)); + expected_tags4[2] = mp(pmt_from_uint64(10000), mp(str0.str()), mp("seq"), mp(1)); + expected_tags4[3] = mp(pmt_from_uint64(20000), mp(str1.str()), mp("seq"), mp(5)); + expected_tags4[4] = mp(pmt_from_uint64(20000), mp(str0.str()), mp("seq"), mp(2)); + expected_tags4[5] = mp(pmt_from_uint64(20000), mp(str0.str()), mp("seq"), mp(3)); + expected_tags4[6] = mp(pmt_from_uint64(30000), mp(str1.str()), mp("seq"), mp(8)); + expected_tags4[7] = mp(pmt_from_uint64(30000), mp(str0.str()), mp("seq"), mp(4)); + expected_tags4[8] = mp(pmt_from_uint64(30000), mp(str0.str()), mp("seq"), mp(5)); + expected_tags4[9] = mp(pmt_from_uint64(40000), mp(str1.str()), mp("seq"), mp(11)); + expected_tags4[10] = mp(pmt_from_uint64(40000), mp(str0.str()), mp("seq"), mp(6)); + expected_tags4[11] = mp(pmt_from_uint64(40000), mp(str0.str()), mp("seq"), mp(7)); + + std::vector tags0 = ann0->data(); + std::vector tags1 = ann1->data(); + std::vector tags2 = ann2->data(); + std::vector tags4 = ann4->data(); + + // The first annotator does not receive any tags from the null sink upstream + CPPUNIT_ASSERT_EQUAL(tags0.size(), (size_t)0); + CPPUNIT_ASSERT_EQUAL(tags1.size(), (size_t)8); + + // For annotator[2-4], we know it gets tags from ann0 and ann1 + // but the tags from the different outputs of ann1 are different for each. + // Just testing ann2 and ann4; if they are correct it would be + // inconceivable for ann3 to have it wrong. + for(size_t i = 0; i < tags2.size(); i++) { + std::cout << "tags2[" << i << "] = " << tags2[i] << "\t\t" << expected_tags2[i] << std::endl; + //pmt_equal(tags2[i], expected_tags2[i]) + CPPUNIT_ASSERT_EQUAL(pmt_write_string(tags2[i]), pmt_write_string(expected_tags2[i])); + } + + std::cout << std::endl; + for(size_t i = 0; i < tags4.size(); i++) { + std::cout << "tags2[" << i << "] = " << tags4[i] << "\t\t" << expected_tags4[i] << std::endl; + //pmt_equal(tags4[i], expected_tags4[i]) + CPPUNIT_ASSERT_EQUAL(pmt_write_string(tags4[i]), pmt_write_string(expected_tags4[i])); + } +} + + +void +qa_block_tags::t3 () +{ + printf("\nqa_block_tags::t3\n"); + 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_annotator_1to1_sptr ann0 (gr_make_annotator_1to1(sizeof(int))); - gr_annotator_1toall_sptr ann1 (gr_make_annotator_1toall(sizeof(int))); - gr_annotator_1toall_sptr ann2 (gr_make_annotator_1toall(sizeof(int))); + gr_annotator_alltoall_sptr ann1 (gr_make_annotator_alltoall(sizeof(int))); + gr_annotator_alltoall_sptr ann2 (gr_make_annotator_alltoall(sizeof(int))); gr_annotator_1to1_sptr ann3 (gr_make_annotator_1to1(sizeof(int))); gr_annotator_1to1_sptr ann4 (gr_make_annotator_1to1(sizeof(int))); gr_block_sptr snk0 (gr_make_null_sink(sizeof(int))); @@ -224,3 +317,31 @@ qa_block_tags::t2 () } } + +void +qa_block_tags::t4 () +{ + printf("\nqa_block_tags::t4\n"); + + 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_annotator_1to1_sptr ann0 (gr_make_annotator_1to1(sizeof(int))); + gr_annotator_1to1_sptr ann1 (gr_make_annotator_1to1(sizeof(int))); + gr_annotator_1to1_sptr ann2 (gr_make_annotator_1to1(sizeof(int))); + gr_block_sptr snk0 (gr_make_null_sink(sizeof(int))); + gr_block_sptr snk1 (gr_make_null_sink(sizeof(int))); + + // using 1-to-1 tag propagation without having equal number of + // ins and outs. Make sure this works; will just exit run early. + tb->connect(src, 0, head, 0); + tb->connect(head, 0, ann0, 0); + tb->connect(ann0, 0, ann1, 0); + tb->connect(ann0, 1, ann2, 0); + tb->connect(ann1, 0, snk0, 0); + tb->connect(ann2, 0, snk1, 0); + + tb->run(); +} + diff --git a/gnuradio-core/src/lib/runtime/qa_block_tags.h b/gnuradio-core/src/lib/runtime/qa_block_tags.h index 44bef9fac..2bf134d96 100644 --- a/gnuradio-core/src/lib/runtime/qa_block_tags.h +++ b/gnuradio-core/src/lib/runtime/qa_block_tags.h @@ -33,12 +33,16 @@ class qa_block_tags : public CppUnit::TestCase { CPPUNIT_TEST (t0); CPPUNIT_TEST (t1); CPPUNIT_TEST (t2); + CPPUNIT_TEST (t3); + CPPUNIT_TEST (t4); CPPUNIT_TEST_SUITE_END (); private: void t0 (); void t1 (); void t2 (); + void t3 (); + void t4 (); }; -- cgit From 222c6c5be69575c00d6396b95d523e0dfa19f2c3 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sun, 14 Nov 2010 00:04:11 -0500 Subject: Fixing some bugs. --- gnuradio-core/src/lib/general/gr_annotator_1to1.cc | 3 +- .../src/lib/general/gr_annotator_alltoall.cc | 3 +- gnuradio-core/src/lib/runtime/gr_block_executor.cc | 18 +-- gnuradio-core/src/lib/runtime/qa_block_tags.cc | 122 +++++++++++---------- 4 files changed, 77 insertions(+), 69 deletions(-) (limited to 'gnuradio-core/src') diff --git a/gnuradio-core/src/lib/general/gr_annotator_1to1.cc b/gnuradio-core/src/lib/general/gr_annotator_1to1.cc index 273f684ed..8b1da5778 100644 --- a/gnuradio-core/src/lib/general/gr_annotator_1to1.cc +++ b/gnuradio-core/src/lib/general/gr_annotator_1to1.cc @@ -86,8 +86,6 @@ gr_annotator_1to1::general_work (int noutput_items, uint64_t N = 10000; int noutputs = output_items.size(); for(int j = 0; j < noutput_items; j++) { - abs_N++; - // the min() is a hack to make sure this doesn't segfault if there are a // different number of ins and outs. This is specifically designed to test // the 1-to-1 propagation policy. @@ -101,6 +99,7 @@ gr_annotator_1to1::general_work (int noutput_items, out = (float*)output_items[i]; out[j] = in[j]; } + abs_N++; } consume_each(noutput_items); diff --git a/gnuradio-core/src/lib/general/gr_annotator_alltoall.cc b/gnuradio-core/src/lib/general/gr_annotator_alltoall.cc index f1fb8bc31..699d5a256 100644 --- a/gnuradio-core/src/lib/general/gr_annotator_alltoall.cc +++ b/gnuradio-core/src/lib/general/gr_annotator_alltoall.cc @@ -85,8 +85,6 @@ gr_annotator_alltoall::general_work (int noutput_items, uint64_t N = 10000; int noutputs = output_items.size(); for(int j = 0; j < noutput_items; j++) { - abs_N++; - for(int i = 0; i < noutputs; i++) { if(abs_N % N == 0) { pmt::pmt_t value = pmt::pmt_from_uint64(d_tag_counter++); @@ -101,6 +99,7 @@ gr_annotator_alltoall::general_work (int noutput_items, out[j] += in[j]; } } + abs_N++; } consume_each(noutput_items); diff --git a/gnuradio-core/src/lib/runtime/gr_block_executor.cc b/gnuradio-core/src/lib/runtime/gr_block_executor.cc index 86d10f81b..dd0993ec7 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_executor.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_executor.cc @@ -87,7 +87,7 @@ min_available_space (gr_block_detail *d, int output_multiple) return min_space; } -static int +static bool propagate_tags(gr_block::TAG_PROPAGATION_POLICY policy, gr_block_detail *d, const std::vector &start_nitems_read) { @@ -95,12 +95,12 @@ propagate_tags(gr_block::TAG_PROPAGATION_POLICY policy, gr_block_detail *d, // if a sink, we don't need to move downstream; // and do not bother if block uses TAGS_NONE attribute if(d->sink_p()) { - return 0; + return true; } switch(policy) { case(gr_block::TPP_DONT): - return 0; + return true; break; case(gr_block::TPP_ALL_TO_ALL): // every tag on every input propogates to everyone downstream @@ -129,15 +129,15 @@ propagate_tags(gr_block::TAG_PROPAGATION_POLICY policy, gr_block_detail *d, } } else { - std::cerr << "Error: propagation_policy 'ONE-TO-ONE' requires ninputs == noutputs" << std::endl; - return -1; + std::cerr << "Error: gr_block_executor: propagation_policy 'ONE-TO-ONE' requires ninputs == noutputs" << std::endl; + return false; } break; default: - return 0; + return true; } - return 0; + return true; } gr_block_executor::gr_block_executor (gr_block_sptr block) @@ -350,7 +350,7 @@ gr_block_executor::run_one_iteration() // determine where to start looking for new tags as 1 past nitems read for (int i = 0; i < d->ninputs(); i++) - d_start_nitems_read[i] = d->nitems_read(i)+1; + d_start_nitems_read[i] = d->nitems_read(i); // Do the actual work of the block int n = m->general_work (noutput_items, d_ninput_items, @@ -358,7 +358,7 @@ gr_block_executor::run_one_iteration() LOG(*d_log << " general_work: noutput_items = " << noutput_items << " result = " << n << std::endl); - if(propagate_tags(m->tag_propagation_policy(), d, d_start_nitems_read) == -1) + if(!propagate_tags(m->tag_propagation_policy(), d, d_start_nitems_read)) goto were_done; if (n == gr_block::WORK_DONE) diff --git a/gnuradio-core/src/lib/runtime/qa_block_tags.cc b/gnuradio-core/src/lib/runtime/qa_block_tags.cc index 2560b7860..8612a1067 100644 --- a/gnuradio-core/src/lib/runtime/qa_block_tags.cc +++ b/gnuradio-core/src/lib/runtime/qa_block_tags.cc @@ -103,24 +103,24 @@ qa_block_tags::t1 () str2 << ann2->name() << ann2->unique_id(); pmt_t expected_tags3[8]; - expected_tags3[0] = mp(pmt_from_uint64(10000), mp(str1.str()), mp("seq"), mp(0)); - expected_tags3[1] = mp(pmt_from_uint64(10000), mp(str0.str()), mp("seq"), mp(0)); - expected_tags3[2] = mp(pmt_from_uint64(20000), mp(str1.str()), mp("seq"), mp(1)); - expected_tags3[3] = mp(pmt_from_uint64(20000), mp(str0.str()), mp("seq"), mp(2)); - expected_tags3[4] = mp(pmt_from_uint64(30000), mp(str1.str()), mp("seq"), mp(2)); - expected_tags3[5] = mp(pmt_from_uint64(30000), mp(str0.str()), mp("seq"), mp(4)); - expected_tags3[6] = mp(pmt_from_uint64(40000), mp(str1.str()), mp("seq"), mp(3)); - expected_tags3[7] = mp(pmt_from_uint64(40000), mp(str0.str()), mp("seq"), mp(6)); + expected_tags3[0] = mp(pmt_from_uint64(0), mp(str1.str()), mp("seq"), mp(0)); + expected_tags3[1] = mp(pmt_from_uint64(0), mp(str0.str()), mp("seq"), mp(0)); + expected_tags3[2] = mp(pmt_from_uint64(10000), mp(str1.str()), mp("seq"), mp(1)); + expected_tags3[3] = mp(pmt_from_uint64(10000), mp(str0.str()), mp("seq"), mp(2)); + expected_tags3[4] = mp(pmt_from_uint64(20000), mp(str1.str()), mp("seq"), mp(2)); + expected_tags3[5] = mp(pmt_from_uint64(20000), mp(str0.str()), mp("seq"), mp(4)); + expected_tags3[6] = mp(pmt_from_uint64(30000), mp(str1.str()), mp("seq"), mp(3)); + expected_tags3[7] = mp(pmt_from_uint64(30000), mp(str0.str()), mp("seq"), mp(6)); pmt_t expected_tags4[8]; - expected_tags4[0] = mp(pmt_from_uint64(10000), mp(str2.str()), mp("seq"), mp(0)); - expected_tags4[1] = mp(pmt_from_uint64(10000), mp(str0.str()), mp("seq"), mp(1)); - expected_tags4[2] = mp(pmt_from_uint64(20000), mp(str2.str()), mp("seq"), mp(1)); - expected_tags4[3] = mp(pmt_from_uint64(20000), mp(str0.str()), mp("seq"), mp(3)); - expected_tags4[4] = mp(pmt_from_uint64(30000), mp(str2.str()), mp("seq"), mp(2)); - expected_tags4[5] = mp(pmt_from_uint64(30000), mp(str0.str()), mp("seq"), mp(5)); - expected_tags4[6] = mp(pmt_from_uint64(40000), mp(str2.str()), mp("seq"), mp(3)); - expected_tags4[7] = mp(pmt_from_uint64(40000), mp(str0.str()), mp("seq"), mp(7)); + expected_tags4[0] = mp(pmt_from_uint64(0), mp(str2.str()), mp("seq"), mp(0)); + expected_tags4[1] = mp(pmt_from_uint64(0), mp(str0.str()), mp("seq"), mp(1)); + expected_tags4[2] = mp(pmt_from_uint64(10000), mp(str2.str()), mp("seq"), mp(1)); + expected_tags4[3] = mp(pmt_from_uint64(10000), mp(str0.str()), mp("seq"), mp(3)); + expected_tags4[4] = mp(pmt_from_uint64(20000), mp(str2.str()), mp("seq"), mp(2)); + expected_tags4[5] = mp(pmt_from_uint64(20000), mp(str0.str()), mp("seq"), mp(5)); + expected_tags4[6] = mp(pmt_from_uint64(30000), mp(str2.str()), mp("seq"), mp(3)); + expected_tags4[7] = mp(pmt_from_uint64(30000), mp(str0.str()), mp("seq"), mp(7)); std::vector tags0 = ann0->data(); std::vector tags3 = ann3->data(); @@ -130,6 +130,7 @@ qa_block_tags::t1 () CPPUNIT_ASSERT_EQUAL(tags0.size(), (size_t)0); // For annotator 3, we know it gets tags from ann0 and ann1, test this + CPPUNIT_ASSERT_EQUAL(tags3.size(), (size_t)8); for(size_t i = 0; i < tags3.size(); i++) { std::cout << "tags3[" << i << "] = " << tags3[i] << "\t\t" << expected_tags3[i] << std::endl; //pmt_equal(tags3[i], expected_tags3[i]) @@ -138,6 +139,7 @@ qa_block_tags::t1 () // For annotator 4, we know it gets tags from ann0 and ann2, test this std::cout << std::endl; + CPPUNIT_ASSERT_EQUAL(tags4.size(), (size_t)8); for(size_t i = 0; i < tags4.size(); i++) { std::cout << "tags4[" << i << "] = " << tags4[i] << "\t\t" << expected_tags4[i] << std::endl; CPPUNIT_ASSERT_EQUAL(pmt_write_string(tags4[i]), pmt_write_string(expected_tags4[i])); @@ -183,42 +185,48 @@ qa_block_tags::t2 () str1 << ann1->name() << ann1->unique_id(); pmt_t expected_tags2[12]; - expected_tags2[0] = mp(pmt_from_uint64(10000), mp(str1.str()), mp("seq"), mp(0)); - expected_tags2[1] = mp(pmt_from_uint64(10000), mp(str0.str()), mp("seq"), mp(0)); - expected_tags2[2] = mp(pmt_from_uint64(10000), mp(str0.str()), mp("seq"), mp(1)); - expected_tags2[3] = mp(pmt_from_uint64(20000), mp(str1.str()), mp("seq"), mp(3)); - expected_tags2[4] = mp(pmt_from_uint64(20000), mp(str0.str()), mp("seq"), mp(2)); - expected_tags2[5] = mp(pmt_from_uint64(20000), mp(str0.str()), mp("seq"), mp(3)); - expected_tags2[6] = mp(pmt_from_uint64(30000), mp(str1.str()), mp("seq"), mp(6)); - expected_tags2[7] = mp(pmt_from_uint64(30000), mp(str0.str()), mp("seq"), mp(4)); - expected_tags2[8] = mp(pmt_from_uint64(30000), mp(str0.str()), mp("seq"), mp(5)); - expected_tags2[9] = mp(pmt_from_uint64(40000), mp(str1.str()), mp("seq"), mp(9)); - expected_tags2[10] = mp(pmt_from_uint64(40000), mp(str0.str()), mp("seq"), mp(6)); - expected_tags2[11] = mp(pmt_from_uint64(40000), mp(str0.str()), mp("seq"), mp(7)); + expected_tags2[0] = mp(pmt_from_uint64(0), mp(str1.str()), mp("seq"), mp(0)); + expected_tags2[1] = mp(pmt_from_uint64(0), mp(str0.str()), mp("seq"), mp(0)); + expected_tags2[2] = mp(pmt_from_uint64(0), mp(str0.str()), mp("seq"), mp(1)); + expected_tags2[3] = mp(pmt_from_uint64(10000), mp(str1.str()), mp("seq"), mp(3)); + expected_tags2[4] = mp(pmt_from_uint64(10000), mp(str0.str()), mp("seq"), mp(2)); + expected_tags2[5] = mp(pmt_from_uint64(10000), mp(str0.str()), mp("seq"), mp(3)); + expected_tags2[6] = mp(pmt_from_uint64(20000), mp(str1.str()), mp("seq"), mp(6)); + expected_tags2[7] = mp(pmt_from_uint64(20000), mp(str0.str()), mp("seq"), mp(4)); + expected_tags2[8] = mp(pmt_from_uint64(20000), mp(str0.str()), mp("seq"), mp(5)); + expected_tags2[9] = mp(pmt_from_uint64(30000), mp(str1.str()), mp("seq"), mp(9)); + expected_tags2[10] = mp(pmt_from_uint64(30000), mp(str0.str()), mp("seq"), mp(6)); + expected_tags2[11] = mp(pmt_from_uint64(30000), mp(str0.str()), mp("seq"), mp(7)); pmt_t expected_tags4[12]; - expected_tags4[0] = mp(pmt_from_uint64(10000), mp(str1.str()), mp("seq"), mp(2)); - expected_tags4[1] = mp(pmt_from_uint64(10000), mp(str0.str()), mp("seq"), mp(0)); - expected_tags4[2] = mp(pmt_from_uint64(10000), mp(str0.str()), mp("seq"), mp(1)); - expected_tags4[3] = mp(pmt_from_uint64(20000), mp(str1.str()), mp("seq"), mp(5)); - expected_tags4[4] = mp(pmt_from_uint64(20000), mp(str0.str()), mp("seq"), mp(2)); - expected_tags4[5] = mp(pmt_from_uint64(20000), mp(str0.str()), mp("seq"), mp(3)); - expected_tags4[6] = mp(pmt_from_uint64(30000), mp(str1.str()), mp("seq"), mp(8)); - expected_tags4[7] = mp(pmt_from_uint64(30000), mp(str0.str()), mp("seq"), mp(4)); - expected_tags4[8] = mp(pmt_from_uint64(30000), mp(str0.str()), mp("seq"), mp(5)); - expected_tags4[9] = mp(pmt_from_uint64(40000), mp(str1.str()), mp("seq"), mp(11)); - expected_tags4[10] = mp(pmt_from_uint64(40000), mp(str0.str()), mp("seq"), mp(6)); - expected_tags4[11] = mp(pmt_from_uint64(40000), mp(str0.str()), mp("seq"), mp(7)); + expected_tags4[0] = mp(pmt_from_uint64(0), mp(str1.str()), mp("seq"), mp(2)); + expected_tags4[1] = mp(pmt_from_uint64(0), mp(str0.str()), mp("seq"), mp(0)); + expected_tags4[2] = mp(pmt_from_uint64(0), mp(str0.str()), mp("seq"), mp(1)); + expected_tags4[3] = mp(pmt_from_uint64(10000), mp(str1.str()), mp("seq"), mp(5)); + expected_tags4[4] = mp(pmt_from_uint64(10000), mp(str0.str()), mp("seq"), mp(2)); + expected_tags4[5] = mp(pmt_from_uint64(10000), mp(str0.str()), mp("seq"), mp(3)); + expected_tags4[6] = mp(pmt_from_uint64(20000), mp(str1.str()), mp("seq"), mp(8)); + expected_tags4[7] = mp(pmt_from_uint64(20000), mp(str0.str()), mp("seq"), mp(4)); + expected_tags4[8] = mp(pmt_from_uint64(20000), mp(str0.str()), mp("seq"), mp(5)); + expected_tags4[9] = mp(pmt_from_uint64(30000), mp(str1.str()), mp("seq"), mp(11)); + expected_tags4[10] = mp(pmt_from_uint64(30000), mp(str0.str()), mp("seq"), mp(6)); + expected_tags4[11] = mp(pmt_from_uint64(30000), mp(str0.str()), mp("seq"), mp(7)); std::vector tags0 = ann0->data(); std::vector tags1 = ann1->data(); std::vector tags2 = ann2->data(); + std::vector tags3 = ann4->data(); std::vector tags4 = ann4->data(); // The first annotator does not receive any tags from the null sink upstream CPPUNIT_ASSERT_EQUAL(tags0.size(), (size_t)0); CPPUNIT_ASSERT_EQUAL(tags1.size(), (size_t)8); + // Make sure the rest all have 12 tags + CPPUNIT_ASSERT_EQUAL(tags2.size(), (size_t)12); + CPPUNIT_ASSERT_EQUAL(tags3.size(), (size_t)12); + CPPUNIT_ASSERT_EQUAL(tags4.size(), (size_t)12); + // For annotator[2-4], we know it gets tags from ann0 and ann1 // but the tags from the different outputs of ann1 are different for each. // Just testing ann2 and ann4; if they are correct it would be @@ -276,24 +284,24 @@ qa_block_tags::t3 () str2 << ann2->name() << ann2->unique_id(); pmt_t expected_tags3[8]; - expected_tags3[0] = mp(pmt_from_uint64(10000), mp(str1.str()), mp("seq"), mp(0)); - expected_tags3[1] = mp(pmt_from_uint64(10000), mp(str0.str()), mp("seq"), mp(0)); - expected_tags3[2] = mp(pmt_from_uint64(20000), mp(str1.str()), mp("seq"), mp(1)); - expected_tags3[3] = mp(pmt_from_uint64(20000), mp(str0.str()), mp("seq"), mp(2)); - expected_tags3[4] = mp(pmt_from_uint64(30000), mp(str1.str()), mp("seq"), mp(2)); - expected_tags3[5] = mp(pmt_from_uint64(30000), mp(str0.str()), mp("seq"), mp(4)); - expected_tags3[6] = mp(pmt_from_uint64(40000), mp(str1.str()), mp("seq"), mp(3)); - expected_tags3[7] = mp(pmt_from_uint64(40000), mp(str0.str()), mp("seq"), mp(6)); + expected_tags3[0] = mp(pmt_from_uint64(0), mp(str1.str()), mp("seq"), mp(0)); + expected_tags3[1] = mp(pmt_from_uint64(0), mp(str0.str()), mp("seq"), mp(0)); + expected_tags3[2] = mp(pmt_from_uint64(10000), mp(str1.str()), mp("seq"), mp(1)); + expected_tags3[3] = mp(pmt_from_uint64(10000), mp(str0.str()), mp("seq"), mp(2)); + expected_tags3[4] = mp(pmt_from_uint64(20000), mp(str1.str()), mp("seq"), mp(2)); + expected_tags3[5] = mp(pmt_from_uint64(20000), mp(str0.str()), mp("seq"), mp(4)); + expected_tags3[6] = mp(pmt_from_uint64(30000), mp(str1.str()), mp("seq"), mp(3)); + expected_tags3[7] = mp(pmt_from_uint64(30000), mp(str0.str()), mp("seq"), mp(6)); pmt_t expected_tags4[8]; - expected_tags4[0] = mp(pmt_from_uint64(10000), mp(str2.str()), mp("seq"), mp(0)); - expected_tags4[1] = mp(pmt_from_uint64(10000), mp(str0.str()), mp("seq"), mp(1)); - expected_tags4[2] = mp(pmt_from_uint64(20000), mp(str2.str()), mp("seq"), mp(1)); - expected_tags4[3] = mp(pmt_from_uint64(20000), mp(str0.str()), mp("seq"), mp(3)); - expected_tags4[4] = mp(pmt_from_uint64(30000), mp(str2.str()), mp("seq"), mp(2)); - expected_tags4[5] = mp(pmt_from_uint64(30000), mp(str0.str()), mp("seq"), mp(5)); - expected_tags4[6] = mp(pmt_from_uint64(40000), mp(str2.str()), mp("seq"), mp(3)); - expected_tags4[7] = mp(pmt_from_uint64(40000), mp(str0.str()), mp("seq"), mp(7)); + expected_tags4[0] = mp(pmt_from_uint64(0), mp(str2.str()), mp("seq"), mp(0)); + expected_tags4[1] = mp(pmt_from_uint64(0), mp(str0.str()), mp("seq"), mp(1)); + expected_tags4[2] = mp(pmt_from_uint64(10000), mp(str2.str()), mp("seq"), mp(1)); + expected_tags4[3] = mp(pmt_from_uint64(10000), mp(str0.str()), mp("seq"), mp(3)); + expected_tags4[4] = mp(pmt_from_uint64(20000), mp(str2.str()), mp("seq"), mp(2)); + expected_tags4[5] = mp(pmt_from_uint64(20000), mp(str0.str()), mp("seq"), mp(5)); + expected_tags4[6] = mp(pmt_from_uint64(30000), mp(str2.str()), mp("seq"), mp(3)); + expected_tags4[7] = mp(pmt_from_uint64(30000), mp(str0.str()), mp("seq"), mp(7)); std::vector tags0 = ann0->data(); std::vector tags3 = ann3->data(); @@ -303,6 +311,7 @@ qa_block_tags::t3 () CPPUNIT_ASSERT_EQUAL(tags0.size(), (size_t)0); // For annotator 3, we know it gets tags from ann0 and ann1, test this + CPPUNIT_ASSERT_EQUAL(tags3.size(), (size_t)8); for(size_t i = 0; i < tags3.size(); i++) { std::cout << "tags3[" << i << "] = " << tags3[i] << "\t\t" << expected_tags3[i] << std::endl; //pmt_equal(tags3[i], expected_tags3[i]) @@ -311,6 +320,7 @@ qa_block_tags::t3 () // For annotator 4, we know it gets tags from ann0 and ann2, test this std::cout << std::endl; + CPPUNIT_ASSERT_EQUAL(tags4.size(), (size_t)8); for(size_t i = 0; i < tags4.size(); i++) { std::cout << "tags4[" << i << "] = " << tags4[i] << "\t\t" << expected_tags4[i] << std::endl; CPPUNIT_ASSERT_EQUAL(pmt_write_string(tags4[i]), pmt_write_string(expected_tags4[i])); -- cgit From 11b2b7c40048bee5201bd10dd753a9471cd6345d Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sun, 14 Nov 2010 01:20:44 -0500 Subject: Adds argument to annotator test blocks to determine when they add a new tag. --- gnuradio-core/src/lib/general/gr_annotator_1to1.cc | 16 +++++----- gnuradio-core/src/lib/general/gr_annotator_1to1.h | 15 ++++++--- gnuradio-core/src/lib/general/gr_annotator_1to1.i | 7 +++-- .../src/lib/general/gr_annotator_alltoall.cc | 17 +++++----- .../src/lib/general/gr_annotator_alltoall.h | 15 ++++++--- .../src/lib/general/gr_annotator_alltoall.i | 5 +-- gnuradio-core/src/lib/runtime/qa_block_tags.cc | 36 +++++++++++----------- 7 files changed, 67 insertions(+), 44 deletions(-) (limited to 'gnuradio-core/src') diff --git a/gnuradio-core/src/lib/general/gr_annotator_1to1.cc b/gnuradio-core/src/lib/general/gr_annotator_1to1.cc index 8b1da5778..d2d2599d3 100644 --- a/gnuradio-core/src/lib/general/gr_annotator_1to1.cc +++ b/gnuradio-core/src/lib/general/gr_annotator_1to1.cc @@ -31,16 +31,19 @@ #include gr_annotator_1to1_sptr -gr_make_annotator_1to1 (size_t sizeof_stream_item, float rel_rate) +gr_make_annotator_1to1 (uint64_t when, size_t sizeof_stream_item, + float rel_rate) { - return gnuradio::get_initial_sptr (new gr_annotator_1to1 (sizeof_stream_item, rel_rate)); + return gnuradio::get_initial_sptr (new gr_annotator_1to1 + (when, sizeof_stream_item, rel_rate)); } -gr_annotator_1to1::gr_annotator_1to1 (size_t sizeof_stream_item, float rel_rate) +gr_annotator_1to1::gr_annotator_1to1 (uint64_t when, size_t sizeof_stream_item, + float rel_rate) : gr_block ("annotator_1to1", gr_make_io_signature (1, -1, sizeof_stream_item), gr_make_io_signature (1, -1, sizeof_stream_item)), - d_itemsize(sizeof_stream_item), d_rel_rate(rel_rate) + d_itemsize(sizeof_stream_item), d_rel_rate(rel_rate), d_when(when) { set_tag_propagation_policy(TPP_ONE_TO_ONE); @@ -81,16 +84,15 @@ gr_annotator_1to1::general_work (int noutput_items, pmt::pmt_t key = pmt::pmt_string_to_symbol("seq"); // Work does nothing to the data stream; just copy all inputs to outputs - // Adds a new tag when the number of items read is a multiple of N + // Adds a new tag when the number of items read is a multiple of d_when abs_N = nitems_read(0); - uint64_t N = 10000; int noutputs = output_items.size(); for(int j = 0; j < noutput_items; j++) { // the min() is a hack to make sure this doesn't segfault if there are a // different number of ins and outs. This is specifically designed to test // the 1-to-1 propagation policy. for(int i = 0; i < std::min(noutputs, ninputs); i++) { - if(abs_N % N == 0) { + if(abs_N % d_when == 0) { pmt::pmt_t value = pmt::pmt_from_uint64(d_tag_counter++); add_item_tag(i, abs_N, key, value, srcid); } diff --git a/gnuradio-core/src/lib/general/gr_annotator_1to1.h b/gnuradio-core/src/lib/general/gr_annotator_1to1.h index 99a4e98c7..ef14f9b52 100644 --- a/gnuradio-core/src/lib/general/gr_annotator_1to1.h +++ b/gnuradio-core/src/lib/general/gr_annotator_1to1.h @@ -30,7 +30,8 @@ typedef boost::shared_ptr gr_annotator_1to1_sptr; // public constructor gr_annotator_1to1_sptr -gr_make_annotator_1to1 (size_t sizeof_stream_item, float rel_rate=1.0); +gr_make_annotator_1to1 (uint64_t when, size_t sizeof_stream_item, + float rel_rate=1.0); /*! * \brief 1-to-1 stream annotator testing block. FOR TESTING PURPOSES ONLY. @@ -54,7 +55,10 @@ class gr_annotator_1to1 : public gr_block gr_vector_const_void_star &input_items, gr_vector_void_star &output_items); - void set_rel_rate(float rrate) { d_rel_rate = rrate; set_relative_rate(d_rel_rate); } + void set_rel_rate(float rrate) { + d_rel_rate = rrate; + set_relative_rate(d_rel_rate); + } float rel_rate() { return d_rel_rate; } @@ -64,16 +68,19 @@ class gr_annotator_1to1 : public gr_block } protected: - gr_annotator_1to1 (size_t sizeof_stream_item, float rel_rate); + gr_annotator_1to1 (uint64_t when, size_t sizeof_stream_item, + float rel_rate); private: size_t d_itemsize; float d_rel_rate; + uint64_t d_when; uint64_t d_tag_counter; std::vector d_stored_tags; friend gr_annotator_1to1_sptr - gr_make_annotator_1to1 (size_t sizeof_stream_item, float rel_rate); + gr_make_annotator_1to1 (uint64_t when, size_t sizeof_stream_item, + float rel_rate); }; #endif diff --git a/gnuradio-core/src/lib/general/gr_annotator_1to1.i b/gnuradio-core/src/lib/general/gr_annotator_1to1.i index f2342af55..d8f10b44f 100644 --- a/gnuradio-core/src/lib/general/gr_annotator_1to1.i +++ b/gnuradio-core/src/lib/general/gr_annotator_1to1.i @@ -22,7 +22,9 @@ GR_SWIG_BLOCK_MAGIC(gr,annotator_1to1); -gr_annotator_1to1_sptr gr_make_annotator_1to1 (size_t sizeof_stream_item, float rel_rate); +gr_annotator_1to1_sptr gr_make_annotator_1to1 (uint64_t when, + size_t sizeof_stream_item, + float rel_rate); class gr_annotator_1to1 : public gr_block { @@ -32,6 +34,7 @@ public: std::vector data() const; private: - gr_annotator_1to1 (size_t sizeof_stream_item, float rel_rate); + gr_annotator_1to1 (uint64_t when, size_t sizeof_stream_item, + float rel_rate); }; diff --git a/gnuradio-core/src/lib/general/gr_annotator_alltoall.cc b/gnuradio-core/src/lib/general/gr_annotator_alltoall.cc index 699d5a256..88419fe0d 100644 --- a/gnuradio-core/src/lib/general/gr_annotator_alltoall.cc +++ b/gnuradio-core/src/lib/general/gr_annotator_alltoall.cc @@ -31,16 +31,20 @@ #include gr_annotator_alltoall_sptr -gr_make_annotator_alltoall (size_t sizeof_stream_item, float rel_rate) +gr_make_annotator_alltoall (uint64_t when, size_t sizeof_stream_item, + float rel_rate) { - return gnuradio::get_initial_sptr (new gr_annotator_alltoall (sizeof_stream_item, rel_rate)); + return gnuradio::get_initial_sptr (new gr_annotator_alltoall + (when, sizeof_stream_item, rel_rate)); } -gr_annotator_alltoall::gr_annotator_alltoall (size_t sizeof_stream_item, float rel_rate) +gr_annotator_alltoall::gr_annotator_alltoall (uint64_t when, + size_t sizeof_stream_item, + float rel_rate) : gr_block ("annotator_alltoall", gr_make_io_signature (1, -1, sizeof_stream_item), gr_make_io_signature (1, -1, sizeof_stream_item)), - d_itemsize(sizeof_stream_item), d_rel_rate(rel_rate) + d_itemsize(sizeof_stream_item), d_rel_rate(rel_rate), d_when(when) { set_tag_propagation_policy(TPP_ALL_TO_ALL); @@ -81,12 +85,11 @@ gr_annotator_alltoall::general_work (int noutput_items, pmt::pmt_t key = pmt::pmt_string_to_symbol("seq"); // Work does nothing to the data stream; just copy all inputs to outputs - // Adds a new tag when the number of items read is a multiple of N - uint64_t N = 10000; + // Adds a new tag when the number of items read is a multiple of d_when int noutputs = output_items.size(); for(int j = 0; j < noutput_items; j++) { for(int i = 0; i < noutputs; i++) { - if(abs_N % N == 0) { + if(abs_N % d_when == 0) { pmt::pmt_t value = pmt::pmt_from_uint64(d_tag_counter++); add_item_tag(i, abs_N, key, value, srcid); } diff --git a/gnuradio-core/src/lib/general/gr_annotator_alltoall.h b/gnuradio-core/src/lib/general/gr_annotator_alltoall.h index 30480e1ef..d6d2f1503 100644 --- a/gnuradio-core/src/lib/general/gr_annotator_alltoall.h +++ b/gnuradio-core/src/lib/general/gr_annotator_alltoall.h @@ -30,7 +30,8 @@ typedef boost::shared_ptr gr_annotator_alltoall_sptr; // public constructor gr_annotator_alltoall_sptr -gr_make_annotator_alltoall (size_t sizeof_stream_item, float rel_rate=1.0); +gr_make_annotator_alltoall (uint64_t when, size_t sizeof_stream_item, + float rel_rate=1.0); /*! * \brief All-to-all stream annotator testing block. FOR TESTING PURPOSES ONLY. @@ -54,7 +55,10 @@ class gr_annotator_alltoall : public gr_block gr_vector_const_void_star &input_items, gr_vector_void_star &output_items); - void set_rel_rate(float rrate) { d_rel_rate = rrate; set_relative_rate(d_rel_rate); } + void set_rel_rate(float rrate) { + d_rel_rate = rrate; + set_relative_rate(d_rel_rate); + } float rel_rate() { return d_rel_rate; } @@ -64,16 +68,19 @@ class gr_annotator_alltoall : public gr_block } protected: - gr_annotator_alltoall (size_t sizeof_stream_item, float rel_rate); + gr_annotator_alltoall (uint64_t when, size_t sizeof_stream_item, + float rel_rate); private: size_t d_itemsize; float d_rel_rate; + uint64_t d_when; uint64_t d_tag_counter; std::vector d_stored_tags; friend gr_annotator_alltoall_sptr - gr_make_annotator_alltoall (size_t sizeof_stream_item, float rel_rate); + gr_make_annotator_alltoall (uint64_t when, size_t sizeof_stream_item, + float rel_rate); }; #endif diff --git a/gnuradio-core/src/lib/general/gr_annotator_alltoall.i b/gnuradio-core/src/lib/general/gr_annotator_alltoall.i index e7ae0b204..c6abb1b5e 100644 --- a/gnuradio-core/src/lib/general/gr_annotator_alltoall.i +++ b/gnuradio-core/src/lib/general/gr_annotator_alltoall.i @@ -22,7 +22,8 @@ GR_SWIG_BLOCK_MAGIC(gr,annotator_alltoall); -gr_annotator_alltoall_sptr gr_make_annotator_alltoall (size_t sizeof_stream_item, +gr_annotator_alltoall_sptr gr_make_annotator_alltoall (uint64_t when, + size_t sizeof_stream_item, float rel_rate); class gr_annotator_alltoall : public gr_block @@ -33,6 +34,6 @@ public: std::vector data() const; private: - gr_annotator_alltoall (size_t sizeof_stream_item, float rel_rate); + gr_annotator_alltoall (uint64_t when, size_t sizeof_stream_item, float rel_rate); }; diff --git a/gnuradio-core/src/lib/runtime/qa_block_tags.cc b/gnuradio-core/src/lib/runtime/qa_block_tags.cc index 8612a1067..9c4dac698 100644 --- a/gnuradio-core/src/lib/runtime/qa_block_tags.cc +++ b/gnuradio-core/src/lib/runtime/qa_block_tags.cc @@ -75,11 +75,11 @@ qa_block_tags::t1 () 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_annotator_alltoall_sptr ann0 (gr_make_annotator_alltoall(sizeof(int))); - gr_annotator_alltoall_sptr ann1 (gr_make_annotator_alltoall(sizeof(int))); - gr_annotator_alltoall_sptr ann2 (gr_make_annotator_alltoall(sizeof(int))); - gr_annotator_alltoall_sptr ann3 (gr_make_annotator_alltoall(sizeof(int))); - gr_annotator_alltoall_sptr ann4 (gr_make_annotator_alltoall(sizeof(int))); + gr_annotator_alltoall_sptr ann0 (gr_make_annotator_alltoall(10000, sizeof(int))); + gr_annotator_alltoall_sptr ann1 (gr_make_annotator_alltoall(10000, sizeof(int))); + gr_annotator_alltoall_sptr ann2 (gr_make_annotator_alltoall(10000, sizeof(int))); + gr_annotator_alltoall_sptr ann3 (gr_make_annotator_alltoall(10000, sizeof(int))); + gr_annotator_alltoall_sptr ann4 (gr_make_annotator_alltoall(10000, sizeof(int))); gr_block_sptr snk0 (gr_make_null_sink(sizeof(int))); gr_block_sptr snk1 (gr_make_null_sink(sizeof(int))); @@ -155,11 +155,11 @@ qa_block_tags::t2 () 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_annotator_alltoall_sptr ann0 (gr_make_annotator_alltoall(sizeof(int))); - gr_annotator_alltoall_sptr ann1 (gr_make_annotator_alltoall(sizeof(int))); - gr_annotator_alltoall_sptr ann2 (gr_make_annotator_alltoall(sizeof(int))); - gr_annotator_alltoall_sptr ann3 (gr_make_annotator_alltoall(sizeof(int))); - gr_annotator_alltoall_sptr ann4 (gr_make_annotator_alltoall(sizeof(int))); + gr_annotator_alltoall_sptr ann0 (gr_make_annotator_alltoall(10000, sizeof(int))); + gr_annotator_alltoall_sptr ann1 (gr_make_annotator_alltoall(10000, sizeof(int))); + gr_annotator_alltoall_sptr ann2 (gr_make_annotator_alltoall(10000, sizeof(int))); + gr_annotator_alltoall_sptr ann3 (gr_make_annotator_alltoall(10000, sizeof(int))); + gr_annotator_alltoall_sptr ann4 (gr_make_annotator_alltoall(10000, sizeof(int))); gr_block_sptr snk0 (gr_make_null_sink(sizeof(int))); gr_block_sptr snk1 (gr_make_null_sink(sizeof(int))); gr_block_sptr snk2 (gr_make_null_sink(sizeof(int))); @@ -255,11 +255,11 @@ qa_block_tags::t3 () 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_annotator_1to1_sptr ann0 (gr_make_annotator_1to1(sizeof(int))); - gr_annotator_alltoall_sptr ann1 (gr_make_annotator_alltoall(sizeof(int))); - gr_annotator_alltoall_sptr ann2 (gr_make_annotator_alltoall(sizeof(int))); - gr_annotator_1to1_sptr ann3 (gr_make_annotator_1to1(sizeof(int))); - gr_annotator_1to1_sptr ann4 (gr_make_annotator_1to1(sizeof(int))); + gr_annotator_1to1_sptr ann0 (gr_make_annotator_1to1(10000, sizeof(int))); + gr_annotator_alltoall_sptr ann1 (gr_make_annotator_alltoall(10000, sizeof(int))); + gr_annotator_alltoall_sptr ann2 (gr_make_annotator_alltoall(10000, sizeof(int))); + gr_annotator_1to1_sptr ann3 (gr_make_annotator_1to1(10000, sizeof(int))); + gr_annotator_1to1_sptr ann4 (gr_make_annotator_1to1(10000, sizeof(int))); gr_block_sptr snk0 (gr_make_null_sink(sizeof(int))); gr_block_sptr snk1 (gr_make_null_sink(sizeof(int))); @@ -337,9 +337,9 @@ qa_block_tags::t4 () 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_annotator_1to1_sptr ann0 (gr_make_annotator_1to1(sizeof(int))); - gr_annotator_1to1_sptr ann1 (gr_make_annotator_1to1(sizeof(int))); - gr_annotator_1to1_sptr ann2 (gr_make_annotator_1to1(sizeof(int))); + gr_annotator_1to1_sptr ann0 (gr_make_annotator_1to1(10000, sizeof(int))); + gr_annotator_1to1_sptr ann1 (gr_make_annotator_1to1(10000, sizeof(int))); + gr_annotator_1to1_sptr ann2 (gr_make_annotator_1to1(10000, sizeof(int))); gr_block_sptr snk0 (gr_make_null_sink(sizeof(int))); gr_block_sptr snk1 (gr_make_null_sink(sizeof(int))); -- cgit From ad1eb7fd03b18b76b0799e6c6f3e1e40ff861742 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sun, 14 Nov 2010 13:42:40 -0500 Subject: Fixing constructor interface to work better through python (int instead of uint64_t). --- gnuradio-core/src/lib/general/gr_annotator_1to1.cc | 6 +++--- gnuradio-core/src/lib/general/gr_annotator_1to1.h | 6 +++--- gnuradio-core/src/lib/general/gr_annotator_1to1.i | 4 ++-- gnuradio-core/src/lib/general/gr_annotator_alltoall.cc | 6 +++--- gnuradio-core/src/lib/general/gr_annotator_alltoall.h | 6 +++--- gnuradio-core/src/lib/general/gr_annotator_alltoall.i | 4 ++-- 6 files changed, 16 insertions(+), 16 deletions(-) (limited to 'gnuradio-core/src') diff --git a/gnuradio-core/src/lib/general/gr_annotator_1to1.cc b/gnuradio-core/src/lib/general/gr_annotator_1to1.cc index d2d2599d3..1a6cadbcf 100644 --- a/gnuradio-core/src/lib/general/gr_annotator_1to1.cc +++ b/gnuradio-core/src/lib/general/gr_annotator_1to1.cc @@ -31,19 +31,19 @@ #include gr_annotator_1to1_sptr -gr_make_annotator_1to1 (uint64_t when, size_t sizeof_stream_item, +gr_make_annotator_1to1 (int when, size_t sizeof_stream_item, float rel_rate) { return gnuradio::get_initial_sptr (new gr_annotator_1to1 (when, sizeof_stream_item, rel_rate)); } -gr_annotator_1to1::gr_annotator_1to1 (uint64_t when, size_t sizeof_stream_item, +gr_annotator_1to1::gr_annotator_1to1 (int when, size_t sizeof_stream_item, float rel_rate) : gr_block ("annotator_1to1", gr_make_io_signature (1, -1, sizeof_stream_item), gr_make_io_signature (1, -1, sizeof_stream_item)), - d_itemsize(sizeof_stream_item), d_rel_rate(rel_rate), d_when(when) + d_itemsize(sizeof_stream_item), d_rel_rate(rel_rate), d_when((uint64_t)when) { set_tag_propagation_policy(TPP_ONE_TO_ONE); diff --git a/gnuradio-core/src/lib/general/gr_annotator_1to1.h b/gnuradio-core/src/lib/general/gr_annotator_1to1.h index ef14f9b52..e9167bf39 100644 --- a/gnuradio-core/src/lib/general/gr_annotator_1to1.h +++ b/gnuradio-core/src/lib/general/gr_annotator_1to1.h @@ -30,7 +30,7 @@ typedef boost::shared_ptr gr_annotator_1to1_sptr; // public constructor gr_annotator_1to1_sptr -gr_make_annotator_1to1 (uint64_t when, size_t sizeof_stream_item, +gr_make_annotator_1to1 (int when, size_t sizeof_stream_item, float rel_rate=1.0); /*! @@ -68,7 +68,7 @@ class gr_annotator_1to1 : public gr_block } protected: - gr_annotator_1to1 (uint64_t when, size_t sizeof_stream_item, + gr_annotator_1to1 (int when, size_t sizeof_stream_item, float rel_rate); private: @@ -79,7 +79,7 @@ protected: std::vector d_stored_tags; friend gr_annotator_1to1_sptr - gr_make_annotator_1to1 (uint64_t when, size_t sizeof_stream_item, + gr_make_annotator_1to1 (int when, size_t sizeof_stream_item, float rel_rate); }; diff --git a/gnuradio-core/src/lib/general/gr_annotator_1to1.i b/gnuradio-core/src/lib/general/gr_annotator_1to1.i index d8f10b44f..99ab4788c 100644 --- a/gnuradio-core/src/lib/general/gr_annotator_1to1.i +++ b/gnuradio-core/src/lib/general/gr_annotator_1to1.i @@ -22,7 +22,7 @@ GR_SWIG_BLOCK_MAGIC(gr,annotator_1to1); -gr_annotator_1to1_sptr gr_make_annotator_1to1 (uint64_t when, +gr_annotator_1to1_sptr gr_make_annotator_1to1 (int when, size_t sizeof_stream_item, float rel_rate); @@ -34,7 +34,7 @@ public: std::vector data() const; private: - gr_annotator_1to1 (uint64_t when, size_t sizeof_stream_item, + gr_annotator_1to1 (int when, size_t sizeof_stream_item, float rel_rate); }; diff --git a/gnuradio-core/src/lib/general/gr_annotator_alltoall.cc b/gnuradio-core/src/lib/general/gr_annotator_alltoall.cc index 88419fe0d..e7bf5d007 100644 --- a/gnuradio-core/src/lib/general/gr_annotator_alltoall.cc +++ b/gnuradio-core/src/lib/general/gr_annotator_alltoall.cc @@ -31,20 +31,20 @@ #include gr_annotator_alltoall_sptr -gr_make_annotator_alltoall (uint64_t when, size_t sizeof_stream_item, +gr_make_annotator_alltoall (int when, size_t sizeof_stream_item, float rel_rate) { return gnuradio::get_initial_sptr (new gr_annotator_alltoall (when, sizeof_stream_item, rel_rate)); } -gr_annotator_alltoall::gr_annotator_alltoall (uint64_t when, +gr_annotator_alltoall::gr_annotator_alltoall (int when, size_t sizeof_stream_item, float rel_rate) : gr_block ("annotator_alltoall", gr_make_io_signature (1, -1, sizeof_stream_item), gr_make_io_signature (1, -1, sizeof_stream_item)), - d_itemsize(sizeof_stream_item), d_rel_rate(rel_rate), d_when(when) + d_itemsize(sizeof_stream_item), d_rel_rate(rel_rate), d_when((uint64_t)when) { set_tag_propagation_policy(TPP_ALL_TO_ALL); diff --git a/gnuradio-core/src/lib/general/gr_annotator_alltoall.h b/gnuradio-core/src/lib/general/gr_annotator_alltoall.h index d6d2f1503..38cb53bd6 100644 --- a/gnuradio-core/src/lib/general/gr_annotator_alltoall.h +++ b/gnuradio-core/src/lib/general/gr_annotator_alltoall.h @@ -30,7 +30,7 @@ typedef boost::shared_ptr gr_annotator_alltoall_sptr; // public constructor gr_annotator_alltoall_sptr -gr_make_annotator_alltoall (uint64_t when, size_t sizeof_stream_item, +gr_make_annotator_alltoall (int when, size_t sizeof_stream_item, float rel_rate=1.0); /*! @@ -68,7 +68,7 @@ class gr_annotator_alltoall : public gr_block } protected: - gr_annotator_alltoall (uint64_t when, size_t sizeof_stream_item, + gr_annotator_alltoall (int when, size_t sizeof_stream_item, float rel_rate); private: @@ -79,7 +79,7 @@ protected: std::vector d_stored_tags; friend gr_annotator_alltoall_sptr - gr_make_annotator_alltoall (uint64_t when, size_t sizeof_stream_item, + gr_make_annotator_alltoall (int when, size_t sizeof_stream_item, float rel_rate); }; diff --git a/gnuradio-core/src/lib/general/gr_annotator_alltoall.i b/gnuradio-core/src/lib/general/gr_annotator_alltoall.i index c6abb1b5e..7812e80c5 100644 --- a/gnuradio-core/src/lib/general/gr_annotator_alltoall.i +++ b/gnuradio-core/src/lib/general/gr_annotator_alltoall.i @@ -22,7 +22,7 @@ GR_SWIG_BLOCK_MAGIC(gr,annotator_alltoall); -gr_annotator_alltoall_sptr gr_make_annotator_alltoall (uint64_t when, +gr_annotator_alltoall_sptr gr_make_annotator_alltoall (int when, size_t sizeof_stream_item, float rel_rate); @@ -34,6 +34,6 @@ public: std::vector data() const; private: - gr_annotator_alltoall (uint64_t when, size_t sizeof_stream_item, float rel_rate); + gr_annotator_alltoall (int when, size_t sizeof_stream_item, float rel_rate); }; -- cgit From a6b5781e36ff75adb1e4d39d755d4ab8f5efd9dd Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sun, 14 Nov 2010 13:43:05 -0500 Subject: First hack at pruning tags to keep from growing. --- gnuradio-core/src/lib/runtime/gr_buffer.cc | 28 +++++++++++++++++++++++++++- gnuradio-core/src/lib/runtime/gr_buffer.h | 3 +++ 2 files changed, 30 insertions(+), 1 deletion(-) (limited to 'gnuradio-core/src') diff --git a/gnuradio-core/src/lib/runtime/gr_buffer.cc b/gnuradio-core/src/lib/runtime/gr_buffer.cc index 1d67470ec..f6a0a98fb 100644 --- a/gnuradio-core/src/lib/runtime/gr_buffer.cc +++ b/gnuradio-core/src/lib/runtime/gr_buffer.cc @@ -156,8 +156,15 @@ gr_buffer::space_available () // Find out the maximum amount of data available to our readers int most_data = d_readers[0]->items_available (); - for (unsigned int i = 1; i < d_readers.size (); i++) + uint64_t min_items_read = d_readers[0]->nitems_read(); + for (size_t i = 1; i < d_readers.size (); i++) { most_data = std::max (most_data, d_readers[i]->items_available ()); + min_items_read = std::min(min_items_read, d_readers[i]->nitems_read()); + } + + for (size_t i = 0; i < d_readers.size (); i++) { + d_readers[i]->prune_tags(min_items_read); + } // The -1 ensures that the case d_write_index == d_read_index is // unambiguous. It indicates that there is no data for the reader @@ -287,6 +294,25 @@ gr_buffer_reader::get_tags_in_range(uint64_t abs_start, return found_items; } +void +gr_buffer_reader::prune_tags(uint64_t max_time) +{ + int n = 0; + uint64_t item_time; + std::deque::iterator itr = d_buffer->get_tags_begin(); + + while(itr != d_buffer->get_tags_end()) { + item_time = pmt::pmt_to_uint64(pmt::pmt_tuple_ref(*itr, 0)); + if(item_time < max_time) { + d_buffer->tags_pop_front(); + n++; + } + else + break; + itr++; + } +} + long gr_buffer_reader_ncurrently_allocated () { diff --git a/gnuradio-core/src/lib/runtime/gr_buffer.h b/gnuradio-core/src/lib/runtime/gr_buffer.h index d6d5564e8..47ba4cd96 100644 --- a/gnuradio-core/src/lib/runtime/gr_buffer.h +++ b/gnuradio-core/src/lib/runtime/gr_buffer.h @@ -101,6 +101,7 @@ class gr_buffer { std::deque::iterator get_tags_begin() { return d_item_tags.begin(); } std::deque::iterator get_tags_end() { return d_item_tags.end(); } + void tags_pop_front() { d_item_tags.pop_front(); } // ------------------------------------------------------------------------- @@ -260,6 +261,8 @@ class gr_buffer_reader { std::vector get_tags_in_range(uint64_t abs_start, uint64_t abs_end); + void prune_tags(uint64_t max_time); + // ------------------------------------------------------------------------- private: -- cgit From 9922d3553e4e3ec6d55cfe8b7aab9323f649247f Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Mon, 15 Nov 2010 23:15:54 -0800 Subject: Removing autogenerated file. --- .../lib/filter/gri_fir_filter_with_buffer_ccf.h | 131 --------------------- 1 file changed, 131 deletions(-) delete mode 100644 gnuradio-core/src/lib/filter/gri_fir_filter_with_buffer_ccf.h (limited to 'gnuradio-core/src') diff --git a/gnuradio-core/src/lib/filter/gri_fir_filter_with_buffer_ccf.h b/gnuradio-core/src/lib/filter/gri_fir_filter_with_buffer_ccf.h deleted file mode 100644 index bd7fa33cf..000000000 --- a/gnuradio-core/src/lib/filter/gri_fir_filter_with_buffer_ccf.h +++ /dev/null @@ -1,131 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2010 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3, or (at your option) - * any later version. - * - * GNU Radio is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - */ - -/* - * WARNING: This file is automatically generated by generate_gri_fir_XXX.py - * Any changes made to this file will be overwritten. - */ - - -#ifndef INCLUDED_GRI_FIR_FILTER_WITH_BUFFER_CCF_H -#define INCLUDED_GRI_FIR_FILTER_WITH_BUFFER_CCF_H - -#include -#include -#include -#include -#include - -/*! - * \brief FIR with internal buffer for gr_complex input, - gr_complex output and float taps - * \ingroup filter - * - */ - -class gri_fir_filter_with_buffer_ccf { - -protected: - std::vector d_taps; // reversed taps - gr_complex *d_buffer; - unsigned int d_idx; - -public: - - // CONSTRUCTORS - - /*! - * \brief construct new FIR with given taps. - * - * Note that taps must be in forward order, e.g., coefficient 0 is - * stored in new_taps[0], coefficient 1 is stored in - * new_taps[1], etc. - */ - gri_fir_filter_with_buffer_ccf (const std::vector &taps); - - ~gri_fir_filter_with_buffer_ccf (); - - // MANIPULATORS - - /*! - * \brief compute a single output value. - * - * \p input is a single input value of the filter type - * - * \returns the filtered input value. - */ - gr_complex filter (gr_complex input); - - - /*! - * \brief compute a single output value; designed for decimating filters. - * - * \p input is a single input value of the filter type. The value of dec is the - * decimating value of the filter, so input[] must have dec valid values. - * The filter pushes dec number of items onto the circ. buffer before computing - * a single output. - * - * \returns the filtered input value. - */ - gr_complex filter (const gr_complex input[], unsigned long dec); - - /*! - * \brief compute an array of N output values. - * - * \p input must have (n - 1 + ntaps()) valid entries. - * input[0] .. input[n - 1 + ntaps() - 1] are referenced to compute the output values. - */ - void filterN (gr_complex output[], const gr_complex input[], - unsigned long n); - - /*! - * \brief compute an array of N output values, decimating the input - * - * \p input must have (decimate * (n - 1) + ntaps()) valid entries. - * input[0] .. input[decimate * (n - 1) + ntaps() - 1] are referenced to - * compute the output values. - */ - void filterNdec (gr_complex output[], const gr_complex input[], - unsigned long n, unsigned long decimate); - - /*! - * \brief install \p new_taps as the current taps. - */ - void set_taps (const std::vector &taps); - - // ACCESSORS - - /*! - * \return number of taps in filter. - */ - unsigned ntaps () const { return d_taps.size (); } - - /*! - * \return current taps - */ - const std::vector get_taps () const - { - return gr_reverse(d_taps); - } -}; - -#endif /* INCLUDED_GRI_FIR_FILTER_WITH_BUFFER_CCF_H */ -- cgit From 68b06ac6ab9571ac266b663b7f9ab173cf68941e Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Tue, 16 Nov 2010 15:01:44 -0800 Subject: Reverting to a sync_block for the annotator functions. Testing different rates can be done using decimating/interpolating fir filters. --- gnuradio-core/src/lib/general/gr_annotator_1to1.cc | 28 ++++++++----------- gnuradio-core/src/lib/general/gr_annotator_1to1.h | 28 ++++++------------- gnuradio-core/src/lib/general/gr_annotator_1to1.i | 10 ++----- .../src/lib/general/gr_annotator_alltoall.cc | 32 ++++++++++------------ .../src/lib/general/gr_annotator_alltoall.h | 29 ++++++-------------- .../src/lib/general/gr_annotator_alltoall.i | 9 ++---- 6 files changed, 50 insertions(+), 86 deletions(-) (limited to 'gnuradio-core/src') diff --git a/gnuradio-core/src/lib/general/gr_annotator_1to1.cc b/gnuradio-core/src/lib/general/gr_annotator_1to1.cc index 1a6cadbcf..11e2c2b4b 100644 --- a/gnuradio-core/src/lib/general/gr_annotator_1to1.cc +++ b/gnuradio-core/src/lib/general/gr_annotator_1to1.cc @@ -31,24 +31,22 @@ #include gr_annotator_1to1_sptr -gr_make_annotator_1to1 (int when, size_t sizeof_stream_item, - float rel_rate) +gr_make_annotator_1to1 (int when, size_t sizeof_stream_item) { return gnuradio::get_initial_sptr (new gr_annotator_1to1 - (when, sizeof_stream_item, rel_rate)); + (when, sizeof_stream_item)); } -gr_annotator_1to1::gr_annotator_1to1 (int when, size_t sizeof_stream_item, - float rel_rate) - : gr_block ("annotator_1to1", - gr_make_io_signature (1, -1, sizeof_stream_item), - gr_make_io_signature (1, -1, sizeof_stream_item)), - d_itemsize(sizeof_stream_item), d_rel_rate(rel_rate), d_when((uint64_t)when) +gr_annotator_1to1::gr_annotator_1to1 (int when, size_t sizeof_stream_item) + : gr_sync_block ("annotator_1to1", + gr_make_io_signature (1, -1, sizeof_stream_item), + gr_make_io_signature (1, -1, sizeof_stream_item)), + d_itemsize(sizeof_stream_item), d_when((uint64_t)when) { set_tag_propagation_policy(TPP_ONE_TO_ONE); d_tag_counter = 0; - set_relative_rate(d_rel_rate); + set_relative_rate(1.0); } gr_annotator_1to1::~gr_annotator_1to1 () @@ -56,10 +54,9 @@ gr_annotator_1to1::~gr_annotator_1to1 () } int -gr_annotator_1to1::general_work (int noutput_items, - gr_vector_int &ninput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) +gr_annotator_1to1::work (int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) { const float *in = (const float*)input_items[0]; float *out = (float*)output_items[0]; @@ -68,7 +65,7 @@ gr_annotator_1to1::general_work (int noutput_items, str << name() << unique_id(); uint64_t abs_N = 0; - int ninputs = ninput_items.size(); + int ninputs = input_items.size(); for(int i = 0; i < ninputs; i++) { abs_N = nitems_read(i); std::vector all_tags = get_tags_in_range(i, abs_N, abs_N + noutput_items); @@ -104,6 +101,5 @@ gr_annotator_1to1::general_work (int noutput_items, abs_N++; } - consume_each(noutput_items); return noutput_items; } diff --git a/gnuradio-core/src/lib/general/gr_annotator_1to1.h b/gnuradio-core/src/lib/general/gr_annotator_1to1.h index e9167bf39..4abc5b051 100644 --- a/gnuradio-core/src/lib/general/gr_annotator_1to1.h +++ b/gnuradio-core/src/lib/general/gr_annotator_1to1.h @@ -23,15 +23,14 @@ #ifndef INCLUDED_GR_ANNOTATOR_1TO1_H #define INCLUDED_GR_ANNOTATOR_1TO1_H -#include +#include class gr_annotator_1to1; typedef boost::shared_ptr gr_annotator_1to1_sptr; // public constructor gr_annotator_1to1_sptr -gr_make_annotator_1to1 (int when, size_t sizeof_stream_item, - float rel_rate=1.0); +gr_make_annotator_1to1 (int when, size_t sizeof_stream_item); /*! * \brief 1-to-1 stream annotator testing block. FOR TESTING PURPOSES ONLY. @@ -46,21 +45,13 @@ gr_make_annotator_1to1 (int when, size_t sizeof_stream_item, * * This block is only meant for testing and showing how to use the tags. */ -class gr_annotator_1to1 : public gr_block +class gr_annotator_1to1 : public gr_sync_block { public: ~gr_annotator_1to1 (); - int general_work (int noutput_items, - gr_vector_int &ninput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - - void set_rel_rate(float rrate) { - d_rel_rate = rrate; - set_relative_rate(d_rel_rate); - } - float rel_rate() { return d_rel_rate; } - + int work (int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); std::vector data() const { @@ -68,19 +59,16 @@ class gr_annotator_1to1 : public gr_block } protected: - gr_annotator_1to1 (int when, size_t sizeof_stream_item, - float rel_rate); + gr_annotator_1to1 (int when, size_t sizeof_stream_item); private: size_t d_itemsize; - float d_rel_rate; uint64_t d_when; uint64_t d_tag_counter; std::vector d_stored_tags; friend gr_annotator_1to1_sptr - gr_make_annotator_1to1 (int when, size_t sizeof_stream_item, - float rel_rate); + gr_make_annotator_1to1 (int when, size_t sizeof_stream_item); }; #endif diff --git a/gnuradio-core/src/lib/general/gr_annotator_1to1.i b/gnuradio-core/src/lib/general/gr_annotator_1to1.i index 99ab4788c..f29ecbf53 100644 --- a/gnuradio-core/src/lib/general/gr_annotator_1to1.i +++ b/gnuradio-core/src/lib/general/gr_annotator_1to1.i @@ -23,18 +23,14 @@ GR_SWIG_BLOCK_MAGIC(gr,annotator_1to1); gr_annotator_1to1_sptr gr_make_annotator_1to1 (int when, - size_t sizeof_stream_item, - float rel_rate); + size_t sizeof_stream_item); -class gr_annotator_1to1 : public gr_block +class gr_annotator_1to1 : public gr_sync_block { public: - void set_rel_rate(float rrate); - float rel_rate(); std::vector data() const; private: - gr_annotator_1to1 (int when, size_t sizeof_stream_item, - float rel_rate); + gr_annotator_1to1 (int when, size_t sizeof_stream_item); }; diff --git a/gnuradio-core/src/lib/general/gr_annotator_alltoall.cc b/gnuradio-core/src/lib/general/gr_annotator_alltoall.cc index e7bf5d007..9306f9e37 100644 --- a/gnuradio-core/src/lib/general/gr_annotator_alltoall.cc +++ b/gnuradio-core/src/lib/general/gr_annotator_alltoall.cc @@ -31,25 +31,22 @@ #include gr_annotator_alltoall_sptr -gr_make_annotator_alltoall (int when, size_t sizeof_stream_item, - float rel_rate) +gr_make_annotator_alltoall (int when, size_t sizeof_stream_item) { return gnuradio::get_initial_sptr (new gr_annotator_alltoall - (when, sizeof_stream_item, rel_rate)); + (when, sizeof_stream_item)); } gr_annotator_alltoall::gr_annotator_alltoall (int when, - size_t sizeof_stream_item, - float rel_rate) - : gr_block ("annotator_alltoall", - gr_make_io_signature (1, -1, sizeof_stream_item), - gr_make_io_signature (1, -1, sizeof_stream_item)), - d_itemsize(sizeof_stream_item), d_rel_rate(rel_rate), d_when((uint64_t)when) + size_t sizeof_stream_item) + : gr_sync_block ("annotator_alltoall", + gr_make_io_signature (1, -1, sizeof_stream_item), + gr_make_io_signature (1, -1, sizeof_stream_item)), + d_itemsize(sizeof_stream_item), d_when((uint64_t)when) { set_tag_propagation_policy(TPP_ALL_TO_ALL); d_tag_counter = 0; - set_relative_rate(d_rel_rate); } gr_annotator_alltoall::~gr_annotator_alltoall () @@ -57,10 +54,9 @@ gr_annotator_alltoall::~gr_annotator_alltoall () } int -gr_annotator_alltoall::general_work (int noutput_items, - gr_vector_int &ninput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) +gr_annotator_alltoall::work (int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) { const float *in = (const float *) input_items[0]; float *out = (float *) output_items[0]; @@ -68,11 +64,12 @@ gr_annotator_alltoall::general_work (int noutput_items, std::stringstream str; str << name() << unique_id(); - uint64_t abs_N = 0; + uint64_t abs_N = 0, end_N; int ninputs = input_items.size(); for(int i = 0; i < ninputs; i++) { abs_N = nitems_read(i); - std::vector all_tags = get_tags_in_range(i, abs_N, abs_N + noutput_items); + end_N = abs_N + (uint64_t)(noutput_items); + std::vector all_tags = get_tags_in_range(i, abs_N, end_N); std::vector::iterator itr; for(itr = all_tags.begin(); itr != all_tags.end(); itr++) { @@ -86,7 +83,9 @@ gr_annotator_alltoall::general_work (int noutput_items, // Work does nothing to the data stream; just copy all inputs to outputs // Adds a new tag when the number of items read is a multiple of d_when + abs_N = nitems_written(0); int noutputs = output_items.size(); + for(int j = 0; j < noutput_items; j++) { for(int i = 0; i < noutputs; i++) { if(abs_N % d_when == 0) { @@ -105,6 +104,5 @@ gr_annotator_alltoall::general_work (int noutput_items, abs_N++; } - consume_each(noutput_items); return noutput_items; } diff --git a/gnuradio-core/src/lib/general/gr_annotator_alltoall.h b/gnuradio-core/src/lib/general/gr_annotator_alltoall.h index 38cb53bd6..e1e51ebf3 100644 --- a/gnuradio-core/src/lib/general/gr_annotator_alltoall.h +++ b/gnuradio-core/src/lib/general/gr_annotator_alltoall.h @@ -23,15 +23,14 @@ #ifndef INCLUDED_GR_ANNOTATOR_ALLTOALL_H #define INCLUDED_GR_ANNOTATOR_ALLTOALL_H -#include +#include class gr_annotator_alltoall; typedef boost::shared_ptr gr_annotator_alltoall_sptr; // public constructor gr_annotator_alltoall_sptr -gr_make_annotator_alltoall (int when, size_t sizeof_stream_item, - float rel_rate=1.0); +gr_make_annotator_alltoall (int when, size_t sizeof_stream_item); /*! * \brief All-to-all stream annotator testing block. FOR TESTING PURPOSES ONLY. @@ -46,41 +45,31 @@ gr_make_annotator_alltoall (int when, size_t sizeof_stream_item, * * This block is only meant for testing and showing how to use the tags. */ -class gr_annotator_alltoall : public gr_block +class gr_annotator_alltoall : public gr_sync_block { public: ~gr_annotator_alltoall (); - int general_work (int noutput_items, - gr_vector_int &ninput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - - void set_rel_rate(float rrate) { - d_rel_rate = rrate; - set_relative_rate(d_rel_rate); - } - float rel_rate() { return d_rel_rate; } - + int work (int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + std::vector data() const { return d_stored_tags; } protected: - gr_annotator_alltoall (int when, size_t sizeof_stream_item, - float rel_rate); + gr_annotator_alltoall (int when, size_t sizeof_stream_item); private: size_t d_itemsize; - float d_rel_rate; uint64_t d_when; uint64_t d_tag_counter; std::vector d_stored_tags; friend gr_annotator_alltoall_sptr - gr_make_annotator_alltoall (int when, size_t sizeof_stream_item, - float rel_rate); + gr_make_annotator_alltoall (int when, size_t sizeof_stream_item); }; #endif diff --git a/gnuradio-core/src/lib/general/gr_annotator_alltoall.i b/gnuradio-core/src/lib/general/gr_annotator_alltoall.i index 7812e80c5..f9bf6dd9a 100644 --- a/gnuradio-core/src/lib/general/gr_annotator_alltoall.i +++ b/gnuradio-core/src/lib/general/gr_annotator_alltoall.i @@ -23,17 +23,14 @@ GR_SWIG_BLOCK_MAGIC(gr,annotator_alltoall); gr_annotator_alltoall_sptr gr_make_annotator_alltoall (int when, - size_t sizeof_stream_item, - float rel_rate); + size_t sizeof_stream_item); -class gr_annotator_alltoall : public gr_block +class gr_annotator_alltoall : public gr_sync_block { public: - void set_rel_rate(float rrate); - float rel_rate(); std::vector data() const; private: - gr_annotator_alltoall (int when, size_t sizeof_stream_item, float rel_rate); + gr_annotator_alltoall (int when, size_t sizeof_stream_item); }; -- cgit From 8d84a2fc9a804b2248fe43c3d8b230ef99aebaa2 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Tue, 16 Nov 2010 15:02:55 -0800 Subject: Adding a way for propagate_tags to handle different rates. The tags are rewritten between blocks to adjust their count based on teh block's relative_rate.w --- gnuradio-core/src/lib/runtime/gr_block_executor.cc | 14 ++- gnuradio-core/src/lib/runtime/gr_buffer.cc | 4 +- gnuradio-core/src/lib/runtime/qa_block_tags.cc | 99 ++++++++++++++++++++++ gnuradio-core/src/lib/runtime/qa_block_tags.h | 2 + 4 files changed, 114 insertions(+), 5 deletions(-) (limited to 'gnuradio-core/src') diff --git a/gnuradio-core/src/lib/runtime/gr_block_executor.cc b/gnuradio-core/src/lib/runtime/gr_block_executor.cc index dd0993ec7..9882c2e5d 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_executor.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_executor.cc @@ -89,7 +89,7 @@ min_available_space (gr_block_detail *d, int output_multiple) static bool propagate_tags(gr_block::TAG_PROPAGATION_POLICY policy, gr_block_detail *d, - const std::vector &start_nitems_read) + const std::vector &start_nitems_read, double rrate) { // Move tags downstream // if a sink, we don't need to move downstream; @@ -109,8 +109,15 @@ propagate_tags(gr_block::TAG_PROPAGATION_POLICY policy, gr_block_detail *d, d->nitems_read(i)); std::vector::iterator t; for(t = tuple.begin(); t != tuple.end(); t++ ) { + uint64_t newcount = pmt::pmt_to_uint64(pmt::pmt_tuple_ref(*t, 0)); + pmt::pmt_t newtup = pmt::mp(pmt::pmt_from_uint64(newcount * rrate), + pmt::pmt_tuple_ref(*t, 1), + pmt::pmt_tuple_ref(*t, 2), + pmt::pmt_tuple_ref(*t, 3)); + for(int o = 0; o < d->noutputs(); o++) - d->output(o)->add_item_tag(*t); + d->output(o)->add_item_tag(newtup); + //d->output(o)->add_item_tag(*t); } } break; @@ -358,7 +365,8 @@ gr_block_executor::run_one_iteration() LOG(*d_log << " general_work: noutput_items = " << noutput_items << " result = " << n << std::endl); - if(!propagate_tags(m->tag_propagation_policy(), d, d_start_nitems_read)) + if(!propagate_tags(m->tag_propagation_policy(), d, + d_start_nitems_read, m->relative_rate())) goto were_done; if (n == gr_block::WORK_DONE) diff --git a/gnuradio-core/src/lib/runtime/gr_buffer.cc b/gnuradio-core/src/lib/runtime/gr_buffer.cc index f6a0a98fb..84a65f921 100644 --- a/gnuradio-core/src/lib/runtime/gr_buffer.cc +++ b/gnuradio-core/src/lib/runtime/gr_buffer.cc @@ -307,8 +307,8 @@ gr_buffer_reader::prune_tags(uint64_t max_time) d_buffer->tags_pop_front(); n++; } - else - break; + //else + // break; itr++; } } diff --git a/gnuradio-core/src/lib/runtime/qa_block_tags.cc b/gnuradio-core/src/lib/runtime/qa_block_tags.cc index 9c4dac698..e337e3768 100644 --- a/gnuradio-core/src/lib/runtime/qa_block_tags.cc +++ b/gnuradio-core/src/lib/runtime/qa_block_tags.cc @@ -355,3 +355,102 @@ qa_block_tags::t4 () tb->run(); } + +void +qa_block_tags::t5 () +{ + printf("\nqa_block_tags::t5\n"); + + 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_annotator_alltoall_sptr ann0 (gr_make_annotator_alltoall(10000, sizeof(int))); + gr_annotator_alltoall_sptr ann1 (gr_make_annotator_alltoall(1000, sizeof(int))); + gr_annotator_alltoall_sptr ann2 (gr_make_annotator_alltoall(1000, sizeof(int))); + gr_annotator_alltoall_sptr ann3 (gr_make_annotator_alltoall(1000, sizeof(int))); + gr_block_sptr snk0 (gr_make_null_sink(sizeof(int))); + + tb->connect(src, 0, head, 0); + tb->connect(head, 0, ann0, 0); + tb->connect(ann0, 0, ann1, 0); + tb->connect(ann1, 0, ann2, 0); + tb->connect(ann2, 0, snk0, 0); + + tb->run(); + + // Kludge together the tags that we know should result from the above graph + std::stringstream str0, str1, str2; + str0 << ann0->name() << ann0->unique_id(); + str1 << ann1->name() << ann1->unique_id(); + str2 << ann2->name() << ann2->unique_id(); + + pmt_t expected_tags1[5]; + expected_tags1[0] = mp(pmt_from_uint64(0), mp(str0.str()), mp("seq"), mp(0)); + expected_tags1[1] = mp(pmt_from_uint64(10000), mp(str0.str()), mp("seq"), mp(1)); + expected_tags1[2] = mp(pmt_from_uint64(20000), mp(str0.str()), mp("seq"), mp(2)); + expected_tags1[3] = mp(pmt_from_uint64(30000), mp(str0.str()), mp("seq"), mp(3)); + expected_tags1[4] = mp(pmt_from_uint64(40000), mp(str0.str()), mp("seq"), mp(4)); + + pmt_t expected_tags2[10]; + expected_tags2[0] = mp(pmt_from_uint64(0), mp(str1.str()), mp("seq"), mp(0)); + expected_tags2[1] = mp(pmt_from_uint64(0), mp(str0.str()), mp("seq"), mp(0)); + expected_tags2[2] = mp(pmt_from_uint64(1000), mp(str1.str()), mp("seq"), mp(1)); + expected_tags2[3] = mp(pmt_from_uint64(1000), mp(str0.str()), mp("seq"), mp(1)); + expected_tags2[4] = mp(pmt_from_uint64(2000), mp(str1.str()), mp("seq"), mp(2)); + expected_tags2[5] = mp(pmt_from_uint64(2000), mp(str0.str()), mp("seq"), mp(2)); + expected_tags2[6] = mp(pmt_from_uint64(3000), mp(str1.str()), mp("seq"), mp(3)); + expected_tags2[7] = mp(pmt_from_uint64(3000), mp(str0.str()), mp("seq"), mp(3)); + expected_tags2[8] = mp(pmt_from_uint64(4000), mp(str1.str()), mp("seq"), mp(4)); + expected_tags2[9] = mp(pmt_from_uint64(4000), mp(str0.str()), mp("seq"), mp(4)); + + pmt_t expected_tags3[12]; + expected_tags3[0] = mp(pmt_from_uint64(0), mp(str2.str()), mp("seq"), mp(0)); + expected_tags3[1] = mp(pmt_from_uint64(0), mp(str1.str()), mp("seq"), mp(0)); + expected_tags3[2] = mp(pmt_from_uint64(0), mp(str0.str()), mp("seq"), mp(0)); + expected_tags3[3] = mp(pmt_from_uint64(1000), mp(str2.str()), mp("seq"), mp(1)); + expected_tags3[4] = mp(pmt_from_uint64(2000), mp(str1.str()), mp("seq"), mp(1)); + expected_tags3[5] = mp(pmt_from_uint64(2000), mp(str0.str()), mp("seq"), mp(1)); + expected_tags3[6] = mp(pmt_from_uint64(2000), mp(str2.str()), mp("seq"), mp(2)); + expected_tags3[7] = mp(pmt_from_uint64(4000), mp(str1.str()), mp("seq"), mp(2)); + expected_tags3[8] = mp(pmt_from_uint64(4000), mp(str0.str()), mp("seq"), mp(2)); + expected_tags3[9] = mp(pmt_from_uint64(3000), mp(str2.str()), mp("seq"), mp(3)); + expected_tags3[10] = mp(pmt_from_uint64(6000), mp(str1.str()), mp("seq"), mp(3)); + expected_tags3[11] = mp(pmt_from_uint64(6000), mp(str0.str()), mp("seq"), mp(3)); + + std::vector tags0 = ann0->data(); + std::vector tags1 = ann1->data(); + std::vector tags2 = ann2->data(); + std::vector tags3 = ann3->data(); + + // The first annotator does not receive any tags from the null sink upstream + CPPUNIT_ASSERT_EQUAL(tags0.size(), (size_t)0); + + // annotator 1 gets tags from annotator 0 + std::cout << "tags1.size(): " << tags1.size() << std::endl; + //CPPUNIT_ASSERT_EQUAL(tags1.size(), (size_t)4); + for(size_t i = 0; i < tags1.size(); i++) { + std::cout << "tags1[" << i << "] = " << tags1[i] << "\t\t" << expected_tags1[i] << std::endl; + //pmt_equal(tags1[i], expected_tags1[i]) + //CPPUNIT_ASSERT_EQUAL(pmt_write_string(tags1[i]), pmt_write_string(expected_tags1[i])); + } + + // annotator 2 gets tags from annotators 0 and 1 + std::cout << std::endl; + std::cout << "tags2.size(): " << tags2.size() << std::endl; + //CPPUNIT_ASSERT_EQUAL(tags2.size(), (size_t)8); + for(size_t i = 0; i < tags2.size(); i++) { + std::cout << "tags2[" << i << "] = " << tags2[i] << "\t\t" << expected_tags2[i] << std::endl; + //CPPUNIT_ASSERT_EQUAL(pmt_write_string(tags2[i]), pmt_write_string(expected_tags2[i])); + } + + // annotator 3 gets tags from annotators 0, 1, and 2 + std::cout << std::endl; + std::cout << "tags3.size(): " << tags3.size() << std::endl; + //CPPUNIT_ASSERT_EQUAL(tags2.size(), (size_t)8); + for(size_t i = 0; i < tags3.size(); i++) { + std::cout << "tags3[" << i << "] = " << tags3[i] << "\t\t" << expected_tags3[i] << std::endl; + //CPPUNIT_ASSERT_EQUAL(pmt_write_string(tags3[i]), pmt_write_string(expected_tags3[i])); + } +} + diff --git a/gnuradio-core/src/lib/runtime/qa_block_tags.h b/gnuradio-core/src/lib/runtime/qa_block_tags.h index 2bf134d96..661d607b2 100644 --- a/gnuradio-core/src/lib/runtime/qa_block_tags.h +++ b/gnuradio-core/src/lib/runtime/qa_block_tags.h @@ -35,6 +35,7 @@ class qa_block_tags : public CppUnit::TestCase { CPPUNIT_TEST (t2); CPPUNIT_TEST (t3); CPPUNIT_TEST (t4); + //CPPUNIT_TEST (t5); CPPUNIT_TEST_SUITE_END (); private: @@ -43,6 +44,7 @@ class qa_block_tags : public CppUnit::TestCase { void t2 (); void t3 (); void t4 (); + void t5 (); }; -- cgit From 9d6c7400ba39a9d5e3ddab9da294b8b6303d9509 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Tue, 16 Nov 2010 15:36:24 -0800 Subject: Adding QA test for testing rate changes. --- gnuradio-core/src/lib/runtime/qa_block_tags.cc | 50 +++++++++++++++----------- gnuradio-core/src/lib/runtime/qa_block_tags.h | 2 +- 2 files changed, 31 insertions(+), 21 deletions(-) (limited to 'gnuradio-core/src') diff --git a/gnuradio-core/src/lib/runtime/qa_block_tags.cc b/gnuradio-core/src/lib/runtime/qa_block_tags.cc index e337e3768..2092e48ed 100644 --- a/gnuradio-core/src/lib/runtime/qa_block_tags.cc +++ b/gnuradio-core/src/lib/runtime/qa_block_tags.cc @@ -31,6 +31,9 @@ #include #include #include +#include +#include +#include #include @@ -363,19 +366,27 @@ qa_block_tags::t5 () 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_annotator_alltoall_sptr ann0 (gr_make_annotator_alltoall(10000, sizeof(int))); - gr_annotator_alltoall_sptr ann1 (gr_make_annotator_alltoall(1000, sizeof(int))); - gr_annotator_alltoall_sptr ann2 (gr_make_annotator_alltoall(1000, sizeof(int))); - gr_annotator_alltoall_sptr ann3 (gr_make_annotator_alltoall(1000, sizeof(int))); - gr_block_sptr snk0 (gr_make_null_sink(sizeof(int))); - + gr_block_sptr src (gr_make_null_source(sizeof(float))); + gr_block_sptr head (gr_make_head(sizeof(float), N)); + gr_annotator_alltoall_sptr ann0 (gr_make_annotator_alltoall(10000, sizeof(float))); + gr_annotator_alltoall_sptr ann1 (gr_make_annotator_alltoall(10000, sizeof(float))); + gr_annotator_alltoall_sptr ann2 (gr_make_annotator_alltoall(1000, sizeof(float))); + gr_annotator_alltoall_sptr ann3 (gr_make_annotator_alltoall(2000, sizeof(float))); + gr_block_sptr snk0 (gr_make_null_sink(sizeof(float))); + + // Rate change blocks + std::vector taps = gr_firdes::low_pass_2(1, 1, 0.4, 0.1, 60); + gr_fir_filter_fff_sptr fir_dec10 (gr_make_fir_filter_fff(10, taps)); + gr_interp_fir_filter_fff_sptr fir_int2 (gr_make_interp_fir_filter_fff(2, taps)); + tb->connect(src, 0, head, 0); tb->connect(head, 0, ann0, 0); tb->connect(ann0, 0, ann1, 0); - tb->connect(ann1, 0, ann2, 0); - tb->connect(ann2, 0, snk0, 0); + tb->connect(ann1, 0, fir_dec10, 0); + tb->connect(fir_dec10, 0, ann2, 0); + tb->connect(ann2, 0, fir_int2, 0); + tb->connect(fir_int2, 0, ann3, 0); + tb->connect(ann3, 0, snk0, 0); tb->run(); @@ -390,7 +401,6 @@ qa_block_tags::t5 () expected_tags1[1] = mp(pmt_from_uint64(10000), mp(str0.str()), mp("seq"), mp(1)); expected_tags1[2] = mp(pmt_from_uint64(20000), mp(str0.str()), mp("seq"), mp(2)); expected_tags1[3] = mp(pmt_from_uint64(30000), mp(str0.str()), mp("seq"), mp(3)); - expected_tags1[4] = mp(pmt_from_uint64(40000), mp(str0.str()), mp("seq"), mp(4)); pmt_t expected_tags2[10]; expected_tags2[0] = mp(pmt_from_uint64(0), mp(str1.str()), mp("seq"), mp(0)); @@ -408,13 +418,13 @@ qa_block_tags::t5 () expected_tags3[0] = mp(pmt_from_uint64(0), mp(str2.str()), mp("seq"), mp(0)); expected_tags3[1] = mp(pmt_from_uint64(0), mp(str1.str()), mp("seq"), mp(0)); expected_tags3[2] = mp(pmt_from_uint64(0), mp(str0.str()), mp("seq"), mp(0)); - expected_tags3[3] = mp(pmt_from_uint64(1000), mp(str2.str()), mp("seq"), mp(1)); + expected_tags3[3] = mp(pmt_from_uint64(2000), mp(str2.str()), mp("seq"), mp(1)); expected_tags3[4] = mp(pmt_from_uint64(2000), mp(str1.str()), mp("seq"), mp(1)); expected_tags3[5] = mp(pmt_from_uint64(2000), mp(str0.str()), mp("seq"), mp(1)); - expected_tags3[6] = mp(pmt_from_uint64(2000), mp(str2.str()), mp("seq"), mp(2)); + expected_tags3[6] = mp(pmt_from_uint64(4000), mp(str2.str()), mp("seq"), mp(2)); expected_tags3[7] = mp(pmt_from_uint64(4000), mp(str1.str()), mp("seq"), mp(2)); expected_tags3[8] = mp(pmt_from_uint64(4000), mp(str0.str()), mp("seq"), mp(2)); - expected_tags3[9] = mp(pmt_from_uint64(3000), mp(str2.str()), mp("seq"), mp(3)); + expected_tags3[9] = mp(pmt_from_uint64(6000), mp(str2.str()), mp("seq"), mp(3)); expected_tags3[10] = mp(pmt_from_uint64(6000), mp(str1.str()), mp("seq"), mp(3)); expected_tags3[11] = mp(pmt_from_uint64(6000), mp(str0.str()), mp("seq"), mp(3)); @@ -428,29 +438,29 @@ qa_block_tags::t5 () // annotator 1 gets tags from annotator 0 std::cout << "tags1.size(): " << tags1.size() << std::endl; - //CPPUNIT_ASSERT_EQUAL(tags1.size(), (size_t)4); + CPPUNIT_ASSERT_EQUAL(tags1.size(), (size_t)4); for(size_t i = 0; i < tags1.size(); i++) { std::cout << "tags1[" << i << "] = " << tags1[i] << "\t\t" << expected_tags1[i] << std::endl; //pmt_equal(tags1[i], expected_tags1[i]) - //CPPUNIT_ASSERT_EQUAL(pmt_write_string(tags1[i]), pmt_write_string(expected_tags1[i])); + CPPUNIT_ASSERT_EQUAL(pmt_write_string(tags1[i]), pmt_write_string(expected_tags1[i])); } // annotator 2 gets tags from annotators 0 and 1 std::cout << std::endl; std::cout << "tags2.size(): " << tags2.size() << std::endl; - //CPPUNIT_ASSERT_EQUAL(tags2.size(), (size_t)8); + CPPUNIT_ASSERT_EQUAL(tags2.size(), (size_t)8); for(size_t i = 0; i < tags2.size(); i++) { std::cout << "tags2[" << i << "] = " << tags2[i] << "\t\t" << expected_tags2[i] << std::endl; - //CPPUNIT_ASSERT_EQUAL(pmt_write_string(tags2[i]), pmt_write_string(expected_tags2[i])); + CPPUNIT_ASSERT_EQUAL(pmt_write_string(tags2[i]), pmt_write_string(expected_tags2[i])); } // annotator 3 gets tags from annotators 0, 1, and 2 std::cout << std::endl; std::cout << "tags3.size(): " << tags3.size() << std::endl; - //CPPUNIT_ASSERT_EQUAL(tags2.size(), (size_t)8); + CPPUNIT_ASSERT_EQUAL(tags3.size(), (size_t)12); for(size_t i = 0; i < tags3.size(); i++) { std::cout << "tags3[" << i << "] = " << tags3[i] << "\t\t" << expected_tags3[i] << std::endl; - //CPPUNIT_ASSERT_EQUAL(pmt_write_string(tags3[i]), pmt_write_string(expected_tags3[i])); + CPPUNIT_ASSERT_EQUAL(pmt_write_string(tags3[i]), pmt_write_string(expected_tags3[i])); } } diff --git a/gnuradio-core/src/lib/runtime/qa_block_tags.h b/gnuradio-core/src/lib/runtime/qa_block_tags.h index 661d607b2..b0d211390 100644 --- a/gnuradio-core/src/lib/runtime/qa_block_tags.h +++ b/gnuradio-core/src/lib/runtime/qa_block_tags.h @@ -35,7 +35,7 @@ class qa_block_tags : public CppUnit::TestCase { CPPUNIT_TEST (t2); CPPUNIT_TEST (t3); CPPUNIT_TEST (t4); - //CPPUNIT_TEST (t5); + CPPUNIT_TEST (t5); CPPUNIT_TEST_SUITE_END (); private: -- cgit From a41e9987f2c9544f38cea7e367bfc81fafea38cc Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Tue, 16 Nov 2010 21:40:48 -0800 Subject: New file sink to handle tagged bursts of data. --- gnuradio-core/src/lib/io/Makefile.am | 9 +- gnuradio-core/src/lib/io/gr_tagged_file_sink.cc | 167 ++++++++++++++++++++++++ gnuradio-core/src/lib/io/gr_tagged_file_sink.h | 65 +++++++++ gnuradio-core/src/lib/io/gr_tagged_file_sink.i | 35 +++++ gnuradio-core/src/lib/io/io.i | 3 +- 5 files changed, 275 insertions(+), 4 deletions(-) create mode 100644 gnuradio-core/src/lib/io/gr_tagged_file_sink.cc create mode 100644 gnuradio-core/src/lib/io/gr_tagged_file_sink.h create mode 100644 gnuradio-core/src/lib/io/gr_tagged_file_sink.i (limited to 'gnuradio-core/src') diff --git a/gnuradio-core/src/lib/io/Makefile.am b/gnuradio-core/src/lib/io/Makefile.am index c52554645..8ce740afd 100644 --- a/gnuradio-core/src/lib/io/Makefile.am +++ b/gnuradio-core/src/lib/io/Makefile.am @@ -56,7 +56,8 @@ libio_la_SOURCES = \ gr_udp_source.cc \ gr_wavfile_sink.cc \ gr_wavfile_source.cc \ - gri_wavfile.cc + gri_wavfile.cc \ + gr_tagged_file_sink.cc grinclude_HEADERS = \ gr_file_sink.h \ @@ -89,7 +90,8 @@ grinclude_HEADERS = \ gr_udp_source.h \ gr_wavfile_source.h \ gr_wavfile_sink.h \ - gri_wavfile.h + gri_wavfile.h \ + gr_tagged_file_sink.h if PYTHON swiginclude_HEADERS = \ @@ -111,5 +113,6 @@ swiginclude_HEADERS = \ gr_udp_sink.i \ gr_udp_source.i \ gr_wavfile_source.i \ - gr_wavfile_sink.i + gr_wavfile_sink.i \ + gr_tagged_file_sink.i endif diff --git a/gnuradio-core/src/lib/io/gr_tagged_file_sink.cc b/gnuradio-core/src/lib/io/gr_tagged_file_sink.cc new file mode 100644 index 000000000..1cd0a9a4b --- /dev/null +++ b/gnuradio-core/src/lib/io/gr_tagged_file_sink.cc @@ -0,0 +1,167 @@ +/* -*- c++ -*- */ +/* + * Copyright 2010 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef O_BINARY +#define OUR_O_BINARY O_BINARY +#else +#define OUR_O_BINARY 0 +#endif + +// should be handled via configure +#ifdef O_LARGEFILE +#define OUR_O_LARGEFILE O_LARGEFILE +#else +#define OUR_O_LARGEFILE 0 +#endif + + +gr_tagged_file_sink::gr_tagged_file_sink (size_t itemsize) + : gr_sync_block ("tagged_file_sink", + gr_make_io_signature (1, 1, itemsize), + gr_make_io_signature (0, 0, 0)), + d_itemsize (itemsize) +{ + d_state = NOT_IN_BURST; +} + +gr_tagged_file_sink_sptr +gr_make_tagged_file_sink (size_t itemsize) +{ + return gnuradio::get_initial_sptr(new gr_tagged_file_sink (itemsize)); +} + +gr_tagged_file_sink::~gr_tagged_file_sink () +{ +} + +bool pmtcompare(pmt::pmt_t x, pmt::pmt_t y) +{ + uint64_t t_x, t_y; + t_x = pmt::pmt_to_uint64(pmt::pmt_tuple_ref(x, 0)); + t_y = pmt::pmt_to_uint64(pmt::pmt_tuple_ref(y, 0)); + return t_x < t_y; +} + +int +gr_tagged_file_sink::work (int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) +{ + char *inbuf = (char *) input_items[0]; + + uint64_t start_N = nitems_read(0); + uint64_t end_N = start_N + (uint64_t)(noutput_items); + pmt::pmt_t bkey = pmt::pmt_string_to_symbol("burst"); + pmt::pmt_t tkey = pmt::pmt_string_to_symbol("packet_time_stamp"); + std::vector all_tags = get_tags_in_range(0, start_N, end_N); + std::sort(all_tags.begin(), all_tags.end(), pmtcompare); + + std::vector::iterator vitr = all_tags.begin(); + + int idx = 0, idx_stop = 0; + while(idx < noutput_items) { + if(d_state == NOT_IN_BURST) { + while(vitr != all_tags.end()) { + if((pmt::pmt_eqv(pmt::pmt_tuple_ref(*vitr, 2), bkey)) && + pmt::pmt_is_true(pmt::pmt_tuple_ref(*vitr,3))) { + uint64_t N = pmt::pmt_to_uint64(pmt::pmt_tuple_ref(*vitr, 0)) - start_N; + idx = (int)N; + d_state = IN_BURST; + + std::cout << "Found start of burst: " << N << std::endl; + + std::stringstream filename; + filename << "file" << d_n << ".dat"; + d_n++; + + int fd; + if ((fd = ::open (filename.str().c_str(), + O_WRONLY|O_CREAT|O_TRUNC|OUR_O_LARGEFILE|OUR_O_BINARY, + 0664)) < 0){ + perror (filename.str().c_str()); + return -1; + } + + // FIXME: + //if ((d_handle = fdopen (fd, d_is_binary ? "wb" : "w")) == NULL){ + if ((d_handle = fdopen (fd, "wb")) == NULL){ + perror (filename.str().c_str()); + ::close(fd); // don't leak file descriptor if fdopen fails. + } + + std::cout << "Created new file: " << filename.str() << std::endl; + + break; + } + + vitr++; + } + return noutput_items; + } + else { // In burst + while(vitr != all_tags.end()) { + if((pmt::pmt_eqv(pmt::pmt_tuple_ref(*vitr, 2), bkey)) && + pmt::pmt_is_false(pmt::pmt_tuple_ref(*vitr,3))) { + uint64_t N = pmt::pmt_to_uint64(pmt::pmt_tuple_ref(*vitr, 0)) - start_N; + idx_stop = (int)N; + + std::cout << "Found end of burst: " << N << std::endl; + + int count = fwrite (&inbuf[idx], d_itemsize, idx_stop-idx, d_handle); + if (count == 0) + break; + idx = idx_stop; + d_state = NOT_IN_BURST; + vitr++; + fclose(d_handle); + break; + } else { + vitr++; + } + } + if(d_state == IN_BURST) { + std::cout << "writing part of burst: " << idx << std::endl; + int count = fwrite (&inbuf[idx], d_itemsize, noutput_items-idx, d_handle); + if (count == 0) + break; + idx = noutput_items; + } + + } + } + + return noutput_items; +} diff --git a/gnuradio-core/src/lib/io/gr_tagged_file_sink.h b/gnuradio-core/src/lib/io/gr_tagged_file_sink.h new file mode 100644 index 000000000..c657e6a75 --- /dev/null +++ b/gnuradio-core/src/lib/io/gr_tagged_file_sink.h @@ -0,0 +1,65 @@ +/* -*- c++ -*- */ +/* + * Copyright 2010 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_GR_TAGGED_FILE_SINK_H +#define INCLUDED_GR_TAGGED_FILE_SINK_H + +#include + +class gr_tagged_file_sink; +typedef boost::shared_ptr gr_tagged_file_sink_sptr; + +gr_tagged_file_sink_sptr gr_make_tagged_file_sink (size_t itemsize); + +/*! + * \brief Write stream to file descriptor. + * \ingroup sink_blk + */ + +class gr_tagged_file_sink : public gr_sync_block +{ + friend gr_tagged_file_sink_sptr gr_make_tagged_file_sink (size_t itemsize); + + private: + enum { + NOT_IN_BURST = 0, + IN_BURST + }; + + size_t d_itemsize; + int d_state; + FILE *d_handle; + int d_n; + + protected: + gr_tagged_file_sink (size_t itemsize); + + public: + ~gr_tagged_file_sink (); + + int work (int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); +}; + + +#endif /* INCLUDED_GR_TAGGED_FILE_SINK_H */ diff --git a/gnuradio-core/src/lib/io/gr_tagged_file_sink.i b/gnuradio-core/src/lib/io/gr_tagged_file_sink.i new file mode 100644 index 000000000..92248e5dd --- /dev/null +++ b/gnuradio-core/src/lib/io/gr_tagged_file_sink.i @@ -0,0 +1,35 @@ +/* -*- c++ -*- */ +/* + * Copyright 2010 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +GR_SWIG_BLOCK_MAGIC(gr,tagged_file_sink) + +gr_tagged_file_sink_sptr +gr_make_tagged_file_sink (size_t itemsize); + +class gr_tagged_file_sink : public gr_sync_block +{ + protected: + gr_tagged_file_sink (size_t itemsize); + + public: + ~gr_tagged_file_sink (); +}; diff --git a/gnuradio-core/src/lib/io/io.i b/gnuradio-core/src/lib/io/io.i index 3538942ca..365577cd4 100644 --- a/gnuradio-core/src/lib/io/io.i +++ b/gnuradio-core/src/lib/io/io.i @@ -43,7 +43,7 @@ #include #include #include - +#include %} %include "gr_file_sink_base.i" @@ -64,4 +64,5 @@ %include "gr_udp_source.i" %include "gr_wavfile_sink.i" %include "gr_wavfile_source.i" +%include "gr_tagged_file_sink.i" -- cgit From 5ef9a41c9ddfae56a77c118c1dcf2b0af2973207 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Tue, 16 Nov 2010 22:31:52 -0800 Subject: Fixed tagging sink. --- gnuradio-core/src/lib/io/gr_tagged_file_sink.cc | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'gnuradio-core/src') diff --git a/gnuradio-core/src/lib/io/gr_tagged_file_sink.cc b/gnuradio-core/src/lib/io/gr_tagged_file_sink.cc index 1cd0a9a4b..8dfde25cc 100644 --- a/gnuradio-core/src/lib/io/gr_tagged_file_sink.cc +++ b/gnuradio-core/src/lib/io/gr_tagged_file_sink.cc @@ -52,7 +52,7 @@ gr_tagged_file_sink::gr_tagged_file_sink (size_t itemsize) : gr_sync_block ("tagged_file_sink", gr_make_io_signature (1, 1, itemsize), gr_make_io_signature (0, 0, 0)), - d_itemsize (itemsize) + d_itemsize (itemsize),d_n(0) { d_state = NOT_IN_BURST; } @@ -88,6 +88,7 @@ gr_tagged_file_sink::work (int noutput_items, pmt::pmt_t tkey = pmt::pmt_string_to_symbol("packet_time_stamp"); std::vector all_tags = get_tags_in_range(0, start_N, end_N); std::sort(all_tags.begin(), all_tags.end(), pmtcompare); + std::cout << "Number of tags: " << all_tags.size() << std::endl; std::vector::iterator vitr = all_tags.begin(); @@ -95,13 +96,15 @@ gr_tagged_file_sink::work (int noutput_items, while(idx < noutput_items) { if(d_state == NOT_IN_BURST) { while(vitr != all_tags.end()) { + //std::cout << "\tNot in burst: " << *vitr << std::endl; + if((pmt::pmt_eqv(pmt::pmt_tuple_ref(*vitr, 2), bkey)) && pmt::pmt_is_true(pmt::pmt_tuple_ref(*vitr,3))) { + uint64_t N = pmt::pmt_to_uint64(pmt::pmt_tuple_ref(*vitr, 0)) - start_N; idx = (int)N; - d_state = IN_BURST; - std::cout << "Found start of burst: " << N << std::endl; + std::cout << std::endl << "Found start of burst: " << N << ", " << N+start_N << std::endl; std::stringstream filename; filename << "file" << d_n << ".dat"; @@ -124,23 +127,27 @@ gr_tagged_file_sink::work (int noutput_items, std::cout << "Created new file: " << filename.str() << std::endl; + d_state = IN_BURST; break; } vitr++; } - return noutput_items; + if(d_state == NOT_IN_BURST) + return noutput_items; } else { // In burst while(vitr != all_tags.end()) { + //std::cout << "\tin burst: " << *vitr << std::endl; + if((pmt::pmt_eqv(pmt::pmt_tuple_ref(*vitr, 2), bkey)) && pmt::pmt_is_false(pmt::pmt_tuple_ref(*vitr,3))) { uint64_t N = pmt::pmt_to_uint64(pmt::pmt_tuple_ref(*vitr, 0)) - start_N; idx_stop = (int)N; - std::cout << "Found end of burst: " << N << std::endl; + std::cout << "Found end of burst: " << N << ", " << N+start_N << std::endl; - int count = fwrite (&inbuf[idx], d_itemsize, idx_stop-idx, d_handle); + int count = fwrite (&inbuf[d_itemsize*idx], d_itemsize, idx_stop-idx, d_handle); if (count == 0) break; idx = idx_stop; @@ -153,7 +160,7 @@ gr_tagged_file_sink::work (int noutput_items, } } if(d_state == IN_BURST) { - std::cout << "writing part of burst: " << idx << std::endl; + std::cout << "writing part of burst: " << noutput_items-idx << std::endl; int count = fwrite (&inbuf[idx], d_itemsize, noutput_items-idx, d_handle); if (count == 0) break; -- cgit From e6751f477ba006923e9f0d2454ff870c52a6f0a5 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Tue, 16 Nov 2010 22:32:46 -0800 Subject: Adding a burst tagger that creates a tag when a signal is observed on line 1. --- gnuradio-core/src/lib/general/Makefile.am | 9 ++- gnuradio-core/src/lib/general/general.i | 2 + gnuradio-core/src/lib/general/gr_burst_tagger.cc | 83 ++++++++++++++++++++++++ gnuradio-core/src/lib/general/gr_burst_tagger.h | 56 ++++++++++++++++ gnuradio-core/src/lib/general/gr_burst_tagger.i | 31 +++++++++ 5 files changed, 178 insertions(+), 3 deletions(-) create mode 100644 gnuradio-core/src/lib/general/gr_burst_tagger.cc create mode 100644 gnuradio-core/src/lib/general/gr_burst_tagger.h create mode 100644 gnuradio-core/src/lib/general/gr_burst_tagger.i (limited to 'gnuradio-core/src') diff --git a/gnuradio-core/src/lib/general/Makefile.am b/gnuradio-core/src/lib/general/Makefile.am index 2e52d88f3..0e9109d6c 100644 --- a/gnuradio-core/src/lib/general/Makefile.am +++ b/gnuradio-core/src/lib/general/Makefile.am @@ -177,7 +177,8 @@ libgeneral_la_SOURCES = \ gr_probe_mpsk_snr_c.cc \ gr_probe_density_b.cc \ gr_annotator_alltoall.cc \ - gr_annotator_1to1.cc + gr_annotator_1to1.cc \ + gr_burst_tagger.cc libgeneral_qa_la_SOURCES = \ qa_general.cc \ @@ -348,7 +349,8 @@ grinclude_HEADERS = \ gr_probe_mpsk_snr_c.h \ gr_probe_density_b.h \ gr_annotator_alltoall.h \ - gr_annotator_1to1.h + gr_annotator_1to1.h \ + gr_burst_tagger.h noinst_HEADERS = \ qa_general.h \ @@ -490,5 +492,6 @@ swiginclude_HEADERS = \ gr_probe_mpsk_snr_c.i \ gr_probe_density_b.i \ gr_annotator_alltoall.i \ - gr_annotator_1to1.i + gr_annotator_1to1.i \ + gr_burst_tagger.i endif diff --git a/gnuradio-core/src/lib/general/general.i b/gnuradio-core/src/lib/general/general.i index 400f0b9b6..0f8b57a44 100644 --- a/gnuradio-core/src/lib/general/general.i +++ b/gnuradio-core/src/lib/general/general.i @@ -143,6 +143,7 @@ #include #include #include +#include %} %include "gr_nop.i" @@ -266,3 +267,4 @@ %include "gr_additive_scrambler_bb.i" %include "gr_annotator_alltoall.i" %include "gr_annotator_1to1.i" +%include "gr_burst_tagger.i" diff --git a/gnuradio-core/src/lib/general/gr_burst_tagger.cc b/gnuradio-core/src/lib/general/gr_burst_tagger.cc new file mode 100644 index 000000000..4b3847b08 --- /dev/null +++ b/gnuradio-core/src/lib/general/gr_burst_tagger.cc @@ -0,0 +1,83 @@ +/* -*- c++ -*- */ +/* + * Copyright 2010 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include + +gr_burst_tagger_sptr +gr_make_burst_tagger(size_t itemsize) +{ + return gnuradio::get_initial_sptr(new gr_burst_tagger(itemsize)); +} + +gr_burst_tagger::gr_burst_tagger(size_t itemsize) + : gr_sync_block ("burst_tagger", + gr_make_io_signature2 (2, 2, itemsize, sizeof(short)), + gr_make_io_signature (1, 1, itemsize)), + d_itemsize(itemsize), d_state(false) +{ + std::stringstream str; + str << name() << unique_id(); + + d_key = pmt::pmt_string_to_symbol("burst"); + d_id = pmt::pmt_string_to_symbol(str.str()); +} + +gr_burst_tagger::~gr_burst_tagger() +{ +} + +int +gr_burst_tagger::work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) +{ + const char *signal = (const char*)input_items[0]; + const short *trigger = (const short*)input_items[1]; + char *out = (char*)output_items[0]; + + memcpy(out, signal, noutput_items * d_itemsize); + + for(int i = 0; i < noutput_items; i++) { + if(trigger[i] > 0) { + if(d_state == false) { + d_state = true; + pmt::pmt_t value = pmt::PMT_T; + add_item_tag(0, nitems_written(0)+i, d_key, value, d_id); + } + } + else { + if(d_state == true) { + d_state = false; + pmt::pmt_t value = pmt::PMT_F; + add_item_tag(0, nitems_written(0)+i, d_key, value, d_id); + } + } + } + + return noutput_items; +} diff --git a/gnuradio-core/src/lib/general/gr_burst_tagger.h b/gnuradio-core/src/lib/general/gr_burst_tagger.h new file mode 100644 index 000000000..8f814bea0 --- /dev/null +++ b/gnuradio-core/src/lib/general/gr_burst_tagger.h @@ -0,0 +1,56 @@ +/* -*- c++ -*- */ +/* + * Copyright 2010 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_GR_BURST_TAGGER_H +#define INCLUDED_GR_BURST_TAGGER_H + +#include + +class gr_burst_tagger; +typedef boost::shared_ptr gr_burst_tagger_sptr; + +gr_burst_tagger_sptr gr_make_burst_tagger(size_t itemsize); + +/*! + * \brief output[i] = input[i] + * \ingroup misc_blk + * + */ +class gr_burst_tagger : public gr_sync_block +{ + size_t d_itemsize; + bool d_state; + pmt::pmt_t d_key; + pmt::pmt_t d_id; + + friend gr_burst_tagger_sptr gr_make_burst_tagger(size_t itemsize); + gr_burst_tagger(size_t itemsize); + + public: + ~gr_burst_tagger(); + + int work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); +}; + +#endif diff --git a/gnuradio-core/src/lib/general/gr_burst_tagger.i b/gnuradio-core/src/lib/general/gr_burst_tagger.i new file mode 100644 index 000000000..ebf1eea8c --- /dev/null +++ b/gnuradio-core/src/lib/general/gr_burst_tagger.i @@ -0,0 +1,31 @@ +/* -*- c++ -*- */ +/* + * Copyright 2010 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +GR_SWIG_BLOCK_MAGIC(gr,burst_tagger) + +gr_burst_tagger_sptr gr_make_burst_tagger(size_t itemsize); + +class gr_burst_tagger : public gr_sync_block +{ + private: + gr_burst_tagger(size_t itemsize); +}; -- cgit From 38d1a6be0d4f80a4a5334ddb8bac0aef08d5c794 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Wed, 17 Nov 2010 15:56:50 -0800 Subject: Adding information and convinience functions for accessing tag information. --- gnuradio-core/src/lib/runtime/gr_tag_info.cc | 37 ++++++++++++++++ gnuradio-core/src/lib/runtime/gr_tag_info.h | 65 ++++++++++++++++++++++++++++ 2 files changed, 102 insertions(+) create mode 100644 gnuradio-core/src/lib/runtime/gr_tag_info.cc create mode 100644 gnuradio-core/src/lib/runtime/gr_tag_info.h (limited to 'gnuradio-core/src') diff --git a/gnuradio-core/src/lib/runtime/gr_tag_info.cc b/gnuradio-core/src/lib/runtime/gr_tag_info.cc new file mode 100644 index 000000000..211f330e9 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_tag_info.cc @@ -0,0 +1,37 @@ +/* -*- c++ -*- */ +/* + * Copyright 2010 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include + +namespace gr_tags { + + const pmt::pmt_t s_key_time = pmt::pmt_string_to_symbol("time"); + const pmt::pmt_t s_key_sample_rate = pmt::pmt_string_to_symbol("sample_rate"); + const pmt::pmt_t s_key_frequency = pmt::pmt_string_to_symbol("frequency"); + const pmt::pmt_t s_key_rssi = pmt::pmt_string_to_symbol("rssi"); + const pmt::pmt_t s_key_rx_gain = pmt::pmt_string_to_symbol("gain"); +} diff --git a/gnuradio-core/src/lib/runtime/gr_tag_info.h b/gnuradio-core/src/lib/runtime/gr_tag_info.h new file mode 100644 index 000000000..af51cf6a9 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_tag_info.h @@ -0,0 +1,65 @@ +/* -*- c++ -*- */ +/* + * Copyright 2010 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_GR_TAG_INFO_H +#define INCLUDED_GR_TAG_INFO_H + +#include + +namespace gr_tags { + + enum { + TAG_NITEM_REF = 0, + TAG_SRCID_REF, + TAG_KEY_REF, + TAG_VALUE_REF + }; + + extern const pmt::pmt_t s_key_time; + extern const pmt::pmt_t s_key_sample_rate; + extern const pmt::pmt_t s_key_frequency; + extern const pmt::pmt_t s_key_rssi; + extern const pmt::pmt_t s_key_gain; + + static inline uint64_t + get_nitems(const pmt::pmt_t &tag) { + return pmt::pmt_to_uint64(pmt::pmt_tuple_ref(tag, TAG_NITEM_REF)); + } + + static inline pmt::pmt_t + get_srcid(const pmt::pmt_t &tag) { + return pmt::pmt_tuple_ref(tag, TAG_SRCID_REF); + } + + static inline pmt::pmt_t + get_key(const pmt::pmt_t &tag) { + return pmt::pmt_tuple_ref(tag, TAG_KEY_REF); + } + + static inline pmt::pmt_t + get_value(const pmt::pmt_t &tag) { + return pmt::pmt_tuple_ref(tag, TAG_VALUE_REF); + } + +}; /* namespace tags */ + +#endif /* GR_TAG_INFO */ -- cgit From 97b1f1aa7d646fbc1250158ec94fe49d0979809c Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Wed, 17 Nov 2010 15:58:04 -0800 Subject: Makefile changes to work in tag info stuff. --- gnuradio-core/src/lib/runtime/Makefile.am | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'gnuradio-core/src') diff --git a/gnuradio-core/src/lib/runtime/Makefile.am b/gnuradio-core/src/lib/runtime/Makefile.am index a3aa36a39..dd9a8ea64 100644 --- a/gnuradio-core/src/lib/runtime/Makefile.am +++ b/gnuradio-core/src/lib/runtime/Makefile.am @@ -68,7 +68,8 @@ libruntime_la_SOURCES = \ gr_vmcircbuf_mmap_tmpfile.cc \ gr_vmcircbuf_createfilemapping.cc \ gr_vmcircbuf_sysv_shm.cc \ - gr_select_handler.cc + gr_select_handler.cc \ + gr_tag_info.cc libruntime_qa_la_SOURCES = \ qa_gr_block.cc \ @@ -122,7 +123,8 @@ grinclude_HEADERS = \ gr_tmp_path.h \ gr_types.h \ gr_unittests.h \ - gr_vmcircbuf.h + gr_vmcircbuf.h \ + gr_tag_info.h noinst_HEADERS = \ gr_vmcircbuf_mmap_shm_open.h \ -- cgit From 6d4393613a78417b91e67af33820748ad3483e61 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Wed, 17 Nov 2010 15:58:49 -0800 Subject: Changing get_tags API to take in a vector reference instead of returning a vector. --- gnuradio-core/src/lib/runtime/gr_block.cc | 14 ++++++----- gnuradio-core/src/lib/runtime/gr_block.h | 18 ++++++++------ gnuradio-core/src/lib/runtime/gr_block_detail.cc | 22 +++++++++-------- gnuradio-core/src/lib/runtime/gr_block_detail.h | 19 +++++++++------ gnuradio-core/src/lib/runtime/gr_block_executor.cc | 28 ++++++++++++++-------- gnuradio-core/src/lib/runtime/gr_block_executor.h | 2 ++ gnuradio-core/src/lib/runtime/gr_buffer.cc | 11 ++++----- gnuradio-core/src/lib/runtime/gr_buffer.h | 6 +++-- 8 files changed, 72 insertions(+), 48 deletions(-) (limited to 'gnuradio-core/src') diff --git a/gnuradio-core/src/lib/runtime/gr_block.cc b/gnuradio-core/src/lib/runtime/gr_block.cc index 778344769..52be37e3b 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_block.cc @@ -152,19 +152,21 @@ gr_block::add_item_tag(unsigned int which_output, d_detail->add_item_tag(which_output, offset, key, value, srcid); } -std::vector -gr_block::get_tags_in_range(unsigned int which_output, +void +gr_block::get_tags_in_range(std::vector &v, + unsigned int which_output, uint64_t start, uint64_t end) { - return d_detail->get_tags_in_range(which_output, start, end); + d_detail->get_tags_in_range(v, which_output, start, end); } -std::vector -gr_block::get_tags_in_range(unsigned int which_output, +void +gr_block::get_tags_in_range(std::vector &v, + unsigned int which_output, uint64_t start, uint64_t end, const pmt::pmt_t &key) { - return d_detail->get_tags_in_range(which_output, start, end, key); + d_detail->get_tags_in_range(v, which_output, start, end, key); } gr_block::TAG_PROPAGATION_POLICY diff --git a/gnuradio-core/src/lib/runtime/gr_block.h b/gnuradio-core/src/lib/runtime/gr_block.h index a717946d2..7caf3c34a 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.h +++ b/gnuradio-core/src/lib/runtime/gr_block.h @@ -268,13 +268,15 @@ class gr_block : public gr_basic_block { * Tags are tuples of: * (item count, source id, key, value) * + * \param v a vector reference to return tags into * \param which_input an integer of which input stream to pull from * \param abs_start a uint64 count of the start of the range of interest * \param abs_end a uint64 count of the end of the range of interest */ - std::vector get_tags_in_range(unsigned int which_input, - uint64_t abs_start, - uint64_t abs_end); + void get_tags_in_range(std::vector &v, + unsigned int which_input, + uint64_t abs_start, + uint64_t abs_end); /*! * \brief Given a [start,end), returns a vector of all tags in the range @@ -285,15 +287,17 @@ class gr_block : public gr_basic_block { * Tags are tuples of: * (item count, source id, key, value) * + * \param v a vector reference to return tags into * \param which_input an integer of which input stream to pull from * \param abs_start a uint64 count of the start of the range of interest * \param abs_end a uint64 count of the end of the range of interest * \param key a PMT symbol key to filter only tags of this key */ - std::vector get_tags_in_range(unsigned int which_input, - uint64_t abs_start, - uint64_t abs_end, - const pmt::pmt_t &key); + void get_tags_in_range(std::vector &v, + unsigned int which_input, + uint64_t abs_start, + uint64_t abs_end, + const pmt::pmt_t &key); // These are really only for internal use, but leaving them public avoids // having to work up an ever-varying list of friends diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.cc b/gnuradio-core/src/lib/runtime/gr_block_detail.cc index 4f3ffc8dc..a360240c0 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.cc @@ -169,25 +169,29 @@ gr_block_detail::add_item_tag(unsigned int which_output, } } -std::vector -gr_block_detail::get_tags_in_range(unsigned int which_input, +void +gr_block_detail::get_tags_in_range(std::vector &v, + unsigned int which_input, uint64_t abs_start, uint64_t abs_end) { // get from gr_buffer_reader's deque of tags - return d_input[which_input]->get_tags_in_range(abs_start, abs_end); + d_input[which_input]->get_tags_in_range(v, abs_start, abs_end); } -std::vector -gr_block_detail::get_tags_in_range(unsigned int which_input, +void +gr_block_detail::get_tags_in_range(std::vector &v, + unsigned int which_input, uint64_t abs_start, uint64_t abs_end, const pmt_t &key) { - std::vector found_items, found_items_by_key; + std::vector found_items; + + v.resize(0); // get from gr_buffer_reader's deque of tags - found_items = d_input[which_input]->get_tags_in_range(abs_start, abs_end); + d_input[which_input]->get_tags_in_range(found_items, abs_start, abs_end); // Filter further by key name pmt_t itemkey; @@ -195,9 +199,7 @@ gr_block_detail::get_tags_in_range(unsigned int which_input, for(itr = found_items.begin(); itr != found_items.end(); itr++) { itemkey = pmt_tuple_ref(*itr, 2); if(pmt_eqv(key, itemkey)) { - found_items_by_key.push_back(*itr); + v.push_back(*itr); } } - - return found_items_by_key; } diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.h b/gnuradio-core/src/lib/runtime/gr_block_detail.h index 5902d1559..834ef47f5 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.h +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.h @@ -25,6 +25,7 @@ #include #include +#include #include /*! @@ -124,13 +125,15 @@ class gr_block_detail { * Tags are tuples of: * (item count, source id, key, value) * + * \param v a vector reference to return tags into * \param which_input an integer of which input stream to pull from * \param abs_start a uint64 count of the start of the range of interest * \param abs_end a uint64 count of the end of the range of interest */ - std::vector get_tags_in_range(unsigned int which_input, - uint64_t abs_start, - uint64_t abs_end); + void get_tags_in_range(std::vector &v, + unsigned int which_input, + uint64_t abs_start, + uint64_t abs_end); /*! * \brief Given a [start,end), returns a vector of all tags in the range @@ -143,15 +146,17 @@ class gr_block_detail { * Tags are tuples of: * (item count, source id, key, value) * + * \param v a vector reference to return tags into * \param which_input an integer of which input stream to pull from * \param abs_start a uint64 count of the start of the range of interest * \param abs_end a uint64 count of the end of the range of interest * \param key a PMT symbol to select only tags of this key */ - std::vector get_tags_in_range(unsigned int which_input, - uint64_t abs_start, - uint64_t abs_end, - const pmt::pmt_t &key); + void get_tags_in_range(std::vector &v, + unsigned int which_input, + uint64_t abs_start, + uint64_t abs_end, + const pmt::pmt_t &key); gr_tpb_detail d_tpb; // used by thread-per-block scheduler int d_produce_or; diff --git a/gnuradio-core/src/lib/runtime/gr_block_executor.cc b/gnuradio-core/src/lib/runtime/gr_block_executor.cc index 9882c2e5d..59799069a 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_executor.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_executor.cc @@ -89,7 +89,8 @@ min_available_space (gr_block_detail *d, int output_multiple) static bool propagate_tags(gr_block::TAG_PROPAGATION_POLICY policy, gr_block_detail *d, - const std::vector &start_nitems_read, double rrate) + const std::vector &start_nitems_read, double rrate, + std::vector &rtags) { // Move tags downstream // if a sink, we don't need to move downstream; @@ -105,10 +106,11 @@ propagate_tags(gr_block::TAG_PROPAGATION_POLICY policy, gr_block_detail *d, case(gr_block::TPP_ALL_TO_ALL): // every tag on every input propogates to everyone downstream for(int i = 0; i < d->ninputs(); i++) { - std::vector tuple = d->get_tags_in_range(i, start_nitems_read[i], - d->nitems_read(i)); + d->get_tags_in_range(rtags, i, start_nitems_read[i], + d->nitems_read(i)); + std::vector::iterator t; - for(t = tuple.begin(); t != tuple.end(); t++ ) { + for(t = rtags.begin(); t != rtags.end(); t++) { uint64_t newcount = pmt::pmt_to_uint64(pmt::pmt_tuple_ref(*t, 0)); pmt::pmt_t newtup = pmt::mp(pmt::pmt_from_uint64(newcount * rrate), pmt::pmt_tuple_ref(*t, 1), @@ -117,7 +119,6 @@ propagate_tags(gr_block::TAG_PROPAGATION_POLICY policy, gr_block_detail *d, for(int o = 0; o < d->noutputs(); o++) d->output(o)->add_item_tag(newtup); - //d->output(o)->add_item_tag(*t); } } break; @@ -127,11 +128,17 @@ propagate_tags(gr_block::TAG_PROPAGATION_POLICY policy, gr_block_detail *d, // type of tag-propagation system is selected in gr_block_detail if(d->ninputs() == d->noutputs()) { for(int i = 0; i < d->ninputs(); i++) { - std::vector tuple = d->get_tags_in_range(i, start_nitems_read[i], - d->nitems_read(i)); + d->get_tags_in_range(rtags, i, start_nitems_read[i], + d->nitems_read(i)); + std::vector::iterator t; - for(t = tuple.begin(); t != tuple.end(); t++ ) { - d->output(i)->add_item_tag(*t); + for(t = rtags.begin(); t != rtags.end(); t++) { + uint64_t newcount = pmt::pmt_to_uint64(pmt::pmt_tuple_ref(*t, 0)); + pmt::pmt_t newtup = pmt::mp(pmt::pmt_from_uint64(newcount * rrate), + pmt::pmt_tuple_ref(*t, 1), + pmt::pmt_tuple_ref(*t, 2), + pmt::pmt_tuple_ref(*t, 3)); + d->output(i)->add_item_tag(newtup); } } } @@ -366,7 +373,8 @@ gr_block_executor::run_one_iteration() << " result = " << n << std::endl); if(!propagate_tags(m->tag_propagation_policy(), d, - d_start_nitems_read, m->relative_rate())) + d_start_nitems_read, m->relative_rate(), + d_returned_tags)) goto were_done; if (n == gr_block::WORK_DONE) diff --git a/gnuradio-core/src/lib/runtime/gr_block_executor.h b/gnuradio-core/src/lib/runtime/gr_block_executor.h index 22b782883..77ace5522 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_executor.h +++ b/gnuradio-core/src/lib/runtime/gr_block_executor.h @@ -25,6 +25,7 @@ #include #include +#include //class gr_block_executor; //typedef boost::shared_ptr gr_block_executor_sptr; @@ -48,6 +49,7 @@ protected: std::vector d_input_done; gr_vector_void_star d_output_items; std::vector d_start_nitems_read; //stores where tag counts are before work + std::vector d_returned_tags; public: gr_block_executor(gr_block_sptr block); diff --git a/gnuradio-core/src/lib/runtime/gr_buffer.cc b/gnuradio-core/src/lib/runtime/gr_buffer.cc index 84a65f921..70d57c094 100644 --- a/gnuradio-core/src/lib/runtime/gr_buffer.cc +++ b/gnuradio-core/src/lib/runtime/gr_buffer.cc @@ -271,13 +271,14 @@ gr_buffer_reader::update_read_pointer (int nitems) d_abs_read_offset += nitems; } -std::vector -gr_buffer_reader::get_tags_in_range(uint64_t abs_start, +void +gr_buffer_reader::get_tags_in_range(std::vector &v, + uint64_t abs_start, uint64_t abs_end) { gruel::scoped_lock guard(*mutex()); - std::vector found_items; + v.resize(0); std::deque::iterator itr = d_buffer->get_tags_begin(); uint64_t item_time; @@ -285,13 +286,11 @@ gr_buffer_reader::get_tags_in_range(uint64_t abs_start, item_time = pmt::pmt_to_uint64(pmt::pmt_tuple_ref(*itr, 0)); if((item_time >= abs_start) && (item_time <= abs_end)) { - found_items.push_back(*itr); + v.push_back(*itr); } itr++; } - - return found_items; } void diff --git a/gnuradio-core/src/lib/runtime/gr_buffer.h b/gnuradio-core/src/lib/runtime/gr_buffer.h index 47ba4cd96..88a76fdc6 100644 --- a/gnuradio-core/src/lib/runtime/gr_buffer.h +++ b/gnuradio-core/src/lib/runtime/gr_buffer.h @@ -255,11 +255,13 @@ class gr_buffer_reader { * Tags are tuples of: * (item count, source id, key, value) * + * \param v a vector reference to return tags into * \param abs_start a uint64 count of the start of the range of interest * \param abs_end a uint64 count of the end of the range of interest */ - std::vector get_tags_in_range(uint64_t abs_start, - uint64_t abs_end); + void get_tags_in_range(std::vector &v, + uint64_t abs_start, + uint64_t abs_end); void prune_tags(uint64_t max_time); -- cgit From b8da2172d0b10f5de04a12b942b48439a7aae8ae Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Wed, 17 Nov 2010 15:59:43 -0800 Subject: Changing blocks to use new get_tags api and tag convinience functions. --- gnuradio-core/src/lib/general/gr_annotator_1to1.cc | 4 +++- .../src/lib/general/gr_annotator_alltoall.cc | 4 +++- gnuradio-core/src/lib/io/gr_tagged_file_sink.cc | 20 ++++++++++++-------- 3 files changed, 18 insertions(+), 10 deletions(-) (limited to 'gnuradio-core/src') diff --git a/gnuradio-core/src/lib/general/gr_annotator_1to1.cc b/gnuradio-core/src/lib/general/gr_annotator_1to1.cc index 11e2c2b4b..511b356e5 100644 --- a/gnuradio-core/src/lib/general/gr_annotator_1to1.cc +++ b/gnuradio-core/src/lib/general/gr_annotator_1to1.cc @@ -68,7 +68,9 @@ gr_annotator_1to1::work (int noutput_items, int ninputs = input_items.size(); for(int i = 0; i < ninputs; i++) { abs_N = nitems_read(i); - std::vector all_tags = get_tags_in_range(i, abs_N, abs_N + noutput_items); + + std::vector all_tags; + get_tags_in_range(all_tags, i, abs_N, abs_N + noutput_items); std::vector::iterator itr; for(itr = all_tags.begin(); itr != all_tags.end(); itr++) { diff --git a/gnuradio-core/src/lib/general/gr_annotator_alltoall.cc b/gnuradio-core/src/lib/general/gr_annotator_alltoall.cc index 9306f9e37..344fd088b 100644 --- a/gnuradio-core/src/lib/general/gr_annotator_alltoall.cc +++ b/gnuradio-core/src/lib/general/gr_annotator_alltoall.cc @@ -69,7 +69,9 @@ gr_annotator_alltoall::work (int noutput_items, for(int i = 0; i < ninputs; i++) { abs_N = nitems_read(i); end_N = abs_N + (uint64_t)(noutput_items); - std::vector all_tags = get_tags_in_range(i, abs_N, end_N); + + std::vector all_tags; + get_tags_in_range(all_tags, i, abs_N, end_N); std::vector::iterator itr; for(itr = all_tags.begin(); itr != all_tags.end(); itr++) { diff --git a/gnuradio-core/src/lib/io/gr_tagged_file_sink.cc b/gnuradio-core/src/lib/io/gr_tagged_file_sink.cc index 8dfde25cc..9b5ae70a6 100644 --- a/gnuradio-core/src/lib/io/gr_tagged_file_sink.cc +++ b/gnuradio-core/src/lib/io/gr_tagged_file_sink.cc @@ -33,6 +33,7 @@ #include #include #include +#include #ifdef O_BINARY #define OUR_O_BINARY O_BINARY @@ -85,8 +86,11 @@ gr_tagged_file_sink::work (int noutput_items, uint64_t start_N = nitems_read(0); uint64_t end_N = start_N + (uint64_t)(noutput_items); pmt::pmt_t bkey = pmt::pmt_string_to_symbol("burst"); - pmt::pmt_t tkey = pmt::pmt_string_to_symbol("packet_time_stamp"); - std::vector all_tags = get_tags_in_range(0, start_N, end_N); + //pmt::pmt_t tkey = pmt::pmt_string_to_symbol("time"); // use gr_tags::s_key_time + + std::vector all_tags; + get_tags_in_range(all_tags, 0, start_N, end_N); + std::sort(all_tags.begin(), all_tags.end(), pmtcompare); std::cout << "Number of tags: " << all_tags.size() << std::endl; @@ -98,10 +102,10 @@ gr_tagged_file_sink::work (int noutput_items, while(vitr != all_tags.end()) { //std::cout << "\tNot in burst: " << *vitr << std::endl; - if((pmt::pmt_eqv(pmt::pmt_tuple_ref(*vitr, 2), bkey)) && - pmt::pmt_is_true(pmt::pmt_tuple_ref(*vitr,3))) { + if((pmt::pmt_eqv(gr_tags::get_key(*vitr), bkey)) && + pmt::pmt_is_true(gr_tags::get_value(*vitr))) { - uint64_t N = pmt::pmt_to_uint64(pmt::pmt_tuple_ref(*vitr, 0)) - start_N; + uint64_t N = gr_tags::get_nitems(*vitr) - start_N; idx = (int)N; std::cout << std::endl << "Found start of burst: " << N << ", " << N+start_N << std::endl; @@ -140,9 +144,9 @@ gr_tagged_file_sink::work (int noutput_items, while(vitr != all_tags.end()) { //std::cout << "\tin burst: " << *vitr << std::endl; - if((pmt::pmt_eqv(pmt::pmt_tuple_ref(*vitr, 2), bkey)) && - pmt::pmt_is_false(pmt::pmt_tuple_ref(*vitr,3))) { - uint64_t N = pmt::pmt_to_uint64(pmt::pmt_tuple_ref(*vitr, 0)) - start_N; + if((pmt::pmt_eqv(gr_tags::get_key(*vitr), bkey)) && + pmt::pmt_is_false(gr_tags::get_value(*vitr))) { + uint64_t N = gr_tags::get_nitems(*vitr) - start_N; idx_stop = (int)N; std::cout << "Found end of burst: " << N << ", " << N+start_N << std::endl; -- cgit From 2ce754d59c537b0ca395442a94c908f2b8b3dd58 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Wed, 17 Nov 2010 19:44:36 -0800 Subject: Moved prune tags to gr_buffer. --- gnuradio-core/src/lib/runtime/gr_buffer.cc | 42 ++++++++++++++---------------- gnuradio-core/src/lib/runtime/gr_buffer.h | 5 ++-- 2 files changed, 22 insertions(+), 25 deletions(-) (limited to 'gnuradio-core/src') diff --git a/gnuradio-core/src/lib/runtime/gr_buffer.cc b/gnuradio-core/src/lib/runtime/gr_buffer.cc index 70d57c094..1488e92f6 100644 --- a/gnuradio-core/src/lib/runtime/gr_buffer.cc +++ b/gnuradio-core/src/lib/runtime/gr_buffer.cc @@ -162,9 +162,7 @@ gr_buffer::space_available () min_items_read = std::min(min_items_read, d_readers[i]->nitems_read()); } - for (size_t i = 0; i < d_readers.size (); i++) { - d_readers[i]->prune_tags(min_items_read); - } + prune_tags(min_items_read); // The -1 ensures that the case d_write_index == d_read_index is // unambiguous. It indicates that there is no data for the reader @@ -230,6 +228,25 @@ gr_buffer::add_item_tag(const pmt::pmt_t &tag) d_item_tags.push_back(tag); } +void +gr_buffer::prune_tags(uint64_t max_time) +{ + //gruel::scoped_lock guard(*mutex()); + + int n = 0; + uint64_t item_time; + std::deque::iterator itr = d_item_tags.begin(); + + while(itr != d_item_tags.end()) { + item_time = pmt::pmt_to_uint64(pmt::pmt_tuple_ref(*itr, 0)); + if(item_time < max_time) { + d_item_tags.pop_front(); + n++; + } + itr++; + } +} + long gr_buffer_ncurrently_allocated () { @@ -293,25 +310,6 @@ gr_buffer_reader::get_tags_in_range(std::vector &v, } } -void -gr_buffer_reader::prune_tags(uint64_t max_time) -{ - int n = 0; - uint64_t item_time; - std::deque::iterator itr = d_buffer->get_tags_begin(); - - while(itr != d_buffer->get_tags_end()) { - item_time = pmt::pmt_to_uint64(pmt::pmt_tuple_ref(*itr, 0)); - if(item_time < max_time) { - d_buffer->tags_pop_front(); - n++; - } - //else - // break; - itr++; - } -} - long gr_buffer_reader_ncurrently_allocated () { diff --git a/gnuradio-core/src/lib/runtime/gr_buffer.h b/gnuradio-core/src/lib/runtime/gr_buffer.h index 88a76fdc6..2d88c1722 100644 --- a/gnuradio-core/src/lib/runtime/gr_buffer.h +++ b/gnuradio-core/src/lib/runtime/gr_buffer.h @@ -99,9 +99,10 @@ class gr_buffer { */ void add_item_tag(const pmt::pmt_t &tag); + void prune_tags(uint64_t max_time); + std::deque::iterator get_tags_begin() { return d_item_tags.begin(); } std::deque::iterator get_tags_end() { return d_item_tags.end(); } - void tags_pop_front() { d_item_tags.pop_front(); } // ------------------------------------------------------------------------- @@ -263,8 +264,6 @@ class gr_buffer_reader { uint64_t abs_start, uint64_t abs_end); - void prune_tags(uint64_t max_time); - // ------------------------------------------------------------------------- private: -- cgit From b34360471571ea7346ab1c6cb87700a920ca5798 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sun, 21 Nov 2010 14:33:58 -0500 Subject: Fixing flowgraph dump to clean it up (via patch from eb). Also added note about mutex locking in prune_tags. --- gnuradio-core/src/lib/runtime/gr_buffer.cc | 8 ++++++++ gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc | 7 ++----- 2 files changed, 10 insertions(+), 5 deletions(-) (limited to 'gnuradio-core/src') diff --git a/gnuradio-core/src/lib/runtime/gr_buffer.cc b/gnuradio-core/src/lib/runtime/gr_buffer.cc index 1488e92f6..0b2eb52a0 100644 --- a/gnuradio-core/src/lib/runtime/gr_buffer.cc +++ b/gnuradio-core/src/lib/runtime/gr_buffer.cc @@ -231,6 +231,14 @@ gr_buffer::add_item_tag(const pmt::pmt_t &tag) void gr_buffer::prune_tags(uint64_t max_time) { + /* NOTE: this function _should_ lock the mutex before editing + d_item_tags. In practice, this function is only called at + runtime by min_available_space in gr_block_executor.cc, + which locks the mutex itself. + + If this function is used elsewhere, remember to lock the + buffer's mutex al la the scoped_lock line below. + */ //gruel::scoped_lock guard(*mutex()); int n = 0; diff --git a/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc b/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc index 031eb6dfd..5d1057e0f 100644 --- a/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc +++ b/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc @@ -264,16 +264,13 @@ void gr_flat_flowgraph::dump() int no = detail->noutputs(); for (int i = 0; i < no; i++) { gr_buffer_sptr buffer = detail->output(i); - std::cout << " output " << i << ": " << buffer - << " space=" << buffer->space_available() << std::endl; + std::cout << " output " << i << ": " << buffer << std::endl; } for (int i = 0; i < ni; i++) { gr_buffer_reader_sptr reader = detail->input(i); std::cout << " reader " << i << ": " << reader - << " reading from buffer=" << reader->buffer() - << " avail=" << reader->items_available() << " items" - << std::endl; + << " reading from buffer=" << reader->buffer() << std::endl; } } -- cgit From be71cffac7e1a90a1fdccdeab8bcf3697fd9ca9c Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sun, 21 Nov 2010 14:43:06 -0500 Subject: Changing name of static tag keys. --- gnuradio-core/src/lib/runtime/gr_tag_info.cc | 10 +++++----- gnuradio-core/src/lib/runtime/gr_tag_info.h | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) (limited to 'gnuradio-core/src') diff --git a/gnuradio-core/src/lib/runtime/gr_tag_info.cc b/gnuradio-core/src/lib/runtime/gr_tag_info.cc index 211f330e9..c64cc7eb8 100644 --- a/gnuradio-core/src/lib/runtime/gr_tag_info.cc +++ b/gnuradio-core/src/lib/runtime/gr_tag_info.cc @@ -29,9 +29,9 @@ namespace gr_tags { - const pmt::pmt_t s_key_time = pmt::pmt_string_to_symbol("time"); - const pmt::pmt_t s_key_sample_rate = pmt::pmt_string_to_symbol("sample_rate"); - const pmt::pmt_t s_key_frequency = pmt::pmt_string_to_symbol("frequency"); - const pmt::pmt_t s_key_rssi = pmt::pmt_string_to_symbol("rssi"); - const pmt::pmt_t s_key_rx_gain = pmt::pmt_string_to_symbol("gain"); + const pmt::pmt_t key_time = pmt::pmt_string_to_symbol("time"); + const pmt::pmt_t key_sample_rate = pmt::pmt_string_to_symbol("sample_rate"); + const pmt::pmt_t key_frequency = pmt::pmt_string_to_symbol("frequency"); + const pmt::pmt_t key_rssi = pmt::pmt_string_to_symbol("rssi"); + const pmt::pmt_t key_rx_gain = pmt::pmt_string_to_symbol("gain"); } diff --git a/gnuradio-core/src/lib/runtime/gr_tag_info.h b/gnuradio-core/src/lib/runtime/gr_tag_info.h index af51cf6a9..0ba699a0e 100644 --- a/gnuradio-core/src/lib/runtime/gr_tag_info.h +++ b/gnuradio-core/src/lib/runtime/gr_tag_info.h @@ -34,11 +34,11 @@ namespace gr_tags { TAG_VALUE_REF }; - extern const pmt::pmt_t s_key_time; - extern const pmt::pmt_t s_key_sample_rate; - extern const pmt::pmt_t s_key_frequency; - extern const pmt::pmt_t s_key_rssi; - extern const pmt::pmt_t s_key_gain; + extern const pmt::pmt_t key_time; + extern const pmt::pmt_t key_sample_rate; + extern const pmt::pmt_t key_frequency; + extern const pmt::pmt_t key_rssi; + extern const pmt::pmt_t key_gain; static inline uint64_t get_nitems(const pmt::pmt_t &tag) { -- cgit From 8f2b07591c404c78c9fc7b9532d3fb6c27165981 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sun, 21 Nov 2010 19:40:35 -0500 Subject: Tagging file source takes in sample rate and uses it to find the last time tag and adjust the time between these tags and the burst start by the sample rate. Also added a function to gr_tag_info that can be used to sort tags based on nitems using std::sort. --- gnuradio-core/src/lib/io/gr_tagged_file_sink.cc | 77 ++++++++++++++++--------- gnuradio-core/src/lib/io/gr_tagged_file_sink.h | 13 +++-- gnuradio-core/src/lib/io/gr_tagged_file_sink.i | 4 +- gnuradio-core/src/lib/runtime/gr_tag_info.h | 20 +++++++ 4 files changed, 81 insertions(+), 33 deletions(-) (limited to 'gnuradio-core/src') diff --git a/gnuradio-core/src/lib/io/gr_tagged_file_sink.cc b/gnuradio-core/src/lib/io/gr_tagged_file_sink.cc index 9b5ae70a6..500a359b3 100644 --- a/gnuradio-core/src/lib/io/gr_tagged_file_sink.cc +++ b/gnuradio-core/src/lib/io/gr_tagged_file_sink.cc @@ -49,33 +49,27 @@ #endif -gr_tagged_file_sink::gr_tagged_file_sink (size_t itemsize) +gr_tagged_file_sink::gr_tagged_file_sink (size_t itemsize, double samp_rate) : gr_sync_block ("tagged_file_sink", gr_make_io_signature (1, 1, itemsize), gr_make_io_signature (0, 0, 0)), - d_itemsize (itemsize),d_n(0) + d_itemsize (itemsize), d_n(0), d_sample_rate(samp_rate) { d_state = NOT_IN_BURST; + d_last_N = 0; + d_timeval = 0; } gr_tagged_file_sink_sptr -gr_make_tagged_file_sink (size_t itemsize) +gr_make_tagged_file_sink (size_t itemsize, double samp_rate) { - return gnuradio::get_initial_sptr(new gr_tagged_file_sink (itemsize)); + return gnuradio::get_initial_sptr(new gr_tagged_file_sink (itemsize, samp_rate)); } gr_tagged_file_sink::~gr_tagged_file_sink () { } -bool pmtcompare(pmt::pmt_t x, pmt::pmt_t y) -{ - uint64_t t_x, t_y; - t_x = pmt::pmt_to_uint64(pmt::pmt_tuple_ref(x, 0)); - t_y = pmt::pmt_to_uint64(pmt::pmt_tuple_ref(y, 0)); - return t_x < t_y; -} - int gr_tagged_file_sink::work (int noutput_items, gr_vector_const_void_star &input_items, @@ -86,13 +80,12 @@ gr_tagged_file_sink::work (int noutput_items, uint64_t start_N = nitems_read(0); uint64_t end_N = start_N + (uint64_t)(noutput_items); pmt::pmt_t bkey = pmt::pmt_string_to_symbol("burst"); - //pmt::pmt_t tkey = pmt::pmt_string_to_symbol("time"); // use gr_tags::s_key_time + //pmt::pmt_t tkey = pmt::pmt_string_to_symbol("time"); // use gr_tags::key_time std::vector all_tags; get_tags_in_range(all_tags, 0, start_N, end_N); - std::sort(all_tags.begin(), all_tags.end(), pmtcompare); - std::cout << "Number of tags: " << all_tags.size() << std::endl; + std::sort(all_tags.begin(), all_tags.end(), gr_tags::nitems_compare); std::vector::iterator vitr = all_tags.begin(); @@ -100,18 +93,53 @@ gr_tagged_file_sink::work (int noutput_items, while(idx < noutput_items) { if(d_state == NOT_IN_BURST) { while(vitr != all_tags.end()) { - //std::cout << "\tNot in burst: " << *vitr << std::endl; - if((pmt::pmt_eqv(gr_tags::get_key(*vitr), bkey)) && pmt::pmt_is_true(gr_tags::get_value(*vitr))) { - uint64_t N = gr_tags::get_nitems(*vitr) - start_N; - idx = (int)N; - - std::cout << std::endl << "Found start of burst: " << N << ", " << N+start_N << std::endl; + uint64_t N = gr_tags::get_nitems(*vitr); + idx = (int)(N - start_N); + + std::cout << std::endl << "Found start of burst: " + << idx << ", " << N << std::endl; + + // Find time burst occurred by getting latest time tag and extrapolating + // to new time based on sample rate of this block. + std::vector time_tags; + get_tags_in_range(time_tags, 0, d_last_N, N, gr_tags::key_time); + if(time_tags.size() > 0) { + pmt::pmt_t tag = time_tags[time_tags.size()-1]; + + uint64_t time_nitems = gr_tags::get_nitems(tag); + + // Get time based on last time tag from USRP + pmt::pmt_t time = gr_tags::get_value(tag); + int tsecs = pmt::pmt_to_long(pmt::pmt_tuple_ref(time, 0)); + double tfrac = pmt::pmt_to_double(pmt::pmt_tuple_ref(time, 1)); + + // Get new time from last time tag + difference in time to when + // burst tag occured based on the sample rate + double delta = (double)(N - time_nitems) / d_sample_rate; + d_timeval = (double)tsecs + tfrac + delta; + + std::cout.setf(std::ios::fixed, std::ios::floatfield); + std::cout.precision(8); + std::cout << "Time found: " << (double)tsecs + tfrac << std::endl; + std::cout << " time: " << d_timeval << std::endl; + std::cout << " time at N = " << time_nitems << " burst N = " << N << std::endl; + } + else { + // if no time tag, use last seen tag and update time based on + // sample rate of the block + d_timeval += (double)(N - d_last_N) / d_sample_rate; + std::cout << "Time not found" << std::endl; + std::cout << " time: " << d_timeval << std::endl; + } + d_last_N = N; std::stringstream filename; - filename << "file" << d_n << ".dat"; + filename.setf(std::ios::fixed, std::ios::floatfield); + filename.precision(8); + filename << "file" << d_n << "_" << d_timeval << ".dat"; d_n++; int fd; @@ -142,15 +170,11 @@ gr_tagged_file_sink::work (int noutput_items, } else { // In burst while(vitr != all_tags.end()) { - //std::cout << "\tin burst: " << *vitr << std::endl; - if((pmt::pmt_eqv(gr_tags::get_key(*vitr), bkey)) && pmt::pmt_is_false(gr_tags::get_value(*vitr))) { uint64_t N = gr_tags::get_nitems(*vitr) - start_N; idx_stop = (int)N; - std::cout << "Found end of burst: " << N << ", " << N+start_N << std::endl; - int count = fwrite (&inbuf[d_itemsize*idx], d_itemsize, idx_stop-idx, d_handle); if (count == 0) break; @@ -164,7 +188,6 @@ gr_tagged_file_sink::work (int noutput_items, } } if(d_state == IN_BURST) { - std::cout << "writing part of burst: " << noutput_items-idx << std::endl; int count = fwrite (&inbuf[idx], d_itemsize, noutput_items-idx, d_handle); if (count == 0) break; diff --git a/gnuradio-core/src/lib/io/gr_tagged_file_sink.h b/gnuradio-core/src/lib/io/gr_tagged_file_sink.h index c657e6a75..956340f8d 100644 --- a/gnuradio-core/src/lib/io/gr_tagged_file_sink.h +++ b/gnuradio-core/src/lib/io/gr_tagged_file_sink.h @@ -28,7 +28,8 @@ class gr_tagged_file_sink; typedef boost::shared_ptr gr_tagged_file_sink_sptr; -gr_tagged_file_sink_sptr gr_make_tagged_file_sink (size_t itemsize); +gr_tagged_file_sink_sptr gr_make_tagged_file_sink (size_t itemsize, + double samp_rate); /*! * \brief Write stream to file descriptor. @@ -37,7 +38,8 @@ gr_tagged_file_sink_sptr gr_make_tagged_file_sink (size_t itemsize); class gr_tagged_file_sink : public gr_sync_block { - friend gr_tagged_file_sink_sptr gr_make_tagged_file_sink (size_t itemsize); + friend gr_tagged_file_sink_sptr gr_make_tagged_file_sink (size_t itemsize, + double samp_rate); private: enum { @@ -49,9 +51,12 @@ class gr_tagged_file_sink : public gr_sync_block int d_state; FILE *d_handle; int d_n; - + double d_sample_rate; + uint64_t d_last_N; + double d_timeval; + protected: - gr_tagged_file_sink (size_t itemsize); + gr_tagged_file_sink (size_t itemsize, double samp_rate); public: ~gr_tagged_file_sink (); diff --git a/gnuradio-core/src/lib/io/gr_tagged_file_sink.i b/gnuradio-core/src/lib/io/gr_tagged_file_sink.i index 92248e5dd..1408adfc1 100644 --- a/gnuradio-core/src/lib/io/gr_tagged_file_sink.i +++ b/gnuradio-core/src/lib/io/gr_tagged_file_sink.i @@ -23,12 +23,12 @@ GR_SWIG_BLOCK_MAGIC(gr,tagged_file_sink) gr_tagged_file_sink_sptr -gr_make_tagged_file_sink (size_t itemsize); +gr_make_tagged_file_sink (size_t itemsize, double samp_rate); class gr_tagged_file_sink : public gr_sync_block { protected: - gr_tagged_file_sink (size_t itemsize); + gr_tagged_file_sink (size_t itemsize, double samp_rate); public: ~gr_tagged_file_sink (); diff --git a/gnuradio-core/src/lib/runtime/gr_tag_info.h b/gnuradio-core/src/lib/runtime/gr_tag_info.h index 0ba699a0e..5ed30a815 100644 --- a/gnuradio-core/src/lib/runtime/gr_tag_info.h +++ b/gnuradio-core/src/lib/runtime/gr_tag_info.h @@ -40,26 +40,46 @@ namespace gr_tags { extern const pmt::pmt_t key_rssi; extern const pmt::pmt_t key_gain; + /*! + * \brief Returns the item \p tag occurred at (as a uint64_t) + */ static inline uint64_t get_nitems(const pmt::pmt_t &tag) { return pmt::pmt_to_uint64(pmt::pmt_tuple_ref(tag, TAG_NITEM_REF)); } + /*! + * \brief Returns the source ID of \p tag (as a PMT) + */ static inline pmt::pmt_t get_srcid(const pmt::pmt_t &tag) { return pmt::pmt_tuple_ref(tag, TAG_SRCID_REF); } + /*! + * \brief Returns the key of \p tag (as a PMT symbol) + */ static inline pmt::pmt_t get_key(const pmt::pmt_t &tag) { return pmt::pmt_tuple_ref(tag, TAG_KEY_REF); } + /*! + * \brief Returns the value of \p tag (as a PMT) + */ static inline pmt::pmt_t get_value(const pmt::pmt_t &tag) { return pmt::pmt_tuple_ref(tag, TAG_VALUE_REF); } + /*! + * \brief Comparison function to test which tag, \p x or \p y, came first in time + */ + static inline bool + nitems_compare(pmt::pmt_t x, pmt::pmt_t y) { + return get_nitems(x) < get_nitems(y); + } + }; /* namespace tags */ #endif /* GR_TAG_INFO */ -- cgit From 1b7b68ec2211c50de98bef7414e4ac807edf460a Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sun, 21 Nov 2010 20:51:37 -0500 Subject: Doxygen comments. Fixing typos that were leading to warnings. --- gnuradio-core/src/lib/runtime/gr_block.h | 2 +- gnuradio-core/src/lib/runtime/gr_block_detail.h | 2 +- gnuradio-core/src/lib/runtime/gr_buffer.h | 6 ++++++ 3 files changed, 8 insertions(+), 2 deletions(-) (limited to 'gnuradio-core/src') diff --git a/gnuradio-core/src/lib/runtime/gr_block.h b/gnuradio-core/src/lib/runtime/gr_block.h index 7caf3c34a..36eed3d10 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.h +++ b/gnuradio-core/src/lib/runtime/gr_block.h @@ -247,7 +247,7 @@ class gr_block : public gr_basic_block { /*! * \brief Adds a new tag onto the given output buffer. * - * \param which_ouput an integer of which output stream to attach the tag + * \param which_output an integer of which output stream to attach the tag * \param abs_offset a uint64 number of the absolute item number * assicated with the tag. Can get from nitems_written. * \param key the tag key as a PMT symbol diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.h b/gnuradio-core/src/lib/runtime/gr_block_detail.h index 834ef47f5..d7ec3b136 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.h +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.h @@ -103,7 +103,7 @@ class gr_block_detail { * from it. It then calls gr_buffer::add_item_tag(pmt::pmt_t t), * which appends the tag onto its deque. * - * \param which_ouput an integer of which output stream to attach the tag + * \param which_output an integer of which output stream to attach the tag * \param abs_offset a uint64 number of the absolute item number * assicated with the tag. Can get from nitems_written. * \param key the tag key as a PMT symbol diff --git a/gnuradio-core/src/lib/runtime/gr_buffer.h b/gnuradio-core/src/lib/runtime/gr_buffer.h index 2d88c1722..fe0e7585d 100644 --- a/gnuradio-core/src/lib/runtime/gr_buffer.h +++ b/gnuradio-core/src/lib/runtime/gr_buffer.h @@ -99,6 +99,11 @@ class gr_buffer { */ void add_item_tag(const pmt::pmt_t &tag); + /*! + * \brief Removes all tags before \p max_time from buffer + * + * \param max_time the time (item number) to trim up until. + */ void prune_tags(uint64_t max_time); std::deque::iterator get_tags_begin() { return d_item_tags.begin(); } @@ -244,6 +249,7 @@ class gr_buffer_reader { /*! * \brief Return the block that reads via this reader. + * */ gr_block_sptr link() { return gr_block_sptr(d_link); } -- cgit From 9217bbcafe547fd5815265758370b07c375d72c9 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sun, 21 Nov 2010 21:17:42 -0500 Subject: Fixed file tagger error handling so it doesn't prematurely exit under certain, but correct, conditions. --- gnuradio-core/src/lib/io/gr_tagged_file_sink.cc | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'gnuradio-core/src') diff --git a/gnuradio-core/src/lib/io/gr_tagged_file_sink.cc b/gnuradio-core/src/lib/io/gr_tagged_file_sink.cc index 500a359b3..371d6268c 100644 --- a/gnuradio-core/src/lib/io/gr_tagged_file_sink.cc +++ b/gnuradio-core/src/lib/io/gr_tagged_file_sink.cc @@ -172,28 +172,37 @@ gr_tagged_file_sink::work (int noutput_items, while(vitr != all_tags.end()) { if((pmt::pmt_eqv(gr_tags::get_key(*vitr), bkey)) && pmt::pmt_is_false(gr_tags::get_value(*vitr))) { - uint64_t N = gr_tags::get_nitems(*vitr) - start_N; - idx_stop = (int)N; + uint64_t N = gr_tags::get_nitems(*vitr); + idx_stop = (int)N - start_N; + + std::cout << "Found end of burst: " + << idx_stop << ", " << N << std::endl; int count = fwrite (&inbuf[d_itemsize*idx], d_itemsize, idx_stop-idx, d_handle); - if (count == 0) - break; + if (count == 0) { + if(ferror(d_handle)) { + perror("gr_tagged_file_sink: error writing file"); + } + } idx = idx_stop; d_state = NOT_IN_BURST; vitr++; fclose(d_handle); break; - } else { + } + else { vitr++; } } if(d_state == IN_BURST) { int count = fwrite (&inbuf[idx], d_itemsize, noutput_items-idx, d_handle); - if (count == 0) - break; + if (count == 0) { + if(ferror(d_handle)) { + perror("gr_tagged_file_sink: error writing file"); + } + } idx = noutput_items; } - } } -- cgit From 7c5dc0920240f566ad4482f47ca8b9095479f04e Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sun, 21 Nov 2010 21:23:31 -0500 Subject: Removed comments to stdout from file tagger; made it easir to go from internally generated bursts to detected bursts (which needs work). --- gnuradio-core/src/lib/io/gr_tagged_file_sink.cc | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'gnuradio-core/src') diff --git a/gnuradio-core/src/lib/io/gr_tagged_file_sink.cc b/gnuradio-core/src/lib/io/gr_tagged_file_sink.cc index 371d6268c..55c42eaff 100644 --- a/gnuradio-core/src/lib/io/gr_tagged_file_sink.cc +++ b/gnuradio-core/src/lib/io/gr_tagged_file_sink.cc @@ -99,8 +99,8 @@ gr_tagged_file_sink::work (int noutput_items, uint64_t N = gr_tags::get_nitems(*vitr); idx = (int)(N - start_N); - std::cout << std::endl << "Found start of burst: " - << idx << ", " << N << std::endl; + //std::cout << std::endl << "Found start of burst: " + // << idx << ", " << N << std::endl; // Find time burst occurred by getting latest time tag and extrapolating // to new time based on sample rate of this block. @@ -121,18 +121,18 @@ gr_tagged_file_sink::work (int noutput_items, double delta = (double)(N - time_nitems) / d_sample_rate; d_timeval = (double)tsecs + tfrac + delta; - std::cout.setf(std::ios::fixed, std::ios::floatfield); - std::cout.precision(8); - std::cout << "Time found: " << (double)tsecs + tfrac << std::endl; - std::cout << " time: " << d_timeval << std::endl; - std::cout << " time at N = " << time_nitems << " burst N = " << N << std::endl; + //std::cout.setf(std::ios::fixed, std::ios::floatfield); + //std::cout.precision(8); + //std::cout << "Time found: " << (double)tsecs + tfrac << std::endl; + //std::cout << " time: " << d_timeval << std::endl; + //std::cout << " time at N = " << time_nitems << " burst N = " << N << std::endl; } else { // if no time tag, use last seen tag and update time based on // sample rate of the block d_timeval += (double)(N - d_last_N) / d_sample_rate; - std::cout << "Time not found" << std::endl; - std::cout << " time: " << d_timeval << std::endl; + //std::cout << "Time not found" << std::endl; + //std::cout << " time: " << d_timeval << std::endl; } d_last_N = N; @@ -157,7 +157,7 @@ gr_tagged_file_sink::work (int noutput_items, ::close(fd); // don't leak file descriptor if fdopen fails. } - std::cout << "Created new file: " << filename.str() << std::endl; + //std::cout << "Created new file: " << filename.str() << std::endl; d_state = IN_BURST; break; @@ -175,8 +175,8 @@ gr_tagged_file_sink::work (int noutput_items, uint64_t N = gr_tags::get_nitems(*vitr); idx_stop = (int)N - start_N; - std::cout << "Found end of burst: " - << idx_stop << ", " << N << std::endl; + //std::cout << "Found end of burst: " + // << idx_stop << ", " << N << std::endl; int count = fwrite (&inbuf[d_itemsize*idx], d_itemsize, idx_stop-idx, d_handle); if (count == 0) { -- cgit From 181ad4cda3879a1760d61054ff32f8abbc9c24cf Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Mon, 22 Nov 2010 22:46:18 -0500 Subject: Check for relative rate and update tag only if not 1.0; otherwise just copy. --- gnuradio-core/src/lib/runtime/gr_block_executor.cc | 26 ++++++++++++++-------- 1 file changed, 17 insertions(+), 9 deletions(-) (limited to 'gnuradio-core/src') diff --git a/gnuradio-core/src/lib/runtime/gr_block_executor.cc b/gnuradio-core/src/lib/runtime/gr_block_executor.cc index 59799069a..ea489d079 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_executor.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_executor.cc @@ -110,15 +110,23 @@ propagate_tags(gr_block::TAG_PROPAGATION_POLICY policy, gr_block_detail *d, d->nitems_read(i)); std::vector::iterator t; - for(t = rtags.begin(); t != rtags.end(); t++) { - uint64_t newcount = pmt::pmt_to_uint64(pmt::pmt_tuple_ref(*t, 0)); - pmt::pmt_t newtup = pmt::mp(pmt::pmt_from_uint64(newcount * rrate), - pmt::pmt_tuple_ref(*t, 1), - pmt::pmt_tuple_ref(*t, 2), - pmt::pmt_tuple_ref(*t, 3)); - - for(int o = 0; o < d->noutputs(); o++) - d->output(o)->add_item_tag(newtup); + if(rrate != 1.0) { + for(t = rtags.begin(); t != rtags.end(); t++) { + uint64_t newcount = pmt::pmt_to_uint64(pmt::pmt_tuple_ref(*t, 0)); + pmt::pmt_t newtup = pmt::mp(pmt::pmt_from_uint64(newcount * rrate), + pmt::pmt_tuple_ref(*t, 1), + pmt::pmt_tuple_ref(*t, 2), + pmt::pmt_tuple_ref(*t, 3)); + + for(int o = 0; o < d->noutputs(); o++) + d->output(o)->add_item_tag(newtup); + } + } + else { + for(t = rtags.begin(); t != rtags.end(); t++) { + for(int o = 0; o < d->noutputs(); o++) + d->output(o)->add_item_tag(*t); + } } } break; -- cgit From 7d14fec5653b7aa92de8ef9ba76f02b7181ee928 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Tue, 23 Nov 2010 22:57:10 -0500 Subject: Removing dependency in QA code to filters that have not necessarily been built yet. Using test block keep_one_in_n to test decimation is handled in propogating tags. --- gnuradio-core/src/lib/runtime/qa_block_tags.cc | 39 ++++---------------------- 1 file changed, 5 insertions(+), 34 deletions(-) (limited to 'gnuradio-core/src') diff --git a/gnuradio-core/src/lib/runtime/qa_block_tags.cc b/gnuradio-core/src/lib/runtime/qa_block_tags.cc index 2092e48ed..14983013c 100644 --- a/gnuradio-core/src/lib/runtime/qa_block_tags.cc +++ b/gnuradio-core/src/lib/runtime/qa_block_tags.cc @@ -31,8 +31,7 @@ #include #include #include -#include -#include +#include #include #include @@ -375,18 +374,14 @@ qa_block_tags::t5 () gr_block_sptr snk0 (gr_make_null_sink(sizeof(float))); // Rate change blocks - std::vector taps = gr_firdes::low_pass_2(1, 1, 0.4, 0.1, 60); - gr_fir_filter_fff_sptr fir_dec10 (gr_make_fir_filter_fff(10, taps)); - gr_interp_fir_filter_fff_sptr fir_int2 (gr_make_interp_fir_filter_fff(2, taps)); + gr_keep_one_in_n_sptr dec10 (gr_make_keep_one_in_n(sizeof(float), 10)); tb->connect(src, 0, head, 0); tb->connect(head, 0, ann0, 0); tb->connect(ann0, 0, ann1, 0); - tb->connect(ann1, 0, fir_dec10, 0); - tb->connect(fir_dec10, 0, ann2, 0); - tb->connect(ann2, 0, fir_int2, 0); - tb->connect(fir_int2, 0, ann3, 0); - tb->connect(ann3, 0, snk0, 0); + tb->connect(ann1, 0, dec10, 0); + tb->connect(dec10, 0, ann2, 0); + tb->connect(ann2, 0, snk0, 0); tb->run(); @@ -414,24 +409,9 @@ qa_block_tags::t5 () expected_tags2[8] = mp(pmt_from_uint64(4000), mp(str1.str()), mp("seq"), mp(4)); expected_tags2[9] = mp(pmt_from_uint64(4000), mp(str0.str()), mp("seq"), mp(4)); - pmt_t expected_tags3[12]; - expected_tags3[0] = mp(pmt_from_uint64(0), mp(str2.str()), mp("seq"), mp(0)); - expected_tags3[1] = mp(pmt_from_uint64(0), mp(str1.str()), mp("seq"), mp(0)); - expected_tags3[2] = mp(pmt_from_uint64(0), mp(str0.str()), mp("seq"), mp(0)); - expected_tags3[3] = mp(pmt_from_uint64(2000), mp(str2.str()), mp("seq"), mp(1)); - expected_tags3[4] = mp(pmt_from_uint64(2000), mp(str1.str()), mp("seq"), mp(1)); - expected_tags3[5] = mp(pmt_from_uint64(2000), mp(str0.str()), mp("seq"), mp(1)); - expected_tags3[6] = mp(pmt_from_uint64(4000), mp(str2.str()), mp("seq"), mp(2)); - expected_tags3[7] = mp(pmt_from_uint64(4000), mp(str1.str()), mp("seq"), mp(2)); - expected_tags3[8] = mp(pmt_from_uint64(4000), mp(str0.str()), mp("seq"), mp(2)); - expected_tags3[9] = mp(pmt_from_uint64(6000), mp(str2.str()), mp("seq"), mp(3)); - expected_tags3[10] = mp(pmt_from_uint64(6000), mp(str1.str()), mp("seq"), mp(3)); - expected_tags3[11] = mp(pmt_from_uint64(6000), mp(str0.str()), mp("seq"), mp(3)); - std::vector tags0 = ann0->data(); std::vector tags1 = ann1->data(); std::vector tags2 = ann2->data(); - std::vector tags3 = ann3->data(); // The first annotator does not receive any tags from the null sink upstream CPPUNIT_ASSERT_EQUAL(tags0.size(), (size_t)0); @@ -453,14 +433,5 @@ qa_block_tags::t5 () std::cout << "tags2[" << i << "] = " << tags2[i] << "\t\t" << expected_tags2[i] << std::endl; CPPUNIT_ASSERT_EQUAL(pmt_write_string(tags2[i]), pmt_write_string(expected_tags2[i])); } - - // annotator 3 gets tags from annotators 0, 1, and 2 - std::cout << std::endl; - std::cout << "tags3.size(): " << tags3.size() << std::endl; - CPPUNIT_ASSERT_EQUAL(tags3.size(), (size_t)12); - for(size_t i = 0; i < tags3.size(); i++) { - std::cout << "tags3[" << i << "] = " << tags3[i] << "\t\t" << expected_tags3[i] << std::endl; - CPPUNIT_ASSERT_EQUAL(pmt_write_string(tags3[i]), pmt_write_string(expected_tags3[i])); - } } -- cgit From 88c83cf6e9374f2cbd5483798a0614d72fb3dcbd Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Tue, 23 Nov 2010 23:57:02 -0500 Subject: Fixing output types from tap_type to o_type in gr_single_pole_iir.h. Doesn't make a difference in the current uses of this class, but could in the future. Thanks to Achilleas Anastasopoulos for pointing this out. --- gnuradio-core/src/lib/filter/gr_single_pole_iir.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'gnuradio-core/src') diff --git a/gnuradio-core/src/lib/filter/gr_single_pole_iir.h b/gnuradio-core/src/lib/filter/gr_single_pole_iir.h index bd59e53ac..da919b35c 100644 --- a/gnuradio-core/src/lib/filter/gr_single_pole_iir.h +++ b/gnuradio-core/src/lib/filter/gr_single_pole_iir.h @@ -71,12 +71,12 @@ public: d_prev_output = 0; } - tap_type prev_output () { return d_prev_output; } + o_type prev_output () { return d_prev_output; } protected: tap_type d_alpha; tap_type d_one_minus_alpha; - tap_type d_prev_output; + o_type d_prev_output; }; @@ -87,7 +87,7 @@ template o_type gr_single_pole_iir::filter (const i_type input) { - tap_type output; + o_type output; output = d_alpha * input + d_one_minus_alpha * d_prev_output; d_prev_output = output; -- cgit From 522073fa95ffcb231bf8c72105bc5cc62dd8d9ed Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Wed, 24 Nov 2010 18:20:40 -0500 Subject: Adding typedef for uint64_t and int64_t so we can use them through SWIG. --- gnuradio-core/src/lib/swig/gnuradio.i | 2 ++ 1 file changed, 2 insertions(+) (limited to 'gnuradio-core/src') diff --git a/gnuradio-core/src/lib/swig/gnuradio.i b/gnuradio-core/src/lib/swig/gnuradio.i index 7d0241f1c..e15a0059c 100644 --- a/gnuradio-core/src/lib/swig/gnuradio.i +++ b/gnuradio-core/src/lib/swig/gnuradio.i @@ -46,6 +46,8 @@ typedef std::complex gr_complex; typedef std::complex gr_complexd; +typedef unsigned long long uint64_t; +typedef long long int64_t; // instantiate the required template specializations -- cgit From dd656e9db5e69ed6b11653deea710e299d72827e Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Wed, 24 Nov 2010 18:21:02 -0500 Subject: Changing API for gr_skiphead to use uint64_t for the offset instead of size_t (still unsigned). Fixes issue #304. Also uses uint64_t's internally so everyone is always on the same type. This should not affect anyone's use of the block. --- gnuradio-core/src/lib/general/gr_skiphead.cc | 8 ++++---- gnuradio-core/src/lib/general/gr_skiphead.h | 10 +++++----- gnuradio-core/src/lib/general/gr_skiphead.i | 8 ++++---- 3 files changed, 13 insertions(+), 13 deletions(-) (limited to 'gnuradio-core/src') diff --git a/gnuradio-core/src/lib/general/gr_skiphead.cc b/gnuradio-core/src/lib/general/gr_skiphead.cc index ea7e9405f..1670eb7cf 100644 --- a/gnuradio-core/src/lib/general/gr_skiphead.cc +++ b/gnuradio-core/src/lib/general/gr_skiphead.cc @@ -27,7 +27,7 @@ #include #include -gr_skiphead::gr_skiphead (size_t itemsize, size_t nitems_to_skip) +gr_skiphead::gr_skiphead (size_t itemsize, uint64_t nitems_to_skip) : gr_block ("skiphead", gr_make_io_signature(1, 1, itemsize), gr_make_io_signature(1, 1, itemsize)), @@ -36,7 +36,7 @@ gr_skiphead::gr_skiphead (size_t itemsize, size_t nitems_to_skip) } gr_skiphead_sptr -gr_make_skiphead (size_t itemsize, size_t nitems_to_skip) +gr_make_skiphead (size_t itemsize, uint64_t nitems_to_skip) { return gnuradio::get_initial_sptr(new gr_skiphead (itemsize, nitems_to_skip)); } @@ -55,11 +55,11 @@ gr_skiphead::general_work(int noutput_items, while (ii < ninput_items){ - long long ni_total = ii + d_nitems; // total items processed so far + uint64_t ni_total = ii + d_nitems; // total items processed so far if (ni_total < d_nitems_to_skip){ // need to skip some more int n_to_skip = (int) std::min(d_nitems_to_skip - ni_total, - (long long)(ninput_items - ii)); + (uint64_t)(ninput_items - ii)); ii += n_to_skip; } diff --git a/gnuradio-core/src/lib/general/gr_skiphead.h b/gnuradio-core/src/lib/general/gr_skiphead.h index 965feff9b..933c126e3 100644 --- a/gnuradio-core/src/lib/general/gr_skiphead.h +++ b/gnuradio-core/src/lib/general/gr_skiphead.h @@ -39,11 +39,11 @@ typedef boost::shared_ptr gr_skiphead_sptr; class gr_skiphead : public gr_block { - friend gr_skiphead_sptr gr_make_skiphead (size_t itemsize, size_t nitems_to_skip); - gr_skiphead (size_t itemsize, size_t nitems_to_skip); + friend gr_skiphead_sptr gr_make_skiphead (size_t itemsize, uint64_t nitems_to_skip); + gr_skiphead (size_t itemsize, uint64_t nitems_to_skip); - long long d_nitems_to_skip; - long long d_nitems; // total items seen + uint64_t d_nitems_to_skip; + uint64_t d_nitems; // total items seen public: @@ -54,7 +54,7 @@ class gr_skiphead : public gr_block }; gr_skiphead_sptr -gr_make_skiphead (size_t itemsize, size_t nitems_to_skip); +gr_make_skiphead (size_t itemsize, uint64_t nitems_to_skip); #endif /* INCLUDED_GR_SKIPHEAD_H */ diff --git a/gnuradio-core/src/lib/general/gr_skiphead.i b/gnuradio-core/src/lib/general/gr_skiphead.i index 52c0808f0..45cbd0437 100644 --- a/gnuradio-core/src/lib/general/gr_skiphead.i +++ b/gnuradio-core/src/lib/general/gr_skiphead.i @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2005,2007 Free Software Foundation, Inc. + * Copyright 2005,2007,2010 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -22,9 +22,9 @@ GR_SWIG_BLOCK_MAGIC(gr,skiphead); -gr_skiphead_sptr gr_make_skiphead (size_t itemsize, size_t nitems_to_skip); +gr_skiphead_sptr gr_make_skiphead (size_t itemsize, uint64_t nitems_to_skip); class gr_skiphead : public gr_block { - friend gr_skiphead_sptr gr_make_skiphead (size_t itemsize, size_t nitems_to_skip); - gr_skiphead (size_t itemsize, size_t nitems_to_skip); + friend gr_skiphead_sptr gr_make_skiphead (size_t itemsize, uint64_t nitems_to_skip); + gr_skiphead (size_t itemsize, uint64_t nitems_to_skip); }; -- cgit From 4649aa471222351e8586b90e98bb947325d340b6 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sun, 28 Nov 2010 19:15:27 -0500 Subject: Changing propagation policy enum type name and making a few other minor edits. --- gnuradio-core/src/lib/runtime/gr_block.cc | 4 ++-- gnuradio-core/src/lib/runtime/gr_block.h | 8 ++++---- gnuradio-core/src/lib/runtime/gr_block_executor.cc | 12 ++++++------ 3 files changed, 12 insertions(+), 12 deletions(-) (limited to 'gnuradio-core/src') diff --git a/gnuradio-core/src/lib/runtime/gr_block.cc b/gnuradio-core/src/lib/runtime/gr_block.cc index 52be37e3b..81a55af9d 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_block.cc @@ -169,14 +169,14 @@ gr_block::get_tags_in_range(std::vector &v, d_detail->get_tags_in_range(v, which_output, start, end, key); } -gr_block::TAG_PROPAGATION_POLICY +gr_block::tag_propagation_policy_t gr_block::tag_propagation_policy() { return d_tag_propagation_policy; } void -gr_block::set_tag_propagation_policy(TAG_PROPAGATION_POLICY p) +gr_block::set_tag_propagation_policy(tag_propagation_policy_t p) { d_tag_propagation_policy = p; } diff --git a/gnuradio-core/src/lib/runtime/gr_block.h b/gnuradio-core/src/lib/runtime/gr_block.h index 36eed3d10..ad7fa9555 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.h +++ b/gnuradio-core/src/lib/runtime/gr_block.h @@ -63,7 +63,7 @@ class gr_block : public gr_basic_block { WORK_DONE = -1 }; - enum TAG_PROPAGATION_POLICY { + enum tag_propagation_policy_t { TPP_DONT = 0, TPP_ALL_TO_ALL = 1, TPP_ONE_TO_ONE = 2 @@ -217,12 +217,12 @@ class gr_block : public gr_basic_block { /*! * \brief Asks for the policy used by the scheduler to moved tags downstream. */ - TAG_PROPAGATION_POLICY tag_propagation_policy(); + tag_propagation_policy_t tag_propagation_policy(); /*! * \brief Set the policy by the scheduler to determine how tags are moved downstream. */ - void set_tag_propagation_policy(TAG_PROPAGATION_POLICY p); + void set_tag_propagation_policy(tag_propagation_policy_t p); // ---------------------------------------------------------------------------- @@ -233,7 +233,7 @@ class gr_block : public gr_basic_block { gr_block_detail_sptr d_detail; // implementation details unsigned d_history; bool d_fixed_rate; - TAG_PROPAGATION_POLICY d_tag_propagation_policy; // policy for moving tags downstream + tag_propagation_policy_t d_tag_propagation_policy; // policy for moving tags downstream protected: diff --git a/gnuradio-core/src/lib/runtime/gr_block_executor.cc b/gnuradio-core/src/lib/runtime/gr_block_executor.cc index 59799069a..4a35e25d5 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_executor.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_executor.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2004,2008,2009 Free Software Foundation, Inc. + * Copyright 2004,2008,2009,2010 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -88,7 +88,7 @@ min_available_space (gr_block_detail *d, int output_multiple) } static bool -propagate_tags(gr_block::TAG_PROPAGATION_POLICY policy, gr_block_detail *d, +propagate_tags(gr_block::tag_propagation_policy_t policy, gr_block_detail *d, const std::vector &start_nitems_read, double rrate, std::vector &rtags) { @@ -100,10 +100,10 @@ propagate_tags(gr_block::TAG_PROPAGATION_POLICY policy, gr_block_detail *d, } switch(policy) { - case(gr_block::TPP_DONT): + case gr_block::TPP_DONT: return true; break; - case(gr_block::TPP_ALL_TO_ALL): + case gr_block::TPP_ALL_TO_ALL: // every tag on every input propogates to everyone downstream for(int i = 0; i < d->ninputs(); i++) { d->get_tags_in_range(rtags, i, start_nitems_read[i], @@ -122,7 +122,7 @@ propagate_tags(gr_block::TAG_PROPAGATION_POLICY policy, gr_block_detail *d, } } break; - case(gr_block::TPP_ONE_TO_ONE): + case gr_block::TPP_ONE_TO_ONE: // tags from input i only go to output i // this requires d->ninputs() == d->noutputs; this is checked when this // type of tag-propagation system is selected in gr_block_detail @@ -362,7 +362,7 @@ gr_block_executor::run_one_iteration() for (int i = 0; i < d->noutputs (); i++) d_output_items[i] = d->output(i)->write_pointer(); - // determine where to start looking for new tags as 1 past nitems read + // determine where to start looking for new tags for (int i = 0; i < d->ninputs(); i++) d_start_nitems_read[i] = d->nitems_read(i); -- cgit From 0f2bd2c94baa43fc8626f5285c0696a379ef5efd Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sun, 28 Nov 2010 19:17:07 -0500 Subject: Swapping order of testing rrate. --- gnuradio-core/src/lib/runtime/gr_block_executor.cc | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'gnuradio-core/src') diff --git a/gnuradio-core/src/lib/runtime/gr_block_executor.cc b/gnuradio-core/src/lib/runtime/gr_block_executor.cc index 9c30b1334..112150235 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_executor.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_executor.cc @@ -110,7 +110,13 @@ propagate_tags(gr_block::tag_propagation_policy_t policy, gr_block_detail *d, d->nitems_read(i)); std::vector::iterator t; - if(rrate != 1.0) { + if(rrate == 1.0) { + for(t = rtags.begin(); t != rtags.end(); t++) { + for(int o = 0; o < d->noutputs(); o++) + d->output(o)->add_item_tag(*t); + } + } + else { for(t = rtags.begin(); t != rtags.end(); t++) { uint64_t newcount = pmt::pmt_to_uint64(pmt::pmt_tuple_ref(*t, 0)); pmt::pmt_t newtup = pmt::mp(pmt::pmt_from_uint64(newcount * rrate), @@ -122,12 +128,6 @@ propagate_tags(gr_block::tag_propagation_policy_t policy, gr_block_detail *d, d->output(o)->add_item_tag(newtup); } } - else { - for(t = rtags.begin(); t != rtags.end(); t++) { - for(int o = 0; o < d->noutputs(); o++) - d->output(o)->add_item_tag(*t); - } - } } break; case gr_block::TPP_ONE_TO_ONE: -- cgit From 34a9654fa10efcf360fde9c42c624739abaabbc5 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Mon, 29 Nov 2010 12:59:54 -0500 Subject: Removing global pmt constants. Were causing segfaults during make check. Must fix this later. --- gnuradio-core/src/lib/io/gr_tagged_file_sink.cc | 4 +++- gnuradio-core/src/lib/runtime/gr_tag_info.cc | 3 ++- gnuradio-core/src/lib/runtime/gr_tag_info.h | 2 ++ 3 files changed, 7 insertions(+), 2 deletions(-) (limited to 'gnuradio-core/src') diff --git a/gnuradio-core/src/lib/io/gr_tagged_file_sink.cc b/gnuradio-core/src/lib/io/gr_tagged_file_sink.cc index 55c42eaff..c76ede542 100644 --- a/gnuradio-core/src/lib/io/gr_tagged_file_sink.cc +++ b/gnuradio-core/src/lib/io/gr_tagged_file_sink.cc @@ -105,7 +105,9 @@ gr_tagged_file_sink::work (int noutput_items, // Find time burst occurred by getting latest time tag and extrapolating // to new time based on sample rate of this block. std::vector time_tags; - get_tags_in_range(time_tags, 0, d_last_N, N, gr_tags::key_time); + //get_tags_in_range(time_tags, 0, d_last_N, N, gr_tags::key_time); + get_tags_in_range(time_tags, 0, d_last_N, N, + pmt::pmt_string_to_symbol("time")); if(time_tags.size() > 0) { pmt::pmt_t tag = time_tags[time_tags.size()-1]; diff --git a/gnuradio-core/src/lib/runtime/gr_tag_info.cc b/gnuradio-core/src/lib/runtime/gr_tag_info.cc index c64cc7eb8..f15329f9b 100644 --- a/gnuradio-core/src/lib/runtime/gr_tag_info.cc +++ b/gnuradio-core/src/lib/runtime/gr_tag_info.cc @@ -28,10 +28,11 @@ #include namespace gr_tags { - +/* const pmt::pmt_t key_time = pmt::pmt_string_to_symbol("time"); const pmt::pmt_t key_sample_rate = pmt::pmt_string_to_symbol("sample_rate"); const pmt::pmt_t key_frequency = pmt::pmt_string_to_symbol("frequency"); const pmt::pmt_t key_rssi = pmt::pmt_string_to_symbol("rssi"); const pmt::pmt_t key_rx_gain = pmt::pmt_string_to_symbol("gain"); +*/ } diff --git a/gnuradio-core/src/lib/runtime/gr_tag_info.h b/gnuradio-core/src/lib/runtime/gr_tag_info.h index 5ed30a815..5a1e1555a 100644 --- a/gnuradio-core/src/lib/runtime/gr_tag_info.h +++ b/gnuradio-core/src/lib/runtime/gr_tag_info.h @@ -34,11 +34,13 @@ namespace gr_tags { TAG_VALUE_REF }; + /* extern const pmt::pmt_t key_time; extern const pmt::pmt_t key_sample_rate; extern const pmt::pmt_t key_frequency; extern const pmt::pmt_t key_rssi; extern const pmt::pmt_t key_gain; + */ /*! * \brief Returns the item \p tag occurred at (as a uint64_t) -- cgit From 649e4387848a5d9273983600be6f35c3e2a88191 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Mon, 29 Nov 2010 14:37:20 -0500 Subject: Block is a gr_block, so this sets its relative rate. Was required for using in the QA of the sample tags code. --- gnuradio-core/src/lib/general/gr_keep_one_in_n.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'gnuradio-core/src') diff --git a/gnuradio-core/src/lib/general/gr_keep_one_in_n.cc b/gnuradio-core/src/lib/general/gr_keep_one_in_n.cc index c07e177fe..85495e277 100644 --- a/gnuradio-core/src/lib/general/gr_keep_one_in_n.cc +++ b/gnuradio-core/src/lib/general/gr_keep_one_in_n.cc @@ -38,8 +38,9 @@ gr_keep_one_in_n::gr_keep_one_in_n (size_t item_size, int n) : gr_block ("keep_one_in_n", gr_make_io_signature (1, 1, item_size), gr_make_io_signature (1, 1, item_size)), - d_n (n), d_count(n) + d_count(n) { + set_n(n); } void @@ -50,6 +51,8 @@ gr_keep_one_in_n::set_n(int n) d_n = n; d_count = n; + + set_relative_rate(1.0 / (float)n); } int -- cgit From 1b179f0b381cbba224674db5678e542ce34a3d2a Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Mon, 29 Nov 2010 14:56:16 -0500 Subject: Modifying QA tests for the sample tags. By default, it only checks the sizes of the tags since order is not specified or guarenteed. --- gnuradio-core/src/lib/runtime/qa_block_tags.cc | 131 ++++++++++++++----------- 1 file changed, 72 insertions(+), 59 deletions(-) (limited to 'gnuradio-core/src') diff --git a/gnuradio-core/src/lib/runtime/qa_block_tags.cc b/gnuradio-core/src/lib/runtime/qa_block_tags.cc index 14983013c..07ce5c276 100644 --- a/gnuradio-core/src/lib/runtime/qa_block_tags.cc +++ b/gnuradio-core/src/lib/runtime/qa_block_tags.cc @@ -40,11 +40,18 @@ using namespace pmt; +// set to 1 to turn on debug output +// The debug output fully checks that the tags seen are what are expected. While +// this behavior currently works with our implementation, there is no guarentee +// that the tags will be coming in this specific order, so it's dangerous to +// rely on this as a test of the tag system working. We would really want to +// tags we know we should see and then test that they all occur once, but in no +// particular order. +#define QA_TAGS_DEBUG 0 + void qa_block_tags::t0 () { - printf("\nqa_block_tags::t0\n"); - unsigned int N = 1000; gr_top_block_sptr tb = gr_make_top_block("top"); gr_block_sptr src (gr_make_null_source(sizeof(int))); @@ -71,8 +78,6 @@ qa_block_tags::t0 () void qa_block_tags::t1 () { - printf("\nqa_block_tags::t1\n"); - int N = 40000; gr_top_block_sptr tb = gr_make_top_block("top"); gr_block_sptr src (gr_make_null_source(sizeof(int))); @@ -98,6 +103,16 @@ qa_block_tags::t1 () tb->run(); + std::vector tags0 = ann0->data(); + std::vector tags3 = ann3->data(); + std::vector tags4 = ann4->data(); + + // The first annotator does not receive any tags from the null sink upstream + CPPUNIT_ASSERT_EQUAL(tags0.size(), (size_t)0); + CPPUNIT_ASSERT_EQUAL(tags3.size(), (size_t)8); + CPPUNIT_ASSERT_EQUAL(tags4.size(), (size_t)8); + +#if QA_TAGS_DEBUG // Kludge together the tags that we know should result from the above graph std::stringstream str0, str1, str2; str0 << ann0->name() << ann0->unique_id(); @@ -123,36 +138,27 @@ qa_block_tags::t1 () expected_tags4[5] = mp(pmt_from_uint64(20000), mp(str0.str()), mp("seq"), mp(5)); expected_tags4[6] = mp(pmt_from_uint64(30000), mp(str2.str()), mp("seq"), mp(3)); expected_tags4[7] = mp(pmt_from_uint64(30000), mp(str0.str()), mp("seq"), mp(7)); - - std::vector tags0 = ann0->data(); - std::vector tags3 = ann3->data(); - std::vector tags4 = ann4->data(); - - // The first annotator does not receive any tags from the null sink upstream - CPPUNIT_ASSERT_EQUAL(tags0.size(), (size_t)0); + std::cout << std::endl << "qa_block_tags::t1" << std::endl; + // For annotator 3, we know it gets tags from ann0 and ann1, test this - CPPUNIT_ASSERT_EQUAL(tags3.size(), (size_t)8); for(size_t i = 0; i < tags3.size(); i++) { std::cout << "tags3[" << i << "] = " << tags3[i] << "\t\t" << expected_tags3[i] << std::endl; - //pmt_equal(tags3[i], expected_tags3[i]) CPPUNIT_ASSERT_EQUAL(pmt_write_string(tags3[i]), pmt_write_string(expected_tags3[i])); } // For annotator 4, we know it gets tags from ann0 and ann2, test this std::cout << std::endl; - CPPUNIT_ASSERT_EQUAL(tags4.size(), (size_t)8); for(size_t i = 0; i < tags4.size(); i++) { std::cout << "tags4[" << i << "] = " << tags4[i] << "\t\t" << expected_tags4[i] << std::endl; CPPUNIT_ASSERT_EQUAL(pmt_write_string(tags4[i]), pmt_write_string(expected_tags4[i])); } +#endif } void qa_block_tags::t2 () { - printf("\nqa_block_tags::t2\n"); - int N = 40000; gr_top_block_sptr tb = gr_make_top_block("top"); gr_block_sptr src (gr_make_null_source(sizeof(int))); @@ -181,6 +187,23 @@ qa_block_tags::t2 () tb->run(); + std::vector tags0 = ann0->data(); + std::vector tags1 = ann1->data(); + std::vector tags2 = ann2->data(); + std::vector tags3 = ann4->data(); + std::vector tags4 = ann4->data(); + + // The first annotator does not receive any tags from the null sink upstream + CPPUNIT_ASSERT_EQUAL(tags0.size(), (size_t)0); + CPPUNIT_ASSERT_EQUAL(tags1.size(), (size_t)8); + + // Make sure the rest all have 12 tags + CPPUNIT_ASSERT_EQUAL(tags2.size(), (size_t)12); + CPPUNIT_ASSERT_EQUAL(tags3.size(), (size_t)12); + CPPUNIT_ASSERT_EQUAL(tags4.size(), (size_t)12); + + +#if QA_TAGS_DEBUG // Kludge together the tags that we know should result from the above graph std::stringstream str0, str1; str0 << ann0->name() << ann0->unique_id(); @@ -214,20 +237,7 @@ qa_block_tags::t2 () expected_tags4[10] = mp(pmt_from_uint64(30000), mp(str0.str()), mp("seq"), mp(6)); expected_tags4[11] = mp(pmt_from_uint64(30000), mp(str0.str()), mp("seq"), mp(7)); - std::vector tags0 = ann0->data(); - std::vector tags1 = ann1->data(); - std::vector tags2 = ann2->data(); - std::vector tags3 = ann4->data(); - std::vector tags4 = ann4->data(); - - // The first annotator does not receive any tags from the null sink upstream - CPPUNIT_ASSERT_EQUAL(tags0.size(), (size_t)0); - CPPUNIT_ASSERT_EQUAL(tags1.size(), (size_t)8); - - // Make sure the rest all have 12 tags - CPPUNIT_ASSERT_EQUAL(tags2.size(), (size_t)12); - CPPUNIT_ASSERT_EQUAL(tags3.size(), (size_t)12); - CPPUNIT_ASSERT_EQUAL(tags4.size(), (size_t)12); + std::cout << std::endl << "qa_block_tags::t2" << std::endl; // For annotator[2-4], we know it gets tags from ann0 and ann1 // but the tags from the different outputs of ann1 are different for each. @@ -235,24 +245,21 @@ qa_block_tags::t2 () // inconceivable for ann3 to have it wrong. for(size_t i = 0; i < tags2.size(); i++) { std::cout << "tags2[" << i << "] = " << tags2[i] << "\t\t" << expected_tags2[i] << std::endl; - //pmt_equal(tags2[i], expected_tags2[i]) CPPUNIT_ASSERT_EQUAL(pmt_write_string(tags2[i]), pmt_write_string(expected_tags2[i])); } std::cout << std::endl; for(size_t i = 0; i < tags4.size(); i++) { std::cout << "tags2[" << i << "] = " << tags4[i] << "\t\t" << expected_tags4[i] << std::endl; - //pmt_equal(tags4[i], expected_tags4[i]) CPPUNIT_ASSERT_EQUAL(pmt_write_string(tags4[i]), pmt_write_string(expected_tags4[i])); } +#endif } void qa_block_tags::t3 () { - printf("\nqa_block_tags::t3\n"); - int N = 40000; gr_top_block_sptr tb = gr_make_top_block("top"); gr_block_sptr src (gr_make_null_source(sizeof(int))); @@ -279,6 +286,17 @@ qa_block_tags::t3 () tb->run(); + + std::vector tags0 = ann0->data(); + std::vector tags3 = ann3->data(); + std::vector tags4 = ann4->data(); + + // The first annotator does not receive any tags from the null sink upstream + CPPUNIT_ASSERT_EQUAL(tags0.size(), (size_t)0); + CPPUNIT_ASSERT_EQUAL(tags3.size(), (size_t)8); + CPPUNIT_ASSERT_EQUAL(tags4.size(), (size_t)8); + +#if QA_TAGS_DEBUG // Kludge together the tags that we know should result from the above graph std::stringstream str0, str1, str2; str0 << ann0->name() << ann0->unique_id(); @@ -304,37 +322,28 @@ qa_block_tags::t3 () expected_tags4[5] = mp(pmt_from_uint64(20000), mp(str0.str()), mp("seq"), mp(5)); expected_tags4[6] = mp(pmt_from_uint64(30000), mp(str2.str()), mp("seq"), mp(3)); expected_tags4[7] = mp(pmt_from_uint64(30000), mp(str0.str()), mp("seq"), mp(7)); - - std::vector tags0 = ann0->data(); - std::vector tags3 = ann3->data(); - std::vector tags4 = ann4->data(); - - // The first annotator does not receive any tags from the null sink upstream - CPPUNIT_ASSERT_EQUAL(tags0.size(), (size_t)0); + std::cout << std::endl << "qa_block_tags::t3" << std::endl; + // For annotator 3, we know it gets tags from ann0 and ann1, test this - CPPUNIT_ASSERT_EQUAL(tags3.size(), (size_t)8); for(size_t i = 0; i < tags3.size(); i++) { std::cout << "tags3[" << i << "] = " << tags3[i] << "\t\t" << expected_tags3[i] << std::endl; - //pmt_equal(tags3[i], expected_tags3[i]) CPPUNIT_ASSERT_EQUAL(pmt_write_string(tags3[i]), pmt_write_string(expected_tags3[i])); } // For annotator 4, we know it gets tags from ann0 and ann2, test this std::cout << std::endl; - CPPUNIT_ASSERT_EQUAL(tags4.size(), (size_t)8); for(size_t i = 0; i < tags4.size(); i++) { std::cout << "tags4[" << i << "] = " << tags4[i] << "\t\t" << expected_tags4[i] << std::endl; CPPUNIT_ASSERT_EQUAL(pmt_write_string(tags4[i]), pmt_write_string(expected_tags4[i])); } +#endif } void qa_block_tags::t4 () { - printf("\nqa_block_tags::t4\n"); - int N = 40000; gr_top_block_sptr tb = gr_make_top_block("top"); gr_block_sptr src (gr_make_null_source(sizeof(int))); @@ -354,6 +363,9 @@ qa_block_tags::t4 () tb->connect(ann1, 0, snk0, 0); tb->connect(ann2, 0, snk1, 0); + std::cerr << std::endl + << "NOTE: This is supposed to produce an error from gr_block_executor" + << std::endl; tb->run(); } @@ -361,16 +373,13 @@ qa_block_tags::t4 () void qa_block_tags::t5 () { - printf("\nqa_block_tags::t5\n"); - int N = 40000; gr_top_block_sptr tb = gr_make_top_block("top"); gr_block_sptr src (gr_make_null_source(sizeof(float))); gr_block_sptr head (gr_make_head(sizeof(float), N)); gr_annotator_alltoall_sptr ann0 (gr_make_annotator_alltoall(10000, sizeof(float))); - gr_annotator_alltoall_sptr ann1 (gr_make_annotator_alltoall(10000, sizeof(float))); + gr_annotator_alltoall_sptr ann1 (gr_make_annotator_alltoall(10000, sizeof(float))); gr_annotator_alltoall_sptr ann2 (gr_make_annotator_alltoall(1000, sizeof(float))); - gr_annotator_alltoall_sptr ann3 (gr_make_annotator_alltoall(2000, sizeof(float))); gr_block_sptr snk0 (gr_make_null_sink(sizeof(float))); // Rate change blocks @@ -385,6 +394,17 @@ qa_block_tags::t5 () tb->run(); + std::vector tags0 = ann0->data(); + std::vector tags1 = ann1->data(); + std::vector tags2 = ann2->data(); + + // The first annotator does not receive any tags from the null sink upstream + CPPUNIT_ASSERT_EQUAL(tags0.size(), (size_t)0); + CPPUNIT_ASSERT_EQUAL(tags1.size(), (size_t)4); + CPPUNIT_ASSERT_EQUAL(tags2.size(), (size_t)8); + + +#if QA_TAGS_DEBUG // Kludge together the tags that we know should result from the above graph std::stringstream str0, str1, str2; str0 << ann0->name() << ann0->unique_id(); @@ -409,29 +429,22 @@ qa_block_tags::t5 () expected_tags2[8] = mp(pmt_from_uint64(4000), mp(str1.str()), mp("seq"), mp(4)); expected_tags2[9] = mp(pmt_from_uint64(4000), mp(str0.str()), mp("seq"), mp(4)); - std::vector tags0 = ann0->data(); - std::vector tags1 = ann1->data(); - std::vector tags2 = ann2->data(); - - // The first annotator does not receive any tags from the null sink upstream - CPPUNIT_ASSERT_EQUAL(tags0.size(), (size_t)0); + std::cout << std::endl << "qa_block_tags::t5" << std::endl; // annotator 1 gets tags from annotator 0 std::cout << "tags1.size(): " << tags1.size() << std::endl; - CPPUNIT_ASSERT_EQUAL(tags1.size(), (size_t)4); for(size_t i = 0; i < tags1.size(); i++) { std::cout << "tags1[" << i << "] = " << tags1[i] << "\t\t" << expected_tags1[i] << std::endl; - //pmt_equal(tags1[i], expected_tags1[i]) CPPUNIT_ASSERT_EQUAL(pmt_write_string(tags1[i]), pmt_write_string(expected_tags1[i])); } // annotator 2 gets tags from annotators 0 and 1 std::cout << std::endl; std::cout << "tags2.size(): " << tags2.size() << std::endl; - CPPUNIT_ASSERT_EQUAL(tags2.size(), (size_t)8); for(size_t i = 0; i < tags2.size(); i++) { std::cout << "tags2[" << i << "] = " << tags2[i] << "\t\t" << expected_tags2[i] << std::endl; CPPUNIT_ASSERT_EQUAL(pmt_write_string(tags2[i]), pmt_write_string(expected_tags2[i])); } +#endif } -- cgit From 82f2222a58e83971308c9caaaae026f396b3e9fe Mon Sep 17 00:00:00 2001 From: Eric Blossom Date: Tue, 30 Nov 2010 17:18:22 -0800 Subject: Remove generated file from repo --- .../lib/filter/gri_fir_filter_with_buffer_ccf.h | 131 --------------------- 1 file changed, 131 deletions(-) delete mode 100644 gnuradio-core/src/lib/filter/gri_fir_filter_with_buffer_ccf.h (limited to 'gnuradio-core/src') diff --git a/gnuradio-core/src/lib/filter/gri_fir_filter_with_buffer_ccf.h b/gnuradio-core/src/lib/filter/gri_fir_filter_with_buffer_ccf.h deleted file mode 100644 index bd7fa33cf..000000000 --- a/gnuradio-core/src/lib/filter/gri_fir_filter_with_buffer_ccf.h +++ /dev/null @@ -1,131 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2010 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3, or (at your option) - * any later version. - * - * GNU Radio is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - */ - -/* - * WARNING: This file is automatically generated by generate_gri_fir_XXX.py - * Any changes made to this file will be overwritten. - */ - - -#ifndef INCLUDED_GRI_FIR_FILTER_WITH_BUFFER_CCF_H -#define INCLUDED_GRI_FIR_FILTER_WITH_BUFFER_CCF_H - -#include -#include -#include -#include -#include - -/*! - * \brief FIR with internal buffer for gr_complex input, - gr_complex output and float taps - * \ingroup filter - * - */ - -class gri_fir_filter_with_buffer_ccf { - -protected: - std::vector d_taps; // reversed taps - gr_complex *d_buffer; - unsigned int d_idx; - -public: - - // CONSTRUCTORS - - /*! - * \brief construct new FIR with given taps. - * - * Note that taps must be in forward order, e.g., coefficient 0 is - * stored in new_taps[0], coefficient 1 is stored in - * new_taps[1], etc. - */ - gri_fir_filter_with_buffer_ccf (const std::vector &taps); - - ~gri_fir_filter_with_buffer_ccf (); - - // MANIPULATORS - - /*! - * \brief compute a single output value. - * - * \p input is a single input value of the filter type - * - * \returns the filtered input value. - */ - gr_complex filter (gr_complex input); - - - /*! - * \brief compute a single output value; designed for decimating filters. - * - * \p input is a single input value of the filter type. The value of dec is the - * decimating value of the filter, so input[] must have dec valid values. - * The filter pushes dec number of items onto the circ. buffer before computing - * a single output. - * - * \returns the filtered input value. - */ - gr_complex filter (const gr_complex input[], unsigned long dec); - - /*! - * \brief compute an array of N output values. - * - * \p input must have (n - 1 + ntaps()) valid entries. - * input[0] .. input[n - 1 + ntaps() - 1] are referenced to compute the output values. - */ - void filterN (gr_complex output[], const gr_complex input[], - unsigned long n); - - /*! - * \brief compute an array of N output values, decimating the input - * - * \p input must have (decimate * (n - 1) + ntaps()) valid entries. - * input[0] .. input[decimate * (n - 1) + ntaps() - 1] are referenced to - * compute the output values. - */ - void filterNdec (gr_complex output[], const gr_complex input[], - unsigned long n, unsigned long decimate); - - /*! - * \brief install \p new_taps as the current taps. - */ - void set_taps (const std::vector &taps); - - // ACCESSORS - - /*! - * \return number of taps in filter. - */ - unsigned ntaps () const { return d_taps.size (); } - - /*! - * \return current taps - */ - const std::vector get_taps () const - { - return gr_reverse(d_taps); - } -}; - -#endif /* INCLUDED_GRI_FIR_FILTER_WITH_BUFFER_CCF_H */ -- cgit From 6246efbefcdb6807daa7c245ebe7a975ab0ce7d4 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Mon, 6 Dec 2010 13:52:55 -0500 Subject: Modifying blsk2 wrapper for PFB arbitrary resampler to allow the user to just specify the requested resampling rate without providing their own filter taps. Taps are then generated inside hier_block2 to cover full bandwidth of input signal. Optional attenuation parameter may be provided. --- .../src/python/gnuradio/blks2impl/pfb_arb_resampler.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'gnuradio-core/src') diff --git a/gnuradio-core/src/python/gnuradio/blks2impl/pfb_arb_resampler.py b/gnuradio-core/src/python/gnuradio/blks2impl/pfb_arb_resampler.py index e40d9636a..cd9289fa5 100644 --- a/gnuradio-core/src/python/gnuradio/blks2impl/pfb_arb_resampler.py +++ b/gnuradio-core/src/python/gnuradio/blks2impl/pfb_arb_resampler.py @@ -31,15 +31,22 @@ class pfb_arb_resampler_ccf(gr.hier_block2): streams. This block is provided to be consistent with the interface to the other PFB block. ''' - def __init__(self, rate, taps, flt_size=32): + def __init__(self, rate, taps=None, flt_size=32, atten=80): gr.hier_block2.__init__(self, "pfb_arb_resampler_ccf", gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature gr.io_signature(1, 1, gr.sizeof_gr_complex)) # Output signature self._rate = rate - self._taps = taps self._size = flt_size + if taps is not None: + self._taps = taps + else: + # Create a filter that covers the full bandwidth of the input signal + bw = 0.5 + tb = 0.1 + self._taps = gr.firdes.low_pass_2(self._size, self._size, bw, tb, atten) + self.pfb = gr.pfb_arb_resampler_ccf(self._rate, self._taps, self._size) self.connect(self, self.pfb) -- cgit