altoslib: Add support for TeleGPS v2
authorKeith Packard <keithp@keithp.com>
Sun, 21 Oct 2018 00:22:59 +0000 (17:22 -0700)
committerKeith Packard <keithp@keithp.com>
Sun, 21 Oct 2018 00:31:57 +0000 (17:31 -0700)
The battery voltage ADC values are different from TeleGPS v1 (max 4095
instead of 32767).

Signed-off-by: Keith Packard <keithp@keithp.com>
altoslib/AltosConvert.java
altoslib/AltosIdleFetch.java
altoslib/AltosSensorTGPS.java [deleted file]
altoslib/AltosSensorTGPS1.java [new file with mode: 0644]
altoslib/AltosSensorTGPS2.java [new file with mode: 0644]
altoslib/AltosTelemetryConfiguration.java
altoslib/Makefile.am

index e1930430add0de07f49812808e053edfa5b0e38e..ce1b8f7f14f7733a29722e6eedd62090733ed63f 100644 (file)
@@ -258,7 +258,13 @@ public class AltosConvert {
                return sensor / 32767.0 * supply * 127/27;
        }
 
-       static double tele_gps_voltage(int sensor) {
+       static double tele_gps_1_voltage(int sensor) {
+               double  supply = 3.3;
+
+               return sensor / 32767.0 * supply * (5.6 + 10.0) / 10.0;
+       }
+
+       static double tele_gps_2_voltage(int sensor) {
                double  supply = 3.3;
 
                return sensor / 4095.0 * supply * (5.6 + 10.0) / 10.0;
index 884d87618b5ac0b52d846fb5d68d97bc0dd56eeb..a68ccac70357f3fa8e607826ca33a977b84878d9 100644 (file)
@@ -40,8 +40,9 @@ class AltosIdler {
        static final int        idle_sensor_emini1 = 13;
        static final int        idle_sensor_emini2 = 14;
        static final int        idle_sensor_tmini2 = 15;
-       static final int        idle_sensor_tgps = 16;
-       static final int        idle_sensor_tmini3 = 17;
+       static final int        idle_sensor_tgps1 = 16;
+       static final int        idle_sensor_tgps2 = 17;
+       static final int        idle_sensor_tmini3 = 18;
 
        public void provide_data(AltosDataListener listener, AltosLink link) throws InterruptedException, TimeoutException, AltosUnknownProduct {
                for (int idler : idlers) {
@@ -82,8 +83,11 @@ class AltosIdler {
                        case idle_sensor_tmini2:
                                AltosSensorTMini2.provide_data(listener, link);
                                break;
-                       case idle_sensor_tgps:
-                               AltosSensorTGPS.provide_data(listener, link);
+                       case idle_sensor_tgps1:
+                               AltosSensorTGPS1.provide_data(listener, link);
+                               break;
+                       case idle_sensor_tgps2:
+                               AltosSensorTGPS2.provide_data(listener, link);
                                break;
                        case idle_sensor_tmini3:
                                AltosSensorTMini3.provide_data(listener, link);
@@ -170,9 +174,12 @@ public class AltosIdleFetch implements AltosDataProvider {
                               AltosIdler.idle_ms5607,
                               AltosIdler.idle_imu,
                               AltosIdler.idle_sensor_mega),
-               new AltosIdler("TeleGPS",
+               new AltosIdler("TeleGPS-v1",
+                              AltosIdler.idle_gps,
+                              AltosIdler.idle_sensor_tgps1),
+               new AltosIdler("TeleGPS-v2",
                               AltosIdler.idle_gps,
-                              AltosIdler.idle_sensor_tgps),
+                              AltosIdler.idle_sensor_tgps2),
        };
 
        AltosLink               link;
diff --git a/altoslib/AltosSensorTGPS.java b/altoslib/AltosSensorTGPS.java
deleted file mode 100644 (file)
index 485e8b3..0000000
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright © 2015 Keith Packard <keithp@keithp.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
- */
-
-package org.altusmetrum.altoslib_13;
-
-import java.util.concurrent.TimeoutException;
-
-public class AltosSensorTGPS {
-       public int      tick;
-       public int      batt;
-
-       static public void provide_data(AltosDataListener listener, AltosLink link) throws InterruptedException {
-               try {
-                       AltosSensorTGPS sensor_tgps = new AltosSensorTGPS(link);
-
-                       if (sensor_tgps == null)
-                               return;
-                       listener.set_battery_voltage(AltosConvert.tele_gps_voltage(sensor_tgps.batt));
-
-               } catch (TimeoutException te) {
-               }
-       }
-
-       public AltosSensorTGPS(AltosLink link) throws InterruptedException, TimeoutException {
-               String[] items = link.adc();
-               for (int i = 0; i < items.length - 1;) {
-                       if (items[i].equals("tick:")) {
-                               tick = Integer.parseInt(items[i+1]);
-                               i += 2;
-                               continue;
-                       }
-                       if (items[i].equals("batt:")) {
-                               batt = Integer.parseInt(items[i+1]);
-                               i += 2;
-                               continue;
-                       }
-                       i++;
-               }
-       }
-}
-
diff --git a/altoslib/AltosSensorTGPS1.java b/altoslib/AltosSensorTGPS1.java
new file mode 100644 (file)
index 0000000..cdd1921
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * Copyright © 2015 Keith Packard <keithp@keithp.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+
+package org.altusmetrum.altoslib_13;
+
+import java.util.concurrent.TimeoutException;
+
+public class AltosSensorTGPS1 {
+       public int      tick;
+       public int      batt;
+
+       static public void provide_data(AltosDataListener listener, AltosLink link) throws InterruptedException {
+               try {
+                       AltosSensorTGPS1        sensor_tgps = new AltosSensorTGPS1(link);
+
+                       if (sensor_tgps == null)
+                               return;
+                       listener.set_battery_voltage(AltosConvert.tele_gps_1_voltage(sensor_tgps.batt));
+
+               } catch (TimeoutException te) {
+               }
+       }
+
+       public AltosSensorTGPS1(AltosLink link) throws InterruptedException, TimeoutException {
+               String[] items = link.adc();
+               for (int i = 0; i < items.length - 1;) {
+                       if (items[i].equals("tick:")) {
+                               tick = Integer.parseInt(items[i+1]);
+                               i += 2;
+                               continue;
+                       }
+                       if (items[i].equals("batt:")) {
+                               batt = Integer.parseInt(items[i+1]);
+                               i += 2;
+                               continue;
+                       }
+                       i++;
+               }
+       }
+}
+
diff --git a/altoslib/AltosSensorTGPS2.java b/altoslib/AltosSensorTGPS2.java
new file mode 100644 (file)
index 0000000..ceca977
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * Copyright © 2015 Keith Packard <keithp@keithp.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+
+package org.altusmetrum.altoslib_13;
+
+import java.util.concurrent.TimeoutException;
+
+public class AltosSensorTGPS2 {
+       public int      tick;
+       public int      batt;
+
+       static public void provide_data(AltosDataListener listener, AltosLink link) throws InterruptedException {
+               try {
+                       AltosSensorTGPS2        sensor_tgps = new AltosSensorTGPS2(link);
+
+                       if (sensor_tgps == null)
+                               return;
+                       listener.set_battery_voltage(AltosConvert.tele_gps_2_voltage(sensor_tgps.batt));
+
+               } catch (TimeoutException te) {
+               }
+       }
+
+       public AltosSensorTGPS2(AltosLink link) throws InterruptedException, TimeoutException {
+               String[] items = link.adc();
+               for (int i = 0; i < items.length - 1;) {
+                       if (items[i].equals("tick:")) {
+                               tick = Integer.parseInt(items[i+1]);
+                               i += 2;
+                               continue;
+                       }
+                       if (items[i].equals("batt:")) {
+                               batt = Integer.parseInt(items[i+1]);
+                               i += 2;
+                               continue;
+                       }
+                       i++;
+               }
+       }
+}
+
index 4411a77d44c635d601582b17cf3805f09b5a50d3..22fd8568cab896f9cf42bfa1268901ba68bf6fe6 100644 (file)
@@ -43,9 +43,15 @@ public class AltosTelemetryConfiguration extends AltosTelemetryStandard {
                listener.set_device_type(device_type());
                cal_data.set_flight(flight());
                cal_data.set_config(config_major(), config_minor(), flight_log_max());
-               if (device_type() == AltosLib.product_telegps)
-                       listener.set_battery_voltage(AltosConvert.tele_gps_voltage(v_batt()));
-               else
+               if (device_type() == AltosLib.product_telegps) {
+                       int v_batt = v_batt();
+                       double batt;
+                       if (v_batt > 4095)
+                               batt = AltosConvert.tele_gps_1_voltage(v_batt);
+                       else
+                               batt = AltosConvert.tele_gps_2_voltage(v_batt);
+                       listener.set_battery_voltage(batt);
+               } else
                        cal_data.set_flight_params(apogee_delay() / 100.0, main_deploy());
 
                cal_data.set_callsign(callsign());
index 2f4e5959e2bd978991e7c8e100ed440b8a0ca1ef..447830e547f242175702bd16c7612e5d0202431c 100644 (file)
@@ -108,7 +108,8 @@ altoslib_JAVA = \
        AltosSensorTMini3.java \
        AltosSensorMega.java \
        AltosSensorMetrum.java \
-       AltosSensorTGPS.java \
+       AltosSensorTGPS1.java \
+       AltosSensorTGPS2.java \
        AltosState.java \
        AltosStateName.java \
        AltosStringInputStream.java \