summaryrefslogtreecommitdiff
path: root/drivers.c
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2015-03-07 11:51:15 -0500
committerEric S. Raymond <esr@thyrsus.com>2015-03-07 11:51:15 -0500
commitdf34a3add8df382eb852a67635c6859ee8cc657f (patch)
treec52183ba41403d093ad1ac971fa45c4ba1289f0c /drivers.c
parent9c49083f2afe799343a610912b0ed404b2ffad05 (diff)
downloadgpsd-df34a3add8df382eb852a67635c6859ee8cc657f.tar.gz
gpsd-report() -> gpsd_log()
This change is done so we can add a "log" hook to the pps_thread_t structure (this is not done yet) and harmonize with the name of the outer logging function. If that name had been left as gpsd_report() there would have been scope for bad confusion with the report_hook member. Also, remove two stray duplicative printf calls from the NMEA2000 driver (drivers shouldn't have printfs!) and fix one typo. This is a step towards factoring out ntplib. For that to happen, the PPS thread code needs to be decoupled from the core session structure. No logic changes. Object compatibility preserved. All regression tests pass.
Diffstat (limited to 'drivers.c')
-rw-r--r--drivers.c154
1 files changed, 79 insertions, 75 deletions
diff --git a/drivers.c b/drivers.c
index 576ef574..bc49cf96 100644
--- a/drivers.c
+++ b/drivers.c
@@ -36,22 +36,22 @@ gps_mask_t generic_parse_input(struct gps_device_t *session)
char *sentence = (char *)session->lexer.outbuffer;
if (sentence[strlen(sentence)-1] != '\n')
- gpsd_report(&session->context->errout, LOG_IO,
- "<= GPS: %s\n", sentence);
+ gpsd_log(&session->context->errout, LOG_IO,
+ "<= GPS: %s\n", sentence);
else
- gpsd_report(&session->context->errout, LOG_IO,
- "<= GPS: %s", sentence);
+ gpsd_log(&session->context->errout, LOG_IO,
+ "<= GPS: %s", sentence);
if ((st=nmea_parse(sentence, session)) == 0) {
- gpsd_report(&session->context->errout, LOG_WARN,
- "unknown sentence: \"%s\"\n", sentence);
+ gpsd_log(&session->context->errout, LOG_WARN,
+ "unknown sentence: \"%s\"\n", sentence);
}
for (dp = gpsd_drivers; *dp; dp++) {
char *trigger = (*dp)->trigger;
if (trigger!=NULL && str_starts_with(sentence, trigger)) {
- gpsd_report(&session->context->errout, LOG_PROG,
- "found trigger string %s.\n", trigger);
+ gpsd_log(&session->context->errout, 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
@@ -65,9 +65,9 @@ gps_mask_t generic_parse_input(struct gps_device_t *session)
return st;
#endif /* NMEA_ENABLE */
} else {
- gpsd_report(&session->context->errout, LOG_SHOUT,
- "packet type %d fell through (should never happen): %s.\n",
- session->lexer.type, gpsd_prettydump(session));
+ gpsd_log(&session->context->errout, LOG_SHOUT,
+ "packet type %d fell through (should never happen): %s.\n",
+ session->lexer.type, gpsd_prettydump(session));
return 0;
}
}
@@ -149,8 +149,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(&session->context->errout, LOG_PROG,
- "=> Probing for Garmin NMEA\n");
+ gpsd_log(&session->context->errout, LOG_PROG,
+ "=> Probing for Garmin NMEA\n");
(void)nmea_send(session, "$PGRMCE");
break;
#endif /* NMEA_ENABLE */
@@ -173,7 +173,8 @@ static void nmea_event_hook(struct gps_device_t *session, event_t event)
* mode! Fix this if we ever find a nondisruptive probe
* string.
*/
- gpsd_report(&session->context->errout, LOG_PROG, "=> Probing for SiRF\n");
+ gpsd_log(&session->context->errout, LOG_PROG,
+ "=> Probing for SiRF\n");
(void)nmea_send(session,
"$PSRF100,0,%d,%d,%d,0",
session->gpsdata.dev.baudrate,
@@ -185,20 +186,21 @@ 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(&session->context->errout, LOG_PROG, "=> Probing for FV-18\n");
+ gpsd_log(&session->context->errout, LOG_PROG,
+ "=> Probing for FV-18\n");
(void)nmea_send(session, "$PFEC,GPint");
break;
case 3:
/* probe for the Trimble Copernicus */
- gpsd_report(&session->context->errout, LOG_PROG,
- "=> Probing for Trimble Copernicus\n");
+ gpsd_log(&session->context->errout, 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(&session->context->errout, LOG_PROG,
- "=> Probing for Evermore\n");
+ gpsd_log(&session->context->errout, 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,
@@ -209,32 +211,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(&session->context->errout, LOG_PROG,
- "=> Probing for GPSClock\n");
+ gpsd_log(&session->context->errout, 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(&session->context->errout, LOG_PROG,
- "=> Probing for Ashtech\n");
+ gpsd_log(&session->context->errout, LOG_PROG,
+ "=> Probing for Ashtech\n");
(void)nmea_send(session, "$PASHQ,RID");
break;
#endif /* ASHTECH_ENABLE */
#ifdef UBLOX_ENABLE
case 7:
/* probe for UBX -- query port configuration */
- gpsd_report(&session->context->errout, LOG_PROG,
- "=> Probing for UBX\n");
+ gpsd_log(&session->context->errout, LOG_PROG,
+ "=> Probing for UBX\n");
(void)ubx_write(session, 0x06, 0x00, NULL, 0);
break;
#endif /* UBLOX_ENABLE */
#ifdef MTK3301_ENABLE
case 8:
/* probe for MTK-3301 -- expect $PMTK705 */
- gpsd_report(&session->context->errout, LOG_PROG,
- "=> Probing for MediaTek\n");
+ gpsd_log(&session->context->errout, LOG_PROG,
+ "=> Probing for MediaTek\n");
(void)nmea_send(session, "$PMTK605");
break;
#endif /* MTK3301_ENABLE */
@@ -514,8 +516,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(&session->context->errout, LOG_INF,
- "PPS trailing edge will be ignored\n");
+ gpsd_log(&session->context->errout, LOG_INF,
+ "PPS trailing edge will be ignored\n");
session->nmea.ignore_trailing_edge = true;
}
}
@@ -687,8 +689,8 @@ static ssize_t tnt_control_send(struct gps_device_t *session,
}
#ifdef __UNUSED__
else {
- gpsd_report(&session->context->errout, LOG_ERROR,
- "Bad TNT sentence: '%s'\n", msg);
+ gpsd_log(&session->context->errout, LOG_ERROR,
+ "Bad TNT sentence: '%s'\n", msg);
}
#endif /* __UNUSED__ */
while (((c = *p) != '\0')) {
@@ -713,12 +715,12 @@ 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(&session->context->errout, LOG_IO,
- "=> GPS: %s\n", buf);
+ gpsd_log(&session->context->errout, LOG_IO,
+ "=> GPS: %s\n", buf);
return true;
} else {
- gpsd_report(&session->context->errout, LOG_WARN,
- "=> GPS: %s FAILED\n", buf);
+ gpsd_log(&session->context->errout, LOG_WARN,
+ "=> GPS: %s FAILED\n", buf);
return false;
}
}
@@ -811,10 +813,10 @@ static int oceanserver_send(struct gpsd_errout_t *errout,
status = (int)write(fd, buf, strlen(buf));
(void)tcdrain(fd);
if (status == (int)strlen(buf)) {
- gpsd_report(errout, LOG_IO, "=> GPS: %s\n", buf);
+ gpsd_log(errout, LOG_IO, "=> GPS: %s\n", buf);
return status;
} else {
- gpsd_report(errout, LOG_WARN, "=> GPS: %s FAILED\n", buf);
+ gpsd_log(errout, LOG_WARN, "=> GPS: %s FAILED\n", buf);
return -1;
}
}
@@ -944,12 +946,12 @@ static gps_mask_t rtcm104v2_analyze(struct gps_device_t *session)
rtcm2_unpack(&session->gpsdata.rtcm2, (char *)session->lexer.isgps.buf);
/* extra guard prevents expensive hexdump calls */
if (session->context->errout.debug >= LOG_RAW)
- gpsd_report(&session->context->errout, 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->lexer.isgps.buflen,
- gpsd_hexdump(session->msgbuf, sizeof(session->msgbuf),
+ gpsd_log(&session->context->errout, 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->lexer.isgps.buflen,
+ gpsd_hexdump(session->msgbuf, sizeof(session->msgbuf),
(char *)session->lexer.isgps.buf,
(session->gpsdata.rtcm2.length +
2) * sizeof(isgps30bits_t)));
@@ -996,7 +998,7 @@ static gps_mask_t rtcm104v3_analyze(struct gps_device_t *session)
{
uint16_t type = getbeu16(session->lexer.inbuffer, 3) >> 4;
- gpsd_report(&session->context->errout, LOG_RAW, "RTCM 3.x packet %d\n", type);
+ gpsd_log(&session->context->errout, LOG_RAW, "RTCM 3.x packet %d\n", type);
rtcm3_unpack(session->context,
&session->gpsdata.rtcm3,
(char *)session->lexer.outbuffer);
@@ -1207,15 +1209,16 @@ static bool aivdm_decode(const char *buf, size_t buflen,
return false;
/* we may need to dump the raw packet */
- gpsd_report(&session->context->errout, LOG_PROG,
- "AIVDM packet length %zd: %s\n", buflen, buf);
+ gpsd_log(&session->context->errout, 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(&session->context->errout, LOG_ERROR, "overlong AIVDM packet.\n");
+ gpsd_log(&session->context->errout, LOG_ERROR,
+ "overlong AIVDM packet.\n");
return false;
}
@@ -1231,7 +1234,8 @@ static bool aivdm_decode(const char *buf, size_t buflen,
/* discard sentences with exiguous commas; catches run-ons */
if (nfields < 7) {
- gpsd_report(&session->context->errout, LOG_ERROR, "malformed AIVDM packet.\n");
+ gpsd_log(&session->context->errout, LOG_ERROR,
+ "malformed AIVDM packet.\n");
return false;
}
@@ -1243,15 +1247,15 @@ static bool aivdm_decode(const char *buf, size_t buflen,
* is going to break if there's ever an AIVDO type 24, though.
*/
if (!str_starts_with((const char *)field[0], "!AIVDO"))
- gpsd_report(&session->context->errout, LOG_INF,
- "invalid empty AIS channel. Assuming 'A'\n");
+ gpsd_log(&session->context->errout, LOG_INF,
+ "invalid empty AIS channel. Assuming 'A'\n");
ais_context = &session->driver.aivdm.context[0];
session->driver.aivdm.ais_channel ='A';
break;
case '1':
if (strcmp((char *)field[4], (char *)"12") == 0) {
- gpsd_report(&session->context->errout, LOG_INF,
- "ignoring bogus AIS channel '12'.\n");
+ gpsd_log(&session->context->errout, LOG_INF,
+ "ignoring bogus AIS channel '12'.\n");
return false;
}
/*@fallthrough@*/
@@ -1266,12 +1270,12 @@ static bool aivdm_decode(const char *buf, size_t buflen,
session->driver.aivdm.ais_channel ='B';
break;
case 'C':
- gpsd_report(&session->context->errout, LOG_INF,
- "ignoring AIS channel C (secure AIS).\n");
+ gpsd_log(&session->context->errout, LOG_INF,
+ "ignoring AIS channel C (secure AIS).\n");
return false;
default:
- gpsd_report(&session->context->errout, LOG_ERROR,
- "invalid AIS channel 0x%0X .\n", field[4][0]);
+ gpsd_log(&session->context->errout, LOG_ERROR,
+ "invalid AIS channel 0x%0X .\n", field[4][0]);
return false;
}
@@ -1279,17 +1283,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(&session->context->errout, LOG_PROG,
- "nfrags=%d, ifrag=%d, decoded_frags=%d, data=%s\n",
- nfrags, ifrag, ais_context->decoded_frags, data);
+ gpsd_log(&session->context->errout, 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(&session->context->errout, LOG_ERROR,
- "invalid fragment #%d received, expected #%d.\n",
- ifrag, ais_context->decoded_frags + 1);
+ gpsd_log(&session->context->errout, 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
@@ -1310,8 +1314,8 @@ static bool aivdm_decode(const char *buf, size_t buflen,
if (ch >= 40)
ch -= 8;
#ifdef __UNUSED_DEBUG__
- gpsd_report(&session->context->errout, LOG_RAW,
- "%c: %s\n", *cp, sixbits[ch]);
+ gpsd_log(&session->context->errout, LOG_RAW,
+ "%c: %s\n", *cp, sixbits[ch]);
#endif /* __UNUSED_DEBUG__ */
/*@ -shiftnegative @*/
for (i = 5; i >= 0; i--) {
@@ -1321,8 +1325,8 @@ static bool aivdm_decode(const char *buf, size_t buflen,
}
ais_context->bitlen++;
if (ais_context->bitlen > sizeof(ais_context->bits)) {
- gpsd_report(&session->context->errout, LOG_INF,
- "overlong AIVDM payload truncated.\n");
+ gpsd_log(&session->context->errout, LOG_INF,
+ "overlong AIVDM payload truncated.\n");
return false;
}
}
@@ -1336,10 +1340,10 @@ static bool aivdm_decode(const char *buf, size_t buflen,
if (ifrag == nfrags) {
if (debug >= LOG_INF) {
size_t clen = BITS_TO_BYTES(ais_context->bitlen);
- gpsd_report(&session->context->errout, LOG_INF,
- "AIVDM payload is %zd bits, %zd chars: %s\n",
- ais_context->bitlen, clen,
- gpsd_hexdump(session->msgbuf, sizeof(session->msgbuf),
+ gpsd_log(&session->context->errout, LOG_INF,
+ "AIVDM payload is %zd bits, %zd chars: %s\n",
+ ais_context->bitlen, clen,
+ gpsd_hexdump(session->msgbuf, sizeof(session->msgbuf),
(char *)ais_context->bits, clen));
}
@@ -1457,8 +1461,8 @@ static void path_rewrite(struct gps_device_t *session, char *prefix)
static gps_mask_t json_pass_packet(struct gps_device_t *session)
{
- gpsd_report(&session->context->errout, LOG_IO,
- "<= GPS: %s\n", (char *)session->lexer.outbuffer);
+ gpsd_log(&session->context->errout, LOG_IO,
+ "<= GPS: %s\n", (char *)session->lexer.outbuffer);
if (strstr(session->gpsdata.dev.path, ":/") != NULL && strstr(session->gpsdata.dev.path, "localhost") == NULL)
{
@@ -1485,9 +1489,9 @@ static gps_mask_t json_pass_packet(struct gps_device_t *session)
session->lexer.outbuflen = strlen((char *)session->lexer.outbuffer);
}
}
- gpsd_report(&session->context->errout, LOG_PROG,
- "JSON, passing through %s\n",
- (char *)session->lexer.outbuffer);
+ gpsd_log(&session->context->errout, LOG_PROG,
+ "JSON, passing through %s\n",
+ (char *)session->lexer.outbuffer);
/*@-nullpass@*/
return PASSTHROUGH_IS;
}