2 * Copyright © 2017 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.
15 package org.altusmetrum.altoslib_11;
20 public class AltosEepromRecordSet implements Iterable<AltosState>, AltosRecordSet {
21 AltosEepromNew eeprom;
22 TreeSet<AltosEepromRecord> ordered;
23 AltosState start_state;
25 class RecordIterator implements Iterator<AltosState> {
26 Iterator<AltosEepromRecord> riterator;
30 public boolean hasNext() {
31 return state == null || riterator.hasNext();
34 public AltosState next() {
36 state = start_state.clone();
38 state = state.clone();
39 AltosEepromRecord r = riterator.next();
40 r.update_state(state);
45 public RecordIterator() {
46 riterator = ordered.iterator();
51 public Iterator<AltosState> iterator() {
52 return new RecordIterator();
55 public void capture_series(AltosFlightSeries series) {
56 series.set_config_data(eeprom.config_data());
57 for (AltosEepromRecord record : ordered) {
58 record.update_state(series);
62 public AltosEepromRecordSet(AltosEepromNew eeprom) {
65 AltosConfigData config_data = eeprom.config_data();
67 AltosEepromRecord record = null;
69 switch (config_data.log_format) {
70 case AltosLib.AO_LOG_FORMAT_FULL:
71 record = new AltosEepromRecordFull(eeprom);
73 case AltosLib.AO_LOG_FORMAT_TINY:
74 record = new AltosEepromRecordTiny(eeprom);
76 case AltosLib.AO_LOG_FORMAT_TELEMETRY:
77 case AltosLib.AO_LOG_FORMAT_TELESCIENCE:
78 case AltosLib.AO_LOG_FORMAT_TELEMEGA:
79 case AltosLib.AO_LOG_FORMAT_TELEMEGA_OLD:
80 record = new AltosEepromRecordMega(eeprom);
82 case AltosLib.AO_LOG_FORMAT_TELEMETRUM:
83 record = new AltosEepromRecordMetrum(eeprom);
85 case AltosLib.AO_LOG_FORMAT_TELEMINI2:
86 case AltosLib.AO_LOG_FORMAT_TELEMINI3:
87 case AltosLib.AO_LOG_FORMAT_EASYMINI:
88 record = new AltosEepromRecordMini(eeprom);
90 case AltosLib.AO_LOG_FORMAT_TELEGPS:
91 record = new AltosEepromRecordGps(eeprom);
93 case AltosLib.AO_LOG_FORMAT_TELEFIRETWO:
94 record = new AltosEepromRecordFireTwo(eeprom);
99 System.out.printf("failed to parse log format %d\n", config_data.log_format);
102 ordered = new TreeSet<AltosEepromRecord>();
104 boolean first = true;
106 start_state = new AltosState();
107 start_state.set_config_data(record.eeprom.config_data());
110 int t = record.tick();
116 while (t < tick - 32767)
120 record.wide_tick = tick;
122 if (!record.hasNext())
124 record = record.next();
128 public AltosEepromRecordSet(Reader input) throws IOException {
129 this(new AltosEepromNew(input));