diff options
Diffstat (limited to 'gr-blocks/lib')
-rw-r--r-- | gr-blocks/lib/CMakeLists.txt | 5 | ||||
-rw-r--r-- | gr-blocks/lib/message_burst_source_impl.cc | 149 | ||||
-rw-r--r-- | gr-blocks/lib/message_burst_source_impl.h | 58 | ||||
-rw-r--r-- | gr-blocks/lib/message_debug_impl.cc | 120 | ||||
-rw-r--r-- | gr-blocks/lib/message_debug_impl.h | 89 | ||||
-rw-r--r-- | gr-blocks/lib/message_sink_impl.cc | 83 | ||||
-rw-r--r-- | gr-blocks/lib/message_sink_impl.h | 50 | ||||
-rw-r--r-- | gr-blocks/lib/message_source_impl.cc | 127 | ||||
-rw-r--r-- | gr-blocks/lib/message_source_impl.h | 56 | ||||
-rw-r--r-- | gr-blocks/lib/message_strobe_impl.cc | 85 | ||||
-rw-r--r-- | gr-blocks/lib/message_strobe_impl.h | 54 |
11 files changed, 876 insertions, 0 deletions
diff --git a/gr-blocks/lib/CMakeLists.txt b/gr-blocks/lib/CMakeLists.txt index 5b3d1e18eb..67e56fa319 100644 --- a/gr-blocks/lib/CMakeLists.txt +++ b/gr-blocks/lib/CMakeLists.txt @@ -164,6 +164,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 */ |