diff options
Diffstat (limited to 'altosui')
-rw-r--r-- | altosui/.gitignore | 1 | ||||
-rw-r--r-- | altosui/AltosIgnite.java | 195 | ||||
-rw-r--r-- | altosui/AltosIgniteUI.java | 7 | ||||
-rw-r--r-- | altosui/AltosInfoTable.java | 34 | ||||
-rw-r--r-- | altosui/AltosSerial.java | 16 | ||||
-rw-r--r-- | altosui/Makefile.am | 1 | ||||
-rw-r--r-- | altosui/altos-windows.nsi | 3 | ||||
-rw-r--r-- | altosui/libaltos/libaltos.c | 4 |
8 files changed, 49 insertions, 212 deletions
diff --git a/altosui/.gitignore b/altosui/.gitignore index 6d65611f..6d2d8c23 100644 --- a/altosui/.gitignore +++ b/altosui/.gitignore @@ -5,6 +5,7 @@ fat/ Manifest.txt Manifest-fat.txt AltosVersion.java +Info.plist libaltosJNI classes altosui diff --git a/altosui/AltosIgnite.java b/altosui/AltosIgnite.java deleted file mode 100644 index f84db0b9..00000000 --- a/altosui/AltosIgnite.java +++ /dev/null @@ -1,195 +0,0 @@ -/* - * Copyright © 2010 Keith Packard <keithp@keithp.com> - * - * 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. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. - */ - -package altosui; - -import java.io.*; -import java.util.concurrent.*; -import java.awt.*; -import java.awt.event.*; -import javax.swing.*; -import javax.swing.filechooser.FileNameExtensionFilter; -import javax.swing.table.*; -import javax.swing.event.*; -import org.altusmetrum.AltosLib.*; - -public class AltosIgnite { - AltosDevice device; - AltosSerial serial; - boolean remote; - boolean serial_started; - final static int None = 0; - final static int Apogee = 1; - final static int Main = 2; - - final static int Unknown = 0; - final static int Ready = 1; - final static int Active = 2; - final static int Open = 3; - - private void start_serial() throws InterruptedException, TimeoutException { - serial_started = true; - if (remote) - serial.start_remote(); - } - - private void stop_serial() throws InterruptedException { - if (!serial_started) - return; - serial_started = false; - if (serial == null) - return; - if (remote) - serial.stop_remote(); - } - - class string_ref { - String value; - - public String get() { - return value; - } - public void set(String i) { - value = i; - } - public string_ref() { - value = null; - } - } - - private boolean get_string(String line, String label, string_ref s) { - if (line.startsWith(label)) { - String quoted = line.substring(label.length()).trim(); - - if (quoted.startsWith("\"")) - quoted = quoted.substring(1); - if (quoted.endsWith("\"")) - quoted = quoted.substring(0,quoted.length()-1); - s.set(quoted); - return true; - } else { - return false; - } - } - - private int status(String status_name) { - if (status_name.equals("unknown")) - return Unknown; - if (status_name.equals("ready")) - return Ready; - if (status_name.equals("active")) - return Active; - if (status_name.equals("open")) - return Open; - return Unknown; - } - - public int status(int igniter) throws InterruptedException, TimeoutException { - int status = Unknown; - if (serial == null) - return status; - string_ref status_name = new string_ref(); - try { - start_serial(); - serial.printf("t\n"); - for (;;) { - String line = serial.get_reply(5000); - if (line == null) - throw new TimeoutException(); - String[] items = line.split("\\s+"); - - if (items.length < 4) - continue; - - if (!items[0].equals("Igniter:")) - continue; - - if (!items[2].equals("Status:")) - continue; - - if (items[1].equals("drogue")) { - if (igniter == Apogee) - status = status(items[3]); - } else if (items[1].equals("main")) { - if (igniter == Main) - status = status(items[3]); - break; - } - } - } finally { - stop_serial(); - } - return status; - } - - public static String status_string(int status) { - switch (status) { - case Unknown: return "Unknown"; - case Ready: return "Ready"; - case Active: return "Active"; - case Open: return "Open"; - default: return "Unknown"; - } - } - - public void fire(int igniter) { - if (serial == null) - return; - try { - start_serial(); - switch (igniter) { - case Main: - serial.printf("i DoIt main\n"); - break; - case Apogee: - serial.printf("i DoIt drogue\n"); - break; - } - } catch (InterruptedException ie) { - } catch (TimeoutException te) { - } finally { - try { - stop_serial(); - } catch (InterruptedException ie) { - } - } - } - - public void close() { - try { - stop_serial(); - } catch (InterruptedException ie) { - } - serial.close(); - serial = null; - } - - public void set_frame(Frame frame) { - serial.set_frame(frame); - } - - public AltosIgnite(AltosDevice in_device) - throws FileNotFoundException, AltosSerialInUseException, TimeoutException, InterruptedException { - - device = in_device; - serial = new AltosSerial(device); - remote = false; - - if (!device.matchProduct(Altos.product_altimeter)) - remote = true; - } -}
\ No newline at end of file diff --git a/altosui/AltosIgniteUI.java b/altosui/AltosIgniteUI.java index 076d99b2..78eba8e6 100644 --- a/altosui/AltosIgniteUI.java +++ b/altosui/AltosIgniteUI.java @@ -72,12 +72,15 @@ public class AltosIgniteUI public void run () { try { - ignite = new AltosIgnite(device); + AltosSerial serial = new AltosSerial(device); + serial.set_frame(owner); + ignite = new AltosIgnite(serial, + !device.matchProduct(Altos.product_altimeter)); + } catch (Exception e) { send_exception(e); return; } - ignite.set_frame(owner); for (;;) { Runnable r; diff --git a/altosui/AltosInfoTable.java b/altosui/AltosInfoTable.java index aa6a6d4e..c1400976 100644 --- a/altosui/AltosInfoTable.java +++ b/altosui/AltosInfoTable.java @@ -40,18 +40,38 @@ public class AltosInfoTable extends JTable { return (infoValueMetrics.getHeight() + infoValueMetrics.getLeading()) * 18 / 10; } + int text_width(String t) { + FontMetrics infoValueMetrics = getFontMetrics(Altos.table_value_font); + + return infoValueMetrics.stringWidth(t); + } + + void set_layout() { + setRowHeight(desired_row_height()); + for (int i = 0; i < info_columns * 2; i++) + { + TableColumn column = getColumnModel().getColumn(i); + + if ((i & 1) == 0) + column.setPreferredWidth(text_width(" Satellites Visible ")); + else + column.setPreferredWidth(text_width(" 179°59.99999' ")); + } + } + public AltosInfoTable() { super(new AltosFlightInfoTableModel(info_rows, info_columns)); model = (AltosFlightInfoTableModel) getModel(); setFont(Altos.table_value_font); setAutoResizeMode(AUTO_RESIZE_ALL_COLUMNS); setShowGrid(true); - setRowHeight(desired_row_height()); + set_layout(); doLayout(); } public void set_font() { setFont(Altos.table_value_font); + set_layout(); doLayout(); } @@ -95,13 +115,8 @@ public class AltosInfoTable extends JTable { if (state == null) return; info_reset(); - info_add_row(0, "Rocket state", "%s", state.data.state()); - info_add_row(0, "Callsign", "%s", state.data.callsign); - info_add_row(0, "Rocket serial", "%6d", state.data.serial); - info_add_row(0, "Rocket flight", "%6d", state.data.flight); - - info_add_row(0, "RSSI", "%6d dBm", state.data.rssi); - info_add_row(0, "CRC Errors", "%6d", crc_errors); + info_add_row(0, "Altitude", "%6.0f m", state.altitude); + info_add_row(0, "Pad altitude", "%6.0f m", state.ground_altitude); info_add_row(0, "Height", "%6.0f m", state.height); info_add_row(0, "Max height", "%6.0f m", state.max_height); info_add_row(0, "Acceleration", "%8.1f m/s²", state.acceleration); @@ -114,7 +129,8 @@ public class AltosInfoTable extends JTable { info_add_row(0, "Drogue", "%9.2f V", state.drogue_sense); if (state.main_sense != AltosRecord.MISSING) info_add_row(0, "Main", "%9.2f V", state.main_sense); - info_add_row(0, "Pad altitude", "%6.0f m", state.ground_altitude); + info_add_row(0, "CRC Errors", "%6d", crc_errors); + if (state.gps == null || !state.gps.connected) { info_add_row(1, "GPS", "not available"); } else { diff --git a/altosui/AltosSerial.java b/altosui/AltosSerial.java index c4e9c697..6cee1609 100644 --- a/altosui/AltosSerial.java +++ b/altosui/AltosSerial.java @@ -41,7 +41,7 @@ import libaltosJNI.*; * threads. */ -public class AltosSerial extends AltosLink implements Runnable { +public class AltosSerial extends AltosLink { static java.util.List<String> devices_opened = Collections.synchronizedList(new LinkedList<String>()); @@ -54,13 +54,19 @@ public class AltosSerial extends AltosLink implements Runnable { Frame frame; public int getchar() { + if (altos == null) + return ERROR; return libaltos.altos_getchar(altos, 0); } public void flush_output() { super.flush_output(); if (altos != null) { - libaltos.altos_flush(altos); + if (libaltos.altos_flush(altos) != 0) { + libaltos.altos_close(altos); + altos = null; + abort_reply(); + } } } @@ -155,7 +161,11 @@ public class AltosSerial extends AltosLink implements Runnable { private void putc(char c) { if (altos != null) - libaltos.altos_putchar(altos, c); + if (libaltos.altos_putchar(altos, c) != 0) { + libaltos.altos_close(altos); + altos = null; + abort_reply(); + } } public void print(String data) { diff --git a/altosui/Makefile.am b/altosui/Makefile.am index 1c8ea491..19db6698 100644 --- a/altosui/Makefile.am +++ b/altosui/Makefile.am @@ -55,7 +55,6 @@ altosui_JAVA = \ AltosHexfile.java \ Altos.java \ AltosIdleMonitorUI.java \ - AltosIgnite.java \ AltosIgniteUI.java \ AltosLaunch.java \ AltosLaunchUI.java \ diff --git a/altosui/altos-windows.nsi b/altosui/altos-windows.nsi index 92c985a9..986919d4 100644 --- a/altosui/altos-windows.nsi +++ b/altosui/altos-windows.nsi @@ -1,6 +1,7 @@ !addplugindir Instdrv/NSIS/Plugins ; Definitions for Java 1.6 Detection !define JRE_VERSION "1.6" +!define JRE_ALTERNATE "1.7" !define JRE_URL "http://javadl.sun.com/webapps/download/AutoDL?BundleId=52247&/jre-6u27-windows-i586-p.exe" !define PRODUCT_NAME "Altus Metrum Windows Software" @@ -42,6 +43,8 @@ Function DetectJRE "CurrentVersion" StrCmp $2 ${JRE_VERSION} done + StrCmp $2 ${JRE_ALTERNATE} done + Call GetJRE done: diff --git a/altosui/libaltos/libaltos.c b/altosui/libaltos/libaltos.c index 1cc27cbe..515432f9 100644 --- a/altosui/libaltos/libaltos.c +++ b/altosui/libaltos/libaltos.c @@ -221,7 +221,7 @@ altos_flush(struct altos_file *file) #endif if (ret < 0) { altos_set_last_posix_error(); - return -errno; + return -last_error.code; } if (ret) { memmove(file->out_data, file->out_data + ret, @@ -247,7 +247,7 @@ altos_putchar(struct altos_file *file, char c) ret = 0; if (file->out_used == USB_BUF_SIZE) ret = altos_flush(file); - return 0; + return ret; } #ifdef USE_POLL |