util: add UTI_IsZeroTimespec()

This commit is contained in:
Miroslav Lichvar 2016-09-16 10:01:37 +02:00
parent 45f86122fa
commit c8373f1649
4 changed files with 14 additions and 3 deletions

View file

@ -1770,9 +1770,9 @@ NCR_SlewTimes(NCR_Instance inst, struct timespec *when, double dfreq, double dof
{
double delta;
if (inst->local_rx.tv_sec || inst->local_rx.tv_nsec)
if (!UTI_IsZeroTimespec(&inst->local_rx))
UTI_AdjustTimespec(&inst->local_rx, when, &inst->local_rx, &delta, dfreq, doffset);
if (inst->local_tx.tv_sec || inst->local_tx.tv_nsec)
if (!UTI_IsZeroTimespec(&inst->local_tx))
UTI_AdjustTimespec(&inst->local_tx, when, &inst->local_tx, &delta, dfreq, doffset);
}

View file

@ -145,7 +145,7 @@ static int pps_poll(RCL_Instance instance)
ts = pps_info.clear_timestamp;
}
if (seq == pps->last_seq || (ts.tv_sec == 0 && ts.tv_nsec == 0)) {
if (seq == pps->last_seq || UTI_IsZeroTimespec(&ts)) {
DEBUG_LOG(LOGF_Refclock, "PPS sample ignored seq=%lu ts=%lu.%09lu",
seq, ts.tv_sec, ts.tv_nsec);
return 0;

8
util.c
View file

@ -47,6 +47,14 @@ UTI_ZeroTimespec(struct timespec *ts)
/* ================================================== */
int
UTI_IsZeroTimespec(struct timespec *ts)
{
return !ts->tv_sec && !ts->tv_nsec;
}
/* ================================================== */
void
UTI_TimevalToTimespec(struct timeval *tv, struct timespec *ts)
{

3
util.h
View file

@ -37,6 +37,9 @@
/* Zero a timespec */
extern void UTI_ZeroTimespec(struct timespec *ts);
/* Check if a timespec is zero */
extern int UTI_IsZeroTimespec(struct timespec *ts);
/* Convert a timeval into a timespec */
extern void UTI_TimevalToTimespec(struct timeval *tv, struct timespec *ts);