From 09e0c304b420a12fa1616005db946523c6e5bef1 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 24 Mar 2013 16:01:08 -0700 Subject: [PATCH 1/1] altosui & altoslib: Move a pile of debug/programming bits to altoslib Prepare to create external Java utilities to flash devices Signed-off-by: Keith Packard --- {altosui => altoslib}/AltosDebug.java | 51 +++++++++++++---------- {altosui => altoslib}/AltosHexfile.java | 2 +- {altosui => altoslib}/AltosRomconfig.java | 3 +- altoslib/Makefile.am | 3 ++ altosui/AltosFlash.java | 3 +- altosui/AltosFlashUI.java | 1 + altosui/AltosRomconfigUI.java | 1 + altosui/Makefile.am | 3 -- 8 files changed, 38 insertions(+), 29 deletions(-) rename {altosui => altoslib}/AltosDebug.java (89%) rename {altosui => altoslib}/AltosHexfile.java (99%) rename {altosui => altoslib}/AltosRomconfig.java (99%) diff --git a/altosui/AltosDebug.java b/altoslib/AltosDebug.java similarity index 89% rename from altosui/AltosDebug.java rename to altoslib/AltosDebug.java index c69369ef..4d8e3ae7 100644 --- a/altosui/AltosDebug.java +++ b/altoslib/AltosDebug.java @@ -15,12 +15,11 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package altosui; +package org.altusmetrum.altoslib_1; import java.io.*; -import org.altusmetrum.altosuilib_1.*; -public class AltosDebug extends AltosSerial { +public class AltosDebug { public static final byte WR_CONFIG = 0x1d; public static final byte RD_CONFIG = 0x24; @@ -53,13 +52,15 @@ public class AltosDebug extends AltosSerial { public static final byte GET_CHIP_ID = 0x68; + AltosLink link; + boolean debug_mode; void ensure_debug_mode() { if (!debug_mode) { - printf("D\n"); + link.printf("D\n"); try { - flush_input(); + link.flush_input(); } catch (InterruptedException ie) { } debug_mode = true; @@ -79,15 +80,19 @@ public class AltosDebug extends AltosSerial { System.out.printf("\n"); } + public void close() { + link.close(); + } + /* * Write target memory */ public void write_memory(int address, byte[] bytes, int start, int len) { ensure_debug_mode(); // dump_memory("write_memory", address, bytes, start, len); - printf("O %x %x\n", len, address); + link.printf("O %x %x\n", len, address); for (int i = 0; i < len; i++) - printf("%02x", bytes[start + i]); + link.printf("%02x", bytes[start + i]); } public void write_memory(int address, byte[] bytes) { @@ -101,21 +106,21 @@ public class AltosDebug extends AltosSerial { throws IOException, InterruptedException { byte[] data = new byte[length]; - flush_input(); + link.flush_input(); ensure_debug_mode(); - printf("I %x %x\n", length, address); + link.printf("I %x %x\n", length, address); int i = 0; int start = 0; while (i < length) { - String line = get_reply().trim(); - if (!Altos.ishex(line) || line.length() % 2 != 0) + String line = link.get_reply().trim(); + if (!AltosLib.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) ((Altos.fromhex(line.charAt(j*2)) << 4) + - Altos.fromhex(line.charAt(j*2+1))); + data[start + j] = (byte) ((AltosLib.fromhex(line.charAt(j*2)) << 4) + + AltosLib.fromhex(line.charAt(j*2+1))); start += this_time; i += this_time; } @@ -134,10 +139,10 @@ public class AltosDebug extends AltosSerial { int this_time = bytes.length - i; if (this_time > 8) this_time = 0; - printf("P"); + link.printf("P"); for (int j = 0; j < this_time; j++) - printf(" %02x", bytes[i+j]); - printf("\n"); + link.printf(" %02x", bytes[i+j]); + link.printf("\n"); i += this_time; } } @@ -153,20 +158,20 @@ public class AltosDebug extends AltosSerial { public byte[] read_bytes(int length) throws IOException, InterruptedException { - flush_input(); + link.flush_input(); ensure_debug_mode(); - printf("G %x\n", length); + link.printf("G %x\n", length); int i = 0; byte[] data = new byte[length]; while (i < length) { - String line = get_reply(); + String line = link.get_reply(); if (line == null) throw new IOException("Timeout in read_bytes"); line = line.trim(); String tokens[] = line.split("\\s+"); for (int j = 0; j < tokens.length; j++) { - if (!Altos.ishex(tokens[j]) || + if (!AltosLib.ishex(tokens[j]) || tokens[j].length() != 2) throw new IOException( String.format @@ -266,10 +271,10 @@ public class AltosDebug extends AltosSerial { * Reset target */ public void reset() { - printf ("R\n"); + link.printf ("R\n"); } - public AltosDebug (AltosDevice in_device) throws FileNotFoundException, AltosSerialInUseException { - super(in_device); + public AltosDebug (AltosLink link) { + this.link = link; } } \ No newline at end of file diff --git a/altosui/AltosHexfile.java b/altoslib/AltosHexfile.java similarity index 99% rename from altosui/AltosHexfile.java rename to altoslib/AltosHexfile.java index 625c5ba1..68f42f14 100644 --- a/altosui/AltosHexfile.java +++ b/altoslib/AltosHexfile.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package altosui; +package org.altusmetrum.altoslib_1; import java.io.*; import java.util.LinkedList; diff --git a/altosui/AltosRomconfig.java b/altoslib/AltosRomconfig.java similarity index 99% rename from altosui/AltosRomconfig.java rename to altoslib/AltosRomconfig.java index 55056b5e..0800a2c4 100644 --- a/altosui/AltosRomconfig.java +++ b/altoslib/AltosRomconfig.java @@ -15,7 +15,8 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package altosui; +package org.altusmetrum.altoslib_1; + import java.io.*; public class AltosRomconfig { diff --git a/altoslib/Makefile.am b/altoslib/Makefile.am index 30a9d954..db0236a1 100644 --- a/altoslib/Makefile.am +++ b/altoslib/Makefile.am @@ -16,6 +16,7 @@ altoslib_JAVA = \ AltosConfigValues.java \ AltosConvert.java \ AltosCRCException.java \ + AltosDebug.java \ AltosEepromChunk.java \ AltosEepromIterable.java \ AltosEepromLog.java \ @@ -30,6 +31,7 @@ altoslib_JAVA = \ AltosGPSQuery.java \ AltosGPSSat.java \ AltosGreatCircle.java \ + AltosHexfile.java \ AltosIdleMonitor.java \ AltosIdleMonitorListener.java \ AltosIgnite.java \ @@ -53,6 +55,7 @@ altoslib_JAVA = \ AltosRecordTM.java \ AltosRecordMM.java \ AltosReplayReader.java \ + AltosRomconfig.java \ AltosSensorMM.java \ AltosSensorTM.java \ AltosState.java \ diff --git a/altosui/AltosFlash.java b/altosui/AltosFlash.java index 239d4dd7..b409a611 100644 --- a/altosui/AltosFlash.java +++ b/altosui/AltosFlash.java @@ -20,6 +20,7 @@ package altosui; import java.awt.event.*; import javax.swing.*; import java.io.*; +import org.altusmetrum.altoslib_1.*; import org.altusmetrum.altosuilib_1.*; public class AltosFlash { @@ -362,7 +363,7 @@ public class AltosFlash { file = in_file; debug_dongle = in_debug_dongle; if (debug_dongle != null) - debug = new AltosDebug(in_debug_dongle); + debug = new AltosDebug(new AltosSerial(in_debug_dongle)); input = new FileInputStream(file); image = new AltosHexfile(input); if (debug != null && !debug.check_connection()) { diff --git a/altosui/AltosFlashUI.java b/altosui/AltosFlashUI.java index f26a3916..e5176278 100644 --- a/altosui/AltosFlashUI.java +++ b/altosui/AltosFlashUI.java @@ -23,6 +23,7 @@ import javax.swing.*; import javax.swing.filechooser.FileNameExtensionFilter; import java.io.*; import java.util.concurrent.*; +import org.altusmetrum.altoslib_1.*; import org.altusmetrum.altosuilib_1.*; public class AltosFlashUI diff --git a/altosui/AltosRomconfigUI.java b/altosui/AltosRomconfigUI.java index cf4658af..909e72a0 100644 --- a/altosui/AltosRomconfigUI.java +++ b/altosui/AltosRomconfigUI.java @@ -20,6 +20,7 @@ package altosui; import java.awt.*; import java.awt.event.*; import javax.swing.*; +import org.altusmetrum.altoslib_1.*; import org.altusmetrum.altosuilib_1.*; public class AltosRomconfigUI diff --git a/altosui/Makefile.am b/altosui/Makefile.am index 4bfef47c..56554697 100644 --- a/altosui/Makefile.am +++ b/altosui/Makefile.am @@ -30,7 +30,6 @@ altosui_JAVA = \ AltosConfigTDUI.java \ AltosCSV.java \ AltosCSVUI.java \ - AltosDebug.java \ AltosDescent.java \ AltosDeviceUIDialog.java \ AltosDisplayThread.java \ @@ -50,7 +49,6 @@ altosui_JAVA = \ AltosFlightStatusUpdate.java \ AltosFlightUI.java \ AltosFreqList.java \ - AltosHexfile.java \ Altos.java \ AltosIdleMonitorUI.java \ AltosIgniteUI.java \ @@ -63,7 +61,6 @@ altosui_JAVA = \ AltosLights.java \ AltosPad.java \ AltosUIPreferencesBackend.java \ - AltosRomconfig.java \ AltosRomconfigUI.java \ AltosScanUI.java \ AltosSerial.java \ -- 2.30.2