util: add UTI_Log2ToDouble()
This commit is contained in:
parent
cde3a003ea
commit
3c217a9e37
3 changed files with 21 additions and 11 deletions
13
refclock.c
13
refclock.c
|
@ -499,15 +499,6 @@ RCL_AddPulse(RCL_Instance instance, struct timeval *pulse_time, double second)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static double
|
|
||||||
poll_interval(int poll)
|
|
||||||
{
|
|
||||||
if (poll >= 0)
|
|
||||||
return 1 << poll;
|
|
||||||
else
|
|
||||||
return 1.0 / (1 << -poll);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
valid_sample_time(RCL_Instance instance, struct timeval *tv)
|
valid_sample_time(RCL_Instance instance, struct timeval *tv)
|
||||||
{
|
{
|
||||||
|
@ -516,7 +507,7 @@ valid_sample_time(RCL_Instance instance, struct timeval *tv)
|
||||||
|
|
||||||
LCL_ReadRawTime(&raw_time);
|
LCL_ReadRawTime(&raw_time);
|
||||||
UTI_DiffTimevalsToDouble(&diff, &raw_time, tv);
|
UTI_DiffTimevalsToDouble(&diff, &raw_time, tv);
|
||||||
if (diff < 0.0 || diff > poll_interval(instance->poll + 1)) {
|
if (diff < 0.0 || diff > UTI_Log2ToDouble(instance->poll + 1)) {
|
||||||
DEBUG_LOG(LOGF_Refclock, "%s refclock sample not valid age=%.6f tv=%s",
|
DEBUG_LOG(LOGF_Refclock, "%s refclock sample not valid age=%.6f tv=%s",
|
||||||
UTI_RefidToString(instance->ref_id), diff, UTI_TimevalToString(tv));
|
UTI_RefidToString(instance->ref_id), diff, UTI_TimevalToString(tv));
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -595,7 +586,7 @@ poll_timeout(void *arg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inst->timeout_id = SCH_AddTimeoutByDelay(poll_interval(poll), poll_timeout, arg);
|
inst->timeout_id = SCH_AddTimeoutByDelay(UTI_Log2ToDouble(poll), poll_timeout, arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
16
util.c
16
util.c
|
@ -643,6 +643,22 @@ UTI_IsTimeOffsetSane(struct timeval *tv, double offset)
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
|
double
|
||||||
|
UTI_Log2ToDouble(int l)
|
||||||
|
{
|
||||||
|
if (l >= 0) {
|
||||||
|
if (l > 31)
|
||||||
|
l = 31;
|
||||||
|
return 1 << l;
|
||||||
|
} else {
|
||||||
|
if (l < -31)
|
||||||
|
l = -31;
|
||||||
|
return 1.0 / (1 << -l);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
void
|
void
|
||||||
UTI_TimevalNetworkToHost(Timeval *src, struct timeval *dest)
|
UTI_TimevalNetworkToHost(Timeval *src, struct timeval *dest)
|
||||||
{
|
{
|
||||||
|
|
3
util.h
3
util.h
|
@ -107,6 +107,9 @@ extern void UTI_Int64ToTimeval(NTP_int64 *src, struct timeval *dest);
|
||||||
/* Check if time + offset is sane */
|
/* Check if time + offset is sane */
|
||||||
extern int UTI_IsTimeOffsetSane(struct timeval *tv, double offset);
|
extern int UTI_IsTimeOffsetSane(struct timeval *tv, double offset);
|
||||||
|
|
||||||
|
/* Get 2 raised to power of a signed integer */
|
||||||
|
extern double UTI_Log2ToDouble(int l);
|
||||||
|
|
||||||
extern void UTI_TimevalNetworkToHost(Timeval *src, struct timeval *dest);
|
extern void UTI_TimevalNetworkToHost(Timeval *src, struct timeval *dest);
|
||||||
extern void UTI_TimevalHostToNetwork(struct timeval *src, Timeval *dest);
|
extern void UTI_TimevalHostToNetwork(struct timeval *src, Timeval *dest);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue