commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] r10547 - in gnuradio/branches/developers/jblum/gui_gut


From: jblum
Subject: [Commit-gnuradio] r10547 - in gnuradio/branches/developers/jblum/gui_guts: gnuradio-core/src/lib/io gr-wxgui/src/python gr-wxgui/src/python/plotter
Date: Sun, 1 Mar 2009 17:38:50 -0700 (MST)

Author: jblum
Date: 2009-03-01 17:38:49 -0700 (Sun, 01 Mar 2009)
New Revision: 10547

Added:
   
gnuradio/branches/developers/jblum/gui_guts/gnuradio-core/src/lib/io/gr_histo_sink.i
   
gnuradio/branches/developers/jblum/gui_guts/gnuradio-core/src/lib/io/gr_histo_sink_f.cc
   
gnuradio/branches/developers/jblum/gui_guts/gnuradio-core/src/lib/io/gr_histo_sink_f.h
   
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/histo_window.py
   
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/histosink_gl.py
   
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/plotter/bar_plotter.py
Modified:
   
gnuradio/branches/developers/jblum/gui_guts/gnuradio-core/src/lib/io/Makefile.am
   
gnuradio/branches/developers/jblum/gui_guts/gnuradio-core/src/lib/io/gr_oscope_guts.cc
   gnuradio/branches/developers/jblum/gui_guts/gnuradio-core/src/lib/io/io.i
   gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/Makefile.am
   
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/const_window.py
   gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/constants.py
   gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/fft_window.py
   
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/plotter/Makefile.am
   
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/plotter/__init__.py
   
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/plotter/plotter_base.py
   
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/scope_window.py
   
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/waterfall_window.py
Log:
WIP! Histogram sink backend.
Histogram GUI window.
Bar graph GL plotter.



Modified: 
gnuradio/branches/developers/jblum/gui_guts/gnuradio-core/src/lib/io/Makefile.am
===================================================================
--- 
gnuradio/branches/developers/jblum/gui_guts/gnuradio-core/src/lib/io/Makefile.am
    2009-03-01 19:44:19 UTC (rev 10546)
+++ 
gnuradio/branches/developers/jblum/gui_guts/gnuradio-core/src/lib/io/Makefile.am
    2009-03-02 00:38:49 UTC (rev 10547)
@@ -33,6 +33,7 @@
        gr_file_source.cc               \
        gr_file_descriptor_sink.cc      \
        gr_file_descriptor_source.cc    \
+       gr_histo_sink_f.cc              \
        gr_message_sink.cc              \
        gr_message_source.cc            \
        gr_oscope_guts.cc               \
@@ -64,6 +65,7 @@
        gr_file_source.h                \
        gr_file_descriptor_sink.h       \
        gr_file_descriptor_source.h     \
+       gr_histo_sink_f.h               \
        gr_message_sink.h               \
        gr_message_source.h             \
        gr_oscope_guts.h                \
@@ -101,6 +103,7 @@
        gr_file_source.i                \
        gr_file_descriptor_sink.i       \
        gr_file_descriptor_source.i     \
+       gr_histo_sink.i                 \
        gr_message_sink.i               \
        gr_message_source.i             \
        gr_oscope_sink.i                \

Added: 
gnuradio/branches/developers/jblum/gui_guts/gnuradio-core/src/lib/io/gr_histo_sink.i
===================================================================
--- 
gnuradio/branches/developers/jblum/gui_guts/gnuradio-core/src/lib/io/gr_histo_sink.i
                                (rev 0)
+++ 
gnuradio/branches/developers/jblum/gui_guts/gnuradio-core/src/lib/io/gr_histo_sink.i
        2009-03-02 00:38:49 UTC (rev 10547)
@@ -0,0 +1,43 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2009 Free Software Foundation, Inc.
+ * 
+ * This file is part of GNU Radio
+ * 
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ * 
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Radio; see the file COPYING.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+
+GR_SWIG_BLOCK_MAGIC(gr,histo_sink_f)
+
+gr_histo_sink_f_sptr gr_make_histo_sink_f (gr_msg_queue_sptr msgq);
+
+class gr_histo_sink_f : public gr_sync_block
+{
+public:
+  ~gr_histo_sink_f (void);
+
+  unsigned int get_frame_size(void);
+  unsigned int get_num_bins(void);
+  float get_maximum(void);
+  float get_minimum(void);
+
+  void set_frame_size(unsigned int frame_size);
+  void set_num_bins(unsigned int num_bins);
+  void set_maximum(float maximum);
+  void set_minimum(float minimum);
+
+};

