summaryrefslogtreecommitdiff
path: root/gr-blocks/lib
diff options
context:
space:
mode:
Diffstat (limited to 'gr-blocks/lib')
-rw-r--r--gr-blocks/lib/CMakeLists.txt6
-rw-r--r--gr-blocks/lib/exponentiate_const_cci_impl.cc102
-rw-r--r--gr-blocks/lib/exponentiate_const_cci_impl.h53
-rw-r--r--gr-blocks/lib/file_source_impl.cc25
-rw-r--r--gr-blocks/lib/file_source_impl.h7
-rw-r--r--gr-blocks/lib/tag_gate_impl.cc41
-rw-r--r--gr-blocks/lib/tag_gate_impl.h6
-rw-r--r--gr-blocks/lib/tag_share_impl.cc79
-rw-r--r--gr-blocks/lib/tag_share_impl.h51
9 files changed, 362 insertions, 8 deletions
diff --git a/gr-blocks/lib/CMakeLists.txt b/gr-blocks/lib/CMakeLists.txt
index 1d69f27a1d..e6eabd8f99 100644
--- a/gr-blocks/lib/CMakeLists.txt
+++ b/gr-blocks/lib/CMakeLists.txt
@@ -65,7 +65,6 @@ include_directories(
${CMAKE_CURRENT_BINARY_DIR}/../include
${GR_BLOCKS_INCLUDE_DIRS}
${GNURADIO_RUNTIME_INCLUDE_DIRS}
- ${VOLK_INCLUDE_DIRS}
${Boost_INCLUDE_DIRS}
)
@@ -116,6 +115,7 @@ list(APPEND gr_blocks_sources
divide_ff_impl.cc
delay_impl.cc
endian_swap_impl.cc
+ exponentiate_const_cci_impl.cc
file_descriptor_sink_impl.cc
file_descriptor_source_impl.cc
file_sink_impl.cc
@@ -190,6 +190,7 @@ list(APPEND gr_blocks_sources
streams_to_vector_impl.cc
stretch_ff_impl.cc
sub_ff_impl.cc
+ tag_share_impl.cc
tagged_file_sink_impl.cc
tagged_stream_to_pdu_impl.cc
tagged_stream_multiply_length_impl.cc
@@ -251,8 +252,6 @@ list(APPEND blocks_libs
gnuradio-runtime
${VOLK_LIBRARIES}
${Boost_LIBRARIES}
- ${BLOCKS_LIBRARIES}
- ${LOG4CPP_LIBRARIES}
)
add_library(gnuradio-blocks SHARED ${gr_blocks_sources})
@@ -329,7 +328,6 @@ if(ENABLE_TESTING)
gnuradio-blocks
${Boost_LIBRARIES}
${CPPUNIT_LIBRARIES}
- ${LOG4CPP_LIBRARIES}
)
GR_ADD_TEST(test_gr_blocks test-gr-blocks)
diff --git a/gr-blocks/lib/exponentiate_const_cci_impl.cc b/gr-blocks/lib/exponentiate_const_cci_impl.cc
new file mode 100644
index 0000000000..c46930febb
--- /dev/null
+++ b/gr-blocks/lib/exponentiate_const_cci_impl.cc
@@ -0,0 +1,102 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2017 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 <gnuradio/io_signature.h>
+#include "exponentiate_const_cci_impl.h"
+#include <volk/volk.h>
+
+namespace gr {
+ namespace blocks {
+
+ exponentiate_const_cci::sptr
+ exponentiate_const_cci::make(int exponent, size_t vlen)
+ {
+ return gnuradio::get_initial_sptr
+ (new exponentiate_const_cci_impl(exponent, vlen));
+ }
+
+ /*
+ * The private constructor
+ */
+ exponentiate_const_cci_impl::exponentiate_const_cci_impl(int exponent, size_t vlen)
+ : gr::sync_block("exponentiate_const_cci",
+ gr::io_signature::make(1, -1, sizeof(gr_complex)*vlen),
+ gr::io_signature::make(1, -1, sizeof(gr_complex)*vlen)),
+ d_exponent(exponent),
+ d_vlen(vlen)
+ {
+ const int alignment_multiple = volk_get_alignment()/sizeof(gr_complex);
+ set_alignment(std::max(1, alignment_multiple));
+ }
+
+ /*
+ * Our virtual destructor.
+ */
+ exponentiate_const_cci_impl::~exponentiate_const_cci_impl()
+ {
+ }
+
+ bool
+ exponentiate_const_cci_impl::check_topology(int ninputs, int noutputs)
+ {
+ return ninputs == noutputs;
+ }
+
+ void
+ exponentiate_const_cci_impl::set_exponent(int exponent) {
+ gr::thread::scoped_lock guard(d_setlock);
+ d_exponent = exponent;
+ }
+
+ int
+ exponentiate_const_cci_impl::work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+ {
+ gr::thread::scoped_lock guard(d_setlock);
+
+ for(unsigned int i = 0; i < input_items.size(); i++) {
+ const gr_complex *in = (const gr_complex *) input_items[i];
+ gr_complex *out = (gr_complex *) output_items[i];
+
+ if(d_exponent > 1) {
+ volk_32fc_x2_multiply_32fc(out, in, in, noutput_items*d_vlen);
+ for(int j = 2; j < d_exponent; j++) {
+ volk_32fc_x2_multiply_32fc(out, out, in, noutput_items*d_vlen);
+ }
+ }
+ else {
+ memcpy(out, in, sizeof(gr_complex)*noutput_items*d_vlen);
+ }
+ }
+
+ // Tell runtime system how many output items we produced.
+ return noutput_items;
+ }
+
+ } /* namespace blocks */
+} /* namespace gr */
+
diff --git a/gr-blocks/lib/exponentiate_const_cci_impl.h b/gr-blocks/lib/exponentiate_const_cci_impl.h
new file mode 100644
index 0000000000..c89fe57646
--- /dev/null
+++ b/gr-blocks/lib/exponentiate_const_cci_impl.h
@@ -0,0 +1,53 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2017 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_BLOCKS_EXPONENTIATE_CONST_CCI_IMPL_H
+#define INCLUDED_BLOCKS_EXPONENTIATE_CONST_CCI_IMPL_H
+
+#include <gnuradio/blocks/exponentiate_const_cci.h>
+
+namespace gr {
+ namespace blocks {
+
+ class exponentiate_const_cci_impl : public exponentiate_const_cci
+ {
+ private:
+ int d_exponent;
+ int d_vlen;
+
+ public:
+ exponentiate_const_cci_impl(int exponent, size_t vlen);
+ ~exponentiate_const_cci_impl();
+ bool check_topology(int ninputs, int noutputs);
+ void set_exponent(int exponent);
+
+ // Where all the action really happens
+ int work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+ };
+
+ } // namespace blocks
+} // namespace gr
+
+#endif /* INCLUDED_BLOCKS_EXPONENTIATE_CONST_CCI_IMPL_H */
+
diff --git a/gr-blocks/lib/file_source_impl.cc b/gr-blocks/lib/file_source_impl.cc
index cc57a905ed..c077c74fd9 100644
--- a/gr-blocks/lib/file_source_impl.cc
+++ b/gr-blocks/lib/file_source_impl.cc
@@ -64,10 +64,15 @@ namespace gr {
io_signature::make(0, 0, 0),
io_signature::make(1, 1, itemsize)),
d_itemsize(itemsize), d_fp(0), d_new_fp(0), d_repeat(repeat),
- d_updated(false)
+ d_updated(false), d_file_begin(true), d_repeat_cnt(0),
+ d_add_begin_tag(pmt::PMT_NIL)
{
open(filename, repeat);
do_update();
+
+ std::stringstream str;
+ str << name() << unique_id();
+ _id = pmt::string_to_symbol(str.str());
}
file_source_impl::~file_source_impl()
@@ -149,9 +154,16 @@ namespace gr {
d_fp = d_new_fp; // install new file pointer
d_new_fp = 0;
d_updated = false;
+ d_file_begin = true;
}
}
+ void
+ file_source_impl::set_begin_tag(pmt::pmt_t val)
+ {
+ d_add_begin_tag = val;
+ }
+
int
file_source_impl::work(int noutput_items,
gr_vector_const_void_star &input_items,
@@ -166,7 +178,14 @@ namespace gr {
throw std::runtime_error("work with file not open");
gr::thread::scoped_lock lock(fp_mutex); // hold for the rest of this function
+
while(size) {
+ // Add stream tag whenever the file starts again
+ if (d_file_begin && d_add_begin_tag != pmt::PMT_NIL) {
+ add_item_tag(0, nitems_written(0) + noutput_items - size, d_add_begin_tag, pmt::from_long(d_repeat_cnt), _id);
+ d_file_begin = false;
+ }
+
i = fread(o, d_itemsize, size, (FILE*)d_fp);
size -= i;
@@ -188,6 +207,10 @@ namespace gr {
fprintf(stderr, "[%s] fseek failed\n", __FILE__);
exit(-1);
}
+ if (d_add_begin_tag != pmt::PMT_NIL) {
+ d_file_begin = true;
+ d_repeat_cnt++;
+ }
}
if(size > 0) { // EOF or error
diff --git a/gr-blocks/lib/file_source_impl.h b/gr-blocks/lib/file_source_impl.h
index 80232a1dbe..19f393fc1d 100644
--- a/gr-blocks/lib/file_source_impl.h
+++ b/gr-blocks/lib/file_source_impl.h
@@ -37,7 +37,12 @@ namespace gr {
FILE *d_new_fp;
bool d_repeat;
bool d_updated;
+ bool d_file_begin;
+ long d_repeat_cnt;
+ pmt::pmt_t d_add_begin_tag;
+
boost::mutex fp_mutex;
+ pmt::pmt_t _id;
void do_update();
@@ -52,6 +57,8 @@ namespace gr {
int work(int noutput_items,
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items);
+
+ void set_begin_tag(pmt::pmt_t val);
};
} /* namespace blocks */
diff --git a/gr-blocks/lib/tag_gate_impl.cc b/gr-blocks/lib/tag_gate_impl.cc
index 643ec6748f..ad55c8af9a 100644
--- a/gr-blocks/lib/tag_gate_impl.cc
+++ b/gr-blocks/lib/tag_gate_impl.cc
@@ -41,11 +41,13 @@ namespace gr {
gr::io_signature::make(1, 1, item_size),
gr::io_signature::make(1, 1, item_size)),
d_item_size(item_size),
- d_propagate_tags(propagate_tags)
+ d_propagate_tags(propagate_tags),
+ d_single_key_set(false)
{
if (!d_propagate_tags) {
set_tag_propagation_policy(TPP_DONT);
}
+ d_single_key = pmt::PMT_NIL;
}
tag_gate_impl::~tag_gate_impl()
@@ -54,10 +56,34 @@ namespace gr {
void tag_gate_impl::set_propagation(bool propagate_tags)
{
+ d_propagate_tags = propagate_tags;
+
if (propagate_tags) {
- set_tag_propagation_policy(TPP_ALL_TO_ALL);
+ set_tag_propagation_policy(TPP_ALL_TO_ALL);
} else {
- set_tag_propagation_policy(TPP_DONT);
+ set_tag_propagation_policy(TPP_DONT);
+ }
+ }
+
+ void tag_gate_impl::set_single_key(const std::string &single_key)
+ {
+ if(single_key == "") {
+ d_single_key = pmt::PMT_NIL;
+ d_single_key_set = false;
+ }
+ else {
+ d_single_key = pmt::intern(single_key);
+ d_single_key_set = true;
+ }
+ }
+
+ std::string tag_gate_impl::single_key() const
+ {
+ if(pmt::equal(d_single_key, pmt::PMT_NIL)) {
+ return "";
+ }
+ else {
+ return pmt::symbol_to_string(d_single_key);
}
}
@@ -68,9 +94,18 @@ namespace gr {
{
const unsigned char *in = (const unsigned char *) input_items[0];
unsigned char *out = (unsigned char *) output_items[0];
+ std::vector<tag_t> tags;
memcpy((void *) out, (void *) in, d_item_size * noutput_items);
+ if (d_single_key_set && (!d_propagate_tags)) {
+ get_tags_in_range(tags, 0, nitems_read(0), nitems_read(0) + noutput_items);
+ for (unsigned int i=0; i < tags.size(); i++) {
+ if (!pmt::equal(tags[i].key, d_single_key))
+ add_item_tag(0, tags[i].offset, tags[i].key, tags[i].value, tags[i].srcid);
+ }
+ }
+
return noutput_items;
}
diff --git a/gr-blocks/lib/tag_gate_impl.h b/gr-blocks/lib/tag_gate_impl.h
index 4983ba10b4..129fb78cb8 100644
--- a/gr-blocks/lib/tag_gate_impl.h
+++ b/gr-blocks/lib/tag_gate_impl.h
@@ -33,6 +33,9 @@ namespace gr {
private:
size_t d_item_size;
bool d_propagate_tags;
+ bool d_single_key_set;
+
+ pmt::pmt_t d_single_key;
public:
tag_gate_impl(size_t item_size, bool propagate_tags);
@@ -43,6 +46,9 @@ namespace gr {
int work(int noutput_items,
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items);
+
+ void set_single_key(const std::string &single_key);
+ std::string single_key() const;
};
} // namespace blocks
diff --git a/gr-blocks/lib/tag_share_impl.cc b/gr-blocks/lib/tag_share_impl.cc
new file mode 100644
index 0000000000..26a54dbf8c
--- /dev/null
+++ b/gr-blocks/lib/tag_share_impl.cc
@@ -0,0 +1,79 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2017 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 <gnuradio/io_signature.h>
+#include "tag_share_impl.h"
+
+namespace gr {
+ namespace blocks {
+
+ tag_share::sptr
+ tag_share::make(size_t sizeof_io_item, size_t sizeof_share_item, size_t vlen)
+ {
+ return gnuradio::get_initial_sptr
+ (new tag_share_impl(sizeof_io_item, sizeof_share_item, vlen));
+ }
+
+ /*
+ * The private constructor
+ */
+ tag_share_impl::tag_share_impl(size_t sizeof_io_item, size_t sizeof_share_item, size_t vlen)
+ : gr::sync_block("tag_share",
+ gr::io_signature::make2(2, 2, sizeof_io_item*vlen, sizeof_share_item*vlen),
+ gr::io_signature::make(1, 1, sizeof_io_item*vlen)),
+ d_sizeof_io_item(sizeof_io_item),
+ d_vlen(vlen)
+ {
+ // This is the entire premise of the block -- to have the GNU Radio runtime
+ // propagate all the tags from Input 0 and Input 1 to Output 0.
+ set_tag_propagation_policy(TPP_ALL_TO_ALL);
+ }
+
+ /*
+ * Our virtual destructor.
+ */
+ tag_share_impl::~tag_share_impl()
+ {
+ }
+
+ int
+ tag_share_impl::work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+ {
+ const void *in = (const void *) input_items[0];
+ void *out = (void *) output_items[0];
+
+ // Input 0 passes through to Output 0
+ memcpy(out, in, d_sizeof_io_item*d_vlen*noutput_items);
+
+ // Tell runtime system how many output items we produced.
+ return noutput_items;
+ }
+
+ } /* namespace blocks */
+} /* namespace gr */
+
diff --git a/gr-blocks/lib/tag_share_impl.h b/gr-blocks/lib/tag_share_impl.h
new file mode 100644
index 0000000000..e5df8e3a0c
--- /dev/null
+++ b/gr-blocks/lib/tag_share_impl.h
@@ -0,0 +1,51 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2017 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_BLOCKS_TAG_SHARE_IMPL_H
+#define INCLUDED_BLOCKS_TAG_SHARE_IMPL_H
+
+#include <gnuradio/blocks/tag_share.h>
+
+namespace gr {
+ namespace blocks {
+
+ class tag_share_impl : public tag_share
+ {
+ private:
+ size_t d_sizeof_io_item;
+ size_t d_vlen;
+
+ public:
+ tag_share_impl(size_t sizeof_io_item, size_t sizeof_share_item, size_t vlen);
+ ~tag_share_impl();
+
+ // Where all the action really happens
+ int work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+ };
+
+ } // namespace blocks
+} // namespace gr
+
+#endif /* INCLUDED_BLOCKS_TAG_SHARE_IMPL_H */
+