altosui: Don't show missing igniter and gps values
[fw/altos] / altosui / AltosInfoTable.java
1 /*
2  * Copyright © 2010 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 altosui;
19
20 import java.awt.*;
21 import java.awt.event.*;
22 import javax.swing.*;
23 import javax.swing.filechooser.FileNameExtensionFilter;
24 import javax.swing.table.*;
25 import java.io.*;
26 import java.util.*;
27 import java.text.*;
28 import java.util.prefs.*;
29 import java.util.concurrent.LinkedBlockingQueue;
30
31 public class AltosInfoTable extends JTable {
32         private AltosFlightInfoTableModel model;
33
34         private Font infoLabelFont = new Font("SansSerif", Font.PLAIN, 14);
35         private Font infoValueFont = new Font("Monospaced", Font.PLAIN, 14);
36
37         static final int info_columns = 3;
38         static final int info_rows = 17;
39
40         int desired_row_height() {
41                 FontMetrics     infoValueMetrics = getFontMetrics(infoValueFont);
42                 return (infoValueMetrics.getHeight() + infoValueMetrics.getLeading()) * 18 / 10;
43         }
44
45         public AltosInfoTable() {
46                 super(new AltosFlightInfoTableModel(info_rows, info_columns));
47                 model = (AltosFlightInfoTableModel) getModel();
48                 setFont(infoValueFont);
49                 setAutoResizeMode(AUTO_RESIZE_ALL_COLUMNS);
50                 setShowGrid(true);
51                 setRowHeight(desired_row_height());
52                 doLayout();
53         }
54
55         public Dimension getPreferredScrollableViewportSize() {
56                 return getPreferredSize();
57         }
58
59         void info_reset() {
60                 model.reset();
61         }
62
63         void info_add_row(int col, String name, String value) {
64                 model.addRow(col, name, value);
65         }
66
67         void info_add_row(int col, String name, String format, Object... parameters) {
68                 info_add_row (col, name, String.format(format, parameters));
69         }
70
71         void info_add_deg(int col, String name, double v, int pos, int neg) {
72                 int     c = pos;
73                 if (v < 0) {
74                         c = neg;
75                         v = -v;
76                 }
77                 double  deg = Math.floor(v);
78                 double  min = (v - deg) * 60;
79
80                 info_add_row(col, name, String.format("%3.0f°%08.5f'", deg, min));
81         }
82
83         void info_finish() {
84                 model.finish();
85         }
86
87         public void clear() {
88                 model.clear();
89         }
90
91         public void show(AltosState state, int crc_errors) {
92                 if (state == null)
93                         return;
94                 info_reset();
95                 info_add_row(0, "Rocket state", "%s", state.data.state());
96                 info_add_row(0, "Callsign", "%s", state.data.callsign);
97                 info_add_row(0, "Rocket serial", "%6d", state.data.serial);
98                 info_add_row(0, "Rocket flight", "%6d", state.data.flight);
99
100                 info_add_row(0, "RSSI", "%6d    dBm", state.data.rssi);
101                 info_add_row(0, "CRC Errors", "%6d", crc_errors);
102                 info_add_row(0, "Height", "%6.0f    m", state.height);
103                 info_add_row(0, "Max height", "%6.0f    m", state.max_height);
104                 info_add_row(0, "Acceleration", "%8.1f  m/s²", state.acceleration);
105                 info_add_row(0, "Max acceleration", "%8.1f  m/s²", state.max_acceleration);
106                 info_add_row(0, "Speed", "%8.1f  m/s", state.ascent ? state.speed : state.baro_speed);
107                 info_add_row(0, "Max Speed", "%8.1f  m/s", state.max_speed);
108                 info_add_row(0, "Temperature", "%9.2f °C", state.temperature);
109                 info_add_row(0, "Battery", "%9.2f V", state.battery);
110                 if (state.drogue_sense != AltosRecord.MISSING)
111                         info_add_row(0, "Drogue", "%9.2f V", state.drogue_sense);
112                 if (state.main_sense != AltosRecord.MISSING)
113                         info_add_row(0, "Main", "%9.2f V", state.main_sense);
114                 info_add_row(0, "Pad altitude", "%6.0f    m", state.ground_altitude);
115                 if (state.gps == null || !state.gps.connected) {
116                         info_add_row(1, "GPS", "not available");
117                 } else {
118                         if (state.gps_ready)
119                                 info_add_row(1, "GPS state", "%s", "ready");
120                         else
121                                 info_add_row(1, "GPS state", "wait (%d)",
122                                              state.gps_waiting);
123                         if (state.data.gps.locked)
124                                 info_add_row(1, "GPS", "   locked");
125                         else if (state.data.gps.connected)
126                                 info_add_row(1, "GPS", " unlocked");
127                         else
128                                 info_add_row(1, "GPS", "  missing");
129                         info_add_row(1, "Satellites", "%6d", state.data.gps.nsat);
130                         info_add_deg(1, "Latitude", state.gps.lat, 'N', 'S');
131                         info_add_deg(1, "Longitude", state.gps.lon, 'E', 'W');
132                         info_add_row(1, "GPS altitude", "%6d", state.gps.alt);
133                         info_add_row(1, "GPS height", "%6.0f", state.gps_height);
134
135                         /* The SkyTraq GPS doesn't report these values */
136                         if (false) {
137                                 info_add_row(1, "GPS ground speed", "%8.1f m/s %3d°",
138                                              state.gps.ground_speed,
139                                              state.gps.course);
140                                 info_add_row(1, "GPS climb rate", "%8.1f m/s",
141                                              state.gps.climb_rate);
142                                 info_add_row(1, "GPS error", "%6d m(h)%3d m(v)",
143                                              state.gps.h_error, state.gps.v_error);
144                         }
145                         info_add_row(1, "GPS hdop", "%8.1f", state.gps.hdop);
146
147                         if (state.npad > 0) {
148                                 if (state.from_pad != null) {
149                                         info_add_row(1, "Distance from pad", "%6d m",
150                                                      (int) (state.from_pad.distance + 0.5));
151                                         info_add_row(1, "Direction from pad", "%6d°",
152                                                      (int) (state.from_pad.bearing + 0.5));
153                                         info_add_row(1, "Elevation from pad", "%6d°",
154                                                      (int) (state.elevation + 0.5));
155                                         info_add_row(1, "Range from pad", "%6d m",
156                                                      (int) (state.range + 0.5));
157                                 } else {
158                                         info_add_row(1, "Distance from pad", "unknown");
159                                         info_add_row(1, "Direction from pad", "unknown");
160                                         info_add_row(1, "Elevation from pad", "unknown");
161                                         info_add_row(1, "Range from pad", "unknown");
162                                 }
163                                 info_add_deg(1, "Pad latitude", state.pad_lat, 'N', 'S');
164                                 info_add_deg(1, "Pad longitude", state.pad_lon, 'E', 'W');
165                                 info_add_row(1, "Pad GPS alt", "%6.0f m", state.pad_alt);
166                         }
167                         info_add_row(1, "GPS date", "%04d-%02d-%02d",
168                                        state.gps.year,
169                                        state.gps.month,
170                                        state.gps.day);
171                         info_add_row(1, "GPS time", "  %02d:%02d:%02d",
172                                        state.gps.hour,
173                                        state.gps.minute,
174                                        state.gps.second);
175                         int     nsat_vis = 0;
176                         int     c;
177
178                         if (state.gps.cc_gps_sat == null)
179                                 info_add_row(2, "Satellites Visible", "%4d", 0);
180                         else {
181                                 info_add_row(2, "Satellites Visible", "%4d", state.gps.cc_gps_sat.length);
182                                 for (c = 0; c < state.gps.cc_gps_sat.length; c++) {
183                                         info_add_row(2, "Satellite id,C/N0",
184                                                      "%4d, %4d",
185                                                      state.gps.cc_gps_sat[c].svid,
186                                                      state.gps.cc_gps_sat[c].c_n0);
187                                 }
188                         }
189                 }
190                 info_finish();
191         }
192 }