Share telemetry parsing code in cc library.
[fw/altos] / ao-tools / lib / cc-telem.c
index a6ac0313b03f173c49cf75859e0b05c9f3740f1b..f82ab961ef3e6de9ab31c5a22f10f43020c7c663 100644 (file)
@@ -62,7 +62,9 @@ int
 cc_telem_parse(const char *input_line, struct cc_telem *telem)
 {
        char *saveptr;
 cc_telem_parse(const char *input_line, struct cc_telem *telem)
 {
        char *saveptr;
-       char *words[PARSE_MAX_WORDS];
+       char *raw_words[PARSE_MAX_WORDS];
+       char **words;
+       int version = 0;
        int nword;
        char line_buf[8192], *line;
        int     tracking_pos;
        int nword;
        char line_buf[8192], *line;
        int     tracking_pos;
@@ -72,13 +74,20 @@ cc_telem_parse(const char *input_line, struct cc_telem *telem)
        line_buf[sizeof(line_buf) - 1] = '\0';
        line = line_buf;
        for (nword = 0; nword < PARSE_MAX_WORDS; nword++) {
        line_buf[sizeof(line_buf) - 1] = '\0';
        line = line_buf;
        for (nword = 0; nword < PARSE_MAX_WORDS; nword++) {
-               words[nword] = strtok_r(line, " \t\n", &saveptr);
+               raw_words[nword] = strtok_r(line, " \t\n", &saveptr);
                line = NULL;
                line = NULL;
-               if (words[nword] == NULL)
+               if (raw_words[nword] == NULL)
                        break;
        }
        if (nword < 36)
                return FALSE;
                        break;
        }
        if (nword < 36)
                return FALSE;
+       words = raw_words;
+       if (strcmp(words[0], "VERSION") == 0) {
+               cc_parse_int(&version, words[1]);
+               words += 2;
+               nword -= 2;
+       }
+
        if (strcmp(words[0], "CALL") != 0)
                return FALSE;
        cc_parse_string(telem->callsign, sizeof (telem->callsign), words[1]);
        if (strcmp(words[0], "CALL") != 0)
                return FALSE;
        cc_parse_string(telem->callsign, sizeof (telem->callsign), words[1]);
@@ -98,6 +107,15 @@ cc_telem_parse(const char *input_line, struct cc_telem *telem)
        cc_parse_int(&telem->flight_vel, words[28]);
        cc_parse_int(&telem->flight_pres, words[30]);
        cc_parse_int(&telem->ground_pres, words[32]);
        cc_parse_int(&telem->flight_vel, words[28]);
        cc_parse_int(&telem->flight_pres, words[30]);
        cc_parse_int(&telem->ground_pres, words[32]);
+       if (version >= 1) {
+               cc_parse_int(&telem->accel_plus_g, words[34]);
+               cc_parse_int(&telem->accel_minus_g, words[36]);
+               words += 4;
+               nword -= 4;
+       } else {
+               telem->accel_plus_g = telem->ground_accel;
+               telem->accel_minus_g = telem->ground_accel + 530;
+       }
        cc_parse_int(&telem->gps.nsat, words[34]);
        if (strcmp (words[36], "unlocked") == 0) {
                telem->gps.gps_connected = 1;
        cc_parse_int(&telem->gps.nsat, words[34]);
        if (strcmp (words[36], "unlocked") == 0) {
                telem->gps.gps_connected = 1;