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.
18 package org.altusmetrum.AltosLib;
24 public class AltosTelemetryIterable extends AltosRecordIterable {
25 TreeSet<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 TreeSet<AltosRecord> ();
48 String line = AltosLib.gets(input);
53 AltosRecord record = AltosTelemetry.parse(line, previous);
56 if (records.isEmpty()) {
57 current_tick = record.tick;
59 int tick = record.tick;
60 while (tick < current_tick - 0x1000)
63 record.tick = current_tick;
65 if (!saw_boost && record.state >= AltosLib.ao_flight_boost)
68 boost_tick = record.tick;
70 if (record.acceleration() != AltosRecord.MISSING)
72 if (record.gps != null)
74 if (record.main_voltage() != AltosRecord.MISSING)
76 if (previous != null && previous.tick != record.tick)
77 records.add(previous);
79 } catch (ParseException pe) {
80 System.out.printf("parse exception %s\n", pe.getMessage());
81 } catch (AltosCRCException ce) {
84 } catch (IOException io) {
85 System.out.printf("io exception\n");
89 records.add(previous);
91 /* Adjust all tick counts to match expected eeprom values,
92 * which starts with a 16-bit tick count 16 samples before boost
95 int tick_adjust = (boost_tick - 16) & 0xffff0000;
96 for (AltosRecord r : this)
97 r.tick -= tick_adjust;
98 boost_tick -= tick_adjust;
100 /* adjust all tick counts to be relative to boost time */
101 for (AltosRecord r : this)
102 r.time = (r.tick - boost_tick) / 100.0;
106 } catch (IOException ie) {