altoslib: Compute tilt angle from eeprom data
[fw/altos] / altoslib / AltosConfigData.java
index 847436cd0b0abc2d68a2fc0b1e7dec18b6686a91..a9e863c7759edac882571fa00ab7904d190b7602 100644 (file)
@@ -31,6 +31,7 @@ public class AltosConfigData implements Iterable<String> {
        public int      log_format;
        public int      log_space;
        public String   version;
+       public int      altitude_32;
 
        /* Strings returned */
        public LinkedList<String>       lines;
@@ -57,6 +58,7 @@ public class AltosConfigData implements Iterable<String> {
 
        /* HAS_LOG */
        public int      flight_log_max;
+       public int      log_fixed;
 
        /* HAS_IGNITE */
        public int      ignite_mode;
@@ -88,6 +90,9 @@ public class AltosConfigData implements Iterable<String> {
        public int      tracker_motion;
        public int      tracker_interval;
 
+       /* HAS_GYRO */
+       public int      accel_zero_along, accel_zero_across, accel_zero_through;
+
        public static String get_string(String line, String label) throws  ParseException {
                if (line.startsWith(label)) {
                        String  quoted = line.substring(label.length()).trim();
@@ -243,6 +248,7 @@ public class AltosConfigData implements Iterable<String> {
                pad_orientation = -1;
 
                flight_log_max = -1;
+               log_fixed = -1;
                ignite_mode = -1;
 
                aes_key = "";
@@ -263,6 +269,10 @@ public class AltosConfigData implements Iterable<String> {
                storage_size = -1;
                storage_erase_unit = -1;
                stored_flight = 0;
+
+               accel_zero_along = -1;
+               accel_zero_across = -1;
+               accel_zero_through = -1;
        }
 
        public void parse_line(String line) {
@@ -274,6 +284,7 @@ public class AltosConfigData implements Iterable<String> {
                try { flight = get_int(line, "current-flight"); } catch (Exception e) {}
                try { log_format = get_int(line, "log-format"); } catch (Exception e) {}
                try { log_space = get_int(line, "log-space"); } catch (Exception e) {}
+               try { altitude_32 = get_int(line, "altitude-32"); } catch (Exception e) {}
                try { version = get_string(line, "software-version"); } catch (Exception e) {}
 
                /* Version also contains MS5607 info, which we ignore here */
@@ -314,6 +325,7 @@ public class AltosConfigData implements Iterable<String> {
 
                /* HAS_LOG */
                try { flight_log_max = get_int(line, "Max flight log:"); } catch (Exception e) {}
+               try { log_fixed = get_int(line, "Log fixed:"); } catch (Exception e) {}
 
                /* HAS_IGNITE */
                try { ignite_mode = get_int(line, "Ignite mode:"); } catch (Exception e) {}
@@ -356,6 +368,18 @@ public class AltosConfigData implements Iterable<String> {
 
                /* Log listing replies */
                try { get_int(line, "flight"); stored_flight++; }  catch (Exception e) {}
+
+               /* HAS_GYRO */
+               try {
+                       if (line.startsWith("IMU call along")) {
+                               String[] bits = line.split("\\s+");
+                               if (bits.length >= 8) {
+                                       accel_zero_along = Integer.parseInt(bits[3]);
+                                       accel_zero_across = Integer.parseInt(bits[5]);
+                                       accel_zero_through = Integer.parseInt(bits[7]);
+                               }
+                       }
+               } catch (Exception e) {}
        }
 
        public AltosConfigData() {
@@ -381,6 +405,10 @@ public class AltosConfigData implements Iterable<String> {
                return radio_frequency >= 0 || radio_setting >= 0 || radio_channel >= 0;
        }
 
+       public boolean has_telemetry_rate() {
+               return telemetry_rate >= 0;
+       }
+
        public void set_frequency(double freq) {
                int     frequency = radio_frequency;
                int     setting = radio_setting;
@@ -420,6 +448,8 @@ public class AltosConfigData implements Iterable<String> {
                        return false;
                if (product.startsWith("TeleMetrum-v2"))
                        return false;
+               if (product.startsWith("EasyMega"))
+                       return false;
                return true;
        }
 
@@ -484,6 +514,7 @@ public class AltosConfigData implements Iterable<String> {
                dest.set_serial(serial);
                dest.set_product(product);
                dest.set_version(version);
+               dest.set_altitude_32(altitude_32);
                dest.set_main_deploy(main_deploy);
                dest.set_apogee_delay(apogee_delay);
                dest.set_apogee_lockout(apogee_lockout);
@@ -495,6 +526,9 @@ public class AltosConfigData implements Iterable<String> {
                if (log_space() == 0)
                        max_enabled = false;
 
+               if (log_fixed > 0)
+                       max_enabled = false;
+
                switch (log_format) {
                case AltosLib.AO_LOG_FORMAT_TINY:
                        max_enabled = false;
@@ -549,20 +583,39 @@ public class AltosConfigData implements Iterable<String> {
                                                        radio_calibration);
                        /* When remote, reset the dongle frequency at the same time */
                        if (remote) {
+                               link.flush_output();
                                link.stop_remote();
                                link.set_radio_frequency(frequency);
+                               link.flush_output();
                                link.start_remote();
                        }
                }
 
-               if (callsign != null)
+               if (telemetry_rate >= 0) {
+                       link.printf("c T %d\n", telemetry_rate);
+                       if (remote) {
+                               link.flush_output();
+                               link.stop_remote();
+                               link.set_telemetry_rate(telemetry_rate);
+                               link.flush_output();
+                               link.start_remote();
+                       }
+               }
+
+               if (callsign != null) {
                        link.printf("c c %s\n", callsign);
+                       if (remote) {
+                               link.flush_output();
+                               link.stop_remote();
+                               link.set_callsign(callsign);
+                               link.flush_output();
+                               link.start_remote();
+                       }
+               }
+
                if (radio_enable >= 0)
                        link.printf("c e %d\n", radio_enable);
 
-               if (telemetry_rate >= 0)
-                       link.printf("c T %d\n", telemetry_rate);
-
                /* HAS_ACCEL */
                /* UI doesn't support accel cal */
                if (pad_orientation >= 0)
@@ -603,6 +656,9 @@ public class AltosConfigData implements Iterable<String> {
                if (tracker_motion >= 0 && tracker_interval >= 0)
                        link.printf("c t %d %d\n", tracker_motion, tracker_interval);
 
+               /* HAS_GYRO */
+               /* UI doesn't support accel cal */
+
                link.printf("c w\n");
                link.flush_output();
        }