Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

GrSimpleScopeSink.h

Go to the documentation of this file.
00001 /* -*- Mode: c++ -*- */
00002 /*
00003  * Copyright 2001 Free Software Foundation, Inc.
00004  * 
00005  * This file is part of GNU Radio
00006  * 
00007  * GNU Radio is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation; either version 2, or (at your option)
00010  * any later version.
00011  * 
00012  * GNU Radio is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  * 
00017  * You should have received a copy of the GNU General Public License
00018  * along with GNU Radio; see the file COPYING.  If not, write to
00019  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00020  * Boston, MA 02111-1307, USA.
00021  */
00022 
00023 #ifndef _GRSIMPLESCOPESINK_H_
00024 #define _GRSIMPLESCOPESINK_H_
00025 
00026 #include <VrSink.h>
00027 #include "VrGUI.h"
00028 
00029 
00030 extern "C" {
00031 #include <dlfcn.h>
00032 #include <float.h>
00033 #include <math.h>
00034            }
00035 
00036 #define XAXIS_NAME                      "Time"
00037 #define YAXIS_NAME                      "Amplitude"
00038 
00039 
00040 template<class iType> 
00041 class GrSimpleScopeSink : public VrSink<iType> {
00042 
00043  public:
00044   virtual const char *name() { return "GrSimpleScopeSink"; }
00045 
00046   virtual int work3(VrSampleRange output, 
00047                     VrSampleRange inputs[], void *i[]);
00048 
00049   void clear() { plot->clear(); }
00050   void set_persistent(int arg_persistent) {plot->set_persistent(arg_persistent); }
00051 
00052   GrSimpleScopeSink(VrGUILayout *layout, double arg_ymin, double arg_ymax,
00053                     int arg_nPoints = maxnPoints);
00054   ~GrSimpleScopeSink();
00055 
00056 
00057   static const int maxnPoints = 1000;   // number of points to plot
00058   static const int divisions = 10;      // number of x-axis divisions
00059 
00060  private:
00061   double        *xValues;
00062   double        *yValues;               // amplitudes to plot on y-axis
00063   int           nPoints;                // number of points to plot
00064   int           ncollected;             // current number of points collected
00065 
00066   VrGUIPlot     *plot;
00067   double        ymin, ymax;             // possible range of sample values
00068 };
00069 
00070 /*****************************************************************************
00071  * Implementation of template (C++ requires it to be in .h file).
00072  ****************************************************************************/
00073 
00074 
00075 /*
00076  * Creates a new GrSimpleScopeSink.
00077  */
00078 template<class iType>
00079 GrSimpleScopeSink<iType>::GrSimpleScopeSink(VrGUILayout *layout, 
00080         double arg_ymin, double arg_ymax, int arg_nPoints)
00081 {
00082   nPoints = arg_nPoints;
00083   if (nPoints > maxnPoints)
00084     nPoints = maxnPoints;
00085 
00086   ncollected = 0;
00087 
00088   yValues = new double[nPoints];
00089   xValues = new double[nPoints];
00090 
00091   for (int i = 0; i < nPoints; i++)
00092     xValues[i] = i;
00093 
00094   ymin = arg_ymin;
00095   ymax = arg_ymax;
00096 
00097   // FIXME remove casts on ymin, ymax...
00098   plot = new VrGUIPlot (layout, XAXIS_NAME, YAXIS_NAME, 1,
00099                         0, nPoints, (int) ymin, (int) ymax, nPoints, divisions);
00100 
00101   // setOptimalSize(nPoints);
00102 }
00103 
00104 template<class iType> int
00105 GrSimpleScopeSink<iType>::work3(VrSampleRange output, 
00106                                 VrSampleRange inputs[], void *ai[])
00107 {
00108   iType **i = (iType **)ai;
00109   sync(output.index);
00110 
00111   unsigned int  n;
00112   bool already_output_something_p = false;
00113 
00114   for (n = 0; n < output.size; n++){
00115     yValues[ncollected++] = *i[0]++;
00116     if (ncollected == nPoints){
00117       if (!already_output_something_p){
00118         plot->data (xValues, yValues, nPoints);
00119         already_output_something_p = true;
00120       }
00121       ncollected = 0;
00122     }
00123   }
00124 
00125   return output.size;
00126 }
00127 
00128 template<class iType> 
00129 GrSimpleScopeSink<iType>::~GrSimpleScopeSink()
00130 {
00131   delete[] xValues;
00132   delete[] yValues;
00133   // delete plot
00134 }
00135 
00136 #endif
00137 
00138 
00139 

Generated on Tue Mar 15 23:48:04 2005 for GNU Radio by  doxygen 1.4.0