Added: 
gnuradio/branches/developers/jblum/gui_guts/gnuradio-core/src/lib/io/gr_histo_sink_f.cc
===================================================================
--- 
gnuradio/branches/developers/jblum/gui_guts/gnuradio-core/src/lib/io/gr_histo_sink_f.cc
                             (rev 0)
+++ 
gnuradio/branches/developers/jblum/gui_guts/gnuradio-core/src/lib/io/gr_histo_sink_f.cc
     2009-03-02 00:38:49 UTC (rev 10547)
@@ -0,0 +1,159 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2009 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Radio; see the file COPYING.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <gr_histo_sink_f.h>
+#include <gr_io_signature.h>
+
+gr_histo_sink_f_sptr
+gr_make_histo_sink_f (gr_msg_queue_sptr msgq)
+{
+  return gr_histo_sink_f_sptr (new gr_histo_sink_f (msgq));
+}
+
+gr_histo_sink_f::gr_histo_sink_f (gr_msg_queue_sptr msgq)
+  : gr_sync_block ("histo_sink_f", gr_make_io_signature (1, 1, sizeof 
(float)), gr_make_io_signature (0, 0, 0)),
+  d_msgq (msgq), d_frame_size(1000), d_sample_count(0), d_minimum(-1), 
d_maximum(1), d_bins(NULL)
+{
+  set_num_bins(11); //allocates the bins, calls clear
+}
+
+gr_histo_sink_f::~gr_histo_sink_f (void)
+{
+  delete [] d_bins;
+}
+
+int
+gr_histo_sink_f::work (int noutput_items,
+  gr_vector_const_void_star &input_items,
+  gr_vector_void_star &output_items)
+{
+  int index;
+  const float *in = (const float *) input_items[0];
+  float scale = ((float)(d_num_bins-1))/(d_maximum - d_minimum);
+  for (unsigned int i = 0; i < noutput_items; i++){
+    /* scale the floating point value to a bin index */
+    index = (int)round(scale*(in[i] - d_minimum));
+    /* increment the bin# */
+    if (index >= 0 && index < (int)d_num_bins) d_bins[index]++;
+    d_sample_count++;
+    /* processed a frame? */
+    if (d_sample_count == d_frame_size){
+      send_frame();
+      clear();
+    }
+  }
+  return noutput_items;
+}
+
+void
+gr_histo_sink_f::send_frame(void){
+  /* output queue full, drop the data */
+  if (d_msgq->full_p()) return;
+  /* Build a message to hold the output records */
+  gr_message_sptr msg = gr_make_message(0, 0, 0, d_num_bins*sizeof(float));
+  float *out = (float *)msg->msg(); // get pointer to raw message buffer
+  /*
+   * Get a count of all bins. This may not be frame size,
+   * since out of range values are ignored.
+   */
+  unsigned int count = 0;
+  for (unsigned int i = 0; i < d_num_bins; i++){
+    count += d_bins[i];
+  }
+  if (count == 0){ //count is zero, send zero bins
+    for (unsigned int i = 0; i < d_num_bins; i++){
+      out[i] = 0;
+    }
+  }else{ //normalize the bins
+    for (unsigned int i = 0; i < d_num_bins; i++){
+      out[i] = ((float)d_bins[i])/count;
+    }
+  }
+  /* send the message */
+  d_msgq->handle(msg);
+}
+
+void
+gr_histo_sink_f::clear(void){
+  d_sample_count = 0;
+  /* zero the bins */
+  for (unsigned int i = 0; i < d_num_bins; i++){
+    d_bins[i] = 0;
+  }
+}
+
+/**************************************************
+ * Getters
+ **************************************************/
+unsigned int
+gr_histo_sink_f::get_frame_size(void){
+  return d_frame_size;
+}
+
+unsigned int
+gr_histo_sink_f::get_num_bins(void){
+  return d_num_bins;
+}
+
+float
+gr_histo_sink_f::get_maximum(void){
+  return d_maximum;
+}
+
+float
+gr_histo_sink_f::get_minimum(void){
+  return d_minimum;
+}
+
+/**************************************************
+ * Setters
+ **************************************************/
+void
+gr_histo_sink_f::set_frame_size(unsigned int frame_size){
+  d_frame_size = frame_size;
+  clear();
+}
+
+void
+gr_histo_sink_f::set_num_bins(unsigned int num_bins){
+  d_num_bins = num_bins;
+  /* allocate a new bin array */
+  delete [] d_bins;
+  d_bins = new float[d_num_bins];
+  clear();
+}
+
+void
+gr_histo_sink_f::set_maximum(float maximum){
+  d_maximum = maximum;
+  clear();
+}
+
+void
+gr_histo_sink_f::set_minimum(float minimum){
+  d_minimum = minimum;
+  clear();
+}

