+/*
+ * Fill out the derived data fields
+ */
+static void
+aoview_state_derive(struct aostate *state)
+{
+ int i;
+
+ state->ground_altitude = aoview_pres_to_altitude(state->ground_pres);
+ state->height = aoview_pres_to_altitude(state->flight_pres) - state->ground_altitude;
+ state->acceleration = (state->ground_accel - state->flight_accel) / 27.0;
+ state->speed = state->flight_vel / 2700.0;
+ state->temperature = ((state->temp / 32767.0 * 3.3) - 0.5) / 0.01;
+ state->drogue_sense = state->drogue / 32767.0 * 15.0;
+ state->main_sense = state->main / 32767.0 * 15.0;
+ state->battery = state->batt / 32767.0 * 5.0;
+ if (!strcmp(state->state, "pad")) {
+ if (state->locked) {
+ state->npad++;
+ state->pad_lat_total += state->lat;
+ state->pad_lon_total += state->lon;
+ state->pad_alt_total += state->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;
+ }
+ }
+ state->ascent = FALSE;
+ for (i = 0; ascent_states[i]; i++)
+ if (!strcmp(state->state, ascent_states[i]))
+ state->ascent = TRUE;
+
+ /* Only look at accelerometer data on the way up */
+ if (state->ascent && state->acceleration > state->max_acceleration)
+ state->max_acceleration = state->acceleration;
+ if (state->ascent && state->speed > state->max_speed)
+ state->max_speed = state->speed;
+
+ if (state->height > state->max_height)
+ state->max_height = state->height;
+ aoview_great_circle(state->pad_lat, state->pad_lon, state->lat, state->lon,
+ &state->distance, &state->bearing);
+}
+