X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=blobdiff_plain;f=telegps%2FTeleGPS.java;h=2897e06a321cf6e0ac7a547e36c65a1e59985dc0;hp=8ff5ac2847eb580cae6f3861b3a3962dbd03ab25;hb=0d966b74f756e88e5dffa92400b105f540429262;hpb=cb23b992be8ba40c97d8988c134a814a13ccd58c diff --git a/telegps/TeleGPS.java b/telegps/TeleGPS.java index 8ff5ac28..2897e06a 100644 --- a/telegps/TeleGPS.java +++ b/telegps/TeleGPS.java @@ -24,8 +24,8 @@ import java.io.*; import java.util.concurrent.*; import java.util.*; import java.text.*; -import org.altusmetrum.altoslib_7.*; -import org.altusmetrum.altosuilib_7.*; +import org.altusmetrum.altoslib_11.*; +import org.altusmetrum.altosuilib_11.*; public class TeleGPS extends AltosUIFrame @@ -53,6 +53,7 @@ public class TeleGPS AltosFlightReader reader; TeleGPSDisplayThread thread; + boolean idle_mode; JMenuBar menu_bar; @@ -71,7 +72,7 @@ public class TeleGPS JTabbedPane pane; - AltosUIMap map; + AltosUIMap map; TeleGPSInfo gps_info; TeleGPSState gps_state; AltosInfoTable info_table; @@ -186,12 +187,10 @@ public class TeleGPS 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(), @@ -221,9 +220,51 @@ public class TeleGPS } } + 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); @@ -373,7 +414,6 @@ public class TeleGPS public void actionPerformed(ActionEvent e) { int rate = rates.rate(); try { - System.out.printf("set rate %d\n", rate); reader.set_telemetry_rate(rate); } catch (TimeoutException te) { } catch (InterruptedException ie) { @@ -398,7 +438,8 @@ public class TeleGPS } - 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); @@ -408,8 +449,13 @@ public class TeleGPS 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); + } } } @@ -481,8 +527,6 @@ public class TeleGPS bag = getContentPane(); bag.setLayout(new GridBagLayout()); - GridBagConstraints c = new GridBagConstraints(); - setTitle("TeleGPS"); menu_bar = new JMenuBar(); @@ -492,25 +536,16 @@ public class TeleGPS monitor_menu = make_menu("Monitor", monitor_menu_entries); device_menu = make_menu("Device", device_menu_entries); + set_inset(3); frequencies = new AltosUIFreqList(); frequencies.setEnabled(false); - c.gridx = 0; - c.gridy = 0; - c.fill = GridBagConstraints.NONE; - c.anchor = GridBagConstraints.WEST; - c.weightx = 0; - c.gridwidth = 1; - bag.add(frequencies, c); + bag.add(frequencies, constraints (0, 1)); rates = new AltosUIRateList(); rates.setEnabled(false); - c.gridx = 1; - c.gridy = 0; - c.fill = GridBagConstraints.NONE; - c.anchor = GridBagConstraints.WEST; - c.weightx = 0; - c.gridwidth = 1; - bag.add(rates, c); + bag.add(rates, constraints(1, 1)); + next_row(); + set_inset(0); displays = new LinkedList(); @@ -518,13 +553,9 @@ public class TeleGPS /* TeleGPS status is always visible */ telegps_status = new TeleGPSStatus(); - c.gridx = 0; - c.gridy = 1; - c.fill = GridBagConstraints.HORIZONTAL; - c.weightx = 1; - c.gridwidth = 2; - bag.add(telegps_status, c); - c.gridwidth = 1; + bag.add(telegps_status, constraints(0, 3, GridBagConstraints.HORIZONTAL)); + next_row(); + displays.add(telegps_status); @@ -534,13 +565,7 @@ public class TeleGPS pane = new JTabbedPane(); /* Make the tabbed pane use the rest of the window space */ - c.gridx = 0; - c.gridy = 2; - c.fill = GridBagConstraints.BOTH; - c.weightx = 1; - c.weighty = 1; - c.gridwidth = 2; - bag.add(pane, c); + bag.add(pane, constraints(0, 3, GridBagConstraints.BOTH)); map = new AltosUIMap(); pane.add(map.getName(), map); @@ -576,9 +601,9 @@ public class TeleGPS 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) { @@ -624,7 +649,7 @@ public class TeleGPS if (new_reader == null) return false; - new TeleGPS(new_reader); + new TeleGPS(new_reader, true); return true; } @@ -651,7 +676,6 @@ public class TeleGPS public static void help(int code) { System.out.printf("Usage: altosui [OPTION]... [FILE]...\n"); System.out.printf(" Options:\n"); - System.out.printf(" --fetchmaps \tpre-fetch maps for site map view\n"); System.out.printf(" --replay \t\trelive the glory of past flights \n"); System.out.printf(" --graph \t\tgraph a flight\n"); System.out.printf(" --csv\tgenerate comma separated output for spreadsheets, etc\n"); @@ -676,20 +700,7 @@ public class TeleGPS for (int i = 0; i < args.length; i++) { if (args[i].equals("--help")) help(0); - else if (args[i].equals("--fetchmaps")) { - if (args.length < i + 3) { - help(1); - } else { - try { - double lat = AltosParse.parse_double_locale(args[i+1]); - double lon = AltosParse.parse_double_locale(args[i+2]); - AltosUIMap.prefetch_maps(lat, lon); - } catch (ParseException e) { - System.out.printf("Can't parse number %s\n", e.toString()); - } - i += 2; - } - } else if (args[i].equals("--replay")) + else if (args[i].equals("--replay")) process = process_replay; else if (args[i].equals("--kml")) process = process_kml;