File: AltosGraphDataPoint.java

package info (click to toggle)
altos 1.6.8-5
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 63,748 kB
  • ctags: 36,577
  • sloc: ansic: 92,100; java: 36,273; makefile: 6,495; xml: 3,096; sh: 1,971; pascal: 1,581
file content (250 lines) | stat: -rw-r--r-- 7,189 bytes parent folder | download
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
/*
 * Copyright © 2013 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.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
 */

package org.altusmetrum.altosuilib_11;

import org.altusmetrum.altoslib_11.*;

public class AltosGraphDataPoint implements AltosUIDataPoint {

	AltosState	state;

	public static final int data_height = 0;
	public static final int data_speed = 1;
	public static final int data_accel = 2;
	public static final int data_temp = 3;
	public static final int data_battery_voltage = 4;
	public static final int data_drogue_voltage = 5;
	public static final int data_main_voltage = 6;
	public static final int data_rssi = 7;
	public static final int data_state = 8;
	public static final int data_gps_height = 9;
	public static final int data_gps_nsat_solution = 10;
	public static final int data_gps_nsat_view = 11;
	public static final int data_gps_altitude = 12;
	public static final int data_temperature = 13;
	public static final int data_range = 14;
	public static final int data_distance = 15;
	public static final int data_pressure = 16;
	public static final int data_accel_along = 17;
	public static final int data_accel_across = 18;
	public static final int data_accel_through = 19;
	public static final int data_gyro_roll = 20;
	public static final int data_gyro_pitch = 21;
	public static final int data_gyro_yaw = 22;
	public static final int data_mag_along = 23;
	public static final int data_mag_across = 24;
	public static final int data_mag_through = 25;
	public static final int data_orient = 26;
	public static final int data_gps_course = 27;
	public static final int data_gps_ground_speed = 28;
	public static final int data_gps_climb_rate = 29;
	public static final int data_gps_pdop = 30;
	public static final int data_gps_hdop = 31;
	public static final int data_gps_vdop = 32;
	public static final int data_ignitor_0 = 33;
	public static final int data_ignitor_num = 32;
	public static final int data_ignitor_max = data_ignitor_0 + data_ignitor_num - 1;
	public static final int data_ignitor_fired_0 = data_ignitor_0 + data_ignitor_num;
	public static final int data_ignitor_fired_max = data_ignitor_fired_0 + data_ignitor_num - 1;

	public double x() throws AltosUIDataMissing {
		double	time = state.time_since_boost();
		if (time < -2)
			throw new AltosUIDataMissing(-1);
		return time;
	}

	public double y(int index) throws AltosUIDataMissing {
		double y = AltosLib.MISSING;
		switch (index) {
		case data_height:
			y = state.height();
			break;
		case data_speed:
			y = state.speed();
			break;
		case data_accel:
			y = state.acceleration();
			break;
		case data_temp:
			y = state.temperature;
			break;
		case data_battery_voltage:
			y = state.battery_voltage;
			break;
		case data_drogue_voltage:
			y = state.apogee_voltage;
			break;
		case data_main_voltage:
			y = state.main_voltage;
			break;
		case data_rssi:
			y = state.rssi;
			break;
		case data_gps_height:
			y = state.gps_height;
			break;
		case data_gps_nsat_solution:
			if (state.gps != null)
				y = state.gps.nsat;
			break;
		case data_gps_nsat_view:
			if (state.gps != null) {
				if (state.gps.cc_gps_sat != null)
					y = state.gps.cc_gps_sat.length;
				else
					y = 0;
			}
			break;
		case data_gps_altitude:
			y = state.gps_altitude();
			break;
		case data_temperature:
			y = state.temperature;
			break;
		case data_range:
			y = state.range;
			break;
		case data_distance:
			if (state.from_pad != null)
				y = state.from_pad.distance;
			break;
		case data_pressure:
			y = state.pressure();
			break;

		case data_accel_along:
			y = state.accel_along();
			break;
		case data_accel_across:
			y = state.accel_across();
			break;
		case data_accel_through:
			y = state.accel_through();
			break;
		case data_gyro_roll:
			y = state.gyro_roll();
			break;
		case data_gyro_pitch:
			y = state.gyro_pitch();
			break;
		case data_gyro_yaw:
			y = state.gyro_yaw();
			break;
		case data_mag_along:
			y = state.mag_along();
			break;
		case data_mag_across:
			y = state.mag_across();
			break;
		case data_mag_through:
			y = state.mag_through();
			break;
		case data_orient:
			y = state.orient();
			break;
		case data_gps_course:
			if (state.gps != null)
				y = state.gps.course;
			else
				y = AltosLib.MISSING;
			break;
		case data_gps_ground_speed:
			if (state.gps != null)
				y = state.gps.ground_speed;
			else
				y = AltosLib.MISSING;
			break;
		case data_gps_climb_rate:
			if (state.gps != null)
				y = state.gps.climb_rate;
			else
				y = AltosLib.MISSING;
			break;
		case data_gps_pdop:
			if (state.gps != null)
				y = state.gps.pdop;
			else
				y = AltosLib.MISSING;
			break;
		case data_gps_hdop:
			if (state.gps != null)
				y = state.gps.hdop;
			else
				y = AltosLib.MISSING;
			break;
		case data_gps_vdop:
			if (state.gps != null)
				y = state.gps.vdop;
			else
				y = AltosLib.MISSING;
			break;
		default:
			if (data_ignitor_0 <= index && index <= data_ignitor_max) {
				int ignitor = index - data_ignitor_0;
				if (state.ignitor_voltage != null && ignitor < state.ignitor_voltage.length)
					y = state.ignitor_voltage[ignitor];
			} else if (data_ignitor_fired_0 <= index && index <= data_ignitor_fired_max) {
				int ignitor = index - data_ignitor_fired_0;
				if (state.ignitor_voltage != null && ignitor < state.ignitor_voltage.length) {
					if ((state.pyro_fired & (1 << ignitor)) != 0)
						y = 1;
					else
						y = 0;
				}
			}
			break;
		}
		if (y == AltosLib.MISSING)
			throw new AltosUIDataMissing(index);
		return y;
	}

	public int id(int index) {
		if (index == data_state) {
			int s = state.state();
			if (AltosLib.ao_flight_boost <= s && s <= AltosLib.ao_flight_landed)
				return s;
		} else if (data_ignitor_fired_0 <= index && index <= data_ignitor_fired_max) {
			int ignitor = index - data_ignitor_fired_0;
			if (state.ignitor_voltage != null && ignitor < state.ignitor_voltage.length) {
				if (state.ignitor_voltage != null && ignitor < state.ignitor_voltage.length) {
					if ((state.pyro_fired & (1 << ignitor)) != 0)
						return 1;
				}
			}
		}
		return -1;
	}

	public String id_name(int index) {
		if (index == data_state) {
			return state.state_name();
		} else if (data_ignitor_fired_0 <= index && index <= data_ignitor_fired_max) {
			int ignitor = index - data_ignitor_fired_0;
			if (state.ignitor_voltage != null && ignitor < state.ignitor_voltage.length)
				return AltosLib.ignitor_name(ignitor);
		}
		return "";
	}

	public AltosGraphDataPoint (AltosState state) {
		this.state = state;
	}
}