diff options
| author | Keith Packard <keithp@keithp.com> | 2010-04-02 16:07:40 -0700 | 
|---|---|---|
| committer | Keith Packard <keithp@keithp.com> | 2010-04-02 16:07:40 -0700 | 
| commit | 65079f84ea64220fa928c3ad96652fed159bf74b (patch) | |
| tree | e16baf082ef35afc902c29837faca13dd0a2ace9 /ao-tools/altosui/AltosUI.java | |
| parent | 02f2be90879b682b6e648cf2debc83223d127b9d (diff) | |
Steal C code from ao-view
Diffstat (limited to 'ao-tools/altosui/AltosUI.java')
| -rw-r--r-- | ao-tools/altosui/AltosUI.java | 76 | 
1 files changed, 69 insertions, 7 deletions
| diff --git a/ao-tools/altosui/AltosUI.java b/ao-tools/altosui/AltosUI.java index 89eaac15..21c3e7a2 100644 --- a/ao-tools/altosui/AltosUI.java +++ b/ao-tools/altosui/AltosUI.java @@ -20,6 +20,8 @@ package altosui;  import java.awt.*;  import java.awt.event.*;  import javax.swing.*; +import javax.swing.filechooser.FileNameExtensionFilter; +import javax.swing.table.AbstractTableModel;  import java.io.*;  import java.util.*;  import java.text.*; @@ -27,6 +29,8 @@ import gnu.io.CommPortIdentifier;  import altosui.AltosSerial;  import altosui.AltosSerialMonitor; +import altosui.AltosTelemetry; +import altosui.AltosState;  class AltosUIMonitor implements AltosSerialMonitor {  	public void data(String data) { @@ -34,6 +38,32 @@ class AltosUIMonitor implements AltosSerialMonitor {  	}  } +class AltosFlightStatusTableModel extends AbstractTableModel { +	private String[] columnNames = {"Height (m)", "State", "RSSI (dBm)", "Speed (m/s)" }; +	private Object[] data = { 0, "idle", 0, 0 }; + +	public int getColumnCount() { return columnNames.length; } +	public int getRowCount() { return 1; } +	public String getColumnName(int col) { return columnNames[col]; } +	public Object getValueAt(int row, int col) { return data[col]; } + +	public void setValueAt(Object value, int col) { +		data[col] = value; +		fireTableCellUpdated(0, col); +	} + +	public void setValueAt(Object value, int row, int col) { +		setValueAt(value, col); +	} + +	public void set(AltosState state) { +		setValueAt(state.height, 0); +		setValueAt(state.data.state, 1); +		setValueAt(state.data.rssi, 2); +		setValueAt(state.speed, 3); +	} +} +  public class AltosUI extends JFrame {  	private int channel = -1; @@ -71,6 +101,31 @@ public class AltosUI extends JFrame {  	}  	final JFileChooser deviceChooser = new JFileChooser(); +	final JFileChooser logdirChooser = new JFileChooser(); +	final String logdirName = "TeleMetrum"; +	File logdir = null; + +	private void setLogdir() { +		if (logdir == null) +			logdir = new File(logdirChooser.getCurrentDirectory(), logdirName); +		logdirChooser.setCurrentDirectory(logdir); +	} + +	private void makeLogdir() { +		setLogdir(); +		if (!logdir.exists()) { +			if (!logdir.mkdirs()) +				JOptionPane.showMessageDialog(AltosUI.this, +							      logdir.getName(), +							      "Cannot create directory", +							      JOptionPane.ERROR_MESSAGE); +		} else if (!logdir.isDirectory()) { +			JOptionPane.showMessageDialog(AltosUI.this, +						      logdir.getName(), +						      "Is not a directory", +						      JOptionPane.ERROR_MESSAGE); +		} +	}  	private void PickSerialDevice() {  		java.util.Enumeration<CommPortIdentifier> port_list = CommPortIdentifier.getPortIdentifiers(); @@ -111,16 +166,23 @@ public class AltosUI extends JFrame {  		return null;  	} +	/* +	 * Open an existing telemetry file and replay it in realtime +	 */ +  	private void Replay() { -//		int returnVal = deviceChooser.showOpenDialog(AltosUI.this); +		setLogdir(); +		logdirChooser.setDialogTitle("Select Telemetry File"); +		logdirChooser.setFileFilter(new FileNameExtensionFilter("Telemetry file", "telem")); +		int returnVal = logdirChooser.showOpenDialog(AltosUI.this); -		/*		if (returnVal == JFileChooser.APPROVE_OPTION) */ { -//			File file = deviceChooser.getSelectedFile(); -//			String	filename = file.getName(); -			String	filename = "/home/keithp/src/cc1111/flights/2010-02-13-serial-051-flight-002.telem"; +		if (returnVal == JFileChooser.APPROVE_OPTION) { +			File file = logdirChooser.getSelectedFile(); +			if (file == null) +				System.out.println("No file selected?"); +			String	filename = file.getName();  			try { -//				FileInputStream	replay = new FileInputStream(file); -				FileInputStream	replay = new FileInputStream(filename); +				FileInputStream	replay = new FileInputStream(file);  				String	line;  				try { | 
