*
* 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; version 2 of the License.
+ * 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
import java.util.concurrent.*;
import java.util.*;
import java.text.*;
-import org.altusmetrum.altoslib_11.*;
-import org.altusmetrum.altosuilib_11.*;
+import org.altusmetrum.altoslib_14.*;
+import org.altusmetrum.altosuilib_14.*;
public class TeleGPS
extends AltosUIFrame
- implements AltosFlightDisplay, AltosFontListener, AltosUnitsListener, ActionListener
+ implements AltosFlightDisplay, AltosFontListener, AltosUnitsListener, ActionListener, AltosEepromGrapher
{
static String[] telegps_icon_names = {
AltosFlightReader reader;
TeleGPSDisplayThread thread;
+ boolean idle_mode;
JMenuBar menu_bar;
JTabbedPane pane;
- AltosUIMapNew map;
+ AltosUIMap map;
TeleGPSInfo gps_info;
TeleGPSState gps_state;
AltosInfoTable info_table;
status_update.saved_listener_state = listener_state;
if (state == null)
- state = new AltosState();
+ state = new AltosState(new AltosCalData());
int i = 0;
for (AltosFlightDisplay display : displays) {
}
void load_maps() {
- new AltosUIMapPreloadNew(this);
+ new AltosUIMapPreload(this);
}
void disconnect() {
disable_rate_menu();
}
- void connect(AltosDevice device) {
- if (reader != null)
- disconnect();
+ void connect_flight(AltosDevice device) {
try {
AltosFlightReader reader = new AltosTelemetryReader(new AltosSerial(device));
- set_reader(reader, device);
+ set_reader(reader, device, false);
} catch (FileNotFoundException ee) {
JOptionPane.showMessageDialog(this,
ee.getMessage(),
}
}
+ void connect_idle(AltosDevice device) {
+ try {
+ AltosFlightReader reader = new AltosIdleReader(new AltosSerial(device), false);
+ set_reader(reader, device, true);
+ } catch (FileNotFoundException ee) {
+ JOptionPane.showMessageDialog(this,
+ ee.getMessage(),
+ String.format ("Cannot open %s", device.toShortString()),
+ JOptionPane.ERROR_MESSAGE);
+ } catch (AltosSerialInUseException si) {
+ JOptionPane.showMessageDialog(this,
+ String.format("Device \"%s\" already in use",
+ device.toShortString()),
+ "Device in use",
+ JOptionPane.ERROR_MESSAGE);
+ } catch (IOException ee) {
+ JOptionPane.showMessageDialog(this,
+ String.format ("Unknown I/O error on %s", device.toShortString()),
+ "Unknown I/O error",
+ JOptionPane.ERROR_MESSAGE);
+ } catch (TimeoutException te) {
+ JOptionPane.showMessageDialog(this,
+ String.format ("Timeout on %s", device.toShortString()),
+ "Timeout error",
+ JOptionPane.ERROR_MESSAGE);
+ } catch (InterruptedException ie) {
+ JOptionPane.showMessageDialog(this,
+ String.format("Interrupted %s", device.toShortString()),
+ "Interrupted exception",
+ JOptionPane.ERROR_MESSAGE);
+ }
+ }
+
+ void connect(AltosDevice device) {
+ if (reader != null)
+ disconnect();
+ if (device.matchProduct(AltosLib.product_basestation))
+ connect_flight(device);
+ else
+ connect_idle(device);
+ }
+
void connect() {
AltosDevice device = AltosDeviceUIDialog.show(this,
- AltosLib.product_basestation);
+ AltosLib.product_any);
if (device == null)
return;
connect(device);
}
void download(){
- new AltosEepromManage(this, AltosLib.product_telegps);
+ new AltosEepromManage(this, this, AltosLib.product_telegps);
}
void configure() {
new TeleGPSConfig(this);
}
+ private static AltosFlightSeries make_series(AltosRecordSet set) {
+ AltosFlightSeries series = new AltosFlightSeries(set.cal_data());
+ set.capture_series(series);
+ series.finish();
+ return series;
+ }
+
void export() {
- AltosDataChooser chooser;
- chooser = new AltosDataChooser(this);
- AltosStateIterable states = chooser.runDialog();
- if (states == null)
+ AltosDataChooser chooser = new AltosDataChooser(this);
+
+ AltosRecordSet set = chooser.runDialog();
+ if (set == null)
return;
- new AltosCSVUI(this, states, chooser.file());
+ AltosFlightSeries series = make_series(set);
+ new AltosCSVUI(this, series, chooser.file());
}
void graph() {
- AltosDataChooser chooser;
- chooser = new AltosDataChooser(this);
- AltosStateIterable states = chooser.runDialog();
- if (states == null)
- return;
- try {
- new TeleGPSGraphUI(states, chooser.file());
- } catch (InterruptedException ie) {
- } catch (IOException ie) {
+ AltosDataChooser chooser = new AltosDataChooser(this);
+ AltosRecordSet set = chooser.runDialog();
+ graph_file(this, set, chooser.file());
+ }
+
+ public void graph_flights(AltosEepromList list) {
+ for (AltosEepromLog log : list) {
+ if (log.file != null) {
+ AltosRecordSet set = record_set(log.file);
+ graph_file(this, set, log.file);
+ }
}
}
}
- public void set_reader(AltosFlightReader reader, AltosDevice device) {
+ public void set_reader(AltosFlightReader reader, AltosDevice device, boolean idle_mode) {
+ this.idle_mode = idle_mode;
status_update = new TeleGPSStatusUpdate(telegps_status);
telegps_status.start(status_update);
thread.start();
if (device != null) {
- enable_frequency_menu(device.getSerial(), reader);
- enable_rate_menu(device.getSerial(), reader);
+ if (idle_mode) {
+ disable_frequency_menu();
+ disable_rate_menu();
+ } else {
+ enable_frequency_menu(device.getSerial(), reader);
+ enable_rate_menu(device.getSerial(), reader);
+ }
}
}
/* Make the tabbed pane use the rest of the window space */
bag.add(pane, constraints(0, 3, GridBagConstraints.BOTH));
- map = new AltosUIMapNew();
+ map = new AltosUIMap();
pane.add(map.getName(), map);
displays.add(map);
add_window();
}
- public TeleGPS(AltosFlightReader reader) {
+ public TeleGPS(AltosFlightReader reader, boolean idle_mode) {
this();
- set_reader(reader, null);
+ set_reader(reader, null, idle_mode);
}
public TeleGPS(AltosDevice device) {
connect(device);
}
- static AltosStateIterable record_iterable(File file) {
- FileInputStream in;
+ static AltosRecordSet record_set(File file) {
try {
- in = new FileInputStream(file);
- } catch (Exception e) {
- System.out.printf("Failed to open file '%s'\n", file);
- return null;
- }
- if (file.getName().endsWith("telem"))
- return new AltosTelemetryFile(in);
- else
- return new AltosEepromFile(in);
+ return AltosLib.record_set(file);
+ } catch (IOException ie) {
+ System.out.printf("%s\n", ie.getMessage());
+ }
+ return null;
}
static AltosReplayReader replay_file(File file) {
- AltosStateIterable states = record_iterable(file);
- if (states == null)
+ AltosRecordSet set = record_set(file);
+ if (set == null)
return null;
- return new AltosReplayReader(states.iterator(), file);
+ return new AltosReplayReader(set, file);
}
- static boolean process_graph(File file) {
- AltosStateIterable states = record_iterable(file);
- if (states == null)
+ private static boolean graph_file(TeleGPS telegps, AltosRecordSet set, File file) {
+ if (set == null)
return false;
+ if (!set.valid()) {
+ JOptionPane.showMessageDialog(telegps,
+ String.format("Failed to parse file %s", file),
+ "Graph Failed",
+ JOptionPane.ERROR_MESSAGE);
+ return false;
+ }
try {
- new TeleGPSGraphUI(states, file);
- } catch (Exception e) {
+ new TeleGPSGraphUI(set, file);
+ } catch (IOException e) {
+ System.out.printf("Exception %s\n", e.toString());
+ } catch (InterruptedException e) {
+ System.out.printf("Exception %s\n", e.toString());
return false;
}
return true;
}
+ static boolean process_graph(File file) {
+ AltosRecordSet set = record_set(file);
+ return graph_file(null, set, file);
+ }
+
static boolean process_replay(File file) {
AltosReplayReader new_reader = replay_file(file);
if (new_reader == null)
return false;
- new TeleGPS(new_reader);
+ new TeleGPS(new_reader, true);
return true;
}