]> err.no Git - mapper/commitdiff
Parse rest of NMEA in an idle cb
authorKaj-Michael Lang <milang@onion.tal.org>
Wed, 2 Jan 2008 14:03:27 +0000 (16:03 +0200)
committerKaj-Michael Lang <milang@onion.tal.org>
Wed, 2 Jan 2008 14:03:27 +0000 (16:03 +0200)
src/gps-nmea-parse.c

index e1c3f74502500fdc55790003cfa124ae4640a802..012226a6bb356a9ff5d6d1d962b3c8b0bc35283e 100644 (file)
@@ -73,7 +73,7 @@ if (_conn_state > RCVR_OFF) {
 return FALSE;
 }
 
-static void 
+static void
 channel_parse_rmc(gchar * sentence)
 {
        /* Recommended Minimum Navigation Information C
@@ -187,7 +187,7 @@ channel_parse_rmc(gchar * sentence)
        /* XXX: Set filter logic somewhere else */
 
        if ((_conn_state == RCVR_FIXED) && (_track_store==TRUE)) {
-               if ((_gps_filter==TRUE) && (track_drop_cnt<GPS_FILTER_MAX_SKIP)) {
+               if ((_gps_filter==TRUE) && (track_drop_cnt<_filter_maxdrop)) {
                        integerize_data(&_gps, &_pos);
                        if ( (_gps.hdop<_filter_hdop || _filter_hdop==0.0) && 
                                (_gps.vdop<_filter_vdop || _filter_vdop==0.0) && 
@@ -214,11 +214,9 @@ channel_parse_rmc(gchar * sentence)
                        map_refresh_mark();
                }
        }
-
-       vprintf("%s(): return\n", __PRETTY_FUNCTION__);
 }
 
-static void 
+static void
 channel_parse_gga(gchar * sentence)
 {
        /* GGA          Global Positioning System Fix Data
@@ -282,11 +280,9 @@ channel_parse_gga(gchar * sentence)
                MACRO_PARSE_FLOAT(_pos.altitude, token);
        } else
                _pos.altitude = NAN;
-
-       vprintf("%s(): return\n", __PRETTY_FUNCTION__);
 }
 
-static void 
+static void
 channel_parse_gsa(gchar * sentence)
 {
        /* GPS DOP and active satellites
@@ -347,11 +343,9 @@ channel_parse_gsa(gchar * sentence)
        token = strsep(&sentence, DELIM);
        if (token && *token)
                MACRO_PARSE_FLOAT(_gps.vdop, token);
-
-       vprintf("%s(): return\n", __PRETTY_FUNCTION__);
 }
 
-static void 
+static void
 channel_parse_gsv(gchar * sentence)
 {
        /* Must be GSV - Satellites in view
@@ -433,8 +427,33 @@ channel_parse_gsv(gchar * sentence)
                /* Keep awake while they watch the progress bar. */
                KEEP_DISPLAY_ON();
        }
+}
+
+static gboolean
+channel_parse_buffer(gpointer data)
+{
+gchar *buf=(gchar *)data;
+
+if (!strncmp(buf + 3, "GSV", 3)) {
+       if (_conn_state == RCVR_UP)
+               channel_parse_gsv(buf + 7);
+} else if (!strncmp(buf + 3, "RMC", 3))
+       channel_parse_rmc(buf + 7);
+else if (!strncmp(buf + 3, "GGA", 3))
+       channel_parse_gga(buf + 7);
+else if (!strncmp(buf + 3, "GSA", 3))
+       channel_parse_gsa(buf + 7);
+else g_print("Unknown NMEA: [%s]\n", buf);
 
-       g_printf("%s(): return\n", __PRETTY_FUNCTION__);
+g_free(buf);
+
+if (_gps_info)
+       gps_display_data();
+
+if (_satdetails_on)
+       gps_display_details();
+
+return FALSE;
 }
 
 gboolean
@@ -464,24 +483,13 @@ switch (status) {
                        /* If we're at a \0 (meaning there is no checksum), or if the
                         * checksum is good, then parse the sentence. */
                        if (!*sptr || csum == strtol(sptr + 1, NULL, 16)) {
+                               gchar *data;
+
                                if (*sptr)
                                        *sptr = '\0';   /* take checksum out of the buffer. */
-                               if (!strncmp(_gps_read_buf + 3, "GSV", 3)) {
-                                       if (_conn_state == RCVR_UP)
-                                               channel_parse_gsv(_gps_read_buf + 7);
-                               } else if (!strncmp(_gps_read_buf + 3, "RMC", 3))
-                                       channel_parse_rmc(_gps_read_buf + 7);
-                               else if (!strncmp(_gps_read_buf + 3, "GGA", 3))
-                                       channel_parse_gga(_gps_read_buf + 7);
-                               else if (!strncmp(_gps_read_buf + 3, "GSA", 3))
-                                       channel_parse_gsa(_gps_read_buf + 7);
-                               else g_print("Unknown NMEA: [%s]\n", _gps_read_buf);
-
-                               if (_gps_info)
-                                       gps_display_data();
-
-                               if (_satdetails_on)
-                                       gps_display_details();
+
+                               data=g_strdup(_gps_read_buf);
+                               g_idle_add_full(G_PRIORITY_HIGH_IDLE, (GSourceFunc)channel_parse_buffer, data, NULL);
                        } else {
                                /* There was a checksum, and it was bad. */
                                g_printerr("%s: Bad checksum in NMEA sentence:\n%s\n", __PRETTY_FUNCTION__, _gps_read_buf);
@@ -510,6 +518,9 @@ switch (status) {
        case G_IO_STATUS_AGAIN:
                return TRUE;
        break;
+       default:
+               g_assert_not_reached();
+       break;
 }
 
 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);