telegps: Get telegps application working again
authorKeith Packard <keithp@keithp.com>
Sat, 27 May 2017 23:12:31 +0000 (16:12 -0700)
committerKeith Packard <keithp@keithp.com>
Sat, 27 May 2017 23:12:31 +0000 (16:12 -0700)
Many minor API tweaks

Signed-off-by: Keith Packard <keithp@keithp.com>
altoslib/AltosFlightReader.java
altoslib/AltosState.java
altoslib/AltosTelemetryReader.java
altosui/AltosUI.java
altosuilib/AltosScanUI.java
telegps/TeleGPS.java
telegps/TeleGPSDisplayThread.java
telegps/TeleGPSGraphUI.java
telegps/TeleGPSState.java
telegps/TeleGPSStatus.java

index 790710e02805b80d715ed4942c1e0af377e13776..f252d60bdf600e701c62cf01a9af1a651eb24287 100644 (file)
@@ -31,6 +31,8 @@ public abstract class AltosFlightReader {
 
        public abstract AltosState read() throws InterruptedException, ParseException, AltosCRCException, IOException;
 
+       public abstract AltosCalData cal_data();
+
        public abstract void close(boolean interrupted);
 
        public void set_frequency(double frequency) throws InterruptedException, TimeoutException { }
index e5a0541e18af3d73ede2e596ae2c7d9c31cf814a..5abc0c2d41a5a6e666039052e784f113f4b6a415 100644 (file)
@@ -1075,11 +1075,14 @@ public class AltosState extends AltosDataListener {
        }
 
        public AltosState() {
+               Thread.dumpStack();
                init();
        }
 
        public AltosState (AltosCalData cal_data) {
                super(cal_data);
+               if (cal_data == null)
+                       Thread.dumpStack();
                init();
        }
 }
index 9611361310a229b614cf8d9d6c734bc5e6e207d0..1020efb0f1f4ffc0d1cbeaccd45a904e58297483 100644 (file)
@@ -23,13 +23,13 @@ import java.io.*;
 import java.util.concurrent.*;
 
 public class AltosTelemetryReader extends AltosFlightReader {
-       AltosLink       link;
-       AltosLog        log;
-       double          frequency;
-       int             telemetry;
-       int             telemetry_rate;
-       public AltosState       state = null;
-       public AltosCalData     cal_data = null;
+       AltosLink               link;
+       AltosLog                log;
+       double                  frequency;
+       int                     telemetry;
+       int                     telemetry_rate;
+       private AltosState      state = null;
+       private AltosCalData    cal_data = null;
 
        LinkedBlockingQueue<AltosLine> telem;
 
@@ -41,14 +41,22 @@ public class AltosTelemetryReader extends AltosFlightReader {
                                throw new IOException("IO error");
                } while (!link.get_monitor());
                AltosTelemetry  telem = AltosTelemetry.parse(l.line);
-               if (cal_data == null)
-                       cal_data = new AltosCalData();
-               if (state == null)
-                       state = new AltosState(cal_data);
-               telem.provide_data(state, cal_data);
+               if (state == null) {
+                       System.out.printf("Make state\n");
+                       state = new AltosState(cal_data());
+               }
+               telem.provide_data(state, state.cal_data);
                return state;
        }
 
+       public AltosCalData cal_data() {
+               if (cal_data == null) {
+                       System.out.printf("Make cal data\n");
+                       cal_data = new AltosCalData();
+               }
+               return cal_data;
+       }
+
        public void flush() {
                telem.clear();
        }
index e7dedffd2ecbdf20613a17f16071cfa1fadc6d8e..b302b670677a73fb533eb00c01ad34db656b8438 100644 (file)
@@ -311,12 +311,10 @@ public class AltosUI extends AltosUIFrame {
                        AltosUI.this);
 
                AltosRecordSet set = chooser.runDialog();
