2 * Copyright © 2010 Keith Packard <keithp@keithp.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
24 public class AltosTelemetryIterable extends AltosRecordIterable {
25 LinkedList<AltosRecord> records;
27 public Iterator<AltosRecord> iterator () {
28 return records.iterator();
31 boolean has_gps = false;
32 boolean has_accel = false;
33 boolean has_ignite = false;
34 public boolean has_gps() { return has_gps; }
35 public boolean has_accel() { return has_accel; }
36 public boolean has_ignite() { return has_ignite; };
38 public AltosTelemetryIterable (FileInputStream input) {
39 boolean saw_boost = false;
43 AltosRecord previous = null;
44 records = new LinkedList<AltosRecord> ();
48 String line = AltosRecord.gets(input);
53 AltosRecord record = AltosTelemetry.parse(line, previous);
57 if (records.isEmpty()) {
58 current_tick = record.tick;
60 int tick = record.tick | (current_tick & ~ 0xffff);
61 if (tick < current_tick - 0x1000)
64 record.tick = current_tick;
66 if (!saw_boost && record.state >= Altos.ao_flight_boost)
69 boost_tick = record.tick;
71 if (record.accel != AltosRecord.MISSING)
73 if (record.gps != null)
75 if (record.main != AltosRecord.MISSING)
78 } catch (ParseException pe) {
79 System.out.printf("parse exception %s\n", pe.getMessage());
80 } catch (AltosCRCException ce) {
83 } catch (IOException io) {
84 System.out.printf("io exception\n");
87 /* adjust all tick counts to be relative to boost time */
88 for (AltosRecord r : this)
89 r.time = (r.tick - boost_tick) / 100.0;
93 } catch (IOException ie) {