altosuilib: Add GPS DOP values to graph
[fw/altos] / altosuilib / AltosGraphDataPoint.java
1 /*
2  * Copyright © 2013 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; version 2 of the License.
7  *
8  * This program is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11  * General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License along
14  * with this program; if not, write to the Free Software Foundation, Inc.,
15  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
16  */
17
18 package org.altusmetrum.altosuilib_3;
19
20 import org.altusmetrum.altoslib_5.*;
21
22 public class AltosGraphDataPoint implements AltosUIDataPoint {
23
24         AltosState      state;
25
26         public static final int data_height = 0;
27         public static final int data_speed = 1;
28         public static final int data_accel = 2;
29         public static final int data_temp = 3;
30         public static final int data_battery_voltage = 4;
31         public static final int data_drogue_voltage = 5;
32         public static final int data_main_voltage = 6;
33         public static final int data_rssi = 7;
34         public static final int data_state = 8;
35         public static final int data_gps_height = 9;
36         public static final int data_gps_nsat_solution = 10;
37         public static final int data_gps_nsat_view = 11;
38         public static final int data_gps_altitude = 12;
39         public static final int data_temperature = 13;
40         public static final int data_range = 14;
41         public static final int data_distance = 15;
42         public static final int data_pressure = 16;
43         public static final int data_accel_x = 17;
44         public static final int data_accel_y = 18;
45         public static final int data_accel_z = 19;
46         public static final int data_gyro_x = 20;
47         public static final int data_gyro_y = 21;
48         public static final int data_gyro_z = 22;
49         public static final int data_mag_x = 23;
50         public static final int data_mag_y = 24;
51         public static final int data_mag_z = 25;
52         public static final int data_orient = 26;
53         public static final int data_gps_course = 27;
54         public static final int data_gps_ground_speed = 28;
55         public static final int data_gps_climb_rate = 29;
56         public static final int data_gps_pdop = 30;
57         public static final int data_gps_hdop = 31;
58         public static final int data_gps_vdop = 32;
59         public static final int data_ignitor_0 = 33;
60         public static final int data_ignitor_num = 32;
61         public static final int data_ignitor_max = data_ignitor_0 + data_ignitor_num - 1;
62         public static final int data_ignitor_fired_0 = data_ignitor_0 + data_ignitor_num;
63         public static final int data_ignitor_fired_max = data_ignitor_fired_0 + data_ignitor_num - 1;
64
65         public double x() throws AltosUIDataMissing {
66                 double  time = state.time_since_boost();
67                 if (time < -2)
68                         throw new AltosUIDataMissing(-1);
69                 return time;
70         }
71
72         public double y(int index) throws AltosUIDataMissing {
73                 double y = AltosLib.MISSING;
74                 switch (index) {
75                 case data_height:
76                         y = state.height();
77                         break;
78                 case data_speed:
79                         y = state.speed();
80                         break;
81                 case data_accel:
82                         y = state.acceleration();
83                         break;
84                 case data_temp:
85                         y = state.temperature;
86                         break;
87                 case data_battery_voltage:
88                         y = state.battery_voltage;
89                         break;
90                 case data_drogue_voltage:
91                         y = state.apogee_voltage;
92                         break;
93                 case data_main_voltage:
94                         y = state.main_voltage;
95                         break;
96                 case data_rssi:
97                         y = state.rssi;
98                         break;
99                 case data_gps_height:
100                         y = state.gps_height;
101                         break;
102                 case data_gps_nsat_solution:
103                         if (state.gps != null)
104                                 y = state.gps.nsat;
105                         break;
106                 case data_gps_nsat_view:
107                         if (state.gps != null) {
108                                 if (state.gps.cc_gps_sat != null)
109                                         y = state.gps.cc_gps_sat.length;
110                                 else
111                                         y = 0;
112                         }
113                         break;
114                 case data_gps_altitude:
115                         y = state.gps_altitude();
116                         break;
117                 case data_temperature:
118                         y = state.temperature;
119                         break;
120                 case data_range:
121                         y = state.range;
122                         break;
123                 case data_distance:
124                         if (state.from_pad != null)
125                                 y = state.from_pad.distance;
126                         break;
127                 case data_pressure:
128                         y = state.pressure();
129                         break;
130
131                 case data_accel_x:
132                 case data_accel_y:
133                 case data_accel_z:
134                 case data_gyro_x:
135                 case data_gyro_y:
136                 case data_gyro_z:
137                         AltosIMU        imu = state.imu;
138                         if (imu == null)
139                                 break;
140                         switch (index) {
141                         case data_accel_x:
142                                 y = imu.accel_x;
143                                 break;
144                         case data_accel_y:
145                                 y = imu.accel_y;
146                                 break;
147                         case data_accel_z:
148                                 y = imu.accel_z;
149                                 break;
150                         case data_gyro_x:
151                                 y = imu.gyro_x;
152                                 break;
153                         case data_gyro_y:
154                                 y = imu.gyro_y;
155                                 break;
156                         case data_gyro_z:
157                                 y = imu.gyro_z;
158                                 break;
159                         }
160                         break;
161                 case data_mag_x:
162                 case data_mag_y:
163                 case data_mag_z:
164                         AltosMag        mag = state.mag;
165                         if (mag == null)
166                                 break;
167                         switch (index) {
168                         case data_mag_x:
169                                 y = mag.x;
170                                 break;
171                         case data_mag_y:
172                                 y = mag.y;
173                                 break;
174                         case data_mag_z:
175                                 y = mag.z;
176                                 break;
177                         }
178                         break;
179                 case data_orient:
180                         y = state.orient();
181                         break;
182                 case data_gps_course:
183                         if (state.gps != null)
184                                 y = state.gps.course;
185                         else
186                                 y = AltosLib.MISSING;
187                         break;
188                 case data_gps_ground_speed:
189                         if (state.gps != null)
190                                 y = state.gps.ground_speed;
191                         else
192                                 y = AltosLib.MISSING;
193                         break;
194                 case data_gps_climb_rate:
195                         if (state.gps != null)
196                                 y = state.gps.climb_rate;
197                         else
198                                 y = AltosLib.MISSING;
199                         break;
200                 case data_gps_pdop:
201                         if (state.gps != null)
202                                 y = state.gps.pdop;
203                         else
204                                 y = AltosLib.MISSING;
205                         break;
206                 case data_gps_hdop:
207                         if (state.gps != null)
208                                 y = state.gps.hdop;
209                         else
210                                 y = AltosLib.MISSING;
211                         break;
212                 case data_gps_vdop:
213                         if (state.gps != null)
214                                 y = state.gps.vdop;
215                         else
216                                 y = AltosLib.MISSING;
217                         break;
218                 default:
219                         if (data_ignitor_0 <= index && index <= data_ignitor_max) {
220                                 int ignitor = index - data_ignitor_0;
221                                 if (state.ignitor_voltage != null && ignitor < state.ignitor_voltage.length)
222                                         y = state.ignitor_voltage[ignitor];
223                         } else if (data_ignitor_fired_0 <= index && index <= data_ignitor_fired_max) {
224                                 int ignitor = index - data_ignitor_fired_0;
225                                 if (state.ignitor_voltage != null && ignitor < state.ignitor_voltage.length) {
226                                         if ((state.pyro_fired & (1 << ignitor)) != 0)
227                                                 y = 1;
228                                         else
229                                                 y = 0;
230                                 }
231                         }
232                         break;
233                 }
234                 if (y == AltosLib.MISSING)
235                         throw new AltosUIDataMissing(index);
236                 return y;
237         }
238
239         public int id(int index) {
240                 if (index == data_state) {
241                         int s = state.state;
242                         if (AltosLib.ao_flight_boost <= s && s <= AltosLib.ao_flight_landed)
243                                 return s;
244                 } else if (data_ignitor_fired_0 <= index && index <= data_ignitor_fired_max) {
245                         int ignitor = index - data_ignitor_fired_0;
246                         if (state.ignitor_voltage != null && ignitor < state.ignitor_voltage.length) {
247                                 if (state.ignitor_voltage != null && ignitor < state.ignitor_voltage.length) {
248                                         if ((state.pyro_fired & (1 << ignitor)) != 0)
249                                                 return 1;
250                                 }
251                         }
252                 }
253                 return -1;
254         }
255
256         public String id_name(int index) {
257                 if (index == data_state) {
258                         return state.state_name();
259                 } else if (data_ignitor_fired_0 <= index && index <= data_ignitor_fired_max) {
260                         int ignitor = index - data_ignitor_fired_0;
261                         if (state.ignitor_voltage != null && ignitor < state.ignitor_voltage.length)
262                                 return AltosLib.ignitor_name(ignitor);
263                 }
264                 return "";
265         }
266
267         public AltosGraphDataPoint (AltosState state) {
268                 this.state = state;
269         }
270 }