Add support for nanoseconds in SHM
This commit is contained in:
parent
df6c2a432f
commit
bbbb3633a7
2 changed files with 17 additions and 11 deletions
|
@ -2468,7 +2468,7 @@ Some examples of applications that can be used as SHM sources are @code{gpsd},
|
||||||
@item SOCK
|
@item SOCK
|
||||||
Unix domain socket driver. It is similar to the SHM driver, but uses a
|
Unix domain socket driver. It is similar to the SHM driver, but uses a
|
||||||
different format and uses a socket instead of shared memory. It does not
|
different format and uses a socket instead of shared memory. It does not
|
||||||
require polling, the offset resolution is not limited to microseconds and it
|
require polling and it
|
||||||
supports transmitting of PPS data. The parameter is a path to the socket which
|
supports transmitting of PPS data. The parameter is a path to the socket which
|
||||||
will be created by @code{chronyd} and used to receive the messages. The format
|
will be created by @code{chronyd} and used to receive the messages. The format
|
||||||
of messages sent over the socket is described in the
|
of messages sent over the socket is described in the
|
||||||
|
|
|
@ -45,7 +45,7 @@ struct shmTime {
|
||||||
* use values
|
* use values
|
||||||
* clear valid
|
* clear valid
|
||||||
*/
|
*/
|
||||||
int count;
|
volatile int count;
|
||||||
time_t clockTimeStampSec;
|
time_t clockTimeStampSec;
|
||||||
int clockTimeStampUSec;
|
int clockTimeStampUSec;
|
||||||
time_t receiveTimeStampSec;
|
time_t receiveTimeStampSec;
|
||||||
|
@ -53,8 +53,10 @@ struct shmTime {
|
||||||
int leap;
|
int leap;
|
||||||
int precision;
|
int precision;
|
||||||
int nsamples;
|
int nsamples;
|
||||||
int valid;
|
volatile int valid;
|
||||||
int dummy[10];
|
int clockTimeStampNSec;
|
||||||
|
int receiveTimeStampNSec;
|
||||||
|
int dummy[8];
|
||||||
};
|
};
|
||||||
|
|
||||||
static int shm_initialise(RCL_Instance instance) {
|
static int shm_initialise(RCL_Instance instance) {
|
||||||
|
@ -89,7 +91,7 @@ static void shm_finalise(RCL_Instance instance)
|
||||||
|
|
||||||
static int shm_poll(RCL_Instance instance)
|
static int shm_poll(RCL_Instance instance)
|
||||||
{
|
{
|
||||||
struct timeval tv1, tv2;
|
struct timeval tv;
|
||||||
struct shmTime t, *shm;
|
struct shmTime t, *shm;
|
||||||
double offset;
|
double offset;
|
||||||
|
|
||||||
|
@ -107,13 +109,17 @@ static int shm_poll(RCL_Instance instance)
|
||||||
|
|
||||||
shm->valid = 0;
|
shm->valid = 0;
|
||||||
|
|
||||||
tv1.tv_sec = t.receiveTimeStampSec;
|
tv.tv_sec = t.receiveTimeStampSec;
|
||||||
tv1.tv_usec = t.receiveTimeStampUSec;
|
tv.tv_usec = t.receiveTimeStampUSec;
|
||||||
tv2.tv_sec = t.clockTimeStampSec;
|
|
||||||
tv2.tv_usec = t.clockTimeStampUSec;
|
|
||||||
|
|
||||||
UTI_DiffTimevalsToDouble(&offset, &tv2, &tv1);
|
offset = t.clockTimeStampSec - t.receiveTimeStampSec;
|
||||||
return RCL_AddSample(instance, &tv1, offset, t.leap);
|
if (t.clockTimeStampNSec / 1000 == t.clockTimeStampUSec &&
|
||||||
|
t.receiveTimeStampNSec / 1000 == t.receiveTimeStampUSec)
|
||||||
|
offset += (t.clockTimeStampNSec - t.receiveTimeStampNSec) * 1e-9;
|
||||||
|
else
|
||||||
|
offset += (t.clockTimeStampUSec - t.receiveTimeStampUSec) * 1e-6;
|
||||||
|
|
||||||
|
return RCL_AddSample(instance, &tv, offset, t.leap);
|
||||||
}
|
}
|
||||||
|
|
||||||
RefclockDriver RCL_SHM_driver = {
|
RefclockDriver RCL_SHM_driver = {
|
||||||
|
|
Loading…
Reference in a new issue