From 403103de15cc60e73d38b56cbc16004123eeeda1 Mon Sep 17 00:00:00 2001 From: Tim O'Shea Date: Tue, 12 Jun 2012 17:36:34 -0400 Subject: new block, gr_annotator_raw allows passing a raw pmt k->v pair from outside the flowgraph/python in at exact samples also added GRUEL autogenerated .i files to gnuradio-core-swig include line --- gnuradio-core/src/lib/general/CMakeLists.txt | 1 + gnuradio-core/src/lib/general/general.i | 2 + gnuradio-core/src/lib/general/gr_annotator_raw.cc | 96 +++++++++++++++++++++++ gnuradio-core/src/lib/general/gr_annotator_raw.h | 69 ++++++++++++++++ gnuradio-core/src/lib/general/gr_annotator_raw.i | 26 ++++++ 5 files changed, 194 insertions(+) create mode 100644 gnuradio-core/src/lib/general/gr_annotator_raw.cc create mode 100644 gnuradio-core/src/lib/general/gr_annotator_raw.h create mode 100644 gnuradio-core/src/lib/general/gr_annotator_raw.i (limited to 'gnuradio-core/src/lib/general') diff --git a/gnuradio-core/src/lib/general/CMakeLists.txt b/gnuradio-core/src/lib/general/CMakeLists.txt index ab9b870aa..3492d5d6f 100644 --- a/gnuradio-core/src/lib/general/CMakeLists.txt +++ b/gnuradio-core/src/lib/general/CMakeLists.txt @@ -292,6 +292,7 @@ set(gr_core_general_triple_threats gr_probe_density_b gr_annotator_alltoall gr_annotator_1to1 + gr_annotator_raw gr_burst_tagger gr_correlate_access_code_tag_bb ) diff --git a/gnuradio-core/src/lib/general/general.i b/gnuradio-core/src/lib/general/general.i index 0696addbd..fe2cbdb82 100644 --- a/gnuradio-core/src/lib/general/general.i +++ b/gnuradio-core/src/lib/general/general.i @@ -135,6 +135,7 @@ #include #include #include +#include #include #include #include @@ -255,6 +256,7 @@ %include "complex_vec_test.i" %include "gr_annotator_alltoall.i" %include "gr_annotator_1to1.i" +%include "gr_annotator_raw.i" %include "gr_burst_tagger.i" %include "gr_cpm.i" %include "gr_correlate_access_code_tag_bb.i" diff --git a/gnuradio-core/src/lib/general/gr_annotator_raw.cc b/gnuradio-core/src/lib/general/gr_annotator_raw.cc new file mode 100644 index 000000000..7aa8714c4 --- /dev/null +++ b/gnuradio-core/src/lib/general/gr_annotator_raw.cc @@ -0,0 +1,96 @@ +/* -*- 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_raw_sptr +gr_make_annotator_raw ( size_t 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)), + 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 ){ + 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)); +} + + +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) +{ + const char *in = (const char*)input_items[0]; + char *out = (char*)output_items[0]; + + uint64_t start_N = nitems_read(0); + uint64_t end_N = start_N + (uint64_t)(noutput_items); + + // locate queued tags that fall in this range and insert them when appropriate + std::vector::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; + } + } + + // copy data across + memcpy(out, in, noutput_items*d_itemsize); + return noutput_items; +} diff --git a/gnuradio-core/src/lib/general/gr_annotator_raw.h b/gnuradio-core/src/lib/general/gr_annotator_raw.h new file mode 100644 index 000000000..0da27daec --- /dev/null +++ b/gnuradio-core/src/lib/general/gr_annotator_raw.h @@ -0,0 +1,69 @@ +/* -*- 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_RAW_H +#define INCLUDED_GR_ANNOTATOR_RAW_H + +#include +#include +#include + +class gr_annotator_raw; +typedef boost::shared_ptr 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; + +/*! + * \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. + * + * This block is intended for testing of tag related blocks + */ +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); + + // 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); + + private: + size_t d_itemsize; + std::vector d_queued_tags; + + friend GR_CORE_API gr_annotator_raw_sptr + gr_make_annotator_raw (size_t sizeof_stream_item); +}; + +#endif diff --git a/gnuradio-core/src/lib/general/gr_annotator_raw.i b/gnuradio-core/src/lib/general/gr_annotator_raw.i new file mode 100644 index 000000000..85777ef5d --- /dev/null +++ b/gnuradio-core/src/lib/general/gr_annotator_raw.i @@ -0,0 +1,26 @@ +/* -*- c++ -*- */ +/* + * Copyright 2010-2011 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_raw); + +%include +%include -- cgit From 07d2fbf97ba715b339c182185147567e329fc8c8 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Wed, 13 Jun 2012 11:05:42 -0400 Subject: core: modifications to gr_annotator_raw. Using mutex to make add_tag and work thread safe. Throwing exception intead of asserting on error. --- gnuradio-core/src/lib/general/gr_annotator_raw.cc | 70 +++++++++++++---------- gnuradio-core/src/lib/general/gr_annotator_raw.h | 24 ++++---- 2 files changed, 52 insertions(+), 42 deletions(-) (limited to 'gnuradio-core/src/lib/general') 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 #include #include +#include + +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::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 #include #include +#include class gr_annotator_raw; typedef boost::shared_ptr 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 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 -- cgit From 9b2855a4d868731a2d4a1eb03b12d5c930c5c6d0 Mon Sep 17 00:00:00 2001 From: Chí-Thanh Christopher Nguyễn Date: Sat, 16 Jun 2012 17:34:19 -0400 Subject: cmake: add support for SYSCONFDIR Set with 'cmake -DSYSCONFDIR=target ...' This fixes http://gnuradio.org/redmine/issues/492 --- gnuradio-core/src/lib/general/CMakeLists.txt | 3 --- 1 file changed, 3 deletions(-) (limited to 'gnuradio-core/src/lib/general') diff --git a/gnuradio-core/src/lib/general/CMakeLists.txt b/gnuradio-core/src/lib/general/CMakeLists.txt index 3492d5d6f..399e07599 100644 --- a/gnuradio-core/src/lib/general/CMakeLists.txt +++ b/gnuradio-core/src/lib/general/CMakeLists.txt @@ -48,9 +48,6 @@ message(STATUS "Loading build date ${BUILD_DATE} into gr_constants...") message(STATUS "Loading version ${VERSION} into gr_constants...") -file(TO_NATIVE_PATH "${CMAKE_INSTALL_PREFIX}/${GR_CONF_DIR}" SYSCONFDIR) -file(TO_NATIVE_PATH "${CMAKE_INSTALL_PREFIX}/${GR_PKG_CONF_DIR}" GR_PREFSDIR) - #double escape for windows backslash path separators string(REPLACE "\\" "\\\\" prefix ${prefix}) string(REPLACE "\\" "\\\\" SYSCONFDIR ${SYSCONFDIR}) -- cgit