From b777fbe0b9010466f90e407d227dcd854a259121 Mon Sep 17 00:00:00 2001 From: Kosma Moczek Date: Fri, 11 Jul 2014 12:18:47 +0200 Subject: [PATCH] minmea_gettimeofday -> minmea_gettime --- minmea.c | 6 +++--- minmea.h | 5 +---- tests.c | 16 ++++++++-------- 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/minmea.c b/minmea.c index 00f9fe2..f1fe3c8 100644 --- a/minmea.c +++ b/minmea.c @@ -517,7 +517,7 @@ bool minmea_parse_gsv(struct minmea_sentence_gsv *frame, const char *sentence) return true; } -int minmea_gettimeofday(struct timeval *tv, const struct minmea_date *date, const struct minmea_time *time_) +int minmea_gettime(struct timespec *ts, const struct minmea_date *date, const struct minmea_time *time_) { if (date->year == -1 || time_->hours == -1) return -1; @@ -533,8 +533,8 @@ int minmea_gettimeofday(struct timeval *tv, const struct minmea_date *date, cons time_t timestamp = timegm(&tm); /* See README.md if your system lacks timegm(). */ if (timestamp != -1) { - tv->tv_sec = timestamp; - tv->tv_usec = time_->microseconds; + ts->tv_sec = timestamp; + ts->tv_nsec = time_->microseconds * 1000; return 0; } else { return -1; diff --git a/minmea.h b/minmea.h index 23d615c..2f8924a 100644 --- a/minmea.h +++ b/minmea.h @@ -9,8 +9,6 @@ #ifndef MINMEA_H #define MINMEA_H -#define _BSD_SOURCE - #ifdef __cplusplus extern "C" { #endif @@ -21,7 +19,6 @@ extern "C" { #include #include #include -#include #define MINMEA_MAX_LENGTH 80 @@ -182,7 +179,7 @@ bool minmea_parse_gsv(struct minmea_sentence_gsv *frame, const char *sentence); /** * Convert GPS UTC date/time representation to a UNIX timestamp. */ -int minmea_gettimeofday(struct timeval *tv, const struct minmea_date *date, const struct minmea_time *time_); +int minmea_gettime(struct timespec *ts, const struct minmea_date *date, const struct minmea_time *time_); /** * Rescale a fixed-point value to a different scale. Rounds towards zero. diff --git a/tests.c b/tests.c index cc0d29c..9bba3db 100644 --- a/tests.c +++ b/tests.c @@ -811,21 +811,21 @@ START_TEST(test_minmea_usage1) } END_TEST -START_TEST(test_minmea_gettimeofday) +START_TEST(test_minmea_gettime) { struct minmea_date d = { 14, 2, 14 }; struct minmea_time t = { 13, 0, 9, 123456 }; - struct timeval tv; - ck_assert(minmea_gettimeofday(&tv, &d, &t) == 0); - ck_assert_int_eq(tv.tv_sec, 1392382809); - ck_assert_int_eq(tv.tv_usec, 123456); + struct timespec ts; + ck_assert(minmea_gettime(&ts, &d, &t) == 0); + ck_assert_int_eq(ts.tv_sec, 1392382809); + ck_assert_int_eq(ts.tv_nsec, 123456000); d.year = -1; - ck_assert(minmea_gettimeofday(&tv, &d, &t) != 0); + ck_assert(minmea_gettime(&ts, &d, &t) != 0); d.year = 2014; t.hours = -1; - ck_assert(minmea_gettimeofday(&tv, &d, &t) != 0); + ck_assert(minmea_gettime(&ts, &d, &t) != 0); } END_TEST @@ -912,7 +912,7 @@ static Suite *minmea_suite(void) suite_add_tcase(s, tc_usage); TCase *tc_utils = tcase_create("minmea_utils"); - tcase_add_test(tc_utils, test_minmea_gettimeofday); + tcase_add_test(tc_utils, test_minmea_gettime); tcase_add_test(tc_utils, test_minmea_rescale); tcase_add_test(tc_utils, test_minmea_float); tcase_add_test(tc_utils, test_minmea_coord);