Added: 
gnuradio/branches/developers/jblum/gui_guts/gnuradio-core/src/lib/io/gr_histo_sink_f.h
===================================================================
--- 
gnuradio/branches/developers/jblum/gui_guts/gnuradio-core/src/lib/io/gr_histo_sink_f.h
                              (rev 0)
+++ 
gnuradio/branches/developers/jblum/gui_guts/gnuradio-core/src/lib/io/gr_histo_sink_f.h
      2009-03-02 00:38:49 UTC (rev 10547)
@@ -0,0 +1,73 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2009 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Radio; see the file COPYING.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef INCLUDED_GR_HISTO_SINK_F_H
+#define INCLUDED_GR_HISTO_SINK_F_H
+
+#include <gr_sync_block.h>
+#include <gr_msg_queue.h>
+
+class gr_histo_sink_f;
+typedef boost::shared_ptr<gr_histo_sink_f> gr_histo_sink_f_sptr;
+
+gr_histo_sink_f_sptr gr_make_histo_sink_f (gr_msg_queue_sptr msgq);
+
+/*!
+ * \brief Histogram module.
+ * \ingroup sink
+ */
+class gr_histo_sink_f : public gr_sync_block
+{
+private:
+  gr_msg_queue_sptr    d_msgq;
+  unsigned int d_num_bins;
+  unsigned int d_frame_size;
+  unsigned int d_sample_count;
+  float d_minimum;
+  float d_maximum;
+  float *d_bins;
+
+  friend gr_histo_sink_f_sptr gr_make_histo_sink_f (gr_msg_queue_sptr msgq);
+  gr_histo_sink_f (gr_msg_queue_sptr msgq);
+  void send_frame(void);
+  void clear(void);
+
+public:
+  ~gr_histo_sink_f (void);
+
+  int work (int noutput_items,
+    gr_vector_const_void_star &input_items,
+    gr_vector_void_star &output_items);
+
+  unsigned int get_frame_size(void);
+  unsigned int get_num_bins(void);
+  float get_maximum(void);
+  float get_minimum(void);
+
+  void set_frame_size(unsigned int frame_size);
+  void set_num_bins(unsigned int num_bins);
+  void set_maximum(float maximum);
+  void set_minimum(float minimum);
+
+};
+
+#endif /* INCLUDED_GR_HISTO_SINK_F_H */

Modified: 
gnuradio/branches/developers/jblum/gui_guts/gnuradio-core/src/lib/io/gr_oscope_guts.cc
===================================================================
--- 
gnuradio/branches/developers/jblum/gui_guts/gnuradio-core/src/lib/io/gr_oscope_guts.cc
      2009-03-01 19:44:19 UTC (rev 10546)
+++ 
gnuradio/branches/developers/jblum/gui_guts/gnuradio-core/src/lib/io/gr_oscope_guts.cc
      2009-03-02 00:38:49 UTC (rev 10547)
@@ -205,8 +205,6 @@
 
 // ----------------------------------------------------------------
 // write output records (duh!)
-// perform interpolation from the trigger point offset
-// writes OUTPUT_RECORD_SIZE-1 samples due to interpolation
 
 void
 gr_oscope_guts::write_output_records ()

Modified: 
gnuradio/branches/developers/jblum/gui_guts/gnuradio-core/src/lib/io/io.i
===================================================================
--- gnuradio/branches/developers/jblum/gui_guts/gnuradio-core/src/lib/io/io.i   
2009-03-01 19:44:19 UTC (rev 10546)
+++ gnuradio/branches/developers/jblum/gui_guts/gnuradio-core/src/lib/io/io.i   
2009-03-02 00:38:49 UTC (rev 10547)
@@ -30,6 +30,7 @@
 #include <gr_file_source.h>
 #include <gr_file_descriptor_sink.h>
 #include <gr_file_descriptor_source.h>
+#include <gr_histo_sink_f.h>
 #include <microtune_4702_eval_board.h>
 #include <microtune_4937_eval_board.h>
 #include <sdr_1000.h>
@@ -50,6 +51,7 @@
 %include "gr_file_source.i"
 %include "gr_file_descriptor_sink.i"
 %include "gr_file_descriptor_source.i"
+%include "gr_histo_sink.i"
 %include "microtune_xxxx_eval_board.i"
 %include "microtune_4702_eval_board.i"
 %include "microtune_4937_eval_board.i"

