commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] [gnuradio] 12/23: qtgui: freq, waterfall, and sink blo


From: git
Subject: [Commit-gnuradio] [gnuradio] 12/23: qtgui: freq, waterfall, and sink blocks produce a frequency message when double-clicked. Also can take in a frequency message to adjust the x-axis.
Date: Thu, 26 Jun 2014 19:54:44 +0000 (UTC)

This is an automated email from the git hooks/post-receive script.

trondeau pushed a commit to branch master
in repository gnuradio.

commit 62e0abcdd071f533fe45b1e4c33d6d43e965ed97
Author: Tom Rondeau <address@hidden>
Date:   Thu Jun 26 12:53:12 2014 -0400

    qtgui: freq, waterfall, and sink blocks produce a frequency message when 
double-clicked. Also can take in a frequency message to adjust the x-axis.
---
 gr-qtgui/grc/qtgui_freq_sink_x.xml                 |  6 +++++
 gr-qtgui/grc/qtgui_sink_x.xml                      |  6 +++++
 gr-qtgui/grc/qtgui_waterfall_sink_x.xml            |  6 +++++
 gr-qtgui/include/gnuradio/qtgui/freq_sink_c.h      | 15 +++++++++++++
 gr-qtgui/include/gnuradio/qtgui/freq_sink_f.h      | 17 +++++++++++++-
 gr-qtgui/include/gnuradio/qtgui/sink_c.h           | 16 ++++++++++++-
 gr-qtgui/include/gnuradio/qtgui/sink_f.h           | 16 ++++++++++++-
 .../include/gnuradio/qtgui/spectrumUpdateEvents.h  | 14 ++++++++++++
 gr-qtgui/include/gnuradio/qtgui/waterfall_sink_c.h | 17 +++++++++++++-
 gr-qtgui/include/gnuradio/qtgui/waterfall_sink_f.h | 15 +++++++++++++
 gr-qtgui/lib/SpectrumGUIClass.cc                   |  7 +++---
 gr-qtgui/lib/freq_sink_c_impl.cc                   | 22 +++++++++++++++++-
 gr-qtgui/lib/freq_sink_c_impl.h                    |  4 ++++
 gr-qtgui/lib/freq_sink_f_impl.cc                   | 22 +++++++++++++++++-
 gr-qtgui/lib/freq_sink_f_impl.h                    |  4 ++++
 gr-qtgui/lib/freqdisplayform.cc                    |  6 +++++
 gr-qtgui/lib/sink_c_impl.cc                        | 20 ++++++++++++++++-
 gr-qtgui/lib/sink_c_impl.h                         |  4 ++++
 gr-qtgui/lib/sink_f_impl.cc                        | 17 +++++++++++++-
 gr-qtgui/lib/sink_f_impl.h                         |  4 ++++
 gr-qtgui/lib/spectrumUpdateEvents.cc               | 26 ++++++++++++++++++++++
 gr-qtgui/lib/spectrumdisplayform.cc                |  3 +++
 gr-qtgui/lib/waterfall_sink_c_impl.cc              | 22 +++++++++++++++++-
 gr-qtgui/lib/waterfall_sink_c_impl.h               |  4 ++++
 gr-qtgui/lib/waterfall_sink_f_impl.cc              | 22 +++++++++++++++++-
 gr-qtgui/lib/waterfall_sink_f_impl.h               |  4 ++++
 gr-qtgui/lib/waterfalldisplayform.cc               |  7 ++++++
 27 files changed, 313 insertions(+), 13 deletions(-)

diff --git a/gr-qtgui/grc/qtgui_freq_sink_x.xml 
b/gr-qtgui/grc/qtgui_freq_sink_x.xml
index b8bbbe1..29c0bc0 100644
--- a/gr-qtgui/grc/qtgui_freq_sink_x.xml
+++ b/gr-qtgui/grc/qtgui_freq_sink_x.xml
@@ -551,6 +551,12 @@ $(gui_hint()($win))</make>
     <nports>$nconnections</nports>
   </sink>
 
+  <sink>
+    <name>freq</name>
+    <type>message</type>
+    <optional>1</optional>
+  </sink>
+
   <source>
     <name>freq</name>
     <type>message</type>
