view future.c @ 198:5cac684eb12e

Fix manual beatnote sign setting
author Daniele Nicolodi <daniele.nicolodi@obspm.fr>
date Mon, 31 Mar 2014 17:03:37 +0200
parents 4102fe614df2
children b955e35c07ae
line wrap: on
line source

/* welcome in the 2012 */

/* required by CVI */
#include <ansi_c.h>

/* time functions */
#include <windows.h>

#include "future.h"


/* an implementation of the C99 `round` function based on `floor` and `ceil` */
double round(double x)
{
	if (x >= 0.0) {
		double y = floor(x);
		if (x - y >= 0.5)
			y += 1.0;
		return y;
	} else {
		double y = ceil(x);
		if (x - y >= 0.5)
			y -= 1.0;
		return y;
	}
}


/* implement high resolution time service */
int gettimeofday(struct timeval *tp, struct timezone *tzp)
{
	/* difference between 1970-01-01 and 1601-01-01
	   in 100-nanoseconds intervals */
	const unsigned __int64 shift = 116444736000000000ULL;
	union {
		FILETIME ft;
		unsigned __int64 integer; /* 100-nanoseconds since 1601-01-01 */
	} now;

	/* retrive system time in UTC. the resolution is limited to the resolution
	   of the system timer, which is typically in the range of 10 milliseconds
	   to 16 milliseconds */
	GetSystemTimeAsFileTime(&now.ft);
	
	/* shift to epoch and truncate to microseconds */
	now.integer = (now.integer - shift) / 10LL;
	
	tp->tv_usec = (long)(now.integer % 1000000LL);
	tp->tv_sec = (long)(now.integer / 1000000LL);
	
	/* FIXME CVI redefines the epoch as seconds since 1900-01-01 ! */
	tp->tv_sec += 2208988800;
	
	return 0;
}