summaryrefslogtreecommitdiff
path: root/gnuradio-core/src/lib/general
diff options
context:
space:
mode:
Diffstat (limited to 'gnuradio-core/src/lib/general')
-rw-r--r--gnuradio-core/src/lib/general/gr_annotator_1toall.cc66
-rw-r--r--gnuradio-core/src/lib/general/gr_annotator_1toall.h42
-rw-r--r--gnuradio-core/src/lib/general/gr_annotator_1toall.i11
3 files changed, 74 insertions, 45 deletions
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 <iomanip>
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<pmt::pmt_t> all_tags = get_tags_in_range(0, (uint64_t)0, abs_N);
+ 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;
- 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 <gr_sync_block.h>
+#include <gr_block.h>
class gr_annotator_1toall;
typedef boost::shared_ptr<gr_annotator_1toall> 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<pmt::pmt_t> 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<pmt::pmt_t> 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<pmt::pmt_t> data() const;
+
private:
- gr_annotator_1toall (size_t sizeof_stream_item);
+ gr_annotator_1toall (size_t sizeof_stream_item, float rel_rate);
};