diff options
| author | Keith Packard <keithp@keithp.com> | 2010-08-23 14:32:58 -0700 |
|---|---|---|
| committer | Keith Packard <keithp@keithp.com> | 2010-08-23 14:32:58 -0700 |
| commit | ebeb13688a9a5442c838641ede6ba0dc92c9a1a4 (patch) | |
| tree | 498e5b186a9c5dbdbc042b631d6f2c48a6fc2e55 /ao-tools/altosui/AltosFlash.java | |
| parent | 7f8d7978606abe544b1b9b6065c5480ed813b8ec (diff) | |
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 <keithp@keithp.com>
Diffstat (limited to 'ao-tools/altosui/AltosFlash.java')
| -rw-r--r-- | ao-tools/altosui/AltosFlash.java | 60 |
1 files changed, 27 insertions, 33 deletions
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 |
