summaryrefslogtreecommitdiff
path: root/gr-blocks/lib
diff options
context:
space:
mode:
authorghostop14 <ghostop14@gmail.com>2020-03-02 17:43:31 -0500
committerdevnulling <devnulling@users.noreply.github.com>2020-03-29 09:37:30 -0700
commit386a7e207fd6f23fcd3d186f919ded394eb78461 (patch)
treec524cb69b51c7f09c9d4458dd880932679022ed7 /gr-blocks/lib
parent3b30c5da8b464f32b762d750be2896149f81ea28 (diff)
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.
Diffstat (limited to 'gr-blocks/lib')
-rw-r--r--gr-blocks/lib/delay_impl.cc26
-rw-r--r--gr-blocks/lib/delay_impl.h2
2 files changed, 25 insertions, 3 deletions
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;
diff --git a/gr-blocks/lib/delay_impl.h b/gr-blocks/lib/delay_impl.h
index c58de83668..2b39e64ce5 100644
--- a/gr-blocks/lib/delay_impl.h
+++ b/gr-blocks/lib/delay_impl.h
@@ -24,7 +24,7 @@ private:
const size_t d_itemsize;
int d_delta;
- gr::thread::mutex d_mutex_delay;
+ void handle_msg(pmt::pmt_t msg);
public:
delay_impl(size_t itemsize, int delay);