diff options
author | Tom Rondeau | 2012-12-06 12:52:35 -0500 |
---|---|---|
committer | Tom Rondeau | 2012-12-06 12:52:35 -0500 |
commit | 53be45f118e6e73d2a50fe0ba4622d6dfe96117c (patch) | |
tree | 994d366c6742c9642371a0e88b51afa44b21f484 /gnuradio-core | |
parent | a47c5485e477a2b29a839c785fea45f29da07919 (diff) | |
download | gnuradio-53be45f118e6e73d2a50fe0ba4622d6dfe96117c.tar.gz gnuradio-53be45f118e6e73d2a50fe0ba4622d6dfe96117c.tar.bz2 gnuradio-53be45f118e6e73d2a50fe0ba4622d6dfe96117c.zip |
core: updated the message debug block to have a 'store' port where messages can be retrieved afterwards.
Updated qa_pdu to use the new 'store' port for testing the resulting message.
Diffstat (limited to 'gnuradio-core')
-rw-r--r-- | gnuradio-core/src/lib/io/gr_message_debug.cc | 39 | ||||
-rw-r--r-- | gnuradio-core/src/lib/io/gr_message_debug.h | 49 | ||||
-rwxr-xr-x | gnuradio-core/src/python/gnuradio/gr/qa_pdu.py | 49 |
3 files changed, 115 insertions, 22 deletions
diff --git a/gnuradio-core/src/lib/io/gr_message_debug.cc b/gnuradio-core/src/lib/io/gr_message_debug.cc index d98954576..7d28ff18e 100644 --- a/gnuradio-core/src/lib/io/gr_message_debug.cc +++ b/gnuradio-core/src/lib/io/gr_message_debug.cc @@ -43,20 +43,49 @@ gr_make_message_debug () return gnuradio::get_initial_sptr(new gr_message_debug()); } -void gr_message_debug::print(pmt::pmt_t msg){ - std::cout << "******* MESSAGE DEBUG PRINT ********\n"; - pmt::pmt_print(msg); - std::cout << "************************************\n"; +void +gr_message_debug::print(pmt::pmt_t msg) +{ + std::cout << "******* MESSAGE DEBUG PRINT ********\n"; + pmt::pmt_print(msg); + std::cout << "************************************\n"; +} + +void +gr_message_debug::store(pmt::pmt_t msg) +{ + gruel::scoped_lock guard(d_mutex); + d_messages.push_back(msg); +} + +int +gr_message_debug::num_messages() +{ + return (int)d_messages.size(); } +pmt::pmt_t +gr_message_debug::get_message(int i) +{ + gruel::scoped_lock guard(d_mutex); + + if((size_t)i >= d_messages.size()) { + throw std::runtime_error("gr_message_debug: index for message out of bounds.\n"); + } -gr_message_debug::gr_message_debug () + return d_messages[i]; +} + +gr_message_debug::gr_message_debug() : 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(&gr_message_debug::print, this, _1)); + + message_port_register_in(pmt::mp("store")); + set_msg_handler(pmt::mp("store"), boost::bind(&gr_message_debug::store, this, _1)); } gr_message_debug::~gr_message_debug() diff --git a/gnuradio-core/src/lib/io/gr_message_debug.h b/gnuradio-core/src/lib/io/gr_message_debug.h index 120694a91..1ffef1b02 100644 --- a/gnuradio-core/src/lib/io/gr_message_debug.h +++ b/gnuradio-core/src/lib/io/gr_message_debug.h @@ -27,11 +27,12 @@ #include <gr_block.h> #include <gr_message.h> #include <gr_msg_queue.h> +#include <gruel/thread.h> class gr_message_debug; typedef boost::shared_ptr<gr_message_debug> gr_message_debug_sptr; -GR_CORE_API gr_message_debug_sptr gr_make_message_debug (); +GR_CORE_API gr_message_debug_sptr gr_make_message_debug(); /*! * \brief Print received messages to stdout @@ -43,13 +44,59 @@ class GR_CORE_API gr_message_debug : public gr_block friend GR_CORE_API gr_message_debug_sptr gr_make_message_debug(); + /*! + * \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 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; + protected: gr_message_debug (); public: ~gr_message_debug (); + + /*! + * \brief Reports the number of messages received by this block. + */ + int num_messages(); + + /*! + * \brief Get a message (as a PMT) from the message vector at index \p i. + * + * Messages passed to the 'store' port will be stored in a + * vector. This function retrieves those messages by index. They are + * index in order of when they were received (all messages are just + * pushed onto the back of a vector). This is mostly useful in + * debugging message passing graphs and in QA code. + * + * \param i The index in the vector for the message to retrieve. + * + * \return a message at index \p i as a pmt_t. + */ + pmt::pmt_t get_message(int i); }; #endif /* INCLUDED_GR_MESSAGE_DEBUG_H */ diff --git a/gnuradio-core/src/python/gnuradio/gr/qa_pdu.py b/gnuradio-core/src/python/gnuradio/gr/qa_pdu.py index 83c7748af..da1331d96 100755 --- a/gnuradio-core/src/python/gnuradio/gr/qa_pdu.py +++ b/gnuradio-core/src/python/gnuradio/gr/qa_pdu.py @@ -36,36 +36,53 @@ class test_pdu(gr_unittest.TestCase): # Just run some data through and make sure it doesn't puke. src_data = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10) - src = gr.pdu_to_tagged_stream(gr.BYTE); - snk3 = gr.tagged_stream_to_pdu(gr.BYTE); - snk2 = gr.vector_sink_b(); - snk = gr.tag_debug(1, "test"); + src = gr.pdu_to_tagged_stream(gr.BYTE) + snk3 = gr.tagged_stream_to_pdu(gr.BYTE) + snk2 = gr.vector_sink_b() + snk = gr.tag_debug(1, "test") - dbg = gr.message_debug(); + dbg = gr.message_debug() self.tb.connect(src, snk) self.tb.connect(src, snk2) self.tb.connect(src, snk3) - self.tb.msg_connect(snk3, "pdus", dbg, "print"); + self.tb.msg_connect(snk3, "pdus", dbg, "store") self.tb.start() # make our reference and message pmts - port = pmt.pmt_intern("pdus"); - msg = pmt.pmt_cons( pmt.PMT_NIL, pmt.pmt_make_u8vector(16, 0xFF) ); + port = pmt.pmt_intern("pdus") + msg = pmt.pmt_cons( pmt.PMT_NIL, pmt.pmt_make_u8vector(16, 0xFF) ) - print "printing port & msg" - pmt.pmt_print(port); - pmt.pmt_print(msg); + #print "printing port & msg" + #pmt.pmt_print(port) + #pmt.pmt_print(msg) # post the message - src.to_basic_block()._post( port, msg ); + src.to_basic_block()._post( port, msg ) - time.sleep(1); - self.tb.stop(); - self.tb.wait(); + while(dbg.num_messages() < 1): + time.sleep(0.5) + self.tb.stop() + self.tb.wait() - print snk2.data(); + # Get the vector of data from the vector sink + result_data = snk2.data() + + # Get the vector of data from the message sink + # Convert the message PMT as a pair into its vector + result_msg = dbg.get_message(0) + msg_vec = pmt.pmt_cdr(result_msg) + pmt.pmt_print(msg_vec) + + # Convert the PMT vector into a Python list + msg_data = [] + for i in xrange(16): + msg_data.append(pmt.pmt_u8vector_ref(msg_vec, i)) + + actual_data = 16*[0xFF,] + self.assertEqual(actual_data, list(result_data)) + self.assertEqual(actual_data, msg_data) if __name__ == '__main__': gr_unittest.run(test_pdu, "test_pdu.xml") |