2 * Copyright © 2010 Keith Packard <keithp@keithp.com>
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.
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.
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.
21 import java.awt.event.*;
23 import javax.swing.filechooser.FileNameExtensionFilter;
24 import javax.swing.table.*;
28 import java.util.prefs.*;
29 import java.util.concurrent.LinkedBlockingQueue;
31 import altosui.AltosFlightInfoTableModel;
32 import altosui.AltosState;
34 public class AltosInfoTable {
36 private JTable table[];
37 private AltosFlightInfoTableModel model[];
40 private Font infoLabelFont = new Font("SansSerif", Font.PLAIN, 14);
41 private Font infoValueFont = new Font("Monospaced", Font.PLAIN, 14);
43 static final int info_columns = 3;
44 static final int info_rows = 17;
46 public AltosInfoTable() {
47 box = Box.createHorizontalBox();
48 model = new AltosFlightInfoTableModel[info_columns];
49 table = new JTable[info_columns];
50 ibox = new Box[info_columns];
51 for (int i = 0; i < info_columns; i++) {
52 model[i] = new AltosFlightInfoTableModel();
53 table[i] = new JTable(model[i]);
54 ibox[i] = box.createVerticalBox();
56 table[i].setFont(infoValueFont);
57 table[i].setRowHeight(rowHeight());
58 table[i].setShowGrid(true);
59 ibox[i].add(table[i].getTableHeader());
60 ibox[i].add(table[i]);
65 public int rowHeight() {
66 FontMetrics infoValueMetrics = table[0].getFontMetrics(infoValueFont);
67 return (infoValueMetrics.getHeight() + infoValueMetrics.getLeading()) * 20 / 10;
70 public int columnWidth() {
71 FontMetrics infoValueMetrics = table[0].getFontMetrics(infoValueFont);
72 return infoValueMetrics.charWidth('0') * 20 * 2;
76 return rowHeight() * info_rows;
80 return columnWidth() * info_columns;
88 for (int i = 0; i < info_columns; i++)
92 void info_add_row(int col, String name, String value) {
93 model[col].addRow(name, value);
96 void info_add_row(int col, String name, String format, Object... parameters) {
97 model[col].addRow(name, String.format(format, parameters));
100 void info_add_deg(int col, String name, double v, int pos, int neg) {
106 double deg = Math.floor(v);
107 double min = (v - deg) * 60;
109 model[col].addRow(name, String.format("%3.0f°%08.5f'", deg, min));
113 for (int i = 0; i < info_columns; i++)
117 public void clear() {
122 public void show(AltosState state, int crc_errors) {
126 info_add_row(0, "Rocket state", "%s", state.data.state());
127 info_add_row(0, "Callsign", "%s", state.data.callsign);
128 info_add_row(0, "Rocket serial", "%6d", state.data.serial);
129 info_add_row(0, "Rocket flight", "%6d", state.data.flight);
131 info_add_row(0, "RSSI", "%6d dBm", state.data.rssi);
132 info_add_row(0, "CRC Errors", "%6d", crc_errors);
133 info_add_row(0, "Height", "%6.0f m", state.height);
134 info_add_row(0, "Max height", "%6.0f m", state.max_height);
135 info_add_row(0, "Acceleration", "%8.1f m/s²", state.acceleration);
136 info_add_row(0, "Max acceleration", "%8.1f m/s²", state.max_acceleration);
137 info_add_row(0, "Speed", "%8.1f m/s", state.ascent ? state.speed : state.baro_speed);
138 info_add_row(0, "Max Speed", "%8.1f m/s", state.max_speed);
139 info_add_row(0, "Temperature", "%9.2f °C", state.temperature);
140 info_add_row(0, "Battery", "%9.2f V", state.battery);
141 info_add_row(0, "Drogue", "%9.2f V", state.drogue_sense);
142 info_add_row(0, "Main", "%9.2f V", state.main_sense);
143 info_add_row(0, "Pad altitude", "%6.0f m", state.ground_altitude);
144 if (state.gps == null) {
145 info_add_row(1, "GPS", "not available");
148 info_add_row(1, "GPS state", "%s", "ready");
150 info_add_row(1, "GPS state", "wait (%d)",
152 if (state.data.gps.locked)
153 info_add_row(1, "GPS", " locked");
154 else if (state.data.gps.connected)
155 info_add_row(1, "GPS", " unlocked");
157 info_add_row(1, "GPS", " missing");
158 info_add_row(1, "Satellites", "%6d", state.data.gps.nsat);
159 info_add_deg(1, "Latitude", state.gps.lat, 'N', 'S');
160 info_add_deg(1, "Longitude", state.gps.lon, 'E', 'W');
161 info_add_row(1, "GPS altitude", "%6d", state.gps.alt);
162 info_add_row(1, "GPS height", "%6.0f", state.gps_height);
164 /* The SkyTraq GPS doesn't report these values */
166 info_add_row(1, "GPS ground speed", "%8.1f m/s %3d°",
167 state.gps.ground_speed,
169 info_add_row(1, "GPS climb rate", "%8.1f m/s",
170 state.gps.climb_rate);
171 info_add_row(1, "GPS error", "%6d m(h)%3d m(v)",
172 state.gps.h_error, state.gps.v_error);
174 info_add_row(1, "GPS hdop", "%8.1f", state.gps.hdop);
176 if (state.npad > 0) {
177 if (state.from_pad != null) {
178 info_add_row(1, "Distance from pad", "%6d m",
179 (int) (state.from_pad.distance + 0.5));
180 info_add_row(1, "Direction from pad", "%6d°",
181 (int) (state.from_pad.bearing + 0.5));
182 info_add_row(1, "Elevation from pad", "%6d°",
183 (int) (state.elevation + 0.5));
184 info_add_row(1, "Range from pad", "%6d m",
185 (int) (state.range + 0.5));
187 info_add_row(1, "Distance from pad", "unknown");
188 info_add_row(1, "Direction from pad", "unknown");
189 info_add_row(1, "Elevation from pad", "unknown");
190 info_add_row(1, "Range from pad", "unknown");
192 info_add_deg(1, "Pad latitude", state.pad_lat, 'N', 'S');
193 info_add_deg(1, "Pad longitude", state.pad_lon, 'E', 'W');
194 info_add_row(1, "Pad GPS alt", "%6.0f m", state.pad_alt);
196 info_add_row(1, "GPS date", "%04d-%02d-%02d",
200 info_add_row(1, "GPS time", " %02d:%02d:%02d",
207 if (state.gps.cc_gps_sat == null)
208 info_add_row(2, "Satellites Visible", "%4d", 0);
210 info_add_row(2, "Satellites Visible", "%4d", state.gps.cc_gps_sat.length);
211 for (c = 0; c < state.gps.cc_gps_sat.length; c++) {
212 info_add_row(2, "Satellite id,C/N0",
214 state.gps.cc_gps_sat[c].svid,
215 state.gps.cc_gps_sat[c].c_n0);