summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2014-09-12 00:11:29 -0400
committerEric S. Raymond <esr@thyrsus.com>2014-09-12 00:11:29 -0400
commit51b6b93201b1e955fe0310b569ded0514c50b0d5 (patch)
tree15b5c3a3f63ef52cc0d85dbc5b06a0d27f0a9d4c
parent3748ed40b6784b1905492e70b33b5d7ce296fa08 (diff)
downloadgpsd-51b6b93201b1e955fe0310b569ded0514c50b0d5.tar.gz
Magic-number elimination. All regression tests pass.
-rw-r--r--drivers.c2
-rw-r--r--gpsd_json.c15
-rw-r--r--gpsdecode.c11
3 files changed, 15 insertions, 13 deletions
diff --git a/drivers.c b/drivers.c
index aad00ed5..5537553a 100644
--- a/drivers.c
+++ b/drivers.c
@@ -1333,7 +1333,7 @@ static bool aivdm_decode(const char *buf, size_t buflen,
/* time to pass buffered-up data to where it's actually processed? */
if (ifrag == nfrags) {
if (debug >= LOG_INF) {
- size_t clen = (ais_context->bitlen + 7) / 8;
+ size_t clen = BITS_TO_BYTES(ais_context->bitlen);
gpsd_report(&session->context->errout, LOG_INF,
"AIVDM payload is %zd bits, %zd chars: %s\n",
ais_context->bitlen, clen,
diff --git a/gpsd_json.c b/gpsd_json.c
index 24913557..eaf206ba 100644
--- a/gpsd_json.c
+++ b/gpsd_json.c
@@ -21,6 +21,7 @@ PERMISSIONS
#include <ctype.h>
#include "gpsd.h"
+#include "bits.h"
#ifdef SOCKET_EXPORT_ENABLE
#include "gps_json.h"
@@ -1880,8 +1881,8 @@ void json_aivdm_dump(const struct ais_t *ais,
ais->type6.bitcount,
json_stringify(buf1, sizeof(buf1),
gpsd_hexdump(scratchbuf, sizeof(scratchbuf),
- (char *)ais->type6.bitdata,
- (ais->type6.bitcount + 7) / 8)));
+ (char *)ais->type6.bitdata,
+ BITS_TO_BYTES(ais->type6.bitcount))));
break;
}
if (ais->type6.dac == 200) {
@@ -2226,7 +2227,7 @@ void json_aivdm_dump(const struct ais_t *ais,
json_stringify(buf1, sizeof(buf1),
gpsd_hexdump(scratchbuf, sizeof(scratchbuf),
(char *)ais->type8.bitdata,
- (ais->type8.bitcount + 7) / 8)));
+ BITS_TO_BYTES(ais->type8.bitcount))));
break;
}
if (ais->type8.dac == 1) {
@@ -3007,7 +3008,7 @@ void json_aivdm_dump(const struct ais_t *ais,
ais->type17.bitcount,
gpsd_hexdump(scratchbuf, sizeof(scratchbuf),
(char *)ais->type17.bitdata,
- (ais->type17.bitcount + 7) / 8));
+ BITS_TO_BYTES(ais->type17.bitcount)));
} else {
(void)snprintf(buf + strlen(buf), buflen - strlen(buf),
"\"lon\":%d,\"lat\":%d,\"data\":\"%zd:%s\"}\r\n",
@@ -3016,7 +3017,7 @@ void json_aivdm_dump(const struct ais_t *ais,
ais->type17.bitcount,
gpsd_hexdump(scratchbuf, sizeof(scratchbuf),
(char *)ais->type17.bitdata,
- (ais->type17.bitcount + 7) / 8));
+ BITS_TO_BYTES(ais->type17.bitcount)));
}
break;
case 18:
@@ -3343,7 +3344,7 @@ void json_aivdm_dump(const struct ais_t *ais,
ais->type25.bitcount,
gpsd_hexdump(scratchbuf, sizeof(scratchbuf),
(char *)ais->type25.bitdata,
- (ais->type25.bitcount + 7) / 8));
+ BITS_TO_BYTES(ais->type25.bitcount)));
break;
case 26: /* Binary Message, Multiple Slot */
(void)snprintf(buf + strlen(buf), buflen - strlen(buf),
@@ -3356,7 +3357,7 @@ void json_aivdm_dump(const struct ais_t *ais,
ais->type26.bitcount,
gpsd_hexdump(scratchbuf, sizeof(scratchbuf),
(char *)ais->type26.bitdata,
- (ais->type26.bitcount + 7) / 8),
+ BITS_TO_BYTES(ais->type26.bitcount)),
ais->type26.radio);
break;
case 27: /* Long Range AIS Broadcast message */
diff --git a/gpsdecode.c b/gpsdecode.c
index 02558ab0..507d7ba4 100644
--- a/gpsdecode.c
+++ b/gpsdecode.c
@@ -12,6 +12,7 @@
#endif /* S_SPLINT_S */
#include "gpsd.h"
+#include "bits.h"
#include "gps_json.h"
static int verbose = 0;
@@ -124,7 +125,7 @@ static void aivdm_csv_dump(struct ais_t *ais, char *buf, size_t buflen)
ais->type6.bitcount,
gpsd_hexdump(scratchbuf, sizeof(scratchbuf),
ais->type6.bitdata,
- (ais->type6.bitcount + 7) / 8));
+ BITS_TO_BYTES(ais->type6.bitcount)));
break;
case 7: /* Binary Acknowledge */
case 13: /* Safety Related Acknowledge */
@@ -232,7 +233,7 @@ static void aivdm_csv_dump(struct ais_t *ais, char *buf, size_t buflen)
ais->type8.bitcount,
gpsd_hexdump(scratchbuf, sizeof(scratchbuf),
ais->type8.bitdata,
- (ais->type8.bitcount + 7) / 8));
+ BITS_TO_BYTES(ais->type8.bitcount)));
break;
case 9:
(void)snprintf(buf + strlen(buf), buflen - strlen(buf),
@@ -291,7 +292,7 @@ static void aivdm_csv_dump(struct ais_t *ais, char *buf, size_t buflen)
ais->type17.bitcount,
gpsd_hexdump(scratchbuf, sizeof(scratchbuf),
ais->type17.bitdata,
- (ais->type17.bitcount + 7) / 8));
+ BITS_TO_BYTES(ais->type17.bitcount)));
break;
case 18:
(void)snprintf(buf + strlen(buf), buflen - strlen(buf),
@@ -447,7 +448,7 @@ static void aivdm_csv_dump(struct ais_t *ais, char *buf, size_t buflen)
ais->type25.bitcount,
gpsd_hexdump(scratchbuf, sizeof(scratchbuf),
ais->type25.bitdata,
- (ais->type25.bitcount + 7) / 8));
+ BITS_TO_BYTES(ais->type25.bitcount)));
break;
case 26: /* Binary Message, Multiple Slot */
(void)snprintf(buf + strlen(buf), buflen - strlen(buf),
@@ -459,7 +460,7 @@ static void aivdm_csv_dump(struct ais_t *ais, char *buf, size_t buflen)
ais->type26.bitcount,
gpsd_hexdump(scratchbuf, sizeof(scratchbuf),
ais->type26.bitdata,
- (ais->type26.bitcount + 7) / 8),
+ BITS_TO_BYTES(ais->type26.bitcount)),
ais->type26.radio);
break;
case 27: /* Long Range AIS Broadcast message */