From 2007288da8a83e3aa925e11cc196f1c65aab2e5c Mon Sep 17 00:00:00 2001 From: Bdale Garbee Date: Thu, 5 Aug 2010 15:00:15 -0400 Subject: working on java packaging details --- ao-tools/altosui/Makefile | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/Makefile b/ao-tools/altosui/Makefile index 541b89e3..63359fbb 100644 --- a/ao-tools/altosui/Makefile +++ b/ao-tools/altosui/Makefile @@ -1,6 +1,6 @@ .SUFFIXES: .java .class -CLASSPATH=classes:./* +CLASSPATH=classes:./*:/usr/share/java/* CLASSFILES=\ Altos.class \ AltosChannelMenu.class \ @@ -31,16 +31,17 @@ CLASSFILES=\ AltosDeviceDialog.class \ AltosVoice.class -FREETTSSRC=/home/keithp/src/freetts/freetts-1.2.2 -FREETTSLIB=$(FREETTSSRC)/lib -FREETTSJAR= \ - cmudict04.jar \ - cmulex.jar \ - cmu_time_awb.jar \ - cmutimelex.jar \ - cmu_us_kal.jar \ - en_us.jar \ - freetts.jar +#FREETTSSRC=/home/keithp/src/freetts/freetts-1.2.2 +#FREETTSLIB=$(FREETTSSRC)/lib +#FREETTSJAR=/usr/share/java/freetts.jar +#FREETTSJAR= \ +# cmudict04.jar \ +# cmulex.jar \ +# cmu_time_awb.jar \ +# cmutimelex.jar \ +# cmu_us_kal.jar \ +# en_us.jar \ +# freetts.jar JAVAFLAGS=-Xlint:unchecked -Xlint:deprecation @@ -66,14 +67,14 @@ altosui.jar: classes/altosui classes/libaltosJNI $(FREETTSJAR) $(CLASSFILES) Man classes/altosui: mkdir -p classes - ln -s .. classes/altosui + ln -sf .. classes/altosui classes/libaltosJNI: mkdir -p classes - ln -s ../../libaltos/libaltosJNI classes/libaltosJNI + ln -sf ../../libaltos/libaltosJNI classes/libaltosJNI -$(FREETTSJAR): - ln -s $(FREETTSLIB)/$@ . +#$(FREETTSJAR): +# ln -s $(FREETTSLIB)/$@ . ifeq ($(OS),Darwin) RESOURCES=altosui.jar $(FREETTSJAR) ../libaltos/libaltos.dylib @@ -92,6 +93,6 @@ altosui: endif clean: - rm -f *.class $(FREETTSJAR) altosui.jar + rm -f *.class altosui.jar rm -f AltosUI.app/Contents/Resources/Java/* rm -rf classes -- cgit v1.2.3 From 7f8d7978606abe544b1b9b6065c5480ed813b8ec Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 23 Aug 2010 11:53:19 -0700 Subject: altosui: Add .ihx file reading code and stub out flashing UI Signed-off-by: Keith Packard --- ao-tools/altosui/AltosFlash.java | 78 ++++++++++++ ao-tools/altosui/AltosHexfile.java | 248 +++++++++++++++++++++++++++++++++++++ ao-tools/altosui/AltosUI.java | 14 +++ ao-tools/altosui/Makefile | 2 + 4 files changed, 342 insertions(+) create mode 100644 ao-tools/altosui/AltosFlash.java create mode 100644 ao-tools/altosui/AltosHexfile.java (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosFlash.java b/ao-tools/altosui/AltosFlash.java new file mode 100644 index 00000000..ac9e81df --- /dev/null +++ b/ao-tools/altosui/AltosFlash.java @@ -0,0 +1,78 @@ +/* + * Copyright © 2010 Keith Packard + * + * 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.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.filechooser.FileNameExtensionFilter; +import javax.swing.table.*; +import java.io.*; +import java.util.*; +import java.text.*; +import java.util.prefs.*; +import java.util.concurrent.LinkedBlockingQueue; + +import altosui.AltosHexfile; + +public class AltosFlash implements Runnable { + File file; + FileInputStream input; + Thread thread; + AltosHexfile image; + JFrame frame; + + public void run() { + try { + image = new AltosHexfile(input); + System.out.printf("read file start %d length %d\n", + image.address, image.data.length); + } catch (IOException e) { + JOptionPane.showMessageDialog(frame, + file, + e.getMessage(), + JOptionPane.ERROR_MESSAGE); + } + } + + public AltosFlash(JFrame in_frame) { + frame = in_frame; + + JFileChooser hexfile_chooser = new JFileChooser(); + + hexfile_chooser.setDialogTitle("Select Flash Image"); + hexfile_chooser.setFileFilter(new FileNameExtensionFilter("Flash Image", "ihx")); + int returnVal = hexfile_chooser.showOpenDialog(frame); + + if (returnVal == JFileChooser.APPROVE_OPTION) { + file = hexfile_chooser.getSelectedFile(); + if (file != null) { + try { + input = new FileInputStream(file); + thread = new Thread(this); + thread.start(); + } catch (FileNotFoundException ee) { + JOptionPane.showMessageDialog(frame, + file, + "Cannot open flash file", + JOptionPane.ERROR_MESSAGE); + } + } + } + } +} \ No newline at end of file diff --git a/ao-tools/altosui/AltosHexfile.java b/ao-tools/altosui/AltosHexfile.java new file mode 100644 index 00000000..c7078877 --- /dev/null +++ b/ao-tools/altosui/AltosHexfile.java @@ -0,0 +1,248 @@ +/* + * Copyright © 2010 Keith Packard + * + * 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.lang.*; +import java.io.*; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.LinkedList; +import java.util.Iterator; +import java.util.Arrays; + +class HexFileInputStream extends PushbackInputStream { + public int line; + + public HexFileInputStream(FileInputStream o) { + super(new BufferedInputStream(o)); + line = 1; + } + + public int read() throws IOException { + int c = super.read(); + if (c == '\n') + line++; + return c; + } + + public void unread(int c) throws IOException { + if (c == '\n') + line--; + if (c != -1) + super.unread(c); + } +} + +class HexRecord implements Comparable { + public int address; + public int type; + public byte checksum; + public byte[] data; + + static final int NORMAL = 0; + static final int EOF = 1; + static final int EXTENDED_ADDRESS = 2; + + enum read_state { + marker, + length, + address, + type, + data, + checksum, + newline, + white, + done, + } + + boolean ishex(int c) { + if ('0' <= c && c <= '9') + return true; + if ('a' <= c && c <= 'f') + return true; + if ('A' <= c && c <= 'F') + return true; + return false; + } + + boolean isspace(int c) { + switch (c) { + case ' ': + case '\t': + return true; + } + return false; + } + + int fromhex(int c) { + if ('0' <= c && c <= '9') + return c - '0'; + if ('a' <= c && c <= 'f') + return c - 'a' + 10; + if ('A' <= c && c <= 'F') + return c - 'A' + 10; + return -1; + } + + public byte checksum() { + byte got = 0; + + got += data.length; + got += (address >> 8) & 0xff; + got += (address ) & 0xff; + got += type; + for (int i = 0; i < data.length; i++) + got += data[i]; + return (byte) (-got); + } + + public int compareTo(Object other) { + HexRecord o = (HexRecord) other; + return address - o.address; + } + + public String toString() { + return String.format("%04x: %02x (%d)", address, type, data.length); + } + + public HexRecord(HexFileInputStream input) throws IOException { + read_state state = read_state.marker; + int nhexbytes = 0; + int hex = 0; + int ndata = 0; + byte got_checksum; + + while (state != read_state.done) { + int c = input.read(); + if (c < 0 && state != read_state.white) + throw new IOException(String.format("%d: Unexpected EOF", input.line)); + if (c == ' ') + continue; + switch (state) { + case marker: + if (c != ':') + throw new IOException("Missing ':'"); + state = read_state.length; + nhexbytes = 2; + hex = 0; + break; + case length: + case address: + case type: + case data: + case checksum: + if(!ishex(c)) + throw new IOException(String.format("Non-hex char '%c'", c)); + hex = hex << 4 | fromhex(c); + --nhexbytes; + if (nhexbytes != 0) + break; + + switch (state) { + case length: + data = new byte[hex]; + state = read_state.address; + nhexbytes = 4; + break; + case address: + address = hex; + state = read_state.type; + nhexbytes = 2; + break; + case type: + type = hex; + if (data.length > 0) + state = read_state.data; + else + state = read_state.checksum; + nhexbytes = 2; + ndata = 0; + break; + case data: + data[ndata] = (byte) hex; + ndata++; + nhexbytes = 2; + if (ndata == data.length) + state = read_state.checksum; + break; + case checksum: + checksum = (byte) hex; + state = read_state.newline; + break; + default: + break; + } + hex = 0; + break; + case newline: + if (c != '\n' && c != '\r') + throw new IOException("Missing newline"); + state = read_state.white; + break; + case white: + if (!isspace(c)) { + input.unread(c); + state = read_state.done; + } + break; + case done: + break; + } + } + got_checksum = checksum(); + if (got_checksum != checksum) + throw new IOException(String.format("Invalid checksum (read 0x%02x computed 0x%02x)\n", + checksum, got_checksum)); + } +} + +public class AltosHexfile { + public int address; + public byte[] data; + + public AltosHexfile(FileInputStream file) throws IOException { + HexFileInputStream input = new HexFileInputStream(file); + LinkedList record_list = new LinkedList(); + boolean done = false; + + while (!done) { + HexRecord record = new HexRecord(input); + + if (record.type == HexRecord.EOF) + done = true; + else + record_list.add(record); + } + HexRecord[] records = record_list.toArray(new HexRecord[0]); + Arrays.sort(records); + if (records.length > 0) { + int base = records[0].address; + int bound = records[records.length-1].address + + records[records.length-1].data.length; + + data = new byte[bound - base]; + address = base; + Arrays.fill(data, (byte) 0xff); + + /* Paint the records into the new array */ + for (int i = 0; i < records.length; i++) { + for (int j = 0; j < records[i].data.length; j++) + data[records[i].address - base + j] = records[i].data[j]; + } + } + } +} \ No newline at end of file diff --git a/ao-tools/altosui/AltosUI.java b/ao-tools/altosui/AltosUI.java index 49d1f11a..565866ea 100644 --- a/ao-tools/altosui/AltosUI.java +++ b/ao-tools/altosui/AltosUI.java @@ -41,6 +41,7 @@ import altosui.AltosVoice; import altosui.AltosFlightStatusTableModel; import altosui.AltosFlightInfoTableModel; import altosui.AltosChannelMenu; +import altosui.AltosFlash; import libaltosJNI.*; @@ -457,6 +458,11 @@ public class AltosUI extends JFrame { void ConfigureTeleMetrum() { new AltosConfig(AltosUI.this); } + + void FlashImage() { + new AltosFlash(AltosUI.this); + } + /* * Open an existing telemetry file and replay it in realtime */ @@ -589,6 +595,14 @@ public class AltosUI extends JFrame { }); menu.add(item); + item = new JMenuItem("Flash Image",KeyEvent.VK_F); + item.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + FlashImage(); + } + }); + menu.add(item); + item = new JMenuItem("Quit",KeyEvent.VK_Q); item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, ActionEvent.CTRL_MASK)); diff --git a/ao-tools/altosui/Makefile b/ao-tools/altosui/Makefile index 541b89e3..ebe59644 100644 --- a/ao-tools/altosui/Makefile +++ b/ao-tools/altosui/Makefile @@ -13,10 +13,12 @@ CLASSFILES=\ AltosEepromReader.class \ AltosEepromRecord.class \ AltosFile.class \ + AltosFlash.class \ AltosFlightInfoTableModel.class \ AltosFlightStatusTableModel.class \ AltosGPS.class \ AltosGreatCircle.class \ + AltosHexfile.class \ AltosLog.class \ AltosParse.class \ AltosPreferences.class \ -- cgit v1.2.3 From ebeb13688a9a5442c838641ede6ba0dc92c9a1a4 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 23 Aug 2010 14:32:58 -0700 Subject: altosui: Add debug dongle API, split flash UI out Create an API to talk through the debug port on another AltOS device. Split the flash UI out from the flash implementation so that a command line flash utility can be written. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosConfigUI.java | 5 +- ao-tools/altosui/AltosDebug.java | 231 +++++++++++++++++++++++++++++++++ ao-tools/altosui/AltosFlash.java | 60 ++++----- ao-tools/altosui/AltosFlashUI.java | 92 +++++++++++++ ao-tools/altosui/AltosHexfile.java | 6 + ao-tools/altosui/AltosRomconfig.java | 110 ++++++++++++++++ ao-tools/altosui/AltosRomconfigUI.java | 160 +++++++++++++++++++++++ ao-tools/altosui/AltosSerial.java | 4 + ao-tools/altosui/AltosUI.java | 4 +- ao-tools/altosui/Makefile | 4 + 10 files changed, 640 insertions(+), 36 deletions(-) create mode 100644 ao-tools/altosui/AltosDebug.java create mode 100644 ao-tools/altosui/AltosFlashUI.java create mode 100644 ao-tools/altosui/AltosRomconfig.java create mode 100644 ao-tools/altosui/AltosRomconfigUI.java (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosConfigUI.java b/ao-tools/altosui/AltosConfigUI.java index 1d8c579a..6825b9a9 100644 --- a/ao-tools/altosui/AltosConfigUI.java +++ b/ao-tools/altosui/AltosConfigUI.java @@ -44,7 +44,10 @@ import altosui.AltosFlightInfoTableModel; import libaltosJNI.*; -public class AltosConfigUI extends JDialog implements ActionListener, ItemListener, DocumentListener { +public class AltosConfigUI + extends JDialog + implements ActionListener, ItemListener, DocumentListener +{ Container pane; Box box; diff --git a/ao-tools/altosui/AltosDebug.java b/ao-tools/altosui/AltosDebug.java new file mode 100644 index 00000000..7bd3a5cd --- /dev/null +++ b/ao-tools/altosui/AltosDebug.java @@ -0,0 +1,231 @@ +/* + * Copyright © 2010 Keith Packard + * + * 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.lang.*; +import java.io.*; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.LinkedList; +import java.util.Iterator; +import altosui.AltosSerial; +import altosui.AltosRomconfig; + +public class AltosDebug extends AltosSerial { + + static final byte WR_CONFIG = 0x1d; + static final byte RD_CONFIG = 0x24; + static final byte CONFIG_TIMERS_OFF = (1 << 3); + static final byte CONFIG_DMA_PAUSE = (1 << 2); + static final byte CONFIG_TIMER_SUSPEND = (1 << 1); + static final byte SET_FLASH_INFO_PAGE = (1 << 0); + + static final byte GET_PC = 0x28; + static final byte READ_STATUS = 0x34; + static final byte STATUS_CHIP_ERASE_DONE = (byte) (1 << 7); + static final byte STATUS_PCON_IDLE = (1 << 6); + static final byte STATUS_CPU_HALTED = (1 << 5); + static final byte STATUS_POWER_MODE_0 = (1 << 4); + static final byte STATUS_HALT_STATUS = (1 << 3); + static final byte STATUS_DEBUG_LOCKED = (1 << 2); + static final byte STATUS_OSCILLATOR_STABLE = (1 << 1); + static final byte STATUS_STACK_OVERFLOW = (1 << 0); + + static final byte SET_HW_BRKPNT = 0x3b; + static byte HW_BRKPNT_N(byte n) { return (byte) ((n) << 3); } + static final byte HW_BRKPNT_N_MASK = (0x3 << 3); + static final byte HW_BRKPNT_ENABLE = (1 << 2); + + static final byte HALT = 0x44; + static final byte RESUME = 0x4c; + static byte DEBUG_INSTR(byte n) { return (byte) (0x54|(n)); } + static final byte STEP_INSTR = 0x5c; + static byte STEP_REPLACE(byte n) { return (byte) (0x64|(n)); } + static final byte GET_CHIP_ID = 0x68; + + + static boolean ishex(int c) { + if ('0' <= c && c <= '9') + return true; + if ('a' <= c && c <= 'f') + return true; + if ('A' <= c && c <= 'F') + return true; + return false; + } + + static boolean ishex(String s) { + for (int i = 0; i < s.length(); i++) + if (!ishex(s.charAt(i))) + return false; + return true; + } + static boolean isspace(int c) { + switch (c) { + case ' ': + case '\t': + return true; + } + return false; + } + + static int fromhex(int c) { + if ('0' <= c && c <= '9') + return c - '0'; + if ('a' <= c && c <= 'f') + return c - 'a' + 10; + if ('A' <= c && c <= 'F') + return c - 'A' + 10; + return -1; + } + + boolean debug_mode; + + void ensure_debug_mode() { + if (!debug_mode) { + printf("D\n"); + debug_mode = true; + } + } + + /* + * Write target memory + */ + public void write_memory(int address, byte[] bytes) { + ensure_debug_mode(); + printf("O %x %x\n", bytes.length, address); + for (int i = 0; i < bytes.length; i++) + printf("%02x", bytes[i]); + } + + /* + * Read target memory + */ + public byte[] read_memory(int address, int length) + throws IOException, InterruptedException { + byte[] data = new byte[length]; + + flush_reply(); + ensure_debug_mode(); + printf("I %x %x\n", length, address); + int i = 0; + while (i < length) { + String line = get_reply().trim(); + if (!ishex(line) || line.length() % 2 != 0) + throw new IOException( + String.format + ("Invalid reply \"%s\"", line)); + int this_time = line.length() / 2; + for (int j = 0; j < this_time; j++) + data[j] = (byte) ((fromhex(line.charAt(j*2)) << 4) + + fromhex(line.charAt(j*2+1))); + i += this_time; + } + + return data; + } + + /* + * Write raw bytes to the debug link using the 'P' command + */ + public void write_bytes(byte[] bytes) throws IOException { + int i = 0; + ensure_debug_mode(); + while (i < bytes.length) { + int this_time = bytes.length - i; + if (this_time > 8) + this_time = 0; + printf("P"); + for (int j = 0; j < this_time; j++) + printf(" %02x", bytes[i+j]); + printf("\n"); + i += this_time; + } + } + + public void write_byte(byte b) throws IOException { + byte[] bytes = { b }; + write_bytes(bytes); + } + + /* + * Read raw bytes from the debug link using the 'G' command + */ + public byte[] read_bytes(int length) + throws IOException, InterruptedException { + + flush_reply(); + ensure_debug_mode(); + printf("G %x\n", length); + int i = 0; + byte[] data = new byte[length]; + while (i < length) { + String line = get_reply().trim(); + String tokens[] = line.split("\\s+"); + for (int j = 0; j < tokens.length; j++) { + if (!ishex(tokens[j]) || + tokens[j].length() != 2) + throw new IOException( + String.format + ("Invalid read_bytes reply \"%s\"", line)); + try { + data[i + j] = (byte) Integer.parseInt(tokens[j], 16); + } catch (NumberFormatException ne) { + throw new IOException( + String.format + ("Invalid read_bytes reply \"%s\"", line)); + } + } + i += tokens.length; + } + return data; + } + + public byte read_status() throws IOException, InterruptedException { + write_byte(READ_STATUS); + return read_bytes(2)[0]; + } + + public boolean check_connection() throws IOException, InterruptedException { + byte reply = read_status(); + System.out.printf("status %x\n", reply); + if ((reply & STATUS_CHIP_ERASE_DONE) == 0) + return false; + if ((reply & STATUS_PCON_IDLE) != 0) + return false; + if ((reply & STATUS_POWER_MODE_0) == 0) + return false; + return true; + } + + public AltosRomconfig romconfig() { + try { + byte[] bytes = read_memory(0xa0, 10); + return new AltosRomconfig(bytes, 0); + } catch (IOException ie) { + } catch (InterruptedException ie) { + } + return new AltosRomconfig(); + } + + /* + * Reset target + */ + public void reset() { + printf ("R\n"); + } +} \ No newline at end of file diff --git a/ao-tools/altosui/AltosFlash.java b/ao-tools/altosui/AltosFlash.java index ac9e81df..bab60c1f 100644 --- a/ao-tools/altosui/AltosFlash.java +++ b/ao-tools/altosui/AltosFlash.java @@ -30,49 +30,43 @@ import java.util.concurrent.LinkedBlockingQueue; import altosui.AltosHexfile; -public class AltosFlash implements Runnable { +public class AltosFlash { File file; FileInputStream input; Thread thread; AltosHexfile image; JFrame frame; + AltosDevice debug_dongle; + AltosDebug debug; + AltosRomconfig rom_config; - public void run() { - try { - image = new AltosHexfile(input); - System.out.printf("read file start %d length %d\n", - image.address, image.data.length); - } catch (IOException e) { - JOptionPane.showMessageDialog(frame, - file, - e.getMessage(), - JOptionPane.ERROR_MESSAGE); - } + public void flash() throws IOException, FileNotFoundException, InterruptedException { + if (!check_rom_config()) + throw new IOException("Invalid rom config settings"); + rom_config.write(image); } - public AltosFlash(JFrame in_frame) { - frame = in_frame; + public boolean check_rom_config() { + if (rom_config == null) + rom_config = debug.romconfig(); + return rom_config != null && rom_config.valid(); + } - JFileChooser hexfile_chooser = new JFileChooser(); + public void set_romconfig (AltosRomconfig romconfig) { + rom_config = romconfig; + } - hexfile_chooser.setDialogTitle("Select Flash Image"); - hexfile_chooser.setFileFilter(new FileNameExtensionFilter("Flash Image", "ihx")); - int returnVal = hexfile_chooser.showOpenDialog(frame); + public void open() throws IOException, FileNotFoundException, InterruptedException { + input = new FileInputStream(file); + image = new AltosHexfile(input); + debug.open(debug_dongle); + if (!debug.check_connection()) + throw new IOException("Debug port not connected"); + } - if (returnVal == JFileChooser.APPROVE_OPTION) { - file = hexfile_chooser.getSelectedFile(); - if (file != null) { - try { - input = new FileInputStream(file); - thread = new Thread(this); - thread.start(); - } catch (FileNotFoundException ee) { - JOptionPane.showMessageDialog(frame, - file, - "Cannot open flash file", - JOptionPane.ERROR_MESSAGE); - } - } - } + public AltosFlash(File in_file, AltosDevice in_debug_dongle) { + file = in_file; + debug_dongle = in_debug_dongle; + debug = new AltosDebug(); } } \ No newline at end of file diff --git a/ao-tools/altosui/AltosFlashUI.java b/ao-tools/altosui/AltosFlashUI.java new file mode 100644 index 00000000..5cae4756 --- /dev/null +++ b/ao-tools/altosui/AltosFlashUI.java @@ -0,0 +1,92 @@ +/* + * Copyright © 2010 Keith Packard + * + * 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.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.filechooser.FileNameExtensionFilter; +import javax.swing.table.*; +import java.io.*; +import java.util.*; +import java.text.*; +import java.util.prefs.*; +import java.util.concurrent.LinkedBlockingQueue; + +import altosui.AltosHexfile; +import altosui.AltosFlash; + +public class AltosFlashUI implements Runnable { + File file; + Thread thread; + JFrame frame; + AltosDevice debug_dongle; + AltosFlash flash; + + public void run() { + flash = new AltosFlash(file, debug_dongle); + try { + flash.open(); + if (!flash.check_rom_config()) { + AltosRomconfigUI romconfig_ui = new AltosRomconfigUI (frame); + romconfig_ui.showDialog(); + AltosRomconfig romconfig = romconfig_ui.romconfig(); + if (romconfig == null) + return; + flash.set_romconfig(romconfig); + } + flash.flash(); + } catch (FileNotFoundException ee) { + JOptionPane.showMessageDialog(frame, + "Cannot open image", + file.toString(), + JOptionPane.ERROR_MESSAGE); + return; + } catch (IOException e) { + JOptionPane.showMessageDialog(frame, + e.getMessage(), + file.toString(), + JOptionPane.ERROR_MESSAGE); + return; + } catch (InterruptedException ie) { + } + } + + public AltosFlashUI(JFrame in_frame) { + frame = in_frame; + + debug_dongle = AltosDeviceDialog.show(frame, AltosDevice.Any); + + if (debug_dongle == null) + return; + + JFileChooser hexfile_chooser = new JFileChooser(); + + hexfile_chooser.setDialogTitle("Select Flash Image"); + hexfile_chooser.setFileFilter(new FileNameExtensionFilter("Flash Image", "ihx")); + int returnVal = hexfile_chooser.showOpenDialog(frame); + + if (returnVal != JFileChooser.APPROVE_OPTION) + return; + + file = hexfile_chooser.getSelectedFile(); + + thread = new Thread(this); + thread.start(); + } +} \ No newline at end of file diff --git a/ao-tools/altosui/AltosHexfile.java b/ao-tools/altosui/AltosHexfile.java index c7078877..360e24ad 100644 --- a/ao-tools/altosui/AltosHexfile.java +++ b/ao-tools/altosui/AltosHexfile.java @@ -214,6 +214,10 @@ public class AltosHexfile { public int address; public byte[] data; + public byte get_byte(int a) { + return data[a - address]; + } + public AltosHexfile(FileInputStream file) throws IOException { HexFileInputStream input = new HexFileInputStream(file); LinkedList record_list = new LinkedList(); @@ -244,5 +248,7 @@ public class AltosHexfile { data[records[i].address - base + j] = records[i].data[j]; } } + for (int i = 0xa0; i < 0xaa; i++) + System.out.printf ("%04x: %02x\n", i, get_byte(i)); } } \ No newline at end of file diff --git a/ao-tools/altosui/AltosRomconfig.java b/ao-tools/altosui/AltosRomconfig.java new file mode 100644 index 00000000..5a2df313 --- /dev/null +++ b/ao-tools/altosui/AltosRomconfig.java @@ -0,0 +1,110 @@ +/* + * Copyright © 2010 Keith Packard + * + * 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 altosui.AltosHexfile; + +public class AltosRomconfig { + public boolean valid; + public int version; + public int check; + public int serial_number; + public int radio_calibration; + + static int get_int(byte[] bytes, int start, int len) { + int v = 0; + int o = 0; + while (len > 0) { + v = v | ((((int) bytes[start]) & 0xff) << o); + start++; + len--; + o += 8; + } + return v; + } + + static void put_int(int value, byte[] bytes, int start, int len) { + while (len > 0) { + bytes[start] = (byte) (value & 0xff); + start++; + len--; + value >>= 8; + } + } + + public AltosRomconfig(byte[] bytes, int offset) { + version = get_int(bytes, offset + 0, 2); + check = get_int(bytes, offset + 2, 2); + if (check == (~version & 0xffff)) { + switch (version) { + case 1: + serial_number = get_int(bytes, offset + 4, 2); + radio_calibration = get_int(bytes, offset + 6, 4); + valid = true; + break; + } + } + System.out.printf("version 0x%x check 0x%x valid %s serial %d cal %d\n", + version, check, valid ? "true" : "false", + serial_number, radio_calibration); + } + + public AltosRomconfig(AltosHexfile hexfile) { + this(hexfile.data, 0xa0 - hexfile.address); + } + + public void write(byte[] bytes, int offset) throws IOException { + if (!valid) + throw new IOException("rom configuration invalid"); + + if (offset < 0 || bytes.length < offset + 10) + throw new IOException("image cannot contain rom config"); + + AltosRomconfig existing = new AltosRomconfig(bytes, offset); + if (!existing.valid) + throw new IOException("image does not contain existing rom config"); + + switch (existing.version) { + case 1: + put_int(serial_number, bytes, offset + 4, 2); + put_int(radio_calibration, bytes, offset + 6, 4); + break; + } + } + + public void write (AltosHexfile hexfile) throws IOException { + write(hexfile.data, 0xa0 - hexfile.address); + new AltosRomconfig(hexfile); + } + + public AltosRomconfig(int in_serial_number, int in_radio_calibration) { + valid = true; + version = 1; + check = (~version & 0xffff); + serial_number = in_serial_number; + radio_calibration = in_radio_calibration; + } + + public boolean valid() { + return valid && serial_number != 0; + } + + public AltosRomconfig() { + valid = false; + } +} diff --git a/ao-tools/altosui/AltosRomconfigUI.java b/ao-tools/altosui/AltosRomconfigUI.java new file mode 100644 index 00000000..21c34ef4 --- /dev/null +++ b/ao-tools/altosui/AltosRomconfigUI.java @@ -0,0 +1,160 @@ +/* + * Copyright © 2010 Keith Packard + * + * 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.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.filechooser.FileNameExtensionFilter; +import javax.swing.table.*; +import javax.swing.event.*; +import java.io.*; +import java.util.*; +import java.text.*; +import java.util.prefs.*; + +import altosui.AltosRomconfig; + +public class AltosRomconfigUI + extends JDialog + implements ActionListener +{ + Container pane; + Box box; + JLabel serial_label; + JLabel radio_calibration_label; + + JFrame owner; + JTextField serial_value; + JTextField radio_calibration_value; + + JButton ok; + JButton cancel; + + /* Build the UI using a grid bag */ + public AltosRomconfigUI(JFrame in_owner) { + super (in_owner, "Configure TeleMetrum Rom Values", true); + + owner = in_owner; + GridBagConstraints c; + + Insets il = new Insets(4,4,4,4); + Insets ir = new Insets(4,4,4,4); + + pane = getContentPane(); + pane.setLayout(new GridBagLayout()); + + /* Serial */ + c = new GridBagConstraints(); + c.gridx = 0; c.gridy = 0; + c.gridwidth = 3; + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.LINE_START; + c.insets = il; + serial_label = new JLabel("Serial:"); + pane.add(serial_label, c); + + c = new GridBagConstraints(); + c.gridx = 3; c.gridy = 0; + c.gridwidth = 3; + c.fill = GridBagConstraints.HORIZONTAL; + c.weightx = 1; + c.anchor = GridBagConstraints.LINE_START; + c.insets = ir; + serial_value = new JTextField("0"); + pane.add(serial_value, c); + + /* Radio calibration value */ + c = new GridBagConstraints(); + c.gridx = 0; c.gridy = 1; + c.gridwidth = 3; + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.LINE_START; + c.insets = il; + c.ipady = 5; + radio_calibration_label = new JLabel("Radio Calibration:"); + pane.add(radio_calibration_label, c); + + c = new GridBagConstraints(); + c.gridx = 3; c.gridy = 1; + c.gridwidth = 3; + c.fill = GridBagConstraints.HORIZONTAL; + c.weightx = 1; + c.anchor = GridBagConstraints.LINE_START; + c.insets = ir; + c.ipady = 5; + radio_calibration_value = new JTextField("1186611"); + pane.add(radio_calibration_value, c); + + /* Buttons */ + c = new GridBagConstraints(); + c.gridx = 0; c.gridy = 2; + c.gridwidth = 3; + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.CENTER; + c.insets = il; + ok = new JButton("OK"); + pane.add(ok, c); + ok.addActionListener(this); + ok.setActionCommand("ok"); + + c = new GridBagConstraints(); + c.gridx = 3; c.gridy = 2; + c.gridwidth = 3; + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.CENTER; + c.insets = il; + cancel = new JButton("Cancel"); + pane.add(cancel, c); + cancel.addActionListener(this); + cancel.setActionCommand("cancel"); + + pack(); + setLocationRelativeTo(owner); + } + + boolean selected; + + /* Listen for events from our buttons */ + public void actionPerformed(ActionEvent e) { + String cmd = e.getActionCommand(); + + if (cmd.equals("ok")) + selected = true; + setVisible(false); + } + + int serial() { + return Integer.parseInt(serial_value.getText()); + } + + int radio_calibration() { + return Integer.parseInt(radio_calibration_value.getText()); + } + + public AltosRomconfig romconfig() { + return new AltosRomconfig(serial(), radio_calibration()); + } + + public AltosRomconfig showDialog() { + setVisible(true); + if (selected) + return romconfig(); + return null; + } +} diff --git a/ao-tools/altosui/AltosSerial.java b/ao-tools/altosui/AltosSerial.java index ba00b55e..a62f1225 100644 --- a/ao-tools/altosui/AltosSerial.java +++ b/ao-tools/altosui/AltosSerial.java @@ -79,6 +79,10 @@ public class AltosSerial implements Runnable { } } + public void flush_reply() { + reply_queue.clear(); + } + public String get_reply() throws InterruptedException { return reply_queue.take(); } diff --git a/ao-tools/altosui/AltosUI.java b/ao-tools/altosui/AltosUI.java index 565866ea..9fd47ea7 100644 --- a/ao-tools/altosui/AltosUI.java +++ b/ao-tools/altosui/AltosUI.java @@ -41,7 +41,7 @@ import altosui.AltosVoice; import altosui.AltosFlightStatusTableModel; import altosui.AltosFlightInfoTableModel; import altosui.AltosChannelMenu; -import altosui.AltosFlash; +import altosui.AltosFlashUI; import libaltosJNI.*; @@ -460,7 +460,7 @@ public class AltosUI extends JFrame { } void FlashImage() { - new AltosFlash(AltosUI.this); + new AltosFlashUI(AltosUI.this); } /* diff --git a/ao-tools/altosui/Makefile b/ao-tools/altosui/Makefile index ebe59644..affbac39 100644 --- a/ao-tools/altosui/Makefile +++ b/ao-tools/altosui/Makefile @@ -8,12 +8,14 @@ CLASSFILES=\ AltosConfigUI.class \ AltosConvert.class \ AltosCSV.class \ + AltosDebug.class \ AltosEepromDownload.class \ AltosEepromMonitor.class \ AltosEepromReader.class \ AltosEepromRecord.class \ AltosFile.class \ AltosFlash.class \ + AltosFlashUI.class \ AltosFlightInfoTableModel.class \ AltosFlightStatusTableModel.class \ AltosGPS.class \ @@ -31,6 +33,8 @@ CLASSFILES=\ AltosUI.class \ AltosDevice.class \ AltosDeviceDialog.class \ + AltosRomconfig.class \ + AltosRomconfigUI.class \ AltosVoice.class FREETTSSRC=/home/keithp/src/freetts/freetts-1.2.2 -- cgit v1.2.3 From b8519b8669ff54741dd738ac343fbd2424451247 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 23 Aug 2010 21:53:37 -0700 Subject: ao-dumplog: Fix --remote and --channel options to actually work --- ao-tools/ao-dumplog/ao-dumplog.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/ao-dumplog/ao-dumplog.c b/ao-tools/ao-dumplog/ao-dumplog.c index 57c43290..6d4fa5bf 100644 --- a/ao-tools/ao-dumplog/ao-dumplog.c +++ b/ao-tools/ao-dumplog/ao-dumplog.c @@ -29,7 +29,7 @@ static const struct option options[] = { { .name = "tty", .has_arg = 1, .val = 'T' }, { .name = "device", .has_arg = 1, .val = 'D' }, - { .name = "remote", .has_arg = 1, .val = 'R' }, + { .name = "remote", .has_arg = 0, .val = 'R' }, { .name = "channel", .has_arg = 1, .val = 'C' }, { 0, 0, 0, 0}, }; @@ -91,7 +91,7 @@ main (int argc, char **argv) int invalid; char serial_line[8192]; - while ((c = getopt_long(argc, argv, "T:D:R", options, NULL)) != -1) { + while ((c = getopt_long(argc, argv, "T:D:C:R", options, NULL)) != -1) { switch (c) { case 'T': tty = optarg; -- cgit v1.2.3 From 86f7b9314b042f2e512fdf35067817e68532867b Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 23 Aug 2010 21:54:47 -0700 Subject: altosui: pad TM config dialog values to avoid clipping descenders --- ao-tools/altosui/AltosConfigUI.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosConfigUI.java b/ao-tools/altosui/AltosConfigUI.java index 6825b9a9..605ccc8b 100644 --- a/ao-tools/altosui/AltosConfigUI.java +++ b/ao-tools/altosui/AltosConfigUI.java @@ -147,6 +147,7 @@ public class AltosConfigUI c.fill = GridBagConstraints.NONE; c.anchor = GridBagConstraints.LINE_START; c.insets = il; + c.ipady = 5; version_label = new JLabel("Software version:"); pane.add(version_label, c); @@ -157,6 +158,7 @@ public class AltosConfigUI c.weightx = 1; c.anchor = GridBagConstraints.LINE_START; c.insets = ir; + c.ipady = 5; version_value = new JLabel(""); pane.add(version_value, c); @@ -167,6 +169,7 @@ public class AltosConfigUI c.fill = GridBagConstraints.NONE; c.anchor = GridBagConstraints.LINE_START; c.insets = il; + c.ipady = 5; serial_label = new JLabel("Serial:"); pane.add(serial_label, c); @@ -177,6 +180,7 @@ public class AltosConfigUI c.weightx = 1; c.anchor = GridBagConstraints.LINE_START; c.insets = ir; + c.ipady = 5; serial_value = new JLabel(""); pane.add(serial_value, c); @@ -187,7 +191,7 @@ public class AltosConfigUI c.fill = GridBagConstraints.NONE; c.anchor = GridBagConstraints.LINE_START; c.insets = il; - c.ipady = 3; + c.ipady = 5; main_deploy_label = new JLabel("Main Deploy Altitude(m):"); pane.add(main_deploy_label, c); @@ -278,7 +282,7 @@ public class AltosConfigUI /* Buttons */ c = new GridBagConstraints(); c.gridx = 0; c.gridy = 7; - c.gridwidth = 2; + c.gridwidth = 6; c.fill = GridBagConstraints.NONE; c.anchor = GridBagConstraints.LINE_START; c.insets = il; @@ -288,8 +292,8 @@ public class AltosConfigUI save.setActionCommand("save"); c = new GridBagConstraints(); - c.gridx = 2; c.gridy = 7; - c.gridwidth = 2; + c.gridx = 0; c.gridy = 7; + c.gridwidth = 6; c.fill = GridBagConstraints.NONE; c.anchor = GridBagConstraints.CENTER; c.insets = il; @@ -299,8 +303,8 @@ public class AltosConfigUI reset.setActionCommand("reset"); c = new GridBagConstraints(); - c.gridx = 4; c.gridy = 7; - c.gridwidth = 2; + c.gridx = 0; c.gridy = 7; + c.gridwidth = 6; c.fill = GridBagConstraints.NONE; c.anchor = GridBagConstraints.LINE_END; c.insets = il; -- cgit v1.2.3 From f9e80f39bc39e5882bfe75f959b6501cb3277cd2 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 23 Aug 2010 21:55:49 -0700 Subject: libaltos: use pipe to wake up getchar on close. use mutexes --- ao-tools/libaltos/libaltos.c | 121 +++++++++++++++++++++++++++++-------------- 1 file changed, 83 insertions(+), 38 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/libaltos/libaltos.c b/ao-tools/libaltos/libaltos.c index 3e8485e4..ffdb2366 100644 --- a/ao-tools/libaltos/libaltos.c +++ b/ao-tools/libaltos/libaltos.c @@ -448,16 +448,20 @@ altos_list_finish(struct altos_list *list) #include #include #include +#include #define USB_BUF_SIZE 64 struct altos_file { int fd; + int pipe[2]; unsigned char out_data[USB_BUF_SIZE]; int out_used; unsigned char in_data[USB_BUF_SIZE]; int in_used; int in_read; + pthread_mutex_t putc_mutex; + pthread_mutex_t getc_mutex; }; struct altos_file * @@ -470,6 +474,7 @@ altos_open(struct altos_device *device) if (!file) return NULL; + pipe(file->pipe); file->fd = open(device->path, O_RDWR | O_NOCTTY); if (file->fd < 0) { perror(device->path); @@ -484,8 +489,8 @@ altos_open(struct altos_device *device) return NULL; } cfmakeraw(&term); - term.c_cc[VMIN] = 0; - term.c_cc[VTIME] = 1; + term.c_cc[VMIN] = 1; + term.c_cc[VTIME] = 0; ret = tcsetattr(file->fd, TCSAFLUSH, &term); if (ret < 0) { perror("tcsetattr"); @@ -493,6 +498,8 @@ altos_open(struct altos_device *device) free(file); return NULL; } + pthread_mutex_init(&file->putc_mutex,NULL); + pthread_mutex_init(&file->getc_mutex,NULL); return file; } @@ -500,8 +507,10 @@ void altos_close(struct altos_file *file) { if (file->fd != -1) { - close(file->fd); + int fd = file->fd; file->fd = -1; + write(file->pipe[1], "\r", 1); + close(fd); } } @@ -512,68 +521,104 @@ altos_free(struct altos_file *file) free(file); } +static int +_altos_flush(struct altos_file *file) +{ + while (file->out_used) { + int ret; + + if (file->fd < 0) + return -EBADF; + fflush(stdout); + ret = write (file->fd, file->out_data, file->out_used); + if (ret < 0) + return -errno; + if (ret) { + memmove(file->out_data, file->out_data + ret, + file->out_used - ret); + file->out_used -= ret; + } + } +} + int altos_putchar(struct altos_file *file, char c) { int ret; + pthread_mutex_lock(&file->putc_mutex); if (file->out_used == USB_BUF_SIZE) { - ret = altos_flush(file); - if (ret) + ret = _altos_flush(file); + if (ret) { + pthread_mutex_unlock(&file->putc_mutex); return ret; + } } file->out_data[file->out_used++] = c; + ret = 0; if (file->out_used == USB_BUF_SIZE) - return altos_flush(file); + ret = _altos_flush(file); + pthread_mutex_unlock(&file->putc_mutex); return 0; } int altos_flush(struct altos_file *file) { - while (file->out_used) { - int ret; - - if (file->fd < 0) - return -EBADF; - ret = write (file->fd, file->out_data, file->out_used); - if (ret < 0) - return -errno; - if (ret) { - memmove(file->out_data, file->out_data + ret, - file->out_used - ret); - file->out_used -= ret; - } - } + int ret; + pthread_mutex_lock(&file->putc_mutex); + ret = _altos_flush(file); + pthread_mutex_unlock(&file->putc_mutex); + return ret; } + #include int altos_getchar(struct altos_file *file, int timeout) { - while (file->in_read == file->in_used) { - int ret; + int ret; + struct pollfd fd[2]; - altos_flush(file); - if (file->fd < 0) - return -EBADF; - if (timeout) { - struct pollfd fd; - int ret; - fd.fd = file->fd; - fd.events = POLLIN; - ret = poll(&fd, 1, timeout); - if (ret == 0) - return LIBALTOS_TIMEOUT; + if (timeout == 0) + timeout = -1; + pthread_mutex_lock(&file->getc_mutex); + fd[0].fd = file->fd; + fd[0].events = POLLIN; + fd[1].fd = file->pipe[0]; + fd[1].events = POLLIN; + while (file->in_read == file->in_used) { + if (file->fd < 0) { + pthread_mutex_unlock(&file->getc_mutex); + return LIBALTOS_ERROR; } - ret = read(file->fd, file->in_data, USB_BUF_SIZE); - if (ret < 0) + altos_flush(file); + + ret = poll(fd, 2, timeout); + if (ret < 0) { + perror("altos_getchar"); + pthread_mutex_unlock(&file->getc_mutex); return LIBALTOS_ERROR; - file->in_read = 0; - file->in_used = ret; + } + if (ret == 0) { + pthread_mutex_unlock(&file->getc_mutex); + return LIBALTOS_TIMEOUT; + } + if (fd[0].revents & POLLIN) { + ret = read(file->fd, file->in_data, USB_BUF_SIZE); + if (ret < 0) { + perror("altos_getchar"); + pthread_mutex_unlock(&file->getc_mutex); + return LIBALTOS_ERROR; + } + file->in_read = 0; + file->in_used = ret; + } } - return file->in_data[file->in_read++]; + ret = file->in_data[file->in_read++]; + pthread_mutex_unlock(&file->getc_mutex); + return ret; } #endif /* POSIX_TTY */ -- cgit v1.2.3 From b1758be01397fd49c441f40852f3558fe9343a2d Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 23 Aug 2010 21:58:50 -0700 Subject: altosui: Add lots more cc1111 debug interface functions These are sufficient to program the flash. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosDebug.java | 139 +++++++++++++++++++++++++++++---------- 1 file changed, 103 insertions(+), 36 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosDebug.java b/ao-tools/altosui/AltosDebug.java index 7bd3a5cd..83ea5bcb 100644 --- a/ao-tools/altosui/AltosDebug.java +++ b/ao-tools/altosui/AltosDebug.java @@ -27,35 +27,35 @@ import altosui.AltosRomconfig; public class AltosDebug extends AltosSerial { - static final byte WR_CONFIG = 0x1d; - static final byte RD_CONFIG = 0x24; - static final byte CONFIG_TIMERS_OFF = (1 << 3); - static final byte CONFIG_DMA_PAUSE = (1 << 2); - static final byte CONFIG_TIMER_SUSPEND = (1 << 1); - static final byte SET_FLASH_INFO_PAGE = (1 << 0); - - static final byte GET_PC = 0x28; - static final byte READ_STATUS = 0x34; - static final byte STATUS_CHIP_ERASE_DONE = (byte) (1 << 7); - static final byte STATUS_PCON_IDLE = (1 << 6); - static final byte STATUS_CPU_HALTED = (1 << 5); - static final byte STATUS_POWER_MODE_0 = (1 << 4); - static final byte STATUS_HALT_STATUS = (1 << 3); - static final byte STATUS_DEBUG_LOCKED = (1 << 2); - static final byte STATUS_OSCILLATOR_STABLE = (1 << 1); - static final byte STATUS_STACK_OVERFLOW = (1 << 0); - - static final byte SET_HW_BRKPNT = 0x3b; - static byte HW_BRKPNT_N(byte n) { return (byte) ((n) << 3); } - static final byte HW_BRKPNT_N_MASK = (0x3 << 3); - static final byte HW_BRKPNT_ENABLE = (1 << 2); - - static final byte HALT = 0x44; - static final byte RESUME = 0x4c; - static byte DEBUG_INSTR(byte n) { return (byte) (0x54|(n)); } - static final byte STEP_INSTR = 0x5c; - static byte STEP_REPLACE(byte n) { return (byte) (0x64|(n)); } - static final byte GET_CHIP_ID = 0x68; + public static final byte WR_CONFIG = 0x1d; + public static final byte RD_CONFIG = 0x24; + public static final byte CONFIG_TIMERS_OFF = (1 << 3); + public static final byte CONFIG_DMA_PAUSE = (1 << 2); + public static final byte CONFIG_TIMER_SUSPEND = (1 << 1); + public static final byte SET_FLASH_INFO_PAGE = (1 << 0); + + public static final byte GET_PC = 0x28; + public static final byte READ_STATUS = 0x34; + public static final byte STATUS_CHIP_ERASE_DONE = (byte) (1 << 7); + public static final byte STATUS_PCON_IDLE = (1 << 6); + public static final byte STATUS_CPU_HALTED = (1 << 5); + public static final byte STATUS_POWER_MODE_0 = (1 << 4); + public static final byte STATUS_HALT_STATUS = (1 << 3); + public static final byte STATUS_DEBUG_LOCKED = (1 << 2); + public static final byte STATUS_OSCILLATOR_STABLE = (1 << 1); + public static final byte STATUS_STACK_OVERFLOW = (1 << 0); + + public static final byte SET_HW_BRKPNT = 0x3b; + public static byte HW_BRKPNT_N(byte n) { return (byte) ((n) << 3); } + public static final byte HW_BRKPNT_N_MASK = (0x3 << 3); + public static final byte HW_BRKPNT_ENABLE = (1 << 2); + + public static final byte HALT = 0x44; + public static final byte RESUME = 0x4c; + public static byte DEBUG_INSTR(byte n) { return (byte) (0x54|(n)); } + public static final byte STEP_INSTR = 0x5c; + public static byte STEP_REPLACE(byte n) { return (byte) (0x64|(n)); } + public static final byte GET_CHIP_ID = 0x68; static boolean ishex(int c) { @@ -102,14 +102,32 @@ public class AltosDebug extends AltosSerial { } } + void dump_memory(String header, int address, byte[] bytes, int start, int len) { + System.out.printf("%s\n", header); + for (int j = 0; j < len; j++) { + if ((j & 15) == 0) { + if (j != 0) + System.out.printf("\n"); + System.out.printf ("%04x:", address + j); + } + System.out.printf(" %02x", bytes[start + j]); + } + System.out.printf("\n"); + } + /* * Write target memory */ - public void write_memory(int address, byte[] bytes) { + public void write_memory(int address, byte[] bytes, int start, int len) { ensure_debug_mode(); - printf("O %x %x\n", bytes.length, address); - for (int i = 0; i < bytes.length; i++) - printf("%02x", bytes[i]); +// dump_memory("write_memory", address, bytes, start, len); + printf("O %x %x\n", len, address); + for (int i = 0; i < len; i++) + printf("%02x", bytes[start + i]); + } + + public void write_memory(int address, byte[] bytes) { + write_memory(address, bytes, 0, bytes.length); } /* @@ -123,6 +141,7 @@ public class AltosDebug extends AltosSerial { ensure_debug_mode(); printf("I %x %x\n", length, address); int i = 0; + int start = 0; while (i < length) { String line = get_reply().trim(); if (!ishex(line) || line.length() % 2 != 0) @@ -131,10 +150,12 @@ public class AltosDebug extends AltosSerial { ("Invalid reply \"%s\"", line)); int this_time = line.length() / 2; for (int j = 0; j < this_time; j++) - data[j] = (byte) ((fromhex(line.charAt(j*2)) << 4) + + data[start + j] = (byte) ((fromhex(line.charAt(j*2)) << 4) + fromhex(line.charAt(j*2+1))); + start += this_time; i += this_time; } +// dump_memory("read_memory", address, data, 0, length); return data; } @@ -195,14 +216,60 @@ public class AltosDebug extends AltosSerial { return data; } + public byte read_byte() throws IOException, InterruptedException { + return read_bytes(1)[0]; + } + + public byte debug_instr(byte[] instruction) throws IOException, InterruptedException { + byte[] command = new byte[1 + instruction.length]; + command[0] = DEBUG_INSTR((byte) instruction.length); + for (int i = 0; i < instruction.length; i++) + command[i+1] = instruction[i]; + write_bytes(command); + return read_byte(); + } + + public byte resume() throws IOException, InterruptedException { + write_byte(RESUME); + return read_byte(); + } + + public int read_uint16() throws IOException, InterruptedException { + byte[] d = read_bytes(2); + return ((int) (d[0] & 0xff) << 8) | (d[1] & 0xff); + } + + public int read_uint8() throws IOException, InterruptedException { + byte[] d = read_bytes(1); + return (int) (d[0] & 0xff); + } + + public int get_chip_id() throws IOException, InterruptedException { + write_byte(GET_CHIP_ID); + return read_uint16(); + } + + public int get_pc() throws IOException, InterruptedException { + write_byte(GET_PC); + return read_uint16(); + } + public byte read_status() throws IOException, InterruptedException { write_byte(READ_STATUS); - return read_bytes(2)[0]; + return read_byte(); + } + + static final byte LJMP = 0x02; + + public void set_pc(int pc) throws IOException, InterruptedException { + byte high = (byte) (pc >> 8); + byte low = (byte) pc; + byte[] jump_mem = { LJMP, high, low }; + debug_instr(jump_mem); } public boolean check_connection() throws IOException, InterruptedException { byte reply = read_status(); - System.out.printf("status %x\n", reply); if ((reply & STATUS_CHIP_ERASE_DONE) == 0) return false; if ((reply & STATUS_PCON_IDLE) != 0) -- cgit v1.2.3 From 8857ac5e43eac6db8d5594b8864df497a712242b Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 23 Aug 2010 22:00:16 -0700 Subject: altosui: remove debug printf from AltosHexfile --- ao-tools/altosui/AltosHexfile.java | 2 -- 1 file changed, 2 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosHexfile.java b/ao-tools/altosui/AltosHexfile.java index 360e24ad..19e35ae1 100644 --- a/ao-tools/altosui/AltosHexfile.java +++ b/ao-tools/altosui/AltosHexfile.java @@ -248,7 +248,5 @@ public class AltosHexfile { data[records[i].address - base + j] = records[i].data[j]; } } - for (int i = 0xa0; i < 0xaa; i++) - System.out.printf ("%04x: %02x\n", i, get_byte(i)); } } \ No newline at end of file -- cgit v1.2.3 From c3f57ffdb6c74de90d982eacd604e658ce9b00a5 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 23 Aug 2010 22:01:11 -0700 Subject: altosui: flush serial output before waiting for reply --- ao-tools/altosui/AltosSerial.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosSerial.java b/ao-tools/altosui/AltosSerial.java index a62f1225..d02e25a9 100644 --- a/ao-tools/altosui/AltosSerial.java +++ b/ao-tools/altosui/AltosSerial.java @@ -84,7 +84,9 @@ public class AltosSerial implements Runnable { } public String get_reply() throws InterruptedException { - return reply_queue.take(); + libaltos.altos_flush(altos); + String line = reply_queue.take(); + return line; } public void add_monitor(LinkedBlockingQueue q) { -- cgit v1.2.3 From bd2b44ddd61fadd8bf8ee6bf783ce019b1be7cc0 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 23 Aug 2010 22:01:38 -0700 Subject: altosui: Remove debug printf from AltosRomconfig --- ao-tools/altosui/AltosRomconfig.java | 3 --- 1 file changed, 3 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosRomconfig.java b/ao-tools/altosui/AltosRomconfig.java index 5a2df313..844da7c4 100644 --- a/ao-tools/altosui/AltosRomconfig.java +++ b/ao-tools/altosui/AltosRomconfig.java @@ -59,9 +59,6 @@ public class AltosRomconfig { break; } } - System.out.printf("version 0x%x check 0x%x valid %s serial %d cal %d\n", - version, check, valid ? "true" : "false", - serial_number, radio_calibration); } public AltosRomconfig(AltosHexfile hexfile) { -- cgit v1.2.3 From 4c0c099716197ef7539be0cf55bbb164f6804958 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 23 Aug 2010 22:02:21 -0700 Subject: altosui: Finish device programming code Altosui can now reprogram Altusmetrum devices. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosFlash.java | 263 ++++++++++++++++++++++++++++++++++++- ao-tools/altosui/AltosFlashUI.java | 115 +++++++++++++++- 2 files changed, 376 insertions(+), 2 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosFlash.java b/ao-tools/altosui/AltosFlash.java index bab60c1f..0f92d6e7 100644 --- a/ao-tools/altosui/AltosFlash.java +++ b/ao-tools/altosui/AltosFlash.java @@ -33,17 +33,274 @@ import altosui.AltosHexfile; public class AltosFlash { File file; FileInputStream input; - Thread thread; AltosHexfile image; JFrame frame; AltosDevice debug_dongle; AltosDebug debug; AltosRomconfig rom_config; + ActionListener listener; + boolean aborted; + + static final byte MOV_direct_data = (byte) 0x75; + static final byte MOV_DPTR_data16 = (byte) 0x90; + static final byte MOV_A_data = (byte) 0x74; + static final byte MOVX_atDPTR_A = (byte) 0xf0; + static final byte MOVX_A_atDPTR = (byte) 0xe0; + static final byte INC_DPTR = (byte) 0xa3; + static final byte TRAP = (byte) 0xa5; + + static final byte JB = (byte) 0x20; + + static final byte MOV_A_direct = (byte) 0xe5; + static final byte MOV_direct1_direct2 = (byte) 0x85; + static final byte MOV_direct_A = (byte) 0xf5; + static final byte MOV_R0_data = (byte) (0x78 | 0); + static final byte MOV_R1_data = (byte) (0x78 | 1); + static final byte MOV_R2_data = (byte) (0x78 | 2); + static final byte MOV_R3_data = (byte) (0x78 | 3); + static final byte MOV_R4_data = (byte) (0x78 | 4); + static final byte MOV_R5_data = (byte) (0x78 | 5); + static final byte MOV_R6_data = (byte) (0x78 | 6); + static final byte MOV_R7_data = (byte) (0x78 | 7); + static final byte DJNZ_R0_rel = (byte) (0xd8 | 0); + static final byte DJNZ_R1_rel = (byte) (0xd8 | 1); + static final byte DJNZ_R2_rel = (byte) (0xd8 | 2); + static final byte DJNZ_R3_rel = (byte) (0xd8 | 3); + static final byte DJNZ_R4_rel = (byte) (0xd8 | 4); + static final byte DJNZ_R5_rel = (byte) (0xd8 | 5); + static final byte DJNZ_R6_rel = (byte) (0xd8 | 6); + static final byte DJNZ_R7_rel = (byte) (0xd8 | 7); + + static final byte P1DIR = (byte) 0xFE; + static final byte P1 = (byte) 0x90; + + /* flash controller */ + static final byte FWT = (byte) 0xAB; + static final byte FADDRL = (byte) 0xAC; + static final byte FADDRH = (byte) 0xAD; + static final byte FCTL = (byte) 0xAE; + static final byte FCTL_BUSY = (byte) 0x80; + static final byte FCTL_BUSY_BIT = (byte) 7; + static final byte FCTL_SWBSY = (byte) 0x40; + static final byte FCTL_SWBSY_BIT = (byte) 6; + static final byte FCTL_CONTRD = (byte) 0x10; + static final byte FCTL_WRITE = (byte) 0x02; + static final byte FCTL_ERASE = (byte) 0x01; + static final byte FWDATA = (byte) 0xAF; + + static final byte ACC = (byte) 0xE0; + + /* offsets within the flash_page program */ + static final int FLASH_ADDR_HIGH = 8; + static final int FLASH_ADDR_LOW = 11; + static final int RAM_ADDR_HIGH = 13; + static final int RAM_ADDR_LOW = 14; + static final int FLASH_WORDS_HIGH = 16; + static final int FLASH_WORDS_LOW = 18; + static final int FLASH_TIMING = 21; + + /* sleep mode control */ + static final int SLEEP = (byte) 0xbe; + static final int SLEEP_USB_EN = (byte) 0x80; + static final int SLEEP_XOSC_STB = (byte) 0x40; + static final int SLEEP_HFRC_STB = (byte) 0x20; + static final int SLEEP_RST_MASK = (byte) 0x18; + static final int SLEEP_RST_POWERON = (byte) 0x00; + static final int SLEEP_RST_EXTERNAL = (byte) 0x10; + static final int SLEEP_RST_WATCHDOG = (byte) 0x08; + static final int SLEEP_OSC_PD = (byte) 0x04; + static final int SLEEP_MODE_MASK = (byte) 0x03; + static final int SLEEP_MODE_PM0 = (byte) 0x00; + static final int SLEEP_MODE_PM1 = (byte) 0x01; + static final int SLEEP_MODE_PM2 = (byte) 0x02; + static final int SLEEP_MODE_PM3 = (byte) 0x03; + + /* clock controller */ + static final byte CLKCON = (byte) 0xC6; + static final byte CLKCON_OSC32K = (byte) 0x80; + static final byte CLKCON_OSC = (byte) 0x40; + static final byte CLKCON_TICKSPD = (byte) 0x38; + static final byte CLKCON_CLKSPD = (byte) 0x07; + + static final byte[] flash_page_proto = { + + MOV_direct_data, P1DIR, (byte) 0x02, + MOV_direct_data, P1, (byte) 0xFF, + + MOV_direct_data, FADDRH, 0, /* FLASH_ADDR_HIGH */ + + MOV_direct_data, FADDRL, 0, /* FLASH_ADDR_LOW */ + + MOV_DPTR_data16, 0, 0, /* RAM_ADDR_HIGH, RAM_ADDR_LOW */ + + MOV_R7_data, 0, /* FLASH_WORDS_HIGH */ + + MOV_R6_data, 0, /* FLASH_WORDS_LOW */ + + + MOV_direct_data, FWT, 0x20, /* FLASH_TIMING */ + + MOV_direct_data, FCTL, FCTL_ERASE, +/* eraseWaitLoop: */ + MOV_A_direct, FCTL, + JB, ACC|FCTL_BUSY_BIT, (byte) 0xfb, + + MOV_direct_data, P1, (byte) 0xfd, + + MOV_direct_data, FCTL, FCTL_WRITE, +/* writeLoop: */ + MOV_R5_data, 2, +/* writeWordLoop: */ + MOVX_A_atDPTR, + INC_DPTR, + MOV_direct_A, FWDATA, + DJNZ_R5_rel, (byte) 0xfa, /* writeWordLoop */ +/* writeWaitLoop: */ + MOV_A_direct, FCTL, + JB, ACC|FCTL_SWBSY_BIT, (byte) 0xfb, /* writeWaitLoop */ + DJNZ_R6_rel, (byte) 0xf1, /* writeLoop */ + DJNZ_R7_rel, (byte) 0xef, /* writeLoop */ + + MOV_direct_data, P1DIR, (byte) 0x00, + MOV_direct_data, P1, (byte) 0xFF, + TRAP, + }; + + public byte[] make_flash_page(int flash_addr, int ram_addr, int byte_count) { + int flash_word_addr = flash_addr >> 1; + int flash_word_count = ((byte_count + 1) >> 1); + + byte[] flash_page = new byte[flash_page_proto.length]; + for (int i = 0; i < flash_page.length; i++) + flash_page[i] = flash_page_proto[i]; + + flash_page[FLASH_ADDR_HIGH] = (byte) (flash_word_addr >> 8); + flash_page[FLASH_ADDR_LOW] = (byte) (flash_word_addr); + flash_page[RAM_ADDR_HIGH] = (byte) (ram_addr >> 8); + flash_page[RAM_ADDR_LOW] = (byte) (ram_addr); + + byte flash_words_low = (byte) (flash_word_count); + byte flash_words_high = (byte) (flash_word_count >> 8); + /* the flashing code has a minor 'bug' */ + if (flash_words_low != 0) + flash_words_high++; + + flash_page[FLASH_WORDS_HIGH] = (byte) flash_words_high; + flash_page[FLASH_WORDS_LOW] = (byte) flash_words_low; + return flash_page; + } + + static byte[] set_clkcon_fast = { + MOV_direct_data, CLKCON, 0x00 + }; + + static byte[] get_sleep = { + MOV_A_direct, SLEEP + }; + + public void clock_init() throws IOException, InterruptedException { + debug.debug_instr(set_clkcon_fast); + + byte status; + do { + status = debug.debug_instr(get_sleep); + } while ((status & SLEEP_XOSC_STB) == 0); + } + + void action(String s, int percent) { + if (listener != null && !aborted) + listener.actionPerformed(new ActionEvent(this, + percent, + s)); + } + + void action(int part, int total) { + int percent = 100 * part / total; + action(String.format("%d/%d (%d%%)", + part, total, percent), + percent); + } public void flash() throws IOException, FileNotFoundException, InterruptedException { if (!check_rom_config()) throw new IOException("Invalid rom config settings"); + if (image.address + image.data.length > 0x8000) + throw new IOException(String.format("Flash image too long %d", + image.address + + image.data.length)); + if ((image.address & 0x3ff) != 0) + throw new IOException(String.format("Flash image must start on page boundary (is 0x%x)", + image.address)); + int ram_address = 0xf000; + int flash_prog = 0xf400; + + /* + * Store desired config values into image + */ rom_config.write(image); + /* + * Bring up the clock + */ + clock_init(); + + int remain = image.data.length; + int flash_addr = image.address; + int image_start = 0; + + action(0, image.data.length); + while (remain > 0 && !aborted) { + int this_time = remain; + if (this_time > 0x400) + this_time = 0x400; + + /* write the data */ + debug.write_memory(ram_address, image.data, + image_start, this_time); + + /* write the flash program */ + byte[] flash_page = make_flash_page(flash_addr, + ram_address, + this_time); + debug.write_memory(flash_prog, flash_page); + + debug.set_pc(flash_prog); + int pc = debug.get_pc(); + debug.resume(); + Thread.sleep(100); + for (int times = 0; times < 10; times++) { + byte status = debug.read_status(); + if ((status & AltosDebug.STATUS_CPU_HALTED) != 0) + break; + Thread.sleep(100); + } + + byte[] check = debug.read_memory(flash_addr, this_time); + for (int i = 0; i < this_time; i++) + if (check[i] != image.data[image_start + i]) + throw new IOException(String.format("Flash write failed at 0x%x (%02x != %02x)", + image.address + image_start + i, + check[i], image.data[image_start + i])); + remain -= this_time; + flash_addr += this_time; + image_start += this_time; + + action(image.data.length - remain, image.data.length); + } + if (!aborted) { + action("done", 100); + debug.set_pc(image.address); + debug.resume(); + } + debug.close(); + } + + public void abort() { + aborted = true; + debug.close(); + } + + public void addActionListener(ActionListener l) { + listener = l; } public boolean check_rom_config() { @@ -56,6 +313,10 @@ public class AltosFlash { rom_config = romconfig; } + public AltosRomconfig romconfig() { + return rom_config; + } + public void open() throws IOException, FileNotFoundException, InterruptedException { input = new FileInputStream(file); image = new AltosHexfile(input); diff --git a/ao-tools/altosui/AltosFlashUI.java b/ao-tools/altosui/AltosFlashUI.java index 5cae4756..0c2041e3 100644 --- a/ao-tools/altosui/AltosFlashUI.java +++ b/ao-tools/altosui/AltosFlashUI.java @@ -31,15 +31,43 @@ import java.util.concurrent.LinkedBlockingQueue; import altosui.AltosHexfile; import altosui.AltosFlash; -public class AltosFlashUI implements Runnable { +public class AltosFlashUI + extends JDialog + implements Runnable, ActionListener +{ + Container pane; + Box box; + JLabel serial_label; + JLabel serial_value; + JLabel file_label; + JLabel file_value; + JProgressBar pbar; + JButton cancel; + File file; Thread thread; JFrame frame; AltosDevice debug_dongle; AltosFlash flash; + public void actionPerformed(ActionEvent e) { + if (e.getSource() == cancel) { + abort(); + dispose(); + } else { + String cmd = e.getActionCommand(); + if (cmd.equals("done")) + dispose(); + else { + pbar.setValue(e.getID()); + pbar.setString(cmd); + } + } + } + public void run() { flash = new AltosFlash(file, debug_dongle); + flash.addActionListener(this); try { flash.open(); if (!flash.check_rom_config()) { @@ -50,6 +78,10 @@ public class AltosFlashUI implements Runnable { return; flash.set_romconfig(romconfig); } + serial_value.setText(String.format("%d", + flash.romconfig().serial_number)); + file_value.setText(file.toString()); + setVisible(true); flash.flash(); } catch (FileNotFoundException ee) { JOptionPane.showMessageDialog(frame, @@ -67,9 +99,90 @@ public class AltosFlashUI implements Runnable { } } + public void abort() { + if (flash != null) + flash.abort(); + } + + public void build_dialog() { + GridBagConstraints c; + Insets il = new Insets(4,4,4,4); + Insets ir = new Insets(4,4,4,4); + + pane = getContentPane(); + pane.setLayout(new GridBagLayout()); + + c = new GridBagConstraints(); + c.gridx = 0; c.gridy = 0; + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.LINE_START; + c.insets = il; + serial_label = new JLabel("Serial:"); + pane.add(serial_label, c); + + c = new GridBagConstraints(); + c.gridx = 1; c.gridy = 0; + c.fill = GridBagConstraints.HORIZONTAL; + c.weightx = 1; + c.anchor = GridBagConstraints.LINE_START; + c.insets = ir; + serial_value = new JLabel(""); + pane.add(serial_value, c); + + c = new GridBagConstraints(); + c.fill = GridBagConstraints.NONE; + c.gridx = 0; c.gridy = 1; + c.anchor = GridBagConstraints.LINE_START; + c.insets = il; + file_label = new JLabel("File:"); + pane.add(file_label, c); + + c = new GridBagConstraints(); + c.fill = GridBagConstraints.HORIZONTAL; + c.weightx = 1; + c.gridx = 1; c.gridy = 1; + c.anchor = GridBagConstraints.LINE_START; + c.insets = ir; + file_value = new JLabel(""); + pane.add(file_value, c); + + pbar = new JProgressBar(); + pbar.setMinimum(0); + pbar.setMaximum(100); + pbar.setValue(0); + pbar.setString(""); + pbar.setStringPainted(true); + pbar.setPreferredSize(new Dimension(600, 20)); + c = new GridBagConstraints(); + c.fill = GridBagConstraints.HORIZONTAL; + c.anchor = GridBagConstraints.CENTER; + c.gridx = 0; c.gridy = 2; + c.gridwidth = GridBagConstraints.REMAINDER; + Insets ib = new Insets(4,4,4,4); + c.insets = ib; + pane.add(pbar, c); + + cancel = new JButton("Cancel"); + c = new GridBagConstraints(); + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.CENTER; + c.gridx = 0; c.gridy = 3; + c.gridwidth = GridBagConstraints.REMAINDER; + Insets ic = new Insets(4,4,4,4); + c.insets = ic; + pane.add(cancel, c); + cancel.addActionListener(this); + pack(); + setLocationRelativeTo(frame); + } + public AltosFlashUI(JFrame in_frame) { + super(in_frame, "Program Altusmetrum Device", false); + frame = in_frame; + build_dialog(); + debug_dongle = AltosDeviceDialog.show(frame, AltosDevice.Any); if (debug_dongle == null) -- cgit v1.2.3 From ef8376c4dd8262a34e02b6bb9e19e907ac2f4330 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 23 Aug 2010 22:08:30 -0700 Subject: altosui: make default Manifest look for built-in freetts --- ao-tools/altosui/Manifest.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/Manifest.txt b/ao-tools/altosui/Manifest.txt index 504d0de3..251ce2a0 100644 --- a/ao-tools/altosui/Manifest.txt +++ b/ao-tools/altosui/Manifest.txt @@ -1,2 +1,2 @@ Main-Class: altosui.AltosUI -Class-Path: /usr/share/java/freetts.jar +Class-Path: freetts.jar -- cgit v1.2.3 From a55b132668a819cc26478a609cb79bd9190deb9d Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 23 Aug 2010 23:01:36 -0700 Subject: altosui: Separate out log file choosing dialog to share with CSV generator This dialog will be shared with the CSV file generating code, so split it out instead of duplicating it. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosLogfileChooser.java | 52 +++++++++++++++++++++++++++++++ ao-tools/altosui/AltosUI.java | 14 +++------ ao-tools/altosui/Makefile | 1 + 3 files changed, 58 insertions(+), 9 deletions(-) create mode 100644 ao-tools/altosui/AltosLogfileChooser.java (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosLogfileChooser.java b/ao-tools/altosui/AltosLogfileChooser.java new file mode 100644 index 00000000..72d21fc8 --- /dev/null +++ b/ao-tools/altosui/AltosLogfileChooser.java @@ -0,0 +1,52 @@ +/* + * Copyright © 2010 Keith Packard + * + * 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.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.filechooser.FileNameExtensionFilter; +import javax.swing.table.*; +import java.io.*; +import java.util.*; +import java.text.*; +import java.util.prefs.*; + +import altosui.AltosPreferences; + +public class AltosLogfileChooser extends JFileChooser { + JFrame frame; + + public File runDialog() { + int ret; + + ret = showOpenDialog(frame); + if (ret == APPROVE_OPTION) + return getSelectedFile(); + return null; + } + + public AltosLogfileChooser(JFrame in_frame) { + in_frame = frame; + setDialogTitle("Select Flight Record File"); + setFileFilter(new FileNameExtensionFilter("Flight data file", + "eeprom", + "telem")); + setCurrentDirectory(AltosPreferences.logdir()); + } +} \ No newline at end of file diff --git a/ao-tools/altosui/AltosUI.java b/ao-tools/altosui/AltosUI.java index 9fd47ea7..64f96cdd 100644 --- a/ao-tools/altosui/AltosUI.java +++ b/ao-tools/altosui/AltosUI.java @@ -42,6 +42,7 @@ import altosui.AltosFlightStatusTableModel; import altosui.AltosFlightInfoTableModel; import altosui.AltosChannelMenu; import altosui.AltosFlashUI; +import altosui.AltosLogfileChooser; import libaltosJNI.*; @@ -529,17 +530,12 @@ public class AltosUI extends JFrame { * Replay a flight from telemetry data */ private void Replay() { - JFileChooser logfile_chooser = new JFileChooser(); + AltosLogfileChooser chooser = new AltosLogfileChooser( + AltosUI.this); - logfile_chooser.setDialogTitle("Select Flight Record File"); - logfile_chooser.setFileFilter(new FileNameExtensionFilter("Flight data file", "eeprom", "telem")); - logfile_chooser.setCurrentDirectory(AltosPreferences.logdir()); - int returnVal = logfile_chooser.showOpenDialog(AltosUI.this); + File file = chooser.runDialog(); - if (returnVal == JFileChooser.APPROVE_OPTION) { - File file = logfile_chooser.getSelectedFile(); - if (file == null) - System.out.println("No file selected?"); + if (file != null) { String filename = file.getName(); try { FileInputStream replay = new FileInputStream(file); diff --git a/ao-tools/altosui/Makefile b/ao-tools/altosui/Makefile index affbac39..de78b765 100644 --- a/ao-tools/altosui/Makefile +++ b/ao-tools/altosui/Makefile @@ -22,6 +22,7 @@ CLASSFILES=\ AltosGreatCircle.class \ AltosHexfile.class \ AltosLog.class \ + AltosLogfileChooser.class \ AltosParse.class \ AltosPreferences.class \ AltosRecord.class \ -- cgit v1.2.3 From 634a550149e7c344a22a637ba484f115592b1018 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 23 Aug 2010 23:15:05 -0700 Subject: altosui: refactor logfile chooser dialog to share more code Move file opening logic into logfile chooser as it can be shared that way. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosLogfileChooser.java | 32 ++++++++++++++++++++++++++++--- ao-tools/altosui/AltosUI.java | 24 ++++------------------- 2 files changed, 33 insertions(+), 23 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosLogfileChooser.java b/ao-tools/altosui/AltosLogfileChooser.java index 72d21fc8..3e9e4892 100644 --- a/ao-tools/altosui/AltosLogfileChooser.java +++ b/ao-tools/altosui/AltosLogfileChooser.java @@ -28,16 +28,42 @@ import java.text.*; import java.util.prefs.*; import altosui.AltosPreferences; +import altosui.AltosReader; +import altosui.AltosEepromReader; +import altosui.AltosTelemetryReader; public class AltosLogfileChooser extends JFileChooser { JFrame frame; + String filename; - public File runDialog() { + public String filename() { + return filename; + } + + public AltosReader runDialog() { int ret; ret = showOpenDialog(frame); - if (ret == APPROVE_OPTION) - return getSelectedFile(); + if (ret == APPROVE_OPTION) { + File file = getSelectedFile(); + if (file == null) + return null; + filename = file.getName(); + try { + FileInputStream in; + + in = new FileInputStream(file); + if (filename.endsWith("eeprom")) + return new AltosEepromReader(in); + else + return new AltosTelemetryReader(in); + } catch (FileNotFoundException fe) { + JOptionPane.showMessageDialog(frame, + filename, + "Cannot open file", + JOptionPane.ERROR_MESSAGE); + } + } return null; } diff --git a/ao-tools/altosui/AltosUI.java b/ao-tools/altosui/AltosUI.java index 64f96cdd..8a4c753f 100644 --- a/ao-tools/altosui/AltosUI.java +++ b/ao-tools/altosui/AltosUI.java @@ -532,26 +532,10 @@ public class AltosUI extends JFrame { private void Replay() { AltosLogfileChooser chooser = new AltosLogfileChooser( AltosUI.this); - - File file = chooser.runDialog(); - - if (file != null) { - String filename = file.getName(); - try { - FileInputStream replay = new FileInputStream(file); - DisplayThread thread; - if (filename.endsWith("eeprom")) - thread = new ReplayEepromThread(replay, filename); - else - thread = new ReplayTelemetryThread(replay, filename); - run_display(thread); - } catch (FileNotFoundException ee) { - JOptionPane.showMessageDialog(AltosUI.this, - filename, - "Cannot open telemetry file", - JOptionPane.ERROR_MESSAGE); - } - } + AltosReader reader = chooser.runDialog(); + if (reader != null) + run_display(new ReplayThread(reader, + chooser.filename())); } /* Connect to TeleMetrum, either directly or through -- cgit v1.2.3 From 7bd220dfd9b3fb0e42eb90c3b37eb7b4169eb21b Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 24 Aug 2010 00:29:11 -0700 Subject: altosui: Add ability to create CSV file from telem or eeprom files This creates a comma separated value file to export data for external programs. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosCSV.java | 120 +++++++++++++++++++++++++++--- ao-tools/altosui/AltosCSVUI.java | 83 +++++++++++++++++++++ ao-tools/altosui/AltosEepromReader.java | 4 +- ao-tools/altosui/AltosLogfileChooser.java | 9 ++- ao-tools/altosui/AltosReader.java | 2 + ao-tools/altosui/AltosUI.java | 17 +++++ ao-tools/altosui/Makefile | 1 + 7 files changed, 224 insertions(+), 12 deletions(-) create mode 100644 ao-tools/altosui/AltosCSVUI.java (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosCSV.java b/ao-tools/altosui/AltosCSV.java index 24936758..f12c0348 100644 --- a/ao-tools/altosui/AltosCSV.java +++ b/ao-tools/altosui/AltosCSV.java @@ -19,12 +19,20 @@ package altosui; import java.lang.*; import java.io.*; +import java.text.*; +import java.util.*; + import altosui.AltosRecord; +import altosui.AltosReader; public class AltosCSV { - File name; - PrintStream out; - boolean header_written; + File name; + PrintStream out; + boolean header_written; + boolean seen_boost; + int boost_tick; + LinkedList pad_records; + AltosState state; static final int ALTOS_CSV_VERSION = 1; @@ -45,6 +53,7 @@ public class AltosCSV { * acceleration (m/s²) * pressure (mBar) * altitude (m) + * height (m) * accelerometer speed (m/s) * barometer speed (m/s) * temp (°C) @@ -76,8 +85,9 @@ public class AltosCSV { } void write_general(AltosRecord record) { - out.printf("%s,%d,%d,%s,%d", - record.version, record.serial, record.flight, record.callsign, record.tick); + out.printf("%s,%d,%d,%s,%8.2f", + record.version, record.serial, record.flight, record.callsign, + (double) (record.tick - boost_tick) / 100.0); } void write_flight_header() { @@ -85,31 +95,123 @@ public class AltosCSV { } void write_flight(AltosRecord record) { - out.printf("%d,%s", record.state, record.state()); + out.printf("%d,%8s", record.state, record.state()); + } + + void write_basic_header() { + out.printf("acceleration pressure altitude height accel_speed baro_speed temperature battery_voltage drogue_voltage main_voltage"); + } + + void write_basic(AltosRecord record) { + out.printf("%8.2f,%10.2f,%8.2f,%8.2f,%8.2f,%8.2f,%5.1f,%5.2f,%5.2f,%5.2f", + record.acceleration(), + record.pressure(), + record.altitude(), + record.height(), + record.accel_speed(), + state.baro_speed, + record.temperature(), + record.battery_voltage(), + record.drogue_voltage(), + record.main_voltage()); + } + + void write_gps_header() { + out.printf("connected locked nsat latitude longitude altitude year month day hour minute second"); + } + + void write_gps(AltosRecord record) { + AltosGPS gps = record.gps; + if (gps == null) + gps = new AltosGPS(); + + out.printf("%2d,%2d,%3d,%12.7f,%12.7f,%6d,%5d,%3d,%3d,%3d,%3d,%3d", + gps.connected?1:0, + gps.locked?1:0, + gps.nsat, + gps.lat, + gps.lon, + gps.alt, + gps.year, + gps.month, + gps.day, + gps.hour, + gps.minute, + gps.second); } void write_header() { out.printf("# "); write_general_header(); out.printf(" "); write_flight_header(); + out.printf(" "); write_basic_header(); + out.printf(" "); write_gps_header(); + out.printf ("\n"); + } + + void write_one(AltosRecord record) { + state = new AltosState(record, state); + write_general(record); out.printf(","); + write_flight(record); out.printf(","); + write_basic(record); out.printf(","); + write_gps(record); out.printf ("\n"); } + void flush_pad() { + while (!pad_records.isEmpty()) { + write_one (pad_records.remove()); + } + } + public void write(AltosRecord record) { if (!header_written) { write_header(); header_written = true; } - write_general(record); out.printf(","); - write_flight(record); - out.printf ("\n"); + if (!seen_boost) { + if (record.state >= Altos.ao_flight_boost) { + seen_boost = true; + boost_tick = record.tick; + flush_pad(); + } + } + if (seen_boost) + write_one(record); + else + pad_records.add(record); } public PrintStream out() { return out; } + public void close() { + if (!pad_records.isEmpty()) { + boost_tick = pad_records.element().tick; + flush_pad(); + } + out.close(); + } + + public void write(AltosReader reader) { + AltosRecord record; + + reader.write_comments(out()); + try { + for (;;) { + record = reader.read(); + if (record == null) + break; + write(record); + } + } catch (IOException ie) { + } catch (ParseException pe) { + } + } + public AltosCSV(File in_name) throws FileNotFoundException { name = in_name; out = new PrintStream(name); + pad_records = new LinkedList(); } } diff --git a/ao-tools/altosui/AltosCSVUI.java b/ao-tools/altosui/AltosCSVUI.java new file mode 100644 index 00000000..2d812361 --- /dev/null +++ b/ao-tools/altosui/AltosCSVUI.java @@ -0,0 +1,83 @@ +/* + * Copyright © 2010 Keith Packard + * + * 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.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.filechooser.FileNameExtensionFilter; +import javax.swing.table.*; +import java.io.*; +import java.util.*; +import java.text.*; +import java.util.prefs.*; +import java.util.concurrent.LinkedBlockingQueue; + +import altosui.AltosLogfileChooser; +import altosui.AltosCSV; + +public class AltosCSVUI + extends JDialog + implements Runnable, ActionListener +{ + JFrame frame; + Thread thread; + AltosReader reader; + AltosCSV writer; + + public void run() { + AltosLogfileChooser chooser; + + chooser = new AltosLogfileChooser(frame); + reader = chooser.runDialog(); + if (reader == null) + return; + JFileChooser csv_chooser; + + File file = chooser.file(); + String path = file.getPath(); + int dot = path.lastIndexOf("."); + if (dot >= 0) + path = path.substring(0,dot); + path = path.concat(".csv"); + csv_chooser = new JFileChooser(path); + int ret = csv_chooser.showSaveDialog(frame); + if (ret == JFileChooser.APPROVE_OPTION) { + try { + writer = new AltosCSV(csv_chooser.getSelectedFile()); + } catch (FileNotFoundException ee) { + JOptionPane.showMessageDialog(frame, + file.getName(), + "Cannot open file", + JOptionPane.ERROR_MESSAGE); + } + writer.write(reader); + reader.close(); + writer.close(); + } + } + + public void actionPerformed(ActionEvent e) { + } + + public AltosCSVUI(JFrame in_frame) { + frame = in_frame; + thread = new Thread(this); + thread.start(); + } +} diff --git a/ao-tools/altosui/AltosEepromReader.java b/ao-tools/altosui/AltosEepromReader.java index c29fd90b..deab2167 100644 --- a/ao-tools/altosui/AltosEepromReader.java +++ b/ao-tools/altosui/AltosEepromReader.java @@ -218,6 +218,7 @@ public class AltosEepromReader extends AltosReader { case Altos.AO_LOG_PRODUCT: break; case Altos.AO_LOG_SERIAL_NUMBER: + state.serial = record.a; break; case Altos.AO_LOG_SOFTWARE_VERSION: break; @@ -228,6 +229,7 @@ public class AltosEepromReader extends AltosReader { public void write_comments(PrintStream out) { Iterator iterator = records.iterator(); + out.printf("# Comments\n"); while (iterator.hasNext()) { AltosOrderedRecord record = iterator.next(); switch (record.cmd) { @@ -250,7 +252,7 @@ public class AltosEepromReader extends AltosReader { out.printf ("# Accel cal: %d %d\n", record.a, record.b); break; case Altos.AO_LOG_RADIO_CAL: - out.printf ("# Radio cal: %d %d\n", record.a); + out.printf ("# Radio cal: %d\n", record.a); break; case Altos.AO_LOG_MANUFACTURER: out.printf ("# Manufacturer: %s\n", record.data); diff --git a/ao-tools/altosui/AltosLogfileChooser.java b/ao-tools/altosui/AltosLogfileChooser.java index 3e9e4892..36b51de6 100644 --- a/ao-tools/altosui/AltosLogfileChooser.java +++ b/ao-tools/altosui/AltosLogfileChooser.java @@ -35,17 +35,22 @@ import altosui.AltosTelemetryReader; public class AltosLogfileChooser extends JFileChooser { JFrame frame; String filename; + File file; public String filename() { return filename; } + public File file() { + return file; + } + public AltosReader runDialog() { int ret; ret = showOpenDialog(frame); if (ret == APPROVE_OPTION) { - File file = getSelectedFile(); + file = getSelectedFile(); if (file == null) return null; filename = file.getName(); @@ -68,7 +73,7 @@ public class AltosLogfileChooser extends JFileChooser { } public AltosLogfileChooser(JFrame in_frame) { - in_frame = frame; + frame = in_frame; setDialogTitle("Select Flight Record File"); setFileFilter(new FileNameExtensionFilter("Flight data file", "eeprom", diff --git a/ao-tools/altosui/AltosReader.java b/ao-tools/altosui/AltosReader.java index 81779e2b..5be8795d 100644 --- a/ao-tools/altosui/AltosReader.java +++ b/ao-tools/altosui/AltosReader.java @@ -25,4 +25,6 @@ import altosui.AltosRecord; public class AltosReader { public AltosRecord read() throws IOException, ParseException { return null; } + public void close() { } + public void write_comments(PrintStream out) { } } diff --git a/ao-tools/altosui/AltosUI.java b/ao-tools/altosui/AltosUI.java index 8a4c753f..63cb486c 100644 --- a/ao-tools/altosui/AltosUI.java +++ b/ao-tools/altosui/AltosUI.java @@ -43,6 +43,7 @@ import altosui.AltosFlightInfoTableModel; import altosui.AltosChannelMenu; import altosui.AltosFlashUI; import altosui.AltosLogfileChooser; +import altosui.AltosCSVUI; import libaltosJNI.*; @@ -545,6 +546,14 @@ public class AltosUI extends JFrame { new AltosEepromDownload(AltosUI.this); } + /* Load a flight log file and write out a CSV file containing + * all of the data in standard units + */ + + private void ExportData() { + new AltosCSVUI(AltosUI.this); + } + /* Create the AltosUI menus */ private void createMenu() { @@ -583,6 +592,14 @@ public class AltosUI extends JFrame { }); menu.add(item); + item = new JMenuItem("Export Data",KeyEvent.VK_F); + item.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + ExportData(); + } + }); + menu.add(item); + item = new JMenuItem("Quit",KeyEvent.VK_Q); item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, ActionEvent.CTRL_MASK)); diff --git a/ao-tools/altosui/Makefile b/ao-tools/altosui/Makefile index de78b765..1273e7d4 100644 --- a/ao-tools/altosui/Makefile +++ b/ao-tools/altosui/Makefile @@ -8,6 +8,7 @@ CLASSFILES=\ AltosConfigUI.class \ AltosConvert.class \ AltosCSV.class \ + AltosCSVUI.class \ AltosDebug.class \ AltosEepromDownload.class \ AltosEepromMonitor.class \ -- cgit v1.2.3 From 7d44cbd621d2b113ac2b802ef17e3d8a660ce7f2 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 24 Aug 2010 03:58:00 -0700 Subject: altosui: disable radio monitoring while using serial line for debugging --- ao-tools/altosui/AltosDebug.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosDebug.java b/ao-tools/altosui/AltosDebug.java index 83ea5bcb..df40410a 100644 --- a/ao-tools/altosui/AltosDebug.java +++ b/ao-tools/altosui/AltosDebug.java @@ -97,7 +97,7 @@ public class AltosDebug extends AltosSerial { void ensure_debug_mode() { if (!debug_mode) { - printf("D\n"); + printf("m 0\nD\n"); debug_mode = true; } } -- cgit v1.2.3 From d93787284c8e514a929edb9f944c98ae0206a33f Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 24 Aug 2010 03:59:09 -0700 Subject: altosui: Delay mapping Flash UI until flashing actually starts The flash operation may be abandoned before it even starts; this makes sure the UI doesn't flash up on the screen. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosFlash.java | 1 + ao-tools/altosui/AltosFlashUI.java | 9 +++++---- 2 files changed, 6 insertions(+), 4 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosFlash.java b/ao-tools/altosui/AltosFlash.java index 0f92d6e7..7aeab89a 100644 --- a/ao-tools/altosui/AltosFlash.java +++ b/ao-tools/altosui/AltosFlash.java @@ -247,6 +247,7 @@ public class AltosFlash { int flash_addr = image.address; int image_start = 0; + action("start", 0); action(0, image.data.length); while (remain > 0 && !aborted) { int this_time = remain; diff --git a/ao-tools/altosui/AltosFlashUI.java b/ao-tools/altosui/AltosFlashUI.java index 0c2041e3..b88a16b3 100644 --- a/ao-tools/altosui/AltosFlashUI.java +++ b/ao-tools/altosui/AltosFlashUI.java @@ -57,8 +57,10 @@ public class AltosFlashUI } else { String cmd = e.getActionCommand(); if (cmd.equals("done")) - dispose(); - else { + ; + else if (cmd.equals("start")) { + setVisible(true); + } else { pbar.setValue(e.getID()); pbar.setString(cmd); } @@ -88,15 +90,14 @@ public class AltosFlashUI "Cannot open image", file.toString(), JOptionPane.ERROR_MESSAGE); - return; } catch (IOException e) { JOptionPane.showMessageDialog(frame, e.getMessage(), file.toString(), JOptionPane.ERROR_MESSAGE); - return; } catch (InterruptedException ie) { } + dispose(); } public void abort() { -- cgit v1.2.3 From f62b2aa08ebfd912b3c732397d43ff9f6162ec88 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 24 Aug 2010 04:01:14 -0700 Subject: altosui: fetch existing romconfig for flashing --- ao-tools/altosui/AltosFlash.java | 2 ++ 1 file changed, 2 insertions(+) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosFlash.java b/ao-tools/altosui/AltosFlash.java index 7aeab89a..b7018555 100644 --- a/ao-tools/altosui/AltosFlash.java +++ b/ao-tools/altosui/AltosFlash.java @@ -315,6 +315,8 @@ public class AltosFlash { } public AltosRomconfig romconfig() { + if (!check_rom_config()) + return null; return rom_config; } -- cgit v1.2.3 From 220f3afdaa432c65f8ad45be7cdbe5c8a3616db3 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 24 Aug 2010 04:01:47 -0700 Subject: altosui: always display romconfig ui while flashing --- ao-tools/altosui/AltosFlashUI.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosFlashUI.java b/ao-tools/altosui/AltosFlashUI.java index b88a16b3..73a97a6b 100644 --- a/ao-tools/altosui/AltosFlashUI.java +++ b/ao-tools/altosui/AltosFlashUI.java @@ -72,14 +72,15 @@ public class AltosFlashUI flash.addActionListener(this); try { flash.open(); - if (!flash.check_rom_config()) { - AltosRomconfigUI romconfig_ui = new AltosRomconfigUI (frame); - romconfig_ui.showDialog(); - AltosRomconfig romconfig = romconfig_ui.romconfig(); - if (romconfig == null) - return; - flash.set_romconfig(romconfig); - } + AltosRomconfigUI romconfig_ui = new AltosRomconfigUI (frame); + + romconfig_ui.set(flash.romconfig()); + romconfig_ui.showDialog(); + + AltosRomconfig romconfig = romconfig_ui.romconfig(); + if (romconfig == null || !romconfig.valid()) + return; + flash.set_romconfig(romconfig); serial_value.setText(String.format("%d", flash.romconfig().serial_number)); file_value.setText(file.toString()); -- cgit v1.2.3 From ba086cc77273efe5397f60dcaccd1e3771441481 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 24 Aug 2010 04:02:27 -0700 Subject: altosui: write USB serial number string while flashing USB serial number is encoded in UCS2 as a part of the string descriptors. Place those right after the other rom config bits so that altosui can find it. altosui is changed to write the serial number there. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosRomconfig.java | 49 +++++++++++++++++++++++++++++++++- ao-tools/altosui/AltosRomconfigUI.java | 21 ++++++++++++++- src/ao.h | 5 ++-- src/ao_product.c | 2 +- 4 files changed, 72 insertions(+), 5 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosRomconfig.java b/ao-tools/altosui/AltosRomconfig.java index 844da7c4..8c9cb27a 100644 --- a/ao-tools/altosui/AltosRomconfig.java +++ b/ao-tools/altosui/AltosRomconfig.java @@ -47,14 +47,57 @@ public class AltosRomconfig { } } + static void put_string(String value, byte[] bytes, int start) { + for (int i = 0; i < value.length(); i++) + bytes[start + i] = (byte) value.charAt(i); + } + + static final int AO_USB_DESC_STRING = 3; + + static void put_usb_serial(int value, byte[] bytes, int start) { + int offset = start + 0xa; + int string_num = 0; + System.out.printf("Put usb serial %d\n", value); + + while (offset < bytes.length && bytes[offset] != 0) { + if (bytes[offset + 1] == AO_USB_DESC_STRING) { + ++string_num; + if (string_num == 4) + break; + } + offset += ((int) bytes[offset]) & 0xff; + } + System.out.printf("offset %d content %d\n", + offset, bytes[offset]); + if (offset >= bytes.length || bytes[offset] == 0) + return; + int len = ((((int) bytes[offset]) & 0xff) - 2) / 2; + String fmt = String.format("%%0%dd", len); + System.out.printf("existing serial length %d format %s\n", len, fmt); + + String s = String.format(fmt, value); + if (s.length() != len) { + System.out.printf("weird usb length issue %s isn't %d\n", + s, len); + return; + } + for (int i = 0; i < len; i++) { + bytes[offset + 2 + i*2] = (byte) s.charAt(i); + bytes[offset + 2 + i*2+1] = 0; + } + } + public AltosRomconfig(byte[] bytes, int offset) { version = get_int(bytes, offset + 0, 2); check = get_int(bytes, offset + 2, 2); + System.out.printf("version %d check %d\n", version, check); if (check == (~version & 0xffff)) { switch (version) { + case 2: case 1: serial_number = get_int(bytes, offset + 4, 2); radio_calibration = get_int(bytes, offset + 6, 4); + System.out.printf("serial %d cal %d\n", serial_number, radio_calibration); valid = true; break; } @@ -77,6 +120,8 @@ public class AltosRomconfig { throw new IOException("image does not contain existing rom config"); switch (existing.version) { + case 2: + put_usb_serial(serial_number, bytes, offset); case 1: put_int(serial_number, bytes, offset + 4, 2); put_int(radio_calibration, bytes, offset + 6, 4); @@ -86,7 +131,9 @@ public class AltosRomconfig { public void write (AltosHexfile hexfile) throws IOException { write(hexfile.data, 0xa0 - hexfile.address); - new AltosRomconfig(hexfile); + AltosRomconfig check = new AltosRomconfig(hexfile); + if (!check.valid()) + throw new IOException("writing new rom config failed\n"); } public AltosRomconfig(int in_serial_number, int in_radio_calibration) { diff --git a/ao-tools/altosui/AltosRomconfigUI.java b/ao-tools/altosui/AltosRomconfigUI.java index 21c34ef4..bc511865 100644 --- a/ao-tools/altosui/AltosRomconfigUI.java +++ b/ao-tools/altosui/AltosRomconfigUI.java @@ -143,12 +143,31 @@ public class AltosRomconfigUI return Integer.parseInt(serial_value.getText()); } + void set_serial(int serial) { + serial_value.setText(String.format("%d", serial)); + } + int radio_calibration() { return Integer.parseInt(radio_calibration_value.getText()); } + void set_radio_calibration(int calibration) { + radio_calibration_value.setText(String.format("%d", calibration)); + } + + public void set(AltosRomconfig config) { + if (config != null && config.valid()) { + set_serial(config.serial_number); + set_radio_calibration(config.radio_calibration); + } + } + public AltosRomconfig romconfig() { - return new AltosRomconfig(serial(), radio_calibration()); + try { + return new AltosRomconfig(serial(), radio_calibration()); + } catch (NumberFormatException ne) { + return null; + } } public AltosRomconfig showDialog() { diff --git a/src/ao.h b/src/ao.h index 9c418db2..d289ced1 100644 --- a/src/ao.h +++ b/src/ao.h @@ -293,12 +293,13 @@ ao_led_init(uint8_t enable); * ao_romconfig.c */ -#define AO_ROMCONFIG_VERSION 1 +#define AO_ROMCONFIG_VERSION 2 extern __code __at (0x00a0) uint16_t ao_romconfig_version; extern __code __at (0x00a2) uint16_t ao_romconfig_check; extern __code __at (0x00a4) uint16_t ao_serial_number; extern __code __at (0x00a6) uint32_t ao_radio_cal; +extern __code __at (0x00aa) uint8_t ao_usb_descriptors []; /* * ao_usb.c @@ -1008,7 +1009,7 @@ ao_rssi_init(uint8_t rssi_led); * each instance of a product */ -extern const uint8_t ao_usb_descriptors []; +extern __code __at(0x00aa) uint8_t ao_usb_descriptors []; extern const char ao_version[]; extern const char ao_manufacturer[]; extern const char ao_product[]; diff --git a/src/ao_product.c b/src/ao_product.c index f0eb4c07..82d6298f 100644 --- a/src/ao_product.c +++ b/src/ao_product.c @@ -28,7 +28,7 @@ const char ao_product[] = AO_iProduct_STRING; #define LE_WORD(x) ((x)&0xFF),((uint8_t) (((uint16_t) (x))>>8)) /* USB descriptors in one giant block of bytes */ -const uint8_t ao_usb_descriptors [] = +__code __at(0x00aa) uint8_t ao_usb_descriptors [] = { /* Device descriptor */ 0x12, -- cgit v1.2.3 From 99400fdc0f19ef538fc362dde5c3ab5b7cdac409 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 24 Aug 2010 16:43:38 -0700 Subject: altosui: flush replies from serial link when entering debug mode We use replies in debug mode a lot and depend on them matching the expected parameters. The case which caused trouble was using TeleMetrum to reprogram TeleDongle -- sending the 'm 0' command (to disable telemetry monitoring on TeleDongle) to the TeleMetrum caused it to reply 'Syntax Error' which confused the subsequent flashing operation. Flushing that reply gets things back in sync. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosDebug.java | 1 + ao-tools/altosui/AltosSerial.java | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosDebug.java b/ao-tools/altosui/AltosDebug.java index df40410a..06c9a0bd 100644 --- a/ao-tools/altosui/AltosDebug.java +++ b/ao-tools/altosui/AltosDebug.java @@ -98,6 +98,7 @@ public class AltosDebug extends AltosSerial { void ensure_debug_mode() { if (!debug_mode) { printf("m 0\nD\n"); + flush_reply(); debug_mode = true; } } diff --git a/ao-tools/altosui/AltosSerial.java b/ao-tools/altosui/AltosSerial.java index d02e25a9..3684f253 100644 --- a/ao-tools/altosui/AltosSerial.java +++ b/ao-tools/altosui/AltosSerial.java @@ -66,8 +66,10 @@ public class AltosSerial implements Runnable { LinkedBlockingQueue q = monitors.get(e); q.put(line); } - } else + } else { +// System.out.printf("GOT: %s\n", line); reply_queue.put(line); + } line = ""; } } else { @@ -80,6 +82,11 @@ public class AltosSerial implements Runnable { } public void flush_reply() { + libaltos.altos_flush(altos); + try { + Thread.sleep(100); + } catch (InterruptedException ie) { + } reply_queue.clear(); } @@ -132,6 +139,7 @@ public class AltosSerial implements Runnable { } public void print(String data) { +// System.out.printf("\"%s\" ", data); for (int i = 0; i < data.length(); i++) putc(data.charAt(i)); } -- cgit v1.2.3 From f0fd423d0bf83bc5c3f9d39e9c09397fbe8caed2 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 26 Aug 2010 23:41:26 -0700 Subject: altosui: Move number parsing code to Altos general class This moves these shared functions to the global shared class. Signed-off-by: Keith Packard --- ao-tools/altosui/Altos.java | 86 ++++++++++++++++++++++++++++++++++++++++ ao-tools/altosui/AltosDebug.java | 43 ++------------------ ao-tools/altosui/AltosParse.java | 10 ++++- 3 files changed, 98 insertions(+), 41 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/Altos.java b/ao-tools/altosui/Altos.java index 53359e23..07bd01ae 100644 --- a/ao-tools/altosui/Altos.java +++ b/ao-tools/altosui/Altos.java @@ -114,4 +114,90 @@ public class Altos { static final int AO_GPS_DATE_VALID = (1 << 6); static final int AO_GPS_NUM_SAT_SHIFT = 0; static final int AO_GPS_NUM_SAT_MASK = 0xf; + + static boolean isspace(int c) { + switch (c) { + case ' ': + case '\t': + return true; + } + return false; + } + + static boolean ishex(int c) { + if ('0' <= c && c <= '9') + return true; + if ('a' <= c && c <= 'f') + return true; + if ('A' <= c && c <= 'F') + return true; + return false; + } + + static boolean ishex(String s) { + for (int i = 0; i < s.length(); i++) + if (!ishex(s.charAt(i))) + return false; + return true; + } + + static int fromhex(int c) { + if ('0' <= c && c <= '9') + return c - '0'; + if ('a' <= c && c <= 'f') + return c - 'a' + 10; + if ('A' <= c && c <= 'F') + return c - 'A' + 10; + return -1; + } + + static int fromhex(String s) throws NumberFormatException { + int c, v = 0; + for (int i = 0; i < s.length(); i++) { + c = s.charAt(i); + if (!ishex(c)) { + if (i == 0) + throw new NumberFormatException(String.format("invalid hex \"%s\"", s)); + return v; + } + v = v * 16 + fromhex(c); + } + return v; + } + + static boolean isdec(int c) { + if ('0' <= c && c <= '9') + return true; + return false; + } + + static boolean isdec(String s) { + for (int i = 0; i < s.length(); i++) + if (!isdec(s.charAt(i))) + return false; + return true; + } + + static int fromdec(int c) { + if ('0' <= c && c <= '9') + return c - '0'; + return -1; + } + + static int fromdec(String s) throws NumberFormatException { + int c, v = 0; + int sign = 1; + for (int i = 0; i < s.length(); i++) { + c = s.charAt(i); + if (i == 0 && c == '-') { + sign = -1; + } else if (!isdec(c)) { + if (i == 0) + throw new NumberFormatException(String.format("invalid number \"%s\"", s)); + return v; + } else + v = v * 10 + fromdec(c); + } + return v * sign; + } } diff --git a/ao-tools/altosui/AltosDebug.java b/ao-tools/altosui/AltosDebug.java index 06c9a0bd..ca2e5a90 100644 --- a/ao-tools/altosui/AltosDebug.java +++ b/ao-tools/altosui/AltosDebug.java @@ -58,41 +58,6 @@ public class AltosDebug extends AltosSerial { public static final byte GET_CHIP_ID = 0x68; - static boolean ishex(int c) { - if ('0' <= c && c <= '9') - return true; - if ('a' <= c && c <= 'f') - return true; - if ('A' <= c && c <= 'F') - return true; - return false; - } - - static boolean ishex(String s) { - for (int i = 0; i < s.length(); i++) - if (!ishex(s.charAt(i))) - return false; - return true; - } - static boolean isspace(int c) { - switch (c) { - case ' ': - case '\t': - return true; - } - return false; - } - - static int fromhex(int c) { - if ('0' <= c && c <= '9') - return c - '0'; - if ('a' <= c && c <= 'f') - return c - 'a' + 10; - if ('A' <= c && c <= 'F') - return c - 'A' + 10; - return -1; - } - boolean debug_mode; void ensure_debug_mode() { @@ -145,14 +110,14 @@ public class AltosDebug extends AltosSerial { int start = 0; while (i < length) { String line = get_reply().trim(); - if (!ishex(line) || line.length() % 2 != 0) + if (!Altos.ishex(line) || line.length() % 2 != 0) throw new IOException( String.format ("Invalid reply \"%s\"", line)); int this_time = line.length() / 2; for (int j = 0; j < this_time; j++) - data[start + j] = (byte) ((fromhex(line.charAt(j*2)) << 4) + - fromhex(line.charAt(j*2+1))); + data[start + j] = (byte) ((Altos.fromhex(line.charAt(j*2)) << 4) + + Altos.fromhex(line.charAt(j*2+1))); start += this_time; i += this_time; } @@ -199,7 +164,7 @@ public class AltosDebug extends AltosSerial { String line = get_reply().trim(); String tokens[] = line.split("\\s+"); for (int j = 0; j < tokens.length; j++) { - if (!ishex(tokens[j]) || + if (!Altos.ishex(tokens[j]) || tokens[j].length() != 2) throw new IOException( String.format diff --git a/ao-tools/altosui/AltosParse.java b/ao-tools/altosui/AltosParse.java index a60dc694..4d82de78 100644 --- a/ao-tools/altosui/AltosParse.java +++ b/ao-tools/altosui/AltosParse.java @@ -20,10 +20,16 @@ package altosui; import java.text.*; import java.lang.*; +import altosui.Altos; + public class AltosParse { + static boolean isdigit(char c) { + return '0' <= c && c <= '9'; + } + static int parse_int(String v) throws ParseException { try { - return Integer.parseInt(v); + return Altos.fromdec(v); } catch (NumberFormatException e) { throw new ParseException("error parsing int " + v, 0); } @@ -31,7 +37,7 @@ public class AltosParse { static int parse_hex(String v) throws ParseException { try { - return Integer.parseInt(v, 16); + return Altos.fromhex(v); } catch (NumberFormatException e) { throw new ParseException("error parsing hex " + v, 0); } -- cgit v1.2.3 From 3dc67c1401976d6e9e2e942d5a4707a4810a0404 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 26 Aug 2010 23:43:00 -0700 Subject: altosui: Add AltosGreatCircle constructors This adds constructurs from AltosGPS pairs and also one from empty args (which defines both distance and bearing as 0). Signed-off-by: Keith Packard --- ao-tools/altosui/AltosGreatCircle.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosGreatCircle.java b/ao-tools/altosui/AltosGreatCircle.java index 878da03e..07c02c16 100644 --- a/ao-tools/altosui/AltosGreatCircle.java +++ b/ao-tools/altosui/AltosGreatCircle.java @@ -17,6 +17,8 @@ package altosui; +import altosui.AltosGPS; + import java.lang.Math; public class AltosGreatCircle { @@ -28,8 +30,8 @@ public class AltosGreatCircle { static final double rad = Math.PI / 180; static final double earth_radius = 6371.2 * 1000; /* in meters */ - AltosGreatCircle (double start_lat, double start_lon, - double end_lat, double end_lon) + public AltosGreatCircle (double start_lat, double start_lon, + double end_lat, double end_lon) { double lat1 = rad * start_lat; double lon1 = rad * -start_lon; @@ -63,4 +65,13 @@ public class AltosGreatCircle { distance = d * earth_radius; bearing = course * 180/Math.PI; } + + public AltosGreatCircle(AltosGPS start, AltosGPS end) { + this(start.lat, start.lon, end.lat, end.lon); + } + + public AltosGreatCircle() { + distance = 0; + bearing = 0; + } } -- cgit v1.2.3 From 651f6102ac79459fc8d5679d852c963dcb5bb3fc Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 26 Aug 2010 23:44:25 -0700 Subject: altosui: add rssi and distance/dir from pad to CSV files Just adds a couple more fields to the CSV files that might be interesting. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosCSV.java | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosCSV.java b/ao-tools/altosui/AltosCSV.java index f12c0348..db50e7a2 100644 --- a/ao-tools/altosui/AltosCSV.java +++ b/ao-tools/altosui/AltosCSV.java @@ -44,6 +44,7 @@ public class AltosCSV { * flight number * callsign * time (seconds since boost) + * rssi * * Flight status * state @@ -74,6 +75,8 @@ public class AltosCSV { * hour (0-23) * minute (0-59) * second (0-59) + * from_pad_dist (m) + * from_pad_dir (deg true) * * GPS Sat data * hdop @@ -81,13 +84,14 @@ public class AltosCSV { */ void write_general_header() { - out.printf("version serial flight call time"); + out.printf("version serial flight call time rssi"); } void write_general(AltosRecord record) { - out.printf("%s,%d,%d,%s,%8.2f", + out.printf("%s,%d,%d,%s,%8.2f,%4d", record.version, record.serial, record.flight, record.callsign, - (double) (record.tick - boost_tick) / 100.0); + (double) record.time, + record.rssi); } void write_flight_header() { @@ -117,7 +121,7 @@ public class AltosCSV { } void write_gps_header() { - out.printf("connected locked nsat latitude longitude altitude year month day hour minute second"); + out.printf("connected locked nsat latitude longitude altitude year month day hour minute second pad_dist pad_dir"); } void write_gps(AltosRecord record) { @@ -125,7 +129,11 @@ public class AltosCSV { if (gps == null) gps = new AltosGPS(); - out.printf("%2d,%2d,%3d,%12.7f,%12.7f,%6d,%5d,%3d,%3d,%3d,%3d,%3d", + AltosGreatCircle from_pad = state.from_pad; + if (from_pad == null) + from_pad = new AltosGreatCircle(); + + out.printf("%2d,%2d,%3d,%12.7f,%12.7f,%6d,%5d,%3d,%3d,%3d,%3d,%3d,%9.0f,%4.0f", gps.connected?1:0, gps.locked?1:0, gps.nsat, @@ -137,7 +145,9 @@ public class AltosCSV { gps.day, gps.hour, gps.minute, - gps.second); + gps.second, + from_pad.distance, + from_pad.bearing); } void write_header() { @@ -205,7 +215,9 @@ public class AltosCSV { write(record); } } catch (IOException ie) { + System.out.printf("IOException\n"); } catch (ParseException pe) { + System.out.printf("ParseException %s\n", pe.getMessage()); } } @@ -214,4 +226,8 @@ public class AltosCSV { out = new PrintStream(name); pad_records = new LinkedList(); } + + public AltosCSV(String in_string) throws FileNotFoundException { + this(new File(in_string)); + } } -- cgit v1.2.3 From e383595cd281687de903fb6176564bbef270cb83 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 26 Aug 2010 23:47:38 -0700 Subject: altosui: AltosEepromReader was mis-setting boost tick It was supposed to use record.tick instead of the (unset) state.tick value. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosEepromReader.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosEepromReader.java b/ao-tools/altosui/AltosEepromReader.java index deab2167..3f2d4c62 100644 --- a/ao-tools/altosui/AltosEepromReader.java +++ b/ao-tools/altosui/AltosEepromReader.java @@ -133,8 +133,6 @@ public class AltosEepromReader extends AltosReader { ground_pres += state.pres; state.ground_pres = (int) (ground_pres / n_pad_samples); state.flight_pres = state.ground_pres; - System.out.printf("ground pressure %d altitude %f\n", - record.b, state.altitude()); ground_accel += state.accel; state.ground_accel = (int) (ground_accel / n_pad_samples); state.flight_accel = state.ground_accel; @@ -156,7 +154,6 @@ public class AltosEepromReader extends AltosReader { seen |= seen_deploy; break; case Altos.AO_LOG_STATE: - System.out.printf("state %d\n", record.a); state.state = record.a; break; case Altos.AO_LOG_GPS_TIME: @@ -298,10 +295,10 @@ public class AltosEepromReader extends AltosReader { break; tick = record.tick; if (!saw_boost && record.cmd == Altos.AO_LOG_STATE && - record.a == Altos.ao_flight_boost) + record.a >= Altos.ao_flight_boost) { saw_boost = true; - boost_tick = state.tick; + boost_tick = tick; } records.add(record); } -- cgit v1.2.3 From 0942912163255523d923140c01afbdb5da1c19b5 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 26 Aug 2010 23:49:37 -0700 Subject: altosui: Add support for old (version < 3) telemetry files This lets the code read telemetry files from pre-released versions of the software. Not strictly necessary for production, but useful for analysing old files. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosGPS.java | 61 ++++++++++++++++++++++-------------- ao-tools/altosui/AltosTelemetry.java | 34 ++++++++++++++------ 2 files changed, 63 insertions(+), 32 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosGPS.java b/ao-tools/altosui/AltosGPS.java index b3ee67e8..acb6fb2c 100644 --- a/ao-tools/altosui/AltosGPS.java +++ b/ao-tools/altosui/AltosGPS.java @@ -52,14 +52,16 @@ public class AltosGPS { AltosGPSSat[] cc_gps_sat; /* tracking data */ - void ParseGPSTime(String date, String time) throws ParseException { + void ParseGPSDate(String date) throws ParseException { String[] ymd = date.split("-"); if (ymd.length != 3) throw new ParseException("error parsing GPS date " + date + " got " + ymd.length, 0); year = AltosParse.parse_int(ymd[0]); month = AltosParse.parse_int(ymd[1]); day = AltosParse.parse_int(ymd[2]); + } + void ParseGPSTime(String time) throws ParseException { String[] hms = time.split(":"); if (hms.length != 3) throw new ParseException("Error parsing GPS time " + time + " got " + hms.length, 0); @@ -73,7 +75,7 @@ public class AltosGPS { hour = minute = second = 0; } - public AltosGPS(String[] words, int i) throws ParseException { + public AltosGPS(String[] words, int i, int version) throws ParseException { AltosParse.word(words[i++], "GPS"); nsat = AltosParse.parse_int(words[i++]); AltosParse.word(words[i++], "sat"); @@ -92,32 +94,44 @@ public class AltosGPS { locked = true; connected = true; - ParseGPSTime(words[i], words[i+1]); i += 2; + if (version > 1) + ParseGPSDate(words[i++]); + else + year = month = day = 0; + ParseGPSTime(words[i++]); lat = AltosParse.parse_coord(words[i++]); lon = AltosParse.parse_coord(words[i++]); - alt = AltosParse.parse_int(AltosParse.strip_suffix(words[i++], "m")); - ground_speed = AltosParse.parse_double(AltosParse.strip_suffix(words[i++], "m/s(H)")); - course = AltosParse.parse_int(AltosParse.strip_suffix(words[i++], "°")); - climb_rate = AltosParse.parse_double(AltosParse.strip_suffix(words[i++], "m/s(V)")); - hdop = AltosParse.parse_double(AltosParse.strip_suffix(words[i++], "(hdop)")); - h_error = AltosParse.parse_int(AltosParse.strip_suffix(words[i++], "(herr)")); - v_error = AltosParse.parse_int(AltosParse.strip_suffix(words[i++], "(verr)")); + alt = AltosParse.parse_int(words[i++]); + if (version > 1 || (i < words.length && !words[i].equals("SAT"))) { + ground_speed = AltosParse.parse_double(AltosParse.strip_suffix(words[i++], "m/s(H)")); + course = AltosParse.parse_int(words[i++]); + climb_rate = AltosParse.parse_double(AltosParse.strip_suffix(words[i++], "m/s(V)")); + hdop = AltosParse.parse_double(AltosParse.strip_suffix(words[i++], "(hdop)")); + h_error = AltosParse.parse_int(words[i++]); + v_error = AltosParse.parse_int(words[i++]); + } } else { i++; } - AltosParse.word(words[i++], "SAT"); - int tracking_channels = 0; - if (words[i].equals("not-connected")) - tracking_channels = 0; - else - tracking_channels = AltosParse.parse_int(words[i]); - i++; - cc_gps_sat = new AltosGPS.AltosGPSSat[tracking_channels]; - for (int chan = 0; chan < tracking_channels; chan++) { - cc_gps_sat[chan] = new AltosGPS.AltosGPSSat(); - cc_gps_sat[chan].svid = AltosParse.parse_int(words[i++]); - cc_gps_sat[chan].c_n0 = AltosParse.parse_int(words[i++]); - } + if (i < words.length) { + AltosParse.word(words[i++], "SAT"); + int tracking_channels = 0; + if (words[i].equals("not-connected")) + tracking_channels = 0; + else + tracking_channels = AltosParse.parse_int(words[i]); + i++; + cc_gps_sat = new AltosGPS.AltosGPSSat[tracking_channels]; + for (int chan = 0; chan < tracking_channels; chan++) { + cc_gps_sat[chan] = new AltosGPS.AltosGPSSat(); + cc_gps_sat[chan].svid = AltosParse.parse_int(words[i++]); + /* Older versions included SiRF status bits */ + if (version < 2) + i++; + cc_gps_sat[chan].c_n0 = AltosParse.parse_int(words[i++]); + } + } else + cc_gps_sat = new AltosGPS.AltosGPSSat[0]; } public void set_latitude(int in_lat) { @@ -172,6 +186,7 @@ public class AltosGPS { nsat = old.nsat; locked = old.locked; connected = old.connected; + date_valid = old.date_valid; lat = old.lat; /* degrees (+N -S) */ lon = old.lon; /* degrees (+E -W) */ alt = old.alt; /* m */ diff --git a/ao-tools/altosui/AltosTelemetry.java b/ao-tools/altosui/AltosTelemetry.java index af29b8c0..bc62690b 100644 --- a/ao-tools/altosui/AltosTelemetry.java +++ b/ao-tools/altosui/AltosTelemetry.java @@ -57,8 +57,12 @@ public class AltosTelemetry extends AltosRecord { String[] words = line.split("\\s+"); int i = 0; - AltosParse.word (words[i++], "VERSION"); - version = AltosParse.parse_int(words[i++]); + if (words[i].equals("CALL")) { + version = 0; + } else { + AltosParse.word (words[i++], "VERSION"); + version = AltosParse.parse_int(words[i++]); + } AltosParse.word (words[i++], "CALL"); callsign = words[i++]; @@ -66,12 +70,19 @@ public class AltosTelemetry extends AltosRecord { AltosParse.word (words[i++], "SERIAL"); serial = AltosParse.parse_int(words[i++]); - AltosParse.word (words[i++], "FLIGHT"); - flight = AltosParse.parse_int(words[i++]); + if (version >= 2) { + AltosParse.word (words[i++], "FLIGHT"); + flight = AltosParse.parse_int(words[i++]); + } else + flight = 0; AltosParse.word(words[i++], "RSSI"); rssi = AltosParse.parse_int(words[i++]); + /* Older telemetry data had mis-computed RSSI value */ + if (version <= 2) + rssi = (rssi + 74) / 2 - 74; + AltosParse.word(words[i++], "STATUS"); status = AltosParse.parse_hex(words[i++]); @@ -113,12 +124,17 @@ public class AltosTelemetry extends AltosRecord { AltosParse.word(words[i++], "gp:"); ground_pres = AltosParse.parse_int(words[i++]); - AltosParse.word(words[i++], "a+:"); - accel_plus_g = AltosParse.parse_int(words[i++]); + if (version >= 1) { + AltosParse.word(words[i++], "a+:"); + accel_plus_g = AltosParse.parse_int(words[i++]); - AltosParse.word(words[i++], "a-:"); - accel_minus_g = AltosParse.parse_int(words[i++]); + AltosParse.word(words[i++], "a-:"); + accel_minus_g = AltosParse.parse_int(words[i++]); + } else { + accel_plus_g = ground_accel; + accel_minus_g = ground_accel + 530; + } - gps = new AltosGPS(words, i); + gps = new AltosGPS(words, i, version); } } -- cgit v1.2.3 From a16db143fc7ca72dc91e7989420049192114642d Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 26 Aug 2010 23:50:51 -0700 Subject: altosui: Serial line is in UTF-8 encoding. Deal with it. We read bytes from the serial line and need to convert each line into a string. So, save the bytes and at EOL, pass the whole mess to the string constructor with the appropriate encoding info. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosSerial.java | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosSerial.java b/ao-tools/altosui/AltosSerial.java index 3684f253..5b47960f 100644 --- a/ao-tools/altosui/AltosSerial.java +++ b/ao-tools/altosui/AltosSerial.java @@ -45,6 +45,8 @@ public class AltosSerial implements Runnable { LinkedBlockingQueue reply_queue; Thread input_thread; String line; + byte[] line_bytes; + int line_count; public void run () { int c; @@ -60,7 +62,14 @@ public class AltosSerial implements Runnable { continue; synchronized(this) { if (c == '\n') { - if (line != "") { + if (line_count != 0) { + try { + line = new String(line_bytes, 0, line_count, "UTF-8"); + } catch (UnsupportedEncodingException ue) { + line = ""; + for (int i = 0; i < line_count; i++) + line = line + line_bytes[i]; + } if (line.startsWith("VERSION")) { for (int e = 0; e < monitors.size(); e++) { LinkedBlockingQueue q = monitors.get(e); @@ -70,10 +79,19 @@ public class AltosSerial implements Runnable { // System.out.printf("GOT: %s\n", line); reply_queue.put(line); } + line_count = 0; line = ""; } } else { - line = line + (char) c; + if (line_bytes == null) { + line_bytes = new byte[256]; + } else if (line_count == line_bytes.length) { + byte[] new_line_bytes = new byte[line_count * 2]; + System.arraycopy(line_bytes, 0, new_line_bytes, 0, line_count); + line_bytes = new_line_bytes; + } + line_bytes[line_count] = (byte) c; + line_count++; } } } @@ -139,7 +157,7 @@ public class AltosSerial implements Runnable { } public void print(String data) { -// System.out.printf("\"%s\" ", data); +//h System.out.printf("\"%s\" ", data); for (int i = 0; i < data.length(); i++) putc(data.charAt(i)); } -- cgit v1.2.3 From 49364608b59de7421ab00d87d2685bc3b5f58411 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 26 Aug 2010 23:53:06 -0700 Subject: altosui: When parsing saved telem files, errors shouldn't abort file Make syntax errors in telem files just skip the current line and move on to the next one instead of abandoning the whole file. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosTelemetryReader.java | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosTelemetryReader.java b/ao-tools/altosui/AltosTelemetryReader.java index f1f6788c..a3402f9c 100644 --- a/ao-tools/altosui/AltosTelemetryReader.java +++ b/ao-tools/altosui/AltosTelemetryReader.java @@ -47,20 +47,25 @@ public class AltosTelemetryReader extends AltosReader { try { for (;;) { String line = AltosRecord.gets(input); - if (line == null) + if (line == null) { break; - AltosTelemetry record = new AltosTelemetry(line); - if (record == null) - break; - if (!saw_boost && record.state >= Altos.ao_flight_boost) - { - saw_boost = true; - boost_tick = record.tick; } - records.add(record); + try { + AltosTelemetry record = new AltosTelemetry(line); + if (record == null) + break; + if (!saw_boost && record.state >= Altos.ao_flight_boost) + { + saw_boost = true; + boost_tick = record.tick; + } + records.add(record); + } catch (ParseException pe) { + System.out.printf("parse exception %s\n", pe.getMessage()); + } } } catch (IOException io) { - } catch (ParseException pe) { + System.out.printf("io exception\n"); } record_iterator = records.iterator(); try { -- cgit v1.2.3 From 7e0506dc2014b7178f52b950e8c1cb820b35f9c6 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 26 Aug 2010 23:54:53 -0700 Subject: altosui: Remove debug printf from AltosState.java Signed-off-by: Keith Packard --- ao-tools/altosui/AltosState.java | 5 ----- 1 file changed, 5 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosState.java b/ao-tools/altosui/AltosState.java index deeb4c77..c13dfe68 100644 --- a/ao-tools/altosui/AltosState.java +++ b/ao-tools/altosui/AltosState.java @@ -124,11 +124,6 @@ public class AltosState { } if (state == Altos.ao_flight_pad) { - if (data.gps == null) - System.out.printf("on pad, gps null\n"); - else - System.out.printf ("on pad gps lat %f lon %f locked %d nsat %d\n", - data.gps.lat, data.gps.lon, data.gps.locked ? 1 : 0, data.gps.nsat); if (data.gps != null && data.gps.locked && data.gps.nsat >= 4) { npad++; if (npad > 1) { -- cgit v1.2.3 From 68967157cee620ebedcc8c2ffd6fc7656532087b Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 26 Aug 2010 23:55:44 -0700 Subject: altosui: command line args are converted to csv format Signed-off-by: Keith Packard --- ao-tools/altosui/AltosUI.java | 63 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 61 insertions(+), 2 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosUI.java b/ao-tools/altosui/AltosUI.java index 63cb486c..4f3b5dde 100644 --- a/ao-tools/altosui/AltosUI.java +++ b/ao-tools/altosui/AltosUI.java @@ -719,8 +719,67 @@ public class AltosUI extends JFrame { this.setJMenuBar(menubar); } + + static String replace_extension(String input, String extension) { + int dot = input.lastIndexOf("."); + if (dot > 0) + input = input.substring(0,dot); + return input.concat(extension); + } + + static AltosReader open_logfile(String filename) { + File file = new File (filename); + try { + FileInputStream in; + + in = new FileInputStream(file); + if (filename.endsWith("eeprom")) + return new AltosEepromReader(in); + else + return new AltosTelemetryReader(in); + } catch (FileNotFoundException fe) { + System.out.printf("Cannot open '%s'\n", filename); + return null; + } + } + + static AltosCSV open_csv(String filename) { + File file = new File (filename); + try { + return new AltosCSV(file); + } catch (FileNotFoundException fe) { + System.out.printf("Cannot open '%s'\n", filename); + return null; + } + } + + static void process_file(String input) { + String output = replace_extension(input,".csv"); + if (input.equals(output)) { + System.out.printf("Not processing '%s'\n", input); + return; + } + System.out.printf("Processing \"%s\" to \"%s\"\n", input, output); + AltosReader reader = open_logfile(input); + if (reader == null) + return; + AltosCSV writer = open_csv(output); + if (writer == null) + return; + writer.write(reader); + reader.close(); + writer.close(); + } + public static void main(final String[] args) { - AltosUI altosui = new AltosUI(); - altosui.setVisible(true); + + /* Handle batch-mode */ + if (args.length > 0) { + for (int i = 0; i < args.length; i++) + process_file(args[i]); + } else { + AltosUI altosui = new AltosUI(); + altosui.setVisible(true); + } } } \ No newline at end of file -- cgit v1.2.3 From 9ea94411c9730f7a271366d309ab4827beeeb839 Mon Sep 17 00:00:00 2001 From: Bdale Garbee Date: Fri, 27 Aug 2010 11:17:54 -0600 Subject: add a dummy install target --- ao-tools/libaltos/Makefile | 3 +++ 1 file changed, 3 insertions(+) (limited to 'ao-tools') diff --git a/ao-tools/libaltos/Makefile b/ao-tools/libaltos/Makefile index a251e54e..9933dc80 100644 --- a/ao-tools/libaltos/Makefile +++ b/ao-tools/libaltos/Makefile @@ -1,5 +1,8 @@ OS:=$(shell uname) +# dummy install target for now so I can work on the rest of the packaging +install: + @echo warning - make install doing nothing in libaltos! # # Linux # -- cgit v1.2.3 From 72c33a72ee105ec692dad62d6d9c1ad40b89bfe8 Mon Sep 17 00:00:00 2001 From: Bdale Garbee Date: Fri, 27 Aug 2010 11:45:19 -0600 Subject: add install target for libaltos --- ao-tools/libaltos/Makefile | 6 +++--- debian/dirs | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/libaltos/Makefile b/ao-tools/libaltos/Makefile index 9933dc80..cd96fd5f 100644 --- a/ao-tools/libaltos/Makefile +++ b/ao-tools/libaltos/Makefile @@ -1,8 +1,5 @@ OS:=$(shell uname) -# dummy install target for now so I can work on the rest of the packaging -install: - @echo warning - make install doing nothing in libaltos! # # Linux # @@ -17,6 +14,9 @@ OS_LDFLAGS= LIBNAME=libaltos.so EXEEXT= +install: $(LIBNAME) + /usr/bin/install -c $(LIBNAME) $(DESTDIR)/usr/lib/altos/$(LIBNAME) + endif # diff --git a/debian/dirs b/debian/dirs index db75fea7..6bf06c6e 100644 --- a/debian/dirs +++ b/debian/dirs @@ -1,5 +1,6 @@ etc/apt/sources.list.d usr/bin +usr/lib/altos usr/share/altos usr/share/applications usr/share/gdm/themes/altusmetrum -- cgit v1.2.3 From 72a18502e40f55cbba6418dc94315517881cd411 Mon Sep 17 00:00:00 2001 From: Bdale Garbee Date: Fri, 27 Aug 2010 11:51:24 -0600 Subject: add an install target for altosui --- ao-tools/altosui/Makefile | 7 ++++++- debian/dirs | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/Makefile b/ao-tools/altosui/Makefile index d3ecb889..258a334f 100644 --- a/ao-tools/altosui/Makefile +++ b/ao-tools/altosui/Makefile @@ -96,8 +96,13 @@ endif ifeq ($(OS),Linux) altosui: echo "#!/bin/sh" > $@ - echo "exec java -Djava.library.path=../libaltos -jar altosui.jar" >> $@ + echo "exec java -Djava.library.path=/usr/lib/altos/libaltos -jar altosui.jar" >> $@ chmod +x ./altosui + +install: altosui.jar altosui + /usr/bin/install -c altosui.jar $(DESTDIR)/usr/share/java/altosui.jar + /usr/bin/install -c altosui $(DESTDIR)/usr/bin/altosui + endif clean: diff --git a/debian/dirs b/debian/dirs index 6bf06c6e..7b4dffb8 100644 --- a/debian/dirs +++ b/debian/dirs @@ -4,5 +4,6 @@ usr/lib/altos usr/share/altos usr/share/applications usr/share/gdm/themes/altusmetrum +usr/share/java usr/share/pixmaps usr/share/slim/themes/altusmetrum -- cgit v1.2.3 From 63bd34cd1b5a411489e8c3ab377f0fe0eec11f67 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 27 Aug 2010 10:58:55 -0700 Subject: altosui: add elevation and range information Signed-off-by: Keith Packard --- ao-tools/altosui/AltosCSV.java | 12 ++-- ao-tools/altosui/AltosEepromReader.java | 99 ++++++++++++++++++++++++++++++++- ao-tools/altosui/AltosEepromRecord.java | 9 ++- ao-tools/altosui/AltosState.java | 13 ++++- ao-tools/altosui/AltosUI.java | 22 ++++++-- 5 files changed, 142 insertions(+), 13 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosCSV.java b/ao-tools/altosui/AltosCSV.java index db50e7a2..4ce8e30e 100644 --- a/ao-tools/altosui/AltosCSV.java +++ b/ao-tools/altosui/AltosCSV.java @@ -76,7 +76,9 @@ public class AltosCSV { * minute (0-59) * second (0-59) * from_pad_dist (m) - * from_pad_dir (deg true) + * from_pad_azimuth (deg true) + * from_pad_range (m) + * from_pad_elevation (deg from horizon) * * GPS Sat data * hdop @@ -121,7 +123,7 @@ public class AltosCSV { } void write_gps_header() { - out.printf("connected locked nsat latitude longitude altitude year month day hour minute second pad_dist pad_dir"); + out.printf("connected locked nsat latitude longitude altitude year month day hour minute second pad_dist pad_range pad_az pad_el"); } void write_gps(AltosRecord record) { @@ -133,7 +135,7 @@ public class AltosCSV { if (from_pad == null) from_pad = new AltosGreatCircle(); - out.printf("%2d,%2d,%3d,%12.7f,%12.7f,%6d,%5d,%3d,%3d,%3d,%3d,%3d,%9.0f,%4.0f", + out.printf("%2d,%2d,%3d,%12.7f,%12.7f,%6d,%5d,%3d,%3d,%3d,%3d,%3d,%9.0f,%9.0f,%4.0f,%4.0f", gps.connected?1:0, gps.locked?1:0, gps.nsat, @@ -147,7 +149,9 @@ public class AltosCSV { gps.minute, gps.second, from_pad.distance, - from_pad.bearing); + state.range, + from_pad.bearing, + state.elevation); } void write_header() { diff --git a/ao-tools/altosui/AltosEepromReader.java b/ao-tools/altosui/AltosEepromReader.java index 3f2d4c62..0705d44e 100644 --- a/ao-tools/altosui/AltosEepromReader.java +++ b/ao-tools/altosui/AltosEepromReader.java @@ -42,7 +42,7 @@ import altosui.AltosEepromMonitor; */ class AltosOrderedRecord extends AltosEepromRecord implements Comparable { - int index; + public int index; public AltosOrderedRecord(String line, int in_index, int prev_tick) throws ParseException { @@ -56,6 +56,11 @@ class AltosOrderedRecord extends AltosEepromRecord implements Comparable> Altos.AO_GPS_NUM_SAT_SHIFT; + System.out.printf("GPS %2d:%02d:%02d%s%s%s %d\n", + state.gps.hour, state.gps.minute, state.gps.second, + state.gps.connected ? " connected" : "", + state.gps.locked ? " locked" : "", + state.gps.date_valid ? " date_valid" : "", + state.gps.nsat); break; case Altos.AO_LOG_GPS_LAT: int lat32 = record.a | (record.b << 16); @@ -267,6 +282,38 @@ public class AltosEepromReader extends AltosReader { } } + /* + * Given an AO_LOG_GPS_TIME record with correct time, and one + * missing time, rewrite the missing time values with the good + * ones, assuming that the difference between them is 'diff' seconds + */ + void update_time(AltosOrderedRecord good, AltosOrderedRecord bad) { + + int diff = (bad.tick - good.tick + 50) / 100; + + int hour = (good.a & 0xff); + int minute = (good.a >> 8); + int second = (good.b & 0xff); + int flags = (good.b >> 8); + int seconds = hour * 3600 + minute * 60 + second; + + int new_seconds = seconds + diff; + if (new_seconds < 0) + new_seconds += 24 * 3600; + int new_second = (new_seconds % 60); + int new_minutes = (new_seconds / 60); + int new_minute = (new_minutes % 60); + int new_hours = (new_minutes / 60); + int new_hour = (new_hours % 24); + + System.out.printf("Synthesizing time good %2d:%02d:%02d bad %2d:%02d:%02d\n", + hour, minute, second, + new_hour, new_minute, new_second); + + bad.a = new_hour + (new_minute << 8); + bad.b = new_second + (flags << 8); + } + /* * Read the whole file, dumping records into a RB tree so * we can enumerate them in time order -- the eeprom data @@ -282,9 +329,13 @@ public class AltosEepromReader extends AltosReader { seen = 0; records = new TreeSet(); + AltosOrderedRecord last_gps_time = null; + int index = 0; int tick = 0; + boolean missing_time = false; + try { for (;;) { String line = AltosRecord.gets(input); @@ -300,6 +351,52 @@ public class AltosEepromReader extends AltosReader { saw_boost = true; boost_tick = tick; } + + /* Two firmware bugs caused the loss of some GPS data. + * The flight date would never be recorded, and often + * the flight time would get overwritten by another + * record. Detect the loss of the GPS date and fix up the + * missing time records + */ + if (record.cmd == Altos.AO_LOG_GPS_DATE) + saw_gps_date = true; + + /* go back and fix up any missing time values */ + if (record.cmd == Altos.AO_LOG_GPS_TIME) { + last_gps_time = record; + if (missing_time) { + System.out.printf("Going back to clean up broken GPS time records\n"); + Iterator iterator = records.iterator(); + while (iterator.hasNext()) { + AltosOrderedRecord old = iterator.next(); + if (old.cmd == Altos.AO_LOG_GPS_TIME) { + System.out.printf("Old time record %d, %d\n", old.a, old.b); + } + if (old.cmd == Altos.AO_LOG_GPS_TIME && + old.a == -1 && old.b == -1) + { + update_time(record, old); + } + } + missing_time = false; + } + } + + if (record.cmd == Altos.AO_LOG_GPS_LAT) { + if (last_gps_time == null || last_gps_time.tick != record.tick) { + AltosOrderedRecord add_gps_time = new AltosOrderedRecord(Altos.AO_LOG_GPS_TIME, + record.tick, + -1, -1, index-1); + if (last_gps_time != null) + update_time(last_gps_time, add_gps_time); + else { + System.out.printf("early GPS missing time\n"); + missing_time = true; + } + records.add(add_gps_time); + record.index = index++; + } + } records.add(record); } } catch (IOException io) { diff --git a/ao-tools/altosui/AltosEepromRecord.java b/ao-tools/altosui/AltosEepromRecord.java index 86ac1fd2..4d0817ab 100644 --- a/ao-tools/altosui/AltosEepromRecord.java +++ b/ao-tools/altosui/AltosEepromRecord.java @@ -44,7 +44,7 @@ public class AltosEepromRecord { public int tick; public int a; public int b; - String data; + public String data; public boolean tick_valid; public AltosEepromRecord (String line) throws ParseException { @@ -107,4 +107,11 @@ public class AltosEepromRecord { } } + public AltosEepromRecord(int in_cmd, int in_tick, int in_a, int in_b) { + tick_valid = true; + cmd = in_cmd; + tick = in_tick; + a = in_a; + b = in_b; + } } diff --git a/ao-tools/altosui/AltosState.java b/ao-tools/altosui/AltosState.java index c13dfe68..3ef00f35 100644 --- a/ao-tools/altosui/AltosState.java +++ b/ao-tools/altosui/AltosState.java @@ -64,6 +64,8 @@ public class AltosState { boolean gps_ready; AltosGreatCircle from_pad; + double elevation; /* from pad */ + double range; /* total distance */ double gps_height; @@ -124,7 +126,7 @@ public class AltosState { } if (state == Altos.ao_flight_pad) { - if (data.gps != null && data.gps.locked && data.gps.nsat >= 4) { + if (data.gps != null && data.gps.locked) { npad++; if (npad > 1) { /* filter pad position */ @@ -161,11 +163,18 @@ public class AltosState { if (data.gps != null) { if (gps == null || !gps.locked || data.gps.locked) gps = data.gps; - if (npad > 0 && gps.locked) + if (npad > 0 && gps.locked) { from_pad = new AltosGreatCircle(pad_lat, pad_lon, gps.lat, gps.lon); + } } + elevation = 0; + range = -1; if (npad > 0) { gps_height = gps.alt - pad_alt; + if (from_pad != null) { + elevation = Math.atan2(height, from_pad.distance) * 180 / Math.PI; + range = Math.sqrt(height * height + from_pad.distance * from_pad.distance); + } } else { gps_height = 0; } diff --git a/ao-tools/altosui/AltosUI.java b/ao-tools/altosui/AltosUI.java index 4f3b5dde..5b48e26f 100644 --- a/ao-tools/altosui/AltosUI.java +++ b/ao-tools/altosui/AltosUI.java @@ -264,7 +264,7 @@ public class AltosUI extends JFrame { private AltosState state; int reported_landing; - public void report(boolean last) { + public synchronized void report(boolean last) { if (state == null) return; @@ -278,7 +278,16 @@ public class AltosUI extends JFrame { } /* If the rocket isn't on the pad, then report height */ - if (state.state > Altos.ao_flight_pad) { + if (Altos.ao_flight_drogue <= state.state && + state.state < Altos.ao_flight_landed && + state.range >= 0) + { + voice.speak("Height %d, bearing %d, elevation %d, range %d.\n", + (int) (state.height + 0.5), + (int) (state.from_pad.bearing + 0.5), + (int) (state.elevation + 0.5), + (int) (state.range + 0.5)); + } else if (state.state > Altos.ao_flight_pad) { voice.speak("%d meters", (int) (state.height + 0.5)); } else { reported_landing = 0; @@ -288,7 +297,7 @@ public class AltosUI extends JFrame { * either we've got a landed report or we haven't heard from it in * a long time */ - if (!state.ascent && + if (state.state >= Altos.ao_flight_drogue && (last || System.currentTimeMillis() - state.report_time >= 15000 || state.state == Altos.ao_flight_landed)) @@ -298,7 +307,7 @@ public class AltosUI extends JFrame { else voice.speak("rocket may have crashed"); if (state.from_pad != null) - voice.speak("bearing %d degrees, range %d meters", + voice.speak("Bearing %d degrees, range %d meters.", (int) (state.from_pad.bearing + 0.5), (int) (state.from_pad.distance + 0.5)); ++reported_landing; @@ -311,7 +320,7 @@ public class AltosUI extends JFrame { state = null; try { for (;;) { - Thread.sleep(10000); + Thread.sleep(20000); report(false); } } catch (InterruptedException ie) { @@ -319,7 +328,10 @@ public class AltosUI extends JFrame { } public void notice(AltosState new_state) { + AltosState old_state = state; state = new_state; + if (old_state != null && old_state.state != state.state) + report(false); } } -- cgit v1.2.3 From c280071b7db4e9a7af31dc5740eb8d27f137950e Mon Sep 17 00:00:00 2001 From: Bdale Garbee Date: Fri, 27 Aug 2010 12:04:13 -0600 Subject: fix up the wrapper's path to the jar file --- ao-tools/altosui/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/Makefile b/ao-tools/altosui/Makefile index 258a334f..73bc230d 100644 --- a/ao-tools/altosui/Makefile +++ b/ao-tools/altosui/Makefile @@ -96,7 +96,7 @@ endif ifeq ($(OS),Linux) altosui: echo "#!/bin/sh" > $@ - echo "exec java -Djava.library.path=/usr/lib/altos/libaltos -jar altosui.jar" >> $@ + echo "exec java -Djava.library.path=/usr/lib/altos/libaltos -jar /usr/share/java/altosui.jar" >> $@ chmod +x ./altosui install: altosui.jar altosui -- cgit v1.2.3 From 5cc933039e4763b8675611c63b6147b42878a2bb Mon Sep 17 00:00:00 2001 From: Bdale Garbee Date: Fri, 27 Aug 2010 12:16:19 -0600 Subject: fix permissions on installed jar file, switch from ao-view to altosui in the desktop file --- ao-tools/altosui/Makefile | 4 ++-- ao-tools/altosui/altosui.1 | 44 ++++++++++++++++++++++++++++++++++++++++++++ debian/altos.desktop | 4 ++-- 3 files changed, 48 insertions(+), 4 deletions(-) create mode 100644 ao-tools/altosui/altosui.1 (limited to 'ao-tools') diff --git a/ao-tools/altosui/Makefile b/ao-tools/altosui/Makefile index 73bc230d..101954db 100644 --- a/ao-tools/altosui/Makefile +++ b/ao-tools/altosui/Makefile @@ -100,8 +100,8 @@ altosui: chmod +x ./altosui install: altosui.jar altosui - /usr/bin/install -c altosui.jar $(DESTDIR)/usr/share/java/altosui.jar - /usr/bin/install -c altosui $(DESTDIR)/usr/bin/altosui + /usr/bin/install -m 0644 altosui.jar $(DESTDIR)/usr/share/java/altosui.jar + /usr/bin/install altosui $(DESTDIR)/usr/bin/altosui endif diff --git a/ao-tools/altosui/altosui.1 b/ao-tools/altosui/altosui.1 new file mode 100644 index 00000000..c3130fce --- /dev/null +++ b/ao-tools/altosui/altosui.1 @@ -0,0 +1,44 @@ +.\" +.\" Copyright © 2010 Bdale Garbee +.\" +.\" 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; 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 +.\" 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. +.\" +.\" +.TH AO-VIEW 1 "altosui" "" +.SH NAME +altosui \- Rocket flight monitor +.SH SYNOPSIS +.B "altosui" +.SH DESCRIPTION +.I altosui +connects to a TeleDongle or TeleMetrum device through a USB serial device. +It provides a user interface to monitor, record and review rocket flight data. +.SH USAGE +When connected to a TeleDongle device, altosui turns on the radio +receiver and listens for telemetry packets. It displays the received +telemetry data, and reports flight status via voice synthesis. All +received telemetry information is recorded to a file. +.P +When connected to a TeleMetrum device, altosui downloads the eeprom +data and stores it in a file. +.SH FILES +All data log files are recorded into a user-specified directory +(default ~/AltOS). Files are named using the current date, the serial +number of the reporting device, the flight number recorded in the data +and either '.telem' for telemetry data or '.eeprom' for eeprom data. +.SH "SEE ALSO" +ao-view(1), ao-load(1), ao-eeprom(1) +.SH AUTHOR +Keith Packard diff --git a/debian/altos.desktop b/debian/altos.desktop index 4281ad3a..4345cf09 100644 --- a/debian/altos.desktop +++ b/debian/altos.desktop @@ -1,10 +1,10 @@ [Desktop Entry] Type=Application -Name=AltOS View +Name=AltOS UI GenericName=TeleMetrum Telemetry Viewer Comment=View and log downlink data from TeleMetrum Icon=/usr/share/pixmaps/altusmetrum.xpm -Exec=/usr/bin/ao-view %f +Exec=/usr/bin/altosui %f Terminal=false MimeType=text/plain; Categories=Education;Science; -- cgit v1.2.3 From a8dbe082960dc9bdd44c6e4b1198423c4e566029 Mon Sep 17 00:00:00 2001 From: Bdale Garbee Date: Fri, 27 Aug 2010 12:18:28 -0600 Subject: install altosui man page --- ao-tools/altosui/Makefile | 1 + 1 file changed, 1 insertion(+) (limited to 'ao-tools') diff --git a/ao-tools/altosui/Makefile b/ao-tools/altosui/Makefile index 101954db..df960130 100644 --- a/ao-tools/altosui/Makefile +++ b/ao-tools/altosui/Makefile @@ -101,6 +101,7 @@ altosui: install: altosui.jar altosui /usr/bin/install -m 0644 altosui.jar $(DESTDIR)/usr/share/java/altosui.jar + /usr/bin/install -m 0644 altosui.1 $(DESTDIR)/usr/share/man/altosui.1 /usr/bin/install altosui $(DESTDIR)/usr/bin/altosui endif -- cgit v1.2.3 From de2e71c4923a0282df74dbe37d087c34b4ddd279 Mon Sep 17 00:00:00 2001 From: Bdale Garbee Date: Fri, 27 Aug 2010 12:25:20 -0600 Subject: fix man page delivery path --- ao-tools/altosui/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/Makefile b/ao-tools/altosui/Makefile index df960130..22752d5d 100644 --- a/ao-tools/altosui/Makefile +++ b/ao-tools/altosui/Makefile @@ -101,7 +101,7 @@ altosui: install: altosui.jar altosui /usr/bin/install -m 0644 altosui.jar $(DESTDIR)/usr/share/java/altosui.jar - /usr/bin/install -m 0644 altosui.1 $(DESTDIR)/usr/share/man/altosui.1 + /usr/bin/install -m 0644 altosui.1 $(DESTDIR)/usr/share/man/man1/altosui.1 /usr/bin/install altosui $(DESTDIR)/usr/bin/altosui endif -- cgit v1.2.3 From 0bd4cc03b3bf23aa32b5ce1921078021d1d8a9c6 Mon Sep 17 00:00:00 2001 From: Bdale Garbee Date: Fri, 27 Aug 2010 13:12:46 -0600 Subject: fix path to installed shared library --- ao-tools/altosui/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/Makefile b/ao-tools/altosui/Makefile index 22752d5d..770abcf3 100644 --- a/ao-tools/altosui/Makefile +++ b/ao-tools/altosui/Makefile @@ -96,7 +96,7 @@ endif ifeq ($(OS),Linux) altosui: echo "#!/bin/sh" > $@ - echo "exec java -Djava.library.path=/usr/lib/altos/libaltos -jar /usr/share/java/altosui.jar" >> $@ + echo "exec java -Djava.library.path=/usr/lib/altos -jar /usr/share/java/altosui.jar" >> $@ chmod +x ./altosui install: altosui.jar altosui -- cgit v1.2.3 From edcfb1bdf64772d3b83405ccf99385b8fea5d8e4 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 29 Aug 2010 17:33:59 -0700 Subject: libaltos: AltusMetrum devices use more than one USB ID. List all usb devices, picking those with AltusMetrum IDs. Signed-off-by: Keith Packard --- ao-tools/libaltos/libaltos.c | 45 +++++++++++++++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 11 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/libaltos/libaltos.c b/ao-tools/libaltos/libaltos.c index ffdb2366..93c483d1 100644 --- a/ao-tools/libaltos/libaltos.c +++ b/ao-tools/libaltos/libaltos.c @@ -391,24 +391,40 @@ get_string(io_object_t object, CFStringRef entry, char *result, int result_len) return 0; } +static int +get_number(io_object_t object, CFStringRef entry, int *result) +{ + CFTypeRef entry_as_number; + Boolean got_number; + + entry_as_number = IORegistryEntrySearchCFProperty (object, + kIOServicePlane, + entry, + kCFAllocatorDefault, + kIORegistryIterateRecursively); + if (entry_as_number) { + got_number = CFNumberGetValue(entry_as_number, + kCFNumberIntType, + result); + if (got_number) + return 1; + } + return 0; +} + struct altos_list * altos_list_start(void) { struct altos_list *list = calloc (sizeof (struct altos_list), 1); CFMutableDictionaryRef matching_dictionary = IOServiceMatching("IOUSBDevice"); - UInt32 vendor = 0xfffe, product = 0x000a; - CFNumberRef vendor_ref = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &vendor); - CFNumberRef product_ref = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &product); io_iterator_t tdIterator; io_object_t tdObject; - - CFDictionaryAddValue(matching_dictionary, CFSTR(kUSBVendorID), vendor_ref); - CFDictionaryAddValue(matching_dictionary, CFSTR(kUSBProductID), product_ref); + kern_return_t ret; + int i; - IOServiceGetMatchingServices(kIOMasterPortDefault, matching_dictionary, &list->iterator); - - CFRelease(vendor_ref); - CFRelease(product_ref); + ret = IOServiceGetMatchingServices(kIOMasterPortDefault, matching_dictionary, &list->iterator); + if (ret != kIOReturnSuccess) + return NULL; return list; } @@ -423,8 +439,15 @@ altos_list_next(struct altos_list *list, struct altos_device *device) if (!object) return 0; + if (!get_number (object, CFSTR(kUSBVendorID), &device->vendor) || + !get_number (object, CFSTR(kUSBProductID), &device->product)) + continue; + if (device->vendor != 0xfffe) + continue; + if (device->product < 0x000a || 0x0013 < device->product) + continue; if (get_string (object, CFSTR("IOCalloutDevice"), device->path, sizeof (device->path)) && - get_string (object, CFSTR("USB Product Name"), device->product, sizeof (device->product)) && + get_string (object, CFSTR("USB Product Name"), device->name, sizeof (device->name)) && get_string (object, CFSTR("USB Serial Number"), serial_string, sizeof (serial_string))) { device->serial = atoi(serial_string); return 1; -- cgit v1.2.3 From ae02b1590439d5c8dfb472cf1f83a14fdcfbaf11 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 29 Aug 2010 21:36:47 -0700 Subject: altosui: provide separate flush_input/flush_output for serial. deal with monitor automatically (yes, this should be two patches, but the diffs in AltosSerial were merged together). First, this replaces the existing flush/flush_reply mess with two simple functions, one to flush output to the serial device, making sure that all data written will be seen while we wait for input. The other sucks any pending input off of the serial line and discards it. Second, AltosSerial now tracks whether the serial line is being used for telemetry monitoring. If so, it enables monitoring, otherwise it disables it. Eliminates a bunch of manual state tracking elsewhere. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosConfig.java | 6 +-- ao-tools/altosui/AltosDebug.java | 8 ++-- ao-tools/altosui/AltosEepromDownload.java | 5 ++- ao-tools/altosui/AltosSerial.java | 62 ++++++++++++++++++++----------- 4 files changed, 50 insertions(+), 31 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosConfig.java b/ao-tools/altosui/AltosConfig.java index ac73e7c5..3d970748 100644 --- a/ao-tools/altosui/AltosConfig.java +++ b/ao-tools/altosui/AltosConfig.java @@ -122,17 +122,17 @@ public class AltosConfig implements Runnable, ActionListener { void start_serial() throws InterruptedException { if (remote) { - serial_line.printf("m 0\n"); serial_line.set_channel(AltosPreferences.channel()); serial_line.set_callsign(AltosPreferences.callsign()); serial_line.printf("p\n"); + serial_line.flush_input(); } } void stop_serial() throws InterruptedException { if (remote) { - serial_line.printf("~\n"); - serial_line.flush(); + serial_line.printf("~"); + serial_line.flush_output(); } } diff --git a/ao-tools/altosui/AltosDebug.java b/ao-tools/altosui/AltosDebug.java index ca2e5a90..3f469d48 100644 --- a/ao-tools/altosui/AltosDebug.java +++ b/ao-tools/altosui/AltosDebug.java @@ -62,8 +62,8 @@ public class AltosDebug extends AltosSerial { void ensure_debug_mode() { if (!debug_mode) { - printf("m 0\nD\n"); - flush_reply(); + printf("D\n"); + flush_input(); debug_mode = true; } } @@ -103,7 +103,7 @@ public class AltosDebug extends AltosSerial { throws IOException, InterruptedException { byte[] data = new byte[length]; - flush_reply(); + flush_input(); ensure_debug_mode(); printf("I %x %x\n", length, address); int i = 0; @@ -155,7 +155,7 @@ public class AltosDebug extends AltosSerial { public byte[] read_bytes(int length) throws IOException, InterruptedException { - flush_reply(); + flush_input(); ensure_debug_mode(); printf("G %x\n", length); int i = 0; diff --git a/ao-tools/altosui/AltosEepromDownload.java b/ao-tools/altosui/AltosEepromDownload.java index 02a71118..5e43345b 100644 --- a/ao-tools/altosui/AltosEepromDownload.java +++ b/ao-tools/altosui/AltosEepromDownload.java @@ -223,10 +223,10 @@ public class AltosEepromDownload implements Runnable { public void run () { if (remote) { - serial_line.printf("m 0\n"); serial_line.set_channel(AltosPreferences.channel()); serial_line.set_callsign(AltosPreferences.callsign()); - serial_line.printf("p\n"); + serial_line.printf("p\nE 0\n"); + serial_line.flush_input(); } monitor = new AltosEepromMonitor(frame, Altos.ao_flight_boost, Altos.ao_flight_landed); @@ -247,6 +247,7 @@ public class AltosEepromDownload implements Runnable { if (remote) serial_line.printf("~"); monitor.done(); + serial_line.flush_output(); serial_line.close(); } diff --git a/ao-tools/altosui/AltosSerial.java b/ao-tools/altosui/AltosSerial.java index 5b47960f..99ba3324 100644 --- a/ao-tools/altosui/AltosSerial.java +++ b/ao-tools/altosui/AltosSerial.java @@ -47,6 +47,7 @@ public class AltosSerial implements Runnable { String line; byte[] line_bytes; int line_count; + boolean monitor_mode; public void run () { int c; @@ -99,35 +100,39 @@ public class AltosSerial implements Runnable { } } - public void flush_reply() { + public void flush_output() { libaltos.altos_flush(altos); + } + + public void flush_input() { + flush_output(); try { - Thread.sleep(100); + Thread.sleep(200); } catch (InterruptedException ie) { } - reply_queue.clear(); + synchronized(this) { + if (!"VERSION".startsWith(line) && + !line.startsWith("VERSION")) + line = ""; + reply_queue.clear(); + } } public String get_reply() throws InterruptedException { - libaltos.altos_flush(altos); + flush_output(); String line = reply_queue.take(); return line; } public void add_monitor(LinkedBlockingQueue q) { + set_monitor(true); monitors.add(q); } public void remove_monitor(LinkedBlockingQueue q) { monitors.remove(q); - } - - public void flush () { - synchronized(this) { - if (!"VERSION".startsWith(line) && !line.startsWith("VERSION")) - line = ""; - reply_queue.clear(); - } + if (monitors.isEmpty()) + set_monitor(false); } public boolean opened() { @@ -135,8 +140,9 @@ public class AltosSerial implements Runnable { } public void close() { - if (altos != null) + if (altos != null) { libaltos.altos_close(altos); + } if (input_thread != null) { try { input_thread.interrupt(); @@ -157,7 +163,7 @@ public class AltosSerial implements Runnable { } public void print(String data) { -//h System.out.printf("\"%s\" ", data); +// System.out.printf("\"%s\" ", data); for (int i = 0; i < data.length(); i++) putc(data.charAt(i)); } @@ -173,17 +179,28 @@ public class AltosSerial implements Runnable { throw new FileNotFoundException(device.getPath()); input_thread = new Thread(this); input_thread.start(); - print("\nE 0\n"); - try { - Thread.sleep(200); - } catch (InterruptedException e) { - } - flush(); + print("~\nE 0\n"); + set_monitor(monitor_mode); + flush_input(); } public void set_channel(int channel) { - if (altos != null) - printf("m 0\nc r %d\nm 1\n", channel); + if (altos != null) { + if (monitor_mode) + printf("m 0\nc r %d\nm 1\n", channel); + else + printf("c r %d\n", channel); + } + } + + void set_monitor(boolean monitor) { + monitor_mode = monitor; + if (altos != null) { + if (monitor) + printf("m 1\n"); + else + printf("m 0\n"); + } } public void set_callsign(String callsign) { @@ -195,6 +212,7 @@ public class AltosSerial implements Runnable { altos = null; input_thread = null; line = ""; + monitor_mode = false; monitors = new LinkedList> (); reply_queue = new LinkedBlockingQueue (); } -- cgit v1.2.3 From e60c59123232915e808cee23ef89eb1a38ced34b Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 29 Aug 2010 21:40:21 -0700 Subject: altosui: discard invalid lines while reading Eeprom flight data This shouldn't happen, but it's easy enough to get back in sync by just skipping lines with weird contents. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosEepromDownload.java | 1 + 1 file changed, 1 insertion(+) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosEepromDownload.java b/ao-tools/altosui/AltosEepromDownload.java index 5e43345b..6dbbd3eb 100644 --- a/ao-tools/altosui/AltosEepromDownload.java +++ b/ao-tools/altosui/AltosEepromDownload.java @@ -142,6 +142,7 @@ public class AltosEepromDownload implements Runnable { if (values == null) { System.out.printf("invalid line: %s\n", line); + continue; } else if (values[0] != addr) { System.out.printf("data address out of sync at 0x%x\n", block * 256 + values[0]); -- cgit v1.2.3 From b7fa1ea3338f63b8edcf8aacccb5e519ca0b213f Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 29 Aug 2010 21:41:40 -0700 Subject: libaltos: Mac OS X cannot use 'poll(2)' on serial lines. Who ships this stuff, anyway? Instead of blocking, we'll poll every 100ms now, otherwise, we won't be able to abort the read when the device is closed. Yay! Signed-off-by: Keith Packard --- ao-tools/libaltos/libaltos.c | 134 +++++++++++++++++++++++++++---------------- 1 file changed, 86 insertions(+), 48 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/libaltos/libaltos.c b/ao-tools/libaltos/libaltos.c index 93c483d1..65cd6c1a 100644 --- a/ao-tools/libaltos/libaltos.c +++ b/ao-tools/libaltos/libaltos.c @@ -21,6 +21,8 @@ #include #include +#define USE_POLL + PUBLIC int altos_init(void) { @@ -33,6 +35,9 @@ altos_fini(void) } #ifdef DARWIN + +#undef USE_POLL + /* Mac OS X don't have strndup even if _GNU_SOURCE is defined */ static char * altos_strndup (const char *s, size_t n) @@ -471,20 +476,21 @@ altos_list_finish(struct altos_list *list) #include #include #include -#include #define USB_BUF_SIZE 64 struct altos_file { int fd; +#ifdef USE_POLL int pipe[2]; +#else + int out_fd; +#endif unsigned char out_data[USB_BUF_SIZE]; int out_used; unsigned char in_data[USB_BUF_SIZE]; int in_used; int in_read; - pthread_mutex_t putc_mutex; - pthread_mutex_t getc_mutex; }; struct altos_file * @@ -497,32 +503,54 @@ altos_open(struct altos_device *device) if (!file) return NULL; - pipe(file->pipe); + printf("open %s\n", device->path); file->fd = open(device->path, O_RDWR | O_NOCTTY); + printf("opened %d\n", file->fd); if (file->fd < 0) { perror(device->path); free(file); return NULL; } +#ifdef USE_POLL + pipe(file->pipe); +#else + file->out_fd = open(device->path, O_RDWR | O_NOCTTY); + if (file->out_fd < 0) { + perror(device->path); + close(file->fd); + free(file); + return NULL; + } +#endif ret = tcgetattr(file->fd, &term); if (ret < 0) { perror("tcgetattr"); close(file->fd); +#ifndef USE_POLL + close(file->out_fd); +#endif free(file); return NULL; } cfmakeraw(&term); +#ifdef USE_POLL term.c_cc[VMIN] = 1; term.c_cc[VTIME] = 0; +#else + term.c_cc[VMIN] = 0; + term.c_cc[VTIME] = 1; +#endif ret = tcsetattr(file->fd, TCSAFLUSH, &term); if (ret < 0) { perror("tcsetattr"); close(file->fd); +#ifndef USE_POLL + close(file->out_fd); +#endif free(file); return NULL; } - pthread_mutex_init(&file->putc_mutex,NULL); - pthread_mutex_init(&file->getc_mutex,NULL); + printf("running %d\n", file->fd); return file; } @@ -532,7 +560,13 @@ altos_close(struct altos_file *file) if (file->fd != -1) { int fd = file->fd; file->fd = -1; +#ifdef USE_POLL write(file->pipe[1], "\r", 1); +#else + close(file->out_fd); + file->out_fd = -1; +#endif + printf("close %d\n", fd); close(fd); } } @@ -544,16 +578,20 @@ altos_free(struct altos_file *file) free(file); } -static int -_altos_flush(struct altos_file *file) +int +altos_flush(struct altos_file *file) { while (file->out_used) { int ret; if (file->fd < 0) return -EBADF; - fflush(stdout); + printf("write %d\n", file->out_used); +#ifdef USE_POLL ret = write (file->fd, file->out_data, file->out_used); +#else + ret = write (file->out_fd, file->out_data, file->out_used); +#endif if (ret < 0) return -errno; if (ret) { @@ -562,6 +600,7 @@ _altos_flush(struct altos_file *file) file->out_used -= ret; } } + return 0; } int @@ -569,79 +608,81 @@ altos_putchar(struct altos_file *file, char c) { int ret; - pthread_mutex_lock(&file->putc_mutex); if (file->out_used == USB_BUF_SIZE) { - ret = _altos_flush(file); + ret = altos_flush(file); if (ret) { - pthread_mutex_unlock(&file->putc_mutex); return ret; } } file->out_data[file->out_used++] = c; ret = 0; if (file->out_used == USB_BUF_SIZE) - ret = _altos_flush(file); - pthread_mutex_unlock(&file->putc_mutex); + ret = altos_flush(file); return 0; } -int -altos_flush(struct altos_file *file) -{ - int ret; - pthread_mutex_lock(&file->putc_mutex); - ret = _altos_flush(file); - pthread_mutex_unlock(&file->putc_mutex); - return ret; -} - - +#ifdef USE_POLL #include +#endif int -altos_getchar(struct altos_file *file, int timeout) +altos_fill(struct altos_file *file, int timeout) { int ret; +#ifdef USE_POLL struct pollfd fd[2]; +#endif if (timeout == 0) timeout = -1; - pthread_mutex_lock(&file->getc_mutex); - fd[0].fd = file->fd; - fd[0].events = POLLIN; - fd[1].fd = file->pipe[0]; - fd[1].events = POLLIN; while (file->in_read == file->in_used) { - if (file->fd < 0) { - pthread_mutex_unlock(&file->getc_mutex); + if (file->fd < 0) return LIBALTOS_ERROR; - } - altos_flush(file); - +#ifdef USE_POLL + fd[0].fd = file->fd; + fd[0].events = POLLIN; + fd[1].fd = file->pipe[0]; + fd[1].events = POLLIN; ret = poll(fd, 2, timeout); if (ret < 0) { perror("altos_getchar"); - pthread_mutex_unlock(&file->getc_mutex); return LIBALTOS_ERROR; } - if (ret == 0) { - pthread_mutex_unlock(&file->getc_mutex); + if (ret == 0) return LIBALTOS_TIMEOUT; - } - if (fd[0].revents & POLLIN) { + if (fd[0].revents & POLLIN) +#endif + { ret = read(file->fd, file->in_data, USB_BUF_SIZE); + if (ret) + printf("read %d\n", ret); if (ret < 0) { perror("altos_getchar"); - pthread_mutex_unlock(&file->getc_mutex); return LIBALTOS_ERROR; } file->in_read = 0; file->in_used = ret; +#ifndef USE_POLL + if (ret == 0 && timeout > 0) + return LIBALTOS_TIMEOUT; +#endif } } - ret = file->in_data[file->in_read++]; - pthread_mutex_unlock(&file->getc_mutex); - return ret; + return 0; +} + +int +altos_getchar(struct altos_file *file, int timeout) +{ + int ret; + while (file->in_read == file->in_used) { + if (file->fd < 0) + return LIBALTOS_ERROR; + ret = altos_fill(file, timeout); + if (ret) + return ret; + } + return file->in_data[file->in_read++]; } #endif /* POSIX_TTY */ @@ -919,9 +960,6 @@ altos_getchar(struct altos_file *file, int timeout) { int ret; while (file->in_read == file->in_used) { - ret = altos_flush(file); - if (ret) - return ret; if (file->handle == INVALID_HANDLE_VALUE) return LIBALTOS_ERROR; ret = altos_fill(file, timeout); -- cgit v1.2.3 From 6527357d1f0e94faf9e7dacac10a39875131be7c Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 29 Aug 2010 21:43:46 -0700 Subject: libaltos: Missing OS_LDFLAGS on cjnitest build --- ao-tools/libaltos/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/libaltos/Makefile b/ao-tools/libaltos/Makefile index cd96fd5f..f336f22f 100644 --- a/ao-tools/libaltos/Makefile +++ b/ao-tools/libaltos/Makefile @@ -96,8 +96,8 @@ SRCS = libaltos.c $(SWIG_WRAP) OBJS = $(SRCS:%.c=%.o) LIBS = $(DARWIN_LIBS) -$(CJNITEST): cjnitest.o $(OBJS) - cc -o $@ $(CFLAGS) cjnitest.o $(OBJS) $(LIBS) +$(CJNITEST): cjnitest.o $(LIBNAME) + cc -o $@ $(CFLAGS) cjnitest.o $(OBJS) $(LIBNAME) $(LIBS) $(OS_LDFLAGS) $(LIBNAME): $(OBJS) gcc -shared $(CFLAGS) -o $@ $(OBJS) $(LIBS) $(LDFLAGS) -- cgit v1.2.3 From 1acd3c7ec167b1b18e4ea493e5978c938a91cc89 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 29 Aug 2010 21:45:19 -0700 Subject: libaltos: cjnitest needs altos_flush now --- ao-tools/libaltos/cjnitest.c | 1 + 1 file changed, 1 insertion(+) (limited to 'ao-tools') diff --git a/ao-tools/libaltos/cjnitest.c b/ao-tools/libaltos/cjnitest.c index 93d1f376..c6d6e069 100644 --- a/ao-tools/libaltos/cjnitest.c +++ b/ao-tools/libaltos/cjnitest.c @@ -30,6 +30,7 @@ main () continue; } altos_puts(file,"v\nc s\n"); + altos_flush(file); while ((c = altos_getchar(file, 100)) >= 0) { putchar (c); } -- cgit v1.2.3 From dd5374b8e660012ae4f8b058454fd101e0749ca7 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 30 Aug 2010 02:00:30 -0700 Subject: libaltos: Fix windows build. Need stdlib.h to get calloc/free defined, remove debug printfs, fix serial timeouts. Signed-off-by: Keith Packard --- ao-tools/libaltos/libaltos.c | 108 ++++++++++++++++++++----------------------- ao-tools/libaltos/libaltos.h | 2 + 2 files changed, 51 insertions(+), 59 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/libaltos/libaltos.c b/ao-tools/libaltos/libaltos.c index 65cd6c1a..1d3b26dd 100644 --- a/ao-tools/libaltos/libaltos.c +++ b/ao-tools/libaltos/libaltos.c @@ -15,7 +15,6 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -#define BUILD_DLL #include "libaltos.h" #include #include @@ -503,9 +502,7 @@ altos_open(struct altos_device *device) if (!file) return NULL; - printf("open %s\n", device->path); file->fd = open(device->path, O_RDWR | O_NOCTTY); - printf("opened %d\n", file->fd); if (file->fd < 0) { perror(device->path); free(file); @@ -550,7 +547,6 @@ altos_open(struct altos_device *device) free(file); return NULL; } - printf("running %d\n", file->fd); return file; } @@ -566,7 +562,6 @@ altos_close(struct altos_file *file) close(file->out_fd); file->out_fd = -1; #endif - printf("close %d\n", fd); close(fd); } } @@ -586,7 +581,6 @@ altos_flush(struct altos_file *file) if (file->fd < 0) return -EBADF; - printf("write %d\n", file->out_used); #ifdef USE_POLL ret = write (file->fd, file->out_data, file->out_used); #else @@ -654,8 +648,6 @@ altos_fill(struct altos_file *file, int timeout) #endif { ret = read(file->fd, file->in_data, USB_BUF_SIZE); - if (ret) - printf("read %d\n", ret); if (ret < 0) { perror("altos_getchar"); return LIBALTOS_ERROR; @@ -689,6 +681,7 @@ altos_getchar(struct altos_file *file, int timeout) #ifdef WINDOWS +#include #include #include @@ -708,7 +701,6 @@ struct altos_file { int in_read; }; - PUBLIC struct altos_list * altos_list_start(void) { @@ -733,15 +725,15 @@ altos_list_next(struct altos_list *list, struct altos_device *device) SP_DEVINFO_DATA dev_info_data; char port[128]; DWORD port_len; - char location[256]; + char friendlyname[256]; char symbolic[256]; DWORD symbolic_len; HKEY dev_key; int vid, pid; int serial; HRESULT result; - DWORD location_type; - DWORD location_len; + DWORD friendlyname_type; + DWORD friendlyname_len; dev_info_data.cbSize = sizeof (SP_DEVINFO_DATA); while(SetupDiEnumDeviceInfo(list->dev_info, list->index, @@ -775,8 +767,6 @@ altos_list_next(struct altos_list *list, struct altos_device *device) sscanf(symbolic + sizeof("\\??\\USB#VID_XXXX&PID_XXXX#") - 1, "%d", &serial); if (!USB_IS_ALTUSMETRUM(vid, pid)) { - printf("Not Altus Metrum symbolic name: %s\n", - symbolic); RegCloseKey(dev_key); continue; } @@ -791,33 +781,26 @@ altos_list_next(struct altos_list *list, struct altos_device *device) continue; } - /* Fetch the 'location information' which is the device name, - * at least on XP */ - location_len = sizeof (location); + /* Fetch the device description which is the device name, + * with firmware that has unique USB ids */ + friendlyname_len = sizeof (friendlyname); if(!SetupDiGetDeviceRegistryProperty(list->dev_info, &dev_info_data, - SPDRP_LOCATION_INFORMATION, - &location_type, - (BYTE *)location, - sizeof(location), - &location_len)) + SPDRP_FRIENDLYNAME, + &friendlyname_type, + (BYTE *)friendlyname, + sizeof(friendlyname), + &friendlyname_len)) { - printf("Failed to get location\n"); + printf("Failed to get friendlyname\n"); continue; } device->vendor = vid; device->product = pid; device->serial = serial; - - if (strcasestr(location, "tele")) - strcpy(device->name, location); - else - strcpy(device->name, ""); + strcpy(device->name, friendlyname); strcpy(device->path, port); - printf ("product: %04x:%04x (%s) path: %s serial %d\n", - device->vendor, device->product, device->name, - device->path, device->serial); return 1; } result = GetLastError(); @@ -844,31 +827,32 @@ altos_fill(struct altos_file *file, int timeout) return LIBALTOS_SUCCESS; file->in_read = file->in_used = 0; - if (timeout) { - timeouts.ReadIntervalTimeout = MAXDWORD; - timeouts.ReadTotalTimeoutMultiplier = MAXDWORD; + if (timeout) timeouts.ReadTotalTimeoutConstant = timeout; - } else { - timeouts.ReadIntervalTimeout = 0; - timeouts.ReadTotalTimeoutMultiplier = 0; - timeouts.ReadTotalTimeoutConstant = 0; - } + else + timeouts.ReadTotalTimeoutConstant = 1000; + + timeouts.ReadIntervalTimeout = MAXDWORD; + timeouts.ReadTotalTimeoutMultiplier = MAXDWORD; timeouts.WriteTotalTimeoutMultiplier = 0; timeouts.WriteTotalTimeoutConstant = 0; - if (!SetCommTimeouts(file->handle, &timeouts)) { + if (!SetCommTimeouts(file->handle, &timeouts)) printf("SetCommTimeouts failed %d\n", GetLastError()); - } - if (!ReadFile(file->handle, file->in_data, USB_BUF_SIZE, &got, NULL)) { - result = GetLastError(); - printf ("read failed %d\n", result); - return LIBALTOS_ERROR; - got = 0; + for (;;) { + if (!ReadFile(file->handle, file->in_data, USB_BUF_SIZE, &got, NULL)) { + result = GetLastError(); + return LIBALTOS_ERROR; + got = 0; + } + file->in_read = 0; + file->in_used = got; + if (got) + return LIBALTOS_SUCCESS; + if (timeout) + return LIBALTOS_TIMEOUT; } - if (got) - return LIBALTOS_SUCCESS; - return LIBALTOS_TIMEOUT; } PUBLIC int @@ -882,7 +866,6 @@ altos_flush(struct altos_file *file) while (used) { if (!WriteFile(file->handle, data, used, &put, NULL)) { result = GetLastError(); - printf ("write failed %d\n", result); return LIBALTOS_ERROR; } data += put; @@ -895,8 +878,9 @@ altos_flush(struct altos_file *file) PUBLIC struct altos_file * altos_open(struct altos_device *device) { - struct altos_file *file = calloc (sizeof (struct altos_file), 1); + struct altos_file *file = calloc (1, sizeof (struct altos_file)); char full_name[64]; + DCB dcbSerialParams = {0}; if (!file) return NULL; @@ -910,14 +894,20 @@ altos_open(struct altos_device *device) free(file); return NULL; } - - timeouts.ReadIntervalTimeout = MAXDWORD; - timeouts.ReadTotalTimeoutMultiplier = MAXDWORD; - timeouts.ReadTotalTimeoutConstant = 100; - timeouts.WriteTotalTimeoutMultiplier = 0; - timeouts.WriteTotalTimeoutConstant = 10000; - if (!SetCommTimeouts(file->handle, &timeouts)) { - printf("SetCommTimeouts failed %d\n", GetLastError()); + dcbSerialParams.DCBlength = sizeof(dcbSerialParams); + if (!GetCommState(file->handle, &dcbSerialParams)) { + CloseHandle(file->handle); + free(file); + return NULL; + } + dcbSerialParams.BaudRate = CBR_9600; + dcbSerialParams.ByteSize = 8; + dcbSerialParams.StopBits = ONESTOPBIT; + dcbSerialParams.Parity = NOPARITY; + if (!SetCommState(file->handle, &dcbSerialParams)) { + CloseHandle(file->handle); + free(file); + return NULL; } return file; diff --git a/ao-tools/libaltos/libaltos.h b/ao-tools/libaltos/libaltos.h index fe2c483c..6e94899e 100644 --- a/ao-tools/libaltos/libaltos.h +++ b/ao-tools/libaltos/libaltos.h @@ -18,6 +18,8 @@ #ifndef _LIBALTOS_H_ #define _LIBALTOS_H_ +#include + #if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) # ifndef BUILD_STATIC # ifdef BUILD_DLL -- cgit v1.2.3 From df34bbe7d1c43b12ab6d610fe810b6e1683e4c21 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 30 Aug 2010 02:49:49 -0700 Subject: libaltos: Improve Makefile Builds Windows .dll correctly now and sample app. Moves linux install target to end so it is not default Adds .NOTPARALLEL to disable parallel gnumake. Removes -g debugging flags to shrink file size. Signed-off-by: Keith Packard --- ao-tools/libaltos/Makefile | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/libaltos/Makefile b/ao-tools/libaltos/Makefile index f336f22f..201cf8e2 100644 --- a/ao-tools/libaltos/Makefile +++ b/ao-tools/libaltos/Makefile @@ -7,16 +7,14 @@ ifeq ($(OS),Linux) JAVA_CFLAGS=-I/usr/lib/jvm/java-6-openjdk/include -OS_CFLAGS=-DLINUX -DPOSIX_TTY $(JAVA_CFLAGS) +OS_LIB_CFLAGS=-DLINUX -DPOSIX_TTY $(JAVA_CFLAGS) + +OS_APP_CFLAGS=$(OS_LIB_CFLAGS) OS_LDFLAGS= LIBNAME=libaltos.so EXEEXT= - -install: $(LIBNAME) - /usr/bin/install -c $(LIBNAME) $(DESTDIR)/usr/lib/altos/$(LIBNAME) - endif # @@ -24,12 +22,13 @@ endif # ifeq ($(OS),Darwin) -OS_CFLAGS=\ +OS_LIB_CFLAGS=\ -DDARWIN -DPOSIX_TTY -arch i386 -arch x86_64 \ --sysroot=/Developer/SDKs/MacOSX10.5.sdk -mmacosx-version-min=10.5 \ -iwithsysroot /System/Library/Frameworks/JavaVM.framework/Headers \ -iwithsysroot /System/Library/Frameworks/IOKit.framework/Headers \ -iwithsysroot /System/Library/Frameworks/CoreFoundation.framework/Headers +OS_APP_CFLAGS=$(OS_LIB_CFLAGS) OS_LDFLAGS =\ -framework IOKit -framework CoreFoundation @@ -46,7 +45,8 @@ ifneq (,$(findstring MINGW,$(OS))) CC=gcc -OS_CFLAGS = -DWINDOWS -mconsole +OS_LIB_CFLAGS = -DWINDOWS -mconsole -DBUILD_DLL +OS_APP_CFLAGS = -DWINDOWS -mconsole OS_LDFLAGS = -lgdi32 -luser32 -lcfgmgr32 -lsetupapi -lole32 \ -ladvapi32 -lcomctl32 -mconsole -Wl,--add-stdcall-alias @@ -87,7 +87,7 @@ all: $(LIBNAME) $(CJNITEST) $(CLASSFILES) .java.class: javac -encoding UTF8 -classpath "$(CLASSPATH)" $(JAVAFLAGS) $*.java -CFLAGS=$(OS_CFLAGS) -O0 -g -I. +CFLAGS=$(OS_LIB_CFLAGS) -O -I. LDFLAGS=$(OS_LDFLAGS) @@ -96,11 +96,11 @@ SRCS = libaltos.c $(SWIG_WRAP) OBJS = $(SRCS:%.c=%.o) LIBS = $(DARWIN_LIBS) -$(CJNITEST): cjnitest.o $(LIBNAME) - cc -o $@ $(CFLAGS) cjnitest.o $(OBJS) $(LIBNAME) $(LIBS) $(OS_LDFLAGS) +$(CJNITEST): cjnitest.c $(LIBNAME) + $(CC) -o $@ $(OS_APP_CFLAGS) cjnitest.c $(LIBNAME) $(LIBS) $(LDFLAGS) $(LIBNAME): $(OBJS) - gcc -shared $(CFLAGS) -o $@ $(OBJS) $(LIBS) $(LDFLAGS) + $(CC) -shared $(CFLAGS) -o $@ $(OBJS) $(LIBS) $(LDFLAGS) clean: rm -f $(CLASSFILES) $(OBJS) $(LIBNAME) $(CJNITEST) cjnitest.o @@ -114,3 +114,11 @@ $(JNI_FILE): libaltos.i0 $(HEADERS) cp swig_bindings/java/*.java libaltosJNI $(SWIG_WRAP): $(JNI_FILE) + +ifeq ($(OS),Linux) +install: $(LIBNAME) + /usr/bin/install -c $(LIBNAME) $(DESTDIR)/usr/lib/altos/$(LIBNAME) + +endif + +.NOTPARALLEL: -- cgit v1.2.3 From 0300fe581c949232bc52b05fe9c1f6032cad6b60 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 30 Aug 2010 02:56:25 -0700 Subject: libaltos: Add pre-built Mac OS X libaltos.dylib This allows the mac bits to be built on Linux. Signed-off-by: Keith Packard --- ao-tools/libaltos/libaltos.dylib | Bin 0 -> 54176 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100755 ao-tools/libaltos/libaltos.dylib (limited to 'ao-tools') diff --git a/ao-tools/libaltos/libaltos.dylib b/ao-tools/libaltos/libaltos.dylib new file mode 100755 index 00000000..89aa12e7 Binary files /dev/null and b/ao-tools/libaltos/libaltos.dylib differ -- cgit v1.2.3 From 20a472cfe3369200150ea4ff067ceb28968dbcac Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 30 Aug 2010 02:58:23 -0700 Subject: libaltos: Add pre-built Windows .dll This lets us create the windows distribution on Linux. Signed-off-by: Keith Packard --- ao-tools/libaltos/altos.dll | Bin 0 -> 30550 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100755 ao-tools/libaltos/altos.dll (limited to 'ao-tools') diff --git a/ao-tools/libaltos/altos.dll b/ao-tools/libaltos/altos.dll new file mode 100755 index 00000000..f40181e8 Binary files /dev/null and b/ao-tools/libaltos/altos.dll differ -- cgit v1.2.3 From 35d9a8214252dbe79aeb69ae47d2e5c58a654702 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 30 Aug 2010 05:27:45 -0700 Subject: libaltos: Use overlapped I/O on windows Otherwise, reads block writes and vice-versa. Crazy stuff. Signed-off-by: Keith Packard --- ao-tools/libaltos/altos.dll | Bin 30550 -> 31765 bytes ao-tools/libaltos/libaltos.c | 127 ++++++++++++++++++++++++++++++------------- 2 files changed, 90 insertions(+), 37 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/libaltos/altos.dll b/ao-tools/libaltos/altos.dll index f40181e8..28e9b4ad 100755 Binary files a/ao-tools/libaltos/altos.dll and b/ao-tools/libaltos/altos.dll differ diff --git a/ao-tools/libaltos/libaltos.c b/ao-tools/libaltos/libaltos.c index 1d3b26dd..059d2ae9 100644 --- a/ao-tools/libaltos/libaltos.c +++ b/ao-tools/libaltos/libaltos.c @@ -492,7 +492,7 @@ struct altos_file { int in_read; }; -struct altos_file * +PUBLIC struct altos_file * altos_open(struct altos_device *device) { struct altos_file *file = calloc (sizeof (struct altos_file), 1); @@ -550,7 +550,7 @@ altos_open(struct altos_device *device) return file; } -void +PUBLIC void altos_close(struct altos_file *file) { if (file->fd != -1) { @@ -566,14 +566,14 @@ altos_close(struct altos_file *file) } } -void +PUBLIC void altos_free(struct altos_file *file) { altos_close(file); free(file); } -int +PUBLIC int altos_flush(struct altos_file *file) { while (file->out_used) { @@ -597,7 +597,7 @@ altos_flush(struct altos_file *file) return 0; } -int +PUBLIC int altos_putchar(struct altos_file *file, char c) { int ret; @@ -619,7 +619,7 @@ altos_putchar(struct altos_file *file, char c) #include #endif -int +static int altos_fill(struct altos_file *file, int timeout) { int ret; @@ -663,7 +663,7 @@ altos_fill(struct altos_file *file, int timeout) return 0; } -int +PUBLIC int altos_getchar(struct altos_file *file, int timeout) { int ret; @@ -699,6 +699,9 @@ struct altos_file { unsigned char in_data[USB_BUF_SIZE]; int in_used; int in_read; + OVERLAPPED ov_read; + BOOL pend_read; + OVERLAPPED ov_write; }; PUBLIC struct altos_list * @@ -817,42 +820,72 @@ altos_list_finish(struct altos_list *list) } static int -altos_fill(struct altos_file *file, int timeout) +altos_queue_read(struct altos_file *file) { - DWORD result; DWORD got; - COMMTIMEOUTS timeouts; - - if (file->in_read < file->in_used) + if (file->pend_read) return LIBALTOS_SUCCESS; - file->in_read = file->in_used = 0; - if (timeout) - timeouts.ReadTotalTimeoutConstant = timeout; - else - timeouts.ReadTotalTimeoutConstant = 1000; + if (!ReadFile(file->handle, file->in_data, USB_BUF_SIZE, &got, &file->ov_read)) { + if (GetLastError() != ERROR_IO_PENDING) + return LIBALTOS_ERROR; + file->pend_read = TRUE; + } else { + file->pend_read = FALSE; + file->in_read = 0; + file->in_used = got; + } + return LIBALTOS_SUCCESS; +} - timeouts.ReadIntervalTimeout = MAXDWORD; - timeouts.ReadTotalTimeoutMultiplier = MAXDWORD; - timeouts.WriteTotalTimeoutMultiplier = 0; - timeouts.WriteTotalTimeoutConstant = 0; +static int +altos_wait_read(struct altos_file *file, int timeout) +{ + DWORD ret; + DWORD got; - if (!SetCommTimeouts(file->handle, &timeouts)) - printf("SetCommTimeouts failed %d\n", GetLastError()); + if (!file->pend_read) + return LIBALTOS_SUCCESS; - for (;;) { - if (!ReadFile(file->handle, file->in_data, USB_BUF_SIZE, &got, NULL)) { - result = GetLastError(); + if (!timeout) + timeout = INFINITE; + + ret = WaitForSingleObject(file->ov_read.hEvent, timeout); + switch (ret) { + case WAIT_OBJECT_0: + if (!GetOverlappedResult(file->handle, &file->ov_read, &got, FALSE)) return LIBALTOS_ERROR; - got = 0; - } + file->pend_read = FALSE; file->in_read = 0; file->in_used = got; - if (got) - return LIBALTOS_SUCCESS; - if (timeout) - return LIBALTOS_TIMEOUT; + break; + case WAIT_TIMEOUT: + return LIBALTOS_TIMEOUT; + break; + default: + return LIBALTOS_ERROR; } + return LIBALTOS_SUCCESS; +} + +static int +altos_fill(struct altos_file *file, int timeout) +{ + int ret; + + if (file->in_read < file->in_used) + return LIBALTOS_SUCCESS; + + file->in_read = file->in_used = 0; + + ret = altos_queue_read(file); + if (ret) + return ret; + ret = altos_wait_read(file, timeout); + if (ret) + return ret; + + return LIBALTOS_SUCCESS; } PUBLIC int @@ -861,12 +894,21 @@ altos_flush(struct altos_file *file) DWORD put; char *data = file->out_data; char used = file->out_used; - DWORD result; + DWORD ret; while (used) { - if (!WriteFile(file->handle, data, used, &put, NULL)) { - result = GetLastError(); - return LIBALTOS_ERROR; + if (!WriteFile(file->handle, data, used, &put, &file->ov_write)) { + if (GetLastError() != ERROR_IO_PENDING) + return LIBALTOS_ERROR; + ret = WaitForSingleObject(file->ov_write.hEvent, INFINITE); + switch (ret) { + case WAIT_OBJECT_0: + if (!GetOverlappedResult(file->handle, &file->ov_write, &put, FALSE)) + return LIBALTOS_ERROR; + break; + default: + return LIBALTOS_ERROR; + } } data += put; used -= put; @@ -881,6 +923,7 @@ altos_open(struct altos_device *device) struct altos_file *file = calloc (1, sizeof (struct altos_file)); char full_name[64]; DCB dcbSerialParams = {0}; + COMMTIMEOUTS timeouts; if (!file) return NULL; @@ -889,11 +932,21 @@ altos_open(struct altos_device *device) strcat(full_name, device->path); file->handle = CreateFile(full_name, GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, - FILE_ATTRIBUTE_NORMAL, NULL); + FILE_FLAG_OVERLAPPED, NULL); if (file->handle == INVALID_HANDLE_VALUE) { free(file); return NULL; } + file->ov_read.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL); + file->ov_write.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL); + + timeouts.ReadIntervalTimeout = MAXDWORD; + timeouts.ReadTotalTimeoutMultiplier = MAXDWORD; + timeouts.ReadTotalTimeoutConstant = 1 << 30; /* almost forever */ + timeouts.WriteTotalTimeoutMultiplier = 0; + timeouts.WriteTotalTimeoutConstant = 0; + SetCommTimeouts(file->handle, &timeouts); + dcbSerialParams.DCBlength = sizeof(dcbSerialParams); if (!GetCommState(file->handle, &dcbSerialParams)) { CloseHandle(file->handle); -- cgit v1.2.3 From 38ac388baf8125c0644b868a7aaf8eba1bdf990d Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 30 Aug 2010 05:28:37 -0700 Subject: altosui: Build linux, mac and windows archives on Linux This adds 'fat' archives for each target OS. Signed-off-by: Keith Packard --- ao-tools/altosui/Makefile | 123 +++++++++++++++++++++++++++++++++------------- 1 file changed, 88 insertions(+), 35 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/Makefile b/ao-tools/altosui/Makefile index 770abcf3..6514c608 100644 --- a/ao-tools/altosui/Makefile +++ b/ao-tools/altosui/Makefile @@ -39,40 +39,57 @@ CLASSFILES=\ AltosRomconfigUI.class \ AltosVoice.class -#FREETTSSRC=/home/keithp/src/freetts/freetts-1.2.2 -#FREETTSLIB=$(FREETTSSRC)/lib -#FREETTSJAR=/usr/share/java/freetts.jar -#FREETTSJAR= \ -# cmudict04.jar \ -# cmulex.jar \ -# cmu_time_awb.jar \ -# cmutimelex.jar \ -# cmu_us_kal.jar \ -# en_us.jar \ -# freetts.jar +# where altosui.jar gets installed +ALTOSLIB=/usr/share/java + +# where freetts.jar is to be found +FREETTSLIB=/usr/share/java + +# all of the freetts files +FREETTSJAR= \ + $(FREETTSLIB)/cmudict04.jar \ + $(FREETTSLIB)/cmulex.jar \ + $(FREETTSLIB)/cmu_time_awb.jar \ + $(FREETTSLIB)/cmutimelex.jar \ + $(FREETTSLIB)/cmu_us_kal.jar \ + $(FREETTSLIB)/en_us.jar \ + $(FREETTSLIB)/freetts.jar + +# The current hex files +HEXLIB=../../src +HEXFILES = \ + $(HEXLIB)/telemetrum-v1.0.ihx \ + $(HEXLIB)/teledongle-v0.2.ihx JAVAFLAGS=-Xlint:unchecked -Xlint:deprecation +ALTOSUIJAR = altosui.jar +FATJAR = fat/altosui.jar + OS:=$(shell uname) -ifeq ($(OS),Linux) -ALTOSUI_APP=altosui -endif +LINUX_APP=altosui + +DARWIN_ZIP=Altos-Mac.zip + +WINDOWS_ZIP=Altos-Windows.zip -ifeq ($(OS),Darwin) -ALTOSUI_APP=AltosUI.app/Contents/Resources/Java/altosui.jar -endif +LINUX_TGZ=Altos-Linux.tgz -all: altosui.jar $(ALTOSUI_APP) +all: $(LINUX_APP) $(DARWIN_ZIP) $(WINDOWS_ZIP) $(LINUX_TGZ) $(CLASSFILES): .java.class: javac -encoding UTF8 -classpath "$(CLASSPATH)" $(JAVAFLAGS) $*.java -altosui.jar: classes/altosui classes/libaltosJNI $(FREETTSJAR) $(CLASSFILES) Manifest.txt +altosui.jar: classes/altosui classes/libaltosJNI $(CLASSFILES) Manifest.txt cd ./classes && jar cfm ../$@ altosui/Manifest.txt altosui/*.class libaltosJNI/*.class +Manifest.txt: Makefile $(CLASSFILES) + echo 'Main-Class: altosui.AltosUI' > $@ + echo "Class-Path: $(FREETTSLIB)/freetts.jar' >> $@ + classes/altosui: mkdir -p classes ln -sf .. classes/altosui @@ -81,32 +98,68 @@ classes/libaltosJNI: mkdir -p classes ln -sf ../../libaltos/libaltosJNI classes/libaltosJNI -#$(FREETTSJAR): -# ln -s $(FREETTSLIB)/$@ . - -ifeq ($(OS),Darwin) -RESOURCES=altosui.jar $(FREETTSJAR) ../libaltos/libaltos.dylib - -$(ALTOSUI_APP): $(RESOURCES) - mkdir -p AltosUI.app/Contents/Resources/Java - cp $(RESOURCES) AltosUI.app/Contents/Resources/Java - -endif - -ifeq ($(OS),Linux) altosui: echo "#!/bin/sh" > $@ echo "exec java -Djava.library.path=/usr/lib/altos -jar /usr/share/java/altosui.jar" >> $@ chmod +x ./altosui -install: altosui.jar altosui +fat/altosui: + echo "#!/bin/sh" > $@ + echo 'ME=`which "$0"`' >> $@ + echo 'DIR=`dirname "$ME"`' >> $@ + echo 'exec java -Djava.library.path="$$DIR" -jar "$$DIR"/altosui.jar' >> $@ + chmod +x $@ + +fat/altosui.jar: $(CLASSFILES) fat/classes/Manifest.txt + mkdir -p fat/classes + test -L fat/classes/altosui || ln -sf ../.. fat/classes/altosui + test -L fat/classes/libaltosJNI || ln -sf ../../../libaltos/libaltosJNI fat/classes/libaltosJNI + cd ./fat/classes && jar cfm ../../$@ Manifest.txt altosui/*.class libaltosJNI/*.class + +fat/classes/Manifest.txt: $(CLASSFILES) Makefile + mkdir -p fat/classes + echo 'Main-Class: altosui.AltosUI' > $@ + echo "Class-Path: freetts.jar" >> $@ + +install: altosui.jar altosui /usr/bin/install -m 0644 altosui.jar $(DESTDIR)/usr/share/java/altosui.jar /usr/bin/install -m 0644 altosui.1 $(DESTDIR)/usr/share/man/man1/altosui.1 /usr/bin/install altosui $(DESTDIR)/usr/bin/altosui - -endif clean: rm -f *.class altosui.jar rm -f AltosUI.app/Contents/Resources/Java/* rm -rf classes + rm -rf windows linux + +FAT_FILES=$(FATJAR) $(FREETTSJAR) $(HEXFILES) + +LINUX_FILES=$(FAT_FILES) ../libaltos/libaltos.so fat/altosui +$(LINUX_TGZ): $(LINUX_FILES) + rm $@ + mkdir -p linux/AltOS + rm -f linux/AltOS/* + cp $(LINUX_FILES) linux/AltOS + cd linux && tar czf ../$@ AltOS + +DARWIN_RESOURCES=$(FATJAR) $(FREETTSJAR) ../libaltos/libaltos.dylib +DARWIN_EXTRA=$(HEXFILES) +DARWIN_FILES=$(DARWIN_RESOURCES) $(DARWIN_EXTRA) + +$(DARWIN_ZIP): $(DARWIN_FILES) + rm $@ + cp -a AltosUI.app darwin/ + mkdir -p darwin/AltosUI.app/Contents/Resources/Java + cp $(DARWIN_RESOURCES) darwin/AltosUI.app/Contents/Resources/Java + mkdir -p darwin/AltOS + cp $(DARWIN_EXTRA) darwin/AltOS + cd darwin && zip -j -r ../$@ AltosUI.app AltOS + +WINDOWS_FILES = $(FAT_FILES) ../libaltos/altos.dll ../../telemetrum.inf + +$(WINDOWS_ZIP): $(WINDOWS_FILES) + rm $@ + mkdir -p windows/AltOS + rm -f windows/AltOS/* + cp $(WINDOWS_FILES) windows/AltOS + cd windows && zip -j -r ../$@ AltOS -- cgit v1.2.3 From a94900b8862b99b4e317ea0ee3edd2a560f270c7 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 30 Aug 2010 05:48:23 -0700 Subject: altosui: build debian-style altosui too This adds the dependencies to make sure altosui and altosui.jar get built. Signed-off-by: Keith Packard --- ao-tools/altosui/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/Makefile b/ao-tools/altosui/Makefile index 6514c608..dcaf3ab0 100644 --- a/ao-tools/altosui/Makefile +++ b/ao-tools/altosui/Makefile @@ -76,7 +76,7 @@ WINDOWS_ZIP=Altos-Windows.zip LINUX_TGZ=Altos-Linux.tgz -all: $(LINUX_APP) $(DARWIN_ZIP) $(WINDOWS_ZIP) $(LINUX_TGZ) +all: altosui altosui.jar $(LINUX_APP) $(DARWIN_ZIP) $(WINDOWS_ZIP) $(LINUX_TGZ) $(CLASSFILES): @@ -88,7 +88,7 @@ altosui.jar: classes/altosui classes/libaltosJNI $(CLASSFILES) Manifest.txt Manifest.txt: Makefile $(CLASSFILES) echo 'Main-Class: altosui.AltosUI' > $@ - echo "Class-Path: $(FREETTSLIB)/freetts.jar' >> $@ + echo "Class-Path: $(FREETTSLIB)/freetts.jar" >> $@ classes/altosui: mkdir -p classes -- cgit v1.2.3 From a9a8d23c877e6f6c76857b7c85e3d43b4da1db27 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 30 Aug 2010 05:49:11 -0700 Subject: altosui: Devices with USB id 0x000a always get listed List 'unknown' AltusMetrum devices anytime the UI needs a device name. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosDevice.java | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosDevice.java b/ao-tools/altosui/AltosDevice.java index 3daf0742..e62a0a7a 100644 --- a/ao-tools/altosui/AltosDevice.java +++ b/ao-tools/altosui/AltosDevice.java @@ -32,6 +32,7 @@ public class AltosDevice extends altos_device { System.err.println("Native library failed to load.\n" + e); } } + public final static int AltusMetrum = libaltosConstants.USB_PRODUCT_ALTUSMETRUM; public final static int TeleMetrum = libaltosConstants.USB_PRODUCT_TELEMETRUM; public final static int TeleDongle = libaltosConstants.USB_PRODUCT_TELEDONGLE; public final static int TeleTerra = libaltosConstants.USB_PRODUCT_TELETERRA; @@ -58,33 +59,23 @@ public class AltosDevice extends altos_device { public boolean matchProduct(int want_product) { + if (!isAltusMetrum()) + return false; + if (want_product == Any) return true; if (want_product == BaseStation) return matchProduct(TeleDongle) || matchProduct(TeleTerra); - if (!isAltusMetrum()) - return false; - int have_product = getProduct(); - if (want_product == have_product) + if (have_product == AltusMetrum) /* old devices match any request */ return true; - if (have_product != libaltosConstants.USB_PRODUCT_ALTUSMETRUM) - return false; - - String name = getName(); + if (want_product == have_product) + return true; - if (name == null) - return false; - if (want_product == libaltosConstants.USB_PRODUCT_TELEMETRUM) - return name.startsWith("TeleMetrum"); - if (want_product == libaltosConstants.USB_PRODUCT_TELEDONGLE) - return name.startsWith("TeleDongle"); - if (want_product == libaltosConstants.USB_PRODUCT_TELETERRA) - return name.startsWith("TeleTerra"); return false; } -- cgit v1.2.3 From cbc72399a0f4d7429df0189bcdae683dd491cb9e Mon Sep 17 00:00:00 2001 From: Bdale Garbee Date: Mon, 30 Aug 2010 17:56:56 -0600 Subject: continue even if rm's don't have anything to do --- ao-tools/altosui/Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/Makefile b/ao-tools/altosui/Makefile index dcaf3ab0..d3b6970f 100644 --- a/ao-tools/altosui/Makefile +++ b/ao-tools/altosui/Makefile @@ -136,7 +136,7 @@ FAT_FILES=$(FATJAR) $(FREETTSJAR) $(HEXFILES) LINUX_FILES=$(FAT_FILES) ../libaltos/libaltos.so fat/altosui $(LINUX_TGZ): $(LINUX_FILES) - rm $@ + rm -f $@ mkdir -p linux/AltOS rm -f linux/AltOS/* cp $(LINUX_FILES) linux/AltOS @@ -147,7 +147,7 @@ DARWIN_EXTRA=$(HEXFILES) DARWIN_FILES=$(DARWIN_RESOURCES) $(DARWIN_EXTRA) $(DARWIN_ZIP): $(DARWIN_FILES) - rm $@ + rm -f $@ cp -a AltosUI.app darwin/ mkdir -p darwin/AltosUI.app/Contents/Resources/Java cp $(DARWIN_RESOURCES) darwin/AltosUI.app/Contents/Resources/Java @@ -158,7 +158,7 @@ $(DARWIN_ZIP): $(DARWIN_FILES) WINDOWS_FILES = $(FAT_FILES) ../libaltos/altos.dll ../../telemetrum.inf $(WINDOWS_ZIP): $(WINDOWS_FILES) - rm $@ + rm -f $@ mkdir -p windows/AltOS rm -f windows/AltOS/* cp $(WINDOWS_FILES) windows/AltOS -- cgit v1.2.3 From 81318e5b7179b0311ab099043ecb04a25d763750 Mon Sep 17 00:00:00 2001 From: Bdale Garbee Date: Mon, 30 Aug 2010 18:15:40 -0600 Subject: make invocation of 'install' pathless to work on more Unix variants --- ao-tools/altosui/Makefile | 6 +++--- ao-tools/libaltos/Makefile | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/Makefile b/ao-tools/altosui/Makefile index d3b6970f..ce627ec0 100644 --- a/ao-tools/altosui/Makefile +++ b/ao-tools/altosui/Makefile @@ -122,9 +122,9 @@ fat/classes/Manifest.txt: $(CLASSFILES) Makefile echo "Class-Path: freetts.jar" >> $@ install: altosui.jar altosui - /usr/bin/install -m 0644 altosui.jar $(DESTDIR)/usr/share/java/altosui.jar - /usr/bin/install -m 0644 altosui.1 $(DESTDIR)/usr/share/man/man1/altosui.1 - /usr/bin/install altosui $(DESTDIR)/usr/bin/altosui + install -m 0644 altosui.jar $(DESTDIR)/usr/share/java/altosui.jar + install -m 0644 altosui.1 $(DESTDIR)/usr/share/man/man1/altosui.1 + install altosui $(DESTDIR)/usr/bin/altosui clean: rm -f *.class altosui.jar diff --git a/ao-tools/libaltos/Makefile b/ao-tools/libaltos/Makefile index 201cf8e2..77ffa1b4 100644 --- a/ao-tools/libaltos/Makefile +++ b/ao-tools/libaltos/Makefile @@ -117,7 +117,7 @@ $(SWIG_WRAP): $(JNI_FILE) ifeq ($(OS),Linux) install: $(LIBNAME) - /usr/bin/install -c $(LIBNAME) $(DESTDIR)/usr/lib/altos/$(LIBNAME) + install -c $(LIBNAME) $(DESTDIR)/usr/lib/altos/$(LIBNAME) endif -- cgit v1.2.3 From 2a004d17a13b4ff52d892bfdecff8ad3d0823f7c Mon Sep 17 00:00:00 2001 From: Bdale Garbee Date: Mon, 30 Aug 2010 19:37:17 -0600 Subject: don't build all the "fat" jar deliverables by default --- ao-tools/altosui/Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/Makefile b/ao-tools/altosui/Makefile index ce627ec0..5a8d7454 100644 --- a/ao-tools/altosui/Makefile +++ b/ao-tools/altosui/Makefile @@ -76,7 +76,8 @@ WINDOWS_ZIP=Altos-Windows.zip LINUX_TGZ=Altos-Linux.tgz -all: altosui altosui.jar $(LINUX_APP) $(DARWIN_ZIP) $(WINDOWS_ZIP) $(LINUX_TGZ) +all: altosui.jar $(LINUX_APP) +fat: altosui.jar $(LINUX_APP) $(DARWIN_ZIP) $(WINDOWS_ZIP) $(LINUX_TGZ) $(CLASSFILES): -- cgit v1.2.3 From 775acb89660cdee2f3c54c38297baefe39f2414c Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 30 Aug 2010 22:24:09 -0700 Subject: altosui: missed AltosReader.class in the Makefile This caused clean builds to fail to make this file Signed-off-by: Keith Packard --- ao-tools/altosui/Makefile | 1 + 1 file changed, 1 insertion(+) (limited to 'ao-tools') diff --git a/ao-tools/altosui/Makefile b/ao-tools/altosui/Makefile index 5a8d7454..bf92b5d6 100644 --- a/ao-tools/altosui/Makefile +++ b/ao-tools/altosui/Makefile @@ -26,6 +26,7 @@ CLASSFILES=\ AltosLogfileChooser.class \ AltosParse.class \ AltosPreferences.class \ + AltosReader.class \ AltosRecord.class \ AltosSerialMonitor.class \ AltosSerial.class \ -- cgit v1.2.3 From a470315e5d822a69ef5304512cf73c604c88e481 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Wed, 1 Sep 2010 20:14:51 -0700 Subject: altosui: Remove Manifest.txt from git repo as it's built now This file is built with appropriate contents for each different .jar file. Signed-off-by: Keith Packard --- ao-tools/altosui/Manifest.txt | 2 -- 1 file changed, 2 deletions(-) delete mode 100644 ao-tools/altosui/Manifest.txt (limited to 'ao-tools') diff --git a/ao-tools/altosui/Manifest.txt b/ao-tools/altosui/Manifest.txt deleted file mode 100644 index 504d0de3..00000000 --- a/ao-tools/altosui/Manifest.txt +++ /dev/null @@ -1,2 +0,0 @@ -Main-Class: altosui.AltosUI -Class-Path: /usr/share/java/freetts.jar -- cgit v1.2.3 From 83552dfa0d38db9cdf3efc89e64e6c7896467856 Mon Sep 17 00:00:00 2001 From: Bdale Garbee Date: Thu, 2 Sep 2010 00:47:54 -0400 Subject: add distclean targets to libaltos and altosui to all Debian package to build --- ao-tools/altosui/Makefile | 2 ++ ao-tools/libaltos/Makefile | 2 ++ 2 files changed, 4 insertions(+) (limited to 'ao-tools') diff --git a/ao-tools/altosui/Makefile b/ao-tools/altosui/Makefile index bf92b5d6..92922de3 100644 --- a/ao-tools/altosui/Makefile +++ b/ao-tools/altosui/Makefile @@ -134,6 +134,8 @@ clean: rm -rf classes rm -rf windows linux +distclean: clean + FAT_FILES=$(FATJAR) $(FREETTSJAR) $(HEXFILES) LINUX_FILES=$(FAT_FILES) ../libaltos/libaltos.so fat/altosui diff --git a/ao-tools/libaltos/Makefile b/ao-tools/libaltos/Makefile index 77ffa1b4..cb767c85 100644 --- a/ao-tools/libaltos/Makefile +++ b/ao-tools/libaltos/Makefile @@ -106,6 +106,8 @@ clean: rm -f $(CLASSFILES) $(OBJS) $(LIBNAME) $(CJNITEST) cjnitest.o rm -rf swig_bindings libaltosJNI +distclean: clean + $(JNI_FILE): libaltos.i0 $(HEADERS) mkdir -p $(SWIG_DIR) mkdir -p libaltosJNI -- cgit v1.2.3 From 3aafd70257b70b7c11ba9c55749157979bc61ea2 Mon Sep 17 00:00:00 2001 From: Bdale Garbee Date: Thu, 2 Sep 2010 00:52:04 -0400 Subject: more makefile distclean target work --- ao-tools/altosui/Makefile | 1 + 1 file changed, 1 insertion(+) (limited to 'ao-tools') diff --git a/ao-tools/altosui/Makefile b/ao-tools/altosui/Makefile index 92922de3..85271039 100644 --- a/ao-tools/altosui/Makefile +++ b/ao-tools/altosui/Makefile @@ -135,6 +135,7 @@ clean: rm -rf windows linux distclean: clean + rm -f $(DARWIN_ZIP) $(WINDOWS_ZIP) $(LINUX_TGZ) FAT_FILES=$(FATJAR) $(FREETTSJAR) $(HEXFILES) -- cgit v1.2.3 From 59ff9180f11063c257746b895a167179b3a4ff7c Mon Sep 17 00:00:00 2001 From: Bdale Garbee Date: Thu, 2 Sep 2010 00:53:16 -0400 Subject: and a few more distclean fixes --- ao-tools/altosui/Makefile | 1 + doc/Makefile | 2 ++ 2 files changed, 3 insertions(+) (limited to 'ao-tools') diff --git a/ao-tools/altosui/Makefile b/ao-tools/altosui/Makefile index 85271039..abf5704f 100644 --- a/ao-tools/altosui/Makefile +++ b/ao-tools/altosui/Makefile @@ -136,6 +136,7 @@ clean: distclean: clean rm -f $(DARWIN_ZIP) $(WINDOWS_ZIP) $(LINUX_TGZ) + rm -rf darwin fat FAT_FILES=$(FATJAR) $(FREETTSJAR) $(HEXFILES) diff --git a/doc/Makefile b/doc/Makefile index f8048dce..e840ec41 100644 --- a/doc/Makefile +++ b/doc/Makefile @@ -26,6 +26,8 @@ telemetrum-doc.pdf: telemetrum-doc.fo clean: rm -f telemetrum-doc.html telemetrum-doc.pdf telemetrum-doc.fo +distclean: clean + indent: telemetrum-doc.xsl xmlindent -i 2 < telemetrum-doc.xsl > telemetrum-doc.new -- cgit v1.2.3 From 2f07ad14a16dbf1b75c71784ceae303825c90ade Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Wed, 1 Sep 2010 22:43:22 -0700 Subject: altosui: Abort flashing if debug port isn't working Check each command going over the debug port and make sure it works as expected. This commit adds checks for initializing the clock, selecting the desired program counter and running the flash program. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosFlash.java | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosFlash.java b/ao-tools/altosui/AltosFlash.java index b7018555..a3e431cd 100644 --- a/ao-tools/altosui/AltosFlash.java +++ b/ao-tools/altosui/AltosFlash.java @@ -202,9 +202,13 @@ public class AltosFlash { debug.debug_instr(set_clkcon_fast); byte status; - do { + for (int times = 0; times < 20; times++) { + Thread.sleep(1); status = debug.debug_instr(get_sleep); - } while ((status & SLEEP_XOSC_STB) == 0); + if ((status & SLEEP_XOSC_STB) != 0) + return; + } + throw new IOException("Failed to initialize target clock"); } void action(String s, int percent) { @@ -221,6 +225,22 @@ public class AltosFlash { percent); } + void run(int pc) throws IOException, InterruptedException { + debug.set_pc(pc); + int set_pc = debug.get_pc(); + if (pc != set_pc) + throw new IOException("Failed to set target program counter"); + debug.resume(); + + for (int times = 0; times < 20; times++) { + byte status = debug.read_status(); + if ((status & AltosDebug.STATUS_CPU_HALTED) != 0) + return; + } + + throw new IOException("Failed to execute program on target"); + } + public void flash() throws IOException, FileNotFoundException, InterruptedException { if (!check_rom_config()) throw new IOException("Invalid rom config settings"); @@ -264,16 +284,7 @@ public class AltosFlash { this_time); debug.write_memory(flash_prog, flash_page); - debug.set_pc(flash_prog); - int pc = debug.get_pc(); - debug.resume(); - Thread.sleep(100); - for (int times = 0; times < 10; times++) { - byte status = debug.read_status(); - if ((status & AltosDebug.STATUS_CPU_HALTED) != 0) - break; - Thread.sleep(100); - } + run(flash_prog); byte[] check = debug.read_memory(flash_addr, this_time); for (int i = 0; i < this_time; i++) -- cgit v1.2.3 From 9a690c9795e8257d2a3225f905117681668a472f Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Wed, 1 Sep 2010 22:46:04 -0700 Subject: altosui: allow flashing to be canceled from the rom config dialog Was using the rom config class wrong, causing cancel actions to work just like 'ok' actions. Oops. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosFlashUI.java | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosFlashUI.java b/ao-tools/altosui/AltosFlashUI.java index 73a97a6b..18795695 100644 --- a/ao-tools/altosui/AltosFlashUI.java +++ b/ao-tools/altosui/AltosFlashUI.java @@ -75,17 +75,17 @@ public class AltosFlashUI AltosRomconfigUI romconfig_ui = new AltosRomconfigUI (frame); romconfig_ui.set(flash.romconfig()); - romconfig_ui.showDialog(); - - AltosRomconfig romconfig = romconfig_ui.romconfig(); - if (romconfig == null || !romconfig.valid()) - return; - flash.set_romconfig(romconfig); - serial_value.setText(String.format("%d", - flash.romconfig().serial_number)); - file_value.setText(file.toString()); - setVisible(true); - flash.flash(); + AltosRomconfig romconfig = romconfig_ui.showDialog(); + + if (romconfig != null && romconfig.valid()) { + flash.set_romconfig(romconfig); + serial_value.setText(String.format("%d", + flash.romconfig().serial_number)); + file_value.setText(file.toString()); + setVisible(true); + flash.flash(); + flash = null; + } } catch (FileNotFoundException ee) { JOptionPane.showMessageDialog(frame, "Cannot open image", @@ -97,6 +97,8 @@ public class AltosFlashUI file.toString(), JOptionPane.ERROR_MESSAGE); } catch (InterruptedException ie) { + } finally { + abort(); } dispose(); } -- cgit v1.2.3 From 5ee6cd41ed189c3166f76558ecada80917f40652 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Wed, 1 Sep 2010 22:47:15 -0700 Subject: altosui: Hide internal rom config UI helper function This was getting mis-used by the flash UI causing the rom dialog 'cancel' button to work just like 'ok'. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosRomconfigUI.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosRomconfigUI.java b/ao-tools/altosui/AltosRomconfigUI.java index bc511865..10b3af80 100644 --- a/ao-tools/altosui/AltosRomconfigUI.java +++ b/ao-tools/altosui/AltosRomconfigUI.java @@ -162,7 +162,7 @@ public class AltosRomconfigUI } } - public AltosRomconfig romconfig() { + AltosRomconfig romconfig() { try { return new AltosRomconfig(serial(), radio_calibration()); } catch (NumberFormatException ne) { -- cgit v1.2.3 From 8d8980f56a4f2c7d6f2ce667130706e0f04f8ded Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Wed, 1 Sep 2010 22:56:12 -0700 Subject: altosui: Remove some debug printfs from AltosRomconfig class Signed-off-by: Keith Packard --- ao-tools/altosui/AltosRomconfig.java | 6 ------ 1 file changed, 6 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosRomconfig.java b/ao-tools/altosui/AltosRomconfig.java index 8c9cb27a..22d2dbd3 100644 --- a/ao-tools/altosui/AltosRomconfig.java +++ b/ao-tools/altosui/AltosRomconfig.java @@ -57,7 +57,6 @@ public class AltosRomconfig { static void put_usb_serial(int value, byte[] bytes, int start) { int offset = start + 0xa; int string_num = 0; - System.out.printf("Put usb serial %d\n", value); while (offset < bytes.length && bytes[offset] != 0) { if (bytes[offset + 1] == AO_USB_DESC_STRING) { @@ -67,13 +66,10 @@ public class AltosRomconfig { } offset += ((int) bytes[offset]) & 0xff; } - System.out.printf("offset %d content %d\n", - offset, bytes[offset]); if (offset >= bytes.length || bytes[offset] == 0) return; int len = ((((int) bytes[offset]) & 0xff) - 2) / 2; String fmt = String.format("%%0%dd", len); - System.out.printf("existing serial length %d format %s\n", len, fmt); String s = String.format(fmt, value); if (s.length() != len) { @@ -90,14 +86,12 @@ public class AltosRomconfig { public AltosRomconfig(byte[] bytes, int offset) { version = get_int(bytes, offset + 0, 2); check = get_int(bytes, offset + 2, 2); - System.out.printf("version %d check %d\n", version, check); if (check == (~version & 0xffff)) { switch (version) { case 2: case 1: serial_number = get_int(bytes, offset + 4, 2); radio_calibration = get_int(bytes, offset + 6, 4); - System.out.printf("serial %d cal %d\n", serial_number, radio_calibration); valid = true; break; } -- cgit v1.2.3 From cff0d1ef6b338b3d5ad9450d4d5f95df934cb5e4 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Wed, 1 Sep 2010 22:56:34 -0700 Subject: altosui: Post error dialog on invalid ROM config values. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosRomconfigUI.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosRomconfigUI.java b/ao-tools/altosui/AltosRomconfigUI.java index 10b3af80..2134975d 100644 --- a/ao-tools/altosui/AltosRomconfigUI.java +++ b/ao-tools/altosui/AltosRomconfigUI.java @@ -134,8 +134,17 @@ public class AltosRomconfigUI public void actionPerformed(ActionEvent e) { String cmd = e.getActionCommand(); - if (cmd.equals("ok")) + if (cmd.equals("ok")) { + AltosRomconfig romconfig = romconfig(); + if (romconfig == null || !romconfig.valid()) { + JOptionPane.showMessageDialog(this, + "Invalid serial number or radio calibration value", + "Invalid rom configuration", + JOptionPane.ERROR_MESSAGE); + return; + } selected = true; + } setVisible(false); } -- cgit v1.2.3 From 3b3aa448f3a0f44137f7530b04b58967ba5f22f5 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 2 Sep 2010 21:11:29 -0700 Subject: altosui: build Mac OS .zip file to include paths Without the paths, the OS X zip file doesn't create a usable application structure. Signed-off-by: Keith Packard --- ao-tools/altosui/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/Makefile b/ao-tools/altosui/Makefile index abf5704f..0f5d05c8 100644 --- a/ao-tools/altosui/Makefile +++ b/ao-tools/altosui/Makefile @@ -159,7 +159,7 @@ $(DARWIN_ZIP): $(DARWIN_FILES) cp $(DARWIN_RESOURCES) darwin/AltosUI.app/Contents/Resources/Java mkdir -p darwin/AltOS cp $(DARWIN_EXTRA) darwin/AltOS - cd darwin && zip -j -r ../$@ AltosUI.app AltOS + cd darwin && zip -r ../$@ AltosUI.app AltOS WINDOWS_FILES = $(FAT_FILES) ../libaltos/altos.dll ../../telemetrum.inf -- cgit v1.2.3 From e5ef42c2b22c6639d90631dbbb588f9fd2494385 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 3 Sep 2010 01:12:24 -0700 Subject: altosui: Report telemetry CRC errors in UI Telemetry CRC errors can signal problems with TeleMetrum or TeleDongle units, so report them in the UI. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosCRCException.java | 26 ++++++++++++++++++++++++++ ao-tools/altosui/AltosLog.java | 1 + ao-tools/altosui/AltosSerial.java | 2 +- ao-tools/altosui/AltosTelemetry.java | 9 ++++++++- ao-tools/altosui/AltosTelemetryReader.java | 2 ++ ao-tools/altosui/AltosUI.java | 26 +++++++++++++++++--------- ao-tools/altosui/Makefile | 1 + 7 files changed, 56 insertions(+), 11 deletions(-) create mode 100644 ao-tools/altosui/AltosCRCException.java (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosCRCException.java b/ao-tools/altosui/AltosCRCException.java new file mode 100644 index 00000000..4a529bcf --- /dev/null +++ b/ao-tools/altosui/AltosCRCException.java @@ -0,0 +1,26 @@ +/* + * Copyright © 2010 Keith Packard + * + * 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; + +public class AltosCRCException extends Exception { + public int rssi; + + public AltosCRCException (int in_rssi) { + rssi = in_rssi; + } +} diff --git a/ao-tools/altosui/AltosLog.java b/ao-tools/altosui/AltosLog.java index ec868b9c..2c241771 100644 --- a/ao-tools/altosui/AltosLog.java +++ b/ao-tools/altosui/AltosLog.java @@ -74,6 +74,7 @@ class AltosLog implements Runnable { open(telem); } } catch (ParseException pe) { + } catch (AltosCRCException ce) { } if (log_file != null) { log_file.write(line); diff --git a/ao-tools/altosui/AltosSerial.java b/ao-tools/altosui/AltosSerial.java index 99ba3324..c3daf3b9 100644 --- a/ao-tools/altosui/AltosSerial.java +++ b/ao-tools/altosui/AltosSerial.java @@ -71,7 +71,7 @@ public class AltosSerial implements Runnable { for (int i = 0; i < line_count; i++) line = line + line_bytes[i]; } - if (line.startsWith("VERSION")) { + if (line.startsWith("VERSION") || line.startsWith("CRC")) { for (int e = 0; e < monitors.size(); e++) { LinkedBlockingQueue q = monitors.get(e); q.put(line); diff --git a/ao-tools/altosui/AltosTelemetry.java b/ao-tools/altosui/AltosTelemetry.java index bc62690b..be22dac6 100644 --- a/ao-tools/altosui/AltosTelemetry.java +++ b/ao-tools/altosui/AltosTelemetry.java @@ -23,6 +23,7 @@ import java.util.HashMap; import altosui.AltosConvert; import altosui.AltosRecord; import altosui.AltosGPS; +import altosui.AltosCRCException; /* * Telemetry data contents @@ -53,10 +54,16 @@ import altosui.AltosGPS; */ public class AltosTelemetry extends AltosRecord { - public AltosTelemetry(String line) throws ParseException { + public AltosTelemetry(String line) throws ParseException, AltosCRCException { String[] words = line.split("\\s+"); int i = 0; + if (words[i].equals("CRC") && words[i+1].equals("INVALID")) { + i += 2; + AltosParse.word(words[i++], "RSSI"); + rssi = AltosParse.parse_int(words[i++]); + throw new AltosCRCException(rssi); + } if (words[i].equals("CALL")) { version = 0; } else { diff --git a/ao-tools/altosui/AltosTelemetryReader.java b/ao-tools/altosui/AltosTelemetryReader.java index a3402f9c..fdedbde2 100644 --- a/ao-tools/altosui/AltosTelemetryReader.java +++ b/ao-tools/altosui/AltosTelemetryReader.java @@ -62,6 +62,8 @@ public class AltosTelemetryReader extends AltosReader { records.add(record); } catch (ParseException pe) { System.out.printf("parse exception %s\n", pe.getMessage()); + } catch (AltosCRCException ce) { + System.out.printf("crc error\n"); } } } catch (IOException io) { diff --git a/ao-tools/altosui/AltosUI.java b/ao-tools/altosui/AltosUI.java index 5b48e26f..e3f61303 100644 --- a/ao-tools/altosui/AltosUI.java +++ b/ao-tools/altosui/AltosUI.java @@ -168,21 +168,17 @@ public class AltosUI extends JFrame { flightInfoModel[i].finish(); } - public void show(AltosState state) { + public void show(AltosState state, int crc_errors) { flightStatusModel.set(state); info_reset(); - if (state.gps_ready) - info_add_row(0, "Ground state", "%s", "ready"); - else - info_add_row(0, "Ground state", "wait (%d)", - state.gps_waiting); 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, "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); @@ -197,6 +193,11 @@ public class AltosUI extends JFrame { if (state.gps == null) { info_add_row(1, "GPS", "not available"); } else { + if (state.gps_ready) + info_add_row(1, "GPS state", "%s", "ready"); + else + info_add_row(1, "GPS state", "wait (%d)", + state.gps_waiting); if (state.data.gps.locked) info_add_row(1, "GPS", " locked"); else if (state.data.gps.connected) @@ -362,7 +363,11 @@ public class AltosUI extends JFrame { String name; - AltosRecord read() throws InterruptedException, ParseException { return null; } + int crc_errors; + + void init() { } + + AltosRecord read() throws InterruptedException, ParseException, AltosCRCException { return null; } void close() { } @@ -387,11 +392,14 @@ public class AltosUI extends JFrame { old_state = state; state = new AltosState(record, state); update(state); - show(state); + show(state, crc_errors); tell(state, old_state); idle_thread.notice(state); } catch (ParseException pp) { System.out.printf("Parse error: %d \"%s\"\n", pp.getErrorOffset(), pp.getMessage()); + } catch (AltosCRCException ce) { + ++crc_errors; + show(state, crc_errors); } } } catch (InterruptedException ee) { @@ -411,7 +419,7 @@ public class AltosUI extends JFrame { AltosSerial serial; LinkedBlockingQueue telem; - AltosRecord read() throws InterruptedException, ParseException { + AltosRecord read() throws InterruptedException, ParseException, AltosCRCException { return new AltosTelemetry(telem.take()); } diff --git a/ao-tools/altosui/Makefile b/ao-tools/altosui/Makefile index 0f5d05c8..8509391e 100644 --- a/ao-tools/altosui/Makefile +++ b/ao-tools/altosui/Makefile @@ -7,6 +7,7 @@ CLASSFILES=\ AltosConfig.class \ AltosConfigUI.class \ AltosConvert.class \ + AltosCRCException.class \ AltosCSV.class \ AltosCSVUI.class \ AltosDebug.class \ -- cgit v1.2.3 From ba65e4aeb952a1cf49a77f1e24e235508fcea71f Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 3 Sep 2010 01:21:57 -0700 Subject: altosui: Deal with altos bug setting radio channel while monitoring If the monitoring thread is active, then setting the radio channel can sometimes cause the monitoring thread to get stuck. I'm not entirely sure why though. For now, work around the issue by making sure monitoring is off, and the monitoring thread has stopped, before changing the radio channel. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosSerial.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosSerial.java b/ao-tools/altosui/AltosSerial.java index c3daf3b9..c4a7ad76 100644 --- a/ao-tools/altosui/AltosSerial.java +++ b/ao-tools/altosui/AltosSerial.java @@ -186,10 +186,14 @@ public class AltosSerial implements Runnable { public void set_channel(int channel) { if (altos != null) { + if (monitor_mode) { + printf("m 0\n"); + flush_input(); + } + printf("c r %d\n", channel); if (monitor_mode) - printf("m 0\nc r %d\nm 1\n", channel); - else - printf("c r %d\n", channel); + printf("m 1\n"); + flush_input(); } } @@ -198,8 +202,10 @@ public class AltosSerial implements Runnable { if (altos != null) { if (monitor) printf("m 1\n"); - else + else { printf("m 0\n"); + flush_input(); + } } } -- cgit v1.2.3 From 71191ecef3ba0e00d0f8a7cd1a24982bfa44ec72 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 3 Sep 2010 01:30:33 -0700 Subject: altosui: Allow 'connect to device' when already connected Opening another serial device involves shutting down the display thread (to reset its state) and spawning another one. Shutting down the display thread normally closes the serial device as a part of the process, and if this isn't done before the new serial device is opened, then the new serial device ends up getting closed too. Interrupting the display thread and waiting for it to stop before opening the new serial device solves the problem. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosUI.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosUI.java b/ao-tools/altosui/AltosUI.java index e3f61303..e63a004c 100644 --- a/ao-tools/altosui/AltosUI.java +++ b/ao-tools/altosui/AltosUI.java @@ -441,6 +441,7 @@ public class AltosUI extends JFrame { if (device != null) { try { + stop_display(); serial_line.open(device); DeviceThread thread = new DeviceThread(serial_line); serial_line.set_channel(AltosPreferences.channel()); @@ -536,8 +537,12 @@ public class AltosUI extends JFrame { Thread display_thread; private void stop_display() { - if (display_thread != null && display_thread.isAlive()) + if (display_thread != null && display_thread.isAlive()) { display_thread.interrupt(); + try { + display_thread.join(); + } catch (InterruptedException ie) {} + } display_thread = null; } -- cgit v1.2.3 From d4f64e95e31e2335470efc15df2ab357b7d197f3 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 3 Sep 2010 11:48:55 -0700 Subject: Revert "altosui: Deal with altos bug setting radio channel while monitoring" This reverts commit ba65e4aeb952a1cf49a77f1e24e235508fcea71f. Testing the old code --- ao-tools/altosui/AltosSerial.java | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosSerial.java b/ao-tools/altosui/AltosSerial.java index c4a7ad76..c3daf3b9 100644 --- a/ao-tools/altosui/AltosSerial.java +++ b/ao-tools/altosui/AltosSerial.java @@ -186,14 +186,10 @@ public class AltosSerial implements Runnable { public void set_channel(int channel) { if (altos != null) { - if (monitor_mode) { - printf("m 0\n"); - flush_input(); - } - printf("c r %d\n", channel); if (monitor_mode) - printf("m 1\n"); - flush_input(); + printf("m 0\nc r %d\nm 1\n", channel); + else + printf("c r %d\n", channel); } } @@ -202,10 +198,8 @@ public class AltosSerial implements Runnable { if (altos != null) { if (monitor) printf("m 1\n"); - else { + else printf("m 0\n"); - flush_input(); - } } } -- cgit v1.2.3 From 16d8d6a8853d09f683b13f9cda3c3174a0aab130 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 3 Sep 2010 12:31:05 -0700 Subject: altosui: Must flush serial line after configuring for telemetry Without flushing the configuration commands to the serial device, it never sees them as the telemetry input thread doesn't flush. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosSerial.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosSerial.java b/ao-tools/altosui/AltosSerial.java index c3daf3b9..bc35d6b8 100644 --- a/ao-tools/altosui/AltosSerial.java +++ b/ao-tools/altosui/AltosSerial.java @@ -101,7 +101,8 @@ public class AltosSerial implements Runnable { } public void flush_output() { - libaltos.altos_flush(altos); + if (altos != null) + libaltos.altos_flush(altos); } public void flush_input() { @@ -180,8 +181,8 @@ public class AltosSerial implements Runnable { input_thread = new Thread(this); input_thread.start(); print("~\nE 0\n"); + flush_output(); set_monitor(monitor_mode); - flush_input(); } public void set_channel(int channel) { @@ -190,6 +191,7 @@ public class AltosSerial implements Runnable { printf("m 0\nc r %d\nm 1\n", channel); else printf("c r %d\n", channel); + flush_output(); } } @@ -200,12 +202,15 @@ public class AltosSerial implements Runnable { printf("m 1\n"); else printf("m 0\n"); + flush_output(); } } public void set_callsign(String callsign) { - if (altos != null) + if (altos != null) { printf ("c c %s\n", callsign); + flush_output(); + } } public AltosSerial() { -- cgit v1.2.3 From 59798c6fd11502a9c8b66090c23ba50eb250692e Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 3 Sep 2010 12:43:45 -0700 Subject: altosui: Catch I/O errors on telemetry device, report to user This catches the USB device being unplugged and makes sure the user sees an error dialog in this case. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosLine.java | 30 ++++++++++++++++++++++++++++++ ao-tools/altosui/AltosLog.java | 15 +++++++++------ ao-tools/altosui/AltosSerial.java | 34 ++++++++++++++++++++++------------ ao-tools/altosui/AltosUI.java | 27 +++++++++++++++++++-------- ao-tools/altosui/Makefile | 1 + ao-tools/libaltos/libaltos.c | 15 ++++++++++++++- 6 files changed, 95 insertions(+), 27 deletions(-) create mode 100644 ao-tools/altosui/AltosLine.java (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosLine.java b/ao-tools/altosui/AltosLine.java new file mode 100644 index 00000000..86e9d4c6 --- /dev/null +++ b/ao-tools/altosui/AltosLine.java @@ -0,0 +1,30 @@ +/* + * Copyright © 2010 Keith Packard + * + * 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; + +public class AltosLine { + public String line; + + public AltosLine() { + line = null; + } + + public AltosLine(String s) { + line = s; + } +} \ No newline at end of file diff --git a/ao-tools/altosui/AltosLog.java b/ao-tools/altosui/AltosLog.java index 2c241771..f876beba 100644 --- a/ao-tools/altosui/AltosLog.java +++ b/ao-tools/altosui/AltosLog.java @@ -24,6 +24,7 @@ import java.text.ParseException; import java.util.concurrent.LinkedBlockingQueue; import altosui.AltosSerial; import altosui.AltosFile; +import altosui.AltosLine; /* * This creates a thread to capture telemetry data and write it to @@ -31,7 +32,7 @@ import altosui.AltosFile; */ class AltosLog implements Runnable { - LinkedBlockingQueue input_queue; + LinkedBlockingQueue input_queue; LinkedBlockingQueue pending_queue; int serial; int flight; @@ -64,9 +65,11 @@ class AltosLog implements Runnable { public void run () { try { for (;;) { - String line = input_queue.take(); + AltosLine line = input_queue.take(); + if (line.line == null) + continue; try { - AltosTelemetry telem = new AltosTelemetry(line); + AltosTelemetry telem = new AltosTelemetry(line.line); if (telem.serial != serial || telem.flight != flight || log_file == null) { close(); serial = telem.serial; @@ -77,11 +80,11 @@ class AltosLog implements Runnable { } catch (AltosCRCException ce) { } if (log_file != null) { - log_file.write(line); + log_file.write(line.line); log_file.write('\n'); log_file.flush(); } else - pending_queue.put(line); + pending_queue.put(line.line); } } catch (InterruptedException ie) { } catch (IOException ie) { @@ -94,7 +97,7 @@ class AltosLog implements Runnable { public AltosLog (AltosSerial s) { pending_queue = new LinkedBlockingQueue (); - input_queue = new LinkedBlockingQueue (); + input_queue = new LinkedBlockingQueue (); s.add_monitor(input_queue); serial = -1; flight = -1; diff --git a/ao-tools/altosui/AltosSerial.java b/ao-tools/altosui/AltosSerial.java index bc35d6b8..a1fc4371 100644 --- a/ao-tools/altosui/AltosSerial.java +++ b/ao-tools/altosui/AltosSerial.java @@ -27,10 +27,12 @@ import java.util.concurrent.LinkedBlockingQueue; import java.util.LinkedList; import java.util.Iterator; import altosui.AltosSerialMonitor; +import altosui.AltosLine; import libaltosJNI.libaltos; import libaltosJNI.altos_device; import libaltosJNI.SWIGTYPE_p_altos_file; import libaltosJNI.SWIGTYPE_p_altos_list; +import libaltosJNI.libaltosConstants; /* * This class reads from the serial port and places each received @@ -41,8 +43,8 @@ import libaltosJNI.SWIGTYPE_p_altos_list; public class AltosSerial implements Runnable { SWIGTYPE_p_altos_file altos; - LinkedList> monitors; - LinkedBlockingQueue reply_queue; + LinkedList> monitors; + LinkedBlockingQueue reply_queue; Thread input_thread; String line; byte[] line_bytes; @@ -57,7 +59,15 @@ public class AltosSerial implements Runnable { c = libaltos.altos_getchar(altos, 0); if (Thread.interrupted()) break; - if (c == -1) + if (c == libaltosConstants.LIBALTOS_ERROR) { + for (int e = 0; e < monitors.size(); e++) { + LinkedBlockingQueue q = monitors.get(e); + q.put(new AltosLine()); + } + reply_queue.put (new AltosLine()); + break; + } + if (c == libaltosConstants.LIBALTOS_TIMEOUT) continue; if (c == '\r') continue; @@ -73,12 +83,12 @@ public class AltosSerial implements Runnable { } if (line.startsWith("VERSION") || line.startsWith("CRC")) { for (int e = 0; e < monitors.size(); e++) { - LinkedBlockingQueue q = monitors.get(e); - q.put(line); + LinkedBlockingQueue q = monitors.get(e); + q.put(new AltosLine (line)); } } else { // System.out.printf("GOT: %s\n", line); - reply_queue.put(line); + reply_queue.put(new AltosLine (line)); } line_count = 0; line = ""; @@ -121,16 +131,16 @@ public class AltosSerial implements Runnable { public String get_reply() throws InterruptedException { flush_output(); - String line = reply_queue.take(); - return line; + AltosLine line = reply_queue.take(); + return line.line; } - public void add_monitor(LinkedBlockingQueue q) { + public void add_monitor(LinkedBlockingQueue q) { set_monitor(true); monitors.add(q); } - public void remove_monitor(LinkedBlockingQueue q) { + public void remove_monitor(LinkedBlockingQueue q) { monitors.remove(q); if (monitors.isEmpty()) set_monitor(false); @@ -218,7 +228,7 @@ public class AltosSerial implements Runnable { input_thread = null; line = ""; monitor_mode = false; - monitors = new LinkedList> (); - reply_queue = new LinkedBlockingQueue (); + monitors = new LinkedList> (); + reply_queue = new LinkedBlockingQueue (); } } diff --git a/ao-tools/altosui/AltosUI.java b/ao-tools/altosui/AltosUI.java index e63a004c..7e3fb7f9 100644 --- a/ao-tools/altosui/AltosUI.java +++ b/ao-tools/altosui/AltosUI.java @@ -44,6 +44,7 @@ import altosui.AltosChannelMenu; import altosui.AltosFlashUI; import altosui.AltosLogfileChooser; import altosui.AltosCSVUI; +import altosui.AltosLine; import libaltosJNI.*; @@ -169,6 +170,8 @@ public class AltosUI extends JFrame { } public void show(AltosState state, int crc_errors) { + if (state == null) + return; flightStatusModel.set(state); info_reset(); @@ -367,7 +370,7 @@ public class AltosUI extends JFrame { void init() { } - AltosRecord read() throws InterruptedException, ParseException, AltosCRCException { return null; } + AltosRecord read() throws InterruptedException, ParseException, AltosCRCException, IOException { return null; } void close() { } @@ -403,6 +406,11 @@ public class AltosUI extends JFrame { } } } catch (InterruptedException ee) { + } catch (IOException ie) { + JOptionPane.showMessageDialog(AltosUI.this, + String.format("Error reading from \"%s\"", name), + "Telemetry Read Error", + JOptionPane.ERROR_MESSAGE); } finally { close(); idle_thread.interrupt(); @@ -417,10 +425,13 @@ public class AltosUI extends JFrame { class DeviceThread extends DisplayThread { AltosSerial serial; - LinkedBlockingQueue telem; + LinkedBlockingQueue telem; - AltosRecord read() throws InterruptedException, ParseException, AltosCRCException { - return new AltosTelemetry(telem.take()); + AltosRecord read() throws InterruptedException, ParseException, AltosCRCException, IOException { + AltosLine l = telem.take(); + if (l.line == null) + throw new IOException("IO error"); + return new AltosTelemetry(l.line); } void close() { @@ -428,11 +439,11 @@ public class AltosUI extends JFrame { serial.remove_monitor(telem); } - public DeviceThread(AltosSerial s) { + public DeviceThread(AltosSerial s, String in_name) { serial = s; - telem = new LinkedBlockingQueue(); + telem = new LinkedBlockingQueue(); serial.add_monitor(telem); - name = "telemetry"; + name = in_name; } } @@ -443,7 +454,7 @@ public class AltosUI extends JFrame { try { stop_display(); serial_line.open(device); - DeviceThread thread = new DeviceThread(serial_line); + DeviceThread thread = new DeviceThread(serial_line, device.getPath()); serial_line.set_channel(AltosPreferences.channel()); serial_line.set_callsign(AltosPreferences.callsign()); run_display(thread); diff --git a/ao-tools/altosui/Makefile b/ao-tools/altosui/Makefile index 8509391e..cc9a440d 100644 --- a/ao-tools/altosui/Makefile +++ b/ao-tools/altosui/Makefile @@ -23,6 +23,7 @@ CLASSFILES=\ AltosGPS.class \ AltosGreatCircle.class \ AltosHexfile.class \ + AltosLine.class \ AltosLog.class \ AltosLogfileChooser.class \ AltosParse.class \ diff --git a/ao-tools/libaltos/libaltos.c b/ao-tools/libaltos/libaltos.c index 059d2ae9..465f0ac8 100644 --- a/ao-tools/libaltos/libaltos.c +++ b/ao-tools/libaltos/libaltos.c @@ -576,6 +576,11 @@ altos_free(struct altos_file *file) PUBLIC int altos_flush(struct altos_file *file) { + if (file->out_used && 0) { + printf ("flush \""); + fwrite(file->out_data, 1, file->out_used, stdout); + printf ("\"\n"); + } while (file->out_used) { int ret; @@ -634,7 +639,7 @@ altos_fill(struct altos_file *file, int timeout) return LIBALTOS_ERROR; #ifdef USE_POLL fd[0].fd = file->fd; - fd[0].events = POLLIN; + fd[0].events = POLLIN|POLLERR|POLLHUP|POLLNVAL; fd[1].fd = file->pipe[0]; fd[1].events = POLLIN; ret = poll(fd, 2, timeout); @@ -644,6 +649,9 @@ altos_fill(struct altos_file *file, int timeout) } if (ret == 0) return LIBALTOS_TIMEOUT; + + if (fd[0].revents & (POLLHUP|POLLERR|POLLNVAL)) + return LIBALTOS_ERROR; if (fd[0].revents & POLLIN) #endif { @@ -660,6 +668,11 @@ altos_fill(struct altos_file *file, int timeout) #endif } } + if (file->in_used && 0) { + printf ("fill \""); + fwrite(file->in_data, 1, file->in_used, stdout); + printf ("\"\n"); + } return 0; } -- cgit v1.2.3 From ecb4a09535b6a8da0765010489a96e605dbdeb46 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 4 Sep 2010 00:13:11 -0700 Subject: altosui: Add windows installer build using 'nsis' nsis happens to be packaged in debian, and it appears to build usable installers, which is all very cool. Signed-off-by: Keith Packard --- .../Instdrv/NSIS/Contrib/InstDrv/Example.nsi | 84 +++ .../Instdrv/NSIS/Contrib/InstDrv/InstDrv-Test.exe | Bin 0 -> 51831 bytes .../altosui/Instdrv/NSIS/Contrib/InstDrv/InstDrv.c | 704 +++++++++++++++++++++ .../Instdrv/NSIS/Contrib/InstDrv/InstDrv.dsp | 110 ++++ .../Instdrv/NSIS/Contrib/InstDrv/InstDrv.dsw | 29 + .../Instdrv/NSIS/Contrib/InstDrv/Readme.txt | 141 +++++ .../Instdrv/NSIS/Contrib/InstDrv/ircomm2k.inf | 137 ++++ .../Instdrv/NSIS/Contrib/InstDrv/ircomm2k.sys | Bin 0 -> 30464 bytes ao-tools/altosui/Instdrv/NSIS/Plugins/InstDrv.dll | Bin 0 -> 6656 bytes ao-tools/altosui/Makefile | 10 +- ao-tools/altosui/altos-windows.nsi | 102 +++ 11 files changed, 1312 insertions(+), 5 deletions(-) create mode 100644 ao-tools/altosui/Instdrv/NSIS/Contrib/InstDrv/Example.nsi create mode 100644 ao-tools/altosui/Instdrv/NSIS/Contrib/InstDrv/InstDrv-Test.exe create mode 100644 ao-tools/altosui/Instdrv/NSIS/Contrib/InstDrv/InstDrv.c create mode 100644 ao-tools/altosui/Instdrv/NSIS/Contrib/InstDrv/InstDrv.dsp create mode 100644 ao-tools/altosui/Instdrv/NSIS/Contrib/InstDrv/InstDrv.dsw create mode 100644 ao-tools/altosui/Instdrv/NSIS/Contrib/InstDrv/Readme.txt create mode 100644 ao-tools/altosui/Instdrv/NSIS/Contrib/InstDrv/ircomm2k.inf create mode 100644 ao-tools/altosui/Instdrv/NSIS/Contrib/InstDrv/ircomm2k.sys create mode 100644 ao-tools/altosui/Instdrv/NSIS/Plugins/InstDrv.dll create mode 100644 ao-tools/altosui/altos-windows.nsi (limited to 'ao-tools') diff --git a/ao-tools/altosui/Instdrv/NSIS/Contrib/InstDrv/Example.nsi b/ao-tools/altosui/Instdrv/NSIS/Contrib/InstDrv/Example.nsi new file mode 100644 index 00000000..3ed821eb --- /dev/null +++ b/ao-tools/altosui/Instdrv/NSIS/Contrib/InstDrv/Example.nsi @@ -0,0 +1,84 @@ +# +# InstDrv Example, (c) 2003 Jan Kiszka (Jan Kiszka@web.de) +# + +Name "InstDrv.dll test" + +OutFile "InstDrv-Test.exe" + +ShowInstDetails show + +ComponentText "InstDrv Plugin Usage Example" + +Page components +Page instfiles + +Section "Install a Driver" InstDriver + InstDrv::InitDriverSetup /NOUNLOAD "{4d36e978-e325-11ce-bfc1-08002be10318}" "IrCOMM2k" + Pop $0 + DetailPrint "InitDriverSetup: $0" + + InstDrv::DeleteOemInfFiles /NOUNLOAD + Pop $0 + DetailPrint "DeleteOemInfFiles: $0" + StrCmp $0 "00000000" PrintInfNames ContInst1 + + PrintInfNames: + Pop $0 + DetailPrint "Deleted $0" + Pop $0 + DetailPrint "Deleted $0" + + ContInst1: + InstDrv::CreateDevice /NOUNLOAD + Pop $0 + DetailPrint "CreateDevice: $0" + + SetOutPath $TEMP + File "ircomm2k.inf" + File "ircomm2k.sys" + + InstDrv::InstallDriver /NOUNLOAD "$TEMP\ircomm2k.inf" + Pop $0 + DetailPrint "InstallDriver: $0" + StrCmp $0 "00000000" PrintReboot ContInst2 + + PrintReboot: + Pop $0 + DetailPrint "Reboot: $0" + + ContInst2: + InstDrv::CountDevices + Pop $0 + DetailPrint "CountDevices: $0" +SectionEnd + +Section "Uninstall the driver again" UninstDriver + InstDrv::InitDriverSetup /NOUNLOAD "{4d36e978-e325-11ce-bfc1-08002be10318}" "IrCOMM2k" + Pop $0 + DetailPrint "InitDriverSetup: $0" + + InstDrv::DeleteOemInfFiles /NOUNLOAD + Pop $0 + DetailPrint "DeleteOemInfFiles: $0" + StrCmp $0 "00000000" PrintInfNames ContUninst1 + + PrintInfNames: + Pop $0 + DetailPrint "Deleted $0" + Pop $0 + DetailPrint "Deleted $0" + + ContUninst1: + InstDrv::RemoveAllDevices + Pop $0 + DetailPrint "RemoveAllDevices: $0" + StrCmp $0 "00000000" PrintReboot ContUninst2 + + PrintReboot: + Pop $0 + DetailPrint "Reboot: $0" + + ContUninst2: + Delete "$SYSDIR\system32\ircomm2k.sys" +SectionEnd \ No newline at end of file diff --git a/ao-tools/altosui/Instdrv/NSIS/Contrib/InstDrv/InstDrv-Test.exe b/ao-tools/altosui/Instdrv/NSIS/Contrib/InstDrv/InstDrv-Test.exe new file mode 100644 index 00000000..615bae15 Binary files /dev/null and b/ao-tools/altosui/Instdrv/NSIS/Contrib/InstDrv/InstDrv-Test.exe differ diff --git a/ao-tools/altosui/Instdrv/NSIS/Contrib/InstDrv/InstDrv.c b/ao-tools/altosui/Instdrv/NSIS/Contrib/InstDrv/InstDrv.c new file mode 100644 index 00000000..efe866e9 --- /dev/null +++ b/ao-tools/altosui/Instdrv/NSIS/Contrib/InstDrv/InstDrv.c @@ -0,0 +1,704 @@ +/* + +InstDrv.dll - Installs or Removes Device Drivers + +Copyright © 2003 Jan Kiszka (Jan.Kiszka@web.de) + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any damages +arising from the use of this software. + +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute +it freely, subject to the following restrictions: + +1. The origin of this software must not be misrepresented; + you must not claim that you wrote the original software. + If you use this software in a product, an acknowledgment in the + product documentation would be appreciated but is not required. +2. Altered versions must be plainly marked as such, + and must not be misrepresented as being the original software. +3. This notice may not be removed or altered from any distribution. + +*/ + + +#include +#include +#include +#include "../exdll/exdll.h" + + +char paramBuf[1024]; +GUID devClass; +char hwIdBuf[1024]; +int initialized = 0; + + + +void* memset(void* dst, int val, unsigned int len) +{ + while (len-- > 0) + *((char *)dst)++ = val; + + return NULL; +} + + + +void* memcpy(void* dst, const void* src, unsigned int len) +{ + while (len-- > 0) + *((char *)dst)++ = *((char *)src)++; + + return NULL; +} + + + +int HexCharToInt(char c) +{ + if ((c >= '0') && (c <= '9')) + return c - '0'; + else if ((c >= 'a') && (c <= 'f')) + return c - 'a' + 10; + else if ((c >= 'A') && (c <= 'F')) + return c - 'A' + 10; + else + return -1; +} + + + +BOOLEAN HexStringToUInt(char* str, int width, void* valBuf) +{ + int i, val; + + + for (i = width - 4; i >= 0; i -= 4) + { + val = HexCharToInt(*str++); + if (val < 0) + return FALSE; + *(unsigned int *)valBuf += val << i; + } + + return TRUE; +} + + + +BOOLEAN StringToGUID(char* guidStr, GUID* pGuid) +{ + int i; + + + memset(pGuid, 0, sizeof(GUID)); + + if (*guidStr++ != '{') + return FALSE; + + if (!HexStringToUInt(guidStr, 32, &pGuid->Data1)) + return FALSE; + guidStr += 8; + + if (*guidStr++ != '-') + return FALSE; + + if (!HexStringToUInt(guidStr, 16, &pGuid->Data2)) + return FALSE; + guidStr += 4; + + if (*guidStr++ != '-') + return FALSE; + + if (!HexStringToUInt(guidStr, 16, &pGuid->Data3)) + return FALSE; + guidStr += 4; + + if (*guidStr++ != '-') + return FALSE; + + for (i = 0; i < 2; i++) + { + if (!HexStringToUInt(guidStr, 8, &pGuid->Data4[i])) + return FALSE; + guidStr += 2; + } + + if (*guidStr++ != '-') + return FALSE; + + for (i = 2; i < 8; i++) + { + if (!HexStringToUInt(guidStr, 8, &pGuid->Data4[i])) + return FALSE; + guidStr += 2; + } + + if (*guidStr++ != '}') + return FALSE; + + return TRUE; +} + + + +DWORD FindNextDevice(HDEVINFO devInfoSet, SP_DEVINFO_DATA* pDevInfoData, DWORD* pIndex) +{ + DWORD buffersize = 0; + LPTSTR buffer = NULL; + DWORD dataType; + DWORD result; + + + while (1) + { + if (!SetupDiEnumDeviceInfo(devInfoSet, (*pIndex)++, pDevInfoData)) + { + result = GetLastError(); + break; + } + + GetDeviceRegistryProperty: + if (!SetupDiGetDeviceRegistryProperty(devInfoSet, pDevInfoData, SPDRP_HARDWAREID, + &dataType, (PBYTE)buffer, buffersize, + &buffersize)) + { + result = GetLastError(); + + if (result == ERROR_INSUFFICIENT_BUFFER) + { + if (buffer != NULL) + LocalFree(buffer); + + buffer = (LPTSTR)LocalAlloc(LPTR, buffersize); + + if (buffer == NULL) + break; + + goto GetDeviceRegistryProperty; + } + else if (result == ERROR_INVALID_DATA) + continue; // ignore invalid entries + else + break; // break on other errors + } + + if (lstrcmpi(buffer, hwIdBuf) == 0) + { + result = 0; + break; + } + } + + if (buffer != NULL) + LocalFree(buffer); + + return result; +} + + + +DWORD FindFirstDevice(HWND hwndParent, const GUID* pDevClass, const LPTSTR hwId, + HDEVINFO* pDevInfoSet, SP_DEVINFO_DATA* pDevInfoData, + DWORD *pIndex, DWORD flags) +{ + DWORD result; + + + *pDevInfoSet = SetupDiGetClassDevs((GUID*)pDevClass, NULL, hwndParent, flags); + if (*pDevInfoSet == INVALID_HANDLE_VALUE) + return GetLastError(); + + pDevInfoData->cbSize = sizeof(SP_DEVINFO_DATA); + *pIndex = 0; + + result = FindNextDevice(*pDevInfoSet, pDevInfoData, pIndex); + + if (result != 0) + SetupDiDestroyDeviceInfoList(*pDevInfoSet); + + return result; +} + + + +/* + * InstDrv::InitDriverSetup devClass drvHWID + * + * devClass - GUID of the driver's device setup class + * drvHWID - Hardware ID of the supported device + * + * Return: + * result - error message, empty on success + */ +void __declspec(dllexport) InitDriverSetup(HWND hwndParent, int string_size, char *variables, stack_t **stacktop) +{ + EXDLL_INIT(); + + /* convert class GUID */ + popstring(paramBuf); + + if (!StringToGUID(paramBuf, &devClass)) + { + popstring(paramBuf); + pushstring("Invalid GUID!"); + return; + } + + /* get hardware ID */ + memset(hwIdBuf, 0, sizeof(hwIdBuf)); + popstring(hwIdBuf); + + initialized = 1; + pushstring(""); +} + + + +/* + * InstDrv::CountDevices + * + * Return: + * result - Number of installed devices the driver supports + */ +void __declspec(dllexport) CountDevices(HWND hwndParent, int string_size, char *variables, stack_t **stacktop) +{ + HDEVINFO devInfoSet; + SP_DEVINFO_DATA devInfoData; + int count = 0; + char countBuf[16]; + DWORD index; + DWORD result; + + + EXDLL_INIT(); + + if (!initialized) + { + pushstring("Fatal error!"); + return; + } + + result = FindFirstDevice(hwndParent, &devClass, hwIdBuf, &devInfoSet, &devInfoData, + &index, DIGCF_PRESENT); + if (result != 0) + { + pushstring("0"); + return; + } + + do + { + count++; + } while (FindNextDevice(devInfoSet, &devInfoData, &index) == 0); + + SetupDiDestroyDeviceInfoList(devInfoSet); + + wsprintf(countBuf, "%d", count); + pushstring(countBuf); +} + + + +/* + * InstDrv::CreateDevice + * + * Return: + * result - Windows error code + */ +void __declspec(dllexport) CreateDevice(HWND hwndParent, int string_size, char *variables, stack_t **stacktop) +{ + HDEVINFO devInfoSet; + SP_DEVINFO_DATA devInfoData; + DWORD result = 0; + char resultBuf[16]; + + + EXDLL_INIT(); + + if (!initialized) + { + pushstring("Fatal error!"); + return; + } + + devInfoSet = SetupDiCreateDeviceInfoList(&devClass, hwndParent); + if (devInfoSet == INVALID_HANDLE_VALUE) + { + wsprintf(resultBuf, "%08X", GetLastError()); + pushstring(resultBuf); + return; + } + + devInfoData.cbSize = sizeof(SP_DEVINFO_DATA); + if (!SetupDiCreateDeviceInfo(devInfoSet, hwIdBuf, &devClass, NULL, + hwndParent, DICD_GENERATE_ID, &devInfoData)) + { + result = GetLastError(); + goto InstallCleanup; + } + + if (!SetupDiSetDeviceRegistryProperty(devInfoSet, &devInfoData, SPDRP_HARDWAREID, + hwIdBuf, (lstrlen(hwIdBuf)+2)*sizeof(TCHAR))) + { + result = GetLastError(); + goto InstallCleanup; + } + + if (!SetupDiCallClassInstaller(DIF_REGISTERDEVICE, devInfoSet, &devInfoData)) + result = GetLastError(); + + InstallCleanup: + SetupDiDestroyDeviceInfoList(devInfoSet); + + wsprintf(resultBuf, "%08X", result); + pushstring(resultBuf); +} + + + +/* + * InstDrv::InstallDriver infPath + * + * Return: + * result - Windows error code + * reboot - non-zero if reboot is required + */ +void __declspec(dllexport) InstallDriver(HWND hwndParent, int string_size, char *variables, stack_t **stacktop) +{ + char resultBuf[16]; + BOOL reboot; + + + EXDLL_INIT(); + popstring(paramBuf); + + if (!initialized) + { + pushstring("Fatal error!"); + return; + } + + if (!UpdateDriverForPlugAndPlayDevices(hwndParent, hwIdBuf, paramBuf, + INSTALLFLAG_FORCE, &reboot)) + { + wsprintf(resultBuf, "%08X", GetLastError()); + pushstring(resultBuf); + } + else + { + wsprintf(resultBuf, "%d", reboot); + pushstring(resultBuf); + pushstring("00000000"); + } +} + + + +/* + * InstDrv::DeleteOemInfFiles + * + * Return: + * result - Windows error code + * oeminf - Path of the deleted devices setup file (oemXX.inf) + * oempnf - Path of the deleted devices setup file (oemXX.pnf) + */ +void __declspec(dllexport) DeleteOemInfFiles(HWND hwndParent, int string_size, char *variables, stack_t **stacktop) +{ + HDEVINFO devInfo; + SP_DEVINFO_DATA devInfoData; + SP_DRVINFO_DATA drvInfoData; + SP_DRVINFO_DETAIL_DATA drvInfoDetail; + DWORD index; + DWORD result; + char resultBuf[16]; + + + if (!initialized) + { + pushstring("Fatal error!"); + return; + } + + result = FindFirstDevice(NULL, &devClass, hwIdBuf, &devInfo, &devInfoData, &index, 0); + if (result != 0) + goto Cleanup1; + + if (!SetupDiBuildDriverInfoList(devInfo, &devInfoData, SPDIT_COMPATDRIVER)) + { + result = GetLastError(); + goto Cleanup2; + } + + drvInfoData.cbSize = sizeof(SP_DRVINFO_DATA); + drvInfoDetail.cbSize = sizeof(SP_DRVINFO_DETAIL_DATA); + + if (!SetupDiEnumDriverInfo(devInfo, &devInfoData, SPDIT_COMPATDRIVER, 0, &drvInfoData)) + { + result = GetLastError(); + goto Cleanup3; + } + + if (!SetupDiGetDriverInfoDetail(devInfo, &devInfoData, &drvInfoData, + &drvInfoDetail, sizeof(drvInfoDetail), NULL)) + { + result = GetLastError(); + + if (result != ERROR_INSUFFICIENT_BUFFER) + goto Cleanup3; + + result = 0; + } + + pushstring(drvInfoDetail.InfFileName); + if (!DeleteFile(drvInfoDetail.InfFileName)) + result = GetLastError(); + else + { + index = lstrlen(drvInfoDetail.InfFileName); + if (index > 3) + { + lstrcpy(drvInfoDetail.InfFileName+index-3, "pnf"); + pushstring(drvInfoDetail.InfFileName); + if (!DeleteFile(drvInfoDetail.InfFileName)) + result = GetLastError(); + } + } + + Cleanup3: + SetupDiDestroyDriverInfoList(devInfo, &devInfoData, SPDIT_COMPATDRIVER); + + Cleanup2: + SetupDiDestroyDeviceInfoList(devInfo); + + Cleanup1: + wsprintf(resultBuf, "%08X", result); + pushstring(resultBuf); +} + + + +/* + * InstDrv::RemoveAllDevices + * + * Return: + * result - Windows error code + * reboot - non-zero if reboot is required + */ +void __declspec(dllexport) RemoveAllDevices(HWND hwndParent, int string_size, char *variables, stack_t **stacktop) +{ + HDEVINFO devInfo; + SP_DEVINFO_DATA devInfoData; + DWORD index; + DWORD result; + char resultBuf[16]; + BOOL reboot = FALSE; + SP_DEVINSTALL_PARAMS instParams; + + + EXDLL_INIT(); + + if (!initialized) + { + pushstring("Fatal error!"); + return; + } + + result = FindFirstDevice(NULL, &devClass, hwIdBuf, &devInfo, &devInfoData, &index, 0); + if (result != 0) + goto Cleanup1; + + do + { + if (!SetupDiCallClassInstaller(DIF_REMOVE, devInfo, &devInfoData)) + { + result = GetLastError(); + break; + } + + instParams.cbSize = sizeof(instParams); + if (!reboot && + SetupDiGetDeviceInstallParams(devInfo, &devInfoData, &instParams) && + ((instParams.Flags & (DI_NEEDRESTART|DI_NEEDREBOOT)) != 0)) + { + reboot = TRUE; + } + + result = FindNextDevice(devInfo, &devInfoData, &index); + } while (result == 0); + + SetupDiDestroyDeviceInfoList(devInfo); + + Cleanup1: + if ((result == 0) || (result == ERROR_NO_MORE_ITEMS)) + { + wsprintf(resultBuf, "%d", reboot); + pushstring(resultBuf); + pushstring("00000000"); + } + else + { + wsprintf(resultBuf, "%08X", result); + pushstring(resultBuf); + } +} + + + +/* + * InstDrv::StartSystemService serviceName + * + * Return: + * result - Windows error code + */ +void __declspec(dllexport) StartSystemService(HWND hwndParent, int string_size, char *variables, stack_t **stacktop) +{ + SC_HANDLE managerHndl; + SC_HANDLE svcHndl; + SERVICE_STATUS svcStatus; + DWORD oldCheckPoint; + DWORD result; + char resultBuf[16]; + + + EXDLL_INIT(); + popstring(paramBuf); + + managerHndl = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS); + if (managerHndl == NULL) + { + result = GetLastError(); + goto Cleanup1; + } + + svcHndl = OpenService(managerHndl, paramBuf, SERVICE_START | SERVICE_QUERY_STATUS); + if (svcHndl == NULL) + { + result = GetLastError(); + goto Cleanup2; + } + + if (!StartService(svcHndl, 0, NULL) || !QueryServiceStatus(svcHndl, &svcStatus)) + { + result = GetLastError(); + goto Cleanup3; + } + + while (svcStatus.dwCurrentState == SERVICE_START_PENDING) + { + oldCheckPoint = svcStatus.dwCheckPoint; + + Sleep(svcStatus.dwWaitHint); + + if (!QueryServiceStatus(svcHndl, &svcStatus)) + { + result = GetLastError(); + break; + } + + if (oldCheckPoint >= svcStatus.dwCheckPoint) + { + if ((svcStatus.dwCurrentState == SERVICE_STOPPED) && + (svcStatus.dwWin32ExitCode != 0)) + result = svcStatus.dwWin32ExitCode; + else + result = ERROR_SERVICE_REQUEST_TIMEOUT; + } + } + + if (svcStatus.dwCurrentState == SERVICE_RUNNING) + result = 0; + + Cleanup3: + CloseServiceHandle(svcHndl); + + Cleanup2: + CloseServiceHandle(managerHndl); + + Cleanup1: + wsprintf(resultBuf, "%08X", result); + pushstring(resultBuf); +} + + + +/* + * InstDrv::StopSystemService serviceName + * + * Return: + * result - Windows error code + */ +void __declspec(dllexport) StopSystemService(HWND hwndParent, int string_size, char *variables, stack_t **stacktop) +{ + SC_HANDLE managerHndl; + SC_HANDLE svcHndl; + SERVICE_STATUS svcStatus; + DWORD oldCheckPoint; + DWORD result; + char resultBuf[16]; + + + EXDLL_INIT(); + popstring(paramBuf); + + managerHndl = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS); + if (managerHndl == NULL) + { + result = GetLastError(); + goto Cleanup1; + } + + svcHndl = OpenService(managerHndl, paramBuf, SERVICE_STOP | SERVICE_QUERY_STATUS); + if (svcHndl == NULL) + { + result = GetLastError(); + goto Cleanup2; + } + + if (!ControlService(svcHndl, SERVICE_CONTROL_STOP, &svcStatus)) + { + result = GetLastError(); + goto Cleanup3; + } + + while (svcStatus.dwCurrentState == SERVICE_STOP_PENDING) + { + oldCheckPoint = svcStatus.dwCheckPoint; + + Sleep(svcStatus.dwWaitHint); + + if (!QueryServiceStatus(svcHndl, &svcStatus)) + { + result = GetLastError(); + break; + } + + if (oldCheckPoint >= svcStatus.dwCheckPoint) + { + result = ERROR_SERVICE_REQUEST_TIMEOUT; + break; + } + } + + if (svcStatus.dwCurrentState == SERVICE_STOPPED) + result = 0; + + Cleanup3: + CloseServiceHandle(svcHndl); + + Cleanup2: + CloseServiceHandle(managerHndl); + + Cleanup1: + wsprintf(resultBuf, "%08X", result); + pushstring(resultBuf); +} + + + +BOOL WINAPI _DllMainCRTStartup(HANDLE hInst, ULONG ul_reason_for_call, LPVOID lpReserved) +{ + return TRUE; +} diff --git a/ao-tools/altosui/Instdrv/NSIS/Contrib/InstDrv/InstDrv.dsp b/ao-tools/altosui/Instdrv/NSIS/Contrib/InstDrv/InstDrv.dsp new file mode 100644 index 00000000..874e66c7 --- /dev/null +++ b/ao-tools/altosui/Instdrv/NSIS/Contrib/InstDrv/InstDrv.dsp @@ -0,0 +1,110 @@ +# Microsoft Developer Studio Project File - Name="InstDrv" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** NICHT BEARBEITEN ** + +# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102 + +CFG=InstDrv - Win32 Debug +!MESSAGE Dies ist kein gültiges Makefile. Zum Erstellen dieses Projekts mit NMAKE +!MESSAGE verwenden Sie den Befehl "Makefile exportieren" und führen Sie den Befehl +!MESSAGE +!MESSAGE NMAKE /f "InstDrv.mak". +!MESSAGE +!MESSAGE Sie können beim Ausführen von NMAKE eine Konfiguration angeben +!MESSAGE durch Definieren des Makros CFG in der Befehlszeile. Zum Beispiel: +!MESSAGE +!MESSAGE NMAKE /f "InstDrv.mak" CFG="InstDrv - Win32 Debug" +!MESSAGE +!MESSAGE Für die Konfiguration stehen zur Auswahl: +!MESSAGE +!MESSAGE "InstDrv - Win32 Release" (basierend auf "Win32 (x86) Dynamic-Link Library") +!MESSAGE "InstDrv - Win32 Debug" (basierend auf "Win32 (x86) Dynamic-Link Library") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +MTL=midl.exe +RSC=rc.exe + +!IF "$(CFG)" == "InstDrv - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Release" +# PROP Intermediate_Dir "Release" +# PROP Ignore_Export_Lib 1 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "INSTDRV_EXPORTS" /YX /FD /c +# ADD CPP /nologo /MT /W3 /GX /O1 /I "C:\Programme\WINDDK\3790\inc\ddk\w2k" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "INSTDRV_EXPORTS" /FD /c +# SUBTRACT CPP /YX +# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 +# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 +# ADD BASE RSC /l 0x407 /d "NDEBUG" +# ADD RSC /l 0x407 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 +# ADD LINK32 kernel32.lib user32.lib gdi32.lib comdlg32.lib advapi32.lib shell32.lib setupapi.lib newdev.lib /nologo /entry:"_DllMainCRTStartup" /dll /machine:I386 /nodefaultlib /out:"../../Plugins/InstDrv.dll" /libpath:"C:\Programme\WINDDK\3790\lib\w2k\i386" /opt:nowin98 +# SUBTRACT LINK32 /pdb:none + +!ELSEIF "$(CFG)" == "InstDrv - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Debug" +# PROP Intermediate_Dir "Debug" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "INSTDRV_EXPORTS" /YX /FD /GZ /c +# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "INSTDRV_EXPORTS" /YX /FD /GZ /c +# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 +# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 +# ADD BASE RSC /l 0x407 /d "_DEBUG" +# ADD RSC /l 0x407 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /entry:"_DllMainCRTStartup" /dll /debug /machine:I386 /pdbtype:sept +# SUBTRACT LINK32 /nodefaultlib + +!ENDIF + +# Begin Target + +# Name "InstDrv - Win32 Release" +# Name "InstDrv - Win32 Debug" +# Begin Group "Quellcodedateien" + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" +# Begin Source File + +SOURCE=.\InstDrv.c +# End Source File +# End Group +# Begin Group "Header-Dateien" + +# PROP Default_Filter "h;hpp;hxx;hm;inl" +# End Group +# Begin Group "Ressourcendateien" + +# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" +# End Group +# End Target +# End Project diff --git a/ao-tools/altosui/Instdrv/NSIS/Contrib/InstDrv/InstDrv.dsw b/ao-tools/altosui/Instdrv/NSIS/Contrib/InstDrv/InstDrv.dsw new file mode 100644 index 00000000..b3d02f0e --- /dev/null +++ b/ao-tools/altosui/Instdrv/NSIS/Contrib/InstDrv/InstDrv.dsw @@ -0,0 +1,29 @@ +Microsoft Developer Studio Workspace File, Format Version 6.00 +# WARNUNG: DIESE ARBEITSBEREICHSDATEI DARF NICHT BEARBEITET ODER GELÖSCHT WERDEN! + +############################################################################### + +Project: "InstDrv"=.\InstDrv.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Global: + +Package=<5> +{{{ +}}} + +Package=<3> +{{{ +}}} + +############################################################################### + diff --git a/ao-tools/altosui/Instdrv/NSIS/Contrib/InstDrv/Readme.txt b/ao-tools/altosui/Instdrv/NSIS/Contrib/InstDrv/Readme.txt new file mode 100644 index 00000000..e5877aa6 --- /dev/null +++ b/ao-tools/altosui/Instdrv/NSIS/Contrib/InstDrv/Readme.txt @@ -0,0 +1,141 @@ +InstDrv.dll version 0.2 - Installs or Removes Device Drivers +------------------------------------------------------------ + + +The plugin helps you to create NSIS scripts for installing device drivers or +removing them again. It can count installed device instances, create new ones +or delete all supported device. InstDrv works on Windows 2000 or later. + + + +InstDrv::InitDriverSetup devClass drvHWID +Return: result + +To start processing a driver, first call this function. devClass is the GUID +of the device class the driver supports, drvHWID is the device hardware ID. If +you don't know what these terms mean, you may want to take a look at the +Windows DDK. This function returns an empty string on success, otherwise an +error message. + +InitDriverSetup has to be called every time after the plugin dll has been +(re-)loaded, or if you want to switch to a different driver. + + + +InstDrv::CountDevices +Return: number + +This call returns the number of installed and supported devices of the driver. + + + +InstDrv::CreateDevice +Return: result + +To create a new deviced node which the driver has to support, use this +function. You may even call it multiple times for more than one instance. The +return value is the Windows error code (in hex). Use CreateDevice before +installing or updating the driver itself. + + + +InstDrv::InstallDriver infPath +Return: result + reboot + +InstallDriver installs or updates a device driver as specified in the .inf +setup script. It returns a Windows error code (in hex) and, on success, a flag +signalling if a system reboot is required. + + + +InstDrv::DeleteOemInfFiles +Return: result + oeminf + oempnf + +DeleteOemInfFiles tries to clean up the Windows inf directory by deleting the +oemXX.inf and oemXX.pnf files associated with the drivers. It returns a +Windows error code (in hex) and, on success, the names of the deleted files. +This functions requires that at least one device instance is still present. +So, call it before you remove the devices itself. You should also call it +before updating a driver. This avoids that the inf directory gets slowly +messed up with useless old setup scripts (which does NOT really accelerate +Windows). The error code which comes up when no device is installed is +"00000103". + + + +InstDrv::RemoveAllDevices +Return: result + reboot + +This functions deletes all devices instances the driver supported. It returns +a Windows error code (in hex) and, on success, a flag signalling if the system +needs to be rebooted. You additionally have to remove the driver binaries from +the system paths. + + + +InstDrv::StartSystemService serviceName +Return: result + +Call this function to start the provided system service. The function blocks +until the service is started or the system reported a timeout. The return value +is the Windows error code (in hex). + + + +InstDrv::StopSystemService serviceName +Return: result + +This function tries to stop the provided system service. It blocks until the +service has been shut down or the system reported a timeout. The return value +is the Windows error code (in hex). + + + +Example.nsi + +The example script installs or removes the virtual COM port driver of IrCOMM2k +(2.0.0-alpha8, see www.ircomm2k.de/english). The driver and its setup script +are only included for demonstration purposes, they do not work without the +rest of IrCOMM2k (but they also do not cause any harm). + + + +Building the Source Code + +To build the plugin from the source code, some include files and libraries +which come with the Windows DDK are required. + + + +History + + 0.2 - fixed bug when calling InitDriverSetup the second time + - added StartSystemService and StopSystemService + + 0.1 - first release + + + +License + +Copyright © 2003 Jan Kiszka (Jan.Kiszka@web.de) + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any damages +arising from the use of this software. + +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute +it freely, subject to the following restrictions: + +1. The origin of this software must not be misrepresented; + you must not claim that you wrote the original software. + If you use this software in a product, an acknowledgment in the + product documentation would be appreciated but is not required. +2. Altered versions must be plainly marked as such, + and must not be misrepresented as being the original software. +3. This notice may not be removed or altered from any distribution. diff --git a/ao-tools/altosui/Instdrv/NSIS/Contrib/InstDrv/ircomm2k.inf b/ao-tools/altosui/Instdrv/NSIS/Contrib/InstDrv/ircomm2k.inf new file mode 100644 index 00000000..ccda1d87 --- /dev/null +++ b/ao-tools/altosui/Instdrv/NSIS/Contrib/InstDrv/ircomm2k.inf @@ -0,0 +1,137 @@ +; IrCOMM2k.inf +; +; Installation file for the Virtual Infrared-COM-Port +; +; (c) Copyright 2001, 2002 Jan Kiszka +; + +[Version] +Signature="$Windows NT$" +Provider=%JK% +Class=Ports +ClassGUID={4d36e978-e325-11ce-bfc1-08002be10318} +;DriverVer=03/26/2002,1.2.1.0 + +[DestinationDirs] +IrCOMM2k.Copy2Drivers = 12 +IrCOMM2k.Copy2Winnt = 10 +IrCOMM2k.Copy2System32 = 11 +IrCOMM2k.Copy2Help = 18 + + +; +; Driver information +; + +[Manufacturer] +%JK% = JK.Mfg + +[JK.Mfg] +%JK.DeviceDescIrCOMM% = IrCOMM2k_inst,IrCOMM2k + + +; +; General installation section +; + +[IrCOMM2k_inst] +CopyFiles = IrCOMM2k.Copy2Drivers ;,IrCOMM2k.Copy2System32,IrCOMM2k.Copy2Help,IrCOMM2k.Copy2Winnt +;AddReg = IrCOMM2k_inst_AddReg + + +; +; File sections +; + +[IrCOMM2k.Copy2Drivers] +ircomm2k.sys,,,2 + +;[IrCOMM2k.Copy2System32] +;ircomm2k.exe,,,2 +;ircomm2k.dll,,,2 + +;[IrCOMM2k.Copy2Help] +;ircomm2k.hlp,,,2 + +;[IrCOMM2k.Copy2Winnt] +;IrCOMM2k-Setup.exe,Setup.exe,,2 + + +; +; Service Installation +; + +[IrCOMM2k_inst.Services] +AddService = IrCOMM2k,0x00000002,IrCOMM2k_DriverService_Inst,IrCOMM2k_DriverEventLog_Inst +;AddService = IrCOMM2kSvc,,IrCOMM2k_Service_Inst + +[IrCOMM2k_DriverService_Inst] +DisplayName = %IrCOMM2k.DrvName% +ServiceType = 1 ; SERVICE_KERNEL_DRIVER +StartType = 3 ; SERVICE_DEMAND_START +ErrorControl = 0 ; SERVICE_ERROR_IGNORE +ServiceBinary = %12%\ircomm2k.sys + +;[IrCOMM2k_Service_Inst] +;DisplayName = %IrCOMM2k.SvcName% +;Description = %IrCOMM2k.SvcDesc% +;ServiceType = 0x00000120 ; SERVICE_WIN32_SHARE_PROCESS, SERVICE_INTERACTIVE_PROCESS +;StartType = 2 ; SERVICE_AUTO_START +;ErrorControl = 0 ; SERVICE_ERROR_IGNORE +;ServiceBinary = %11%\ircomm2k.exe +;Dependencies = IrCOMM2k +;AddReg = IrCOMM2kSvcAddReg + + +[IrCOMM2k_inst.nt.HW] +AddReg=IrCOMM2kHwAddReg + +[IrCOMM2kHwAddReg] +HKR,,PortSubClass,REG_BINARY,0x00000001 +;HKR,,TimeoutScaling,REG_DWORD,0x00000001 +;HKR,,StatusLines,REG_DWORD,0x00000000 + +;[IrCOMM2k_inst_AddReg] +;HKR,,EnumPropPages32,,"ircomm2k.dll,IrCOMM2kPropPageProvider" +;HKLM,%UNINSTALL_KEY%,DisplayIcon,0x00020000,"%windir%\IrCOMM2k-Setup.exe" +;HKLM,%UNINSTALL_KEY%,DisplayName,,"IrCOMM2k 1.2.1 " +;HKLM,%UNINSTALL_KEY%,DisplayVersion,,"1.2.1" +;HKLM,%UNINSTALL_KEY%,HelpLink,,"http://www.ircomm2k.de" +;HKLM,%UNINSTALL_KEY%,Publisher,,%JK% +;HKLM,%UNINSTALL_KEY%,UninstallString,0x00020000,"%windir%\IrCOMM2k-Setup.exe" + +;[IrCOMM2kSvcAddReg] +;HKR,Parameters,ActiveConnectOnly,REG_DWORD,0x00000000 + + +[IrCOMM2k_DriverEventLog_Inst] +AddReg = IrCOMM2k_DriverEventLog_AddReg + +[IrCOMM2k_DriverEventLog_AddReg] +HKR,,EventMessageFile,REG_EXPAND_SZ,"%SystemRoot%\System32\IoLogMsg.dll;%SystemRoot%\System32\drivers\ircomm2k.sys" +HKR,,TypesSupported,REG_DWORD,7 + + +[Strings] + +; +; Non-Localizable Strings +; + +REG_SZ = 0x00000000 +REG_MULTI_SZ = 0x00010000 +REG_EXPAND_SZ = 0x00020000 +REG_BINARY = 0x00000001 +REG_DWORD = 0x00010001 +SERVICEROOT = "System\CurrentControlSet\Services" +UNINSTALL_KEY = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\IrCOMM2k" + +; +; Localizable Strings +; + +JK = "Jan Kiszka" +JK.DeviceDescIrCOMM = "Virtueller Infrarot-Kommunikationsanschluss" +IrCOMM2k.DrvName = "Virtueller Infrarot-Kommunikationsanschluss" +;IrCOMM2k.SvcName = "Virtueller Infrarot-Kommunikationsanschluß, Dienstprogramm" +;IrCOMM2k.SvcDesc = "Bildet über Infarot einen Kommunikationsanschluß nach." diff --git a/ao-tools/altosui/Instdrv/NSIS/Contrib/InstDrv/ircomm2k.sys b/ao-tools/altosui/Instdrv/NSIS/Contrib/InstDrv/ircomm2k.sys new file mode 100644 index 00000000..7882583b Binary files /dev/null and b/ao-tools/altosui/Instdrv/NSIS/Contrib/InstDrv/ircomm2k.sys differ diff --git a/ao-tools/altosui/Instdrv/NSIS/Plugins/InstDrv.dll b/ao-tools/altosui/Instdrv/NSIS/Plugins/InstDrv.dll new file mode 100644 index 00000000..482e955e Binary files /dev/null and b/ao-tools/altosui/Instdrv/NSIS/Plugins/InstDrv.dll differ diff --git a/ao-tools/altosui/Makefile b/ao-tools/altosui/Makefile index cc9a440d..58acb26e 100644 --- a/ao-tools/altosui/Makefile +++ b/ao-tools/altosui/Makefile @@ -75,12 +75,12 @@ LINUX_APP=altosui DARWIN_ZIP=Altos-Mac.zip -WINDOWS_ZIP=Altos-Windows.zip +WINDOWS_EXE=Altos-Windows.exe LINUX_TGZ=Altos-Linux.tgz all: altosui.jar $(LINUX_APP) -fat: altosui.jar $(LINUX_APP) $(DARWIN_ZIP) $(WINDOWS_ZIP) $(LINUX_TGZ) +fat: altosui.jar $(LINUX_APP) $(DARWIN_ZIP) $(WINDOWS_EXE) $(LINUX_TGZ) $(CLASSFILES): @@ -137,7 +137,7 @@ clean: rm -rf windows linux distclean: clean - rm -f $(DARWIN_ZIP) $(WINDOWS_ZIP) $(LINUX_TGZ) + rm -f $(DARWIN_ZIP) $(WINDOWS_EXE) $(LINUX_TGZ) rm -rf darwin fat FAT_FILES=$(FATJAR) $(FREETTSJAR) $(HEXFILES) @@ -165,9 +165,9 @@ $(DARWIN_ZIP): $(DARWIN_FILES) WINDOWS_FILES = $(FAT_FILES) ../libaltos/altos.dll ../../telemetrum.inf -$(WINDOWS_ZIP): $(WINDOWS_FILES) +$(WINDOWS_EXE): $(WINDOWS_FILES) altos-install.nsi rm -f $@ mkdir -p windows/AltOS rm -f windows/AltOS/* cp $(WINDOWS_FILES) windows/AltOS - cd windows && zip -j -r ../$@ AltOS + makensis altos-windows.nsi diff --git a/ao-tools/altosui/altos-windows.nsi b/ao-tools/altosui/altos-windows.nsi new file mode 100644 index 00000000..abb0823b --- /dev/null +++ b/ao-tools/altosui/altos-windows.nsi @@ -0,0 +1,102 @@ +!addplugindir Instdrv/NSIS/Plugins + +Name "Altus Metrum Installer" + +OutFile "Altos-Windows.exe" + +; Default install directory +InstallDir "$PROGRAMFILES\AltusMetrum" + +; Tell the installer where to re-install a new version +InstallDirRegKey HKLM "Software\AltusMetrum" "Install_Dir" + +LicenseText "GNU General Public License Version 2" +LicenseData "../../COPYING" + +; Need admin privs for Vista or Win7 +RequestExecutionLevel admin + +ShowInstDetails Show + +ComponentText "Altus Metrum Software and Driver Installer" + +; Pages to present + +Page license +Page components +Page directory +Page instfiles + +UninstPage uninstConfirm +UninstPage instfiles + +; And the stuff to install + +Section "Install Driver" InstDriver + InstDrv::InitDriverSetup /NOUNLOAD {4D36E96D-E325-11CE-BFC1-08002BE10318} "Altus Metrum" + Pop $0 + DetailPrint "InitDriverSetup: $0" + + InstDrv::DeleteOemInfFiles /NOUNLOAD + InstDrv::CreateDevice /NOUNLOAD + SetOutPath $TEMP + File "../../telemetrum.inf" + InstDrv::InstallDriver /NOUNLOAD "$TEMP\telemetrum.inf" +SectionEnd + +Section "AltosUI Application" + SetOutPath $INSTDIR + + File "windows/AltOS/*.jar" + File "windows/AltOS/*.dll" + + CreateShortCut "$SMPROGRAMS\AltusMetrum.lnk" "$INSTDIR\altosui.jar" +SectionEnd + +Section "AltosUI Desktop Shortcut" + CreateShortCut "$DESKTOP\AltusMetrum.lnk" "$INSTDIR\altosui.jar" +SectionEnd + +Section "TeleMetrum and TeleDongle Firmware" + + SetOutPath $INSTDIR + + File "windows/AltOS/telemetrum-v1.0.ihx" + File "windows/AltOS/teledongle-v0.2.ihx" + +SectionEnd + +Section "Uninstaller" + + ; Deal with the uninstaller + + SetOutPath $INSTDIR + + ; Write the install path to the registry + WriteRegStr HKLM SOFTWARE\AltusMetrum "Install_Dir" "$INSTDIR" + + ; Write the uninstall keys for windows + WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\AltusMetrum" "DisplayName" "Altus Metrum" + WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\AltusMetrum" "UninstallString" '"$INSTDIR\uninstall.exe"' + WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\AltusMetrum" "NoModify" "1" + WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\AltusMetrum" "NoRepair" "1" + + WriteUninstaller "uninstall.exe" +SectionEnd + +Section "Uninstall" + DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\AltusMetrum" + DeleteRegKey HKLM "Software\AltusMetrum" + + Delete "$INSTDIR\*.*" + RMDir "$INSTDIR" + + ; Remove devices + InstDrv::InitDriverSetup /NOUNLOAD {4D36E96D-E325-11CE-BFC1-08002BE10318} "Altus Metrum" + InstDrv::DeleteOemInfFiles /NOUNLOAD + InstDrv::RemoveAllDevices + + ; Remove shortcuts, if any + Delete "$SMPROGRAMS\AltusMetrum.lnk" + Delete "$DESKTOP\AltusMetrum.lnk" +SectionEnd -- cgit v1.2.3 From c0988ddbf104ea729090c2e7e2a28cc6dc9e90f6 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 4 Sep 2010 00:14:15 -0700 Subject: altosui: ignore built files --- ao-tools/altosui/.gitignore | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'ao-tools') diff --git a/ao-tools/altosui/.gitignore b/ao-tools/altosui/.gitignore index 59913193..63672058 100644 --- a/ao-tools/altosui/.gitignore +++ b/ao-tools/altosui/.gitignore @@ -1,2 +1,14 @@ +windows/ +linux/ +darwin/ +fat/ +Manifest.txt +libaltosJNI +classes +altosui +Altos-Linux.tgz +Altos-Mac.zip +Altos-Windows.exe +*.jar *.class altosui -- cgit v1.2.3 From f550677df016070430ed38bfa2b2be33f1b8c40a Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 4 Sep 2010 00:16:41 -0700 Subject: altosui: oops. renamed the nsis file to altos-windows.nsi And forgot to change the dependency in the Makefile Signed-off-by: Keith Packard --- ao-tools/altosui/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/Makefile b/ao-tools/altosui/Makefile index 58acb26e..92f0e690 100644 --- a/ao-tools/altosui/Makefile +++ b/ao-tools/altosui/Makefile @@ -165,7 +165,7 @@ $(DARWIN_ZIP): $(DARWIN_FILES) WINDOWS_FILES = $(FAT_FILES) ../libaltos/altos.dll ../../telemetrum.inf -$(WINDOWS_EXE): $(WINDOWS_FILES) altos-install.nsi +$(WINDOWS_EXE): $(WINDOWS_FILES) altos-windows.nsi rm -f $@ mkdir -p windows/AltOS rm -f windows/AltOS/* -- cgit v1.2.3 From e844e8a0695e27af6f8e3e37a5e3bcc865b862e3 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 4 Sep 2010 01:13:42 -0700 Subject: altosui: Add icons to application and Windows menus. Use the altus-metrum icon for an application icon and a windows start menu/desktop icon. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosUI.java | 4 ++++ ao-tools/altosui/Makefile | 19 ++++++++++++++----- ao-tools/altosui/altos-windows.nsi | 6 ++++-- 3 files changed, 22 insertions(+), 7 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosUI.java b/ao-tools/altosui/AltosUI.java index 7e3fb7f9..eb376be4 100644 --- a/ao-tools/altosui/AltosUI.java +++ b/ao-tools/altosui/AltosUI.java @@ -75,6 +75,10 @@ public class AltosUI extends JFrame { String[] statusNames = { "Height (m)", "State", "RSSI (dBm)", "Speed (m/s)" }; Object[][] statusData = { { "0", "pad", "-50", "0" } }; + java.net.URL imgURL = AltosUI.class.getResource("/images/altus-metrum-16x16.jpg"); + if (imgURL != null) + setIconImage(new ImageIcon(imgURL).getImage()); + AltosPreferences.init(this); vbox = Box.createVerticalBox(); diff --git a/ao-tools/altosui/Makefile b/ao-tools/altosui/Makefile index 92f0e690..90621f36 100644 --- a/ao-tools/altosui/Makefile +++ b/ao-tools/altosui/Makefile @@ -42,6 +42,9 @@ CLASSFILES=\ AltosRomconfigUI.class \ AltosVoice.class +JAVA_ICON=../../icon/altus-metrum-16x16.jpg +WINDOWS_ICON=../../icon/altus-metrum.ico + # where altosui.jar gets installed ALTOSLIB=/usr/share/java @@ -87,8 +90,8 @@ $(CLASSFILES): .java.class: javac -encoding UTF8 -classpath "$(CLASSPATH)" $(JAVAFLAGS) $*.java -altosui.jar: classes/altosui classes/libaltosJNI $(CLASSFILES) Manifest.txt - cd ./classes && jar cfm ../$@ altosui/Manifest.txt altosui/*.class libaltosJNI/*.class +altosui.jar: classes/images classes/altosui classes/libaltosJNI $(CLASSFILES) Manifest.txt + cd ./classes && jar cfm ../$@ altosui/Manifest.txt images/* altosui/*.class libaltosJNI/*.class Manifest.txt: Makefile $(CLASSFILES) echo 'Main-Class: altosui.AltosUI' > $@ @@ -102,6 +105,10 @@ classes/libaltosJNI: mkdir -p classes ln -sf ../../libaltos/libaltosJNI classes/libaltosJNI +classes/images: + mkdir -p classes/images + ln -sf ../../$(JAVA_ICON) classes/images + altosui: echo "#!/bin/sh" > $@ echo "exec java -Djava.library.path=/usr/lib/altos -jar /usr/share/java/altosui.jar" >> $@ @@ -114,11 +121,13 @@ fat/altosui: echo 'exec java -Djava.library.path="$$DIR" -jar "$$DIR"/altosui.jar' >> $@ chmod +x $@ -fat/altosui.jar: $(CLASSFILES) fat/classes/Manifest.txt +fat/altosui.jar: $(CLASSFILES) $(JAVA_ICON) fat/classes/Manifest.txt mkdir -p fat/classes test -L fat/classes/altosui || ln -sf ../.. fat/classes/altosui + mkdir -p fat/classes/images + cp $(JAVA_ICON) fat/classes/images test -L fat/classes/libaltosJNI || ln -sf ../../../libaltos/libaltosJNI fat/classes/libaltosJNI - cd ./fat/classes && jar cfm ../../$@ Manifest.txt altosui/*.class libaltosJNI/*.class + cd ./fat/classes && jar cfm ../../$@ Manifest.txt images/* altosui/*.class libaltosJNI/*.class fat/classes/Manifest.txt: $(CLASSFILES) Makefile mkdir -p fat/classes @@ -163,7 +172,7 @@ $(DARWIN_ZIP): $(DARWIN_FILES) cp $(DARWIN_EXTRA) darwin/AltOS cd darwin && zip -r ../$@ AltosUI.app AltOS -WINDOWS_FILES = $(FAT_FILES) ../libaltos/altos.dll ../../telemetrum.inf +WINDOWS_FILES = $(FAT_FILES) ../libaltos/altos.dll ../../telemetrum.inf $(WINDOWS_ICON) $(WINDOWS_EXE): $(WINDOWS_FILES) altos-windows.nsi rm -f $@ diff --git a/ao-tools/altosui/altos-windows.nsi b/ao-tools/altosui/altos-windows.nsi index abb0823b..5ac708f9 100644 --- a/ao-tools/altosui/altos-windows.nsi +++ b/ao-tools/altosui/altos-windows.nsi @@ -50,11 +50,13 @@ Section "AltosUI Application" File "windows/AltOS/*.jar" File "windows/AltOS/*.dll" - CreateShortCut "$SMPROGRAMS\AltusMetrum.lnk" "$INSTDIR\altosui.jar" + File "windows/AltOS/*.ico" + + CreateShortCut "$SMPROGRAMS\AltusMetrum.lnk" "$INSTDIR\altosui.jar" "" "$INSTDIR\altus-metrum.ico" SectionEnd Section "AltosUI Desktop Shortcut" - CreateShortCut "$DESKTOP\AltusMetrum.lnk" "$INSTDIR\altosui.jar" + CreateShortCut "$DESKTOP\AltusMetrum.lnk" "$INSTDIR\altosui.jar" "" "$INSTDIR\altus-metrum.ico" SectionEnd Section "TeleMetrum and TeleDongle Firmware" -- cgit v1.2.3 From 887b11f6b9c81b9f15348d54017e700ca7dc5e55 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 4 Sep 2010 17:27:17 -0700 Subject: Use autotools for altosui and libaltos This switches from hand-written Makefiles to automake with libtool for these parts of the system. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosUI.java | 2 +- ao-tools/altosui/Makefile | 182 ---------------------------------- ao-tools/altosui/Makefile-standalone | 182 ++++++++++++++++++++++++++++++++++ ao-tools/altosui/Makefile.am | 165 ++++++++++++++++++++++++++++++ ao-tools/altosui/altos-windows.nsi | 20 ++-- ao-tools/altosui/altosui-fat | 4 + ao-tools/libaltos/.gitignore | 12 +++ ao-tools/libaltos/Makefile | 126 ----------------------- ao-tools/libaltos/Makefile-standalone | 126 +++++++++++++++++++++++ ao-tools/libaltos/Makefile.am | 27 +++++ configure.ac | 39 +++++++- 11 files changed, 566 insertions(+), 319 deletions(-) delete mode 100644 ao-tools/altosui/Makefile create mode 100644 ao-tools/altosui/Makefile-standalone create mode 100644 ao-tools/altosui/Makefile.am create mode 100755 ao-tools/altosui/altosui-fat create mode 100644 ao-tools/libaltos/.gitignore delete mode 100644 ao-tools/libaltos/Makefile create mode 100644 ao-tools/libaltos/Makefile-standalone create mode 100644 ao-tools/libaltos/Makefile.am (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosUI.java b/ao-tools/altosui/AltosUI.java index eb376be4..37625e8e 100644 --- a/ao-tools/altosui/AltosUI.java +++ b/ao-tools/altosui/AltosUI.java @@ -75,7 +75,7 @@ public class AltosUI extends JFrame { String[] statusNames = { "Height (m)", "State", "RSSI (dBm)", "Speed (m/s)" }; Object[][] statusData = { { "0", "pad", "-50", "0" } }; - java.net.URL imgURL = AltosUI.class.getResource("/images/altus-metrum-16x16.jpg"); + java.net.URL imgURL = AltosUI.class.getResource("/altus-metrum-16x16.jpg"); if (imgURL != null) setIconImage(new ImageIcon(imgURL).getImage()); diff --git a/ao-tools/altosui/Makefile b/ao-tools/altosui/Makefile deleted file mode 100644 index 90621f36..00000000 --- a/ao-tools/altosui/Makefile +++ /dev/null @@ -1,182 +0,0 @@ -.SUFFIXES: .java .class - -CLASSPATH=classes:./*:/usr/share/java/* -CLASSFILES=\ - Altos.class \ - AltosChannelMenu.class \ - AltosConfig.class \ - AltosConfigUI.class \ - AltosConvert.class \ - AltosCRCException.class \ - AltosCSV.class \ - AltosCSVUI.class \ - AltosDebug.class \ - AltosEepromDownload.class \ - AltosEepromMonitor.class \ - AltosEepromReader.class \ - AltosEepromRecord.class \ - AltosFile.class \ - AltosFlash.class \ - AltosFlashUI.class \ - AltosFlightInfoTableModel.class \ - AltosFlightStatusTableModel.class \ - AltosGPS.class \ - AltosGreatCircle.class \ - AltosHexfile.class \ - AltosLine.class \ - AltosLog.class \ - AltosLogfileChooser.class \ - AltosParse.class \ - AltosPreferences.class \ - AltosReader.class \ - AltosRecord.class \ - AltosSerialMonitor.class \ - AltosSerial.class \ - AltosState.class \ - AltosTelemetry.class \ - AltosTelemetryReader.class \ - AltosUI.class \ - AltosDevice.class \ - AltosDeviceDialog.class \ - AltosRomconfig.class \ - AltosRomconfigUI.class \ - AltosVoice.class - -JAVA_ICON=../../icon/altus-metrum-16x16.jpg -WINDOWS_ICON=../../icon/altus-metrum.ico - -# where altosui.jar gets installed -ALTOSLIB=/usr/share/java - -# where freetts.jar is to be found -FREETTSLIB=/usr/share/java - -# all of the freetts files -FREETTSJAR= \ - $(FREETTSLIB)/cmudict04.jar \ - $(FREETTSLIB)/cmulex.jar \ - $(FREETTSLIB)/cmu_time_awb.jar \ - $(FREETTSLIB)/cmutimelex.jar \ - $(FREETTSLIB)/cmu_us_kal.jar \ - $(FREETTSLIB)/en_us.jar \ - $(FREETTSLIB)/freetts.jar - -# The current hex files -HEXLIB=../../src -HEXFILES = \ - $(HEXLIB)/telemetrum-v1.0.ihx \ - $(HEXLIB)/teledongle-v0.2.ihx - -JAVAFLAGS=-Xlint:unchecked -Xlint:deprecation - -ALTOSUIJAR = altosui.jar -FATJAR = fat/altosui.jar - -OS:=$(shell uname) - -LINUX_APP=altosui - -DARWIN_ZIP=Altos-Mac.zip - -WINDOWS_EXE=Altos-Windows.exe - -LINUX_TGZ=Altos-Linux.tgz - -all: altosui.jar $(LINUX_APP) -fat: altosui.jar $(LINUX_APP) $(DARWIN_ZIP) $(WINDOWS_EXE) $(LINUX_TGZ) - -$(CLASSFILES): - -.java.class: - javac -encoding UTF8 -classpath "$(CLASSPATH)" $(JAVAFLAGS) $*.java - -altosui.jar: classes/images classes/altosui classes/libaltosJNI $(CLASSFILES) Manifest.txt - cd ./classes && jar cfm ../$@ altosui/Manifest.txt images/* altosui/*.class libaltosJNI/*.class - -Manifest.txt: Makefile $(CLASSFILES) - echo 'Main-Class: altosui.AltosUI' > $@ - echo "Class-Path: $(FREETTSLIB)/freetts.jar" >> $@ - -classes/altosui: - mkdir -p classes - ln -sf .. classes/altosui - -classes/libaltosJNI: - mkdir -p classes - ln -sf ../../libaltos/libaltosJNI classes/libaltosJNI - -classes/images: - mkdir -p classes/images - ln -sf ../../$(JAVA_ICON) classes/images - -altosui: - echo "#!/bin/sh" > $@ - echo "exec java -Djava.library.path=/usr/lib/altos -jar /usr/share/java/altosui.jar" >> $@ - chmod +x ./altosui - -fat/altosui: - echo "#!/bin/sh" > $@ - echo 'ME=`which "$0"`' >> $@ - echo 'DIR=`dirname "$ME"`' >> $@ - echo 'exec java -Djava.library.path="$$DIR" -jar "$$DIR"/altosui.jar' >> $@ - chmod +x $@ - -fat/altosui.jar: $(CLASSFILES) $(JAVA_ICON) fat/classes/Manifest.txt - mkdir -p fat/classes - test -L fat/classes/altosui || ln -sf ../.. fat/classes/altosui - mkdir -p fat/classes/images - cp $(JAVA_ICON) fat/classes/images - test -L fat/classes/libaltosJNI || ln -sf ../../../libaltos/libaltosJNI fat/classes/libaltosJNI - cd ./fat/classes && jar cfm ../../$@ Manifest.txt images/* altosui/*.class libaltosJNI/*.class - -fat/classes/Manifest.txt: $(CLASSFILES) Makefile - mkdir -p fat/classes - echo 'Main-Class: altosui.AltosUI' > $@ - echo "Class-Path: freetts.jar" >> $@ - -install: altosui.jar altosui - install -m 0644 altosui.jar $(DESTDIR)/usr/share/java/altosui.jar - install -m 0644 altosui.1 $(DESTDIR)/usr/share/man/man1/altosui.1 - install altosui $(DESTDIR)/usr/bin/altosui - -clean: - rm -f *.class altosui.jar - rm -f AltosUI.app/Contents/Resources/Java/* - rm -rf classes - rm -rf windows linux - -distclean: clean - rm -f $(DARWIN_ZIP) $(WINDOWS_EXE) $(LINUX_TGZ) - rm -rf darwin fat - -FAT_FILES=$(FATJAR) $(FREETTSJAR) $(HEXFILES) - -LINUX_FILES=$(FAT_FILES) ../libaltos/libaltos.so fat/altosui -$(LINUX_TGZ): $(LINUX_FILES) - rm -f $@ - mkdir -p linux/AltOS - rm -f linux/AltOS/* - cp $(LINUX_FILES) linux/AltOS - cd linux && tar czf ../$@ AltOS - -DARWIN_RESOURCES=$(FATJAR) $(FREETTSJAR) ../libaltos/libaltos.dylib -DARWIN_EXTRA=$(HEXFILES) -DARWIN_FILES=$(DARWIN_RESOURCES) $(DARWIN_EXTRA) - -$(DARWIN_ZIP): $(DARWIN_FILES) - rm -f $@ - cp -a AltosUI.app darwin/ - mkdir -p darwin/AltosUI.app/Contents/Resources/Java - cp $(DARWIN_RESOURCES) darwin/AltosUI.app/Contents/Resources/Java - mkdir -p darwin/AltOS - cp $(DARWIN_EXTRA) darwin/AltOS - cd darwin && zip -r ../$@ AltosUI.app AltOS - -WINDOWS_FILES = $(FAT_FILES) ../libaltos/altos.dll ../../telemetrum.inf $(WINDOWS_ICON) - -$(WINDOWS_EXE): $(WINDOWS_FILES) altos-windows.nsi - rm -f $@ - mkdir -p windows/AltOS - rm -f windows/AltOS/* - cp $(WINDOWS_FILES) windows/AltOS - makensis altos-windows.nsi diff --git a/ao-tools/altosui/Makefile-standalone b/ao-tools/altosui/Makefile-standalone new file mode 100644 index 00000000..90621f36 --- /dev/null +++ b/ao-tools/altosui/Makefile-standalone @@ -0,0 +1,182 @@ +.SUFFIXES: .java .class + +CLASSPATH=classes:./*:/usr/share/java/* +CLASSFILES=\ + Altos.class \ + AltosChannelMenu.class \ + AltosConfig.class \ + AltosConfigUI.class \ + AltosConvert.class \ + AltosCRCException.class \ + AltosCSV.class \ + AltosCSVUI.class \ + AltosDebug.class \ + AltosEepromDownload.class \ + AltosEepromMonitor.class \ + AltosEepromReader.class \ + AltosEepromRecord.class \ + AltosFile.class \ + AltosFlash.class \ + AltosFlashUI.class \ + AltosFlightInfoTableModel.class \ + AltosFlightStatusTableModel.class \ + AltosGPS.class \ + AltosGreatCircle.class \ + AltosHexfile.class \ + AltosLine.class \ + AltosLog.class \ + AltosLogfileChooser.class \ + AltosParse.class \ + AltosPreferences.class \ + AltosReader.class \ + AltosRecord.class \ + AltosSerialMonitor.class \ + AltosSerial.class \ + AltosState.class \ + AltosTelemetry.class \ + AltosTelemetryReader.class \ + AltosUI.class \ + AltosDevice.class \ + AltosDeviceDialog.class \ + AltosRomconfig.class \ + AltosRomconfigUI.class \ + AltosVoice.class + +JAVA_ICON=../../icon/altus-metrum-16x16.jpg +WINDOWS_ICON=../../icon/altus-metrum.ico + +# where altosui.jar gets installed +ALTOSLIB=/usr/share/java + +# where freetts.jar is to be found +FREETTSLIB=/usr/share/java + +# all of the freetts files +FREETTSJAR= \ + $(FREETTSLIB)/cmudict04.jar \ + $(FREETTSLIB)/cmulex.jar \ + $(FREETTSLIB)/cmu_time_awb.jar \ + $(FREETTSLIB)/cmutimelex.jar \ + $(FREETTSLIB)/cmu_us_kal.jar \ + $(FREETTSLIB)/en_us.jar \ + $(FREETTSLIB)/freetts.jar + +# The current hex files +HEXLIB=../../src +HEXFILES = \ + $(HEXLIB)/telemetrum-v1.0.ihx \ + $(HEXLIB)/teledongle-v0.2.ihx + +JAVAFLAGS=-Xlint:unchecked -Xlint:deprecation + +ALTOSUIJAR = altosui.jar +FATJAR = fat/altosui.jar + +OS:=$(shell uname) + +LINUX_APP=altosui + +DARWIN_ZIP=Altos-Mac.zip + +WINDOWS_EXE=Altos-Windows.exe + +LINUX_TGZ=Altos-Linux.tgz + +all: altosui.jar $(LINUX_APP) +fat: altosui.jar $(LINUX_APP) $(DARWIN_ZIP) $(WINDOWS_EXE) $(LINUX_TGZ) + +$(CLASSFILES): + +.java.class: + javac -encoding UTF8 -classpath "$(CLASSPATH)" $(JAVAFLAGS) $*.java + +altosui.jar: classes/images classes/altosui classes/libaltosJNI $(CLASSFILES) Manifest.txt + cd ./classes && jar cfm ../$@ altosui/Manifest.txt images/* altosui/*.class libaltosJNI/*.class + +Manifest.txt: Makefile $(CLASSFILES) + echo 'Main-Class: altosui.AltosUI' > $@ + echo "Class-Path: $(FREETTSLIB)/freetts.jar" >> $@ + +classes/altosui: + mkdir -p classes + ln -sf .. classes/altosui + +classes/libaltosJNI: + mkdir -p classes + ln -sf ../../libaltos/libaltosJNI classes/libaltosJNI + +classes/images: + mkdir -p classes/images + ln -sf ../../$(JAVA_ICON) classes/images + +altosui: + echo "#!/bin/sh" > $@ + echo "exec java -Djava.library.path=/usr/lib/altos -jar /usr/share/java/altosui.jar" >> $@ + chmod +x ./altosui + +fat/altosui: + echo "#!/bin/sh" > $@ + echo 'ME=`which "$0"`' >> $@ + echo 'DIR=`dirname "$ME"`' >> $@ + echo 'exec java -Djava.library.path="$$DIR" -jar "$$DIR"/altosui.jar' >> $@ + chmod +x $@ + +fat/altosui.jar: $(CLASSFILES) $(JAVA_ICON) fat/classes/Manifest.txt + mkdir -p fat/classes + test -L fat/classes/altosui || ln -sf ../.. fat/classes/altosui + mkdir -p fat/classes/images + cp $(JAVA_ICON) fat/classes/images + test -L fat/classes/libaltosJNI || ln -sf ../../../libaltos/libaltosJNI fat/classes/libaltosJNI + cd ./fat/classes && jar cfm ../../$@ Manifest.txt images/* altosui/*.class libaltosJNI/*.class + +fat/classes/Manifest.txt: $(CLASSFILES) Makefile + mkdir -p fat/classes + echo 'Main-Class: altosui.AltosUI' > $@ + echo "Class-Path: freetts.jar" >> $@ + +install: altosui.jar altosui + install -m 0644 altosui.jar $(DESTDIR)/usr/share/java/altosui.jar + install -m 0644 altosui.1 $(DESTDIR)/usr/share/man/man1/altosui.1 + install altosui $(DESTDIR)/usr/bin/altosui + +clean: + rm -f *.class altosui.jar + rm -f AltosUI.app/Contents/Resources/Java/* + rm -rf classes + rm -rf windows linux + +distclean: clean + rm -f $(DARWIN_ZIP) $(WINDOWS_EXE) $(LINUX_TGZ) + rm -rf darwin fat + +FAT_FILES=$(FATJAR) $(FREETTSJAR) $(HEXFILES) + +LINUX_FILES=$(FAT_FILES) ../libaltos/libaltos.so fat/altosui +$(LINUX_TGZ): $(LINUX_FILES) + rm -f $@ + mkdir -p linux/AltOS + rm -f linux/AltOS/* + cp $(LINUX_FILES) linux/AltOS + cd linux && tar czf ../$@ AltOS + +DARWIN_RESOURCES=$(FATJAR) $(FREETTSJAR) ../libaltos/libaltos.dylib +DARWIN_EXTRA=$(HEXFILES) +DARWIN_FILES=$(DARWIN_RESOURCES) $(DARWIN_EXTRA) + +$(DARWIN_ZIP): $(DARWIN_FILES) + rm -f $@ + cp -a AltosUI.app darwin/ + mkdir -p darwin/AltosUI.app/Contents/Resources/Java + cp $(DARWIN_RESOURCES) darwin/AltosUI.app/Contents/Resources/Java + mkdir -p darwin/AltOS + cp $(DARWIN_EXTRA) darwin/AltOS + cd darwin && zip -r ../$@ AltosUI.app AltOS + +WINDOWS_FILES = $(FAT_FILES) ../libaltos/altos.dll ../../telemetrum.inf $(WINDOWS_ICON) + +$(WINDOWS_EXE): $(WINDOWS_FILES) altos-windows.nsi + rm -f $@ + mkdir -p windows/AltOS + rm -f windows/AltOS/* + cp $(WINDOWS_FILES) windows/AltOS + makensis altos-windows.nsi diff --git a/ao-tools/altosui/Makefile.am b/ao-tools/altosui/Makefile.am new file mode 100644 index 00000000..20c8b26d --- /dev/null +++ b/ao-tools/altosui/Makefile.am @@ -0,0 +1,165 @@ +JAVAROOT=classes + +CLASSPATH_ENV=CLASSPATH="classes/altosui/*:../libaltos/libaltosJNI/*:$(FREETTS)/*:/usr/share/java/*" + +altosui_JAVA = \ + AltosChannelMenu.java \ + AltosConfig.java \ + AltosConfigUI.java \ + AltosConvert.java \ + AltosCRCException.java \ + AltosCSV.java \ + AltosCSVUI.java \ + AltosDebug.java \ + AltosDeviceDialog.java \ + AltosDevice.java \ + AltosEepromDownload.java \ + AltosEepromMonitor.java \ + AltosEepromReader.java \ + AltosEepromRecord.java \ + AltosFile.java \ + AltosFlash.java \ + AltosFlashUI.java \ + AltosFlightInfoTableModel.java \ + AltosFlightStatusTableModel.java \ + AltosGPS.java \ + AltosGreatCircle.java \ + AltosHexfile.java \ + Altos.java \ + AltosLine.java \ + AltosLogfileChooser.java \ + AltosLog.java \ + AltosParse.java \ + AltosPreferences.java \ + AltosReader.java \ + AltosRecord.java \ + AltosRomconfig.java \ + AltosRomconfigUI.java \ + AltosSerial.java \ + AltosSerialMonitor.java \ + AltosState.java \ + AltosTelemetry.java \ + AltosTelemetryReader.java \ + AltosUI.java \ + AltosVoice.java + +FREETTS_CLASS= \ + cmudict04.jar \ + cmulex.jar \ + cmu_time_awb.jar \ + cmutimelex.jar \ + cmu_us_kal.jar \ + en_us.jar \ + freetts.jar + +LIBALTOS= \ + libaltos.so \ + libaltos.dylib \ + altos.dll + +JAR=altosui.jar + +FATJAR=altosui-fat.jar + +# Icons +JAVA_ICON=$(top_srcdir)/icon/altus-metrum-16x16.jpg +WINDOWS_ICON=$(top_srcdir)/icon/altus-metrum.ico + +# Firmware +FIRMWARE_TD=$(top_srcdir)/src/teledongle-v0.2.ihx +FIRMWARE_TM=$(top_srcdir)/src/telemetrum-v1.0.ihx +FIRMWARE=$(FIRMWARE_TM) $(FIRMWARE_TD) + +# Distribution targets +LINUX_DIST=Altos-Linux-$(VERSION).tar.bz2 +MACOSX_DIST=Altos-Mac-$(VERSION).zip +WINDOWS_DIST=Altos-Windows-$(VERSION_DASH).exe + +FAT_FILES=$(FATJAR) $(FREETTS_CLASS) + +LINUX_FILES=$(FAT_FILES) libaltos.so + +MACOSX_FILES=$(FAT_FILES) libaltos.dylib +MACOSX_EXTRA=$(FIRMWARE) + +WINDOWS_FILES=$(FAT_FILES) altos.dll $(top_srcdir)/telemetrum.inf $(WINDOWS_ICON) + +all-local: classes/altosui $(JAR) $(FATJAR) + +clean-local: + -rm -rf classes/altosui $(JAR) $(FATJAR) \ + $(LINUX_DIST) $(MACOSX_DIST) $(WINDOWS_DIST) $(FREETTS_CLASS) \ + $(LIBALTOS) Manifest.txt Manifest-fat.txt altos-windows.log \ + altosui altosui-test macosx linux + +fat: $(FATJAR) $(LINUX_DIST) $(MACOSX_DIST) $(WINDOWS_DIST) + +altosuidir=$(datadir)/java + +install-altosuiJAVA: altosui.jar + @$(NORMAL_INSTALL) + test -z "$(altosuidir)" || $(MKDIR_P) "$(DESTDIR)$(altosuidir)" + echo " $(INSTALL_DATA)" "$<" "'$(DESTDIR)$(altosuidir)/altosui.jar'"; \ + $(INSTALL_DATA) "$<" "$(DESTDIR)$(altosuidir)" + +classes/altosui: + mkdir -p classes/altosui + +$(JAR): classaltosui.stamp Manifest.txt $(JAVA_ICON) + jar cfm $@ Manifest.txt \ + -C $(top_srcdir)/icon altus-metrum-16x16.jpg \ + -C classes altosui \ + -C ../libaltos libaltosJNI + +$(FATJAR): classaltosui.stamp Manifest-fat.txt $(FREETTS_CLASS) $(LIBALTOS) $(JAVA_ICON) + jar cfm $@ Manifest-fat.txt \ + -C $(top_srcdir)/icon altus-metrum-16x16.jpg \ + -C classes altosui \ + -C ../libaltos libaltosJNI + +Manifest.txt: Makefile + echo 'Main-Class: altosui.AltosUI' > $@ + echo "Class-Path: $(FREETTS)/freetts.jar" >> $@ + +Manifest-fat.txt: + echo 'Main-Class: altosui.AltosUI' > $@ + echo "Class-Path: freetts.jar" >> $@ + +altosui: Makefile + echo "#!/bin/sh" > $@ + echo 'exec java -cp "$(FREETTS)/*" -Djava.library.path="$(libdir)" -jar "$(altosuidir)/altosui.jar"' >> $@ + chmod +x $@ + +altosui-test: Makefile + echo "#!/bin/sh" > $@ + echo 'exec java -cp "$(FREETTS)/*" -Djava.library.path="../libaltos" -jar altosui.jar' >> $@ + chmod +x $@ + +$(LIBALTOS): + -rm -f "$@" + $(LN_S) ../libaltos/"$@" . + +$(FREETTS_CLASS): Makefile + -rm -f "$@" + $(LN_S) "$(FREETTS)"/"$@" . + +$(LINUX_DIST): $(LINUX_FILES) + -rm -f $@ + -rm -rf linux + mkdir -p linux/AltOS + cp -a $(LINUX_FILES) linux/AltOS + tar cjf $@ -C linux AltOS + +$(MACOSX_DIST): $(MACOSX_FILES) $(MACOSX_EXTRA) + -rm -f $@ + -rm -rf macosx + mkdir macosx + cp -a AltosUI.app macosx/ + mkdir -p macosx/AltOS macosx/AltosUI.app/Contents/Resources/Java + cp -a $(MACOSX_FILES) macosx/AltosUI.app/Contents/Resources/Java + cp -a $(MACOSX_EXTRA) macosx/AltOS + cd macosx && zip -r ../$@ AltosUI.app AltOS + +$(WINDOWS_DIST): $(WINDOWS_FILES) altos-windows.nsi + -rm -f $@ + makensis -Oaltos-windows.log "-XOutFile $@" altos-windows.nsi \ No newline at end of file diff --git a/ao-tools/altosui/altos-windows.nsi b/ao-tools/altosui/altos-windows.nsi index 5ac708f9..6f38ac0e 100644 --- a/ao-tools/altosui/altos-windows.nsi +++ b/ao-tools/altosui/altos-windows.nsi @@ -2,8 +2,6 @@ Name "Altus Metrum Installer" -OutFile "Altos-Windows.exe" - ; Default install directory InstallDir "$PROGRAMFILES\AltusMetrum" @@ -47,10 +45,18 @@ SectionEnd Section "AltosUI Application" SetOutPath $INSTDIR - File "windows/AltOS/*.jar" - File "windows/AltOS/*.dll" + File "altosui.jar" + File "cmudict04.jar" + File "cmulex.jar" + File "cmu_time_awb.jar" + File "cmutimelex.jar" + File "cmu_us_kal.jar" + File "en_us.jar" + File "freetts.jar" + + File "*.dll" - File "windows/AltOS/*.ico" + File "../../icon/*.ico" CreateShortCut "$SMPROGRAMS\AltusMetrum.lnk" "$INSTDIR\altosui.jar" "" "$INSTDIR\altus-metrum.ico" SectionEnd @@ -63,8 +69,8 @@ Section "TeleMetrum and TeleDongle Firmware" SetOutPath $INSTDIR - File "windows/AltOS/telemetrum-v1.0.ihx" - File "windows/AltOS/teledongle-v0.2.ihx" + File "../../src/telemetrum-v1.0/telemetrum-v1.0.ihx" + File "../../src/teledongle-v0.2/teledongle-v0.2.ihx" SectionEnd diff --git a/ao-tools/altosui/altosui-fat b/ao-tools/altosui/altosui-fat new file mode 100755 index 00000000..a95b78b8 --- /dev/null +++ b/ao-tools/altosui/altosui-fat @@ -0,0 +1,4 @@ +#!/bin/sh +me=`which "$0"` +dir=`dirname "$me"` +exec java -cp "$dir/*" -Djava.library.path="$dir" -jar "$dir"/altosui.jar diff --git a/ao-tools/libaltos/.gitignore b/ao-tools/libaltos/.gitignore new file mode 100644 index 00000000..c490e6f8 --- /dev/null +++ b/ao-tools/libaltos/.gitignore @@ -0,0 +1,12 @@ +*.so +*.lo +*.la +*.java +*.class +.libs/ +classlibaltos.stamp +libaltos_wrap.c +libaltosJNI +cjnitest +libaltos.swig +swig_bindings/ diff --git a/ao-tools/libaltos/Makefile b/ao-tools/libaltos/Makefile deleted file mode 100644 index cb767c85..00000000 --- a/ao-tools/libaltos/Makefile +++ /dev/null @@ -1,126 +0,0 @@ -OS:=$(shell uname) - -# -# Linux -# -ifeq ($(OS),Linux) - -JAVA_CFLAGS=-I/usr/lib/jvm/java-6-openjdk/include - -OS_LIB_CFLAGS=-DLINUX -DPOSIX_TTY $(JAVA_CFLAGS) - -OS_APP_CFLAGS=$(OS_LIB_CFLAGS) - -OS_LDFLAGS= - -LIBNAME=libaltos.so -EXEEXT= -endif - -# -# Darwin (Mac OS X) -# -ifeq ($(OS),Darwin) - -OS_LIB_CFLAGS=\ - -DDARWIN -DPOSIX_TTY -arch i386 -arch x86_64 \ - --sysroot=/Developer/SDKs/MacOSX10.5.sdk -mmacosx-version-min=10.5 \ - -iwithsysroot /System/Library/Frameworks/JavaVM.framework/Headers \ - -iwithsysroot /System/Library/Frameworks/IOKit.framework/Headers \ - -iwithsysroot /System/Library/Frameworks/CoreFoundation.framework/Headers -OS_APP_CFLAGS=$(OS_LIB_CFLAGS) - -OS_LDFLAGS =\ - -framework IOKit -framework CoreFoundation - -LIBNAME=libaltos.dylib -EXEEXT= - -endif - -# -# Windows -# -ifneq (,$(findstring MINGW,$(OS))) - -CC=gcc - -OS_LIB_CFLAGS = -DWINDOWS -mconsole -DBUILD_DLL -OS_APP_CFLAGS = -DWINDOWS -mconsole - -OS_LDFLAGS = -lgdi32 -luser32 -lcfgmgr32 -lsetupapi -lole32 \ - -ladvapi32 -lcomctl32 -mconsole -Wl,--add-stdcall-alias - -LIBNAME=altos.dll - -EXEEXT=.exe - -endif - -.SUFFIXES: .java .class - -CLASSPATH=".:jnitest/*:libaltosJNI:/usr/share/java/*" - -SWIG_DIR=swig_bindings/java -SWIG_FILE=$(SWIG_DIR)/libaltos.swig -SWIG_WRAP=$(SWIG_DIR)/libaltos_wrap.c - -JNI_DIR=libaltosJNI -JNI_FILE=$(JNI_DIR)/libaltosJNI.java -JNI_SRCS=$(JNI_FILE) \ - $(JNI_DIR)/SWIGTYPE_p_altos_file.java \ - $(JNI_DIR)/SWIGTYPE_p_altos_list.java \ - $(JNI_DIR)/altos_device.java \ - $(JNI_DIR)/libaltos.java - -JAVAFILES=\ - $(JNI_SRCS) - -CLASSFILES = $(JAVAFILES:%.java=%.class) - -JAVAFLAGS=-Xlint:unchecked - -CJNITEST=cjnitest$(EXEEXT) - -all: $(LIBNAME) $(CJNITEST) $(CLASSFILES) - -.java.class: - javac -encoding UTF8 -classpath "$(CLASSPATH)" $(JAVAFLAGS) $*.java - -CFLAGS=$(OS_LIB_CFLAGS) -O -I. - -LDFLAGS=$(OS_LDFLAGS) - -HEADERS=libaltos.h -SRCS = libaltos.c $(SWIG_WRAP) -OBJS = $(SRCS:%.c=%.o) -LIBS = $(DARWIN_LIBS) - -$(CJNITEST): cjnitest.c $(LIBNAME) - $(CC) -o $@ $(OS_APP_CFLAGS) cjnitest.c $(LIBNAME) $(LIBS) $(LDFLAGS) - -$(LIBNAME): $(OBJS) - $(CC) -shared $(CFLAGS) -o $@ $(OBJS) $(LIBS) $(LDFLAGS) - -clean: - rm -f $(CLASSFILES) $(OBJS) $(LIBNAME) $(CJNITEST) cjnitest.o - rm -rf swig_bindings libaltosJNI - -distclean: clean - -$(JNI_FILE): libaltos.i0 $(HEADERS) - mkdir -p $(SWIG_DIR) - mkdir -p libaltosJNI - sed 's;//%;%;' libaltos.i0 $(HEADERS) > $(SWIG_FILE) - swig -java -package libaltosJNI $(SWIG_FILE) - cp swig_bindings/java/*.java libaltosJNI - -$(SWIG_WRAP): $(JNI_FILE) - -ifeq ($(OS),Linux) -install: $(LIBNAME) - install -c $(LIBNAME) $(DESTDIR)/usr/lib/altos/$(LIBNAME) - -endif - -.NOTPARALLEL: diff --git a/ao-tools/libaltos/Makefile-standalone b/ao-tools/libaltos/Makefile-standalone new file mode 100644 index 00000000..4e438050 --- /dev/null +++ b/ao-tools/libaltos/Makefile-standalone @@ -0,0 +1,126 @@ +OS:=$(shell uname) + +# +# Linux +# +ifeq ($(OS),Linux) + +JAVA_CFLAGS=-I/usr/lib/jvm/java-6-openjdk/include + +OS_LIB_CFLAGS=-DLINUX -DPOSIX_TTY $(JAVA_CFLAGS) + +OS_APP_CFLAGS=$(OS_LIB_CFLAGS) + +OS_LDFLAGS= + +LIBNAME=libaltos.so +EXEEXT= +endif + +# +# Darwin (Mac OS X) +# +ifeq ($(OS),Darwin) + +OS_LIB_CFLAGS=\ + -DDARWIN -DPOSIX_TTY -arch i386 -arch x86_64 \ + --sysroot=/Developer/SDKs/MacOSX10.5.sdk -mmacosx-version-min=10.5 \ + -iwithsysroot /System/Library/Frameworks/JavaVM.framework/Headers \ + -iwithsysroot /System/Library/Frameworks/IOKit.framework/Headers \ + -iwithsysroot /System/Library/Frameworks/CoreFoundation.framework/Headers +OS_APP_CFLAGS=$(OS_LIB_CFLAGS) + +OS_LDFLAGS =\ + -framework IOKit -framework CoreFoundation + +LIBNAME=libaltos.dylib +EXEEXT= + +endif + +# +# Windows +# +ifneq (,$(findstring MINGW,$(OS))) + +CC=gcc + +OS_LIB_CFLAGS = -DWINDOWS -mconsole -DBUILD_DLL +OS_APP_CFLAGS = -DWINDOWS -mconsole + +OS_LDFLAGS = -lgdi32 -luser32 -lcfgmgr32 -lsetupapi -lole32 \ + -ladvapi32 -lcomctl32 -mconsole -Wl,--add-stdcall-alias + +LIBNAME=altos.dll + +EXEEXT=.exe + +endif + +.SUFFIXES: .java .class + +CLASSPATH=".:jnitest/*:libaltosJNI:/usr/share/java/*" + +SWIG_DIR=swig_bindings/java +SWIG_FILE=$(SWIG_DIR)/libaltos.swig +SWIG_WRAP=$(SWIG_DIR)/libaltos_wrap.c + +JNI_DIR=libaltosJNI +JNI_FILE=$(JNI_DIR)/libaltosJNI.java +JNI_SRCS=$(JNI_FILE) \ + $(JNI_DIR)/SWIGTYPE_p_altos_file.java \ + $(JNI_DIR)/SWIGTYPE_p_altos_list.java \ + $(JNI_DIR)/altos_device.java \ + $(JNI_DIR)/libaltos.java + +JAVAFILES=\ + $(JNI_SRCS) + +CLASSFILES = $(JAVAFILES:%.java=%.class) + +JAVAFLAGS=-Xlint:unchecked + +CJNITEST=cjnitest$(EXEEXT) + +all: $(LIBNAME) $(CJNITEST) $(CLASSFILES) + +.java.class: + javac -encoding UTF8 -classpath "$(CLASSPATH)" $(JAVAFLAGS) $*.java + +CFLAGS=$(OS_LIB_CFLAGS) -O -I. + +LDFLAGS=$(OS_LDFLAGS) + +HEADERS=libaltos.h +SRCS = libaltos.c $(SWIG_WRAP) +OBJS = $(SRCS:%.c=%.o) +LIBS = $(DARWIN_LIBS) + +$(CJNITEST): cjnitest.c $(LIBNAME) + $(CC) -o $@ $(OS_APP_CFLAGS) cjnitest.c $(LIBNAME) $(LIBS) $(LDFLAGS) + +$(LIBNAME): $(OBJS) + $(CC) -shared $(CFLAGS) -o $@ $(OBJS) $(LIBS) $(LDFLAGS) + +clean: + rm -f $(CLASSFILES) $(OBJS) $(LIBNAME) $(CJNITEST) cjnitest.o + rm -rf swig_bindings libaltosJNI + +distclean: clean + +$(JNI_FILE): libaltos.i0 $(HEADERS) + mkdir -p $(SWIG_DIR) + mkdir -p libaltosJNI + sed 's;//%;%;' libaltos.i0 $(HEADERS) > $(SWIG_FILE) + swig -java -package libaltosJNI $(SWIG_FILE) + cp swig_bindings/java/*.java libaltosJNI + +$(SWIG_WRAP): $(JNI_FILE) + +ifeq ($(OS),Linux) +install: $(LIBNAME) + install -c $(LIBNAME) $(DESTDIR)/usr/lib/altos/$(LIBNAME) + +endif + +.NOTPARALLEL: diff --git a/ao-tools/libaltos/Makefile.am b/ao-tools/libaltos/Makefile.am new file mode 100644 index 00000000..2f1d6fca --- /dev/null +++ b/ao-tools/libaltos/Makefile.am @@ -0,0 +1,27 @@ +JAVAC=javac +AM_CFLAGS="-I$(JVM_INCLUDE)" + +lib_LTLIBRARIES=libaltos.la + +libaltos_la_SOURCES=\ + libaltos.c + +HFILES=libaltos.h + +SWIG_FILE=libaltos.swig + +CLASSDIR=libaltosJNI + +$(SWIG_FILE): libaltos.i0 $(HFILES) + sed 's;//%;%;' libaltos.i0 $(HFILES) > $(SWIG_FILE) + +all-local: classlibaltos.stamp + +classlibaltos.stamp: $(SWIG_FILE) + swig -java -package libaltosJNI $(SWIG_FILE) + mkdir -p libaltosJNI + $(JAVAC) -d . $(AM_JAVACFLAGS) $(JAVACFLAGS) *.java && \ + touch classlibaltos.stamp + +clean-local: + -rm -rf libaltosJNI *.class *.java classlibaltos.stamp $(SWIG_FILE) \ No newline at end of file diff --git a/configure.ac b/configure.ac index fafc6b34..19ae0ac8 100644 --- a/configure.ac +++ b/configure.ac @@ -17,19 +17,50 @@ dnl 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. dnl dnl Process this file with autoconf to create configure. -AC_INIT(COPYING) - -AM_INIT_AUTOMAKE(altos, 0.1) +AC_PREREQ(2.57) +AC_INIT([altos], 0.7.1) +AC_CONFIG_SRCDIR([src/ao.h]) +AM_INIT_AUTOMAKE([foreign dist-bzip2]) AM_MAINTAINER_MODE +VERSION_DASH=`echo $VERSION | sed 's/\./-/g'` +AC_SUBST(VERSION_DASH) + dnl ========================================================================== AM_CONFIG_HEADER(config.h) +AC_ARG_WITH(freetts, AS_HELP_STRING([--with-freetts=PATH], + [Set freetts class path (default /usr/share/java)]), + [FREETTS=$withval], [FREETTS=/usr/share/java]) + +AC_SUBST(FREETTS) + +AC_ARG_WITH(jvm, AS_HELP_STRING([--with-jvm-include=PATH], + [Set jvm include path for jni builds (default searches in /usr/lib/jvm)]), + [JVM_INCLUDE=$withval], [JVM_INCLUDE=auto]) + +if test "x$JVM_INCLUDE" = "xauto"; then + AC_MSG_CHECKING([JVM include files]) + for jvm in default-java java-6-openjdk java-6-sun; do + if test "x$JVM_INCLUDE" = "xauto"; then + INCLUDE="/usr/lib/jvm/$jvm/include" + if test -f "$INCLUDE"/jni.h; then + JVM_INCLUDE="$INCLUDE" + fi + fi + done + if test "x$JVM_INCLUDE" = "xauto"; then + AC_MSG_ERROR([no JVM include files found]) + fi + AC_MSG_RESULT([$JVM_INCLUDE]) +fi + AC_PROG_CC AC_PROG_INSTALL AC_PROG_LN_S AC_PROG_RANLIB +AC_PROG_LIBTOOL PKG_PROG_PKG_CONFIG CFLAGS="-g" @@ -92,5 +123,7 @@ ao-tools/ao-list/Makefile ao-tools/ao-load/Makefile ao-tools/ao-postflight/Makefile ao-tools/ao-view/Makefile +ao-tools/libaltos/Makefile +ao-tools/altosui/Makefile ao-utils/Makefile ]) -- cgit v1.2.3 From aed59e1c057c13e28fd368dc2592aa4628211097 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 4 Sep 2010 17:59:11 -0700 Subject: Add version numbers to released files. Set version to 0.7.1 Instead of using git revision counts for version numbers, use explicit versions numbers configured in the configure.ac file. Expose published files with version numbers. Signed-off-by: Keith Packard --- ao-tools/altosui/Makefile.am | 8 ++++---- ao-tools/altosui/altos-windows.nsi | 4 ++-- configure.ac | 2 +- src/Makefile | 2 ++ src/Makefile.proto | 6 ++---- src/Version.in | 1 + src/teledongle-v0.1/.gitignore | 2 +- src/teledongle-v0.1/Makefile.defs | 2 +- src/teledongle-v0.2/.gitignore | 2 +- src/teledongle-v0.2/Makefile.defs | 2 +- src/telemetrum-v0.1-sirf/.gitignore | 2 +- src/telemetrum-v0.1-sirf/Makefile.defs | 2 +- src/telemetrum-v0.1-sky/.gitignore | 2 +- src/telemetrum-v0.1-sky/Makefile.defs | 2 +- src/telemetrum-v1.0/.gitignore | 2 +- src/telemetrum-v1.0/Makefile.defs | 2 +- src/tidongle/.gitignore | 2 +- src/tidongle/Makefile.defs | 2 +- 18 files changed, 24 insertions(+), 23 deletions(-) create mode 100644 src/Version.in (limited to 'ao-tools') diff --git a/ao-tools/altosui/Makefile.am b/ao-tools/altosui/Makefile.am index 20c8b26d..ed7e2f76 100644 --- a/ao-tools/altosui/Makefile.am +++ b/ao-tools/altosui/Makefile.am @@ -66,8 +66,8 @@ JAVA_ICON=$(top_srcdir)/icon/altus-metrum-16x16.jpg WINDOWS_ICON=$(top_srcdir)/icon/altus-metrum.ico # Firmware -FIRMWARE_TD=$(top_srcdir)/src/teledongle-v0.2.ihx -FIRMWARE_TM=$(top_srcdir)/src/telemetrum-v1.0.ihx +FIRMWARE_TD=$(top_srcdir)/src/teledongle-v0.2-$(VERSION).ihx +FIRMWARE_TM=$(top_srcdir)/src/telemetrum-v1.0-$(VERSION).ihx FIRMWARE=$(FIRMWARE_TM) $(FIRMWARE_TD) # Distribution targets @@ -77,7 +77,7 @@ WINDOWS_DIST=Altos-Windows-$(VERSION_DASH).exe FAT_FILES=$(FATJAR) $(FREETTS_CLASS) -LINUX_FILES=$(FAT_FILES) libaltos.so +LINUX_FILES=$(FAT_FILES) libaltos.so $(FIRMWARE) MACOSX_FILES=$(FAT_FILES) libaltos.dylib MACOSX_EXTRA=$(FIRMWARE) @@ -162,4 +162,4 @@ $(MACOSX_DIST): $(MACOSX_FILES) $(MACOSX_EXTRA) $(WINDOWS_DIST): $(WINDOWS_FILES) altos-windows.nsi -rm -f $@ - makensis -Oaltos-windows.log "-XOutFile $@" altos-windows.nsi \ No newline at end of file + makensis -Oaltos-windows.log "-XOutFile $@" "-DVERSION=$(VERSION)" altos-windows.nsi \ No newline at end of file diff --git a/ao-tools/altosui/altos-windows.nsi b/ao-tools/altosui/altos-windows.nsi index 6f38ac0e..c8539a5c 100644 --- a/ao-tools/altosui/altos-windows.nsi +++ b/ao-tools/altosui/altos-windows.nsi @@ -69,8 +69,8 @@ Section "TeleMetrum and TeleDongle Firmware" SetOutPath $INSTDIR - File "../../src/telemetrum-v1.0/telemetrum-v1.0.ihx" - File "../../src/teledongle-v0.2/teledongle-v0.2.ihx" + File "../../src/telemetrum-v1.0/telemetrum-v1.0-${VERSION}.ihx" + File "../../src/teledongle-v0.2/teledongle-v0.2-${VERSION}.ihx" SectionEnd diff --git a/configure.ac b/configure.ac index 19ae0ac8..d376af3f 100644 --- a/configure.ac +++ b/configure.ac @@ -59,7 +59,6 @@ fi AC_PROG_CC AC_PROG_INSTALL AC_PROG_LN_S -AC_PROG_RANLIB AC_PROG_LIBTOOL PKG_PROG_PKG_CONFIG @@ -126,4 +125,5 @@ ao-tools/ao-view/Makefile ao-tools/libaltos/Makefile ao-tools/altosui/Makefile ao-utils/Makefile +src/Version ]) diff --git a/src/Makefile b/src/Makefile index 24f562e1..95d24425 100644 --- a/src/Makefile +++ b/src/Makefile @@ -4,6 +4,8 @@ # CC=sdcc +include Version + SUBDIRS=telemetrum-v1.0 teledongle-v0.2 telemetrum-v0.1-sky telemetrum-v0.1-sirf teledongle-v0.1 tidongle test all: all-recursive diff --git a/src/Makefile.proto b/src/Makefile.proto index 59a3b8a6..b23eb257 100644 --- a/src/Makefile.proto +++ b/src/Makefile.proto @@ -10,7 +10,7 @@ vpath ao-make-product.5c .. CC=sdcc ifndef VERSION -VERSION=$(shell git describe) +include ../Version endif CFLAGS=--model-small --debug --opt-code-speed @@ -214,11 +214,9 @@ all: ../$(PROG) ../altitude.h: make-altitude nickle $< > $@ -ao_product.h: ao-make-product.5c always +ao_product.h: ao-make-product.5c ../Version $(call quiet,NICKLE,$<) $< -m altusmetrum.org -i $(IDPRODUCT) -p $(PRODUCT) -v $(VERSION) > $@ -always: - ao_product.rel: ao_product.c ao_product.h $(call quiet,CC) -c $(CFLAGS) -D PRODUCT_DEFS='\"ao_product.h\"' -o$@ $< diff --git a/src/Version.in b/src/Version.in new file mode 100644 index 00000000..aff9490b --- /dev/null +++ b/src/Version.in @@ -0,0 +1 @@ +VERSION=@VERSION@ diff --git a/src/teledongle-v0.1/.gitignore b/src/teledongle-v0.1/.gitignore index 96c802bd..9826814b 100644 --- a/src/teledongle-v0.1/.gitignore +++ b/src/teledongle-v0.1/.gitignore @@ -1,2 +1,2 @@ -teledongle-v0.1 +teledongle-v0.1* ao_product.h diff --git a/src/teledongle-v0.1/Makefile.defs b/src/teledongle-v0.1/Makefile.defs index be7741d8..ceb80b7a 100644 --- a/src/teledongle-v0.1/Makefile.defs +++ b/src/teledongle-v0.1/Makefile.defs @@ -1,4 +1,4 @@ -PROG = teledongle-v0.1.ihx +PROG = teledongle-v0.1-$(VERSION).ihx SRC = \ $(TD_SRC) \ diff --git a/src/teledongle-v0.2/.gitignore b/src/teledongle-v0.2/.gitignore index af79a766..f6ea8c6c 100644 --- a/src/teledongle-v0.2/.gitignore +++ b/src/teledongle-v0.2/.gitignore @@ -1,2 +1,2 @@ -teledongle-v0.2 +teledongle-v0.2* ao_product.h diff --git a/src/teledongle-v0.2/Makefile.defs b/src/teledongle-v0.2/Makefile.defs index cbec7805..ea9713b6 100644 --- a/src/teledongle-v0.2/Makefile.defs +++ b/src/teledongle-v0.2/Makefile.defs @@ -1,4 +1,4 @@ -PROG = teledongle-v0.2.ihx +PROG = teledongle-v0.2-$(VERSION).ihx SRC = \ $(TD_SRC) \ diff --git a/src/telemetrum-v0.1-sirf/.gitignore b/src/telemetrum-v0.1-sirf/.gitignore index 6d584f36..7698f5aa 100644 --- a/src/telemetrum-v0.1-sirf/.gitignore +++ b/src/telemetrum-v0.1-sirf/.gitignore @@ -1,2 +1,2 @@ -telemetrum-v0.1-sirf +telemetrum-v0.1-sirf* ao_product.h diff --git a/src/telemetrum-v0.1-sirf/Makefile.defs b/src/telemetrum-v0.1-sirf/Makefile.defs index 2ce6e6ed..a7310fbc 100644 --- a/src/telemetrum-v0.1-sirf/Makefile.defs +++ b/src/telemetrum-v0.1-sirf/Makefile.defs @@ -1,4 +1,4 @@ -PROG = telemetrum-v0.1-sirf.ihx +PROG = telemetrum-v0.1-sirf-$(VERSION).ihx SRC = \ $(TM_BASE_SRC) \ diff --git a/src/telemetrum-v0.1-sky/.gitignore b/src/telemetrum-v0.1-sky/.gitignore index 5a9fafb5..d25d7ad9 100644 --- a/src/telemetrum-v0.1-sky/.gitignore +++ b/src/telemetrum-v0.1-sky/.gitignore @@ -1,2 +1,2 @@ -telemetrum-v0.1-sky +telemetrum-v0.1-sky* ao_product.h diff --git a/src/telemetrum-v0.1-sky/Makefile.defs b/src/telemetrum-v0.1-sky/Makefile.defs index 098ac547..000287ba 100644 --- a/src/telemetrum-v0.1-sky/Makefile.defs +++ b/src/telemetrum-v0.1-sky/Makefile.defs @@ -1,4 +1,4 @@ -PROG = telemetrum-v0.1-sky.ihx +PROG = telemetrum-v0.1-sky-$(VERSION).ihx SRC = \ $(TM_BASE_SRC) \ diff --git a/src/telemetrum-v1.0/.gitignore b/src/telemetrum-v1.0/.gitignore index 76228093..c2212151 100644 --- a/src/telemetrum-v1.0/.gitignore +++ b/src/telemetrum-v1.0/.gitignore @@ -1,2 +1,2 @@ -telemetrum-v0.2 +telemetrum-* ao_product.h diff --git a/src/telemetrum-v1.0/Makefile.defs b/src/telemetrum-v1.0/Makefile.defs index 624ce6e8..010578df 100644 --- a/src/telemetrum-v1.0/Makefile.defs +++ b/src/telemetrum-v1.0/Makefile.defs @@ -1,4 +1,4 @@ -PROG = telemetrum-v1.0.ihx +PROG = telemetrum-v1.0-$(VERSION).ihx SRC = \ $(TM_BASE_SRC) \ diff --git a/src/tidongle/.gitignore b/src/tidongle/.gitignore index 3323f640..3888a0f9 100644 --- a/src/tidongle/.gitignore +++ b/src/tidongle/.gitignore @@ -1,2 +1,2 @@ -tidongle +tidongle* ao_product.h diff --git a/src/tidongle/Makefile.defs b/src/tidongle/Makefile.defs index fdd51732..0e13cb20 100644 --- a/src/tidongle/Makefile.defs +++ b/src/tidongle/Makefile.defs @@ -1,4 +1,4 @@ -PROG = tidongle.ihx +PROG = tidongle-$(VERSION).ihx SRC = \ $(TI_SRC) -- cgit v1.2.3 From 044fd27449c70474f51b99dec25fd23d3c03a559 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 4 Sep 2010 18:20:45 -0700 Subject: altosui: Fix windows installer to ship correct files Was shipping altosui.jar instead of altosui-fat.jar Signed-off-by: Keith Packard --- ao-tools/altosui/.gitignore | 15 ++++++++++----- ao-tools/altosui/Makefile.am | 7 ++++--- ao-tools/altosui/altos-windows.nsi | 6 +++--- ao-tools/libaltos/Makefile.am | 1 + 4 files changed, 18 insertions(+), 11 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/.gitignore b/ao-tools/altosui/.gitignore index 63672058..89be1d53 100644 --- a/ao-tools/altosui/.gitignore +++ b/ao-tools/altosui/.gitignore @@ -1,14 +1,19 @@ windows/ linux/ -darwin/ +macosx/ fat/ Manifest.txt +Manifest-fat.txt libaltosJNI classes altosui -Altos-Linux.tgz -Altos-Mac.zip -Altos-Windows.exe +altosui-test +classaltosui.stamp +Altos-Linux-*.tar.bz2 +Altos-Mac-*.zip +Altos-Windows-*.exe +*.dll +*.dylib +*.so *.jar *.class -altosui diff --git a/ao-tools/altosui/Makefile.am b/ao-tools/altosui/Makefile.am index ed7e2f76..13bceae2 100644 --- a/ao-tools/altosui/Makefile.am +++ b/ao-tools/altosui/Makefile.am @@ -1,4 +1,5 @@ JAVAROOT=classes +AM_JAVACFLAGS=-encoding UTF-8 CLASSPATH_ENV=CLASSPATH="classes/altosui/*:../libaltos/libaltosJNI/*:$(FREETTS)/*:/usr/share/java/*" @@ -77,14 +78,14 @@ WINDOWS_DIST=Altos-Windows-$(VERSION_DASH).exe FAT_FILES=$(FATJAR) $(FREETTS_CLASS) -LINUX_FILES=$(FAT_FILES) libaltos.so $(FIRMWARE) +LINUX_FILES=$(FAT_FILES) libaltos.so $(FIRMWARE) altosui-fat MACOSX_FILES=$(FAT_FILES) libaltos.dylib MACOSX_EXTRA=$(FIRMWARE) WINDOWS_FILES=$(FAT_FILES) altos.dll $(top_srcdir)/telemetrum.inf $(WINDOWS_ICON) -all-local: classes/altosui $(JAR) $(FATJAR) +all-local: classes/altosui $(JAR) $(FATJAR) altosui altosui-test clean-local: -rm -rf classes/altosui $(JAR) $(FATJAR) \ @@ -139,7 +140,7 @@ $(LIBALTOS): -rm -f "$@" $(LN_S) ../libaltos/"$@" . -$(FREETTS_CLASS): Makefile +$(FREETTS_CLASS): -rm -f "$@" $(LN_S) "$(FREETTS)"/"$@" . diff --git a/ao-tools/altosui/altos-windows.nsi b/ao-tools/altosui/altos-windows.nsi index c8539a5c..6ebec214 100644 --- a/ao-tools/altosui/altos-windows.nsi +++ b/ao-tools/altosui/altos-windows.nsi @@ -45,7 +45,7 @@ SectionEnd Section "AltosUI Application" SetOutPath $INSTDIR - File "altosui.jar" + File "altosui-fat.jar" File "cmudict04.jar" File "cmulex.jar" File "cmu_time_awb.jar" @@ -58,11 +58,11 @@ Section "AltosUI Application" File "../../icon/*.ico" - CreateShortCut "$SMPROGRAMS\AltusMetrum.lnk" "$INSTDIR\altosui.jar" "" "$INSTDIR\altus-metrum.ico" + CreateShortCut "$SMPROGRAMS\AltusMetrum.lnk" "$INSTDIR\altosui-fat.jar" "" "$INSTDIR\altus-metrum.ico" SectionEnd Section "AltosUI Desktop Shortcut" - CreateShortCut "$DESKTOP\AltusMetrum.lnk" "$INSTDIR\altosui.jar" "" "$INSTDIR\altus-metrum.ico" + CreateShortCut "$DESKTOP\AltusMetrum.lnk" "$INSTDIR\altosui-fat.jar" "" "$INSTDIR\altus-metrum.ico" SectionEnd Section "TeleMetrum and TeleDongle Firmware" diff --git a/ao-tools/libaltos/Makefile.am b/ao-tools/libaltos/Makefile.am index 2f1d6fca..4d29d80e 100644 --- a/ao-tools/libaltos/Makefile.am +++ b/ao-tools/libaltos/Makefile.am @@ -1,5 +1,6 @@ JAVAC=javac AM_CFLAGS="-I$(JVM_INCLUDE)" +AM_JAVACFLAGS=-encoding UTF-8 lib_LTLIBRARIES=libaltos.la -- cgit v1.2.3 From 828e9e4c68e3ac90b6ba2e9fd5f131a9975f7e4a Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 4 Sep 2010 18:39:58 -0700 Subject: altosui: Fix up Mac OSX .zip file Must contain 'altosui.jar' instead of altosui-fat.jar. Also, was using 'cp -a' instead of 'cp -p' which made files represented by symlinks not end up in the archive. Signed-off-by: Keith Packard --- ao-tools/altosui/Makefile.am | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/Makefile.am b/ao-tools/altosui/Makefile.am index 13bceae2..65a3cf9a 100644 --- a/ao-tools/altosui/Makefile.am +++ b/ao-tools/altosui/Makefile.am @@ -157,8 +157,9 @@ $(MACOSX_DIST): $(MACOSX_FILES) $(MACOSX_EXTRA) mkdir macosx cp -a AltosUI.app macosx/ mkdir -p macosx/AltOS macosx/AltosUI.app/Contents/Resources/Java - cp -a $(MACOSX_FILES) macosx/AltosUI.app/Contents/Resources/Java - cp -a $(MACOSX_EXTRA) macosx/AltOS + cp -p $(FATJAR) macosx/AltosUI.app/Contents/Resources/Java/altosui.jar + cp -p $(FREETTS_CLASS) libaltos.dylib macosx/AltosUI.app/Contents/Resources/Java + cp -p $(MACOSX_EXTRA) macosx/AltOS cd macosx && zip -r ../$@ AltosUI.app AltOS $(WINDOWS_DIST): $(WINDOWS_FILES) altos-windows.nsi -- cgit v1.2.3 From c3a17c71a45207dd715d537704f161de9219f0d7 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 4 Sep 2010 18:49:22 -0700 Subject: altosui: Fix linux fat distribution Again, use 'cp -p' instead of 'cp -a' to get files into the archive instead of links. Also, make the shell script 'altosui' instead of 'altosui-fat'. Signed-off-by: Keith Packard --- ao-tools/altosui/Makefile.am | 9 ++++++--- ao-tools/altosui/altosui-fat | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/Makefile.am b/ao-tools/altosui/Makefile.am index 65a3cf9a..bc8dbc0d 100644 --- a/ao-tools/altosui/Makefile.am +++ b/ao-tools/altosui/Makefile.am @@ -78,7 +78,8 @@ WINDOWS_DIST=Altos-Windows-$(VERSION_DASH).exe FAT_FILES=$(FATJAR) $(FREETTS_CLASS) -LINUX_FILES=$(FAT_FILES) libaltos.so $(FIRMWARE) altosui-fat +LINUX_FILES=$(FAT_FILES) libaltos.so $(FIRMWARE) +LINUX_EXTRA=altosui-fat MACOSX_FILES=$(FAT_FILES) libaltos.dylib MACOSX_EXTRA=$(FIRMWARE) @@ -144,11 +145,13 @@ $(FREETTS_CLASS): -rm -f "$@" $(LN_S) "$(FREETTS)"/"$@" . -$(LINUX_DIST): $(LINUX_FILES) +$(LINUX_DIST): $(LINUX_FILES) $(LINUX_EXTRA) -rm -f $@ -rm -rf linux mkdir -p linux/AltOS - cp -a $(LINUX_FILES) linux/AltOS + cp -p $(LINUX_FILES) linux/AltOS + cp -p altosui-fat linux/AltOS/altosui + chmod +x linux/AltOS/altosui tar cjf $@ -C linux AltOS $(MACOSX_DIST): $(MACOSX_FILES) $(MACOSX_EXTRA) diff --git a/ao-tools/altosui/altosui-fat b/ao-tools/altosui/altosui-fat index a95b78b8..9e5a8f15 100755 --- a/ao-tools/altosui/altosui-fat +++ b/ao-tools/altosui/altosui-fat @@ -1,4 +1,4 @@ #!/bin/sh me=`which "$0"` dir=`dirname "$me"` -exec java -cp "$dir/*" -Djava.library.path="$dir" -jar "$dir"/altosui.jar +exec java -cp "$dir/*" -Djava.library.path="$dir" -jar "$dir"/altosui-fat.jar -- cgit v1.2.3 From eb0e7a59f0806734a4c959a3ce7c57f71cbe3986 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 5 Sep 2010 00:57:38 -0700 Subject: altosui: Return AO_LOG_INVALID instead of exception for eeprom files When an eeprom file contains an invalid line, just return AO_LOG_INVALID instead of throwing an exception. This allows us to replay and parse files with extraneous serial communication. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosEepromRecord.java | 99 ++++++++++++++++++--------------- 1 file changed, 54 insertions(+), 45 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosEepromRecord.java b/ao-tools/altosui/AltosEepromRecord.java index 4d0817ab..95cbe015 100644 --- a/ao-tools/altosui/AltosEepromRecord.java +++ b/ao-tools/altosui/AltosEepromRecord.java @@ -47,7 +47,7 @@ public class AltosEepromRecord { public String data; public boolean tick_valid; - public AltosEepromRecord (String line) throws ParseException { + public AltosEepromRecord (String line) { tick_valid = false; tick = 0; a = 0; @@ -55,52 +55,61 @@ public class AltosEepromRecord { data = null; if (line == null) { cmd = Altos.AO_LOG_INVALID; + data = ""; } else { - String[] tokens = line.split("\\s+"); + try { + String[] tokens = line.split("\\s+"); - if (tokens[0].length() == 1) { - if (tokens.length != 4) - throw new ParseException(line, 0); - cmd = tokens[0].codePointAt(0); - tick = Integer.parseInt(tokens[1],16); - tick_valid = true; - a = Integer.parseInt(tokens[2],16); - b = Integer.parseInt(tokens[3],16); - } else if (tokens[0].equals("Config") && tokens[1].equals("version:")) { - cmd = Altos.AO_LOG_CONFIG_VERSION; - data = tokens[2]; - } else if (tokens[0].equals("Main") && tokens[1].equals("deploy:")) { - cmd = Altos.AO_LOG_MAIN_DEPLOY; - a = Integer.parseInt(tokens[2]); - } else if (tokens[0].equals("Apogee") && tokens[1].equals("delay:")) { - cmd = Altos.AO_LOG_APOGEE_DELAY; - a = Integer.parseInt(tokens[2]); - } else if (tokens[0].equals("Radio") && tokens[1].equals("channel:")) { - cmd = Altos.AO_LOG_RADIO_CHANNEL; - a = Integer.parseInt(tokens[2]); - } else if (tokens[0].equals("Callsign:")) { - cmd = Altos.AO_LOG_CALLSIGN; - data = tokens[1].replaceAll("\"",""); - } else if (tokens[0].equals("Accel") && tokens[1].equals("cal")) { - cmd = Altos.AO_LOG_ACCEL_CAL; - a = Integer.parseInt(tokens[3]); - b = Integer.parseInt(tokens[5]); - } else if (tokens[0].equals("Radio") && tokens[1].equals("cal:")) { - cmd = Altos.AO_LOG_RADIO_CAL; - a = Integer.parseInt(tokens[2]); - } else if (tokens[0].equals("manufacturer")) { - cmd = Altos.AO_LOG_MANUFACTURER; - data = tokens[1]; - } else if (tokens[0].equals("product")) { - cmd = Altos.AO_LOG_PRODUCT; - data = tokens[1]; - } else if (tokens[0].equals("serial-number")) { - cmd = Altos.AO_LOG_SERIAL_NUMBER; - a = Integer.parseInt(tokens[1]); - } else if (tokens[0].equals("software-version")) { - cmd = Altos.AO_LOG_SOFTWARE_VERSION; - data = tokens[1]; - } else { + if (tokens[0].length() == 1) { + if (tokens.length != 4) { + cmd = Altos.AO_LOG_INVALID; + data = line; + } else { + cmd = tokens[0].codePointAt(0); + tick = Integer.parseInt(tokens[1],16); + tick_valid = true; + a = Integer.parseInt(tokens[2],16); + b = Integer.parseInt(tokens[3],16); + } + } else if (tokens[0].equals("Config") && tokens[1].equals("version:")) { + cmd = Altos.AO_LOG_CONFIG_VERSION; + data = tokens[2]; + } else if (tokens[0].equals("Main") && tokens[1].equals("deploy:")) { + cmd = Altos.AO_LOG_MAIN_DEPLOY; + a = Integer.parseInt(tokens[2]); + } else if (tokens[0].equals("Apogee") && tokens[1].equals("delay:")) { + cmd = Altos.AO_LOG_APOGEE_DELAY; + a = Integer.parseInt(tokens[2]); + } else if (tokens[0].equals("Radio") && tokens[1].equals("channel:")) { + cmd = Altos.AO_LOG_RADIO_CHANNEL; + a = Integer.parseInt(tokens[2]); + } else if (tokens[0].equals("Callsign:")) { + cmd = Altos.AO_LOG_CALLSIGN; + data = tokens[1].replaceAll("\"",""); + } else if (tokens[0].equals("Accel") && tokens[1].equals("cal")) { + cmd = Altos.AO_LOG_ACCEL_CAL; + a = Integer.parseInt(tokens[3]); + b = Integer.parseInt(tokens[5]); + } else if (tokens[0].equals("Radio") && tokens[1].equals("cal:")) { + cmd = Altos.AO_LOG_RADIO_CAL; + a = Integer.parseInt(tokens[2]); + } else if (tokens[0].equals("manufacturer")) { + cmd = Altos.AO_LOG_MANUFACTURER; + data = tokens[1]; + } else if (tokens[0].equals("product")) { + cmd = Altos.AO_LOG_PRODUCT; + data = tokens[1]; + } else if (tokens[0].equals("serial-number")) { + cmd = Altos.AO_LOG_SERIAL_NUMBER; + a = Integer.parseInt(tokens[1]); + } else if (tokens[0].equals("software-version")) { + cmd = Altos.AO_LOG_SOFTWARE_VERSION; + data = tokens[1]; + } else { + cmd = Altos.AO_LOG_INVALID; + data = line; + } + } catch (NumberFormatException ne) { cmd = Altos.AO_LOG_INVALID; data = line; } -- cgit v1.2.3 From b2aa689bf3d61e4a3ebe7c828162d1be20aad0f6 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 5 Sep 2010 00:59:54 -0700 Subject: altosui: Remove debugging printf from AltosEepromReader These were in place while validing the GPS data reconstruction code that handles eeprom files missing the first GPS date line due to the record overwriting bug in old firmware versions. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosEepromReader.java | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosEepromReader.java b/ao-tools/altosui/AltosEepromReader.java index 0705d44e..e2a780ac 100644 --- a/ao-tools/altosui/AltosEepromReader.java +++ b/ao-tools/altosui/AltosEepromReader.java @@ -177,12 +177,6 @@ public class AltosEepromReader extends AltosReader { state.gps.date_valid = (flags & Altos.AO_GPS_DATE_VALID) != 0; state.gps.nsat = (flags & Altos.AO_GPS_NUM_SAT_MASK) >> Altos.AO_GPS_NUM_SAT_SHIFT; - System.out.printf("GPS %2d:%02d:%02d%s%s%s %d\n", - state.gps.hour, state.gps.minute, state.gps.second, - state.gps.connected ? " connected" : "", - state.gps.locked ? " locked" : "", - state.gps.date_valid ? " date_valid" : "", - state.gps.nsat); break; case Altos.AO_LOG_GPS_LAT: int lat32 = record.a | (record.b << 16); @@ -306,10 +300,6 @@ public class AltosEepromReader extends AltosReader { int new_hours = (new_minutes / 60); int new_hour = (new_hours % 24); - System.out.printf("Synthesizing time good %2d:%02d:%02d bad %2d:%02d:%02d\n", - hour, minute, second, - new_hour, new_minute, new_second); - bad.a = new_hour + (new_minute << 8); bad.b = new_second + (flags << 8); } @@ -365,13 +355,9 @@ public class AltosEepromReader extends AltosReader { if (record.cmd == Altos.AO_LOG_GPS_TIME) { last_gps_time = record; if (missing_time) { - System.out.printf("Going back to clean up broken GPS time records\n"); Iterator iterator = records.iterator(); while (iterator.hasNext()) { AltosOrderedRecord old = iterator.next(); - if (old.cmd == Altos.AO_LOG_GPS_TIME) { - System.out.printf("Old time record %d, %d\n", old.a, old.b); - } if (old.cmd == Altos.AO_LOG_GPS_TIME && old.a == -1 && old.b == -1) { @@ -389,10 +375,9 @@ public class AltosEepromReader extends AltosReader { -1, -1, index-1); if (last_gps_time != null) update_time(last_gps_time, add_gps_time); - else { - System.out.printf("early GPS missing time\n"); + else missing_time = true; - } + records.add(add_gps_time); record.index = index++; } -- cgit v1.2.3 From 2d58f319a7c1a6a8ccc6a539722009996ba886ab Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 5 Sep 2010 01:01:10 -0700 Subject: altosui: Eeprom files contain only one date; save it. While reading eeprom files, the GPS record is reconstructed each time the system sees the first GPS log item (the time field), but as the date isn't repeated, we need to copy it from the old GPS data record. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosEepromReader.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosEepromReader.java b/ao-tools/altosui/AltosEepromReader.java index e2a780ac..ac54ff44 100644 --- a/ao-tools/altosui/AltosEepromReader.java +++ b/ao-tools/altosui/AltosEepromReader.java @@ -116,7 +116,7 @@ public class AltosEepromReader extends AltosReader { if (last_reported) return null; last_reported = true; - return state; + return new AltosRecord(state); } record = record_iterator.next(); @@ -167,7 +167,15 @@ public class AltosEepromReader extends AltosReader { break; case Altos.AO_LOG_GPS_TIME: gps_tick = state.tick; + AltosGPS old = state.gps; state.gps = new AltosGPS(); + + /* GPS date doesn't get repeated through the file */ + if (old != null) { + state.gps.year = old.year; + state.gps.month = old.month; + state.gps.day = old.day; + } state.gps.hour = (record.a & 0xff); state.gps.minute = (record.a >> 8); state.gps.second = (record.b & 0xff); @@ -197,7 +205,7 @@ public class AltosEepromReader extends AltosReader { } break; case Altos.AO_LOG_GPS_DATE: - state.gps.year = record.a & 0xff; + state.gps.year = (record.a & 0xff) + 2000; state.gps.month = record.a >> 8; state.gps.day = record.b & 0xff; break; @@ -334,6 +342,8 @@ public class AltosEepromReader extends AltosReader { AltosOrderedRecord record = new AltosOrderedRecord(line, index++, tick); if (record == null) break; + if (record.cmd == Altos.AO_LOG_INVALID) + continue; tick = record.tick; if (!saw_boost && record.cmd == Altos.AO_LOG_STATE && record.a >= Altos.ao_flight_boost) -- cgit v1.2.3 From 3d99584fcfe43b22e8581874e0ac77ce3d635d48 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 5 Sep 2010 01:03:18 -0700 Subject: altosui: Add elevation and range data to main display Reported by voice, it's useful to see these on the display as well. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosUI.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosUI.java b/ao-tools/altosui/AltosUI.java index 37625e8e..6a1814ff 100644 --- a/ao-tools/altosui/AltosUI.java +++ b/ao-tools/altosui/AltosUI.java @@ -231,11 +231,19 @@ public class AltosUI extends JFrame { if (state.npad > 0) { if (state.from_pad != null) { - info_add_row(1, "Distance from pad", "%6.0f m", state.from_pad.distance); - info_add_row(1, "Direction from pad", "%6.0f°", state.from_pad.bearing); + info_add_row(1, "Distance from pad", "%6d m", + (int) (state.from_pad.distance + 0.5)); + info_add_row(1, "Direction from pad", "%6d°", + (int) (state.from_pad.bearing + 0.5)); + info_add_row(1, "Elevation from pad", "%6d°", + (int) (state.elevation + 0.5)); + info_add_row(1, "Range from pad", "%6d m", + (int) (state.range + 0.5)); } else { info_add_row(1, "Distance from pad", "unknown"); info_add_row(1, "Direction from pad", "unknown"); + info_add_row(1, "Elevation from pad", "unknown"); + info_add_row(1, "Range from pad", "unknown"); } info_add_deg(1, "Pad latitude", state.pad_lat, 'N', 'S'); info_add_deg(1, "Pad longitude", state.pad_lon, 'E', 'W'); -- cgit v1.2.3 From 6205547ec7191aab0259a8449520e966a96129e6 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 5 Sep 2010 01:08:50 -0700 Subject: altosui: When replay thread is interrupted, don't make final report Normally, the replay process makes one final report after the file has been parsed. However, if the reading process is interrupted to display something else, this report is just annoying, so don't make it. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosUI.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosUI.java b/ao-tools/altosui/AltosUI.java index 6a1814ff..49153766 100644 --- a/ao-tools/altosui/AltosUI.java +++ b/ao-tools/altosui/AltosUI.java @@ -384,11 +384,12 @@ public class AltosUI extends JFrame { AltosRecord read() throws InterruptedException, ParseException, AltosCRCException, IOException { return null; } - void close() { } + void close(boolean interrupted) { } void update(AltosState state) throws InterruptedException { } public void run() { + boolean interrupted = false; String line; AltosState state = null; AltosState old_state = null; @@ -418,14 +419,18 @@ public class AltosUI extends JFrame { } } } catch (InterruptedException ee) { + interrupted = true; } catch (IOException ie) { JOptionPane.showMessageDialog(AltosUI.this, String.format("Error reading from \"%s\"", name), "Telemetry Read Error", JOptionPane.ERROR_MESSAGE); } finally { - close(); + close(interrupted); idle_thread.interrupt(); + try { + idle_thread.join(); + } catch (InterruptedException ie) {} } } @@ -446,7 +451,7 @@ public class AltosUI extends JFrame { return new AltosTelemetry(l.line); } - void close() { + void close(boolean interrupted) { serial.close(); serial.remove_monitor(telem); } @@ -530,8 +535,9 @@ public class AltosUI extends JFrame { return null; } - public void close () { - report(); + public void close (boolean interrupted) { + if (!interrupted) + report(); } public ReplayThread(AltosReader in_reader, String in_name) { -- cgit v1.2.3 From 410ba89eef9c9817eef81b702966cb88820ff7c4 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 5 Sep 2010 01:13:01 -0700 Subject: altosui: Start idle thread after the rocket leaves the pad This makes the first altitude report time consistently 10 seconds after launch, instead of some random time depending on when the rocket launched relative to the time the device connection was made. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosUI.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosUI.java b/ao-tools/altosui/AltosUI.java index 49153766..fbce5e14 100644 --- a/ao-tools/altosui/AltosUI.java +++ b/ao-tools/altosui/AltosUI.java @@ -277,6 +277,7 @@ public class AltosUI extends JFrame { class IdleThread extends Thread { + boolean started; private AltosState state; int reported_landing; @@ -346,6 +347,10 @@ public class AltosUI extends JFrame { public void notice(AltosState new_state) { AltosState old_state = state; state = new_state; + if (!started && state.state > Altos.ao_flight_pad) { + started = true; + start(); + } if (old_state != null && old_state.state != state.state) report(false); } @@ -398,7 +403,6 @@ public class AltosUI extends JFrame { info_reset(); info_finish(); - idle_thread.start(); try { for (;;) { try { -- cgit v1.2.3 From 4dec5c36702d76dc95beada7c1d3222a638a2cbb Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 5 Sep 2010 01:19:11 -0700 Subject: altosui: Add AltosVoice.drain() to wait for queued speech to finish drain() blocks until all pending phrases have been processed, allowing the UI code to avoid pending data that will end up stale by the time it is emitted. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosVoice.java | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosVoice.java b/ao-tools/altosui/AltosVoice.java index ebe9d5a8..ac13ee14 100644 --- a/ao-tools/altosui/AltosVoice.java +++ b/ao-tools/altosui/AltosVoice.java @@ -27,6 +27,7 @@ public class AltosVoice implements Runnable { Voice voice; LinkedBlockingQueue phrases; Thread thread; + boolean busy; final static String voice_name = "kevin16"; @@ -35,15 +36,30 @@ public class AltosVoice implements Runnable { for (;;) { String s = phrases.take(); voice.speak(s); + synchronized(this) { + if (phrases.isEmpty()) { + busy = false; + notifyAll(); + } + } } } catch (InterruptedException e) { } } + public synchronized void drain() throws InterruptedException { + while (busy) + wait(); + } + public void speak_always(String s) { try { - if (voice != null) - phrases.put(s); + if (voice != null) { + synchronized(this) { + busy = true; + phrases.put(s); + } + } } catch (InterruptedException e) { } } @@ -58,6 +74,7 @@ public class AltosVoice implements Runnable { } public AltosVoice () { + busy = false; voice_manager = VoiceManager.getInstance(); voice = voice_manager.getVoice(voice_name); if (voice != null) { -- cgit v1.2.3 From 9941b05a1d03dafd6cd899b5fe999ed769efb1d6 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 5 Sep 2010 01:21:14 -0700 Subject: altosui: Prevent voice altitude data from queueing up When flight status changes rapidly, the queue of voice data can get quite long. This change does two things -- first, it remembers when the altitude reporting happens due to flight events and delays the periodic reporting until a suitable time after that, second it ensures that the voice data has all been delivered before generating a new altitude report. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosUI.java | 58 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 49 insertions(+), 9 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosUI.java b/ao-tools/altosui/AltosUI.java index fbce5e14..3aaeb888 100644 --- a/ao-tools/altosui/AltosUI.java +++ b/ao-tools/altosui/AltosUI.java @@ -280,6 +280,8 @@ public class AltosUI extends JFrame { boolean started; private AltosState state; int reported_landing; + int report_interval; + long report_time; public synchronized void report(boolean last) { if (state == null) @@ -331,51 +333,88 @@ public class AltosUI extends JFrame { } } + long now () { + return System.currentTimeMillis(); + } + + void set_report_time() { + report_time = now() + report_interval; + } + public void run () { reported_landing = 0; state = null; + report_interval = 10000; try { for (;;) { - Thread.sleep(20000); + set_report_time(); + for (;;) { + voice.drain(); + synchronized (this) { + long sleep_time = report_time - now(); + if (sleep_time <= 0) + break; + wait(sleep_time); + } + } report(false); } } catch (InterruptedException ie) { + try { + voice.drain(); + } catch (InterruptedException iie) { } } } - public void notice(AltosState new_state) { + public synchronized void notice(AltosState new_state, boolean spoken) { AltosState old_state = state; state = new_state; if (!started && state.state > Altos.ao_flight_pad) { started = true; start(); } - if (old_state != null && old_state.state != state.state) - report(false); + + if (state.state < Altos.ao_flight_drogue) + report_interval = 10000; + else + report_interval = 20000; + if (old_state != null && old_state.state != state.state) { + report_time = now(); + this.notify(); + } else if (spoken) + set_report_time(); } } - private void tell(AltosState state, AltosState old_state) { + private boolean tell(AltosState state, AltosState old_state) { + boolean ret = false; if (old_state == null || old_state.state != state.state) { voice.speak(state.data.state()); if ((old_state == null || old_state.state <= Altos.ao_flight_boost) && state.state > Altos.ao_flight_boost) { voice.speak("max speed: %d meters per second.", (int) (state.max_speed + 0.5)); + ret = true; } else if ((old_state == null || old_state.state < Altos.ao_flight_drogue) && state.state >= Altos.ao_flight_drogue) { voice.speak("max height: %d meters.", (int) (state.max_height + 0.5)); + ret = true; } } if (old_state == null || old_state.gps_ready != state.gps_ready) { - if (state.gps_ready) + if (state.gps_ready) { voice.speak("GPS ready"); - else if (old_state != null) + ret = true; + } + else if (old_state != null) { voice.speak("GPS lost"); + ret = true; + } } old_state = state; + return ret; } class DisplayThread extends Thread { @@ -398,6 +437,7 @@ public class AltosUI extends JFrame { String line; AltosState state = null; AltosState old_state = null; + boolean told; idle_thread = new IdleThread(); @@ -413,8 +453,8 @@ public class AltosUI extends JFrame { state = new AltosState(record, state); update(state); show(state, crc_errors); - tell(state, old_state); - idle_thread.notice(state); + told = tell(state, old_state); + idle_thread.notice(state, told); } catch (ParseException pp) { System.out.printf("Parse error: %d \"%s\"\n", pp.getErrorOffset(), pp.getMessage()); } catch (AltosCRCException ce) { -- cgit v1.2.3 From 38e1d87c8d449866faac026577fefa9a118428cb Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 5 Sep 2010 01:23:53 -0700 Subject: altosui: Use local .class files in the classpath This ensures that compiling only a few changed files will locate the old .class files instead of using a stale .jar file. --- ao-tools/altosui/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/Makefile.am b/ao-tools/altosui/Makefile.am index bc8dbc0d..98482823 100644 --- a/ao-tools/altosui/Makefile.am +++ b/ao-tools/altosui/Makefile.am @@ -1,7 +1,7 @@ JAVAROOT=classes AM_JAVACFLAGS=-encoding UTF-8 -CLASSPATH_ENV=CLASSPATH="classes/altosui/*:../libaltos/libaltosJNI/*:$(FREETTS)/*:/usr/share/java/*" +CLASSPATH_ENV=CLASSPATH=".:classes:../libaltos:$(FREETTS)/*:/usr/share/java/*" altosui_JAVA = \ AltosChannelMenu.java \ -- cgit v1.2.3 From 6c653a4cba5fef8d49261cf1c024f3e86e9058c6 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 5 Sep 2010 01:52:36 -0700 Subject: altosui: Record flight number when scanning file, not when running The very first record in the eeprom is the flight number, but it is time-stamped with the 'boost' time, and so it gets sorted until much later, delaying the return of data until the rocket enters boost mode. This drops all of the nice pad GPS and state date on the floor. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosEepromReader.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosEepromReader.java b/ao-tools/altosui/AltosEepromReader.java index ac54ff44..86bbaee0 100644 --- a/ao-tools/altosui/AltosEepromReader.java +++ b/ao-tools/altosui/AltosEepromReader.java @@ -130,9 +130,7 @@ public class AltosEepromReader extends AltosReader { state.tick = record.tick; switch (record.cmd) { case Altos.AO_LOG_FLIGHT: - state.ground_accel = record.a; - state.flight = record.b; - seen |= seen_flight; + /* recorded when first read from the file */ break; case Altos.AO_LOG_SENSOR: state.accel = record.a; @@ -351,6 +349,11 @@ public class AltosEepromReader extends AltosReader { saw_boost = true; boost_tick = tick; } + if (record.cmd == Altos.AO_LOG_FLIGHT) { + state.ground_accel = record.a; + state.flight = record.b; + seen |= seen_flight; + } /* Two firmware bugs caused the loss of some GPS data. * The flight date would never be recorded, and often -- cgit v1.2.3 From b61fec225ada6a9e252e4c7920101ee18c77cbdc Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 5 Sep 2010 01:55:56 -0700 Subject: altosui: eeprom files place 'boost' time in the flight number record. Instead of looking for the first state change record, use the Flight record to get the boost tick. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosEepromReader.java | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/AltosEepromReader.java b/ao-tools/altosui/AltosEepromReader.java index 86bbaee0..cb82f9a9 100644 --- a/ao-tools/altosui/AltosEepromReader.java +++ b/ao-tools/altosui/AltosEepromReader.java @@ -101,8 +101,6 @@ public class AltosEepromReader extends AltosReader { int gps_tick; - boolean saw_boost; - int boost_tick; boolean saw_gps_date; @@ -343,15 +341,10 @@ public class AltosEepromReader extends AltosReader { if (record.cmd == Altos.AO_LOG_INVALID) continue; tick = record.tick; - if (!saw_boost && record.cmd == Altos.AO_LOG_STATE && - record.a >= Altos.ao_flight_boost) - { - saw_boost = true; - boost_tick = tick; - } if (record.cmd == Altos.AO_LOG_FLIGHT) { state.ground_accel = record.a; state.flight = record.b; + boost_tick = tick; seen |= seen_flight; } -- cgit v1.2.3 From 3d49d5f69b41c27003dbc5ccf1899014bd13bd99 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 5 Sep 2010 02:05:06 -0700 Subject: altosui: ensure that 'altosui' script is installed. Pass arguments along. Signed-off-by: Keith Packard --- ao-tools/altosui/Makefile.am | 6 ++++-- ao-tools/altosui/altosui-fat | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/altosui/Makefile.am b/ao-tools/altosui/Makefile.am index 98482823..dd4b31e6 100644 --- a/ao-tools/altosui/Makefile.am +++ b/ao-tools/altosui/Makefile.am @@ -3,6 +3,8 @@ AM_JAVACFLAGS=-encoding UTF-8 CLASSPATH_ENV=CLASSPATH=".:classes:../libaltos:$(FREETTS)/*:/usr/share/java/*" +bin_SCRIPTS=altosui + altosui_JAVA = \ AltosChannelMenu.java \ AltosConfig.java \ @@ -129,12 +131,12 @@ Manifest-fat.txt: altosui: Makefile echo "#!/bin/sh" > $@ - echo 'exec java -cp "$(FREETTS)/*" -Djava.library.path="$(libdir)" -jar "$(altosuidir)/altosui.jar"' >> $@ + echo 'exec java -cp "$(FREETTS)/*" -Djava.library.path="$(libdir)" -jar "$(altosuidir)/altosui.jar" "$$@"' >> $@ chmod +x $@ altosui-test: Makefile echo "#!/bin/sh" > $@ - echo 'exec java -cp "$(FREETTS)/*" -Djava.library.path="../libaltos" -jar altosui.jar' >> $@ + echo 'exec java -cp "$(FREETTS)/*" -Djava.library.path="../libaltos" -jar altosui.jar "$$*"' >> $@ chmod +x $@ $(LIBALTOS): diff --git a/ao-tools/altosui/altosui-fat b/ao-tools/altosui/altosui-fat index 9e5a8f15..95b1c051 100755 --- a/ao-tools/altosui/altosui-fat +++ b/ao-tools/altosui/altosui-fat @@ -1,4 +1,4 @@ #!/bin/sh me=`which "$0"` dir=`dirname "$me"` -exec java -cp "$dir/*" -Djava.library.path="$dir" -jar "$dir"/altosui-fat.jar +exec java -cp "$dir/*" -Djava.library.path="$dir" -jar "$dir"/altosui-fat.jar "$@" -- cgit v1.2.3