summaryrefslogtreecommitdiff
path: root/gnuradio-runtime
diff options
context:
space:
mode:
Diffstat (limited to 'gnuradio-runtime')
-rw-r--r--gnuradio-runtime/include/gnuradio/block.h6
-rw-r--r--gnuradio-runtime/include/gnuradio/buffer.h10
-rw-r--r--gnuradio-runtime/include/pmt/pmt.h10
-rw-r--r--gnuradio-runtime/lib/buffer.cc58
-rw-r--r--gnuradio-runtime/lib/pmt/pmt.cc12
-rw-r--r--gnuradio-runtime/lib/pmt/qa_pmt_prims.cc9
-rw-r--r--gnuradio-runtime/python/gnuradio/gr/tag_utils.py17
-rwxr-xr-xgnuradio-runtime/python/pmt/qa_pmt.py2
-rw-r--r--gnuradio-runtime/swig/pmt_swig.i2
9 files changed, 78 insertions, 48 deletions
diff --git a/gnuradio-runtime/include/gnuradio/block.h b/gnuradio-runtime/include/gnuradio/block.h
index a033e0ac27..43fc50c54b 100644
--- a/gnuradio-runtime/include/gnuradio/block.h
+++ b/gnuradio-runtime/include/gnuradio/block.h
@@ -636,7 +636,7 @@ namespace gr {
void add_item_tag(unsigned int which_output, const tag_t &tag);
/*!
- * \brief Removes a tag from the given input buffer.
+ * \brief DEPRECATED. Will be removed in 3.8.
*
* \param which_input an integer of which input stream to remove the tag from
* \param abs_offset a uint64 number of the absolute item number
@@ -662,9 +662,7 @@ namespace gr {
}
/*!
- * \brief Removes a tag from the given input buffer.
- *
- * If no such tag is found, does nothing.
+ * \brief DEPRECATED. Will be removed in 3.8.
*
* \param which_input an integer of which input stream to remove the tag from
* \param tag the tag object to remove
diff --git a/gnuradio-runtime/include/gnuradio/buffer.h b/gnuradio-runtime/include/gnuradio/buffer.h
index e2d5760e59..c0c9f3d39d 100644
--- a/gnuradio-runtime/include/gnuradio/buffer.h
+++ b/gnuradio-runtime/include/gnuradio/buffer.h
@@ -28,7 +28,7 @@
#include <gnuradio/tags.h>
#include <boost/weak_ptr.hpp>
#include <gnuradio/thread/thread.h>
-#include <deque>
+#include <map>
namespace gr {
@@ -125,8 +125,10 @@ namespace gr {
*/
void prune_tags(uint64_t max_time);
- std::deque<tag_t>::iterator get_tags_begin() { return d_item_tags.begin(); }
- std::deque<tag_t>::iterator get_tags_end() { return d_item_tags.end(); }
+ std::multimap<uint64_t,tag_t>::iterator get_tags_begin() { return d_item_tags.begin(); }
+ std::multimap<uint64_t,tag_t>::iterator get_tags_end() { return d_item_tags.end(); }
+ std::multimap<uint64_t,tag_t>::iterator get_tags_lower_bound(uint64_t x) { return d_item_tags.lower_bound(x); }
+ std::multimap<uint64_t,tag_t>::iterator get_tags_upper_bound(uint64_t x) { return d_item_tags.upper_bound(x); }
// -------------------------------------------------------------------------
@@ -157,7 +159,7 @@ namespace gr {
unsigned int d_write_index; // in items [0,d_bufsize)
uint64_t d_abs_write_offset; // num items written since the start
bool d_done;
- std::deque<tag_t> d_item_tags;
+ std::multimap<uint64_t,tag_t> d_item_tags;
uint64_t d_last_min_items_read;
unsigned index_add(unsigned a, unsigned b)
diff --git a/gnuradio-runtime/include/pmt/pmt.h b/gnuradio-runtime/include/pmt/pmt.h
index 3e17571b23..cb6fdf44d5 100644
--- a/gnuradio-runtime/include/pmt/pmt.h
+++ b/gnuradio-runtime/include/pmt/pmt.h
@@ -201,6 +201,7 @@ PMT_API bool is_real(pmt_t obj);
//! Return the pmt value that represents double \p x.
PMT_API pmt_t from_double(double x);
+PMT_API pmt_t from_float(float x);
/*!
* \brief Convert pmt to double if possible.
@@ -211,6 +212,15 @@ PMT_API pmt_t from_double(double x);
*/
PMT_API double to_double(pmt_t x);
+/*!
+ * \brief Convert pmt to float if possible.
+ *
+ * This basically is to_double() with a type-cast; the PMT stores
+ * the value as a double in any case. Use this when strict typing
+ * is required.
+ */
+PMT_API float to_float(pmt_t x);
+
/*
* ------------------------------------------------------------------------
* Complex
diff --git a/gnuradio-runtime/lib/buffer.cc b/gnuradio-runtime/lib/buffer.cc
index 162324e590..f00e9a04bf 100644
--- a/gnuradio-runtime/lib/buffer.cc
+++ b/gnuradio-runtime/lib/buffer.cc
@@ -23,7 +23,7 @@
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
-
+#include <algorithm>
#include <gnuradio/buffer.h>
#include <gnuradio/math.h>
#include "vmcircbuf.h"
@@ -225,16 +225,16 @@ namespace gr {
buffer::add_item_tag(const tag_t &tag)
{
gr::thread::scoped_lock guard(*mutex());
- d_item_tags.push_back(tag);
+ d_item_tags.insert(std::pair<uint64_t,tag_t>(tag.offset,tag));
}
void
buffer::remove_item_tag(const tag_t &tag, long id)
{
gr::thread::scoped_lock guard(*mutex());
- for(std::deque<tag_t>::iterator it = d_item_tags.begin(); it != d_item_tags.end(); ++it) {
- if(*it == tag) {
- (*it).marked_deleted.push_back(id);
+ for(std::multimap<uint64_t,tag_t>::iterator it = d_item_tags.lower_bound(tag.offset); it != d_item_tags.upper_bound(tag.offset); ++it) {
+ if((*it).second == tag) {
+ (*it).second.marked_deleted.push_back(id);
}
}
}
@@ -250,25 +250,9 @@ namespace gr {
If this function is used elsewhere, remember to lock the
buffer's mutex al la the scoped_lock line below.
*/
- //gr::thread::scoped_lock guard(*mutex());
- std::deque<tag_t>::iterator itr = d_item_tags.begin();
-
- uint64_t item_time;
-
- // Since tags are not guarenteed to be in any particular order, we
- // need to erase here instead of pop_front. An erase in the middle
- // invalidates all iterators; so this resets the iterator to find
- // more. Mostly, we wil be erasing from the front and
- // therefore lose little time this way.
- while(itr != d_item_tags.end()) {
- item_time = (*itr).offset;
- if(item_time+d_max_reader_delay + bufsize() < max_time) {
- d_item_tags.erase(itr);
- itr = d_item_tags.begin();
- }
- else
- itr++;
- }
+ std::multimap<uint64_t, tag_t>::iterator end_itr = d_item_tags.lower_bound(max_time);
+ std::multimap<uint64_t, tag_t>::iterator begin_itr = d_item_tags.begin();
+ d_item_tags.erase(begin_itr, end_itr);
}
long
@@ -333,30 +317,28 @@ namespace gr {
buffer_reader::get_tags_in_range(std::vector<tag_t> &v,
uint64_t abs_start,
uint64_t abs_end,
- long id)
+ long id)
{
gr::thread::scoped_lock guard(*mutex());
v.resize(0);
- std::deque<tag_t>::iterator itr = d_buffer->get_tags_begin();
+ std::multimap<uint64_t,tag_t>::iterator itr = d_buffer->get_tags_lower_bound(abs_start);
+ std::multimap<uint64_t,tag_t>::iterator itr_end = d_buffer->get_tags_upper_bound(abs_end);
uint64_t item_time;
- while(itr != d_buffer->get_tags_end()) {
- item_time = (*itr).offset + d_attr_delay;
-
+ while(itr != itr_end) {
+ item_time = (*itr).second.offset + d_attr_delay;
if((item_time >= abs_start) && (item_time < abs_end)) {
- std::vector<long>::iterator id_itr;
- id_itr = std::find(itr->marked_deleted.begin(), itr->marked_deleted.end(), id);
-
+ std::vector<long>::iterator id_itr;
+ id_itr = std::find(itr->second.marked_deleted.begin(), itr->second.marked_deleted.end(), id);
// If id is not in the vector of marked blocks
- if(id_itr == itr->marked_deleted.end()) {
- tag_t t = *itr;
+ if(id_itr == itr->second.marked_deleted.end()) {
+ tag_t t = (*itr).second;
t.offset += d_attr_delay;
- v.push_back(t);
- v.back().marked_deleted.clear();
- }
+ v.push_back(t);
+ v.back().marked_deleted.clear();
+ }
}
-
itr++;
}
}
diff --git a/gnuradio-runtime/lib/pmt/pmt.cc b/gnuradio-runtime/lib/pmt/pmt.cc
index 082b98a80d..da830e1aed 100644
--- a/gnuradio-runtime/lib/pmt/pmt.cc
+++ b/gnuradio-runtime/lib/pmt/pmt.cc
@@ -368,6 +368,12 @@ from_double(double x)
return pmt_t(new pmt_real(x));
}
+pmt_t
+from_float(float x)
+{
+ return pmt_t(new pmt_real(x));
+}
+
double
to_double(pmt_t x)
{
@@ -379,6 +385,12 @@ to_double(pmt_t x)
throw wrong_type("pmt_to_double", x);
}
+float
+to_float(pmt_t x)
+{
+ return float(to_double(x));
+}
+
////////////////////////////////////////////////////////////////////////////
// Complex
////////////////////////////////////////////////////////////////////////////
diff --git a/gnuradio-runtime/lib/pmt/qa_pmt_prims.cc b/gnuradio-runtime/lib/pmt/qa_pmt_prims.cc
index 2f46b014db..2b3ca32293 100644
--- a/gnuradio-runtime/lib/pmt/qa_pmt_prims.cc
+++ b/gnuradio-runtime/lib/pmt/qa_pmt_prims.cc
@@ -125,6 +125,15 @@ qa_pmt_prims::test_reals()
CPPUNIT_ASSERT_EQUAL(-1.0, pmt::to_double(m1));
CPPUNIT_ASSERT_EQUAL(1.0, pmt::to_double(p1));
CPPUNIT_ASSERT_EQUAL(1.0, pmt::to_double(pmt::from_long(1)));
+
+ pmt::pmt_t p2 = pmt::from_float(1);
+ pmt::pmt_t m2 = pmt::from_float(-1);
+ CPPUNIT_ASSERT(pmt::is_real(p2));
+ CPPUNIT_ASSERT(pmt::is_real(m2));
+ CPPUNIT_ASSERT_THROW(pmt::to_float(pmt::PMT_T), pmt::wrong_type);
+ CPPUNIT_ASSERT_EQUAL(float(-1.0), pmt::to_float(m2));
+ CPPUNIT_ASSERT_EQUAL(float(1.0), pmt::to_float(p2));
+ CPPUNIT_ASSERT_EQUAL(float(1.0), pmt::to_float(pmt::from_long(1)));
}
void
diff --git a/gnuradio-runtime/python/gnuradio/gr/tag_utils.py b/gnuradio-runtime/python/gnuradio/gr/tag_utils.py
index cbca9d44ae..ba46e3f4d9 100644
--- a/gnuradio-runtime/python/gnuradio/gr/tag_utils.py
+++ b/gnuradio-runtime/python/gnuradio/gr/tag_utils.py
@@ -89,9 +89,22 @@ def python_to_tag(tag_struct):
tag.srcid = tag_struct[3]
good = True
+ elif(len(tag_struct) == 3):
+ if(isinstance(tag_struct[0], (int,long))):
+ tag.offset = tag_struct[0]
+ good = True
+
+ if(isinstance(tag_struct[1], pmt.pmt_swig.swig_int_ptr)):
+ tag.key = tag_struct[1]
+ good = True
+
+ if(isinstance(tag_struct[2], pmt.pmt_swig.swig_int_ptr)):
+ tag.value = tag_struct[2]
+ good = True
+
+ tag.srcid = pmt.PMT_F
+
if(good):
return tag
else:
return None
-
-
diff --git a/gnuradio-runtime/python/pmt/qa_pmt.py b/gnuradio-runtime/python/pmt/qa_pmt.py
index 5c1af2c00e..32cff62f44 100755
--- a/gnuradio-runtime/python/pmt/qa_pmt.py
+++ b/gnuradio-runtime/python/pmt/qa_pmt.py
@@ -36,7 +36,9 @@ class test_pmt(unittest.TestCase):
const = 123765
x_pmt = pmt.from_double(const)
x_int = pmt.to_double(x_pmt)
+ x_float = pmt.to_float(x_pmt)
self.assertEqual(x_int, const)
+ self.assertEqual(x_float, const)
def test03(self):
v = pmt.init_f32vector(3, [11, -22, 33])
diff --git a/gnuradio-runtime/swig/pmt_swig.i b/gnuradio-runtime/swig/pmt_swig.i
index e54b544977..c4b678222d 100644
--- a/gnuradio-runtime/swig/pmt_swig.i
+++ b/gnuradio-runtime/swig/pmt_swig.i
@@ -111,6 +111,8 @@ namespace pmt{
bool is_real(pmt_t obj);
pmt_t from_double(double x);
double to_double(pmt_t x);
+ pmt_t from_float(double x);
+ double to_float(pmt_t x);
bool is_complex(pmt_t obj);
pmt_t make_rectangular(double re, double im);