Modified: 
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/Makefile.am
===================================================================
--- gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/Makefile.am 
2009-03-01 19:44:19 UTC (rev 10546)
+++ gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/Makefile.am 
2009-03-02 00:38:49 UTC (rev 10547)
@@ -41,6 +41,8 @@
        fftsink_nongl.py                \
        fftsink_gl.py                   \
        fft_window.py                   \
+       histosink_gl.py                 \
+       histo_window.py                 \
        numbersink2.py                  \
        number_window.py                \
        plot.py                         \

Modified: 
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/const_window.py
===================================================================
--- 
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/const_window.py 
    2009-03-01 19:44:19 UTC (rev 10546)
+++ 
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/const_window.py 
    2009-03-02 00:38:49 UTC (rev 10547)
@@ -130,6 +130,7 @@
                self.plotter.set_x_label('Inphase')
                self.plotter.set_y_label('Quadrature')
                self.plotter.enable_point_label(True)
+               self.plotter.enable_grid_lines(True)
                #setup the box with plot and controls
                self.control_panel = control_panel(self)
                main_box = wx.BoxSizer(wx.HORIZONTAL)

Modified: 
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/constants.py
===================================================================
--- 
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/constants.py    
    2009-03-01 19:44:19 UTC (rev 10546)
+++ 
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/constants.py    
    2009-03-02 00:38:49 UTC (rev 10547)
@@ -59,4 +59,7 @@
 Y_DIVS_KEY = 'y_divs'
 Y_OFF_KEY = 'y_off'
 Y_PER_DIV_KEY = 'y_per_div'
-
+MAXIMUM_KEY = 'maximum'
+MINIMUM_KEY = 'minimum'
+NUM_BINS_KEY = 'num_bins'
+FRAME_SIZE_KEY = 'frame_size'

Modified: 
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/fft_window.py
===================================================================
--- 
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/fft_window.py   
    2009-03-01 19:44:19 UTC (rev 10546)
+++ 
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/fft_window.py   
    2009-03-02 00:38:49 UTC (rev 10547)
@@ -162,6 +162,7 @@
                self.plotter.SetSize(wx.Size(*size))
                self.plotter.set_title(title)
                self.plotter.enable_point_label(True)
+               self.plotter.enable_grid_lines(True)
                #setup the box with plot and controls
                self.control_panel = control_panel(self)
                main_box = wx.BoxSizer(wx.HORIZONTAL)

Added: 
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/histo_window.py
===================================================================
--- 
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/histo_window.py 
                            (rev 0)
+++ 
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/histo_window.py 
    2009-03-02 00:38:49 UTC (rev 10547)
