From 995976ab06a8f688343b8fec87e1305e2d5ee80e Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Wed, 27 Aug 2014 16:42:04 -0400 Subject: The big leap. Most instances of gpsd_report are replaced... ...with calls to gps_notify(), which indirects to its output method through a slot in an errout structure. Usually the errout structure lives inside the session context, but because struct errout_t is its own thing this does not have to be the case. One large clique of gpsd_notify() calls, in packet.c and isgps.c, looks at a struct errout_t copy in a lexer control block This change is not complete. Remnant gpsd_report calls need to be changed, and gpsmon needs to be tweaked so that the struct_error_t in its context is a non-defaukt hook updating the cuses display rather than simply dumping to stderr. Also the report label functionality needs to be added. All regression tests pass. --- driver_navcom.c | 104 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 52 insertions(+), 52 deletions(-) (limited to 'driver_navcom.c') diff --git a/driver_navcom.c b/driver_navcom.c index 2317fbe5..bd484567 100644 --- a/driver_navcom.c +++ b/driver_navcom.c @@ -104,7 +104,7 @@ static void navcom_cmd_0x20(struct gps_device_t *session, uint8_t block_id, putbyte(msg, 16, checksum(msg + 3, 13)); putbyte(msg, 17, 0x03); (void)navcom_send_cmd(session, msg, 18); - gpsd_report(session->context->errout.debug, LOG_PROG, + gpsd_notify(&session->context->errout, LOG_PROG, "Navcom: sent command 0x20 (Data Request) " "- data block id = %02x at rate %02x\n", block_id, rate); } @@ -127,7 +127,7 @@ static void UNUSED navcom_cmd_0x3f(struct gps_device_t *session) putbyte(msg, 10, checksum(msg + 3, 7)); putbyte(msg, 11, 0x03); (void)navcom_send_cmd(session, msg, 12); - gpsd_report(session->context->errout.debug, LOG_PROG, + gpsd_notify(&session->context->errout, LOG_PROG, "Navcom: sent command 0x3f (LED Configuration Block)\n"); } @@ -148,9 +148,9 @@ static void navcom_cmd_0x1c(struct gps_device_t *session, uint8_t mode, putbyte(msg, 10, checksum(msg + 3, 7)); putbyte(msg, 11, 0x03); (void)navcom_send_cmd(session, msg, 12); - gpsd_report(session->context->errout.debug, LOG_PROG, + gpsd_notify(&session->context->errout, LOG_PROG, "Navcom: sent command 0x1c (Test Support Block)\n"); - gpsd_report(session->context->errout.debug, LOG_DATA, + gpsd_notify(&session->context->errout, LOG_DATA, "Navcom: command 0x1c mode = %02x, length = %u\n", mode, length); } @@ -175,9 +175,9 @@ static void navcom_cmd_0x11(struct gps_device_t *session, putbyte(msg, 10, checksum(msg + 3, 7)); putbyte(msg, 11, 0x03); (void)navcom_send_cmd(session, msg, 12); - gpsd_report(session->context->errout.debug, LOG_PROG, + gpsd_notify(&session->context->errout, LOG_PROG, "Navcom: sent command 0x11 (Serial Port Configuration)\n"); - gpsd_report(session->context->errout.debug, LOG_DATA, + gpsd_notify(&session->context->errout, LOG_DATA, "Navcom: serial port selection: 0x%02x\n", port_selection); } #endif /* RECONFIGURE_ENABLE */ @@ -276,27 +276,27 @@ static gps_mask_t handle_0x83(struct gps_device_t *session) } /*@ -relaxtypes -charint @*/ - gpsd_report(session->context->errout.debug, LOG_PROG, + gpsd_notify(&session->context->errout, LOG_PROG, "Navcom: received packet type 0x83 (Ionosphere and UTC Data)\n"); - gpsd_report(session->context->errout.debug, LOG_DATA, + gpsd_notify(&session->context->errout, LOG_DATA, "Navcom: Scaled parameters follow:\n"); - gpsd_report(session->context->errout.debug, LOG_DATA, + gpsd_notify(&session->context->errout, LOG_DATA, "Navcom: GPS Week: %u, GPS Time of Week: %u (GPS Time: %f)\n", week, tow, week * 604800 + tow / 1000.0); - gpsd_report(session->context->errout.debug, LOG_DATA, + gpsd_notify(&session->context->errout, LOG_DATA, "Navcom: a0: %12.4E, a1: %12.4E, a2: %12.4E, a3: %12.4E, " "b0: %12.4E, b1: %12.4E, b2: %12.4E, b3: %12.4E\n", (double)alpha0 * SF_ALPHA0, (double)alpha1 * SF_ALPHA1, (double)alpha2 * SF_ALPHA2, (double)alpha3 * SF_ALPHA3, (double)beta0 * SF_BETA0, (double)beta1 * SF_BETA1, (double)beta2 * SF_BETA2, (double)beta3 * SF_BETA3); - gpsd_report(session->context->errout.debug, LOG_DATA, + gpsd_notify(&session->context->errout, LOG_DATA, "Navcom: A0: %19.12E, A1: %19.12E\n", (double)a0 * SF_A0, (double)a1 * SF_A1); - gpsd_report(session->context->errout.debug, LOG_DATA, + gpsd_notify(&session->context->errout, LOG_DATA, "Navcom: UTC Ref. Time: %lu, UTC Ref. Week: %u, dTls: %d\n", (unsigned long)tot * SF_TOT, wnt, dtls); - gpsd_report(session->context->errout.debug, LOG_DATA, + gpsd_notify(&session->context->errout, LOG_DATA, "Navcom: Week of leap seconds: %u, Day number of leap seconds: %u, dTlsf: %d\n", wnlsf, dn, dtlsf); @@ -322,10 +322,10 @@ static gps_mask_t handle_0x06(struct gps_device_t *session) uint8_t cmd_id = getub(buf, 3); uint8_t port = getub(buf, 4); session->driver.navcom.physical_port = port; /* This tells us which serial port was used last */ - gpsd_report(session->context->errout.debug, LOG_PROG, + gpsd_notify(&session->context->errout, LOG_PROG, "Navcom: received packet type 0x06 (Acknowledgement (without error))\n"); /*@ -type @*/ - gpsd_report(session->context->errout.debug, LOG_DATA, + gpsd_notify(&session->context->errout, LOG_DATA, "Navcom: acknowledged command id 0x%02x on port %c\n", cmd_id, (port == 0 ? 'A' : (port == 1 ? 'B' : '?'))); /*@ +type @*/ @@ -340,17 +340,17 @@ static gps_mask_t handle_0x15(struct gps_device_t *session) size_t msg_len = (size_t) getleu16(buf, 1); /*@ -type @*/ uint8_t port, cmd_id = getub(buf, 3); - gpsd_report(session->context->errout.debug, LOG_PROG, + gpsd_notify(&session->context->errout, LOG_PROG, "Navcom: received packet type 0x15 (Negative Acknowledge)\n"); for (n = 4; n < (msg_len - 2); n += 2) { uint8_t err_id = getub(buf, n); uint8_t err_desc = getub(buf, n + 1); - gpsd_report(session->context->errout.debug, LOG_DATA, + gpsd_notify(&session->context->errout, LOG_DATA, "Navcom: error id = 0x%02x, error description = 0x%02x\n", err_id, err_desc); } port = getub(buf, n); - gpsd_report(session->context->errout.debug, LOG_DATA, + gpsd_notify(&session->context->errout, LOG_DATA, "Navcom: negative acknowledge was for command id 0x%02x on port %c\n", cmd_id, (port == 0 ? 'A' : (port == 1 ? 'B' : '?'))); /*@ -type @*/ @@ -494,19 +494,19 @@ static gps_mask_t handle_0xb1(struct gps_device_t *session) if (tdop != DOP_UNDEFINED) session->gpsdata.dop.tdop = tdop / 10.0; - gpsd_report(session->context->errout.debug, LOG_PROG, + gpsd_notify(&session->context->errout, LOG_PROG, "Navcom: received packet type 0xb1 (PVT Report)\n"); - gpsd_report(session->context->errout.debug, LOG_DATA, + gpsd_notify(&session->context->errout, LOG_DATA, "Navcom: navigation mode %s (0x%02x) - %s - %s\n", ((-nav_mode & 0x80)!='\0' ? "invalid" : "valid"), nav_mode, ((nav_mode & 0x40)!='\0' ? "3D" : "2D"), ((nav_mode & 0x03)!='\0' ? "DGPS" : "GPS")); /*@ +type @*/ - gpsd_report(session->context->errout.debug, LOG_DATA, + gpsd_notify(&session->context->errout, LOG_DATA, "Navcom: latitude = %f, longitude = %f, altitude = %f, geoid = %f\n", session->newdata.latitude, session->newdata.longitude, session->newdata.altitude, session->gpsdata.separation); - gpsd_report(session->context->errout.debug, LOG_DATA, + gpsd_notify(&session->context->errout, LOG_DATA, "Navcom: velocities: north = %f, east = %f, up = %f (track = %f, speed = %f)\n", vel_north * VEL_RES, vel_east * VEL_RES, vel_up * VEL_RES, session->newdata.track, session->newdata.speed); @@ -521,7 +521,7 @@ static gps_mask_t handle_0xb1(struct gps_device_t *session) | STATUS_SET | MODE_SET | USED_IS | HERR_SET | VERR_SET | TIMERR_SET | DOP_SET | TIME_SET | PPSTIME_IS; - gpsd_report(session->context->errout.debug, LOG_DATA, + gpsd_notify(&session->context->errout, LOG_DATA, "PVT 0xb1: time=%.2f, lat=%.2f lon=%.2f alt=%.f " "speed=%.2f track=%.2f climb=%.2f mode=%d status=%d " "epx=%.2f epy=%.2f epv=%.2f " @@ -647,41 +647,41 @@ static gps_mask_t handle_0x81(struct gps_device_t *session) session->context->gps_week = (unsigned short)wn; session->context->gps_tow = (double)(toc * SF_TOC); /* leap second? */ - gpsd_report(session->context->errout.debug, LOG_PROG, + gpsd_notify(&session->context->errout, LOG_PROG, "Navcom: received packet type 0x81 (Packed Ephemeris Data)\n"); - gpsd_report(session->context->errout.debug, LOG_DATA, + gpsd_notify(&session->context->errout, LOG_DATA, "Navcom: PRN: %u, Week: %u, TOW: %.3f SV clock bias/drift/drift rate: %#19.12E/%#19.12E/%#19.12E\n", prn, session->context->gps_week, session->context->gps_tow, ((double)af0) * SF_AF0, ((double)af1) * SF_AF1, ((double)af2) * SF_AF2); - gpsd_report(session->context->errout.debug, LOG_DATA, + gpsd_notify(&session->context->errout, LOG_DATA, "Navcom: IODE (!AODE): %u Crs: %19.12e, Delta n: %19.12e, M0: %19.12e\n", iode, (double)crs * SF_CRS, (double)delta_n * SF_DELTA_N * GPS_PI, (double)m0 * SF_M0 * GPS_PI); - gpsd_report(session->context->errout.debug, LOG_DATA, + gpsd_notify(&session->context->errout, LOG_DATA, "Navcom: Cuc: %19.12e, Eccentricity: %19.12e, Cus: %19.12e, A^1/2: %19.12e\n", (double)cuc * SF_CUC, (double)e * SF_E, (double)cus * SF_CUS, (double)sqrt_a * SF_SQRT_A); - gpsd_report(session->context->errout.debug, LOG_DATA, + gpsd_notify(&session->context->errout, LOG_DATA, "Navcom: TOE: %u, Cic: %19.12e, Omega %19.12e, Cis: %19.12e\n", toe * SF_TOE, (double)cic * SF_CIC, (double)Omega0 * SF_OMEGA0 * GPS_PI, (double)cis * SF_CIS); - gpsd_report(session->context->errout.debug, LOG_DATA, + gpsd_notify(&session->context->errout, LOG_DATA, "Navcom: i0: %19.12e, Crc: %19.12e, omega: %19.12e, Omega dot: %19.12e\n", (double)i0 * SF_I0 * GPS_PI, (double)crc * SF_CRC, (double)omega * SF_OMEGA * GPS_PI, (double)Omegadot * SF_OMEGADOT * GPS_PI); - gpsd_report(session->context->errout.debug, LOG_DATA, + gpsd_notify(&session->context->errout, LOG_DATA, "Navcom: IDOT: %19.12e, Codes on L2: 0x%x, GPS Week: %u, L2 P data flag: %x\n", (double)idot * SF_IDOT * GPS_PI, cl2, week - (week % 1024) + wn, l2pd); - gpsd_report(session->context->errout.debug, LOG_DATA, + gpsd_notify(&session->context->errout, LOG_DATA, "Navcom: SV accuracy: 0x%x, SV health: 0x%x, TGD: %f, IODC (!AODC): %u\n", ura, svh, (double)tgd * SF_TGD, iodc); - gpsd_report(session->context->errout.debug, LOG_DATA, "Navcom: Transmission time: %u\n", tow); + gpsd_notify(&session->context->errout, LOG_DATA, "Navcom: Transmission time: %u\n", tow); #undef SF_TGD #undef SF_TOC @@ -750,7 +750,7 @@ static gps_mask_t handle_0x86(struct gps_device_t *session) } /*@ -predboolothers @*/ - gpsd_report(session->context->errout.debug, LOG_DATA, + gpsd_notify(&session->context->errout, LOG_DATA, "Navcom: engine status = 0x%x, almanac = %s, time = 0x%x, pos = 0x%x\n", eng_status & 0x07, (eng_status & 0x08 ? "valid" : "invalid"), eng_status & 0x30 >> 4, eng_status & 0xc0 >> 6); @@ -760,7 +760,7 @@ static gps_mask_t handle_0x86(struct gps_device_t *session) i = 0; for (n = 17; n < msg_len; n += 14) { if (i >= MAXCHANNELS) { - gpsd_report(session->context->errout.debug, LOG_ERROR, + gpsd_notify(&session->context->errout, LOG_ERROR, "Navcom: packet type 0x86: too many satellites!\n"); gpsd_zero_satellites(&session->gpsdata); return 0; @@ -789,12 +789,12 @@ static gps_mask_t handle_0x86(struct gps_device_t *session) s = session->gpsdata.ss[i++] = (p2_snr ? p2_snr : ca_snr) / 4.0; /*@ end @*/ } - gpsd_report(session->context->errout.debug, LOG_DATA, + gpsd_notify(&session->context->errout, LOG_DATA, "Navcom: prn = %3u, ele = %02u, azm = %03u, snr = %d (%s), " "dgps age = %.1fs, log ch = %d, hw ch = 0x%02x\n", prn, ele, azm, s, (p2_snr ? "P2" : "C/A"), (double)dgps_age * 0.1, log_channel & 0x3f, hw_channel); - gpsd_report(session->context->errout.debug, LOG_DATA, + gpsd_notify(&session->context->errout, LOG_DATA, "Navcom: sol. valid = %c, clock = %s, pos. = %s, " "height = %s, err. code = 0x%x\n", (sol_status & 0x01 ? 'Y' : 'N'), @@ -805,7 +805,7 @@ static gps_mask_t handle_0x86(struct gps_device_t *session) /*@ +predboolothers -charint @*/ } - gpsd_report(session->context->errout.debug, LOG_DATA, + gpsd_notify(&session->context->errout, LOG_DATA, "CS 0x86: visible=%d, used=%d, mask={SATELLITE|STATUS}\n", session->gpsdata.satellites_visible, session->gpsdata.satellites_used); @@ -828,10 +828,10 @@ static gps_mask_t handle_0xb0(struct gps_device_t *session) session->context->gps_week = (unsigned short)week; session->context->gps_tow = (double)tow / 1000.0; - gpsd_report(session->context->errout.debug, LOG_PROG, + gpsd_notify(&session->context->errout, LOG_PROG, "Navcom: received packet type 0xb0 (Raw Meas. Data Block)\n"); /*@ -predboolothers @*/ - gpsd_report(session->context->errout.debug, LOG_DATA, + gpsd_notify(&session->context->errout, LOG_DATA, "Navcom: week = %u, tow = %.3f, time slew accumulator = %u (1/1023mS), status = 0x%02x " "(%sclock %s - %u blocks follow)\n", session->context->gps_week, @@ -869,17 +869,17 @@ static gps_mask_t handle_0xb0(struct gps_device_t *session) double p2 = (sv_status & 0x20 ? c1 + (double)p2_ca_pseudorange / 16.0 * LAMBDA_L1 : NAN); - gpsd_report(session->context->errout.debug, LOG_DATA + 1, + gpsd_notify(&session->context->errout, LOG_DATA + 1, "Navcom: >> sv status = 0x%02x (PRN %u - C/A & L1 %s - P1 %s - P2 & L2 %s)\n", sv_status, (sv_status & 0x1f), (sv_status & 0x80 ? "valid" : "invalid"), (sv_status & 0x40 ? "valid" : "invalid"), (sv_status & 0x20 ? "valid" : "invalid")); - gpsd_report(session->context->errout.debug, LOG_DATA + 1, + gpsd_notify(&session->context->errout, LOG_DATA + 1, "Navcom: >>> ch status = 0x%02x (Logical channel: %u - CA C/No: %u dBHz) " "sL1: %u, sL2: %u\n", ch_status, ch_status & 0x0f, ((ch_status & 0xf0) >> 4) + 35, l1_slips, l2_slips); - gpsd_report(session->context->errout.debug, LOG_DATA + 1, + gpsd_notify(&session->context->errout, LOG_DATA + 1, "Navcom: >>> C1: %14.3f, L1: %14.3f, L2: %14.3f, P1: %14.3f, P2: %14.3f\n", c1, l1, l2, p1, p2); /*@ +predboolothers -charint @*/ @@ -920,15 +920,15 @@ static gps_mask_t handle_0xb5(struct gps_device_t *session) session->newdata.time = gpsd_gpstime_resolve(session, (unsigned short)week, (double)tow / 1000.0f); - gpsd_report(session->context->errout.debug, LOG_PROG, + gpsd_notify(&session->context->errout, LOG_PROG, "Navcom: received packet type 0xb5 (Pseudorange Noise Statistics)\n"); - gpsd_report(session->context->errout.debug, LOG_DATA, + gpsd_notify(&session->context->errout, LOG_DATA, "Navcom: epe = %f\n", session->gpsdata.epe); return mask; } else { /* Ignore this message block */ if (!session->driver.navcom.warned) { - gpsd_report(session->context->errout.debug, LOG_WARN, + gpsd_notify(&session->context->errout, LOG_WARN, "Navcom: received packet type 0xb5 (Pseudorange Noise Statistics) ignored " " - sizeof(double) == 64 bits required\n"); session->driver.navcom.warned = true; @@ -1051,16 +1051,16 @@ static gps_mask_t handle_0xae(struct gps_device_t *session) asicstr = "?"; } - gpsd_report(session->context->errout.debug, LOG_PROG, + gpsd_notify(&session->context->errout, LOG_PROG, "Navcom: received packet type 0xae (Identification Block)\n"); if (msg_len == 0x0037) { - gpsd_report(session->context->errout.debug, LOG_INF, "Navcom: ID Data: " + gpsd_notify(&session->context->errout, LOG_INF, "Navcom: ID Data: " "%s %s Ver. %u.%u.%u, DC S/N: %u.%u, RF S/N: %u.%u, " "Build ID: %s, Boot software: %s\n", engconfstr, asicstr, swvermaj, swvermin, slsbn, dcser, dcclass, rfcser, rfcclass, softtm, bootstr); } else { - gpsd_report(session->context->errout.debug, LOG_INF, "Navcom: ID Data: " + gpsd_notify(&session->context->errout, LOG_INF, "Navcom: ID Data: " "%s %s Ver. %u.%u.%u, DC S/N: %u.%u, RF S/N: %u.%u, " "Build ID: %s, Boot software: %s, " "IOP Ver.: %u.%u.%u, PIC: %u, IOP Build ID: %s\n", @@ -1104,13 +1104,13 @@ static gps_mask_t handle_0xef(struct gps_device_t *session) osc_filter_drift_est = NAN; } - gpsd_report(session->context->errout.debug, LOG_DATA, + gpsd_notify(&session->context->errout, LOG_DATA, "Navcom: oscillator temp. = %d, nav. status = 0x%02x, " "nav. clock offset = %f, nav. clock drift = %f, " "osc. filter drift est. = %f, acc.time slew value = %d\n", osc_temp, nav_status, nav_clock_offset, nav_clock_drift, osc_filter_drift_est, time_slew); - gpsd_report(session->context->errout.debug, LOG_DATA, + gpsd_notify(&session->context->errout, LOG_DATA, "CDO 0xef: time=%.2f mask={TIME}\n", session->newdata.time); return 0; } @@ -1131,7 +1131,7 @@ gps_mask_t navcom_parse(struct gps_device_t * session, unsigned char *buf, msg_len = (uint) getleu16(buf, 4); /*@ -usedef -compdef @*/ - gpsd_report(session->context->errout.debug, LOG_RAW, "Navcom: packet type 0x%02x\n", cmd_id); + gpsd_notify(&session->context->errout, LOG_RAW, "Navcom: packet type 0x%02x\n", cmd_id); /*@ +usedef +compdef @*/ session->cycle_end_reliable = true; @@ -1160,7 +1160,7 @@ gps_mask_t navcom_parse(struct gps_device_t * session, unsigned char *buf, case 0xef: return handle_0xef(session); default: - gpsd_report(session->context->errout.debug, LOG_PROG, + gpsd_notify(&session->context->errout, LOG_PROG, "Navcom: received packet type 0x%02x, length %d - unknown or unimplemented\n", cmd_id, msg_len); return 0; -- cgit v1.2.1