diff options
author | Eric S. Raymond <esr@thyrsus.com> | 2010-12-19 11:51:45 -0500 |
---|---|---|
committer | Eric S. Raymond <esr@thyrsus.com> | 2010-12-19 11:51:45 -0500 |
commit | 0d1d9e9a01fb18f3206053cd8821c129b4b10684 (patch) | |
tree | fff2f2f06d99cedd0314c35c099725165afd564c /driver_nmea.c | |
parent | 3d48c64283d33bbd0654874cb174ea25c95d3fe5 (diff) | |
download | gpsd-0d1d9e9a01fb18f3206053cd8821c129b4b10684.tar.gz |
Update context century from a greater ZDA century; handles century rollovers.
All regression tests pass.
Diffstat (limited to 'driver_nmea.c')
-rw-r--r-- | driver_nmea.c | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/driver_nmea.c b/driver_nmea.c index 7e9215b4..8d08303f 100644 --- a/driver_nmea.c +++ b/driver_nmea.c @@ -657,7 +657,7 @@ static gps_mask_t processGPZDA(int c UNUSED, char *field[], || field[4][0] == '\0') { gpsd_report(LOG_WARN, "malformed ZDA\n"); } else { - int year, mon, mday; + int year, mon, mday, century; merge_hhmmss(field[1], session); /* @@ -669,12 +669,34 @@ static gps_mask_t processGPZDA(int c UNUSED, char *field[], year = atoi(field[4]); mon = atoi(field[3]); mday = atoi(field[2]); + century = year - year % 100; if ( (1900 > year ) || (2200 < year ) ) { gpsd_report(LOG_WARN, "malformed ZDA year: %s\n", field[4]); } else if ( (1 > mon ) || (12 < mon ) ) { gpsd_report(LOG_WARN, "malformed ZDA month: %s\n", field[3]); } else if ( (1 > mday ) || (31 < mday ) ) { gpsd_report(LOG_WARN, "malformed ZDA day: %s\n", field[2]); + } else if (century > session->context->century) { + /* + * This mismatch is almost certainly not due to a GPS week + * rollover, because that would throw the ZDA report backward + * into the last rollover period instead of forward. Almost + * certainly it means that a century mark has passed while + * gpsd was running, and we should trust the new ZDA year. + */ + gpsd_report(LOG_WARN, "century rollover detected.\n"); + session->context->century = century; +#if 0 + } else if (century < session->context->century) { + /* + * This looks like a GPS week-counter rollover. Hidden + * assumption in the above test is that a bogus (small positive + * or negative) system clock value will always fail the + * above guard and thus never trigger this error message. + */ + gpsd_report(LOG_ERROR, "ZDA year %s less than clock year, " + "probable GPS week rollover lossage\n", field[2]); +#endif } else { year -= 1900; session->driver.nmea.date.tm_year = year; |