ICP3 working
[fw/altos] / altosui / AltosIdleMonitorUI.java
index 8eb0d520c339f88ad5d99c5a87d1f9561e580dfd..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;
                }
@@ -177,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) {
@@ -190,19 +207,23 @@ class AltosIdleMonitor extends Thread {
                        adc = new AltosADC(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;
@@ -324,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();