@@ -0,0 +1,158 @@
+#
+# Copyright 2009 Free Software Foundation, Inc.
+#
+# This file is part of GNU Radio
+#
+# GNU Radio is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# GNU Radio is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GNU Radio; see the file COPYING.  If not, write to
+# the Free Software Foundation, Inc., 51 Franklin Street,
+# Boston, MA 02110-1301, USA.
+#
+
+##################################################
+# Imports
+##################################################
+import plotter
+import common
+import wx
+import numpy
+import math
+import pubsub
+from constants import *
+from gnuradio import gr #for gr.prefs
+
+##################################################
+# Constants
+##################################################
+DEFAULT_WIN_SIZE = (600, 300)
+
+##################################################
+# histo window control panel
+##################################################
+class control_panel(wx.Panel):
+       """
+       A control panel with wx widgits to control the plotter and histo sink.
+       """
+
+       def __init__(self, parent):
+               """
+               Create a new control panel.
+               @param parent the wx parent window
+               """
+               self.parent = parent
+               wx.Panel.__init__(self, parent, -1, style=wx.SUNKEN_BORDER)
+               control_box = wx.BoxSizer(wx.VERTICAL)
+               SIZE = (100, -1)
+               #y axis lvl
+               control_box.AddSpacer(5)
+               hbox = wx.BoxSizer(wx.HORIZONTAL)
+               control_box.Add(hbox, 0, wx.EXPAND)
+               hbox.Add(wx.StaticText(self, -1, ' Y Off '), 1, 
wx.ALIGN_CENTER_VERTICAL)
+               y_off_slider = wx.Slider(self, size=SIZE, 
style=wx.SL_HORIZONTAL)
+               y_off_slider.SetRange(0, 1000)
+               def y_off_slider_changed(evt): parent[Y_OFF_KEY] = 
float(y_off_slider.GetValue())/y_off_slider.GetMax()
+               y_off_slider.Bind(wx.EVT_SLIDER, y_off_slider_changed)
+               parent.subscribe(Y_OFF_KEY, lambda x: 
y_off_slider.SetValue(int(round(x*y_off_slider.GetMax()))))
+               hbox.Add(y_off_slider, 0, wx.ALIGN_CENTER_VERTICAL)
+               #run/stop
+               self.run_button = common.ToggleButtonController(self, parent, 
RUNNING_KEY, 'Stop', 'Run')
+               control_box.Add(self.run_button, 0, wx.EXPAND)
+               #set sizer
+               self.SetSizerAndFit(control_box)
+
+##################################################
+# histo window with plotter and control panel
+##################################################
+class histo_window(wx.Panel, pubsub.pubsub):
+       def __init__(
+               self,
+               parent,
+               controller,
+               size,
+               title,
+               maximum_key,
+               minimum_key,
+               num_bins_key,
+               frame_size_key,
+               msg_key,
+       ):
+               pubsub.pubsub.__init__(self)
+               
+               #setup
+               #proxy the keys
+               self.proxy(MAXIMUM_KEY, controller, maximum_key)
+               self.proxy(MINIMUM_KEY, controller, minimum_key)
+               self.proxy(NUM_BINS_KEY, controller, num_bins_key)
+               self.proxy(FRAME_SIZE_KEY, controller, frame_size_key)
+               self.proxy(MSG_KEY, controller, msg_key)
+               #init panel and plot
+               wx.Panel.__init__(self, parent, -1, style=wx.SIMPLE_BORDER)
+               self.plotter = plotter.bar_plotter(self)
+               self.plotter.SetSize(wx.Size(*size))
+               self.plotter.set_title(title)
+               self.plotter.enable_point_label(True)
+               self.plotter.enable_grid_lines(False)
+               #setup the box with plot and controls
+               self.control_panel = control_panel(self)
+               main_box = wx.BoxSizer(wx.HORIZONTAL)
+               main_box.Add(self.plotter, 1, wx.EXPAND)
+               main_box.Add(self.control_panel, 0, wx.EXPAND)
+               self.SetSizerAndFit(main_box)
+               #initialize values
+               self[MAXIMUM_KEY] = 1
+               self[MINIMUM_KEY] = -1
+               self[NUM_BINS_KEY] = 31
+               self[FRAME_SIZE_KEY] = 2048
+               self[Y_OFF_KEY] = 0.5
+               self[RUNNING_KEY] = True
+               #register events
+               self.subscribe(MSG_KEY, self.handle_msg)
+               for key in (
+                       MAXIMUM_KEY, MINIMUM_KEY, NUM_BINS_KEY, Y_OFF_KEY,
+               ): self.subscribe(key, self.update_grid)
+               #initial update
+               self.update_grid()
+
+       def handle_msg(self, msg):
+               """
+               Handle the message from the fft sink message queue.
+               @param msg the frame as a character array
+               """
+               if not self[RUNNING_KEY]: return
+               #convert to floating point numbers
+               samples = numpy.fromstring(msg, 
numpy.float32)[:self[NUM_BINS_KEY]] #only take first frame
+               samples *= 100
+               self.plotter.set_bars(
+                       bars=samples,
+                       bar_width=0.6,
+                       color_spec=(0, 0, 1),
+               )
+               #update the plotter
+               self.plotter.update()
+
+       def update_grid(self, *args):
+               """
+               Update the plotter grid.
+               Determine the x and y axis grid parameters.
+               """
+               if self[Y_OFF_KEY] <= 0: self[Y_OFF_KEY] = 0.001; return
+               #update the x grid
+               self.plotter.set_x_grid(
+                       self[MINIMUM_KEY],
+                       self[MAXIMUM_KEY],
+                       (self[MAXIMUM_KEY] - self[MINIMUM_KEY])/8, #TODO histo 
plotter
+               )
+               self.plotter.set_x_label('Counts')
+               self.plotter.set_y_grid(0, 100.*self[Y_OFF_KEY], 
100.*self[Y_OFF_KEY]/4)
+               self.plotter.set_y_label('Frequency', '%')
+               self.plotter.update()

Added: 
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/histosink_gl.py
===================================================================
--- 
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/histosink_gl.py 
                            (rev 0)
+++ 
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/histosink_gl.py 
    2009-03-02 00:38:49 UTC (rev 10547)
