ICP3 working
[fw/altos] / altosui / AltosIdleMonitorUI.java
index a5f41e258891054732ee867a2ef9cb1ba468197a..ce608d2b3bc6480e0717e318047e3df0a98868d4 100644 (file)
@@ -27,6 +27,7 @@ import java.util.*;
 import java.text.*;
 import java.util.prefs.*;
 import java.util.concurrent.*;
+import org.altusmetrum.AltosLib.*;
 
 class AltosADC {
        int     tick;
@@ -83,6 +84,7 @@ class AltosADC {
                                        i += 2;
                                        continue;
                                }
+                               i++;
                        }
                        break;
                }
@@ -90,7 +92,9 @@ class AltosADC {
 }
 
 class AltosGPSQuery extends AltosGPS {
-       public AltosGPSQuery (AltosSerial serial) throws TimeoutException, InterruptedException {
+       public AltosGPSQuery (AltosSerial serial, AltosConfigData config_data)
+               throws TimeoutException, InterruptedException {
+               boolean says_done = config_data.compare_version("1.0") >= 0;
                serial.printf("g\n");
                for (;;) {
                        String line = serial.get_reply_no_dialog(5000);
@@ -140,6 +144,8 @@ class AltosGPSQuery extends AltosGPS {
                                int status = Integer.decode(bits[1]);
                                connected = (status & Altos.AO_GPS_RUNNING) != 0;
                                locked = (status & Altos.AO_GPS_VALID) != 0;
+                               if (!says_done)
+                                       break;
                                continue;
                        }
                        if (line.startsWith("Sats:")) {
@@ -173,8 +179,23 @@ class AltosIdleMonitor extends Thread {
        AltosADC                adc;
        AltosGPS                gps;
 
+       int AltosRSSI() throws TimeoutException, InterruptedException {
+               serial.printf("s\n");
+               String line = serial.get_reply_no_dialog(5000);
+               if (line == null)
+                       throw new TimeoutException();
+               String[] items = line.split("\\s+");
+               if (items.length < 2)
+                       return 0;
+               if (!items[0].equals("RSSI:"))
+                       return 0;
+               int rssi = Integer.parseInt(items[1]);
+               return rssi;
+       }
+
        void update_state() throws InterruptedException, TimeoutException {
-               AltosRecord     record = new AltosRecord();
+               AltosRecordTM   record = new AltosRecordTM();
+               int             rssi;
 
                try {
                        if (remote) {
@@ -184,21 +205,25 @@ class AltosIdleMonitor extends Thread {
                                serial.flush_input();
                        config_data = new AltosConfigData(serial);
                        adc = new AltosADC(serial);
-                       gps = new AltosGPSQuery(serial);
+                       gps = new AltosGPSQuery(serial, config_data);
                } finally {
-                       if (remote)
+                       if (remote) {
                                serial.stop_remote();
+                               rssi = AltosRSSI();
+                       } else
+                               rssi = 0;
                }
 
                record.version = 0;
                record.callsign = config_data.callsign;
                record.serial = config_data.serial;
                record.flight = config_data.log_available() > 0 ? 255 : 0;
-               record.rssi = 0;
+               record.rssi = rssi;
                record.status = 0;
                record.state = Altos.ao_flight_idle;
 
                record.tick = adc.tick;
+
                record.accel = adc.accel;
                record.pres = adc.pres;
                record.batt = adc.batt;
@@ -237,6 +262,8 @@ class AltosIdleMonitor extends Thread {
                                        update_state();
                                        post_state();
                                } catch (TimeoutException te) {
+                                       if (AltosSerial.debug)
+                                               System.out.printf ("monitor idle data timeout\n");
                                }
                                Thread.sleep(1000);
                        }
@@ -293,7 +320,10 @@ public class AltosIdleMonitorUI extends AltosFrame implements AltosFlightDisplay
                set_font();
        }
 
+       AltosFlightStatusUpdate status_update;
+
        public void show(AltosState state, int crc_errors) {
+               status_update.saved_state = state;
                try {
                        pad.show(state, crc_errors);
                        flightStatus.show(state, crc_errors);
@@ -315,7 +345,7 @@ public class AltosIdleMonitorUI extends AltosFrame implements AltosFlightDisplay
 
                device = AltosDeviceDialog.show(in_owner, Altos.product_any);
                remote = false;
-               if (!device.matchProduct(Altos.product_telemetrum))
+               if (!device.matchProduct(Altos.product_altimeter))
                        remote = true;
 
                serial = device.getSerial();
@@ -333,12 +363,12 @@ public class AltosIdleMonitorUI extends AltosFrame implements AltosFlightDisplay
                /* Stick frequency selector at top of table for telemetry monitoring */
                if (remote && serial >= 0) {
                        // Frequency menu
-                       frequencies = new AltosFreqList(AltosPreferences.frequency(serial));
+                       frequencies = new AltosFreqList(AltosUIPreferences.frequency(serial));
                        frequencies.addActionListener(new ActionListener() {
                                        public void actionPerformed(ActionEvent e) {
                                                double frequency = frequencies.frequency();
                                                thread.set_frequency(frequency);
-                                               AltosPreferences.set_frequency(device.getSerial(),
+                                               AltosUIPreferences.set_frequency(device.getSerial(),
                                                                               frequency);
                                        }
                        });
@@ -382,7 +412,7 @@ public class AltosIdleMonitorUI extends AltosFrame implements AltosFlightDisplay
 
                setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
 
-               AltosPreferences.register_font_listener(this);
+               AltosUIPreferences.register_font_listener(this);
 
                addWindowListener(new WindowAdapter() {
                                @Override
@@ -390,7 +420,7 @@ public class AltosIdleMonitorUI extends AltosFrame implements AltosFlightDisplay
                                        disconnect();
                                        setVisible(false);
                                        dispose();
-                                       AltosPreferences.unregister_font_listener(AltosIdleMonitorUI.this);
+                                       AltosUIPreferences.unregister_font_listener(AltosIdleMonitorUI.this);
                                }
                        });
 
@@ -399,6 +429,10 @@ public class AltosIdleMonitorUI extends AltosFrame implements AltosFlightDisplay
 
                thread = new AltosIdleMonitor(this, device, remote);
 
+               status_update = new AltosFlightStatusUpdate(flightStatus);
+
+               new javax.swing.Timer(100, status_update).start();
+
                thread.start();
        }
 }