From a11329e1dc986a02710e258f588a93ad02e9ed9e Mon Sep 17 00:00:00 2001 From: Reinhard Arlt Date: Thu, 7 May 2015 16:36:38 +0200 Subject: Improve nmea2000 ais coding. --- driver_nmea2000.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'driver_nmea2000.c') diff --git a/driver_nmea2000.c b/driver_nmea2000.c index 5748d357..a56b7cd4 100644 --- a/driver_nmea2000.c +++ b/driver_nmea2000.c @@ -646,11 +646,14 @@ static gps_mask_t hnd_129794(unsigned char *bu, int len, PGN *pgn, struct gps_de ais->type5.dte = (unsigned int) ((bu[73] >> 6) & 0x01); for (l=0,cpy_stop=0;l<7;l++) { - if (((char) bu[9+l] < ' ') || ((char) bu[9+l] > 0x7e)) { + char next; + + next = (char) bu[9+l]; + if ((next < ' ') || (next > 0x7e)) { cpy_stop = 1; } if (cpy_stop == 0) { - ais->type5.callsign[l] = (char) bu[9+l]; + ais->type5.callsign[l] = next; } else { ais->type5.callsign[l] = 0; } @@ -658,11 +661,14 @@ static gps_mask_t hnd_129794(unsigned char *bu, int len, PGN *pgn, struct gps_de ais->type5.callsign[7] = (char) 0; for (l=0,cpy_stop=0;l 0x7e)) { + char next; + + next = (char) bu[16+l]; + if ((next < ' ') || (next > 0x7e)) { cpy_stop = 1; } if (cpy_stop == 0) { - ais->type5.shipname[l] = (char) bu[16+l]; + ais->type5.shipname[l] = next; } else { ais->type5.shipname[l] = 0; } @@ -670,11 +676,14 @@ static gps_mask_t hnd_129794(unsigned char *bu, int len, PGN *pgn, struct gps_de ais->type5.shipname[AIS_SHIPNAME_MAXLEN] = (char) 0; for (l=0,cpy_stop=0;l<20;l++) { - if (((char) bu[53+l] < ' ') || ((char) bu[53+l] > 0x7e)) { + char next; + + next = (char) bu[53+l]; + if ((next < ' ') || (next > 0x7e)) { cpy_stop = 1; } if (cpy_stop == 0) { - ais->type5.destination[l] = (char) bu[53+l]; + ais->type5.destination[l] = next; } else { ais->type5.destination[l] = 0; } -- cgit v1.2.1