Mercurial > hg > beaglert
diff core/ClockSync.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/ClockSync.cpp Sun Sep 13 21:33:01 2015 +0100 +++ b/core/ClockSync.cpp Sun Sep 13 21:34:47 2015 +0100 @@ -14,9 +14,9 @@ T1p=-1; T2=-1; T2p=-1; - receiveLoopSleepUs=10; + receiveLoopSleepUs=100; receiveLoopTimeout=1e5; - movingAverage.setLength(201); + movingAverage.setLength(31); expectedClockSyncType=isSlave() ? kSync : kNone; } ClockSync::ClockSync(bool thisIsSlave, int aPort, VirtualClock &aVirtualClock){ @@ -41,6 +41,7 @@ ((int*)buffer)[0]=clockSyncType; } void ClockSync::setTimestamp(myClock_t timestamp){ +// printf("setting timestamp: %lld\n", timestamp); ((myClock_t*)((char*)buffer+sizeof(int)))[0]=timestamp; } void ClockSync::print(){ @@ -146,13 +147,13 @@ localTimestamp=receive(); if(localTimestamp<=0){ if(localTimestamp==0){ - // //printf("Socket not ready to be read: %lld\n", localTimestamp); +// printf("Socket not ready to be read: %lld\n", localTimestamp); } else if(localTimestamp==-1){ - //printf("Error while receiving: %lld\n", localTimestamp); + printf("Error while receiving: %lld\n", localTimestamp); } else if(localTimestamp==-2){ - // //printf("Wrong size of the received clockSync: %lld\n", localTimestamp); + printf("Wrong size of the received clockSync: %lld\n", localTimestamp); } continue ; //keep waiting } @@ -162,7 +163,7 @@ //printf("Wrong clockSync type: %d, expected: %d\n",clockSyncType, expectedClockSyncType); return -2; //start over } - //printf("Received clockSync type: %d, clockSyncTimestamp: %lld\n", clockSyncType, clockSyncTimestamp); +// printf("Received clockSync type: %d, clockSyncTimestamp: %lld\n", clockSyncType, clockSyncTimestamp); if(isSlave()==true){ int ret=slaveHandleMessage(); if(ret==1 && clockSyncType==kDelayResp){ //we are done, end of a cycle! @@ -208,7 +209,8 @@ T2p=clockSyncTimestamp; //TODO: evaluate things double offset=(T1p-T1-T2p+T2)/2.0d; - printf("-----------OFFSET IS : %04.1f, average: %04.2f\n", offset, movingAverage.add(offset)); + printf("-----------OFFSET IS : %04.4f seconds, average: %04.4f seconds\n", + offset/44100.f, movingAverage.add(offset)/44100.f); expectedClockSyncType=kSync; //end of the cycle, wait for next sync. break; }