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> {
21 TreeSet<AltosEepromRecord> ordered;
22 AltosState start_state;
24 class RecordIterator implements Iterator<AltosState> {
25 Iterator<AltosEepromRecord> riterator;
29 public boolean hasNext() {
30 return state == null || riterator.hasNext();
33 public AltosState next() {
35 state = start_state.clone();
37 state = state.clone();
38 AltosEepromRecord r = riterator.next();
39 r.update_state(state);
44 public RecordIterator() {
45 riterator = ordered.iterator();
50 public Iterator<AltosState> iterator() {
51 return new RecordIterator();
54 public AltosEepromRecordSet(AltosEepromNew eeprom) {
55 AltosConfigData config_data = eeprom.config_data();
57 AltosEepromRecord record = null;
59 switch (config_data.log_format) {
60 case AltosLib.AO_LOG_FORMAT_FULL:
61 record = new AltosEepromRecordFull(eeprom);
63 case AltosLib.AO_LOG_FORMAT_TINY:
64 record = new AltosEepromRecordTiny(eeprom);
66 case AltosLib.AO_LOG_FORMAT_TELEMETRY:
67 case AltosLib.AO_LOG_FORMAT_TELESCIENCE:
68 case AltosLib.AO_LOG_FORMAT_TELEMEGA:
69 case AltosLib.AO_LOG_FORMAT_TELEMEGA_OLD:
70 record = new AltosEepromRecordMega(eeprom);
72 case AltosLib.AO_LOG_FORMAT_TELEMETRUM:
73 record = new AltosEepromRecordMetrum(eeprom);
75 case AltosLib.AO_LOG_FORMAT_TELEMINI2:
76 case AltosLib.AO_LOG_FORMAT_TELEMINI3:
77 case AltosLib.AO_LOG_FORMAT_EASYMINI:
78 record = new AltosEepromRecordMini(eeprom);
80 case AltosLib.AO_LOG_FORMAT_TELEGPS:
81 record = new AltosEepromRecordGps(eeprom);
83 case AltosLib.AO_LOG_FORMAT_TELEFIRETWO:
84 record = new AltosEepromRecordFireTwo(eeprom);
89 System.out.printf("failed to parse log format %d\n", config_data.log_format);
92 ordered = new TreeSet<AltosEepromRecord>();
96 start_state = new AltosState();
97 start_state.set_config_data(record.eeprom.config_data());
100 int t = record.tick();
106 while (t < tick - 32767)
110 record.wide_tick = tick;
112 if (!record.hasNext())
114 record = record.next();
118 public AltosEepromRecordSet(Reader input) throws IOException {
119 this(new AltosEepromNew(input));