summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2012-06-20 09:00:33 -0400
committerEric S. Raymond <esr@thyrsus.com>2012-06-20 09:10:28 -0400
commit7f5851d906449063c6cc653e7967549e861a2fea (patch)
treed69483f350637411f556eb18f94e50c2ba0b0296
parent6f34d11aae04a9a9d47c3a4f6af3d5a55774b53e (diff)
downloadgpsd-7f5851d906449063c6cc653e7967549e861a2fea.tar.gz
Split gpsd_hexdump() so AIS dumping will be invertible.
-rw-r--r--gpsd.h-tail1
-rw-r--r--hex.c47
-rw-r--r--libgpsd_core.c4
-rw-r--r--packet.c8
-rw-r--r--serial.c2
5 files changed, 34 insertions, 28 deletions
diff --git a/gpsd.h-tail b/gpsd.h-tail
index d11795b6..49ced0c6 100644
--- a/gpsd.h-tail
+++ b/gpsd.h-tail
@@ -723,6 +723,7 @@ extern gps_mask_t gpsd_interpret_subframe(struct gps_device_t *, unsigned int,
extern gps_mask_t gpsd_interpret_subframe_raw(struct gps_device_t *,
unsigned int, uint32_t[]);
extern /*@ observer @*/ const char *gpsd_hexdump(/*@null@*/char *, size_t);
+extern /*@ observer @*/ const char *gpsd_packetdump(/*@null@*/char *, size_t);
# ifdef __cplusplus
extern "C" {
# endif
diff --git a/hex.c b/hex.c
index ef67f06b..c4130a66 100644
--- a/hex.c
+++ b/hex.c
@@ -8,7 +8,7 @@
#include "gpsd.h"
-const char /*@ observer @*/ *gpsd_hexdump(char *binbuf, size_t binbuflen)
+const char /*@ observer @*/ *gpsd_packetdump(char *binbuf, size_t binbuflen)
{
char *cp;
bool printable = true;
@@ -19,31 +19,36 @@ const char /*@ observer @*/ *gpsd_hexdump(char *binbuf, size_t binbuflen)
printable = false;
if (printable)
return binbuf;
- else {
- static char hexbuf[MAX_PACKET_LENGTH * 2 + 1];
+ else
+ return gpsd_hexdump(binbuf, binbuflen);
+}
+
+const char /*@ observer @*/ *gpsd_hexdump(char *binbuf, size_t binbuflen)
+{
+ /* FIXME: this isn't thead-safe! */
+ static char hexbuf[MAX_PACKET_LENGTH * 2 + 1];
#ifndef SQUELCH_ENABLE
- size_t i, j = 0;
- size_t len =
- (size_t) ((binbuflen >
- MAX_PACKET_LENGTH) ? MAX_PACKET_LENGTH : binbuflen);
- const char *ibuf = (const char *)binbuf;
- const char *hexchar = "0123456789abcdef";
+ size_t i, j = 0;
+ size_t len =
+ (size_t) ((binbuflen >
+ MAX_PACKET_LENGTH) ? MAX_PACKET_LENGTH : binbuflen);
+ const char *ibuf = (const char *)binbuf;
+ const char *hexchar = "0123456789abcdef";
- if (NULL == binbuf || 0 == binbuflen)
- return "";
+ if (NULL == binbuf || 0 == binbuflen)
+ return "";
- /*@ -shiftimplementation @*/
- for (i = 0; i < len; i++) {
- hexbuf[j++] = hexchar[(ibuf[i] & 0xf0) >> 4];
- hexbuf[j++] = hexchar[ibuf[i] & 0x0f];
- }
- /*@ +shiftimplementation @*/
- hexbuf[j] = '\0';
+ /*@ -shiftimplementation @*/
+ for (i = 0; i < len; i++) {
+ hexbuf[j++] = hexchar[(ibuf[i] & 0xf0) >> 4];
+ hexbuf[j++] = hexchar[ibuf[i] & 0x0f];
+ }
+ /*@ +shiftimplementation @*/
+ hexbuf[j] = '\0';
#else /* SQUELCH defined */
- hexbuf[0] = '\0';
+ hexbuf[0] = '\0';
#endif /* SQUELCH_ENABLE */
- return hexbuf;
- }
+ return hexbuf;
}
/*@ +charint -shiftimplementation @*/
diff --git a/libgpsd_core.c b/libgpsd_core.c
index 6140a694..c7747435 100644
--- a/libgpsd_core.c
+++ b/libgpsd_core.c
@@ -1007,14 +1007,14 @@ gps_mask_t gpsd_poll(struct gps_device_t *session)
/*
* The guard looks superfluous, but it keeps the rather expensive
- * gpsd_hexdump() function from being called even when the debug
+ * gpsd_packetdump() function from being called even when the debug
* level does not actually require it.
*/
if (session->context->debug >= LOG_RAW)
gpsd_report(LOG_RAW, "raw packet of type %d, %zd:%s\n",
session->packet.type,
session->packet.outbuflen,
- gpsd_hexdump((char *)session->packet.outbuffer, session->packet.outbuflen));
+ gpsd_packetdump((char *)session->packet.outbuffer, session->packet.outbuflen));
/* Get data from current packet into the fix structure */
if (session->packet.type != COMMENT_PACKET)
diff --git a/packet.c b/packet.c
index 3a1ffd11..a946af34 100644
--- a/packet.c
+++ b/packet.c
@@ -1362,7 +1362,7 @@ static void packet_accept(struct gps_packet_t *lexer, int packet_type)
if (lexer->debug >= LOG_RAW+1)
gpsd_report(LOG_RAW+1, "Packet type %d accepted %zu = %s\n",
packet_type, packetlen,
- gpsd_hexdump((char *)lexer->outbuffer, lexer->outbuflen));
+ gpsd_packetdump((char *)lexer->outbuffer, lexer->outbuflen));
} else {
gpsd_report(LOG_ERROR, "Rejected too long packet type %d len %zu\n",
packet_type, packetlen);
@@ -1380,7 +1380,7 @@ static void packet_discard(struct gps_packet_t *lexer)
gpsd_report(LOG_RAW + 1,
"Packet discard of %zu, chars remaining is %zu = %s\n",
discard, remaining,
- gpsd_hexdump((char *)lexer->inbuffer, lexer->inbuflen));
+ gpsd_packetdump((char *)lexer->inbuffer, lexer->inbuflen));
}
static void character_discard(struct gps_packet_t *lexer)
@@ -1391,7 +1391,7 @@ static void character_discard(struct gps_packet_t *lexer)
if (lexer->debug >= LOG_RAW+1)
gpsd_report(LOG_RAW + 1, "Character discarded, buffer %zu chars = %s\n",
lexer->inbuflen,
- gpsd_hexdump((char *)lexer->inbuffer, lexer->inbuflen));
+ gpsd_packetdump((char *)lexer->inbuffer, lexer->inbuflen));
}
/* get 0-origin big-endian words relative to start of packet buffer */
@@ -2019,7 +2019,7 @@ ssize_t packet_get(int fd, struct gps_packet_t *lexer)
gpsd_report(LOG_RAW + 1,
"Read %zd chars to buffer offset %zd (total %zd): %s\n",
recvd, lexer->inbuflen, lexer->inbuflen + recvd,
- gpsd_hexdump((char *)lexer->inbufptr, (size_t) recvd));
+ gpsd_packetdump((char *)lexer->inbufptr, (size_t) recvd));
lexer->inbuflen += recvd;
}
gpsd_report(LOG_SPIN, "packet_get() fd %d -> %zd (%d)\n",
diff --git a/serial.c b/serial.c
index 851ebf36..c5eaa4d9 100644
--- a/serial.c
+++ b/serial.c
@@ -507,7 +507,7 @@ ssize_t gpsd_write(struct gps_device_t * session, const char *buf, size_t len)
/* extra guard prevents expensive hexdump calls */
if (session->context->debug >= LOG_IO)
gpsd_report(LOG_IO, "=> GPS: %s%s\n",
- gpsd_hexdump((char *)buf, len), ok ? "" : " FAILED");
+ gpsd_packetdump((char *)buf, len), ok ? "" : " FAILED");
return status;
}