- AltosState new_state = null;
- double boost_time = -1;
- double start_time;
-
- year = month = day = -1;
- hour = minute = second = -1;
- serial = flight = -1;
- for (;;) {
- try {
- AltosRecord record = reader.read();
- if (record == null)
- break;
- if (serial < 0)
- serial = record.serial;
- if ((record.seen & AltosRecord.seen_flight) != 0 && flight < 0)
- flight = record.flight;
- new_state = new AltosState(record, state);
- if (state == null) {
- start_time = new_state.time;
+
+ for (AltosState s : states) {
+ state = s;
+ if (state.acceleration() < 1)
+ boost_time = state.time;
+ if (state.state >= AltosLib.ao_flight_boost && state.state <= AltosLib.ao_flight_landed)
+ 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;
+ has_imu = false;
+ has_mag = false;
+ has_orient = 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;
+
+ int state_id = state.state;
+ if (state.time >= boost_time && state_id < Altos.ao_flight_boost)
+ state_id = Altos.ao_flight_boost;
+ if (state.time >= landed_time && state_id < Altos.ao_flight_landed)
+ state_id = 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_id && state_id < Altos.ao_flight_invalid) {
+ double acceleration = state.acceleration();
+ double speed = state.speed();
+ if (acceleration != AltosLib.MISSING && speed != AltosLib.MISSING) {
+ state_accel[state_id] += acceleration;
+ state_speed[state_id] += speed;
+ state_count[state_id]++;