altoslib: Support multiple telemetry rates
authorKeith Packard <keithp@keithp.com>
Thu, 3 Jul 2014 05:48:13 +0000 (22:48 -0700)
committerKeith Packard <keithp@keithp.com>
Sat, 5 Jul 2014 07:38:10 +0000 (00:38 -0700)
Altos now supports 2400 and 9600 baud in addition to the classic 38400
baud rate. Add support to altoslib for these as well

Signed-off-by: Keith Packard <keithp@keithp.com>
altoslib/AltosConfigData.java
altoslib/AltosConfigValues.java
altoslib/AltosFlightReader.java
altoslib/AltosLib.java
altoslib/AltosLink.java
altoslib/AltosPreferences.java
altoslib/AltosTelemetryReader.java

index 3bf8ea43d2ad4b0601fa975612947f0ea2ac5006..847436cd0b0abc2d68a2fc0b1e7dec18b6686a91 100644 (file)
@@ -46,6 +46,7 @@ public class AltosConfigData implements Iterable<String> {
        public String   callsign;
        public int      radio_enable;
        public int      radio_calibration;
        public String   callsign;
        public int      radio_enable;
        public int      radio_calibration;
+       public int      telemetry_rate;
        /* Old HAS_RADIO values */
        public int      radio_channel;
        public int      radio_setting;
        /* Old HAS_RADIO values */
        public int      radio_channel;
        public int      radio_setting;
@@ -235,6 +236,7 @@ public class AltosConfigData implements Iterable<String> {
                radio_calibration = -1;
                radio_channel = -1;
                radio_setting = -1;
                radio_calibration = -1;
                radio_channel = -1;
                radio_setting = -1;
+               telemetry_rate = -1;
 
                accel_cal_plus = -1;
                accel_cal_minus = -1;
 
                accel_cal_plus = -1;
                accel_cal_minus = -1;
@@ -292,6 +294,7 @@ public class AltosConfigData implements Iterable<String> {
                try { callsign = get_string(line, "Callsign:"); } catch (Exception e) {}
                try { radio_enable = get_int(line, "Radio enable:"); } catch (Exception e) {}
                try { radio_calibration = get_int(line, "Radio cal:"); } catch (Exception e) {}
                try { callsign = get_string(line, "Callsign:"); } catch (Exception e) {}
                try { radio_enable = get_int(line, "Radio enable:"); } catch (Exception e) {}
                try { radio_calibration = get_int(line, "Radio cal:"); } catch (Exception e) {}
+               try { telemetry_rate = get_int(line, "Telemetry rate:"); } catch (Exception e) {}
 
                /* Old HAS_RADIO values */
                try { radio_channel = get_int(line, "Radio channel:"); } catch (Exception e) {}
 
                /* Old HAS_RADIO values */
                try { radio_channel = get_int(line, "Radio channel:"); } catch (Exception e) {}
@@ -440,6 +443,8 @@ public class AltosConfigData implements Iterable<String> {
                        callsign = source.callsign();
                if (radio_calibration >= 0)
                        radio_calibration = source.radio_calibration();
                        callsign = source.callsign();
                if (radio_calibration >= 0)
                        radio_calibration = source.radio_calibration();
+               if (telemetry_rate >= 0)
+                       telemetry_rate = source.telemetry_rate();
 
                /* HAS_ACCEL */
                if (pad_orientation >= 0)
 
                /* HAS_ACCEL */
                if (pad_orientation >= 0)
@@ -484,6 +489,7 @@ public class AltosConfigData implements Iterable<String> {
                dest.set_apogee_lockout(apogee_lockout);
                dest.set_radio_calibration(radio_calibration);
                dest.set_radio_frequency(frequency());
                dest.set_apogee_lockout(apogee_lockout);
                dest.set_radio_calibration(radio_calibration);
                dest.set_radio_frequency(frequency());
+               dest.set_telemetry_rate(telemetry_rate);
                boolean max_enabled = true;
 
                if (log_space() == 0)
                boolean max_enabled = true;
 
                if (log_space() == 0)
@@ -554,6 +560,9 @@ public class AltosConfigData implements Iterable<String> {
                if (radio_enable >= 0)
                        link.printf("c e %d\n", radio_enable);
 
                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)
                /* HAS_ACCEL */
                /* UI doesn't support accel cal */
                if (pad_orientation >= 0)
index b0c49e98fe0af83bf23a02c8a5c5acf2821ab971..987da53be7e0bda21519f033bf7dd00324e25674 100644 (file)
@@ -53,6 +53,10 @@ public interface AltosConfigValues {
 
        public abstract String callsign();
 
 
        public abstract String callsign();
 
+       public abstract void set_telemetry_rate(int new_telemetry_rate);
+
+       public abstract int telemetry_rate() throws AltosConfigDataException;
+
        public abstract void set_flight_log_max(int new_flight_log_max);
 
        public abstract void set_flight_log_max_enabled(boolean enable);
        public abstract void set_flight_log_max(int new_flight_log_max);
 
        public abstract void set_flight_log_max_enabled(boolean enable);
index ac151396e7bc2706495d21b0fca1d4cb5f8ba566..c0565e8898d926a6320f43a1191d1d575aa8a019 100644 (file)
@@ -38,12 +38,18 @@ public class AltosFlightReader {
 
        public void set_telemetry(int telemetry) { }
 
 
        public void set_telemetry(int telemetry) { }
 
+       public void set_telemetry_rate(int telemetry_rate) throws InterruptedException, TimeoutException { }
+
        public void save_telemetry() { }
 
        public void save_telemetry() { }
 
+       public void save_telemetry_rate() { }
+
        public void update(AltosState state) throws InterruptedException { }
 
        public boolean supports_telemetry(int telemetry) { return false; }
 
        public void update(AltosState state) throws InterruptedException { }
 
        public boolean supports_telemetry(int telemetry) { return false; }
 
+       public boolean supports_telemetry_rate(int telemetry_rate) { return false; }
+
        public File backing_file() { return null; }
 
        public boolean has_monitor_battery() throws InterruptedException { return false; }
        public File backing_file() { return null; }
 
        public boolean has_monitor_battery() throws InterruptedException { return false; }
index ec32fffc3fcb6b8a8b07269eaced0db4e406a139..c2ec0e3bb1a3af007093832fe2cf6d859e9e1c41 100644 (file)
@@ -161,6 +161,15 @@ public class AltosLib {
                "Off", "Standard Telemetry", "TeleMetrum v0.9", "TeleMetrum v0.8"
        };
 
                "Off", "Standard Telemetry", "TeleMetrum v0.9", "TeleMetrum v0.8"
        };
 
+       public static final int ao_telemetry_rate_38400 = 0;
+       public static final int ao_telemetry_rate_9600 = 1;
+       public static final int ao_telemetry_rate_2400 = 2;
+       public static final int ao_telemetry_rate_max = 2;
+
+       public static final Integer[] ao_telemetry_rate_values = {
+               38400, 9600, 2400
+       };
+
        public static final String launch_sites_url = "http://www.altusmetrum.org/AltOS/launch-sites.txt";
 
        public static final int ao_telemetry_standard_len = 32;
        public static final String launch_sites_url = "http://www.altusmetrum.org/AltOS/launch-sites.txt";
 
        public static final int ao_telemetry_standard_len = 32;
index ef40c8cb4cbcaebd5d6e98e21810bc65394e9cd5..eadab5dff6d3029b77c7e8b08e84c0444f6cba79 100644 (file)
@@ -274,6 +274,8 @@ public abstract class AltosLink implements Runnable {
        }
 
        public void flush_output() {
        }
 
        public void flush_output() {
+               if (pending_output == null)
+                       return;
                for (String s : pending_output)
                        System.out.print(s);
                pending_output.clear();
                for (String s : pending_output)
                        System.out.print(s);
                pending_output.clear();
@@ -305,6 +307,7 @@ public abstract class AltosLink implements Runnable {
         */
        public boolean monitor_mode = false;
        public int telemetry = AltosLib.ao_telemetry_standard;
         */
        public boolean monitor_mode = false;
        public int telemetry = AltosLib.ao_telemetry_standard;
+       public int telemetry_rate = AltosLib.ao_telemetry_rate_38400;
        public double frequency;
        public String callsign;
        AltosConfigData config_data;
        public double frequency;
        public String callsign;
        AltosConfigData config_data;
@@ -356,6 +359,15 @@ public abstract class AltosLink implements Runnable {
                flush_output();
        }
 
                flush_output();
        }
 
+       public void set_telemetry_rate(int in_telemetry_rate) {
+               telemetry_rate = in_telemetry_rate;
+               if (monitor_mode)
+                       printf("m 0\nc T %d\nm %x\n", telemetry_rate, telemetry_len());
+               else
+                       printf("c T %d\n", telemetry_rate);
+               flush_output();
+       }
+
        public void set_monitor(boolean monitor) {
                monitor_mode = monitor;
                if (monitor)
        public void set_monitor(boolean monitor) {
                monitor_mode = monitor;
                if (monitor)
@@ -383,7 +395,7 @@ public abstract class AltosLink implements Runnable {
                flush_output();
        }
 
                flush_output();
        }
 
-       public AltosConfigData config_data() throws InterruptedException, TimeoutException {
+       public AltosConfigData config_data() throws InterruptedException, TimeoutException {
                synchronized(config_data_lock) {
                        if (config_data == null) {
                                printf("m 0\n");
                synchronized(config_data_lock) {
                        if (config_data == null) {
                                printf("m 0\n");
index 159951e46f83ffd501f94ee46989acdd275536ef..72cfeb4bc5a47e81c63c2ba0582e0de3438b5263 100644 (file)
@@ -35,6 +35,9 @@ public class AltosPreferences {
        /* telemetry format preference name */
        public final static String telemetryPreferenceFormat = "TELEMETRY-%d";
 
        /* telemetry format preference name */
        public final static String telemetryPreferenceFormat = "TELEMETRY-%d";
 
+       /* telemetry rate format preference name */
+       public final static String telemetryRatePreferenceFormat = "RATE-%d";
+
        /* voice preference name */
        public final static String voicePreference = "VOICE";
 
        /* voice preference name */
        public final static String voicePreference = "VOICE";
 
@@ -50,6 +53,9 @@ public class AltosPreferences {
        /* scanning telemetry preferences name */
        public final static String scanningTelemetryPreference = "SCANNING-TELEMETRY";
 
        /* scanning telemetry preferences name */
        public final static String scanningTelemetryPreference = "SCANNING-TELEMETRY";
 
+       /* scanning telemetry rate preferences name */
+       public final static String scanningTelemetryRatePreference = "SCANNING-RATE";
+
        /* Launcher serial preference name */
        public final static String launcherSerialPreference = "LAUNCHER-SERIAL";
 
        /* Launcher serial preference name */
        public final static String launcherSerialPreference = "LAUNCHER-SERIAL";
 
@@ -74,6 +80,9 @@ public class AltosPreferences {
        /* Telemetry (map serial to telemetry format) */
        public static Hashtable<Integer, Integer> telemetries;
 
        /* Telemetry (map serial to telemetry format) */
        public static Hashtable<Integer, Integer> telemetries;
 
+       /* Telemetry rate (map serial to telemetry format) */
+       public static Hashtable<Integer, Integer> telemetry_rates;
+
        /* Voice preference */
        public static boolean voice;
 
        /* Voice preference */
        public static boolean voice;
 
@@ -86,6 +95,8 @@ public class AltosPreferences {
        /* Scanning telemetry */
        public static int scanning_telemetry;
 
        /* Scanning telemetry */
        public static int scanning_telemetry;
 
+       public static int scanning_telemetry_rate;
+
        /* List of frequencies */
        public final static String common_frequencies_node_name = "COMMON-FREQUENCIES";
        public static AltosFrequency[] common_frequencies;
        /* List of frequencies */
        public final static String common_frequencies_node_name = "COMMON-FREQUENCIES";
        public static AltosFrequency[] common_frequencies;
@@ -159,12 +170,16 @@ public class AltosPreferences {
 
                telemetries = new Hashtable<Integer,Integer>();
 
 
                telemetries = new Hashtable<Integer,Integer>();
 
+               telemetry_rates = new Hashtable<Integer,Integer>();
+
                voice = backend.getBoolean(voicePreference, true);
 
                callsign = backend.getString(callsignPreference,"N0CALL");
 
                scanning_telemetry = backend.getInt(scanningTelemetryPreference,(1 << AltosLib.ao_telemetry_standard));
 
                voice = backend.getBoolean(voicePreference, true);
 
                callsign = backend.getString(callsignPreference,"N0CALL");
 
                scanning_telemetry = backend.getInt(scanningTelemetryPreference,(1 << AltosLib.ao_telemetry_standard));
 
+               scanning_telemetry_rate = backend.getInt(scanningTelemetryRatePreference,(1 << AltosLib.ao_telemetry_rate_38400));
+
                launcher_serial = backend.getInt(launcherSerialPreference, 0);
 
                launcher_channel = backend.getInt(launcherChannelPreference, 0);
                launcher_serial = backend.getInt(launcherSerialPreference, 0);
 
                launcher_channel = backend.getInt(launcherChannelPreference, 0);
@@ -266,6 +281,25 @@ public class AltosPreferences {
                }
        }
 
                }
        }
 
+       public static void set_telemetry_rate(int serial, int new_telemetry_rate) {
+               synchronized (backend) {
+                       telemetry_rates.put(serial, new_telemetry_rate);
+                       backend.putInt(String.format(telemetryRatePreferenceFormat, serial), new_telemetry_rate);
+                       flush_preferences();
+               }
+       }
+
+       public static int telemetry_rate(int serial) {
+               synchronized (backend) {
+                       if (telemetry_rates.containsKey(serial))
+                               return telemetry_rates.get(serial);
+                       int telemetry_rate = backend.getInt(String.format(telemetryRatePreferenceFormat, serial),
+                                                           AltosLib.ao_telemetry_rate_38400);
+                       telemetry_rates.put(serial, telemetry_rate);
+                       return telemetry_rate;
+               }
+       }
+
        public static void set_scanning_telemetry(int new_scanning_telemetry) {
                synchronized (backend) {
                        scanning_telemetry = new_scanning_telemetry;
        public static void set_scanning_telemetry(int new_scanning_telemetry) {
                synchronized (backend) {
                        scanning_telemetry = new_scanning_telemetry;
@@ -280,6 +314,20 @@ public class AltosPreferences {
                }
        }
 
                }
        }
 
+       public static void set_scanning_telemetry_rate(int new_scanning_telemetry_rate) {
+               synchronized (backend) {
+                       scanning_telemetry_rate = new_scanning_telemetry_rate;
+                       backend.putInt(scanningTelemetryRatePreference, scanning_telemetry_rate);
+                       flush_preferences();
+               }
+       }
+
+       public static int scanning_telemetry_rate() {
+               synchronized(backend) {
+                       return scanning_telemetry_rate;
+               }
+       }
+
        public static void set_voice(boolean new_voice) {
                synchronized (backend) {
                        voice = new_voice;
        public static void set_voice(boolean new_voice) {
                synchronized (backend) {
                        voice = new_voice;
index 589f57f25f6ac5e200d1f2cc81f892d33c18945e..5ed501348b07174bb0debee09d499ada26bffb56 100644 (file)
@@ -26,6 +26,7 @@ public class AltosTelemetryReader extends AltosFlightReader {
        AltosLog        log;
        double          frequency;
        int             telemetry;
        AltosLog        log;
        double          frequency;
        int             telemetry;
+       int             telemetry_rate;
        AltosState      state = null;
 
        LinkedBlockingQueue<AltosLine> telem;
        AltosState      state = null;
 
        LinkedBlockingQueue<AltosLine> telem;
@@ -92,6 +93,23 @@ public class AltosTelemetryReader extends AltosFlightReader {
                }
        }
 
                }
        }
 
+       public boolean supports_telemetry_rate(int telemetry_rate) {
+               try {
+                       /* Version 1.4.1.1 supports all rates, older versions don't */
+                       if (link.config_data().compare_version("1.4.1.1") >= 0)
+                               return true;
+
+                       if (telemetry_rate == AltosLib.ao_telemetry_rate_38400)
+                               return true;
+                       else
+                               return false;
+               } catch (InterruptedException ie) {
+                       return false;
+               } catch (TimeoutException te) {
+                       return true;
+               }
+       }
+
        public void save_frequency() {
                AltosPreferences.set_frequency(link.serial, frequency);
        }
        public void save_frequency() {
                AltosPreferences.set_frequency(link.serial, frequency);
        }
@@ -105,6 +123,15 @@ public class AltosTelemetryReader extends AltosFlightReader {
                AltosPreferences.set_telemetry(link.serial, telemetry);
        }
 
                AltosPreferences.set_telemetry(link.serial, telemetry);
        }
 
+       public void set_telemetry_rate(int in_telemetry_rate) {
+               telemetry_rate = in_telemetry_rate;
+               link.set_telemetry_rate(telemetry_rate);
+       }
+
+       public void save_telemetry_rate() {
+               AltosPreferences.set_telemetry_rate(link.serial, telemetry_rate);
+       }
+
        public void set_monitor(boolean monitor) {
                link.set_monitor(monitor);
        }
        public void set_monitor(boolean monitor) {
                link.set_monitor(monitor);
        }
@@ -133,6 +160,8 @@ public class AltosTelemetryReader extends AltosFlightReader {
                        set_frequency(frequency);
                        telemetry = AltosPreferences.telemetry(link.serial);
                        set_telemetry(telemetry);
                        set_frequency(frequency);
                        telemetry = AltosPreferences.telemetry(link.serial);
                        set_telemetry(telemetry);
+                       telemetry_rate = AltosPreferences.telemetry_rate(link.serial);
+                       set_telemetry_rate(telemetry_rate);
                        link.add_monitor(telem);
                        success = true;
                } finally {
                        link.add_monitor(telem);
                        success = true;
                } finally {