summaryrefslogtreecommitdiff
path: root/rtcm3.c
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2008-07-16 22:42:11 +0000
committerEric S. Raymond <esr@thyrsus.com>2008-07-16 22:42:11 +0000
commit4ca672e113bd7ab6c106c41d53b10a4828228b4a (patch)
treecbb7a3fc813135f5d2e7ac2d22a113888d60b6f8 /rtcm3.c
parent70c598e28e5cabe3694dcc4a894838a14a7cde15 (diff)
downloadgpsd-4ca672e113bd7ab6c106c41d53b10a4828228b4a.tar.gz
Factor out the bitfield functions, fix a bug in one, add tests.
Diffstat (limited to 'rtcm3.c')
-rw-r--r--rtcm3.c38
1 files changed, 2 insertions, 36 deletions
diff --git a/rtcm3.c b/rtcm3.c
index a1a4376c..f271cc5f 100644
--- a/rtcm3.c
+++ b/rtcm3.c
@@ -51,40 +51,6 @@ firmware.
/* Other magic values */
#define INVALID_PSEUDORANGE 0x80000 /* DF012 */
-static unsigned long long ufld(char buf[], unsigned int start, unsigned int width)
-/* extract a bitfield from the buffer as an unsigned big-endian long */
-{
- unsigned long long fld = 0;
- unsigned int i;;
-
- assert(width <= 64);
- for (i = 0; i < (width + 7) / 8; i++) {
- fld <<= 8;
- fld |= (unsigned char)buf[start / 8 + i];
- }
- //printf("Extracting %d:%d from %s: segment 0x%llx = %lld\n", start, width, gpsd_hexdump(buf, 12), fld, fld);
-
- fld &= (0xffffffff >> (start % 8));
- //printf("After masking: 0x%llx = %lld\n", fld, fld);
- fld >>= (start + width) % 8;
-
- return fld;
-}
-
-static signed long long sfld(char buf[], unsigned int start, unsigned int width)
-/* extract a bitfield from the buffer as a signed big-endian long */
-{
- unsigned long long un = ufld(buf, start, width);
- signed long long fld;
-
- if (un & (1 << width))
- fld = -(un & ~(1 << width));
- else
- fld = (signed long long)un;
-
- return fld;
-}
-
void rtcm3_unpack(/*@out@*/struct rtcm3_t *rtcm, char *buf)
/* break out the raw bits into the scaled report-structure fields */
{
@@ -93,8 +59,8 @@ void rtcm3_unpack(/*@out@*/struct rtcm3_t *rtcm, char *buf)
signed long temp;
/*@ -evalorder -sefparams @*/
-#define ugrab(width) (bitcount += width, ufld(buf, bitcount-width, width))
-#define sgrab(width) (bitcount += width, sfld(buf, bitcount-width, width))
+#define ugrab(width) (bitcount += width, ubits(buf, bitcount-width, width))
+#define sgrab(width) (bitcount += width, sbits(buf, bitcount-width, width))
assert(ugrab(8) == 0xD3);
assert(ugrab(6) == 0x00);