diff options
author | Eric S. Raymond <esr@thyrsus.com> | 2013-09-29 01:42:45 -0400 |
---|---|---|
committer | Eric S. Raymond <esr@thyrsus.com> | 2013-09-29 01:46:53 -0400 |
commit | 4361ec2d89bdf451602d659ddfd0fb9a79c178a2 (patch) | |
tree | af067d1d7614a9e67f449eec933ba3347cde10b0 /driver_nmea0183.c | |
parent | a77b95b57475c2856707e91b197f8aaa8e5eb407 (diff) | |
download | gpsd-4361ec2d89bdf451602d659ddfd0fb9a79c178a2.tar.gz |
Change gpsd_report to no longer use a global. All regression tests pass.
This is a large, ugly change. But without it we can't troubleshoot the
ICP/IP-source initialization bug properly - colliding definitions of
gpsd_report() were interfering with error reporting early in gpsd runs.
More cleanup work remains to be done, but at least this is working.
Diffstat (limited to 'driver_nmea0183.c')
-rw-r--r-- | driver_nmea0183.c | 122 |
1 files changed, 73 insertions, 49 deletions
diff --git a/driver_nmea0183.c b/driver_nmea0183.c index 9359c089..25b8615f 100644 --- a/driver_nmea0183.c +++ b/driver_nmea0183.c @@ -79,16 +79,19 @@ static void merge_ddmmyy(char *ddmmyy, struct gps_device_t *session) /* check for century wrap */ if (session->driver.nmea.date.tm_year % 100 == 99 && yy == 0) { session->context->century += 100; - gpsd_report(LOG_WARN, "century rollover detected.\n"); + gpsd_report(session->context->debug, LOG_WARN, "century rollover detected.\n"); } year = (session->context->century + yy); if ( (1 > mon ) || (12 < mon ) ) { - gpsd_report(LOG_WARN, "merge_ddmmyy(%s), malformed month\n", ddmmyy); + gpsd_report(session->context->debug, LOG_WARN, + "merge_ddmmyy(%s), malformed month\n", ddmmyy); } else if ( (1 > mday ) || (31 < mday ) ) { - gpsd_report(LOG_WARN, "merge_ddmmyy(%s), malformed day\n", ddmmyy); + gpsd_report(session->context->debug, LOG_WARN, + "merge_ddmmyy(%s), malformed day\n", ddmmyy); } else { - gpsd_report(LOG_DATA, "merge_ddmmyy(%s) sets year %d\n", + gpsd_report(session->context->debug, LOG_DATA, + "merge_ddmmyy(%s) sets year %d\n", ddmmyy, year); session->driver.nmea.date.tm_year = year - 1900; session->driver.nmea.date.tm_mon = mon - 1; @@ -118,7 +121,8 @@ static void register_fractional_time(const char *tag, const char *fld, session->driver.nmea.this_frac_time; session->driver.nmea.this_frac_time = safe_atof(fld); session->driver.nmea.latch_frac_time = true; - gpsd_report(LOG_DATA, "%s: registers fractional time %.2f\n", + gpsd_report(session->context->debug, LOG_DATA, + "%s: registers fractional time %.2f\n", tag, session->driver.nmea.this_frac_time); } } @@ -208,7 +212,7 @@ static gps_mask_t processGPRMC(int count, char *field[], } } - gpsd_report(LOG_DATA, + gpsd_report(session->context->debug, LOG_DATA, "RMC: ddmmyy=%s hhmmss=%s lat=%.2f lon=%.2f " "speed=%.2f track=%.2f mode=%d status=%d\n", field[9], field[1], @@ -264,7 +268,7 @@ static gps_mask_t processGPGLL(int count, char *field[], merge_hhmmss(field[5], session); register_fractional_time(field[0], field[5], session); if (session->driver.nmea.date.tm_year == 0) - gpsd_report(LOG_WARN, + gpsd_report(session->context->debug, LOG_WARN, "can't use GLL time until after ZDA or RMC has supplied a year.\n"); else { mask = TIME_SET; @@ -294,7 +298,7 @@ static gps_mask_t processGPGLL(int count, char *field[], mask |= STATUS_SET; } - gpsd_report(LOG_DATA, + gpsd_report(session->context->debug, LOG_DATA, "GLL: hhmmss=%s lat=%.2f lon=%.2f mode=%d status=%d\n", field[5], session->newdata.latitude, @@ -354,7 +358,7 @@ static gps_mask_t processGPGGA(int c UNUSED, char *field[], merge_hhmmss(field[1], session); register_fractional_time(field[0], field[1], session); if (session->driver.nmea.date.tm_year == 0) - gpsd_report(LOG_WARN, + gpsd_report(session->context->debug, LOG_WARN, "can't use GGA time until after ZDA or RMC has supplied a year.\n"); else { mask |= TIME_SET; @@ -396,7 +400,7 @@ static gps_mask_t processGPGGA(int c UNUSED, char *field[], session->newdata.longitude); } } - gpsd_report(LOG_DATA, + gpsd_report(session->context->debug, LOG_DATA, "GGA: hhmmss=%s lat=%.2f lon=%.2f alt=%.2f mode=%d status=%d\n", field[1], session->newdata.latitude, @@ -439,7 +443,7 @@ static gps_mask_t processGPGST(int count, char *field[], struct gps_device_t *se #undef PARSE_FIELD register_fractional_time(field[0], field[1], session); - gpsd_report(LOG_DATA, + gpsd_report(session->context->debug, LOG_DATA, "GST: utc = %.2f, rms = %.2f, maj = %.2f, min = %.2f, ori = %.2f, lat = %.2f, lon = %.2f, alt = %.2f\n", session->gpsdata.gst.utctime, session->gpsdata.gst.rms_deviation, @@ -480,7 +484,8 @@ static gps_mask_t processGPGSA(int count, char *field[], * Alarmingly, it's possible this error may be generic to SiRFstarIII. */ if (count < 17) { - gpsd_report(LOG_DATA, "GPGSA: malformed, setting ONLINE_SET only.\n"); + gpsd_report(session->context->debug, LOG_DATA, + "GPGSA: malformed, setting ONLINE_SET only.\n"); mask = ONLINE_SET; } else if (session->driver.nmea.latch_mode) { /* last GGA had a non-advancing timestamp; don't trust this GSA */ @@ -497,7 +502,8 @@ static gps_mask_t processGPGSA(int count, char *field[], mask = 0; else mask = MODE_SET; - gpsd_report(LOG_PROG, "GPGSA sets mode %d\n", session->newdata.mode); + gpsd_report(session->context->debug, LOG_PROG, + "GPGSA sets mode %d\n", session->newdata.mode); session->gpsdata.dop.pdop = safe_atof(field[15]); session->gpsdata.dop.hdop = safe_atof(field[16]); session->gpsdata.dop.vdop = safe_atof(field[17]); @@ -511,7 +517,7 @@ static gps_mask_t processGPGSA(int count, char *field[], prn; } mask |= DOP_SET | USED_IS; - gpsd_report(LOG_DATA, + gpsd_report(session->context->debug, LOG_DATA, "GPGSA: mode=%d used=%d pdop=%.2f hdop=%.2f vdop=%.2f\n", session->newdata.mode, session->gpsdata.satellites_used, @@ -540,14 +546,16 @@ static gps_mask_t processGPGSV(int count, char *field[], */ int n, fldnum; if (count <= 3) { - gpsd_report(LOG_WARN, "malformed GPGSV - fieldcount %d <= 3\n", + gpsd_report(session->context->debug, LOG_WARN, + "malformed GPGSV - fieldcount %d <= 3\n", count); gpsd_zero_satellites(&session->gpsdata); session->gpsdata.satellites_visible = 0; return ONLINE_SET; } if (count % 4 != 0) { - gpsd_report(LOG_WARN, "malformed GPGSV - fieldcount %d %% 4 != 0\n", + gpsd_report(session->context->debug, LOG_WARN, + "malformed GPGSV - fieldcount %d %% 4 != 0\n", count); gpsd_zero_satellites(&session->gpsdata); session->gpsdata.satellites_visible = 0; @@ -556,7 +564,7 @@ static gps_mask_t processGPGSV(int count, char *field[], session->driver.nmea.await = atoi(field[1]); if ((session->driver.nmea.part = atoi(field[2])) < 1) { - gpsd_report(LOG_WARN, "malformed GPGSV - bad part\n"); + gpsd_report(session->context->debug, LOG_WARN, "malformed GPGSV - bad part\n"); gpsd_zero_satellites(&session->gpsdata); return ONLINE_SET; } else if (session->driver.nmea.part == 1) @@ -564,7 +572,8 @@ static gps_mask_t processGPGSV(int count, char *field[], for (fldnum = 4; fldnum < count;) { if (session->gpsdata.satellites_visible >= MAXCHANNELS) { - gpsd_report(LOG_ERROR, "internal error - too many satellites [%d]!\n", + gpsd_report(session->context->debug, LOG_ERROR, + "internal error - too many satellites [%d]!\n", session->gpsdata.satellites_visible); gpsd_zero_satellites(&session->gpsdata); break; @@ -592,13 +601,13 @@ static gps_mask_t processGPGSV(int count, char *field[], } if (session->driver.nmea.part == session->driver.nmea.await && atoi(field[3]) != session->gpsdata.satellites_visible) - gpsd_report(LOG_WARN, + gpsd_report(session->context->debug, LOG_WARN, "GPGSV field 3 value of %d != actual count %d\n", atoi(field[3]), session->gpsdata.satellites_visible); /* not valid data until we've seen a complete set of parts */ if (session->driver.nmea.part < session->driver.nmea.await) { - gpsd_report(LOG_PROG, "Partial satellite data (%d of %d).\n", + gpsd_report(session->context->debug, LOG_PROG, "Partial satellite data (%d of %d).\n", session->driver.nmea.part, session->driver.nmea.await); return ONLINE_SET; } @@ -613,13 +622,15 @@ static gps_mask_t processGPGSV(int count, char *field[], for (n = 0; n < session->gpsdata.satellites_visible; n++) if (session->gpsdata.azimuth[n] != 0) goto sane; - gpsd_report(LOG_WARN, "Satellite data no good (%d of %d).\n", + gpsd_report(session->context->debug, LOG_WARN, + "Satellite data no good (%d of %d).\n", session->driver.nmea.part, session->driver.nmea.await); gpsd_zero_satellites(&session->gpsdata); return ONLINE_SET; sane: session->gpsdata.skyview_time = NAN; - gpsd_report(LOG_DATA, "GSV: Satellite data OK (%d of %d).\n", + gpsd_report(session->context->debug, LOG_DATA, + "GSV: Satellite data OK (%d of %d).\n", session->driver.nmea.part, session->driver.nmea.await); return SATELLITE_SET; } @@ -660,7 +671,8 @@ static gps_mask_t processPGRME(int c UNUSED, char *field[], mask = HERR_SET | VERR_SET | PERR_IS; } - gpsd_report(LOG_DATA, "PGRME: epx=%.2f epy=%.2f epv=%.2f\n", + gpsd_report(session->context->debug, LOG_DATA, + "PGRME: epx=%.2f epy=%.2f epv=%.2f\n", session->newdata.epx, session->newdata.epy, session->newdata.epv); @@ -694,13 +706,14 @@ static gps_mask_t processGPGBS(int c UNUSED, char *field[], session->newdata.epy = safe_atof(field[2]); session->newdata.epx = safe_atof(field[3]); session->newdata.epv = safe_atof(field[4]); - gpsd_report(LOG_DATA, "GBS: epx=%.2f epy=%.2f epv=%.2f\n", + gpsd_report(session->context->debug, LOG_DATA, + "GBS: epx=%.2f epy=%.2f epv=%.2f\n", session->newdata.epx, session->newdata.epy, session->newdata.epv); return HERR_SET | VERR_SET; } else { - gpsd_report(LOG_PROG, + gpsd_report(session->context->debug, LOG_PROG, "second in $GPGBS error estimates doesn't match.\n"); return 0; } @@ -728,7 +741,7 @@ static gps_mask_t processGPZDA(int c UNUSED, char *field[], if (field[1][0] == '\0' || field[2][0] == '\0' || field[3][0] == '\0' || field[4][0] == '\0') { - gpsd_report(LOG_WARN, "ZDA fields are empty\n"); + gpsd_report(session->context->debug, LOG_WARN, "ZDA fields are empty\n"); } else { int year, mon, mday, century; @@ -744,11 +757,14 @@ static gps_mask_t processGPZDA(int c UNUSED, char *field[], mday = atoi(field[2]); century = year - year % 100; if ( (1900 > year ) || (2200 < year ) ) { - gpsd_report(LOG_WARN, "malformed ZDA year: %s\n", field[4]); + gpsd_report(session->context->debug, 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]); + gpsd_report(session->context->debug, 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]); + gpsd_report(session->context->debug, LOG_WARN, + "malformed ZDA day: %s\n", field[2]); } else { if (century > session->context->century) { /* @@ -758,14 +774,17 @@ static gps_mask_t processGPZDA(int c UNUSED, char *field[], * 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"); + gpsd_report(session->context->debug, LOG_WARN, + "century rollover detected.\n"); session->context->century = century; } else if (session->context->start_time >= GPS_EPOCH && century < session->context->century) { /* * This looks like a GPS week-counter rollover. */ - gpsd_report(LOG_WARN, "ZDA year %d less than clock year, " - "probable GPS week rollover lossage\n", year); + gpsd_report(session->context->debug, LOG_WARN, + "ZDA year %d less than clock year, " + "probable GPS week rollover lossage\n", + year); } session->driver.nmea.date.tm_year = year - 1900; session->driver.nmea.date.tm_mon = mon - 1; @@ -814,7 +833,8 @@ static gps_mask_t processHDT(int c UNUSED, char *field[], session->gpsdata.attitude.depth = NAN; mask |= (ATTITUDE_SET); - gpsd_report(LOG_RAW, "time %.3f, heading %lf.\n", + gpsd_report(session->context->debug, LOG_RAW, + "time %.3f, heading %lf.\n", session->newdata.time, session->gpsdata.attitude.heading); return mask; @@ -861,7 +881,8 @@ static gps_mask_t processDBT(int c UNUSED, char *field[], * no better place to put it. Should work in practice as nobody is * likely to be operating a depth sounder at varying altitudes. */ - gpsd_report(LOG_RAW, "mode %d, depth %lf.\n", + gpsd_report(session->context->debug, LOG_RAW, + "mode %d, depth %lf.\n", session->newdata.mode, session->newdata.altitude); return mask; @@ -927,7 +948,8 @@ static gps_mask_t processTNTHTM(int c UNUSED, char *field[], session->gpsdata.attitude.depth = NAN; mask |= (ATTITUDE_SET); - gpsd_report(LOG_RAW, "time %.3f, heading %lf (%c).\n", + gpsd_report(session->context->debug, LOG_RAW, + "time %.3f, heading %lf (%c).\n", session->newdata.time, session->gpsdata.attitude.heading, session->gpsdata.attitude.mag_st); @@ -985,7 +1007,8 @@ static gps_mask_t processOHPR(int c UNUSED, char *field[], session->gpsdata.attitude.gyro_y = safe_atof(field[16]); mask |= (ATTITUDE_SET); - gpsd_report(LOG_RAW, "Heading %lf.\n", session->gpsdata.attitude.heading); + gpsd_report(session->context->debug, LOG_RAW, + "Heading %lf.\n", session->gpsdata.attitude.heading); return mask; } #endif /* OCEANSERVER_ENABLE */ @@ -1000,7 +1023,8 @@ static gps_mask_t processPASHR(int c UNUSED, char *field[], if (0 == strcmp("RID", field[1])) { /* Receiver ID */ (void)snprintf(session->subtype, sizeof(session->subtype) - 1, "%s ver %s", field[2], field[3]); - gpsd_report(LOG_DATA, "PASHR,RID: subtype=%s mask={}\n", + gpsd_report(session->context->debug, LOG_DATA, + "PASHR,RID: subtype=%s mask={}\n", session->subtype); return mask; } else if (0 == strcmp("POS", field[1])) { /* 3D Position */ @@ -1032,7 +1056,7 @@ static gps_mask_t processPASHR(int c UNUSED, char *field[], mask |= (TIME_SET | LATLON_SET | ALTITUDE_SET); mask |= (SPEED_SET | TRACK_SET | CLIMB_SET); mask |= DOP_SET; - gpsd_report(LOG_DATA, + gpsd_report(session->context->debug, LOG_DATA, "PASHR,POS: hhmmss=%s lat=%.2f lon=%.2f alt=%.f speed=%.2f track=%.2f climb=%.2f mode=%d status=%d pdop=%.2f hdop=%.2f vdop=%.2f tdop=%.2f\n", field[4], session->newdata.latitude, session->newdata.longitude, session->newdata.altitude, @@ -1055,7 +1079,8 @@ static gps_mask_t processPASHR(int c UNUSED, char *field[], session->gpsdata.used[u++] = p; } session->gpsdata.satellites_used = u; - gpsd_report(LOG_DATA, "PASHR,SAT: used=%d\n", + gpsd_report(session->context->debug, LOG_DATA, + "PASHR,SAT: used=%d\n", session->gpsdata.satellites_used); session->gpsdata.skyview_time = NAN; mask |= SATELLITE_SET | USED_IS; @@ -1142,7 +1167,8 @@ gps_mask_t nmea_parse(char *sentence, struct gps_device_t * session) * packets. This may be a generic bug of all Garmin chipsets. */ if (strlen(sentence) > NMEA_MAX) { - gpsd_report(LOG_WARN, "Overlong packet of %zd chars rejected.\n", + gpsd_report(session->context->debug, LOG_WARN, + "Overlong packet of %zd chars rejected.\n", strlen(sentence)); return ONLINE_SET; } @@ -1221,7 +1247,7 @@ gps_mask_t nmea_parse(char *sentence, struct gps_device_t * session) * WARNING: This assumes time is always field 0, and that field 0 * is a timestamp whenever TIME_SET is set. */ - gpsd_report(LOG_DATA, + gpsd_report(session->context->debug, LOG_DATA, "%s time is %2f = %d-%02d-%02dT%02d:%02d:%02.2fZ\n", session->driver.nmea.field[0], session->newdata.time, 1900 + session->driver.nmea.date.tm_year, @@ -1253,7 +1279,7 @@ gps_mask_t nmea_parse(char *sentence, struct gps_device_t * session) * mid-cycle, as in the Garmin eXplorist 210; those might jitter. */ if (session->driver.nmea.latch_frac_time) { - gpsd_report(LOG_PROG, + gpsd_report(session->context->debug, LOG_PROG, "%s sentence timestamped %.2f.\n", session->driver.nmea.field[0], session->driver.nmea.this_frac_time); @@ -1262,7 +1288,7 @@ gps_mask_t nmea_parse(char *sentence, struct gps_device_t * session) session->driver.nmea.last_frac_time)) { uint lasttag = session->driver.nmea.lasttag; retval |= CLEAR_IS; - gpsd_report(LOG_PROG, + gpsd_report(session->context->debug, LOG_PROG, "%s starts a reporting cycle.\n", session->driver.nmea.field[0]); /* @@ -1275,7 +1301,7 @@ gps_mask_t nmea_parse(char *sentence, struct gps_device_t * session) && (session->driver.nmea.cycle_enders & (1 << lasttag)) == 0 && !session->driver.nmea.cycle_continue) { session->driver.nmea.cycle_enders |= (1 << lasttag); - gpsd_report(LOG_PROG, + gpsd_report(session->context->debug, LOG_PROG, "tagged %s as a cycle ender.\n", nmea_phrase[lasttag - 1].name); } @@ -1283,11 +1309,11 @@ gps_mask_t nmea_parse(char *sentence, struct gps_device_t * session) } else { /* extend the cycle to an un-timestamped sentence? */ if ((session->driver.nmea.lasttag & session->driver.nmea.cycle_enders) != 0) - gpsd_report(LOG_PROG, + gpsd_report(session->context->debug, LOG_PROG, "%s is just after a cycle ender.\n", session->driver.nmea.field[0]); if (session->driver.nmea.cycle_continue) { - gpsd_report(LOG_PROG, + gpsd_report(session->context->debug, LOG_PROG, "%s extends the reporting cycle.\n", session->driver.nmea.field[0]); session->driver.nmea.cycle_enders &=~ (1 << session->driver.nmea.lasttag); @@ -1297,7 +1323,7 @@ gps_mask_t nmea_parse(char *sentence, struct gps_device_t * session) /* here's where we check for end-of-cycle */ if ((session->driver.nmea.latch_frac_time || session->driver.nmea.cycle_continue) && (session->driver.nmea.cycle_enders & (1 << thistag))!=0) { - gpsd_report(LOG_PROG, + gpsd_report(session->context->debug, LOG_PROG, "%s ends a reporting cycle.\n", session->driver.nmea.field[0]); retval |= REPORT_IS; @@ -1323,8 +1349,6 @@ void nmea_add_checksum(char *sentence) if (*p == '$' || *p == '!') { p++; - } else { - gpsd_report(LOG_ERROR, "Bad NMEA sentence: '%s'\n", sentence); } while (((c = *p) != '*') && (c != '\0')) { sum ^= c; |