summaryrefslogtreecommitdiff
path: root/altoslib/AltosTelemetryRecordSet.java
blob: 0323c25e7fcb96ca41a28fb29f597242dfdaa321 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
 * Copyright © 2017 Keith Packard <keithp@keithp.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 */

package org.altusmetrum.altoslib_11;

import java.io.*;
import java.util.*;

public class AltosTelemetryRecordSet implements AltosRecordSet {
	AltosTelemetry			telemetry;
	TreeSet<AltosTelemetryRecord>	ordered;

	public void capture_series(AltosDataListener listener) {
		for (AltosTelemetryRecord record : ordered) {
			record.update_state(listener);
		}
		listener.finish();
	}

	public AltosTelemetryRecordSet(AltosTelemetry telemetry) {
		this.telemetry = telemetry;

		AltosTelemetryRecord	record = null;

		switch (config_data.log_format) {
		case AltosLib.AO_LOG_FORMAT_FULL:
			record = new AltosTelemetryRecordFull(eeprom);
			break;
		case AltosLib.AO_LOG_FORMAT_TINY:
			record = new AltosTelemetryRecordTiny(eeprom);
			break;
		case AltosLib.AO_LOG_FORMAT_TELEMETRY:
		case AltosLib.AO_LOG_FORMAT_TELESCIENCE:
		case AltosLib.AO_LOG_FORMAT_TELEMEGA:
		case AltosLib.AO_LOG_FORMAT_TELEMEGA_OLD:
			record = new AltosTelemetryRecordMega(eeprom);
			break;
		case AltosLib.AO_LOG_FORMAT_TELEMETRUM:
			record = new AltosTelemetryRecordMetrum(eeprom);
			break;
		case AltosLib.AO_LOG_FORMAT_TELEMINI2:
		case AltosLib.AO_LOG_FORMAT_TELEMINI3:
		case AltosLib.AO_LOG_FORMAT_EASYMINI:
			record = new AltosTelemetryRecordMini(eeprom);
			break;
		case AltosLib.AO_LOG_FORMAT_TELEGPS:
			record = new AltosTelemetryRecordGps(eeprom);
			break;
		case AltosLib.AO_LOG_FORMAT_TELEFIRETWO:
			record = new AltosTelemetryRecordFireTwo(eeprom);
			break;
		}

		if (record == null) {
			System.out.printf("failed to parse log format %d\n", config_data.log_format);
			return;
		}
		ordered = new TreeSet<AltosTelemetryRecord>();
		int	tick = 0;
		boolean first = true;

		start_state = new AltosState();
		start_state.set_config_data(record.eeprom.config_data());

		for (;;) {
			int	t = record.tick();

			if (first) {
				tick = t;
				first = false;
			} else {
				while (t < tick - 32767)
					t += 65536;
				tick = t;
			}
			record.wide_tick = tick;
			ordered.add(record);
			if (!record.hasNext())
				break;
			record = record.next();
		}
	}

	public AltosTelemetryRecordSet(Reader input) throws IOException {
		this(new AltosTelemetryNew(input));
	}
}