Add M command to monitor serial bytes
[fw/altos] / aoview / aoview_state.c
index 8b43ec2993c87559c95f786e057b8f702229755f..a0a608e0b8804851bdf0efa720fabb78ac6eed51 100644 (file)
@@ -110,6 +110,7 @@ aoview_state_derive(struct aodata *data, struct aostate *state)
        state->report_time = aoview_time();
 
        state->prev_data = state->data;
+       state->prev_npad = state->npad;
        state->data = *data;
        tick_count = data->tick;
        if (tick_count < state->prev_data.tick)
@@ -129,14 +130,20 @@ aoview_state_derive(struct aodata *data, struct aostate *state)
        state->main_sense = data->main / 32767.0 * 15.0;
        state->battery = data->batt / 32767.0 * 5.0;
        if (!strcmp(data->state, "pad")) {
-               if (data->locked && data->nsat > 4) {
+               if (data->gps_locked && data->nsat >= 4) {
                        state->npad++;
                        state->pad_lat_total += data->lat;
                        state->pad_lon_total += data->lon;
                        state->pad_alt_total += data->alt;
-                       state->pad_lat = state->pad_lat_total / state->npad;
-                       state->pad_lon = state->pad_lon_total / state->npad;
-                       state->pad_alt = state->pad_alt_total / state->npad;
+                       if (state->npad > 1) {
+                               state->pad_lat = (state->pad_lat * 31 + data->lat) / 32.0;
+                               state->pad_lon = (state->pad_lon * 31 + data->lon) / 32.0;
+                               state->pad_alt = (state->pad_alt * 31 + data->alt) / 32.0;
+                       } else {
+                               state->pad_lat = data->lat;
+                               state->pad_lon = data->lon;
+                               state->pad_alt = data->alt;
+                       }
                }
        }
        state->ascent = FALSE;
@@ -152,7 +159,7 @@ aoview_state_derive(struct aodata *data, struct aostate *state)
 
        if (state->height > state->max_height)
                state->max_height = state->height;
-       if (data->locked) {
+       if (data->gps_locked) {
                state->lat = data->lat;
                state->lon = data->lon;
                aoview_great_circle(state->pad_lat, state->pad_lon, data->lat, data->lon,
@@ -178,6 +185,8 @@ aoview_speak_state(struct aostate *state)
                        aoview_voice_speak("max speed %d meters per second\n",
                                           (int) state->max_speed);
        }
+       if (state->prev_npad < MIN_PAD_SAMPLES && state->npad >= MIN_PAD_SAMPLES)
+               aoview_voice_speak("g p s ready\n");
 }
 
 void
@@ -287,7 +296,7 @@ aoview_state_notify(struct aodata *data)
        aoview_table_add_row(0, "Main", "%5.2fV", state->main_sense);
        aoview_table_add_row(0, "Pad altitude", "%dm", state->ground_altitude);
        aoview_table_add_row(1, "Satellites", "%d", state->data.nsat);
-       if (state->data.locked) {
+       if (state->data.gps_locked) {
                aoview_state_add_deg(1, "Latitude", state->data.lat, 'N', 'S');
                aoview_state_add_deg(1, "Longitude", state->data.lon, 'E', 'W');
                aoview_table_add_row(1, "GPS height", "%d", state->gps_height);
@@ -304,8 +313,10 @@ aoview_state_notify(struct aodata *data)
                                     state->data.hdop, state->data.h_error, state->data.v_error);
                aoview_table_add_row(1, "Distance from pad", "%5.0fm", state->distance);
                aoview_table_add_row(1, "Direction from pad", "%4.0f°", state->bearing);
-       } else {
+       } else if (state->data.gps_connected) {
                aoview_table_add_row(1, "GPS", "unlocked");
+       } else {
+               aoview_table_add_row(1, "GPS", "not available");
        }
        if (state->npad) {
                aoview_state_add_deg(1, "Pad latitude", state->pad_lat, 'N', 'S');