summaryrefslogtreecommitdiff
path: root/bits.h
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2005-07-18 04:11:06 +0000
committerEric S. Raymond <esr@thyrsus.com>2005-07-18 04:11:06 +0000
commit72349b076a2156fa6aed8daa1a2838f9f6c40a64 (patch)
treefac7461296b273c88b6deaaaa38e8bd080ba82b5 /bits.h
parentb69a184bbea4852fc2d6eae6cf0234b1eb5d8fa2 (diff)
downloadgpsd-72349b076a2156fa6aed8daa1a2838f9f6c40a64.tar.gz
Add little-endian macros to bits.h. More fixes for the DBUS problem.
Diffstat (limited to 'bits.h')
-rw-r--r--bits.h31
1 files changed, 27 insertions, 4 deletions
diff --git a/bits.h b/bits.h
index f6b89210..7e192db4 100644
--- a/bits.h
+++ b/bits.h
@@ -14,6 +14,8 @@
* Both 32- and 64-bit systems with gcc are OK with this set.
*/
+#ifndef BITS_H
+#define BITS_H
union int_float {
int32_t i;
float f;
@@ -23,6 +25,7 @@ union long_double {
int64_t l;
double d;
};
+#endif /* BITS_H */
#ifndef GET_ORIGIN
#define GET_ORIGIN 0
@@ -31,22 +34,42 @@ union long_double {
#define PUT_ORIGIN 0
#endif
-/* SiRF and most other GPS protocols use big-endian (network byte order) */
+/* these are independent of byte order */
#define getsb(buf, off) ((int8_t)buf[(off)-(GET_ORIGIN)])
#define getub(buf, off) ((u_int8_t)buf[(off)-(GET_ORIGIN)])
+#define putbyte(buf,off,b) {buf[(off)-(PUT_ORIGIN)] = (unsigned char)(b);}
+
+#ifdef LITTLE_ENDIAN_PROTOCOL
+
+#define getsw(buf, off) ((int16_t)(((u_int16_t)getub(buf, off+1) << 8) | (u_int16_t)getub(buf, off)))
+#define getuw(buf, off) ((u_int16_t)(((u_int16_t)getub(buf, off+1) << 8) | (u_int16_t)getub(buf, off)))
+#define getsl(buf, off) ((int32_t)(((u_int16_t)getuw(buf, off+2) << 16) | getuw(buf, off)))
+#define getul(buf, off) ((u_int32_t)(((u_int16_t)getuw(buf, off+2) << 16) | getuw(buf, off)))
+
+#define putword(buf,off,w) {putbyte(buf,off+1,(w) >> 8); putbyte(buf,off,w);}
+#define putlong(buf,off,l) {putword(buf,off+2,(l) >> 16); putword(buf,off,l);}
+#define getsL(buf, off) ((int64_t)(((u_int64_t)getul(buf, off+4) << 32) | getul(buf, off)))
+#define getuL(buf, off) ((u_int64_t)(((u_int64_t)getul(buf, off+4) << 32) | getul(buf, off)))
+
+#else
+
+/* SiRF and most other GPS protocols use big-endian (network byte order) */
#define getsw(buf, off) ((int16_t)(((u_int16_t)getub(buf, off) << 8) | (u_int16_t)getub(buf, off+1)))
#define getuw(buf, off) ((u_int16_t)(((u_int16_t)getub(buf, off) << 8) | (u_int16_t)getub(buf, off+1)))
#define getsl(buf, off) ((int32_t)(((u_int16_t)getuw(buf, off) << 16) | getuw(buf, off+2)))
#define getul(buf, off) ((u_int32_t)(((u_int16_t)getuw(buf, off) << 16) | getuw(buf, off+2)))
#define getsL(buf, off) ((int64_t)(((u_int64_t)getul(buf, off) << 32) | getul(buf, off+4)))
#define getuL(buf, off) ((u_int64_t)(((u_int64_t)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)
-#define putbyte(buf,off,b) {buf[(off)-(PUT_ORIGIN)] = (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);}
+#endif
+
+#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)
+
+
/* Zodiac protocol description uses 1-origin indexing by little-endian word */
#define getword(n) ( (session->outbuffer[2*(n)-2]) \
| (session->outbuffer[2*(n)-1] << 8))