altosui: Make scan UI handle incremental telem data
authorKeith Packard <keithp@keithp.com>
Wed, 18 Jul 2012 07:01:51 +0000 (00:01 -0700)
committerKeith Packard <keithp@keithp.com>
Wed, 18 Jul 2012 07:01:51 +0000 (00:01 -0700)
The new telem format doesn't send everything in each telem packet, so
we need to handle updating information incrementally in the scan
results. This involved clearing old scan data when switching
frequencies and then updating existing entries with new data as it arrives.

Signed-off-by: Keith Packard <keithp@keithp.com>
altoslib/AltosIdleMonitor.java
altoslib/AltosTelemetryReader.java
altosui/AltosScanUI.java

index cd518c28370cc42243ff4b1b73d8a6f7445aebbf..57c4da71f3ffb78465c78cd467e87e4faafbe033 100644 (file)
@@ -162,8 +162,6 @@ class AltosSensorMM {
                                }
                                i++;
                        }
-                       for (int i = 0; i < sense.length; i++)
-                               System.out.printf("sense[%d]: %d\n", i, sense[i]);
                        break;
                }
        }
index 911a099af7d33a62183b4d0bc0adeea1217c76c2..bdb44eefb369edb940027aec7bd38fe191a8e22c 100644 (file)
@@ -44,6 +44,11 @@ public class AltosTelemetryReader extends AltosFlightReader {
                telem.clear();
        }
 
+       public void reset() {
+               previous = null;
+               flush();
+       }
+
        public void close(boolean interrupted) {
                link.remove_monitor(telem);
                log.close();
index 44eeda6dcc83ff228c21efe0415a1bf4f7de5bfa..ef6389b6c94d966b502fa774f0f8d0615ecf3a63 100644 (file)
@@ -59,29 +59,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<AltosScanResult> implements ListModel {
        
        LinkedList<ListDataListener>    listeners = new LinkedList<ListDataListener>();
 
+       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;
        }
 
@@ -205,6 +226,7 @@ public class AltosScanUI
        
        void set_frequency() throws InterruptedException, TimeoutException {
                reader.set_frequency(frequencies[frequency_index].frequency);
+               reader.reset();
        }
        
        void next() throws InterruptedException, TimeoutException {