+ double boost_time(AltosStateIterable states) {
+ double boost_time = AltosLib.MISSING;
+ AltosState state = null;
+
+ for (AltosState s : states) {
+ state = s;
+ if (state.acceleration() < 1)
+ boost_time = state.time;
+ if (state.state >= Altos.ao_flight_boost)
+ break;
+ }
+ if (state == null)
+ return 0;
+
+ if (boost_time == AltosLib.MISSING)
+ boost_time = state.time;
+ return boost_time;
+ }
+
+
+ public AltosFlightStats(AltosStateIterable states) throws InterruptedException, IOException {
+ double boost_time = boost_time(states);
+ double end_time = 0;
+ double landed_time = landed_time(states);
+
+ year = month = day = AltosLib.MISSING;
+ hour = minute = second = AltosLib.MISSING;
+ serial = flight = AltosLib.MISSING;
+ lat = lon = AltosLib.MISSING;
+ has_gps = false;
+ has_other_adc = false;
+ has_rssi = false;
+ 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_other_adc = true;
+ if (state.rssi != AltosLib.MISSING)
+ has_rssi = true;
+ end_time = state.time;
+ if (state.time >= boost_time && state.state < Altos.ao_flight_boost)
+ state.state = Altos.ao_flight_boost;
+ if (state.time >= landed_time && state.state < Altos.ao_flight_landed)
+ state.state = Altos.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;
+ }
+ if (0 <= state.state && state.state < Altos.ao_flight_invalid) {
+ state_accel[state.state] += state.acceleration();
+ state_speed[state.state] += state.speed();
+ state_count[state.state]++;
+ if (state_start[state.state] == 0.0)
+ state_start[state.state] = state.time;
+ if (state_end[state.state] < state.time)
+ state_end[state.state] = state.time;
+ max_height = state.max_height();
+ max_speed = state.max_speed();
+ max_acceleration = state.max_acceleration();
+ }
+ if (state.gps != null && state.gps.locked && state.gps.nsat >= 4) {
+ if (state.state <= Altos.ao_flight_pad) {
+ pad_lat = state.gps.lat;
+ pad_lon = state.gps.lon;
+ }
+ lat = state.gps.lat;
+ lon = state.gps.lon;
+ has_gps = true;