[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] [gnuradio] 01/03: analog: Adds ability to set the sig_
From: |
git |
Subject: |
[Commit-gnuradio] [gnuradio] 01/03: analog: Adds ability to set the sig_source frequency using a key:value pair. |
Date: |
Wed, 9 Mar 2016 15:50:52 +0000 (UTC) |
This is an automated email from the git hooks/post-receive script.
jcorgan pushed a commit to branch master
in repository gnuradio.
commit 4fb3c42740ac4080376cc6666b60580755aa3258
Author: Tom Rondeau <address@hidden>
Date: Sat Mar 5 13:40:38 2016 -0500
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.
---
gr-analog/lib/sig_source_X_impl.cc.t | 32 +++++++++++++++++++++++++++++++-
gr-analog/lib/sig_source_X_impl.h.t | 2 +-
2 files changed, 32 insertions(+), 2 deletions(-)
diff --git a/gr-analog/lib/sig_source_X_impl.cc.t
b/gr-analog/lib/sig_source_X_impl.cc.t
index 227d4ba..017177e 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,
diff --git a/gr-analog/lib/sig_source_X_impl.h.t
b/gr-analog/lib/sig_source_X_impl.h.t
index bd3609d..f5dfd5c 100644
--- a/gr-analog/lib/sig_source_X_impl.h.t
+++ b/gr-analog/lib/sig_source_X_impl.h.t
@@ -59,7 +59,7 @@ namespace gr {
void set_sampling_freq(double sampling_freq);
void set_waveform(gr_waveform_t waveform);
- void set_frequency_msg(pmt::pmt_t msg){
set_frequency(pmt::to_double(msg)); };
+ void set_frequency_msg(pmt::pmt_t msg);
void set_frequency(double frequency);
void set_amplitude(double ampl);
void set_offset(@TYPE@ offset);