diff core/VirtualClock.cpp @ 139:4e2dd3eb1d28 ClockSync

The reported offset is now meaningful. The whole thing is waaay too jittery.
author Giulio Moro <giuliomoro@yahoo.it>
date Sun, 13 Sep 2015 21:34:47 +0100
parents e77e2e712fbc
children 44d07fa9bd03
line wrap: on
line diff
--- a/core/VirtualClock.cpp	Sun Sep 13 21:33:01 2015 +0100
+++ b/core/VirtualClock.cpp	Sun Sep 13 21:34:47 2015 +0100
@@ -20,19 +20,20 @@
 		period=movingAverage.add((currentTime-lastSync)/count); //TODO: replace with Kalman filter
 	}
 	lastSync=currentTime;
+//	printf("lastSync: %lld\n",lastSync-startTime);
 }
 
 double VirtualClock::getNow(){
-	myClock_t now=Clock::getTimeUs();
+	myClock_t currentSystemTime=Clock::getTimeUs();
 	if(period<=0){
-		return now;
+		return currentSystemTime;
 	}
 	//  double beginningOfPeriod=lastSync; // TODO: if sync() does not get called every time (but e.g. only every so often),
 													 // then this line (and the class) needs editing
-	myClock_t elapsed=(now-startTime);
-	double frac=elapsed/(double)period;
-	//  printf("now=%lld; beginningOfPeriod=%f; lastSync=%lld; period=%lld; frac=%f\n", now, beginningOfPeriod, lastSync, period, frac);
-	return frac;
+	myClock_t elapsed=(currentSystemTime-startTime);
+	double now=elapsed/(double)period;
+//	printf("elapsed=%lld;  sincelastSync=%lld; period=%f; now=%f\n", elapsed, currentSystemTime-lastSync, period, now);
+	return now;
 }
 
 double VirtualClock::getPeriod(){