From db69281bbd3c60b38b4fa489944492a7a8a739d6 Mon Sep 17 00:00:00 2001 From: Jon Schlueter Date: Tue, 5 Jan 2016 02:04:47 -0500 Subject: [aivdm] Refactor in aivdm_decode for pad make the pad local variable actually be number of bits of padding instead of the ASCII value of the number of bits of padding directly. No logic change --- drivers.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'drivers.c') diff --git a/drivers.c b/drivers.c index de5ce78c..dce33c4b 100644 --- a/drivers.c +++ b/drivers.c @@ -1185,7 +1185,7 @@ static bool aivdm_decode(const char *buf, size_t buflen, unsigned char *field[NMEA_MAX*2]; unsigned char fieldcopy[NMEA_MAX*2+1]; unsigned char *data, *cp; - unsigned char pad; + int pad; struct aivdm_context_t *ais_context; int i; @@ -1211,7 +1211,11 @@ static bool aivdm_decode(const char *buf, size_t buflen, field[nfields++] = (unsigned char *)buf; for (cp = fieldcopy; cp < fieldcopy + buflen; cp++) - if (*cp == (unsigned char)',') { + { + if ( + (*cp == (unsigned char)',') || + (*cp == (unsigned char)'*') + ) { *cp = '\0'; field[nfields++] = cp + 1; } @@ -1264,7 +1268,10 @@ static bool aivdm_decode(const char *buf, size_t buflen, nfrags = atoi((char *)field[1]); /* number of fragments to expect */ ifrag = atoi((char *)field[2]); /* fragment id */ data = field[5]; - pad = field[6][0]; /* number of padding bits */ + + pad = 0; + if(isdigit(field[6][0])) + pad = field[6][0] - '0'; /* number of padding bits ASCII encoded*/ gpsd_log(&session->context->errout, LOG_PROG, "nfrags=%d, ifrag=%d, decoded_frags=%d, data=%s\n", nfrags, ifrag, ais_context->decoded_frags, data); @@ -1311,8 +1318,7 @@ static bool aivdm_decode(const char *buf, size_t buflen, } } } - if (isdigit(pad)) - ais_context->bitlen -= (pad - '0'); /* ASCII assumption */ + ais_context->bitlen -= pad; /* time to pass buffered-up data to where it's actually processed? */ if (ifrag == nfrags) { -- cgit v1.2.1