Skip to content
This repository was archived by the owner on Apr 13, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions include/libswiftnav/time.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,16 @@
#define GPS_EPOCH 315964800

#define WN_UNKNOWN -1
#define TOW_UNKNOWN -1

/** Structure representing a GPS time. */
typedef struct __attribute__((packed)) {
double tow; /**< Seconds since the GPS start of week. */
s16 wn; /**< GPS week number. */
} gps_time_t;

#define GPS_TIME_UNKNOWN ((gps_time_t){TOW_UNKNOWN, WN_UNKNOWN})

void normalize_gps_time(gps_time_t *t_gps);

time_t gps2time(const gps_time_t *t);
Expand Down
11 changes: 7 additions & 4 deletions src/time.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,14 @@ gps_time_t glo_time2gps_time(u16 nt, u8 n4, s8 h, s8 m, s8 s)
u8 j = 0;
u16 day_of_year = 0;
u32 glo_year = 0;
gps_time_t gps_t = {0, 0};
gps_time_t gps_t = GPS_TIME_UNKNOWN;

assert(n4 >= N4_MIN && n4 <= N4_MAX);
if (n4 < N4_MIN || n4 > N4_MAX)
return GPS_TIME_UNKNOWN;

if (nt >= GLO_NT_0_FLOOR && nt <= GLO_NT_0_CEILING) {
if (nt < GLO_NT_0_FLOOR)
return GPS_TIME_UNKNOWN;
else if (nt <= GLO_NT_0_CEILING) {
j = 1;
day_of_year = nt;
}
Expand All @@ -165,7 +168,7 @@ gps_time_t glo_time2gps_time(u16 nt, u8 n4, s8 h, s8 m, s8 s)
day_of_year = nt - LEAP_YEAR_DAYS - YEAR_DAYS * 2;
}
else
assert(0 && "invalid nt");
return GPS_TIME_UNKNOWN;

glo_year = 1996 + 4 * (n4 - 1) + (j - 1);

Expand Down
8 changes: 8 additions & 0 deletions tests/check_time.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,14 @@ START_TEST(test_glo_time2gps_time)
/* GLO time 31st Dec 2011 12:12:12 */
{.nt = 1461, .n4 = 4, .h = 12, .m = 12, .s = 12,
.ret = {.wn = 1668, .tow = 551549}},
{.nt = 0, .n4 = 4, .h = 12, .m = 12, .s = 12,
.ret = GPS_TIME_UNKNOWN},
{.nt = 1462, .n4 = 4, .h = 12, .m = 12, .s = 12,
.ret = GPS_TIME_UNKNOWN},
{.nt = 1461, .n4 = 0, .h = 12, .m = 12, .s = 12,
.ret = GPS_TIME_UNKNOWN},
{.nt = 1461, .n4 = 32, .h = 12, .m = 12, .s = 12,
.ret = GPS_TIME_UNKNOWN},
};
for (size_t i = 0;
i < sizeof(testcases) / sizeof(struct glo_time2gps_time_testcase);
Expand Down