summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2006-12-04 12:56:36 +0000
committerEric S. Raymond <esr@thyrsus.com>2006-12-04 12:56:36 +0000
commitfd02178983c99006a2bef5467c80730407881724 (patch)
tree7527443e868e314b013408e4463bd59301fad6e9
parent47d11ae5cd320e9dbc14d7a5185899d508ebb06b (diff)
downloadgpsd-fd02178983c99006a2bef5467c80730407881724.tar.gz
Break up some modules a little finer, in support of some Python bindings.
All regression tests pass. No logic changes.
-rw-r--r--Makefile.am3
-rw-r--r--hex.c76
-rw-r--r--libgpsd_core.c67
-rw-r--r--strl.c2
4 files changed, 79 insertions, 69 deletions
diff --git a/Makefile.am b/Makefile.am
index fad9cc94..2f2e7f54 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -135,7 +135,8 @@ libgps_c_sources = \
timebase.h \
bsd-base64.c \
bsd-base64.h \
- strl.c
+ strl.c \
+ hex.c
BUILT_SOURCES = packet_names.h
packet_names.h: packet_states.h
diff --git a/hex.c b/hex.c
new file mode 100644
index 00000000..48e9ad3e
--- /dev/null
+++ b/hex.c
@@ -0,0 +1,76 @@
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <math.h>
+#include <string.h>
+
+#include "gpsd_config.h"
+#include "gpsd.h"
+
+char /*@ observer @*/ *gpsd_hexdump(const void *binbuf, size_t binbuflen)
+{
+ 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";
+
+ /*@ -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';
+#endif /* SQUELCH_ENABLE */
+ return hexbuf;
+}
+
+int gpsd_hexpack(char *src, char *dst, int len){
+ int i, k, l;
+
+ l = (int)(strlen(src) / 2);
+ if ((l < 1) || (l > len))
+ return -1;
+
+ bzero(dst, len);
+ for (i = 0; i < l; i++)
+ if ((k = hex2bin(src+i*2)) != -1)
+ dst[i] = (char)(k & 0xff);
+ else
+ return -1;
+ return l;
+}
+
+/*@ +charint -shiftimplementation @*/
+int hex2bin(char *s)
+{
+ int a, b;
+
+ a = s[0] & 0xff;
+ b = s[1] & 0xff;
+
+ if ((a >= 'a') && (a <= 'z'))
+ a = a + 10 - 'a';
+ else if ((a >= 'A') && (a <= 'Z'))
+ a = a + 10 - 'A';
+ else if ((a >= '0') && (a <= '9'))
+ a -= '0';
+ else
+ return -1;
+
+ if ((b >= 'a') && (b <= 'z'))
+ b = b + 10 - 'a';
+ else if ((b >= 'A') && (b <= 'Z'))
+ b = b + 10 - 'A';
+ else if ((b >= '0') && (b <= '9'))
+ b -= '0';
+ else
+ return -1;
+
+ return ((a<<4) + b);
+}
+/*@ -charint +shiftimplementation @*/
diff --git a/libgpsd_core.c b/libgpsd_core.c
index 005408d3..f325909e 100644
--- a/libgpsd_core.c
+++ b/libgpsd_core.c
@@ -776,70 +776,3 @@ void gpsd_zero_satellites(/*@out@*/struct gps_data_t *out)
out->satellites = 0;
}
-char /*@ observer @*/ *gpsd_hexdump(const void *binbuf, size_t binbuflen)
-{
- 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";
-
- /*@ -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';
-#endif /* SQUELCH_ENABLE */
- return hexbuf;
-}
-
-int gpsd_hexpack(char *src, char *dst, int len){
- int i, k, l;
-
- l = (int)(strlen(src) / 2);
- if ((l < 1) || (l > len))
- return -1;
-
- bzero(dst, len);
- for (i = 0; i < l; i++)
- if ((k = hex2bin(src+i*2)) != -1)
- dst[i] = (char)(k & 0xff);
- else
- return -1;
- return l;
-}
-
-/*@ +charint -shiftimplementation @*/
-int hex2bin(char *s)
-{
- int a, b;
-
- a = s[0] & 0xff;
- b = s[1] & 0xff;
-
- if ((a >= 'a') && (a <= 'z'))
- a = a + 10 - 'a';
- else if ((a >= 'A') && (a <= 'Z'))
- a = a + 10 - 'A';
- else if ((a >= '0') && (a <= '9'))
- a -= '0';
- else
- return -1;
-
- if ((b >= 'a') && (b <= 'z'))
- b = b + 10 - 'a';
- else if ((b >= 'A') && (b <= 'Z'))
- b = b + 10 - 'A';
- else if ((b >= '0') && (b <= '9'))
- b -= '0';
- else
- return -1;
-
- return ((a<<4) + b);
-}
-/*@ -charint +shiftimplementation @*/
diff --git a/strl.c b/strl.c
index 41a4c7b3..48dce9ce 100644
--- a/strl.c
+++ b/strl.c
@@ -2,7 +2,7 @@
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
-#include <gpsd_config.h>
+#include "gpsd_config.h"
#ifndef HAVE_STRLCAT
/* $OpenBSD: strlcat.c,v 1.13 2005/08/08 08:05:37 espie Exp $ */