altosui: Fetch RF calibration value for TBT v4.0 units from web
authorKeith Packard <keithp@keithp.com>
Wed, 3 Oct 2018 00:03:28 +0000 (17:03 -0700)
committerKeith Packard <keithp@keithp.com>
Wed, 3 Oct 2018 00:03:28 +0000 (17:03 -0700)
We shipped a pile of TBT v4.0 units without programming the RF
calibration value into flash. This change checks to see if the target
is in the right serial number range and has the default RF calibration
value, in which case it fetches the RF calibration value from our web
site.

Signed-off-by: Keith Packard <keithp@keithp.com>
altoslib/AltosLib.java
altoslib/AltosRomconfig.java
altoslib/Makefile.am
altosuilib/AltosFlashUI.java

index 254448d..40d7a27 100644 (file)
@@ -230,6 +230,9 @@ public class AltosLib {
        public static final String launch_sites_env = "LAUNCH_SITES";
 //     public static final String launch_sites_url = "file:///home/keithp/misc/text/altusmetrum/AltOS/launch-sites.txt";
 
+       public static final String unit_info_url = "https://altusmetrum.org/cgi-bin/unitinfo.cgi?sn=%d";
+       public static final String unit_info_env = "UNIT_INFO";
+
        public static final int ao_telemetry_standard_len = 32;
        public static final int ao_telemetry_0_9_len = 95;
        public static final int ao_telemetry_0_8_len = 94;
index ccd0127..ebeb76f 100644 (file)
 package org.altusmetrum.altoslib_13;
 
 import java.io.*;
+import java.util.concurrent.*;
 
-public class AltosRomconfig {
+public class AltosRomconfig implements AltosUnitInfoListener {
        public boolean  valid;
+       public boolean  radio_calibration_broken;
        public int      version;
        public int      check;
        public int      serial_number;
@@ -117,6 +119,29 @@ public class AltosRomconfig {
        final static String ao_radio_cal = "ao_radio_cal";
        final static String ao_usb_descriptors = "ao_usb_descriptors";
 
+       Semaphore       unit_info_done;
+
+       public void notify_unit_info(AltosUnitInfo unit_info) {
+               unit_info_done.release();
+       }
+
+       private void fetch_radio_cal() {
+               unit_info_done = new Semaphore(0);
+               AltosUnitInfo   info = new AltosUnitInfo(serial_number, this);
+
+               /* Block waiting for the rf calibration data */
+               radio_calibration_broken = true;
+               try {
+                       unit_info_done.acquire();
+                       int new_cal = info.rfcal();
+                       if (new_cal != AltosLib.MISSING) {
+                               radio_calibration = new_cal;
+                               radio_calibration_broken = false;
+                       }
+               } catch (InterruptedException ie) {
+               }
+       }
+
        public AltosRomconfig(AltosHexfile hexfile) {
                try {
                        version = get_int(hexfile, ao_romconfig_version, 2);
@@ -131,7 +156,18 @@ public class AltosRomconfig {
                                        } catch (AltosNoSymbol missing) {
                                                radio_calibration = 0;
                                        }
+
                                        valid = true;
+
+                                       /* XXX TeleBT v4.0 units originally shipped without RF calibration programmed. Go fetch
+                                        * the correct value from the web site
+                                        */
+                                       if (serial_number == 2584 ||
+                                           (3686 <= serial_number && serial_number <= 3938 && radio_calibration == 5695485))
+                                       {
+                                               fetch_radio_cal();
+                                       }
+
                                        break;
                                }
                        }
index 7c5d767..9297633 100644 (file)
@@ -183,7 +183,9 @@ altoslib_JAVA = \
        AltosMapLoader.java \
        AltosMapTypeListener.java \
        AltosJson.java \
-       AltosVersion.java
+       AltosVersion.java \
+       AltosUnitInfo.java \
+       AltosUnitInfoListener.java
 
 JAR=altoslib_$(ALTOSLIB_VERSION).jar
 
index 6c9cae5..b91776a 100644 (file)
@@ -325,6 +325,17 @@ public class AltosFlashUI
                                return false;
                }
 
+               if (existing_config.radio_calibration_broken) {
+                       int ret = JOptionPane.showConfirmDialog(this,
+                                                               String.format("Radio calibration value %d may be incorrect\nFlash anyways?",
+                                                                             existing_config.radio_calibration),
+                                                               "Radio Calibration Invalid",
+                                                               JOptionPane.YES_NO_OPTION);
+                       if (ret != JOptionPane.YES_OPTION)
+                               return false;
+               }
+
+
                new_config = AltosRomconfigUI.show(frame, existing_config);
                if (new_config == null)
                        return false;