2 * Copyright © 2013 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; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
19 package org.altusmetrum.altoslib_11;
25 class AltosEepromIterator implements Iterator<AltosState> {
27 Iterator<AltosEeprom> body;
31 public boolean hasNext() {
32 return !seen || body.hasNext();
35 public AltosState next() {
37 AltosState n = state.clone();
38 AltosEeprom e = body.next();
47 public void remove () {
50 public AltosEepromIterator(AltosState start, Iterator<AltosEeprom> body) {
57 public class AltosEepromFile extends AltosStateIterable {
59 AltosEepromIterable headers;
60 AltosEepromIterable body;
61 AltosEepromRecordSet set;
64 public void write_comments(PrintStream out) {
68 public void write(PrintStream out) {
73 public AltosEepromFile(Reader input) throws IOException {
74 set = new AltosEepromRecordSet(input);
78 public AltosEepromFile(FileInputStream input) {
79 headers = new AltosEepromIterable(AltosEepromHeader.read(input));
81 start = headers.state();
82 if (start.state() != AltosLib.ao_flight_stateless)
83 start.set_state(AltosLib.ao_flight_pad);
85 if (start.log_format == AltosLib.MISSING) {
86 if (start.product != null) {
87 if (start.product.startsWith("TeleMetrum"))
88 start.log_format = AltosLib.AO_LOG_FORMAT_FULL;
89 else if (start.product.startsWith("TeleMini"))
90 start.log_format = AltosLib.AO_LOG_FORMAT_TINY;
94 switch (start.log_format) {
95 case AltosLib.AO_LOG_FORMAT_FULL:
96 body = new AltosEepromIterable(AltosEepromTM.read(input));
98 case AltosLib.AO_LOG_FORMAT_TINY:
99 body = new AltosEepromIterable(AltosEepromTMini.read(input));
101 case AltosLib.AO_LOG_FORMAT_TELEMETRY:
102 case AltosLib.AO_LOG_FORMAT_TELESCIENCE:
103 case AltosLib.AO_LOG_FORMAT_TELEMEGA:
104 case AltosLib.AO_LOG_FORMAT_TELEMEGA_OLD:
105 body = new AltosEepromIterable(AltosEepromMega.read(input, start.log_format));
107 case AltosLib.AO_LOG_FORMAT_TELEMETRUM:
108 body = new AltosEepromIterable(AltosEepromMetrum2.read(input));
110 case AltosLib.AO_LOG_FORMAT_TELEMINI2:
111 case AltosLib.AO_LOG_FORMAT_TELEMINI3:
112 case AltosLib.AO_LOG_FORMAT_EASYMINI:
113 body = new AltosEepromIterable(AltosEepromMini.read(input));
115 case AltosLib.AO_LOG_FORMAT_TELEGPS:
116 body = new AltosEepromIterable(AltosEepromGPS.read(input));
118 case AltosLib.AO_LOG_FORMAT_TELEFIRETWO:
119 body = new AltosEepromIterable(AltosEepromFireTwo.read(input));
122 body = new AltosEepromIterable(new LinkedList<AltosEeprom>());
126 /* Find boost tick */
127 AltosState state = start.clone();
128 for (AltosEeprom eeprom : body) {
129 eeprom.update_state(state);
130 state.finish_update();
131 if (state.state() >= AltosLib.ao_flight_boost) {
132 start.set_boost_tick(state.tick);
138 public Iterator<AltosState> iterator() {
140 return set.iterator();
142 AltosState state = start.clone();
143 Iterator<AltosEeprom> i = body.iterator();
145 while (i.hasNext() && !state.valid()) {
146 i.next().update_state(state);
147 state.finish_update();
149 return new AltosEepromIterator(state, i);