]> err.no Git - mapper/blobdiff - src/gps-nmea-parse.c
Move some variables around
[mapper] / src / gps-nmea-parse.c
index dee16731c73215f5a4cdc85e1d58a76fe15957d2..96bcbe373d4acbfc59c264f61da5a2ed0cd2979c 100644 (file)
 #include <math.h>
 #include <errno.h>
 #include <glib/gstdio.h>
-#include <gtk/gtk.h>
 #include <fcntl.h>
-#include <libxml/parser.h>
 
 #include "utils.h"
 #include "gps.h"
-#include "mapper-types.h"
-#include "ui-common.h"
-#include "map.h"
-#include "track.h"
-#include "route.h"
-#include "gps-panels.h"
-#include "settings.h"
-#include "gps-conn.h"
-#include "gtkgps.h"
-#include "gtkcompass.h"
+#include "gps-nmea-parse.h"
+
+#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_rmc(Gps *gps, gchar *sentence)
 {
        /* Recommended Minimum Navigation Information C
         *  1) UTC Time
@@ -73,9 +70,7 @@ gps_nmea_parse_rmc(Gps *gps, gchar * sentence)
        gdouble tmpd = 0.f;
        guint tmpi = 0;
        gboolean newly_fixed = FALSE;
-       vprintf("%s(): %s\n", __PRETTY_FUNCTION__, sentence);
-
-#define DELIM ","
+       g_debug("%s(): %s", __PRETTY_FUNCTION__, sentence);
 
        /* Parse time. */
        token = strsep(&sentence, DELIM);
@@ -87,14 +82,16 @@ gps_nmea_parse_rmc(Gps *gps, gchar * sentence)
        if (token && *token == 'A') {
                /* Data is valid. */
                if (gps->io.conn != RCVR_FIXED) {
-                       newly_fixed = TRUE;
+                       gps->data.newly_fixed = TRUE;
                        gps_conn_set_state(gps, RCVR_FIXED);
+               } else {
+                       gps->data.newly_fixed = FALSE;
                }
        } else {
                /* Data is invalid - not enough satellites?. */
                if (gps->io.conn != RCVR_UP) {
                        gps_conn_set_state(gps, RCVR_UP);
-                       track_add(NULL, FALSE);
+                       /* track_add(NULL, FALSE); */
                }
        }
 
@@ -155,20 +152,12 @@ gps_nmea_parse_rmc(Gps *gps, gchar * sentence)
                strcat(gpsdate, token);
                strptime(gpsdate, "%H%M%S%d%m%y", &time);
                gps->data.time = mktime(&time) + _gmtoffset;
-       } else
+       } else {
                gps->data.time = time(NULL);
-
-       /* Add new data to track only if we have a fix */
-       _track_store=TRUE;
+       }
 
        gps_data_integerize(&gps->data);
-       gps_display_data_speed(info_banner.speed, gps->data.speed);
-
-       if ((gps->io.conn==RCVR_FIXED) && (_track_store==TRUE) && filter_check(&filter, &gps->data, &map_loc)==TRUE) {
-               track_add(&_gps->data, newly_fixed);
-               gps->data.lheading=gps->data.heading;
-               map_refresh_mark();
-       }
+       gps->data.lheading=gps->data.heading;
 }
 
 static void
@@ -201,9 +190,7 @@ gps_nmea_parse_gga(Gps *gps, gchar * sentence)
           15. the checksum data
         */
        gchar *token;
-       vprintf("%s(): %s\n", __PRETTY_FUNCTION__, sentence);
-
-#define DELIM ","
+       g_debug("%s(): %s", __PRETTY_FUNCTION__, sentence);
 
        /* Skip Fix time */
        token = strsep(&sentence, DELIM);
@@ -256,8 +243,6 @@ gps_nmea_parse_gsa(Gps *gps, gchar * sentence)
 
        g_debug("%s(): %s\n", __PRETTY_FUNCTION__, sentence);
 
-#define DELIM ","
-
        /* Skip Auto selection. */
        token = strsep(&sentence, DELIM);
 
@@ -372,40 +357,52 @@ gps_nmea_parse_gsv(Gps *gps, gchar * sentence)
                        if (gps->io.conn==RCVR_UP) {
                                gdouble fraction = running_total * sqrt(num_sats_used) / num_sats_used / 100.0;
                                BOUND(fraction, 0.0, 1.0);
-                               gps_conn_set_progress(gps, fraction);
+                               if (gps->connection_progress!=NULL)
+                                       gps->connection_progress(gps, fraction);
                        }
                        running_total=0;
                        num_sats_used=0;
                }
                satcnt = 0;
-
-               /* Keep awake while they watch the progress bar. */
-               KEEP_DISPLAY_ON();
        }
 }
 
 gboolean
-gps_nmea_parse(gchar *data)
+gps_nmea_parse(Gps *gps)
 {
-Gps *gps=_gps;
-
-if (!strncmp(data + 3, "GSV", 3)) {
-       if (gps->io.conn==RCVR_UP)
-               gps_nmea_parse_gsv(gps, data + 7);
-} else if (!strncmp(data + 3, "RMC", 3))
-       gps_nmea_parse_rmc(gps, data + 7);
-else if (!strncmp(data + 3, "GGA", 3))
-       gps_nmea_parse_gga(gps, data + 7);
-else if (!strncmp(data + 3, "GSA", 3))
-       gps_nmea_parse_gsa(gps, data + 7);
-else g_debug("Unknown NMEA: [%s]\n", data);
-g_free(data);
-
-if (_gps_info)
-       gps_display_data(&gps->data);
-
-if (_satdetails_on)
-       gps_display_details(&gps->data);
+g_assert(gps);
+
+g_debug("NMEA2 %d %s", gps->io.nmea_cnt, 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);
+       if (gps->update_satellite)
+               g_idle_add_full(G_PRIORITY_DEFAULT, (GSourceFunc)gps->update_satellite, gps, NULL);
+
+} else if (!strncmp(gps->io.nmea, NMEA_RMC, NMEA_PRLEN)) {
+       gps_nmea_parse_rmc(gps, gps->io.nmea + NMEA_PRLEN+1);
+       if ((gps->io.conn==RCVR_FIXED) && (gps->update_location!=NULL))
+               gps->update_location(gps);
+
+} else if (!strncmp(gps->io.nmea, NMEA_GGA, NMEA_PRLEN)) {
+       gps_nmea_parse_gga(gps, gps->io.nmea + NMEA_PRLEN+1);
+       if (gps->update_info)
+               g_idle_add_full(G_PRIORITY_DEFAULT, (GSourceFunc)gps->update_info, gps, NULL);
+
+} else if (!strncmp(gps->io.nmea, NMEA_GSA, NMEA_PRLEN)) {
+       gps_nmea_parse_gsa(gps, gps->io.nmea + NMEA_PRLEN+1);
+       if (gps->update_satellite)
+               g_idle_add_full(G_PRIORITY_DEFAULT, (GSourceFunc)gps->update_satellite, gps, NULL);
+       if (gps->update_info)
+               g_idle_add_full(G_PRIORITY_DEFAULT, (GSourceFunc)gps->update_info, gps, NULL);
+
+} else g_printerr("Unknown NMEA: [%s]\n", gps->io.nmea);
 
 return FALSE;
 }