From 97fd10af58ecd4effcf1715eed502836e3c2e1da Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Mon, 9 May 2011 12:13:50 +0100 Subject: gr-qtgui: makes time sink a sync_block (since it is) and uses set_output_multiple instead of forecast. The result is that multiple streams maintain constant relationship, which they did not before. This should also prevent us from having to keep so much book-keeping of the indecies, and we will hopefully be able to clean this up soon. --- gr-qtgui/lib/qtgui_time_sink_c.cc | 32 ++++++++++++-------------------- gr-qtgui/lib/qtgui_time_sink_c.h | 25 +++++++++++-------------- gr-qtgui/lib/qtgui_time_sink_f.cc | 28 ++++++++++------------------ gr-qtgui/lib/qtgui_time_sink_f.h | 13 +++++-------- 4 files changed, 38 insertions(+), 60 deletions(-) (limited to 'gr-qtgui/lib') diff --git a/gr-qtgui/lib/qtgui_time_sink_c.cc b/gr-qtgui/lib/qtgui_time_sink_c.cc index 6c4793ea1..e5c4cd7d6 100644 --- a/gr-qtgui/lib/qtgui_time_sink_c.cc +++ b/gr-qtgui/lib/qtgui_time_sink_c.cc @@ -44,9 +44,9 @@ qtgui_time_sink_c::qtgui_time_sink_c (int size, double bw, const std::string &name, int nconnections, QWidget *parent) - : gr_block ("time_sink_c", - gr_make_io_signature (nconnections, nconnections, sizeof(gr_complex)), - gr_make_io_signature (0, 0, 0)), + : gr_sync_block ("time_sink_c", + 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(2*nconnections), d_parent(parent) { @@ -59,6 +59,7 @@ qtgui_time_sink_c::qtgui_time_sink_c (int size, double bw, } initialize(); + set_output_multiple(d_size); } qtgui_time_sink_c::~qtgui_time_sink_c() @@ -69,15 +70,6 @@ qtgui_time_sink_c::~qtgui_time_sink_c() } } -void -qtgui_time_sink_c::forecast(int noutput_items, gr_vector_int &ninput_items_required) -{ - unsigned int ninputs = ninput_items_required.size(); - for (unsigned int i = 0; i < ninputs; i++) { - ninput_items_required[i] = std::min(d_size, 8191); - } -} - void qtgui_time_sink_c::initialize() { @@ -144,10 +136,9 @@ qtgui_time_sink_c::set_color(int which, const std::string &color) } int -qtgui_time_sink_c::general_work (int noutput_items, - gr_vector_int &ninput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) +qtgui_time_sink_c::work (int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) { int n=0, j=0, idx=0; const gr_complex *in = (const gr_complex*)input_items[idx]; @@ -159,7 +150,6 @@ qtgui_time_sink_c::general_work (int noutput_items, // If we have enough input for one full plot, do it if(datasize >= resid) { - d_current_time = get_highres_clock(); // Fill up residbufs with d_size number of items for(n = 0; n < d_nconnections; n+=2) { @@ -171,6 +161,7 @@ qtgui_time_sink_c::general_work (int noutput_items, } // Update the plot if its time + d_current_time = get_highres_clock(); if(diff_timespec(d_current_time, d_last_time) > d_update_time) { d_last_time = d_current_time; d_qApplication->postEvent(d_main_gui, @@ -181,7 +172,9 @@ qtgui_time_sink_c::general_work (int noutput_items, j += resid; } // Otherwise, copy what we received into the residbufs for next time + // because we set the output_multiple, this should never need to be called else { + assert(0); for(n = 0; n < d_nconnections; n+=2) { in = (const gr_complex*)input_items[idx++]; for(unsigned int k = 0; k < resid; k++) { @@ -193,7 +186,6 @@ qtgui_time_sink_c::general_work (int noutput_items, j += datasize; } } - - consume_each(j); - return j; + + return noutput_items; } diff --git a/gr-qtgui/lib/qtgui_time_sink_c.h b/gr-qtgui/lib/qtgui_time_sink_c.h index aa46ab3a7..8366fc617 100644 --- a/gr-qtgui/lib/qtgui_time_sink_c.h +++ b/gr-qtgui/lib/qtgui_time_sink_c.h @@ -25,7 +25,7 @@ #include #include -#include +#include #include #include #include @@ -35,24 +35,22 @@ class qtgui_time_sink_c; typedef boost::shared_ptr qtgui_time_sink_c_sptr; GR_QTGUI_API qtgui_time_sink_c_sptr qtgui_make_time_sink_c(int size, double bw, - const std::string &name, - int nconnectons=1, - QWidget *parent=NULL); + const std::string &name, + int nconnectons=1, + QWidget *parent=NULL); -class GR_QTGUI_API qtgui_time_sink_c : public gr_block +class GR_QTGUI_API qtgui_time_sink_c : public gr_sync_block { private: friend GR_QTGUI_API qtgui_time_sink_c_sptr qtgui_make_time_sink_c(int size, double bw, - const std::string &name, - int nconnections, - QWidget *parent); + const std::string &name, + int nconnections, + QWidget *parent); qtgui_time_sink_c(int size, double bw, const std::string &name, int nconnections, QWidget *parent=NULL); - void forecast(int noutput_items, gr_vector_int &ninput_items_required); - void initialize(); int d_size; @@ -84,10 +82,9 @@ public: QApplication *d_qApplication; - int general_work (int noutput_items, - gr_vector_int &ninput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); + int work (int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); }; #endif /* INCLUDED_QTGUI_TIME_SINK_C_H */ diff --git a/gr-qtgui/lib/qtgui_time_sink_f.cc b/gr-qtgui/lib/qtgui_time_sink_f.cc index 28789c163..ac7b853b5 100644 --- a/gr-qtgui/lib/qtgui_time_sink_f.cc +++ b/gr-qtgui/lib/qtgui_time_sink_f.cc @@ -44,9 +44,9 @@ qtgui_time_sink_f::qtgui_time_sink_f (int size, double bw, const std::string &name, int nconnections, QWidget *parent) - : gr_block ("time_sink_f", - gr_make_io_signature (nconnections, nconnections, sizeof(float)), - gr_make_io_signature (0, 0, 0)), + : gr_sync_block ("time_sink_f", + gr_make_io_signature (nconnections, nconnections, sizeof(float)), + gr_make_io_signature (0, 0, 0)), d_size(size), d_bandwidth(bw), d_name(name), d_nconnections(nconnections), d_parent(parent) { @@ -59,6 +59,7 @@ qtgui_time_sink_f::qtgui_time_sink_f (int size, double bw, } initialize(); + set_output_multiple(d_size); } qtgui_time_sink_f::~qtgui_time_sink_f() @@ -69,15 +70,6 @@ qtgui_time_sink_f::~qtgui_time_sink_f() } } -void -qtgui_time_sink_f::forecast(int noutput_items, gr_vector_int &ninput_items_required) -{ - unsigned int ninputs = ninput_items_required.size(); - for (unsigned int i = 0; i < ninputs; i++) { - ninput_items_required[i] = std::min(d_size, 8191); - } -} - void qtgui_time_sink_f::initialize() { @@ -144,10 +136,9 @@ qtgui_time_sink_f::set_color(int which, const std::string &color) } int -qtgui_time_sink_f::general_work (int noutput_items, - gr_vector_int &ninput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) +qtgui_time_sink_f::work (int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) { int n=0, j=0, idx=0; const float *in = (const float*)input_items[idx]; @@ -180,7 +171,9 @@ qtgui_time_sink_f::general_work (int noutput_items, j += resid; } // Otherwise, copy what we received into the residbufs for next time + // because we set the output_multiple, this should never need to be called else { + assert(0); for(n = 0; n < d_nconnections; n++) { in = (const float*)input_items[idx++]; for(unsigned int k = 0; k < resid; k++) { @@ -192,6 +185,5 @@ qtgui_time_sink_f::general_work (int noutput_items, } } - consume_each(j); - return j; + return noutput_items; } diff --git a/gr-qtgui/lib/qtgui_time_sink_f.h b/gr-qtgui/lib/qtgui_time_sink_f.h index 29fca79ee..b4865024e 100644 --- a/gr-qtgui/lib/qtgui_time_sink_f.h +++ b/gr-qtgui/lib/qtgui_time_sink_f.h @@ -25,7 +25,7 @@ #include #include -#include +#include #include #include #include @@ -39,7 +39,7 @@ GR_QTGUI_API qtgui_time_sink_f_sptr qtgui_make_time_sink_f(int size, double bw, int nconnectons=1, QWidget *parent=NULL); -class GR_QTGUI_API qtgui_time_sink_f : public gr_block +class GR_QTGUI_API qtgui_time_sink_f : public gr_sync_block { private: friend GR_QTGUI_API qtgui_time_sink_f_sptr qtgui_make_time_sink_f(int size, double bw, @@ -51,8 +51,6 @@ private: int nconnections, QWidget *parent=NULL); - void forecast(int noutput_items, gr_vector_int &ninput_items_required); - void initialize(); int d_size; @@ -84,10 +82,9 @@ public: QApplication *d_qApplication; - int general_work (int noutput_items, - gr_vector_int &ninput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); + int work (int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); }; #endif /* INCLUDED_QTGUI_TIME_SINK_F_H */ -- cgit From 697562c3d4319ab6f13e4c2910a853409731595d Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Tue, 7 Jun 2011 21:48:02 -0400 Subject: qtgui: replace timespec with typedef so its easier to replace --- gr-qtgui/lib/ConstellationDisplayPlot.cc | 4 +- gr-qtgui/lib/ConstellationDisplayPlot.h | 2 +- gr-qtgui/lib/FrequencyDisplayPlot.cc | 4 +- gr-qtgui/lib/FrequencyDisplayPlot.h | 2 +- gr-qtgui/lib/SpectrumGUIClass.cc | 20 ++-- gr-qtgui/lib/SpectrumGUIClass.h | 8 +- gr-qtgui/lib/WaterfallDisplayPlot.cc | 18 +-- gr-qtgui/lib/WaterfallDisplayPlot.h | 4 +- gr-qtgui/lib/highResTimeFunctions.h | 196 +++++++++++++++++-------------- gr-qtgui/lib/qtgui_sink_c.cc | 2 +- gr-qtgui/lib/qtgui_sink_f.cc | 2 +- gr-qtgui/lib/qtgui_time_sink_c.cc | 4 +- gr-qtgui/lib/qtgui_time_sink_f.cc | 4 +- gr-qtgui/lib/spectrumUpdateEvents.cc | 8 +- gr-qtgui/lib/spectrumUpdateEvents.h | 12 +- gr-qtgui/lib/spectrumdisplayform.cc | 4 +- 16 files changed, 159 insertions(+), 135 deletions(-) (limited to 'gr-qtgui/lib') diff --git a/gr-qtgui/lib/ConstellationDisplayPlot.cc b/gr-qtgui/lib/ConstellationDisplayPlot.cc index 7ec2db820..fc3293bc7 100644 --- a/gr-qtgui/lib/ConstellationDisplayPlot.cc +++ b/gr-qtgui/lib/ConstellationDisplayPlot.cc @@ -58,7 +58,7 @@ protected: ConstellationDisplayPlot::ConstellationDisplayPlot(QWidget* parent) : QwtPlot(parent) { - timespec_reset(&_lastReplot); + highres_timespec_reset(&_lastReplot); resize(parent->width(), parent->height()); @@ -183,7 +183,7 @@ void ConstellationDisplayPlot::PlotNewData(const double* realDataPoints, const double timeInterval) { if((numDataPoints > 0) && - (diff_timespec(get_highres_clock(), _lastReplot) > timeInterval)) { + (diff_highres_timespec(get_highres_clock(), _lastReplot) > timeInterval)) { if(numDataPoints != _numPoints){ _numPoints = numDataPoints; diff --git a/gr-qtgui/lib/ConstellationDisplayPlot.h b/gr-qtgui/lib/ConstellationDisplayPlot.h index 3a85f3bc3..38e401c68 100644 --- a/gr-qtgui/lib/ConstellationDisplayPlot.h +++ b/gr-qtgui/lib/ConstellationDisplayPlot.h @@ -83,7 +83,7 @@ private: double* _realDataPoints; double* _imagDataPoints; - timespec _lastReplot; + highres_timespec _lastReplot; int64_t _numPoints; int64_t _penSize; diff --git a/gr-qtgui/lib/FrequencyDisplayPlot.cc b/gr-qtgui/lib/FrequencyDisplayPlot.cc index 4d60cd9be..e8c8e230d 100644 --- a/gr-qtgui/lib/FrequencyDisplayPlot.cc +++ b/gr-qtgui/lib/FrequencyDisplayPlot.cc @@ -120,7 +120,7 @@ FrequencyDisplayPlot::FrequencyDisplayPlot(QWidget* parent) _startFrequency = 0; _stopFrequency = 4000; - timespec_reset(&_lastReplot); + highres_timespec_reset(&_lastReplot); resize(parent->width(), parent->height()); @@ -362,7 +362,7 @@ FrequencyDisplayPlot::PlotNewData(const double* dataPoints, const int64_t numDat { // Only update plot if there is data and if the time interval has elapsed if((numDataPoints > 0) && - (diff_timespec(get_highres_clock(), _lastReplot) > timeInterval)) { + (diff_highres_timespec(get_highres_clock(), _lastReplot) > timeInterval)) { if(numDataPoints != _numPoints) { _numPoints = numDataPoints; diff --git a/gr-qtgui/lib/FrequencyDisplayPlot.h b/gr-qtgui/lib/FrequencyDisplayPlot.h index 6689703bc..98c8d77b1 100644 --- a/gr-qtgui/lib/FrequencyDisplayPlot.h +++ b/gr-qtgui/lib/FrequencyDisplayPlot.h @@ -122,7 +122,7 @@ private: double _noiseFloorAmplitude; - timespec _lastReplot; + highres_timespec _lastReplot; bool _useCenterFrequencyFlag; }; diff --git a/gr-qtgui/lib/SpectrumGUIClass.cc b/gr-qtgui/lib/SpectrumGUIClass.cc index b472470c6..798554ab6 100644 --- a/gr-qtgui/lib/SpectrumGUIClass.cc +++ b/gr-qtgui/lib/SpectrumGUIClass.cc @@ -54,7 +54,7 @@ SpectrumGUIClass::SpectrumGUIClass(const uint64_t maxDataSize, _windowType = 5; - timespec_reset(&_lastGUIUpdateTime); + highres_timespec_reset(&_lastGUIUpdateTime); _windowOpennedFlag = false; _fftBuffersCreatedFlag = false; @@ -123,7 +123,7 @@ SpectrumGUIClass::OpenSpectrumWindow(QWidget* parent, qApp->postEvent(_spectrumDisplayForm, new QEvent(QEvent::Type(QEvent::User+3))); - timespec_reset(&_lastGUIUpdateTime); + highres_timespec_reset(&_lastGUIUpdateTime); // Draw Blank Display UpdateWindow(false, NULL, 0, NULL, 0, NULL, 0, get_highres_clock(), true); @@ -229,7 +229,7 @@ SpectrumGUIClass::UpdateWindow(const bool updateDisplayFlag, const uint64_t realTimeDomainDataSize, const float* complexTimeDomainData, const uint64_t complexTimeDomainDataSize, - const timespec timestamp, + const highres_timespec timestamp, const bool lastOfMultipleFFTUpdateFlag) { //gruel::scoped_lock lock(d_mutex); @@ -283,11 +283,11 @@ SpectrumGUIClass::UpdateWindow(const bool updateDisplayFlag, _lastDataPointCount = bufferSize; } - const timespec currentTime = get_highres_clock(); - const timespec lastUpdateGUITime = GetLastGUIUpdateTime(); + const highres_timespec currentTime = get_highres_clock(); + const highres_timespec lastUpdateGUITime = GetLastGUIUpdateTime(); - if((diff_timespec(currentTime, lastUpdateGUITime) > (4*_updateTime)) && - (GetPendingGUIUpdateEvents() > 0) && !timespec_empty(&lastUpdateGUITime)) { + if((diff_highres_timespec(currentTime, lastUpdateGUITime) > (4*_updateTime)) && + (GetPendingGUIUpdateEvents() > 0) && !highres_timespec_empty(&lastUpdateGUITime)) { // Do not update the display if too much data is pending to be displayed _droppedEntriesCount++; } @@ -376,17 +376,17 @@ SpectrumGUIClass::SetFFTSize(const int newSize) _fftSize = newSize; } -timespec +highres_timespec SpectrumGUIClass::GetLastGUIUpdateTime() { gruel::scoped_lock lock(d_mutex); - timespec returnValue; + highres_timespec returnValue; returnValue = _lastGUIUpdateTime; return returnValue; } void -SpectrumGUIClass::SetLastGUIUpdateTime(const timespec newTime) +SpectrumGUIClass::SetLastGUIUpdateTime(const highres_timespec newTime) { gruel::scoped_lock lock(d_mutex); _lastGUIUpdateTime = newTime; diff --git a/gr-qtgui/lib/SpectrumGUIClass.h b/gr-qtgui/lib/SpectrumGUIClass.h index ad06674f5..95f010671 100644 --- a/gr-qtgui/lib/SpectrumGUIClass.h +++ b/gr-qtgui/lib/SpectrumGUIClass.h @@ -66,7 +66,7 @@ public: const uint64_t, const float*, const uint64_t, const float*, const uint64_t, - const timespec, const bool); + const highres_timespec, const bool); float GetPowerValue(); void SetPowerValue(const float); @@ -78,8 +78,8 @@ public: int GetFFTSizeIndex(); void SetFFTSize(const int); - timespec GetLastGUIUpdateTime(); - void SetLastGUIUpdateTime(const timespec); + highres_timespec GetLastGUIUpdateTime(); + void SetLastGUIUpdateTime(const highres_timespec); unsigned int GetPendingGUIUpdateEvents(); void IncrementPendingGUIUpdateEvents(); @@ -114,7 +114,7 @@ private: int _windowType; int64_t _lastDataPointCount; int _fftSize; - timespec _lastGUIUpdateTime; + highres_timespec _lastGUIUpdateTime; unsigned int _pendingGUIUpdateEventsCount; int _droppedEntriesCount; bool _fftBuffersCreatedFlag; diff --git a/gr-qtgui/lib/WaterfallDisplayPlot.cc b/gr-qtgui/lib/WaterfallDisplayPlot.cc index 52381a9f6..9bcbc46d0 100644 --- a/gr-qtgui/lib/WaterfallDisplayPlot.cc +++ b/gr-qtgui/lib/WaterfallDisplayPlot.cc @@ -110,7 +110,7 @@ class TimeScaleData public: TimeScaleData() { - timespec_reset(&_zeroTime); + highres_timespec_reset(&_zeroTime); _secondsPerLine = 1.0; } @@ -118,12 +118,12 @@ public: { } - virtual timespec GetZeroTime() const + virtual highres_timespec GetZeroTime() const { return _zeroTime; } - virtual void SetZeroTime(const timespec newTime) + virtual void SetZeroTime(const highres_timespec newTime) { _zeroTime = newTime; } @@ -140,7 +140,7 @@ public: protected: - timespec _zeroTime; + highres_timespec _zeroTime; double _secondsPerLine; private: @@ -160,7 +160,7 @@ public: virtual QwtText label(double value) const { - timespec lineTime = timespec_add(GetZeroTime(), (-value) * GetSecondsPerLine()); + highres_timespec lineTime = highres_timespec_add(GetZeroTime(), -value*GetSecondsPerLine()); std::string time_str = pt::to_simple_string(pt::from_time_t(lineTime.tv_sec)); // lops off the YYYY-mmm-DD part of the string @@ -212,7 +212,7 @@ protected: using QwtPlotZoomer::trackerText; virtual QwtText trackerText( const QwtDoublePoint& p ) const { - timespec lineTime = timespec_add(GetZeroTime(), (-p.y()) * GetSecondsPerLine()); + highres_timespec lineTime = highres_timespec_add(GetZeroTime(), -p.y()*GetSecondsPerLine()); std::string time_str = pt::to_simple_string(pt::from_time_t(lineTime.tv_sec)); // lops off the YYYY-mmm-DD part of the string @@ -254,7 +254,7 @@ WaterfallDisplayPlot::WaterfallDisplayPlot(QWidget* parent) setAxisTitle(QwtPlot::yLeft, "Time"); setAxisScaleDraw(QwtPlot::yLeft, new QwtTimeScaleDraw()); - timespec_reset(&_lastReplot); + highres_timespec_reset(&_lastReplot); d_spectrogram = new PlotWaterfall(_waterfallData, "Waterfall Display"); @@ -389,7 +389,7 @@ void WaterfallDisplayPlot::PlotNewData(const double* dataPoints, const int64_t numDataPoints, const double timePerFFT, - const timespec timestamp, + const highres_timespec timestamp, const int droppedFrames) { if(numDataPoints > 0){ @@ -408,7 +408,7 @@ WaterfallDisplayPlot::PlotNewData(const double* dataPoints, _lastReplot = get_highres_clock(); } - if(diff_timespec(get_highres_clock(), _lastReplot) > timePerFFT) { + if(diff_highres_timespec(get_highres_clock(), _lastReplot) > timePerFFT) { //FIXME: We may want to average the data between these updates to smooth display _waterfallData->addFFTData(dataPoints, numDataPoints, droppedFrames); _waterfallData->IncrementNumLinesToUpdate(); diff --git a/gr-qtgui/lib/WaterfallDisplayPlot.h b/gr-qtgui/lib/WaterfallDisplayPlot.h index 583bf9407..435453fcc 100644 --- a/gr-qtgui/lib/WaterfallDisplayPlot.h +++ b/gr-qtgui/lib/WaterfallDisplayPlot.h @@ -51,7 +51,7 @@ public: double GetStopFrequency()const; void PlotNewData(const double* dataPoints, const int64_t numDataPoints, - const double timePerFFT, const timespec timestamp, + const double timePerFFT, const highres_timespec timestamp, const int droppedFrames); void SetIntensityRange(const double minIntensity, const double maxIntensity); @@ -98,7 +98,7 @@ private: WaterfallData* _waterfallData; - timespec _lastReplot; + highres_timespec _lastReplot; bool _useCenterFrequencyFlag; diff --git a/gr-qtgui/lib/highResTimeFunctions.h b/gr-qtgui/lib/highResTimeFunctions.h index 251bbad8b..de08d8adc 100644 --- a/gr-qtgui/lib/highResTimeFunctions.h +++ b/gr-qtgui/lib/highResTimeFunctions.h @@ -1,3 +1,25 @@ +/* -*- c++ -*- */ +/* + * Copyright 2011 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 HIGH_RES_TIME_FUNCTIONS_H #define HIGH_RES_TIME_FUNCTIONS_H @@ -6,11 +28,13 @@ #include /* Requires the librt and libm libraries */ +typedef timespec highres_timespec; + static const long NSEC_PER_SEC = 1000000000L; static inline bool -timespec_greater(const struct timespec* t1, - const struct timespec* t0) +highres_timespec_greater(const highres_timespec* t1, + const highres_timespec* t0) { return ((t1->tv_sec > t0->tv_sec) || ((t1->tv_sec == t0->tv_sec) && @@ -18,8 +42,8 @@ timespec_greater(const struct timespec* t1, } static inline bool -timespec_greater(const struct timespec t1, - const struct timespec t0) +highres_timespec_greater(const highres_timespec t1, + const highres_timespec t0) { return ((t1.tv_sec > t0.tv_sec) || ((t1.tv_sec == t0.tv_sec) && @@ -27,8 +51,8 @@ timespec_greater(const struct timespec t1, } static inline bool -timespec_less(const struct timespec* t1, - const struct timespec* t0) +highres_timespec_less(const highres_timespec* t1, + const highres_timespec* t0) { return ((t1->tv_sec < t0->tv_sec) || ((t1->tv_sec == t0->tv_sec) && @@ -36,8 +60,8 @@ timespec_less(const struct timespec* t1, } static inline bool -timespec_less(const struct timespec t1, - const struct timespec t0) +highres_timespec_less(const highres_timespec t1, + const highres_timespec t0) { return ((t1.tv_sec < t0.tv_sec) || ((t1.tv_sec == t0.tv_sec) && @@ -45,31 +69,31 @@ timespec_less(const struct timespec t1, } static inline bool -timespec_equal(const struct timespec* t1, - const struct timespec* t0) +highres_timespec_equal(const highres_timespec* t1, + const highres_timespec* t0) { return ((t1->tv_sec == t0->tv_sec) && (t1->tv_nsec == t0->tv_nsec)); } static inline bool -timespec_equal(const struct timespec t1, - const struct timespec t0) +highres_timespec_equal(const highres_timespec t1, + const highres_timespec t0) { return ((t1.tv_sec == t0.tv_sec) && (t1.tv_nsec == t0.tv_nsec)); } static inline void -timespec_reset(struct timespec* ret) +highres_timespec_reset(highres_timespec* ret) { ret->tv_sec = 0; ret->tv_nsec = 0; } static inline void -set_normalized_timespec(struct timespec *ts, - time_t sec, long nsec) +set_normalized_highres_timespec(highres_timespec *ts, + time_t sec, long nsec) { while (nsec > NSEC_PER_SEC) { nsec -= NSEC_PER_SEC; @@ -83,22 +107,22 @@ set_normalized_timespec(struct timespec *ts, ts->tv_nsec = nsec; } -static inline struct timespec -convert_to_timespec(const double timeValue) +static inline highres_timespec +convert_to_highres_timespec(const double timeValue) { - struct timespec ret; + highres_timespec ret; double seconds = 0; long nsec = static_cast(modf(timeValue, &seconds) * static_cast(NSEC_PER_SEC)); time_t sec = static_cast(seconds); - set_normalized_timespec(&ret, sec, nsec); + set_normalized_highres_timespec(&ret, sec, nsec); return ret; } static inline double -convert_from_timespec(const timespec actual) +convert_from_highres_timespec(const highres_timespec actual) { return (static_cast(actual.tv_sec) + (static_cast(actual.tv_nsec) / @@ -106,108 +130,108 @@ convert_from_timespec(const timespec actual) } static inline void -timespec_add(struct timespec *ret, - const struct timespec* t1, - const struct timespec* t0) +highres_timespec_add(highres_timespec *ret, + const highres_timespec* t1, + const highres_timespec* t0) { time_t sec = t1->tv_sec + t0->tv_sec; long nsec = t1->tv_nsec + t0->tv_nsec; - set_normalized_timespec(ret, sec, nsec); + set_normalized_highres_timespec(ret, sec, nsec); } static inline void -timespec_add(struct timespec *ret, - const struct timespec t1, - const struct timespec t0) +highres_timespec_add(highres_timespec *ret, + const highres_timespec t1, + const highres_timespec t0) { - return timespec_add(ret, &t1, &t0); + return highres_timespec_add(ret, &t1, &t0); } -static inline struct timespec -timespec_add(const struct timespec t1, - const struct timespec t0) +static inline highres_timespec +highres_timespec_add(const highres_timespec t1, + const highres_timespec t0) { - struct timespec ret; - timespec_add(&ret, &t1, &t0); + highres_timespec ret; + highres_timespec_add(&ret, &t1, &t0); return ret; } -static inline struct timespec -timespec_add(const struct timespec t1, - const double time0) +static inline highres_timespec +highres_timespec_add(const highres_timespec t1, + const double time0) { - struct timespec ret; - struct timespec t0; - t0 = convert_to_timespec(time0); + highres_timespec ret; + highres_timespec t0; + t0 = convert_to_highres_timespec(time0); - timespec_add(&ret, &t1, &t0); + highres_timespec_add(&ret, &t1, &t0); return ret; } static inline void -timespec_subtract(struct timespec *ret, - const struct timespec* t1, - const struct timespec* t0) +highres_timespec_subtract(highres_timespec *ret, + const highres_timespec* t1, + const highres_timespec* t0) { time_t sec = t1->tv_sec - t0->tv_sec; long nsec = t1->tv_nsec - t0->tv_nsec; - set_normalized_timespec(ret, sec, nsec); + set_normalized_highres_timespec(ret, sec, nsec); } static inline void -timespec_subtract(struct timespec *ret, - const struct timespec t1, - const struct timespec t0) +highres_timespec_subtract(highres_timespec *ret, + const highres_timespec t1, + const highres_timespec t0) { - return timespec_subtract(ret, &t1, &t0); + return highres_timespec_subtract(ret, &t1, &t0); } -static inline struct timespec -timespec_subtract(const struct timespec t1, - const struct timespec t0) +static inline highres_timespec +highres_timespec_subtract(const highres_timespec t1, + const highres_timespec t0) { - struct timespec ret; - timespec_subtract(&ret, &t1, &t0); + highres_timespec ret; + highres_timespec_subtract(&ret, &t1, &t0); return ret; } -static inline struct timespec -timespec_subtract(const struct timespec t1, - const double time0) +static inline highres_timespec +highres_timespec_subtract(const highres_timespec t1, + const double time0) { - struct timespec ret; - struct timespec t0; - t0 = convert_to_timespec(time0); + highres_timespec ret; + highres_timespec t0; + t0 = convert_to_highres_timespec(time0); - timespec_subtract(&ret, &t1, &t0); + highres_timespec_subtract(&ret, &t1, &t0); return ret; } static inline double -diff_timespec(struct timespec* ret, - const struct timespec *t1, - const struct timespec* t0) +diff_highres_timespec(highres_timespec* ret, + const highres_timespec *t1, + const highres_timespec* t0) { - struct timespec actual; + highres_timespec actual; time_t sec = 0; long nsec = 0; - if(timespec_greater(t1, t0)){ + if(highres_timespec_greater(t1, t0)){ sec = t1->tv_sec - t0->tv_sec; nsec = t1->tv_nsec - t0->tv_nsec; - set_normalized_timespec(&actual, sec, nsec); + set_normalized_highres_timespec(&actual, sec, nsec); if(ret != NULL){ ret->tv_sec = actual.tv_sec; ret->tv_nsec = actual.tv_nsec; } - return convert_from_timespec(actual); + return convert_from_highres_timespec(actual); } else{ sec = t0->tv_sec - t1->tv_sec; @@ -216,33 +240,33 @@ diff_timespec(struct timespec* ret, // Do nothing with the ret value as the ret value // would have to store a negative, which it can't. - set_normalized_timespec(&actual, sec, nsec); + set_normalized_highres_timespec(&actual, sec, nsec); - return (-convert_from_timespec(actual)); + return (-convert_from_highres_timespec(actual)); } } static inline double -diff_timespec(struct timespec* ret, - const struct timespec t1, - const struct timespec t0) +diff_highres_timespec(highres_timespec* ret, + const highres_timespec t1, + const highres_timespec t0) { - return diff_timespec(ret, &t1, &t0); + return diff_highres_timespec(ret, &t1, &t0); } static inline double -diff_timespec(const struct timespec t1, - const struct timespec t0) +diff_highres_timespec(const highres_timespec t1, + const highres_timespec t0) { - return diff_timespec(NULL, &t1, &t0); + return diff_highres_timespec(NULL, &t1, &t0); } static inline double -diff_timespec(const struct timespec* t1, - const struct timespec* t0) +diff_highres_timespec(const highres_timespec* t1, + const highres_timespec* t0) { - return diff_timespec(NULL, t1, t0); + return diff_highres_timespec(NULL, t1, t0); } @@ -250,7 +274,7 @@ diff_timespec(const struct timespec* t1, // If we can use clock_gettime, use it; // otherwise, use gettimeofday static inline void -get_highres_clock(struct timespec* ret) +get_highres_clock(highres_timespec* ret) { if(clock_gettime(CLOCK_REALTIME, ret) != 0){ // Unable to get high resolution time - @@ -267,7 +291,7 @@ get_highres_clock(struct timespec* ret) // Trick timer functions into thinking it has an nsec timer // but only use the low resolution (usec) timer. static inline void -get_highres_clock(struct timespec* ret) +get_highres_clock(highres_timespec* ret) { timeval lowResTime; gettimeofday(&lowResTime, NULL); @@ -276,24 +300,24 @@ get_highres_clock(struct timespec* ret) } #endif -static inline struct timespec +static inline highres_timespec get_highres_clock() { - struct timespec ret; + highres_timespec ret; get_highres_clock(&ret); return ret; } static inline bool -timespec_empty(const struct timespec* ret) +highres_timespec_empty(const highres_timespec* ret) { return ( (ret->tv_sec == 0 ) && (ret->tv_nsec == 0) ); } static inline bool -timespec_empty(const struct timespec ret) +highres_timespec_empty(const highres_timespec ret) { - return timespec_empty(&ret); + return highres_timespec_empty(&ret); } #endif /* HIGH_RES_TIME_FUNCTIONS_H */ diff --git a/gr-qtgui/lib/qtgui_sink_c.cc b/gr-qtgui/lib/qtgui_sink_c.cc index 7b40dd01d..e980318ca 100644 --- a/gr-qtgui/lib/qtgui_sink_c.cc +++ b/gr-qtgui/lib/qtgui_sink_c.cc @@ -272,7 +272,7 @@ qtgui_sink_c::general_work (int noutput_items, // If we have enough input for one full FFT, do it if(datasize >= resid) { - const timespec currentTime = get_highres_clock(); + const highres_timespec currentTime = get_highres_clock(); // Fill up residbuf with d_fftsize number of items memcpy(d_residbuf+d_index, &in[j], sizeof(gr_complex)*resid); diff --git a/gr-qtgui/lib/qtgui_sink_f.cc b/gr-qtgui/lib/qtgui_sink_f.cc index 3312b9006..4e1799150 100644 --- a/gr-qtgui/lib/qtgui_sink_f.cc +++ b/gr-qtgui/lib/qtgui_sink_f.cc @@ -268,7 +268,7 @@ qtgui_sink_f::general_work (int noutput_items, // If we have enough input for one full FFT, do it if(datasize >= resid) { - const timespec currentTime = get_highres_clock(); + const highres_timespec currentTime = get_highres_clock(); // Fill up residbuf with d_fftsize number of items memcpy(d_residbuf+d_index, &in[j], sizeof(float)*resid); diff --git a/gr-qtgui/lib/qtgui_time_sink_c.cc b/gr-qtgui/lib/qtgui_time_sink_c.cc index 6c4793ea1..a4fc48536 100644 --- a/gr-qtgui/lib/qtgui_time_sink_c.cc +++ b/gr-qtgui/lib/qtgui_time_sink_c.cc @@ -94,7 +94,7 @@ qtgui_time_sink_c::initialize() // initialize update time to 10 times a second set_update_time(0.1); - timespec_reset(&d_last_time); + highres_timespec_reset(&d_last_time); } @@ -171,7 +171,7 @@ qtgui_time_sink_c::general_work (int noutput_items, } // Update the plot if its time - if(diff_timespec(d_current_time, d_last_time) > d_update_time) { + if(diff_highres_timespec(d_current_time, d_last_time) > d_update_time) { d_last_time = d_current_time; d_qApplication->postEvent(d_main_gui, new TimeUpdateEvent(d_residbufs, d_size)); diff --git a/gr-qtgui/lib/qtgui_time_sink_f.cc b/gr-qtgui/lib/qtgui_time_sink_f.cc index 28789c163..e04109e96 100644 --- a/gr-qtgui/lib/qtgui_time_sink_f.cc +++ b/gr-qtgui/lib/qtgui_time_sink_f.cc @@ -94,7 +94,7 @@ qtgui_time_sink_f::initialize() // initialize update time to 10 times a second set_update_time(0.1); - timespec_reset(&d_last_time); + highres_timespec_reset(&d_last_time); } @@ -170,7 +170,7 @@ qtgui_time_sink_f::general_work (int noutput_items, } // Update the plot if its time - if(diff_timespec(d_current_time, d_last_time) > d_update_time) { + if(diff_highres_timespec(d_current_time, d_last_time) > d_update_time) { d_last_time = d_current_time; d_qApplication->postEvent(d_main_gui, new TimeUpdateEvent(d_residbufs, d_size)); diff --git a/gr-qtgui/lib/spectrumUpdateEvents.cc b/gr-qtgui/lib/spectrumUpdateEvents.cc index ae4caf31a..6d7ca2701 100644 --- a/gr-qtgui/lib/spectrumUpdateEvents.cc +++ b/gr-qtgui/lib/spectrumUpdateEvents.cc @@ -8,10 +8,10 @@ SpectrumUpdateEvent::SpectrumUpdateEvent(const std::complex* fftPoints, const double* realTimeDomainPoints, const double* imagTimeDomainPoints, const uint64_t numTimeDomainDataPoints, - const timespec dataTimestamp, + const highres_timespec dataTimestamp, const bool repeatDataFlag, const bool lastOfMultipleUpdateFlag, - const timespec generatedTimestamp, + const highres_timespec generatedTimestamp, const int droppedFFTFrames) : QEvent(QEvent::Type(10005)) { @@ -90,7 +90,7 @@ SpectrumUpdateEvent::getNumTimeDomainDataPoints() const return _numTimeDomainDataPoints; } -timespec +highres_timespec SpectrumUpdateEvent::getDataTimestamp() const { return _dataTimestamp; @@ -108,7 +108,7 @@ SpectrumUpdateEvent::getLastOfMultipleUpdateFlag() const return _lastOfMultipleUpdateFlag; } -timespec +highres_timespec SpectrumUpdateEvent::getEventGeneratedTimestamp() const { return _eventGeneratedTimestamp; diff --git a/gr-qtgui/lib/spectrumUpdateEvents.h b/gr-qtgui/lib/spectrumUpdateEvents.h index a5e359a4c..9224cad08 100644 --- a/gr-qtgui/lib/spectrumUpdateEvents.h +++ b/gr-qtgui/lib/spectrumUpdateEvents.h @@ -16,10 +16,10 @@ public: const double* realTimeDomainPoints, const double* imagTimeDomainPoints, const uint64_t numTimeDomainDataPoints, - const timespec dataTimestamp, + const highres_timespec dataTimestamp, const bool repeatDataFlag, const bool lastOfMultipleUpdateFlag, - const timespec generatedTimestamp, + const highres_timespec generatedTimestamp, const int droppedFFTFrames); ~SpectrumUpdateEvent(); @@ -29,10 +29,10 @@ public: const double* getImagTimeDomainPoints() const; uint64_t getNumFFTDataPoints() const; uint64_t getNumTimeDomainDataPoints() const; - timespec getDataTimestamp() const; + highres_timespec getDataTimestamp() const; bool getRepeatDataFlag() const; bool getLastOfMultipleUpdateFlag() const; - timespec getEventGeneratedTimestamp() const; + highres_timespec getEventGeneratedTimestamp() const; int getDroppedFFTFrames() const; protected: @@ -43,10 +43,10 @@ private: double* _imagDataTimeDomainPoints; uint64_t _numFFTDataPoints; uint64_t _numTimeDomainDataPoints; - timespec _dataTimestamp; + highres_timespec _dataTimestamp; bool _repeatDataFlag; bool _lastOfMultipleUpdateFlag; - timespec _eventGeneratedTimestamp; + highres_timespec _eventGeneratedTimestamp; int _droppedFFTFrames; }; diff --git a/gr-qtgui/lib/spectrumdisplayform.cc b/gr-qtgui/lib/spectrumdisplayform.cc index 991f51f47..df1903391 100644 --- a/gr-qtgui/lib/spectrumdisplayform.cc +++ b/gr-qtgui/lib/spectrumdisplayform.cc @@ -145,10 +145,10 @@ SpectrumDisplayForm::newFrequencyData( const SpectrumUpdateEvent* spectrumUpdate const std::complex* complexDataPoints = spectrumUpdateEvent->getFFTPoints(); const uint64_t numFFTDataPoints = spectrumUpdateEvent->getNumFFTDataPoints(); const uint64_t numTimeDomainDataPoints = spectrumUpdateEvent->getNumTimeDomainDataPoints(); - const timespec dataTimestamp = spectrumUpdateEvent->getDataTimestamp(); + const highres_timespec dataTimestamp = spectrumUpdateEvent->getDataTimestamp(); const bool repeatDataFlag = spectrumUpdateEvent->getRepeatDataFlag(); const bool lastOfMultipleUpdatesFlag = spectrumUpdateEvent->getLastOfMultipleUpdateFlag(); - const timespec generatedTimestamp = spectrumUpdateEvent->getEventGeneratedTimestamp(); + const highres_timespec generatedTimestamp = spectrumUpdateEvent->getEventGeneratedTimestamp(); double* realTimeDomainDataPoints = (double*)spectrumUpdateEvent->getRealTimeDomainPoints(); double* imagTimeDomainDataPoints = (double*)spectrumUpdateEvent->getImagTimeDomainPoints(); -- cgit From 1418dccc89f554202e33d4d743c910407e8710a6 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Tue, 7 Jun 2011 22:27:35 -0400 Subject: qtgui: partially switch to gruel high res timer --- gr-qtgui/lib/ConstellationDisplayPlot.cc | 2 +- gr-qtgui/lib/FrequencyDisplayPlot.cc | 2 +- gr-qtgui/lib/SpectrumGUIClass.cc | 6 +- gr-qtgui/lib/WaterfallDisplayPlot.cc | 14 +- gr-qtgui/lib/highResTimeFunctions.h | 284 ++----------------------------- gr-qtgui/lib/qtgui_time_sink_c.cc | 2 +- gr-qtgui/lib/qtgui_time_sink_c.h | 4 +- gr-qtgui/lib/qtgui_time_sink_f.cc | 2 +- gr-qtgui/lib/qtgui_time_sink_f.h | 4 +- 9 files changed, 31 insertions(+), 289 deletions(-) (limited to 'gr-qtgui/lib') diff --git a/gr-qtgui/lib/ConstellationDisplayPlot.cc b/gr-qtgui/lib/ConstellationDisplayPlot.cc index fc3293bc7..77550de81 100644 --- a/gr-qtgui/lib/ConstellationDisplayPlot.cc +++ b/gr-qtgui/lib/ConstellationDisplayPlot.cc @@ -58,7 +58,7 @@ protected: ConstellationDisplayPlot::ConstellationDisplayPlot(QWidget* parent) : QwtPlot(parent) { - highres_timespec_reset(&_lastReplot); + highres_timespec_reset(_lastReplot); resize(parent->width(), parent->height()); diff --git a/gr-qtgui/lib/FrequencyDisplayPlot.cc b/gr-qtgui/lib/FrequencyDisplayPlot.cc index e8c8e230d..6b3fa175b 100644 --- a/gr-qtgui/lib/FrequencyDisplayPlot.cc +++ b/gr-qtgui/lib/FrequencyDisplayPlot.cc @@ -120,7 +120,7 @@ FrequencyDisplayPlot::FrequencyDisplayPlot(QWidget* parent) _startFrequency = 0; _stopFrequency = 4000; - highres_timespec_reset(&_lastReplot); + highres_timespec_reset(_lastReplot); resize(parent->width(), parent->height()); diff --git a/gr-qtgui/lib/SpectrumGUIClass.cc b/gr-qtgui/lib/SpectrumGUIClass.cc index 798554ab6..fda58d78e 100644 --- a/gr-qtgui/lib/SpectrumGUIClass.cc +++ b/gr-qtgui/lib/SpectrumGUIClass.cc @@ -54,7 +54,7 @@ SpectrumGUIClass::SpectrumGUIClass(const uint64_t maxDataSize, _windowType = 5; - highres_timespec_reset(&_lastGUIUpdateTime); + highres_timespec_reset(_lastGUIUpdateTime); _windowOpennedFlag = false; _fftBuffersCreatedFlag = false; @@ -123,7 +123,7 @@ SpectrumGUIClass::OpenSpectrumWindow(QWidget* parent, qApp->postEvent(_spectrumDisplayForm, new QEvent(QEvent::Type(QEvent::User+3))); - highres_timespec_reset(&_lastGUIUpdateTime); + highres_timespec_reset(_lastGUIUpdateTime); // Draw Blank Display UpdateWindow(false, NULL, 0, NULL, 0, NULL, 0, get_highres_clock(), true); @@ -287,7 +287,7 @@ SpectrumGUIClass::UpdateWindow(const bool updateDisplayFlag, const highres_timespec lastUpdateGUITime = GetLastGUIUpdateTime(); if((diff_highres_timespec(currentTime, lastUpdateGUITime) > (4*_updateTime)) && - (GetPendingGUIUpdateEvents() > 0) && !highres_timespec_empty(&lastUpdateGUITime)) { + (GetPendingGUIUpdateEvents() > 0) && !highres_timespec_empty(lastUpdateGUITime)) { // Do not update the display if too much data is pending to be displayed _droppedEntriesCount++; } diff --git a/gr-qtgui/lib/WaterfallDisplayPlot.cc b/gr-qtgui/lib/WaterfallDisplayPlot.cc index 9bcbc46d0..cc7ab14a3 100644 --- a/gr-qtgui/lib/WaterfallDisplayPlot.cc +++ b/gr-qtgui/lib/WaterfallDisplayPlot.cc @@ -110,7 +110,7 @@ class TimeScaleData public: TimeScaleData() { - highres_timespec_reset(&_zeroTime); + highres_timespec_reset(_zeroTime); _secondsPerLine = 1.0; } @@ -161,13 +161,14 @@ public: virtual QwtText label(double value) const { highres_timespec lineTime = highres_timespec_add(GetZeroTime(), -value*GetSecondsPerLine()); - std::string time_str = pt::to_simple_string(pt::from_time_t(lineTime.tv_sec)); + unsigned long milliseconds = lineTime*1000/gruel::high_res_timer_tps(); + std::string time_str = pt::to_simple_string(pt::from_time_t(milliseconds/1000)); // lops off the YYYY-mmm-DD part of the string size_t ind = time_str.find(" "); if(ind != std::string::npos) time_str = time_str.substr(ind); - return QwtText(QString("").sprintf("%s.%03ld", time_str.c_str(), lineTime.tv_nsec/1000000)); + return QwtText(QString("").sprintf("%s.%03ld", time_str.c_str(), milliseconds%1000)); } virtual void initiateUpdate() @@ -213,13 +214,14 @@ protected: virtual QwtText trackerText( const QwtDoublePoint& p ) const { highres_timespec lineTime = highres_timespec_add(GetZeroTime(), -p.y()*GetSecondsPerLine()); - std::string time_str = pt::to_simple_string(pt::from_time_t(lineTime.tv_sec)); + unsigned long milliseconds = lineTime*1000/gruel::high_res_timer_tps(); + std::string time_str = pt::to_simple_string(pt::from_time_t(milliseconds/1000)); // lops off the YYYY-mmm-DD part of the string size_t ind = time_str.find(" "); if(ind != std::string::npos) time_str = time_str.substr(ind); - QString yLabel(QString("").sprintf("%s.%03ld", time_str.c_str(), lineTime.tv_nsec/1000000)); + QString yLabel(QString("").sprintf("%s.%03ld", time_str.c_str(), milliseconds%1000)); QwtText t(QString("%1 %2, %3"). arg(p.x(), 0, 'f', GetFrequencyPrecision()). @@ -254,7 +256,7 @@ WaterfallDisplayPlot::WaterfallDisplayPlot(QWidget* parent) setAxisTitle(QwtPlot::yLeft, "Time"); setAxisScaleDraw(QwtPlot::yLeft, new QwtTimeScaleDraw()); - highres_timespec_reset(&_lastReplot); + highres_timespec_reset(_lastReplot); d_spectrogram = new PlotWaterfall(_waterfallData, "Waterfall Display"); diff --git a/gr-qtgui/lib/highResTimeFunctions.h b/gr-qtgui/lib/highResTimeFunctions.h index de08d8adc..18cf66ede 100644 --- a/gr-qtgui/lib/highResTimeFunctions.h +++ b/gr-qtgui/lib/highResTimeFunctions.h @@ -23,301 +23,41 @@ #ifndef HIGH_RES_TIME_FUNCTIONS_H #define HIGH_RES_TIME_FUNCTIONS_H -#include -#include #include -/* Requires the librt and libm libraries */ +#include -typedef timespec highres_timespec; - -static const long NSEC_PER_SEC = 1000000000L; - -static inline bool -highres_timespec_greater(const highres_timespec* t1, - const highres_timespec* t0) -{ - return ((t1->tv_sec > t0->tv_sec) || - ((t1->tv_sec == t0->tv_sec) && - (t1->tv_nsec > t0->tv_nsec))); -} - -static inline bool -highres_timespec_greater(const highres_timespec t1, - const highres_timespec t0) -{ - return ((t1.tv_sec > t0.tv_sec) || - ((t1.tv_sec == t0.tv_sec) && - (t1.tv_nsec > t0.tv_nsec))); -} - -static inline bool -highres_timespec_less(const highres_timespec* t1, - const highres_timespec* t0) -{ - return ((t1->tv_sec < t0->tv_sec) || - ((t1->tv_sec == t0->tv_sec) && - (t1->tv_nsec < t0->tv_nsec))); -} - -static inline bool -highres_timespec_less(const highres_timespec t1, - const highres_timespec t0) -{ - return ((t1.tv_sec < t0.tv_sec) || - ((t1.tv_sec == t0.tv_sec) && - (t1.tv_nsec < t0.tv_nsec))); -} - -static inline bool -highres_timespec_equal(const highres_timespec* t1, - const highres_timespec* t0) -{ - return ((t1->tv_sec == t0->tv_sec) && - (t1->tv_nsec == t0->tv_nsec)); -} - -static inline bool -highres_timespec_equal(const highres_timespec t1, - const highres_timespec t0) -{ - return ((t1.tv_sec == t0.tv_sec) && - (t1.tv_nsec == t0.tv_nsec)); -} - -static inline void -highres_timespec_reset(highres_timespec* ret) -{ - ret->tv_sec = 0; - ret->tv_nsec = 0; -} - -static inline void -set_normalized_highres_timespec(highres_timespec *ts, - time_t sec, long nsec) -{ - while (nsec > NSEC_PER_SEC) { - nsec -= NSEC_PER_SEC; - ++sec; - } - while(nsec < 0) { - nsec += NSEC_PER_SEC; - --sec; - } - ts->tv_sec = sec; - ts->tv_nsec = nsec; -} - -static inline highres_timespec -convert_to_highres_timespec(const double timeValue) -{ - highres_timespec ret; - double seconds = 0; - long nsec = static_cast(modf(timeValue, &seconds) * - static_cast(NSEC_PER_SEC)); - time_t sec = static_cast(seconds); - - set_normalized_highres_timespec(&ret, sec, nsec); - - return ret; -} - -static inline double -convert_from_highres_timespec(const highres_timespec actual) -{ - return (static_cast(actual.tv_sec) + - (static_cast(actual.tv_nsec) / - static_cast(NSEC_PER_SEC))); -} - -static inline void -highres_timespec_add(highres_timespec *ret, - const highres_timespec* t1, - const highres_timespec* t0) -{ - time_t sec = t1->tv_sec + t0->tv_sec; - long nsec = t1->tv_nsec + t0->tv_nsec; - - set_normalized_highres_timespec(ret, sec, nsec); -} - -static inline void -highres_timespec_add(highres_timespec *ret, - const highres_timespec t1, - const highres_timespec t0) -{ - return highres_timespec_add(ret, &t1, &t0); -} - -static inline highres_timespec -highres_timespec_add(const highres_timespec t1, - const highres_timespec t0) -{ - highres_timespec ret; - highres_timespec_add(&ret, &t1, &t0); - return ret; -} - -static inline highres_timespec -highres_timespec_add(const highres_timespec t1, - const double time0) -{ - highres_timespec ret; - highres_timespec t0; - t0 = convert_to_highres_timespec(time0); - - highres_timespec_add(&ret, &t1, &t0); - - return ret; -} - -static inline void -highres_timespec_subtract(highres_timespec *ret, - const highres_timespec* t1, - const highres_timespec* t0) -{ - time_t sec = t1->tv_sec - t0->tv_sec; - long nsec = t1->tv_nsec - t0->tv_nsec; - - set_normalized_highres_timespec(ret, sec, nsec); -} +typedef gruel::high_res_timer_type highres_timespec; static inline void -highres_timespec_subtract(highres_timespec *ret, - const highres_timespec t1, - const highres_timespec t0) +highres_timespec_reset(highres_timespec &ret) { - return highres_timespec_subtract(ret, &t1, &t0); + ret = 0; } static inline highres_timespec -highres_timespec_subtract(const highres_timespec t1, - const highres_timespec t0) -{ - highres_timespec ret; - highres_timespec_subtract(&ret, &t1, &t0); - return ret; -} - -static inline highres_timespec -highres_timespec_subtract(const highres_timespec t1, - const double time0) -{ - highres_timespec ret; - highres_timespec t0; - t0 = convert_to_highres_timespec(time0); - - highres_timespec_subtract(&ret, &t1, &t0); - - return ret; -} - -static inline double -diff_highres_timespec(highres_timespec* ret, - const highres_timespec *t1, - const highres_timespec* t0) -{ - highres_timespec actual; - time_t sec = 0; - long nsec = 0; - - if(highres_timespec_greater(t1, t0)){ - sec = t1->tv_sec - t0->tv_sec; - nsec = t1->tv_nsec - t0->tv_nsec; - - set_normalized_highres_timespec(&actual, sec, nsec); - - if(ret != NULL){ - ret->tv_sec = actual.tv_sec; - ret->tv_nsec = actual.tv_nsec; - } - - return convert_from_highres_timespec(actual); - } - else{ - sec = t0->tv_sec - t1->tv_sec; - nsec = t0->tv_nsec - t1->tv_nsec; - - // Do nothing with the ret value as the ret value - // would have to store a negative, which it can't. - - set_normalized_highres_timespec(&actual, sec, nsec); - - return (-convert_from_highres_timespec(actual)); - } -} - -static inline double -diff_highres_timespec(highres_timespec* ret, - const highres_timespec t1, - const highres_timespec t0) -{ - return diff_highres_timespec(ret, &t1, &t0); -} - -static inline double -diff_highres_timespec(const highres_timespec t1, - const highres_timespec t0) +highres_timespec_add(const highres_timespec &t1, double t) { - return diff_highres_timespec(NULL, &t1, &t0); + return t1 + t*gruel::high_res_timer_tps(); } - static inline double -diff_highres_timespec(const highres_timespec* t1, - const highres_timespec* t0) +diff_highres_timespec(const highres_timespec &t1, + const highres_timespec &t0) { - return diff_highres_timespec(NULL, t1, t0); + return std::abs(double(t1 - t0)/gruel::high_res_timer_tps()); } - -#ifdef CLOCK_REALTIME -// If we can use clock_gettime, use it; -// otherwise, use gettimeofday -static inline void -get_highres_clock(highres_timespec* ret) -{ - if(clock_gettime(CLOCK_REALTIME, ret) != 0){ - // Unable to get high resolution time - - // fail over to low resolution time - timeval lowResTime; - gettimeofday(&lowResTime, NULL); - ret->tv_sec = lowResTime.tv_sec; - ret->tv_nsec = lowResTime.tv_usec*1000; - } -} - -#else - -// Trick timer functions into thinking it has an nsec timer -// but only use the low resolution (usec) timer. -static inline void -get_highres_clock(highres_timespec* ret) -{ - timeval lowResTime; - gettimeofday(&lowResTime, NULL); - ret->tv_sec = lowResTime.tv_sec; - ret->tv_nsec = lowResTime.tv_usec*1000; -} -#endif - static inline highres_timespec get_highres_clock() { - highres_timespec ret; - get_highres_clock(&ret); - return ret; + return gruel::high_res_timer_now(); } static inline bool -highres_timespec_empty(const highres_timespec* ret) +highres_timespec_empty(const highres_timespec &t) { - return ( (ret->tv_sec == 0 ) && (ret->tv_nsec == 0) ); + return t == 0; } -static inline bool -highres_timespec_empty(const highres_timespec ret) -{ - return highres_timespec_empty(&ret); -} #endif /* HIGH_RES_TIME_FUNCTIONS_H */ diff --git a/gr-qtgui/lib/qtgui_time_sink_c.cc b/gr-qtgui/lib/qtgui_time_sink_c.cc index a4fc48536..79b74f938 100644 --- a/gr-qtgui/lib/qtgui_time_sink_c.cc +++ b/gr-qtgui/lib/qtgui_time_sink_c.cc @@ -94,7 +94,7 @@ qtgui_time_sink_c::initialize() // initialize update time to 10 times a second set_update_time(0.1); - highres_timespec_reset(&d_last_time); + highres_timespec_reset(d_last_time); } diff --git a/gr-qtgui/lib/qtgui_time_sink_c.h b/gr-qtgui/lib/qtgui_time_sink_c.h index aa46ab3a7..f06ffa8f5 100644 --- a/gr-qtgui/lib/qtgui_time_sink_c.h +++ b/gr-qtgui/lib/qtgui_time_sink_c.h @@ -68,8 +68,8 @@ private: QWidget *d_parent; TimeDisplayForm *d_main_gui; - timespec d_current_time; - timespec d_last_time; + highres_timespec d_current_time; + highres_timespec d_last_time; public: ~qtgui_time_sink_c(); diff --git a/gr-qtgui/lib/qtgui_time_sink_f.cc b/gr-qtgui/lib/qtgui_time_sink_f.cc index e04109e96..20caedac7 100644 --- a/gr-qtgui/lib/qtgui_time_sink_f.cc +++ b/gr-qtgui/lib/qtgui_time_sink_f.cc @@ -94,7 +94,7 @@ qtgui_time_sink_f::initialize() // initialize update time to 10 times a second set_update_time(0.1); - highres_timespec_reset(&d_last_time); + highres_timespec_reset(d_last_time); } diff --git a/gr-qtgui/lib/qtgui_time_sink_f.h b/gr-qtgui/lib/qtgui_time_sink_f.h index 29fca79ee..7cb0a9d37 100644 --- a/gr-qtgui/lib/qtgui_time_sink_f.h +++ b/gr-qtgui/lib/qtgui_time_sink_f.h @@ -68,8 +68,8 @@ private: QWidget *d_parent; TimeDisplayForm *d_main_gui; - timespec d_current_time; - timespec d_last_time; + highres_timespec d_current_time; + highres_timespec d_last_time; public: ~qtgui_time_sink_f(); -- cgit From eae515a2356a140e4407945eed21e56b90bb98d9 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Tue, 7 Jun 2011 22:39:07 -0400 Subject: qtgui: removed most of the functions in highResTimeFunctions.h --- gr-qtgui/lib/ConstellationDisplayPlot.cc | 4 ++-- gr-qtgui/lib/FrequencyDisplayPlot.cc | 4 ++-- gr-qtgui/lib/SpectrumGUIClass.cc | 8 ++++---- gr-qtgui/lib/WaterfallDisplayPlot.cc | 22 +++++++++++----------- gr-qtgui/lib/highResTimeFunctions.h | 27 --------------------------- gr-qtgui/lib/qtgui_time_sink_c.cc | 5 +++-- gr-qtgui/lib/qtgui_time_sink_f.cc | 4 ++-- 7 files changed, 24 insertions(+), 50 deletions(-) (limited to 'gr-qtgui/lib') diff --git a/gr-qtgui/lib/ConstellationDisplayPlot.cc b/gr-qtgui/lib/ConstellationDisplayPlot.cc index 77550de81..cecfc1d29 100644 --- a/gr-qtgui/lib/ConstellationDisplayPlot.cc +++ b/gr-qtgui/lib/ConstellationDisplayPlot.cc @@ -58,7 +58,7 @@ protected: ConstellationDisplayPlot::ConstellationDisplayPlot(QWidget* parent) : QwtPlot(parent) { - highres_timespec_reset(_lastReplot); + _lastReplot = 0; resize(parent->width(), parent->height()); @@ -183,7 +183,7 @@ void ConstellationDisplayPlot::PlotNewData(const double* realDataPoints, const double timeInterval) { if((numDataPoints > 0) && - (diff_highres_timespec(get_highres_clock(), _lastReplot) > timeInterval)) { + (get_highres_clock() - _lastReplot > timeInterval*gruel::high_res_timer_tps())) { if(numDataPoints != _numPoints){ _numPoints = numDataPoints; diff --git a/gr-qtgui/lib/FrequencyDisplayPlot.cc b/gr-qtgui/lib/FrequencyDisplayPlot.cc index 6b3fa175b..5db32c6f1 100644 --- a/gr-qtgui/lib/FrequencyDisplayPlot.cc +++ b/gr-qtgui/lib/FrequencyDisplayPlot.cc @@ -120,7 +120,7 @@ FrequencyDisplayPlot::FrequencyDisplayPlot(QWidget* parent) _startFrequency = 0; _stopFrequency = 4000; - highres_timespec_reset(_lastReplot); + _lastReplot = 0; resize(parent->width(), parent->height()); @@ -362,7 +362,7 @@ FrequencyDisplayPlot::PlotNewData(const double* dataPoints, const int64_t numDat { // Only update plot if there is data and if the time interval has elapsed if((numDataPoints > 0) && - (diff_highres_timespec(get_highres_clock(), _lastReplot) > timeInterval)) { + (get_highres_clock() - _lastReplot > timeInterval*gruel::high_res_timer_tps())) { if(numDataPoints != _numPoints) { _numPoints = numDataPoints; diff --git a/gr-qtgui/lib/SpectrumGUIClass.cc b/gr-qtgui/lib/SpectrumGUIClass.cc index fda58d78e..002e944ea 100644 --- a/gr-qtgui/lib/SpectrumGUIClass.cc +++ b/gr-qtgui/lib/SpectrumGUIClass.cc @@ -54,7 +54,7 @@ SpectrumGUIClass::SpectrumGUIClass(const uint64_t maxDataSize, _windowType = 5; - highres_timespec_reset(_lastGUIUpdateTime); + _lastGUIUpdateTime = 0; _windowOpennedFlag = false; _fftBuffersCreatedFlag = false; @@ -123,7 +123,7 @@ SpectrumGUIClass::OpenSpectrumWindow(QWidget* parent, qApp->postEvent(_spectrumDisplayForm, new QEvent(QEvent::Type(QEvent::User+3))); - highres_timespec_reset(_lastGUIUpdateTime); + _lastGUIUpdateTime = 0; // Draw Blank Display UpdateWindow(false, NULL, 0, NULL, 0, NULL, 0, get_highres_clock(), true); @@ -286,8 +286,8 @@ SpectrumGUIClass::UpdateWindow(const bool updateDisplayFlag, const highres_timespec currentTime = get_highres_clock(); const highres_timespec lastUpdateGUITime = GetLastGUIUpdateTime(); - if((diff_highres_timespec(currentTime, lastUpdateGUITime) > (4*_updateTime)) && - (GetPendingGUIUpdateEvents() > 0) && !highres_timespec_empty(lastUpdateGUITime)) { + if((currentTime - lastUpdateGUITime > (4*_updateTime)*gruel::high_res_timer_tps()) && + (GetPendingGUIUpdateEvents() > 0) && lastUpdateGUITime != 0) { // Do not update the display if too much data is pending to be displayed _droppedEntriesCount++; } diff --git a/gr-qtgui/lib/WaterfallDisplayPlot.cc b/gr-qtgui/lib/WaterfallDisplayPlot.cc index cc7ab14a3..90386281a 100644 --- a/gr-qtgui/lib/WaterfallDisplayPlot.cc +++ b/gr-qtgui/lib/WaterfallDisplayPlot.cc @@ -110,7 +110,7 @@ class TimeScaleData public: TimeScaleData() { - highres_timespec_reset(_zeroTime); + _zeroTime = 0; _secondsPerLine = 1.0; } @@ -160,15 +160,15 @@ public: virtual QwtText label(double value) const { - highres_timespec lineTime = highres_timespec_add(GetZeroTime(), -value*GetSecondsPerLine()); - unsigned long milliseconds = lineTime*1000/gruel::high_res_timer_tps(); - std::string time_str = pt::to_simple_string(pt::from_time_t(milliseconds/1000)); + double secs = GetZeroTime()/double(gruel::high_res_timer_tps()) - (value * GetSecondsPerLine()); + std::string time_str = pt::to_simple_string(pt::from_time_t(time_t(secs))); // lops off the YYYY-mmm-DD part of the string size_t ind = time_str.find(" "); if(ind != std::string::npos) time_str = time_str.substr(ind); - return QwtText(QString("").sprintf("%s.%03ld", time_str.c_str(), milliseconds%1000)); + return QwtText(QString("").sprintf("%s.%03ld", time_str.c_str(), + long(std::fmod(secs*1000, 1000)))); } virtual void initiateUpdate() @@ -213,15 +213,15 @@ protected: using QwtPlotZoomer::trackerText; virtual QwtText trackerText( const QwtDoublePoint& p ) const { - highres_timespec lineTime = highres_timespec_add(GetZeroTime(), -p.y()*GetSecondsPerLine()); - unsigned long milliseconds = lineTime*1000/gruel::high_res_timer_tps(); - std::string time_str = pt::to_simple_string(pt::from_time_t(milliseconds/1000)); + double secs = GetZeroTime()/double(gruel::high_res_timer_tps()) - (p.y() * GetSecondsPerLine()); + std::string time_str = pt::to_simple_string(pt::from_time_t(time_t(secs))); // lops off the YYYY-mmm-DD part of the string size_t ind = time_str.find(" "); if(ind != std::string::npos) time_str = time_str.substr(ind); - QString yLabel(QString("").sprintf("%s.%03ld", time_str.c_str(), milliseconds%1000)); + QString yLabel(QString("").sprintf("%s.%03ld", time_str.c_str(), + long(std::fmod(secs*1000, 1000)))); QwtText t(QString("%1 %2, %3"). arg(p.x(), 0, 'f', GetFrequencyPrecision()). @@ -256,7 +256,7 @@ WaterfallDisplayPlot::WaterfallDisplayPlot(QWidget* parent) setAxisTitle(QwtPlot::yLeft, "Time"); setAxisScaleDraw(QwtPlot::yLeft, new QwtTimeScaleDraw()); - highres_timespec_reset(_lastReplot); + _lastReplot = 0; d_spectrogram = new PlotWaterfall(_waterfallData, "Waterfall Display"); @@ -410,7 +410,7 @@ WaterfallDisplayPlot::PlotNewData(const double* dataPoints, _lastReplot = get_highres_clock(); } - if(diff_highres_timespec(get_highres_clock(), _lastReplot) > timePerFFT) { + if(get_highres_clock() - _lastReplot > timePerFFT*gruel::high_res_timer_tps()) { //FIXME: We may want to average the data between these updates to smooth display _waterfallData->addFFTData(dataPoints, numDataPoints, droppedFrames); _waterfallData->IncrementNumLinesToUpdate(); diff --git a/gr-qtgui/lib/highResTimeFunctions.h b/gr-qtgui/lib/highResTimeFunctions.h index 18cf66ede..6b3844901 100644 --- a/gr-qtgui/lib/highResTimeFunctions.h +++ b/gr-qtgui/lib/highResTimeFunctions.h @@ -23,41 +23,14 @@ #ifndef HIGH_RES_TIME_FUNCTIONS_H #define HIGH_RES_TIME_FUNCTIONS_H -#include #include typedef gruel::high_res_timer_type highres_timespec; -static inline void -highres_timespec_reset(highres_timespec &ret) -{ - ret = 0; -} - -static inline highres_timespec -highres_timespec_add(const highres_timespec &t1, double t) -{ - return t1 + t*gruel::high_res_timer_tps(); -} - -static inline double -diff_highres_timespec(const highres_timespec &t1, - const highres_timespec &t0) -{ - return std::abs(double(t1 - t0)/gruel::high_res_timer_tps()); -} - static inline highres_timespec get_highres_clock() { return gruel::high_res_timer_now(); } -static inline bool -highres_timespec_empty(const highres_timespec &t) -{ - return t == 0; -} - - #endif /* HIGH_RES_TIME_FUNCTIONS_H */ diff --git a/gr-qtgui/lib/qtgui_time_sink_c.cc b/gr-qtgui/lib/qtgui_time_sink_c.cc index 79b74f938..3d5786da1 100644 --- a/gr-qtgui/lib/qtgui_time_sink_c.cc +++ b/gr-qtgui/lib/qtgui_time_sink_c.cc @@ -94,7 +94,7 @@ qtgui_time_sink_c::initialize() // initialize update time to 10 times a second set_update_time(0.1); - highres_timespec_reset(d_last_time); + d_last_time = 0; } @@ -171,7 +171,8 @@ qtgui_time_sink_c::general_work (int noutput_items, } // Update the plot if its time - if(diff_highres_timespec(d_current_time, d_last_time) > d_update_time) { + //if(diff_highres_timespec(d_current_time, d_last_time) > d_update_time) { + if(get_highres_clock() - d_last_time > d_update_time) { d_last_time = d_current_time; d_qApplication->postEvent(d_main_gui, new TimeUpdateEvent(d_residbufs, d_size)); diff --git a/gr-qtgui/lib/qtgui_time_sink_f.cc b/gr-qtgui/lib/qtgui_time_sink_f.cc index 20caedac7..8fd867340 100644 --- a/gr-qtgui/lib/qtgui_time_sink_f.cc +++ b/gr-qtgui/lib/qtgui_time_sink_f.cc @@ -94,7 +94,7 @@ qtgui_time_sink_f::initialize() // initialize update time to 10 times a second set_update_time(0.1); - highres_timespec_reset(d_last_time); + d_last_time = 0; } @@ -170,7 +170,7 @@ qtgui_time_sink_f::general_work (int noutput_items, } // Update the plot if its time - if(diff_highres_timespec(d_current_time, d_last_time) > d_update_time) { + if(get_highres_clock() - d_last_time > d_update_time) { d_last_time = d_current_time; d_qApplication->postEvent(d_main_gui, new TimeUpdateEvent(d_residbufs, d_size)); -- cgit From bbf11bb338a4a88a1f270f77649212fea0b0cab0 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Tue, 7 Jun 2011 22:55:41 -0400 Subject: qtgui: removed all traces of highResTimeFunctions.h --- gr-qtgui/lib/ConstellationDisplayPlot.cc | 6 +++--- gr-qtgui/lib/ConstellationDisplayPlot.h | 4 ++-- gr-qtgui/lib/FrequencyDisplayPlot.cc | 4 ++-- gr-qtgui/lib/FrequencyDisplayPlot.h | 4 ++-- gr-qtgui/lib/Makefile.am | 1 - gr-qtgui/lib/SpectrumGUIClass.cc | 14 +++++++------- gr-qtgui/lib/SpectrumGUIClass.h | 8 ++++---- gr-qtgui/lib/TimeDomainDisplayPlot.h | 1 - gr-qtgui/lib/WaterfallDisplayPlot.cc | 16 ++++++++-------- gr-qtgui/lib/WaterfallDisplayPlot.h | 6 +++--- gr-qtgui/lib/qtgui_sink_c.cc | 2 +- gr-qtgui/lib/qtgui_sink_f.cc | 2 +- gr-qtgui/lib/qtgui_time_sink_c.cc | 5 ++--- gr-qtgui/lib/qtgui_time_sink_c.h | 4 ++-- gr-qtgui/lib/qtgui_time_sink_f.cc | 4 ++-- gr-qtgui/lib/qtgui_time_sink_f.h | 4 ++-- gr-qtgui/lib/spectrumUpdateEvents.cc | 8 ++++---- gr-qtgui/lib/spectrumUpdateEvents.h | 14 +++++++------- gr-qtgui/lib/spectrumdisplayform.cc | 4 ++-- 19 files changed, 54 insertions(+), 57 deletions(-) (limited to 'gr-qtgui/lib') diff --git a/gr-qtgui/lib/ConstellationDisplayPlot.cc b/gr-qtgui/lib/ConstellationDisplayPlot.cc index cecfc1d29..dda7cfea2 100644 --- a/gr-qtgui/lib/ConstellationDisplayPlot.cc +++ b/gr-qtgui/lib/ConstellationDisplayPlot.cc @@ -183,8 +183,8 @@ void ConstellationDisplayPlot::PlotNewData(const double* realDataPoints, const double timeInterval) { if((numDataPoints > 0) && - (get_highres_clock() - _lastReplot > timeInterval*gruel::high_res_timer_tps())) { - + (gruel::high_res_timer_now() - _lastReplot > timeInterval*gruel::high_res_timer_tps())) { + if(numDataPoints != _numPoints){ _numPoints = numDataPoints; @@ -199,7 +199,7 @@ void ConstellationDisplayPlot::PlotNewData(const double* realDataPoints, memcpy(_realDataPoints, realDataPoints, numDataPoints*sizeof(double)); memcpy(_imagDataPoints, imagDataPoints, numDataPoints*sizeof(double)); - _lastReplot = get_highres_clock(); + _lastReplot = gruel::high_res_timer_now(); } } diff --git a/gr-qtgui/lib/ConstellationDisplayPlot.h b/gr-qtgui/lib/ConstellationDisplayPlot.h index 38e401c68..23004f86c 100644 --- a/gr-qtgui/lib/ConstellationDisplayPlot.h +++ b/gr-qtgui/lib/ConstellationDisplayPlot.h @@ -34,7 +34,7 @@ #include #include #include -#include +#include #include #include @@ -83,7 +83,7 @@ private: double* _realDataPoints; double* _imagDataPoints; - highres_timespec _lastReplot; + gruel::high_res_timer_type _lastReplot; int64_t _numPoints; int64_t _penSize; diff --git a/gr-qtgui/lib/FrequencyDisplayPlot.cc b/gr-qtgui/lib/FrequencyDisplayPlot.cc index 5db32c6f1..f57edd8f6 100644 --- a/gr-qtgui/lib/FrequencyDisplayPlot.cc +++ b/gr-qtgui/lib/FrequencyDisplayPlot.cc @@ -362,7 +362,7 @@ FrequencyDisplayPlot::PlotNewData(const double* dataPoints, const int64_t numDat { // Only update plot if there is data and if the time interval has elapsed if((numDataPoints > 0) && - (get_highres_clock() - _lastReplot > timeInterval*gruel::high_res_timer_tps())) { + (gruel::high_res_timer_now() - _lastReplot > timeInterval*gruel::high_res_timer_tps())) { if(numDataPoints != _numPoints) { _numPoints = numDataPoints; @@ -401,7 +401,7 @@ FrequencyDisplayPlot::PlotNewData(const double* dataPoints, const int64_t numDat SetUpperIntensityLevel(_peakAmplitude); - _lastReplot = get_highres_clock(); + _lastReplot = gruel::high_res_timer_now(); } } diff --git a/gr-qtgui/lib/FrequencyDisplayPlot.h b/gr-qtgui/lib/FrequencyDisplayPlot.h index 98c8d77b1..a263fec2f 100644 --- a/gr-qtgui/lib/FrequencyDisplayPlot.h +++ b/gr-qtgui/lib/FrequencyDisplayPlot.h @@ -35,7 +35,7 @@ #include #include #include -#include +#include #include #include @@ -122,7 +122,7 @@ private: double _noiseFloorAmplitude; - highres_timespec _lastReplot; + gruel::high_res_timer_type _lastReplot; bool _useCenterFrequencyFlag; }; diff --git a/gr-qtgui/lib/Makefile.am b/gr-qtgui/lib/Makefile.am index 95b636d89..849ee8360 100644 --- a/gr-qtgui/lib/Makefile.am +++ b/gr-qtgui/lib/Makefile.am @@ -70,7 +70,6 @@ grinclude_HEADERS = \ WaterfallDisplayPlot.h \ waterfallGlobalData.h \ ConstellationDisplayPlot.h \ - highResTimeFunctions.h \ plot_waterfall.h \ spectrumdisplayform.h \ timedisplayform.h \ diff --git a/gr-qtgui/lib/SpectrumGUIClass.cc b/gr-qtgui/lib/SpectrumGUIClass.cc index 002e944ea..af95e2bb2 100644 --- a/gr-qtgui/lib/SpectrumGUIClass.cc +++ b/gr-qtgui/lib/SpectrumGUIClass.cc @@ -126,7 +126,7 @@ SpectrumGUIClass::OpenSpectrumWindow(QWidget* parent, _lastGUIUpdateTime = 0; // Draw Blank Display - UpdateWindow(false, NULL, 0, NULL, 0, NULL, 0, get_highres_clock(), true); + UpdateWindow(false, NULL, 0, NULL, 0, NULL, 0, gruel::high_res_timer_now(), true); // Set up the initial frequency axis settings SetFrequencyRange(_centerFrequency, _startFrequency, _stopFrequency); @@ -229,7 +229,7 @@ SpectrumGUIClass::UpdateWindow(const bool updateDisplayFlag, const uint64_t realTimeDomainDataSize, const float* complexTimeDomainData, const uint64_t complexTimeDomainDataSize, - const highres_timespec timestamp, + const gruel::high_res_timer_type timestamp, const bool lastOfMultipleFFTUpdateFlag) { //gruel::scoped_lock lock(d_mutex); @@ -283,8 +283,8 @@ SpectrumGUIClass::UpdateWindow(const bool updateDisplayFlag, _lastDataPointCount = bufferSize; } - const highres_timespec currentTime = get_highres_clock(); - const highres_timespec lastUpdateGUITime = GetLastGUIUpdateTime(); + const gruel::high_res_timer_type currentTime = gruel::high_res_timer_now(); + const gruel::high_res_timer_type lastUpdateGUITime = GetLastGUIUpdateTime(); if((currentTime - lastUpdateGUITime > (4*_updateTime)*gruel::high_res_timer_tps()) && (GetPendingGUIUpdateEvents() > 0) && lastUpdateGUITime != 0) { @@ -376,17 +376,17 @@ SpectrumGUIClass::SetFFTSize(const int newSize) _fftSize = newSize; } -highres_timespec +gruel::high_res_timer_type SpectrumGUIClass::GetLastGUIUpdateTime() { gruel::scoped_lock lock(d_mutex); - highres_timespec returnValue; + gruel::high_res_timer_type returnValue; returnValue = _lastGUIUpdateTime; return returnValue; } void -SpectrumGUIClass::SetLastGUIUpdateTime(const highres_timespec newTime) +SpectrumGUIClass::SetLastGUIUpdateTime(const gruel::high_res_timer_type newTime) { gruel::scoped_lock lock(d_mutex); _lastGUIUpdateTime = newTime; diff --git a/gr-qtgui/lib/SpectrumGUIClass.h b/gr-qtgui/lib/SpectrumGUIClass.h index 95f010671..857c2515f 100644 --- a/gr-qtgui/lib/SpectrumGUIClass.h +++ b/gr-qtgui/lib/SpectrumGUIClass.h @@ -66,7 +66,7 @@ public: const uint64_t, const float*, const uint64_t, const float*, const uint64_t, - const highres_timespec, const bool); + const gruel::high_res_timer_type, const bool); float GetPowerValue(); void SetPowerValue(const float); @@ -78,8 +78,8 @@ public: int GetFFTSizeIndex(); void SetFFTSize(const int); - highres_timespec GetLastGUIUpdateTime(); - void SetLastGUIUpdateTime(const highres_timespec); + gruel::high_res_timer_type GetLastGUIUpdateTime(); + void SetLastGUIUpdateTime(const gruel::high_res_timer_type); unsigned int GetPendingGUIUpdateEvents(); void IncrementPendingGUIUpdateEvents(); @@ -114,7 +114,7 @@ private: int _windowType; int64_t _lastDataPointCount; int _fftSize; - highres_timespec _lastGUIUpdateTime; + gruel::high_res_timer_type _lastGUIUpdateTime; unsigned int _pendingGUIUpdateEventsCount; int _droppedEntriesCount; bool _fftBuffersCreatedFlag; diff --git a/gr-qtgui/lib/TimeDomainDisplayPlot.h b/gr-qtgui/lib/TimeDomainDisplayPlot.h index 4c7b1e319..af87e1b14 100644 --- a/gr-qtgui/lib/TimeDomainDisplayPlot.h +++ b/gr-qtgui/lib/TimeDomainDisplayPlot.h @@ -36,7 +36,6 @@ #include #include #include -#include #include #include diff --git a/gr-qtgui/lib/WaterfallDisplayPlot.cc b/gr-qtgui/lib/WaterfallDisplayPlot.cc index 90386281a..20e1fa4ec 100644 --- a/gr-qtgui/lib/WaterfallDisplayPlot.cc +++ b/gr-qtgui/lib/WaterfallDisplayPlot.cc @@ -118,12 +118,12 @@ public: { } - virtual highres_timespec GetZeroTime() const + virtual gruel::high_res_timer_type GetZeroTime() const { return _zeroTime; } - virtual void SetZeroTime(const highres_timespec newTime) + virtual void SetZeroTime(const gruel::high_res_timer_type newTime) { _zeroTime = newTime; } @@ -140,7 +140,7 @@ public: protected: - highres_timespec _zeroTime; + gruel::high_res_timer_type _zeroTime; double _secondsPerLine; private: @@ -391,7 +391,7 @@ void WaterfallDisplayPlot::PlotNewData(const double* dataPoints, const int64_t numDataPoints, const double timePerFFT, - const highres_timespec timestamp, + const gruel::high_res_timer_type timestamp, const int droppedFrames) { if(numDataPoints > 0){ @@ -407,10 +407,10 @@ WaterfallDisplayPlot::PlotNewData(const double* dataPoints, replot(); } - _lastReplot = get_highres_clock(); + _lastReplot = gruel::high_res_timer_now(); } - if(get_highres_clock() - _lastReplot > timePerFFT*gruel::high_res_timer_tps()) { + if(gruel::high_res_timer_now() - _lastReplot > timePerFFT*gruel::high_res_timer_tps()) { //FIXME: We may want to average the data between these updates to smooth display _waterfallData->addFFTData(dataPoints, numDataPoints, droppedFrames); _waterfallData->IncrementNumLinesToUpdate(); @@ -427,7 +427,7 @@ WaterfallDisplayPlot::PlotNewData(const double* dataPoints, replot(); - _lastReplot = get_highres_clock(); + _lastReplot = gruel::high_res_timer_now(); } } } @@ -570,7 +570,7 @@ WaterfallDisplayPlot::_UpdateIntensityRangeDisplay() replot(); // Update the last replot timer - _lastReplot = get_highres_clock(); + _lastReplot = gruel::high_res_timer_now(); } void diff --git a/gr-qtgui/lib/WaterfallDisplayPlot.h b/gr-qtgui/lib/WaterfallDisplayPlot.h index 435453fcc..0c6a521b1 100644 --- a/gr-qtgui/lib/WaterfallDisplayPlot.h +++ b/gr-qtgui/lib/WaterfallDisplayPlot.h @@ -32,7 +32,7 @@ #include #include -#include +#include class WaterfallDisplayPlot:public QwtPlot{ Q_OBJECT @@ -51,7 +51,7 @@ public: double GetStopFrequency()const; void PlotNewData(const double* dataPoints, const int64_t numDataPoints, - const double timePerFFT, const highres_timespec timestamp, + const double timePerFFT, const gruel::high_res_timer_type timestamp, const int droppedFrames); void SetIntensityRange(const double minIntensity, const double maxIntensity); @@ -98,7 +98,7 @@ private: WaterfallData* _waterfallData; - highres_timespec _lastReplot; + gruel::high_res_timer_type _lastReplot; bool _useCenterFrequencyFlag; diff --git a/gr-qtgui/lib/qtgui_sink_c.cc b/gr-qtgui/lib/qtgui_sink_c.cc index e980318ca..965be0773 100644 --- a/gr-qtgui/lib/qtgui_sink_c.cc +++ b/gr-qtgui/lib/qtgui_sink_c.cc @@ -272,7 +272,7 @@ qtgui_sink_c::general_work (int noutput_items, // If we have enough input for one full FFT, do it if(datasize >= resid) { - const highres_timespec currentTime = get_highres_clock(); + const gruel::high_res_timer_type currentTime = gruel::high_res_timer_now(); // Fill up residbuf with d_fftsize number of items memcpy(d_residbuf+d_index, &in[j], sizeof(gr_complex)*resid); diff --git a/gr-qtgui/lib/qtgui_sink_f.cc b/gr-qtgui/lib/qtgui_sink_f.cc index 4e1799150..a435064c0 100644 --- a/gr-qtgui/lib/qtgui_sink_f.cc +++ b/gr-qtgui/lib/qtgui_sink_f.cc @@ -268,7 +268,7 @@ qtgui_sink_f::general_work (int noutput_items, // If we have enough input for one full FFT, do it if(datasize >= resid) { - const highres_timespec currentTime = get_highres_clock(); + const gruel::high_res_timer_type currentTime = gruel::high_res_timer_now(); // Fill up residbuf with d_fftsize number of items memcpy(d_residbuf+d_index, &in[j], sizeof(float)*resid); diff --git a/gr-qtgui/lib/qtgui_time_sink_c.cc b/gr-qtgui/lib/qtgui_time_sink_c.cc index 3d5786da1..3d38419b2 100644 --- a/gr-qtgui/lib/qtgui_time_sink_c.cc +++ b/gr-qtgui/lib/qtgui_time_sink_c.cc @@ -159,7 +159,7 @@ qtgui_time_sink_c::general_work (int noutput_items, // If we have enough input for one full plot, do it if(datasize >= resid) { - d_current_time = get_highres_clock(); + d_current_time = gruel::high_res_timer_now(); // Fill up residbufs with d_size number of items for(n = 0; n < d_nconnections; n+=2) { @@ -171,8 +171,7 @@ qtgui_time_sink_c::general_work (int noutput_items, } // Update the plot if its time - //if(diff_highres_timespec(d_current_time, d_last_time) > d_update_time) { - if(get_highres_clock() - d_last_time > d_update_time) { + if(gruel::high_res_timer_now() - d_last_time > d_update_time) { d_last_time = d_current_time; d_qApplication->postEvent(d_main_gui, new TimeUpdateEvent(d_residbufs, d_size)); diff --git a/gr-qtgui/lib/qtgui_time_sink_c.h b/gr-qtgui/lib/qtgui_time_sink_c.h index f06ffa8f5..459423c40 100644 --- a/gr-qtgui/lib/qtgui_time_sink_c.h +++ b/gr-qtgui/lib/qtgui_time_sink_c.h @@ -68,8 +68,8 @@ private: QWidget *d_parent; TimeDisplayForm *d_main_gui; - highres_timespec d_current_time; - highres_timespec d_last_time; + gruel::high_res_timer_type d_current_time; + gruel::high_res_timer_type d_last_time; public: ~qtgui_time_sink_c(); diff --git a/gr-qtgui/lib/qtgui_time_sink_f.cc b/gr-qtgui/lib/qtgui_time_sink_f.cc index 8fd867340..58cc7a38a 100644 --- a/gr-qtgui/lib/qtgui_time_sink_f.cc +++ b/gr-qtgui/lib/qtgui_time_sink_f.cc @@ -159,7 +159,7 @@ qtgui_time_sink_f::general_work (int noutput_items, // If we have enough input for one full plot, do it if(datasize >= resid) { - d_current_time = get_highres_clock(); + d_current_time = gruel::high_res_timer_now(); // Fill up residbufs with d_size number of items for(n = 0; n < d_nconnections; n++) { @@ -170,7 +170,7 @@ qtgui_time_sink_f::general_work (int noutput_items, } // Update the plot if its time - if(get_highres_clock() - d_last_time > d_update_time) { + if(gruel::high_res_timer_now() - d_last_time > d_update_time) { d_last_time = d_current_time; d_qApplication->postEvent(d_main_gui, new TimeUpdateEvent(d_residbufs, d_size)); diff --git a/gr-qtgui/lib/qtgui_time_sink_f.h b/gr-qtgui/lib/qtgui_time_sink_f.h index 7cb0a9d37..632246c6e 100644 --- a/gr-qtgui/lib/qtgui_time_sink_f.h +++ b/gr-qtgui/lib/qtgui_time_sink_f.h @@ -68,8 +68,8 @@ private: QWidget *d_parent; TimeDisplayForm *d_main_gui; - highres_timespec d_current_time; - highres_timespec d_last_time; + gruel::high_res_timer_type d_current_time; + gruel::high_res_timer_type d_last_time; public: ~qtgui_time_sink_f(); diff --git a/gr-qtgui/lib/spectrumUpdateEvents.cc b/gr-qtgui/lib/spectrumUpdateEvents.cc index 6d7ca2701..9be2f5357 100644 --- a/gr-qtgui/lib/spectrumUpdateEvents.cc +++ b/gr-qtgui/lib/spectrumUpdateEvents.cc @@ -8,10 +8,10 @@ SpectrumUpdateEvent::SpectrumUpdateEvent(const std::complex* fftPoints, const double* realTimeDomainPoints, const double* imagTimeDomainPoints, const uint64_t numTimeDomainDataPoints, - const highres_timespec dataTimestamp, + const gruel::high_res_timer_type dataTimestamp, const bool repeatDataFlag, const bool lastOfMultipleUpdateFlag, - const highres_timespec generatedTimestamp, + const gruel::high_res_timer_type generatedTimestamp, const int droppedFFTFrames) : QEvent(QEvent::Type(10005)) { @@ -90,7 +90,7 @@ SpectrumUpdateEvent::getNumTimeDomainDataPoints() const return _numTimeDomainDataPoints; } -highres_timespec +gruel::high_res_timer_type SpectrumUpdateEvent::getDataTimestamp() const { return _dataTimestamp; @@ -108,7 +108,7 @@ SpectrumUpdateEvent::getLastOfMultipleUpdateFlag() const return _lastOfMultipleUpdateFlag; } -highres_timespec +gruel::high_res_timer_type SpectrumUpdateEvent::getEventGeneratedTimestamp() const { return _eventGeneratedTimestamp; diff --git a/gr-qtgui/lib/spectrumUpdateEvents.h b/gr-qtgui/lib/spectrumUpdateEvents.h index 9224cad08..5a17657b7 100644 --- a/gr-qtgui/lib/spectrumUpdateEvents.h +++ b/gr-qtgui/lib/spectrumUpdateEvents.h @@ -6,7 +6,7 @@ #include #include #include -#include +#include class SpectrumUpdateEvent:public QEvent{ @@ -16,10 +16,10 @@ public: const double* realTimeDomainPoints, const double* imagTimeDomainPoints, const uint64_t numTimeDomainDataPoints, - const highres_timespec dataTimestamp, + const gruel::high_res_timer_type dataTimestamp, const bool repeatDataFlag, const bool lastOfMultipleUpdateFlag, - const highres_timespec generatedTimestamp, + const gruel::high_res_timer_type generatedTimestamp, const int droppedFFTFrames); ~SpectrumUpdateEvent(); @@ -29,10 +29,10 @@ public: const double* getImagTimeDomainPoints() const; uint64_t getNumFFTDataPoints() const; uint64_t getNumTimeDomainDataPoints() const; - highres_timespec getDataTimestamp() const; + gruel::high_res_timer_type getDataTimestamp() const; bool getRepeatDataFlag() const; bool getLastOfMultipleUpdateFlag() const; - highres_timespec getEventGeneratedTimestamp() const; + gruel::high_res_timer_type getEventGeneratedTimestamp() const; int getDroppedFFTFrames() const; protected: @@ -43,10 +43,10 @@ private: double* _imagDataTimeDomainPoints; uint64_t _numFFTDataPoints; uint64_t _numTimeDomainDataPoints; - highres_timespec _dataTimestamp; + gruel::high_res_timer_type _dataTimestamp; bool _repeatDataFlag; bool _lastOfMultipleUpdateFlag; - highres_timespec _eventGeneratedTimestamp; + gruel::high_res_timer_type _eventGeneratedTimestamp; int _droppedFFTFrames; }; diff --git a/gr-qtgui/lib/spectrumdisplayform.cc b/gr-qtgui/lib/spectrumdisplayform.cc index df1903391..0e8594029 100644 --- a/gr-qtgui/lib/spectrumdisplayform.cc +++ b/gr-qtgui/lib/spectrumdisplayform.cc @@ -145,10 +145,10 @@ SpectrumDisplayForm::newFrequencyData( const SpectrumUpdateEvent* spectrumUpdate const std::complex* complexDataPoints = spectrumUpdateEvent->getFFTPoints(); const uint64_t numFFTDataPoints = spectrumUpdateEvent->getNumFFTDataPoints(); const uint64_t numTimeDomainDataPoints = spectrumUpdateEvent->getNumTimeDomainDataPoints(); - const highres_timespec dataTimestamp = spectrumUpdateEvent->getDataTimestamp(); + const gruel::high_res_timer_type dataTimestamp = spectrumUpdateEvent->getDataTimestamp(); const bool repeatDataFlag = spectrumUpdateEvent->getRepeatDataFlag(); const bool lastOfMultipleUpdatesFlag = spectrumUpdateEvent->getLastOfMultipleUpdateFlag(); - const highres_timespec generatedTimestamp = spectrumUpdateEvent->getEventGeneratedTimestamp(); + const gruel::high_res_timer_type generatedTimestamp = spectrumUpdateEvent->getEventGeneratedTimestamp(); double* realTimeDomainDataPoints = (double*)spectrumUpdateEvent->getRealTimeDomainPoints(); double* imagTimeDomainDataPoints = (double*)spectrumUpdateEvent->getImagTimeDomainPoints(); -- cgit From fd509d44bfa14375dce396e712869be257903fc7 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Tue, 7 Jun 2011 23:04:42 -0400 Subject: qtgui: make a common function for the time label creation in waterfall --- gr-qtgui/lib/WaterfallDisplayPlot.cc | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) (limited to 'gr-qtgui/lib') diff --git a/gr-qtgui/lib/WaterfallDisplayPlot.cc b/gr-qtgui/lib/WaterfallDisplayPlot.cc index 20e1fa4ec..3dc182bca 100644 --- a/gr-qtgui/lib/WaterfallDisplayPlot.cc +++ b/gr-qtgui/lib/WaterfallDisplayPlot.cc @@ -147,6 +147,19 @@ private: }; +static QString +make_time_label(double secs) +{ + std::string time_str = pt::to_simple_string(pt::from_time_t(time_t(secs))); + + // lops off the YYYY-mmm-DD part of the string + size_t ind = time_str.find(" "); + if(ind != std::string::npos) + time_str = time_str.substr(ind); + + return QString("").sprintf("%s.%03ld", time_str.c_str(), long(std::fmod(secs*1000, 1000))); +} + class QwtTimeScaleDraw: public QwtScaleDraw, public TimeScaleData { public: @@ -161,14 +174,7 @@ public: virtual QwtText label(double value) const { double secs = GetZeroTime()/double(gruel::high_res_timer_tps()) - (value * GetSecondsPerLine()); - std::string time_str = pt::to_simple_string(pt::from_time_t(time_t(secs))); - - // lops off the YYYY-mmm-DD part of the string - size_t ind = time_str.find(" "); - if(ind != std::string::npos) - time_str = time_str.substr(ind); - return QwtText(QString("").sprintf("%s.%03ld", time_str.c_str(), - long(std::fmod(secs*1000, 1000)))); + return QwtText(make_time_label(secs)); } virtual void initiateUpdate() @@ -214,18 +220,9 @@ protected: virtual QwtText trackerText( const QwtDoublePoint& p ) const { double secs = GetZeroTime()/double(gruel::high_res_timer_tps()) - (p.y() * GetSecondsPerLine()); - std::string time_str = pt::to_simple_string(pt::from_time_t(time_t(secs))); - - // lops off the YYYY-mmm-DD part of the string - size_t ind = time_str.find(" "); - if(ind != std::string::npos) - time_str = time_str.substr(ind); - QString yLabel(QString("").sprintf("%s.%03ld", time_str.c_str(), - long(std::fmod(secs*1000, 1000)))); - QwtText t(QString("%1 %2, %3"). - arg(p.x(), 0, 'f', GetFrequencyPrecision()). - arg(_unitType.c_str()).arg(yLabel)); + arg(p.x(), 0, 'f', GetFrequencyPrecision()). + arg(_unitType.c_str()).arg(make_time_label(secs))); return t; } -- cgit From bba53da8418681d03ffd504042900bdd316f8e58 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Tue, 7 Jun 2011 23:05:49 -0400 Subject: added high_res_timer_epoch to give ticks at the epoch --- gr-qtgui/lib/WaterfallDisplayPlot.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gr-qtgui/lib') diff --git a/gr-qtgui/lib/WaterfallDisplayPlot.cc b/gr-qtgui/lib/WaterfallDisplayPlot.cc index 3dc182bca..1476be2bd 100644 --- a/gr-qtgui/lib/WaterfallDisplayPlot.cc +++ b/gr-qtgui/lib/WaterfallDisplayPlot.cc @@ -125,7 +125,7 @@ public: virtual void SetZeroTime(const gruel::high_res_timer_type newTime) { - _zeroTime = newTime; + _zeroTime = newTime - gruel::high_res_timer_epoch(); } virtual void SetSecondsPerLine(const double newTime) -- cgit