X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=blobdiff_plain;f=altosui%2FAltosScanUI.java;h=a5ccb15aac379a6d6cb82dc8a0a4850b8eb567f0;hp=dd6672aa29886a41ebea1140dc0eb9d9f8d918b2;hb=1280ba2e51b36f417f3adb6d101405ee75e7e509;hpb=cbf54a826d12c49b1b1996be247869d5ff4e2236 diff --git a/altosui/AltosScanUI.java b/altosui/AltosScanUI.java index dd6672aa..a5ccb15a 100644 --- a/altosui/AltosScanUI.java +++ b/altosui/AltosScanUI.java @@ -20,14 +20,13 @@ 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 java.util.concurrent.*; +import org.altusmetrum.altoslib_2.*; +import org.altusmetrum.altosuilib_1.*; class AltosScanResult { String callsign; @@ -58,29 +57,50 @@ class AltosScanResult { } public boolean equals(AltosScanResult other) { - return (callsign.equals(other.callsign) && - serial == other.serial && - flight == other.flight && + return (serial == other.serial && frequency.frequency == other.frequency.frequency && telemetry == other.telemetry); } + + public boolean up_to_date(AltosScanResult other) { + if (flight == 0 && other.flight != 0) { + flight = other.flight; + return false; + } + if (callsign.equals("N0CALL") && !other.callsign.equals("N0CALL")) { + callsign = other.callsign; + return false; + } + return true; + } } class AltosScanResults extends LinkedList implements ListModel { LinkedList listeners = new LinkedList(); + void changed(ListDataEvent de) { + for (ListDataListener l : listeners) + l.contentsChanged(de); + } + public boolean add(AltosScanResult r) { - for (AltosScanResult old : this) - if (old.equals(r)) + int i = 0; + for (AltosScanResult old : this) { + if (old.equals(r)) { + if (!old.up_to_date(r)) + changed (new ListDataEvent(this, + ListDataEvent.CONTENTS_CHANGED, + i, i)); return true; + } + i++; + } super.add(r); - ListDataEvent de = new ListDataEvent(this, - ListDataEvent.INTERVAL_ADDED, - this.size() - 2, this.size() - 1); - for (ListDataListener l : listeners) - l.contentsChanged(de); + changed(new ListDataEvent(this, + ListDataEvent.INTERVAL_ADDED, + this.size() - 2, this.size() - 1)); return true; } @@ -102,7 +122,7 @@ class AltosScanResults extends LinkedList implements ListModel } public class AltosScanUI - extends JDialog + extends AltosUIDialog implements ActionListener { AltosUI owner; @@ -130,8 +150,7 @@ public class AltosScanUI void scan_exception(Exception e) { if (e instanceof FileNotFoundException) { JOptionPane.showMessageDialog(owner, - String.format("Cannot open device \"%s\"", - device.toShortString()), + ((FileNotFoundException) e).getMessage(), "Cannot open target device", JOptionPane.ERROR_MESSAGE); } else if (e instanceof AltosSerialInUseException) { @@ -165,13 +184,13 @@ public class AltosScanUI try { for (;;) { try { - AltosRecord record = reader.read(); - if (record == null) + AltosState state = reader.read(); + if (state == null) continue; - if ((record.seen & AltosRecord.seen_flight) != 0) { - final AltosScanResult result = new AltosScanResult(record.callsign, - record.serial, - record.flight, + if (state.flight != AltosLib.MISSING) { + final AltosScanResult result = new AltosScanResult(state.callsign, + state.serial, + state.flight, frequencies[frequency_index], telemetry); Runnable r = new Runnable() { @@ -205,10 +224,11 @@ public class AltosScanUI void set_frequency() throws InterruptedException, TimeoutException { reader.set_frequency(frequencies[frequency_index].frequency); + reader.reset(); } void next() throws InterruptedException, TimeoutException { - reader.serial.set_monitor(false); + reader.set_monitor(false); Thread.sleep(100); ++frequency_index; if (frequency_index >= frequencies.length || @@ -224,7 +244,7 @@ public class AltosScanUI } set_frequency(); set_label(); - reader.serial.set_monitor(true); + reader.set_monitor(true); } @@ -268,7 +288,7 @@ public class AltosScanUI scanning_telemetry |= (1 << Altos.ao_telemetry_standard); telemetry_boxes[Altos.ao_telemetry_standard - Altos.ao_telemetry_min].setSelected(true); } - AltosPreferences.set_scanning_telemetry(scanning_telemetry); + AltosUIPreferences.set_scanning_telemetry(scanning_telemetry); } if (cmd.equals("monitor")) { @@ -308,11 +328,11 @@ public class AltosScanUI } private boolean open() { - device = AltosDeviceDialog.show(owner, Altos.product_basestation); + device = AltosDeviceUIDialog.show(owner, Altos.product_basestation); if (device == null) return false; try { - reader = new AltosTelemetryReader(device); + reader = new AltosTelemetryReader(new AltosSerial(device)); set_frequency(); set_telemetry(); try { @@ -326,8 +346,7 @@ public class AltosScanUI return true; } catch (FileNotFoundException ee) { JOptionPane.showMessageDialog(owner, - String.format("Cannot open device \"%s\"", - device.toShortString()), + ee.getMessage(), "Cannot open target device", JOptionPane.ERROR_MESSAGE); } catch (AltosSerialInUseException si) { @@ -361,7 +380,7 @@ public class AltosScanUI owner = in_owner; - frequencies = AltosPreferences.common_frequencies(); + frequencies = AltosUIPreferences.common_frequencies(); frequency_index = 0; telemetry = Altos.ao_telemetry_min; @@ -386,7 +405,7 @@ public class AltosScanUI set_label(); - c.fill = GridBagConstraints.NONE; + c.fill = GridBagConstraints.HORIZONTAL; c.anchor = GridBagConstraints.WEST; c.insets = i; c.weightx = 1; @@ -402,11 +421,11 @@ public class AltosScanUI c.gridy = 2; pane.add(telemetry_label, c); - int scanning_telemetry = AltosPreferences.scanning_telemetry(); + int scanning_telemetry = AltosUIPreferences.scanning_telemetry(); telemetry_boxes = new JCheckBox[Altos.ao_telemetry_max - Altos.ao_telemetry_min + 1]; for (int k = Altos.ao_telemetry_min; k <= Altos.ao_telemetry_max; k++) { int j = k - Altos.ao_telemetry_min; - telemetry_boxes[j] = new JCheckBox(Altos.ao_telemetry_name[k]); + telemetry_boxes[j] = new JCheckBox(AltosLib.telemetry_name(k)); c.gridy = 3 + j; pane.add(telemetry_boxes[j], c); telemetry_boxes[j].setActionCommand("telemetry");