ugps: add quality measurement parameters
[project/ugps.git] / nmea.c
diff --git a/nmea.c b/nmea.c
index d51d936d2e69bcae34804a93d23d7f8df165c230..195753e80773d5feb940d7080fd8c3851ecf184c 100644 (file)
--- a/nmea.c
+++ b/nmea.c
@@ -52,8 +52,9 @@ struct nmea_param {
 } nmea_params[MAX_NMEA_PARAM];
 
 static int nmea_bad_time;
-char longitude[33] = { 0 }, latitude[33] = { 0 }, course[17] = { 0 }, speed[17] = { 0 }, elevation[17] = { 0 };
+char longitude[33] = { 0 }, latitude[33] = { 0 }, course[17] = { 0 }, speed[17] = { 0 }, elevation[17] = { 0 }, satellites[3] = { 0 }, hdop[5] = { 0 };
 int gps_valid = 0;
+char gps_fields = 0;
 
 static void
 nmea_txt_cb(void)
@@ -119,6 +120,8 @@ parse_gps_coords(char *latstr, char *vhem, char *lonstr, char *hhem)
        snprintf(longitude, sizeof(longitude), "%f", lon);
 
        DEBUG(3, "position: %s %s\n", latitude, longitude);
+       gps_fields |= GPS_FIELD_LAT | GPS_FIELD_LON;
+
        gps_timestamp();
 }
 
@@ -219,7 +222,12 @@ nmea_gga_cb(void)
 {
        if (!gps_valid)
                return;
+       strncpy(satellites, nmea_params[7].str, sizeof(satellites));
+       strncpy(hdop, nmea_params[8].str, sizeof(hdop));
        strncpy(elevation, nmea_params[9].str, sizeof(elevation));
+       gps_fields |= GPS_FIELD_SAT | GPS_FIELD_HDP | GPS_FIELD_ALT;
+       DEBUG(4, "satellites: %s\n", satellites);
+       DEBUG(4, "HDOP: %s\n", hdop);
        DEBUG(4, "height: %s\n", elevation);
 }
 
@@ -230,6 +238,7 @@ nmea_vtg_cb(void)
                return;
        strncpy(course, nmea_params[1].str, sizeof(course));
        strncpy(speed, nmea_params[7].str, sizeof(speed));
+       gps_fields |= GPS_FIELD_COG | GPS_FIELD_SPD;
        DEBUG(4, "course: %s\n", course);
        DEBUG(4, "speed: %s\n", speed);
 }
@@ -311,7 +320,8 @@ nmea_process(char *a)
        int cnt;
        unsigned int i;
 
-       if (strncmp(a, "$GP", 3))
+       if (strncmp(a, "$GP", 3) &&
+           strncmp(a, "$GN", 3))
                return;
 
        a++;
@@ -331,7 +341,8 @@ nmea_process(char *a)
        }
 
        for (i = 0; i < ARRAY_SIZE(nmea_msgs); i++) {
-               if (strcmp(nmea_params[0].str, nmea_msgs[i].msg))
+               if (strcmp(nmea_params[0].str, nmea_msgs[i].msg) &&
+                   strcmp(nmea_params[3].str, nmea_msgs[i].msg))
                        continue;
                if (nmea_msgs[i].cnt <= cnt)
                        nmea_msgs[i].handler();