altoslib: Remove spurious debug printf in AltosCalData
[fw/altos] / altoslib / AltosEepromRecordSet.java
1 /*
2  * Copyright © 2017 Keith Packard <keithp@keithp.com>
3  *
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.
8  *
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.
13  */
14
15 package org.altusmetrum.altoslib_13;
16
17 import java.io.*;
18 import java.util.*;
19
20 public class AltosEepromRecordSet implements AltosRecordSet {
21         AltosEeprom                     eeprom;
22         TreeSet<AltosEepromRecord>      ordered;
23         AltosCalData                    cal_data;
24
25         public AltosConfigData config_data() {
26                 return eeprom.config_data();
27         }
28
29         public AltosCalData cal_data() {
30                 if (cal_data == null) {
31                         cal_data = new AltosCalData(config_data());
32                         for (AltosEepromRecord record : ordered) {
33                                 if (record.cmd() == AltosLib.AO_LOG_FLIGHT) {
34                                         cal_data.set_tick(record.tick());
35                                         cal_data.set_boost_tick();
36                                         break;
37                                 }
38                         }
39                 }
40                 return cal_data;
41         }
42
43         public void capture_series(AltosDataListener listener) {
44                 AltosCalData    cal_data = cal_data();
45
46                 cal_data.reset();
47                 listener.set_log_format(config_data().log_format);
48
49                 for (AltosEepromRecord record : ordered) {
50                         record.provide_data(listener, cal_data);
51                 }
52                 listener.finish();
53         }
54
55         public AltosEepromRecordSet(AltosEeprom eeprom) {
56                 this.eeprom = eeprom;
57
58                 AltosConfigData         config_data = eeprom.config_data();
59
60                 AltosEepromRecord       record = null;
61
62                 switch (config_data.log_format) {
63                 case AltosLib.AO_LOG_FORMAT_FULL:
64                         record = new AltosEepromRecordFull(eeprom);
65                         break;
66                 case AltosLib.AO_LOG_FORMAT_TINY:
67                         record = new AltosEepromRecordTiny(eeprom);
68                         break;
69                 case AltosLib.AO_LOG_FORMAT_TELEMETRY:
70                 case AltosLib.AO_LOG_FORMAT_TELESCIENCE:
71                 case AltosLib.AO_LOG_FORMAT_TELEMEGA:
72                 case AltosLib.AO_LOG_FORMAT_TELEMEGA_3:
73                 case AltosLib.AO_LOG_FORMAT_TELEMEGA_OLD:
74                 case AltosLib.AO_LOG_FORMAT_EASYMEGA_2:
75                         record = new AltosEepromRecordMega(eeprom);
76                         break;
77                 case AltosLib.AO_LOG_FORMAT_TELEMETRUM:
78                         record = new AltosEepromRecordMetrum(eeprom);
79                         break;
80                 case AltosLib.AO_LOG_FORMAT_TELEMINI2:
81                 case AltosLib.AO_LOG_FORMAT_TELEMINI3:
82                 case AltosLib.AO_LOG_FORMAT_EASYMINI1:
83                 case AltosLib.AO_LOG_FORMAT_EASYMINI2:
84                         record = new AltosEepromRecordMini(eeprom);
85                         break;
86                 case AltosLib.AO_LOG_FORMAT_TELEGPS:
87                         record = new AltosEepromRecordGps(eeprom);
88                         break;
89                 case AltosLib.AO_LOG_FORMAT_TELEFIRETWO:
90                         record = new AltosEepromRecordFireTwo(eeprom);
91                         break;
92                 }
93
94                 if (record == null) {
95                         System.out.printf("failed to parse log format %d\n", config_data.log_format);
96                         return;
97                 }
98                 ordered = new TreeSet<AltosEepromRecord>();
99                 int     tick = 0;
100                 boolean first = true;
101
102                 do {
103                         int     t = record.tick();
104
105                         if (first) {
106                                 tick = t;
107                                 first = false;
108                         } else {
109                                 while (t < tick - 32767)
110                                         t += 65536;
111                                 tick = t;
112                         }
113                         record.wide_tick = tick;
114                         ordered.add(record);
115                         record = record.next();
116                 } while (record != null);
117         }
118
119         public AltosEepromRecordSet(InputStream input) throws IOException {
120                 this(new AltosEeprom(input));
121         }
122 }