+ final JFileChooser deviceChooser = new JFileChooser();
+
+ private void PickSerialDevice() {
+ java.util.Enumeration<CommPortIdentifier> port_list = CommPortIdentifier.getPortIdentifiers();
+ while (port_list.hasMoreElements()) {
+ CommPortIdentifier identifier = port_list.nextElement();
+ System.out.println("Serial port " + identifier.getName());
+ }
+ }
+
+ private void ConnectToDevice() {
+ PickSerialDevice();
+ int returnVal = deviceChooser.showOpenDialog(AltosUI.this);
+
+ if (returnVal == JFileChooser.APPROVE_OPTION) {
+ File file = deviceChooser.getSelectedFile();
+ try {
+ serialLine.open(file);
+ } catch (FileNotFoundException ee) {
+ JOptionPane.showMessageDialog(AltosUI.this,
+ file.getName(),
+ "Cannot open serial port",
+ JOptionPane.ERROR_MESSAGE);
+ }
+ }
+ }
+
+ String readline(FileInputStream s) throws IOException {
+ int c;
+ String line = "";
+
+ while ((c = s.read()) != -1) {
+ if (c == '\r')
+ continue;
+ if (c == '\n')
+ return line;
+ line = line + (char) c;
+ }
+ return null;
+ }
+
+ private void Replay() {
+// int returnVal = deviceChooser.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";
+ try {
+// FileInputStream replay = new FileInputStream(file);
+ FileInputStream replay = new FileInputStream(filename);
+ String line;
+
+ try {
+ while ((line = readline(replay)) != null) {
+ try {
+ AltosTelemetry t = new AltosTelemetry(line);
+ System.out.println ("Version " + t.version + t.callsign);
+ } catch (ParseException pp) {
+ JOptionPane.showMessageDialog(AltosUI.this,
+ line,
+ "error parsing",
+ JOptionPane.ERROR_MESSAGE);
+ break;
+ }
+ }
+ } catch (IOException ee) {
+ JOptionPane.showMessageDialog(AltosUI.this,
+ filename,
+ "error reading",
+ JOptionPane.ERROR_MESSAGE);
+ } finally {
+ try {
+ replay.close();
+ } catch (IOException e) {}
+ }
+ } catch (FileNotFoundException ee) {
+ JOptionPane.showMessageDialog(AltosUI.this,
+ filename,
+ "Cannot open serial port",
+ JOptionPane.ERROR_MESSAGE);
+ }
+ }
+ }
+
+ private void SaveFlightData() {
+ }
+