minmea_gettimeofday -> minmea_gettime

This commit is contained in:
Kosma Moczek 2014-07-11 12:18:47 +02:00
parent 23e2f950c5
commit b777fbe0b9
3 changed files with 12 additions and 15 deletions

View File

@ -517,7 +517,7 @@ bool minmea_parse_gsv(struct minmea_sentence_gsv *frame, const char *sentence)
return true; 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) if (date->year == -1 || time_->hours == -1)
return -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(). */ time_t timestamp = timegm(&tm); /* See README.md if your system lacks timegm(). */
if (timestamp != -1) { if (timestamp != -1) {
tv->tv_sec = timestamp; ts->tv_sec = timestamp;
tv->tv_usec = time_->microseconds; ts->tv_nsec = time_->microseconds * 1000;
return 0; return 0;
} else { } else {
return -1; return -1;

View File

@ -9,8 +9,6 @@
#ifndef MINMEA_H #ifndef MINMEA_H
#define MINMEA_H #define MINMEA_H
#define _BSD_SOURCE
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
@ -21,7 +19,6 @@ extern "C" {
#include <errno.h> #include <errno.h>
#include <time.h> #include <time.h>
#include <math.h> #include <math.h>
#include <sys/time.h>
#define MINMEA_MAX_LENGTH 80 #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. * 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. * Rescale a fixed-point value to a different scale. Rounds towards zero.

16
tests.c
View File

@ -811,21 +811,21 @@ START_TEST(test_minmea_usage1)
} }
END_TEST END_TEST
START_TEST(test_minmea_gettimeofday) START_TEST(test_minmea_gettime)
{ {
struct minmea_date d = { 14, 2, 14 }; struct minmea_date d = { 14, 2, 14 };
struct minmea_time t = { 13, 0, 9, 123456 }; struct minmea_time t = { 13, 0, 9, 123456 };
struct timeval tv; struct timespec ts;
ck_assert(minmea_gettimeofday(&tv, &d, &t) == 0); ck_assert(minmea_gettime(&ts, &d, &t) == 0);
ck_assert_int_eq(tv.tv_sec, 1392382809); ck_assert_int_eq(ts.tv_sec, 1392382809);
ck_assert_int_eq(tv.tv_usec, 123456); ck_assert_int_eq(ts.tv_nsec, 123456000);
d.year = -1; d.year = -1;
ck_assert(minmea_gettimeofday(&tv, &d, &t) != 0); ck_assert(minmea_gettime(&ts, &d, &t) != 0);
d.year = 2014; d.year = 2014;
t.hours = -1; t.hours = -1;
ck_assert(minmea_gettimeofday(&tv, &d, &t) != 0); ck_assert(minmea_gettime(&ts, &d, &t) != 0);
} }
END_TEST END_TEST
@ -912,7 +912,7 @@ static Suite *minmea_suite(void)
suite_add_tcase(s, tc_usage); suite_add_tcase(s, tc_usage);
TCase *tc_utils = tcase_create("minmea_utils"); 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_rescale);
tcase_add_test(tc_utils, test_minmea_float); tcase_add_test(tc_utils, test_minmea_float);
tcase_add_test(tc_utils, test_minmea_coord); tcase_add_test(tc_utils, test_minmea_coord);