From 386a7e207fd6f23fcd3d186f919ded394eb78461 Mon Sep 17 00:00:00 2001 From: ghostop14 <ghostop14@gmail.com> Date: Mon, 2 Mar 2020 17:43:31 -0500 Subject: gr-blocks: Add Msg Port to Delay Block These updates add the ability to set the block delay value with an asynchronous message. In this manner, blocks doing calculations such as those for DoA or antenna arrays can provide delay updates only when needed. --- gr-blocks/lib/delay_impl.cc | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'gr-blocks/lib/delay_impl.cc') diff --git a/gr-blocks/lib/delay_impl.cc b/gr-blocks/lib/delay_impl.cc index 6162c7b87a..97e3ecf92f 100644 --- a/gr-blocks/lib/delay_impl.cc +++ b/gr-blocks/lib/delay_impl.cc @@ -35,6 +35,9 @@ delay_impl::delay_impl(size_t itemsize, int delay) } set_dly(delay); d_delta = 0; + + message_port_register_in(pmt::mp("dly")); + set_msg_handler(pmt::mp("dly"), [this](pmt::pmt_t msg) { this->handle_msg(msg); }); } delay_impl::~delay_impl() {} @@ -53,7 +56,7 @@ void delay_impl::set_dly(int d) // protects from quickly-repeated calls to this function that // would end with d_delta=0. if (d != dly()) { - gr::thread::scoped_lock l(d_mutex_delay); + gr::thread::scoped_lock l(d_setlock); int old = dly(); set_history(d + 1); declare_sample_delay(history() - 1); @@ -61,12 +64,31 @@ void delay_impl::set_dly(int d) } } +void delay_impl::handle_msg(pmt::pmt_t msg) +{ + if (pmt::is_number(msg)) { + int value = pmt::to_long(msg); + set_dly(value); + } else { + if (pmt::is_pair(msg)) { + pmt::pmt_t data = pmt::cdr(msg); + if (pmt::is_number(data)) { + int value = pmt::to_long(data); + set_dly(value); + } else + GR_LOG_WARN( + d_logger, + "Delay message must be a number or a number pair. Ignoring value."); + } + } +} + int delay_impl::general_work(int noutput_items, gr_vector_int& ninput_items, gr_vector_const_void_star& input_items, gr_vector_void_star& output_items) { - gr::thread::scoped_lock l(d_mutex_delay); + gr::thread::scoped_lock l(d_setlock); assert(input_items.size() == output_items.size()); const char* iptr; -- cgit v1.2.3