summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gr-qtgui/lib/ConstellationDisplayPlot.cc2
-rw-r--r--gr-qtgui/lib/FrequencyDisplayPlot.cc2
-rw-r--r--gr-qtgui/lib/SpectrumGUIClass.cc6
-rw-r--r--gr-qtgui/lib/WaterfallDisplayPlot.cc14
-rw-r--r--gr-qtgui/lib/highResTimeFunctions.h284
-rw-r--r--gr-qtgui/lib/qtgui_time_sink_c.cc2
-rw-r--r--gr-qtgui/lib/qtgui_time_sink_c.h4
-rw-r--r--gr-qtgui/lib/qtgui_time_sink_f.cc2
-rw-r--r--gr-qtgui/lib/qtgui_time_sink_f.h4
9 files changed, 31 insertions, 289 deletions
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 <ctime>
-#include <sys/time.h>
#include <cmath>
-/* Requires the librt and libm libraries */
+#include <gruel/high_res_timer.h>
-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<long>(modf(timeValue, &seconds) *
- static_cast<double>(NSEC_PER_SEC));
- time_t sec = static_cast<time_t>(seconds);
-
- set_normalized_highres_timespec(&ret, sec, nsec);
-
- return ret;
-}
-
-static inline double
-convert_from_highres_timespec(const highres_timespec actual)
-{
- return (static_cast<double>(actual.tv_sec) +
- (static_cast<double>(actual.tv_nsec) /
- static_cast<double>(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();