diff options
Diffstat (limited to 'gnuradio-core/src/lib/general')
-rw-r--r-- | gnuradio-core/src/lib/general/gr_annotator_raw.cc | 70 | ||||
-rw-r--r-- | gnuradio-core/src/lib/general/gr_annotator_raw.h | 24 | ||||
-rw-r--r-- | gnuradio-core/src/lib/general/gr_keep_m_in_n.cc | 49 | ||||
-rw-r--r-- | gnuradio-core/src/lib/general/gr_keep_m_in_n.h | 2 | ||||
-rw-r--r-- | gnuradio-core/src/lib/general/gr_keep_m_in_n.i | 2 | ||||
-rw-r--r-- | gnuradio-core/src/lib/general/gr_pack_k_bits_bb.cc | 34 | ||||
-rw-r--r-- | gnuradio-core/src/lib/general/gr_pack_k_bits_bb.h | 2 |
7 files changed, 98 insertions, 85 deletions
diff --git a/gnuradio-core/src/lib/general/gr_annotator_raw.cc b/gnuradio-core/src/lib/general/gr_annotator_raw.cc index 7aa8714c4..074c09173 100644 --- a/gnuradio-core/src/lib/general/gr_annotator_raw.cc +++ b/gnuradio-core/src/lib/general/gr_annotator_raw.cc @@ -29,50 +29,59 @@ #include <string.h> #include <iostream> #include <iomanip> +#include <stdexcept> + +using namespace pmt; gr_annotator_raw_sptr -gr_make_annotator_raw ( size_t sizeof_stream_item) +gr_make_annotator_raw(size_t sizeof_stream_item) { - return gnuradio::get_initial_sptr (new gr_annotator_raw - (sizeof_stream_item)); + return gnuradio::get_initial_sptr(new gr_annotator_raw + (sizeof_stream_item)); } -gr_annotator_raw::gr_annotator_raw (size_t sizeof_stream_item) - : gr_sync_block ("annotator_raw", - gr_make_io_signature (1, 1, sizeof_stream_item), - gr_make_io_signature (1, 1, sizeof_stream_item)), +gr_annotator_raw::gr_annotator_raw(size_t sizeof_stream_item) + : gr_sync_block("annotator_raw", + 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); set_relative_rate(1.0); } +void gr_annotator_raw::add_tag(uint64_t offset, pmt_t key, pmt_t val) +{ + gruel::scoped_lock l(d_mutex); -void gr_annotator_raw::add_tag( uint64_t offset, pmt_t key, pmt_t val ){ - gr_tag_t tag; - tag.srcid = pmt::pmt_intern(d_name); - tag.key = key; - tag.value = val; - tag.offset = offset; + gr_tag_t tag; + tag.srcid = pmt::pmt_intern(d_name); + tag.key = key; + tag.value = val; + tag.offset = offset; - // add our new tag - d_queued_tags.push_back( tag ); - // make sure our tags are in offset order - std::sort(d_queued_tags.begin(), d_queued_tags.end(), gr_tag_t::offset_compare); - // make sure we are not adding an item in the past! - assert(tag->offset >= nitems_read(0)); + // add our new tag + d_queued_tags.push_back(tag); + // make sure our tags are in offset order + std::sort(d_queued_tags.begin(), d_queued_tags.end(), + gr_tag_t::offset_compare); + // make sure we are not adding an item in the past! + if(tag.offset >= nitems_read(0)) { + throw std::runtime_error("gr_annotator_raw::add_tag: item added too far in the past\n."); + } } - -gr_annotator_raw::~gr_annotator_raw () +gr_annotator_raw::~gr_annotator_raw() { } int -gr_annotator_raw::work (int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) +gr_annotator_raw::work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) { + gruel::scoped_lock l(d_mutex); + const char *in = (const char*)input_items[0]; char *out = (char*)output_items[0]; @@ -81,12 +90,13 @@ gr_annotator_raw::work (int noutput_items, // locate queued tags that fall in this range and insert them when appropriate std::vector<gr_tag_t>::iterator i = d_queued_tags.begin(); - while( i != d_queued_tags.end() ){ - if( (*i).offset >= start_N && (*i).offset < end_N){ - add_item_tag(0, (*i).offset,(*i).key, (*i).value, (*i).srcid); - i = d_queued_tags.erase(i); - } else { - break; + while( i != d_queued_tags.end() ) { + if( (*i).offset >= start_N && (*i).offset < end_N) { + add_item_tag(0, (*i).offset,(*i).key, (*i).value, (*i).srcid); + i = d_queued_tags.erase(i); + } + else { + break; } } diff --git a/gnuradio-core/src/lib/general/gr_annotator_raw.h b/gnuradio-core/src/lib/general/gr_annotator_raw.h index 0da27daec..8a6c3f6c0 100644 --- a/gnuradio-core/src/lib/general/gr_annotator_raw.h +++ b/gnuradio-core/src/lib/general/gr_annotator_raw.h @@ -26,18 +26,17 @@ #include <gr_core_api.h> #include <gr_sync_block.h> #include <gruel/pmt.h> +#include <gruel/thread.h> class gr_annotator_raw; typedef boost::shared_ptr<gr_annotator_raw> gr_annotator_raw_sptr; // public constructor GR_CORE_API gr_annotator_raw_sptr -gr_make_annotator_raw (size_t sizeof_stream_item); - -using namespace pmt; +gr_make_annotator_raw(size_t sizeof_stream_item); /*! - * \brief raw stream annotator testing block. + * \brief raw stream annotator testing block. * * This block creates arbitrary tags to be sent downstream * blocks to be sent are set manually via accessor methods and are sent only once. @@ -47,23 +46,24 @@ using namespace pmt; class GR_CORE_API gr_annotator_raw : public gr_sync_block { public: - ~gr_annotator_raw (); - int work (int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); + ~gr_annotator_raw(); + int work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); - // insert a tag to be added - void add_tag( uint64_t offset, pmt::pmt_t key, pmt::pmt_t val ); + // insert a tag to be added + void add_tag(uint64_t offset, pmt::pmt_t key, pmt::pmt_t val); protected: - gr_annotator_raw (size_t sizeof_stream_item); + gr_annotator_raw(size_t sizeof_stream_item); private: size_t d_itemsize; std::vector<gr_tag_t> d_queued_tags; + gruel::mutex d_mutex; friend GR_CORE_API gr_annotator_raw_sptr - gr_make_annotator_raw (size_t sizeof_stream_item); + gr_make_annotator_raw(size_t sizeof_stream_item); }; #endif diff --git a/gnuradio-core/src/lib/general/gr_keep_m_in_n.cc b/gnuradio-core/src/lib/general/gr_keep_m_in_n.cc index a9f4c12ba..0da69a126 100644 --- a/gnuradio-core/src/lib/general/gr_keep_m_in_n.cc +++ b/gnuradio-core/src/lib/general/gr_keep_m_in_n.cc @@ -30,9 +30,9 @@ #include <stdio.h> gr_keep_m_in_n_sptr -gr_make_keep_m_in_n (size_t item_size, int m, int n, int offset) +gr_make_keep_m_in_n(size_t item_size, int m, int n, int offset) { - return gnuradio::get_initial_sptr(new gr_keep_m_in_n (item_size, m, n, offset)); + return gnuradio::get_initial_sptr(new gr_keep_m_in_n(item_size, m, n, offset)); } @@ -40,17 +40,17 @@ gr_make_keep_m_in_n (size_t item_size, int m, int n, int offset) * * offset = 0, starts with 0th item * offset = 1, starts with 1st item, etc... -* +* * we take m items out of each n */ -gr_keep_m_in_n::gr_keep_m_in_n (size_t item_size, int m, int n, int offset) - : gr_block ("keep_m_in_n", - gr_make_io_signature (1, 1, item_size), - gr_make_io_signature (1, 1, item_size)), +gr_keep_m_in_n::gr_keep_m_in_n(size_t item_size, int m, int n, int offset) + : gr_block("keep_m_in_n", + gr_make_io_signature(1, 1, item_size), + gr_make_io_signature(1, 1, item_size)), d_n(n), d_m(m), - d_offset( offset ), - d_itemsize( item_size ) + d_offset(offset), + d_itemsize(item_size) { // sanity checking assert(d_m > 0); @@ -62,33 +62,36 @@ gr_keep_m_in_n::gr_keep_m_in_n (size_t item_size, int m, int n, int offset) } -void gr_keep_m_in_n::forecast (int noutput_items, gr_vector_int &ninput_items_required){ - ninput_items_required[0] = d_n*(noutput_items/d_m); +void +gr_keep_m_in_n::forecast(int noutput_items, gr_vector_int &ninput_items_required) +{ + ninput_items_required[0] = d_n*(noutput_items/d_m); } -void gr_keep_m_in_n::set_offset(int offset){ - d_offset = offset; +void +gr_keep_m_in_n::set_offset(int offset) +{ + d_offset = offset; } - int -gr_keep_m_in_n::general_work (int noutput_items, - gr_vector_int &ninput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) +gr_keep_m_in_n::general_work(int noutput_items, + gr_vector_int &ninput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) { - uint8_t* out = (uint8_t*) output_items[0]; - const uint8_t* in = (const uint8_t*) input_items[0]; + uint8_t* out = (uint8_t*)output_items[0]; + const uint8_t* in = (const uint8_t*)input_items[0]; // iterate over data blocks of size {n, input : m, output} - int blks = std::min( noutput_items/d_m, ninput_items[0]/d_n ); - for(int i=0; i<blks; i++){ + int blks = std::min(noutput_items/d_m, ninput_items[0]/d_n); + for(int i=0; i<blks; i++) { // set up copy pointers const uint8_t* iptr = &in[(i*d_n + d_offset)*d_itemsize]; uint8_t* optr = &out[i*d_m*d_itemsize]; // perform copy memcpy( optr, iptr, d_m*d_itemsize ); - } + } consume_each(d_n); return d_m; diff --git a/gnuradio-core/src/lib/general/gr_keep_m_in_n.h b/gnuradio-core/src/lib/general/gr_keep_m_in_n.h index 22fbd2f4c..711c704f5 100644 --- a/gnuradio-core/src/lib/general/gr_keep_m_in_n.h +++ b/gnuradio-core/src/lib/general/gr_keep_m_in_n.h @@ -29,7 +29,7 @@ class gr_keep_m_in_n; typedef boost::shared_ptr<gr_keep_m_in_n> gr_keep_m_in_n_sptr; -GR_CORE_API gr_keep_m_in_n_sptr +GR_CORE_API gr_keep_m_in_n_sptr gr_make_keep_m_in_n (size_t item_size, int m, int n, int offset); diff --git a/gnuradio-core/src/lib/general/gr_keep_m_in_n.i b/gnuradio-core/src/lib/general/gr_keep_m_in_n.i index cb5c63683..de89cec2c 100644 --- a/gnuradio-core/src/lib/general/gr_keep_m_in_n.i +++ b/gnuradio-core/src/lib/general/gr_keep_m_in_n.i @@ -22,7 +22,7 @@ GR_SWIG_BLOCK_MAGIC(gr,keep_m_in_n) -gr_keep_m_in_n_sptr +gr_keep_m_in_n_sptr gr_make_keep_m_in_n (size_t itemsize, int m, int n, int offset); class gr_keep_m_in_n : public gr_sync_block diff --git a/gnuradio-core/src/lib/general/gr_pack_k_bits_bb.cc b/gnuradio-core/src/lib/general/gr_pack_k_bits_bb.cc index fc7e689fe..0a366a4cc 100644 --- a/gnuradio-core/src/lib/general/gr_pack_k_bits_bb.cc +++ b/gnuradio-core/src/lib/general/gr_pack_k_bits_bb.cc @@ -29,41 +29,41 @@ #include <stdexcept> #include <iostream> -gr_pack_k_bits_bb_sptr gr_make_pack_k_bits_bb (unsigned k) +gr_pack_k_bits_bb_sptr gr_make_pack_k_bits_bb(unsigned k) { - return gnuradio::get_initial_sptr(new gr_pack_k_bits_bb (k)); + return gnuradio::get_initial_sptr(new gr_pack_k_bits_bb(k)); } gr_pack_k_bits_bb::gr_pack_k_bits_bb (unsigned k) - : gr_sync_decimator ("pack_k_bits_bb", - gr_make_io_signature (1, 1, sizeof (unsigned char)), - gr_make_io_signature (1, 1, sizeof (unsigned char)), - k), + : gr_sync_decimator("pack_k_bits_bb", + gr_make_io_signature (1, 1, sizeof(unsigned char)), + gr_make_io_signature (1, 1, sizeof(unsigned char)), + k), d_k (k) { if (d_k == 0) - throw std::out_of_range ("interpolation must be > 0"); + throw std::out_of_range("interpolation must be > 0"); } -gr_pack_k_bits_bb::~gr_pack_k_bits_bb () +gr_pack_k_bits_bb::~gr_pack_k_bits_bb() { } int -gr_pack_k_bits_bb::work (int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) +gr_pack_k_bits_bb::work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) { - const unsigned char *in = (const unsigned char *) input_items[0]; - unsigned char *out = (unsigned char *) output_items[0]; + const unsigned char *in = (const unsigned char *)input_items[0]; + unsigned char *out = (unsigned char *)output_items[0]; - for (int i = 0; i < noutput_items; i++){ + for(int i = 0; i < noutput_items; i++) { out[i] = 0x00; - for (unsigned int j = 0; j < d_k; j++){ - out[i] |= (0x01 & in[i*d_k+j])<<(d_k-j-1); + for(unsigned int j = 0; j < d_k; j++) { + out[i] |= (0x01 & in[i*d_k+j])<<(d_k-j-1); } } - + return noutput_items; } diff --git a/gnuradio-core/src/lib/general/gr_pack_k_bits_bb.h b/gnuradio-core/src/lib/general/gr_pack_k_bits_bb.h index 00b8f8f13..caf6d7992 100644 --- a/gnuradio-core/src/lib/general/gr_pack_k_bits_bb.h +++ b/gnuradio-core/src/lib/general/gr_pack_k_bits_bb.h @@ -33,7 +33,7 @@ GR_CORE_API gr_pack_k_bits_bb_sptr gr_make_pack_k_bits_bb (unsigned k); class gr_pack_k_bits_bb; /*! - * \brief Converts a byte with k relevent bits to k output bytes with 1 bit in the LSB. + * \brief Converts a stream of bytes with 1 bit in the LSB to a byte with k relevent bits. * \ingroup converter_blk */ class GR_CORE_API gr_pack_k_bits_bb : public gr_sync_decimator |