altoslib: remove duplicate AltosGPSQuery class
[fw/altos] / altoslib / AltosIdleMonitor.java
index cd518c28370cc42243ff4b1b73d8a6f7445aebbf..f38e3dac7e3b9e2decd8601c2771ce73e43ef81d 100644 (file)
 package org.altusmetrum.AltosLib;
 
 import java.io.*;
-import java.util.*;
-import java.text.*;
-import java.util.prefs.*;
 import java.util.concurrent.*;
 
-class AltosSensorTM {
-       int     tick;
-       int     accel;
-       int     pres;
-       int     temp;
-       int     batt;
-       int     drogue;
-       int     main;
+class AltosSensorTM extends AltosRecordTM {
 
-       public AltosSensorTM(AltosLink link) throws InterruptedException, TimeoutException {
+       public AltosSensorTM(AltosLink link, AltosConfigData config_data) throws InterruptedException, TimeoutException {
+               super();
                link.printf("a\n");
                for (;;) {
                        String line = link.get_reply_no_dialog(5000);
@@ -82,6 +73,10 @@ class AltosSensorTM {
                        }
                        break;
                }
+               ground_accel = config_data.accel_cal_plus;
+               ground_pres = pres;
+               accel_plus_g = config_data.accel_cal_plus;
+               accel_minus_g = config_data.accel_cal_minus;
        }
 }
 
@@ -162,8 +157,6 @@ class AltosSensorMM {
                                }
                                i++;
                        }
-                       for (int i = 0; i < sense.length; i++)
-                               System.out.printf("sense[%d]: %d\n", i, sense[i]);
                        break;
                }
        }
@@ -240,82 +233,6 @@ class AltosMs5607Query extends AltosMs5607 {
        }
 }
 
-class AltosGPSQuery extends AltosGPS {
-       public AltosGPSQuery (AltosLink link, AltosConfigData config_data)
-               throws TimeoutException, InterruptedException {
-               boolean says_done = config_data.compare_version("1.0") >= 0;
-               link.printf("g\n");
-               for (;;) {
-                       String line = link.get_reply_no_dialog(5000);
-                       if (line == null)
-                               throw new TimeoutException();
-                       String[] bits = line.split("\\s+");
-                       if (bits.length == 0)
-                               continue;
-                       if (line.startsWith("Date:")) {
-                               if (bits.length < 2)
-                                       continue;
-                               String[] d = bits[1].split(":");
-                               if (d.length < 3)
-                                       continue;
-                               year = Integer.parseInt(d[0]) + 2000;
-                               month = Integer.parseInt(d[1]);
-                               day = Integer.parseInt(d[2]);
-                               continue;
-                       }
-                       if (line.startsWith("Time:")) {
-                               if (bits.length < 2)
-                                       continue;
-                               String[] d = bits[1].split("/");
-                               if (d.length < 3)
-                                       continue;
-                               hour = Integer.parseInt(d[0]);
-                               minute = Integer.parseInt(d[1]);
-                               second = Integer.parseInt(d[2]);
-                               continue;
-                       }
-                       if (line.startsWith("Lat/Lon:")) {
-                               if (bits.length < 3)
-                                       continue;
-                               lat = Integer.parseInt(bits[1]) * 1.0e-7;
-                               lon = Integer.parseInt(bits[2]) * 1.0e-7;
-                               continue;
-                       }
-                       if (line.startsWith("Alt:")) {
-                               if (bits.length < 2)
-                                       continue;
-                               alt = Integer.parseInt(bits[1]);
-                               continue;
-                       }
-                       if (line.startsWith("Flags:")) {
-                               if (bits.length < 2)
-                                       continue;
-                               int status = Integer.decode(bits[1]);
-                               connected = (status & AltosLib.AO_GPS_RUNNING) != 0;
-                               locked = (status & AltosLib.AO_GPS_VALID) != 0;
-                               if (!says_done)
-                                       break;
-                               continue;
-                       }
-                       if (line.startsWith("Sats:")) {
-                               if (bits.length < 2)
-                                       continue;
-                               nsat = Integer.parseInt(bits[1]);
-                               cc_gps_sat = new AltosGPSSat[nsat];
-                               for (int i = 0; i < nsat; i++) {
-                                       int     svid = Integer.parseInt(bits[2+i*2]);
-                                       int     cc_n0 = Integer.parseInt(bits[3+i*2]);
-                                       cc_gps_sat[i] = new AltosGPSSat(svid, cc_n0);
-                               }
-                       }
-                       if (line.startsWith("done"))
-                               break;
-                       if (line.startsWith("Syntax error"))
-                               break;
-               }
-       }
-}
-
 public class AltosIdleMonitor extends Thread {
        AltosLink               link;
        AltosIdleMonitorListener        listener;
@@ -341,8 +258,7 @@ public class AltosIdleMonitor extends Thread {
        }
 
        void update_state() throws InterruptedException, TimeoutException {
-               AltosRecord     record;
-               int             rssi;
+               AltosRecord     record = null;
 
                try {
                        if (remote) {
@@ -352,20 +268,7 @@ public class AltosIdleMonitor extends Thread {
                                link.flush_input();
                        config_data = new AltosConfigData(link);
                        if (config_data.product.startsWith("TeleMetrum")) {
-                               AltosRecordTM record_tm = new AltosRecordTM();
-                               AltosSensorTM sensor = new AltosSensorTM(link);
-                               record_tm.accel = sensor.accel;
-                               record_tm.pres = sensor.pres;
-                               record_tm.batt = sensor.batt;
-                               record_tm.temp = sensor.temp;
-                               record_tm.drogue = sensor.drogue;
-                               record_tm.main = sensor.main;
-                               record_tm.ground_accel = record_tm.accel;
-                               record_tm.ground_pres = record_tm.pres;
-                               record_tm.accel_plus_g = config_data.accel_cal_plus;
-                               record_tm.accel_minus_g = config_data.accel_cal_minus;
-                               record_tm.tick = sensor.tick;
-                               record = record_tm;
+                               record = new AltosSensorTM(link, config_data);
                        } else if (config_data.product.startsWith("MegaMetrum")) {
                                AltosRecordMM record_mm = new AltosRecordMM();
                                AltosSensorMM sensor = new AltosSensorMM(link);
@@ -392,24 +295,27 @@ public class AltosIdleMonitor extends Thread {
                                record = new AltosRecord();
 
                        gps = new AltosGPSQuery(link, config_data);
+
+                       record.version = 0;
+                       record.callsign = config_data.callsign;
+                       record.serial = config_data.serial;
+                       record.flight = config_data.log_available() > 0 ? 255 : 0;
+                       record.status = 0;
+                       record.state = AltosLib.ao_flight_idle;
+                       record.gps = gps;
+                       record.new_gps = true;
+                       state = new AltosState (record, state);
                } finally {
                        if (remote) {
                                link.stop_remote();
-                               rssi = AltosRSSI();
-                       } else
-                               rssi = 0;
+                               if (record != null)
+                                       record.rssi = AltosRSSI();
+                       } else {
+                               if (record != null)
+                                       record.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 = rssi;
-               record.status = 0;
-               record.state = AltosLib.ao_flight_idle;
-
-               record.gps = gps;
-               state = new AltosState (record, state);
        }
 
        public void set_frequency(double in_frequency) {