Skip to content

Commit

Permalink
Check valid flags in NAV-TIMEGPS
Browse files Browse the repository at this point in the history
Split 22a020e Support UBX NAV-PVT
  • Loading branch information
clarkli86 authored and eric-s-raymond committed Sep 19, 2017
1 parent 22de774 commit 3d0da91
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
32 changes: 22 additions & 10 deletions driver_ubx.c
Original file line number Diff line number Diff line change
Expand Up @@ -292,24 +292,36 @@ static gps_mask_t
ubx_msg_nav_timegps(struct gps_device_t *session, unsigned char *buf,
size_t data_len)
{
unsigned int gw, tow, flags;
unsigned int gw, iTOW, flags;
int fTOW;
gps_mask_t mask = 0;

if (data_len != 16)
return 0;

tow = (unsigned int)getleu32(buf, 0);
gw = (unsigned int)getles16(buf, 8);
flags = (unsigned int)getub(buf, 11);
if ((flags & 0x7) != 0)
// Valid leap seconds
if ((flags & UBX_TIMEGPS_VALID_LEAP_SECOND) == UBX_TIMEGPS_VALID_LEAP_SECOND)
session->context->leap_seconds = (int)getub(buf, 10);
session->newdata.time = gpsd_gpstime_resolve(session,
(unsigned short int)gw,
(double)tow / 1000.0);
// Valid GPS time of week and week number
#define VALID_TIME (UBX_TIMEGPS_VALID_TIME | UBX_TIMEGPS_VALID_WEEK)
if ((flags & VALID_TIME) == VALID_TIME)
#undef VALID_TIME
{
iTOW = (unsigned int)getleu32(buf, 0);
fTOW = (int)getles32(buf, 4);
gw = (unsigned int)getles16(buf, 8);
session->newdata.time =
gpsd_gpstime_resolve(session,
(unsigned short int)gw,
((double)iTOW * 1e-3));
mask |= (TIME_SET | NTPTIME_IS);
}

gpsd_log(&session->context->errout, LOG_DATA,
"TIMEGPS: time=%.2f leap=%d, mask={TIME}\n",
session->newdata.time, session->context->leap_seconds);
return TIME_SET | NTPTIME_IS;
"TIMEGPS: time=%.2f mask={TIME}\n",
session->newdata.time);
return mask;
}

/**
Expand Down
4 changes: 4 additions & 0 deletions driver_ubx.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ typedef enum {
#define UBX_SOL_VALID_WEEK 0x04
#define UBX_SOL_VALID_TIME 0x08

#define UBX_TIMEGPS_VALID_TIME 0x01
#define UBX_TIMEGPS_VALID_WEEK 0x02
#define UBX_TIMEGPS_VALID_LEAP_SECOND 0x04

/* from UBX_NAV_SVINFO */
#define UBX_SAT_USED 0x01
#define UBX_SAT_DGPS 0x02
Expand Down

0 comments on commit 3d0da91

Please sign in to comment.