summaryrefslogtreecommitdiff
path: root/bits.h
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2005-06-09 16:03:29 +0000
committerEric S. Raymond <esr@thyrsus.com>2005-06-09 16:03:29 +0000
commite0928086f3f5493a66cf34a966930188b23da8d8 (patch)
tree71b44e1292302e6a52e2bcb56c0c7d7aa4b020d9 /bits.h
parentf576bd91918508d5c3a3be1a1b60ed8e57047190 (diff)
downloadgpsd-e0928086f3f5493a66cf34a966930188b23da8d8.tar.gz
Make sirfmon use the bits macros.
Diffstat (limited to 'bits.h')
-rw-r--r--bits.h23
1 files changed, 18 insertions, 5 deletions
diff --git a/bits.h b/bits.h
index c38fa7e5..5554a3d7 100644
--- a/bits.h
+++ b/bits.h
@@ -1,8 +1,9 @@
/*
* bits.h - extract binary data from message buffer
- *
- * these macros extract bytes, words, longwords, floats or doubles from
+ * * These macros extract bytes, words, longwords, floats or doubles from
* a message that contains these items in MSB-first byte order.
+ * By defining the GET_ORIGIN and PUT_ORIGIN macros, it's possible to
+ * change the origin of the indexing.
*
* assumptions:
* char is 8 bits, short is 16 bits, int is 32 bits, long long is 64 bits,
@@ -13,7 +14,7 @@
* also, using such explicitly sized types usually causes warnings at many
* other places in a program (like when calling library routines). we will
* need to consider this again when we want to port to an architecture which
- * implements differently sized types. it looks like 64bit systems with
+ * implements differently sized types. Noth 32- and 64-bit systems with
* gcc are OK.
*/
@@ -27,8 +28,12 @@ union long_double {
double d;
};
-#define getsb(buf, off) ((char)buf[off])
-#define getub(buf, off) (buf[off])
+#ifndef GET_ORIGIN
+#define GET_ORIGIN 0
+#endif
+
+#define getsb(buf, off) ((char)buf[GET_ORIGIN+(off)])
+#define getub(buf, off) (buf[GET_ORIGIN+(off)])
#define getsw(buf, off) ((short)(((unsigned)getub(buf, off) << 8) | (unsigned)getub(buf, off+1)))
#define getuw(buf, off) ((unsigned short)(((unsigned)getub(buf, off) << 8) | (unsigned)getub(buf, off+1)))
#define getsl(buf, off) ((int)(((unsigned)getuw(buf, off) << 16) | getuw(buf, off+2)))
@@ -37,3 +42,11 @@ union long_double {
#define getuL(buf, off) ((unsigned long long)(((unsigned long long)getul(buf, off) << 32) | getul(buf, off+4)))
#define getf(buf, off) (i_f.i = getsl(buf, off), i_f.f)
#define getd(buf, off) (l_d.l = getsL(buf, off), l_d.d)
+
+#ifndef PUT_ORIGIN
+#define PUT_ORIGIN 0
+#endif
+
+#define putbyte(buf,off,b) {buf[PUT_ORIGIN+(off)] = (unsigned char)(b);}
+#define putword(buf,off,w) {putbyte(buf,off,(w) >> 8); putbyte(buf,off+1,w);}
+#define putlong(buf,off,l) {putword(buf,off,(l) >> 16); putword(buf,off+2,l);}