diff options
author | Tom Rondeau | 2011-04-23 14:30:32 -0400 |
---|---|---|
committer | Tom Rondeau | 2011-04-23 14:30:32 -0400 |
commit | 01f44f64c916b4aa38bc81662d2c8b82c4cc0b57 (patch) | |
tree | 841a9a0cf39952ffbea58ec17b0efbe945eeb074 /gr-qtgui | |
parent | bbb5e850224aca9dae15d24bd898cc56232327c9 (diff) | |
download | gnuradio-01f44f64c916b4aa38bc81662d2c8b82c4cc0b57.tar.gz gnuradio-01f44f64c916b4aa38bc81662d2c8b82c4cc0b57.tar.bz2 gnuradio-01f44f64c916b4aa38bc81662d2c8b82c4cc0b57.zip |
gr-qtgui: moving towards allowing time plot to have multiple connections.
Diffstat (limited to 'gr-qtgui')
-rw-r--r-- | gr-qtgui/lib/TimeDomainDisplayPlot.cc | 66 | ||||
-rw-r--r-- | gr-qtgui/lib/TimeDomainDisplayPlot.h | 14 | ||||
-rw-r--r-- | gr-qtgui/lib/qtgui_time_sink_c.cc | 32 | ||||
-rw-r--r-- | gr-qtgui/lib/qtgui_time_sink_c.h | 2 | ||||
-rw-r--r-- | gr-qtgui/lib/spectrumUpdateEvents.cc | 22 | ||||
-rw-r--r-- | gr-qtgui/lib/spectrumUpdateEvents.h | 11 | ||||
-rw-r--r-- | gr-qtgui/lib/spectrumdisplayform.cc | 12 | ||||
-rw-r--r-- | gr-qtgui/lib/timedisplayform.cc | 23 | ||||
-rw-r--r-- | gr-qtgui/lib/timedisplayform.h | 2 |
9 files changed, 94 insertions, 90 deletions
diff --git a/gr-qtgui/lib/TimeDomainDisplayPlot.cc b/gr-qtgui/lib/TimeDomainDisplayPlot.cc index 9e7b796e8..c9973fbc2 100644 --- a/gr-qtgui/lib/TimeDomainDisplayPlot.cc +++ b/gr-qtgui/lib/TimeDomainDisplayPlot.cc @@ -27,7 +27,7 @@ #include <qwt_scale_draw.h> #include <qwt_legend.h> - +#include <iostream> class TimePrecisionClass { @@ -92,16 +92,16 @@ private: std::string _unitType; }; -TimeDomainDisplayPlot::TimeDomainDisplayPlot(QWidget* parent):QwtPlot(parent) +TimeDomainDisplayPlot::TimeDomainDisplayPlot(int nplots, QWidget* parent) + : QwtPlot(parent), _nplots(nplots) { timespec_reset(&_lastReplot); resize(parent->width(), parent->height()); _numPoints = 1024; - _realDataPoints = new double[_numPoints]; - _imagDataPoints = new double[_numPoints]; _xAxisPoints = new double[_numPoints]; + memset(_xAxisPoints, 0x0, _numPoints*sizeof(double)); _zoomer = new TimeDomainDisplayZoomer(canvas(), 0); _zoomer->setSelectionFlags(QwtPicker::RectSelection | QwtPicker::DragSelection); @@ -125,21 +125,20 @@ TimeDomainDisplayPlot::TimeDomainDisplayPlot(QWidget* parent):QwtPlot(parent) set_yaxis(-2.0, 2.0); setAxisTitle(QwtPlot::yLeft, "Normalized Voltage"); + // Setup dataPoints and plot vectors // Automatically deleted when parent is deleted - _real_plot_curve = new QwtPlotCurve("Real Data"); - _real_plot_curve->attach(this); - _real_plot_curve->setPen(QPen(Qt::blue)); - _real_plot_curve->setRawData(_xAxisPoints, _realDataPoints, _numPoints); - - _imag_plot_curve = new QwtPlotCurve("Imaginary Data"); - _imag_plot_curve->attach(this); - _imag_plot_curve->setPen(QPen(Qt::magenta)); - _imag_plot_curve->setRawData(_xAxisPoints, _imagDataPoints, _numPoints); - // _imag_plot_curve->setVisible(false); - - memset(_realDataPoints, 0x0, _numPoints*sizeof(double)); - memset(_imagDataPoints, 0x0, _numPoints*sizeof(double)); - memset(_xAxisPoints, 0x0, _numPoints*sizeof(double)); + for(int i = 0; i < _nplots; i++) { + _dataPoints.push_back(new double[_numPoints]); + memset(_dataPoints[i], 0x0, _numPoints*sizeof(double)); + + _plot_curve.push_back(new QwtPlotCurve(QString("Data %1").arg(i))); + _plot_curve[i]->attach(this); + if(i == 0) + _plot_curve[i]->setPen(QPen(Qt::blue)); + else + _plot_curve[i]->setPen(QPen(Qt::red)); + _plot_curve[i]->setRawData(_xAxisPoints, _dataPoints[i], _numPoints); + } _sampleRate = 1; _resetXAxisPoints(); @@ -183,8 +182,8 @@ TimeDomainDisplayPlot::TimeDomainDisplayPlot(QWidget* parent):QwtPlot(parent) TimeDomainDisplayPlot::~TimeDomainDisplayPlot() { - delete[] _realDataPoints; - delete[] _imagDataPoints; + for(int i = 0; i < _nplots; i++) + delete [] _dataPoints[i]; delete[] _xAxisPoints; // _zoomer and _panner deleted when parent deleted @@ -216,8 +215,8 @@ TimeDomainDisplayPlot::resizeSlot( QSize *s ) resize(s->width(), s->height()); } -void TimeDomainDisplayPlot::PlotNewData(const double* realDataPoints, - const double* imagDataPoints, +void TimeDomainDisplayPlot::PlotNewData(const int which, + const double* dataPoints, const int64_t numDataPoints, const double timeInterval) { @@ -227,33 +226,28 @@ void TimeDomainDisplayPlot::PlotNewData(const double* realDataPoints, if(numDataPoints != _numPoints){ _numPoints = numDataPoints; - delete[] _realDataPoints; - delete[] _imagDataPoints; + delete[] _dataPoints[which]; + _dataPoints[which] = new double[_numPoints]; + delete[] _xAxisPoints; - _realDataPoints = new double[_numPoints]; - _imagDataPoints = new double[_numPoints]; _xAxisPoints = new double[_numPoints]; - _real_plot_curve->setRawData(_xAxisPoints, _realDataPoints, _numPoints); - _imag_plot_curve->setRawData(_xAxisPoints, _imagDataPoints, _numPoints); + _plot_curve[which]->setRawData(_xAxisPoints, _dataPoints[which], _numPoints); set_xaxis(0, numDataPoints); _resetXAxisPoints(); } - memcpy(_realDataPoints, realDataPoints, numDataPoints*sizeof(double)); - memcpy(_imagDataPoints, imagDataPoints, numDataPoints*sizeof(double)); + std::cout << "DisplayPlot: " << which << std::endl; + memcpy(_dataPoints[which], dataPoints, numDataPoints*sizeof(double)); + std::cout << "after" << std::endl; - _lastReplot = get_highres_clock(); + if(which == _nplots-1) + _lastReplot = get_highres_clock(); } } -void TimeDomainDisplayPlot::SetImaginaryDataVisible(const bool visibleFlag) -{ - _imag_plot_curve->setVisible(visibleFlag); -} - void TimeDomainDisplayPlot::_resetXAxisPoints() { double delt = 1.0/_sampleRate; diff --git a/gr-qtgui/lib/TimeDomainDisplayPlot.h b/gr-qtgui/lib/TimeDomainDisplayPlot.h index 328371e6a..3a983a924 100644 --- a/gr-qtgui/lib/TimeDomainDisplayPlot.h +++ b/gr-qtgui/lib/TimeDomainDisplayPlot.h @@ -25,6 +25,7 @@ #include <stdint.h> #include <cstdio> +#include <vector> #include <qwt_plot.h> #include <qwt_painter.h> #include <qwt_plot_canvas.h> @@ -43,14 +44,12 @@ class TimeDomainDisplayPlot:public QwtPlot{ Q_OBJECT public: - TimeDomainDisplayPlot(QWidget*); + TimeDomainDisplayPlot(int nplots, QWidget*); virtual ~TimeDomainDisplayPlot(); - void PlotNewData(const double* realDataPoints, const double* imagDataPoints, + void PlotNewData(const int which, const double* dataPoints, const int64_t numDataPoints, const double timeInterval); - void SetImaginaryDataVisible(const bool); - virtual void replot(); void set_yaxis(double min, double max); @@ -74,8 +73,8 @@ protected: private: void _resetXAxisPoints(); - QwtPlotCurve* _real_plot_curve; - QwtPlotCurve* _imag_plot_curve; + int _nplots; + std::vector<QwtPlotCurve*> _plot_curve; QwtPlotPanner* _panner; QwtPlotZoomer* _zoomer; @@ -83,8 +82,7 @@ private: QwtDblClickPlotPicker *_picker; QwtPlotMagnifier *_magnifier; - double* _realDataPoints; - double* _imagDataPoints; + std::vector<double*> _dataPoints; double* _xAxisPoints; double _sampleRate; diff --git a/gr-qtgui/lib/qtgui_time_sink_c.cc b/gr-qtgui/lib/qtgui_time_sink_c.cc index cff265835..2c8ff86e5 100644 --- a/gr-qtgui/lib/qtgui_time_sink_c.cc +++ b/gr-qtgui/lib/qtgui_time_sink_c.cc @@ -48,14 +48,14 @@ qtgui_time_sink_c::qtgui_time_sink_c (int size, double bw, gr_make_io_signature (nconnections, nconnections, sizeof(gr_complex)), gr_make_io_signature (0, 0, 0)), d_size(size), d_bandwidth(bw), d_name(name), - d_nconnections(nconnections), d_parent(parent) + d_nconnections(2*nconnections), d_parent(parent) { d_main_gui = NULL; d_index = 0; for(int i = 0; i < d_nconnections; i++) { - d_residbufs.push_back(new gr_complex[d_size]); + d_residbufs.push_back(new double[d_size]); } initialize(); @@ -90,7 +90,7 @@ qtgui_time_sink_c::initialize() d_qApplication = new QApplication(argc, argv); } - d_main_gui = new TimeDisplayForm(d_parent); + d_main_gui = new TimeDisplayForm(d_nconnections, d_parent); // initialize update time to 10 times a second set_update_time(0.1); @@ -148,22 +148,30 @@ qtgui_time_sink_c::general_work (int noutput_items, const timespec currentTime = get_highres_clock(); // Fill up residbufs with d_fftsize number of items - for(n = 0; n < d_nconnections; n++) { - memcpy(d_residbufs[n]+d_index, &in[j], sizeof(gr_complex)*resid); + for(n = 0; n < d_nconnections; n+=2) { + for(unsigned int k = 0; k < resid; k++) { + d_residbufs[n][d_index+k] = in[j+k].real(); + d_residbufs[n+1][d_index+k] = in[j+k].imag(); + } + + d_qApplication->postEvent(d_main_gui, + new TimeUpdateEvent(n, d_residbufs[n], d_size, + currentTime, true)); + //d_qApplication->postEvent(d_main_gui, + // new TimeUpdateEvent(n+1, d_residbufs[n+1], d_size, + // currentTime, true)); } d_index = 0; - j += resid; - - d_qApplication->postEvent(d_main_gui, - new TimeUpdateEvent(d_residbufs, d_size, - currentTime, true)); } // Otherwise, copy what we received into the residbufs for next time else { - for(n = 0; n < d_nconnections; n++) { - memcpy(d_residbufs[n]+d_index, &in[j], sizeof(gr_complex)*datasize); + for(n = 0; n < d_nconnections; n+=2) { + for(unsigned int k = 0; k < resid; k++) { + d_residbufs[n][d_index+k] = in[j+k].real(); + d_residbufs[n+1][d_index+k] = in[j+k].imag(); + } } d_index += datasize; j += datasize; diff --git a/gr-qtgui/lib/qtgui_time_sink_c.h b/gr-qtgui/lib/qtgui_time_sink_c.h index 0c4e93803..67687061b 100644 --- a/gr-qtgui/lib/qtgui_time_sink_c.h +++ b/gr-qtgui/lib/qtgui_time_sink_c.h @@ -60,7 +60,7 @@ private: int d_nconnections; int d_index; - std::vector<gr_complex*> d_residbufs; + std::vector<double*> d_residbufs; double d_update_time; diff --git a/gr-qtgui/lib/spectrumUpdateEvents.cc b/gr-qtgui/lib/spectrumUpdateEvents.cc index 7d297a0d2..037225760 100644 --- a/gr-qtgui/lib/spectrumUpdateEvents.cc +++ b/gr-qtgui/lib/spectrumUpdateEvents.cc @@ -179,13 +179,15 @@ SpectrumFrequencyRangeEvent::GetStopFrequency() const /***************************************************************************/ - -TimeUpdateEvent::TimeUpdateEvent(const std::vector<gr_complex*> &timeDomainPoints, +#include <iostream> +TimeUpdateEvent::TimeUpdateEvent(const int which, + const double *timeDomainPoints, const uint64_t numTimeDomainDataPoints, const timespec dataTimestamp, const bool repeatDataFlag) : QEvent(QEvent::Type(10005)) { + _which = which; if(numTimeDomainDataPoints < 1) { _numTimeDomainDataPoints = 1; } @@ -193,11 +195,11 @@ TimeUpdateEvent::TimeUpdateEvent(const std::vector<gr_complex*> &timeDomainPoint _numTimeDomainDataPoints = numTimeDomainDataPoints; } - _dataTimeDomainPoints = new gr_complex[_numTimeDomainDataPoints]; - memset(_dataTimeDomainPoints, 0x0, _numTimeDomainDataPoints*sizeof(gr_complex)); + _dataTimeDomainPoints = new double[_numTimeDomainDataPoints]; + memset(_dataTimeDomainPoints, 0x0, _numTimeDomainDataPoints*sizeof(double)); if(numTimeDomainDataPoints > 0) { - memcpy(_dataTimeDomainPoints, timeDomainPoints[0], - numTimeDomainDataPoints*sizeof(gr_complex)); + memcpy(_dataTimeDomainPoints, timeDomainPoints, + numTimeDomainDataPoints*sizeof(double)); } _dataTimestamp = dataTimestamp; @@ -209,7 +211,13 @@ TimeUpdateEvent::~TimeUpdateEvent() delete[] _dataTimeDomainPoints; } -const gr_complex* +int +TimeUpdateEvent::which() const +{ + return _which; +} + +const double* TimeUpdateEvent::getTimeDomainPoints() const { return _dataTimeDomainPoints; diff --git a/gr-qtgui/lib/spectrumUpdateEvents.h b/gr-qtgui/lib/spectrumUpdateEvents.h index 1a92eefb5..09771571c 100644 --- a/gr-qtgui/lib/spectrumUpdateEvents.h +++ b/gr-qtgui/lib/spectrumUpdateEvents.h @@ -5,9 +5,7 @@ #include <QEvent> #include <QString> #include <complex> -#include <vector> #include <highResTimeFunctions.h> -#include <gr_complex.h> class SpectrumUpdateEvent:public QEvent{ @@ -94,14 +92,16 @@ private: class TimeUpdateEvent: public QEvent { public: - TimeUpdateEvent(const std::vector<gr_complex*> &timeDomainPoints, + TimeUpdateEvent(const int which, + const double *timeDomainPoints, const uint64_t numTimeDomainDataPoints, const timespec dataTimestamp, const bool repeatDataFlag); ~TimeUpdateEvent(); - const gr_complex *getTimeDomainPoints() const; + int which() const; + const double *getTimeDomainPoints() const; uint64_t getNumTimeDomainDataPoints() const; timespec getDataTimestamp() const; bool getRepeatDataFlag() const; @@ -109,7 +109,8 @@ public: protected: private: - gr_complex *_dataTimeDomainPoints; + int _which; + double *_dataTimeDomainPoints; uint64_t _numTimeDomainDataPoints; timespec _dataTimestamp; bool _repeatDataFlag; diff --git a/gr-qtgui/lib/spectrumdisplayform.cc b/gr-qtgui/lib/spectrumdisplayform.cc index acc7a209d..2c666871d 100644 --- a/gr-qtgui/lib/spectrumdisplayform.cc +++ b/gr-qtgui/lib/spectrumdisplayform.cc @@ -36,7 +36,7 @@ SpectrumDisplayForm::SpectrumDisplayForm(QWidget* parent) _frequencyDisplayPlot = new FrequencyDisplayPlot(FrequencyPlotDisplayFrame); _waterfallDisplayPlot = new WaterfallDisplayPlot(WaterfallPlotDisplayFrame); - _timeDomainDisplayPlot = new TimeDomainDisplayPlot(TimeDomainDisplayFrame); + _timeDomainDisplayPlot = new TimeDomainDisplayPlot(2, TimeDomainDisplayFrame); _constellationDisplayPlot = new ConstellationDisplayPlot(ConstellationDisplayFrame); _numRealDataPoints = 1024; _realFFTDataPoints = new double[_numRealDataPoints]; @@ -232,11 +232,15 @@ SpectrumDisplayForm::newFrequencyData( const SpectrumUpdateEvent* spectrumUpdate _peakAmplitude, d_update_time); } if(tabindex == d_plot_time) { - _timeDomainDisplayPlot->PlotNewData(realTimeDomainDataPoints, - imagTimeDomainDataPoints, + _timeDomainDisplayPlot->PlotNewData(0, + realTimeDomainDataPoints, numTimeDomainDataPoints, d_update_time); - } + _timeDomainDisplayPlot->PlotNewData(1, + imagTimeDomainDataPoints, + numTimeDomainDataPoints, + d_update_time); + } if(tabindex == d_plot_constellation) { _constellationDisplayPlot->PlotNewData(realTimeDomainDataPoints, imagTimeDomainDataPoints, diff --git a/gr-qtgui/lib/timedisplayform.cc b/gr-qtgui/lib/timedisplayform.cc index e90eaab06..65940b013 100644 --- a/gr-qtgui/lib/timedisplayform.cc +++ b/gr-qtgui/lib/timedisplayform.cc @@ -26,7 +26,7 @@ #include <timedisplayform.h> #include <iostream> -TimeDisplayForm::TimeDisplayForm(QWidget* parent) +TimeDisplayForm::TimeDisplayForm(int nplots, QWidget* parent) : QWidget(parent) { _systemSpecifiedFlag = false; @@ -34,8 +34,8 @@ TimeDisplayForm::TimeDisplayForm(QWidget* parent) _intValidator->setBottom(0); _layout = new QGridLayout(this); - _timeDomainDisplayPlot = new TimeDomainDisplayPlot(this); - _layout->addWidget(_timeDomainDisplayPlot, 0, 0); + _timeDomainDisplayPlot = new TimeDomainDisplayPlot(nplots, this); + _layout->addWidget(_timeDomainDisplayPlot, 0, 0, 100, 100); _numRealDataPoints = 1024; @@ -65,24 +65,15 @@ TimeDisplayForm::~TimeDisplayForm() void TimeDisplayForm::newData( const TimeUpdateEvent* spectrumUpdateEvent) { - const gr_complex* timeDomainDataPoints = spectrumUpdateEvent->getTimeDomainPoints(); + const int which = spectrumUpdateEvent->which(); + const double* timeDomainDataPoints = spectrumUpdateEvent->getTimeDomainPoints(); const uint64_t numTimeDomainDataPoints = spectrumUpdateEvent->getNumTimeDomainDataPoints(); const timespec generatedTimestamp = spectrumUpdateEvent->getDataTimestamp(); - - // FIXME: make time domain display take complex inputs - double *real = new double[numTimeDomainDataPoints]; - double *imag = new double[numTimeDomainDataPoints]; - for(uint64_t i = 0; i < numTimeDomainDataPoints; i++) { - real[i] = timeDomainDataPoints[i].real(); - imag[i] = timeDomainDataPoints[i].imag(); - } - _timeDomainDisplayPlot->PlotNewData(real, imag, + //std::cout << "TimeDisplayForm: which: " << which << std::endl; + _timeDomainDisplayPlot->PlotNewData(which, timeDomainDataPoints, numTimeDomainDataPoints, d_update_time); - - delete [] real; - delete [] imag; } void diff --git a/gr-qtgui/lib/timedisplayform.h b/gr-qtgui/lib/timedisplayform.h index 947e28153..888d28e21 100644 --- a/gr-qtgui/lib/timedisplayform.h +++ b/gr-qtgui/lib/timedisplayform.h @@ -39,7 +39,7 @@ class TimeDisplayForm : public QWidget Q_OBJECT public: - TimeDisplayForm(QWidget* parent = 0); + TimeDisplayForm(int nplots=1, QWidget* parent = 0); ~TimeDisplayForm(); void Reset(); |