@@ -0,0 +1,111 @@
+#
+# Copyright 2009 Free Software Foundation, Inc.
+#
+# This file is part of GNU Radio
+#
+# GNU Radio is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# GNU Radio is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GNU Radio; see the file COPYING.  If not, write to
+# the Free Software Foundation, Inc., 51 Franklin Street,
+# Boston, MA 02110-1301, USA.
+#
+
+##################################################
+# Imports
+##################################################
+import histo_window
+import common
+from gnuradio import gr, blks2
+from pubsub import pubsub
+from constants import *
+
+##################################################
+# histo sink block (wrapper for old wxgui)
+##################################################
+class histo_sink_f(gr.hier_block2):
+       """
+       A histogram block and a gui window.
+       """
+
+       def __init__(
+               self,
+               parent,
+               size=histo_window.DEFAULT_WIN_SIZE,
+               title='',
+       ):
+               
+               #init
+               gr.hier_block2.__init__(
+                       self,
+                       "histo_sink",
+                       gr.io_signature(1, 1, gr.sizeof_float),
+                       gr.io_signature(0, 0, 0),
+               )
+               #blocks
+               msgq = gr.msg_queue(2)
+               histo = gr.histo_sink_f(msgq)
+               #connect
+               self.connect(self, histo)
+               #controller
+               self.controller = pubsub()
+               self.controller.subscribe(MAXIMUM_KEY, histo.set_maximum)
+               self.controller.publish(MAXIMUM_KEY, histo.get_maximum)
+               self.controller.subscribe(MINIMUM_KEY, histo.set_minimum)
+               self.controller.publish(MINIMUM_KEY, histo.get_minimum)
+               self.controller.subscribe(NUM_BINS_KEY, histo.set_num_bins)
+               self.controller.publish(NUM_BINS_KEY, histo.get_num_bins)
+               self.controller.subscribe(FRAME_SIZE_KEY, histo.set_frame_size)
+               self.controller.publish(FRAME_SIZE_KEY, histo.get_frame_size)
+               #start input watcher
+               common.input_watcher(msgq, self.controller, MSG_KEY)
+               #create window
+               self.win = histo_window.histo_window(
+                       parent=parent,
+                       controller=self.controller,
+                       size=size,
+                       title=title,
+                       maximum_key=MAXIMUM_KEY,
+                       minimum_key=MINIMUM_KEY,
+                       num_bins_key=NUM_BINS_KEY,
+                       frame_size_key=FRAME_SIZE_KEY,
+                       msg_key=MSG_KEY,
+               )
+               common.register_access_methods(self, self.win)
+
+# ----------------------------------------------------------------
+# Standalone test app
+# ----------------------------------------------------------------
+
+import wx
+from gnuradio.wxgui import stdgui2
+
+class test_app_block (stdgui2.std_top_block):
+    def __init__(self, frame, panel, vbox, argv):
+        stdgui2.std_top_block.__init__ (self, frame, panel, vbox, argv)
+
+        # build our flow graph
+        input_rate = 20.48e3
+
+        src2 = gr.sig_source_f (input_rate, gr.GR_SIN_WAVE, 2e3, 1)
+        #src2 = gr.sig_source_f (input_rate, gr.GR_CONST_WAVE, 5.75e3, 1)
+        thr2 = gr.throttle(gr.sizeof_float, input_rate)
+        sink2 = histo_sink_f (panel, title="Data")
+        vbox.Add (sink2.win, 1, wx.EXPAND)
+
+        self.connect(src2, thr2, sink2)
+
+def main ():
+    app = stdgui2.stdapp (test_app_block, "Histo Sink Test App")
+    app.MainLoop ()
+
+if __name__ == '__main__':
+    main ()

Modified: 
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/plotter/Makefile.am
===================================================================
--- 
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/plotter/Makefile.am
 2009-03-01 19:44:19 UTC (rev 10546)
+++ 
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/plotter/Makefile.am
 2009-03-02 00:38:49 UTC (rev 10547)
@@ -30,6 +30,7 @@
 
 ourpython_PYTHON =                     \
        __init__.py                     \
+       bar_plotter.py          \
        channel_plotter.py              \
        common.py                       \
        gltext.py                       \

Modified: 
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/plotter/__init__.py
===================================================================
--- 
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/plotter/__init__.py
 2009-03-01 19:44:19 UTC (rev 10546)
+++ 
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/plotter/__init__.py
 2009-03-02 00:38:49 UTC (rev 10547)
@@ -21,3 +21,4 @@
 
 from channel_plotter import channel_plotter
 from waterfall_plotter import waterfall_plotter
+from bar_plotter import bar_plotter

Added: 
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/plotter/bar_plotter.py
===================================================================
--- 
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/plotter/bar_plotter.py
                              (rev 0)
+++ 
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/plotter/bar_plotter.py
      2009-03-02 00:38:49 UTC (rev 10547)
