X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=blobdiff_plain;f=telegps%2FTeleGPS.java;h=cf2cbd4fefce4e114fb8605cbdda3a2a5ff535cb;hp=078f40618e3914a39abcc0879c2529f96541372f;hb=238e56e0f6ab2f623e0faf25298b38dc3a4aff74;hpb=6683146168216aacdc0842934cec1fb48ea03518 diff --git a/telegps/TeleGPS.java b/telegps/TeleGPS.java index 078f4061..cf2cbd4f 100644 --- a/telegps/TeleGPS.java +++ b/telegps/TeleGPS.java @@ -3,7 +3,8 @@ * * 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 @@ -24,8 +25,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 +54,7 @@ public class TeleGPS AltosFlightReader reader; TeleGPSDisplayThread thread; + boolean idle_mode; JMenuBar menu_bar; @@ -71,7 +73,7 @@ public class TeleGPS JTabbedPane pane; - AltosUIMapNew map; + AltosUIMap map; TeleGPSInfo gps_info; TeleGPSState gps_state; AltosInfoTable info_table; @@ -173,7 +175,7 @@ public class TeleGPS } void load_maps() { - new AltosUIMapPreloadNew(this); + new AltosUIMapPreload(this); } void disconnect() { @@ -186,12 +188,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 +221,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 +415,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 +439,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 +450,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); + } } } @@ -521,7 +568,7 @@ public class TeleGPS /* 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); @@ -555,9 +602,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) { @@ -567,16 +614,23 @@ public class TeleGPS static AltosStateIterable record_iterable(File file) { FileInputStream in; - 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); + if (file.getName().endsWith("telem")) { + try { + in = new FileInputStream(file); + return new AltosTelemetryFile(in); + } catch (Exception e) { + System.out.printf("Failed to open file '%s'\n", file); + } + } else { + + try { + AltosEepromFile f = new AltosEepromFile(new FileReader(file)); + return f; + } catch (Exception e) { + System.out.printf("Failed to open file '%s'\n", file); + } + } + return null; } static AltosReplayReader replay_file(File file) { @@ -603,7 +657,7 @@ public class TeleGPS if (new_reader == null) return false; - new TeleGPS(new_reader); + new TeleGPS(new_reader, true); return true; }