From: Kaj-Michael Lang Date: Tue, 29 Jan 2008 16:09:54 +0000 (+0200) Subject: Sanity check for the NMEA sentence we try to parse. X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=45c94211797fb2a63374d631f32055c5dcc4d0a8;p=mapper Sanity check for the NMEA sentence we try to parse. - define the used NMEA prefixes. - Don't blindly skip the common prefix, check the whole NMEA prefix. - Check that the sentence is long enough to make sense. --- diff --git a/src/gps-nmea-parse.c b/src/gps-nmea-parse.c index 810791a..05a7597 100644 --- a/src/gps-nmea-parse.c +++ b/src/gps-nmea-parse.c @@ -42,6 +42,12 @@ #define DELIM "," +#define NMEA_RMC "$GPRMC" +#define NMEA_GGA "$GPGGA" +#define NMEA_GSA "$GPGSA" +#define NMEA_GSV "$GPGSV" +#define NMEA_PRLEN (6) + static void gps_nmea_parse_rmc(Gps *gps, gchar *sentence) { @@ -367,18 +373,23 @@ gboolean gps_nmea_parse(Gps *gps) { g_assert(gps); -g_assert(gps->io.nmea); - -g_debug("%s(): %s", __PRETTY_FUNCTION__, gps->io.nmea); - -if (!strncmp(gps->io.nmea + 3, "GSV", 3)) { - gps_nmea_parse_gsv(gps, gps->io.nmea + 7); -} else if (!strncmp(gps->io.nmea + 3, "RMC", 3)) - gps_nmea_parse_rmc(gps, gps->io.nmea + 7); -else if (!strncmp(gps->io.nmea + 3, "GGA", 3)) - gps_nmea_parse_gga(gps, gps->io.nmea + 7); -else if (!strncmp(gps->io.nmea + 3, "GSA", 3)) - gps_nmea_parse_gsa(gps, gps->io.nmea + 7); + +g_debug("NMEA: %s", gps->io.nmea); + +if (!gps->io.nmea) + return FALSE; + +if (strlen(gps->io.nmea)io.nmea, NMEA_GSV, NMEA_PRLEN)) { + gps_nmea_parse_gsv(gps, gps->io.nmea + NMEA_PRLEN+1); +} else if (!strncmp(gps->io.nmea, NMEA_RMC, NMEA_PRLEN)) + gps_nmea_parse_rmc(gps, gps->io.nmea + NMEA_PRLEN+1); +else if (!strncmp(gps->io.nmea, NMEA_GGA, NMEA_PRLEN)) + gps_nmea_parse_gga(gps, gps->io.nmea + NMEA_PRLEN+1); +else if (!strncmp(gps->io.nmea, NMEA_GSA, NMEA_PRLEN)) + gps_nmea_parse_gsa(gps, gps->io.nmea + NMEA_PRLEN+1); else g_printerr("Unknown NMEA: [%s]\n", gps->io.nmea); g_free(gps->io.nmea); gps->io.nmea=NULL;