diff options
Diffstat (limited to 'gr-qtgui/lib')
-rw-r--r-- | gr-qtgui/lib/ConstellationDisplayPlot.cc | 8 | ||||
-rw-r--r-- | gr-qtgui/lib/ConstellationDisplayPlot.h | 4 | ||||
-rw-r--r-- | gr-qtgui/lib/FrequencyDisplayPlot.cc | 6 | ||||
-rw-r--r-- | gr-qtgui/lib/FrequencyDisplayPlot.h | 4 | ||||
-rw-r--r-- | gr-qtgui/lib/Makefile.am | 1 | ||||
-rw-r--r-- | gr-qtgui/lib/SpectrumGUIClass.cc | 22 | ||||
-rw-r--r-- | gr-qtgui/lib/SpectrumGUIClass.h | 8 | ||||
-rw-r--r-- | gr-qtgui/lib/TimeDomainDisplayPlot.h | 1 | ||||
-rw-r--r-- | gr-qtgui/lib/WaterfallDisplayPlot.cc | 59 | ||||
-rw-r--r-- | gr-qtgui/lib/WaterfallDisplayPlot.h | 6 | ||||
-rw-r--r-- | gr-qtgui/lib/highResTimeFunctions.h | 315 | ||||
-rw-r--r-- | gr-qtgui/lib/qtgui_sink_c.cc | 2 | ||||
-rw-r--r-- | gr-qtgui/lib/qtgui_sink_f.cc | 2 | ||||
-rw-r--r-- | gr-qtgui/lib/qtgui_time_sink_c.cc | 6 | ||||
-rw-r--r-- | gr-qtgui/lib/qtgui_time_sink_c.h | 4 | ||||
-rw-r--r-- | gr-qtgui/lib/qtgui_time_sink_f.cc | 6 | ||||
-rw-r--r-- | gr-qtgui/lib/qtgui_time_sink_f.h | 4 | ||||
-rw-r--r-- | gr-qtgui/lib/spectrumUpdateEvents.cc | 8 | ||||
-rw-r--r-- | gr-qtgui/lib/spectrumUpdateEvents.h | 14 | ||||
-rw-r--r-- | gr-qtgui/lib/spectrumdisplayform.cc | 4 |
20 files changed, 109 insertions, 375 deletions
diff --git a/gr-qtgui/lib/ConstellationDisplayPlot.cc b/gr-qtgui/lib/ConstellationDisplayPlot.cc index 7ec2db820..dda7cfea2 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); + _lastReplot = 0; resize(parent->width(), parent->height()); @@ -183,8 +183,8 @@ void ConstellationDisplayPlot::PlotNewData(const double* realDataPoints, const double timeInterval) { if((numDataPoints > 0) && - (diff_timespec(get_highres_clock(), _lastReplot) > timeInterval)) { - + (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 3a85f3bc3..23004f86c 100644 --- a/gr-qtgui/lib/ConstellationDisplayPlot.h +++ b/gr-qtgui/lib/ConstellationDisplayPlot.h @@ -34,7 +34,7 @@ #include <qwt_plot_zoomer.h> #include <qwt_plot_panner.h> #include <qwt_plot_marker.h> -#include <highResTimeFunctions.h> +#include <gruel/high_res_timer.h> #include <qwt_symbol.h> #include <qtgui_util.h> @@ -83,7 +83,7 @@ private: double* _realDataPoints; double* _imagDataPoints; - 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 4d60cd9be..f57edd8f6 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); + _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_timespec(get_highres_clock(), _lastReplot) > timeInterval)) { + (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 6689703bc..a263fec2f 100644 --- a/gr-qtgui/lib/FrequencyDisplayPlot.h +++ b/gr-qtgui/lib/FrequencyDisplayPlot.h @@ -35,7 +35,7 @@ #include <qwt_plot_panner.h> #include <qwt_plot_marker.h> #include <qwt_plot_magnifier.h> -#include <highResTimeFunctions.h> +#include <gruel/high_res_timer.h> #include <qwt_symbol.h> #include <qtgui_util.h> @@ -122,7 +122,7 @@ private: double _noiseFloorAmplitude; - 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 b472470c6..af95e2bb2 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); + _lastGUIUpdateTime = 0; _windowOpennedFlag = false; _fftBuffersCreatedFlag = false; @@ -123,10 +123,10 @@ SpectrumGUIClass::OpenSpectrumWindow(QWidget* parent, qApp->postEvent(_spectrumDisplayForm, new QEvent(QEvent::Type(QEvent::User+3))); - timespec_reset(&_lastGUIUpdateTime); + _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 timespec timestamp, + const gruel::high_res_timer_type 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 gruel::high_res_timer_type currentTime = gruel::high_res_timer_now(); + const gruel::high_res_timer_type lastUpdateGUITime = GetLastGUIUpdateTime(); - if((diff_timespec(currentTime, lastUpdateGUITime) > (4*_updateTime)) && - (GetPendingGUIUpdateEvents() > 0) && !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++; } @@ -376,17 +376,17 @@ SpectrumGUIClass::SetFFTSize(const int newSize) _fftSize = newSize; } -timespec +gruel::high_res_timer_type SpectrumGUIClass::GetLastGUIUpdateTime() { gruel::scoped_lock lock(d_mutex); - timespec returnValue; + gruel::high_res_timer_type returnValue; returnValue = _lastGUIUpdateTime; return returnValue; } void -SpectrumGUIClass::SetLastGUIUpdateTime(const 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 ad06674f5..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 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); - timespec GetLastGUIUpdateTime(); - void SetLastGUIUpdateTime(const 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; - 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 <qwt_plot_panner.h> #include <qwt_plot_magnifier.h> #include <qwt_plot_marker.h> -#include <highResTimeFunctions.h> #include <qwt_symbol.h> #include <qtgui_util.h> diff --git a/gr-qtgui/lib/WaterfallDisplayPlot.cc b/gr-qtgui/lib/WaterfallDisplayPlot.cc index 52381a9f6..1476be2bd 100644 --- a/gr-qtgui/lib/WaterfallDisplayPlot.cc +++ b/gr-qtgui/lib/WaterfallDisplayPlot.cc @@ -110,7 +110,7 @@ class TimeScaleData public: TimeScaleData() { - timespec_reset(&_zeroTime); + _zeroTime = 0; _secondsPerLine = 1.0; } @@ -118,14 +118,14 @@ public: { } - virtual timespec GetZeroTime() const + virtual gruel::high_res_timer_type GetZeroTime() const { return _zeroTime; } - virtual void SetZeroTime(const timespec newTime) + 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) @@ -140,13 +140,26 @@ public: protected: - timespec _zeroTime; + gruel::high_res_timer_type _zeroTime; double _secondsPerLine; 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: @@ -160,14 +173,8 @@ public: virtual QwtText label(double value) const { - timespec lineTime = 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 - 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)); + double secs = GetZeroTime()/double(gruel::high_res_timer_tps()) - (value * GetSecondsPerLine()); + return QwtText(make_time_label(secs)); } virtual void initiateUpdate() @@ -212,18 +219,10 @@ protected: using QwtPlotZoomer::trackerText; virtual QwtText trackerText( const QwtDoublePoint& p ) const { - timespec lineTime = 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 - 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)); - + double secs = GetZeroTime()/double(gruel::high_res_timer_tps()) - (p.y() * GetSecondsPerLine()); 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; } @@ -254,7 +253,7 @@ WaterfallDisplayPlot::WaterfallDisplayPlot(QWidget* parent) setAxisTitle(QwtPlot::yLeft, "Time"); setAxisScaleDraw(QwtPlot::yLeft, new QwtTimeScaleDraw()); - timespec_reset(&_lastReplot); + _lastReplot = 0; d_spectrogram = new PlotWaterfall(_waterfallData, "Waterfall Display"); @@ -389,7 +388,7 @@ void WaterfallDisplayPlot::PlotNewData(const double* dataPoints, const int64_t numDataPoints, const double timePerFFT, - const timespec timestamp, + const gruel::high_res_timer_type timestamp, const int droppedFrames) { if(numDataPoints > 0){ @@ -405,10 +404,10 @@ WaterfallDisplayPlot::PlotNewData(const double* dataPoints, replot(); } - _lastReplot = get_highres_clock(); + _lastReplot = gruel::high_res_timer_now(); } - if(diff_timespec(get_highres_clock(), _lastReplot) > timePerFFT) { + 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(); @@ -425,7 +424,7 @@ WaterfallDisplayPlot::PlotNewData(const double* dataPoints, replot(); - _lastReplot = get_highres_clock(); + _lastReplot = gruel::high_res_timer_now(); } } } @@ -568,7 +567,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 583bf9407..0c6a521b1 100644 --- a/gr-qtgui/lib/WaterfallDisplayPlot.h +++ b/gr-qtgui/lib/WaterfallDisplayPlot.h @@ -32,7 +32,7 @@ #include <qtgui_util.h> #include <plot_waterfall.h> -#include <highResTimeFunctions.h> +#include <gruel/high_res_timer.h> 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 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; - timespec _lastReplot; + gruel::high_res_timer_type _lastReplot; bool _useCenterFrequencyFlag; diff --git a/gr-qtgui/lib/highResTimeFunctions.h b/gr-qtgui/lib/highResTimeFunctions.h index 251bbad8b..6b3844901 100644 --- a/gr-qtgui/lib/highResTimeFunctions.h +++ b/gr-qtgui/lib/highResTimeFunctions.h @@ -1,299 +1,36 @@ +/* -*- 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 -#include <ctime> -#include <sys/time.h> -#include <cmath> -/* Requires the librt and libm libraries */ - -static const long NSEC_PER_SEC = 1000000000L; - -static inline bool -timespec_greater(const struct timespec* t1, - const struct timespec* t0) -{ - return ((t1->tv_sec > t0->tv_sec) || - ((t1->tv_sec == t0->tv_sec) && - (t1->tv_nsec > t0->tv_nsec))); -} - -static inline bool -timespec_greater(const struct timespec t1, - const struct timespec t0) -{ - return ((t1.tv_sec > t0.tv_sec) || - ((t1.tv_sec == t0.tv_sec) && - (t1.tv_nsec > t0.tv_nsec))); -} - -static inline bool -timespec_less(const struct timespec* t1, - const struct timespec* t0) -{ - return ((t1->tv_sec < t0->tv_sec) || - ((t1->tv_sec == t0->tv_sec) && - (t1->tv_nsec < t0->tv_nsec))); -} - -static inline bool -timespec_less(const struct timespec t1, - const struct timespec t0) -{ - return ((t1.tv_sec < t0.tv_sec) || - ((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) -{ - 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) -{ - return ((t1.tv_sec == t0.tv_sec) && - (t1.tv_nsec == t0.tv_nsec)); -} - -static inline void -timespec_reset(struct timespec* ret) -{ - ret->tv_sec = 0; - ret->tv_nsec = 0; -} - -static inline void -set_normalized_timespec(struct 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 struct timespec -convert_to_timespec(const double timeValue) -{ - struct timespec ret; - double seconds = 0; - long nsec = static_cast<long>(modf(timeValue, &seconds) * - static_cast<double>(NSEC_PER_SEC)); - time_t sec = static_cast<time_t>(seconds); - - set_normalized_timespec(&ret, sec, nsec); - - return ret; -} - -static inline double -convert_from_timespec(const timespec actual) -{ - return (static_cast<double>(actual.tv_sec) + - (static_cast<double>(actual.tv_nsec) / - static_cast<double>(NSEC_PER_SEC))); -} - -static inline void -timespec_add(struct timespec *ret, - const struct timespec* t1, - const struct timespec* t0) -{ - time_t sec = t1->tv_sec + t0->tv_sec; - long nsec = t1->tv_nsec + t0->tv_nsec; +#include <gruel/high_res_timer.h> - set_normalized_timespec(ret, sec, nsec); -} - -static inline void -timespec_add(struct timespec *ret, - const struct timespec t1, - const struct timespec t0) -{ - return timespec_add(ret, &t1, &t0); -} - -static inline struct timespec -timespec_add(const struct timespec t1, - const struct timespec t0) -{ - struct timespec ret; - timespec_add(&ret, &t1, &t0); - return ret; -} - -static inline struct timespec -timespec_add(const struct timespec t1, - const double time0) -{ - struct timespec ret; - struct timespec t0; - t0 = convert_to_timespec(time0); - - timespec_add(&ret, &t1, &t0); - - return ret; -} +typedef gruel::high_res_timer_type highres_timespec; -static inline void -timespec_subtract(struct timespec *ret, - const struct timespec* t1, - const struct 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); -} - -static inline void -timespec_subtract(struct timespec *ret, - const struct timespec t1, - const struct timespec t0) -{ - return timespec_subtract(ret, &t1, &t0); -} - -static inline struct timespec -timespec_subtract(const struct timespec t1, - const struct timespec t0) -{ - struct timespec ret; - timespec_subtract(&ret, &t1, &t0); - return ret; -} - -static inline struct timespec -timespec_subtract(const struct timespec t1, - const double time0) -{ - struct timespec ret; - struct timespec t0; - t0 = convert_to_timespec(time0); - - timespec_subtract(&ret, &t1, &t0); - - return ret; -} - -static inline double -diff_timespec(struct timespec* ret, - const struct timespec *t1, - const struct timespec* t0) -{ - struct timespec actual; - time_t sec = 0; - long nsec = 0; - - if(timespec_greater(t1, t0)){ - sec = t1->tv_sec - t0->tv_sec; - nsec = t1->tv_nsec - t0->tv_nsec; - - set_normalized_timespec(&actual, sec, nsec); - - if(ret != NULL){ - ret->tv_sec = actual.tv_sec; - ret->tv_nsec = actual.tv_nsec; - } - - return convert_from_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_timespec(&actual, sec, nsec); - - return (-convert_from_timespec(actual)); - } -} - -static inline double -diff_timespec(struct timespec* ret, - const struct timespec t1, - const struct timespec t0) -{ - return diff_timespec(ret, &t1, &t0); -} - -static inline double -diff_timespec(const struct timespec t1, - const struct timespec t0) -{ - return diff_timespec(NULL, &t1, &t0); -} - - -static inline double -diff_timespec(const struct timespec* t1, - const struct timespec* t0) -{ - return diff_timespec(NULL, t1, t0); -} - - -#ifdef CLOCK_REALTIME -// If we can use clock_gettime, use it; -// otherwise, use gettimeofday -static inline void -get_highres_clock(struct 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(struct timespec* ret) -{ - timeval lowResTime; - gettimeofday(&lowResTime, NULL); - ret->tv_sec = lowResTime.tv_sec; - ret->tv_nsec = lowResTime.tv_usec*1000; -} -#endif - -static inline struct timespec +static inline highres_timespec get_highres_clock() { - struct timespec ret; - get_highres_clock(&ret); - return ret; -} - -static inline bool -timespec_empty(const struct timespec* ret) -{ - return ( (ret->tv_sec == 0 ) && (ret->tv_nsec == 0) ); -} - -static inline bool -timespec_empty(const struct timespec ret) -{ - return timespec_empty(&ret); + return gruel::high_res_timer_now(); } #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..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 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 3312b9006..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 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 e5c4cd7d6..207d4a924 100644 --- a/gr-qtgui/lib/qtgui_time_sink_c.cc +++ b/gr-qtgui/lib/qtgui_time_sink_c.cc @@ -86,7 +86,7 @@ qtgui_time_sink_c::initialize() // initialize update time to 10 times a second set_update_time(0.1); - timespec_reset(&d_last_time); + d_last_time = 0; } @@ -150,6 +150,7 @@ qtgui_time_sink_c::work (int noutput_items, // If we have enough input for one full plot, do it if(datasize >= resid) { + 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) { @@ -161,8 +162,7 @@ qtgui_time_sink_c::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) { + 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 8366fc617..51d5ad183 100644 --- a/gr-qtgui/lib/qtgui_time_sink_c.h +++ b/gr-qtgui/lib/qtgui_time_sink_c.h @@ -66,8 +66,8 @@ private: QWidget *d_parent; TimeDisplayForm *d_main_gui; - timespec d_current_time; - 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 ac7b853b5..2fe99f43c 100644 --- a/gr-qtgui/lib/qtgui_time_sink_f.cc +++ b/gr-qtgui/lib/qtgui_time_sink_f.cc @@ -86,7 +86,7 @@ qtgui_time_sink_f::initialize() // initialize update time to 10 times a second set_update_time(0.1); - timespec_reset(&d_last_time); + d_last_time = 0; } @@ -150,7 +150,7 @@ qtgui_time_sink_f::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++) { @@ -161,7 +161,7 @@ qtgui_time_sink_f::work (int noutput_items, } // Update the plot if its time - if(diff_timespec(d_current_time, 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 b4865024e..a69d32877 100644 --- a/gr-qtgui/lib/qtgui_time_sink_f.h +++ b/gr-qtgui/lib/qtgui_time_sink_f.h @@ -66,8 +66,8 @@ private: QWidget *d_parent; TimeDisplayForm *d_main_gui; - timespec d_current_time; - 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 ae4caf31a..9be2f5357 100644 --- a/gr-qtgui/lib/spectrumUpdateEvents.cc +++ b/gr-qtgui/lib/spectrumUpdateEvents.cc @@ -8,10 +8,10 @@ SpectrumUpdateEvent::SpectrumUpdateEvent(const std::complex<float>* fftPoints, const double* realTimeDomainPoints, const double* imagTimeDomainPoints, const uint64_t numTimeDomainDataPoints, - const timespec dataTimestamp, + const gruel::high_res_timer_type dataTimestamp, const bool repeatDataFlag, const bool lastOfMultipleUpdateFlag, - const 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; } -timespec +gruel::high_res_timer_type SpectrumUpdateEvent::getDataTimestamp() const { return _dataTimestamp; @@ -108,7 +108,7 @@ SpectrumUpdateEvent::getLastOfMultipleUpdateFlag() const return _lastOfMultipleUpdateFlag; } -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 a5e359a4c..5a17657b7 100644 --- a/gr-qtgui/lib/spectrumUpdateEvents.h +++ b/gr-qtgui/lib/spectrumUpdateEvents.h @@ -6,7 +6,7 @@ #include <QString> #include <complex> #include <vector> -#include <highResTimeFunctions.h> +#include <gruel/high_res_timer.h> class SpectrumUpdateEvent:public QEvent{ @@ -16,10 +16,10 @@ public: const double* realTimeDomainPoints, const double* imagTimeDomainPoints, const uint64_t numTimeDomainDataPoints, - const timespec dataTimestamp, + const gruel::high_res_timer_type dataTimestamp, const bool repeatDataFlag, const bool lastOfMultipleUpdateFlag, - const 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; - timespec getDataTimestamp() const; + gruel::high_res_timer_type getDataTimestamp() const; bool getRepeatDataFlag() const; bool getLastOfMultipleUpdateFlag() const; - 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; - timespec _dataTimestamp; + gruel::high_res_timer_type _dataTimestamp; bool _repeatDataFlag; bool _lastOfMultipleUpdateFlag; - 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 991f51f47..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<float>* complexDataPoints = spectrumUpdateEvent->getFFTPoints(); const uint64_t numFFTDataPoints = spectrumUpdateEvent->getNumFFTDataPoints(); const uint64_t numTimeDomainDataPoints = spectrumUpdateEvent->getNumTimeDomainDataPoints(); - const timespec dataTimestamp = spectrumUpdateEvent->getDataTimestamp(); + const gruel::high_res_timer_type dataTimestamp = spectrumUpdateEvent->getDataTimestamp(); const bool repeatDataFlag = spectrumUpdateEvent->getRepeatDataFlag(); const bool lastOfMultipleUpdatesFlag = spectrumUpdateEvent->getLastOfMultipleUpdateFlag(); - const timespec generatedTimestamp = spectrumUpdateEvent->getEventGeneratedTimestamp(); + const gruel::high_res_timer_type generatedTimestamp = spectrumUpdateEvent->getEventGeneratedTimestamp(); double* realTimeDomainDataPoints = (double*)spectrumUpdateEvent->getRealTimeDomainPoints(); double* imagTimeDomainDataPoints = (double*)spectrumUpdateEvent->getImagTimeDomainPoints(); |