summaryrefslogtreecommitdiff
path: root/gnuradio-core/src
diff options
context:
space:
mode:
Diffstat (limited to 'gnuradio-core/src')
-rw-r--r--gnuradio-core/src/lib/general/gr_annotator_1to1.cc69
-rw-r--r--gnuradio-core/src/lib/general/gr_annotator_1to1.h42
-rw-r--r--gnuradio-core/src/lib/general/gr_annotator_1to1.i11
-rw-r--r--gnuradio-core/src/lib/general/gr_annotator_1toall.cc2
-rw-r--r--gnuradio-core/src/lib/general/gr_annotator_1toall.i4
-rw-r--r--gnuradio-core/src/lib/runtime/qa_block_tags.cc58
-rw-r--r--gnuradio-core/src/lib/runtime/qa_block_tags.h2
7 files changed, 132 insertions, 56 deletions
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 <iomanip>
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<pmt::pmt_t> all_tags = get_tags_in_range(0, (uint64_t)0, abs_N);
- std::vector<pmt::pmt_t>::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<pmt::pmt_t> all_tags = get_tags_in_range(0, abs_N, abs_N + noutput_items);
+ std::vector<pmt::pmt_t>::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 <gr_sync_block.h>
+#include <gr_block.h>
class gr_annotator_1to1;
typedef boost::shared_ptr<gr_annotator_1to1> 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<pmt::pmt_t> 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<pmt::pmt_t> 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<pmt::pmt_t> 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<pmt::pmt_t> all_tags = get_tags_in_range(0, abs_N, abs_N + noutput_items);
- std::vector<pmt::pmt_t>::iterator itr;
+ std::vector<pmt::pmt_t>::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<pmt::pmt_t> 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<pmt::pmt_t> tags0 = ann0->data();
+ std::vector<pmt::pmt_t> tags3 = ann3->data();
+ std::vector<pmt::pmt_t> 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: