diff options
-rw-r--r-- | driver_ais.c | 100 | ||||
-rw-r--r-- | driver_evermore.c | 38 | ||||
-rw-r--r-- | driver_garmin.c | 222 | ||||
-rw-r--r-- | driver_garmin_txt.c | 88 | ||||
-rw-r--r-- | driver_geostar.c | 177 | ||||
-rw-r--r-- | driver_italk.c | 50 | ||||
-rw-r--r-- | driver_navcom.c | 108 | ||||
-rw-r--r-- | driver_nmea0183.c | 122 | ||||
-rw-r--r-- | driver_nmea2000.c | 207 | ||||
-rw-r--r-- | driver_oncore.c | 33 | ||||
-rw-r--r-- | driver_proto.c | 22 | ||||
-rw-r--r-- | driver_rtcm3.c | 5 | ||||
-rw-r--r-- | driver_sirf.c | 200 | ||||
-rw-r--r-- | driver_superstar2.c | 41 | ||||
-rw-r--r-- | driver_tsip.c | 148 | ||||
-rw-r--r-- | driver_ubx.c | 126 | ||||
-rw-r--r-- | driver_zodiac.c | 28 | ||||
-rw-r--r-- | drivers.c | 119 | ||||
-rw-r--r-- | gpsctl.c | 179 | ||||
-rw-r--r-- | gpsd.c | 346 | ||||
-rw-r--r-- | gpsd.h-tail | 42 | ||||
-rw-r--r-- | gpsd_json.c | 3 | ||||
-rw-r--r-- | gpsdecode.c | 16 | ||||
-rw-r--r-- | gpsmon.c | 8 | ||||
-rw-r--r-- | gpspacket.c | 2 | ||||
-rw-r--r-- | isgps.c | 26 | ||||
-rw-r--r-- | libgpsd_core.c | 140 | ||||
-rw-r--r-- | net_dgpsip.c | 12 | ||||
-rw-r--r-- | net_gnss_dispatch.c | 2 | ||||
-rw-r--r-- | net_ntrip.c | 138 | ||||
-rw-r--r-- | ntpshm.c | 149 | ||||
-rw-r--r-- | packet.c | 88 | ||||
-rw-r--r-- | serial.c | 39 | ||||
-rw-r--r-- | shmexport.c | 8 | ||||
-rw-r--r-- | subframe.c | 130 | ||||
-rw-r--r-- | test_geoid.c | 5 | ||||
-rw-r--r-- | test_packet.c | 4 | ||||
-rw-r--r-- | timebase.c | 12 |
38 files changed, 1874 insertions, 1309 deletions
diff --git a/driver_ais.c b/driver_ais.c index d482aadc..b69a0592 100644 --- a/driver_ais.c +++ b/driver_ais.c @@ -59,9 +59,10 @@ static void from_sixbit(unsigned char *bitvec, uint start, int count, char *to) } /*@ +charint @*/ -bool ais_binary_decode(struct ais_t *ais, - const unsigned char *bits, size_t bitlen, - struct ais_type24_queue_t *type24_queue) +bool ais_binary_decode(const int debug, + struct ais_t *ais, + const unsigned char *bits, size_t bitlen, + struct ais_type24_queue_t *type24_queue) /* decode an AIS binary packet */ { bool imo; @@ -76,7 +77,8 @@ bool ais_binary_decode(struct ais_t *ais, ais->type = UBITS(0, 6); ais->repeat = UBITS(6, 2); ais->mmsi = UBITS(8, 30); - gpsd_report(LOG_INF, "AIVDM message type %d, MMSI %09d:\n", + gpsd_report(debug, LOG_INF, + "AIVDM message type %d, MMSI %09d:\n", ais->type, ais->mmsi); /* * Something about the shape of this switch statement confuses @@ -89,7 +91,8 @@ bool ais_binary_decode(struct ais_t *ais, case 2: case 3: if (bitlen != 168) { - gpsd_report(LOG_WARN, "AIVDM message type %d size not 168 bits (%zd).\n", + gpsd_report(debug, LOG_WARN, + "AIVDM message type %d size not 168 bits (%zd).\n", ais->type, bitlen); return false; @@ -111,7 +114,8 @@ bool ais_binary_decode(struct ais_t *ais, case 4: /* Base Station Report */ case 11: /* UTC/Date Response */ if (bitlen != 168) { - gpsd_report(LOG_WARN, "AIVDM message type %d size not 168 bits (%zd).\n", + gpsd_report(debug, LOG_WARN, + "AIVDM message type %d size not 168 bits (%zd).\n", ais->type, bitlen); return false; @@ -132,7 +136,8 @@ bool ais_binary_decode(struct ais_t *ais, break; case 5: /* Ship static and voyage related data */ if (bitlen != 424) { - gpsd_report(LOG_WARN, "AIVDM message type 5 size not 424 bits (%zd).\n", + gpsd_report(debug, LOG_WARN, + "AIVDM message type 5 size not 424 bits (%zd).\n", bitlen); return false; } @@ -157,7 +162,8 @@ bool ais_binary_decode(struct ais_t *ais, break; case 6: /* Addressed Binary Message */ if (bitlen < 88 || bitlen > 1008) { - gpsd_report(LOG_WARN, "AIVDM message type 6 size is out of range (%zd).\n", + gpsd_report(debug, LOG_WARN, + "AIVDM message type 6 size is out of range (%zd).\n", bitlen); return false; } @@ -366,7 +372,8 @@ bool ais_binary_decode(struct ais_t *ais, { unsigned int mmsi[4]; if (bitlen < 72 || bitlen > 158) { - gpsd_report(LOG_WARN, "AIVDM message type %d size is out of range (%zd).\n", + gpsd_report(debug, LOG_WARN, + "AIVDM message type %d size is out of range (%zd).\n", ais->type, bitlen); return false; @@ -386,7 +393,8 @@ bool ais_binary_decode(struct ais_t *ais, } case 8: /* Binary Broadcast Message */ if (bitlen < 56 || bitlen > 1008) { - gpsd_report(LOG_WARN, "AIVDM message type 8 size is out of range (%zd).\n", + gpsd_report(debug, LOG_WARN, + "AIVDM message type 8 size is out of range (%zd).\n", bitlen); return false; } @@ -589,7 +597,8 @@ bool ais_binary_decode(struct ais_t *ais, break; case 9: /* Standard SAR Aircraft Position Report */ if (bitlen != 168) { - gpsd_report(LOG_WARN, "AIVDM message type 9 size not 168 bits (%zd).\n", + gpsd_report(debug, LOG_WARN, + "AIVDM message type 9 size not 168 bits (%zd).\n", bitlen); return false; } @@ -609,7 +618,8 @@ bool ais_binary_decode(struct ais_t *ais, break; case 10: /* UTC/Date inquiry */ if (bitlen != 72) { - gpsd_report(LOG_WARN, "AIVDM message type 10 size not 72 bits (%zd).\n", + gpsd_report(debug, LOG_WARN, + "AIVDM message type 10 size not 72 bits (%zd).\n", bitlen); return false; } @@ -619,7 +629,8 @@ bool ais_binary_decode(struct ais_t *ais, break; case 12: /* Safety Related Message */ if (bitlen < 72 || bitlen > 1008) { - gpsd_report(LOG_WARN, "AIVDM message type 12 size is out of range (%zd).\n", + gpsd_report(debug, LOG_WARN, + "AIVDM message type 12 size is out of range (%zd).\n", bitlen); return false; } @@ -631,7 +642,8 @@ bool ais_binary_decode(struct ais_t *ais, break; case 14: /* Safety Related Broadcast Message */ if (bitlen < 40 || bitlen > 1008) { - gpsd_report(LOG_WARN, "AIVDM message type 14 size is out of range (%zd).\n", + gpsd_report(debug, LOG_WARN, + "AIVDM message type 14 size is out of range (%zd).\n", bitlen); return false; } @@ -640,7 +652,8 @@ bool ais_binary_decode(struct ais_t *ais, break; case 15: /* Interrogation */ if (bitlen < 88 || bitlen > 168) { - gpsd_report(LOG_WARN, "AIVDM message type 15 size is out of range (%zd).\n", + gpsd_report(debug, LOG_WARN, + "AIVDM message type 15 size is out of range (%zd).\n", bitlen); return false; } @@ -665,7 +678,8 @@ bool ais_binary_decode(struct ais_t *ais, break; case 16: /* Assigned Mode Command */ if (bitlen != 96 && bitlen != 144) { - gpsd_report(LOG_WARN, "AIVDM message type 16 size is out of range (%zd).\n", + gpsd_report(debug, LOG_WARN, + "AIVDM message type 16 size is out of range (%zd).\n", bitlen); return false; } @@ -682,7 +696,8 @@ bool ais_binary_decode(struct ais_t *ais, break; case 17: /* GNSS Broadcast Binary Message */ if (bitlen < 80 || bitlen > 816) { - gpsd_report(LOG_WARN, "AIVDM message type 17 size is out of range (%zd).\n", + gpsd_report(debug, LOG_WARN, + "AIVDM message type 17 size is out of range (%zd).\n", bitlen); return false; } @@ -697,7 +712,8 @@ bool ais_binary_decode(struct ais_t *ais, break; case 18: /* Standard Class B CS Position Report */ if (bitlen != 168) { - gpsd_report(LOG_WARN, "AIVDM message type 18 size not 168 bits (%zd).\n", + gpsd_report(debug, LOG_WARN, + "AIVDM message type 18 size not 168 bits (%zd).\n", bitlen); return false; } @@ -721,7 +737,8 @@ bool ais_binary_decode(struct ais_t *ais, break; case 19: /* Extended Class B CS Position Report */ if (bitlen != 312) { - gpsd_report(LOG_WARN, "AIVDM message type 19 size not 312 bits (%zd).\n", + gpsd_report(debug, LOG_WARN, + "AIVDM message type 19 size not 312 bits (%zd).\n", bitlen); return false; } @@ -748,7 +765,8 @@ bool ais_binary_decode(struct ais_t *ais, break; case 20: /* Data Link Management Message */ if (bitlen < 72 || bitlen > 160) { - gpsd_report(LOG_WARN, "AIVDM message type 20 size is out of range (%zd).\n", + gpsd_report(debug, LOG_WARN, + "AIVDM message type 20 size is out of range (%zd).\n", bitlen); return false; } @@ -772,7 +790,8 @@ bool ais_binary_decode(struct ais_t *ais, break; case 21: /* Aid-to-Navigation Report */ if (bitlen < 272 || bitlen > 360) { - gpsd_report(LOG_WARN, "AIVDM message type 21 size is out of range (%zd).\n", + gpsd_report(debug, LOG_WARN, + "AIVDM message type 21 size is out of range (%zd).\n", bitlen); return false; } @@ -799,7 +818,8 @@ bool ais_binary_decode(struct ais_t *ais, break; case 22: /* Channel Management */ if (bitlen != 168) { - gpsd_report(LOG_WARN, "AIVDM message type 22 size not 168 bits (%zd).\n", + gpsd_report(debug, LOG_WARN, + "AIVDM message type 22 size not 168 bits (%zd).\n", bitlen); return false; } @@ -823,7 +843,8 @@ bool ais_binary_decode(struct ais_t *ais, break; case 23: /* Group Assignment Command */ if (bitlen != 160) { - gpsd_report(LOG_WARN, "AIVDM message type 23 size not 160 bits (%zd).\n", + gpsd_report(debug, LOG_WARN, + "AIVDM message type 23 size not 160 bits (%zd).\n", bitlen); return false; } @@ -841,7 +862,8 @@ bool ais_binary_decode(struct ais_t *ais, switch (UBITS(38, 2)) { case 0: if (bitlen != 160) { - gpsd_report(LOG_WARN, "AIVDM message type 24A size not 160 bits (%zd).\n", + gpsd_report(debug, LOG_WARN, + "AIVDM message type 24A size not 160 bits (%zd).\n", bitlen); return false; } @@ -851,7 +873,7 @@ bool ais_binary_decode(struct ais_t *ais, { struct ais_type24a_t *saveptr = &type24_queue->ships[type24_queue->index]; - gpsd_report(LOG_PROG, + gpsd_report(debug, LOG_PROG, "AIVDM: 24A from %09u stashed.\n", ais->mmsi); saveptr->mmsi = ais->mmsi; @@ -870,7 +892,8 @@ bool ais_binary_decode(struct ais_t *ais, } case 1: if (bitlen != 168) { - gpsd_report(LOG_WARN, "AIVDM message type 24B size not 168 bits (%zd).\n", + gpsd_report(debug, LOG_WARN, + "AIVDM message type 24B size not 168 bits (%zd).\n", bitlen); return false; } @@ -907,7 +930,7 @@ bool ais_binary_decode(struct ais_t *ais, (void)strlcpy(ais->type24.shipname, type24_queue->ships[i].shipname, sizeof(type24_queue->ships[i].shipname)); - gpsd_report(LOG_PROG, + gpsd_report(debug, LOG_PROG, "AIVDM 24B from %09u matches a 24A.\n", ais->mmsi); /* prevent false match if a 24B is repeated */ @@ -915,7 +938,7 @@ bool ais_binary_decode(struct ais_t *ais, return true; } } - gpsd_report(LOG_WARN, + gpsd_report(debug, LOG_WARN, "AIVDM 24B from %09u can't be matched to a 24A.\n", ais->mmsi); ais->type24.part = both; @@ -927,21 +950,24 @@ bool ais_binary_decode(struct ais_t *ais, return true; } default: - gpsd_report(LOG_WARN, "AIVDM message type 24 of subtype unknown.\n"); + gpsd_report(debug, LOG_WARN, + "AIVDM message type 24 of subtype unknown.\n"); return false; } // break; case 25: /* Binary Message, Single Slot */ /* this check and the following one reject line noise */ if (bitlen < 40 || bitlen > 168) { - gpsd_report(LOG_WARN, "AIVDM message type 25 size not between 40 to 168 bits (%zd).\n", + gpsd_report(debug, LOG_WARN, + "AIVDM message type 25 size not between 40 to 168 bits (%zd).\n", bitlen); return false; } ais->type25.addressed = (bool)UBITS(38, 1); ais->type25.structured = (bool)UBITS(39, 1); if (bitlen < (unsigned)(40 + (16*ais->type25.structured) + (30*ais->type25.addressed))) { - gpsd_report(LOG_WARN, "AIVDM message type 25 too short for mode.\n"); + gpsd_report(debug, LOG_WARN, + "AIVDM message type 25 too short for mode.\n"); return false; } if (ais->type25.addressed) @@ -964,14 +990,16 @@ bool ais_binary_decode(struct ais_t *ais, break; case 26: /* Binary Message, Multiple Slot */ if (bitlen < 60 || bitlen > 1004) { - gpsd_report(LOG_WARN, "AIVDM message type 26 size is out of range (%zd).\n", + gpsd_report(debug, LOG_WARN, + "AIVDM message type 26 size is out of range (%zd).\n", bitlen); return false; } ais->type26.addressed = (bool)UBITS(38, 1); ais->type26.structured = (bool)UBITS(39, 1); if ((signed)bitlen < 40 + 16*ais->type26.structured + 30*ais->type26.addressed + 20) { - gpsd_report(LOG_WARN, "AIVDM message type 26 too short for mode.\n"); + gpsd_report(debug, LOG_WARN, + "AIVDM message type 26 too short for mode.\n"); return false; } if (ais->type26.addressed) @@ -985,7 +1013,8 @@ bool ais_binary_decode(struct ais_t *ais, break; case 27: /* Long Range AIS Broadcast message */ if (bitlen != 96) { - gpsd_report(LOG_WARN, "AIVDM message type 27 size not 96 bits (%zd).\n", + gpsd_report(debug, LOG_WARN, + "AIVDM message type 27 size not 96 bits (%zd).\n", bitlen); return false; } @@ -999,7 +1028,8 @@ bool ais_binary_decode(struct ais_t *ais, ais->type27.gnss = (bool)UBITS(94, 1); break; default: - gpsd_report(LOG_ERROR, "Unparsed AIVDM message type %d.\n",ais->type); + gpsd_report(debug, LOG_ERROR, + "Unparsed AIVDM message type %d.\n",ais->type); return false; } /* *INDENT-ON* */ diff --git a/driver_evermore.c b/driver_evermore.c index 83888076..30cf7ff9 100644 --- a/driver_evermore.c +++ b/driver_evermore.c @@ -173,7 +173,8 @@ gps_mask_t evermore_parse(struct gps_device_t * session, unsigned char *buf, /*@ +usedef @*/ /*@ -usedef -compdef @*/ - gpsd_report(LOG_RAW, "EverMore packet type 0x%02x (%zd bytes)\n", type, tp-buf2); + gpsd_report(session->context->debug, LOG_RAW, + "EverMore packet type 0x%02x (%zd bytes)\n", type, tp-buf2); /*@ +usedef +compdef @*/ (void)snprintf(session->gpsdata.tag, sizeof(session->gpsdata.tag), @@ -211,7 +212,7 @@ gps_mask_t evermore_parse(struct gps_device_t * session, unsigned char *buf, "%3.2f", version); mask |= DEVICEID_SET; } - gpsd_report(LOG_DATA, + gpsd_report(session->context->debug, LOG_DATA, "NDO 0x02: time=%.2f, lat=%.2f lon=%.2f alt=%.2f speed=%.2f track=%.2f climb=%.2f mode=%d subtype='%s\n", session->newdata.time, session->newdata.latitude, session->newdata.longitude, session->newdata.altitude, @@ -256,7 +257,7 @@ gps_mask_t evermore_parse(struct gps_device_t * session, unsigned char *buf, } /* that's all the information in this packet */ mask = TIME_SET | PPSTIME_IS | DOP_SET | MODE_SET | STATUS_SET; - gpsd_report(LOG_DATA, + gpsd_report(session->context->debug, LOG_DATA, "DDO 0x04: gdop=%.2f pdop=%.2f hdop=%.2f vdop=%.2f tdop=%.2f mode=%d, status=%d mask={TIME| DOP|MODE|STATUS}\n", session->gpsdata.dop.gdop, session->gpsdata.dop.pdop, session->gpsdata.dop.hdop, session->gpsdata.dop.vdop, @@ -272,7 +273,7 @@ gps_mask_t evermore_parse(struct gps_device_t * session, unsigned char *buf, gpsd_zero_satellites(&session->gpsdata); memset(session->gpsdata.used, 0, sizeof(session->gpsdata.used)); if (session->gpsdata.satellites_visible > 12) { - gpsd_report(LOG_WARN, + gpsd_report(session->context->debug, LOG_WARN, "Warning: EverMore packet has information about %d satellites!\n", session->gpsdata.satellites_visible); } @@ -311,7 +312,7 @@ gps_mask_t evermore_parse(struct gps_device_t * session, unsigned char *buf, session->gpsdata.satellites_visible = (int)satcnt; /* that's all the information in this packet */ mask = SATELLITE_SET | USED_IS; - gpsd_report(LOG_DATA, + gpsd_report(session->context->debug, LOG_DATA, "CSO 0x06: time=%.2f used=%d visible=%d mask={TIME|SATELLITE|USED}\n", session->newdata.time, session->gpsdata.satellites_used, session->gpsdata.satellites_visible); @@ -354,24 +355,28 @@ gps_mask_t evermore_parse(struct gps_device_t * session, unsigned char *buf, } #undef SBITS #undef UBITS - gpsd_report(LOG_DATA, "MDO 0x04: time=%.2f mask={TIME|RAW}\n", + gpsd_report(session->context->debug, LOG_DATA, + "MDO 0x04: time=%.2f mask={TIME|RAW}\n", session->newdata.time); return TIME_SET | PPSTIME_IS | RAW_IS; case 0x20: /* LogConfig Info, could be used as a probe for EverMore GPS */ - gpsd_report(LOG_IO, "LogConfig EverMore packet, length %zd\n", datalen); + gpsd_report(session->context->debug, LOG_IO, + "LogConfig EverMore packet, length %zd\n", datalen); return ONLINE_SET; case 0x22: /* LogData */ - gpsd_report(LOG_IO, "LogData EverMore packet, length %zd\n", datalen); + gpsd_report(session->context->debug, LOG_IO, + "LogData EverMore packet, length %zd\n", datalen); return ONLINE_SET; case 0x38: /* ACK */ - gpsd_report(LOG_PROG, "EverMore command %02X ACK\n", getub(buf2, 3)); + gpsd_report(session->context->debug, LOG_PROG, + "EverMore command %02X ACK\n", getub(buf2, 3)); return ONLINE_SET; default: - gpsd_report(LOG_WARN, + gpsd_report(session->context->debug, LOG_WARN, "unknown EverMore packet EID 0x%02x, length %zd\n", buf2[0], datalen); return 0; @@ -456,7 +461,8 @@ static bool evermore_protocol(struct gps_device_t *session, int protocol) (char)0x00, /* 3: reserved */ }; /*@ -charint */ - gpsd_report(LOG_PROG, "evermore_protocol(%d)\n", protocol); + gpsd_report(session->context->debug, LOG_PROG, + "evermore_protocol(%d)\n", protocol); /*@i1@*/ tmp8 = (protocol != 0) ? 1 : 0; /* NMEA : binary */ evrm_protocol_config[1] = tmp8; @@ -486,7 +492,8 @@ static bool evermore_nmea_config(struct gps_device_t *session, int mode) 0, 0, 0, 0, 0, 0, /* 10-15: reserved */ }; /*@ -charint */ - gpsd_report(LOG_PROG, "evermore_nmea_config(%d)\n", mode); + gpsd_report(session->context->debug, LOG_PROG, + "evermore_nmea_config(%d)\n", mode); /*@i1@*/ tmp8 = (mode == 1) ? 5 : 1; /* NMEA GPGSV, gpsd */ evrm_nmeaout_config[6] = tmp8; /* GPGSV, 1s or 5s */ @@ -499,7 +506,7 @@ static bool evermore_nmea_config(struct gps_device_t *session, int mode) static void evermore_mode(struct gps_device_t *session, int mode) { - gpsd_report(LOG_PROG, "evermore_mode(%d), %d\n", mode, + gpsd_report(session->context->debug, LOG_PROG, "evermore_mode(%d), %d\n", mode, session->back_to_nmea ? 1 : 0); if (mode == MODE_NMEA) { /* NMEA */ @@ -544,7 +551,8 @@ static bool evermore_speed(struct gps_device_t *session, speed_t speed, char parity, int stopbits) { /*@ -type @*/ - gpsd_report(LOG_PROG, "evermore_speed(%u%c%d)\n", speed, parity, + gpsd_report(session->context->debug, LOG_PROG, + "evermore_speed(%u%c%d)\n", speed, parity, stopbits); /* parity and stopbit switching aren't available on this chip */ if (parity != session->gpsdata.dev.parity @@ -586,7 +594,7 @@ static bool evermore_rate_switcher(struct gps_device_t *session, double rate) { /*@ +charint @*/ if (rate < 1 || rate > 10) { - gpsd_report(LOG_ERROR, "valid rate range is 1-10.\n"); + gpsd_report(session->context->debug, LOG_ERROR, "valid rate range is 1-10.\n"); return false; } else { unsigned char evrm_rate_config[] = { diff --git a/driver_garmin.c b/driver_garmin.c index 7e4f82f3..a340072d 100644 --- a/driver_garmin.c +++ b/driver_garmin.c @@ -304,17 +304,17 @@ gps_mask_t PrintSERPacket(struct gps_device_t *session, unsigned char pkt_id, cpo_pvt_data *pvt = NULL; cpo_rcv_data *rmd = NULL; - gpsd_report(LOG_IO, "Garmin: PrintSERPacket(, %#02x, %#02x, )\n", pkt_id, - pkt_len); + gpsd_report(session->context->debug, LOG_IO, + "Garmin: PrintSERPacket(, %#02x, %#02x, )\n", pkt_id, pkt_len); session->cycle_end_reliable = true; switch (pkt_id) { case ACK: - gpsd_report(LOG_PROG, "Garmin: ACK\n"); + gpsd_report(session->context->debug, LOG_PROG, "Garmin: ACK\n"); break; case NAK: - gpsd_report(LOG_PROG, "Garmin: NAK\n"); + gpsd_report(session->context->debug, LOG_PROG, "Garmin: NAK\n"); break; case GARMIN_PKTID_L001_COMMAND_DATA: prod_id = get_uint16((uint8_t *) buf); @@ -339,29 +339,36 @@ gps_mask_t PrintSERPacket(struct gps_device_t *session, unsigned char pkt_id, break; } /*@ +branchstate @*/ - gpsd_report(LOG_PROG, "Garmin: Appl, Command Data: %s\n", msg); + gpsd_report(session->context->debug, LOG_PROG, + "Garmin: Appl, Command Data: %s\n", msg); break; case GARMIN_PKTID_PRODUCT_RQST: - gpsd_report(LOG_PROG, "Garmin: Appl, Product Data req\n"); + gpsd_report(session->context->debug, LOG_PROG, + "Garmin: Appl, Product Data req\n"); break; case GARMIN_PKTID_PRODUCT_DATA: prod_id = get_uint16((uint8_t *) buf); ver = get_uint16((uint8_t *) & buf[2]); maj_ver = (int)(ver / 100); min_ver = (int)(ver - (maj_ver * 100)); - gpsd_report(LOG_PROG, "Garmin: Appl, Product Data, sz: %d\n", + gpsd_report(session->context->debug, LOG_PROG, + "Garmin: Appl, Product Data, sz: %d\n", pkt_len); (void)snprintf(session->subtype, sizeof(session->subtype), "%d: %d.%02d", (int)prod_id, maj_ver, min_ver); - gpsd_report(LOG_INF, "Garmin: Product ID: %d, SoftVer: %d.%02d\n", + gpsd_report(session->context->debug, LOG_INF, + "Garmin: Product ID: %d, SoftVer: %d.%02d\n", prod_id, maj_ver, min_ver); - gpsd_report(LOG_INF, "Garmin: Product Desc: %s\n", &buf[4]); + gpsd_report(session->context->debug, LOG_INF, + "Garmin: Product Desc: %s\n", &buf[4]); mask |= DEVICEID_SET; - gpsd_report(LOG_DATA, "Garmin: PRODUCT_DATA: subtype=%s\n", + gpsd_report(session->context->debug, LOG_DATA, + "Garmin: PRODUCT_DATA: subtype=%s\n", session->subtype); break; case GARMIN_PKTID_PVT_DATA: - gpsd_report(LOG_PROG, "Garmin: Appl, PVT Data Sz: %d\n", pkt_len); + gpsd_report(session->context->debug, LOG_PROG, + "Garmin: Appl, PVT Data Sz: %d\n", pkt_len); pvt = (cpo_pvt_data *) buf; @@ -375,26 +382,29 @@ gps_mask_t PrintSERPacket(struct gps_device_t *session, unsigned char pkt_id, time_l += (time_t) round(pvt->gps_tow); session->context->gps_tow = pvt->gps_tow; session->newdata.time = (timestamp_t)time_l; - gpsd_report(LOG_PROG, "Garmin: time_l: %ld\n", (long int)time_l); + gpsd_report(session->context->debug, LOG_PROG, + "Garmin: time_l: %ld\n", (long int)time_l); session->newdata.latitude = radtodeg(pvt->lat); /* sanity check the lat */ if (90.0 < session->newdata.latitude) { session->newdata.latitude = 90.0; - gpsd_report(LOG_INF, "Garmin: ERROR: Latitude overrange\n"); + gpsd_report(session->context->debug, LOG_INF, + "Garmin: ERROR: Latitude overrange\n"); } else if (-90.0 > session->newdata.latitude) { session->newdata.latitude = -90.0; - gpsd_report(LOG_INF, + gpsd_report(session->context->debug, LOG_INF, "Garmin: ERROR: Latitude negative overrange\n"); } session->newdata.longitude = radtodeg(pvt->lon); /* sanity check the lon */ if (180.0 < session->newdata.longitude) { session->newdata.longitude = 180.0; - gpsd_report(LOG_INF, "Garmin: ERROR: Longitude overrange\n"); + gpsd_report(session->context->debug, LOG_INF, + "Garmin: ERROR: Longitude overrange\n"); } else if (-180.0 > session->newdata.longitude) { session->newdata.longitude = -180.0; - gpsd_report(LOG_INF, + gpsd_report(session->context->debug, LOG_INF, "Garmin: ERROR: Longitude negative overrange\n"); } // altitude over WGS84 converted to MSL @@ -456,18 +466,20 @@ gps_mask_t PrintSERPacket(struct gps_device_t *session, unsigned char pkt_id, break; } - gpsd_report(LOG_PROG, "Garmin: Appl, mode %d, status %d\n", + gpsd_report(session->context->debug, LOG_PROG, + "Garmin: Appl, mode %d, status %d\n", session->newdata.mode, session->gpsdata.status); - gpsd_report(LOG_INF, "Garmin: UTC Time: %lf\n", + gpsd_report(session->context->debug, LOG_INF, + "Garmin: UTC Time: %lf\n", session->newdata.time); - gpsd_report(LOG_INF, + gpsd_report(session->context->debug, LOG_INF, "Garmin: Geoid Separation (MSL-WGS84): from garmin %lf, calculated %lf\n", -pvt->msl_hght, wgs84_separation(session->newdata.latitude, session->newdata.longitude)); - gpsd_report(LOG_INF, + gpsd_report(session->context->debug, LOG_INF, "Garmin: Alt: %.3f, Epe: %.3f, Eph: %.3f, Epv: %.3f, Fix: %d, Gps_tow: %f, Lat: %.3f, Lon: %.3f, LonVel: %.3f, LatVel: %.3f, AltVel: %.3f, MslHgt: %.3f, Leap: %d, GarminDays: %d\n", pvt->alt, pvt->epe, pvt->eph, pvt->epv, GPSD_LE16TOH(pvt->fix), pvt->gps_tow, session->newdata.latitude, @@ -489,7 +501,7 @@ gps_mask_t PrintSERPacket(struct gps_device_t *session, unsigned char pkt_id, if (session->fixcnt > 3) mask |= PPSTIME_IS; } - gpsd_report(LOG_DATA, + gpsd_report(session->context->debug, LOG_DATA, "Garmin: PVT_DATA: time=%.2f, lat=%.2f lon=%.2f " "speed=%.2f track=%.2f climb=%.2f " "epx=%.2f epy=%.2f epv=%.2f " @@ -509,11 +521,13 @@ gps_mask_t PrintSERPacket(struct gps_device_t *session, unsigned char pkt_id, case GARMIN_PKTID_RMD_DATA: case GARMIN_PKTID_RMD41_DATA: rmd = (cpo_rcv_data *) buf; - gpsd_report(LOG_IO, "Garmin: PVT RMD Data Sz: %d\n", pkt_len); - gpsd_report(LOG_PROG, "Garmin: PVT RMD rcvr_tow: %f, rcvr_wn: %d\n", + gpsd_report(session->context->debug, LOG_IO, + "Garmin: PVT RMD Data Sz: %d\n", pkt_len); + gpsd_report(session->context->debug, LOG_PROG, + "Garmin: PVT RMD rcvr_tow: %f, rcvr_wn: %d\n", rmd->rcvr_tow, rmd->rcvr_wn); for (i = 0; i < GARMIN_CHANNELS; i++) { - gpsd_report(LOG_INF, + gpsd_report(session->context->debug, LOG_INF, "Garmin: PVT RMD Sat: %3u, cycles: %9u, pr: %16.6f, " "phase: %7.3f, slp_dtct: %3s, snr: %3u, Valid: %3s\n", (int)rmd->sv[i].svid + 1, @@ -527,7 +541,8 @@ gps_mask_t PrintSERPacket(struct gps_device_t *session, unsigned char pkt_id, break; case GARMIN_PKTID_SAT_DATA: - gpsd_report(LOG_PROG, "Garmin: SAT Data Sz: %d\n", pkt_len); + gpsd_report(session->context->debug, LOG_PROG, + "Garmin: SAT Data Sz: %d\n", pkt_len); sats = (cpo_sat_data *) buf; session->gpsdata.satellites_visible = 0; @@ -535,7 +550,7 @@ gps_mask_t PrintSERPacket(struct gps_device_t *session, unsigned char pkt_id, memset(session->gpsdata.used, 0, sizeof(session->gpsdata.used)); gpsd_zero_satellites(&session->gpsdata); for (i = 0, j = 0; i < GARMIN_CHANNELS; i++, sats++) { - gpsd_report(LOG_INF, + gpsd_report(session->context->debug, LOG_INF, "Garmin: Sat %3d, snr: %5u, elev: %2d, Azmth: %3d, Stat: %x\n", sats->svid, GPSD_LE16TOH(sats->snr), sats->elev, GPSD_LE16TOH(sats->azmth), @@ -576,7 +591,7 @@ gps_mask_t PrintSERPacket(struct gps_device_t *session, unsigned char pkt_id, mask |= SATELLITE_SET; if (session->gpsdata.satellites_used > 0) mask |= USED_IS; - gpsd_report(LOG_DATA, + gpsd_report(session->context->debug, LOG_DATA, "Garmin: SAT_DATA: visible=%d used=%d\n", session->gpsdata.satellites_visible, session->gpsdata.satellites_used); @@ -584,20 +599,23 @@ gps_mask_t PrintSERPacket(struct gps_device_t *session, unsigned char pkt_id, case GARMIN_PKTID_PROTOCOL_ARRAY: // this packet is never requested, it just comes, in some case // after a GARMIN_PKTID_PRODUCT_RQST - gpsd_report(LOG_INF, "Garmin: Appl, Product Capability, sz: %d\n", + gpsd_report(session->context->debug, LOG_INF, + "Garmin: Appl, Product Capability, sz: %d\n", pkt_len); for (i = 0; i < pkt_len; i += 3) { - gpsd_report(LOG_INF, "Garmin: %c%03d\n", buf[i], - get_uint16((uint8_t *) & buf[i + 1])); + gpsd_report(session->context->debug, LOG_INF, + "Garmin: %c%03d\n", + buf[i], get_uint16((uint8_t *) & buf[i + 1])); } break; default: - gpsd_report(LOG_WARN, + gpsd_report(session->context->debug, LOG_WARN, "Garmin: Unknown packet id: %#02x, Sz: %#02x\n", pkt_id, pkt_len); break; } - gpsd_report(LOG_IO, "Garmin: PrintSERPacket(, %#02x, %#02x, )\n", + gpsd_report(session->context->debug, LOG_IO, + "Garmin: PrintSERPacket(, %#02x, %#02x, )\n", pkt_id, pkt_len); return mask; } @@ -619,17 +637,19 @@ static gps_mask_t PrintUSBPacket(struct gps_device_t *session, Packet_t * pkt) // uint8_t *buffer = (uint8_t *) pkt; - gpsd_report(LOG_PROG, "Garmin: PrintUSBPacket()\n"); + gpsd_report(session->context->debug, LOG_PROG, "Garmin: PrintUSBPacket()\n"); // gem if (DLE == pkt->mPacketType) { - gpsd_report(LOG_PROG, "Garmin: really a SER packet!\n"); + gpsd_report(session->context->debug, LOG_PROG, + "Garmin: really a SER packet!\n"); return PrintSERPacket(session, (unsigned char)buffer[1], (int)buffer[2], (unsigned char *)(buffer + 3)); } // gem if (4096 < mDataSize) { - gpsd_report(LOG_WARN, "Garmin: bogus packet, size too large=%d\n", + gpsd_report(session->context->debug, LOG_WARN, + "Garmin: bogus packet, size too large=%d\n", mDataSize); return 0; } @@ -641,16 +661,17 @@ static gps_mask_t PrintUSBPacket(struct gps_device_t *session, Packet_t * pkt) /* Garmin USB layer specific */ switch (pkt->mPacketId) { case GARMIN_PKTID_TRANSPORT_START_SESSION_REQ: - gpsd_report(LOG_PROG, "Garmin: Transport, Start Session req\n"); + gpsd_report(session->context->debug, LOG_PROG, + "Garmin: Transport, Start Session req\n"); break; case GARMIN_PKTID_TRANSPORT_START_SESSION_RESP: mode = get_int32(&pkt->mData.uchars[0]); - gpsd_report(LOG_PROG, + gpsd_report(session->context->debug, LOG_PROG, "Garmin: Transport, Start Session resp, unit: 0x%x\n", mode); break; default: - gpsd_report(LOG_PROG, + gpsd_report(session->context->debug, LOG_PROG, "Garmin: Transport, Packet: Type %d %d %d, ID: %d, Sz: %d\n", pkt->mPacketType, pkt->mReserved1, pkt->mReserved2, pkt->mPacketId, mDataSize); @@ -670,10 +691,12 @@ static gps_mask_t PrintUSBPacket(struct gps_device_t *session, Packet_t * pkt) switch (pkt->mPacketId) { case PRIV_PKTID_SET_MODE: prod_id = get_uint16(&pkt->mData.uchars[0]); - gpsd_report(LOG_PROG, "Garmin: Private, Set Mode: %d\n", prod_id); + gpsd_report(session->context->debug, LOG_PROG, + "Garmin: Private, Set Mode: %d\n", prod_id); break; case PRIV_PKTID_INFO_REQ: - gpsd_report(LOG_PROG, "Garmin: Private, ID: Info Req\n"); + gpsd_report(session->context->debug, LOG_PROG, + "Garmin: Private, ID: Info Req\n"); break; case PRIV_PKTID_INFO_RESP: veri = get_int32(pkt->mData.uchars); @@ -681,19 +704,21 @@ static gps_mask_t PrintUSBPacket(struct gps_device_t *session, Packet_t * pkt) min_ver = (int)(veri & 0xffff); mode = get_int32(&pkt->mData.uchars[4]); serial = get_int32(&pkt->mData.uchars[8]); - gpsd_report(LOG_PROG, "Garmin: Private, ID: Info Resp\n"); - gpsd_report(LOG_INF, + gpsd_report(session->context->debug, LOG_PROG, + "Garmin: Private, ID: Info Resp\n"); + gpsd_report(session->context->debug, LOG_INF, "Garmin: USB Driver found, Version %d.%d, Mode: %d, GPS Serial# %u\n", maj_ver, min_ver, mode, serial); break; default: - gpsd_report(LOG_PROG, "Garmin: Private, Packet: ID: %d, Sz: %d\n", + gpsd_report(session->context->debug, LOG_PROG, + "Garmin: Private, Packet: ID: %d, Sz: %d\n", pkt->mPacketId, mDataSize); break; } break; default: - gpsd_report(LOG_PROG, + gpsd_report(session->context->debug, LOG_PROG, "Garmin: Packet: Type %d %d %d, ID: %d, Sz: %d\n", pkt->mPacketType, pkt->mReserved1, pkt->mReserved2, pkt->mPacketId, mDataSize); @@ -729,7 +754,8 @@ static void Build_Send_USB_Packet(struct gps_device_t *session, theBytesReturned = gpsd_write(session, (const char *)thePacket, (size_t) theBytesToWrite); - gpsd_report(LOG_IO, "Garmin: SendPacket(), wrote %zd bytes\n", + gpsd_report(session->context->debug, LOG_IO, + "Garmin: SendPacket(), wrote %zd bytes\n", theBytesReturned); // Garmin says: @@ -801,7 +827,8 @@ static void Build_Send_SER_Packet(struct gps_device_t *session, theBytesReturned = gpsd_write(session, (const char *)thePacket, (size_t) theBytesToWrite); - gpsd_report(LOG_IO, "Garmin: SendPacket(), wrote %zd bytes\n", + gpsd_report(session->context->debug, LOG_IO, + "Garmin: SendPacket(), wrote %zd bytes\n", theBytesReturned); } @@ -817,7 +844,8 @@ static void Build_Send_SER_Packet(struct gps_device_t *session, * libudev: http://www.kernel.org/pub/linux/utils/kernel/hotplug/libudev/ */ /*@-compdef -usedef -nullpass@*/ -static bool is_usb_device(const char *path UNUSED, int vendor, int product) +static bool is_usb_device(const char *path UNUSED, int vendor, int product, + const int debug) { // discover devices libusb_device **list; @@ -825,11 +853,13 @@ static bool is_usb_device(const char *path UNUSED, int vendor, int product) ssize_t i = 0; bool found = false; - gpsd_report(LOG_INF, "attempting USB device enumeration.\n"); + gpsd_report(debug, LOG_INF, + "attempting USB device enumeration.\n"); (void)libusb_init(NULL); if ((cnt = libusb_get_device_list(NULL, &list)) < 0) { - gpsd_report(LOG_ERROR, "USB device list call failed.\n"); + gpsd_report(debug, LOG_ERROR, + "USB device list call failed.\n"); libusb_exit(NULL); return false; } @@ -840,13 +870,14 @@ static bool is_usb_device(const char *path UNUSED, int vendor, int product) int r = libusb_get_device_descriptor(dev, &desc); if (r < 0) { - gpsd_report(LOG_ERROR, + gpsd_report(debug, LOG_ERROR, "USB descriptor fetch failed on device %zd.\n", i); continue; } /* we can extract device descriptor data */ - gpsd_report(LOG_INF, "%04x:%04x (bus %d, device %d)\n", + gpsd_report(debug, LOG_INF, + "%04x:%04x (bus %d, device %d)\n", desc.idVendor, desc.idProduct, libusb_get_bus_number(dev), libusb_get_device_address(dev)); @@ -858,7 +889,8 @@ static bool is_usb_device(const char *path UNUSED, int vendor, int product) } } - gpsd_report(LOG_SHOUT, "vendor/product match with %04x:%04x %sfound\n", + gpsd_report(debug, LOG_SHOUT, + "vendor/product match with %04x:%04x %sfound\n", vendor, product, found ? "" : "not "); libusb_free_device_list(list, 1); libusb_exit(NULL); @@ -893,7 +925,7 @@ static bool is_usb_device(const char *path UNUSED, int vendor, int product) * return 1 is device found * return 0 if not */ -static bool garmin_usb_detect(struct gps_device_t *session UNUSED) +static bool garmin_usb_detect(struct gps_device_t *session) { #if defined(__linux__) || defined(S_SPLINT_S) /* @@ -906,11 +938,12 @@ static bool garmin_usb_detect(struct gps_device_t *session UNUSED) return false; else { #ifdef HAVE_LIBUSB - if (!is_usb_device(session->gpsdata.dev.path, 0x091e, 0x0003)) + if (!is_usb_device(session->gpsdata.dev.path, 0x091e, 0x0003, + session->context->debug)) return false; if (!gpsd_set_raw(session)) { - gpsd_report(LOG_ERROR, + gpsd_report(session->context->debug, LOG_ERROR, "Garmin: garmin_usb_detect: error changing port attributes: %s\n", strerror(errno)); return false; @@ -918,7 +951,7 @@ static bool garmin_usb_detect(struct gps_device_t *session UNUSED) if (sizeof(session->driver.garmin.Buffer) < sizeof(Packet_t)) { /* dunno how this happens, but it does on some compilers */ - gpsd_report(LOG_ERROR, + gpsd_report(session->context->debug, LOG_ERROR, "Garmin: garmin_usb_detect: Compile error, garmin.Buffer too small.\n"); return false; } @@ -926,7 +959,8 @@ static bool garmin_usb_detect(struct gps_device_t *session UNUSED) // FIXME!!! needs to use libusb totally and move garmin_gps aside */ // set Mode 1, mode 0 is broken somewhere past 2.6.14 // but how? - gpsd_report(LOG_PROG, "Garmin: Set garmin_gps driver mode = 0\n"); + gpsd_report(session->context->debug, LOG_PROG, + "Garmin: Set garmin_gps driver mode = 0\n"); Build_Send_USB_Packet(session, GARMIN_LAYERID_PRIVATE, PRIV_PKTID_SET_MODE, 4, MODE_GARMIN_SERIAL); // expect no return packet !? @@ -951,12 +985,13 @@ static void garmin_event_hook(struct gps_device_t *session, event_t event) */ if (event == event_identified || event == event_reactivate) { // Tell the device to send product data - gpsd_report(LOG_PROG, "Garmin: Get Product Data\n"); + gpsd_report(session->context->debug, LOG_PROG, "Garmin: Get Product Data\n"); Build_Send_SER_Packet(session, GARMIN_LAYERID_APPL, GARMIN_PKTID_PRODUCT_RQST, 0, 0); // turn on PVT data 49 - gpsd_report(LOG_PROG, "Garmin: Set to send reports every 1 second\n"); + gpsd_report(session->context->debug, LOG_PROG, + "Garmin: Set to send reports every 1 second\n"); Build_Send_SER_Packet(session, GARMIN_LAYERID_APPL, GARMIN_PKTID_L001_COMMAND_DATA, 2, @@ -964,7 +999,8 @@ static void garmin_event_hook(struct gps_device_t *session, event_t event) #if USE_RMD // turn on RMD data 110 - gpsd_report(LOG_PROG, "Garmin: Set to send Raw sat data\n"); + gpsd_report(session->context->debug, LOG_PROG, + "Garmin: Set to send Raw sat data\n"); Build_Send_SER_Packet(session, GARMIN_LAYERID_APPL, GARMIN_PKTID_L001_COMMAND_DATA, 2, CMND_START_RM_DATA); @@ -972,7 +1008,7 @@ static void garmin_event_hook(struct gps_device_t *session, event_t event) } if (event == event_deactivate) /* FIX-ME: is any action needed, or is closing the port sufficient? */ - gpsd_report(LOG_PROG, "Garmin: garmin_close()\n"); + gpsd_report(session->context->debug, LOG_PROG, "Garmin: garmin_close()\n"); } #define Send_ACK() Build_Send_SER_Packet(session, 0, ACK, 0, 0) @@ -997,22 +1033,24 @@ gps_mask_t garmin_ser_parse(struct gps_device_t *session) if (session->packet.type == GARMIN_PACKET) session->gpsdata.dev.driver_mode = MODE_BINARY; - gpsd_report(LOG_RAW, "Garmin: garmin_ser_parse()\n"); + gpsd_report(session->context->debug, LOG_RAW, "Garmin: garmin_ser_parse()\n"); if (6 > len) { /* WTF? */ /* minimum packet; <DLE> [pkt id] [length=0] [chksum] <DLE> <STX> */ Send_NAK(); - gpsd_report(LOG_RAW + 1, "Garmin: serial too short: %zd\n", len); + gpsd_report(session->context->debug, LOG_RAW + 1, + "Garmin: serial too short: %zd\n", len); return 0; } /* debug */ for (i = 0; i < (int)len; i++) { - gpsd_report(LOG_RAW + 1, "Garmin: Char: %#02x\n", buf[i]); + gpsd_report(session->context->debug, LOG_RAW + 1, + "Garmin: Char: %#02x\n", buf[i]); } if ('\x10' != buf[0]) { Send_NAK(); - gpsd_report(LOG_RAW + 1, "Garmin: buf[0] not DLE\n"); + gpsd_report(session->context->debug, LOG_RAW + 1, "Garmin: buf[0] not DLE\n"); return 0; } n = 1; @@ -1021,7 +1059,7 @@ gps_mask_t garmin_ser_parse(struct gps_device_t *session) if ('\x10' == pkt_id) { if ('\x10' != buf[n++]) { Send_NAK(); - gpsd_report(LOG_RAW + 1, "Garmin: Bad pkt_id %#02x\n", pkt_id); + gpsd_report(session->context->debug, LOG_RAW + 1, "Garmin: Bad pkt_id %#02x\n", pkt_id); return 0; } } @@ -1030,7 +1068,8 @@ gps_mask_t garmin_ser_parse(struct gps_device_t *session) chksum += pkt_len; if ('\x10' == pkt_len) { if ('\x10' != buf[n++]) { - gpsd_report(LOG_RAW + 1, "Garmin: Bad pkt_len %#02x\n", pkt_len); + gpsd_report(session->context->debug, LOG_RAW + 1, + "Garmin: Bad pkt_len %#02x\n", pkt_len); Send_NAK(); return 0; } @@ -1043,7 +1082,8 @@ gps_mask_t garmin_ser_parse(struct gps_device_t *session) break; } if (len < n + i) { - gpsd_report(LOG_RAW + 1, "Garmin: Packet too short %zd < %zd\n", + gpsd_report(session->context->debug, LOG_RAW + 1, + "Garmin: Packet too short %zd < %zd\n", len, n + i); Send_NAK(); return 0; @@ -1053,7 +1093,8 @@ gps_mask_t garmin_ser_parse(struct gps_device_t *session) got_dle = 0; if ('\x10' != c) { Send_NAK(); - gpsd_report(LOG_RAW + 1, "Garmin: Bad DLE %#02x\n", c); + gpsd_report(session->context->debug, LOG_RAW + 1, + "Garmin: Bad DLE %#02x\n", c); return 0; } } else { @@ -1067,7 +1108,7 @@ gps_mask_t garmin_ser_parse(struct gps_device_t *session) /* get checksum */ if (len < n + i) { Send_NAK(); - gpsd_report(LOG_RAW + 1, + gpsd_report(session->context->debug, LOG_RAW + 1, "Garmin: No checksum, Packet too short %zd < %zd\n", len, n + i); return 0; @@ -1077,7 +1118,7 @@ gps_mask_t garmin_ser_parse(struct gps_device_t *session) /* get final DLE */ if (len < n + i) { Send_NAK(); - gpsd_report(LOG_RAW + 1, + gpsd_report(session->context->debug, LOG_RAW + 1, "Garmin: No final DLE, Packet too short %zd < %zd\n", len, n + i); return 0; @@ -1085,13 +1126,13 @@ gps_mask_t garmin_ser_parse(struct gps_device_t *session) c = buf[n + i++]; if ('\x10' != c) { Send_NAK(); - gpsd_report(LOG_RAW + 1, "Garmin: Final DLE not DLE\n"); + gpsd_report(session->context->debug, LOG_RAW + 1, "Garmin: Final DLE not DLE\n"); return 0; } /* get final ETX */ if (len < n + i) { Send_NAK(); - gpsd_report(LOG_RAW + 1, + gpsd_report(session->context->debug, LOG_RAW + 1, "Garmin: No final ETX, Packet too short %zd < %zd\n", len, n + i); return 0; @@ -1100,18 +1141,20 @@ gps_mask_t garmin_ser_parse(struct gps_device_t *session) c = buf[n + i]; if ('\x03' != c) { Send_NAK(); - gpsd_report(LOG_RAW + 1, "Garmin: Final ETX not ETX\n"); + gpsd_report(session->context->debug, LOG_RAW + 1, + "Garmin: Final ETX not ETX\n"); return 0; } /* debug */ /*@ -usedef -compdef @*/ for (i = 0; i < data_index; i++) { - gpsd_report(LOG_RAW + 1, "Garmin: Char: %#02x\n", data_buf[i]); + gpsd_report(session->context->debug, LOG_RAW + 1, + "Garmin: Char: %#02x\n", data_buf[i]); } - gpsd_report(LOG_IO, + gpsd_report(session->context->debug, LOG_IO, "Garmin: garmin_ser_parse() Type: %#02x, Len: %#02x, chksum: %#02x\n", pkt_id, pkt_len, chksum); mask = PrintSERPacket(session, pkt_id, pkt_len, data_buf); @@ -1121,7 +1164,7 @@ gps_mask_t garmin_ser_parse(struct gps_device_t *session) (void)usleep(300); Send_ACK(); /*@ +usedef +compdef @*/ - gpsd_report(LOG_IO, "Garmin: garmin_ser_parse( )\n"); + gpsd_report(session->context->debug, LOG_IO, "Garmin: garmin_ser_parse( )\n"); return mask; } @@ -1149,12 +1192,13 @@ static void garmin_switcher(struct gps_device_t *session, int mode) ssize_t status = gpsd_write(session, switcher, sizeof(switcher)); /*@ -charint @*/ if (status == (ssize_t)sizeof(switcher)) { - gpsd_report(LOG_IO, + gpsd_report(session->context->debug, LOG_IO, "Garmin: => GPS: turn off binary %02x %02x %02x... \n", switcher[0], switcher[1], switcher[2]); session->gpsdata.dev.driver_mode = MODE_NMEA; } else { - gpsd_report(LOG_ERROR, "Garmin: => GPS: FAILED\n"); + gpsd_report(session->context->debug, LOG_ERROR, + "Garmin: => GPS: FAILED\n"); } settle(); // wait 333mS, essential! @@ -1238,7 +1282,7 @@ static int GetPacket(struct gps_device_t *session) session->driver.garmin.BufferLen = 0; session->packet.outbuflen = 0; - gpsd_report(LOG_IO, "Garmin: GetPacket()\n"); + gpsd_report(session->context->debug, LOG_IO, "Garmin: GetPacket()\n"); for (cnt = 0; cnt < 10; cnt++) { size_t pkt_size; @@ -1259,17 +1303,18 @@ static int GetPacket(struct gps_device_t *session) if (0 > theBytesReturned) { // read error... // or EAGAIN, but O_NONBLOCK is never set - gpsd_report(LOG_ERROR, + gpsd_report(session->context->debug, LOG_ERROR, "Garmin: GetPacket() read error=%d, errno=%d\n", theBytesReturned, errno); continue; } - gpsd_report(LOG_RAW, "Garmin: got %d bytes\n", theBytesReturned); + gpsd_report(session->context->debug, LOG_RAW, + "Garmin: got %d bytes\n", theBytesReturned); session->driver.garmin.BufferLen += theBytesReturned; if (256 <= session->driver.garmin.BufferLen) { // really bad read error... - gpsd_report(LOG_ERROR, + gpsd_report(session->context->debug, LOG_ERROR, "Garmin: GetPacket() packet too long, %ld > 255 !\n", session->driver.garmin.BufferLen); session->driver.garmin.BufferLen = 0; @@ -1280,7 +1325,7 @@ static int GetPacket(struct gps_device_t *session) // have enough data to check packet size if (session->driver.garmin.BufferLen > pkt_size) { // wrong amount of data in buffer - gpsd_report(LOG_ERROR, + gpsd_report(session->context->debug, LOG_ERROR, "Garmin: GetPacket() packet size wrong! Packet: %ld, s/b %ld\n", session->driver.garmin.BufferLen, pkt_size); session->driver.garmin.BufferLen = 0; @@ -1302,15 +1347,16 @@ static int GetPacket(struct gps_device_t *session) } // dump the individual bytes, debug only // for ( x = 0; x < session->driver.garmin.BufferLen; x++ ) { - // gpsd_report(LOG_RAW+1, "Garmin: p[%d] = %x\n", x, session->driver.garmin.Buffer[x]); + // gpsd_report(session->context->debug, LOG_RAW+1, "Garmin: p[%d] = %x\n", x, session->driver.garmin.Buffer[x]); // } if (10 <= cnt) { - gpsd_report(LOG_ERROR, + gpsd_report(session->context->debug, LOG_ERROR, "Garmin: GetPacket() packet too long or too slow!\n"); return -1; } - gpsd_report(LOG_RAW, "Garmin: GotPacket() sz=%d \n", + gpsd_report(session->context->debug, LOG_RAW, + "Garmin: GotPacket() sz=%d \n", session->driver.garmin.BufferLen); session->packet.outbuflen = session->driver.garmin.BufferLen; return 0; @@ -1318,7 +1364,7 @@ static int GetPacket(struct gps_device_t *session) static gps_mask_t garmin_usb_parse(struct gps_device_t *session) { - gpsd_report(LOG_PROG, "Garmin: garmin_usb_parse()\n"); + gpsd_report(session->context->debug, LOG_PROG, "Garmin: garmin_usb_parse()\n"); return PrintUSBPacket(session, (Packet_t *) session->driver.garmin.Buffer); } diff --git a/driver_garmin_txt.c b/driver_garmin_txt.c index 855f4ee4..9e0801c4 100644 --- a/driver_garmin_txt.c +++ b/driver_garmin_txt.c @@ -129,17 +129,19 @@ invalid data. * * examples: - * gar_decode(cbuf, 9, "EW", 100000.0, &result); + * gar_decode(0, cbuf, 9, "EW", 100000.0, &result); * E01412345 -> +14.12345 - * gar_decode(cbuf, 9, "EW", 100000.0, &result); + * gar_decode(0, cbuf, 9, "EW", 100000.0, &result); * W01412345 -> -14.12345 - * gar_decode(cbuf, 3, "", 10.0, &result); + * gar_decode(0, cbuf, 3, "", 10.0, &result); * 123 -> +12.3 **************************************************************************/ -static int gar_decode(const char *data, const size_t length, const char *prefix, const double dividor, /*@out@*/ +static int gar_decode(const int debug, + const char *data, const size_t length, + const char *prefix, const double dividor, /*@out@*/ double *result) { char buf[10]; @@ -151,13 +153,13 @@ static int gar_decode(const char *data, const size_t length, const char *prefix, /* splint is buggy here, thinks buf can be a null pointer */ /*@ -mustdefine -nullderef -nullpass @*/ if (length >= sizeof(buf)) { - gpsd_report(LOG_ERROR, "internal buffer too small\n"); + gpsd_report(debug, LOG_ERROR, "internal buffer too small\n"); return -1; } bzero(buf, (int)sizeof(buf)); (void)strlcpy(buf, data, length); - gpsd_report(LOG_RAW + 2, "Decoded string: %s\n", buf); + gpsd_report(debug, LOG_RAW + 2, "Decoded string: %s\n", buf); if (strchr(buf, '_') != NULL) { /* value is not valid, ignore it */ @@ -184,13 +186,14 @@ static int gar_decode(const char *data, const size_t length, const char *prefix, break; } } - gpsd_report(LOG_WARN, "Unexpected char \"%c\" in data \"%s\"\n", + gpsd_report(debug, LOG_WARN, + "Unexpected char \"%c\" in data \"%s\"\n", buf[0], buf); return -1; } while (0); if (strspn(buf + offset, "0123456789") != length - offset) { - gpsd_report(LOG_WARN, "Invalid value %s\n", buf); + gpsd_report(debug, LOG_WARN, "Invalid value %s\n", buf); return -1; } /*@ +mustdefine +nullderef +nullpass @*/ @@ -210,7 +213,8 @@ static int gar_decode(const char *data, const size_t length, const char *prefix, * -1: data error * -2: data not valid **************************************************************************/ -static int gar_int_decode(const char *data, const size_t length, +static int gar_int_decode(const int debug, + const char *data, const size_t length, const unsigned int min, const unsigned int max, /*@out@*/ unsigned int *result) { @@ -219,13 +223,13 @@ static int gar_int_decode(const char *data, const size_t length, /*@ -mustdefine @*/ if (length >= sizeof(buf)) { - gpsd_report(LOG_ERROR, "internal buffer too small\n"); + gpsd_report(debug, LOG_ERROR, "internal buffer too small\n"); return -1; } bzero(buf, (int)sizeof(buf)); (void)strlcpy(buf, data, length); - gpsd_report(LOG_RAW + 2, "Decoded string: %s\n", buf); + gpsd_report(debug, LOG_RAW + 2, "Decoded string: %s\n", buf); if (strchr(buf, '_') != NULL) { /* value is not valid, ignore it */ @@ -234,7 +238,7 @@ static int gar_int_decode(const char *data, const size_t length, /*@ -nullpass @*//* splint bug */ if (strspn(buf, "0123456789") != length) { - gpsd_report(LOG_WARN, "Invalid value %s\n", buf); + gpsd_report(debug, LOG_WARN, "Invalid value %s\n", buf); return -1; } @@ -243,7 +247,8 @@ static int gar_int_decode(const char *data, const size_t length, *result = res; return 0; /* SUCCESS */ } else { - gpsd_report(LOG_WARN, "Value %u out of range <%u, %u>\n", res, min, + gpsd_report(debug, LOG_WARN, + "Value %u out of range <%u, %u>\n", res, min, max); return -1; } @@ -263,12 +268,14 @@ gps_mask_t garmintxt_parse(struct gps_device_t * session) gps_mask_t mask = 0; - gpsd_report(LOG_PROG, "Garmin Simple Text packet, len %zd: %s\n", + gpsd_report(session->context->debug, LOG_PROG, + "Garmin Simple Text packet, len %zd: %s\n", session->packet.outbuflen, (char*)session->packet.outbuffer); if (session->packet.outbuflen < 54) { /* trailing CR and LF can be ignored; ('@' + 54x 'DATA' + '\r\n') has length 57 */ - gpsd_report(LOG_WARN, "Message is too short, rejected.\n"); + gpsd_report(session->context->debug, LOG_WARN, + "Message is too short, rejected.\n"); return ONLINE_SET; } @@ -281,32 +288,38 @@ gps_mask_t garmintxt_parse(struct gps_device_t * session) do { unsigned int result; char *buf = (char *)session->packet.outbuffer + 1; - gpsd_report(LOG_PROG, "Timestamp: %.12s\n", buf); + gpsd_report(session->context->debug, LOG_PROG, "Timestamp: %.12s\n", buf); /* year */ - if (0 != gar_int_decode(buf + 0, 2, 0, 99, &result)) + if (0 != gar_int_decode(session->context->debug, + buf + 0, 2, 0, 99, &result)) break; session->driver.garmintxt.date.tm_year = (session->context->century + (int)result) - 1900; /* month */ - if (0 != gar_int_decode(buf + 2, 2, 1, 12, &result)) + if (0 != gar_int_decode(session->context->debug, + buf + 2, 2, 1, 12, &result)) break; session->driver.garmintxt.date.tm_mon = (int)result - 1; /* day */ - if (0 != gar_int_decode(buf + 4, 2, 1, 31, &result)) + if (0 != gar_int_decode(session->context->debug, + buf + 4, 2, 1, 31, &result)) break; session->driver.garmintxt.date.tm_mday = (int)result; /* hour */ - if (0 != gar_int_decode(buf + 6, 2, 0, 23, &result)) + if (0 != gar_int_decode(session->context->debug, + buf + 6, 2, 0, 23, &result)) break; session->driver.garmintxt.date.tm_hour = (int)result; /* mday update?? */ /* minute */ - if (0 != gar_int_decode(buf + 8, 2, 0, 59, &result)) + if (0 != gar_int_decode(session->context->debug, + buf + 8, 2, 0, 59, &result)) break; session->driver.garmintxt.date.tm_min = (int)result; /* second */ /* second value can be even 60, occasional leap second */ - if (0 != gar_int_decode(buf + 10, 2, 0, 60, &result)) + if (0 != gar_int_decode(session->context->debug, + buf + 10, 2, 0, 60, &result)) break; session->driver.garmintxt.date.tm_sec = (int)result; session->driver.garmintxt.subseconds = 0; @@ -331,12 +344,14 @@ gps_mask_t garmintxt_parse(struct gps_device_t * session) /* Latitude, [NS]ddmmmmm */ /* decode degrees of Latitude */ if (0 != - gar_decode((char *)session->packet.outbuffer + 13, 3, "NS", 1.0, - &lat)) + gar_decode(session->context->debug, + (char *)session->packet.outbuffer + 13, 3, "NS", 1.0, + &lat)) break; /* decode minutes of Latitude */ if (0 != - gar_int_decode((char *)session->packet.outbuffer + 16, 5, 0, + gar_int_decode(session->context->debug, + (char *)session->packet.outbuffer + 16, 5, 0, 99999, °frag)) break; lat += degfrag * 100.0 / 60.0 / 100000.0; @@ -345,12 +360,14 @@ gps_mask_t garmintxt_parse(struct gps_device_t * session) /* Longitude, [EW]dddmmmmm */ /* decode degrees of Longitude */ if (0 != - gar_decode((char *)session->packet.outbuffer + 21, 4, "EW", 1.0, + gar_decode(session->context->debug, + (char *)session->packet.outbuffer + 21, 4, "EW", 1.0, &lon)) break; /* decode minutes of Longitude */ if (0 != - gar_int_decode((char *)session->packet.outbuffer + 25, 5, 0, + gar_int_decode(session->context->debug, + (char *)session->packet.outbuffer + 25, 5, 0, 99999, °frag)) break; lon += degfrag * 100.0 / 60.0 / 100000.0; @@ -388,7 +405,8 @@ gps_mask_t garmintxt_parse(struct gps_device_t * session) do { double eph; if (0 != - gar_decode((char *)session->packet.outbuffer + 31, 3, "", 1.0, + gar_decode(session->context->debug, + (char *)session->packet.outbuffer + 31, 3, "", 1.0, &eph)) break; /* eph is a circular error, sqrt(epx**2 + epy**2) */ @@ -401,7 +419,8 @@ gps_mask_t garmintxt_parse(struct gps_device_t * session) do { double alt; if (0 != - gar_decode((char *)session->packet.outbuffer + 34, 6, "+-", 1.0, + gar_decode(session->context->debug, + (char *)session->packet.outbuffer + 34, 6, "+-", 1.0, &alt)) break; session->newdata.altitude = alt; @@ -412,11 +431,13 @@ gps_mask_t garmintxt_parse(struct gps_device_t * session) do { double ewvel, nsvel, speed, track; if (0 != - gar_decode((char *)session->packet.outbuffer + 40, 5, "EW", 10.0, + gar_decode(session->context->debug, + (char *)session->packet.outbuffer + 40, 5, "EW", 10.0, &ewvel)) break; if (0 != - gar_decode((char *)session->packet.outbuffer + 45, 5, "NS", 10.0, + gar_decode(session->context->debug, + (char *)session->packet.outbuffer + 45, 5, "NS", 10.0, &nsvel)) break; speed = sqrt(ewvel * ewvel + nsvel * nsvel); /* is this correct formula? Result is in mps */ @@ -433,14 +454,15 @@ gps_mask_t garmintxt_parse(struct gps_device_t * session) do { double climb; if (0 != - gar_decode((char *)session->packet.outbuffer + 50, 5, "UD", 100.0, + gar_decode(session->context->debug, + (char *)session->packet.outbuffer + 50, 5, "UD", 100.0, &climb)) break; session->newdata.climb = climb; /* climb in mps */ mask |= CLIMB_SET; } while (0); - gpsd_report(LOG_DATA, + gpsd_report(session->context->debug, LOG_DATA, "GTXT: time=%.2f, lat=%.2f lon=%.2f alt=%.2f speed=%.2f track=%.2f climb=%.2f exp=%.2f epy=%.2f mode=%d status=%d\n", session->newdata.time, session->newdata.latitude, session->newdata.longitude, session->newdata.altitude, diff --git a/driver_geostar.c b/driver_geostar.c index eb8ba612..35c6be1b 100644 --- a/driver_geostar.c +++ b/driver_geostar.c @@ -68,7 +68,7 @@ static int geostar_write(struct gps_device_t *session, session->msgbuflen = len * 4; - gpsd_report(LOG_IO, "Sent GeoStar packet id 0x%x\n", id); + gpsd_report(session->context->debug, LOG_IO, "Sent GeoStar packet id 0x%x\n", id); if (gpsd_write(session, session->msgbuf, session->msgbuflen) != (ssize_t) session->msgbuflen) return -1; @@ -106,7 +106,8 @@ static bool geostar_detect(struct gps_device_t *session) break; if (generic_get(session) >= 0) { if (session->packet.type == GEOSTAR_PACKET) { - gpsd_report(LOG_RAW, "geostar_detect found\n"); + gpsd_report(session->context->debug, LOG_RAW, + "geostar_detect found\n"); ret = true; break; } @@ -130,7 +131,8 @@ static gps_mask_t geostar_analyze(struct gps_device_t *session) char buf2[BUFSIZ]; if (session->packet.type != GEOSTAR_PACKET) { - gpsd_report(LOG_INF, "geostar_analyze packet type %d\n", + gpsd_report(session->context->debug, LOG_INF, + "geostar_analyze packet type %d\n", session->packet.type); return 0; } @@ -157,19 +159,20 @@ static gps_mask_t geostar_analyze(struct gps_device_t *session) (void)snprintf(session->gpsdata.tag, sizeof(session->gpsdata.tag), "ID%02x", id); - gpsd_report(LOG_IO, "GeoStar packet id 0x%02x length %d: %s\n", id, len, buf2); + gpsd_report(session->context->debug, LOG_IO, + "GeoStar packet id 0x%02x length %d: %s\n", id, len, buf2); session->cycle_end_reliable = true; switch (id) { case 0x10: - gpsd_report(LOG_INF, "Raw measurements\n"); + gpsd_report(session->context->debug, LOG_INF, "Raw measurements\n"); break; case 0x11: - gpsd_report(LOG_INF, "GPS sub-frame data\n"); + gpsd_report(session->context->debug, LOG_INF, "GPS sub-frame data\n"); break; case 0x12: - gpsd_report(LOG_INF, "GLONASS sub-frame data\n"); + gpsd_report(session->context->debug, LOG_INF, "GLONASS sub-frame data\n"); break; case 0x13: d1 = getled64(buf, OFFSET(1)); @@ -177,7 +180,8 @@ static gps_mask_t geostar_analyze(struct gps_device_t *session) d3 = getled64(buf, OFFSET(5)); d4 = getled64(buf, OFFSET(29)); /* GPS time */ d5 = getled64(buf, OFFSET(31)); /* GLONASS time */ - gpsd_report(LOG_INF, "ECEF coordinates %g %g %g %f %f\n", d1, d2, d3, d4, d5); + gpsd_report(session->context->debug, LOG_INF, + "ECEF coordinates %g %g %g %f %f\n", d1, d2, d3, d4, d5); break; case 0x20: d1 = getled64(buf, OFFSET(1)); /* time */ @@ -209,26 +213,30 @@ static gps_mask_t geostar_analyze(struct gps_device_t *session) } mask |= TIME_SET | PPSTIME_IS | LATLON_SET | ALTITUDE_SET | SPEED_SET | TRACK_SET | DOP_SET | USED_IS | REPORT_IS; - gpsd_report(LOG_INF, "Geographic coordinates %f %g %g %g %g %g\n", - d1, - session->newdata.latitude, - session->newdata.longitude, - session->newdata.altitude, - session->newdata.speed, - session->newdata.track); - gpsd_report(LOG_INF, "Dilution of precision %g %g %g %g %g\n", - session->gpsdata.dop.gdop, - session->gpsdata.dop.pdop, - session->gpsdata.dop.tdop, - session->gpsdata.dop.hdop, - session->gpsdata.dop.vdop); + gpsd_report(session->context->debug, LOG_INF, + "Geographic coordinates %f %g %g %g %g %g\n", + d1, + session->newdata.latitude, + session->newdata.longitude, + session->newdata.altitude, + session->newdata.speed, + session->newdata.track); + gpsd_report(session->context->debug, LOG_INF, + "Dilution of precision %g %g %g %g %g\n", + session->gpsdata.dop.gdop, + session->gpsdata.dop.pdop, + session->gpsdata.dop.tdop, + session->gpsdata.dop.hdop, + session->gpsdata.dop.vdop); break; case 0x21: ul1 = getleu32(buf, OFFSET(1)); ul2 = getleu32(buf, OFFSET(2)); uw1 = getleu16(buf, OFFSET(3)); uw2 = getleu16(buf, OFFSET(3) + 2); - gpsd_report(LOG_INF, "Current receiver telemetry %x %d %d %d\n", ul1, ul2, uw1, uw2); + gpsd_report(session->context->debug, LOG_INF, + "Current receiver telemetry %x %d %d %d\n", + ul1, ul2, uw1, uw2); if(ul1 & (1<<3)) { session->newdata.mode = MODE_2D; } @@ -247,7 +255,7 @@ static gps_mask_t geostar_analyze(struct gps_device_t *session) break; case 0x22: ul1 = getleu32(buf, OFFSET(1)); - gpsd_report(LOG_INF, "SVs in view %d\n", ul1); + gpsd_report(session->context->debug, LOG_INF, "SVs in view %d\n", ul1); session->gpsdata.satellites_visible = (int)ul1; if(ul1 > GEOSTAR_CHANNELS) ul1 = GEOSTAR_CHANNELS; for(i = 0, j = 0; (uint32_t)i < ul1; i++) { @@ -255,7 +263,7 @@ static gps_mask_t geostar_analyze(struct gps_device_t *session) s1 = getles16(buf, OFFSET(3) + i * 3 * 4); s2 = getles16(buf, OFFSET(3) + 2 + i * 3 * 4); s3 = getles16(buf, OFFSET(4) + 2 + i * 3 * 4); - gpsd_report(LOG_INF, "ID %d Az %g El %g SNR %g\n", + gpsd_report(session->context->debug, LOG_INF, "ID %d Az %g El %g SNR %g\n", decode_channel_id(ul2), s1*0.001*RAD_2_DEG, s2*0.001*RAD_2_DEG, s3*0.1); session->gpsdata.PRN[i] = decode_channel_id(ul2); session->gpsdata.azimuth[i] = (int)round((double)s1*0.001 * RAD_2_DEG); @@ -272,46 +280,58 @@ static gps_mask_t geostar_analyze(struct gps_device_t *session) ul1 = getleu32(buf, OFFSET(1)); ul2 = getleu32(buf, OFFSET(2)); ul3 = getleu32(buf, OFFSET(3)); - gpsd_report(LOG_INF, "Receiver power-up message %d %d %d\n", ul1, ul2, ul3); + gpsd_report(session->context->debug, LOG_INF, + "Receiver power-up message %d %d %d\n", ul1, ul2, ul3); break; case 0x3f: ul1 = getleu32(buf, OFFSET(1)); ul2 = getleu32(buf, OFFSET(2)); - gpsd_report(LOG_WARN, "Negative acknowledge %x %d\n", ul1, ul2); + gpsd_report(session->context->debug, LOG_WARN, + "Negative acknowledge %x %d\n", ul1, ul2); break; case 0x40: - gpsd_report(LOG_INF, "Response to Set initial parameters\n"); + gpsd_report(session->context->debug, LOG_INF, + "Response to Set initial parameters\n"); break; case 0x41: - gpsd_report(LOG_INF, "Response to Set serial ports parameters\n"); + gpsd_report(session->context->debug, LOG_INF, + "Response to Set serial ports parameters\n"); break; case 0x42: ul1 = getleu32(buf, OFFSET(1)); ul2 = getleu32(buf, OFFSET(2)); ul3 = getleu32(buf, OFFSET(3)); - gpsd_report(LOG_INF, "Response to Set receiver operation mode %d %d %d\n", + gpsd_report(session->context->debug, LOG_INF, + "Response to Set receiver operation mode %d %d %d\n", ul1, ul2, ul3); break; case 0x43: - gpsd_report(LOG_INF, "Response to Set navigation task solution parameters\n"); + gpsd_report(session->context->debug, LOG_INF, + "Response to Set navigation task solution parameters\n"); break; case 0x44: - gpsd_report(LOG_INF, "Response to Set output data rate\n"); + gpsd_report(session->context->debug, LOG_INF, + "Response to Set output data rate\n"); break; case 0x46: - gpsd_report(LOG_INF, "Response to Assign data protocol to communication port\n"); + gpsd_report(session->context->debug, LOG_INF, + "Response to Assign data protocol to communication port\n"); break; case 0x48: - gpsd_report(LOG_INF, "Response to Set GPS almanac\n"); + gpsd_report(session->context->debug, LOG_INF, + "Response to Set GPS almanac\n"); break; case 0x49: - gpsd_report(LOG_INF, "Response to Set GLONASS almanac\n"); + gpsd_report(session->context->debug, LOG_INF, + "Response to Set GLONASS almanac\n"); break; case 0x4a: - gpsd_report(LOG_INF, "Response to Set GPS ephemeris\n"); + gpsd_report(session->context->debug, LOG_INF, + "Response to Set GPS ephemeris\n"); break; - case 0x4b: - gpsd_report(LOG_INF, "Response to Set GLONASS ephemeris\n"); + case 0x4b: + gpsd_report(session->context->debug, LOG_INF, + "Response to Set GLONASS ephemeris\n"); break; case 0x4c: ul1 = getleu32(buf, OFFSET(1)); @@ -319,60 +339,75 @@ static gps_mask_t geostar_analyze(struct gps_device_t *session) ul3 = getleu32(buf, OFFSET(3)); ul4 = getleu32(buf, OFFSET(4)); ul5 = getleu32(buf, OFFSET(5)); - gpsd_report(LOG_INF, "Response to Set PPS parameters %d %d %d %d %d\n", + gpsd_report(session->context->debug, LOG_INF, + "Response to Set PPS parameters %d %d %d %d %d\n", ul1, ul2, ul3, ul4, ul5); break; case 0x4d: - gpsd_report(LOG_INF, "Response to Enable/disable SV in position fix\n"); + gpsd_report(session->context->debug, LOG_INF, + "Response to Enable/disable SV in position fix\n"); break; case 0x4e: - gpsd_report(LOG_INF, "Response to Enable/disable NMEA messages\n"); + gpsd_report(session->context->debug, LOG_INF, + "Response to Enable/disable NMEA messages\n"); break; case 0x4f: ul1 = getleu32(buf, OFFSET(1)); ul2 = getleu32(buf, OFFSET(2)); - gpsd_report(LOG_INF, "Response to Enable/disable binary messages %x %x\n", + gpsd_report(session->context->debug, LOG_INF, + "Response to Enable/disable binary messages %x %x\n", ul1, ul2); break; case 0x80: - gpsd_report(LOG_INF, "Response to Query initial parameters\n"); + gpsd_report(session->context->debug, LOG_INF, + "Response to Query initial parameters\n"); break; case 0x81: - gpsd_report(LOG_INF, "Response to Query serial ports parameters\n"); + gpsd_report(session->context->debug, LOG_INF, + "Response to Query serial ports parameters\n"); break; case 0x82: ul1 = getleu32(buf, OFFSET(1)); ul2 = getleu32(buf, OFFSET(2)); ul3 = getleu32(buf, OFFSET(3)); - gpsd_report(LOG_INF, "Response to Query receiver operation mode %d %d %d\n", + gpsd_report(session->context->debug, LOG_INF, + "Response to Query receiver operation mode %d %d %d\n", ul1, ul2, ul3); break; case 0x83: - gpsd_report(LOG_INF, "Response to Query navigation task solution parameters\n"); + gpsd_report(session->context->debug, LOG_INF, + "Response to Query navigation task solution parameters\n"); break; case 0x84: - gpsd_report(LOG_INF, "Response to Query output data rate\n"); + gpsd_report(session->context->debug, LOG_INF, + "Response to Query output data rate\n"); break; case 0x86: session->driver.geostar.physical_port = (unsigned int)getleu32(buf, OFFSET(1)); - gpsd_report(LOG_INF, "Response to Query data protocol assignment to communication port\n"); - gpsd_report(LOG_INF, "Connected to physical port %d\n", + gpsd_report(session->context->debug, LOG_INF, + "Response to Query data protocol assignment to communication port\n"); + gpsd_report(session->context->debug, LOG_INF, + "Connected to physical port %d\n", session->driver.geostar.physical_port); break; case 0x88: - gpsd_report(LOG_INF, "Response to Query GPS almanac\n"); + gpsd_report(session->context->debug, LOG_INF, + "Response to Query GPS almanac\n"); break; case 0x89: - gpsd_report(LOG_INF, "Response to Query GLONASS almanac\n"); + gpsd_report(session->context->debug, LOG_INF, + "Response to Query GLONASS almanac\n"); break; case 0x8a: - gpsd_report(LOG_INF, "Response to Query GPS ephemerides\n"); + gpsd_report(session->context->debug, LOG_INF, + "Response to Query GPS ephemerides\n"); break; case 0x8b: d1 = getled64(buf, OFFSET(23)); d2 = getled64(buf, OFFSET(25)); d3 = getled64(buf, OFFSET(27)); - gpsd_report(LOG_INF, "Response to Query GLONASS ephemerides %g %g %g\n", + gpsd_report(session->context->debug, LOG_INF, + "Response to Query GLONASS ephemerides %g %g %g\n", d1, d2, d3); break; case 0x8c: @@ -381,23 +416,28 @@ static gps_mask_t geostar_analyze(struct gps_device_t *session) ul3 = getleu32(buf, OFFSET(3)); ul4 = getleu32(buf, OFFSET(4)); ul5 = getleu32(buf, OFFSET(5)); - gpsd_report(LOG_INF, "Response to Query PPS parameters %d %d %d %d %d\n", + gpsd_report(session->context->debug, LOG_INF, + "Response to Query PPS parameters %d %d %d %d %d\n", ul1, ul2, ul3, ul4, ul5); break; case 0x8d: - gpsd_report(LOG_INF, "Response to Query enable/disable status of the SV in position fix\n"); + gpsd_report(session->context->debug, LOG_INF, + "Response to Query enable/disable status of the SV in position fix\n"); break; case 0x8e: - gpsd_report(LOG_INF, "Response to Query enable NMEA messages\n"); + gpsd_report(session->context->debug, LOG_INF, + "Response to Query enable NMEA messages\n"); break; case 0x8f: ul1 = getleu32(buf, OFFSET(1)); ul2 = getleu32(buf, OFFSET(2)); - gpsd_report(LOG_INF, "Response to Query enable binary messages %x %x\n", + gpsd_report(session->context->debug, LOG_INF, + "Response to Query enable binary messages %x %x\n", ul1, ul2); break; case 0xc0: - gpsd_report(LOG_INF, "Response to Change operation mode command\n"); + gpsd_report(session->context->debug, LOG_INF, + "Response to Change operation mode command\n"); break; case 0xc1: ul4 = getleu32(buf, OFFSET(1)); @@ -408,27 +448,34 @@ static gps_mask_t geostar_analyze(struct gps_device_t *session) (void)snprintf(session->subtype, sizeof(session->subtype), "%d.%d %d.%d.%d %x %c-%d\n", ul4>>16, ul4&0xFFFF, ul1>>9, (ul1>>5)&0xF, ul1&0x1F, ul2, ul3>>24, ul3&0x00FFFFFF); /*@ +formattype @*/ - gpsd_report(LOG_INF, "Response to Request FW version command: %s\n", + gpsd_report(session->context->debug, LOG_INF, + "Response to Request FW version command: %s\n", session->subtype); mask |= DEVICEID_SET; break; case 0xc2: - gpsd_report(LOG_INF, "Response to Restart receiver command\n"); + gpsd_report(session->context->debug, LOG_INF, + "Response to Restart receiver command\n"); break; case 0xc3: - gpsd_report(LOG_INF, "Response to Store parameters to Flash command\n"); + gpsd_report(session->context->debug, LOG_INF, + "Response to Store parameters to Flash command\n"); break; case 0xd0: - gpsd_report(LOG_INF, "Response to Erase Flash sector command\n"); + gpsd_report(session->context->debug, LOG_INF, + "Response to Erase Flash sector command\n"); break; case 0xd1: - gpsd_report(LOG_INF, "Response to Write data to Flash command\n"); + gpsd_report(session->context->debug, LOG_INF, + "Response to Write data to Flash command\n"); break; case 0xd2: - gpsd_report(LOG_INF, "Response to Store Serial Number command\n"); + gpsd_report(session->context->debug, LOG_INF, + "Response to Store Serial Number command\n"); break; default: - gpsd_report(LOG_WARN, "Unhandled GeoStar packet type 0x%02x\n", id); + gpsd_report(session->context->debug, LOG_WARN, + "Unhandled GeoStar packet type 0x%02x\n", id); break; } @@ -549,7 +596,7 @@ static void geostar_mode(struct gps_device_t *session, int mode) /* Switch to binary mode */ (void)nmea_send(session, "$GPSGG,SWPROT"); } else { - gpsd_report(LOG_ERROR, "unknown mode %i requested\n", mode); + gpsd_report(session->context->debug, LOG_ERROR, "unknown mode %i requested\n", mode); } /*@+shiftimplementation@*/ } diff --git a/driver_italk.c b/driver_italk.c index 224a3392..c8f6b2fe 100644 --- a/driver_italk.c +++ b/driver_italk.c @@ -41,7 +41,8 @@ static gps_mask_t decode_itk_navfix(struct gps_device_t *session, double epx, epy, epz, evx, evy, evz, eph; if (len != 296) { - gpsd_report(LOG_PROG, "ITALK: bad NAV_FIX (len %zu, should be 296)\n", + gpsd_report(session->context->debug, LOG_PROG, + "ITALK: bad NAV_FIX (len %zu, should be 296)\n", len); return -1; } @@ -105,7 +106,7 @@ static gps_mask_t decode_itk_navfix(struct gps_device_t *session, session->gpsdata.status = STATUS_FIX; } - gpsd_report(LOG_DATA, + gpsd_report(session->context->debug, LOG_DATA, "NAV_FIX: time=%.2f, lat=%.2f lon=%.2f alt=%.f speed=%.2f track=%.2f climb=%.2f mode=%d status=%d gdop=%.2f pdop=%.2f hdop=%.2f vdop=%.2f tdop=%.2f\n", session->newdata.time, session->newdata.latitude, session->newdata.longitude, session->newdata.altitude, @@ -123,7 +124,7 @@ static gps_mask_t decode_itk_prnstatus(struct gps_device_t *session, gps_mask_t mask; if (len < 62) { - gpsd_report(LOG_PROG, "ITALK: runt PRN_STATUS (len=%zu)\n", len); + gpsd_report(session->context->debug, LOG_PROG, "ITALK: runt PRN_STATUS (len=%zu)\n", len); mask = 0; } else { unsigned int i, nsv, nchan, st; @@ -155,7 +156,7 @@ static gps_mask_t decode_itk_prnstatus(struct gps_device_t *session, session->gpsdata.satellites_used = (int)nsv; mask = USED_IS | SATELLITE_SET;; - gpsd_report(LOG_DATA, + gpsd_report(session->context->debug, LOG_DATA, "PRN_STATUS: time=%.2f visible=%d used=%d mask={USED|SATELLITE}\n", session->newdata.time, session->gpsdata.satellites_visible, @@ -172,7 +173,7 @@ static gps_mask_t decode_itk_utcionomodel(struct gps_device_t *session, unsigned short flags; if (len != 64) { - gpsd_report(LOG_PROG, + gpsd_report(session->context->debug, LOG_PROG, "ITALK: bad UTC_IONO_MODEL (len %zu, should be 64)\n", len); return 0; @@ -189,7 +190,7 @@ static gps_mask_t decode_itk_utcionomodel(struct gps_device_t *session, session->newdata.time = gpsd_gpstime_resolve(session, (unsigned short) getleu16(buf, 7 + 36), (unsigned int)getleu32(buf, 7 + 38) / 1000.0); - gpsd_report(LOG_DATA, + gpsd_report(session->context->debug, LOG_DATA, "UTC_IONO_MODEL: time=%.2f mask={TIME}\n", session->newdata.time); return TIME_SET | PPSTIME_IS; @@ -203,7 +204,7 @@ static gps_mask_t decode_itk_subframe(struct gps_device_t *session, uint32_t words[10]; if (len != 64) { - gpsd_report(LOG_PROG, + gpsd_report(session->context->debug, LOG_PROG, "ITALK: bad SUBFRAME (len %zu, should be 64)\n", len); return 0; } @@ -211,7 +212,7 @@ static gps_mask_t decode_itk_subframe(struct gps_device_t *session, flags = (unsigned short) getleu16(buf, 7 + 4); prn = (unsigned short) getleu16(buf, 7 + 6); sf = (unsigned short) getleu16(buf, 7 + 8); - gpsd_report(LOG_PROG, "iTalk 50B SUBFRAME prn %u sf %u - decode %s %s\n", + gpsd_report(session->context->debug, LOG_PROG, "iTalk 50B SUBFRAME prn %u sf %u - decode %s %s\n", prn, sf, flags & SUBFRAME_WORD_FLAG_MASK ? "error" : "ok", flags & SUBFRAME_GPS_PREAMBLE_INVERTED ? "(inverted)" : ""); @@ -235,16 +236,17 @@ static gps_mask_t decode_itk_pseudo(struct gps_device_t *session, n = (unsigned short) getleu16(buf, 7 + 4); if ((n < 1) || (n > MAXCHANNELS)){ - gpsd_report(LOG_INF, "ITALK: bad PSEUDO channel count\n"); + gpsd_report(session->context->debug, LOG_INF, + "ITALK: bad PSEUDO channel count\n"); return 0; } if (len != (size_t)((n+1)*36)) { - gpsd_report(LOG_PROG, + gpsd_report(session->context->debug, LOG_PROG, "ITALK: bad PSEUDO len %zu\n", len); } - gpsd_report(LOG_PROG, "iTalk PSEUDO [%u]\n", n); + gpsd_report(session->context->debug, LOG_PROG, "iTalk PSEUDO [%u]\n", n); flags = (unsigned short)getleu16(buf, 7 + 6); if ((flags & 0x3) != 0x3) return 0; // bail if measurement time not valid. @@ -282,45 +284,46 @@ static gps_mask_t italk_parse(struct gps_device_t *session, type = (uint) getub(buf, 4); /* we may need to dump the raw packet */ - gpsd_report(LOG_RAW, "raw italk packet type 0x%02x\n", type); + gpsd_report(session->context->debug, LOG_RAW, + "raw italk packet type 0x%02x\n", type); session->cycle_end_reliable = true; switch (type) { case ITALK_NAV_FIX: - gpsd_report(LOG_IO, "iTalk NAV_FIX len %zu\n", len); + gpsd_report(session->context->debug, LOG_IO, "iTalk NAV_FIX len %zu\n", len); mask = decode_itk_navfix(session, buf, len) | (CLEAR_IS | REPORT_IS); break; case ITALK_PRN_STATUS: - gpsd_report(LOG_IO, "iTalk PRN_STATUS len %zu\n", len); + gpsd_report(session->context->debug, LOG_IO, "iTalk PRN_STATUS len %zu\n", len); mask = decode_itk_prnstatus(session, buf, len); break; case ITALK_UTC_IONO_MODEL: - gpsd_report(LOG_IO, "iTalk UTC_IONO_MODEL len %zu\n", len); + gpsd_report(session->context->debug, LOG_IO, "iTalk UTC_IONO_MODEL len %zu\n", len); mask = decode_itk_utcionomodel(session, buf, len); break; case ITALK_ACQ_DATA: - gpsd_report(LOG_IO, "iTalk ACQ_DATA len %zu\n", len); + gpsd_report(session->context->debug, LOG_IO, "iTalk ACQ_DATA len %zu\n", len); break; case ITALK_TRACK: - gpsd_report(LOG_IO, "iTalk TRACK len %zu\n", len); + gpsd_report(session->context->debug, LOG_IO, "iTalk TRACK len %zu\n", len); break; case ITALK_PSEUDO: - gpsd_report(LOG_IO, "iTalk PSEUDO len %zu\n", len); + gpsd_report(session->context->debug, LOG_IO, "iTalk PSEUDO len %zu\n", len); mask = decode_itk_pseudo(session, buf, len); break; case ITALK_RAW_ALMANAC: - gpsd_report(LOG_IO, "iTalk RAW_ALMANAC len %zu\n", len); + gpsd_report(session->context->debug, LOG_IO, "iTalk RAW_ALMANAC len %zu\n", len); break; case ITALK_RAW_EPHEMERIS: - gpsd_report(LOG_IO, "iTalk RAW_EPHEMERIS len %zu\n", len); + gpsd_report(session->context->debug, LOG_IO, "iTalk RAW_EPHEMERIS len %zu\n", len); break; case ITALK_SUBFRAME: mask = decode_itk_subframe(session, buf, len); break; case ITALK_BIT_STREAM: - gpsd_report(LOG_IO, "iTalk BIT_STREAM len %zu\n", len); + gpsd_report(session->context->debug, LOG_IO, "iTalk BIT_STREAM len %zu\n", len); break; case ITALK_AGC: @@ -354,12 +357,13 @@ static gps_mask_t italk_parse(struct gps_device_t *session, case ITALK_PULL_FIX: case ITALK_MEMCTRL: case ITALK_STOP_TASK: - gpsd_report(LOG_IO, + gpsd_report(session->context->debug, LOG_IO, "iTalk not processing packet: id 0x%02x length %zu\n", type, len); break; default: - gpsd_report(LOG_IO, "iTalk unknown packet: id 0x%02x length %zu\n", + gpsd_report(session->context->debug, LOG_IO, + "iTalk unknown packet: id 0x%02x length %zu\n", type, len); } (void)snprintf(session->gpsdata.tag, sizeof(session->gpsdata.tag), diff --git a/driver_navcom.c b/driver_navcom.c index 498abc4c..406ca0e8 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(LOG_PROG, + gpsd_report(session->context->debug, 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(LOG_PROG, + gpsd_report(session->context->debug, LOG_PROG, "Navcom: sent command 0x3f (LED Configuration Block)\n"); } @@ -148,8 +148,8 @@ 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(LOG_PROG, "Navcom: sent command 0x1c (Test Support Block)\n"); - gpsd_report(LOG_IO, + gpsd_report(session->context->debug, LOG_PROG, "Navcom: sent command 0x1c (Test Support Block)\n"); + gpsd_report(session->context->debug, LOG_IO, "Navcom: command 0x1c mode = %02x, length = %u\n", mode, length); } @@ -174,9 +174,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(LOG_PROG, + gpsd_report(session->context->debug, LOG_PROG, "Navcom: sent command 0x11 (Serial Port Configuration)\n"); - gpsd_report(LOG_IO, + gpsd_report(session->context->debug, LOG_IO, "Navcom: serial port selection: 0x%02x\n", port_selection); } #endif /* RECONFIGURE_ENABLE */ @@ -275,26 +275,26 @@ static gps_mask_t handle_0x83(struct gps_device_t *session) } /*@ -relaxtypes -charint @*/ - gpsd_report(LOG_PROG, + gpsd_report(session->context->debug, LOG_PROG, "Navcom: received packet type 0x83 (Ionosphere and UTC Data)\n"); - gpsd_report(LOG_IO, "Navcom: Scaled parameters follow:\n"); - gpsd_report(LOG_IO, + gpsd_report(session->context->debug, LOG_IO, "Navcom: Scaled parameters follow:\n"); + gpsd_report(session->context->debug, LOG_IO, "Navcom: GPS Week: %u, GPS Time of Week: %u (GPS Time: %f)\n", week, tow, week * 604800 + tow / 1000.0); - gpsd_report(LOG_IO, + gpsd_report(session->context->debug, LOG_IO, "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(LOG_IO, + gpsd_report(session->context->debug, LOG_IO, "Navcom: A0: %19.12E, A1: %19.12E\n", (double)a0 * SF_A0, (double)a1 * SF_A1); - gpsd_report(LOG_IO, + gpsd_report(session->context->debug, LOG_IO, "Navcom: UTC Ref. Time: %lu, UTC Ref. Week: %u, dTls: %d\n", (unsigned long)tot * SF_TOT, wnt, dtls); - gpsd_report(LOG_IO, + gpsd_report(session->context->debug, LOG_IO, "Navcom: Week of leap seconds: %u, Day number of leap seconds: %u, dTlsf: %d\n", wnlsf, dn, dtlsf); @@ -320,10 +320,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(LOG_PROG, + gpsd_report(session->context->debug, LOG_PROG, "Navcom: received packet type 0x06 (Acknowledgement (without error))\n"); /*@ -type @*/ - gpsd_report(LOG_IO, + gpsd_report(session->context->debug, LOG_IO, "Navcom: acknowledged command id 0x%02x on port %c\n", cmd_id, (port == 0 ? 'A' : (port == 1 ? 'B' : '?'))); /*@ +type @*/ @@ -338,17 +338,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(LOG_PROG, + gpsd_report(session->context->debug, 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(LOG_IO, + gpsd_report(session->context->debug, LOG_IO, "Navcom: error id = 0x%02x, error description = 0x%02x\n", err_id, err_desc); } port = getub(buf, n); - gpsd_report(LOG_IO, + gpsd_report(session->context->debug, LOG_IO, "Navcom: negative acknowledge was for command id 0x%02x on port %c\n", cmd_id, (port == 0 ? 'A' : (port == 1 ? 'B' : '?'))); /*@ -type @*/ @@ -492,17 +492,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(LOG_PROG, "Navcom: received packet type 0xb1 (PVT Report)\n"); - gpsd_report(LOG_IO, "Navcom: navigation mode %s (0x%02x) - %s - %s\n", + gpsd_report(session->context->debug, LOG_PROG, + "Navcom: received packet type 0xb1 (PVT Report)\n"); + gpsd_report(session->context->debug, LOG_IO, + "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(LOG_IO, + gpsd_report(session->context->debug, LOG_IO, "Navcom: latitude = %f, longitude = %f, altitude = %f, geoid = %f\n", session->newdata.latitude, session->newdata.longitude, session->newdata.altitude, session->gpsdata.separation); - gpsd_report(LOG_IO, + gpsd_report(session->context->debug, LOG_IO, "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); @@ -517,7 +519,8 @@ 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(LOG_DATA, "PVT 0xb1: time=%.2f, lat=%.2f lon=%.2f alt=%.f " + gpsd_report(session->context->debug, 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 " "gdop=%.2f pdop=%.2f hdop=%.2f vdop=%.2f tdop=%.2f " @@ -642,41 +645,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(LOG_PROG, + gpsd_report(session->context->debug, LOG_PROG, "Navcom: received packet type 0x81 (Packed Ephemeris Data)\n"); - gpsd_report(LOG_IO, + gpsd_report(session->context->debug, LOG_IO, "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(LOG_IO, + gpsd_report(session->context->debug, LOG_IO, "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(LOG_IO, + gpsd_report(session->context->debug, LOG_IO, "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(LOG_IO, + gpsd_report(session->context->debug, LOG_IO, "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(LOG_IO, + gpsd_report(session->context->debug, LOG_IO, "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(LOG_IO, + gpsd_report(session->context->debug, LOG_IO, "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(LOG_IO, + gpsd_report(session->context->debug, LOG_IO, "Navcom: SV accuracy: 0x%x, SV health: 0x%x, TGD: %f, IODC (!AODC): %u\n", ura, svh, (double)tgd * SF_TGD, iodc); - gpsd_report(LOG_IO, "Navcom: Transmission time: %u\n", tow); + gpsd_report(session->context->debug, LOG_IO, "Navcom: Transmission time: %u\n", tow); #undef SF_TGD #undef SF_TOC @@ -745,7 +748,7 @@ static gps_mask_t handle_0x86(struct gps_device_t *session) } /*@ -predboolothers @*/ - gpsd_report(LOG_IO, + gpsd_report(session->context->debug, LOG_IO, "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); @@ -755,7 +758,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(LOG_ERROR, + gpsd_report(session->context->debug, LOG_ERROR, "Navcom: packet type 0x86: too many satellites!\n"); gpsd_zero_satellites(&session->gpsdata); return 0; @@ -784,12 +787,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(LOG_IO, + gpsd_report(session->context->debug, LOG_IO, "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(LOG_IO, + gpsd_report(session->context->debug, LOG_IO, "Navcom: sol. valid = %c, clock = %s, pos. = %s, " "height = %s, err. code = 0x%x\n", (sol_status & 0x01 ? 'Y' : 'N'), @@ -800,7 +803,7 @@ static gps_mask_t handle_0x86(struct gps_device_t *session) /*@ +predboolothers -charint @*/ } - gpsd_report(LOG_DATA, + gpsd_report(session->context->debug, LOG_DATA, "CS 0x86: visible=%d, used=%d, mask={SATELLITE|STATUS}\n", session->gpsdata.satellites_visible, session->gpsdata.satellites_used); @@ -823,10 +826,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(LOG_PROG, + gpsd_report(session->context->debug, LOG_PROG, "Navcom: received packet type 0xb0 (Raw Meas. Data Block)\n"); /*@ -predboolothers @*/ - gpsd_report(LOG_IO, + gpsd_report(session->context->debug, LOG_IO, "Navcom: week = %u, tow = %.3f, time slew accumulator = %u (1/1023mS), status = 0x%02x " "(%sclock %s - %u blocks follow)\n", session->context->gps_week, @@ -864,17 +867,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(LOG_IO + 1, + gpsd_report(session->context->debug, LOG_IO + 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(LOG_IO + 1, + gpsd_report(session->context->debug, LOG_IO + 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(LOG_IO + 1, + gpsd_report(session->context->debug, LOG_IO + 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 @*/ @@ -915,14 +918,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(LOG_PROG, + gpsd_report(session->context->debug, LOG_PROG, "Navcom: received packet type 0xb5 (Pseudorange Noise Statistics)\n"); - gpsd_report(LOG_IO, "Navcom: epe = %f\n", session->gpsdata.epe); + gpsd_report(session->context->debug, LOG_IO, + "Navcom: epe = %f\n", session->gpsdata.epe); return mask; } else { /* Ignore this message block */ if (!session->driver.navcom.warned) { - gpsd_report(LOG_WARN, + gpsd_report(session->context->debug, LOG_WARN, "Navcom: received packet type 0xb5 (Pseudorange Noise Statistics) ignored " " - sizeof(double) == 64 bits required\n"); session->driver.navcom.warned = true; @@ -1045,16 +1049,16 @@ static gps_mask_t handle_0xae(struct gps_device_t *session) asicstr = "?"; } - gpsd_report(LOG_PROG, + gpsd_report(session->context->debug, LOG_PROG, "Navcom: received packet type 0xae (Identification Block)\n"); if (msg_len == 0x0037) { - gpsd_report(LOG_INF, "Navcom: ID Data: " + gpsd_report(session->context->debug, 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(LOG_INF, "Navcom: ID Data: " + gpsd_report(session->context->debug, 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", @@ -1098,13 +1102,13 @@ static gps_mask_t handle_0xef(struct gps_device_t *session) osc_filter_drift_est = NAN; } - gpsd_report(LOG_IO, + gpsd_report(session->context->debug, LOG_IO, "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(LOG_DATA, + gpsd_report(session->context->debug, LOG_DATA, "CDO 0xef: time=%.2f mask={TIME}\n", session->newdata.time); return 0; } @@ -1125,7 +1129,7 @@ gps_mask_t navcom_parse(struct gps_device_t * session, unsigned char *buf, msg_len = (uint) getleu16(buf, 4); /*@ -usedef -compdef @*/ - gpsd_report(LOG_RAW, "Navcom: packet type 0x%02x\n", cmd_id); + gpsd_report(session->context->debug, LOG_RAW, "Navcom: packet type 0x%02x\n", cmd_id); /*@ +usedef +compdef @*/ (void)snprintf(session->gpsdata.tag, sizeof(session->gpsdata.tag), @@ -1157,7 +1161,7 @@ gps_mask_t navcom_parse(struct gps_device_t * session, unsigned char *buf, case 0xef: return handle_0xef(session); default: - gpsd_report(LOG_PROG, + gpsd_report(session->context->debug, LOG_PROG, "Navcom: received packet type 0x%02x, length %d - unknown or unimplemented\n", cmd_id, msg_len); return 0; 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; diff --git a/driver_nmea2000.c b/driver_nmea2000.c index e7ea5a3d..4d262876 100644 --- a/driver_nmea2000.c +++ b/driver_nmea2000.c @@ -59,7 +59,8 @@ FILE *logFile = NULL; extern bool __attribute__ ((weak)) gpsd_add_device(const char *device_name, bool flag_nowait); -static void print_data(unsigned char *buffer, int len, PGN *pgn) +static void print_data(const gps_context_t *context, + unsigned char *buffer, int len, PGN *pgn) { #ifdef LIBGPS_DEBUG /*@-bufferoverflowhigh@*/ @@ -72,7 +73,7 @@ static void print_data(unsigned char *buffer, int len, PGN *pgn) ptr += l2; for (l1=0;l1<len;l1++) { if (((l1 % 20) == 0) && (l1 != 0)) { - gpsd_report(LOG_IO,"%s\n", bu); + gpsd_report(context->debug, LOG_IO,"%s\n", bu); ptr = 0; l2 = sprintf(&bu[ptr], " : "); ptr += l2; @@ -80,7 +81,7 @@ static void print_data(unsigned char *buffer, int len, PGN *pgn) l2 = sprintf(&bu[ptr], "%02ux ", (unsigned int)buffer[l1]); ptr += l2; } - gpsd_report(LOG_IO,"%s\n", bu); + gpsd_report(context->debug, LOG_IO,"%s\n", bu); } /*@+bufferoverflowhigh@*/ #endif @@ -102,22 +103,29 @@ static gps_mask_t get_mode(struct gps_device_t *session) } -static int decode_ais_header(unsigned char *bu, int len, struct ais_t *ais, unsigned int mask) +static int decode_ais_header(const gps_context_t *context, + unsigned char *bu, int len, struct ais_t *ais, unsigned int mask) { if (len > 4) { ais->type = (unsigned int) ( bu[0] & 0x3f); ais->repeat = (unsigned int) ((bu[0] >> 6) & 0x03); ais->mmsi = (unsigned int) getleu32(bu, 1); ais->mmsi &= mask; - gpsd_report(LOG_INF, "NMEA2000 AIS message type %u, MMSI %09d:\n", ais->type, ais->mmsi); - printf("NMEA2000 AIS message type %2u, MMSI %09u:\n", ais->type, ais->mmsi); + gpsd_report(context->debug, LOG_INF, + "NMEA2000 AIS message type %u, MMSI %09d:\n", + ais->type, ais->mmsi); + printf("NMEA2000 AIS message type %2u, MMSI %09u:\n", + ais->type, ais->mmsi); return(1); } else { ais->type = 0; ais->repeat = 0; ais->mmsi = 0; - gpsd_report(LOG_ERROR, "NMEA2000 AIS message type %u, too short message.\n", ais->type); - printf("NMEA2000 AIS message type %u, too short message.\n", ais->type); + gpsd_report(context->debug, LOG_ERROR, + "NMEA2000 AIS message type %u, too short message.\n", + ais->type); + printf("NMEA2000 AIS message type %u, too short message.\n", + ais->type); } return(0); } @@ -172,48 +180,54 @@ static double ais_direction(unsigned int val, double scale) static gps_mask_t hnd_059392(unsigned char *bu, int len, PGN *pgn, struct gps_device_t *session) { - print_data(bu, len, pgn); - gpsd_report(LOG_DATA, "pgn %6d(%3d):\n", pgn->pgn, session->driver.nmea2000.unit); + print_data(session->context, bu, len, pgn); + gpsd_report(session->context->debug, LOG_DATA, + "pgn %6d(%3d):\n", pgn->pgn, session->driver.nmea2000.unit); return(0); } static gps_mask_t hnd_060928(unsigned char *bu, int len, PGN *pgn, struct gps_device_t *session) { - print_data(bu, len, pgn); - gpsd_report(LOG_DATA, "pgn %6d(%3d):\n", pgn->pgn, session->driver.nmea2000.unit); + print_data(session->context, bu, len, pgn); + gpsd_report(session->context->debug, LOG_DATA, + "pgn %6d(%3d):\n", pgn->pgn, session->driver.nmea2000.unit); return(0); } static gps_mask_t hnd_126208(unsigned char *bu, int len, PGN *pgn, struct gps_device_t *session) { - print_data(bu, len, pgn); - gpsd_report(LOG_DATA, "pgn %6d(%3d):\n", pgn->pgn, session->driver.nmea2000.unit); + print_data(session->context, bu, len, pgn); + gpsd_report(session->context->debug, LOG_DATA, + "pgn %6d(%3d):\n", pgn->pgn, session->driver.nmea2000.unit); return(0); } static gps_mask_t hnd_126464(unsigned char *bu, int len, PGN *pgn, struct gps_device_t *session) { - print_data(bu, len, pgn); - gpsd_report(LOG_DATA, "pgn %6d(%3d):\n", pgn->pgn, session->driver.nmea2000.unit); + print_data(session->context, bu, len, pgn); + gpsd_report(session->context->debug, LOG_DATA, + "pgn %6d(%3d):\n", pgn->pgn, session->driver.nmea2000.unit); return(0); } static gps_mask_t hnd_126996(unsigned char *bu, int len, PGN *pgn, struct gps_device_t *session) { - print_data(bu, len, pgn); - gpsd_report(LOG_DATA, "pgn %6d(%3d):\n", pgn->pgn, session->driver.nmea2000.unit); + print_data(session->context, bu, len, pgn); + gpsd_report(session->context->debug, LOG_DATA, + "pgn %6d(%3d):\n", pgn->pgn, session->driver.nmea2000.unit); return(0); } static gps_mask_t hnd_129025(unsigned char *bu, int len, PGN *pgn, struct gps_device_t *session) { - print_data(bu, len, pgn); - gpsd_report(LOG_DATA, "pgn %6d(%3d):\n", pgn->pgn, session->driver.nmea2000.unit); + print_data(session->context, bu, len, pgn); + gpsd_report(session->context->debug, LOG_DATA, + "pgn %6d(%3d):\n", pgn->pgn, session->driver.nmea2000.unit); /*@-type@*//* splint has a bug here */ session->newdata.latitude = getles32(bu, 0) * 1e-7; @@ -228,8 +242,9 @@ static gps_mask_t hnd_129025(unsigned char *bu, int len, PGN *pgn, struct gps_de static gps_mask_t hnd_129026(unsigned char *bu, int len, PGN *pgn, struct gps_device_t *session) { - print_data(bu, len, pgn); - gpsd_report(LOG_DATA, "pgn %6d(%3d):\n", pgn->pgn, session->driver.nmea2000.unit); + print_data(session->context, bu, len, pgn); + gpsd_report(session->context->debug, LOG_DATA, + "pgn %6d(%3d):\n", pgn->pgn, session->driver.nmea2000.unit); session->driver.nmea2000.sid[0] = bu[0]; @@ -249,8 +264,9 @@ static gps_mask_t hnd_126992(unsigned char *bu, int len, PGN *pgn, struct gps_de //uint8_t sid; //uint8_t source; - print_data(bu, len, pgn); - gpsd_report(LOG_DATA, "pgn %6d(%3d):\n", pgn->pgn, session->driver.nmea2000.unit); + print_data(session->context, bu, len, pgn); + gpsd_report(session->context->debug, LOG_DATA, + "pgn %6d(%3d):\n", pgn->pgn, session->driver.nmea2000.unit); //sid = bu[0]; //source = bu[1] & 0x0f; @@ -274,8 +290,9 @@ static gps_mask_t hnd_129539(unsigned char *bu, int len, PGN *pgn, struct gps_de unsigned int req_mode; unsigned int act_mode; - print_data(bu, len, pgn); - gpsd_report(LOG_DATA, "pgn %6d(%3d):\n", pgn->pgn, session->driver.nmea2000.unit); + print_data(session->context, bu, len, pgn); + gpsd_report(session->context->debug, LOG_DATA, + "pgn %6d(%3d):\n", pgn->pgn, session->driver.nmea2000.unit); mask = 0; session->driver.nmea2000.sid[1] = bu[0]; @@ -299,7 +316,8 @@ static gps_mask_t hnd_129539(unsigned char *bu, int len, PGN *pgn, struct gps_de /*@+type@*/ mask |= DOP_SET; - gpsd_report(LOG_DATA, "pgn %6d(%3d): sid:%02x hdop:%5.2f vdop:%5.2f tdop:%5.2f\n", + gpsd_report(session->context->debug, LOG_DATA, + "pgn %6d(%3d): sid:%02x hdop:%5.2f vdop:%5.2f tdop:%5.2f\n", pgn->pgn, session->driver.nmea2000.unit, session->driver.nmea2000.sid[1], @@ -317,8 +335,9 @@ static gps_mask_t hnd_129540(unsigned char *bu, int len, PGN *pgn, struct gps_de { int l1, l2; - print_data(bu, len, pgn); - gpsd_report(LOG_DATA, "pgn %6d(%3d):\n", pgn->pgn, session->driver.nmea2000.unit); + print_data(session->context, bu, len, pgn); + gpsd_report(session->context->debug, LOG_DATA, + "pgn %6d(%3d):\n", pgn->pgn, session->driver.nmea2000.unit); session->driver.nmea2000.sid[2] = bu[0]; session->gpsdata.satellites_visible = (int)bu[2]; @@ -357,8 +376,9 @@ static gps_mask_t hnd_129029(unsigned char *bu, int len, PGN *pgn, struct gps_de { gps_mask_t mask; - print_data(bu, len, pgn); - gpsd_report(LOG_DATA, "pgn %6d(%3d):\n", pgn->pgn, session->driver.nmea2000.unit); + print_data(session->context, bu, len, pgn); + gpsd_report(session->context->debug, LOG_DATA, + "pgn %6d(%3d):\n", pgn->pgn, session->driver.nmea2000.unit); mask = 0; session->driver.nmea2000.sid[3] = bu[0]; @@ -425,10 +445,11 @@ static gps_mask_t hnd_129038(unsigned char *bu, int len, PGN *pgn, struct gps_de struct ais_t *ais; ais = &session->gpsdata.ais; - print_data(bu, len, pgn); - gpsd_report(LOG_DATA, "pgn %6d(%3d):\n", pgn->pgn, session->driver.nmea2000.unit); + print_data(session->context, bu, len, pgn); + gpsd_report(session->context->debug, LOG_DATA, + "pgn %6d(%3d):\n", pgn->pgn, session->driver.nmea2000.unit); - if (decode_ais_header(bu, len, ais, 0xffffffffU) != 0) { + if (decode_ais_header(session->context, bu, len, ais, 0xffffffffU) != 0) { ais->type1.lon = (int) (getles32(bu, 5) * 0.06); ais->type1.lat = (int) (getles32(bu, 9) * 0.06); ais->type1.accuracy = (bool) ((bu[13] >> 0) & 0x01); @@ -454,10 +475,11 @@ static gps_mask_t hnd_129039(unsigned char *bu, int len, PGN *pgn, struct gps_de struct ais_t *ais; ais = &session->gpsdata.ais; - print_data(bu, len, pgn); - gpsd_report(LOG_DATA, "pgn %6d(%3d):\n", pgn->pgn, session->driver.nmea2000.unit); + print_data(session->context, bu, len, pgn); + gpsd_report(session->context->debug, LOG_DATA, + "pgn %6d(%3d):\n", pgn->pgn, session->driver.nmea2000.unit); - if (decode_ais_header(bu, len, ais, 0xffffffffU) != 0) { + if (decode_ais_header(session->context, bu, len, ais, 0xffffffffU) != 0) { ais->type18.lon = (int) (getles32(bu, 5) * 0.06); ais->type18.lat = (int) (getles32(bu, 9) * 0.06); ais->type18.accuracy = (bool) ((bu[13] >> 0) & 0x01); @@ -489,10 +511,11 @@ static gps_mask_t hnd_129040(unsigned char *bu, int len, PGN *pgn, struct gps_de struct ais_t *ais; ais = &session->gpsdata.ais; - print_data(bu, len, pgn); - gpsd_report(LOG_DATA, "pgn %6d(%3d):\n", pgn->pgn, session->driver.nmea2000.unit); + print_data(session->context, bu, len, pgn); + gpsd_report(session->context->debug, LOG_DATA, + "pgn %6d(%3d):\n", pgn->pgn, session->driver.nmea2000.unit); - if (decode_ais_header(bu, len, ais, 0xffffffffU) != 0) { + if (decode_ais_header(session->context, bu, len, ais, 0xffffffffU) != 0) { uint16_t length, beam, to_bow, to_starboard; int l; @@ -543,10 +566,11 @@ static gps_mask_t hnd_129794(unsigned char *bu, int len, PGN *pgn, struct gps_de struct ais_t *ais; ais = &session->gpsdata.ais; - print_data(bu, len, pgn); - gpsd_report(LOG_DATA, "pgn %6d(%3d):\n", pgn->pgn, session->driver.nmea2000.unit); + print_data(session->context, bu, len, pgn); + gpsd_report(session->context->debug, LOG_DATA, + "pgn %6d(%3d):\n", pgn->pgn, session->driver.nmea2000.unit); - if (decode_ais_header(bu, len, ais, 0xffffffffU) != 0) { + if (decode_ais_header(session->context, bu, len, ais, 0xffffffffU) != 0) { uint16_t length, beam, to_bow, to_starboard, date; int l; uint32_t time; @@ -636,10 +660,11 @@ static gps_mask_t hnd_129798(unsigned char *bu, int len, PGN *pgn, struct gps_de struct ais_t *ais; ais = &session->gpsdata.ais; - print_data(bu, len, pgn); - gpsd_report(LOG_DATA, "pgn %6d(%3d):\n", pgn->pgn, session->driver.nmea2000.unit); + print_data(session->context, bu, len, pgn); + gpsd_report(session->context->debug, LOG_DATA, + "pgn %6d(%3d):\n", pgn->pgn, session->driver.nmea2000.unit); - if (decode_ais_header(bu, len, ais, 0xffffffffU) != 0) { + if (decode_ais_header(session->context, bu, len, ais, 0xffffffffU) != 0) { ais->type9.lon = (int) (getles32(bu, 5) * 0.06); ais->type9.lat = (int) (getles32(bu, 9) * 0.06); ais->type9.accuracy = (bool) ((bu[13] >> 0) & 0x01); @@ -667,10 +692,11 @@ static gps_mask_t hnd_129802(unsigned char *bu, int len, PGN *pgn, struct gps_de struct ais_t *ais; ais = &session->gpsdata.ais; - print_data(bu, len, pgn); - gpsd_report(LOG_DATA, "pgn %6d(%3d):\n", pgn->pgn, session->driver.nmea2000.unit); + print_data(session->context, bu, len, pgn); + gpsd_report(session->context->debug, LOG_DATA, + "pgn %6d(%3d):\n", pgn->pgn, session->driver.nmea2000.unit); - if (decode_ais_header(bu, len, ais, 0x3fffffff) != 0) { + if (decode_ais_header(session->context, bu, len, ais, 0x3fffffff) != 0) { int l; /* ais->type14.channel = (bu[ 5] >> 0) & 0x1f; */ @@ -691,15 +717,18 @@ static gps_mask_t hnd_129809(unsigned char *bu, int len, PGN *pgn, struct gps_de struct ais_t *ais; ais = &session->gpsdata.ais; - print_data(bu, len, pgn); - gpsd_report(LOG_DATA, "pgn %6d(%3d):\n", pgn->pgn, session->driver.nmea2000.unit); + print_data(session->context, bu, len, pgn); + gpsd_report(session->context->debug, LOG_DATA, + "pgn %6d(%3d):\n", pgn->pgn, session->driver.nmea2000.unit); - if (decode_ais_header(bu, len, ais, 0xffffffffU) != 0) { + if (decode_ais_header(session->context, bu, len, ais, 0xffffffffU) != 0) { int l; int index = session->aivdm[0].type24_queue.index; struct ais_type24a_t *saveptr = &session->aivdm[0].type24_queue.ships[index]; - gpsd_report(LOG_PROG, "NMEA2000: AIS message 24A from %09u stashed.\n", ais->mmsi); + gpsd_report(session->context->debug, LOG_PROG, + "NMEA2000: AIS message 24A from %09u stashed.\n", + ais->mmsi); saveptr->mmsi = ais->mmsi; @@ -724,10 +753,11 @@ static gps_mask_t hnd_129810(unsigned char *bu, int len, PGN *pgn, struct gps_de struct ais_t *ais; ais = &session->gpsdata.ais; - print_data(bu, len, pgn); - gpsd_report(LOG_DATA, "pgn %6d(%3d):\n", pgn->pgn, session->driver.nmea2000.unit); + print_data(session->context, bu, len, pgn); + gpsd_report(session->context->debug, LOG_DATA, + "pgn %6d(%3d):\n", pgn->pgn, session->driver.nmea2000.unit); - if (decode_ais_header(bu, len, ais, 0xffffffffU) != 0) { + if (decode_ais_header(session->context, bu, len, ais, 0xffffffffU) != 0) { int i, l; for (i = 0; i < MAX_TYPE24_INTERLEAVE; i++) { @@ -772,7 +802,9 @@ static gps_mask_t hnd_129810(unsigned char *bu, int len, PGN *pgn, struct gps_de } } - gpsd_report(LOG_PROG, "NMEA2000: AIS 24B from %09u matches a 24A.\n", ais->mmsi); + gpsd_report(session->context->debug, LOG_PROG, + "NMEA2000: AIS 24B from %09u matches a 24A.\n", + ais->mmsi); /* prevent false match if a 24B is repeated */ session->aivdm[0].type24_queue.ships[i].mmsi = 0; #if NMEA2000_DEBUG_AIS @@ -792,7 +824,7 @@ static gps_mask_t hnd_129810(unsigned char *bu, int len, PGN *pgn, struct gps_de return(ONLINE_SET | AIS_SET); } } - gpsd_report(LOG_WARN, "NMEA2000: AIS 24B from %09u can't be matched to a 24A.\n", ais->mmsi); + gpsd_report(session->context->debug, LOG_WARN, "NMEA2000: AIS 24B from %09u can't be matched to a 24A.\n", ais->mmsi); return(0); } return(0); @@ -880,7 +912,8 @@ static void find_pgn(struct can_frame *frame, struct gps_device_t *session) session->driver.nmea2000.workpgn = NULL; can_net = session->driver.nmea2000.can_net; if (can_net > (NMEA2000_NETS-1)) { - gpsd_report(LOG_ERROR, "NMEA2000 find_pgn: Invalid can network %d.\n", can_net); + gpsd_report(session->context->debug, LOG_ERROR, + "NMEA2000 find_pgn: Invalid can network %d.\n", can_net); return; } @@ -968,7 +1001,8 @@ static void find_pgn(struct can_frame *frame, struct gps_device_t *session) if (work->fast == 0) { size_t l2; - gpsd_report(LOG_DATA, "pgn %6d:%s \n", work->pgn, work->name); + gpsd_report(session->context->debug, LOG_DATA, + "pgn %6d:%s \n", work->pgn, work->name); session->driver.nmea2000.workpgn = (void *) work; /*@i1@*/session->packet.outbuflen = frame->can_dlc & 0x0f; for (l2=0;l2<session->packet.outbuflen;l2++) { @@ -981,17 +1015,20 @@ static void find_pgn(struct can_frame *frame, struct gps_device_t *session) /*@i2@*/session->driver.nmea2000.fast_packet_len = frame->data[1]; /*@i2@*/session->driver.nmea2000.idx = frame->data[0]; #if NMEA2000_FAST_DEBUG - gpsd_report(LOG_ERROR, "Set idx %2x %2x %2x %6d\n", frame->data[0], - session->driver.nmea2000.unit, - frame->data[1], - source_pgn); + gpsd_report(session->context->debug, LOG_ERROR, + "Set idx %2x %2x %2x %6d\n", + frame->data[0], + session->driver.nmea2000.unit, + frame->data[1], + source_pgn); #endif /* of #if NMEA2000_FAST_DEBUG */ session->packet.inbuflen = 0; session->driver.nmea2000.idx += 1; for (l2=2;l2<8;l2++) { /*@i3@*/session->packet.inbuffer[session->packet.inbuflen++] = frame->data[l2]; } - gpsd_report(LOG_DATA, "pgn %6d:%s \n", work->pgn, work->name); + gpsd_report(session->context->debug, LOG_DATA, + "pgn %6d:%s \n", work->pgn, work->name); } /*@i2@*/else if (frame->data[0] == session->driver.nmea2000.idx) { unsigned int l2; @@ -1003,7 +1040,9 @@ static void find_pgn(struct can_frame *frame, struct gps_device_t *session) } if (session->packet.inbuflen == session->driver.nmea2000.fast_packet_len) { #if NMEA2000_FAST_DEBUG - gpsd_report(LOG_ERROR, "Fast done %2x %2x %2x %2x %6d\n", session->driver.nmea2000.idx, + gpsd_report(session->context->debug, LOG_ERROR, + "Fast done %2x %2x %2x %2x %6d\n", + session->driver.nmea2000.idx, /*@i1@*/frame->data[0], session->driver.nmea2000.unit, (unsigned int) session->driver.nmea2000.fast_packet_len, @@ -1019,14 +1058,18 @@ static void find_pgn(struct can_frame *frame, struct gps_device_t *session) session->driver.nmea2000.idx += 1; } } else { - gpsd_report(LOG_ERROR, "Fast error %2x %2x %2x %2x %6d\n", session->driver.nmea2000.idx, + gpsd_report(session->context->debug, LOG_ERROR, + "Fast error %2x %2x %2x %2x %6d\n", + session->driver.nmea2000.idx, /*@i1@*/frame->data[0], session->driver.nmea2000.unit, (unsigned int) session->driver.nmea2000.fast_packet_len, source_pgn); } } else { - gpsd_report(LOG_WARN, "PGN not found %08d %08x \n", source_pgn, source_pgn); + gpsd_report(session->context->debug, LOG_WARN, + "PGN not found %08d %08x \n", + source_pgn, source_pgn); } } else { // we got a unknown unit number @@ -1124,7 +1167,8 @@ int nmea2000_open(struct gps_device_t *session) } if (unit_ptr != NULL) { if (isdigit(interface_name[l]) == 0) { - gpsd_report(LOG_ERROR, "NMEA2000 open: Invalid character in unit number.\n"); + gpsd_report(session->context->debug, LOG_ERROR, + "NMEA2000 open: Invalid character in unit number.\n"); return -1; } } @@ -1133,7 +1177,8 @@ int nmea2000_open(struct gps_device_t *session) if (unit_ptr != NULL) { unit_number = atoi(unit_ptr); if ((unit_number < 0) || (unit_number > (NMEA2000_UNITS-1))) { - gpsd_report(LOG_ERROR, "NMEA2000 open: Unit number out of range.\n"); + gpsd_report(session->context->debug, LOG_ERROR, + "NMEA2000 open: Unit number out of range.\n"); return -1; } for (l = 0; l < NMEA2000_NETS; l++) { @@ -1145,7 +1190,8 @@ int nmea2000_open(struct gps_device_t *session) } } if (can_net < 0) { - gpsd_report(LOG_ERROR, "NMEA2000 open: CAN device not open: %s .\n", interface_name); + gpsd_report(session->context->debug, LOG_ERROR, + "NMEA2000 open: CAN device not open: %s .\n", interface_name); return -1; } } else { @@ -1153,7 +1199,7 @@ int nmea2000_open(struct gps_device_t *session) if (strncmp(can_interface_name[l], interface_name, MIN(sizeof(interface_name), sizeof(can_interface_name[l]))) == 0) { - gpsd_report(LOG_ERROR, "NMEA2000 open: CAN device duplicate open: %s .\n", interface_name); + gpsd_report(session->context->debug, LOG_ERROR, "NMEA2000 open: CAN device duplicate open: %s .\n", interface_name); return -1; } } @@ -1164,7 +1210,8 @@ int nmea2000_open(struct gps_device_t *session) } } if (can_net < 0) { - gpsd_report(LOG_ERROR, "NMEA2000 open: Too many CAN networks open.\n"); + gpsd_report(session->context->debug, LOG_ERROR, + "NMEA2000 open: Too many CAN networks open.\n"); return -1; } } @@ -1173,13 +1220,15 @@ int nmea2000_open(struct gps_device_t *session) sock = socket(PF_CAN, SOCK_RAW, CAN_RAW); if (BAD_SOCKET(sock)) { - gpsd_report(LOG_ERROR, "NMEA2000 open: can not get socket.\n"); + gpsd_report(session->context->debug, LOG_ERROR, + "NMEA2000 open: can not get socket.\n"); return -1; } status = fcntl(sock, F_SETFL, O_NONBLOCK); if (status != 0) { - gpsd_report(LOG_ERROR, "NMEA2000 open: can not set socket to O_NONBLOCK.\n"); + gpsd_report(session->context->debug, LOG_ERROR, + "NMEA2000 open: can not set socket to O_NONBLOCK.\n"); close(sock); return -1; } @@ -1190,7 +1239,8 @@ int nmea2000_open(struct gps_device_t *session) * with that device's index */ if (status != 0) { - gpsd_report(LOG_ERROR, "NMEA2000 open: can not find CAN device.\n"); + gpsd_report(session->context->debug, LOG_ERROR, + "NMEA2000 open: can not find CAN device.\n"); close(sock); return -1; } @@ -1200,7 +1250,7 @@ int nmea2000_open(struct gps_device_t *session) addr.can_ifindex = ifr.ifr_ifindex; status = bind(sock, (struct sockaddr*)&addr, sizeof(addr) ); if (status != 0) { - gpsd_report(LOG_ERROR, "NMEA2000 open: bind failed.\n"); + gpsd_report(session->context->debug, LOG_ERROR, "NMEA2000 open: bind failed.\n"); close(sock); return -1; } @@ -1234,7 +1284,8 @@ int nmea2000_open(struct gps_device_t *session) void nmea2000_close(struct gps_device_t *session) { if (!BAD_SOCKET(session->gpsdata.gps_fd)) { - gpsd_report(LOG_SPIN, "close(%d) in nmea2000_close(%s)\n", + gpsd_report(session->context->debug, LOG_SPIN, + "close(%d) in nmea2000_close(%s)\n", session->gpsdata.gps_fd, session->gpsdata.dev.path); (void)close(session->gpsdata.gps_fd); INVALIDATE_SOCKET(session->gpsdata.gps_fd); diff --git a/driver_oncore.c b/driver_oncore.c index 1cdefa5d..cf383a72 100644 --- a/driver_oncore.c +++ b/driver_oncore.c @@ -80,7 +80,7 @@ oncore_msg_navsol(struct gps_device_t *session, unsigned char *buf, return 0; mask = ONLINE_SET; - gpsd_report(LOG_IO, "oncore NAVSOL - navigation data\n"); + gpsd_report(session->context->debug, LOG_IO, "oncore NAVSOL - navigation data\n"); flags = (unsigned char)getub(buf, 72); @@ -92,7 +92,7 @@ oncore_msg_navsol(struct gps_device_t *session, unsigned char *buf, session->gpsdata.status = STATUS_FIX; session->newdata.mode = MODE_2D; } else { - gpsd_report(LOG_WARN, "oncore NAVSOL no fix - flags 0x%02x\n", flags); + gpsd_report(session->context->debug, LOG_WARN, "oncore NAVSOL no fix - flags 0x%02x\n", flags); session->newdata.mode = MODE_NO_FIX; session->gpsdata.status = STATUS_NO_FIX; } @@ -116,7 +116,7 @@ oncore_msg_navsol(struct gps_device_t *session, unsigned char *buf, session->newdata.time = (timestamp_t)timegm(&unpacked_date) + nsec * 1e-9; /*@ +unrecog */ mask |= TIME_SET; - gpsd_report(LOG_IO, + gpsd_report(session->context->debug, LOG_IO, "oncore NAVSOL - time: %04d-%02d-%02d %02d:%02d:%02d.%09d\n", unpacked_date.tm_year + 1900, unpacked_date.tm_mon + 1, unpacked_date.tm_mday, unpacked_date.tm_hour, @@ -132,7 +132,7 @@ oncore_msg_navsol(struct gps_device_t *session, unsigned char *buf, dop = getbeu16(buf, 35) / 10.0f; /*@+type@*/ - gpsd_report(LOG_IO, + gpsd_report(session->context->debug, LOG_IO, "oncore NAVSOL - %lf %lf %.2lfm-%.2lfm | %.2fm/s %.1fdeg dop=%.1f\n", lat, lon, alt, wgs84_separation(lat, lon), speed, track, (float)dop); @@ -161,7 +161,7 @@ oncore_msg_navsol(struct gps_device_t *session, unsigned char *buf, sn = (int)getub(buf, off + 2); status = (int)getub(buf, off + 3); - gpsd_report(LOG_IO, "%2d %2d %2d %3d %02x\n", i, sv, mode, sn, + gpsd_report(session->context->debug, LOG_IO, "%2d %2d %2d %3d %02x\n", i, sv, mode, sn, status); if (sn) { @@ -216,7 +216,7 @@ oncore_msg_navsol(struct gps_device_t *session, unsigned char *buf, (void)oncore_control_send(session, (char *)pollBo, sizeof(pollBo)); (void)oncore_control_send(session, (char *)pollEn, sizeof(pollEn)); - gpsd_report(LOG_DATA, + gpsd_report(session->context->debug, LOG_DATA, "NAVSOL: time=%.2f lat=%.2f lon=%.2f alt=%.2f speed=%.2f track=%.2f mode=%d status=%d visible=%d used=%d\n", session->newdata.time, session->newdata.latitude, session->newdata.longitude, session->newdata.altitude, @@ -239,7 +239,7 @@ oncore_msg_utc_offset(struct gps_device_t *session, unsigned char *buf, if (data_len != 8) return 0; - gpsd_report(LOG_IO, "oncore UTCTIME - leap seconds\n"); + gpsd_report(session->context->debug, LOG_IO, "oncore UTCTIME - leap seconds\n"); utc_offset = (int)getub(buf, 4); if (utc_offset == 0) return 0; /* that part of almanac not received yet */ @@ -261,7 +261,7 @@ oncore_msg_pps_offset(struct gps_device_t *session, unsigned char *buf, if (data_len != 11) return 0; - gpsd_report(LOG_IO, "oncore PPS offset\n"); + gpsd_report(session->context->debug, LOG_IO, "oncore PPS offset\n"); pps_offset_ns = (int)getbes32(buf, 4); session->driver.oncore.pps_offset_ns = pps_offset_ns; @@ -283,9 +283,9 @@ oncore_msg_svinfo(struct gps_device_t *session, unsigned char *buf, if (data_len != 92) return 0; - gpsd_report(LOG_IO, "oncore SVINFO - satellite data\n"); + gpsd_report(session->context->debug, LOG_IO, "oncore SVINFO - satellite data\n"); nchan = (unsigned int)getub(buf, 4); - gpsd_report(LOG_IO, "oncore SVINFO - %d satellites:\n", nchan); + gpsd_report(session->context->debug, LOG_IO, "oncore SVINFO - %d satellites:\n", nchan); /* Then we clamp the value to not read outside the table. */ if (nchan > 12) nchan = 12; @@ -298,7 +298,7 @@ oncore_msg_svinfo(struct gps_device_t *session, unsigned char *buf, el = (int)getub(buf, off + 3); az = (int)getbeu16(buf, off + 4); - gpsd_report(LOG_IO, "%2d %2d %2d %3d\n", i, sv, el, az); + gpsd_report(session->context->debug, LOG_IO, "%2d %2d %2d %3d\n", i, sv, el, az); /* Store for use when Ea messages come. */ session->driver.oncore.PRN[i] = sv; @@ -312,7 +312,7 @@ oncore_msg_svinfo(struct gps_device_t *session, unsigned char *buf, } } - gpsd_report(LOG_DATA, "SVINFO: mask={SATELLITE}\n"); + gpsd_report(session->context->debug, LOG_DATA, "SVINFO: mask={SATELLITE}\n"); return SATELLITE_SET; } @@ -329,7 +329,7 @@ oncore_msg_time_raim(struct gps_device_t *session UNUSED, return 0; sawtooth_ns = (int)getub(buf, 25); - gpsd_report(LOG_IO, "oncore PPS sawtooth: %d\n",sawtooth_ns); + gpsd_report(session->context->debug, LOG_IO, "oncore PPS sawtooth: %d\n",sawtooth_ns); /* session->driver.oncore.traim_sawtooth_ns = sawtooth_ns; */ @@ -363,7 +363,7 @@ gps_mask_t oncore_dispatch(struct gps_device_t * session, unsigned char *buf, type = ONCTYPE(buf[2], buf[3]); /* we may need to dump the raw packet */ - gpsd_report(LOG_RAW, "raw Oncore packet type 0x%04x\n", type); + gpsd_report(session->context->debug, LOG_RAW, "raw Oncore packet type 0x%04x\n", type); (void)snprintf(session->gpsdata.tag, sizeof(session->gpsdata.tag), "MOT-%c%c", type >> 8, type & 0xff); @@ -390,7 +390,7 @@ gps_mask_t oncore_dispatch(struct gps_device_t * session, unsigned char *buf, default: /* FIX-ME: This gets noisy in a hurry. Change once your driver works */ - gpsd_report(LOG_WARN, "unknown packet id @@%c%c length %zd\n", + gpsd_report(session->context->debug, LOG_WARN, "unknown packet id @@%c%c length %zd\n", type >> 8, type & 0xff, len); return 0; } @@ -424,7 +424,8 @@ static ssize_t oncore_control_send(struct gps_device_t *session, session->msgbuf[msglen + 4] = '\n'; session->msgbuflen = msglen + 5; - gpsd_report(LOG_IO, "writing oncore control type %c%c\n", msg[0], msg[1]); + gpsd_report(session->context->debug, LOG_IO, + "writing oncore control type %c%c\n", msg[0], msg[1]); return gpsd_write(session, session->msgbuf, session->msgbuflen); } diff --git a/driver_proto.c b/driver_proto.c index 2ef2bf7c..e6cc9ceb 100644 --- a/driver_proto.c +++ b/driver_proto.c @@ -72,7 +72,7 @@ _proto__msg_navsol(struct gps_device_t *session, unsigned char *buf, size_t data if (data_len != _PROTO__NAVSOL_MSG_LEN) return 0; - gpsd_report(LOG_IO, "_proto_ NAVSOL - navigation data\n"); + gpsd_report(session->context->debug, LOG_IO, "_proto_ NAVSOL - navigation data\n"); /* if this protocol has a way to test message validity, use it */ flags = GET_FLAGS(); if ((flags & _PROTO__SOLUTION_VALID) == 0) @@ -120,7 +120,7 @@ _proto__msg_navsol(struct gps_device_t *session, unsigned char *buf, size_t data * the fields it potentially set and the transfer mask. Doing this * makes it relatively easy to track down data-management problems. */ - gpsd_report(LOG_DATA, "NAVSOL: time=%.2f, lat=%.2f lon=%.2f alt=%.2f mode=%d status=%d\n", + gpsd_report(session->context->debug, LOG_DATA, "NAVSOL: time=%.2f, lat=%.2f lon=%.2f alt=%.2f mode=%d status=%d\n", session->newdata.time, session->newdata.latitude, session->newdata.longitude, @@ -142,7 +142,7 @@ _proto__msg_utctime(struct gps_device_t *session, unsigned char *buf, size_t dat if (data_len != UTCTIME_MSG_LEN) return 0; - gpsd_report(LOG_IO, "_proto_ UTCTIME - navigation data\n"); + gpsd_report(session->context->debug, LOG_IO, "_proto_ UTCTIME - navigation data\n"); /* if this protocol has a way to test message validity, use it */ flags = GET_FLAGS(); if ((flags & _PROTO__TIME_VALID) == 0) @@ -168,7 +168,7 @@ _proto__msg_svinfo(struct gps_device_t *session, unsigned char *buf, size_t data if (data_len != SVINFO_MSG_LEN ) return 0; - gpsd_report(LOG_IO, "_proto_ SVINFO - navigation data\n"); + gpsd_report(session->context->debug, LOG_IO, "_proto_ SVINFO - navigation data\n"); /* if this protocol has a way to test message validity, use it */ flags = GET_FLAGS(); if ((flags & _PROTO__SVINFO_VALID) == 0) @@ -183,7 +183,7 @@ _proto__msg_svinfo(struct gps_device_t *session, unsigned char *buf, size_t data */ nchan = GET_NUMBER_OF_CHANNELS(); if ((nchan < 1) || (nchan > MAXCHANNELS)) { - gpsd_report(LOG_INF, "too many channels reported\n"); + gpsd_report(session->context->debug, LOG_INF, "too many channels reported\n"); return 0; } gpsd_zero_satellites(&session->gpsdata); @@ -207,7 +207,7 @@ _proto__msg_svinfo(struct gps_device_t *session, unsigned char *buf, size_t data session->gpsdata.skyview_time = NaN; session->gpsdata.satellites_used = nsv; session->gpsdata.satellites_visible = st; - gpsd_report(LOG_DATA, + gpsd_report(session->context->debug, LOG_DATA, "SVINFO: visible=%d used=%d mask={SATELLITE|USED}\n", session->gpsdata.satellites_visible, session->gpsdata.satellites_used); @@ -226,7 +226,7 @@ _proto__msg_raw(struct gps_device_t *session, unsigned char *buf, size_t data_le if (data_len != RAW_MSG_LEN ) return 0; - gpsd_report(LOG_IO, "_proto_ RAW - raw measurements\n"); + gpsd_report(session->context->debug, LOG_IO, "_proto_ RAW - raw measurements\n"); /* if this protocol has a way to test message validity, use it */ flags = GET_FLAGS(); if ((flags & _PROTO__SVINFO_VALID) == 0) @@ -241,7 +241,7 @@ _proto__msg_raw(struct gps_device_t *session, unsigned char *buf, size_t data_le */ nchan = GET_NUMBER_OF_CHANNELS(); if ((nchan < 1) || (nchan > MAXCHANNELS)) { - gpsd_report(LOG_INF, "too many channels reported\n"); + gpsd_report(session->context->debug, LOG_INF, "too many channels reported\n"); return 0; } @@ -285,7 +285,7 @@ gps_mask_t _proto__dispatch(struct gps_device_t *session, unsigned char *buf, si type = GET_MESSAGE_TYPE(); /* we may need to dump the raw packet */ - gpsd_report(LOG_RAW, "raw _proto_ packet type 0x%02x\n", type); + gpsd_report(session->context->debug, LOG_RAW, "raw _proto_ packet type 0x%02x\n", type); /* * The tag field is only 8 bytes; be careful you do not overflow. @@ -299,7 +299,7 @@ gps_mask_t _proto__dispatch(struct gps_device_t *session, unsigned char *buf, si /* Deliver message to specific decoder based on message type */ default: - gpsd_report(LOG_WARN, "unknown packet id %d length %d\n", type, len); + gpsd_report(session->context->debug, LOG_WARN, "unknown packet id %d length %d\n", type, len); return 0; } } @@ -349,7 +349,7 @@ static ssize_t _proto__control_send(struct gps_device_t *session, /* we may need to dump the message */ return gpsd_write(session, session->msgbuf, session->msgbuflen); - gpsd_report(LOG_IO, "writing _proto_ control type %02x\n"); + gpsd_report(session->context->debug, LOG_IO, "writing _proto_ control type %02x\n"); return gpsd_write(session, session->msgbuf, session->msgbuflen); } /*@ -charint +usedef +compdef @*/ diff --git a/driver_rtcm3.c b/driver_rtcm3.c index 90fbdae5..f5e6f832 100644 --- a/driver_rtcm3.c +++ b/driver_rtcm3.c @@ -65,7 +65,8 @@ BSD terms apply: see the file COPYING in the distribution root for details. /* *INDENT-OFF* */ /*@ -type @*//* re-enable when we're ready to take this live */ -void rtcm3_unpack( /*@out@*/ struct rtcm3_t *rtcm, char *buf) +void rtcm3_unpack(const int debug, + /*@out@*/ struct rtcm3_t *rtcm, char *buf) /* break out the raw bits into the scaled report-structure fields */ { unsigned int n, n2, n3, n4; @@ -96,7 +97,7 @@ void rtcm3_unpack( /*@out@*/ struct rtcm3_t *rtcm, char *buf) rtcm->length = (uint)ugrab(10); rtcm->type = (uint)ugrab(12); - gpsd_report(LOG_RAW, "RTCM3: type %d payload length %d\n", + gpsd_report(debug, LOG_RAW, "RTCM3: type %d payload length %d\n", rtcm->type, rtcm->length); switch (rtcm->type) { diff --git a/driver_sirf.c b/driver_sirf.c index fbb6a4b8..3cc9c7d0 100644 --- a/driver_sirf.c +++ b/driver_sirf.c @@ -195,8 +195,8 @@ static unsigned char enablemid52[] = { /*@ -charint @*/ -static gps_mask_t sirf_msg_debug(unsigned char *, size_t); -static gps_mask_t sirf_msg_errors(unsigned char *, size_t); +static gps_mask_t sirf_msg_debug(unsigned char *, size_t, const int); +static gps_mask_t sirf_msg_errors(unsigned char *, size_t, const int); static gps_mask_t sirf_msg_navdata(struct gps_device_t *, unsigned char *, size_t); @@ -236,7 +236,8 @@ static bool sirf_write(struct gps_device_t *session, unsigned char *msg) msg[len + 4] = (unsigned char)((crc & 0xff00) >> 8); msg[len + 5] = (unsigned char)(crc & 0x00ff); - gpsd_report(LOG_IO, "SiRF: Writing control type %02x:\n", msg[4]); + gpsd_report(session->context->debug, + LOG_IO, "SiRF: Writing control type %02x:\n", msg[4]); ok = (gpsd_write(session, (const char *)msg, len+8) == (ssize_t) (len+8)); return (ok); } @@ -281,10 +282,12 @@ static bool sirfbin_speed(struct gps_device_t *session, speed_t speed, char pari 0x00, 0x00, 0xb0, 0xb3 }; /*@ -charint @*/ - gpsd_report(LOG_PROG, "SiRF: sirf_speed(%d,%c,%d)\n", + gpsd_report(session->context->debug, LOG_PROG, + "SiRF: sirf_speed(%d,%c,%d)\n", speed, parity, stopbits); if (9600 >= speed) { - gpsd_report(LOG_WARN, "SiRF may lag at 9600bps or less.\n"); + gpsd_report(session->context->debug, LOG_WARN, + "SiRF may lag at 9600bps or less.\n"); } switch (parity) { @@ -334,7 +337,8 @@ static bool sirf_to_nmea(struct gps_device_t *session, speed_t speed) /*@ -charint @*/ if (speed >= 0xffff) { - gpsd_report(LOG_ERROR, "SiRF: can't switch from SiRF to NMEA because current speed %u is big.", + gpsd_report(session->context->debug, LOG_ERROR, + "SiRF: can't switch from SiRF to NMEA because current speed %u is big.", speed); return false; } @@ -388,7 +392,8 @@ static ssize_t sirf_get(struct gps_device_t *session) (void)gpsd_switch_driver(session, "Generic NMEA"); } else { /* should never happen */ - gpsd_report(LOG_PROG, "SiRF: Unexpected packet type %d\n", + gpsd_report(session->context->debug, LOG_PROG, + "SiRF: Unexpected packet type %d\n", session->packet.type); (void)gpsd_switch_driver(session, "Generic NMEA"); } @@ -396,7 +401,8 @@ static ssize_t sirf_get(struct gps_device_t *session) return len; } -static gps_mask_t sirf_msg_debug(unsigned char *buf, size_t len) +static gps_mask_t sirf_msg_debug(unsigned char *buf, size_t len, + const int debug) { char msgbuf[MAX_PACKET_LENGTH * 3 + 2]; int i; @@ -409,7 +415,7 @@ static gps_mask_t sirf_msg_debug(unsigned char *buf, size_t len) (void)snprintf(msgbuf + strlen(msgbuf), sizeof(msgbuf) - strlen(msgbuf), "%c", buf[i] ^ 0xff); - gpsd_report(LOG_PROG, "SiRF: DEV 0xe1: %s\n", msgbuf); + gpsd_report(debug, LOG_PROG, "SiRF: DEV 0xe1: %s\n", msgbuf); } else if (0xff == (unsigned char)buf[0]) { /* Debug messages */ for (i = 1; i < (int)len; i++) if (isprint(buf[i])) @@ -419,28 +425,30 @@ static gps_mask_t sirf_msg_debug(unsigned char *buf, size_t len) (void)snprintf(msgbuf + strlen(msgbuf), sizeof(msgbuf) - strlen(msgbuf), "\\x%02x", (unsigned int)buf[i]); - gpsd_report(LOG_PROG, "SiRF: DBG 0xff: %s\n", msgbuf); + gpsd_report(debug, LOG_PROG, "SiRF: DBG 0xff: %s\n", msgbuf); } /*@ -charint @*/ return 0; } -static gps_mask_t sirf_msg_errors(unsigned char *buf, size_t len UNUSED) +static gps_mask_t sirf_msg_errors(unsigned char *buf, size_t len UNUSED, + const int debug) { switch (getbeu16(buf, 1)) { case 2: - gpsd_report(LOG_PROG, + gpsd_report(debug, LOG_PROG, "SiRF: EID 0x0a type 2: Subframe %u error on PRN %u\n", getbeu32(buf, 9), getbeu32(buf, 5)); break; case 4107: - gpsd_report(LOG_PROG, + gpsd_report(debug, LOG_PROG, "SiRF: EID 0x0a type 4107: neither KF nor LSQ fix.\n"); break; default: - gpsd_report(LOG_PROG, "SiRF: EID 0x0a: Error MID %d\n", + gpsd_report(debug, LOG_PROG, + "SiRF: EID 0x0a: Error MID %d\n", getbeu16(buf, 1)); break; } @@ -448,7 +456,7 @@ static gps_mask_t sirf_msg_errors(unsigned char *buf, size_t len UNUSED) } /* Navigation Library Measurement Data MID 28 */ -static gps_mask_t sirf_msg_nlmd(struct gps_device_t *session UNUSED, +static gps_mask_t sirf_msg_nlmd(struct gps_device_t *session, unsigned char *buf UNUSED, size_t len) { @@ -461,7 +469,8 @@ static gps_mask_t sirf_msg_nlmd(struct gps_device_t *session UNUSED, * different double orders, neither IEEE754 */ /* FIXME - decode the time, since this is the first MID with a * good time stamp this will be good for ntpshm time */ - gpsd_report(LOG_PROG, "SiRF: MID 0x1c, NLMD, gps_tow: %f\n", + gpsd_report(session->context->debug, LOG_PROG, + "SiRF: MID 0x1c, NLMD, gps_tow: %f\n", (double)gps_tow); return 0; @@ -493,13 +502,16 @@ static gps_mask_t sirf_msg_swversion(struct gps_device_t *session, session->driver.sirf.driverstate |= SIRF_GE_232; } if (strstr((char *)(buf + 1), "ES")) - gpsd_report(LOG_INF, "SiRF: Firmware has XTrac capability\n"); - gpsd_report(LOG_PROG, "SiRF: fv: %0.2f, Driver state flags are: %0x\n", + gpsd_report(session->context->debug, LOG_INF, + "SiRF: Firmware has XTrac capability\n"); + gpsd_report(session->context->debug, LOG_PROG, + "SiRF: fv: %0.2f, Driver state flags are: %0x\n", fv, session->driver.sirf.driverstate); #ifdef NTPSHM_ENABLE session->driver.sirf.time_seen = 0; #endif /* NTPSHM_ENABLE */ - gpsd_report(LOG_DATA, "SiRF: FV MID 0x06: subtype='%s' mask={DEVICEID}\n", + gpsd_report(session->context->debug, LOG_DATA, + "SiRF: FV MID 0x06: subtype='%s' mask={DEVICEID}\n", session->subtype); return DEVICEID_SET; } @@ -520,12 +532,13 @@ static gps_mask_t sirf_msg_navdata(struct gps_device_t *session, words[i] = (uint32_t)getbeu32(buf, 4 * i + 3); } - gpsd_report(LOG_IO, "SiRF: NavData chan %u svid %u\n",chan,svid); + gpsd_report(session->context->debug, LOG_IO, + "SiRF: NavData chan %u svid %u\n",chan,svid); #ifdef RECONFIGURE_ENABLE if (!session->context->readonly && session->gpsdata.dev.baudrate < 38400) { /* some USB are also too slow, no way to tell which ones */ - gpsd_report(LOG_WARN, + gpsd_report(session->context->debug, LOG_WARN, "WARNING: SiRF: link too slow, disabling subframes.\n"); (void)sirf_write(session, disablesubframe); } @@ -566,7 +579,7 @@ static gps_mask_t sirf_msg_svinfo(struct gps_device_t *session, session->gpsdata.azimuth[st] != 0 && session->gpsdata.elevation[st] != 0; #ifdef __UNUSED__ - gpsd_report(LOG_PROG, + gpsd_report(session->context->debug, LOG_PROG, "SiRF: PRN=%2d El=%3.2f Az=%3.2f ss=%3d stat=%04x %c\n", getub(buf, off), getub(buf, off + 2) / 2.0, @@ -587,18 +600,19 @@ static gps_mask_t sirf_msg_svinfo(struct gps_device_t *session, } #ifdef NTPSHM_ENABLE if (st < 3) { - gpsd_report(LOG_PROG, + gpsd_report(session->context->debug, LOG_PROG, "SiRF: NTPD not enough satellites seen: %d\n", st); } else { /* SiRF says if 3 sats in view the time is good */ - gpsd_report(LOG_PROG, + gpsd_report(session->context->debug, LOG_PROG, "SiRF: NTPD valid time MID 0x04, seen=0x%02x, time:%.2lf, leap:%d\n", session->driver.sirf.time_seen, session->gpsdata.skyview_time, session->context->leap_seconds); } #endif /* NTPSHM_ENABLE */ - gpsd_report(LOG_DATA, "SiRF: MTD 0x04: visible=%d mask={SATELLITE}\n", + gpsd_report(session->context->debug, LOG_DATA, + "SiRF: MTD 0x04: visible=%d mask={SATELLITE}\n", session->gpsdata.satellites_visible); return SATELLITE_SET; } @@ -695,7 +709,7 @@ static gps_mask_t sirf_msg_navsol(struct gps_device_t *session, session->newdata.mode = MODE_2D; if (session->newdata.mode == MODE_3D) mask |= ALTITUDE_SET | CLIMB_SET; - gpsd_report(LOG_PROG, + gpsd_report(session->context->debug, LOG_PROG, "SiRF: MND 0x02: Navtype = 0x%0x, Status = %d, mode = %d\n", navtype, session->gpsdata.status, session->newdata.mode); /* byte 20 is HDOP, see below */ @@ -704,10 +718,11 @@ static gps_mask_t sirf_msg_navsol(struct gps_device_t *session, (unsigned short)getbes16(buf, 22), (double)getbeu32(buf, 24) * 1e-2); #ifdef NTPSHM_ENABLE if (session->newdata.mode <= MODE_NO_FIX) { - gpsd_report(LOG_PROG, "SiRF: NTPD no fix, mode: %d\n", + gpsd_report(session->context->debug, LOG_PROG, + "SiRF: NTPD no fix, mode: %d\n", session->newdata.mode); } else { - gpsd_report(LOG_PROG, + gpsd_report(session->context->debug, LOG_PROG, "SiRF: NTPD valid time MID 0x02, seen=0x%02x, time;%.2lf, leap:%d\n", session->driver.sirf.time_seen, session->newdata.time, session->context->leap_seconds); @@ -721,7 +736,7 @@ static gps_mask_t sirf_msg_navsol(struct gps_device_t *session, if ( 3 <= session->gpsdata.satellites_visible ) { mask |= PPSTIME_IS; } - gpsd_report(LOG_DATA, + gpsd_report(session->context->debug, LOG_DATA, "SiRF: MND 0x02: time=%.2f lat=%.2f lon=%.2f alt=%.2f track=%.2f speed=%.2f mode=%d status=%d hdop=%.2f used=%d\n", session->newdata.time, session->newdata.latitude, session->newdata.longitude, session->newdata.altitude, @@ -781,7 +796,7 @@ static gps_mask_t sirf_msg_geodetic(struct gps_device_t *session, session->newdata.mode = MODE_3D; else if (session->gpsdata.status) session->newdata.mode = MODE_2D; - gpsd_report(LOG_PROG, + gpsd_report(session->context->debug, LOG_PROG, "SiRF: GND 0x29: Navtype = 0x%0x, Status = %d, mode = %d\n", navtype, session->gpsdata.status, session->newdata.mode); mask |= STATUS_SET | MODE_SET; @@ -849,17 +864,20 @@ static gps_mask_t sirf_msg_geodetic(struct gps_device_t *session, /*@ -compdef -unrecog */ session->newdata.time = (timestamp_t)timegm(&unpacked_date) + subseconds; /*@ +compdef +unrecog */ - gpsd_report(LOG_PROG, "SiRF: GND 0x29 UTC: %lf\n", + gpsd_report(session->context->debug, LOG_PROG, + "SiRF: GND 0x29 UTC: %lf\n", session->newdata.time); #ifdef NTPSHM_ENABLE if (session->newdata.mode <= MODE_NO_FIX) { - gpsd_report(LOG_PROG, "SiRF: NTPD no fix, mode: $d\n", + gpsd_report(session->context->debug, LOG_PROG, + "SiRF: NTPD no fix, mode: $d\n", session->newdata.mode); } else if (0 == unpacked_date.tm_year) { - gpsd_report(LOG_PROG, "SiRF: NTPD no year\n", + gpsd_report(session->context->debug, LOG_PROG, + "SiRF: NTPD no year\n", session->newdata.mode); } else { - gpsd_report(LOG_PROG, + gpsd_report(session->context->debug, LOG_PROG, "SiRF: NTPD valid time MID 0x29, seen=0x%02x\n", session->driver.sirf.time_seen); } @@ -879,7 +897,7 @@ static gps_mask_t sirf_msg_geodetic(struct gps_device_t *session, if (session->newdata.mode == MODE_3D) mask |= ALTITUDE_SET | CLIMB_SET; } - gpsd_report(LOG_DATA, + gpsd_report(session->context->debug, LOG_DATA, "SiRF: GND 0x29: time=%.2f lat=%.2f lon=%.2f alt=%.2f track=%.2f speed=%.2f mode=%d status=%d\n", session->newdata.time, session->newdata.latitude, @@ -911,7 +929,8 @@ static gps_mask_t sirf_msg_sysparam(struct gps_device_t *session, session->driver.sirf.track_smooth_mode = (unsigned char)getub(buf, 12); #ifdef RECONFIGURE_ENABLE if (!session->context->readonly) { - gpsd_report(LOG_PROG, "SiRF: Setting Navigation Parameters\n"); + gpsd_report(session->context->debug, LOG_PROG, + "SiRF: Setting Navigation Parameters\n"); (void)sirf_write(session, modecontrol); } #endif /* RECONFIGURE_ENABLE */ @@ -960,7 +979,7 @@ static gps_mask_t sirf_msg_ublox(struct gps_device_t *session, session->newdata.mode = MODE_3D; else if (session->gpsdata.status) session->newdata.mode = MODE_2D; - gpsd_report(LOG_PROG, + gpsd_report(session->context->debug, LOG_PROG, "SiRF: EMND 0x62: Navtype = 0x%0x, Status = %d, mode = %d\n", navtype, session->gpsdata.status, session->newdata.mode); @@ -983,9 +1002,10 @@ static gps_mask_t sirf_msg_ublox(struct gps_device_t *session, /*@ +compdef */ #ifdef NTPSHM_ENABLE if (0 == (session->driver.sirf.time_seen & TIME_SEEN_UTC_2)) { - gpsd_report(LOG_RAW, "SiRF: NTPD just SEEN_UTC_2\n"); + gpsd_report(session->context->debug, LOG_RAW, + "SiRF: NTPD just SEEN_UTC_2\n"); } - gpsd_report(LOG_PROG, + gpsd_report(session->context->debug, LOG_PROG, "SiRF: NTPD valid time MID 0x62, seen=0x%02x\n", session->driver.sirf.time_seen); session->driver.sirf.time_seen |= TIME_SEEN_UTC_2; @@ -999,7 +1019,7 @@ static gps_mask_t sirf_msg_ublox(struct gps_device_t *session, session->gpsdata.dop.vdop = (int)getub(buf, 37) / 5.0; session->gpsdata.dop.tdop = (int)getub(buf, 38) / 5.0; session->driver.sirf.driverstate |= UBLOX; - gpsd_report(LOG_DATA, + gpsd_report(session->context->debug, LOG_DATA, "SiRF: EMD 0x62: time=%.2f lat=%.2f lon=%.2f alt=%.f speed=%.2f track=%.2f climb=%.2f mode=%d status=%d gdop=%.2f pdop=%.2f hdop=%.2f vdop=%.2f tdop=%.2f\n", session->newdata.time, session->newdata.latitude, session->newdata.longitude, session->newdata.altitude, @@ -1019,7 +1039,8 @@ static gps_mask_t sirf_msg_ppstime(struct gps_device_t *session, if (len != 19) return 0; - gpsd_report(LOG_PROG, "SiRF: PPS 0x34: Status = 0x%02x\n", + gpsd_report(session->context->debug, LOG_PROG, + "SiRF: PPS 0x34: Status = 0x%02x\n", getub(buf, 14)); if (((int)getub(buf, 14) & 0x07) == 0x07) { /* valid UTC time? */ struct tm unpacked_date; @@ -1036,9 +1057,10 @@ static gps_mask_t sirf_msg_ppstime(struct gps_device_t *session, session->context->valid |= LEAP_SECOND_VALID; #ifdef NTPSHM_ENABLE if (0 == (session->driver.sirf.time_seen & TIME_SEEN_UTC_2)) { - gpsd_report(LOG_RAW, "SiRF: NTPD just SEEN_UTC_2\n"); + gpsd_report(session->context->debug, LOG_RAW, + "SiRF: NTPD just SEEN_UTC_2\n"); } - gpsd_report(LOG_PROG, + gpsd_report(session->context->debug, LOG_PROG, "SiRF: NTPD valid time MID 0x34, seen=0x%02x, leap=%d\n", session->driver.sirf.time_seen, session->context->leap_seconds); @@ -1061,7 +1083,8 @@ gps_mask_t sirf_parse(struct gps_device_t * session, unsigned char *buf, buf += 4; len -= 8; - gpsd_report(LOG_RAW, "SiRF: Raw packet type 0x%02x\n", buf[0]); + gpsd_report(session->context->debug, LOG_RAW, + "SiRF: Raw packet type 0x%02x\n", buf[0]); (void)snprintf(session->gpsdata.tag, sizeof(session->gpsdata.tag), "MID%d", (int)buf[0]); @@ -1074,7 +1097,7 @@ gps_mask_t sirf_parse(struct gps_device_t * session, unsigned char *buf, return sirf_msg_navsol(session, buf, len) | (CLEAR_IS | REPORT_IS); else { - gpsd_report(LOG_PROG, + gpsd_report(session->context->debug, LOG_PROG, "SiRF: MND 0x02 skipped, uBlox flag is on.\n"); return 0; } @@ -1082,14 +1105,15 @@ gps_mask_t sirf_parse(struct gps_device_t * session, unsigned char *buf, return sirf_msg_svinfo(session, buf, len); case 0x05: /* Raw Tracker Data Out MID 5 */ - gpsd_report(LOG_PROG, "SiRF: unused Raw Tracker Data 0x05\n"); + gpsd_report(session->context->debug, LOG_PROG, + "SiRF: unused Raw Tracker Data 0x05\n"); return 0; case 0x06: /* Software Version String MID 6 */ return sirf_msg_swversion(session, buf, len); case 0x07: /* Clock Status Data MID 7 */ - gpsd_report(LOG_PROG, "SiRF: unused CLK 0x07\n"); + gpsd_report(session->context->debug, LOG_PROG, "SiRF: unused CLK 0x07\n"); return 0; case 0x08: /* subframe data MID 8 */ @@ -1107,7 +1131,7 @@ gps_mask_t sirf_parse(struct gps_device_t * session, unsigned char *buf, return sirf_msg_navdata(session, buf, len); case 0x09: /* CPU Throughput MID 9 */ - gpsd_report(LOG_PROG, + gpsd_report(session->context->debug, LOG_PROG, "SiRF: THR 0x09: SegStatMax=%.3f, SegStatLat=%3.f, AveTrkTime=%.3f, Last MS=%u\n", (float)getbeu16(buf, 1) / 186, (float)getbeu16(buf, 3) / 186, @@ -1115,34 +1139,37 @@ gps_mask_t sirf_parse(struct gps_device_t * session, unsigned char *buf, return 0; case 0x0a: /* Error ID Data MID 10 */ - return sirf_msg_errors(buf, len); + return sirf_msg_errors(buf, len, session->context->debug); case 0x0b: /* Command Acknowledgement MID 11 */ - gpsd_report(LOG_PROG, "SiRF: ACK 0x0b: %02x\n", getub(buf, 1)); + gpsd_report(session->context->debug, LOG_PROG, + "SiRF: ACK 0x0b: %02x\n", getub(buf, 1)); return 0; case 0x0c: /* Command NAcknowledgement MID 12 */ - gpsd_report(LOG_PROG, "SiRF: NAK 0x0c: %02x\n", getub(buf, 1)); + gpsd_report(session->context->debug, LOG_PROG, + "SiRF: NAK 0x0c: %02x\n", getub(buf, 1)); return 0; case 0x0d: /* Visible List MID 13 */ - gpsd_report(LOG_PROG, "SiRF: unused VIS 0x0d\n"); + gpsd_report(session->context->debug, LOG_PROG, "SiRF: unused VIS 0x0d\n"); return 0; case 0x0e: /* Almanac Data MID 14 */ - gpsd_report(LOG_PROG, "SiRF: unused ALM 0x0e\n"); + gpsd_report(session->context->debug, LOG_PROG, "SiRF: unused ALM 0x0e\n"); return 0; case 0x0f: /* Ephemeris Data MID 15 */ - gpsd_report(LOG_PROG, "SiRF: unused EPH 0x0f\n"); + gpsd_report(session->context->debug, LOG_PROG, "SiRF: unused EPH 0x0f\n"); return 0; case 0x11: /* Differential Corrections MID 17 */ - gpsd_report(LOG_PROG, "SiRF: unused DIFF 0x11\n"); + gpsd_report(session->context->debug, LOG_PROG, "SiRF: unused DIFF 0x11\n"); return 0; case 0x12: /* OK To Send MID 18 */ - gpsd_report(LOG_PROG, "SiRF: OTS 0x12: send indicator = %d\n", + gpsd_report(session->context->debug, LOG_PROG, + "SiRF: OTS 0x12: send indicator = %d\n", getub(buf, 1)); return 0; @@ -1153,27 +1180,28 @@ gps_mask_t sirf_parse(struct gps_device_t * session, unsigned char *buf, return sirf_msg_dgpsstatus(session, buf, len); case 0x1c: /* Navigation Library Measurement Data MID 28 */ - gpsd_report(LOG_PROG, "SiRF: NLMD 0x1c\n"); + gpsd_report(session->context->debug, LOG_PROG, + "SiRF: NLMD 0x1c\n"); return sirf_msg_nlmd(session, buf, len); case 0x1d: /* Navigation Library DGPS Data MID 29 */ - gpsd_report(LOG_PROG, "SiRF: unused NLDG 0x1d\n"); + gpsd_report(session->context->debug, LOG_PROG, "SiRF: unused NLDG 0x1d\n"); return 0; case 0x1e: /* Navigation Library SV State Data MID 30 */ - gpsd_report(LOG_PROG, "SiRF: unused NLSV 0x1e\n"); + gpsd_report(session->context->debug, LOG_PROG, "SiRF: unused NLSV 0x1e\n"); return 0; case 0x1f: /* Navigation Library Initialization Data MID 31 */ - gpsd_report(LOG_PROG, "SiRF: unused NLID 0x1f\n"); + gpsd_report(session->context->debug, LOG_PROG, "SiRF: unused NLID 0x1f\n"); return 0; case 0x29: /* Geodetic Navigation Data MID 41 */ - gpsd_report(LOG_PROG, "SiRF: unused GND 0x29\n"); + gpsd_report(session->context->debug, LOG_PROG, "SiRF: unused GND 0x29\n"); return 0; case 0x32: /* SBAS corrections MID 50 */ - gpsd_report(LOG_PROG, "SiRF: unused SBAS 0x32\n"); + gpsd_report(session->context->debug, LOG_PROG, "SiRF: unused SBAS 0x32\n"); return 0; case 0x34: /* PPS Time MID 52 */ @@ -1201,21 +1229,21 @@ gps_mask_t sirf_parse(struct gps_device_t * session, unsigned char *buf, return sirf_msg_ppstime(session, buf, len); case 0x62: /* uBlox Extended Measured Navigation Data MID 98 */ - gpsd_report(LOG_PROG, "SiRF: uBlox EMND 0x62\n"); + gpsd_report(session->context->debug, LOG_PROG, "SiRF: uBlox EMND 0x62\n"); return sirf_msg_ublox(session, buf, len) | (CLEAR_IS | REPORT_IS); case 0x80: /* Initialize Data Source MID 128 */ - gpsd_report(LOG_PROG, "SiRF: unused INIT 0x80\n"); + gpsd_report(session->context->debug, LOG_PROG, "SiRF: unused INIT 0x80\n"); return 0; case 0xe1: /* Development statistics messages MID 225 */ /* FALLTHROUGH */ case 0xff: /* Debug messages MID 255 */ - (void)sirf_msg_debug(buf, len); + (void)sirf_msg_debug(buf, len, session->context->debug); return 0; default: - gpsd_report(LOG_WARN, "SiRF: Unknown packet id %d length %zd\n", + gpsd_report(session->context->debug, LOG_WARN, "SiRF: Unknown packet id %d length %zd\n", buf[0], len); return 0; } @@ -1247,71 +1275,80 @@ static void sirfbin_event_hook(struct gps_device_t *session, event_t event) if (event == event_identified || event == event_reactivate) { if (session->packet.type == NMEA_PACKET) { - gpsd_report(LOG_PROG, "SiRF: Switching chip mode to binary.\n"); + gpsd_report(session->context->debug, LOG_PROG, + "SiRF: Switching chip mode to binary.\n"); (void)nmea_send(session, "$PSRF100,0,%d,8,1,0", session->gpsdata.dev.baudrate); (void)usleep(3330); /* guessed settling time */ } - gpsd_report(LOG_PROG, "SiRF: Probing for firmware version...\n"); + gpsd_report(session->context->debug, LOG_PROG, + "SiRF: Probing for firmware version...\n"); (void)sirf_write(session, versionprobe); (void)usleep(3330); /* guessed settling time */ - gpsd_report(LOG_PROG, "SiRF: Requesting navigation parameters...\n"); + gpsd_report(session->context->debug, LOG_PROG, + "SiRF: Requesting navigation parameters...\n"); (void)sirf_write(session, navparams); (void)usleep(3330); /* guessed settling time */ #ifdef RECONFIGURE_ENABLE - gpsd_report(LOG_PROG, "SiRF: Requesting periodic ecef reports...\n"); + gpsd_report(session->context->debug, LOG_PROG, + "SiRF: Requesting periodic ecef reports...\n"); (void)sirf_write(session, requestecef); (void)usleep(3330); /* guessed settling time */ - gpsd_report(LOG_PROG, "SiRF: Requesting periodic tracker reports...\n"); + gpsd_report(session->context->debug, LOG_PROG, + "SiRF: Requesting periodic tracker reports...\n"); (void)sirf_write(session, requesttracker); (void)usleep(3330); /* guessed settling time */ - gpsd_report(LOG_PROG, "SiRF: Setting DGPS control to use SBAS...\n"); + gpsd_report(session->context->debug, LOG_PROG, + "SiRF: Setting DGPS control to use SBAS...\n"); (void)sirf_write(session, dgpscontrol); (void)usleep(3330); /* guessed settling time */ - gpsd_report(LOG_PROG, "SiRF: Setting SBAS to auto/integrity mode...\n"); + gpsd_report(session->context->debug, LOG_PROG, + "SiRF: Setting SBAS to auto/integrity mode...\n"); (void)sirf_write(session, sbasparams); (void)usleep(3330); /* guessed settling time */ - gpsd_report(LOG_PROG, "SiRF: Enabling PPS message...\n"); + gpsd_report(session->context->debug, LOG_PROG, + "SiRF: Enabling PPS message...\n"); (void)sirf_write(session, enablemid52); (void)usleep(3330); /* guessed settling time */ if (session->gpsdata.dev.baudrate >= 38400) { /* some USB devices are also too slow, no way to tell which ones */ - gpsd_report(LOG_PROG, "SiRF: Enabling subframe transmission...\n"); + gpsd_report(session->context->debug, LOG_PROG, + "SiRF: Enabling subframe transmission...\n"); (void)sirf_write(session, enablesubframe); (void)usleep(3330); /* guessed settling time */ } /* disable some MIDs. we do not decode it, so don't send it */ - gpsd_report(LOG_PROG, "SiRF: unset MID 7...\n"); + gpsd_report(session->context->debug, LOG_PROG, "SiRF: unset MID 7...\n"); putbyte(unsetmidXX, 6, 0x11); (void)sirf_write(session, unsetmidXX); (void)usleep(3330); /* guessed settling time */ - gpsd_report(LOG_PROG, "SiRF: unset MID 28...\n"); + gpsd_report(session->context->debug, LOG_PROG, "SiRF: unset MID 28...\n"); putbyte(unsetmidXX, 6, 0x1c); (void)sirf_write(session, unsetmidXX); (void)usleep(3330); /* guessed settling time */ - gpsd_report(LOG_PROG, "SiRF: unset MID 29...\n"); + gpsd_report(session->context->debug, LOG_PROG, "SiRF: unset MID 29...\n"); putbyte(unsetmidXX, 6, 0x1d); (void)sirf_write(session, unsetmidXX); (void)usleep(3330); /* guessed settling time */ - gpsd_report(LOG_PROG, "SiRF: unset MID 30...\n"); + gpsd_report(session->context->debug, LOG_PROG, "SiRF: unset MID 30...\n"); putbyte(unsetmidXX, 6, 0x1e); (void)sirf_write(session, unsetmidXX); (void)usleep(3330); /* guessed settling time */ - gpsd_report(LOG_PROG, "SiRF: unset MID 31...\n"); + gpsd_report(session->context->debug, LOG_PROG, "SiRF: unset MID 31...\n"); putbyte(unsetmidXX, 6, 0x1f); (void)sirf_write(session, unsetmidXX); (void)usleep(3330); /* guessed settling time */ @@ -1344,7 +1381,8 @@ static void sirfbin_event_hook(struct gps_device_t *session, event_t event) putbyte(moderevert, 16, session->driver.sirf.dr_timeout); putbyte(moderevert, 17, session->driver.sirf.track_smooth_mode); /*@ +shiftimplementation @*/ - gpsd_report(LOG_PROG, "SiRF: Reverting navigation parameters...\n"); + gpsd_report(session->context->debug, LOG_PROG, + "SiRF: Reverting navigation parameters...\n"); (void)sirf_write(session, moderevert); } } diff --git a/driver_superstar2.c b/driver_superstar2.c index b92340e2..64bbd97e 100644 --- a/driver_superstar2.c +++ b/driver_superstar2.c @@ -50,11 +50,11 @@ static void superstar2_set_mode(struct gps_device_t *, int); * Decode the message ACK message */ static gps_mask_t -superstar2_msg_ack(struct gps_device_t *session UNUSED, +superstar2_msg_ack(struct gps_device_t *session, unsigned char *buf, size_t data_len) { if (data_len == 11) - gpsd_report(LOG_PROG, + gpsd_report(session->context->debug, LOG_PROG, "superstar2 #126 - " "ACK %d %d %d %d %d\n", buf[5], buf[6], buf[7], buf[8], buf[9]); @@ -80,7 +80,8 @@ superstar2_msg_navsol_lla(struct gps_device_t *session, if (data_len != 77) return 0; - gpsd_report(LOG_PROG, "superstar2 #20 - user navigation data\n"); + gpsd_report(session->context->debug, LOG_PROG, + "superstar2 #20 - user navigation data\n"); mask = 0; /*@ +charint @*/ @@ -141,7 +142,7 @@ superstar2_msg_navsol_lla(struct gps_device_t *session, } mask |= MODE_SET | STATUS_SET; - gpsd_report(LOG_DATA, + gpsd_report(session->context->debug, LOG_DATA, "NAVSOL_LLA: time=%.2f lat=%.2f lon=%.2f alt=%.2f track=%.2f speed=%.2f climb=%.2f mode=%d status=%d hdop=%.2f hdop=%.2f used=%d\n", session->newdata.time, session->newdata.latitude, @@ -170,7 +171,8 @@ superstar2_msg_svinfo(struct gps_device_t *session, if (data_len != 67) return 0; - gpsd_report(LOG_PROG, "superstar2 #33 - satellite data\n"); + gpsd_report(session->context->debug, LOG_PROG, + "superstar2 #33 - satellite data\n"); nchan = 12; gpsd_zero_satellites(&session->gpsdata); @@ -199,7 +201,7 @@ superstar2_msg_svinfo(struct gps_device_t *session, session->gpsdata.skyview_time = NAN; session->gpsdata.satellites_used = nsv; session->gpsdata.satellites_visible = st; - gpsd_report(LOG_DATA, + gpsd_report(session->context->debug, LOG_DATA, "SVINFO: visible=%d used=%d mask={SATELLITE|USED}\n", session->gpsdata.satellites_visible, session->gpsdata.satellites_used); @@ -224,12 +226,13 @@ superstar2_msg_version(struct gps_device_t *session, (void)snprintf(boot_sw, 15, "%s", (char *)buf + 36); (void)snprintf(ser_num, 14, "%s", (char *)buf + 73); - gpsd_report(LOG_PROG, + gpsd_report(session->context->debug, LOG_PROG, "superstar2 #45 - " "hw part %s boot sw %s main sw %s ser num %s\n", hw_part, boot_sw, main_sw, ser_num); (void)strlcpy(session->subtype, main_sw, sizeof(session->subtype)); - gpsd_report(LOG_DATA, "VERSION: subtype='%s' mask={DEVEICEID}\n", + gpsd_report(session->context->debug, LOG_DATA, + "VERSION: subtype='%s' mask={DEVEICEID}\n", session->subtype); return DEVICEID_SET; } @@ -247,7 +250,8 @@ superstar2_msg_timing(struct gps_device_t *session, unsigned char *buf, if (data_len != 65) return 0; - gpsd_report(LOG_PROG, "superstar2 #113 - timing status\n"); + gpsd_report(session->context->debug, LOG_PROG, + "superstar2 #113 - timing status\n"); /*@ +charint @*/ if ((getub(buf, 55) & 0x30) != 0) mask = 0; @@ -268,7 +272,8 @@ superstar2_msg_timing(struct gps_device_t *session, unsigned char *buf, session->context->leap_seconds = (int)getsb(buf, 20); mask = TIME_SET | PPSTIME_IS; } - gpsd_report(LOG_DATA, "TIMING: time=%.2f mask={TIME}\n", + gpsd_report(session->context->debug, LOG_DATA, + "TIMING: time=%.2f mask={TIME}\n", session->newdata.time); return mask; } @@ -285,11 +290,13 @@ superstar2_msg_measurement(struct gps_device_t *session, unsigned char *buf, unsigned long ul; double t; - gpsd_report(LOG_PROG, "superstar2 #23 - measurement block\n"); + gpsd_report(session->context->debug, LOG_PROG, + "superstar2 #23 - measurement block\n"); n = (int)getub(buf, 6); /* number of measurements */ if ((n < 1) || (n > MAXCHANNELS)) { - gpsd_report(LOG_INF, "too many measurements\n"); + gpsd_report(session->context->debug, LOG_INF, + "too many measurements\n"); return 0; } t = getled64((char *)buf, 7); /* measurement time */ @@ -328,7 +335,7 @@ superstar2_msg_iono_utc(struct gps_device_t *session, unsigned char *buf, i = (unsigned int)getub(buf, 12); u = (unsigned int)getub(buf, 21); - gpsd_report(LOG_PROG, + gpsd_report(session->context->debug, LOG_PROG, "superstar2 #75 - ionospheric & utc data: iono %s utc %s\n", i ? "ok" : "bad", u ? "ok" : "bad"); session->driver.superstar2.last_iono = time(NULL); @@ -346,7 +353,8 @@ superstar2_msg_ephemeris(struct gps_device_t *session, unsigned char *buf, { unsigned int prn; prn = (unsigned int)(getub(buf, 4) & 0x1f); - gpsd_report(LOG_PROG, "superstar2 #22 - ephemeris data - prn %u\n", prn); + gpsd_report(session->context->debug, LOG_PROG, + "superstar2 #22 - ephemeris data - prn %u\n", prn); /* ephemeris data updates fairly slowly, but when it does, poll UTC */ if ((time(NULL) - session->driver.superstar2.last_iono) > 60) @@ -368,7 +376,8 @@ superstar2_write(struct gps_device_t *session, char *msg, size_t msglen) c += 0x100; msg[(int)msg[3] + 4] = (char)((c >> 8) & 0xff); msg[(int)msg[3] + 5] = (char)(c & 0xff); - gpsd_report(LOG_IO, "writing superstar2 control type %d len %zu\n", + gpsd_report(session->context->debug, LOG_IO, + "writing superstar2 control type %d len %zu\n", (int)msg[1] & 0x7f, msglen); return gpsd_write(session, msg, msglen); } @@ -411,7 +420,7 @@ superstar2_dispatch(struct gps_device_t * session, unsigned char *buf, return superstar2_msg_ephemeris(session, buf, len); default: - gpsd_report(LOG_WARN, + gpsd_report(session->context->debug, LOG_WARN, "unknown superstar2 packet id 0x%02x length %zd\n", type, len); return 0; diff --git a/driver_tsip.c b/driver_tsip.c index 35b3c76b..1913f808 100644 --- a/driver_tsip.c +++ b/driver_tsip.c @@ -55,7 +55,7 @@ static int tsip_write(struct gps_device_t *session, *ep++ = '\x03'; session->msgbuflen = (size_t) (ep - session->msgbuf); /*@ -charint @*/ - gpsd_report(LOG_IO, "Sent TSIP packet id 0x%02x\n", id); + gpsd_report(session->context->debug, LOG_IO, "Sent TSIP packet id 0x%02x\n", id); if (gpsd_write(session, session->msgbuf, session->msgbuflen) != (ssize_t) session->msgbuflen) return -1; @@ -103,7 +103,8 @@ static bool tsip_detect(struct gps_device_t *session) break; if (generic_get(session) >= 0) { if (session->packet.type == TSIP_PACKET) { - gpsd_report(LOG_RAW, "tsip_detect found\n"); + gpsd_report(session->context->debug, LOG_RAW, + "tsip_detect found\n"); ret = true; break; } @@ -134,7 +135,7 @@ static gps_mask_t tsip_analyze(struct gps_device_t *session) char buf2[BUFSIZ]; if (session->packet.type != TSIP_PACKET) { - gpsd_report(LOG_INF, "tsip_analyze packet type %d\n", + gpsd_report(session->context->debug, LOG_INF, "tsip_analyze packet type %d\n", session->packet.type); return 0; } @@ -161,8 +162,9 @@ static gps_mask_t tsip_analyze(struct gps_device_t *session) (void)snprintf(session->gpsdata.tag, sizeof(session->gpsdata.tag), "ID%02x", id = (unsigned)session->packet.outbuffer[1]); - gpsd_report(LOG_IO, "TSIP packet id 0x%02x length %d: %s\n", id, len, - buf2); + gpsd_report(session->context->debug, LOG_IO, + "TSIP packet id 0x%02x length %d: %s\n", + id, len, buf2); (void)time(&now); session->cycle_end_reliable = true; @@ -170,11 +172,12 @@ static gps_mask_t tsip_analyze(struct gps_device_t *session) case 0x13: /* Packet Received */ u1 = getub(buf, 0); u2 = getub(buf, 1); - gpsd_report(LOG_WARN, + gpsd_report(session->context->debug, LOG_WARN, "Received packet of type %02x cannot be parsed\n", u1); #if USE_SUPERPACKET if ((int)u1 == 0x8e && (int)u2 == 0x23) { /* no Compact Super Packet */ - gpsd_report(LOG_WARN, "No Compact Super Packet, use LFwEI\n"); + gpsd_report(session->context->debug, LOG_WARN, + "No Compact Super Packet, use LFwEI\n"); /* Request LFwEI Super Packet */ putbyte(buf, 0, 0x20); @@ -210,7 +213,8 @@ static gps_mask_t tsip_analyze(struct gps_device_t *session) "sw %u %u %u %02u.%02u.%04u %s", u2, u3, u4, u6, u5, s1, buf2); /*@ +formattype @*/ - gpsd_report(LOG_INF, "Software version: %s\n", + gpsd_report(session->context->debug, LOG_INF, + "Software version: %s\n", session->subtype); mask |= DEVICEID_SET; @@ -235,14 +239,16 @@ static gps_mask_t tsip_analyze(struct gps_device_t *session) (void)snprintf(session->subtype, sizeof(session->subtype), "hw %u %02u.%02u.%04u %02u %u %s", ul1, u2, u3, s1, u4, s2, buf2); - gpsd_report(LOG_INF, "Hardware version: %s\n", + gpsd_report(session->context->debug, LOG_INF, + "Hardware version: %s\n", session->subtype); mask |= DEVICEID_SET; /* Detecting device by Hardware Code */ if (s2 == 3001) { - gpsd_report(LOG_INF, "This device is Accutime Gold\n"); + gpsd_report(session->context->debug, LOG_INF, + "This device is Accutime Gold\n"); session->driver.tsip.subtype = TSIP_ACCUTIME_GOLD; configuration_packets_accutime_gold(session); } @@ -266,7 +272,8 @@ static gps_mask_t tsip_analyze(struct gps_device_t *session) gpsd_gpstime_resolve(session, (unsigned short)s1, (double)f1); mask |= TIME_SET | PPSTIME_IS; } - gpsd_report(LOG_INF, "GPS Time %f %d %f\n", f1, s1, f2); + gpsd_report(session->context->debug, LOG_INF, + "GPS Time %f %d %f\n", f1, s1, f2); break; case 0x42: /* Single-Precision Position Fix, XYZ ECEF */ if (len != 16) @@ -275,8 +282,8 @@ static gps_mask_t tsip_analyze(struct gps_device_t *session) f2 = getbef32((char *)buf, 4); /* Y */ f3 = getbef32((char *)buf, 8); /* Z */ f4 = getbef32((char *)buf, 12); /* time-of-fix */ - gpsd_report(LOG_INF, "GPS Position XYZ %f %f %f %f\n", f1, f2, f3, - f4); + gpsd_report(session->context->debug, LOG_INF, + "GPS Position XYZ %f %f %f %f\n", f1, f2, f3, f4); break; case 0x43: /* Velocity Fix, XYZ ECEF */ if (len != 20) @@ -286,7 +293,8 @@ static gps_mask_t tsip_analyze(struct gps_device_t *session) f3 = getbef32((char *)buf, 8); /* Z velocity */ f4 = getbef32((char *)buf, 12); /* bias rate */ f5 = getbef32((char *)buf, 16); /* time-of-fix */ - gpsd_report(LOG_INF, "GPS Velocity XYZ %f %f %f %f %f\n", f1, f2, f3, + gpsd_report(session->context->debug, LOG_INF, + "GPS Velocity XYZ %f %f %f %f %f\n", f1, f2, f3, f4, f5); break; case 0x45: /* Software Version Information */ @@ -295,13 +303,19 @@ static gps_mask_t tsip_analyze(struct gps_device_t *session) /*@ -formattype @*/ (void)snprintf(session->subtype, sizeof(session->subtype), "%d.%d %02d%02d%02d %d.%d %02d%02d%02d", - getub(buf, 0), getub(buf, 1), getub(buf, 4), getub(buf, - 2), - getub(buf, 3), getub(buf, 5), getub(buf, 6), getub(buf, - 9), - getub(buf, 7), getub(buf, 8)); + getub(buf, 0), + getub(buf, 1), + getub(buf, 4), + getub(buf, 2), + getub(buf, 3), + getub(buf, 5), + getub(buf, 6), + getub(buf, 9), + getub(buf, 7), + getub(buf, 8)); /*@ +formattype @*/ - gpsd_report(LOG_INF, "Software version: %s\n", session->subtype); + gpsd_report(session->context->debug, LOG_INF, + "Software version: %s\n", session->subtype); mask |= DEVICEID_SET; break; case 0x46: /* Health of Receiver */ @@ -319,7 +333,8 @@ static gps_mask_t tsip_analyze(struct gps_device_t *session) mask |= STATUS_SET; } } - gpsd_report(LOG_PROG, "Receiver health %02x %02x\n", u1, u2); + gpsd_report(session->context->debug, LOG_PROG, + "Receiver health %02x %02x\n", u1, u2); break; case 0x47: /* Signal Levels for all Satellites */ gpsd_zero_satellites(&session->gpsdata); @@ -339,12 +354,14 @@ static gps_mask_t tsip_analyze(struct gps_device_t *session) (void)snprintf(buf2 + strlen(buf2), sizeof(buf2) - strlen(buf2), " %d=%.1f", (int)u1, f1); } - gpsd_report(LOG_PROG, "Signal Levels (%d):%s\n", count, buf2); + gpsd_report(session->context->debug, LOG_PROG, + "Signal Levels (%d):%s\n", count, buf2); mask |= SATELLITE_SET; break; case 0x48: /* GPS System Message */ buf[len] = '\0'; - gpsd_report(LOG_PROG, "GPS System Message: %s\n", buf); + gpsd_report(session->context->debug, LOG_PROG, + "GPS System Message: %s\n", buf); break; case 0x49: /* Almanac Health Page */ break; @@ -364,8 +381,8 @@ static gps_mask_t tsip_analyze(struct gps_device_t *session) mask |= TIME_SET | PPSTIME_IS; } mask |= LATLON_SET | ALTITUDE_SET | CLEAR_IS | REPORT_IS; - gpsd_report(LOG_DATA, "SPPLLA 0x4a " - "time=%.2f lat=%.2f lon=%.2f alt=%.2f\n", + gpsd_report(session->context->debug, LOG_DATA, + "SPPLLA 0x4a time=%.2f lat=%.2f lon=%.2f alt=%.2f\n", session->newdata.time, session->newdata.latitude, session->newdata.longitude, @@ -377,10 +394,12 @@ static gps_mask_t tsip_analyze(struct gps_device_t *session) u1 = getub(buf, 0); /* Machine ID */ u2 = getub(buf, 1); /* Status 1 */ u3 = getub(buf, 2); /* Status 2 */ - gpsd_report(LOG_INF, "Machine ID %02x %02x %02x\n", u1, u2, u3); + gpsd_report(session->context->debug, LOG_INF, + "Machine ID %02x %02x %02x\n", u1, u2, u3); #if USE_SUPERPACKET if ((u3 & 0x01) != (uint8_t) 0 && !session->driver.tsip.superpkt) { - gpsd_report(LOG_PROG, "Switching to Super Packet mode\n"); + gpsd_report(session->context->debug, LOG_PROG, + "Switching to Super Packet mode\n"); /* set new I/O Options for Super Packet output */ putbyte(buf, 0, 0x2c); /* Position: SP, MSL */ @@ -403,8 +422,8 @@ static gps_mask_t tsip_analyze(struct gps_device_t *session) u2 = getub(buf, 1); /* Velocity */ u3 = getub(buf, 2); /* Timing */ u4 = getub(buf, 3); /* Aux */ - gpsd_report(LOG_INF, "IO Options %02x %02x %02x %02x\n", u1, u2, u3, - u4); + gpsd_report(session->context->debug, LOG_INF, + "IO Options %02x %02x %02x %02x\n", u1, u2, u3, u4); #if USE_SUPERPACKET if ((u1 & 0x20) != (uint8_t) 0) { /* Output Super Packets? */ /* No LFwEI Super Packet */ @@ -434,11 +453,12 @@ static gps_mask_t tsip_analyze(struct gps_device_t *session) /*@ +evalorder @*/ if ((session->newdata.track = atan2(f1, f2) * RAD_2_DEG) < 0) session->newdata.track += 360.0; - gpsd_report(LOG_INF, "GPS Velocity ENU %f %f %f %f %f\n", f1, f2, f3, + gpsd_report(session->context->debug, LOG_INF, + "GPS Velocity ENU %f %f %f %f %f\n", f1, f2, f3, f4, f5); mask |= SPEED_SET | TRACK_SET | CLIMB_SET; - gpsd_report(LOG_DATA, "VFENU 0x56 " - "time=%.2f speed=%.2f track=%.2f climb=%.2f\n", + gpsd_report(session->context->debug, LOG_DATA, + "VFENU 0x56 time=%.2f speed=%.2f track=%.2f climb=%.2f\n", session->newdata.time, session->newdata.speed, session->newdata.track, @@ -455,7 +475,8 @@ static gps_mask_t tsip_analyze(struct gps_device_t *session) if (getub(buf, 0) == 0x01) /* good current fix? */ (void)gpsd_gpstime_resolve(session, (unsigned short)s1, (double)f1); /*@ -charint @*/ - gpsd_report(LOG_INF, "Fix info %02x %02x %d %f\n", u1, u2, s1, f1); + gpsd_report(session->context->debug, LOG_INF, + "Fix info %02x %02x %d %f\n", u1, u2, s1, f1); break; case 0x58: /* Satellite System Data/Acknowledge from Receiver */ break; @@ -468,7 +489,8 @@ static gps_mask_t tsip_analyze(struct gps_device_t *session) f2 = getbef32((char *)buf, 9); /* Code phase */ f3 = getbef32((char *)buf, 13); /* Doppler */ d1 = getbed64((char *)buf, 17); /* Time of Measurement */ - gpsd_report(LOG_PROG, "Raw Measurement Data %d %f %f %f %f\n", + gpsd_report(session->context->debug, LOG_PROG, + "Raw Measurement Data %d %f %f %f %f\n", getub(buf, 0), f1, f2, f3, d1); break; case 0x5b: /* Satellite Ephemeris Status */ @@ -485,7 +507,7 @@ static gps_mask_t tsip_analyze(struct gps_device_t *session) d1 = getbef32((char *)buf, 12) * RAD_2_DEG; /* Elevation */ d2 = getbef32((char *)buf, 16) * RAD_2_DEG; /* Azimuth */ i = (int)(u2 >> 3); /* channel number */ - gpsd_report(LOG_INF, + gpsd_report(session->context->debug, LOG_INF, "Satellite Tracking Status: Ch %2d PRN %3d Res %d Acq %d Eph %2d SNR %4.1f LMT %.04f El %4.1f Az %5.1f\n", i, u1, u2 & 7, u3, u4, f1, f2, d1, d2); if (i < TSIP_CHANNELS) { @@ -559,8 +581,8 @@ static gps_mask_t tsip_analyze(struct gps_device_t *session) " %d", session->gpsdata.used[i] = (int)getub(buf, 17 + i)); /*@ -charint @*/ - gpsd_report(LOG_DATA, "AIVSS: 0x6d " - "status=%d used=%d " + gpsd_report(session->context->debug, LOG_DATA, + "AIVSS: 0x6d status=%d used=%d " "pdop=%.1f hdop=%.1f vdop=%.1f tdop=%.1f gdup=%.1f\n", session->gpsdata.status, session->gpsdata.satellites_used, @@ -597,7 +619,8 @@ static gps_mask_t tsip_analyze(struct gps_device_t *session) mask |= STATUS_SET; } /*@ -charint @*/ - gpsd_report(LOG_DATA, "DPFM 0x82 status=%d\n", session->gpsdata.status); + gpsd_report(session->context->debug, LOG_DATA, + "DPFM 0x82 status=%d\n", session->gpsdata.status); break; case 0x83: /* Double-Precision XYZ Position Fix and Bias Information */ if (len != 36) @@ -607,8 +630,8 @@ static gps_mask_t tsip_analyze(struct gps_device_t *session) d3 = getbed64((char *)buf, 16); /* Z */ d4 = getbed64((char *)buf, 24); /* clock bias */ f1 = getbef32((char *)buf, 32); /* time-of-fix */ - gpsd_report(LOG_INF, "GPS Position XYZ %f %f %f %f %f\n", d1, d2, d3, - d4, f1); + gpsd_report(session->context->debug, LOG_INF, + "GPS Position XYZ %f %f %f %f %f\n", d1, d2, d3, d4, f1); break; case 0x84: /* Double-Precision LLA Position Fix and Bias Information */ if (len != 36) @@ -625,13 +648,14 @@ static gps_mask_t tsip_analyze(struct gps_device_t *session) (double)f1); mask |= TIME_SET | PPSTIME_IS; } - gpsd_report(LOG_INF, "GPS DP LLA %f %f %f %f\n", + gpsd_report(session->context->debug, LOG_INF, + "GPS DP LLA %f %f %f %f\n", session->newdata.time, session->newdata.latitude, session->newdata.longitude, session->newdata.altitude); mask |= LATLON_SET | ALTITUDE_SET | CLEAR_IS | REPORT_IS; - gpsd_report(LOG_DATA, "DPPLLA 0x84 " - "time=%.2f lat=%.2f lon=%.2f alt=%.2f\n", + gpsd_report(session->context->debug, LOG_DATA, + "DPPLLA 0x84 time=%.2f lat=%.2f lon=%.2f alt=%.2f\n", session->newdata.time, session->newdata.latitude, session->newdata.longitude, @@ -654,7 +678,8 @@ static gps_mask_t tsip_analyze(struct gps_device_t *session) d3 = getbed64((char *)buf, 19); /* DZ */ d4 = getbed64((char *)buf, 27); /* A-axis */ d5 = getbed64((char *)buf, 35); /* Eccentricity Squared */ - gpsd_report(LOG_INF, "Current Datum %d %f %f %f %f %f\n", s1, d1, + gpsd_report(session->context->debug, LOG_INF, + "Current Datum %d %f %f %f %f %f\n", s1, d1, d2, d3, d4, d5); break; @@ -675,7 +700,7 @@ static gps_mask_t tsip_analyze(struct gps_device_t *session) u4 = getub(buf, 29); /* utc offset */ s4 = getbes16(buf, 30); /* tsip.gps_week */ /* PRN/IODE data follows */ - gpsd_report(LOG_RAW, + gpsd_report(session->context->debug, LOG_RAW, "LFwEI %d %d %d %u %d %u %u %x %x %u %u %d\n", s1, s2, s3, ul1, sl1, ul2, sl2, u1, u2, u3, u4, s4); @@ -723,7 +748,7 @@ static gps_mask_t tsip_analyze(struct gps_device_t *session) TIME_SET | PPSTIME_IS | LATLON_SET | ALTITUDE_SET | SPEED_SET | TRACK_SET | CLIMB_SET | STATUS_SET | MODE_SET | CLEAR_IS | REPORT_IS; - gpsd_report(LOG_DATA, + gpsd_report(session->context->debug, LOG_DATA, "SP-LFEI 0x20: time=%.2f lat=%.2f lon=%.2f alt=%.2f " "speed=%.2f track=%.2f climb=%.2f " "mode=%d status=%d\n", @@ -748,7 +773,7 @@ static gps_mask_t tsip_analyze(struct gps_device_t *session) s2 = getbes16(buf, 21); /* east velocity */ s3 = getbes16(buf, 23); /* north velocity */ s4 = getbes16(buf, 25); /* up velocity */ - gpsd_report(LOG_INF, "CSP %u %d %u %u %d %u %d %d %d %d\n", ul1, + gpsd_report(session->context->debug, LOG_INF, "CSP %u %d %u %u %d %u %d %d %d %d\n", ul1, s1, u1, u2, sl1, ul2, sl3, s2, s3, s4); if ((int)u1 > 10) { session->context->leap_seconds = (int)u1; @@ -794,7 +819,7 @@ static gps_mask_t tsip_analyze(struct gps_device_t *session) TIME_SET | PPSTIME_IS | LATLON_SET | ALTITUDE_SET | SPEED_SET | TRACK_SET |CLIMB_SET | STATUS_SET | MODE_SET | CLEAR_IS | REPORT_IS; - gpsd_report(LOG_DATA, + gpsd_report(session->context->debug, LOG_DATA, "SP-CSP 0x23: time=%.2f lat=%.2f lon=%.2f alt=%.2f " "speed=%.2f track=%.2f climb=%.2f mode=%d status=%d\n", session->newdata.time, @@ -806,7 +831,7 @@ static gps_mask_t tsip_analyze(struct gps_device_t *session) case 0xab: /* Thunderbolt Timing Superpacket */ if (len != 17) { - gpsd_report(4, "pkt 0xab len=%d\n", len); + gpsd_report(session->context->debug, 4, "pkt 0xab len=%d\n", len); break; } session->driver.tsip.last_41 = now; /* keep timestamp for request */ @@ -820,17 +845,19 @@ static gps_mask_t tsip_analyze(struct gps_device_t *session) session->newdata.time = gpsd_gpstime_resolve(session, (unsigned short)s1, (double)ul1); mask |= TIME_SET | PPSTIME_IS | CLEAR_IS; - gpsd_report(LOG_DATA, "SP-TTS 0xab time=%.2f mask={TIME}\n", + gpsd_report(session->context->debug, LOG_DATA, + "SP-TTS 0xab time=%.2f mask={TIME}\n", session->newdata.time); } - gpsd_report(4, "GPS Time %u %d %d\n", ul1, s1, s2); + gpsd_report(session->context->debug, 4, + "GPS Time %u %d %d\n", ul1, s1, s2); break; case 0xac: /* Thunderbolt Position Superpacket */ if (len != 68) { - gpsd_report(4, "pkt 0xac len=%d\n", len); + gpsd_report(session->context->debug, 4, "pkt 0xac len=%d\n", len); break; } @@ -896,8 +923,8 @@ static gps_mask_t tsip_analyze(struct gps_device_t *session) } mask |= LATLON_SET | ALTITUDE_SET | MODE_SET | REPORT_IS; - gpsd_report(LOG_DATA, "SP-TPS 0xac " - "time=%.2f lat=%.2f lon=%.2f alt=%.2f\n", + gpsd_report(session->context->debug, LOG_DATA, + "SP-TPS 0xac time=%.2f lat=%.2f lon=%.2f alt=%.2f\n", session->newdata.time, session->newdata.latitude, session->newdata.longitude, @@ -905,7 +932,8 @@ static gps_mask_t tsip_analyze(struct gps_device_t *session) break; default: - gpsd_report(LOG_WARN, "Unhandled TSIP superpacket type 0x%02x\n", + gpsd_report(session->context->debug, LOG_WARN, + "Unhandled TSIP superpacket type 0x%02x\n", u1); } break; @@ -921,12 +949,12 @@ static gps_mask_t tsip_analyze(struct gps_device_t *session) f3 = getbef32((char *)buf, 13); /* DOP Mask */ f4 = getbef32((char *)buf, 17); /* DOP Switch */ u5 = getub(buf, 21); /* DGPS Age Limit (not in Accutime Gold) */ - gpsd_report(LOG_INF, + gpsd_report(session->context->debug, LOG_INF, "Navigation Configuration %u %u %u %u %f %f %f %f %u\n", u1, u2, u3, u4, f1, f2, f3, f4, u5); break; default: - gpsd_report(LOG_WARN, "Unhandled TSIP packet type 0x%02x\n", id); + gpsd_report(session->context->debug, LOG_WARN, "Unhandled TSIP packet type 0x%02x\n", id); break; } @@ -968,7 +996,8 @@ static gps_mask_t tsip_analyze(struct gps_device_t *session) ((now - session->driver.tsip.req_compact) > 5)) { /* Compact Superpacket requested but no response */ session->driver.tsip.req_compact = 0; - gpsd_report(LOG_WARN, "No Compact Super Packet, use LFwEI\n"); + gpsd_report(session->context->debug, LOG_WARN, + "No Compact Super Packet, use LFwEI\n"); /* Request LFwEI Super Packet */ putbyte(buf, 0, 0x20); @@ -1150,7 +1179,8 @@ static void tsip_mode(struct gps_device_t *session, int mode) ; } else { - gpsd_report(LOG_ERROR, "unknown mode %i requested\n", mode); + gpsd_report(session->context->debug, LOG_ERROR, + "unknown mode %i requested\n", mode); } } #endif /* RECONFIGURE_ENABLE */ diff --git a/driver_ubx.c b/driver_ubx.c index df9611d5..172efff0 100644 --- a/driver_ubx.c +++ b/driver_ubx.c @@ -57,7 +57,7 @@ static gps_mask_t ubx_msg_nav_timegps(struct gps_device_t *session, static gps_mask_t ubx_msg_nav_svinfo(struct gps_device_t *session, unsigned char *buf, size_t data_len); static void ubx_msg_sbas(struct gps_device_t *session, unsigned char *buf); -static void ubx_msg_inf(unsigned char *buf, size_t data_len); +static void ubx_msg_inf(unsigned char *buf, size_t data_len, const int debug); /** * Navigation solution message @@ -121,7 +121,7 @@ ubx_msg_nav_sol(struct gps_device_t *session, unsigned char *buf, session->gpsdata.status = STATUS_FIX; mask |= MODE_SET | STATUS_SET; - gpsd_report(LOG_DATA, + gpsd_report(session->context->debug, LOG_DATA, "NAVSOL: time=%.2f lat=%.2f lon=%.2f alt=%.2f track=%.2f speed=%.2f climb=%.2f mode=%d status=%d used=%d\n", session->newdata.time, session->newdata.latitude, @@ -157,7 +157,8 @@ ubx_msg_nav_dop(struct gps_device_t *session, unsigned char *buf, session->gpsdata.dop.tdop = (double)(getleu16(buf, 8) / 100.0); session->gpsdata.dop.vdop = (double)(getleu16(buf, 10) / 100.0); session->gpsdata.dop.hdop = (double)(getleu16(buf, 12) / 100.0); - gpsd_report(LOG_DATA, "NAVDOP: gdop=%.2f pdop=%.2f " + gpsd_report(session->context->debug, LOG_DATA, + "NAVDOP: gdop=%.2f pdop=%.2f " "hdop=%.2f vdop=%.2f tdop=%.2f mask={DOP}\n", session->gpsdata.dop.gdop, session->gpsdata.dop.hdop, @@ -187,7 +188,8 @@ ubx_msg_nav_timegps(struct gps_device_t *session, unsigned char *buf, (unsigned short int)gw, (double)tow / 1000.0); - gpsd_report(LOG_DATA, "TIMEGPS: time=%.2f mask={TIME}\n", + gpsd_report(session->context->debug, LOG_DATA, + "TIMEGPS: time=%.2f mask={TIME}\n", session->newdata.time); return TIME_SET | PPSTIME_IS; } @@ -202,13 +204,14 @@ ubx_msg_nav_svinfo(struct gps_device_t *session, unsigned char *buf, unsigned int i, j, nchan, nsv, st; if (data_len < 152) { - gpsd_report(LOG_PROG, "runt svinfo (datalen=%zd)\n", data_len); + gpsd_report(session->context->debug, LOG_PROG, + "runt svinfo (datalen=%zd)\n", data_len); return 0; } /*@ +charint @*/ nchan = (unsigned int)getub(buf, 4); if (nchan > MAXCHANNELS) { - gpsd_report(LOG_WARN, + gpsd_report(session->context->debug, LOG_WARN, "Invalid NAV SVINFO message, >%d reported visible", MAXCHANNELS); return 0; @@ -238,7 +241,7 @@ ubx_msg_nav_svinfo(struct gps_device_t *session, unsigned char *buf, session->gpsdata.skyview_time = NAN; session->gpsdata.satellites_visible = (int)st; session->gpsdata.satellites_used = (int)nsv; - gpsd_report(LOG_DATA, + gpsd_report(session->context->debug, LOG_DATA, "SVINFO: visible=%d used=%d mask={SATELLITE|USED}\n", session->gpsdata.satellites_visible, session->gpsdata.satellites_used); @@ -253,14 +256,15 @@ static void ubx_msg_sbas(struct gps_device_t *session, unsigned char *buf) #ifdef __UNUSED_DEBUG__ unsigned int i, nsv; - gpsd_report(LOG_WARN, "SBAS: %d %d %d %d %d\n", + gpsd_report(session->context->debug, LOG_WARN, + "SBAS: %d %d %d %d %d\n", (int)getub(buf, 4), (int)getub(buf, 5), (int)getub(buf, 6), (int)getub(buf, 7), (int)getub(buf, 8)); nsv = (int)getub(buf, 8); for (i = 0; i < nsv; i++) { int off = 12 + 12 * i; - gpsd_report(LOG_WARN, "SBAS info on SV: %d\n", (int)getub(buf, off)); + gpsd_report(session->context->debug, LOG_WARN, "SBAS info on SV: %d\n", (int)getub(buf, off)); } #endif /* __UNUSED_DEBUG__ */ /* really 'in_use' depends on the sats info, EGNOS is still in test */ @@ -278,7 +282,8 @@ static gps_mask_t ubx_msg_sfrb(struct gps_device_t *session, unsigned char *buf) chan = (unsigned int)getub(buf, 0); svid = (unsigned int)getub(buf, 1); - gpsd_report(LOG_PROG, "UBX_RXM_SFRB: %u %u\n", chan, svid); + gpsd_report(session->context->debug, LOG_PROG, + "UBX_RXM_SFRB: %u %u\n", chan, svid); /* UBX does all the parity checking, but still bad data gets through */ for (i = 0; i < 10; i++) { @@ -288,7 +293,7 @@ static gps_mask_t ubx_msg_sfrb(struct gps_device_t *session, unsigned char *buf) return gpsd_interpret_subframe(session, svid, words); } -static void ubx_msg_inf(unsigned char *buf, size_t data_len) +static void ubx_msg_inf(unsigned char *buf, size_t data_len, const int debug) { unsigned short msgid; static char txtbuf[MAX_PACKET_LENGTH]; @@ -301,19 +306,19 @@ static void ubx_msg_inf(unsigned char *buf, size_t data_len) txtbuf[data_len] = '\0'; switch (msgid) { case UBX_INF_DEBUG: - gpsd_report(LOG_PROG, "UBX_INF_DEBUG: %s\n", txtbuf); + gpsd_report(debug, LOG_PROG, "UBX_INF_DEBUG: %s\n", txtbuf); break; case UBX_INF_TEST: - gpsd_report(LOG_PROG, "UBX_INF_TEST: %s\n", txtbuf); + gpsd_report(debug, LOG_PROG, "UBX_INF_TEST: %s\n", txtbuf); break; case UBX_INF_NOTICE: - gpsd_report(LOG_INF, "UBX_INF_NOTICE: %s\n", txtbuf); + gpsd_report(debug, LOG_INF, "UBX_INF_NOTICE: %s\n", txtbuf); break; case UBX_INF_WARNING: - gpsd_report(LOG_WARN, "UBX_INF_WARNING: %s\n", txtbuf); + gpsd_report(debug, LOG_WARN, "UBX_INF_WARNING: %s\n", txtbuf); break; case UBX_INF_ERROR: - gpsd_report(LOG_WARN, "UBX_INF_ERROR: %s\n", txtbuf); + gpsd_report(debug, LOG_WARN, "UBX_INF_ERROR: %s\n", txtbuf); break; default: break; @@ -341,106 +346,106 @@ gps_mask_t ubx_parse(struct gps_device_t * session, unsigned char *buf, data_len = (size_t) getles16(buf, 4); switch (msgid) { case UBX_NAV_POSECEF: - gpsd_report(LOG_IO, "UBX_NAV_POSECEF\n"); + gpsd_report(session->context->debug, LOG_IO, "UBX_NAV_POSECEF\n"); break; case UBX_NAV_POSLLH: - gpsd_report(LOG_IO, "UBX_NAV_POSLLH\n"); + gpsd_report(session->context->debug, LOG_IO, "UBX_NAV_POSLLH\n"); break; case UBX_NAV_STATUS: - gpsd_report(LOG_IO, "UBX_NAV_STATUS\n"); + gpsd_report(session->context->debug, LOG_IO, "UBX_NAV_STATUS\n"); break; case UBX_NAV_DOP: - gpsd_report(LOG_PROG, "UBX_NAV_DOP\n"); + gpsd_report(session->context->debug, LOG_PROG, "UBX_NAV_DOP\n"); mask = ubx_msg_nav_dop(session, &buf[UBX_PREFIX_LEN], data_len); break; case UBX_NAV_SOL: - gpsd_report(LOG_PROG, "UBX_NAV_SOL\n"); + gpsd_report(session->context->debug, LOG_PROG, "UBX_NAV_SOL\n"); mask = ubx_msg_nav_sol(session, &buf[UBX_PREFIX_LEN], data_len) | (CLEAR_IS | REPORT_IS); break; case UBX_NAV_POSUTM: - gpsd_report(LOG_IO, "UBX_NAV_POSUTM\n"); + gpsd_report(session->context->debug, LOG_IO, "UBX_NAV_POSUTM\n"); break; case UBX_NAV_VELECEF: - gpsd_report(LOG_IO, "UBX_NAV_VELECEF\n"); + gpsd_report(session->context->debug, LOG_IO, "UBX_NAV_VELECEF\n"); break; case UBX_NAV_VELNED: - gpsd_report(LOG_IO, "UBX_NAV_VELNED\n"); + gpsd_report(session->context->debug, LOG_IO, "UBX_NAV_VELNED\n"); break; case UBX_NAV_TIMEGPS: - gpsd_report(LOG_PROG, "UBX_NAV_TIMEGPS\n"); + gpsd_report(session->context->debug, LOG_PROG, "UBX_NAV_TIMEGPS\n"); mask = ubx_msg_nav_timegps(session, &buf[UBX_PREFIX_LEN], data_len); break; case UBX_NAV_TIMEUTC: - gpsd_report(LOG_IO, "UBX_NAV_TIMEUTC\n"); + gpsd_report(session->context->debug, LOG_IO, "UBX_NAV_TIMEUTC\n"); break; case UBX_NAV_CLOCK: - gpsd_report(LOG_IO, "UBX_NAV_CLOCK\n"); + gpsd_report(session->context->debug, LOG_IO, "UBX_NAV_CLOCK\n"); break; case UBX_NAV_SVINFO: - gpsd_report(LOG_PROG, "UBX_NAV_SVINFO\n"); + gpsd_report(session->context->debug, LOG_PROG, "UBX_NAV_SVINFO\n"); mask = ubx_msg_nav_svinfo(session, &buf[UBX_PREFIX_LEN], data_len); break; case UBX_NAV_DGPS: - gpsd_report(LOG_IO, "UBX_NAV_DGPS\n"); + gpsd_report(session->context->debug, LOG_IO, "UBX_NAV_DGPS\n"); break; case UBX_NAV_SBAS: - gpsd_report(LOG_IO, "UBX_NAV_SBAS\n"); + gpsd_report(session->context->debug, LOG_IO, "UBX_NAV_SBAS\n"); ubx_msg_sbas(session, &buf[6]); break; case UBX_NAV_EKFSTATUS: - gpsd_report(LOG_IO, "UBX_NAV_EKFSTATUS\n"); + gpsd_report(session->context->debug, LOG_IO, "UBX_NAV_EKFSTATUS\n"); break; case UBX_RXM_RAW: - gpsd_report(LOG_IO, "UBX_RXM_RAW\n"); + gpsd_report(session->context->debug, LOG_IO, "UBX_RXM_RAW\n"); break; case UBX_RXM_SFRB: mask = ubx_msg_sfrb(session, &buf[UBX_PREFIX_LEN]); break; case UBX_RXM_SVSI: - gpsd_report(LOG_PROG, "UBX_RXM_SVSI\n"); + gpsd_report(session->context->debug, LOG_PROG, "UBX_RXM_SVSI\n"); break; case UBX_RXM_ALM: - gpsd_report(LOG_IO, "UBX_RXM_ALM\n"); + gpsd_report(session->context->debug, LOG_IO, "UBX_RXM_ALM\n"); break; case UBX_RXM_EPH: - gpsd_report(LOG_IO, "UBX_RXM_EPH\n"); + gpsd_report(session->context->debug, LOG_IO, "UBX_RXM_EPH\n"); break; case UBX_RXM_POSREQ: - gpsd_report(LOG_IO, "UBX_RXM_POSREQ\n"); + gpsd_report(session->context->debug, LOG_IO, "UBX_RXM_POSREQ\n"); break; case UBX_MON_SCHED: - gpsd_report(LOG_IO, "UBX_MON_SCHED\n"); + gpsd_report(session->context->debug, LOG_IO, "UBX_MON_SCHED\n"); break; case UBX_MON_IO: - gpsd_report(LOG_IO, "UBX_MON_IO\n"); + gpsd_report(session->context->debug, LOG_IO, "UBX_MON_IO\n"); break; case UBX_MON_IPC: - gpsd_report(LOG_IO, "UBX_MON_IPC\n"); + gpsd_report(session->context->debug, LOG_IO, "UBX_MON_IPC\n"); break; case UBX_MON_VER: - gpsd_report(LOG_IO, "UBX_MON_VER\n"); + gpsd_report(session->context->debug, LOG_IO, "UBX_MON_VER\n"); break; case UBX_MON_EXCEPT: - gpsd_report(LOG_IO, "UBX_MON_EXCEPT\n"); + gpsd_report(session->context->debug, LOG_IO, "UBX_MON_EXCEPT\n"); break; case UBX_MON_MSGPP: - gpsd_report(LOG_IO, "UBX_MON_MSGPP\n"); + gpsd_report(session->context->debug, LOG_IO, "UBX_MON_MSGPP\n"); break; case UBX_MON_RXBUF: - gpsd_report(LOG_IO, "UBX_MON_RXBUF\n"); + gpsd_report(session->context->debug, LOG_IO, "UBX_MON_RXBUF\n"); break; case UBX_MON_TXBUF: - gpsd_report(LOG_IO, "UBX_MON_TXBUF\n"); + gpsd_report(session->context->debug, LOG_IO, "UBX_MON_TXBUF\n"); break; case UBX_MON_HW: - gpsd_report(LOG_IO, "UBX_MON_HW\n"); + gpsd_report(session->context->debug, LOG_IO, "UBX_MON_HW\n"); break; case UBX_MON_USB: - gpsd_report(LOG_IO, "UBX_MON_USB\n"); + gpsd_report(session->context->debug, LOG_IO, "UBX_MON_USB\n"); break; case UBX_INF_DEBUG: @@ -452,24 +457,24 @@ gps_mask_t ubx_parse(struct gps_device_t * session, unsigned char *buf, case UBX_INF_WARNING: /* FALLTHROUGH */ case UBX_INF_ERROR: - ubx_msg_inf(buf, data_len); + ubx_msg_inf(buf, data_len, session->context->debug); break; case UBX_TIM_TP: - gpsd_report(LOG_IO, "UBX_TIM_TP\n"); + gpsd_report(session->context->debug, LOG_IO, "UBX_TIM_TP\n"); break; case UBX_TIM_TM: - gpsd_report(LOG_IO, "UBX_TIM_TM\n"); + gpsd_report(session->context->debug, LOG_IO, "UBX_TIM_TM\n"); break; case UBX_TIM_TM2: - gpsd_report(LOG_IO, "UBX_TIM_TM2\n"); + gpsd_report(session->context->debug, LOG_IO, "UBX_TIM_TM2\n"); break; case UBX_TIM_SVIN: - gpsd_report(LOG_IO, "UBX_TIM_SVIN\n"); + gpsd_report(session->context->debug, LOG_IO, "UBX_TIM_SVIN\n"); break; case UBX_CFG_PRT: - gpsd_report(LOG_IO, "UBX_CFG_PRT\n"); + gpsd_report(session->context->debug, LOG_IO, "UBX_CFG_PRT\n"); for (i = 0; i < (int)sizeof(session->driver.ubx.port_settings); i++) session->driver.ubx.port_settings[i] = buf[UBX_PREFIX_LEN+i]; /* turn off NMEA output, turn on UBX on this port */ @@ -482,18 +487,20 @@ gps_mask_t ubx_parse(struct gps_device_t * session, unsigned char *buf, break; case UBX_ACK_NAK: - gpsd_report(LOG_IO, "UBX_ACK_NAK, class: %02x, id: %02x\n", + gpsd_report(session->context->debug, LOG_IO, + "UBX_ACK_NAK, class: %02x, id: %02x\n", buf[UBX_CLASS_OFFSET], buf[UBX_TYPE_OFFSET]); break; case UBX_ACK_ACK: - gpsd_report(LOG_IO, "UBX_ACK_ACK, class: %02x, id: %02x\n", + gpsd_report(session->context->debug, LOG_IO, + "UBX_ACK_ACK, class: %02x, id: %02x\n", buf[UBX_CLASS_OFFSET], buf[UBX_TYPE_OFFSET]); break; default: - gpsd_report(LOG_WARN, + gpsd_report(session->context->debug, LOG_WARN, "UBX: unknown packet id 0x%04hx (length %zd)\n", msgid, len); } @@ -565,7 +572,7 @@ bool ubx_write(struct gps_device_t * session, /*@ +type @*/ - gpsd_report(LOG_IO, + gpsd_report(session->context->debug, LOG_IO, "=> GPS: UBX class: %02x, id: %02x, len: %zd, crc: %02x%02x\n", msg_class, msg_id, data_len, CK_A, CK_B); @@ -615,7 +622,7 @@ static void ubx_event_hook(struct gps_device_t *session, event_t event) else if (event == event_identified) { unsigned char msg[32]; - gpsd_report(LOG_IO, "UBX configure\n"); + gpsd_report(session->context->debug, LOG_IO, "UBX configure\n"); (void)ubx_write(session, 0x06u, 0x00, NULL, 0); /* get this port's settings */ @@ -660,7 +667,7 @@ static void ubx_event_hook(struct gps_device_t *session, event_t event) }; /* reserved */ /*@ +type @*/ - gpsd_report(LOG_IO, "UBX revert\n"); + gpsd_report(session->context->debug, LOG_IO, "UBX revert\n"); /* Reverting all in one fast and reliable reset */ (void)ubx_write(session, 0x06, 0x04, msg, 4); /* CFG-RST */ @@ -746,7 +753,8 @@ static bool ubx_rate(struct gps_device_t *session, double cycletime) if (cycletime < 200.0) cycletime = 200.0; - gpsd_report(LOG_IO, "UBX rate change, report every %f secs\n", cycletime); + gpsd_report(session->context->debug, LOG_IO, + "UBX rate change, report every %f secs\n", cycletime); s = (unsigned short)cycletime; msg[0] = (unsigned char)(s >> 8); msg[1] = (unsigned char)(s & 0xff); diff --git a/driver_zodiac.c b/driver_zodiac.c index 63ee40e8..1af2250d 100644 --- a/driver_zodiac.c +++ b/driver_zodiac.c @@ -94,7 +94,8 @@ static ssize_t zodiac_spew(struct gps_device_t *session, unsigned short type, if (end_write(session->gpsdata.gps_fd, &h, hlen) != (ssize_t) hlen || end_write(session->gpsdata.gps_fd, dat, datlen) != (ssize_t) datlen) { - gpsd_report(LOG_RAW, "Reconfigure write failed\n"); + gpsd_report(session->context->debug, LOG_RAW, + "Reconfigure write failed\n"); return -1; } } @@ -106,7 +107,8 @@ static ssize_t zodiac_spew(struct gps_device_t *session, unsigned short type, (void)snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), " %04x", dat[i]); - gpsd_report(LOG_RAW, "Sent Zodiac packet: %s\n", buf); + gpsd_report(session->context->debug, LOG_RAW, + "Sent Zodiac packet: %s\n", buf); return 0; } @@ -212,7 +214,7 @@ static gps_mask_t handle1000(struct gps_device_t *session) mask = TIME_SET | PPSTIME_IS | LATLON_SET | ALTITUDE_SET | CLIMB_SET | SPEED_SET | TRACK_SET | STATUS_SET | MODE_SET; - gpsd_report(LOG_DATA, + gpsd_report(session->context->debug, LOG_DATA, "1000: time=%.2f lat=%.2f lon=%.2f alt=%.2f track=%.2f speed=%.2f climb=%.2f mode=%d status=%d\n", session->newdata.time, session->newdata.latitude, session->newdata.longitude, session->newdata.altitude, @@ -257,7 +259,8 @@ static gps_mask_t handle1002(struct gps_device_t *session) session->gpsdata.skyview_time = gpsd_gpstime_resolve(session, (unsigned short)gps_week, (double)gps_seconds); - gpsd_report(LOG_DATA, "1002: visible=%d used=%d mask={SATELLITE|USED}\n", + gpsd_report(session->context->debug, LOG_DATA, + "1002: visible=%d used=%d mask={SATELLITE|USED}\n", session->gpsdata.satellites_visible, session->gpsdata.satellites_used); return SATELLITE_SET | USED_IS; @@ -302,7 +305,8 @@ static gps_mask_t handle1003(struct gps_device_t *session) } } session->gpsdata.skyview_time = NAN; - gpsd_report(LOG_DATA, "NAVDOP: visible=%d gdop=%.2f pdop=%.2f " + gpsd_report(session->context->debug, LOG_DATA, + "NAVDOP: visible=%d gdop=%.2f pdop=%.2f " "hdop=%.2f vdop=%.2f tdop=%.2f mask={SATELLITE|DOP}\n", session->gpsdata.satellites_visible, session->gpsdata.dop.gdop, @@ -336,7 +340,8 @@ static gps_mask_t handle1011(struct gps_device_t *session) * The Zodiac is supposed to send one of these messages on startup. */ getstringz(session->subtype, session->packet.outbuffer, 19, 28); /* software version field */ - gpsd_report(LOG_DATA, "1011: subtype=%s mask={DEVICEID}\n", + gpsd_report(session->context->debug, LOG_DATA, + "1011: subtype=%s mask={DEVICEID}\n", session->subtype); return DEVICEID_SET; } @@ -365,11 +370,13 @@ static gps_mask_t zodiac_analyze(struct gps_device_t *session) if (session->packet.type != ZODIAC_PACKET) { const struct gps_type_t **dp; - gpsd_report(LOG_PROG, "zodiac_analyze packet type %d\n", + gpsd_report(session->context->debug, LOG_PROG, + "zodiac_analyze packet type %d\n", session->packet.type); // Wrong packet type ? // Maybe find a trigger just in case it's an Earthmate - gpsd_report(LOG_RAW + 4, "Is this a trigger: %s ?\n", + gpsd_report(session->context->debug, LOG_RAW + 4, + "Is this a trigger: %s ?\n", (char *)session->packet.outbuffer); for (dp = gpsd_drivers; *dp; dp++) { @@ -379,7 +386,7 @@ static gps_mask_t zodiac_analyze(struct gps_device_t *session) && strncmp((char *)session->packet.outbuffer, trigger, strlen(trigger)) == 0 && isatty(session->gpsdata.gps_fd) != 0) { - gpsd_report(LOG_PROG, "found %s.\n", trigger); + gpsd_report(session->context->debug, LOG_PROG, "found %s.\n", trigger); (void)gpsd_switch_driver(session, (*dp)->type_name); return 0; @@ -392,7 +399,8 @@ static gps_mask_t zodiac_analyze(struct gps_device_t *session) for (i = 0; i < (int)session->packet.outbuflen; i++) (void)snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "%02x", (unsigned int)session->packet.outbuffer[i]); - gpsd_report(LOG_RAW, "Raw Zodiac packet type %d length %zd: %s\n", + gpsd_report(session->context->debug, LOG_RAW, + "Raw Zodiac packet type %d length %zd: %s\n", id, session->packet.outbuflen, buf); if (session->packet.outbuflen < 10) @@ -38,18 +38,20 @@ gps_mask_t generic_parse_input(struct gps_device_t *session) char *sentence = (char *)session->packet.outbuffer; if (sentence[strlen(sentence)-1] != '\n') - gpsd_report(LOG_IO, "<= GPS: %s\n", sentence); + gpsd_report(session->context->debug, LOG_IO, "<= GPS: %s\n", sentence); else - gpsd_report(LOG_IO, "<= GPS: %s", sentence); + gpsd_report(session->context->debug, LOG_IO, "<= GPS: %s", sentence); if ((st=nmea_parse(sentence, session)) == 0) { - gpsd_report(LOG_WARN, "unknown sentence: \"%s\"\n", sentence); + gpsd_report(session->context->debug, LOG_WARN, + "unknown sentence: \"%s\"\n", sentence); } for (dp = gpsd_drivers; *dp; dp++) { char *trigger = (*dp)->trigger; if (trigger!=NULL && strncmp(sentence,trigger,strlen(trigger))==0) { - gpsd_report(LOG_PROG, "found trigger string %s.\n", trigger); + gpsd_report(session->context->debug, LOG_PROG, + "found trigger string %s.\n", trigger); if (*dp != session->device_type) { (void)gpsd_switch_driver(session, (*dp)->type_name); if (session->device_type != NULL @@ -149,7 +151,8 @@ static void nmea_event_hook(struct gps_device_t *session, event_t event) #ifdef NMEA_ENABLE case 0: /* probe for Garmin serial GPS -- expect $PGRMC followed by data */ - gpsd_report(LOG_PROG, "=> Probing for Garmin NMEA\n"); + gpsd_report(session->context->debug, LOG_PROG, + "=> Probing for Garmin NMEA\n"); (void)nmea_send(session, "$PGRMCE"); break; #endif /* NMEA_ENABLE */ @@ -167,7 +170,7 @@ static void nmea_event_hook(struct gps_device_t *session, event_t event) * select the NMEA driver without switching the device back to * binary mode! Fix this if we ever find a nondisruptive probe string. */ - gpsd_report(LOG_PROG, "=> Probing for SiRF\n"); + gpsd_report(session->context->debug, LOG_PROG, "=> Probing for SiRF\n"); (void)nmea_send(session, "$PSRF100,0,%d,%d,%d,0", session->gpsdata.dev.baudrate, @@ -179,18 +182,20 @@ static void nmea_event_hook(struct gps_device_t *session, event_t event) #ifdef NMEA_ENABLE case 2: /* probe for the FV-18 -- expect $PFEC,GPint followed by data */ - gpsd_report(LOG_PROG, "=> Probing for FV-18\n"); + gpsd_report(session->context->debug, LOG_PROG, "=> Probing for FV-18\n"); (void)nmea_send(session, "$PFEC,GPint"); break; case 3: /* probe for the Trimble Copernicus */ - gpsd_report(LOG_PROG, "=> Probing for Trimble Copernicus\n"); + gpsd_report(session->context->debug, LOG_PROG, + "=> Probing for Trimble Copernicus\n"); (void)nmea_send(session, "$PTNLSNM,0139,01"); break; #endif /* NMEA_ENABLE */ #ifdef EVERMORE_ENABLE case 4: - gpsd_report(LOG_PROG, "=> Probing for Evermore\n"); + gpsd_report(session->context->debug, LOG_PROG, + "=> Probing for Evermore\n"); /* Enable checksum and GGA(1s), GLL(0s), GSA(1s), GSV(1s), RMC(1s), VTG(0s), PEMT101(0s) */ /* EverMore will reply with: \x10\x02\x04\x38\x8E\xC6\x10\x03 */ (void)gpsd_write(session, @@ -201,28 +206,32 @@ static void nmea_event_hook(struct gps_device_t *session, event_t event) #ifdef GPSCLOCK_ENABLE case 5: /* probe for Furuno Electric GH-79L4-N (GPSClock); expect $PFEC,GPssd */ - gpsd_report(LOG_PROG, "=> Probing for GPSClock\n"); + gpsd_report(session->context->debug, LOG_PROG, + "=> Probing for GPSClock\n"); (void)nmea_send(session, "$PFEC,GPsrq"); break; #endif /* GPSCLOCK_ENABLE */ #ifdef ASHTECH_ENABLE case 6: /* probe for Ashtech -- expect $PASHR,RID */ - gpsd_report(LOG_PROG, "=> Probing for Ashtech\n"); + gpsd_report(session->context->debug, LOG_PROG, + "=> Probing for Ashtech\n"); (void)nmea_send(session, "$PASHQ,RID"); break; #endif /* ASHTECH_ENABLE */ #ifdef UBX_ENABLE case 7: /* probe for UBX -- query software version */ - gpsd_report(LOG_PROG, "=> Probing for UBX\n"); + gpsd_report(session->context->debug, LOG_PROG, + "=> Probing for UBX\n"); (void)ubx_write(session, 0x0au, 0x04, NULL, 0); break; #endif /* UBX_ENABLE */ #ifdef MTK3301_ENABLE case 8: /* probe for MTK-3301 -- expect $PMTK705 */ - gpsd_report(LOG_PROG, "=> Probing for MediaTek\n"); + gpsd_report(session->context->debug, LOG_PROG, + "=> Probing for MediaTek\n"); (void)nmea_send(session, "$PMTK605"); break; #endif /* MTK3301_ENABLE */ @@ -523,7 +532,8 @@ static void gpsclock_event_hook(struct gps_device_t *session, event_t event) * ignore the trailing PPS edge when extracting time from this chip. */ if (event == event_identified || event == event_reactivate) { - gpsd_report(LOG_INF, "PPS trailing edge will be ignored\n"); + gpsd_report(session->context->debug, LOG_INF, + "PPS trailing edge will be ignored\n"); session->driver.nmea.ignore_trailing_edge = true; } } @@ -687,9 +697,13 @@ static void tnt_add_checksum(char *sentence) if (*p == '@') { p++; - } else { - gpsd_report(LOG_ERROR, "Bad TNT sentence: '%s'\n", sentence); + } +#ifdef __UNUSED__ + else { + gpsd_report(session->context->debug, LOG_ERROR, + "Bad TNT sentence: '%s'\n", sentence); } +#endif /* __UNUSED__ */ while (((c = *p) != '\0')) { sum ^= c; p++; @@ -722,10 +736,10 @@ static bool tnt_send(struct gps_device_t *session, const char *fmt, ...) va_end(ap); sent = tnt_control_send(session, buf, strlen(buf)); if (sent == (ssize_t) strlen(buf)) { - gpsd_report(LOG_IO, "=> GPS: %s\n", buf); + gpsd_report(session->context->debug, LOG_IO, "=> GPS: %s\n", buf); return true; } else { - gpsd_report(LOG_WARN, "=> GPS: %s FAILED\n", buf); + gpsd_report(session->context->debug, LOG_WARN, "=> GPS: %s FAILED\n", buf); return false; } } @@ -803,7 +817,7 @@ const struct gps_type_t trueNorth = { * **************************************************************************/ -static int oceanserver_send(int fd, const char *fmt, ...) +static int oceanserver_send(const int debug, const int fd, const char *fmt, ...) { int status; char buf[BUFSIZ]; @@ -816,10 +830,10 @@ static int oceanserver_send(int fd, const char *fmt, ...) status = (int)write(fd, buf, strlen(buf)); (void)tcdrain(fd); if (status == (int)strlen(buf)) { - gpsd_report(LOG_IO, "=> GPS: %s\n", buf); + gpsd_report(debug, LOG_IO, "=> GPS: %s\n", buf); return status; } else { - gpsd_report(LOG_WARN, "=> GPS: %s FAILED\n", buf); + gpsd_report(debug, LOG_WARN, "=> GPS: %s FAILED\n", buf); return -1; } } @@ -831,9 +845,11 @@ static void oceanserver_event_hook(struct gps_device_t *session, return; if (event == event_configure && session->packet.counter == 0) { /* report in NMEA format */ - (void)oceanserver_send(session->gpsdata.gps_fd, "2\n"); + (void)oceanserver_send(session->context->debug, + session->gpsdata.gps_fd, "2\n"); /* ship all fields */ - (void)oceanserver_send(session->gpsdata.gps_fd, "X2047"); + (void)oceanserver_send(session->context->debug, + session->gpsdata.gps_fd, "X2047"); } } @@ -945,7 +961,8 @@ static gps_mask_t rtcm104v2_analyze(struct gps_device_t *session) rtcm2_unpack(&session->gpsdata.rtcm2, (char *)session->packet.isgps.buf); /* extra guard prevents expensive hexdump calls */ if (session->context->debug >= LOG_RAW) - gpsd_report(LOG_RAW, "RTCM 2.x packet type 0x%02x length %d words from %zd bytes: %s\n", + gpsd_report(session->context->debug, LOG_RAW, + "RTCM 2.x packet type 0x%02x length %d words from %zd bytes: %s\n", session->gpsdata.rtcm2.type, session->gpsdata.rtcm2.length + 2, session->packet.isgps.buflen, @@ -994,8 +1011,10 @@ static gps_mask_t rtcm104v3_analyze(struct gps_device_t *session) { uint16_t type = getbeu16(session->packet.inbuffer, 3) >> 4; - gpsd_report(LOG_RAW, "RTCM 3.x packet %d\n", type); - rtcm3_unpack(&session->gpsdata.rtcm3, (char *)session->packet.outbuffer); + gpsd_report(session->context->debug, LOG_RAW, "RTCM 3.x packet %d\n", type); + rtcm3_unpack(session->context->debug, + &session->gpsdata.rtcm3, + (char *)session->packet.outbuffer); session->cycle_end_reliable = true; return RTCM3_SET; } @@ -1095,7 +1114,8 @@ static gps_mask_t processMTK3301(struct gps_device_t *session) case 001: /* ACK / NACK */ reason = atoi(session->driver.nmea.field[2]); if (atoi(session->driver.nmea.field[1]) == -1) - gpsd_report(LOG_WARN, "MTK NACK: unknown sentence\n"); + gpsd_report(session->context->debug, LOG_WARN, + "MTK NACK: unknown sentence\n"); else if (reason < 3) { const char *mtk_reasons[] = { "Invalid", @@ -1103,11 +1123,14 @@ static gps_mask_t processMTK3301(struct gps_device_t *session) "Valid but Failed", "Valid success" }; - gpsd_report(LOG_WARN, "MTK NACK: %s, reason: %s\n", session->driver.nmea.field[1], + gpsd_report(session->context->debug, LOG_WARN, + "MTK NACK: %s, reason: %s\n", + session->driver.nmea.field[1], mtk_reasons[reason]); } else - gpsd_report(LOG_WARN, "MTK ACK: %s\n", session->driver.nmea.field[1]); + gpsd_report(session->context->debug, LOG_WARN, + "MTK ACK: %s\n", session->driver.nmea.field[1]); break; default: return ONLINE_SET; /* ignore */ @@ -1238,14 +1261,15 @@ static bool aivdm_decode(const char *buf, size_t buflen, return false; /* we may need to dump the raw packet */ - gpsd_report(LOG_PROG, "AIVDM packet length %zd: %s\n", buflen, buf); + gpsd_report(session->context->debug, LOG_PROG, + "AIVDM packet length %zd: %s\n", buflen, buf); /* first clear the result, making sure we don't return garbage */ memset(ais, 0, sizeof(*ais)); /* discard overlong sentences */ if (strlen(buf) > sizeof(fieldcopy)-1) { - gpsd_report(LOG_ERROR, "overlong AIVDM packet.\n"); + gpsd_report(session->context->debug, LOG_ERROR, "overlong AIVDM packet.\n"); return false; } @@ -1261,7 +1285,7 @@ static bool aivdm_decode(const char *buf, size_t buflen, /* discard sentences with exiguous commas; catches run-ons */ if (nfields < 7) { - gpsd_report(LOG_ERROR, "malformed AIVDM packet.\n"); + gpsd_report(session->context->debug, LOG_ERROR, "malformed AIVDM packet.\n"); return false; } @@ -1274,7 +1298,8 @@ static bool aivdm_decode(const char *buf, size_t buflen, * is going to break if there's ever an AIVDO type 24, though. */ if (strncmp((const char *)field[0], "!AIVDO", 6) != 0) - gpsd_report(LOG_ERROR, "invalid empty AIS channel. Assuming 'A'\n"); + gpsd_report(session->context->debug, LOG_ERROR, + "invalid empty AIS channel. Assuming 'A'\n"); ais_context = &session->aivdm[0]; session->aivdm_ais_channel ='A'; break; @@ -1291,7 +1316,8 @@ static bool aivdm_decode(const char *buf, size_t buflen, session->aivdm_ais_channel ='B'; break; default: - gpsd_report(LOG_ERROR, "invalid AIS channel 0x%0X .\n", field[4][0]); + gpsd_report(session->context->debug, LOG_ERROR, + "invalid AIS channel 0x%0X .\n", field[4][0]); return false; } @@ -1299,15 +1325,17 @@ static bool aivdm_decode(const char *buf, size_t buflen, ifrag = atoi((char *)field[2]); /* fragment id */ data = field[5]; pad = field[6][0]; /* number of padding bits */ - gpsd_report(LOG_PROG, "nfrags=%d, ifrag=%d, decoded_frags=%d, data=%s\n", + gpsd_report(session->context->debug, LOG_PROG, + "nfrags=%d, ifrag=%d, decoded_frags=%d, data=%s\n", nfrags, ifrag, ais_context->decoded_frags, data); /* assemble the binary data */ /* check fragment ordering */ if (ifrag != ais_context->decoded_frags + 1) { - gpsd_report(LOG_ERROR, "invalid fragment #%d received, expected #%d.\n", - ifrag, ais_context->decoded_frags + 1); + gpsd_report(session->context->debug, LOG_ERROR, + "invalid fragment #%d received, expected #%d.\n", + ifrag, ais_context->decoded_frags + 1); if (ifrag != 1) return false; /* else, ifrag==1: Just discard all that was previously decoded and @@ -1327,7 +1355,8 @@ static bool aivdm_decode(const char *buf, size_t buflen, if (ch >= 40) ch -= 8; #ifdef __UNUSED_DEBUG__ - gpsd_report(LOG_RAW, "%c: %s\n", *cp, sixbits[ch]); + gpsd_report(session->context->debug, LOG_RAW, + "%c: %s\n", *cp, sixbits[ch]); #endif /* __UNUSED_DEBUG__ */ /*@ -shiftnegative @*/ for (i = 5; i >= 0; i--) { @@ -1337,7 +1366,8 @@ static bool aivdm_decode(const char *buf, size_t buflen, } ais_context->bitlen++; if (ais_context->bitlen > sizeof(ais_context->bits)) { - gpsd_report(LOG_INF, "overlong AIVDM payload truncated.\n"); + gpsd_report(session->context->debug, LOG_INF, + "overlong AIVDM payload truncated.\n"); return false; } } @@ -1351,7 +1381,8 @@ static bool aivdm_decode(const char *buf, size_t buflen, if (ifrag == nfrags) { if (debug >= LOG_INF) { size_t clen = (ais_context->bitlen + 7) / 8; - gpsd_report(LOG_INF, "AIVDM payload is %zd bits, %zd chars: %s\n", + gpsd_report(session->context->debug, LOG_INF, + "AIVDM payload is %zd bits, %zd chars: %s\n", ais_context->bitlen, clen, gpsd_hexdump((char *)ais_context->bits, clen)); } @@ -1360,7 +1391,8 @@ static bool aivdm_decode(const char *buf, size_t buflen, ais_context->decoded_frags = 0; /* decode the assembled binary packet */ - return ais_binary_decode(ais, + return ais_binary_decode(session->context->debug, + ais, ais_context->bits, ais_context->bitlen, split24 ? NULL : &ais_context->type24_queue); @@ -1466,7 +1498,8 @@ static void path_rewrite(struct gps_device_t *session, char *prefix) static gps_mask_t json_pass_packet(struct gps_device_t *session UNUSED) { - gpsd_report(LOG_IO, "<= GPS: %s\n", (char *)session->packet.outbuffer); + gpsd_report(session->context->debug, LOG_IO, + "<= GPS: %s\n", (char *)session->packet.outbuffer); /*@-nullpass@*/ /* required only because splint is buggy */ /* devices and paths need to be edited to */ @@ -1488,7 +1521,7 @@ static gps_mask_t json_pass_packet(struct gps_device_t *session UNUSED) sizeof(session->packet.outbuffer)); } - gpsd_report (LOG_PROG, + gpsd_report(session->context->debug, LOG_PROG, "JSON, passing through %s\n", (char *)session->packet.outbuffer); /*@-nullpass@*/ @@ -23,6 +23,7 @@ static int debuglevel; static unsigned int timeout = 8; +static struct gps_context_t context; /* * Set this as high or higher than the maximum number of subtype @@ -71,7 +72,8 @@ static gps_mask_t get_packet(struct gps_device_t *session) #endif if (errno == EINTR || !FD_ISSET(session->gpsdata.gps_fd, &rfds)) continue; - gpsd_report(LOG_ERROR, "select %s\n", strerror(errno)); + gpsd_report(session->context->debug, LOG_ERROR, + "select %s\n", strerror(errno)); exit(EXIT_FAILURE); } /*@ +usedef +type +nullpass +compdef @*/ @@ -80,7 +82,7 @@ static gps_mask_t get_packet(struct gps_device_t *session) /* conditional prevents mask dumper from eating CPU */ if (debuglevel >= LOG_DATA) - gpsd_report(LOG_DATA, + gpsd_report(session->context->debug, LOG_DATA, "packet mask = %s\n", gps_maskdump(session->gpsdata.set)); @@ -132,18 +134,18 @@ static bool gps_query(/*@out@*/struct gps_data_t *gpsdata, (void)strlcat(buf, "\n", BUFSIZ); /*@-usedef@*/ if (write(gpsdata->gps_fd, buf, strlen(buf)) <= 0) { - gpsd_report(LOG_ERROR, "gps_query(), write failed\n"); + gpsd_report(context.debug, LOG_ERROR, "gps_query(), write failed\n"); return false; } /*@+usedef@*/ - gpsd_report(LOG_PROG, "gps_query(), wrote, %s\n", buf); + gpsd_report(context.debug, LOG_PROG, "gps_query(), wrote, %s\n", buf); FD_ZERO(&rfds); starttime = time(NULL); for (;;) { FD_CLR(gpsdata->gps_fd, &rfds); - gpsd_report(LOG_PROG, "waiting...\n"); + gpsd_report(context.debug, LOG_PROG, "waiting...\n"); /*@ -usedef -type -nullpass -compdef @*/ tv.tv_sec = 2; @@ -156,16 +158,16 @@ static bool gps_query(/*@out@*/struct gps_data_t *gpsdata, #endif if (errno == EINTR || !FD_ISSET(gpsdata->gps_fd, &rfds)) continue; - gpsd_report(LOG_ERROR, "select %s\n", strerror(errno)); + gpsd_report(context.debug, LOG_ERROR, "select %s\n", strerror(errno)); exit(EXIT_FAILURE); } /*@ +usedef +type +nullpass +compdef @*/ - gpsd_report(LOG_PROG, "reading...\n"); + gpsd_report(context.debug, LOG_PROG, "reading...\n"); (void)gps_read(gpsdata); if (ERROR_SET & gpsdata->set) { - gpsd_report(LOG_ERROR, "error '%s'\n", gpsdata->error); + gpsd_report(context.debug, LOG_ERROR, "error '%s'\n", gpsdata->error); return false; } @@ -173,7 +175,7 @@ static bool gps_query(/*@out@*/struct gps_data_t *gpsdata, if ((expect & gpsdata->set) != 0) return true; else if (time(NULL) - starttime > timeout) { - gpsd_report(LOG_ERROR, + gpsd_report(context.debug, LOG_ERROR, "timed out after %d seconds\n", timeout); return false; @@ -187,10 +189,10 @@ static bool gps_query(/*@out@*/struct gps_data_t *gpsdata, static void onsig(int sig) { if (sig == SIGALRM) { - gpsd_report(LOG_ERROR, "packet recognition timed out.\n"); + gpsd_report(context.debug, LOG_ERROR, "packet recognition timed out.\n"); exit(EXIT_FAILURE); } else { - gpsd_report(LOG_ERROR, "killed by signal %d\n", sig); + gpsd_report(context.debug, LOG_ERROR, "killed by signal %d\n", sig); exit(EXIT_SUCCESS); } } @@ -235,7 +237,8 @@ int main(int argc, char **argv) #ifdef RECONFIGURE_ENABLE rate = optarg; #else - gpsd_report(LOG_ERROR, "cycle-change capability has been conditioned out.\n"); + gpsd_report(context.debug, LOG_ERROR, + "cycle-change capability has been conditioned out.\n"); #endif /* RECONFIGURE_ENABLE */ break; case 'x': /* ship specified control string */ @@ -243,12 +246,13 @@ int main(int argc, char **argv) control = optarg; lowlevel = true; if ((cooklen = hex_escapes(cooked, control)) <= 0) { - gpsd_report(LOG_ERROR, + gpsd_report(context.debug, LOG_ERROR, "invalid escape string (error %d)\n", (int)cooklen); exit(EXIT_FAILURE); } #else - gpsd_report(LOG_ERROR, "control_send capability has been conditioned out.\n"); + gpsd_report(context.debug, LOG_ERROR, + "control_send capability has been conditioned out.\n"); #endif /* CONTROLSEND_ENABLE */ break; case 'e': /* echo specified control string with wrapper */ @@ -287,7 +291,8 @@ int main(int argc, char **argv) #ifdef RECONFIGURE_ENABLE to_nmea = true; #else - gpsd_report(LOG_ERROR, "speed-change capability has been conditioned out.\n"); + gpsd_report(context.debug, LOG_ERROR, + "speed-change capability has been conditioned out.\n"); #endif /* RECONFIGURE_ENABLE */ break; case 'r': /* force-switch to default mode */ @@ -295,14 +300,16 @@ int main(int argc, char **argv) reset = true; lowlevel = false; /* so we'll abort if the daemon is running */ #else - gpsd_report(LOG_ERROR, "reset capability has been conditioned out.\n"); + gpsd_report(context.debug, LOG_ERROR, + "reset capability has been conditioned out.\n"); #endif /* RECONFIGURE_ENABLE */ break; case 's': /* change output baud rate */ #ifdef RECONFIGURE_ENABLE speed = optarg; #else - gpsd_report(LOG_ERROR, "speed-change capability has been conditioned out.\n"); + gpsd_report(context.debug, LOG_ERROR, + "speed-change capability has been conditioned out.\n"); #endif /* RECONFIGURE_ENABLE */ break; case 't': /* force the device type */ @@ -340,19 +347,22 @@ int main(int argc, char **argv) } } if (matchcount == 0) - gpsd_report(LOG_ERROR, "no driver type name matches '%s'.\n", devtype); + gpsd_report(context.debug, LOG_ERROR, + "no driver type name matches '%s'.\n", devtype); else if (matchcount == 1) { assert(forcetype != NULL); - gpsd_report(LOG_PROG, "%s driver selected.\n", forcetype->type_name); + gpsd_report(context.debug, LOG_PROG, + "%s driver selected.\n", forcetype->type_name); } else { forcetype = NULL; - gpsd_report(LOG_ERROR, "%d driver type names match '%s'.\n", + gpsd_report(context.debug, LOG_ERROR, + "%d driver type names match '%s'.\n", matchcount, devtype); } } if (((int)to_nmea + (int)to_binary + (int)reset) > 1) { - gpsd_report(LOG_ERROR, "make up your mind, would you?\n"); + gpsd_report(context.debug, LOG_ERROR, "make up your mind, would you?\n"); exit(EXIT_SUCCESS); } @@ -364,7 +374,8 @@ int main(int argc, char **argv) if (!lowlevel) { /* Try to open the stream to gpsd. */ if (gps_open(NULL, NULL, &gpsdata) != 0) { - gpsd_report(LOG_ERROR, "no gpsd running or network error: %s.\n", + gpsd_report(context.debug, LOG_ERROR, + "no gpsd running or network error: %s.\n", netlib_errstr(errno)); lowlevel = true; } @@ -376,21 +387,22 @@ int main(int argc, char **argv) /* what devices have we available? */ if (!gps_query(&gpsdata, DEVICELIST_SET, (int)timeout, "?DEVICES;\n")) { - gpsd_report(LOG_ERROR, "no DEVICES response received.\n"); + gpsd_report(context.debug, LOG_ERROR, "no DEVICES response received.\n"); (void)gps_close(&gpsdata); exit(EXIT_FAILURE); } if (gpsdata.devices.ndevices == 0) { - gpsd_report(LOG_ERROR, "no devices connected.\n"); + gpsd_report(context.debug, LOG_ERROR, "no devices connected.\n"); (void)gps_close(&gpsdata); exit(EXIT_FAILURE); } else if (gpsdata.devices.ndevices > 1 && device == NULL) { - gpsd_report(LOG_ERROR, + gpsd_report(context.debug, LOG_ERROR, "multiple devices and no device specified.\n"); (void)gps_close(&gpsdata); exit(EXIT_FAILURE); } - gpsd_report(LOG_PROG,"%d device(s) found.\n",gpsdata.devices.ndevices); + gpsd_report(context.debug, LOG_PROG, + "%d device(s) found.\n",gpsdata.devices.ndevices); /* try to mine the devicelist return for the data we want */ if (gpsdata.devices.ndevices == 1 && device == NULL) { @@ -402,7 +414,8 @@ int main(int argc, char **argv) if (strcmp(device, gpsdata.devices.list[i].path) == 0) { goto devicelist_entry_matches; } - gpsd_report(LOG_ERROR, "specified device not found in device list.\n"); + gpsd_report(context.debug, LOG_ERROR, + "specified device not found in device list.\n"); (void)gps_close(&gpsdata); exit(EXIT_FAILURE); devicelist_entry_matches:; @@ -415,7 +428,7 @@ int main(int argc, char **argv) /* if the device has not identified, watch it until it does so */ if (gpsdata.dev.driver[0] == '\0') { if (gps_stream(&gpsdata, WATCH_ENABLE|WATCH_JSON, NULL) == -1) { - gpsd_report(LOG_ERROR, "stream set failed.\n"); + gpsd_report(context.debug, LOG_ERROR, "stream set failed.\n"); (void)gps_close(&gpsdata); exit(EXIT_FAILURE); } @@ -423,7 +436,7 @@ int main(int argc, char **argv) while (devcount > 0) { errno = 0; if (gps_read(&gpsdata) == -1) { - gpsd_report(LOG_ERROR, "data read failed.\n"); + gpsd_report(context.debug, LOG_ERROR, "data read failed.\n"); (void)gps_close(&gpsdata); exit(EXIT_FAILURE); } @@ -436,7 +449,7 @@ int main(int argc, char **argv) } } } - gpsd_report(LOG_ERROR, "data read failed.\n"); + gpsd_report(context.debug, LOG_ERROR, "data read failed.\n"); (void)gps_close(&gpsdata); exit(EXIT_FAILURE); matching_device_seen:; @@ -444,7 +457,7 @@ int main(int argc, char **argv) /* sanity check */ if (gpsdata.dev.driver[0] == '\0') { - gpsd_report(LOG_SHOUT, "%s can't be identified.\n", + gpsd_report(context.debug, LOG_SHOUT, "%s can't be identified.\n", gpsdata.dev.path); (void)gps_close(&gpsdata); exit(EXIT_SUCCESS); @@ -452,7 +465,8 @@ int main(int argc, char **argv) /* if no control operation was specified, just ID the device */ if (speed==NULL && rate == NULL && !to_nmea && !to_binary && !reset) { - gpsd_report(LOG_SHOUT, "%s identified as %s at %d\n", + gpsd_report(context.debug, LOG_SHOUT, + "%s identified as %s at %d\n", gpsdata.dev.path, gpsdata.dev.driver, gpsdata.dev.baudrate); @@ -462,24 +476,29 @@ int main(int argc, char **argv) #ifdef RECONFIGURE_ENABLE if (reset) { - gpsd_report(LOG_PROG, "cannot reset with gpsd running.\n"); + gpsd_report(context.debug, LOG_PROG, + "cannot reset with gpsd running.\n"); exit(EXIT_SUCCESS); } /*@-boolops@*/ if (to_nmea) { if (!gps_query(&gpsdata, DEVICE_SET, (int)timeout, "?DEVICE={\"path\":\"%s\",\"native\":0}\r\n", device) || (gpsdata.dev.driver_mode != MODE_NMEA)) { - gpsd_report(LOG_ERROR, "%s mode change to NMEA failed\n", gpsdata.dev.path); + gpsd_report(context.debug, LOG_ERROR, + "%s mode change to NMEA failed\n", gpsdata.dev.path); status = 1; } else - gpsd_report(LOG_PROG, "%s mode change succeeded\n", gpsdata.dev.path); + gpsd_report(context.debug, LOG_PROG, + "%s mode change succeeded\n", gpsdata.dev.path); } else if (to_binary) { if (gps_query(&gpsdata, DEVICE_SET, (int)timeout, "?DEVICE={\"path\":\"%s\",\"native\":1}\r\n", device) || (gpsdata.dev.driver_mode != MODE_BINARY)) { - gpsd_report(LOG_ERROR, "%s mode change to native mode failed\n", gpsdata.dev.path); + gpsd_report(context.debug, LOG_ERROR, + "%s mode change to native mode failed\n", gpsdata.dev.path); status = 1; } else - gpsd_report(LOG_PROG, "%s mode change succeeded\n", gpsdata.dev.path); + gpsd_report(context.debug, LOG_PROG, + "%s mode change succeeded\n", gpsdata.dev.path); } /*@+boolops@*/ if (speed != NULL) { @@ -497,17 +516,20 @@ int main(int argc, char **argv) if (modespec!=NULL) { *modespec = '\0'; if (strchr("78", *++modespec) == NULL) { - gpsd_report(LOG_ERROR, "No support for that word lengths.\n"); + gpsd_report(context.debug, LOG_ERROR, + "No support for that word lengths.\n"); status = 1; } parity = *++modespec; if (strchr("NOE", parity) == NULL) { - gpsd_report(LOG_ERROR, "What parity is '%c'?\n", parity); + gpsd_report(context.debug, LOG_ERROR, + "What parity is '%c'?\n", parity); status = 1; } stopbits = *++modespec; if (strchr("12", stopbits) == NULL) { - gpsd_report(LOG_ERROR, "Stop bits must be 1 or 2.\n"); + gpsd_report(context.debug, LOG_ERROR, + "Stop bits must be 1 or 2.\n"); status = 1; } } @@ -518,12 +540,14 @@ int main(int argc, char **argv) device, speed, parity, stopbits); } if (atoi(speed) != (int)gpsdata.dev.baudrate) { - gpsd_report(LOG_ERROR, "%s driver won't support %s%c%c\n", + gpsd_report(context.debug, LOG_ERROR, + "%s driver won't support %s%c%c\n", gpsdata.dev.path, speed, parity, stopbits); status = 1; } else - gpsd_report(LOG_PROG, "%s change to %s%c%c succeeded\n", + gpsd_report(context.debug, LOG_PROG, + "%s change to %s%c%c succeeded\n", gpsdata.dev.path, speed, parity, stopbits); } @@ -545,7 +569,8 @@ int main(int argc, char **argv) int i; if (device == NULL || forcetype == NULL) { - gpsd_report(LOG_ERROR, "device and type must be specified for the reset operation.\n"); + gpsd_report(context.debug, LOG_ERROR, + "device and type must be specified for the reset operation.\n"); exit(EXIT_FAILURE); } @@ -575,7 +600,6 @@ int main(int argc, char **argv) #endif /* RECONFIGURE_ENABLE */ } else { /* access to the daemon failed, use the low-level facilities */ - static struct gps_context_t context; /* start it zeroed */ static struct gps_device_t session; /* zero this too */ /*@ -mustfreeonly -immediatetrans @*/ gps_context_init(&context); @@ -596,14 +620,15 @@ int main(int argc, char **argv) int seq; if (device == NULL) { - gpsd_report(LOG_ERROR, "device must be specified for low-level access.\n"); + gpsd_report(context.debug, LOG_ERROR, + "device must be specified for low-level access.\n"); exit(EXIT_FAILURE); } gpsd_time_init(&context, time(NULL)); gpsd_init(&session, &context, device); - gpsd_report(LOG_PROG, "initialization passed.\n"); + gpsd_report(context.debug, LOG_PROG, "initialization passed.\n"); if (gpsd_activate(&session) == -1) { - gpsd_report(LOG_ERROR, + gpsd_report(context.debug, LOG_ERROR, "activation of device %s failed, errno=%d\n", device, errno); exit(EXIT_FAILURE); @@ -611,21 +636,27 @@ int main(int argc, char **argv) /* hunt for packet type and serial parameters */ for (seq = 0; session.device_type == NULL; seq++) { if (get_packet(&session) == ERROR_SET) { - gpsd_report(LOG_ERROR, + gpsd_report(context.debug, LOG_ERROR, "autodetection failed.\n"); exit(EXIT_FAILURE); } else if (session.packet.type > COMMENT_PACKET) { - gpsd_report(LOG_IO, - "autodetection after %d reads finds packet type %d.\n", seq, session.packet.type); + gpsd_report(context.debug, LOG_IO, + "autodetection after %d reads finds packet type %d.\n", + seq, session.packet.type); (void) alarm(0); break; } } - gpsd_report(LOG_PROG, "%s looks like a %s at %d.\n", - device, gpsd_id(&session), session.gpsdata.dev.baudrate); + gpsd_report(context.debug, LOG_PROG, + "%s looks like a %s at %d.\n", + device, gpsd_id(&session), + session.gpsdata.dev.baudrate); if (forcetype!=NULL && strcmp("Generic NMEA", session.device_type->type_name) !=0 && strcmp(forcetype->type_name, session.device_type->type_name)!=0) { - gpsd_report(LOG_ERROR, "'%s' doesn't match non-generic type '%s' of selected device.\n", forcetype->type_name, session.device_type->type_name); + gpsd_report(context.debug, LOG_ERROR, + "'%s' doesn't match non-generic type '%s' of selected device.\n", + forcetype->type_name, + session.device_type->type_name); } /* @@ -642,8 +673,10 @@ int main(int argc, char **argv) break; } } - gpsd_report(LOG_SHOUT, "%s identified as a %s at %d.\n", - device, gpsd_id(&session), session.gpsdata.dev.baudrate); + gpsd_report(context.debug, LOG_SHOUT, + "%s identified as a %s at %d.\n", + device, gpsd_id(&session), + session.gpsdata.dev.baudrate); } /* if no control operation was specified, we're done */ @@ -666,15 +699,15 @@ int main(int argc, char **argv) bool write_enable = context.readonly; context.readonly = false; if (session.device_type->mode_switcher == NULL) { - gpsd_report(LOG_SHOUT, + gpsd_report(context.debug, LOG_SHOUT, "%s devices have no mode switch.\n", session.device_type->type_name); status = 1; } else { int target_mode = to_nmea ? MODE_NMEA : MODE_BINARY; - gpsd_report(LOG_SHOUT, - "switching to mode %s.\n", + gpsd_report(context.debug, LOG_SHOUT, + "switching to mode %s.\n", to_nmea ? "NMEA" : "BINARY"); session.device_type->mode_switcher(&session, target_mode); settle(&session); @@ -692,24 +725,27 @@ int main(int argc, char **argv) if (modespec!=NULL) { *modespec = '\0'; if (strchr("78", *++modespec) == NULL) { - gpsd_report(LOG_ERROR, "No support for that word lengths.\n"); + gpsd_report(context.debug, LOG_ERROR, + "No support for that word lengths.\n"); status = 1; } parity = *++modespec; if (strchr("NOE", parity) == NULL) { - gpsd_report(LOG_ERROR, "What parity is '%c'?\n", parity); + gpsd_report(context.debug, LOG_ERROR, + "What parity is '%c'?\n", parity); status = 1; } stopbits = *++modespec; if (strchr("12", parity) == NULL) { - gpsd_report(LOG_ERROR, "Stop bits must be 1 or 2.\n"); + gpsd_report(context.debug, LOG_ERROR, + "Stop bits must be 1 or 2.\n"); status = 1; } stopbits = (int)(stopbits-'0'); } if (status == 0) { if (session.device_type->speed_switcher == NULL) { - gpsd_report(LOG_ERROR, + gpsd_report(context.debug, LOG_ERROR, "%s devices have no speed switch.\n", session.device_type->type_name); status = 1; @@ -719,11 +755,13 @@ int main(int argc, char **argv) parity, stopbits)) { settle(&session); - gpsd_report(LOG_PROG, "%s change to %s%c%d succeeded\n", - session.gpsdata.dev.path, - speed, parity, stopbits); + gpsd_report(context.debug, LOG_PROG, + "%s change to %s%c%d succeeded\n", + session.gpsdata.dev.path, + speed, parity, stopbits); } else { - gpsd_report(LOG_ERROR, "%s driver won't support %s%c%d.\n", + gpsd_report(context.debug, LOG_ERROR, + "%s driver won't support %s%c%d.\n", session.gpsdata.dev.path, speed, parity, stopbits); status = 1; @@ -734,7 +772,7 @@ int main(int argc, char **argv) bool write_enable = context.readonly; context.readonly = false; if (session.device_type->rate_switcher == NULL) { - gpsd_report(LOG_ERROR, + gpsd_report(context.debug, LOG_ERROR, "%s devices have no rate switcher.\n", session.device_type->type_name); status = 1; @@ -742,7 +780,7 @@ int main(int argc, char **argv) double rate_dbl = strtod(rate, NULL); if (!session.device_type->rate_switcher(&session, rate_dbl)) { - gpsd_report(LOG_ERROR, "rate switch failed.\n"); + gpsd_report(context.debug, LOG_ERROR, "rate switch failed.\n"); status = 1; } settle(&session); @@ -756,7 +794,7 @@ int main(int argc, char **argv) bool write_enable = context.readonly; context.readonly = false; if (session.device_type->control_send == NULL) { - gpsd_report(LOG_ERROR, + gpsd_report(context.debug, LOG_ERROR, "%s devices have no control sender.\n", session.device_type->type_name); status = 1; @@ -764,7 +802,8 @@ int main(int argc, char **argv) if (session.device_type->control_send(&session, cooked, (size_t)cooklen) == -1) { - gpsd_report(LOG_ERROR, "control transmission failed.\n"); + gpsd_report(context.debug, LOG_ERROR, + "control transmission failed.\n"); status = 1; } settle(&session); @@ -180,11 +180,12 @@ static void visibilize(/*@out@*/char *buf2, size_t len, const char *buf) 0x00ff & (unsigned)*sp); } -void gpsd_report(int errlevel, const char *fmt, ...) +void gpsd_report(const int debuglevel, const int errlevel, + const char *fmt, ...) /* assemble command in printf(3) style, use stderr or syslog */ { #ifndef SQUELCH_ENABLE - if (errlevel <= context.debug) { + if (errlevel <= debuglevel) { char buf[BUFSIZ], buf2[BUFSIZ]; char *err_str; va_list ap; @@ -324,18 +325,18 @@ static socket_t filesock(char *filename) /*@ -mayaliasunique -usedef @*/ if (BAD_SOCKET(sock = socket(AF_UNIX, SOCK_STREAM, 0))) { - gpsd_report(LOG_ERROR, "Can't create device-control socket\n"); + gpsd_report(context.debug, LOG_ERROR, "Can't create device-control socket\n"); return -1; } (void)strlcpy(addr.sun_path, filename, sizeof(addr.sun_path)); addr.sun_family = (sa_family_t)AF_UNIX; if (bind(sock, (struct sockaddr *)&addr, (int)sizeof(addr)) < 0) { - gpsd_report(LOG_ERROR, "can't bind to local socket %s\n", filename); + gpsd_report(context.debug, LOG_ERROR, "can't bind to local socket %s\n", filename); (void)close(sock); return -1; } if (listen(sock, QLEN) == -1) { - gpsd_report(LOG_ERROR, "can't listen on local socket %s\n", filename); + gpsd_report(context.debug, LOG_ERROR, "can't listen on local socket %s\n", filename); (void)close(sock); return -1; } @@ -418,7 +419,8 @@ static socket_t passivesock_af(int af, char *service, char *tcp_or_udp, int qlen if ((pse = getservbyname(service, tcp_or_udp))) port = ntohs((in_port_t) pse->s_port); else if ((port = (in_port_t) atoi(service)) == 0) { - gpsd_report(LOG_ERROR, "can't get \"%s\" service entry.\n", service); + gpsd_report(context.debug, LOG_ERROR, + "can't get \"%s\" service entry.\n", service); return -1; } ppe = getprotobyname(tcp_or_udp); @@ -483,7 +485,8 @@ static socket_t passivesock_af(int af, char *service, char *tcp_or_udp, int qlen if (s > -1) { int on = 1; if (setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof(on)) == -1) { - gpsd_report(LOG_ERROR, "Error: SETSOCKOPT IPV6_V6ONLY\n"); + gpsd_report(context.debug, LOG_ERROR, + "Error: SETSOCKOPT IPV6_V6ONLY\n"); (void)close(s); return -1; } @@ -491,37 +494,43 @@ static socket_t passivesock_af(int af, char *service, char *tcp_or_udp, int qlen break; #endif default: - gpsd_report(LOG_ERROR, "unhandled address family %d\n", af); + gpsd_report(context.debug, LOG_ERROR, + "unhandled address family %d\n", af); return -1; } - gpsd_report(LOG_IO, "opening %s socket\n", af_str); + gpsd_report(context.debug, LOG_IO, + "opening %s socket\n", af_str); if (BAD_SOCKET(s)) { - gpsd_report(LOG_ERROR, "can't create %s socket\n", af_str); + gpsd_report(context.debug, LOG_ERROR, + "can't create %s socket\n", af_str); return -1; } if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (char *)&one, (int)sizeof(one)) == -1) { - gpsd_report(LOG_ERROR, "Error: SETSOCKOPT SO_REUSEADDR\n"); + gpsd_report(context.debug, LOG_ERROR, + "Error: SETSOCKOPT SO_REUSEADDR\n"); (void)close(s); return -1; } if (bind(s, &sat.sa, sin_len) < 0) { - gpsd_report(LOG_ERROR, "can't bind to %s port %s, %s\n", af_str, + gpsd_report(context.debug, LOG_ERROR, + "can't bind to %s port %s, %s\n", af_str, service, strerror(errno)); if (errno == EADDRINUSE) { - gpsd_report(LOG_ERROR, "maybe gpsd is already running!\n"); + gpsd_report(context.debug, LOG_ERROR, + "maybe gpsd is already running!\n"); } (void)close(s); return -1; } if (type == SOCK_STREAM && listen(s, qlen) == -1) { - gpsd_report(LOG_ERROR, "can't listen on port %s\n", service); + gpsd_report(context.debug, LOG_ERROR, "can't listen on port %s\n", service); (void)close(s); return -1; } - gpsd_report(LOG_SPIN, "passivesock_af() -> %d\n", s); + gpsd_report(context.debug, LOG_SPIN, "passivesock_af() -> %d\n", s); return s; /*@ +mustfreefresh -matchanyintegral @*/ } @@ -606,9 +615,12 @@ static void detach_client(struct subscriber_t *sub) return; c_ip = netlib_sock2ip(sub->fd); (void)shutdown(sub->fd, SHUT_RDWR); - gpsd_report(LOG_SPIN, "close(%d) in detach_client()\n", sub->fd); + gpsd_report(context.debug, LOG_SPIN, + "close(%d) in detach_client()\n", + sub->fd); (void)close(sub->fd); - gpsd_report(LOG_INF, "detaching %s (sub %d, fd %d) in detach_client\n", + gpsd_report(context.debug, LOG_INF, + "detaching %s (sub %d, fd %d) in detach_client\n", c_ip, sub_index(sub), sub->fd); FD_CLR(sub->fd, &all_fds); adjust_max_fd(sub->fd, false); @@ -633,7 +645,8 @@ static ssize_t throttled_write(struct subscriber_t *sub, char *buf, if (context.debug >= 3) { if (isprint(buf[0])) - gpsd_report(LOG_IO, "=> client(%d): %s\n", sub_index(sub), buf); + gpsd_report(context.debug, LOG_IO, + "=> client(%d): %s\n", sub_index(sub), buf); else { char *cp, buf2[MAX_PACKET_LENGTH * 3]; buf2[0] = '\0'; @@ -641,8 +654,8 @@ static ssize_t throttled_write(struct subscriber_t *sub, char *buf, (void)snprintf(buf2 + strlen(buf2), sizeof(buf2) - strlen(buf2), "%02x", (unsigned int)(*cp & 0xff)); - gpsd_report(LOG_IO, "=> client(%d): =%s\n", sub_index(sub), - buf2); + gpsd_report(context.debug, LOG_IO, + "=> client(%d): =%s\n", sub_index(sub), buf2); } } @@ -660,20 +673,23 @@ static ssize_t throttled_write(struct subscriber_t *sub, char *buf, if (status == (ssize_t) len) return status; else if (status > -1) { - gpsd_report(LOG_INF, "short write disconnecting client(%d)\n", + gpsd_report(context.debug, LOG_INF, + "short write disconnecting client(%d)\n", sub_index(sub)); detach_client(sub); return 0; } else if (errno == EAGAIN || errno == EINTR) return 0; /* no data written, and errno says to retry */ else if (errno == EBADF) - gpsd_report(LOG_WARN, "client(%d) has vanished.\n", sub_index(sub)); + gpsd_report(context.debug, LOG_WARN, "client(%d) has vanished.\n", sub_index(sub)); else if (errno == EWOULDBLOCK && timestamp() - sub->active > NOREAD_TIMEOUT) - gpsd_report(LOG_INF, "client(%d) timed out.\n", sub_index(sub)); + gpsd_report(context.debug, LOG_INF, + "client(%d) timed out.\n", sub_index(sub)); else - gpsd_report(LOG_INF, "client(%d) write: %s\n", sub_index(sub), - strerror(errno)); + gpsd_report(context.debug, LOG_INF, + "client(%d) write: %s\n", + sub_index(sub), strerror(errno)); detach_client(sub); return status; } @@ -739,8 +755,8 @@ static bool open_device( /*@null@*/struct gps_device_t *device) if (NULL == device || gpsd_activate(device) < 0) { return false; } - gpsd_report(LOG_INF, "device %s activated\n", - device->gpsdata.dev.path); + gpsd_report(context.debug, LOG_INF, + "device %s activated\n", device->gpsdata.dev.path); FD_SET(device->gpsdata.gps_fd, &all_fds); adjust_max_fd(device->gpsdata.gps_fd, true); return true; @@ -753,7 +769,7 @@ bool gpsd_add_device(const char *device_name, bool flag_nowait) bool ret = false; /* we can't handle paths longer than GPS_PATH_MAX, so don't try */ if (strlen(device_name) >= GPS_PATH_MAX) { - gpsd_report(LOG_ERROR, + gpsd_report(context.debug, LOG_ERROR, "ignoring device %s: path length exceeds maximum %d\n", device_name, GPS_PATH_MAX); return false; @@ -773,11 +789,13 @@ bool gpsd_add_device(const char *device_name, bool flag_nowait) if (!(devp->shmindex >= 0)) ntpd_link_activate(devp); - gpsd_report(LOG_INF, "NTPD ntpd_link_activate: %d\n", + gpsd_report(context.debug, LOG_INF, + "NTPD ntpd_link_activate: %d\n", (int)devp->shmindex >= 0); #endif /* NTPSHM_ENABLE */ - gpsd_report(LOG_INF, "stashing device %s at slot %d\n", + gpsd_report(context.debug, LOG_INF, + "stashing device %s at slot %d\n", device_name, (int)(devp - devices)); if (!flag_nowait) { devp->gpsdata.gps_fd = -1; @@ -829,7 +847,8 @@ static void handle_control(int sfd, char *buf) if (buf[0] == '-') { /* remove device named after - */ (void)snarfline(buf + 1, &stash); - gpsd_report(LOG_INF, "<= control(%d): removing %s\n", sfd, stash); + gpsd_report(context.debug, LOG_INF, + "<= control(%d): removing %s\n", sfd, stash); if ((devp = find_device(stash))) { deactivate_device(devp); free_device(devp); @@ -840,11 +859,13 @@ static void handle_control(int sfd, char *buf) /* add device named after + */ (void)snarfline(buf + 1, &stash); if (find_device(stash)) { - gpsd_report(LOG_INF, "<= control(%d): %s already active \n", sfd, + gpsd_report(context.debug, LOG_INF, + "<= control(%d): %s already active \n", sfd, stash); ignore_return(write(sfd, "ERROR\n", 6)); } else { - gpsd_report(LOG_INF, "<= control(%d): adding %s\n", sfd, stash); + gpsd_report(context.debug, LOG_INF, + "<= control(%d): adding %s\n", sfd, stash); if (gpsd_add_device(stash, NOWAIT)) ignore_return(write(sfd, "OK\n", 3)); else @@ -856,21 +877,24 @@ static void handle_control(int sfd, char *buf) (void)snarfline(buf + 1, &stash); eq = strchr(stash, '='); if (eq == NULL) { - gpsd_report(LOG_WARN, "<= control(%d): ill-formed command \n", + gpsd_report(context.debug, LOG_WARN, + "<= control(%d): ill-formed command \n", sfd); ignore_return(write(sfd, "ERROR\n", 6)); } else { *eq++ = '\0'; if ((devp = find_device(stash))) { if (devp->context->readonly || (devp->sourcetype <= source_blockdev)) { - gpsd_report(LOG_WARN, "<= control(%d): attempted to write to a read-only device\n", + gpsd_report(context.debug, LOG_WARN, + "<= control(%d): attempted to write to a read-only device\n", sfd); ignore_return(write(sfd, "ERROR\n", 6)); } else { - gpsd_report(LOG_INF, "<= control(%d): writing to %s \n", sfd, + gpsd_report(context.debug, LOG_INF, + "<= control(%d): writing to %s \n", sfd, stash); if (write(devp->gpsdata.gps_fd, eq, strlen(eq)) <= 0) { - gpsd_report(LOG_WARN, "<= control(%d): write to device failed\n", + gpsd_report(context.debug, LOG_WARN, "<= control(%d): write to device failed\n", sfd); ignore_return(write(sfd, "ERROR\n", 6)); } else { @@ -878,7 +902,8 @@ static void handle_control(int sfd, char *buf) } } } else { - gpsd_report(LOG_INF, "<= control(%d): %s not active \n", sfd, + gpsd_report(context.debug, LOG_INF, + "<= control(%d): %s not active \n", sfd, stash); ignore_return(write(sfd, "ERROR\n", 6)); } @@ -889,7 +914,8 @@ static void handle_control(int sfd, char *buf) (void)snarfline(buf + 1, &stash); eq = strchr(stash, '='); if (eq == NULL) { - gpsd_report(LOG_WARN, "<= control(%d): ill-formed command\n", + gpsd_report(context.debug, LOG_WARN, + "<= control(%d): ill-formed command\n", sfd); ignore_return(write(sfd, "ERROR\n", 6)); } else { @@ -898,7 +924,8 @@ static void handle_control(int sfd, char *buf) len = strlen(eq) + 5; if ((devp = find_device(stash)) != NULL) { if (devp->context->readonly || (devp->sourcetype <= source_blockdev)) { - gpsd_report(LOG_WARN, "<= control(%d): attempted to write to a read-only device\n", + gpsd_report(context.debug, LOG_WARN, + "<= control(%d): attempted to write to a read-only device\n", sfd); ignore_return(write(sfd, "ERROR\n", 6)); } else { @@ -906,16 +933,17 @@ static void handle_control(int sfd, char *buf) /* NOTE: this destroys the original buffer contents */ st = gpsd_hexpack(eq, eq, len); if (st <= 0) { - gpsd_report(LOG_INF, + gpsd_report(context.debug, LOG_INF, "<= control(%d): invalid hex string (error %d).\n", sfd, st); ignore_return(write(sfd, "ERROR\n", 6)); } else { - gpsd_report(LOG_INF, + gpsd_report(context.debug, LOG_INF, "<= control(%d): writing %d bytes fromhex(%s) to %s\n", sfd, st, eq, stash); if (write(devp->gpsdata.gps_fd, eq, (size_t) st) <= 0) { - gpsd_report(LOG_WARN, "<= control(%d): write to device failed\n", + gpsd_report(context.debug, LOG_WARN, + "<= control(%d): write to device failed\n", sfd); ignore_return(write(sfd, "ERROR\n", 6)); } else { @@ -924,7 +952,8 @@ static void handle_control(int sfd, char *buf) } } } else { - gpsd_report(LOG_INF, "<= control(%d): %s not active\n", sfd, + gpsd_report(context.debug, LOG_INF, + "<= control(%d): %s not active\n", sfd, stash); ignore_return(write(sfd, "ERROR\n", 6)); } @@ -952,7 +981,8 @@ static bool awaken(struct gps_device_t *device) /* open that device */ if (!initialized_device(device)) { if (!open_device(device)) { - gpsd_report(LOG_PROG, "%s: open failed\n", + gpsd_report(context.debug, LOG_PROG, + "%s: open failed\n", device->gpsdata.dev.path); free_device(device); return false; @@ -960,18 +990,19 @@ static bool awaken(struct gps_device_t *device) } if (!BAD_SOCKET(device->gpsdata.gps_fd)) { - gpsd_report(LOG_PROG, + gpsd_report(context.debug, LOG_PROG, "device %d (fd=%d, path %s) already active.\n", (int)(device - devices), device->gpsdata.gps_fd, device->gpsdata.dev.path); return true; } else { if (gpsd_activate(device) < 0) { - gpsd_report(LOG_ERROR, "%s: device activation failed.\n", + gpsd_report(context.debug, LOG_ERROR, + "%s: device activation failed.\n", device->gpsdata.dev.path); return false; } else { - gpsd_report(LOG_RAW, + gpsd_report(context.debug, LOG_RAW, "flagging descriptor %d in assign_channel()\n", device->gpsdata.gps_fd); FD_SET(device->gpsdata.gps_fd, &all_fds); @@ -1018,8 +1049,9 @@ static void set_serial(struct gps_device_t *device, } } - gpsd_report(LOG_PROG, "set_serial(,%d,%s) %c%d\n", speed, modestring, - parity, stopbits); + gpsd_report(context.debug, LOG_PROG, + "set_serial(,%d,%s) %c%d\n", + speed, modestring, parity, stopbits); /* no support for other word sizes yet */ /* *INDENT-OFF* */ if (wordsize == (int)(9 - stopbits) @@ -1131,7 +1163,7 @@ static void handle_request(struct subscriber_t *sub, (void)snprintf(reply, replylen, "{\"class\":\"ERROR\",\"message\":\"Invalid WATCH: %s\"}\r\n", json_error_string(status)); - gpsd_report(LOG_ERROR, "response: %s\n", reply); + gpsd_report(context.debug, LOG_ERROR, "response: %s\n", reply); } else if (sub->policy.watcher) { if (sub->policy.devpath[0] == '\0') { /* awaken all devices */ @@ -1149,7 +1181,8 @@ static void handle_request(struct subscriber_t *sub, (void)snprintf(reply, replylen, "{\"class\":\"ERROR\",\"message\":\"No such device as %s\"}\r\n", sub->policy.devpath); - gpsd_report(LOG_ERROR, "response: %s\n", reply); + gpsd_report(context.debug, LOG_ERROR, + "response: %s\n", reply); goto bailout; } else if (awaken(devp)) { if (devp->sourcetype == source_gpsd) { @@ -1160,7 +1193,8 @@ static void handle_request(struct subscriber_t *sub, (void)snprintf(reply, replylen, "{\"class\":\"ERROR\",\"message\":\"Can't assign %s\"}\r\n", sub->policy.devpath); - gpsd_report(LOG_ERROR, "response: %s\n", reply); + gpsd_report(context.debug, LOG_ERROR, + "response: %s\n", reply); goto bailout; } } @@ -1195,7 +1229,7 @@ static void handle_request(struct subscriber_t *sub, (void)snprintf(reply, replylen, "{\"class\":\"ERROR\",\"message\":\"Invalid DEVICE: \"%s\"}\r\n", json_error_string(status)); - gpsd_report(LOG_ERROR, "response: %s\n", reply); + gpsd_report(context.debug, LOG_ERROR, "response: %s\n", reply); goto bailout; } else { if (devconf.path[0] != '\0') { @@ -1206,7 +1240,8 @@ static void handle_request(struct subscriber_t *sub, (void)snprintf(reply, replylen, "{\"class\":\"ERROR\",\"message\":\"Can't open %s.\"}\r\n", devconf.path); - gpsd_report(LOG_ERROR, "response: %s\n", reply); + gpsd_report(context.debug, LOG_ERROR, + "response: %s\n", reply); goto bailout; } } else { @@ -1221,13 +1256,15 @@ static void handle_request(struct subscriber_t *sub, (void)strlcat(reply, "{\"class\":\"ERROR\",\"message\":\"Can't perform DEVICE configuration, no devices attached.\"}\r\n", replylen); - gpsd_report(LOG_ERROR, "response: %s\n", reply); + gpsd_report(context.debug, LOG_ERROR, + "response: %s\n", reply); goto bailout; } else if (devcount > 1) { (void)snprintf(reply + strlen(reply), replylen - strlen(reply), "{\"class\":\"ERROR\",\"message\":\"No path specified in DEVICE, but multiple devices are attached.\"}\r\n"); - gpsd_report(LOG_ERROR, "response: %s\n", reply); + gpsd_report(context.debug, LOG_ERROR, + "response: %s\n", reply); goto bailout; } /* we should have exactly one device now */ @@ -1360,7 +1397,7 @@ static void handle_request(struct subscriber_t *sub, (void)snprintf(reply, replylen, "{\"class\":\"ERROR\",\"message\":\"Unrecognized request '%.*s'\"}\r\n", (int)(errend - buf), buf); - gpsd_report(LOG_ERROR, "ERROR response: %s\n", reply); + gpsd_report(context.debug, LOG_ERROR, "ERROR response: %s\n", reply); buf += strlen(buf); } bailout: @@ -1427,28 +1464,32 @@ static void pseudonmea_report(struct subscriber_t *sub, if ((changed & REPORT_IS) != 0) { nmea_tpv_dump(device, buf, sizeof(buf)); - gpsd_report(LOG_IO, "<= GPS (binary tpv) %s: %s\n", + gpsd_report(context.debug, LOG_IO, + "<= GPS (binary tpv) %s: %s\n", device->gpsdata.dev.path, buf); (void)throttled_write(sub, buf, strlen(buf)); } if ((changed & SATELLITE_SET) != 0) { nmea_sky_dump(device, buf, sizeof(buf)); - gpsd_report(LOG_IO, "<= GPS (binary sky) %s: %s\n", + gpsd_report(context.debug, LOG_IO, + "<= GPS (binary sky) %s: %s\n", device->gpsdata.dev.path, buf); (void)throttled_write(sub, buf, strlen(buf)); } if ((changed & SUBFRAME_SET) != 0) { nmea_subframe_dump(device, buf, sizeof(buf)); - gpsd_report(LOG_IO, "<= GPS (binary subframe) %s: %s\n", + gpsd_report(context.debug, LOG_IO, + "<= GPS (binary subframe) %s: %s\n", device->gpsdata.dev.path, buf); (void)throttled_write(sub, buf, strlen(buf)); } #ifdef AIVDM_ENABLE if ((changed & AIS_SET) != 0) { nmea_ais_dump(device, buf, sizeof(buf)); - gpsd_report(LOG_IO, "<= AIS (binary ais) %s: %s\n", + gpsd_report(context.debug, LOG_IO, + "<= AIS (binary ais) %s: %s\n", device->gpsdata.dev.path, buf); (void)throttled_write(sub, buf, strlen(buf)); } @@ -1466,8 +1507,8 @@ static void consume_packets(struct gps_device_t *device) struct subscriber_t *sub; #endif /* SOCKET_EXPORT_ENABLE */ - gpsd_report(LOG_RAW + 1, "polling %d\n", - device->gpsdata.gps_fd); + gpsd_report(context.debug, LOG_RAW + 1, + "polling %d\n", device->gpsdata.gps_fd); #ifdef NETFEED_ENABLE /* @@ -1483,7 +1524,7 @@ static void consume_packets(struct gps_device_t *device) } (void)ntrip_open(device, ""); if (device->ntrip.conn_state == ntrip_conn_err) { - gpsd_report(LOG_WARN, + gpsd_report(context.debug, LOG_WARN, "connection to ntrip server failed\n"); device->ntrip.conn_state = ntrip_conn_init; deactivate_device(device); @@ -1498,7 +1539,7 @@ static void consume_packets(struct gps_device_t *device) changed = gpsd_poll(device); if (changed == ERROR_SET) { - gpsd_report(LOG_WARN, + gpsd_report(context.debug, LOG_WARN, "device read of %s returned error or packet sniffer failed sync (flags %s)\n", device->gpsdata.dev.path, gps_maskdump(changed)); @@ -1510,7 +1551,7 @@ static void consume_packets(struct gps_device_t *device) * fd may have been in an end-of-file condition on select. */ if (fragments == 0) { - gpsd_report(LOG_DATA, + gpsd_report(context.debug, LOG_DATA, "%s returned zero bytes\n", device->gpsdata.dev.path); if (device->zerokill) { @@ -1519,9 +1560,11 @@ static void consume_packets(struct gps_device_t *device) if (device->ntrip.works) { device->ntrip.works = false; // reset so we try this once only if (gpsd_activate(device) < 0) { - gpsd_report(LOG_WARN, "reconnect to ntrip server failed\n"); + gpsd_report(context.debug, LOG_WARN, + "reconnect to ntrip server failed\n"); } else { - gpsd_report(LOG_INFO, "reconnecting to ntrip server\n"); + gpsd_report(context.debug, LOG_INFO, + "reconnecting to ntrip server\n"); FD_SET(device->gpsdata.gps_fd, &all_fds); } } @@ -1530,7 +1573,7 @@ static void consume_packets(struct gps_device_t *device) * Disable listening to this fd for long enough * that the buffer can fill up again. */ - gpsd_report(LOG_DATA, + gpsd_report(context.debug, LOG_DATA, "%s will be repolled in %f seconds\n", device->gpsdata.dev.path, DEVICE_REAWAKE); device->reawake = timestamp() + DEVICE_REAWAKE; @@ -1557,7 +1600,7 @@ static void consume_packets(struct gps_device_t *device) /* conditional prevents mask dumper from eating CPU */ if (context.debug >= LOG_DATA) - gpsd_report(LOG_DATA, + gpsd_report(context.debug, LOG_DATA, "packet type %d from %s with %s\n", device->packet.type, device->gpsdata.dev.path, @@ -1594,7 +1637,7 @@ static void consume_packets(struct gps_device_t *device) */ if ((changed & RTCM2_SET) != 0 || (changed & RTCM3_SET) != 0) { if (device->packet.outbuflen > RTCM_MAX) { - gpsd_report(LOG_ERROR, + gpsd_report(context.debug, LOG_ERROR, "overlong RTCM packet (%zd bytes)\n", device->packet.outbuflen); } else { @@ -1606,9 +1649,11 @@ static void consume_packets(struct gps_device_t *device) if (dp->device_type->rtcm_writer(dp, (const char *)device->packet.outbuffer, device->packet.outbuflen) == 0) - gpsd_report(LOG_ERROR, "Write to RTCM sink failed\n"); + gpsd_report(context.debug, LOG_ERROR, + "Write to RTCM sink failed\n"); else { - gpsd_report(LOG_IO, "<= DGPS: %zd bytes of RTCM relayed.\n", + gpsd_report(context.debug, LOG_IO, + "<= DGPS: %zd bytes of RTCM relayed.\n", device->packet.outbuflen); } } @@ -1632,18 +1677,18 @@ static void consume_packets(struct gps_device_t *device) * Else we may be providing GPS time. */ if (device->context->enable_ntpshm == 0) { - //gpsd_report(LOG_PROG, "NTP: off\n"); + //gpsd_report(context.debug, LOG_PROG, "NTP: off\n"); } else if ((changed & TIME_SET) == 0) { - //gpsd_report(LOG_PROG, "NTP: No time this packet\n"); + //gpsd_report(context.debug, LOG_PROG, "NTP: No time this packet\n"); } else if (isnan(device->newdata.time)) { - //gpsd_report(LOG_PROG, "NTP: bad new time\n"); + //gpsd_report(context.debug, LOG_PROG, "NTP: bad new time\n"); } else if (device->newdata.time == device->last_fixtime) { - //gpsd_report(LOG_PROG, "NTP: Not a new time\n"); + //gpsd_report(context.debug, LOG_PROG, "NTP: Not a new time\n"); } else if (!device->ship_to_ntpd) { - //gpsd_report(LOG_PROG, "NTP: No precision time report\n"); + //gpsd_report(context.debug, LOG_PROG, "NTP: No precision time report\n"); } else { double offset; - //gpsd_report(LOG_PROG, "NTP: Got one\n"); + //gpsd_report(context.debug, LOG_PROG, "NTP: Got one\n"); /* assume zero when there's no offset method */ if (device->device_type == NULL || device->device_type->ntp_offset == NULL) @@ -1718,12 +1763,13 @@ static void consume_packets(struct gps_device_t *device) if (changed & DATA_IS) { /* guard keeps mask dumper from eating CPU */ if (context.debug >= LOG_PROG) - gpsd_report(LOG_PROG, + gpsd_report(context.debug, LOG_PROG, "Changed mask: %s with %sreliable cycle detection\n", gps_maskdump(changed), device->cycle_end_reliable ? "" : "un"); if ((changed & REPORT_IS) != 0) - gpsd_report(LOG_PROG, "time to report a fix\n"); + gpsd_report(context.debug, LOG_PROG, + "time to report a fix\n"); if (sub->policy.nmea) pseudonmea_report(sub, changed, device); @@ -1811,7 +1857,7 @@ static void netgnss_autoconnect(struct gps_context_t *context, FILE *sfp = fopen(serverlist, "r"); if (sfp == NULL) { - gpsd_report(LOG_ERROR, "no DGPS server list found.\n"); + gpsd_report(context.debug, LOG_ERROR, "no DGPS server list found.\n"); return; } @@ -1845,7 +1891,8 @@ static void netgnss_autoconnect(struct gps_context_t *context, (void)fclose(sfp); if (keep[0].server[0] == '\0') { - gpsd_report(LOG_ERROR, "no DGPS servers within %dm.\n", + gpsd_report(context.debug, LOG_ERROR, + "no DGPS servers within %dm.\n", (int)(DGPS_THRESHOLD / 1000)); return; } @@ -1855,7 +1902,8 @@ static void netgnss_autoconnect(struct gps_context_t *context, qsort((void *)keep, SERVER_SAMPLE, sizeof(struct dgps_server_t), srvcmp); for (sp = keep; sp < keep + SERVER_SAMPLE; sp++) { if (sp->server[0] != '\0') { - gpsd_report(LOG_INF, "%s is %dkm away.\n", sp->server, + gpsd_report(context.debug, LOG_INF, + "%s is %dkm away.\n", sp->server, (int)(sp->dist / 1000)); if (dgpsip_open(context, sp->server) >= 0) break; @@ -1961,7 +2009,7 @@ int main(int argc, char *argv[]) #ifdef SYSTEMD_ENABLE sd_socket_count = sd_get_socket_count(); if (sd_socket_count > 0 && control_socket) { - gpsd_report(LOG_WARN, + gpsd_report(context.debug, LOG_WARN, "control socket passed on command line ignored\n"); control_socket = NULL; } @@ -1979,7 +2027,7 @@ int main(int argc, char *argv[]) sd_socket_count <= 0 #endif && optind >= argc) { - gpsd_report(LOG_ERROR, + gpsd_report(context.debug, LOG_ERROR, "can't run with neither control socket nor devices\n"); exit(EXIT_FAILURE); } @@ -2000,22 +2048,24 @@ int main(int argc, char *argv[]) if (control_socket) { (void)unlink(control_socket); if (BAD_SOCKET(csock = filesock(control_socket))) { - gpsd_report(LOG_ERROR, + gpsd_report(context.debug, LOG_ERROR, "control socket create failed, netlib error %d\n", csock); exit(EXIT_FAILURE); } else - gpsd_report(LOG_SPIN, "control socket %s is fd %d\n", + gpsd_report(context.debug, LOG_SPIN, + "control socket %s is fd %d\n", control_socket, csock); FD_SET(csock, &all_fds); adjust_max_fd(csock, true); - gpsd_report(LOG_PROG, "control socket opened at %s\n", + gpsd_report(context.debug, LOG_PROG, + "control socket opened at %s\n", control_socket); } #endif /* CONTROL_SOCKET_ENABLE */ #else if (optind >= argc) { - gpsd_report(LOG_ERROR, + gpsd_report(context.debug, LOG_ERROR, "can't run with no devices specified\n"); exit(EXIT_FAILURE); } @@ -2026,7 +2076,8 @@ int main(int argc, char *argv[]) if (go_background) { /* not SuS/POSIX portable, but we have our own fallback version */ if (daemon(0, 0) != 0) - gpsd_report(LOG_ERROR,"demonization failed: %s\n",strerror(errno)); + gpsd_report(context.debug, LOG_ERROR, + "demonization failed: %s\n",strerror(errno)); } if (pid_file) { @@ -2036,12 +2087,13 @@ int main(int argc, char *argv[]) (void)fprintf(fp, "%u\n", (unsigned int)getpid()); (void)fclose(fp); } else { - gpsd_report(LOG_ERROR, "Cannot create PID file: %s.\n", pid_file); + gpsd_report(context.debug, LOG_ERROR, + "Cannot create PID file: %s.\n", pid_file); } } openlog("gpsd", LOG_PID, LOG_USER); - gpsd_report(LOG_INF, "launching (Version %s)\n", VERSION); + gpsd_report(context.debug, LOG_INF, "launching (Version %s)\n", VERSION); #ifdef SOCKET_EXPORT_ENABLE /*@ -observertrans @*/ @@ -2050,12 +2102,12 @@ int main(int argc, char *argv[]) getservbyname("gpsd", "tcp") ? "gpsd" : DEFAULT_GPSD_PORT; /*@ +observertrans @*/ if (passivesocks(gpsd_service, "tcp", QLEN, msocks) < 1) { - gpsd_report(LOG_ERR, + gpsd_report(context.debug, LOG_ERR, "command sockets creation failed, netlib errors %d, %d\n", msocks[0], msocks[1]); exit(EXIT_FAILURE); } - gpsd_report(LOG_INF, "listening on port %s\n", gpsd_service); + gpsd_report(context.debug, LOG_INF, "listening on port %s\n", gpsd_service); #endif /* SOCKET_EXPORT_ENABLE */ #ifdef NTPSHM_ENABLE @@ -2064,7 +2116,7 @@ int main(int argc, char *argv[]) // nice() can ONLY succeed when run as root! // do not even bother as non-root if (nice(NICEVAL) == -1 && errno != 0) - gpsd_report(LOG_INF, "NTPD Priority setting failed.\n"); + gpsd_report(context.debug, LOG_INF, "NTPD Priority setting failed.\n"); } (void)ntpshm_init(&context, NOWAIT); #endif /* NTPSHM_ENABLE */ @@ -2073,18 +2125,19 @@ int main(int argc, char *argv[]) /* we need to connect to dbus as root */ if (initialize_dbus_connection()) { /* the connection could not be started */ - gpsd_report(LOG_ERROR, "unable to connect to the DBUS system bus\n"); + gpsd_report(context.debug, LOG_ERROR, + "unable to connect to the DBUS system bus\n"); } else - gpsd_report(LOG_PROG, + gpsd_report(context.debug, LOG_PROG, "successfully connected to the DBUS system bus\n"); #endif /* defined(DBUS_EXPORT_ENABLE) && !defined(S_SPLINT_S) */ #ifdef SHM_EXPORT_ENABLE /* create the shared segment as root so readers can't mess with it */ if (!shm_acquire(&context)) { - gpsd_report(LOG_ERROR, "shared-segment creation failed,\n"); + gpsd_report(context.debug, LOG_ERROR, "shared-segment creation failed,\n"); } else - gpsd_report(LOG_PROG, "shared-segment creation succeeded,\n"); + gpsd_report(context.debug, LOG_PROG, "shared-segment creation succeeded,\n"); #endif /* SHM_EXPORT_ENABLE */ /* @@ -2095,7 +2148,7 @@ int main(int argc, char *argv[]) in_restart = false; for (i = optind; i < argc; i++) { if (!gpsd_add_device(argv[i], NOWAIT)) { - gpsd_report(LOG_ERROR, + gpsd_report(context.debug, LOG_ERROR, "initial GPS device %s open failed\n", argv[i]); } @@ -2109,7 +2162,8 @@ int main(int argc, char *argv[]) #if defined(HAVE_LIBCAP) && !defined(S_SPLINT_S) /* set flag: keep privileges across setuid() call */ if (prctl(PR_SET_KEEPCAPS, 1L, 0L, 0L, 0L) == -1) - gpsd_report(LOG_ERR, "prctl(PR_SET_KEEPCAPS, 1L ) failed\n"); + gpsd_report(context.debug, LOG_ERR, + "prctl(PR_SET_KEEPCAPS, 1L ) failed\n"); #endif /* HAVE_LIBCAP */ /* make default devices accessible even after we drop privileges */ @@ -2131,22 +2185,26 @@ int main(int argc, char *argv[]) struct group *grp = getgrnam(GPSD_GROUP); if (grp) if (setgid(grp->gr_gid) != 0) - gpsd_report(LOG_ERROR, "setgid() failed, errno %s\n", + gpsd_report(context.debug, LOG_ERROR, + "setgid() failed, errno %s\n", strerror(errno)); } #else if ((optind < argc && stat(argv[optind], &stb) == 0) || stat(PROTO_TTY, &stb) == 0) { - gpsd_report(LOG_PROG, "changing to group %d\n", stb.st_gid); + gpsd_report(context.debug, LOG_PROG, + "changing to group %d\n", stb.st_gid); if (setgid(stb.st_gid) != 0) - gpsd_report(LOG_ERROR, "setgid() failed, errno %s\n", + gpsd_report(context.debug, LOG_ERROR, + "setgid() failed, errno %s\n", strerror(errno)); } #endif pw = getpwnam(GPSD_USER); if (pw) if (setuid(pw->pw_uid) != 0) - gpsd_report(LOG_ERROR, "setuid() failed, errno %s\n", + gpsd_report(context.debug, LOG_ERROR, + "setuid() failed, errno %s\n", strerror(errno)); /*@+type@*/ @@ -2156,16 +2214,19 @@ int main(int argc, char *argv[]) cap_t caps = cap_from_text("cap_sys_time=pe"); if (!caps) - gpsd_report(LOG_ERR, "cap_from_text() failed.\n"); + gpsd_report(context.debug, LOG_ERR, "cap_from_text() failed.\n"); else if (cap_set_proc(caps) == -1) { - gpsd_report(LOG_ERR, "cap_set_proc() failed to drop root privs\n"); + gpsd_report(context.debug, LOG_ERR, + "cap_set_proc() failed to drop root privs\n"); cap_free(caps); } } #endif /* HAVE_LIBCAP */ } - gpsd_report(LOG_INF, "running with effective group ID %d\n", getegid()); - gpsd_report(LOG_INF, "running with effective user ID %d\n", geteuid()); + gpsd_report(context.debug, LOG_INF, + "running with effective group ID %d\n", getegid()); + gpsd_report(context.debug, LOG_INF, + "running with effective user ID %d\n", geteuid()); #ifdef SOCKET_EXPORT_ENABLE for (i = 0; i < NITEMS(subscribers); i++) @@ -2213,7 +2274,7 @@ int main(int argc, char *argv[]) (void)gpsd_wrap(&devices[dfd]); } in_restart = true; - gpsd_report(LOG_WARN, "gpsd restarted by SIGHUP\n"); + gpsd_report(context.debug, LOG_WARN, "gpsd restarted by SIGHUP\n"); } signalled = 0; @@ -2238,7 +2299,7 @@ int main(int argc, char *argv[]) if (in_restart) for (i = optind; i < argc; i++) { if (!gpsd_add_device(argv[i], NOWAIT)) { - gpsd_report(LOG_ERROR, + gpsd_report(context.debug, LOG_ERROR, "GPS device %s open failed\n", argv[i]); } @@ -2247,7 +2308,7 @@ int main(int argc, char *argv[]) while (0 == signalled) { (void)memcpy((char *)&rfds, (char *)&all_fds, sizeof(rfds)); - gpsd_report(LOG_RAW + 2, "select waits\n"); + gpsd_report(context.debug, LOG_RAW + 2, "select waits\n"); /* * Poll for user commands or GPS data. The timeout doesn't * actually matter here since select returns whenever one of @@ -2272,7 +2333,7 @@ int main(int argc, char *argv[]) #endif if (errno == EINTR) continue; - gpsd_report(LOG_ERROR, "select: %s\n", strerror(errno)); + gpsd_report(context.debug, LOG_ERROR, "select: %s\n", strerror(errno)); exit(EXIT_FAILURE); } /*@ +usedef +nullpass @*/ @@ -2291,7 +2352,8 @@ int main(int argc, char *argv[]) if (FD_ISSET(i, &rfds)) (void)snprintf(dbuf + strlen(dbuf), sizeof(dbuf) - strlen(dbuf), " %d ", i); - gpsd_report(LOG_SPIN, "select() {%s} at %f (errno %d)\n", + gpsd_report(context.debug, LOG_SPIN, + "select() {%s} at %f (errno %d)\n", dbuf, timestamp(), errno); } @@ -2306,7 +2368,8 @@ int main(int argc, char *argv[]) /*@+matchanyintegral@*/ if (BAD_SOCKET(ssock)) - gpsd_report(LOG_ERROR, "accept: %s\n", strerror(errno)); + gpsd_report(context.debug, LOG_ERROR, + "accept: %s\n", strerror(errno)); else { struct subscriber_t *client = NULL; int opts = fcntl(ssock, F_GETFL); @@ -2319,7 +2382,8 @@ int main(int argc, char *argv[]) c_ip = netlib_sock2ip(ssock); client = allocate_client(); if (client == NULL) { - gpsd_report(LOG_ERROR, "Client %s connect on fd %d -" + gpsd_report(context.debug, LOG_ERROR, + "Client %s connect on fd %d -" "no subscriber slots available\n", c_ip, ssock); (void)close(ssock); @@ -2327,7 +2391,7 @@ int main(int argc, char *argv[]) if (setsockopt (ssock, SOL_SOCKET, SO_LINGER, (char *)&linger, (int)sizeof(struct linger)) == -1) { - gpsd_report(LOG_ERROR, + gpsd_report(context.debug, LOG_ERROR, "Error: SETSOCKOPT SO_LINGER\n"); (void)close(ssock); } else { @@ -2336,7 +2400,7 @@ int main(int argc, char *argv[]) adjust_max_fd(ssock, true); client->fd = ssock; client->active = timestamp(); - gpsd_report(LOG_SPIN, + gpsd_report(context.debug, LOG_SPIN, "client %s (%d) connect on fd %d\n", c_ip, sub_index(client), ssock); json_version_dump(announce, sizeof(announce)); @@ -2358,9 +2422,11 @@ int main(int argc, char *argv[]) /*@-matchanyintegral@*/ if (BAD_SOCKET(ssock)) - gpsd_report(LOG_ERROR, "accept: %s\n", strerror(errno)); + gpsd_report(context.debug, LOG_ERROR, + "accept: %s\n", strerror(errno)); else { - gpsd_report(LOG_INF, "control socket connect on fd %d\n", + gpsd_report(context.debug, LOG_INF, + "control socket connect on fd %d\n", ssock); FD_SET(ssock, &all_fds); FD_SET(ssock, &control_fds); @@ -2377,11 +2443,13 @@ int main(int argc, char *argv[]) while ((rd = read(cfd, buf, sizeof(buf) - 1)) > 0) { buf[rd] = '\0'; - gpsd_report(LOG_IO, "<= control(%d): %s\n", cfd, buf); + gpsd_report(context.debug, LOG_IO, + "<= control(%d): %s\n", cfd, buf); /* coverity[tainted_data] Safe, never handed to exec */ handle_control(cfd, buf); } - gpsd_report(LOG_SPIN, "close(%d) of control socket\n", cfd); + gpsd_report(context.debug, LOG_SPIN, + "close(%d) of control socket\n", cfd); (void)close(cfd); FD_CLR(cfd, &all_fds); FD_CLR(cfd, &control_fds); @@ -2400,7 +2468,7 @@ int main(int argc, char *argv[]) consume_packets(device); else if (device->reawake>0 && timestamp()>device->reawake) { /* device may have had a zero-length read */ - gpsd_report(LOG_DATA, + gpsd_report(context.debug, LOG_DATA, "%s reawakened after zero-length read\n", device->gpsdata.dev.path); device->reawake = (timestamp_t)0; @@ -2435,7 +2503,8 @@ int main(int argc, char *argv[]) char buf[BUFSIZ]; int buflen; - gpsd_report(LOG_PROG, "checking client(%d)\n", + gpsd_report(context.debug, LOG_PROG, + "checking client(%d)\n", sub_index(sub)); if ((buflen = (int)recv(sub->fd, buf, sizeof(buf) - 1, 0)) <= 0) { @@ -2444,7 +2513,7 @@ int main(int argc, char *argv[]) if (buf[buflen - 1] != '\n') buf[buflen++] = '\n'; buf[buflen] = '\0'; - gpsd_report(LOG_IO, + gpsd_report(context.debug, LOG_IO, "<= client(%d): %s\n", sub_index(sub), buf); /* @@ -2460,7 +2529,7 @@ int main(int argc, char *argv[]) } else { if (!sub->policy.watcher && timestamp() - sub->active > COMMAND_TIMEOUT) { - gpsd_report(LOG_WARN, + gpsd_report(context.debug, LOG_WARN, "client(%d) timed out on command wait.\n", sub_index(sub)); detach_client(sub); @@ -2496,14 +2565,15 @@ int main(int argc, char *argv[]) device->packet.type != BAD_PACKET) { if (device->releasetime == 0) { device->releasetime = timestamp(); - gpsd_report(LOG_PROG, "device %d (fd %d) released\n", - (int)(device - devices), - device->gpsdata.gps_fd); + gpsd_report(context.debug, LOG_PROG, + "device %d (fd %d) released\n", + (int)(device - devices), + device->gpsdata.gps_fd); } else if (timestamp() - device->releasetime > RELEASE_TIMEOUT) { - gpsd_report(LOG_PROG, "device %d closed\n", + gpsd_report(context.debug, LOG_PROG, "device %d closed\n", (int)(device - devices)); - gpsd_report(LOG_RAW, "unflagging descriptor %d\n", + gpsd_report(context.debug, LOG_RAW, "unflagging descriptor %d\n", device->gpsdata.gps_fd); deactivate_device(device); } @@ -2513,8 +2583,9 @@ int main(int argc, char *argv[]) (device->opentime == 0 || timestamp() - device->opentime > DEVICE_RECONNECT)) { device->opentime = timestamp(); - gpsd_report(LOG_INF, "reconnection attempt on device %d\n", - (int)(device - devices)); + gpsd_report(context.debug, LOG_INF, + "reconnection attempt on device %d\n", + (int)(device - devices)); (void)awaken(device); } } @@ -2526,7 +2597,8 @@ int main(int argc, char *argv[]) if (SIGHUP == (int)signalled) longjmp(restartbuf, 1); - gpsd_report(LOG_WARN, "received terminating signal %d.\n", signalled); + gpsd_report(context.debug, LOG_WARN, + "received terminating signal %d.\n", signalled); /* try to undo all device configurations */ for (dfd = 0; dfd < MAXDEVICES; dfd++) { @@ -2534,7 +2606,7 @@ int main(int argc, char *argv[]) (void)gpsd_wrap(&devices[dfd]); } - gpsd_report(LOG_WARN, "exiting.\n"); + gpsd_report(context.debug, LOG_WARN, "exiting.\n"); #ifdef SOCKET_EXPORT_ENABLE /* diff --git a/gpsd.h-tail b/gpsd.h-tail index 75d05962..2cee2f8f 100644 --- a/gpsd.h-tail +++ b/gpsd.h-tail @@ -190,23 +190,6 @@ extern ssize_t packet_get(int, struct gps_packet_t *); extern int packet_sniff(struct gps_packet_t *); #define packet_buffered_input(lexer) ((lexer)->inbuffer + (lexer)->inbuflen - (lexer)->inbufptr) -extern void isgps_init(/*@out@*/struct gps_packet_t *); -enum isgpsstat_t isgps_decode(struct gps_packet_t *, - bool (*preamble_match)(isgps30bits_t *), - bool (*length_check)(struct gps_packet_t *), - size_t, - unsigned int); -extern unsigned int isgps_parity(isgps30bits_t); -extern void isgps_output_magnavox(const isgps30bits_t *, unsigned int, FILE *); - -extern enum isgpsstat_t rtcm2_decode(struct gps_packet_t *, unsigned int); -extern void json_rtcm2_dump(const struct rtcm2_t *, - /*@null@*/const char *, /*@out@*/char[], size_t); -extern void rtcm2_unpack(/*@out@*/struct rtcm2_t *, char *); -extern void json_rtcm3_dump(const struct rtcm3_t *, - /*@null@*/const char *, /*@out@*/char[], size_t); -extern void rtcm3_unpack(/*@out@*/struct rtcm3_t *, char *); - /* Next, declarations for the core library... */ /* factors for converting among confidence interval units */ @@ -684,6 +667,24 @@ struct gps_device_t { #define IS_HIGHEST_BIT(v,m) (v & ~((m<<1)-1))==0 +/* driver helper functions */ +extern void isgps_init(/*@out@*/struct gps_packet_t *); +enum isgpsstat_t isgps_decode(struct gps_packet_t *, + bool (*preamble_match)(isgps30bits_t *), + bool (*length_check)(struct gps_packet_t *), + size_t, + unsigned int); +extern unsigned int isgps_parity(isgps30bits_t); +extern void isgps_output_magnavox(const isgps30bits_t *, unsigned int, FILE *); + +extern enum isgpsstat_t rtcm2_decode(struct gps_packet_t *, unsigned int); +extern void json_rtcm2_dump(const struct rtcm2_t *, + /*@null@*/const char *, /*@out@*/char[], size_t); +extern void rtcm2_unpack(/*@out@*/struct rtcm2_t *, char *); +extern void json_rtcm3_dump(const struct rtcm3_t *, + /*@null@*/const char *, /*@out@*/char[], size_t); +extern void rtcm3_unpack(const int, /*@out@*/struct rtcm3_t *, char *); + /* here are the available GPS drivers */ extern const struct gps_type_t **gpsd_drivers; @@ -823,7 +824,8 @@ extern /*@observer@*/const char *gpsd_maskdump(gps_mask_t); /* exceptional driver methods */ extern bool ubx_write(struct gps_device_t *, unsigned int, unsigned int, /*@null@*/unsigned char *, size_t); -extern bool ais_binary_decode(struct ais_t *, +extern bool ais_binary_decode(const int debug, + struct ais_t *ais, const unsigned char *, size_t, /*@null@*/struct ais_type24_queue_t *); @@ -843,9 +845,9 @@ extern void libgps_dump_state(struct gps_data_t *); /* caller should supply this */ # if __GNUC__ >= 3 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7) -__attribute__((__format__(__printf__, 2, 3))) void gpsd_report(int, const char *, ...); +__attribute__((__format__(__printf__, 3, 4))) void gpsd_report(const int, const int, const char *, ...); # else /* not a new enough GCC, use the unprotected prototype */ -void gpsd_report(int, const char *, ...); +void gpsd_report(const int, const int, const char *, ...); #endif #ifdef S_SPLINT_S diff --git a/gpsd_json.c b/gpsd_json.c index b060fad6..cd2d215f 100644 --- a/gpsd_json.c +++ b/gpsd_json.c @@ -350,9 +350,6 @@ void json_sky_dump(const struct gps_data_t *datap, if (reply[strlen(reply) - 1] == ',') reply[strlen(reply) - 1] = '\0'; /* trim trailing comma */ (void)strlcat(reply, "}\r\n", replylen); - if (datap->satellites_visible != reported) - gpsd_report(LOG_WARN, "Satellite count %d != PRN count %d\n", - datap->satellites_visible, reported); } void json_device_dump(const struct gps_device_t *device, diff --git a/gpsdecode.c b/gpsdecode.c index 25b1d002..90799f3d 100644 --- a/gpsdecode.c +++ b/gpsdecode.c @@ -27,22 +27,6 @@ static unsigned int typelist[32]; * **************************************************************************/ -void gpsd_report(int errlevel, const char *fmt, ...) -/* assemble command in printf(3) style, use stderr or syslog */ -{ - if (errlevel <= verbose) { - char buf[BUFSIZ]; - va_list ap; - - (void)strlcpy(buf, "gpsdecode: ", BUFSIZ); - va_start(ap, fmt); - (void)vsnprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), fmt, - ap); - va_end(ap); - (void)fputs(buf, stderr); - } -} - #ifdef AIVDM_ENABLE static void aivdm_csv_dump(struct ais_t *ais, char *buf, size_t buflen) { @@ -158,7 +158,7 @@ static void visibilize(/*@out@*/char *buf2, size_t len, const char *buf) 0x00ff & (unsigned)*sp); } -void gpsd_report(int errlevel, const char *fmt, ...) +void gpsd_report(const int debuglevel, const int errlevel, const char *fmt, ...) /* our version of the logger */ { char buf[BUFSIZ]; @@ -198,7 +198,7 @@ void gpsd_report(int errlevel, const char *fmt, ...) (void)strlcpy(buf, "gpsd:", BUFSIZ); (void)strncat(buf, err_str, BUFSIZ - strlen(buf) ); - if (errlevel <= context.debug && packetwin != NULL) { + if (errlevel <= debuglevel && packetwin != NULL) { char buf2[BUFSIZ]; va_list ap; va_start(ap, fmt); @@ -243,7 +243,7 @@ static ssize_t readpkt(void) /* conditional prevents mask dumper from eating CPU */ if (context.debug >= LOG_DATA) - gpsd_report(LOG_DATA, + gpsd_report(context.debug, LOG_DATA, "packet mask = %s\n", gps_maskdump(session.gpsdata.set)); @@ -598,7 +598,7 @@ int main(int argc, char **argv) (void)strlcpy(session.gpsdata.dev.path, argv[optind], sizeof(session.gpsdata.dev.path)); if (gpsd_activate(&session) == -1) { - gpsd_report(LOG_ERROR, + gpsd_report(context.debug, LOG_ERROR, "activation of device %s failed, errno=%d\n", session.gpsdata.dev.path, errno); exit(EXIT_FAILURE); diff --git a/gpspacket.c b/gpspacket.c index 172b41c3..ca46f87f 100644 --- a/gpspacket.c +++ b/gpspacket.c @@ -14,7 +14,7 @@ static PyObject *ErrorObject = NULL; static PyObject *report_callback = NULL; -void gpsd_report(int errlevel, const char *fmt, ... ) +void gpsd_report(int unused UNUSED, int errlevel, const char *fmt, ... ) { char buf[BUFSIZ]; PyObject *args; @@ -140,7 +140,9 @@ unsigned int isgps_parity(isgps30bits_t th) 0xff]); /*@ -charint @*/ +#ifdef __UNUSED__ gpsd_report(ISGPS_ERRLEVEL_BASE + 2, "ISGPS parity %u\n", p); +#endif /* __UNUSED__ */ return (p); } @@ -182,7 +184,7 @@ enum isgpsstat_t isgps_decode(struct gps_packet_t *session, { /* ASCII characters 64-127, @ through DEL */ if ((c & MAG_TAG_MASK) != MAG_TAG_DATA) { - gpsd_report(ISGPS_ERRLEVEL_BASE + 1, + gpsd_report(session->debug, ISGPS_ERRLEVEL_BASE + 1, "ISGPS word tag not correct, skipping byte\n"); return ISGPS_SKIP; } @@ -202,18 +204,18 @@ enum isgpsstat_t isgps_decode(struct gps_packet_t *session, session->isgps.curr_word |= c >> -(session->isgps.curr_offset); } - gpsd_report(ISGPS_ERRLEVEL_BASE + 2, + gpsd_report(session->debug, ISGPS_ERRLEVEL_BASE + 2, "ISGPS syncing at byte %lu: 0x%08x\n", session->char_counter, session->isgps.curr_word); if (preamble_match(&session->isgps.curr_word)) { if (isgps_parityok(session->isgps.curr_word)) { - gpsd_report(ISGPS_ERRLEVEL_BASE + 1, + gpsd_report(session->debug, ISGPS_ERRLEVEL_BASE + 1, "ISGPS preamble ok, parity ok -- locked\n"); session->isgps.locked = true; break; } - gpsd_report(ISGPS_ERRLEVEL_BASE + 1, + gpsd_report(session->debug, ISGPS_ERRLEVEL_BASE + 1, "ISGPS preamble ok, parity fail\n"); } session->isgps.curr_offset++; @@ -242,13 +244,13 @@ enum isgpsstat_t isgps_decode(struct gps_packet_t *session, * another preamble pattern in the data stream. -wsr */ if (preamble_match(&session->isgps.curr_word)) { - gpsd_report(ISGPS_ERRLEVEL_BASE + 2, + gpsd_report(session->debug, ISGPS_ERRLEVEL_BASE + 2, "ISGPS preamble spotted (index: %u)\n", session->isgps.bufindex); session->isgps.bufindex = 0; } #endif - gpsd_report(ISGPS_ERRLEVEL_BASE + 2, + gpsd_report(session->debug, ISGPS_ERRLEVEL_BASE + 2, "ISGPS processing word %u (offset %d)\n", session->isgps.bufindex, session->isgps.curr_offset); @@ -259,7 +261,7 @@ enum isgpsstat_t isgps_decode(struct gps_packet_t *session, */ if (session->isgps.bufindex >= (unsigned)maxlen) { session->isgps.bufindex = 0; - gpsd_report(ISGPS_ERRLEVEL_BASE + 1, + gpsd_report(session->debug, ISGPS_ERRLEVEL_BASE + 1, "ISGPS buffer overflowing -- resetting\n"); return ISGPS_NO_SYNC; } @@ -270,7 +272,7 @@ enum isgpsstat_t isgps_decode(struct gps_packet_t *session, /* *INDENT-OFF* */ if ((session->isgps.bufindex == 0) && !preamble_match((isgps30bits_t *) session->isgps.buf)) { - gpsd_report(ISGPS_ERRLEVEL_BASE + 1, + gpsd_report(session->debug, ISGPS_ERRLEVEL_BASE + 1, "ISGPS word 0 not a preamble- punting\n"); return ISGPS_NO_SYNC; } @@ -294,20 +296,22 @@ enum isgpsstat_t isgps_decode(struct gps_packet_t *session, c >> -(session->isgps.curr_offset); } } else { - gpsd_report(ISGPS_ERRLEVEL_BASE + 0, + gpsd_report(session->debug, ISGPS_ERRLEVEL_BASE + 0, "ISGPS parity failure, lost lock\n"); session->isgps.locked = false; } } session->isgps.curr_offset -= 6; - gpsd_report(ISGPS_ERRLEVEL_BASE + 2, "ISGPS residual %d\n", + gpsd_report(session->debug, ISGPS_ERRLEVEL_BASE + 2, + "ISGPS residual %d\n", session->isgps.curr_offset); return res; } /*@ +shiftnegative @*/ /* never achieved lock */ - gpsd_report(ISGPS_ERRLEVEL_BASE + 1, "ISGPS lock never achieved\n"); + gpsd_report(session->debug, ISGPS_ERRLEVEL_BASE + 1, + "ISGPS lock never achieved\n"); return ISGPS_NO_SYNC; } diff --git a/libgpsd_core.c b/libgpsd_core.c index d18f0333..cee20149 100644 --- a/libgpsd_core.c +++ b/libgpsd_core.c @@ -30,9 +30,8 @@ #include "driver_nmea2000.h" #endif /* defined(NMEA2000_ENABLE) */ -static int debuglevel; - -void gpsd_report(int errlevel UNUSED, const char *fmt, ... ) +void gpsd_report(const int debuglevel, + const int errlevel, const char *fmt, ... ) /* our version of the logger */ { if (errlevel <= debuglevel) { @@ -78,11 +77,13 @@ void gpsd_report(int errlevel UNUSED, const char *fmt, ... ) } } -static void gpsd_run_device_hook(char *device_name, char *hook) +static void gpsd_run_device_hook(const int debuglevel, + char *device_name, char *hook) { struct stat statbuf; if (stat(DEVICEHOOKPATH, &statbuf) == -1) - gpsd_report(LOG_PROG, "no %s present, skipped running %s hook\n", + gpsd_report(debuglevel, LOG_PROG, + "no %s present, skipped running %s hook\n", DEVICEHOOKPATH, hook); else { /* @@ -93,18 +94,20 @@ static void gpsd_run_device_hook(char *device_name, char *hook) size_t bufsize = strlen(DEVICEHOOKPATH) + 1 + strlen(device_name) + 1 + strlen(hook) + 1; char *buf = malloc(bufsize); if (buf == NULL) - gpsd_report(LOG_ERROR, "error allocating run-hook buffer\n"); + gpsd_report(debuglevel, LOG_ERROR, + "error allocating run-hook buffer\n"); else { int status; (void)snprintf(buf, bufsize, "%s %s %s", DEVICEHOOKPATH, device_name, hook); - gpsd_report(LOG_INF, "running %s\n", buf); + gpsd_report(debuglevel, LOG_INF, "running %s\n", buf); status = system(buf); if (status == -1) - gpsd_report(LOG_ERROR, "error running %s\n", buf); + gpsd_report(debuglevel, LOG_ERROR, "error running %s\n", buf); else - gpsd_report(LOG_INF, "%s returned %d\n", DEVICEHOOKPATH, + gpsd_report(debuglevel, LOG_INF, + "%s returned %d\n", DEVICEHOOKPATH, WEXITSTATUS(status)); free(buf); } @@ -119,11 +122,12 @@ int gpsd_switch_driver(struct gps_device_t *session, char *type_name) if (identified && strcmp(session->device_type->type_name, type_name) == 0) return 0; - gpsd_report(LOG_PROG, "switch_driver(%s) called...\n", type_name); + gpsd_report(session->context->debug, LOG_PROG, + "switch_driver(%s) called...\n", type_name); /*@ -compmempass @*/ for (dp = gpsd_drivers; *dp; dp++) if (strcmp((*dp)->type_name, type_name) == 0) { - gpsd_report(LOG_PROG, "selecting %s driver...\n", + gpsd_report(session->context->debug, LOG_PROG, "selecting %s driver...\n", (*dp)->type_name); gpsd_assert_sync(session); /*@i@*/ session->device_type = *dp; @@ -138,7 +142,7 @@ int gpsd_switch_driver(struct gps_device_t *session, char *type_name) session->notify_clients = true; return 1; } - gpsd_report(LOG_ERROR, "invalid GPS type \"%s\".\n", type_name); + gpsd_report(session->context->debug, LOG_ERROR, "invalid GPS type \"%s\".\n", type_name); return 0; /*@ +compmempass @*/ } @@ -234,7 +238,7 @@ void gpsd_deactivate(struct gps_device_t *session) session->device_type->mode_switcher(session, 0); } #endif /* RECONFIGURE_ENABLE */ - gpsd_report(LOG_INF, "closing GPS=%s (%d)\n", + gpsd_report(session->context->debug, LOG_INF, "closing GPS=%s (%d)\n", session->gpsdata.dev.path, session->gpsdata.gps_fd); #if defined(NMEA2000_ENABLE) if (session->sourcetype == source_can) @@ -242,7 +246,9 @@ void gpsd_deactivate(struct gps_device_t *session) else #endif /* of defined(NMEA2000_ENABLE) */ (void)gpsd_close(session); - gpsd_run_device_hook(session->gpsdata.dev.path, "DEACTIVATE"); + gpsd_run_device_hook(session->context->debug, + session->gpsdata.dev.path, + "DEACTIVATE"); } void gpsd_clear(struct gps_device_t *session) @@ -277,7 +283,7 @@ int gpsd_open(struct gps_device_t *session) session->gpsdata.gps_fd = netgnss_uri_open(session, session->gpsdata.dev.path); session->sourcetype = source_tcp; - gpsd_report(LOG_SPIN, + gpsd_report(session->context->debug, LOG_SPIN, "netgnss_uri_open(%s) returns socket on fd %d\n", session->gpsdata.dev.path, session->gpsdata.gps_fd); return session->gpsdata.gps_fd; @@ -289,18 +295,18 @@ int gpsd_open(struct gps_device_t *session) INVALIDATE_SOCKET(session->gpsdata.gps_fd); port = strchr(server, ':'); if (port == NULL) { - gpsd_report(LOG_ERROR, "Missing colon in TCP feed spec.\n"); + gpsd_report(session->context->debug, LOG_ERROR, "Missing colon in TCP feed spec.\n"); return -1; } *port++ = '\0'; - gpsd_report(LOG_INF, "opening TCP feed at %s, port %s.\n", server, + gpsd_report(session->context->debug, LOG_INF, "opening TCP feed at %s, port %s.\n", server, port); if ((dsock = netlib_connectsock(AF_UNSPEC, server, port, "tcp")) < 0) { - gpsd_report(LOG_ERROR, "TCP device open error %s.\n", + gpsd_report(session->context->debug, LOG_ERROR, "TCP device open error %s.\n", netlib_errstr(dsock)); return -1; } else - gpsd_report(LOG_SPIN, "TCP device opened on fd %d\n", dsock); + gpsd_report(session->context->debug, LOG_SPIN, "TCP device opened on fd %d\n", dsock); session->gpsdata.gps_fd = dsock; session->sourcetype = source_tcp; return session->gpsdata.gps_fd; @@ -312,18 +318,18 @@ int gpsd_open(struct gps_device_t *session) session->gpsdata.gps_fd = -1; port = strchr(server, ':'); if (port == NULL) { - gpsd_report(LOG_ERROR, "Missing colon in UDP feed spec.\n"); + gpsd_report(session->context->debug, LOG_ERROR, "Missing colon in UDP feed spec.\n"); return -1; } *port++ = '\0'; - gpsd_report(LOG_INF, "opening UDP feed at %s, port %s.\n", server, + gpsd_report(session->context->debug, LOG_INF, "opening UDP feed at %s, port %s.\n", server, port); if ((dsock = netlib_connectsock(AF_UNSPEC, server, port, "udp")) < 0) { - gpsd_report(LOG_ERROR, "UDP device open error %s.\n", + gpsd_report(session->context->debug, LOG_ERROR, "UDP device open error %s.\n", netlib_errstr(dsock)); return -1; } else - gpsd_report(LOG_SPIN, "UDP device opened on fd %d\n", dsock); + gpsd_report(session->context->debug, LOG_SPIN, "UDP device opened on fd %d\n", dsock); session->gpsdata.gps_fd = dsock; session->sourcetype = source_udp; return session->gpsdata.gps_fd; @@ -340,14 +346,14 @@ int gpsd_open(struct gps_device_t *session) port = DEFAULT_GPSD_PORT; } else *port++ = '\0'; - gpsd_report(LOG_INF, "opening remote gpsd feed at %s, port %s.\n", server, + gpsd_report(session->context->debug, LOG_INF, "opening remote gpsd feed at %s, port %s.\n", server, port); if ((dsock = netlib_connectsock(AF_UNSPEC, server, port, "tcp")) < 0) { - gpsd_report(LOG_ERROR, "remote gpsd device open error %s.\n", + gpsd_report(session->context->debug, LOG_ERROR, "remote gpsd device open error %s.\n", netlib_errstr(dsock)); return -1; } else - gpsd_report(LOG_SPIN, "remote gpsd feed opened on fd %d\n", dsock); + gpsd_report(session->context->debug, LOG_SPIN, "remote gpsd feed opened on fd %d\n", dsock); /*@+branchstate +nullpass@*/ /* watch to remote is issued when WATCH is */ session->gpsdata.gps_fd = dsock; @@ -368,7 +374,8 @@ int gpsd_open(struct gps_device_t *session) int gpsd_activate(struct gps_device_t *session) /* acquire a connection to the GPS device */ { - gpsd_run_device_hook(session->gpsdata.dev.path, "ACTIVATE"); + gpsd_run_device_hook(session->context->debug, + session->gpsdata.dev.path, "ACTIVATE"); session->gpsdata.gps_fd = gpsd_open(session); if (session->gpsdata.gps_fd < 0) @@ -383,27 +390,27 @@ int gpsd_activate(struct gps_device_t *session) /*@ -mustfreeonly @*/ for (dp = gpsd_drivers; *dp; dp++) { if ((*dp)->probe_detect != NULL) { - gpsd_report(LOG_PROG, "Probing \"%s\" driver...\n", + gpsd_report(session->context->debug, LOG_PROG, "Probing \"%s\" driver...\n", (*dp)->type_name); (void)tcflush(session->gpsdata.gps_fd, TCIOFLUSH); /* toss stale data */ if ((*dp)->probe_detect(session) != 0) { - gpsd_report(LOG_PROG, "Probe found \"%s\" driver...\n", + gpsd_report(session->context->debug, LOG_PROG, "Probe found \"%s\" driver...\n", (*dp)->type_name); session->device_type = *dp; gpsd_assert_sync(session); goto foundit; } else - gpsd_report(LOG_PROG, "Probe not found \"%s\" driver...\n", + gpsd_report(session->context->debug, LOG_PROG, "Probe not found \"%s\" driver...\n", (*dp)->type_name); } } /*@ +mustfreeonly @*/ - gpsd_report(LOG_PROG, "no probe matched...\n"); + gpsd_report(session->context->debug, LOG_PROG, "no probe matched...\n"); } foundit: #endif /* NON_NMEA_ENABLE */ gpsd_clear(session); - gpsd_report(LOG_INF, + gpsd_report(session->context->debug, LOG_INF, "gpsd_activate(): activated GPS (fd %d)\n", session->gpsdata.gps_fd); /* @@ -602,7 +609,7 @@ static bool invert(double mat[4][4], /*@out@*/ double inverse[4][4]) /*@ +fixedformalarray +mustdefine @*/ -static gps_mask_t fill_dop(const struct gps_data_t * gpsdata, struct dop_t * dop) +static gps_mask_t fill_dop(const struct gps_data_t * gpsdata, struct dop_t * dop, const int debug) { double prod[4][4]; double inv[4][4]; @@ -613,14 +620,14 @@ static gps_mask_t fill_dop(const struct gps_data_t * gpsdata, struct dop_t * dop memset(satpos, 0, sizeof(satpos)); #ifdef __UNUSED__ - gpsd_report(LOG_INF, "Satellite picture:\n"); + gpsd_report(session->context->debug, LOG_INF, "Satellite picture:\n"); for (k = 0; k < MAXCHANNELS; k++) { bool used_in_solution = false; for (j = 0; j < ; j++) if (collect->used == i) used_in_solution = true; if (gpsdata->used[k]) - gpsd_report(LOG_INF, "az: %d el: %d SV: %d\n", + gpsd_report(session->context->debug, LOG_INF, "az: %d el: %d SV: %d\n", gpsdata->azimuth[k], gpsdata->elevation[k], used_in_solution); } @@ -640,8 +647,11 @@ static gps_mask_t fill_dop(const struct gps_data_t * gpsdata, struct dop_t * dop /* If we don't have 4 satellites then we don't have enough information to calculate DOPS */ if (n < 4) { - gpsd_report(LOG_DATA + 2, "Not enough satellites available %d < 4:\n", +#ifdef __UNUSED__ + gpsd_report(session->context->debug, LOG_DATA + 2, + "Not enough satellites available %d < 4:\n", n); +#endif /* __UNUSED__ */ return 0; /* Is this correct return code here? or should it be ERROR_SET */ } @@ -649,9 +659,9 @@ static gps_mask_t fill_dop(const struct gps_data_t * gpsdata, struct dop_t * dop memset(inv, 0, sizeof(inv)); #ifdef __UNUSED__ - gpsd_report(LOG_INF, "Line-of-sight matrix:\n"); + gpsd_report(session->context->debug, LOG_INF, "Line-of-sight matrix:\n"); for (k = 0; k < n; k++) { - gpsd_report(LOG_INF, "%f %f %f %f\n", + gpsd_report(debug, LOG_INF, "%f %f %f %f\n", satpos[k][0], satpos[k][1], satpos[k][2], satpos[k][3]); } #endif /* __UNUSED__ */ @@ -666,9 +676,9 @@ static gps_mask_t fill_dop(const struct gps_data_t * gpsdata, struct dop_t * dop } #ifdef __UNUSED__ - gpsd_report(LOG_INF, "product:\n"); + gpsd_report(debug, LOG_INF, "product:\n"); for (k = 0; k < 4; k++) { - gpsd_report(LOG_INF, "%f %f %f %f\n", + gpsd_report(session->context->debug, LOG_INF, "%f %f %f %f\n", prod[k][0], prod[k][1], prod[k][2], prod[k][3]); } #endif /* __UNUSED__ */ @@ -679,15 +689,15 @@ static gps_mask_t fill_dop(const struct gps_data_t * gpsdata, struct dop_t * dop * Note: this will print garbage unless all the subdeterminants * are computed in the invert() function. */ - gpsd_report(LOG_RAW, "inverse:\n"); + gpsd_report(debug, LOG_RAW, "inverse:\n"); for (k = 0; k < 4; k++) { - gpsd_report(LOG_RAW, "%f %f %f %f\n", + gpsd_report(session->context->debug, LOG_RAW, "%f %f %f %f\n", inv[k][0], inv[k][1], inv[k][2], inv[k][3]); } #endif /* __UNUSED__ */ } else { #ifndef USE_QT - gpsd_report(LOG_DATA, + gpsd_report(debug, LOG_DATA, "LOS matrix is singular, can't calculate DOPs - source '%s'\n", gpsdata->dev.path); #endif @@ -703,7 +713,7 @@ static gps_mask_t fill_dop(const struct gps_data_t * gpsdata, struct dop_t * dop gdop = sqrt(inv[0][0] + inv[1][1] + inv[2][2] + inv[3][3]); #ifndef USE_QT - gpsd_report(LOG_DATA, + gpsd_report(debug, LOG_DATA, "DOPS computed/reported: X=%f/%f, Y=%f/%f, H=%f/%f, V=%f/%f, P=%f/%f, T=%f/%f, G=%f/%f\n", xdop, dop->xdop, ydop, dop->ydop, hdop, dop->hdop, vdop, dop->vdop, pdop, dop->pdop, tdop, dop->tdop, gdop, dop->gdop); @@ -946,9 +956,9 @@ gps_mask_t gpsd_poll(struct gps_device_t *session) double gap = now - session->packet.start_time; if (gap > min_cycle) - gpsd_report(LOG_WARN, "cycle-start detector failed.\n"); + gpsd_report(session->context->debug, LOG_WARN, "cycle-start detector failed.\n"); else if (gap > quiet_time) { - gpsd_report(LOG_PROG, "transmission pause of %f\n", gap); + gpsd_report(session->context->debug, LOG_PROG, "transmission pause of %f\n", gap); session->sor = now; session->packet.start_char = session->packet.char_counter; } @@ -967,7 +977,7 @@ gps_mask_t gpsd_poll(struct gps_device_t *session) if (session->device_type != NULL) { newlen = session->device_type->get_packet(session); /* coverity[deref_ptr] */ - gpsd_report(LOG_RAW, + gpsd_report(session->context->debug, LOG_RAW, "%s is known to be %s\n", session->gpsdata.dev.path, session->device_type->type_name); @@ -976,10 +986,10 @@ gps_mask_t gpsd_poll(struct gps_device_t *session) } /* update the scoreboard structure from the GPS */ - gpsd_report(LOG_RAW + 2, "%s sent %zd new characters\n", + gpsd_report(session->context->debug, LOG_RAW + 2, "%s sent %zd new characters\n", session->gpsdata.dev.path, newlen); if (newlen < 0) { /* read error */ - gpsd_report(LOG_INF, "GPS on %s returned error %zd (%lf sec since data)\n", + gpsd_report(session->context->debug, LOG_INF, "GPS on %s returned error %zd (%lf sec since data)\n", session->gpsdata.dev.path, newlen, timestamp() - session->gpsdata.online); session->gpsdata.online = (timestamp_t)0; @@ -990,18 +1000,19 @@ gps_mask_t gpsd_poll(struct gps_device_t *session) * wrong time... */ if (session->gpsdata.online > 0 && timestamp() - session->gpsdata.online >= session->gpsdata.dev.cycle * 2) { - gpsd_report(LOG_INF, "GPS on %s is offline (%lf sec since data)\n", + gpsd_report(session->context->debug, LOG_INF, "GPS on %s is offline (%lf sec since data)\n", session->gpsdata.dev.path, timestamp() - session->gpsdata.online); session->gpsdata.online = (timestamp_t)0; } return NODATA_IS; } else /* (newlen > 0) */ { - gpsd_report(LOG_RAW, + gpsd_report(session->context->debug, LOG_RAW, "packet sniff on %s finds type %d\n", session->gpsdata.dev.path, session->packet.type); if (session->packet.type == COMMENT_PACKET) { - gpsd_report (LOG_PROG, "comment, sync lock deferred\n"); + gpsd_report(session->context->debug, LOG_PROG, + "comment, sync lock deferred\n"); /* FALL THROUGH */ } else if (session->packet.type > COMMENT_PACKET) { first_sync = (session->device_type == NULL); @@ -1023,8 +1034,11 @@ gps_mask_t gpsd_poll(struct gps_device_t *session) /*@+nullderef@*/ /* FALL THROUGH */ } else if (session->getcount++>1 && !gpsd_next_hunt_setting(session)) { - gpsd_run_device_hook(session->gpsdata.dev.path, "DEACTIVATE"); - gpsd_report(LOG_INF, "hunt on %s failed (%lf sec since data)\n", + gpsd_run_device_hook(session->context->debug, + session->gpsdata.dev.path, + "DEACTIVATE"); + gpsd_report(session->context->debug, LOG_INF, + "hunt on %s failed (%lf sec since data)\n", session->gpsdata.dev.path, timestamp() - session->gpsdata.online); return ERROR_SET; @@ -1032,14 +1046,16 @@ gps_mask_t gpsd_poll(struct gps_device_t *session) } if (session->packet.outbuflen == 0) { /* got new data, but no packet */ - gpsd_report(LOG_RAW + 3, "New data on %s, not yet a packet\n", + gpsd_report(session->context->debug, LOG_RAW + 3, + "New data on %s, not yet a packet\n", session->gpsdata.dev.path); return ONLINE_SET; } else { /* we have recognized a packet */ gps_mask_t received = PACKET_SET; session->gpsdata.online = timestamp(); - gpsd_report(LOG_RAW + 3, "Accepted packet on %s.\n", + gpsd_report(session->context->debug, LOG_RAW + 3, + "Accepted packet on %s.\n", session->gpsdata.dev.path); /* track the packet count since achieving sync on the device */ @@ -1047,7 +1063,7 @@ gps_mask_t gpsd_poll(struct gps_device_t *session) speed_t speed = gpsd_get_speed(session); /*@-nullderef@*/ - gpsd_report(LOG_INF, + gpsd_report(session->context->debug, LOG_INF, "%s identified as type %s (%f sec @ %dbps)\n", session->gpsdata.dev.path, session->device_type->type_name, @@ -1084,7 +1100,7 @@ gps_mask_t gpsd_poll(struct gps_device_t *session) * level does not actually require it. */ if (session->context->debug >= LOG_RAW) - gpsd_report(LOG_RAW, "raw packet of type %d, %zd:%s\n", + gpsd_report(session->context->debug, LOG_RAW, "raw packet of type %d, %zd:%s\n", session->packet.type, session->packet.outbuflen, gpsd_packetdump((char *)session->packet.outbuffer, session->packet.outbuflen)); @@ -1113,7 +1129,7 @@ gps_mask_t gpsd_poll(struct gps_device_t *session) */ if ((received & SATELLITE_SET) != 0 && session->gpsdata.satellites_visible > 0) { - session->gpsdata.set |= fill_dop(&session->gpsdata, &session->gpsdata.dop); + session->gpsdata.set |= fill_dop(&session->gpsdata, &session->gpsdata.dop, session->context->debug); session->gpsdata.epe = NAN; } #endif /* CHEAPFLOATS_ENABLE */ @@ -1125,7 +1141,7 @@ gps_mask_t gpsd_poll(struct gps_device_t *session) /* don't downgrade mode if holding previous fix */ if (session->gpsdata.fix.mode > session->newdata.mode) session->gpsdata.set &= ~MODE_SET; - //gpsd_report(LOG_PROG, + //gpsd_report(session->context->debug, LOG_PROG, // "transfer mask on %s: %02x\n", session->gpsdata.tag, session->gpsdata.set); gps_merge_fix(&session->gpsdata.fix, session->gpsdata.set, &session->newdata); @@ -1164,10 +1180,10 @@ gps_mask_t gpsd_poll(struct gps_device_t *session) /*@+relaxtypes +longunsignedintegral@*/ if ((session->gpsdata.set & TIME_SET) != 0) { if (session->newdata.time > time(NULL) + (60 * 60 * 24 * 365)) - gpsd_report(LOG_WARN, + gpsd_report(session->context->debug, LOG_WARN, "date more than a year in the future!\n"); else if (session->newdata.time < 0) - gpsd_report(LOG_ERROR, "date in %s is negative!\n", session->gpsdata.tag); + gpsd_report(session->context->debug, LOG_ERROR, "date in %s is negative!\n", session->gpsdata.tag); } /*@-relaxtypes -longunsignedintegral@*/ diff --git a/net_dgpsip.c b/net_dgpsip.c index f7209534..c7d305c5 100644 --- a/net_dgpsip.c +++ b/net_dgpsip.c @@ -36,17 +36,19 @@ int dgpsip_open(struct gps_device_t *device, const char *dgpsserver) netlib_connectsock(AF_UNSPEC, dgpsserver, dgpsport, "tcp"); if (device->gpsdata.gps_fd >= 0) { char hn[256], buf[BUFSIZ]; - gpsd_report(LOG_PROG, "connection to DGPS server %s established.\n", + gpsd_report(device->context->debug, LOG_PROG, + "connection to DGPS server %s established.\n", dgpsserver); (void)gethostname(hn, sizeof(hn)); /* greeting required by some RTCM104 servers; others will ignore it */ (void)snprintf(buf, sizeof(buf), "HELO %s gpsd %s\r\nR\r\n", hn, VERSION); if (write(device->gpsdata.gps_fd, buf, strlen(buf)) != (ssize_t) strlen(buf)) - gpsd_report(LOG_ERROR, "hello to DGPS server %s failed\n", + gpsd_report(device->context->debug, LOG_ERROR, + "hello to DGPS server %s failed\n", dgpsserver); } else - gpsd_report(LOG_ERROR, + gpsd_report(device->context->debug, LOG_ERROR, "can't connect to DGPS server %s, netlib error %d.\n", dgpsserver, device->gpsdata.gps_fd); opts = fcntl(device->gpsdata.gps_fd, F_GETFL); @@ -78,9 +80,9 @@ void dgpsip_report(struct gps_context_t *context, gps->gpsdata.fix.altitude); if (write(dgpsip->gpsdata.gps_fd, buf, strlen(buf)) == (ssize_t) strlen(buf)) - gpsd_report(LOG_IO, "=> dgps %s\n", buf); + gpsd_report(context->debug, LOG_IO, "=> dgps %s\n", buf); else - gpsd_report(LOG_IO, "write to dgps FAILED\n"); + gpsd_report(context->debug, LOG_IO, "write to dgps FAILED\n"); } } } diff --git a/net_gnss_dispatch.c b/net_gnss_dispatch.c index acd8b7f4..91c59186 100644 --- a/net_gnss_dispatch.c +++ b/net_gnss_dispatch.c @@ -44,7 +44,7 @@ int netgnss_uri_open(struct gps_device_t *dev, char *netgnss_service) #ifndef REQUIRE_DGNSS_PROTO return dgpsip_open(dev, netgnss_service); #else - gpsd_report(LOG_ERROR, + gpsd_report(dev->context, LOG_ERROR, "Unknown or unspecified DGNSS protocol for service %s\n", netgnss_service); return -1; diff --git a/net_ntrip.c b/net_ntrip.c index dd21f139..858a1872 100644 --- a/net_ntrip.c +++ b/net_ntrip.c @@ -35,7 +35,8 @@ /*@ -temptrans -mustfreefresh @*/ static /*@null@*/ char *ntrip_field_iterate( /*@null@ */ char *start, /*@null@*/ char *prev, - const char *eol) + const char *eol, + const int debug) { char *s, *t, *u; @@ -57,7 +58,7 @@ static /*@null@*/ char *ntrip_field_iterate( /*@null@ */ char *start, if ((t = strstr(t, ";"))) *t = '\0'; - gpsd_report(LOG_RAW, "Next Ntrip source table field %s\n", s); + gpsd_report(debug, LOG_RAW, "Next Ntrip source table field %s\n", s); return s; } @@ -66,19 +67,20 @@ static /*@null@*/ char *ntrip_field_iterate( /*@null@ */ char *start, /*@ -mustfreefresh @*/ static void ntrip_str_parse(char *str, size_t len, - /*@out@*/ struct ntrip_stream_t *hold) + /*@out@*/ struct ntrip_stream_t *hold, + const int debug) { char *s, *eol = str + len; memset(hold, 0, sizeof(*hold)); /* <mountpoint> */ - if ((s = ntrip_field_iterate(str, NULL, eol))) + if ((s = ntrip_field_iterate(str, NULL, eol, debug))) (void)strlcpy(hold->mountpoint, s, sizeof(hold->mountpoint)); /* <identifier> */ - s = ntrip_field_iterate(NULL, s, eol); + s = ntrip_field_iterate(NULL, s, eol, debug); /* <format> */ - if ((s = ntrip_field_iterate(NULL, s, eol))) { + if ((s = ntrip_field_iterate(NULL, s, eol, debug))) { if (strcasecmp("RTCM 2", s) == 0) hold->format = fmt_rtcm2; else if (strcasecmp("RTCM 2.0", s) == 0) @@ -98,41 +100,41 @@ static void ntrip_str_parse(char *str, size_t len, hold->format = fmt_unknown; } /* <format-details> */ - s = ntrip_field_iterate(NULL, s, eol); + s = ntrip_field_iterate(NULL, s, eol, debug); /* <carrier> */ - if ((s = ntrip_field_iterate(NULL, s, eol))) + if ((s = ntrip_field_iterate(NULL, s, eol, debug))) hold->carrier = atoi(s); /* <nav-system> */ - s = ntrip_field_iterate(NULL, s, eol); + s = ntrip_field_iterate(NULL, s, eol, debug); /* <network> */ - s = ntrip_field_iterate(NULL, s, eol); + s = ntrip_field_iterate(NULL, s, eol, debug); /* <country> */ - s = ntrip_field_iterate(NULL, s, eol); + s = ntrip_field_iterate(NULL, s, eol, debug); /* <latitude> */ hold->latitude = NAN; - if ((s = ntrip_field_iterate(NULL, s, eol))) + if ((s = ntrip_field_iterate(NULL, s, eol, debug))) hold->latitude = atof(s); /* <longitude> */ hold->longitude = NAN; - if ((s = ntrip_field_iterate(NULL, s, eol))) + if ((s = ntrip_field_iterate(NULL, s, eol, debug))) hold->longitude = atof(s); /* <nmea> */ - if ((s = ntrip_field_iterate(NULL, s, eol))) { + if ((s = ntrip_field_iterate(NULL, s, eol, debug))) { hold->nmea = atoi(s); } /* <solution> */ - s = ntrip_field_iterate(NULL, s, eol); + s = ntrip_field_iterate(NULL, s, eol, debug); /* <generator> */ - s = ntrip_field_iterate(NULL, s, eol); + s = ntrip_field_iterate(NULL, s, eol, debug); /* <compr-encryp> */ - if ((s = ntrip_field_iterate(NULL, s, eol))) { + if ((s = ntrip_field_iterate(NULL, s, eol, debug))) { if (strcasecmp("none", s) == 0) hold->compr_encryp = cmp_enc_none; else hold->compr_encryp = cmp_enc_unknown; } /* <authentication> */ - if ((s = ntrip_field_iterate(NULL, s, eol))) { + if ((s = ntrip_field_iterate(NULL, s, eol, debug))) { if (strcasecmp("N", s) == 0) hold->authentication = auth_none; else if (strcasecmp("B", s) == 0) @@ -143,15 +145,15 @@ static void ntrip_str_parse(char *str, size_t len, hold->authentication = auth_unknown; } /* <fee> */ - if ((s = ntrip_field_iterate(NULL, s, eol))) { + if ((s = ntrip_field_iterate(NULL, s, eol, debug))) { hold->fee = atoi(s); } /* <bitrate> */ - if ((s = ntrip_field_iterate(NULL, s, eol))) { + if ((s = ntrip_field_iterate(NULL, s, eol, debug))) { hold->bitrate = atoi(s); } /* ...<misc> */ - while ((s = ntrip_field_iterate(NULL, s, eol))); + while ((s = ntrip_field_iterate(NULL, s, eol, debug))); } static int ntrip_sourcetable_parse(struct gps_device_t *device) @@ -181,19 +183,22 @@ static int ntrip_sourcetable_parse(struct gps_device_t *device) if (match) { return 1; } - gpsd_report(LOG_ERROR, "ntrip stream read error %d on fd %d\n", - errno, fd); + gpsd_report(device->context->debug, LOG_ERROR, + "ntrip stream read error %d on fd %d\n", + errno, fd); return -1; } else if (rlen == 0) { // server closed the connection - gpsd_report(LOG_ERROR, "ntrip stream unexpected close %d on fd %d during sourcetable read\n", - errno, fd); + gpsd_report(device->context->debug, LOG_ERROR, + "ntrip stream unexpected close %d on fd %d during sourcetable read\n", + errno, fd); return -1; } line = buf; rlen = len += rlen; - gpsd_report(LOG_RAW, "Ntrip source table buffer %s\n", buf); + gpsd_report(device->context->debug, LOG_RAW, + "Ntrip source table buffer %s\n", buf); sourcetable = device->ntrip.sourcetable_parse; if (!sourcetable) { @@ -206,8 +211,9 @@ static int ntrip_sourcetable_parse(struct gps_device_t *device) line += llen; len -= llen; } else { - gpsd_report(LOG_WARN, "Received unexpexted Ntrip reply %s.\n", - buf); + gpsd_report(device->context->debug, LOG_WARN, + "Received unexpexted Ntrip reply %s.\n", + buf); return -1; } } @@ -223,7 +229,8 @@ static int ntrip_sourcetable_parse(struct gps_device_t *device) if (!(eol = strstr(line, NTRIP_BR))) break; - gpsd_report(LOG_IO, "next Ntrip source table line %s\n", line); + gpsd_report(device->context->debug, LOG_IO, + "next Ntrip source table line %s\n", line); *eol = '\0'; llen = (ssize_t) (eol - line); @@ -233,18 +240,19 @@ static int ntrip_sourcetable_parse(struct gps_device_t *device) /* parse STR */ if (strncmp(line, NTRIP_STR, strlen(NTRIP_STR)) == 0) { ntrip_str_parse(line + strlen(NTRIP_STR), - (size_t) (llen - strlen(NTRIP_STR)), &hold); + (size_t) (llen - strlen(NTRIP_STR)), + &hold, device->context->debug); if (strcmp(device->ntrip.stream.mountpoint, hold.mountpoint) == 0) { /* todo: support for RTCM 3.0, SBAS (WAAS, EGNOS), ... */ if (hold.format == fmt_unknown) { - gpsd_report(LOG_ERROR, + gpsd_report(device->context->debug, LOG_ERROR, "Ntrip stream %s format not supported\n", line); return -1; } /* todo: support encryption and compression algorithms */ if (hold.compr_encryp != cmp_enc_none) { - gpsd_report(LOG_ERROR, + gpsd_report(device->context->debug, LOG_ERROR, "Ntrip stream %s compression/encryption algorithm not supported\n", line); return -1; @@ -252,7 +260,7 @@ static int ntrip_sourcetable_parse(struct gps_device_t *device) /* todo: support digest authentication */ if (hold.authentication != auth_none && hold.authentication != auth_basic) { - gpsd_report(LOG_ERROR, + gpsd_report(device->context->debug, LOG_ERROR, "Ntrip stream %s authentication method not supported\n", line); return -1; @@ -282,7 +290,7 @@ static int ntrip_sourcetable_parse(struct gps_device_t *device) llen += strlen(NTRIP_BR); line += llen; len -= llen; - gpsd_report(LOG_RAW, + gpsd_report(device->context->debug, LOG_RAW, "Remaining Ntrip source table buffer %zd %s\n", len, line); } @@ -298,7 +306,8 @@ done: return match ? 1 : -1; } -static int ntrip_stream_req_probe(const struct ntrip_stream_t *stream) +static int ntrip_stream_req_probe(const struct ntrip_stream_t *stream, + const int debug) { int dsock; ssize_t r; @@ -306,10 +315,10 @@ static int ntrip_stream_req_probe(const struct ntrip_stream_t *stream) dsock = netlib_connectsock(AF_UNSPEC, stream->url, stream->port, "tcp"); if (dsock < 0) { - gpsd_report(LOG_ERROR, "ntrip stream connect error %d in req probe\n", dsock); + gpsd_report(debug, LOG_ERROR, "ntrip stream connect error %d in req probe\n", dsock); return -1; } - gpsd_report(LOG_SPIN, "ntrip stream for req probe connected on fd %d\n", dsock); + gpsd_report(debug, LOG_SPIN, "ntrip stream for req probe connected on fd %d\n", dsock); (void)snprintf(buf, sizeof(buf), "GET / HTTP/1.1\r\n" "User-Agent: NTRIP gpsd/%s\r\n" @@ -318,8 +327,9 @@ static int ntrip_stream_req_probe(const struct ntrip_stream_t *stream) "\r\n", VERSION, stream->url); r = write(dsock, buf, strlen(buf)); if (r != (ssize_t)strlen(buf)) { - gpsd_report(LOG_ERROR, "ntrip stream write error %d on fd %d during probe request %zd\n", - errno, dsock, r); + gpsd_report(debug, LOG_ERROR, + "ntrip stream write error %d on fd %d during probe request %zd\n", + errno, dsock, r); (int)close(dsock); return -1; } @@ -353,19 +363,22 @@ static int ntrip_auth_encode(const struct ntrip_stream_t *stream, /* *INDENT-ON* */ -static int ntrip_stream_get_req(const struct ntrip_stream_t *stream) +static int ntrip_stream_get_req(const struct ntrip_stream_t *stream, + const int debug) { int dsock; char buf[BUFSIZ]; dsock = netlib_connectsock(AF_UNSPEC, stream->url, stream->port, "tcp"); if (BAD_SOCKET(dsock)) { - gpsd_report(LOG_ERROR, "ntrip stream connect error %d\n", dsock); + gpsd_report(debug, LOG_ERROR, + "ntrip stream connect error %d\n", dsock); return -1; } - gpsd_report(LOG_SPIN, "netlib_connectsock() returns socket on fd %d\n", - dsock); + gpsd_report(debug, LOG_SPIN, + "netlib_connectsock() returns socket on fd %d\n", + dsock); (void)snprintf(buf, sizeof(buf), "GET /%s HTTP/1.1\r\n" @@ -376,15 +389,17 @@ static int ntrip_stream_get_req(const struct ntrip_stream_t *stream) "Connection: close\r\n" "\r\n", stream->mountpoint, VERSION, stream->url, stream->authStr); if (write(dsock, buf, strlen(buf)) != (ssize_t) strlen(buf)) { - gpsd_report(LOG_ERROR, "ntrip stream write error %d on fd %d during get request\n", errno, - dsock); + gpsd_report(debug, LOG_ERROR, + "ntrip stream write error %d on fd %d during get request\n", errno, + dsock); (void)close(dsock); return -1; } return dsock; } -static int ntrip_stream_get_parse(const struct ntrip_stream_t *stream, int dsock) +static int ntrip_stream_get_parse(const struct ntrip_stream_t *stream, + const int dsock, const int debug) { /*@-nullpass@*/ char buf[BUFSIZ]; @@ -393,29 +408,30 @@ static int ntrip_stream_get_parse(const struct ntrip_stream_t *stream, int dsock while (read(dsock, buf, sizeof(buf) - 1) == -1) { if (errno == EINTR) continue; - gpsd_report(LOG_ERROR, "ntrip stream read error %d on fd %d during get rsp\n", errno, - dsock); + gpsd_report(debug, LOG_ERROR, + "ntrip stream read error %d on fd %d during get rsp\n", errno, + dsock); goto close; } /* parse 401 Unauthorized */ /* coverity[string_null] - guaranteed terminated by the memset above */ if (strstr(buf, NTRIP_UNAUTH)!=NULL) { - gpsd_report(LOG_ERROR, + gpsd_report(debug, LOG_ERROR, "not authorized for Ntrip stream %s/%s\n", stream->url, stream->mountpoint); goto close; } /* parse SOURCETABLE */ if (strstr(buf, NTRIP_SOURCETABLE)!=NULL) { - gpsd_report(LOG_ERROR, + gpsd_report(debug, LOG_ERROR, "Broadcaster doesn't recognize Ntrip stream %s:%s/%s\n", stream->url, stream->port, stream->mountpoint); goto close; } /* parse ICY 200 OK */ if (strstr(buf, NTRIP_ICY)==NULL) { - gpsd_report(LOG_ERROR, + gpsd_report(debug, LOG_ERROR, "Unknown reply %s from Ntrip service %s:%s/%s\n", buf, stream->url, stream->port, stream->mountpoint); goto close; @@ -462,7 +478,7 @@ int ntrip_open(struct gps_device_t *device, char *caster) tmp = amp + 1; url = tmp; } else { - gpsd_report(LOG_ERROR, + gpsd_report(device->context->debug, LOG_ERROR, "can't extract user-ID and password from %s\n", caster); device->ntrip.conn_state = ntrip_conn_err; @@ -475,8 +491,9 @@ int ntrip_open(struct gps_device_t *device, char *caster) stream = slash + 1; } else { /* todo: add autoconnect like in dgpsip.c */ - gpsd_report(LOG_ERROR, "can't extract Ntrip stream from %s\n", - caster); + gpsd_report(device->context->debug, LOG_ERROR, + "can't extract Ntrip stream from %s\n", + caster); device->ntrip.conn_state = ntrip_conn_err; return -1; } @@ -510,7 +527,8 @@ int ntrip_open(struct gps_device_t *device, char *caster) port, sizeof(device->ntrip.stream.port)); - ret = ntrip_stream_req_probe(&device->ntrip.stream); + ret = ntrip_stream_req_probe(&device->ntrip.stream, + device->context->debug); if (ret == -1) { device->ntrip.conn_state = ntrip_conn_err; return -1; @@ -532,7 +550,8 @@ int ntrip_open(struct gps_device_t *device, char *caster) device->ntrip.conn_state = ntrip_conn_err; return -1; } - ret = ntrip_stream_get_req(&device->ntrip.stream); + ret = ntrip_stream_get_req(&device->ntrip.stream, + device->context->debug); if (ret == -1) { device->ntrip.conn_state = ntrip_conn_err; return -1; @@ -542,7 +561,8 @@ int ntrip_open(struct gps_device_t *device, char *caster) break; case ntrip_conn_sent_get: ret = ntrip_stream_get_parse(&device->ntrip.stream, - device->gpsdata.gps_fd); + device->gpsdata.gps_fd, + device->context->debug); if (ret == -1) { device->ntrip.conn_state = ntrip_conn_err; return -1; @@ -578,9 +598,9 @@ void ntrip_report(struct gps_context_t *context, gpsd_position_fix_dump(gps, buf, sizeof(buf)); if (write(caster->gpsdata.gps_fd, buf, strlen(buf)) == (ssize_t) strlen(buf)) { - gpsd_report(LOG_IO, "=> dgps %s\n", buf); + gpsd_report(context->debug, LOG_IO, "=> dgps %s\n", buf); } else { - gpsd_report(LOG_IO, "ntrip report write failed\n"); + gpsd_report(context->debug, LOG_IO, "ntrip report write failed\n"); } } } @@ -115,7 +115,7 @@ struct shmTime * ipcrm -M 0x4e545032 * ipcrm -M 0x4e545033 */ -static /*@null@*/ volatile struct shmTime *getShmTime(int unit) +static /*@null@*/ volatile struct shmTime *getShmTime(struct gps_context_t *context, int unit) { int shmid; unsigned int perms; @@ -137,7 +137,8 @@ static /*@null@*/ volatile struct shmTime *getShmTime(int unit) shmid = shmget((key_t) (NTPD_BASE + unit), sizeof(struct shmTime), (int)(IPC_CREAT | perms)); if (shmid == -1) { - gpsd_report(LOG_ERROR, "NTPD shmget(%ld, %zd, %o) fail: %s\n", + gpsd_report(context->debug, LOG_ERROR, + "NTPD shmget(%ld, %zd, %o) fail: %s\n", (long int)(NTPD_BASE + unit), sizeof(struct shmTime), (int)perms, strerror(errno)); return NULL; @@ -145,11 +146,13 @@ static /*@null@*/ volatile struct shmTime *getShmTime(int unit) p = (struct shmTime *)shmat(shmid, 0, 0); /*@ -mustfreefresh */ if ((int)(long)p == -1) { - gpsd_report(LOG_ERROR, "NTPD shmat failed: %s\n", + gpsd_report(context->debug, LOG_ERROR, + "NTPD shmat failed: %s\n", strerror(errno)); return NULL; } - gpsd_report(LOG_PROG, "NTPD shmat(%d,0,0) succeeded, segment %d\n", + gpsd_report(context->debug, LOG_PROG, + "NTPD shmat(%d,0,0) succeeded, segment %d\n", shmid, unit); return p; /*@ +mustfreefresh */ @@ -167,7 +170,7 @@ void ntpshm_init(struct gps_context_t *context, bool enablepps UNUSED) for (i = 0; i < NTPSHMSEGS; i++) { // Only grab the first two when running as root. if (2 <= i || 0 == getuid()) { - context->shmTime[i] = getShmTime(i); + context->shmTime[i] = getShmTime(context, i); } } memset(context->shmTimeInuse, 0, sizeof(context->shmTimeInuse)); @@ -218,10 +221,11 @@ int ntpshm_put(struct gps_device_t *session, double fixtime, double fudge) struct timeval tv; double seconds, microseconds; - // gpsd_report(LOG_PROG, "NTP: doing ntpshm_put(,%g, %g)\n", fixtime, fudge); + // gpsd_report(session->context->debug, LOG_PROG, "NTP: doing ntpshm_put(,%g, %g)\n", fixtime, fudge); if (session->shmindex < 0 || (shmTime = session->context->shmTime[session->shmindex]) == NULL) { - gpsd_report(LOG_RAW, "NTPD missing shm\n"); + gpsd_report(session->context->debug, LOG_RAW, + "NTPD missing shm\n"); return 0; } @@ -229,7 +233,8 @@ int ntpshm_put(struct gps_device_t *session, double fixtime, double fudge) fixtime += fudge; microseconds = 1000000.0 * modf(fixtime, &seconds); if (shmTime->clockTimeStampSec == (time_t) seconds) { - gpsd_report(LOG_RAW, "NTPD ntpshm_put: skipping duplicate second\n"); + gpsd_report(session->context->debug, LOG_RAW, + "NTPD ntpshm_put: skipping duplicate second\n"); return 0; } @@ -266,7 +271,7 @@ int ntpshm_put(struct gps_device_t *session, double fixtime, double fudge) shmTime->count++; shmTime->valid = 1; - gpsd_report(LOG_RAW, + gpsd_report(session->context->debug, LOG_RAW, "NTPD ntpshm_put: Clock: %lu.%06lu @ %lu.%06lu, fudge: %0.3f\n", (unsigned long)seconds, (unsigned long)microseconds, (unsigned long)tv.tv_sec, (unsigned long)tv.tv_usec, fudge); @@ -327,7 +332,8 @@ static int ntpshm_pps(struct gps_device_t *session, struct timeval *tv) l_offset *= 1000000; l_offset += tv->tv_usec - shmTime->receiveTimeStampUSec; if (0 > l_offset || 1000000 < l_offset) { - gpsd_report(LOG_RAW, "PPS ntpshm_pps: no current GPS seconds: %ld\n", + gpsd_report(session->context->debug, LOG_RAW, + "PPS ntpshm_pps: no current GPS seconds: %ld\n", (long)l_offset); return -1; } @@ -369,7 +375,8 @@ static int ntpshm_pps(struct gps_device_t *session, struct timeval *tv) /* this is more an offset jitter/dispersion than precision, * but still useful for debug */ precision = offset != 0 ? (int)(ceil(log(offset) / M_LN2)) : -20; - gpsd_report(LOG_RAW, "PPS ntpshm_pps %lu.%03lu @ %lu.%06lu, preci %d\n", + gpsd_report(session->context->debug, LOG_RAW, + "PPS ntpshm_pps %lu.%03lu @ %lu.%06lu, preci %d\n", (unsigned long)seconds, (unsigned long)microseconds / 1000, (unsigned long)tv->tv_sec, (unsigned long)tv->tv_usec, precision); @@ -447,15 +454,16 @@ static int init_kernel_pps(struct gps_device_t *session) { session->kernelpps_handle = -1; if ( !isatty(session->gpsdata.gps_fd) ) { - gpsd_report(LOG_INF, "KPPS gps_fd not a tty\n"); + gpsd_report(session->context->debug, LOG_INF, "KPPS gps_fd not a tty\n"); return -1; } /* Attach the line PPS discipline, so no need to ldattach */ /* This activates the magic /dev/pps0 device */ /* Note: this ioctl() requires root */ if ( 0 > ioctl(session->gpsdata.gps_fd, TIOCSETD, &ldisc)) { - gpsd_report(LOG_INF, "KPPS cannot set PPS line discipline: %s\n" - , strerror(errno)); + gpsd_report(session->context->debug, LOG_INF, + "KPPS cannot set PPS line discipline: %s\n", + strerror(errno)); return -1; } @@ -480,8 +488,9 @@ static int init_kernel_pps(struct gps_device_t *session) { } close(fd); } - gpsd_report(LOG_INF, "KPPS checking %s, %s\n" - , globbuf.gl_pathv[i], path); + gpsd_report(session->context->debug, LOG_INF, + "KPPS checking %s, %s\n", + globbuf.gl_pathv[i], path); if ( 0 == strncmp( path, session->gpsdata.dev.path, sizeof(path))) { /* this is the pps we are looking for */ /* FIXME, now build the proper pps device path */ @@ -494,7 +503,7 @@ static int init_kernel_pps(struct gps_device_t *session) { globfree(&globbuf); if ( 0 == pps_num ) { - gpsd_report(LOG_INF, "KPPS device not found.\n"); + gpsd_report(session->context->debug, LOG_INF, "KPPS device not found.\n"); return -1; } /* contruct the magic device path */ @@ -503,24 +512,27 @@ static int init_kernel_pps(struct gps_device_t *session) { /* root privs are required for this device open */ int ret = open(path, O_RDWR); if ( 0 > ret ) { - gpsd_report(LOG_INF, "KPPS cannot open %s: %s\n" - , path, strerror(errno)); + gpsd_report(session->context->debug, LOG_INF, + "KPPS cannot open %s: %s\n", path, strerror(errno)); return -1; } /* root privs are not required past this point */ if ( 0 > time_pps_create(ret, &session->kernelpps_handle )) { - gpsd_report(LOG_INF, "KPPS time_pps_create(%d) failed: %s\n" - , ret, strerror(errno)); + gpsd_report(session->context->debug, LOG_INF, + "KPPS time_pps_create(%d) failed: %s\n", + ret, strerror(errno)); return -1; } else { /* have kernel PPS handle */ int caps; /* get features supported */ if ( 0 > time_pps_getcap(session->kernelpps_handle, &caps)) { - gpsd_report(LOG_ERROR, "KPPS time_pps_getcap() failed\n"); + gpsd_report(session->context->debug, LOG_ERROR, + "KPPS time_pps_getcap() failed\n"); } else { - gpsd_report(LOG_INF, "KPPS caps %0x\n", caps); + gpsd_report(session->context->debug, + LOG_INF, "KPPS caps %0x\n", caps); } /* linux 2.6.34 can not PPS_ECHOASSERT | PPS_ECHOCLEAR */ @@ -528,7 +540,7 @@ static int init_kernel_pps(struct gps_device_t *session) { pp.mode = PPS_CAPTUREBOTH; if ( 0 > time_pps_setparams(session->kernelpps_handle, &pp)) { - gpsd_report(LOG_ERROR, + gpsd_report(session->context->debug, LOG_ERROR, "KPPS time_pps_setparams() failed: %s\n", strerror(errno)); time_pps_destroy(session->kernelpps_handle); return -1; @@ -572,17 +584,19 @@ static /*@null@*/ void *gpsd_ppsmonitor(void *arg) int chronyfd = -1; char chrony_path[PATH_MAX]; - gpsd_report(LOG_PROG, "PPS Create Thread gpsd_ppsmonitor\n"); + gpsd_report(session->context->debug, LOG_PROG, + "PPS Create Thread gpsd_ppsmonitor\n"); /* wait for the device to go active - makes this safe to call early */ while (BAD_SOCKET(session->gpsdata.gps_fd)) { - /* gpsd_report(LOG_PROG, "PPS thread awaiting device activation\n"); */ + /* gpsd_report(session->context->debug, LOG_PROG, "PPS thread awaiting device activation\n"); */ (void)sleep(1); } /* Activates PPS support for RS-232 or USB devices only. */ if (!(session->sourcetype == source_rs232 || session->sourcetype == source_usb)) { - gpsd_report(LOG_PROG, "PPS thread deactivation. Not RS-232 or USB device.\n"); + gpsd_report(session->context->debug, LOG_PROG, + "PPS thread deactivation. Not RS-232 or USB device.\n"); (void)ntpshm_free(session->context, session->shmTimeP); return NULL; } @@ -600,14 +614,17 @@ static /*@null@*/ void *gpsd_ppsmonitor(void *arg) } if (access(chrony_path, F_OK) != 0) { - gpsd_report(LOG_PROG, "PPS chrony socket %s doesn't exist\n", chrony_path); + gpsd_report(session->context->debug, LOG_PROG, + "PPS chrony socket %s doesn't exist\n", chrony_path); } else { chronyfd = netlib_localsocket(chrony_path, SOCK_DGRAM); if (chronyfd < 0) - gpsd_report(LOG_PROG, "PPS can not connect chrony socket: %s\n", + gpsd_report(session->context->debug, LOG_PROG, + "PPS can not connect chrony socket: %s\n", chrony_path); else - gpsd_report(LOG_RAW, "PPS using chrony socket: %s\n", chrony_path); + gpsd_report(session->context->debug, LOG_RAW, + "PPS using chrony socket: %s\n", chrony_path); } /* end chrony */ @@ -616,7 +633,8 @@ static /*@null@*/ void *gpsd_ppsmonitor(void *arg) /* some operations in init_kernel_pps() require root privs */ (void)init_kernel_pps( session ); if ( 0 <= session->kernelpps_handle ) { - gpsd_report(LOG_WARN, "KPPS kernel PPS will be used\n"); + gpsd_report(session->context->debug, LOG_WARN, + "KPPS kernel PPS will be used\n"); } memset( (void *)&pi, 0, sizeof(pps_info_t)); #endif @@ -635,8 +653,9 @@ static /*@null@*/ void *gpsd_ppsmonitor(void *arg) #if defined(TIOCMIWAIT) #define PPS_LINE_TIOC (TIOCM_CD|TIOCM_CAR|TIOCM_RI|TIOCM_CTS) if (ioctl(session->gpsdata.gps_fd, TIOCMIWAIT, PPS_LINE_TIOC) != 0) { - gpsd_report(LOG_ERROR, "PPS ioctl(TIOCMIWAIT) failed: %d %.40s\n" - , errno, strerror(errno)); + gpsd_report(session->context->debug, LOG_ERROR, + "PPS ioctl(TIOCMIWAIT) failed: %d %.40s\n", + errno, strerror(errno)); break; } #endif /* TIOCMIWAIT */ @@ -647,14 +666,16 @@ static /*@null@*/ void *gpsd_ppsmonitor(void *arg) * not uSec like gettimeofday */ if ( 0 > clock_gettime(CLOCK_REALTIME, &ts) ) { /* uh, oh, can not get time! */ - gpsd_report(LOG_ERROR, "PPS clock_gettime() failed\n"); + gpsd_report(session->context->debug, LOG_ERROR, + "PPS clock_gettime() failed\n"); break; } TSTOTV( &tv, &ts); #else if ( 0 > gettimeofday(&tv, NULL) ) { /* uh, oh, can not get time! */ - gpsd_report(LOG_ERROR, "PPS gettimeofday() failed\n"); + gpsd_report(session->context->debug, LOG_ERROR, + "PPS gettimeofday() failed\n"); break; } TVTOTS( &ts, &tv); @@ -669,7 +690,8 @@ static /*@null@*/ void *gpsd_ppsmonitor(void *arg) memset( (void *)&kernelpps_tv, 0, sizeof(kernelpps_tv)); if ( 0 > time_pps_fetch(session->kernelpps_handle, PPS_TSFMT_TSPEC , &pi, &kernelpps_tv)) { - gpsd_report(LOG_ERROR, "KPPS kernel PPS failed\n"); + gpsd_report(session->context->debug, LOG_ERROR, + "KPPS kernel PPS failed\n"); } else { // find the last edge if ( pi.assert_timestamp.tv_sec > pi.clear_timestamp.tv_sec ) { @@ -685,16 +707,18 @@ static /*@null@*/ void *gpsd_ppsmonitor(void *arg) kpps_edge = 0; tv_kpps = pi.clear_timestamp; } - gpsd_report(LOG_PROG, "KPPS assert %ld.%09ld, sequence: %ld - " - "clear %ld.%09ld, sequence: %ld\n", - pi.assert_timestamp.tv_sec, - pi.assert_timestamp.tv_nsec, - pi.assert_sequence, - pi.clear_timestamp.tv_sec, - pi.clear_timestamp.tv_nsec, - pi.clear_sequence); - gpsd_report(LOG_PROG, "KPPS data: using %s\n", - kpps_edge ? "assert" : "clear"); + gpsd_report(session->context->debug, LOG_PROG, + "KPPS assert %ld.%09ld, sequence: %ld - " + "clear %ld.%09ld, sequence: %ld\n", + pi.assert_timestamp.tv_sec, + pi.assert_timestamp.tv_nsec, + pi.assert_sequence, + pi.clear_timestamp.tv_sec, + pi.clear_timestamp.tv_nsec, + pi.clear_sequence); + gpsd_report(session->context->debug, LOG_PROG, + "KPPS data: using %s\n", + kpps_edge ? "assert" : "clear"); #define timediff_kpps(x, y) (int)((x.tv_sec-y.tv_sec)*1000000+((x.tv_nsec-y.tv_nsec)/1000)) cycle_kpps = timediff_kpps(tv_kpps, pulse_kpps[kpps_edge]); @@ -704,7 +728,7 @@ static /*@null@*/ void *gpsd_ppsmonitor(void *arg) duration_kpps = 0; } #undef timediff_kpps - gpsd_report(LOG_INF, + gpsd_report(session->context->debug, LOG_INF, "KPPS cycle: %7d, duration: %7d @ %lu.%09lu\n", cycle_kpps, duration_kpps, (unsigned long)tv_kpps.tv_sec, @@ -722,7 +746,8 @@ static /*@null@*/ void *gpsd_ppsmonitor(void *arg) /*@ +ignoresigns */ if (ioctl(session->gpsdata.gps_fd, TIOCMGET, &state) != 0) { - gpsd_report(LOG_ERROR, "PPS ioctl(TIOCMGET) failed\n"); + gpsd_report(session->context->debug, LOG_ERROR, + "PPS ioctl(TIOCMGET) failed\n"); break; } /*@ -ignoresigns */ @@ -740,17 +765,18 @@ static /*@null@*/ void *gpsd_ppsmonitor(void *arg) if (999000 < cycle && 1001000 > cycle) { duration = 0; unchanged = 0; - gpsd_report(LOG_RAW, + gpsd_report(session->context->debug, LOG_RAW, "PPS pps-detect on %s invisible pulse\n", session->gpsdata.dev.path); } else if (++unchanged == 10) { unchanged = 1; - gpsd_report(LOG_WARN, + gpsd_report(session->context->debug, LOG_WARN, "PPS TIOCMIWAIT returns unchanged state, ppsmonitor sleeps 10\n"); (void)sleep(10); } } else { - gpsd_report(LOG_RAW, "PPS pps-detect on %s changed to %d\n", + gpsd_report(session->context->debug, LOG_RAW, + "PPS pps-detect on %s changed to %d\n", session->gpsdata.dev.path, state); laststate = state; unchanged = 0; @@ -760,7 +786,8 @@ static /*@null@*/ void *gpsd_ppsmonitor(void *arg) // strange, try again continue; } - gpsd_report(LOG_INF, "PPS cycle: %7d, duration: %7d @ %lu.%06lu\n", + gpsd_report(session->context->debug, LOG_INF, + "PPS cycle: %7d, duration: %7d @ %lu.%06lu\n", cycle, duration, (unsigned long)tv.tv_sec, (unsigned long)tv.tv_usec); @@ -855,7 +882,8 @@ static /*@null@*/ void *gpsd_ppsmonitor(void *arg) if (ok) { char *log1 = NULL; - gpsd_report(LOG_RAW, "PPS edge accepted %.100s", log); + gpsd_report(session->context->debug, LOG_RAW, + "PPS edge accepted %.100s", log); /* chrony expects tv-sec since Jan 1970 */ /* FIXME!! offset is double of the error from local time */ sample.pulse = 0; @@ -902,7 +930,7 @@ static /*@null@*/ void *gpsd_ppsmonitor(void *arg) } else { log1 = "skipped ship_to_ntp=0"; } - gpsd_report(LOG_RAW, + gpsd_report(session->context->debug, LOG_RAW, "PPS edge %.20s %lu.%06lu offset %.9f\n", log1, (unsigned long)sample.tv.tv_sec, @@ -911,19 +939,20 @@ static /*@null@*/ void *gpsd_ppsmonitor(void *arg) if (session->context->pps_hook != NULL) session->context->pps_hook(session, &tv); } else { - gpsd_report(LOG_RAW, "PPS edge rejected %.100s", log); + gpsd_report(session->context->debug, LOG_RAW, + "PPS edge rejected %.100s", log); } } #if defined(HAVE_SYS_TIMEPPS_H) if (session->kernelpps_handle > 0) { - gpsd_report(LOG_PROG, "PPS descriptor cleaned up\n"); + gpsd_report(session->context->debug, LOG_PROG, "PPS descriptor cleaned up\n"); time_pps_destroy(session->kernelpps_handle); } #endif if (chronyfd != -1) (void)close(chronyfd); - gpsd_report(LOG_PROG, "PPS gpsd_ppsmonitor exited.\n"); + gpsd_report(session->context->debug, LOG_PROG, "PPS gpsd_ppsmonitor exited.\n"); return NULL; } /*@+mustfreefresh +type +unrecog@*/ @@ -933,7 +962,7 @@ static void pps_thread_activate(struct gps_device_t *session) { pthread_t pt; if (session->shmTimeP >= 0) { - gpsd_report(LOG_PROG, "PPS thread launched\n"); + gpsd_report(session->context->debug, LOG_PROG, "PPS thread launched\n"); /*@-compdef -nullpass@*/ (void)pthread_create(&pt, NULL, gpsd_ppsmonitor, (void *)session); /*@+compdef +nullpass@*/ @@ -967,7 +996,7 @@ void ntpd_link_activate(struct gps_device_t *session) session->shmindex = ntpshm_alloc(session->context); if (0 > session->shmindex) { - gpsd_report(LOG_INF, "NTPD ntpshm_alloc() failed\n"); + gpsd_report(session->context->debug, LOG_INF, "NTPD ntpshm_alloc() failed\n"); #if defined(PPS_ENABLE) } else if (session->context->shmTimePPS) { /* We also have the 1pps capability, allocate a shared-memory segment @@ -975,7 +1004,7 @@ void ntpd_link_activate(struct gps_device_t *session) * transitions */ if ((session->shmTimeP = ntpshm_alloc(session->context)) < 0) { - gpsd_report(LOG_INF, "NTPD ntpshm_alloc(1) failed\n"); + gpsd_report(session->context->debug, LOG_INF, "NTPD ntpshm_alloc(1) failed\n"); } else pps_thread_activate(session); #endif /* PPS_ENABLE */ @@ -179,7 +179,8 @@ static void character_pushback(struct gps_packet_t *lexer) --lexer->inbufptr; /*@+modobserver@*/ --lexer->char_counter; - gpsd_report(LOG_RAW + 2, "%08ld: character pushed back\n", + gpsd_report(lexer->debug, LOG_RAW + 2, + "%08ld: character pushed back\n", lexer->char_counter); } @@ -898,7 +899,7 @@ static void nextstate(struct gps_packet_t *lexer, unsigned char c) n++) csum ^= lexer->inbuffer[n]; if (csum != c) { - gpsd_report(LOG_IO, + gpsd_report(lexer->debug, LOG_IO, "Navcom packet type 0x%hhx bad checksum 0x%hhx, expecting 0x%x\n", lexer->inbuffer[3], csum, c); lexer->state = GROUND_STATE; @@ -985,14 +986,15 @@ static void nextstate(struct gps_packet_t *lexer, unsigned char c) short sum = getword(0) + getword(1) + getword(2) + getword(3); sum *= -1; if (sum != getword(4)) { - gpsd_report(LOG_IO, + gpsd_report(lexer->debug, LOG_IO, "Zodiac Header checksum 0x%hx expecting 0x%hx\n", sum, getword(4)); lexer->state = GROUND_STATE; break; } } - gpsd_report(LOG_RAW + 1, "Zodiac header id=%hd len=%hd flags=%hx\n", + gpsd_report(lexer->debug, LOG_RAW + 1, + "Zodiac header id=%hd len=%hd flags=%hx\n", getword(1), getword(2), getword(3)); #undef getword if (lexer->length == 0) { @@ -1119,7 +1121,8 @@ static void nextstate(struct gps_packet_t *lexer, unsigned char c) if ((c == '>') && (lexer->inbufptr[0] == '<') && (lexer->inbufptr[1] == '!')) { lexer->state = ITALK_RECOGNIZED; - gpsd_report(LOG_IO, "ITALK: trying to process runt packet\n"); + gpsd_report(lexer->debug, LOG_IO, + "ITALK: trying to process runt packet\n"); break; } else if (--lexer->length == 0) lexer->state = ITALK_DELIVERED; @@ -1266,7 +1269,7 @@ static void nextstate(struct gps_packet_t *lexer, unsigned char c) lexer->state = JSON_STRINGLITERAL; lexer->json_after = JSON_END_ATTRIBUTE; } else { - gpsd_report(LOG_RAW + 2, + gpsd_report(lexer->debug, LOG_RAW + 2, "%08ld: missing attribute start after header\n", lexer->char_counter); lexer->state = GROUND_STATE; @@ -1359,11 +1362,14 @@ static void packet_accept(struct gps_packet_t *lexer, int packet_type) lexer->outbuffer[packetlen] = '\0'; lexer->type = packet_type; if (lexer->debug >= LOG_RAW+1) - gpsd_report(LOG_RAW+1, "Packet type %d accepted %zu = %s\n", - packet_type, packetlen, - gpsd_packetdump((char *)lexer->outbuffer, lexer->outbuflen)); + gpsd_report(lexer->debug, LOG_RAW+1, + "Packet type %d accepted %zu = %s\n", + packet_type, packetlen, + gpsd_packetdump((char *)lexer->outbuffer, + lexer->outbuflen)); } else { - gpsd_report(LOG_ERROR, "Rejected too long packet type %d len %zu\n", + gpsd_report(lexer->debug, LOG_ERROR, + "Rejected too long packet type %d len %zu\n", packet_type, packetlen); } } @@ -1376,7 +1382,7 @@ static void packet_discard(struct gps_packet_t *lexer) lexer->inbufptr = memmove(lexer->inbuffer, lexer->inbufptr, remaining); lexer->inbuflen = remaining; if (lexer->debug >= LOG_RAW+1) - gpsd_report(LOG_RAW + 1, + gpsd_report(lexer->debug, LOG_RAW + 1, "Packet discard of %zu, chars remaining is %zu = %s\n", discard, remaining, gpsd_packetdump((char *)lexer->inbuffer, lexer->inbuflen)); @@ -1388,7 +1394,8 @@ static void character_discard(struct gps_packet_t *lexer) memmove(lexer->inbuffer, lexer->inbuffer + 1, (size_t)-- lexer->inbuflen); lexer->inbufptr = lexer->inbuffer; if (lexer->debug >= LOG_RAW+1) - gpsd_report(LOG_RAW + 1, "Character discarded, buffer %zu chars = %s\n", + gpsd_report(lexer->debug, LOG_RAW + 1, + "Character discarded, buffer %zu chars = %s\n", lexer->inbuflen, gpsd_packetdump((char *)lexer->inbuffer, lexer->inbuflen)); } @@ -1423,7 +1430,7 @@ void packet_parse(struct gps_packet_t *lexer) #include "packet_names.h" }; nextstate(lexer, c); - gpsd_report(LOG_RAW + 2, + gpsd_report(lexer->debug, LOG_RAW + 2, "%08ld: character '%c' [%02x], new state: %s\n", lexer->char_counter, (isprint(c) ? c : '.'), c, state_table[lexer->state]); @@ -1465,7 +1472,7 @@ void packet_parse(struct gps_packet_t *lexer) && csum[1] == toupper(end[2])); } if (!checksum_ok) { - gpsd_report(LOG_WARN, + gpsd_report(lexer->debug, LOG_WARN, "bad checksum in NMEA packet; expected %s.\n", csum); packet_accept(lexer, BAD_PACKET); @@ -1518,10 +1525,12 @@ void packet_parse(struct gps_packet_t *lexer) for (n = 0; n < lexer->length - 2; n++) a += (unsigned)lexer->inbuffer[n]; b = (unsigned)getleu16(lexer->inbuffer, lexer->length - 2); - gpsd_report(LOG_IO, "SuperStarII pkt dump: type %u len %u\n", + gpsd_report(lexer->debug, LOG_IO, + "SuperStarII pkt dump: type %u len %u\n", lexer->inbuffer[1], (unsigned int)lexer->length); if (a != b) { - gpsd_report(LOG_IO, "REJECT SuperStarII packet type 0x%02x" + gpsd_report(lexer->debug, LOG_IO, + "REJECT SuperStarII packet type 0x%02x" "%zd bad checksum 0x%04x, expecting 0x%04x\n", lexer->inbuffer[1], lexer->length, a, b); packet_accept(lexer, BAD_PACKET); @@ -1544,11 +1553,13 @@ void packet_parse(struct gps_packet_t *lexer) for (i = 2; i < len - 3; i++) b ^= lexer->inbuffer[i]; if (a == b) { - gpsd_report(LOG_IO, "Accept OnCore packet @@%c%c len %d\n", + gpsd_report(lexer->debug, LOG_IO, + "Accept OnCore packet @@%c%c len %d\n", lexer->inbuffer[2], lexer->inbuffer[3], len); packet_accept(lexer, ONCORE_PACKET); } else { - gpsd_report(LOG_IO, "REJECT OnCore packet @@%c%c len %d\n", + gpsd_report(lexer->debug, LOG_IO, + "REJECT OnCore packet @@%c%c len %d\n", lexer->inbuffer[2], lexer->inbuffer[3], len); packet_accept(lexer, BAD_PACKET); lexer->state = GROUND_STATE; @@ -1570,7 +1581,8 @@ void packet_parse(struct gps_packet_t *lexer) if (dlecnt > 2) { dlecnt -= 2; dlecnt /= 2; - gpsd_report(LOG_RAW, "Unstuffed %d DLEs\n", dlecnt); + gpsd_report(lexer->debug, LOG_RAW, + "Unstuffed %d DLEs\n", dlecnt); packetlen -= dlecnt; } #endif /* TSIP_ENABLE */ @@ -1620,7 +1632,7 @@ void packet_parse(struct gps_packet_t *lexer) /*@ +charint */ chksum &= 0xff; if (chksum) { - gpsd_report(LOG_IO, + gpsd_report(lexer->debug, LOG_IO, "Garmin checksum failed: %02x!=0\n", chksum); goto not_garmin; } @@ -1628,7 +1640,8 @@ void packet_parse(struct gps_packet_t *lexer) packet_discard(lexer); break; not_garmin:; - gpsd_report(LOG_RAW + 1, "Not a Garmin packet\n"); + gpsd_report(lexer->debug, LOG_RAW + 1, + "Not a Garmin packet\n"); #endif /* GARMIN_ENABLE */ #ifdef TSIP_ENABLE /* check for some common TSIP packet types: @@ -1678,7 +1691,7 @@ void packet_parse(struct gps_packet_t *lexer) (0xbc == pkt_id) || (0x38 == pkt_id)) && ((0x41 > pkt_id) || (0x8f < pkt_id))) { - gpsd_report(LOG_IO, + gpsd_report(lexer->debug, LOG_IO, "Packet ID 0x%02x out of range for TSIP\n", pkt_id); goto not_tsip; @@ -1764,14 +1777,14 @@ void packet_parse(struct gps_packet_t *lexer) /* pass */ ; else { /* pass */ ; - gpsd_report(LOG_IO, + gpsd_report(lexer->debug, LOG_IO, "TSIP REJECT pkt_id = %#02x, packetlen= %zu\n", pkt_id, packetlen); goto not_tsip; } #undef TSIP_ID_AND_LENGTH /* Debug */ - gpsd_report(LOG_RAW, + gpsd_report(lexer->debug, LOG_RAW, "TSIP pkt_id = %#02x, packetlen= %zu\n", pkt_id, packetlen); /*@ -charint +ifempty @*/ @@ -1779,7 +1792,7 @@ void packet_parse(struct gps_packet_t *lexer) packet_discard(lexer); break; not_tsip: - gpsd_report(LOG_RAW + 1, "Not a TSIP packet\n"); + gpsd_report(lexer->debug, LOG_RAW + 1, "Not a TSIP packet\n"); /* * More attempts to recognize ambiguous TSIP-like * packet types could go here. @@ -1798,7 +1811,8 @@ void packet_parse(struct gps_packet_t *lexer) lexer->inbufptr - lexer->inbuffer)) { packet_accept(lexer, RTCM3_PACKET); } else { - gpsd_report(LOG_IO, "RTCM3 data checksum failure, " + gpsd_report(lexer->debug, LOG_IO, + "RTCM3 data checksum failure, " "%0x against %02x %02x %02x\n", crc24q_hash(lexer->inbuffer, lexer->inbufptr - lexer->inbuffer - @@ -1821,7 +1835,7 @@ void packet_parse(struct gps_packet_t *lexer) if (len == 0 || sum == getword(5 + len)) { packet_accept(lexer, ZODIAC_PACKET); } else { - gpsd_report(LOG_IO, + gpsd_report(lexer->debug, LOG_IO, "Zodiac data checksum 0x%hx over length %hd, expecting 0x%hx\n", sum, len, getword(5 + len)); packet_accept(lexer, BAD_PACKET); @@ -1838,7 +1852,7 @@ void packet_parse(struct gps_packet_t *lexer) unsigned char ck_a = (unsigned char)0; unsigned char ck_b = (unsigned char)0; len = lexer->inbufptr - lexer->inbuffer; - gpsd_report(LOG_IO, "UBX: len %d\n", len); + gpsd_report(lexer->debug, LOG_IO, "UBX: len %d\n", len); for (n = 2; n < (len - 2); n++) { ck_a += lexer->inbuffer[n]; ck_b += ck_a; @@ -1847,7 +1861,7 @@ void packet_parse(struct gps_packet_t *lexer) ck_b == lexer->inbuffer[len - 1]) packet_accept(lexer, UBX_PACKET); else { - gpsd_report(LOG_IO, + gpsd_report(lexer->debug, LOG_IO, "UBX checksum 0x%02hhx%02hhx over length %d," " expecting 0x%02hhx%02hhx (type 0x%02hhx%02hhx)\n", ck_a, @@ -1898,7 +1912,7 @@ void packet_parse(struct gps_packet_t *lexer) goto not_evermore; crc &= 0xff; if (crc != checksum) { - gpsd_report(LOG_IO, + gpsd_report(lexer->debug, LOG_IO, "EverMore checksum failed: %02x != %02x\n", crc, checksum); goto not_evermore; @@ -1940,7 +1954,7 @@ void packet_parse(struct gps_packet_t *lexer) if (len == 0 || csum == xsum) packet_accept(lexer, ITALK_PACKET); else { - gpsd_report(LOG_IO, + gpsd_report(lexer->debug, LOG_IO, "ITALK: checksum failed - " "type 0x%02x expected 0x%04x got 0x%04x\n", lexer->inbuffer[4], xsum, csum); @@ -1976,7 +1990,7 @@ void packet_parse(struct gps_packet_t *lexer) if (cs == 0) packet_accept(lexer, GEOSTAR_PACKET); else { - gpsd_report(LOG_IO, + gpsd_report(lexer->debug, LOG_IO, "GeoStar checksum failed 0x%x over length %d\n", cs, len); packet_accept(lexer, BAD_PACKET); @@ -2042,22 +2056,24 @@ ssize_t packet_get(int fd, struct gps_packet_t *lexer) /*@ +modobserver @*/ if (recvd == -1) { if ((errno == EAGAIN) || (errno == EINTR)) { - gpsd_report(LOG_RAW + 2, "no bytes ready\n"); + gpsd_report(lexer->debug, LOG_RAW + 2, "no bytes ready\n"); recvd = 0; /* fall through, input buffer may be nonempty */ } else { - gpsd_report(LOG_RAW + 2, "errno: %s\n", strerror(errno)); + gpsd_report(lexer->debug, LOG_RAW + 2, + "errno: %s\n", strerror(errno)); return -1; } } else { if (lexer->debug >= LOG_RAW+1) - gpsd_report(LOG_RAW + 1, + gpsd_report(lexer->debug, LOG_RAW + 1, "Read %zd chars to buffer offset %zd (total %zd): %s\n", recvd, lexer->inbuflen, lexer->inbuflen + recvd, gpsd_packetdump((char *)lexer->inbufptr, (size_t) recvd)); lexer->inbuflen += recvd; } - gpsd_report(LOG_SPIN, "packet_get() fd %d -> %zd (%d)\n", + gpsd_report(lexer->debug, LOG_SPIN, + "packet_get() fd %d -> %zd (%d)\n", fd, recvd, errno); /* @@ -182,7 +182,7 @@ bool gpsd_set_raw(struct gps_device_t * session) { (void)cfmakeraw(&session->ttyset); if (tcsetattr(session->gpsdata.gps_fd, TCIOFLUSH, &session->ttyset) == -1) { - gpsd_report(LOG_ERROR, + gpsd_report(session->context->debug, LOG_ERROR, "error changing port attributes: %s\n", strerror(errno)); return false; } @@ -315,7 +315,8 @@ void gpsd_set_speed(struct gps_device_t *session, (void)usleep(200000); (void)tcflush(session->gpsdata.gps_fd, TCIOFLUSH); } - gpsd_report(LOG_INF, "speed %u, %d%c%d\n", + gpsd_report(session->context->debug, LOG_INF, + "speed %u, %d%c%d\n", gpsd_get_speed(session), 9 - stopbits, parity, stopbits); @@ -360,11 +361,11 @@ int gpsd_serial_open(struct gps_device_t *session) if (session->context->readonly || (session->sourcetype <= source_blockdev)) { mode = (mode_t) O_RDONLY; - gpsd_report(LOG_INF, + gpsd_report(session->context->debug, LOG_INF, "opening read-only GPS data source type %d and at '%s'\n", (int)session->sourcetype, session->gpsdata.dev.path); } else { - gpsd_report(LOG_INF, + gpsd_report(session->context->debug, LOG_INF, "opening GPS data source type %d at '%s'\n", (int)session->sourcetype, session->gpsdata.dev.path); } @@ -381,15 +382,18 @@ int gpsd_serial_open(struct gps_device_t *session) if (connect(session->gpsdata.gps_fd, (struct sockaddr *) &addr, sizeof (addr)) == -1) { if (errno != EINPROGRESS && errno != EAGAIN) { (void)close(session->gpsdata.gps_fd); - gpsd_report(LOG_ERROR, "bluetooth socket connect failed: %s\n", + gpsd_report(session->context->debug, LOG_ERROR, + "bluetooth socket connect failed: %s\n", strerror(errno)); return -1; } - gpsd_report(LOG_ERROR, "bluetooth socket connect in progress or again : %s\n", + gpsd_report(session->context->debug, LOG_ERROR, + "bluetooth socket connect in progress or again : %s\n", strerror(errno)); } (void)fcntl(session->gpsdata.gps_fd, F_SETFL, (int)mode | O_NONBLOCK); - gpsd_report(LOG_PROG, "bluez device open success: %s %s\n", + gpsd_report(session->context->debug, LOG_PROG, + "bluez device open success: %s %s\n", session->gpsdata.dev.path, strerror(errno)); } else #endif /* BLUEZ */ @@ -397,17 +401,19 @@ int gpsd_serial_open(struct gps_device_t *session) if ((session->gpsdata.gps_fd = open(session->gpsdata.dev.path, (int)(mode | O_NONBLOCK | O_NOCTTY))) == -1) { - gpsd_report(LOG_ERROR, + gpsd_report(session->context->debug, LOG_ERROR, "device open failed: %s - retrying read-only\n", strerror(errno)); if ((session->gpsdata.gps_fd = open(session->gpsdata.dev.path, O_RDONLY | O_NONBLOCK | O_NOCTTY)) == -1) { - gpsd_report(LOG_ERROR, "read-only device open failed: %s\n", - strerror(errno)); + gpsd_report(session->context->debug, LOG_ERROR, + "read-only device open failed: %s\n", + strerror(errno)); return -1; } - gpsd_report(LOG_PROG, "file device open success: %s\n", + gpsd_report(session->context->debug, LOG_PROG, + "file device open success: %s\n", strerror(errno)); } } @@ -436,7 +442,7 @@ int gpsd_serial_open(struct gps_device_t *session) * Don't touch devices already opened by another process. */ if (fusercount(session->gpsdata.dev.path) > 1) { - gpsd_report(LOG_ERROR, + gpsd_report(session->context->debug, LOG_ERROR, "%s already opened by another process\n", session->gpsdata.dev.path); (void)close(session->gpsdata.gps_fd); @@ -514,7 +520,8 @@ int gpsd_serial_open(struct gps_device_t *session) session->gpsdata.dev.stopbits = 1; } - gpsd_report(LOG_SPIN, "open(%s) -> %d in gpsd_serial_open()\n", + gpsd_report(session->context->debug, LOG_SPIN, + "open(%s) -> %d in gpsd_serial_open()\n", session->gpsdata.dev.path, session->gpsdata.gps_fd); return session->gpsdata.gps_fd; } @@ -531,7 +538,8 @@ ssize_t gpsd_write(struct gps_device_t * session, const char *buf, size_t len) (void)tcdrain(session->gpsdata.gps_fd); /* extra guard prevents expensive hexdump calls */ if (session->context->debug >= LOG_IO) - gpsd_report(LOG_IO, "=> GPS: %s%s\n", + gpsd_report(session->context->debug, LOG_IO, + "=> GPS: %s%s\n", gpsd_packetdump((char *)buf, len), ok ? "" : " FAILED"); return status; } @@ -636,7 +644,8 @@ void gpsd_close(struct gps_device_t *session) (void)tcsetattr(session->gpsdata.gps_fd, TCSANOW, &session->ttyset_old); } - gpsd_report(LOG_SPIN, "close(%d) in gpsd_close(%s)\n", + gpsd_report(session->context->debug, LOG_SPIN, + "close(%d) in gpsd_close(%s)\n", session->gpsdata.gps_fd, session->gpsdata.dev.path); (void)close(session->gpsdata.gps_fd); session->gpsdata.gps_fd = -1; diff --git a/shmexport.c b/shmexport.c index 9e213ff2..f78ba5ad 100644 --- a/shmexport.c +++ b/shmexport.c @@ -35,7 +35,8 @@ bool shm_acquire(struct gps_context_t *context) shmid = shmget((key_t)GPSD_KEY, sizeof(struct gps_data_t), (int)(IPC_CREAT|0666)); if (shmid == -1) { - gpsd_report(LOG_ERROR, "shmget(%ld, %zd, 0666) failed: %s\n", + gpsd_report(context->debug, LOG_ERROR, + "shmget(%ld, %zd, 0666) failed: %s\n", (long int)GPSD_KEY, sizeof(struct gps_data_t), strerror(errno)); @@ -43,11 +44,12 @@ bool shm_acquire(struct gps_context_t *context) } context->shmexport = (char *)shmat(shmid, 0, 0); if ((int)(long)context->shmexport == -1) { - gpsd_report(LOG_ERROR, "shmat failed: %s\n", strerror(errno)); + gpsd_report(context->debug, LOG_ERROR, "shmat failed: %s\n", strerror(errno)); context->shmexport = NULL; return false; } - gpsd_report(LOG_PROG, "shmat() succeeded, segment %d\n", shmid); + gpsd_report(context->debug, LOG_PROG, + "shmat() succeeded, segment %d\n", shmid); return true; } @@ -22,7 +22,8 @@ gps_mask_t gpsd_interpret_subframe_raw(struct gps_device_t *session, speed_t speed = gpsd_get_speed(session); if (speed < 38400) - gpsd_report(LOG_WARN, "speed less than 38,400 may cause data lag and loss of functionality\n"); + gpsd_report(session->context->debug, LOG_WARN, + "speed less than 38,400 may cause data lag and loss of functionality\n"); } /* @@ -43,7 +44,8 @@ gps_mask_t gpsd_interpret_subframe_raw(struct gps_device_t *session, * word is inverted. * */ - gpsd_report(LOG_IO, "50B: gpsd_interpret_subframe_raw: " + gpsd_report(session->context->debug, LOG_IO, + "50B: gpsd_interpret_subframe_raw: " "%08x %08x %08x %08x %08x %08x %08x %08x %08x %08x\n", words[0], words[1], words[2], words[3], words[4], words[5], words[6], words[7], words[8], words[9]); @@ -53,7 +55,7 @@ gps_mask_t gpsd_interpret_subframe_raw(struct gps_device_t *session, words[0] ^= 0x3fffffc0; /* invert */ } else if (preamble != 0x74) { /* strangely this is very common, so don't log it */ - gpsd_report(LOG_IO, + gpsd_report(session->context->debug, LOG_IO, "50B: gpsd_interpret_subframe_raw: bad preamble 0x%x\n", preamble); return 0; @@ -70,7 +72,7 @@ gps_mask_t gpsd_interpret_subframe_raw(struct gps_device_t *session, } parity = (uint32_t)isgps_parity((isgps30bits_t)words[i]); if (parity != (words[i] & 0x3f)) { - gpsd_report(LOG_IO, + gpsd_report(session->context->debug, LOG_IO, "50B: gpsd_interpret_subframe_raw parity fail words[%d] 0x%x != 0x%x\n", i, parity, (words[i] & 0x1)); return 0; @@ -87,7 +89,7 @@ gps_mask_t gpsd_interpret_subframe_raw(struct gps_device_t *session, static void subframe_almanac(uint8_t tSVID, uint32_t words[], uint8_t subframe, uint8_t sv, uint8_t data_id, - /*@out@*/struct almanac_t *almp) + /*@out@*/struct almanac_t *almp, const debug) { /*@+matchanyintegral -shiftimplementation@*/ almp->sv = sv; /* ignore the 0 sv problem for now */ @@ -123,7 +125,7 @@ static void subframe_almanac(uint8_t tSVID, uint32_t words[], almp->af0 |= ((words[9] >> 2) & 0x000007); almp->af0 = (short)uint2int(almp->af0, 11); almp->d_af0 = pow(2.0,-20) * almp->af0; - gpsd_report(LOG_PROG, + gpsd_report(debug, LOG_PROG, "50B: SF:%d SV:%2u TSV:%2u data_id %d e:%g toa:%lu " "deltai:%.10e Omegad:%.5e svh:%u sqrtA:%.10g Omega0:%.10e " "omega:%.10e M0:%.11e af0:%.5e af1:%.5e\n", @@ -162,7 +164,7 @@ gps_mask_t gpsd_interpret_subframe(struct gps_device_t *session, uint8_t preamble; int i = 0; /* handy loop counter */ struct subframe_t *subp = &session->gpsdata.subframe; - gpsd_report(LOG_IO, + gpsd_report(session->context->debug, LOG_IO, "50B: gpsd_interpret_subframe: (%d) " "%06x %06x %06x %06x %06x %06x %06x %06x %06x %06x\n", tSVID, words[0], words[1], words[2], words[3], words[4], @@ -175,7 +177,7 @@ gps_mask_t gpsd_interpret_subframe(struct gps_device_t *session, words[0] ^= 0xffffff; } if (preamble != 0x74) { - gpsd_report(LOG_WARN, + gpsd_report(session->context->debug, LOG_WARN, "50B: gpsd_interpret_subframe bad preamble: 0x%x header 0x%x\n", preamble, words[0]); return 0; @@ -188,7 +190,7 @@ gps_mask_t gpsd_interpret_subframe(struct gps_device_t *session, subp->subframe_num = ((words[1] >> 2) & 0x07); subp->alert = (bool)((words[1] >> 6) & 0x01); subp->antispoof = (bool)((words[1] >> 6) & 0x01); - gpsd_report(LOG_PROG, + gpsd_report(session->context->debug, LOG_PROG, "50B: SF:%d SV:%2u TOW17:%7lu Alert:%u AS:%u IF:%d\n", subp->subframe_num, subp->tSVID, subp->l_TOW17, (unsigned)subp->alert, (unsigned)subp->antispoof, @@ -232,7 +234,8 @@ gps_mask_t gpsd_interpret_subframe(struct gps_device_t *session, subp->sub1.d_af0 = pow(2.0, -31) * subp->sub1.af0; subp->sub1.IODC <<= 8; subp->sub1.IODC |= ((words[7] >> 16) & 0x00FF); - gpsd_report(LOG_PROG, "50B: SF:1 SV:%2u WN:%4u IODC:%4u" + gpsd_report(session->context->debug, LOG_PROG, + "50B: SF:1 SV:%2u WN:%4u IODC:%4u" " L2:%u ura:%u hlth:%u L2P:%u Tgd:%g toc:%lu af2:%.4g" " af1:%.6e af0:%.7e\n", subp->tSVID, @@ -276,7 +279,7 @@ gps_mask_t gpsd_interpret_subframe(struct gps_device_t *session, subp->sub2.fit = ((words[9] >> 7) & 0x000001); subp->sub2.AODO = ((words[9] >> 2) & 0x00001F); subp->sub2.u_AODO = subp->sub2.AODO * 900; - gpsd_report(LOG_PROG, + gpsd_report(session->context->debug, LOG_PROG, "50B: SF:2 SV:%2u IODE:%3u Crs:%.6e deltan:%.6e " "M0:%.11e Cuc:%.6e e:%f Cus:%.6e sqrtA:%.11g " "toe:%lu FIT:%u AODO:%5u\n", @@ -320,7 +323,7 @@ gps_mask_t gpsd_interpret_subframe(struct gps_device_t *session, subp->sub3.IDOT = (int16_t)((words[9] >> 2) & 0x003FFF); subp->sub3.IDOT = uint2int(subp->sub3.IDOT, 14); subp->sub3.d_IDOT = pow(2.0, -43) * subp->sub3.IDOT; - gpsd_report(LOG_PROG, + gpsd_report(session->context->debug, LOG_PROG, "50B: SF:3 SV:%2u IODE:%3u I IDOT:%.6g Cic:%.6e Omega0:%.11e " " Cis:%.7g i0:%.11e Crc:%.7g omega:%.11e Omegad:%.6e\n", subp->tSVID, subp->sub3.IODE, subp->sub3.d_IDOT, @@ -473,15 +476,16 @@ gps_mask_t gpsd_interpret_subframe(struct gps_device_t *session, } /*@-charint@*/ - gpsd_report(LOG_PROG, "50B: SF:4-13 data_id %d ai:%u " - "ERD1:%d ERD2:%d ERD3:%d ERD4:%d " - "ERD5:%d ERD6:%d ERD7:%d ERD8:%d " - "ERD9:%d ERD10:%d ERD11:%d ERD12:%d " - "ERD13:%d ERD14:%d ERD15:%d ERD16:%d " - "ERD17:%d ERD18:%d ERD19:%d ERD20:%d " - "ERD21:%d ERD22:%d ERD23:%d ERD24:%d " - "ERD25:%d ERD26:%d ERD27:%d ERD28:%d " - "ERD29:%d ERD30:%d\n", + gpsd_report(session->context->debug, LOG_PROG, + "50B: SF:4-13 data_id %d ai:%u " + "ERD1:%d ERD2:%d ERD3:%d ERD4:%d " + "ERD5:%d ERD6:%d ERD7:%d ERD8:%d " + "ERD9:%d ERD10:%d ERD11:%d ERD12:%d " + "ERD13:%d ERD14:%d ERD15:%d ERD16:%d " + "ERD17:%d ERD18:%d ERD19:%d ERD20:%d " + "ERD21:%d ERD22:%d ERD23:%d ERD24:%d " + "ERD25:%d ERD26:%d ERD27:%d ERD28:%d " + "ERD29:%d ERD30:%d\n", subp->data_id, subp->sub4_13.ai, subp->sub4_13.ERD[1], subp->sub4_13.ERD[2], subp->sub4_13.ERD[3], subp->sub4_13.ERD[4], @@ -551,17 +555,18 @@ gps_mask_t gpsd_interpret_subframe(struct gps_device_t *session, subp->sub4_25.svhx[6] = ((words[9] >> 12) & 0x00003F); subp->sub4_25.svhx[7] = ((words[9] >> 6) & 0x00003F); - gpsd_report(LOG_PROG, "50B: SF:4-25 data_id %d " - "SV1:%u SV2:%u SV3:%u SV4:%u " - "SV5:%u SV6:%u SV7:%u SV8:%u " - "SV9:%u SV10:%u SV11:%u SV12:%u " - "SV13:%u SV14:%u SV15:%u SV16:%u " - "SV17:%u SV18:%u SV19:%u SV20:%u " - "SV21:%u SV22:%u SV23:%u SV24:%u " - "SV25:%u SV26:%u SV27:%u SV28:%u " - "SV29:%u SV30:%u SV31:%u SV32:%u " - "SVH25:%u SVH26:%u SVH27:%u SVH28:%u " - "SVH29:%u SVH30:%u SVH31:%u SVH32:%u\n", + gpsd_report(session->context->debug, LOG_PROG, + "50B: SF:4-25 data_id %d " + "SV1:%u SV2:%u SV3:%u SV4:%u " + "SV5:%u SV6:%u SV7:%u SV8:%u " + "SV9:%u SV10:%u SV11:%u SV12:%u " + "SV13:%u SV14:%u SV15:%u SV16:%u " + "SV17:%u SV18:%u SV19:%u SV20:%u " + "SV21:%u SV22:%u SV23:%u SV24:%u " + "SV25:%u SV26:%u SV27:%u SV28:%u " + "SV29:%u SV30:%u SV31:%u SV32:%u " + "SVH25:%u SVH26:%u SVH27:%u SVH28:%u " + "SVH29:%u SVH30:%u SVH31:%u SVH32:%u\n", subp->data_id, subp->sub4_25.svf[1], subp->sub4_25.svf[2], subp->sub4_25.svf[3], subp->sub4_25.svf[4], @@ -657,8 +662,9 @@ gps_mask_t gpsd_interpret_subframe(struct gps_device_t *session, subp->sub4_17.str[i++] = (words[9] >> 8) & 0xff; subp->sub4_17.str[i] = '\0'; /*@ +type @*/ - gpsd_report(LOG_PROG, "50B: SF:4-17 system message: %.24s\n", - subp->sub4_17.str); + gpsd_report(session->context->debug, LOG_PROG, + "50B: SF:4-17 system message: %.24s\n", + subp->sub4_17.str); break; case 18: case 56: @@ -707,19 +713,19 @@ gps_mask_t gpsd_interpret_subframe(struct gps_device_t *session, /* leap second future */ subp->sub4_18.lsf = (int8_t)((words[9] >> 16) & 0x0000FF); - gpsd_report(LOG_PROG, - "50B: SF:4-18 a0:%.5g a1:%.5g a2:%.5g a3:%.5g " - "b0:%.5g b1:%.5g b2:%.5g b3:%.5g " - "A1:%.11e A0:%.11e tot:%.5g WNt:%u " - "ls: %d WNlsf:%u DN:%u, lsf:%d\n", - subp->sub4_18.d_alpha0, subp->sub4_18.d_alpha1, - subp->sub4_18.d_alpha2, subp->sub4_18.d_alpha3, - subp->sub4_18.d_beta0, subp->sub4_18.d_beta1, - subp->sub4_18.d_beta2, subp->sub4_18.d_beta3, - subp->sub4_18.d_A1, subp->sub4_18.d_A0, - subp->sub4_18.d_tot, subp->sub4_18.WNt, - subp->sub4_18.leap, subp->sub4_18.WNlsf, - subp->sub4_18.DN, subp->sub4_18.lsf); + gpsd_report(session->context->debug, LOG_PROG, + "50B: SF:4-18 a0:%.5g a1:%.5g a2:%.5g a3:%.5g " + "b0:%.5g b1:%.5g b2:%.5g b3:%.5g " + "A1:%.11e A0:%.11e tot:%.5g WNt:%u " + "ls: %d WNlsf:%u DN:%u, lsf:%d\n", + subp->sub4_18.d_alpha0, subp->sub4_18.d_alpha1, + subp->sub4_18.d_alpha2, subp->sub4_18.d_alpha3, + subp->sub4_18.d_beta0, subp->sub4_18.d_beta1, + subp->sub4_18.d_beta2, subp->sub4_18.d_beta3, + subp->sub4_18.d_A1, subp->sub4_18.d_A0, + subp->sub4_18.d_tot, subp->sub4_18.WNt, + subp->sub4_18.leap, subp->sub4_18.WNlsf, + subp->sub4_18.DN, subp->sub4_18.lsf); #ifdef NTPSHM_ENABLE /* IS-GPS-200 Revision E, paragraph 20.3.3.5.2.4 */ @@ -746,10 +752,12 @@ gps_mask_t gpsd_interpret_subframe(struct gps_device_t *session, if ( -1 < sv ) { subp->is_almanac = 1; subframe_almanac(subp->tSVID, words, subp->subframe_num, - (uint8_t)sv, subp->data_id, &subp->sub4.almanac); + (uint8_t)sv, subp->data_id, + &subp->sub4.almanac, + session->context->debug); } else if ( -2 == sv ) { /* unknown or secret page */ - gpsd_report(LOG_PROG, + gpsd_report(session->context->debug, LOG_PROG, "50B: SF:4-%d data_id %d\n", subp->pageid, subp->data_id); return 0; @@ -766,7 +774,8 @@ gps_mask_t gpsd_interpret_subframe(struct gps_device_t *session, if ( 25 > subp->pageid ) { subp->is_almanac = 1; subframe_almanac(subp->tSVID, words, subp->subframe_num, - subp->pageid, subp->data_id, &subp->sub5.almanac); + subp->pageid, subp->data_id, &subp->sub5.almanac, + session->context->debug); } else if ( 51 == subp->pageid ) { /* for some inscrutable reason page 25 is sent as page 51 * IS-GPS-200E Table 20-V */ @@ -798,14 +807,14 @@ gps_mask_t gpsd_interpret_subframe(struct gps_device_t *session, subp->sub5_25.sv[22] = ((words[7] >> 12) & 0x00003F); subp->sub5_25.sv[23] = ((words[7] >> 6) & 0x00003F); subp->sub5_25.sv[24] = ((words[7] >> 0) & 0x00003F); - gpsd_report(LOG_PROG, - "50B: SF:5-25 SV:%2u ID:%u toa:%lu WNa:%u " - "SV1:%u SV2:%u SV3:%u SV4:%u " - "SV5:%u SV6:%u SV7:%u SV8:%u " - "SV9:%u SV10:%u SV11:%u SV12:%u " - "SV13:%u SV14:%u SV15:%u SV16:%u " - "SV17:%u SV18:%u SV19:%u SV20:%u " - "SV21:%u SV22:%u SV23:%u SV24:%u\n", + gpsd_report(session->context->debug, LOG_PROG, + "50B: SF:5-25 SV:%2u ID:%u toa:%lu WNa:%u " + "SV1:%u SV2:%u SV3:%u SV4:%u " + "SV5:%u SV6:%u SV7:%u SV8:%u " + "SV9:%u SV10:%u SV11:%u SV12:%u " + "SV13:%u SV14:%u SV15:%u SV16:%u " + "SV17:%u SV18:%u SV19:%u SV20:%u " + "SV21:%u SV22:%u SV23:%u SV24:%u\n", subp->tSVID, subp->data_id, subp->sub5_25.l_toa, subp->sub5_25.WNa, subp->sub5_25.sv[1], subp->sub5_25.sv[2], @@ -822,8 +831,9 @@ gps_mask_t gpsd_interpret_subframe(struct gps_device_t *session, subp->sub5_25.sv[23], subp->sub5_25.sv[24]); } else { /* unknown page */ - gpsd_report(LOG_PROG, "50B: SF:5-%d data_id %d uknown page\n", - subp->pageid, subp->data_id); + gpsd_report(session->context->debug, LOG_PROG, + "50B: SF:5-%d data_id %d uknown page\n", + subp->pageid, subp->data_id); return 0; } break; diff --git a/test_geoid.c b/test_geoid.c index a6d5b779..e88251df 100644 --- a/test_geoid.c +++ b/test_geoid.c @@ -9,11 +9,6 @@ #include "gpsd.h" -void gpsd_report(int errlevel UNUSED, const char *fmt UNUSED, ...) -{ - /* stub required to prevent linkage error */ -} - int main(int argc, char **argv) { double lat, lon; diff --git a/test_packet.c b/test_packet.c index 30da233f..eee8e3e4 100644 --- a/test_packet.c +++ b/test_packet.c @@ -17,10 +17,10 @@ static int verbose = 0; -void gpsd_report(int errlevel, const char *fmt, ...) +void gpsd_report(int debuglevel, int errlevel, const char *fmt, ...) /* assemble command in printf(3) style, use stderr or syslog */ { - if (errlevel <= verbose) { + if (errlevel <= debuglevel) { char buf[BUFSIZ]; va_list ap; @@ -126,7 +126,8 @@ void gpsd_time_init(struct gps_context_t *context, time_t starttime) context->rollovers = (int)((context->start_time-GPS_EPOCH) / GPS_ROLLOVER); if (context->start_time < GPS_EPOCH) - gpsd_report(LOG_ERROR, "system time looks bogus, dates may not be reliable.\n"); + gpsd_report(context->debug, LOG_ERROR, + "system time looks bogus, dates may not be reliable.\n"); else { /* we've forced the UTC timezone, so this is actually UTC */ struct tm *now = localtime(&context->start_time); @@ -138,7 +139,8 @@ void gpsd_time_init(struct gps_context_t *context, time_t starttime) now->tm_year += 1900; context->century = now->tm_year - (now->tm_year % 100); (void)unix_to_iso8601((timestamp_t)context->start_time, scr, sizeof(scr)); - gpsd_report(LOG_INF, "startup at %s (%d)\n", + gpsd_report(context->debug, LOG_INF, + "startup at %s (%d)\n", scr, (int)context->start_time); } } @@ -192,7 +194,8 @@ timestamp_t gpsd_utc_resolve(/*@in@*/struct gps_device_t *session) if (session->newdata.time < (timestamp_t)session->context->start_time) { char scr[128]; (void)unix_to_iso8601(session->newdata.time, scr, sizeof(scr)); - gpsd_report(LOG_WARN, "GPS week rollover makes time %s (%f) invalid\n", + gpsd_report(session->context->debug, LOG_WARN, + "GPS week rollover makes time %s (%f) invalid\n", scr, session->newdata.time); } @@ -213,7 +216,8 @@ timestamp_t gpsd_gpstime_resolve(/*@in@*/struct gps_device_t *session, * to 13 bits. */ if ((int)week < (session->context->gps_week & 0x3ff)) { - gpsd_report(LOG_INF, "GPS week 10-bit rollover detected.\n"); + gpsd_report(session->context->debug, LOG_INF, + "GPS week 10-bit rollover detected.\n"); ++session->context->rollovers; } |