- for (AltosState state : states) {
- if (serial == AltosLib.MISSING && state.serial != AltosLib.MISSING)
- serial = state.serial;
- if (flight == AltosLib.MISSING && state.flight != AltosLib.MISSING)
- flight = state.flight;
- if (state.battery_voltage != AltosLib.MISSING)
- has_battery = true;
- if (state.main_voltage != AltosLib.MISSING)
- has_flight_adc = true;
- if (state.rssi != AltosLib.MISSING)
- has_rssi = true;
- end_time = state.time;
-
- if (state.pressure() != AltosLib.MISSING)
- has_flight_data = true;
-
- int state_id = state.state();
- if (state.time >= boost_time && state_id < AltosLib.ao_flight_boost)
- state_id = AltosLib.ao_flight_boost;
- if (state.time >= landed_time && state_id < AltosLib.ao_flight_landed)
- state_id = AltosLib.ao_flight_landed;
- if (state.gps != null && state.gps.locked) {
- year = state.gps.year;
- month = state.gps.month;
- day = state.gps.day;
- hour = state.gps.hour;
- minute = state.gps.minute;
- second = state.gps.second;
+
+ for (int s = 0; s < AltosLib.ao_flight_invalid + 1; s++)
+ state_speed[s] = state_accel[s] = state_start[s] = state_end[s] = AltosLib.MISSING;
+
+ if (series.state_series != null) {
+ for (AltosTimeValue state : series.state_series) {
+ int s = (int) state.value;
+
+ if (s < AltosLib.ao_flight_startup && AltosLib.ao_flight_landed < s)
+ continue;
+
+ if (s == AltosLib.ao_flight_boost)
+ state_start[s] = boost_time;
+ else
+ state_start[s] = series.state_series.time_of(s);
+
+ if (s == AltosLib.ao_flight_main)
+ state_end[s] = landed_time;
+ else
+ state_end[s] = series.state_series.time_of(s+1);
+
+ if (series.speed_series != null)
+ state_speed[s] = series.speed_series.average(state_start[s], state_end[s]);
+
+ if (series.accel_series != null)
+ state_accel[s] = series.accel_series.average(state_start[s], state_end[s]);