#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)
{
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)<NMEA_PRLEN+1)
+ return FALSE;
+
+if (!strncmp(gps->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;