-/* XXX fixme */
-//             if (states != null) {
-//                     AltosFlightReader reader = new AltosReplayReader(states.iterator(),
-//                                                                      chooser.file());
-//                     new AltosFlightUI(voice, reader);
-//             }
+               if (set != null) {
+                       AltosReplayReader reader = new AltosReplayReader(set, chooser.file());
+                       new AltosFlightUI(voice, reader);
+               }
        }
 
        /* Connect to TeleMetrum, either directly or through
@@ -329,6 +327,7 @@ public class AltosUI extends AltosUIFrame {
        private static AltosFlightSeries make_series(AltosRecordSet set) {
                AltosFlightSeries series = new AltosFlightSeries(set.cal_data());
                set.capture_series(series);
+               series.finish();
                return series;
        }
 
index ad53f66ba20c63cce431c76863b3c7570f013b9f..2dc093dc82e775e96c2e9ff3e29b7ff97f5e3f95 100644 (file)
@@ -213,10 +213,11 @@ public class AltosScanUI
                                                if (state == null)
                                                        continue;
                                                packet_count++;
-                                               if (reader.cal_data.flight != AltosLib.MISSING) {
-                                                       final AltosScanResult   result = new AltosScanResult(reader.cal_data.callsign,
-                                                                                                            reader.cal_data.serial,
-                                                                                                            reader.cal_data.flight,
+                                               AltosCalData    cal_data = state.cal_data;
+                                               if (cal_data.flight != AltosLib.MISSING) {
+                                                       final AltosScanResult   result = new AltosScanResult(cal_data.callsign,
+                                                                                                            cal_data.serial,
+                                                                                                            cal_data.flight,
                                                                                                             frequencies[frequency_index],
                                                                                                             telemetry,
                                                                                                             rate);
index cf2cbd4fefce4e114fb8605cbdda3a2a5ff535cb..5e500e0259a74623e6d934d2e85b876bc0107d2a 100644 (file)
@@ -152,7 +152,7 @@ public class TeleGPS
                        status_update.saved_listener_state = listener_state;
 
                        if (state == null)
-                               state = new AltosState();
+                               state = new AltosState(new AltosCalData());
 
                        int i = 0;
                        for (AltosFlightDisplay display : displays) {
@@ -287,23 +287,30 @@ public class TeleGPS
                new TeleGPSConfig(this);
        }
 
+       private static AltosFlightSeries make_series(AltosRecordSet set) {
+               AltosFlightSeries series = new AltosFlightSeries(set.cal_data());
+               set.capture_series(series);
+               series.finish();
+               return series;
+       }
+
        void export() {
-               AltosDataChooser chooser;
-               chooser = new AltosDataChooser(this);
-               AltosStateIterable states = chooser.runDialog();
-               if (states == null)
+               AltosDataChooser chooser = new AltosDataChooser(this);
+
+               AltosRecordSet set = chooser.runDialog();
+               if (set == null)
                        return;
-               new AltosCSVUI(this, states, chooser.file());
+               AltosFlightSeries series = make_series(set);
+               new AltosCSVUI(this, series, series.cal_data, chooser.file());
        }
 
        void graph() {
-               AltosDataChooser chooser;
-               chooser = new AltosDataChooser(this);
-               AltosStateIterable states = chooser.runDialog();
-               if (states == null)
+               AltosDataChooser chooser = new AltosDataChooser(this);
+               AltosRecordSet set = chooser.runDialog();
+               if (set == null)
                        return;
                try {
-                       new TeleGPSGraphUI(states, chooser.file());
+                       new TeleGPSGraphUI(set, chooser.file());
                } catch (InterruptedException ie) {
                } catch (IOException ie) {
                }
@@ -612,7 +619,7 @@ public class TeleGPS
                connect(device);
        }
 
-       static AltosStateIterable record_iterable(File file) {
+       static AltosRecordSet record_set(File file) {
                FileInputStream in;
                 if (file.getName().endsWith("telem")) {
                         try {
@@ -624,8 +631,7 @@ public class TeleGPS
                 } else {
 
                         try {
-                                AltosEepromFile f = new AltosEepromFile(new FileReader(file));
-                                return f;
+                                return new AltosEepromFile(new FileReader(file));
                         } catch (Exception e) {
                                 System.out.printf("Failed to open file '%s'\n", file);
                         }
@@ -634,18 +640,18 @@ public class TeleGPS
        }
 
        static AltosReplayReader replay_file(File file) {
-               AltosStateIterable states = record_iterable(file);
-               if (states == null)
+               AltosRecordSet set = record_set(file);
+               if (set == null)
                        return null;
-               return new AltosReplayReader(states.iterator(), file);
+               return new AltosReplayReader(set, file);
        }
 
        static boolean process_graph(File file) {
-               AltosStateIterable states = record_iterable(file);
-               if (states == null)
+               AltosRecordSet set = record_set(file);
+               if (set == null)
                        return false;
                try {
-                       new TeleGPSGraphUI(states, file);
+                       new TeleGPSGraphUI(set, file);
                } catch (Exception e) {
                        return false;
                }
index a9c80dc00d537cd60cb87c892e72abfad257583f..c311dd7e01b03fa8fc37d835b62895f062f9cca3 100644 (file)
@@ -31,7 +31,9 @@ public class TeleGPSDisplayThread extends Thread {
        IdleThread              idle_thread;
        AltosVoice              voice;
        AltosFlightReader       reader;
-       AltosState              old_state, state;
+       AltosState              state;
+       int                     old_state = AltosLib.ao_flight_invalid;
+       boolean                 old_gps_ready = false;
        AltosListenerState      listener_state;
        AltosFlightDisplay      display;
 
@@ -130,11 +132,12 @@ public class TeleGPSDisplayThread extends Thread {
                }
 
                public synchronized void notice(boolean spoken) {
-                       if (old_state != null && old_state.state() != state.state()) {
+                       if (old_state != state.state()) {
                                report_time = now();
                                this.notify();
                        } else if (spoken)
                                set_report_time();
+                       old_state = state.state();
                }
 
                public IdleThread() {
@@ -144,17 +147,17 @@ public class TeleGPSDisplayThread extends Thread {
 
        synchronized boolean tell() {
                boolean ret = false;
-               if (old_state == null || old_state.gps_ready != state.gps_ready) {
+               if (old_gps_ready != state.gps_ready) {
                        if (state.gps_ready) {
                                voice.speak("GPS ready");
                                ret = true;
                        }
-                       else if (old_state != null) {
+                       else if (old_gps_ready) {
                                voice.speak("GPS lost");
                                ret = true;
                        }
+                       old_gps_ready = state.gps_ready;
                }
-               old_state = state;
                return ret;
        }
 
@@ -173,7 +176,6 @@ public class TeleGPSDisplayThread extends Thread {
                                                listener_state.running = false;
                                                break;
                                        }
-                                       reader.update(state);
                                        show_safely();
                                        told = tell();
                                        idle_thread.notice(told);
index 55ee370e33b2a4e1dda1e3b3a0dd629114d1f7a4..3e76564020b8b492ce2b3ad6100c1befa14ec77f 100644 (file)
@@ -34,21 +34,41 @@ import org.jfree.chart.ChartPanel;
 import org.jfree.chart.JFreeChart;
 import org.jfree.ui.RefineryUtilities;
 
-public class TeleGPSGraphUI extends AltosUIFrame
+public class TeleGPSGraphUI extends AltosUIFrame implements AltosFontListener, AltosUnitsListener
 {
        JTabbedPane             pane;
-       AltosGraph              graph;
+       AltosGraphNew           graph;
        AltosUIEnable           enable;
        AltosUIMap              map;
        AltosState              state;
        AltosFlightStats        stats;
-       AltosGraphDataSet       graphDataSet;
        AltosFlightStatsTable   statsTable;
-
-       void fill_map(AltosStateIterable states) {
-               for (AltosState state : states) {
-                       if (state.gps != null && state.gps.locked && state.gps.nsat >= 4)
-                               map.show(state, null);
+       AltosGPS                gps;
+       boolean                 has_gps;
+
+       void fill_map(AltosFlightSeries flight_series) {
+               boolean                 any_gps = false;
+               AltosGPSTimeValue       gtv_last = null;
+
+               if (flight_series.gps_series != null) {
+                       for (AltosGPSTimeValue gtv : flight_series.gps_series) {
+                               gtv_last = gtv;
+                               AltosGPS gps = gtv.gps;
+                               if (gps != null &&
+                                   gps.locked &&
+                                   gps.nsat >= 4) {
+                                       if (map == null)
+                                               map = new AltosUIMap();
+                                       map.show(gps, (int) flight_series.value_before(AltosFlightSeries.state_name, gtv.time));
+                                       this.gps = gps;
+                                       has_gps = true;
+                               }
+                       }
+               }
+               if (gtv_last != null) {
+                       int state = (int) flight_series.value_after(AltosFlightSeries.state_name, gtv_last.time);
+                       if (state == AltosLib.ao_flight_landed)
+                               map.show(gtv_last.gps, state);
                }
        }
 
@@ -58,16 +78,35 @@ public class TeleGPSGraphUI extends AltosUIFrame
                TeleGPS.subtract_window();
        }
 
-       TeleGPSGraphUI(AltosStateIterable states, File file) throws InterruptedException, IOException {
+       public void font_size_changed(int font_size) {
+               if (map != null)
+                       map.font_size_changed(font_size);
+               if (statsTable != null)
+                       statsTable.font_size_changed(font_size);
+       }
+
+       public void units_changed(boolean imperial_units) {
+               if (map != null)
+                       map.units_changed(imperial_units);
+               if (enable != null)
+                       enable.units_changed(imperial_units);
+       }
+
+       TeleGPSGraphUI(AltosRecordSet set, File file) throws InterruptedException, IOException {
                super(file.getName());
-               state = null;
+               AltosCalData cal_data = set.cal_data();
+
+               AltosUIFlightSeries flight_series = new AltosUIFlightSeries(cal_data);
+               set.capture_series(flight_series);
+               flight_series.finish();
 
                pane = new JTabbedPane();
 
                enable = new AltosUIEnable();
-               stats = new AltosFlightStats(states);
-               graphDataSet = new AltosGraphDataSet(states);
-               graph = new AltosGraph(enable, stats, graphDataSet);
+               stats = new AltosFlightStats(flight_series);
+
+               graph = new AltosGraphNew(enable, stats, flight_series, cal_data);
+
                statsTable = new AltosFlightStatsTable(stats);
 
                map = new AltosUIMap();
@@ -75,11 +114,14 @@ public class TeleGPSGraphUI extends AltosUIFrame
                pane.add("Graph", graph.panel);
                pane.add("Configure Graph", enable);
                pane.add("Statistics", statsTable);
-               fill_map(states);
+               fill_map(flight_series);
                pane.add("Map", map);
 
                setContentPane (pane);
 
+               AltosUIPreferences.register_font_listener(this);
+               AltosPreferences.register_units_listener(this);
+
                addWindowListener(new WindowAdapter() {
                                @Override
                                public void windowClosing(WindowEvent e) {
index 9ba0b7a59cabf42b7cee93b371750a530d0fd2e1..2e39037c529f4e15d16111d70047025b6ff41ab8 100644 (file)
@@ -124,10 +124,10 @@ public class TeleGPSState extends AltosUIFlightTab {
 
        class FirmwareVersion extends AltosUIIndicator {
                public void show(AltosState state, AltosListenerState listener_state) {
-                       if (state.firmware_version == null)
+                       if (state.cal_data.firmware_version == null)
                                show("Missing");
                        else
-                               show(state.firmware_version);
+                               show(state.cal_data.firmware_version);
                }
 
                public FirmwareVersion(Container container, int y) {
@@ -137,9 +137,7 @@ public class TeleGPSState extends AltosUIFlightTab {
 
        class FlightLogMax extends AltosUIIndicator {
                public void show(AltosState state, AltosListenerState listener_state) {
-                       int storage = state.flight_log_max;
-                       if (storage == AltosLib.MISSING)
-                               storage = state.log_space >> 10;
+                       int storage = state.cal_data.flight_log_max;
                        if (storage == AltosLib.MISSING)
                                show("Missing");
                        else
index 5479f43a025927f762c4051aed61dff1b84185d6..a6ddd1b0935759b542ac5fc3b88329aac65f2151 100644 (file)
@@ -75,11 +75,13 @@ public class TeleGPSStatus extends JComponent implements AltosFlightDisplay {
                String  call;
 
                void show(AltosState state, AltosListenerState listener_state) {
-                       if (state.callsign != call) {
-                               value.setText(state.callsign);
-                               call = state.callsign;
+                       if (state.cal_data == null)
+                               System.out.printf("null cal data?\n");
+                       if (state.cal_data.callsign != call) {
+                               value.setText(state.cal_data.callsign);
+                               call = state.cal_data.callsign;
                        }
-                       if (state.callsign == null)
+                       if (state.cal_data.callsign == null)
                                setVisible(false);
                        else
                                setVisible(true);
@@ -100,12 +102,12 @@ public class TeleGPSStatus extends JComponent implements AltosFlightDisplay {
        class Serial extends Value {
                int     serial = -1;
                void show(AltosState state, AltosListenerState listener_state) {
-                       if (state.serial != serial) {
-                               if (state.serial == AltosLib.MISSING)
+                       if (state.cal_data.serial != serial) {
+                               if (state.cal_data.serial == AltosLib.MISSING)
                                        value.setText("none");
                                else
-                                       value.setText(String.format("%d", state.serial));
-                               serial = state.serial;
+                                       value.setText(String.format("%d", state.cal_data.serial));
+                               serial = state.cal_data.serial;
                        }
                }
 
@@ -126,12 +128,12 @@ public class TeleGPSStatus extends JComponent implements AltosFlightDisplay {
                int     last_flight = -1;
 
                void show(AltosState state, AltosListenerState listener_state) {
-                       if (state.flight != last_flight) {
-                               if (state.flight == AltosLib.MISSING)
+                       if (state.cal_data.flight != last_flight) {
+                               if (state.cal_data.flight == AltosLib.MISSING)
                                        value.setText("none");
                                else
-                                       value.setText(String.format("%d", state.flight));
-                               last_flight = state.flight;
+                                       value.setText(String.format("%d", state.cal_data.flight));
+                               last_flight = state.cal_data.flight;
                        }
                }