summaryrefslogtreecommitdiff
path: root/packet.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 /packet.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 'packet.c')
-rw-r--r--packet.c226
1 files changed, 113 insertions, 113 deletions
diff --git a/packet.c b/packet.c
index 08e58864..8c6bacde 100644
--- a/packet.c
+++ b/packet.c
@@ -202,11 +202,11 @@ static bool character_pushback(struct gps_lexer_t *lexer, unsigned int newstate)
if (lexer->errout.debug >= LOG_RAW + 2)
{
unsigned char c = *lexer->inbufptr;
- gpsd_report(&lexer->errout, LOG_RAW + 2,
- "%08ld: character '%c' [%02x] pushed back, state set to %s\n",
- lexer->char_counter,
- (isprint((int)c) ? c : '.'), c,
- state_table[lexer->state]);
+ gpsd_log(&lexer->errout, LOG_RAW + 2,
+ "%08ld: character '%c' [%02x] pushed back, state set to %s\n",
+ lexer->char_counter,
+ (isprint((int)c) ? c : '.'), c,
+ state_table[lexer->state]);
}
return false;
@@ -971,9 +971,9 @@ static bool nextstate(struct gps_lexer_t *lexer, unsigned char c)
n++)
csum ^= lexer->inbuffer[n];
if (csum != c) {
- gpsd_report(&lexer->errout, LOG_IO,
- "Navcom packet type 0x%hhx bad checksum 0x%hhx, expecting 0x%x\n",
- lexer->inbuffer[3], csum, c);
+ gpsd_log(&lexer->errout, LOG_IO,
+ "Navcom packet type 0x%hhx bad checksum 0x%hhx, expecting 0x%x\n",
+ lexer->inbuffer[3], csum, c);
lexer->state = GROUND_STATE;
break;
}
@@ -1057,16 +1057,16 @@ static bool nextstate(struct gps_lexer_t *lexer, unsigned char c)
short sum = getword(0) + getword(1) + getword(2) + getword(3);
sum *= -1;
if (sum != getword(4)) {
- gpsd_report(&lexer->errout, LOG_IO,
- "Zodiac Header checksum 0x%hx expecting 0x%hx\n",
- sum, getword(4));
+ gpsd_log(&lexer->errout, LOG_IO,
+ "Zodiac Header checksum 0x%hx expecting 0x%hx\n",
+ sum, getword(4));
lexer->state = GROUND_STATE;
break;
}
}
- gpsd_report(&lexer->errout, LOG_RAW + 1,
- "Zodiac header id=%hd len=%hd flags=%hx\n",
- getword(1), getword(2), getword(3));
+ gpsd_log(&lexer->errout, LOG_RAW + 1,
+ "Zodiac header id=%hd len=%hd flags=%hx\n",
+ getword(1), getword(2), getword(3));
#undef getword
if (lexer->length == 0) {
lexer->state = ZODIAC_RECOGNIZED;
@@ -1196,8 +1196,8 @@ static bool nextstate(struct gps_lexer_t *lexer, unsigned char c)
if ((c == '>') && (lexer->inbufptr[0] == '<') &&
(lexer->inbufptr[1] == '!')) {
lexer->state = ITALK_RECOGNIZED;
- gpsd_report(&lexer->errout, LOG_IO,
- "ITALK: trying to process runt packet\n");
+ gpsd_log(&lexer->errout, LOG_IO,
+ "ITALK: trying to process runt packet\n");
break;
} else if (--lexer->length == 0)
lexer->state = ITALK_DELIVERED;
@@ -1352,9 +1352,9 @@ static bool nextstate(struct gps_lexer_t *lexer, unsigned char c)
lexer->state = JSON_STRINGLITERAL;
lexer->json_after = JSON_END_ATTRIBUTE;
} else {
- gpsd_report(&lexer->errout, LOG_RAW + 2,
- "%08ld: missing attribute start after header\n",
- lexer->char_counter);
+ gpsd_log(&lexer->errout, LOG_RAW + 2,
+ "%08ld: missing attribute start after header\n",
+ lexer->char_counter);
lexer->state = GROUND_STATE;
}
break;
@@ -1444,17 +1444,17 @@ static void packet_accept(struct gps_lexer_t *lexer, int packet_type)
lexer->type = packet_type;
if (lexer->errout.debug >= LOG_RAW+1) {
char scratchbuf[MAX_PACKET_LENGTH*2+1];
- gpsd_report(&lexer->errout, LOG_RAW+1,
- "Packet type %d accepted %zu = %s\n",
- packet_type, packetlen,
- gpsd_packetdump(scratchbuf, sizeof(scratchbuf),
- (char *)lexer->outbuffer,
- lexer->outbuflen));
+ gpsd_log(&lexer->errout, LOG_RAW+1,
+ "Packet type %d accepted %zu = %s\n",
+ packet_type, packetlen,
+ gpsd_packetdump(scratchbuf, sizeof(scratchbuf),
+ (char *)lexer->outbuffer,
+ lexer->outbuflen));
}
} else {
- gpsd_report(&lexer->errout, LOG_ERROR,
- "Rejected too long packet type %d len %zu\n",
- packet_type, packetlen);
+ gpsd_log(&lexer->errout, LOG_ERROR,
+ "Rejected too long packet type %d len %zu\n",
+ packet_type, packetlen);
}
}
@@ -1467,10 +1467,10 @@ static void packet_discard(struct gps_lexer_t *lexer)
lexer->inbuflen = remaining;
if (lexer->errout.debug >= LOG_RAW+1) {
char scratchbuf[MAX_PACKET_LENGTH*2+1];
- gpsd_report(&lexer->errout, LOG_RAW + 1,
- "Packet discard of %zu, chars remaining is %zu = %s\n",
- discard, remaining,
- gpsd_packetdump(scratchbuf, sizeof(scratchbuf),
+ gpsd_log(&lexer->errout, LOG_RAW + 1,
+ "Packet discard of %zu, chars remaining is %zu = %s\n",
+ discard, remaining,
+ gpsd_packetdump(scratchbuf, sizeof(scratchbuf),
(char *)lexer->inbuffer, lexer->inbuflen));
}
}
@@ -1482,10 +1482,10 @@ static void character_discard(struct gps_lexer_t *lexer)
lexer->inbufptr = lexer->inbuffer;
if (lexer->errout.debug >= LOG_RAW+1) {
char scratchbuf[MAX_PACKET_LENGTH*2+1];
- gpsd_report(&lexer->errout, LOG_RAW + 1,
- "Character discarded, buffer %zu chars = %s\n",
- lexer->inbuflen,
- gpsd_packetdump(scratchbuf, sizeof(scratchbuf),
+ gpsd_log(&lexer->errout, LOG_RAW + 1,
+ "Character discarded, buffer %zu chars = %s\n",
+ lexer->inbuflen,
+ gpsd_packetdump(scratchbuf, sizeof(scratchbuf),
(char *)lexer->inbuffer, lexer->inbuflen));
}
}
@@ -1520,10 +1520,10 @@ void packet_parse(struct gps_lexer_t *lexer)
unsigned int oldstate = lexer->state;
if (!nextstate(lexer, c))
continue;
- gpsd_report(&lexer->errout, LOG_RAW + 2,
- "%08ld: character '%c' [%02x], %s -> %s\n",
- lexer->char_counter, (isprint(c) ? c : '.'), c,
- state_table[oldstate], state_table[lexer->state]);
+ gpsd_log(&lexer->errout, LOG_RAW + 2,
+ "%08ld: character '%c' [%02x], %s -> %s\n",
+ lexer->char_counter, (isprint(c) ? c : '.'), c,
+ state_table[oldstate], state_table[lexer->state]);
lexer->char_counter++;
if (lexer->state == GROUND_STATE) {
@@ -1562,9 +1562,9 @@ void packet_parse(struct gps_lexer_t *lexer)
&& csum[1] == toupper((unsigned char) end[2]));
}
if (!checksum_ok) {
- gpsd_report(&lexer->errout, LOG_WARN,
- "bad checksum in NMEA packet; expected %s.\n",
- csum);
+ gpsd_log(&lexer->errout, LOG_WARN,
+ "bad checksum in NMEA packet; expected %s.\n",
+ csum);
packet_accept(lexer, BAD_PACKET);
lexer->state = GROUND_STATE;
packet_discard(lexer);
@@ -1615,14 +1615,14 @@ void packet_parse(struct gps_lexer_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(&lexer->errout, LOG_IO,
- "SuperStarII pkt dump: type %u len %u\n",
- lexer->inbuffer[1], (unsigned int)lexer->length);
+ gpsd_log(&lexer->errout, LOG_IO,
+ "SuperStarII pkt dump: type %u len %u\n",
+ lexer->inbuffer[1], (unsigned int)lexer->length);
if (a != b) {
- gpsd_report(&lexer->errout, LOG_IO,
- "REJECT SuperStarII packet type 0x%02x"
- "%zd bad checksum 0x%04x, expecting 0x%04x\n",
- lexer->inbuffer[1], lexer->length, a, b);
+ gpsd_log(&lexer->errout, 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);
lexer->state = GROUND_STATE;
} else {
@@ -1643,14 +1643,14 @@ void packet_parse(struct gps_lexer_t *lexer)
for (i = 2; i < len - 3; i++)
b ^= lexer->inbuffer[i];
if (a == b) {
- gpsd_report(&lexer->errout, LOG_IO,
- "Accept OnCore packet @@%c%c len %d\n",
- lexer->inbuffer[2], lexer->inbuffer[3], len);
+ gpsd_log(&lexer->errout, 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(&lexer->errout, LOG_IO,
- "REJECT OnCore packet @@%c%c len %d\n",
- lexer->inbuffer[2], lexer->inbuffer[3], len);
+ gpsd_log(&lexer->errout, 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;
}
@@ -1671,8 +1671,8 @@ void packet_parse(struct gps_lexer_t *lexer)
if (dlecnt > 2) {
dlecnt -= 2;
dlecnt /= 2;
- gpsd_report(&lexer->errout, LOG_RAW,
- "Unstuffed %d DLEs\n", dlecnt);
+ gpsd_log(&lexer->errout, LOG_RAW,
+ "Unstuffed %d DLEs\n", dlecnt);
packetlen -= dlecnt;
}
#endif /* TSIP_ENABLE */
@@ -1722,16 +1722,16 @@ void packet_parse(struct gps_lexer_t *lexer)
/*@ +charint */
chksum &= 0xff;
if (chksum) {
- gpsd_report(&lexer->errout, LOG_IO,
- "Garmin checksum failed: %02x!=0\n", chksum);
+ gpsd_log(&lexer->errout, LOG_IO,
+ "Garmin checksum failed: %02x!=0\n", chksum);
goto not_garmin;
}
packet_accept(lexer, GARMIN_PACKET);
packet_discard(lexer);
break;
not_garmin:;
- gpsd_report(&lexer->errout, LOG_RAW + 1,
- "Not a Garmin packet\n");
+ gpsd_log(&lexer->errout, LOG_RAW + 1,
+ "Not a Garmin packet\n");
#endif /* GARMIN_ENABLE */
#ifdef TSIP_ENABLE
/* check for some common TSIP packet types:
@@ -1781,9 +1781,9 @@ void packet_parse(struct gps_lexer_t *lexer)
(0xbc == pkt_id) ||
(0x38 == pkt_id))
&& ((0x41 > pkt_id) || (0x8f < pkt_id))) {
- gpsd_report(&lexer->errout, LOG_IO,
- "Packet ID 0x%02x out of range for TSIP\n",
- pkt_id);
+ gpsd_log(&lexer->errout, LOG_IO,
+ "Packet ID 0x%02x out of range for TSIP\n",
+ pkt_id);
goto not_tsip;
}
/* *INDENT-ON* */
@@ -1865,22 +1865,22 @@ void packet_parse(struct gps_lexer_t *lexer)
/* pass */ ;
else {
/* pass */ ;
- gpsd_report(&lexer->errout, LOG_IO,
- "TSIP REJECT pkt_id = %#02x, packetlen= %zu\n",
- pkt_id, packetlen);
+ gpsd_log(&lexer->errout, LOG_IO,
+ "TSIP REJECT pkt_id = %#02x, packetlen= %zu\n",
+ pkt_id, packetlen);
goto not_tsip;
}
#undef TSIP_ID_AND_LENGTH
/* Debug */
- gpsd_report(&lexer->errout, LOG_RAW,
- "TSIP pkt_id = %#02x, packetlen= %zu\n",
- pkt_id, packetlen);
+ gpsd_log(&lexer->errout, LOG_RAW,
+ "TSIP pkt_id = %#02x, packetlen= %zu\n",
+ pkt_id, packetlen);
/*@ -charint +ifempty @*/
packet_accept(lexer, TSIP_PACKET);
packet_discard(lexer);
break;
not_tsip:
- gpsd_report(&lexer->errout, LOG_RAW + 1, "Not a TSIP packet\n");
+ gpsd_log(&lexer->errout, LOG_RAW + 1, "Not a TSIP packet\n");
/*
* More attempts to recognize ambiguous TSIP-like
* packet types could go here.
@@ -1899,13 +1899,13 @@ void packet_parse(struct gps_lexer_t *lexer)
lexer->inbufptr - lexer->inbuffer)) {
packet_accept(lexer, RTCM3_PACKET);
} else {
- gpsd_report(&lexer->errout, LOG_IO,
- "RTCM3 data checksum failure, "
- "%0x against %02x %02x %02x\n",
- crc24q_hash(lexer->inbuffer,
- lexer->inbufptr - lexer->inbuffer -
- 3), lexer->inbufptr[-3],
- lexer->inbufptr[-2], lexer->inbufptr[-1]);
+ gpsd_log(&lexer->errout, LOG_IO,
+ "RTCM3 data checksum failure, "
+ "%0x against %02x %02x %02x\n",
+ crc24q_hash(lexer->inbuffer,
+ lexer->inbufptr - lexer->inbuffer -
+ 3), lexer->inbufptr[-3],
+ lexer->inbufptr[-2], lexer->inbufptr[-1]);
packet_accept(lexer, BAD_PACKET);
}
packet_discard(lexer);
@@ -1923,9 +1923,9 @@ void packet_parse(struct gps_lexer_t *lexer)
if (len == 0 || sum == getword(5 + len)) {
packet_accept(lexer, ZODIAC_PACKET);
} else {
- gpsd_report(&lexer->errout, LOG_IO,
- "Zodiac data checksum 0x%hx over length %hd, expecting 0x%hx\n",
- sum, len, getword(5 + len));
+ gpsd_log(&lexer->errout, LOG_IO,
+ "Zodiac data checksum 0x%hx over length %hd, expecting 0x%hx\n",
+ sum, len, getword(5 + len));
packet_accept(lexer, BAD_PACKET);
lexer->state = GROUND_STATE;
}
@@ -1940,7 +1940,7 @@ void packet_parse(struct gps_lexer_t *lexer)
unsigned char ck_a = (unsigned char)0;
unsigned char ck_b = (unsigned char)0;
len = lexer->inbufptr - lexer->inbuffer;
- gpsd_report(&lexer->errout, LOG_IO, "UBX: len %d\n", len);
+ gpsd_log(&lexer->errout, LOG_IO, "UBX: len %d\n", len);
for (n = 2; n < (len - 2); n++) {
ck_a += lexer->inbuffer[n];
ck_b += ck_a;
@@ -1949,15 +1949,15 @@ void packet_parse(struct gps_lexer_t *lexer)
ck_b == lexer->inbuffer[len - 1])
packet_accept(lexer, UBX_PACKET);
else {
- gpsd_report(&lexer->errout, LOG_IO,
- "UBX checksum 0x%02hhx%02hhx over length %d,"
- " expecting 0x%02hhx%02hhx (type 0x%02hhx%02hhx)\n",
- ck_a,
- ck_b,
- len,
- lexer->inbuffer[len - 2],
- lexer->inbuffer[len - 1],
- lexer->inbuffer[2], lexer->inbuffer[3]);
+ gpsd_log(&lexer->errout, LOG_IO,
+ "UBX checksum 0x%02hhx%02hhx over length %d,"
+ " expecting 0x%02hhx%02hhx (type 0x%02hhx%02hhx)\n",
+ ck_a,
+ ck_b,
+ len,
+ lexer->inbuffer[len - 2],
+ lexer->inbuffer[len - 1],
+ lexer->inbuffer[2], lexer->inbuffer[3]);
packet_accept(lexer, BAD_PACKET);
lexer->state = GROUND_STATE;
}
@@ -2000,9 +2000,9 @@ void packet_parse(struct gps_lexer_t *lexer)
goto not_evermore;
crc &= 0xff;
if (crc != checksum) {
- gpsd_report(&lexer->errout, LOG_IO,
- "EverMore checksum failed: %02x != %02x\n",
- crc, checksum);
+ gpsd_log(&lexer->errout, LOG_IO,
+ "EverMore checksum failed: %02x != %02x\n",
+ crc, checksum);
goto not_evermore;
}
/*@ +charint */
@@ -2042,10 +2042,10 @@ void packet_parse(struct gps_lexer_t *lexer)
if (len == 0 || csum == xsum)
packet_accept(lexer, ITALK_PACKET);
else {
- gpsd_report(&lexer->errout, LOG_IO,
- "ITALK: checksum failed - "
- "type 0x%02x expected 0x%04x got 0x%04x\n",
- lexer->inbuffer[4], xsum, csum);
+ gpsd_log(&lexer->errout, LOG_IO,
+ "ITALK: checksum failed - "
+ "type 0x%02x expected 0x%04x got 0x%04x\n",
+ lexer->inbuffer[4], xsum, csum);
packet_accept(lexer, BAD_PACKET);
lexer->state = GROUND_STATE;
}
@@ -2078,9 +2078,9 @@ void packet_parse(struct gps_lexer_t *lexer)
if (cs == 0)
packet_accept(lexer, GEOSTAR_PACKET);
else {
- gpsd_report(&lexer->errout, LOG_IO,
- "GeoStar checksum failed 0x%x over length %d\n",
- cs, len);
+ gpsd_log(&lexer->errout, LOG_IO,
+ "GeoStar checksum failed 0x%x over length %d\n",
+ cs, len);
packet_accept(lexer, BAD_PACKET);
lexer->state = GROUND_STATE;
}
@@ -2143,28 +2143,28 @@ ssize_t packet_get(int fd, struct gps_lexer_t *lexer)
/*@ +modobserver @*/
if (recvd == -1) {
if ((errno == EAGAIN) || (errno == EINTR)) {
- gpsd_report(&lexer->errout, LOG_RAW + 2, "no bytes ready\n");
+ gpsd_log(&lexer->errout, LOG_RAW + 2, "no bytes ready\n");
recvd = 0;
/* fall through, input buffer may be nonempty */
} else {
- gpsd_report(&lexer->errout, LOG_RAW + 2,
- "errno: %s\n", strerror(errno));
+ gpsd_log(&lexer->errout, LOG_RAW + 2,
+ "errno: %s\n", strerror(errno));
return -1;
}
} else {
if (lexer->errout.debug >= LOG_RAW+1) {
char scratchbuf[MAX_PACKET_LENGTH*2+1];
- gpsd_report(&lexer->errout, LOG_RAW + 1,
- "Read %zd chars to buffer offset %zd (total %zd): %s\n",
- recvd, lexer->inbuflen, lexer->inbuflen + recvd,
- gpsd_packetdump(scratchbuf, sizeof(scratchbuf),
- (char *)lexer->inbufptr, (size_t) recvd));
+ gpsd_log(&lexer->errout, LOG_RAW + 1,
+ "Read %zd chars to buffer offset %zd (total %zd): %s\n",
+ recvd, lexer->inbuflen, lexer->inbuflen + recvd,
+ gpsd_packetdump(scratchbuf, sizeof(scratchbuf),
+ (char *)lexer->inbufptr, (size_t) recvd));
}
lexer->inbuflen += recvd;
}
- gpsd_report(&lexer->errout, LOG_SPIN,
- "packet_get() fd %d -> %zd (%d)\n",
- fd, recvd, errno);
+ gpsd_log(&lexer->errout, LOG_SPIN,
+ "packet_get() fd %d -> %zd (%d)\n",
+ fd, recvd, errno);
/*
* Bail out, indicating no more input, only if we just received