summaryrefslogtreecommitdiff
path: root/gr-blocks/lib
diff options
context:
space:
mode:
Diffstat (limited to 'gr-blocks/lib')
-rw-r--r--gr-blocks/lib/CMakeLists.txt7
-rw-r--r--gr-blocks/lib/message_burst_source_impl.cc149
-rw-r--r--gr-blocks/lib/message_burst_source_impl.h58
-rw-r--r--gr-blocks/lib/message_debug_impl.cc120
-rw-r--r--gr-blocks/lib/message_debug_impl.h89
-rw-r--r--gr-blocks/lib/message_sink_impl.cc83
-rw-r--r--gr-blocks/lib/message_sink_impl.h50
-rw-r--r--gr-blocks/lib/message_source_impl.cc127
-rw-r--r--gr-blocks/lib/message_source_impl.h56
-rw-r--r--gr-blocks/lib/message_strobe_impl.cc85
-rw-r--r--gr-blocks/lib/message_strobe_impl.h54
-rw-r--r--gr-blocks/lib/moving_average_XX_impl.cc.t114
-rw-r--r--gr-blocks/lib/moving_average_XX_impl.h.t65
-rw-r--r--gr-blocks/lib/peak_detector_XX_impl.cc.t122
-rw-r--r--gr-blocks/lib/peak_detector_XX_impl.h.t66
15 files changed, 1245 insertions, 0 deletions
diff --git a/gr-blocks/lib/CMakeLists.txt b/gr-blocks/lib/CMakeLists.txt
index eb7868dd42..d84d79de7d 100644
--- a/gr-blocks/lib/CMakeLists.txt
+++ b/gr-blocks/lib/CMakeLists.txt
@@ -99,12 +99,14 @@ expand_cc_h_impl(argmax_XX fs is ss)
expand_cc_h_impl(divide_XX ss ii ff cc)
expand_cc_h_impl(integrate_XX ss ii ff cc)
expand_cc_h_impl(max_XX ff ii ss)
+expand_cc_h_impl(moving_average_XX ss ii ff cc)
expand_cc_h_impl(multiply_XX ss ii)
expand_cc_h_impl(multiply_const_XX ss ii)
expand_cc_h_impl(multiply_const_vXX ss ii ff cc)
expand_cc_h_impl(mute_XX ss ii ff cc)
expand_cc_h_impl(not_XX bb ss ii)
expand_cc_h_impl(or_XX bb ss ii)
+expand_cc_h_impl(peak_detector_XX fb ib sb)
expand_cc_h_impl(probe_signal_X b s i f c)
expand_cc_h_impl(probe_signal_vX b s i f c)
expand_cc_h_impl(sample_and_hold_XX bb ss ii ff)
@@ -169,6 +171,11 @@ list(APPEND gr_blocks_sources
interleaved_short_to_complex_impl.cc
keep_m_in_n_impl.cc
keep_one_in_n_impl.cc
+ message_debug_impl.cc
+ message_sink_impl.cc
+ message_source_impl.cc
+ message_strobe_impl.cc
+ message_burst_source_impl.cc
multiply_cc_impl.cc
multiply_ff_impl.cc
multiply_conjugate_cc_impl.cc
diff --git a/gr-blocks/lib/message_burst_source_impl.cc b/gr-blocks/lib/message_burst_source_impl.cc
new file mode 100644
index 0000000000..f3c90eda31
--- /dev/null
+++ b/gr-blocks/lib/message_burst_source_impl.cc
@@ -0,0 +1,149 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2012-2013 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 "message_burst_source_impl.h"
+#include <gr_io_signature.h>
+#include <cstdio>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <stdexcept>
+#include <string.h>
+#include <gr_tags.h>
+
+namespace gr {
+ namespace blocks {
+
+ message_burst_source::sptr
+ message_burst_source::make(size_t itemsize, int msgq_limit)
+ {
+ return gnuradio::get_initial_sptr
+ (new message_burst_source_impl(itemsize, msgq_limit));
+ }
+
+ message_burst_source::sptr
+ message_burst_source::make(size_t itemsize, gr_msg_queue_sptr msgq)
+ {
+ return gnuradio::get_initial_sptr
+ (new message_burst_source_impl(itemsize, msgq));
+ }
+
+ message_burst_source_impl::message_burst_source_impl(size_t itemsize, int msgq_limit)
+ : gr_sync_block("message_burst_source",
+ gr_make_io_signature(0, 0, 0),
+ gr_make_io_signature(1, 1, itemsize)),
+ d_itemsize(itemsize), d_msgq(gr_make_msg_queue(msgq_limit)),
+ d_msg_offset(0), d_eof(false)
+ {
+ std::stringstream id;
+ id << name() << unique_id();
+ d_me = pmt::pmt_string_to_symbol(id.str());
+ }
+
+ message_burst_source_impl::message_burst_source_impl(size_t itemsize, gr_msg_queue_sptr msgq)
+ : gr_sync_block("message_burst_source",
+ gr_make_io_signature(0, 0, 0),
+ gr_make_io_signature(1, 1, itemsize)),
+ d_itemsize(itemsize), d_msgq(msgq),
+ d_msg_offset(0), d_eof(false)
+ {
+ std::stringstream id;
+ id << name() << unique_id();
+ d_me = pmt::pmt_string_to_symbol(id.str());
+ }
+
+ message_burst_source_impl::~message_burst_source_impl()
+ {
+ }
+
+ int
+ message_burst_source_impl::work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+ {
+ char *out = (char*)output_items[0];
+ int nn = 0;
+
+ uint64_t abs_sample_count = nitems_written(0);
+
+ while(nn < noutput_items) {
+ if(d_msg) {
+ //
+ // Consume whatever we can from the current message
+ //
+
+ int mm = std::min(noutput_items - nn,
+ (int)((d_msg->length() - d_msg_offset) / d_itemsize));
+ memcpy(out, &(d_msg->msg()[d_msg_offset]), mm * d_itemsize);
+
+ nn += mm;
+ out += mm * d_itemsize;
+ d_msg_offset += mm * d_itemsize;
+ assert(d_msg_offset <= d_msg->length());
+
+ if(d_msg_offset == d_msg->length()) {
+ if(d_msg->type() == 1) // type == 1 sets EOF
+ d_eof = true;
+ d_msg.reset();
+ //tag end of burst
+ add_item_tag(0, //stream ID
+ abs_sample_count+nn-1, //sample number
+ pmt::pmt_string_to_symbol("tx_eob"),
+ pmt::pmt_from_bool(1),
+ d_me); //block src id
+ }
+ }
+ else {
+ //
+ // No current message
+ //
+ if(d_msgq->empty_p() && nn > 0) { // no more messages in the queue, return what we've got
+ break;
+ }
+
+ if(d_eof)
+ return -1;
+
+ d_msg = d_msgq->delete_head(); // block, waiting for a message
+ d_msg_offset = 0;
+ //tag start of burst
+ add_item_tag(0, //stream ID
+ abs_sample_count+nn, //sample number
+ pmt::pmt_string_to_symbol("tx_sob"),
+ pmt::pmt_from_bool(1),
+ d_me); //block src id
+
+ if((d_msg->length() % d_itemsize) != 0)
+ throw std::runtime_error("msg length is not a multiple of d_itemsize");
+ }
+ }
+
+ return nn;
+ }
+
+ } /* namespace blocks */
+} /* namespace gr */
diff --git a/gr-blocks/lib/message_burst_source_impl.h b/gr-blocks/lib/message_burst_source_impl.h
new file mode 100644
index 0000000000..2d5e6a974f
--- /dev/null
+++ b/gr-blocks/lib/message_burst_source_impl.h
@@ -0,0 +1,58 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2012-2013 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_MESSAGE_BURST_SOURCE_IMPL_H
+#define INCLUDED_GR_MESSAGE_BURST_SOURCE_IMPL_H
+
+#include <blocks/message_burst_source.h>
+#include <gr_message.h>
+
+namespace gr {
+ namespace blocks {
+
+ class message_burst_source_impl : public message_burst_source
+ {
+ private:
+ size_t d_itemsize;
+ gr_msg_queue_sptr d_msgq;
+ gr_message_sptr d_msg;
+ unsigned d_msg_offset;
+ bool d_eof;
+
+ pmt::pmt_t d_me;
+
+ public:
+ message_burst_source_impl(size_t itemsize, int msgq_limit);
+ message_burst_source_impl(size_t itemsize, gr_msg_queue_sptr msgq);
+ ~message_burst_source_impl();
+
+ gr_msg_queue_sptr msgq() const { return d_msgq; }
+
+ int work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* INCLUDED_GR_MESSAGE_BURST_SOURCE_IMPL_H */
diff --git a/gr-blocks/lib/message_debug_impl.cc b/gr-blocks/lib/message_debug_impl.cc
new file mode 100644
index 0000000000..d7b1e5db09
--- /dev/null
+++ b/gr-blocks/lib/message_debug_impl.cc
@@ -0,0 +1,120 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2005,2010,2012-2013 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 "message_debug_impl.h"
+#include <gr_io_signature.h>
+#include <cstdio>
+#include <iostream>
+
+namespace gr {
+ namespace blocks {
+
+ message_debug::sptr
+ message_debug::make()
+ {
+ return gnuradio::get_initial_sptr
+ (new message_debug_impl());
+ }
+
+ void
+ message_debug_impl::print(pmt::pmt_t msg)
+ {
+ std::cout << "******* MESSAGE DEBUG PRINT ********\n";
+ pmt::pmt_print(msg);
+ std::cout << "************************************\n";
+ }
+
+ void
+ message_debug_impl::store(pmt::pmt_t msg)
+ {
+ gruel::scoped_lock guard(d_mutex);
+ d_messages.push_back(msg);
+ }
+
+ void
+ message_debug_impl::print_pdu(pmt::pmt_t pdu)
+ {
+ pmt::pmt_t meta = pmt::pmt_car(pdu);
+ pmt::pmt_t vector = pmt::pmt_cdr(pdu);
+ std::cout << "* MESSAGE DEBUG PRINT PDU VERBOSE *\n";
+ pmt::pmt_print(meta);
+ size_t len = pmt::pmt_length(vector);
+ std::cout << "pdu_length = " << len << std::endl;
+ std::cout << "contents = " << std::endl;
+ size_t offset(0);
+ const uint8_t* d = (const uint8_t*) pmt_uniform_vector_elements(vector, offset);
+ for(size_t i=0; i<len; i+=16){
+ printf("%04x: ", ((unsigned int)i));
+ for(size_t j=i; j<std::min(i+16,len); j++){
+ printf("%02x ",d[j] );
+ }
+
+ std::cout << std::endl;
+ }
+
+ std::cout << "***********************************\n";
+ }
+
+ int
+ message_debug_impl::num_messages()
+ {
+ return (int)d_messages.size();
+ }
+
+ pmt::pmt_t
+ message_debug_impl::get_message(int i)
+ {
+ gruel::scoped_lock guard(d_mutex);
+
+ if((size_t)i >= d_messages.size()) {
+ throw std::runtime_error("message_debug: index for message out of bounds.\n");
+ }
+
+ return d_messages[i];
+ }
+
+ message_debug_impl::message_debug_impl()
+ : gr_block("message_debug",
+ gr_make_io_signature(0, 0, 0),
+ gr_make_io_signature(0, 0, 0))
+ {
+ message_port_register_in(pmt::mp("print"));
+ set_msg_handler(pmt::mp("print"), boost::bind(&message_debug_impl::print, this, _1));
+
+ message_port_register_in(pmt::mp("store"));
+ set_msg_handler(pmt::mp("store"), boost::bind(&message_debug_impl::store, this, _1));
+
+ message_port_register_in(pmt::mp("print_pdu"));
+ set_msg_handler(pmt::mp("print_pdu"), boost::bind(&message_debug_impl::print_pdu, this, _1));
+ }
+
+ message_debug_impl::~message_debug_impl()
+ {
+ }
+
+ } /* namespace blocks */
+} /* namespace gr */
+
diff --git a/gr-blocks/lib/message_debug_impl.h b/gr-blocks/lib/message_debug_impl.h
new file mode 100644
index 0000000000..c9d82bd561
--- /dev/null
+++ b/gr-blocks/lib/message_debug_impl.h
@@ -0,0 +1,89 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2005,2012-2013 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_MESSAGE_DEBUG_IMPL_H
+#define INCLUDED_GR_MESSAGE_DEBUG_IMPL_H
+
+#include <blocks/message_debug.h>
+#include <gr_block.h>
+#include <gruel/thread.h>
+#include <gruel/pmt.h>
+
+namespace gr {
+ namespace blocks {
+
+ class message_debug_impl : public message_debug
+ {
+ private:
+
+ /*!
+ * \brief Messages received in this port are printed to stdout.
+ *
+ * This port receives messages from the scheduler's message
+ * handling mechanism and prints it to stdout. This message
+ * handler function is only meant to be used by the scheduler to
+ * handle messages posted to port 'print'.
+ *
+ * \param msg A pmt message passed from the scheduler's message handling.
+ */
+ void print(pmt::pmt_t msg);
+
+ /*!
+ * \brief PDU formatted messages received in this port are printed to stdout.
+ *
+ * This port receives messages from the scheduler's message
+ * handling mechanism and prints it to stdout. This message
+ * handler function is only meant to be used by the scheduler to
+ * handle messages posted to port 'print'.
+ *
+ * \param pdu A PDU message passed from the scheduler's message handling.
+ */
+ void print_pdu(pmt::pmt_t pdu);
+
+ /*!
+ * \brief Messages received in this port are stored in a vector.
+ *
+ * This port receives messages from the scheduler's message
+ * handling mechanism and stores it in a vector. Messages can be
+ * retrieved later using the 'get_message' function. This
+ * message handler function is only meant to be used by the
+ * scheduler to handle messages posted to port 'store'.
+ *
+ * \param msg A pmt message passed from the scheduler's message handling.
+ */
+ void store(pmt::pmt_t msg);
+
+ gruel::mutex d_mutex;
+ std::vector<pmt::pmt_t> d_messages;
+
+ public:
+ message_debug_impl();
+ ~message_debug_impl();
+
+ int num_messages();
+ pmt::pmt_t get_message(int i);
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* INCLUDED_GR_MESSAGE_DEBUG_IMPL_H */
diff --git a/gr-blocks/lib/message_sink_impl.cc b/gr-blocks/lib/message_sink_impl.cc
new file mode 100644
index 0000000000..a8dbfb4c71
--- /dev/null
+++ b/gr-blocks/lib/message_sink_impl.cc
@@ -0,0 +1,83 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2005,2010,2013 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 "message_sink_impl.h"
+#include <gr_io_signature.h>
+#include <cstdio>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <stdexcept>
+#include <string.h>
+
+namespace gr {
+ namespace blocks {
+
+ message_sink::sptr
+ message_sink::make(size_t itemsize, gr_msg_queue_sptr msgq, bool dont_block)
+ {
+ return gnuradio::get_initial_sptr
+ (new message_sink_impl(itemsize, msgq, dont_block));
+ }
+
+ message_sink_impl::message_sink_impl(size_t itemsize, gr_msg_queue_sptr msgq, bool dont_block)
+ : gr_sync_block("message_sink",
+ gr_make_io_signature(1, 1, itemsize),
+ gr_make_io_signature(0, 0, 0)),
+ d_itemsize(itemsize), d_msgq(msgq), d_dont_block(dont_block)
+ {
+ }
+
+ message_sink_impl::~message_sink_impl()
+ {
+ }
+
+ int
+ message_sink_impl::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];
+
+ // if we'd block, drop the data on the floor and say everything is OK
+ if(d_dont_block && d_msgq->full_p())
+ return noutput_items;
+
+ // build a message to hold whatever we've got
+ gr_message_sptr msg = gr_make_message(0, // msg type
+ d_itemsize, // arg1 for other end
+ noutput_items, // arg2 for other end (redundant)
+ noutput_items * d_itemsize); // len of msg
+ memcpy(msg->msg(), in, noutput_items * d_itemsize);
+
+ d_msgq->handle(msg); // send it
+
+ return noutput_items;
+ }
+
+ } /* namespace blocks */
+} /* namespace gr */
diff --git a/gr-blocks/lib/message_sink_impl.h b/gr-blocks/lib/message_sink_impl.h
new file mode 100644
index 0000000000..a3106bc058
--- /dev/null
+++ b/gr-blocks/lib/message_sink_impl.h
@@ -0,0 +1,50 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2005,2013 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_MESSAGE_SINK_IMPL_H
+#define INCLUDED_GR_MESSAGE_SINK_IMPL_H
+
+#include <blocks/message_sink.h>
+
+namespace gr {
+ namespace blocks {
+
+ class message_sink_impl : public message_sink
+ {
+ private:
+ size_t d_itemsize;
+ gr_msg_queue_sptr d_msgq;
+ bool d_dont_block;
+
+ public:
+ message_sink_impl(size_t itemsize, gr_msg_queue_sptr msgq, bool dont_block);
+ ~message_sink_impl();
+
+ int work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* INCLUDED_GR_MESSAGE_SINK_IMPL_H */
diff --git a/gr-blocks/lib/message_source_impl.cc b/gr-blocks/lib/message_source_impl.cc
new file mode 100644
index 0000000000..cda4fc16c0
--- /dev/null
+++ b/gr-blocks/lib/message_source_impl.cc
@@ -0,0 +1,127 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2005,2010,2013 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 "message_source_impl.h"
+#include <gr_io_signature.h>
+#include <cstdio>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <stdexcept>
+#include <string.h>
+
+namespace gr {
+ namespace blocks {
+
+ message_source::sptr
+ message_source::make(size_t itemsize, int msgq_limit)
+ {
+ return gnuradio::get_initial_sptr
+ (new message_source_impl(itemsize, msgq_limit));
+ }
+
+ message_source::sptr
+ message_source::make(size_t itemsize, gr_msg_queue_sptr msgq)
+ {
+ return gnuradio::get_initial_sptr
+ (new message_source_impl(itemsize, msgq));
+ }
+
+ message_source_impl::message_source_impl(size_t itemsize, int msgq_limit)
+ : gr_sync_block("message_source",
+ gr_make_io_signature(0, 0, 0),
+ gr_make_io_signature(1, 1, itemsize)),
+ d_itemsize(itemsize), d_msgq(gr_make_msg_queue(msgq_limit)),
+ d_msg_offset(0), d_eof(false)
+ {
+ }
+
+ message_source_impl::message_source_impl(size_t itemsize, gr_msg_queue_sptr msgq)
+ : gr_sync_block("message_source",
+ gr_make_io_signature(0, 0, 0),
+ gr_make_io_signature(1, 1, itemsize)),
+ d_itemsize(itemsize), d_msgq(msgq),
+ d_msg_offset(0), d_eof(false)
+ {
+ }
+
+ message_source_impl::~message_source_impl()
+ {
+ }
+
+ int
+ message_source_impl::work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+ {
+ char *out = (char*)output_items[0];
+ int nn = 0;
+
+ while(nn < noutput_items) {
+ if(d_msg) {
+ //
+ // Consume whatever we can from the current message
+ //
+ int mm = std::min(noutput_items - nn,
+ (int)((d_msg->length() - d_msg_offset) / d_itemsize));
+ memcpy(out, &(d_msg->msg()[d_msg_offset]), mm * d_itemsize);
+
+ nn += mm;
+ out += mm * d_itemsize;
+ d_msg_offset += mm * d_itemsize;
+ assert(d_msg_offset <= d_msg->length());
+
+ if(d_msg_offset == d_msg->length()) {
+ if(d_msg->type() == 1) // type == 1 sets EOF
+ d_eof = true;
+ d_msg.reset();
+ }
+ }
+ else {
+ //
+ // No current message
+ //
+ if(d_msgq->empty_p() && nn > 0) { // no more messages in the queue, return what we've got
+ break;
+ }
+
+ if(d_eof)
+ return -1;
+
+ d_msg = d_msgq->delete_head(); // block, waiting for a message
+ d_msg_offset = 0;
+
+ if((d_msg->length() % d_itemsize) != 0)
+ throw std::runtime_error("msg length is not a multiple of d_itemsize");
+ }
+ }
+
+ return nn;
+ }
+
+ } /* namespace blocks */
+} /* namespace gr */
diff --git a/gr-blocks/lib/message_source_impl.h b/gr-blocks/lib/message_source_impl.h
new file mode 100644
index 0000000000..c420704478
--- /dev/null
+++ b/gr-blocks/lib/message_source_impl.h
@@ -0,0 +1,56 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2005,2013 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_MESSAGE_SOURCE_IMPL_H
+#define INCLUDED_GR_MESSAGE_SOURCE_IMPL_H
+
+#include <blocks/message_source.h>
+#include <gr_message.h>
+
+namespace gr {
+ namespace blocks {
+
+ class message_source_impl : public message_source
+ {
+ private:
+ size_t d_itemsize;
+ gr_msg_queue_sptr d_msgq;
+ gr_message_sptr d_msg;
+ unsigned d_msg_offset;
+ bool d_eof;
+
+ public:
+ message_source_impl(size_t itemsize, int msgq_limit);
+ message_source_impl(size_t itemsize, gr_msg_queue_sptr msgq);
+ ~message_source_impl();
+
+ gr_msg_queue_sptr msgq() const { return d_msgq; }
+
+ int work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* INCLUDED_GR_MESSAGE_SOURCE_IMPL_H */
diff --git a/gr-blocks/lib/message_strobe_impl.cc b/gr-blocks/lib/message_strobe_impl.cc
new file mode 100644
index 0000000000..c4b0e5d567
--- /dev/null
+++ b/gr-blocks/lib/message_strobe_impl.cc
@@ -0,0 +1,85 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2012-2013 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 "message_strobe_impl.h"
+#include <gr_io_signature.h>
+#include <cstdio>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <stdexcept>
+#include <string.h>
+#include <iostream>
+
+namespace gr {
+ namespace blocks {
+
+ message_strobe::sptr
+ message_strobe::make(pmt::pmt_t msg, float period_ms)
+ {
+ return gnuradio::get_initial_sptr
+ (new message_strobe_impl(msg, period_ms));
+ }
+
+ message_strobe_impl::message_strobe_impl(pmt::pmt_t msg, float period_ms)
+ : gr_block("message_strobe",
+ gr_make_io_signature(0, 0, 0),
+ gr_make_io_signature(0, 0, 0)),
+ d_finished(false),
+ d_period_ms(period_ms),
+ d_msg(msg)
+ {
+ message_port_register_out(pmt::mp("strobe"));
+ d_thread = boost::shared_ptr<boost::thread>
+ (new boost::thread(boost::bind(&message_strobe_impl::run, this)));
+
+ message_port_register_in(pmt::mp("set_msg"));
+ set_msg_handler(pmt::mp("set_msg"),
+ boost::bind(&message_strobe_impl::set_msg, this, _1));
+ }
+
+ message_strobe_impl::~message_strobe_impl()
+ {
+ d_finished = true;
+ d_thread->interrupt();
+ d_thread->join();
+ }
+
+ void message_strobe_impl::run()
+ {
+ while(!d_finished) {
+ boost::this_thread::sleep(boost::posix_time::milliseconds(d_period_ms));
+ if(d_finished) {
+ return;
+ }
+
+ message_port_pub(pmt::mp("strobe"), d_msg);
+ }
+ }
+
+ } /* namespace blocks */
+} /* namespace gr */
diff --git a/gr-blocks/lib/message_strobe_impl.h b/gr-blocks/lib/message_strobe_impl.h
new file mode 100644
index 0000000000..1b2edae593
--- /dev/null
+++ b/gr-blocks/lib/message_strobe_impl.h
@@ -0,0 +1,54 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2012-2013 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_MESSAGE_STROBE_IMPL_H
+#define INCLUDED_GR_MESSAGE_STROBE_IMPL_H
+
+#include <blocks/message_strobe.h>
+
+namespace gr {
+ namespace blocks {
+
+ class BLOCKS_API message_strobe_impl : public message_strobe
+ {
+ private:
+ boost::shared_ptr<boost::thread> d_thread;
+ bool d_finished;
+ float d_period_ms;
+ pmt::pmt_t d_msg;
+
+ void run();
+
+ public:
+ message_strobe_impl(pmt::pmt_t msg, float period_ms);
+ ~message_strobe_impl();
+
+ void set_msg(pmt::pmt_t msg) { d_msg = msg; }
+ pmt::pmt_t msg() const { return d_msg; }
+ void set_period(float period_ms) { d_period_ms = period_ms; }
+ float period() const { return d_period_ms; }
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* INCLUDED_GR_MESSAGE_STROBE_IMPL_H */
diff --git a/gr-blocks/lib/moving_average_XX_impl.cc.t b/gr-blocks/lib/moving_average_XX_impl.cc.t
new file mode 100644
index 0000000000..566deff116
--- /dev/null
+++ b/gr-blocks/lib/moving_average_XX_impl.cc.t
@@ -0,0 +1,114 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2008,2010,2013 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.
+ */
+
+// @WARNING@
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "@NAME_IMPL@.h"
+#include <gr_io_signature.h>
+
+namespace gr {
+ namespace blocks {
+
+ @NAME@::sptr
+ @NAME@::make(int length, @O_TYPE@ scale, int max_iter)
+ {
+ return gnuradio::get_initial_sptr
+ (new @NAME_IMPL@(length, scale, max_iter));
+ }
+
+ @NAME_IMPL@::@NAME_IMPL@(int length, @O_TYPE@ scale, int max_iter)
+ : gr_sync_block("@NAME@",
+ gr_make_io_signature(1, 1, sizeof(@I_TYPE@)),
+ gr_make_io_signature(1, 1, sizeof(@O_TYPE@))),
+ d_length(length),
+ d_scale(scale),
+ d_max_iter(max_iter),
+ d_new_length(length),
+ d_new_scale(scale),
+ d_updated(false)
+ {
+ set_history(length);
+ }
+
+ @NAME_IMPL@::~@NAME_IMPL@()
+ {
+ }
+
+ void
+ @NAME_IMPL@::set_length_and_scale(int length, @O_TYPE@ scale)
+ {
+ d_new_length = length;
+ d_new_scale = scale;
+ d_updated = true;
+ }
+
+ void
+ @NAME_IMPL@::set_length(int length)
+ {
+ d_new_length = length;
+ d_updated = true;
+ }
+
+ void
+ @NAME_IMPL@::set_scale(@O_TYPE@ scale)
+ {
+ d_new_scale = scale;
+ d_updated = true;
+ }
+
+ int
+ @NAME_IMPL@::work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+ {
+ if(d_updated) {
+ d_length = d_new_length;
+ d_scale = d_new_scale;
+ set_history(d_length);
+ d_updated = false;
+ return 0; // history requirements might have changed
+ }
+
+ const @I_TYPE@ *in = (const @I_TYPE@ *)input_items[0];
+ @O_TYPE@ *out = (@O_TYPE@ *)output_items[0];
+
+ @I_TYPE@ sum = 0;
+ int num_iter = (noutput_items>d_max_iter) ? d_max_iter : noutput_items;
+ for(int i = 0; i < d_length-1; i++) {
+ sum += in[i];
+ }
+
+ for(int i = 0; i < num_iter; i++) {
+ sum += in[i+d_length-1];
+ out[i] = sum * d_scale;
+ sum -= in[i];
+ }
+
+ return num_iter;
+ }
+
+ } /* namespace blocks */
+} /* namespace gr */
diff --git a/gr-blocks/lib/moving_average_XX_impl.h.t b/gr-blocks/lib/moving_average_XX_impl.h.t
new file mode 100644
index 0000000000..7234cbe139
--- /dev/null
+++ b/gr-blocks/lib/moving_average_XX_impl.h.t
@@ -0,0 +1,65 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2008,2013 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.
+ */
+
+// @WARNING@
+
+#ifndef @GUARD_NAME_IMPL@
+#define @GUARD_NAME_IMPL@
+
+#include <blocks/@NAME@.h>
+
+namespace gr {
+ namespace blocks {
+
+ class @NAME_IMPL@ : public @NAME@
+ {
+ private:
+ int d_length;
+ @O_TYPE@ d_scale;
+ int d_max_iter;
+
+ int d_new_length;
+ @O_TYPE@ d_new_scale;
+ bool d_updated;
+
+ public:
+ @NAME_IMPL@(int length, @O_TYPE@ scale,
+ int max_iter = 4096);
+ ~@NAME_IMPL@();
+
+ int length() const { return d_new_length; }
+ @O_TYPE@ scale() const { return d_new_scale; }
+
+ void set_length_and_scale(int length, @O_TYPE@ scale);
+ void set_length(int length);
+ void set_scale(@O_TYPE@ scale);
+
+ int work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* @GUARD_NAME_IMPL@ */
diff --git a/gr-blocks/lib/peak_detector_XX_impl.cc.t b/gr-blocks/lib/peak_detector_XX_impl.cc.t
new file mode 100644
index 0000000000..27518962f5
--- /dev/null
+++ b/gr-blocks/lib/peak_detector_XX_impl.cc.t
@@ -0,0 +1,122 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2007,2010,2013 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.
+ */
+
+// @WARNING@
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "@NAME_IMPL@.h"
+#include <gr_io_signature.h>
+#include <string.h>
+
+namespace gr {
+ namespace blocks {
+
+ @NAME@::sptr
+ @NAME@::make(float threshold_factor_rise,
+ float threshold_factor_fall,
+ int look_ahead, float alpha)
+ {
+ return gnuradio::get_initial_sptr
+ (new @NAME_IMPL@(threshold_factor_rise,
+ threshold_factor_fall,
+ look_ahead, alpha));
+ }
+
+ @NAME_IMPL@::@NAME_IMPL@(float threshold_factor_rise,
+ float threshold_factor_fall,
+ int look_ahead, float alpha)
+ : gr_sync_block("@BASE_NAME@",
+ gr_make_io_signature(1, 1, sizeof(@I_TYPE@)),
+ gr_make_io_signature(1, 1, sizeof(char))),
+ d_threshold_factor_rise(threshold_factor_rise),
+ d_threshold_factor_fall(threshold_factor_fall),
+ d_look_ahead(look_ahead), d_avg_alpha(alpha), d_avg(0), d_found(0)
+ {
+ }
+
+ @NAME_IMPL@::~@NAME_IMPL@()
+ {
+ }
+
+ int
+ @NAME_IMPL@::work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+ {
+ @I_TYPE@ *iptr = (@I_TYPE@*)input_items[0];
+ char *optr = (char*)output_items[0];
+
+ memset(optr, 0, noutput_items*sizeof(char));
+
+ @I_TYPE@ peak_val = -(@I_TYPE@)INFINITY;
+ int peak_ind = 0;
+ unsigned char state = 0;
+ int i = 0;
+
+ //printf("noutput_items %d\n",noutput_items);
+ while(i < noutput_items) {
+ if(state == 0) { // below threshold
+ if(iptr[i] > d_avg*d_threshold_factor_rise) {
+ state = 1;
+ }
+ else {
+ d_avg = (d_avg_alpha)*iptr[i] + (1-d_avg_alpha)*d_avg;
+ i++;
+ }
+ }
+ else if(state == 1) { // above threshold, have not found peak
+ //printf("Entered State 1: %f i: %d noutput_items: %d\n", iptr[i], i, noutput_items);
+ if(iptr[i] > peak_val) {
+ peak_val = iptr[i];
+ peak_ind = i;
+ d_avg = (d_avg_alpha)*iptr[i] + (1-d_avg_alpha)*d_avg;
+ i++;
+ }
+ else if(iptr[i] > d_avg*d_threshold_factor_fall) {
+ d_avg = (d_avg_alpha)*iptr[i] + (1-d_avg_alpha)*d_avg;
+ i++;
+ }
+ else {
+ optr[peak_ind] = 1;
+ state = 0;
+ peak_val = -(@I_TYPE@)INFINITY;
+ //printf("Leaving State 1: Peak: %f Peak Ind: %d i: %d noutput_items: %d\n",
+ //peak_val, peak_ind, i, noutput_items);
+ }
+ }
+ }
+
+ if(state == 0) {
+ //printf("Leave in State 0, produced %d\n",noutput_items);
+ return noutput_items;
+ }
+ else { // only return up to passing the threshold
+ //printf("Leave in State 1, only produced %d of %d\n",peak_ind,noutput_items);
+ return peak_ind+1;
+ }
+ }
+
+ } /* namespace blocks */
+} /* namespace gr */
diff --git a/gr-blocks/lib/peak_detector_XX_impl.h.t b/gr-blocks/lib/peak_detector_XX_impl.h.t
new file mode 100644
index 0000000000..ef52f0f744
--- /dev/null
+++ b/gr-blocks/lib/peak_detector_XX_impl.h.t
@@ -0,0 +1,66 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2007,2013 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.
+ */
+
+// @WARNING@
+
+#ifndef @GUARD_NAME_IMPL@
+#define @GUARD_NAME_IMPL@
+
+#include <blocks/@NAME@.h>
+
+namespace gr {
+ namespace blocks {
+
+ class @NAME_IMPL@ : public @NAME@
+ {
+ private:
+ float d_threshold_factor_rise;
+ float d_threshold_factor_fall;
+ int d_look_ahead;
+ float d_avg_alpha;
+ float d_avg;
+ unsigned char d_found;
+
+ public:
+ @NAME_IMPL@(float threshold_factor_rise,
+ float threshold_factor_fall,
+ int look_ahead, float alpha);
+ ~@NAME_IMPL@();
+
+ void set_threshold_factor_rise(float thr) { d_threshold_factor_rise = thr; }
+ void set_threshold_factor_fall(float thr) { d_threshold_factor_fall = thr; }
+ void set_look_ahead(int look) { d_look_ahead = look; }
+ void set_alpha(int alpha) { d_avg_alpha = alpha; }
+ float threshold_factor_rise() { return d_threshold_factor_rise; }
+ float threshold_factor_fall() { return d_threshold_factor_fall; }
+ int look_ahead() { return d_look_ahead; }
+ float alpha() { return d_avg_alpha; }
+
+ int work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* @GUARD_NAME_IMPL@ */