Add date to GPS data, captured from GPRMC packet.
[fw/altos] / ao-tools / lib / cc-telem.c
index f82ab961ef3e6de9ab31c5a22f10f43020c7c663..9a2f6155a4345ce12bd22e022a83a89dc590237f 100644 (file)
@@ -93,6 +93,13 @@ cc_telem_parse(const char *input_line, struct cc_telem *telem)
        cc_parse_string(telem->callsign, sizeof (telem->callsign), words[1]);
        cc_parse_int(&telem->serial, words[3]);
 
+       if (version >= 2) {
+               cc_parse_int(&telem->flight, words[5]);
+               words += 2;
+               nword -= 2;
+       } else
+               telem->flight = 0;
+
        cc_parse_int(&telem->rssi, words[5]);
        cc_parse_string(telem->state, sizeof (telem->state), words[9]);
        cc_parse_int(&telem->tick, words[10]);
@@ -120,6 +127,7 @@ cc_telem_parse(const char *input_line, struct cc_telem *telem)
        if (strcmp (words[36], "unlocked") == 0) {
                telem->gps.gps_connected = 1;
                telem->gps.gps_locked = 0;
+               telem->gps.gps_time.year = telem->gps.gps_time.month = telem->gps.gps_time.day = 0;
                telem->gps.gps_time.hour = telem->gps.gps_time.minute = telem->gps.gps_time.second = 0;
                telem->gps.lat = telem->gps.lon = 0;
                telem->gps.alt = 0;
@@ -127,6 +135,16 @@ cc_telem_parse(const char *input_line, struct cc_telem *telem)
        } else if (nword >= 40) {
                telem->gps.gps_locked = 1;
                telem->gps.gps_connected = 1;
+               if (version >= 2) {
+                       sscanf(words[36], "%d-%d-%d",
+                              &telem->gps.gps_time.year,
+                              &telem->gps.gps_time.month,
+                              &telem->gps.gps_time.day);
+                       words += 1;
+                       nword -= 1;
+               } else {
+                       telem->gps.gps_time.year = telem->gps.gps_time.month = telem->gps.gps_time.day = 0;
+               }
                sscanf(words[36], "%d:%d:%d", &telem->gps.gps_time.hour, &telem->gps.gps_time.minute, &telem->gps.gps_time.second);
                cc_parse_pos(&telem->gps.lat, words[37]);
                cc_parse_pos(&telem->gps.lon, words[38]);
@@ -135,6 +153,7 @@ cc_telem_parse(const char *input_line, struct cc_telem *telem)
        } else {
                telem->gps.gps_connected = 0;
                telem->gps.gps_locked = 0;
+               telem->gps.gps_time.year = telem->gps.gps_time.month = telem->gps.gps_time.day = 0;
                telem->gps.gps_time.hour = telem->gps.gps_time.minute = telem->gps.gps_time.second = 0;
                telem->gps.lat = telem->gps.lon = 0;
                telem->gps.alt = 0;