diff --git a/gr-qtgui/grc/qtgui_sink_x.xml b/gr-qtgui/grc/qtgui_sink_x.xml
index c41468d..ab76403 100644
--- a/gr-qtgui/grc/qtgui_sink_x.xml
+++ b/gr-qtgui/grc/qtgui_sink_x.xml
@@ -174,12 +174,18 @@ Qt.QObject.connect(self._$(id)_win, 
Qt.SIGNAL("plotPointSelected(QPointF, int)")
                <type>raw</type>
                <hide>part</hide>
        </param>
+
        <sink>
                <name>in</name>
                <type>$type</type>
                <nports>$num_inputs</nports>
        </sink>
 
+  <sink>
+    <name>freq</name>
+    <type>message</type>
+    <optional>1</optional>
+  </sink>
 
   <source>
     <name>freq</name>
diff --git a/gr-qtgui/grc/qtgui_waterfall_sink_x.xml 
b/gr-qtgui/grc/qtgui_waterfall_sink_x.xml
index c340313..b194d37 100644
--- a/gr-qtgui/grc/qtgui_waterfall_sink_x.xml
+++ b/gr-qtgui/grc/qtgui_waterfall_sink_x.xml
@@ -393,6 +393,12 @@ $(gui_hint()($win))</make>
     <nports>$nconnections</nports>
   </sink>
 
+  <sink>
+    <name>freq</name>
+    <type>message</type>
+    <optional>1</optional>
+  </sink>
+
   <source>
     <name>freq</name>
     <type>message</type>
diff --git a/gr-qtgui/include/gnuradio/qtgui/freq_sink_c.h 
b/gr-qtgui/include/gnuradio/qtgui/freq_sink_c.h
index fcbfd72..c2f5068 100644
--- a/gr-qtgui/include/gnuradio/qtgui/freq_sink_c.h
+++ b/gr-qtgui/include/gnuradio/qtgui/freq_sink_c.h
@@ -46,6 +46,21 @@ namespace gr {
      * different color, and the \a set_title and \a set_color
      * functions can be used to change the lable and color for a given
      * input number.
+     *
+     * Message Ports:
+     *
+     * - freq (input):
+     *        Receives a PMT pair: (intern("freq"), double(frequency).
+     *        This is used to retune the center frequency of the
+     *        display's x-axis.
+     *
+     * - freq (output):
+     *        Produces a PMT pair with (intern("freq"), double(frequency).
+     *        When a user double-clicks on the display, the frequency
+     *        that the cursor is on is used to retune the x-axis scale
+     *        to recenter onto the clicked frequency. A message
+     *        containing the new frequency is also produced and can be
+     *        used by other blocks to update their frequency setting.
      */
     class QTGUI_API freq_sink_c : virtual public sync_block
     {
diff --git a/gr-qtgui/include/gnuradio/qtgui/freq_sink_f.h 
b/gr-qtgui/include/gnuradio/qtgui/freq_sink_f.h
index c49b9d9..bc7f0a6 100644
--- a/gr-qtgui/include/gnuradio/qtgui/freq_sink_f.h
+++ b/gr-qtgui/include/gnuradio/qtgui/freq_sink_f.h
@@ -34,7 +34,7 @@
 
 namespace gr {
   namespace qtgui {
-    
+
     /*!
      * \brief A graphical sink to display multiple signals in frequency.
      * \ingroup instrumentation_blk
@@ -46,6 +46,21 @@ namespace gr {
      * different color, and the \a set_title and \a set_color
      * functions can be used to change the lable and color for a given
      * input number.
+     *
+     * Message Ports:
+     *
+     * - freq (input):
+     *        Receives a PMT pair: (intern("freq"), double(frequency).
+     *        This is used to retune the center frequency of the
+     *        display's x-axis.
+     *
+     * - freq (output):
+     *        Produces a PMT pair with (intern("freq"), double(frequency).
+     *        When a user double-clicks on the display, the frequency
+     *        that the cursor is on is used to retune the x-axis scale
+     *        to recenter onto the clicked frequency. A message
+     *        containing the new frequency is also produced and can be
+     *        used by other blocks to update their frequency setting.
      */
     class QTGUI_API freq_sink_f : virtual public sync_block
     {
diff --git a/gr-qtgui/include/gnuradio/qtgui/sink_c.h 
b/gr-qtgui/include/gnuradio/qtgui/sink_c.h
index c9cb48b..74a9636 100644
--- a/gr-qtgui/include/gnuradio/qtgui/sink_c.h
+++ b/gr-qtgui/include/gnuradio/qtgui/sink_c.h
@@ -47,8 +47,22 @@ namespace gr {
      * spectrogram (waterfall), time domain I&Q, and constellation (I
      * vs. Q) plots. The plots may be turned off by setting the
      * appropriate boolean value in the constructor to False.
+     *
+     * Message Ports:
+     *
+     * - freq (input):
+     *        Receives a PMT pair: (intern("freq"), double(frequency).
+     *        This is used to retune the center frequency of the
+     *        display's x-axis.
+     *
+     * - freq (output):
+     *        Produces a PMT pair with (intern("freq"), double(frequency).
+     *        When a user double-clicks on the display, the frequency
+     *        that the cursor is on is used to retune the x-axis scale
+     *        to recenter onto the clicked frequency. A message
+     *        containing the new frequency is also produced and can be
+     *        used by other blocks to update their frequency setting.
      */
-
     class QTGUI_API sink_c : virtual public block
     {
     public:
diff --git a/gr-qtgui/include/gnuradio/qtgui/sink_f.h 
b/gr-qtgui/include/gnuradio/qtgui/sink_f.h
index 0e8004b..a371171 100644
--- a/gr-qtgui/include/gnuradio/qtgui/sink_f.h
+++ b/gr-qtgui/include/gnuradio/qtgui/sink_f.h
@@ -47,8 +47,22 @@ namespace gr {
      * spectrogram (waterfall), and time domain plots. The plots may be
      * turned off by setting the appropriate boolean value in the
      * constructor to False.
+     *
+     * Message Ports:
+     *
+     * - freq (input):
+     *        Receives a PMT pair: (intern("freq"), double(frequency).
+     *        This is used to retune the center frequency of the
+     *        display's x-axis.
+     *
+     * - freq (output):
+     *        Produces a PMT pair with (intern("freq"), double(frequency).
+     *        When a user double-clicks on the display, the frequency
+     *        that the cursor is on is used to retune the x-axis scale
+     *        to recenter onto the clicked frequency. A message
+     *        containing the new frequency is also produced and can be
+     *        used by other blocks to update their frequency setting.
      */
-
     class QTGUI_API sink_f : virtual public block
     {
     public:
diff --git a/gr-qtgui/include/gnuradio/qtgui/spectrumUpdateEvents.h 
b/gr-qtgui/include/gnuradio/qtgui/spectrumUpdateEvents.h
index d26f41e..7ab2d23 100644
--- a/gr-qtgui/include/gnuradio/qtgui/spectrumUpdateEvents.h
+++ b/gr-qtgui/include/gnuradio/qtgui/spectrumUpdateEvents.h
@@ -176,6 +176,20 @@ private:
 };
 
 
+class SetFreqEvent:public QEvent
+{
+public:
+  SetFreqEvent(const double, const double);
+  ~SetFreqEvent();
+  double getCenterFrequency() const;
+  double getBandwidth() const;
+
+private:
+  double _centerFrequency;
+  double _bandwidth;
+};
+
+
 /********************************************************************/
 
 
diff --git a/gr-qtgui/include/gnuradio/qtgui/waterfall_sink_c.h 
b/gr-qtgui/include/gnuradio/qtgui/waterfall_sink_c.h
index 17a6569..657bbae 100644
--- a/gr-qtgui/include/gnuradio/qtgui/waterfall_sink_c.h
+++ b/gr-qtgui/include/gnuradio/qtgui/waterfall_sink_c.h
@@ -52,6 +52,21 @@ namespace gr {
      * would love to see them. Otherwise, to display multiple signals
      * here, it's probably best to sum the signals together and
      * connect that here.
+     *
+     * Message Ports:
+     *
+     * - freq (input):
+     *        Receives a PMT pair: (intern("freq"), double(frequency).
+     *        This is used to retune the center frequency of the
+     *        display's x-axis.
+     *
+     * - freq (output):
+     *        Produces a PMT pair with (intern("freq"), double(frequency).
+     *        When a user double-clicks on the display, the frequency
+     *        that the cursor is on is used to retune the x-axis scale
+     *        to recenter onto the clicked frequency. A message
+     *        containing the new frequency is also produced and can be
+     *        used by other blocks to update their frequency setting.
      */
     class QTGUI_API waterfall_sink_c : virtual public sync_block
     {
@@ -87,7 +102,7 @@ namespace gr {
 #endif
 
       virtual void clear_data() = 0;
-      
+
       virtual void set_fft_size(const int fftsize) = 0;
       virtual int fft_size() const = 0;
       virtual void set_fft_average(const float fftavg) = 0;
diff --git a/gr-qtgui/include/gnuradio/qtgui/waterfall_sink_f.h 
b/gr-qtgui/include/gnuradio/qtgui/waterfall_sink_f.h
index 3877158..c8fa9a0 100644
--- a/gr-qtgui/include/gnuradio/qtgui/waterfall_sink_f.h
+++ b/gr-qtgui/include/gnuradio/qtgui/waterfall_sink_f.h
@@ -52,6 +52,21 @@ namespace gr {
      * would love to see them. Otherwise, to display multiple signals
      * here, it's probably best to sum the signals together and
      * connect that here.
+     *
+     * Message Ports:
+     *
+     * - freq (input):
+     *        Receives a PMT pair: (intern("freq"), double(frequency).
+     *        This is used to retune the center frequency of the
+     *        display's x-axis.
+     *
+     * - freq (output):
+     *        Produces a PMT pair with (intern("freq"), double(frequency).
+     *        When a user double-clicks on the display, the frequency
+     *        that the cursor is on is used to retune the x-axis scale
+     *        to recenter onto the clicked frequency. A message
+     *        containing the new frequency is also produced and can be
+     *        used by other blocks to update their frequency setting.
      */
     class QTGUI_API waterfall_sink_f : virtual public sync_block
     {
diff --git a/gr-qtgui/lib/SpectrumGUIClass.cc b/gr-qtgui/lib/SpectrumGUIClass.cc
index 98feec5..5272d8a 100644
--- a/gr-qtgui/lib/SpectrumGUIClass.cc
+++ b/gr-qtgui/lib/SpectrumGUIClass.cc
@@ -192,9 +192,10 @@ SpectrumGUIClass::setFrequencyRange(const double 
centerFreq,
   _startFrequency = startFreq;
   _stopFrequency = stopFreq;
 
-  _spectrumDisplayForm->setFrequencyRange(_centerFrequency,
-                                         _startFrequency,
-                                         _stopFrequency);
+  qApp->postEvent(_spectrumDisplayForm,
+                  new SpectrumFrequencyRangeEvent(_centerFrequency,
+                                                  _startFrequency,
+                                                  _stopFrequency));
 }
 
 double
diff --git a/gr-qtgui/lib/freq_sink_c_impl.cc b/gr-qtgui/lib/freq_sink_c_impl.cc
index da8a750..a95814e 100644
--- a/gr-qtgui/lib/freq_sink_c_impl.cc
+++ b/gr-qtgui/lib/freq_sink_c_impl.cc
@@ -72,6 +72,9 @@ namespace gr {
       // setup output message port to post frequency when display is
       // double-clicked
       message_port_register_out(pmt::mp("freq"));
+      message_port_register_in(pmt::mp("freq"));
+      set_msg_handler(pmt::mp("freq"),
+                      boost::bind(&freq_sink_c_impl::handle_set_freq, this, 
_1));
 
       d_main_gui = NULL;
 
@@ -453,7 +456,24 @@ namespace gr {
     {
       if(d_main_gui->checkClicked()) {
         d_center_freq = d_main_gui->getClickedFreq();
-        message_port_pub(pmt::mp("freq"), pmt::from_double(d_center_freq));
+        double norm_freq = d_center_freq / d_bandwidth;
+        message_port_pub(pmt::mp("freq"),
+                         pmt::cons(pmt::mp("freq"),
+                                   pmt::from_double(norm_freq)));
+      }
+    }
+
+    void
+    freq_sink_c_impl::handle_set_freq(pmt::pmt_t msg)
+    {
+      if(pmt::is_pair(msg)) {
+        pmt::pmt_t x = pmt::cdr(msg);
+        if(pmt::is_real(x)) {
+          double freq = pmt::to_double(x);
+          d_center_freq = freq*d_bandwidth;
+          d_qApplication->postEvent(d_main_gui,
+                                    new SetFreqEvent(d_center_freq, 
d_bandwidth));
+        }
       }
     }
 
diff --git a/gr-qtgui/lib/freq_sink_c_impl.h b/gr-qtgui/lib/freq_sink_c_impl.h
index 8cc5438..4beea57 100644
--- a/gr-qtgui/lib/freq_sink_c_impl.h
+++ b/gr-qtgui/lib/freq_sink_c_impl.h
@@ -73,6 +73,10 @@ namespace gr {
       void check_clicked();
       void fft(float *data_out, const gr_complex *data_in, int size);
 
+      // Handles message input port for setting new center frequency.
+      // The message is a PMT pair (intern('freq'), double(frequency)).
+      void handle_set_freq(pmt::pmt_t msg);
+
     public:
       freq_sink_c_impl(int size, int wintype,
                       double fc, double bw,
diff --git a/gr-qtgui/lib/freq_sink_f_impl.cc b/gr-qtgui/lib/freq_sink_f_impl.cc
index 0b564d5..80a09a1 100644
--- a/gr-qtgui/lib/freq_sink_f_impl.cc
+++ b/gr-qtgui/lib/freq_sink_f_impl.cc
@@ -72,6 +72,9 @@ namespace gr {
       // setup output message port to post frequency when display is
       // double-clicked
       message_port_register_out(pmt::mp("freq"));
+      message_port_register_in(pmt::mp("freq"));
+      set_msg_handler(pmt::mp("freq"),
+                      boost::bind(&freq_sink_f_impl::handle_set_freq, this, 
_1));
 
       d_main_gui = NULL;
 
@@ -456,7 +459,24 @@ namespace gr {
     {
       if(d_main_gui->checkClicked()) {
         d_center_freq = d_main_gui->getClickedFreq();
-        message_port_pub(pmt::mp("freq"), pmt::from_double(d_center_freq));
+        double norm_freq = d_center_freq / d_bandwidth;
+        message_port_pub(pmt::mp("freq"),
+                         pmt::cons(pmt::mp("freq"),
+                                   pmt::from_double(norm_freq)));
+      }
+    }
+
+    void
+    freq_sink_f_impl::handle_set_freq(pmt::pmt_t msg)
+    {
+      if(pmt::is_pair(msg)) {
+        pmt::pmt_t x = pmt::cdr(msg);
+        if(pmt::is_real(x)) {
+          double freq = pmt::to_double(x);
+          d_center_freq = freq*d_bandwidth;
+          d_qApplication->postEvent(d_main_gui,
+                                    new SetFreqEvent(d_center_freq, 
d_bandwidth));
+        }
       }
     }
 
diff --git a/gr-qtgui/lib/freq_sink_f_impl.h b/gr-qtgui/lib/freq_sink_f_impl.h
index e0fdcf9..74b95c5 100644
--- a/gr-qtgui/lib/freq_sink_f_impl.h
+++ b/gr-qtgui/lib/freq_sink_f_impl.h
@@ -73,6 +73,10 @@ namespace gr {
       void check_clicked();
       void fft(float *data_out, const float *data_in, int size);
 
+      // Handles message input port for setting new center frequency.
+      // The message is a PMT pair (intern('freq'), double(frequency)).
+      void handle_set_freq(pmt::pmt_t msg);
+
     public:
       freq_sink_f_impl(int size, int wintype,
                       double fc, double bw,
diff --git a/gr-qtgui/lib/freqdisplayform.cc b/gr-qtgui/lib/freqdisplayform.cc
index 6d2f9b9..537325f 100644
--- a/gr-qtgui/lib/freqdisplayform.cc
+++ b/gr-qtgui/lib/freqdisplayform.cc
@@ -92,6 +92,10 @@ FreqDisplayForm::customEvent( QEvent * e)
   if(e->type() == FreqUpdateEvent::Type()) {
     newData(e);
   }
+  else if(e->type() == SpectrumFrequencyRangeEventType) {
+    SetFreqEvent *fevent = (SetFreqEvent*)e;
+    setFrequencyRange(fevent->getCenterFrequency(), fevent->getBandwidth());
+  }
 }
 
 int
@@ -155,6 +159,8 @@ FreqDisplayForm::setFrequencyRange(const double centerfreq,
   d_center_freq = centerfreq;
   d_samp_rate = bandwidth;
 
+  std::cerr << "FDISP NEW FREQ: " << centerfreq << std::endl;
+
   getPlot()->setFrequencyRange(centerfreq, bandwidth,
                               d_units, strunits[iunit]);
 }
diff --git a/gr-qtgui/lib/sink_c_impl.cc b/gr-qtgui/lib/sink_c_impl.cc
index b73ab47..01e60a6 100644
--- a/gr-qtgui/lib/sink_c_impl.cc
+++ b/gr-qtgui/lib/sink_c_impl.cc
@@ -76,6 +76,9 @@ namespace gr {
       // setup output message port to post frequency when display is
       // double-clicked
       message_port_register_out(pmt::mp("freq"));
+      message_port_register_in(pmt::mp("freq"));
+      set_msg_handler(pmt::mp("freq"),
+                      boost::bind(&sink_c_impl::handle_set_freq, this, _1));
 
       d_main_gui = NULL;
 
@@ -327,7 +330,22 @@ namespace gr {
     {
       if(d_main_gui->checkClicked()) {
         d_center_freq = d_main_gui->getClickedFreq();
-        message_port_pub(pmt::mp("freq"), pmt::from_double(d_center_freq));
+        double norm_freq = d_center_freq / d_bandwidth;
+        message_port_pub(pmt::mp("freq"),
+                         pmt::cons(pmt::mp("freq"),
+                                   pmt::from_double(norm_freq)));
+      }
+    }
+
+    void
+    sink_c_impl::handle_set_freq(pmt::pmt_t msg)
+    {
+      if(pmt::is_pair(msg)) {
+        pmt::pmt_t x = pmt::cdr(msg);
+        if(pmt::is_real(x)) {
+          double freq = pmt::to_double(x);
+          set_frequency_range(freq*d_bandwidth, d_bandwidth);
+        }
       }
     }
 
diff --git a/gr-qtgui/lib/sink_c_impl.h b/gr-qtgui/lib/sink_c_impl.h
index 22b8b21..0628bc2 100644
--- a/gr-qtgui/lib/sink_c_impl.h
+++ b/gr-qtgui/lib/sink_c_impl.h
@@ -70,6 +70,10 @@ namespace gr {
       void check_clicked();
       void fft(float *data_out, const gr_complex *data_in, int size);
 
+      // Handles message input port for setting new center frequency.
+      // The message is a PMT pair (intern('freq'), double(frequency)).
+      void handle_set_freq(pmt::pmt_t msg);
+
     public:
       sink_c_impl(int fftsize, int wintype,
                  double fc, double bw,
diff --git a/gr-qtgui/lib/sink_f_impl.cc b/gr-qtgui/lib/sink_f_impl.cc
index 960acb3..28ba314 100644
--- a/gr-qtgui/lib/sink_f_impl.cc
+++ b/gr-qtgui/lib/sink_f_impl.cc
@@ -316,7 +316,22 @@ namespace gr {
     {
       if(d_main_gui->checkClicked()) {
         d_center_freq = d_main_gui->getClickedFreq();
-        message_port_pub(pmt::mp("freq"), pmt::from_double(d_center_freq));
+        double norm_freq = d_center_freq / d_bandwidth;
+        message_port_pub(pmt::mp("freq"),
+                         pmt::cons(pmt::mp("freq"),
+                                   pmt::from_double(norm_freq)));
+      }
+    }
+
+    void
+    sink_f_impl::handle_set_freq(pmt::pmt_t msg)
+    {
+      if(pmt::is_pair(msg)) {
+        pmt::pmt_t x = pmt::cdr(msg);
+        if(pmt::is_real(x)) {
+          double freq = pmt::to_double(x);
+          set_frequency_range(freq*d_bandwidth, d_bandwidth);
+        }
       }
     }
 
diff --git a/gr-qtgui/lib/sink_f_impl.h b/gr-qtgui/lib/sink_f_impl.h
index a547da3..5b39d82 100644
--- a/gr-qtgui/lib/sink_f_impl.h
+++ b/gr-qtgui/lib/sink_f_impl.h
@@ -68,6 +68,10 @@ namespace gr {
       void check_clicked();
       void fft(float *data_out, const float *data_in, int size);
 
+      // Handles message input port for setting new center frequency.
+      // The message is a PMT pair (intern('freq'), double(frequency)).
+      void handle_set_freq(pmt::pmt_t msg);
+
     public:
       sink_f_impl(int fftsize, int wintype,
                  double fc, double bw,
diff --git a/gr-qtgui/lib/spectrumUpdateEvents.cc 
b/gr-qtgui/lib/spectrumUpdateEvents.cc
index f48e079..1294587 100644
--- a/gr-qtgui/lib/spectrumUpdateEvents.cc
+++ b/gr-qtgui/lib/spectrumUpdateEvents.cc
@@ -296,6 +296,32 @@ FreqUpdateEvent::getNumDataPoints() const
 }
 
 
+
+SetFreqEvent::SetFreqEvent(const double centerFreq,
+                           const double bandwidth)
+  : QEvent(QEvent::Type(SpectrumFrequencyRangeEventType))
+{
+  _centerFrequency = centerFreq;
+  _bandwidth = bandwidth;
+}
+
+SetFreqEvent::~SetFreqEvent()
+{
+}
+
+double
+SetFreqEvent::getCenterFrequency() const
+{
+  return _centerFrequency;
+}
+
+double
+SetFreqEvent::getBandwidth() const
+{
+  return _bandwidth;
+}
+
+
 /***************************************************************************/
 
 
diff --git a/gr-qtgui/lib/spectrumdisplayform.cc 
b/gr-qtgui/lib/spectrumdisplayform.cc
index 6dc38a2..ca9d981 100644
--- a/gr-qtgui/lib/spectrumdisplayform.cc
+++ b/gr-qtgui/lib/spectrumdisplayform.cc
@@ -31,6 +31,9 @@ SpectrumDisplayForm::SpectrumDisplayForm(QWidget* parent)
 {
   setupUi(this);
 
+  d_clicked = false;
+  d_clicked_freq = 0;
+
   _systemSpecifiedFlag = false;
   _intValidator = new QIntValidator(this);
   _intValidator->setBottom(0);
diff --git a/gr-qtgui/lib/waterfall_sink_c_impl.cc 
b/gr-qtgui/lib/waterfall_sink_c_impl.cc
index 6147b31..b4d6b2c 100644
--- a/gr-qtgui/lib/waterfall_sink_c_impl.cc
+++ b/gr-qtgui/lib/waterfall_sink_c_impl.cc
@@ -72,6 +72,9 @@ namespace gr {
       // setup output message port to post frequency when display is
       // double-clicked
       message_port_register_out(pmt::mp("freq"));
+      message_port_register_in(pmt::mp("freq"));
+      set_msg_handler(pmt::mp("freq"),
+                      boost::bind(&waterfall_sink_c_impl::handle_set_freq, 
this, _1));
 
       d_main_gui = NULL;
 
@@ -427,7 +430,24 @@ namespace gr {
     {
       if(d_main_gui->checkClicked()) {
         d_center_freq = d_main_gui->getClickedFreq();
-        message_port_pub(pmt::mp("freq"), pmt::from_double(d_center_freq));
+        double norm_freq = d_center_freq / d_bandwidth;
+        message_port_pub(pmt::mp("freq"),
+                         pmt::cons(pmt::mp("freq"),
+                                   pmt::from_double(norm_freq)));
+      }
+    }
+
+    void
+    waterfall_sink_c_impl::handle_set_freq(pmt::pmt_t msg)
+    {
+      if(pmt::is_pair(msg)) {
+        pmt::pmt_t x = pmt::cdr(msg);
+        if(pmt::is_real(x)) {
+          double freq = pmt::to_double(x);
+          d_center_freq = freq*d_bandwidth;
+          d_qApplication->postEvent(d_main_gui,
+                                    new SetFreqEvent(d_center_freq, 
d_bandwidth));
+        }
       }
     }
 
diff --git a/gr-qtgui/lib/waterfall_sink_c_impl.h 
b/gr-qtgui/lib/waterfall_sink_c_impl.h
index 1e5ee17..ecff5a9 100644
--- a/gr-qtgui/lib/waterfall_sink_c_impl.h
+++ b/gr-qtgui/lib/waterfall_sink_c_impl.h
@@ -71,6 +71,10 @@ namespace gr {
       void check_clicked();
       void fft(float *data_out, const gr_complex *data_in, int size);
 
+      // Handles message input port for setting new center frequency.
+      // The message is a PMT pair (intern('freq'), double(frequency)).
+      void handle_set_freq(pmt::pmt_t msg);
+
     public:
       waterfall_sink_c_impl(int size, int wintype,
                            double fc, double bw,
diff --git a/gr-qtgui/lib/waterfall_sink_f_impl.cc 
b/gr-qtgui/lib/waterfall_sink_f_impl.cc
index 27de72e..32f16eb 100644
--- a/gr-qtgui/lib/waterfall_sink_f_impl.cc
+++ b/gr-qtgui/lib/waterfall_sink_f_impl.cc
@@ -71,6 +71,9 @@ namespace gr {
       // setup output message port to post frequency when display is
       // double-clicked
       message_port_register_out(pmt::mp("freq"));
+      message_port_register_in(pmt::mp("freq"));
+      set_msg_handler(pmt::mp("freq"),
+                      boost::bind(&waterfall_sink_f_impl::handle_set_freq, 
this, _1));
 
       d_main_gui = NULL;
 
@@ -428,7 +431,24 @@ namespace gr {
     {
       if(d_main_gui->checkClicked()) {
         d_center_freq = d_main_gui->getClickedFreq();
-        message_port_pub(pmt::mp("freq"), pmt::from_double(d_center_freq));
+        double norm_freq = d_center_freq / d_bandwidth;
+        message_port_pub(pmt::mp("freq"),
+                         pmt::cons(pmt::mp("freq"),
+                                   pmt::from_double(norm_freq)));
+      }
+    }
+
+    void
+    waterfall_sink_f_impl::handle_set_freq(pmt::pmt_t msg)
+    {
+      if(pmt::is_pair(msg)) {
+        pmt::pmt_t x = pmt::cdr(msg);
+        if(pmt::is_real(x)) {
+          double freq = pmt::to_double(x);
+          d_center_freq = freq*d_bandwidth;
+          d_qApplication->postEvent(d_main_gui,
+                                    new SetFreqEvent(d_center_freq, 
d_bandwidth));
+        }
       }
     }
 
diff --git a/gr-qtgui/lib/waterfall_sink_f_impl.h 
b/gr-qtgui/lib/waterfall_sink_f_impl.h
index db86b6a..86cf0dc 100644
--- a/gr-qtgui/lib/waterfall_sink_f_impl.h
+++ b/gr-qtgui/lib/waterfall_sink_f_impl.h
@@ -71,6 +71,10 @@ namespace gr {
       void check_clicked();
       void fft(float *data_out, const float *data_in, int size);
 
+      // Handles message input port for setting new center frequency.
+      // The message is a PMT pair (intern('freq'), double(frequency)).
+      void handle_set_freq(pmt::pmt_t msg);
+
     public:
       waterfall_sink_f_impl(int size, int wintype,
                            double fc, double bw,
diff --git a/gr-qtgui/lib/waterfalldisplayform.cc 
b/gr-qtgui/lib/waterfalldisplayform.cc
index 3f7cf79..fa6c2f7 100644
--- a/gr-qtgui/lib/waterfalldisplayform.cc
+++ b/gr-qtgui/lib/waterfalldisplayform.cc
@@ -46,6 +46,9 @@ WaterfallDisplayForm::WaterfallDisplayForm(int nplots, 
QWidget* parent)
   d_min_val =  1000;
   d_max_val = -1000;
 
+  d_clicked = false;
+  d_clicked_freq = 0;
+
   // We don't use the normal menus that are part of the displayform.
   // Clear them out to get rid of their resources.
   for(int i = 0; i < nplots; i++) {
@@ -136,6 +139,10 @@ WaterfallDisplayForm::customEvent( QEvent * e)
   if(e->type() == WaterfallUpdateEvent::Type()) {
     newData(e);
   }
+  else if(e->type() == SpectrumFrequencyRangeEventType) {
+    SetFreqEvent *fevent = (SetFreqEvent*)e;
+    setFrequencyRange(fevent->getCenterFrequency(), fevent->getBandwidth());
+  }
 }
 
 int



reply via email to

[Prev in Thread] Current Thread [Next in Thread]