@@ -0,0 +1,137 @@
+#
+# Copyright 2009 Free Software Foundation, Inc.
+#
+# This file is part of GNU Radio
+#
+# GNU Radio is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# GNU Radio is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GNU Radio; see the file COPYING.  If not, write to
+# the Free Software Foundation, Inc., 51 Franklin Street,
+# Boston, MA 02110-1301, USA.
+#
+
+import wx
+from plotter_base import grid_plotter_base
+from OpenGL import GL
+import common
+import numpy
+
+LEGEND_TEXT_FONT_SIZE = 8
+LEGEND_BOX_PADDING = 3
+PADDING = 35, 15, 40, 60 #top, right, bottom, left
+#constants for the waveform storage
+SAMPLES_KEY = 'samples'
+COLOR_SPEC_KEY = 'color_spec'
+MARKERY_KEY = 'marker'
+TRIG_OFF_KEY = 'trig_off'
+
+##################################################
+# Bar Plotter for histogram waveforms
+##################################################
+class bar_plotter(grid_plotter_base):
+
+       def __init__(self, parent):
+               """
+               Create a new bar plotter.
+               """
+               #init
+               grid_plotter_base.__init__(self, parent, PADDING)
+               self._bars = list()
+               self._bar_width = .5
+               self._color_spec = (0, 0, 0)
+               #setup channel plotter
+               self.register_init(self._init_bar_plotter)
+               self.register_draw(self._draw_bars)
+
+       def _init_bar_plotter(self):
+               """
+               Run gl initialization tasks.
+               """
+               GL.glEnableClientState(GL.GL_VERTEX_ARRAY)
+
+       def _draw_bars(self):
+               """
+               Draw the vertical bars.
+               """
+               bars = self._bars
+               num_bars = len(bars)
+               if num_bars == 0: return
+               #use scissor to prevent drawing outside grid
+               GL.glEnable(GL.GL_SCISSOR_TEST)
+               GL.glScissor(
+                       self.padding_left,
+                       self.padding_bottom+1,
+                       self.width-self.padding_left-self.padding_right-1,
+                       self.height-self.padding_top-self.padding_bottom-1,
+               )
+               #load the points
+               points = list()
+               width = self._bar_width/2
+               for i, bar in enumerate(bars):
+                       points.extend([
+                                       (i-width, 0),
+                                       (i+width, 0),
+                                       (i+width, bar),
+                                       (i-width, bar),
+                               ]
+                       )
+               GL.glColor3f(*self._color_spec)
+               #matrix transforms
+               GL.glPushMatrix()
+               GL.glTranslatef(self.padding_left, self.padding_top, 0)
+               GL.glScalef(
+                       (self.width-self.padding_left-self.padding_right),
+                       (self.height-self.padding_top-self.padding_bottom),
+                       1,
+               )
+               GL.glTranslatef(0, 1, 0)
+               GL.glScalef(1.0/(num_bars-1), -1.0/(self.y_max-self.y_min), 1)
+               GL.glTranslatef(0, -self.y_min, 0)
+               #draw the bars
+               GL.glVertexPointerf(points)
+               GL.glDrawArrays(GL.GL_QUADS, 0, len(points))
+               GL.glPopMatrix()
+               GL.glDisable(GL.GL_SCISSOR_TEST)
+
+       def _populate_point_label(self, x_val, y_val):
+               """
+               Get the text the will populate the point label.
+               Give X and Y values for the current point.
+               Give values for the channel at the X coordinate.
+               @param x_val the current x value
+               @param y_val the current y value
+               @return a string with newlines
+               """
+               #convert x val to bar #
+               bar_index = (len(self._bars)-1)*(x_val - 
self.x_min)/(self.x_max - self.x_min)
+               if abs(bar_index - round(bar_index)) > self._bar_width/2: 
return ''
+               bar_index = int(round(bar_index))
+               bar_value = self._bars[bar_index]
+               return '%s: %s\n%s: %s'%(
+                       self.x_label, common.eng_format(x_val, self.x_units),
+                       self.y_label, common.eng_format(bar_value, 
self.y_units),
+               )
+
+       def set_bars(self, bars, bar_width, color_spec):
+               """
+               Set the bars.
+               @param bars a list of bars
+               @param bar_width the fractional width of the bar, between 0 and 
1
+               @param color_spec the color tuple
+               """
+               self.lock()
+               self._bars = bars
+               self._bar_width = bar_width
+               self._color_spec = color_spec
+               self.unlock()
+
+

Modified: 
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/plotter/plotter_base.py
===================================================================
--- 
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/plotter/plotter_base.py
     2009-03-01 19:44:19 UTC (rev 10546)
+++ 
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/plotter/plotter_base.py
     2009-03-02 00:38:49 UTC (rev 10547)
@@ -133,6 +133,7 @@
                self._grid_cache = common.gl_cache(self._draw_grid)
                self.register_init(self._grid_cache.init)
                self.register_draw(self._grid_cache.draw)
