annotate future.c @ 194:4b74b81e0c79

Fix KK data provider. Wait for command reply before sending the next one.
author Daniele Nicolodi <daniele.nicolodi@obspm.fr>
date Mon, 31 Mar 2014 17:03:32 +0200
parents 4102fe614df2
children b955e35c07ae
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
16
9d57d1fcbcd5 Implementation of the C99 round() function
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
1 /* welcome in the 2012 */
9d57d1fcbcd5 Implementation of the C99 round() function
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
2
9d57d1fcbcd5 Implementation of the C99 round() function
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
3 /* required by CVI */
9d57d1fcbcd5 Implementation of the C99 round() function
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
4 #include <ansi_c.h>
9d57d1fcbcd5 Implementation of the C99 round() function
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
5
81
be814b934eca Implement gettimeofday()
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 16
diff changeset
6 /* time functions */
be814b934eca Implement gettimeofday()
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 16
diff changeset
7 #include <windows.h>
be814b934eca Implement gettimeofday()
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 16
diff changeset
8
be814b934eca Implement gettimeofday()
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 16
diff changeset
9 #include "future.h"
be814b934eca Implement gettimeofday()
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 16
diff changeset
10
be814b934eca Implement gettimeofday()
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 16
diff changeset
11
16
9d57d1fcbcd5 Implementation of the C99 round() function
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
12 /* an implementation of the C99 `round` function based on `floor` and `ceil` */
9d57d1fcbcd5 Implementation of the C99 round() function
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
13 double round(double x)
9d57d1fcbcd5 Implementation of the C99 round() function
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
14 {
9d57d1fcbcd5 Implementation of the C99 round() function
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
15 if (x >= 0.0) {
9d57d1fcbcd5 Implementation of the C99 round() function
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
16 double y = floor(x);
9d57d1fcbcd5 Implementation of the C99 round() function
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
17 if (x - y >= 0.5)
9d57d1fcbcd5 Implementation of the C99 round() function
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
18 y += 1.0;
9d57d1fcbcd5 Implementation of the C99 round() function
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
19 return y;
9d57d1fcbcd5 Implementation of the C99 round() function
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
20 } else {
9d57d1fcbcd5 Implementation of the C99 round() function
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
21 double y = ceil(x);
9d57d1fcbcd5 Implementation of the C99 round() function
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
22 if (x - y >= 0.5)
9d57d1fcbcd5 Implementation of the C99 round() function
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
23 y -= 1.0;
9d57d1fcbcd5 Implementation of the C99 round() function
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
24 return y;
9d57d1fcbcd5 Implementation of the C99 round() function
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
25 }
9d57d1fcbcd5 Implementation of the C99 round() function
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
26 }
81
be814b934eca Implement gettimeofday()
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 16
diff changeset
27
be814b934eca Implement gettimeofday()
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 16
diff changeset
28
be814b934eca Implement gettimeofday()
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 16
diff changeset
29 /* implement high resolution time service */
be814b934eca Implement gettimeofday()
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 16
diff changeset
30 int gettimeofday(struct timeval *tp, struct timezone *tzp)
be814b934eca Implement gettimeofday()
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 16
diff changeset
31 {
be814b934eca Implement gettimeofday()
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 16
diff changeset
32 /* difference between 1970-01-01 and 1601-01-01
be814b934eca Implement gettimeofday()
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 16
diff changeset
33 in 100-nanoseconds intervals */
be814b934eca Implement gettimeofday()
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 16
diff changeset
34 const unsigned __int64 shift = 116444736000000000ULL;
be814b934eca Implement gettimeofday()
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 16
diff changeset
35 union {
be814b934eca Implement gettimeofday()
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 16
diff changeset
36 FILETIME ft;
be814b934eca Implement gettimeofday()
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 16
diff changeset
37 unsigned __int64 integer; /* 100-nanoseconds since 1601-01-01 */
be814b934eca Implement gettimeofday()
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 16
diff changeset
38 } now;
be814b934eca Implement gettimeofday()
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 16
diff changeset
39
be814b934eca Implement gettimeofday()
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 16
diff changeset
40 /* retrive system time in UTC. the resolution is limited to the resolution
be814b934eca Implement gettimeofday()
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 16
diff changeset
41 of the system timer, which is typically in the range of 10 milliseconds
be814b934eca Implement gettimeofday()
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 16
diff changeset
42 to 16 milliseconds */
be814b934eca Implement gettimeofday()
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 16
diff changeset
43 GetSystemTimeAsFileTime(&now.ft);
be814b934eca Implement gettimeofday()
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 16
diff changeset
44
be814b934eca Implement gettimeofday()
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 16
diff changeset
45 /* shift to epoch and truncate to microseconds */
be814b934eca Implement gettimeofday()
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 16
diff changeset
46 now.integer = (now.integer - shift) / 10LL;
be814b934eca Implement gettimeofday()
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 16
diff changeset
47
be814b934eca Implement gettimeofday()
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 16
diff changeset
48 tp->tv_usec = (long)(now.integer % 1000000LL);
be814b934eca Implement gettimeofday()
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 16
diff changeset
49 tp->tv_sec = (long)(now.integer / 1000000LL);
be814b934eca Implement gettimeofday()
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 16
diff changeset
50
be814b934eca Implement gettimeofday()
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 16
diff changeset
51 /* FIXME CVI redefines the epoch as seconds since 1900-01-01 ! */
be814b934eca Implement gettimeofday()
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 16
diff changeset
52 tp->tv_sec += 2208988800;
be814b934eca Implement gettimeofday()
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 16
diff changeset
53
be814b934eca Implement gettimeofday()
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 16
diff changeset
54 return 0;
be814b934eca Implement gettimeofday()
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 16
diff changeset
55 }
be814b934eca Implement gettimeofday()
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 16
diff changeset
56