summaryrefslogtreecommitdiff
path: root/gr-blocks/lib
diff options
context:
space:
mode:
authorJacob Gilbert <mrjacobagilbert@gmail.com>2020-08-27 08:11:33 -0700
committermormj <34754695+mormj@users.noreply.github.com>2020-10-24 17:45:47 -0400
commit9248b29768c7810f029a1188726b2ad05141f382 (patch)
treef67f4ffecb79f4bf962c30f2f134beac86c111ae /gr-blocks/lib
parent88c11a8cf3c437ed0e1a477ce30e7cc01ebc2bfd (diff)
blocks: improvements to the message_debug block
aggregates the data to be printed into a stringstream so that it is printed at the same time reducing debug information becoming muddled between competing cout statements. this change also provides an argument to this block to disable the printing of PDU uniform vectors which are often not needed for debug purposes
Diffstat (limited to 'gr-blocks/lib')
-rw-r--r--gr-blocks/lib/message_debug_impl.cc93
-rw-r--r--gr-blocks/lib/message_debug_impl.h5
2 files changed, 62 insertions, 36 deletions
diff --git a/gr-blocks/lib/message_debug_impl.cc b/gr-blocks/lib/message_debug_impl.cc
index 299dd47d09..fa0f66d973 100644
--- a/gr-blocks/lib/message_debug_impl.cc
+++ b/gr-blocks/lib/message_debug_impl.cc
@@ -20,16 +20,36 @@
namespace gr {
namespace blocks {
-message_debug::sptr message_debug::make()
+message_debug::sptr message_debug::make(bool en_uvec)
{
- return gnuradio::make_block_sptr<message_debug_impl>();
+ return gnuradio::make_block_sptr<message_debug_impl>(en_uvec);
}
+message_debug_impl::message_debug_impl(bool en_uvec)
+ : block("message_debug", io_signature::make(0, 0, 0), io_signature::make(0, 0, 0)),
+ d_en_uvec(en_uvec)
+{
+ message_port_register_in(pmt::mp("print"));
+ set_msg_handler(pmt::mp("print"), [this](pmt::pmt_t msg) { this->print(msg); });
+
+ message_port_register_in(pmt::mp("store"));
+ set_msg_handler(pmt::mp("store"), [this](pmt::pmt_t msg) { this->store(msg); });
+
+ message_port_register_in(pmt::mp("print_pdu"));
+ set_msg_handler(pmt::mp("print_pdu"),
+ [this](pmt::pmt_t msg) { this->print_pdu(msg); });
+}
+
+message_debug_impl::~message_debug_impl() {}
+
void message_debug_impl::print(pmt::pmt_t msg)
{
- std::cout << "******* MESSAGE DEBUG PRINT ********\n";
- pmt::print(msg);
- std::cout << "************************************\n";
+ std::stringstream sout;
+
+ sout << "******* MESSAGE DEBUG PRINT ********" << std::endl
+ << pmt::write_string(msg) << std::endl
+ << "************************************" << std::endl;
+ std::cout << sout.str();
}
void message_debug_impl::store(pmt::pmt_t msg)
@@ -40,25 +60,44 @@ void message_debug_impl::store(pmt::pmt_t msg)
void message_debug_impl::print_pdu(pmt::pmt_t pdu)
{
+ if (pmt::is_null(pdu) || !pmt::is_pair(pdu)) {
+ return;
+ }
+
+ std::stringstream sout;
+
pmt::pmt_t meta = pmt::car(pdu);
pmt::pmt_t vector = pmt::cdr(pdu);
- std::cout << "* MESSAGE DEBUG PRINT PDU VERBOSE *\n";
- pmt::print(meta);
- size_t len = pmt::blob_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;
+ sout << "***** VERBOSE PDU DEBUG PRINT ******" << std::endl
+ << pmt::write_string(meta) << std::endl;
+
+ if (pmt::is_uniform_vector(vector)) {
+ size_t len = pmt::blob_length(vector);
+ if (d_en_uvec) {
+ sout << "pdu length = " << len << " bytes" << std::endl
+ << "pdu vector 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) {
+ sout << std::hex << std::setw(4) << std::setfill('0')
+ << static_cast<unsigned int>(i) << ": ";
+ for (size_t j = i; j < std::min(i + 16, len); j++) {
+ sout << std::hex << std::setw(2) << std::setfill('0')
+ << static_cast<unsigned int>(d[j]) << " ";
+ }
+ sout << std::endl;
+ }
+ } else {
+ sout << "pdu length = " << len << " bytes (printing disabled)" << std::endl;
+ }
+ } else {
+ sout << "Message CDR is not a uniform vector..." << std::endl;
}
- std::cout << "***********************************\n";
+ sout << "************************************" << std::endl;
+ std::cout << sout.str();
}
int message_debug_impl::num_messages() { return (int)d_messages.size(); }
@@ -74,21 +113,5 @@ pmt::pmt_t message_debug_impl::get_message(int i)
return d_messages[i];
}
-message_debug_impl::message_debug_impl()
- : block("message_debug", io_signature::make(0, 0, 0), io_signature::make(0, 0, 0))
-{
- message_port_register_in(pmt::mp("print"));
- set_msg_handler(pmt::mp("print"), [this](pmt::pmt_t msg) { this->print(msg); });
-
- message_port_register_in(pmt::mp("store"));
- set_msg_handler(pmt::mp("store"), [this](pmt::pmt_t msg) { this->store(msg); });
-
- message_port_register_in(pmt::mp("print_pdu"));
- set_msg_handler(pmt::mp("print_pdu"),
- [this](pmt::pmt_t msg) { this->print_pdu(msg); });
-}
-
-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
index 94db67f68d..2d61e18044 100644
--- a/gr-blocks/lib/message_debug_impl.h
+++ b/gr-blocks/lib/message_debug_impl.h
@@ -22,6 +22,8 @@ namespace blocks {
class message_debug_impl : public message_debug
{
private:
+ bool d_en_uvec;
+
/*!
* \brief Messages received in this port are printed to stdout.
*
@@ -63,11 +65,12 @@ private:
std::vector<pmt::pmt_t> d_messages;
public:
- message_debug_impl();
+ message_debug_impl(bool en_uvec);
~message_debug_impl();
int num_messages();
pmt::pmt_t get_message(int i);
+ void set_vector_print(bool en) { d_en_uvec = en; };
};
} /* namespace blocks */