From abecb543258c9402a73b1e1ce4b0036770d469cd Mon Sep 17 00:00:00 2001 From: Astrid Smith Date: Fri, 28 Oct 2011 23:33:23 -0700 Subject: Revised to use gettimeofday() --- host/calibrator_client.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/host/calibrator_client.c b/host/calibrator_client.c index 3b5eee5..26d5002 100644 --- a/host/calibrator_client.c +++ b/host/calibrator_client.c @@ -36,18 +36,16 @@ int main(int *argc, char **argv) int fd = open("/dev/ttyACM0", O_RDONLY); long int count_total = 0; // total overflows so far ever - struct timespec initial; // initial timestamp + struct timeval initial; // initial timestamp signed long long int initial_nsec; signed long int initial_msec; strcpy(&line, &blankline); - clock_gettime(CLOCK_REALTIME, &initial); + gettimeofday(&initial, NULL); - initial_nsec = initial.tv_nsec; - - initial_msec = (initial.tv_sec * 1000) + (initial.tv_nsec / (1000 * 1000)); + initial_msec = (initial.tv_sec * 1000) + (initial.tv_usec / 1000); while (1) { double current, average; @@ -55,7 +53,7 @@ int main(int *argc, char **argv) int position, pos_avg, i; int len; - struct timespec current_time; + struct timeval current_time; signed long long int cur_nsec; signed long int cur_msec; @@ -66,9 +64,8 @@ int main(int *argc, char **argv) puts("Fucked\n"); continue; } - clock_gettime(CLOCK_REALTIME, ¤t_time); - cur_nsec = (current_time.tv_nsec) + ((current_time.tv_sec - initial.tv_sec) * 1000 * 1000 * 1000); - cur_msec = (current_time.tv_nsec / (1000 * 1000)) + ((current_time.tv_sec) * 1000); + gettimeofday(¤t_time, NULL); + cur_msec = (current_time.tv_usec / 1000) + (current_time.tv_sec * 1000); count_total++; -- cgit v1.2.3