From: Keith Packard Date: Sun, 21 Oct 2018 00:22:59 +0000 (-0700) Subject: altoslib: Add support for TeleGPS v2 X-Git-Tag: 1.9~25 X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=commitdiff_plain;h=f13e294d4644096b0529383c1d60d5e4b7916d76 altoslib: Add support for TeleGPS v2 The battery voltage ADC values are different from TeleGPS v1 (max 4095 instead of 32767). Signed-off-by: Keith Packard --- diff --git a/altoslib/AltosConvert.java b/altoslib/AltosConvert.java index e1930430..ce1b8f7f 100644 --- a/altoslib/AltosConvert.java +++ b/altoslib/AltosConvert.java @@ -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; diff --git a/altoslib/AltosIdleFetch.java b/altoslib/AltosIdleFetch.java index 884d8761..a68ccac7 100644 --- a/altoslib/AltosIdleFetch.java +++ b/altoslib/AltosIdleFetch.java @@ -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 index 485e8b3c..00000000 --- a/altoslib/AltosSensorTGPS.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright © 2015 Keith Packard - * - * 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 index 00000000..cdd19217 --- /dev/null +++ b/altoslib/AltosSensorTGPS1.java @@ -0,0 +1,56 @@ +/* + * Copyright © 2015 Keith Packard + * + * 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 index 00000000..ceca977e --- /dev/null +++ b/altoslib/AltosSensorTGPS2.java @@ -0,0 +1,56 @@ +/* + * Copyright © 2015 Keith Packard + * + * 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++; + } + } +} + diff --git a/altoslib/AltosTelemetryConfiguration.java b/altoslib/AltosTelemetryConfiguration.java index 4411a77d..22fd8568 100644 --- a/altoslib/AltosTelemetryConfiguration.java +++ b/altoslib/AltosTelemetryConfiguration.java @@ -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()); diff --git a/altoslib/Makefile.am b/altoslib/Makefile.am index 2f4e5959..447830e5 100644 --- a/altoslib/Makefile.am +++ b/altoslib/Makefile.am @@ -108,7 +108,8 @@ altoslib_JAVA = \ AltosSensorTMini3.java \ AltosSensorMega.java \ AltosSensorMetrum.java \ - AltosSensorTGPS.java \ + AltosSensorTGPS1.java \ + AltosSensorTGPS2.java \ AltosState.java \ AltosStateName.java \ AltosStringInputStream.java \