+               self.enable_grid_lines(True)
                #setup padding
                self.padding_top, self.padding_right, self.padding_bottom, 
self.padding_left = padding
                #store title and unit strings
@@ -263,7 +264,7 @@
                for tick in self._get_ticks(self.x_min, self.x_max, 
self.x_step, self.x_scalar):
                        scaled_tick = 
(self.width-self.padding_left-self.padding_right)*\
                                
(tick/self.x_scalar-self.x_min)/(self.x_max-self.x_min) + self.padding_left-1
-                       self._draw_dashed_line(
+                       self._draw_grid_line(
                                (scaled_tick, self.padding_top),
                                (scaled_tick, self.height-self.padding_bottom),
                        )
@@ -277,7 +278,7 @@
                for tick in self._get_ticks(self.y_min, self.y_max, 
self.y_step, self.y_scalar):
                        scaled_tick = 
(self.height-self.padding_top-self.padding_bottom)*\
                                (1 - 
(tick/self.y_scalar-self.y_min)/(self.y_max-self.y_min)) + self.padding_top
-                       self._draw_dashed_line(
+                       self._draw_grid_line(
                                (self.padding_left, scaled_tick),
                                (self.width-self.padding_right, scaled_tick),
                        )
@@ -354,12 +355,25 @@
                stop = int(math.floor(max/step))
                return [i*step*scalar for i in range(start, stop+1)]
 
-       def _draw_dashed_line(self, coor1, coor2):
+       def enable_grid_lines(self, enable=None):
                """
+               Enable/disable the grid lines.
+               @param enable true to enable
+               @return the enable state when None
+               """
+               if enable is None: return self._enable_grid_lines
+               self.lock()
+               self._enable_grid_lines = enable
+               self._grid_cache.changed(True)
+               self.unlock()
+
+       def _draw_grid_line(self, coor1, coor2):
+               """
                Draw a dashed line from coor1 to coor2.
                @param corr1 a tuple of x, y
                @param corr2 a tuple of x, y
                """
+               if not self.enable_grid_lines(): return
                GL.glEnable(GL.GL_LINE_STIPPLE)
                GL.glLineStipple(1, int("1110" + "0000" + "1110" + "0000", 2))
                GL.glBegin(GL.GL_LINES)
@@ -405,6 +419,7 @@
                y_val = y_win_scalar*(self.y_max-self.y_min) + self.y_min
                #create text
                label_str = self._populate_point_label(x_val, y_val)
+               if not label_str: return
                txt = gltext.Text(label_str, font_size=POINT_LABEL_FONT_SIZE)
                w, h = txt.get_size()
                #draw rect + text

Modified: 
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/scope_window.py
===================================================================
--- 
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/scope_window.py 
    2009-03-01 19:44:19 UTC (rev 10546)
+++ 
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/scope_window.py 
    2009-03-02 00:38:49 UTC (rev 10547)
@@ -127,7 +127,6 @@
                hbox = wx.BoxSizer(wx.HORIZONTAL)
                scope_mode_box.Add(hbox, 0, wx.EXPAND)
                hbox.Add(wx.StaticText(self, -1, ' T Offset '), 1, 
wx.ALIGN_CENTER_VERTICAL)
-               #t axis control
                t_off_slider = wx.Slider(self, size=SIZE, 
style=wx.SL_HORIZONTAL)
                t_off_slider.SetRange(0, 1000)
                def t_off_slider_changed(evt): parent[T_FRAC_OFF_KEY] = 
float(t_off_slider.GetValue())/t_off_slider.GetMax()
@@ -330,6 +329,7 @@
                self.plotter.set_title(title)
                self.plotter.enable_legend(True)
                self.plotter.enable_point_label(True)
+               self.plotter.enable_grid_lines(True)
                #setup the box with plot and controls
                self.control_panel = control_panel(self)
                main_box = wx.BoxSizer(wx.HORIZONTAL)

Modified: 
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/waterfall_window.py
===================================================================
--- 
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/waterfall_window.py
 2009-03-01 19:44:19 UTC (rev 10546)
+++ 
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/waterfall_window.py
 2009-03-02 00:38:49 UTC (rev 10547)
@@ -180,6 +180,7 @@
                self.plotter.SetSize(wx.Size(*size))
                self.plotter.set_title(title)
                self.plotter.enable_point_label(True)
+               self.plotter.enable_grid_lines(False)
                #setup the box with plot and controls
                self.control_panel = control_panel(self)
                main_box = wx.BoxSizer(wx.HORIZONTAL)





reply via email to

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