diff options
author | Johnathan Corgan <johnathan@corganlabs.com> | 2015-11-12 09:12:04 -0800 |
---|---|---|
committer | Johnathan Corgan <johnathan@corganlabs.com> | 2015-11-12 09:12:04 -0800 |
commit | 2d0b64bf031c16a8c0e41a2dd9f446baf0a88492 (patch) | |
tree | 4ee569c2f844c11c8e962ebbd3987740b9232147 | |
parent | a18e480c8c751247d510480f7d0fca7c73775472 (diff) | |
parent | 36231753f1621324700a7f5acf0867daec3dedf4 (diff) |
Merge remote-tracking branch 'jdemel/analog-msg-port'
-rw-r--r-- | gr-analog/grc/analog_sig_source_x.xml | 5 | ||||
-rw-r--r-- | gr-analog/lib/sig_source_X_impl.cc.t | 5 | ||||
-rw-r--r-- | gr-analog/lib/sig_source_X_impl.h.t | 1 | ||||
-rwxr-xr-x | gr-analog/python/analog/qa_sig_source.py | 16 |
4 files changed, 25 insertions, 2 deletions
diff --git a/gr-analog/grc/analog_sig_source_x.xml b/gr-analog/grc/analog_sig_source_x.xml index b2cd8ad433..e3c587b254 100644 --- a/gr-analog/grc/analog_sig_source_x.xml +++ b/gr-analog/grc/analog_sig_source_x.xml @@ -97,6 +97,11 @@ <value>0</value> <type>$type.offset_type</type> </param> + <sink> + <name>freq</name> + <type>message</type> + <optional>1</optional> + </sink> <source> <name>out</name> <type>$type</type> diff --git a/gr-analog/lib/sig_source_X_impl.cc.t b/gr-analog/lib/sig_source_X_impl.cc.t index 5e0cace9c4..227d4ba46e 100644 --- a/gr-analog/lib/sig_source_X_impl.cc.t +++ b/gr-analog/lib/sig_source_X_impl.cc.t @@ -52,7 +52,10 @@ namespace gr { d_sampling_freq(sampling_freq), d_waveform(waveform), d_frequency(frequency), d_ampl(ampl), d_offset(offset) { - d_nco.set_freq(2 * M_PI * d_frequency / d_sampling_freq); + 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)); } @IMPL_NAME@::~@IMPL_NAME@() diff --git a/gr-analog/lib/sig_source_X_impl.h.t b/gr-analog/lib/sig_source_X_impl.h.t index 930a810a67..bd3609df16 100644 --- a/gr-analog/lib/sig_source_X_impl.h.t +++ b/gr-analog/lib/sig_source_X_impl.h.t @@ -59,6 +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(double frequency); void set_amplitude(double ampl); void set_offset(@TYPE@ offset); diff --git a/gr-analog/python/analog/qa_sig_source.py b/gr-analog/python/analog/qa_sig_source.py index 5ee4f24af8..8d050fa72b 100755 --- a/gr-analog/python/analog/qa_sig_source.py +++ b/gr-analog/python/analog/qa_sig_source.py @@ -21,7 +21,7 @@ # import math - +import pmt from gnuradio import gr, gr_unittest, analog, blocks class test_sig_source(gr_unittest.TestCase): @@ -156,5 +156,19 @@ class test_sig_source(gr_unittest.TestCase): dst_data = dst1.data() self.assertFloatTuplesAlmostEqual(expected_result, dst_data, 5) + def test_freq_msg(self): + src = analog.sig_source_c(8, analog.GR_SIN_WAVE, 1.0, 1.0) + op = blocks.head(gr.sizeof_gr_complex, 9) + snk = blocks.vector_sink_c() + self.tb.connect(src, op, snk) + self.assertAlmostEqual(src.frequency(), 1.0) + + frequency = 3.0 + src._post(pmt.to_pmt('freq'), pmt.from_double(frequency)) + self.tb.run() + + self.assertAlmostEqual(src.frequency(), frequency) + + if __name__ == '__main__': gr_unittest.run(test_sig_source, "test_sig_source.xml") |