diff options
author | Tom Rondeau <tom@trondeau.com> | 2016-03-05 13:40:38 -0500 |
---|---|---|
committer | Tom Rondeau <tom@trondeau.com> | 2016-03-08 14:32:24 -0500 |
commit | 4fb3c42740ac4080376cc6666b60580755aa3258 (patch) | |
tree | 05d3b5362a71e03cf293cd0e4248f52d8a304a1f /gr-analog/lib/sig_source_X_impl.cc.t | |
parent | c0381e0ec2ddde61ee4cfd23f2e431af4249874e (diff) |
analog: Adds ability to set the sig_source frequency using a key:value pair.
Uses same message structure as the UHD command and the QTGUI freq and
waterfall sinks of the key:value pair where the key must be
"freq".
Also does proper type checking on the PMT.
Diffstat (limited to 'gr-analog/lib/sig_source_X_impl.cc.t')
-rw-r--r-- | gr-analog/lib/sig_source_X_impl.cc.t | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/gr-analog/lib/sig_source_X_impl.cc.t b/gr-analog/lib/sig_source_X_impl.cc.t index 227d4ba46e..017177eae0 100644 --- a/gr-analog/lib/sig_source_X_impl.cc.t +++ b/gr-analog/lib/sig_source_X_impl.cc.t @@ -53,7 +53,7 @@ namespace gr { d_frequency(frequency), d_ampl(ampl), d_offset(offset) { set_frequency(frequency); - + message_port_register_in(pmt::mp("freq")); set_msg_handler(pmt::mp("freq"), boost::bind(&@IMPL_NAME@::set_frequency_msg, this, _1)); } @@ -62,6 +62,36 @@ namespace gr { { } + void + @IMPL_NAME@::set_frequency_msg(pmt::pmt_t msg) + { + // Accepts either a number that is assumed to be the new + // frequency or a key:value pair message where the key must be + // "freq" and the value is the new frequency. + + if(pmt::is_number(msg)) { + set_frequency(pmt::to_double(msg)); + } + else if(pmt::is_pair(msg)) { + pmt::pmt_t key = pmt::car(msg); + pmt::pmt_t val = pmt::cdr(msg); + if(pmt::eq(key, pmt::intern("freq"))) { + if(pmt::is_number(val)) { + set_frequency(pmt::to_double(val)); + } + } + else { + GR_LOG_WARN(d_logger, boost::format("Set Frequency Message must have " + "the key = 'freq'; got '%1%'.") \ + % pmt::write_string(key)); + } + } + else { + GR_LOG_WARN(d_logger, "Set Frequency Message must be either a number or a " + "key:value pair where the key is 'freq'."); + } + } + int @IMPL_NAME@::work(int noutput_items, gr_vector_const_void_star &input_items, |