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;
63 public void write_comments(PrintStream out) {
67 public void write(PrintStream out) {
72 public AltosEepromFile(FileInputStream input) {
73 headers = new AltosEepromIterable(AltosEepromHeader.read(input));
75 start = headers.state();
76 if (start.state() != AltosLib.ao_flight_stateless)
77 start.set_state(AltosLib.ao_flight_pad);
79 if (start.log_format == AltosLib.MISSING) {
80 if (start.product != null) {
81 if (start.product.startsWith("TeleMetrum"))
82 start.log_format = AltosLib.AO_LOG_FORMAT_FULL;
83 else if (start.product.startsWith("TeleMini"))
84 start.log_format = AltosLib.AO_LOG_FORMAT_TINY;
88 switch (start.log_format) {
89 case AltosLib.AO_LOG_FORMAT_FULL:
90 body = new AltosEepromIterable(AltosEepromTM.read(input));
92 case AltosLib.AO_LOG_FORMAT_TINY:
93 body = new AltosEepromIterable(AltosEepromTMini.read(input));
95 case AltosLib.AO_LOG_FORMAT_TELEMETRY:
96 case AltosLib.AO_LOG_FORMAT_TELESCIENCE:
97 case AltosLib.AO_LOG_FORMAT_TELEMEGA:
98 case AltosLib.AO_LOG_FORMAT_TELEMEGA_OLD:
99 body = new AltosEepromIterable(AltosEepromMega.read(input, start.log_format));
101 case AltosLib.AO_LOG_FORMAT_TELEMETRUM:
102 body = new AltosEepromIterable(AltosEepromMetrum2.read(input));
104 case AltosLib.AO_LOG_FORMAT_TELEMINI2:
105 case AltosLib.AO_LOG_FORMAT_TELEMINI3:
106 case AltosLib.AO_LOG_FORMAT_EASYMINI:
107 body = new AltosEepromIterable(AltosEepromMini.read(input));
109 case AltosLib.AO_LOG_FORMAT_TELEGPS:
110 body = new AltosEepromIterable(AltosEepromGPS.read(input));
112 case AltosLib.AO_LOG_FORMAT_TELEFIRETWO:
113 body = new AltosEepromIterable(AltosEepromFireTwo.read(input));
116 body = new AltosEepromIterable(new LinkedList<AltosEeprom>());
120 /* Find boost tick */
121 AltosState state = start.clone();
122 for (AltosEeprom eeprom : body) {
123 eeprom.update_state(state);
124 state.finish_update();
125 if (state.state() >= AltosLib.ao_flight_boost) {
126 start.set_boost_tick(state.tick);
132 public Iterator<AltosState> iterator() {
133 AltosState state = start.clone();
134 Iterator<AltosEeprom> i = body.iterator();
136 while (i.hasNext() && !state.valid()) {
137 i.next().update_state(state);
138 state.finish_update();
140 return new AltosEepromIterator(state, i);