Mercurial > hg > beaglert
comparison core/UdpServer.cpp @ 149:134bff10e561 ClockSync
Added simple one-variable one-measurement Kalman filter, Pid controller(which output is not used). Virtual clock is now much more precise and reactive for period. Still it is lagging behind a bit on the overall offset.
author | Giulio Moro <giuliomoro@yahoo.it> |
---|---|
date | Mon, 21 Sep 2015 03:12:21 +0100 |
parents | e77e2e712fbc |
children |
comparison
equal
deleted
inserted
replaced
148:6cd38e261027 | 149:134bff10e561 |
---|---|
61 return -1; | 61 return -1; |
62 if(timeoutMsecs<0) | 62 if(timeoutMsecs<0) |
63 return select(inSocket+1, &stReadFDS, NULL, NULL, NULL); //calling this with a NULL timeout will block indefinitely | 63 return select(inSocket+1, &stReadFDS, NULL, NULL, NULL); //calling this with a NULL timeout will block indefinitely |
64 FD_ZERO(&stReadFDS); | 64 FD_ZERO(&stReadFDS); |
65 FD_SET(inSocket, &stReadFDS); | 65 FD_SET(inSocket, &stReadFDS); |
66 if(timeoutMsecs>=1000){ | 66 float timeOutSecs=timeoutMsecs*0.001; |
67 float timeOutSecs=timeoutMsecs*0.001; | 67 stTimeOut.tv_sec=(long int)timeOutSecs; |
68 stTimeOut.tv_sec=(long int)timeOutSecs; | 68 timeOutSecs-=(int)timeOutSecs; |
69 timeOutSecs-=(int)timeOutSecs; | 69 long int timeOutUsecs=timeOutSecs*1000000; |
70 stTimeOut.tv_usec=(long int)(timeOutSecs*1000000); | 70 stTimeOut.tv_usec=timeOutUsecs; |
71 } else //faster! | |
72 stTimeOut.tv_usec=(long int)timeoutMsecs*1000; | |
73 int descriptorReady= select(inSocket+1, &stReadFDS, NULL, NULL, &stTimeOut); | 71 int descriptorReady= select(inSocket+1, &stReadFDS, NULL, NULL, &stTimeOut); |
74 return descriptorReady>0? 1 : descriptorReady; | 72 // printf("stTimeOut.tv_sec=%ld, stTimeOut.tv_usec=%ld, descriptorReady: \n",stTimeOut.tv_sec,stTimeOut.tv_usec, descriptorReady); |
73 // return descriptorReady>0 ? (timeOutUsecs-stTimeOut.tv_usec) : descriptorReady; | |
74 return descriptorReady>0 ? 1 : descriptorReady; | |
75 } | 75 } |
76 | 76 |
77 int UdpServer::read(//Returns the number of bytes read, or -1 if there was an error. | 77 int UdpServer::read(//Returns the number of bytes read, or -1 if there was an error. |
78 void *destBuffer, | 78 void *destBuffer, |
79 int maxBytesToRead, | 79 int maxBytesToRead, |