From 1e4b8674d874a190eca1a98a397aaf0a9d15bda1 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 19 Oct 2018 13:19:03 -0700 Subject: altoslib: Add ADXL375 support and EasyMega v2.0 support EasyMega v2.0 replaces the MMA655X with an ADXL375 part. Signed-off-by: Keith Packard --- altoslib/AltosAdxl375.java | 93 +++++++++++++++++++++++++++++++++++++++++++ altoslib/AltosCalData.java | 26 +++++++++++- altoslib/AltosConfigData.java | 16 ++++++++ altoslib/AltosIdleFetch.java | 12 +++++- altoslib/Makefile.am | 1 + 5 files changed, 145 insertions(+), 3 deletions(-) create mode 100644 altoslib/AltosAdxl375.java (limited to 'altoslib') diff --git a/altoslib/AltosAdxl375.java b/altoslib/AltosAdxl375.java new file mode 100644 index 00000000..2129ed6e --- /dev/null +++ b/altoslib/AltosAdxl375.java @@ -0,0 +1,93 @@ +/* + * Copyright © 2012 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.*; + +public class AltosAdxl375 implements Cloneable { + + private int accel; + private int axis; + + public static final int X_AXIS = 0; + public static final int Y_AXIS = 1; + public static final int Z_AXIS = 2; + + public boolean parse_line(String line) throws NumberFormatException { + if (line.startsWith("ADXL375 value")) { + System.out.printf("adxl parse line %s\n", line); + String[] items = line.split("\\s+"); + if (axis == AltosLib.MISSING) + throw new NumberFormatException("No ADXL375 axis specified"); + if (items.length >= 3) { + accel = Integer.parseInt(items[2 + axis]); + System.out.printf("accel %d\n", accel); + return true; + } + } + return false; + } + + public AltosAdxl375 clone() { + AltosAdxl375 n = new AltosAdxl375(axis); + + n.accel = accel; + return n; + } + + static public void provide_data(AltosDataListener listener, AltosLink link) throws InterruptedException, AltosUnknownProduct { + try { + AltosCalData cal_data = listener.cal_data(); + AltosAdxl375 adxl375 = new AltosAdxl375(link, cal_data.adxl375_axis); + + if (adxl375 != null) { + int accel = adxl375.accel; + if (cal_data.adxl375_inverted) + accel = -accel; + if (cal_data.pad_orientation == 1) + accel = -accel; + listener.set_acceleration(cal_data.acceleration(accel)); + } + } catch (TimeoutException te) { + } catch (NumberFormatException ne) { + } + } + + public AltosAdxl375() { + accel = AltosLib.MISSING; + axis = AltosLib.MISSING; + } + + public AltosAdxl375(int axis) { + this(); + this.axis = axis; + } + + public AltosAdxl375(AltosLink link, int axis) throws InterruptedException, TimeoutException, NumberFormatException { + this(axis); + link.printf("A\n"); + for (;;) { + String line = link.get_reply_no_dialog(5000); + if (line == null) + throw new TimeoutException(); + if (parse_line(line)) + break; + } + } +} diff --git a/altoslib/AltosCalData.java b/altoslib/AltosCalData.java index d448fdfe..c3d79250 100644 --- a/altoslib/AltosCalData.java +++ b/altoslib/AltosCalData.java @@ -133,6 +133,18 @@ public class AltosCalData { mma655x_inverted = inverted; } + public boolean adxl375_inverted = false; + + public void set_adxl375_inverted(boolean inverted) { + adxl375_inverted = inverted; + } + + public int adxl375_axis = AltosLib.MISSING; + + public void set_adxl375_axis(int axis) { + adxl375_axis = axis; + } + public int pad_orientation = AltosLib.MISSING; public void set_pad_orientation(int orientation) { @@ -142,7 +154,11 @@ public class AltosCalData { /* Compute acceleration */ public double acceleration(double sensor) { - return AltosConvert.acceleration_from_sensor(sensor, accel_plus_g, accel_minus_g, ground_accel); + double accel; + accel = AltosConvert.acceleration_from_sensor(sensor, accel_plus_g, accel_minus_g, ground_accel); + System.out.printf("acceleration %g (+ %g - %g g %g) -> %g\n", + sensor, accel_plus_g, accel_minus_g, ground_accel, accel); + return accel; } public AltosMs5607 ms5607 = null; @@ -404,6 +420,14 @@ public class AltosCalData { set_mma655x_inverted(config_data.mma655x_inverted()); } catch (AltosUnknownProduct up) { } + try { + set_adxl375_inverted(config_data.adxl375_inverted()); + } catch (AltosUnknownProduct up) { + } + try { + set_adxl375_axis(config_data.adxl375_axis()); + } catch (AltosUnknownProduct up) { + } set_pad_orientation(config_data.pad_orientation); } } diff --git a/altoslib/AltosConfigData.java b/altoslib/AltosConfigData.java index 48dab421..29ce033d 100644 --- a/altoslib/AltosConfigData.java +++ b/altoslib/AltosConfigData.java @@ -581,6 +581,22 @@ public class AltosConfigData { throw new AltosUnknownProduct(product); } + public boolean adxl375_inverted() throws AltosUnknownProduct { + if (product != null) { + if (product.startsWith("EasyMega-v2")) + return true; + } + throw new AltosUnknownProduct(product); + } + + public int adxl375_axis() throws AltosUnknownProduct { + if (product != null) { + if (product.startsWith("EasyMega-v2")) + return AltosAdxl375.X_AXIS; + } + throw new AltosUnknownProduct(product); + } + public void get_values(AltosConfigValues source) throws AltosConfigDataException { /* HAS_FLIGHT */ diff --git a/altoslib/AltosIdleFetch.java b/altoslib/AltosIdleFetch.java index 88a65e63..884d8761 100644 --- a/altoslib/AltosIdleFetch.java +++ b/altoslib/AltosIdleFetch.java @@ -32,7 +32,7 @@ class AltosIdler { static final int idle_mag = 2; static final int idle_mma655x = 4; static final int idle_ms5607 = 5; - + static final int idle_adxl375 = 6; static final int idle_sensor_tm = 10; static final int idle_sensor_metrum = 11; @@ -58,6 +58,9 @@ class AltosIdler { case idle_mma655x: AltosMma655x.provide_data(listener, link); break; + case idle_adxl375: + AltosAdxl375.provide_data(listener, link); + break; case idle_ms5607: AltosMs5607.provide_data(listener, link); break; @@ -157,11 +160,16 @@ public class AltosIdleFetch implements AltosDataProvider { AltosIdler.idle_ms5607, AltosIdler.idle_imu, AltosIdler.idle_sensor_mega), - new AltosIdler("EasyMega", + new AltosIdler("EasyMega-v1", AltosIdler.idle_mma655x, AltosIdler.idle_ms5607, AltosIdler.idle_imu, AltosIdler.idle_mag, AltosIdler.idle_sensor_mega), + new AltosIdler("EasyMega-v2", + AltosIdler.idle_adxl375, + AltosIdler.idle_ms5607, + AltosIdler.idle_imu, + AltosIdler.idle_sensor_mega), new AltosIdler("TeleGPS", AltosIdler.idle_gps, AltosIdler.idle_sensor_tgps), diff --git a/altoslib/Makefile.am b/altoslib/Makefile.am index 92976332..2f4e5959 100644 --- a/altoslib/Makefile.am +++ b/altoslib/Makefile.am @@ -28,6 +28,7 @@ altoslib_JAVA = \ AltosLib.java \ AltosAccelCal.java \ AltosAccelCalListener.java \ + AltosAdxl375.java \ AltosCalData.java \ AltosCompanion.java \ AltosConfigData.java \ -- cgit v1.2.3 From 6aa451ce81bfdfe679e3f9902043a5f0d235c745 Mon Sep 17 00:00:00 2001 From: Bdale Garbee Date: Sat, 20 Oct 2018 01:17:39 -0600 Subject: altoslib: fix computation of TeleGPS battery voltage --- altoslib/AltosConvert.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'altoslib') diff --git a/altoslib/AltosConvert.java b/altoslib/AltosConvert.java index d2460187..e1930430 100644 --- a/altoslib/AltosConvert.java +++ b/altoslib/AltosConvert.java @@ -261,7 +261,7 @@ public class AltosConvert { static double tele_gps_voltage(int sensor) { double supply = 3.3; - return sensor / 32767.0 * supply * (5.6 + 10.0) / 10.0; + return sensor / 4095.0 * supply * (5.6 + 10.0) / 10.0; } static double tele_bt_3_battery(int raw) { -- cgit v1.2.3 From f13e294d4644096b0529383c1d60d5e4b7916d76 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 20 Oct 2018 17:22:59 -0700 Subject: 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 --- altoslib/AltosConvert.java | 8 ++++- altoslib/AltosIdleFetch.java | 19 +++++++---- altoslib/AltosSensorTGPS.java | 56 ------------------------------- altoslib/AltosSensorTGPS1.java | 56 +++++++++++++++++++++++++++++++ altoslib/AltosSensorTGPS2.java | 56 +++++++++++++++++++++++++++++++ altoslib/AltosTelemetryConfiguration.java | 12 +++++-- altoslib/Makefile.am | 3 +- 7 files changed, 143 insertions(+), 67 deletions(-) delete mode 100644 altoslib/AltosSensorTGPS.java create mode 100644 altoslib/AltosSensorTGPS1.java create mode 100644 altoslib/AltosSensorTGPS2.java (limited to 'altoslib') 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 \ -- cgit v1.2.3 From 8c92656576aff3ceab5bead3c835d96c36098fe7 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 20 Oct 2018 17:24:41 -0700 Subject: altoslib: Add support for EasyMega-v2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit adxl375 instead of mma6555. mpu9250 rotated 90° compared with other megas. Signed-off-by: Keith Packard --- altoslib/AltosConfigData.java | 2 + altoslib/AltosEepromRecordMega.java | 113 +++++++++++++++++++++++++++++++++--- altoslib/AltosEepromRecordSet.java | 1 + altoslib/AltosLib.java | 1 + 4 files changed, 108 insertions(+), 9 deletions(-) (limited to 'altoslib') diff --git a/altoslib/AltosConfigData.java b/altoslib/AltosConfigData.java index 29ce033d..d315f96a 100644 --- a/altoslib/AltosConfigData.java +++ b/altoslib/AltosConfigData.java @@ -201,6 +201,8 @@ public class AltosConfigData { case AltosLib.AO_LOG_FORMAT_TELEMEGA: case AltosLib.AO_LOG_FORMAT_TELEMEGA_3: return 4095 - value; + case AltosLib.AO_LOG_FORMAT_EASYMEGA_2: + return -value; default: return AltosLib.MISSING; } diff --git a/altoslib/AltosEepromRecordMega.java b/altoslib/AltosEepromRecordMega.java index 6b28c50a..c37dbfa2 100644 --- a/altoslib/AltosEepromRecordMega.java +++ b/altoslib/AltosEepromRecordMega.java @@ -32,6 +32,7 @@ public class AltosEepromRecordMega extends AltosEepromRecord { switch (log_format) { case AltosLib.AO_LOG_FORMAT_TELEMEGA: case AltosLib.AO_LOG_FORMAT_TELEMEGA_3: + case AltosLib.AO_LOG_FORMAT_EASYMEGA_2: return data32(16); case AltosLib.AO_LOG_FORMAT_TELEMEGA_OLD: return data16(14); @@ -43,6 +44,7 @@ public class AltosEepromRecordMega extends AltosEepromRecord { switch (log_format) { case AltosLib.AO_LOG_FORMAT_TELEMEGA: case AltosLib.AO_LOG_FORMAT_TELEMEGA_3: + case AltosLib.AO_LOG_FORMAT_EASYMEGA_2: return data32(20); case AltosLib.AO_LOG_FORMAT_TELEMEGA_OLD: return data16(16); @@ -54,6 +56,7 @@ public class AltosEepromRecordMega extends AltosEepromRecord { switch (log_format) { case AltosLib.AO_LOG_FORMAT_TELEMEGA: case AltosLib.AO_LOG_FORMAT_TELEMEGA_3: + case AltosLib.AO_LOG_FORMAT_EASYMEGA_2: return data32(24); case AltosLib.AO_LOG_FORMAT_TELEMEGA_OLD: return data16(18); @@ -78,6 +81,98 @@ public class AltosEepromRecordMega extends AltosEepromRecord { private int mag_x() { return data16(20); } private int mag_z() { return data16(22); } private int mag_y() { return data16(24); } + + private int accel_across() { + switch (log_format) { + case AltosLib.AO_LOG_FORMAT_TELEMEGA: + case AltosLib.AO_LOG_FORMAT_TELEMEGA_3: + case AltosLib.AO_LOG_FORMAT_TELEMEGA_OLD: + return accel_x(); + case AltosLib.AO_LOG_FORMAT_EASYMEGA_2: + return -accel_y(); + default: + return AltosLib.MISSING; + } + } + + private int accel_along(){ + switch (log_format) { + case AltosLib.AO_LOG_FORMAT_TELEMEGA: + case AltosLib.AO_LOG_FORMAT_TELEMEGA_3: + case AltosLib.AO_LOG_FORMAT_TELEMEGA_OLD: + return accel_y(); + case AltosLib.AO_LOG_FORMAT_EASYMEGA_2: + return accel_x(); + default: + return AltosLib.MISSING; + } + } + + private int accel_through() { + return accel_z(); + } + + private int gyro_pitch() { + switch (log_format) { + case AltosLib.AO_LOG_FORMAT_TELEMEGA: + case AltosLib.AO_LOG_FORMAT_TELEMEGA_3: + case AltosLib.AO_LOG_FORMAT_TELEMEGA_OLD: + return gyro_x(); + case AltosLib.AO_LOG_FORMAT_EASYMEGA_2: + return -gyro_y(); + default: + return AltosLib.MISSING; + } + } + + private int gyro_roll() { + switch (log_format) { + case AltosLib.AO_LOG_FORMAT_TELEMEGA: + case AltosLib.AO_LOG_FORMAT_TELEMEGA_3: + case AltosLib.AO_LOG_FORMAT_TELEMEGA_OLD: + return gyro_y(); + case AltosLib.AO_LOG_FORMAT_EASYMEGA_2: + return gyro_x(); + default: + return AltosLib.MISSING; + } + } + + private int gyro_yaw() { + return gyro_z(); + } + + private int mag_across() { + switch (log_format) { + case AltosLib.AO_LOG_FORMAT_TELEMEGA: + case AltosLib.AO_LOG_FORMAT_TELEMEGA_3: + case AltosLib.AO_LOG_FORMAT_TELEMEGA_OLD: + return mag_x(); + case AltosLib.AO_LOG_FORMAT_EASYMEGA_2: + return -mag_y(); + default: + return AltosLib.MISSING; + } + } + + private int mag_along() { + switch (log_format) { + case AltosLib.AO_LOG_FORMAT_TELEMEGA: + case AltosLib.AO_LOG_FORMAT_TELEMEGA_3: + case AltosLib.AO_LOG_FORMAT_TELEMEGA_OLD: + return mag_y(); + case AltosLib.AO_LOG_FORMAT_EASYMEGA_2: + return mag_y(); + default: + return AltosLib.MISSING; + } + } + + private int mag_through() { + return mag_z(); + } + + private int accel() { return data16(26); } /* AO_LOG_TEMP_VOLT elements */ @@ -138,16 +233,16 @@ public class AltosEepromRecordMega extends AltosEepromRecord { listener.set_pressure(pt.pres); listener.set_temperature(pt.temp); - int accel_along = accel_y(); - int accel_across = accel_x(); - int accel_through = accel_z(); - int gyro_roll = gyro_y(); - int gyro_pitch = gyro_x(); - int gyro_yaw = gyro_z(); + int accel_along = accel_along(); + int accel_across = accel_across(); + int accel_through = accel_through(); + int gyro_roll = gyro_roll(); + int gyro_pitch = gyro_pitch(); + int gyro_yaw = gyro_yaw(); - int mag_along = mag_y(); - int mag_across = mag_x(); - int mag_through = mag_z(); + int mag_along = mag_along(); + int mag_across = mag_across(); + int mag_through = mag_through(); if (log_format == AltosLib.AO_LOG_FORMAT_TELEMEGA_OLD) cal_data.check_imu_wrap(gyro_roll, gyro_pitch, gyro_yaw); diff --git a/altoslib/AltosEepromRecordSet.java b/altoslib/AltosEepromRecordSet.java index 27f81df6..e26a1e00 100644 --- a/altoslib/AltosEepromRecordSet.java +++ b/altoslib/AltosEepromRecordSet.java @@ -71,6 +71,7 @@ public class AltosEepromRecordSet implements AltosRecordSet { case AltosLib.AO_LOG_FORMAT_TELEMEGA: case AltosLib.AO_LOG_FORMAT_TELEMEGA_3: case AltosLib.AO_LOG_FORMAT_TELEMEGA_OLD: + case AltosLib.AO_LOG_FORMAT_EASYMEGA_2: record = new AltosEepromRecordMega(eeprom); break; case AltosLib.AO_LOG_FORMAT_TELEMETRUM: diff --git a/altoslib/AltosLib.java b/altoslib/AltosLib.java index 8b0170ae..93567c06 100644 --- a/altoslib/AltosLib.java +++ b/altoslib/AltosLib.java @@ -374,6 +374,7 @@ public class AltosLib { public static final int AO_LOG_FORMAT_TELEFIRETWO = 13; public static final int AO_LOG_FORMAT_EASYMINI2 = 14; public static final int AO_LOG_FORMAT_TELEMEGA_3 = 15; + public static final int AO_LOG_FORMAT_EASYMEGA_2 = 16; public static final int AO_LOG_FORMAT_NONE = 127; public static boolean isspace(int c) { -- cgit v1.2.3 From 48e221cca00c9f925ff57588dd782842705f7a23 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 20 Oct 2018 17:29:36 -0700 Subject: altoslib: When flashing hardware, pull USB data from device if needed If we fail to extract USB vid/pid and product values from the device ROM, use the data discovered over USB when the device was originally discovered. Also, use the USB product to select appropriate .ihx files instead of only using the USB vid/pid. This will help people avoid using the wrong file when reflashing devices. Signed-off-by: Keith Packard --- altoslib/AltosFlash.java | 6 ++++- altoslib/AltosHexsym.java | 6 ++++- altoslib/AltosProgrammer.java | 2 +- altoslib/AltosRomconfig.java | 10 +++++++- altoslib/AltosSelfFlash.java | 6 ++++- altosuilib/AltosDeviceUIDialog.java | 51 +++++++++++++++++++++++++++---------- altosuilib/AltosFlashUI.java | 44 +++++++++++++++----------------- altosuilib/AltosUSBDevice.java | 9 +++++++ 8 files changed, 92 insertions(+), 42 deletions(-) (limited to 'altoslib') diff --git a/altoslib/AltosFlash.java b/altoslib/AltosFlash.java index e6b05713..434a0265 100644 --- a/altoslib/AltosFlash.java +++ b/altoslib/AltosFlash.java @@ -331,9 +331,13 @@ public class AltosFlash extends AltosProgrammer { rom_config = romconfig; } - public AltosRomconfig target_romconfig() throws InterruptedException { + public AltosRomconfig target_romconfig(AltosUsbId usb_id, String usb_product) throws InterruptedException { if (!check_rom_config()) return null; + if (rom_config.usb_id == null) + rom_config.usb_id = usb_id; + if (rom_config.usb_product == null) + rom_config.usb_product = usb_product; return rom_config; } diff --git a/altoslib/AltosHexsym.java b/altoslib/AltosHexsym.java index b1323484..a2ba6935 100644 --- a/altoslib/AltosHexsym.java +++ b/altoslib/AltosHexsym.java @@ -24,8 +24,12 @@ public class AltosHexsym { final static long invalid_addr = 0xffffffff; + public String toString() { + return String.format("%s:0x%x", name, address); + } + public AltosHexsym(String name, long address) { this.name = name; this.address = address; } -} \ No newline at end of file +} diff --git a/altoslib/AltosProgrammer.java b/altoslib/AltosProgrammer.java index 1872392d..f87e334c 100644 --- a/altoslib/AltosProgrammer.java +++ b/altoslib/AltosProgrammer.java @@ -28,7 +28,7 @@ public abstract class AltosProgrammer { abstract public void abort(); - abstract public AltosRomconfig target_romconfig() throws InterruptedException; + abstract public AltosRomconfig target_romconfig(AltosUsbId usb_id, String usb_product) throws InterruptedException; abstract public AltosRomconfig image_romconfig(); diff --git a/altoslib/AltosRomconfig.java b/altoslib/AltosRomconfig.java index ebeb76f3..00811ce7 100644 --- a/altoslib/AltosRomconfig.java +++ b/altoslib/AltosRomconfig.java @@ -273,6 +273,14 @@ public class AltosRomconfig implements AltosUnitInfoListener { throw new IOException("writing new rom config failed\n"); } + public String toString() { + return String.format("valid %b version %d serial %d radio %d usb %04x:%04x %s", + valid, version, serial_number, radio_calibration, + usb_id == null ? 0 : usb_id.vid, + usb_id == null ? 0 : usb_id.pid, + usb_product == null ? "unknown" : usb_product); + } + public AltosRomconfig(int in_serial_number, int in_radio_calibration) { valid = true; version = 1; @@ -282,7 +290,7 @@ public class AltosRomconfig implements AltosUnitInfoListener { } public boolean valid() { - return valid && serial_number != 0; + return valid; } public AltosRomconfig() { diff --git a/altoslib/AltosSelfFlash.java b/altoslib/AltosSelfFlash.java index 0250cce7..70a5ced5 100644 --- a/altoslib/AltosSelfFlash.java +++ b/altoslib/AltosSelfFlash.java @@ -184,9 +184,13 @@ public class AltosSelfFlash extends AltosProgrammer { rom_config = romconfig; } - public AltosRomconfig target_romconfig() throws InterruptedException { + public AltosRomconfig target_romconfig(AltosUsbId usb_id, String usb_product) throws InterruptedException { if (!check_rom_config()) return null; + if (rom_config.usb_id == null) + rom_config.usb_id = usb_id; + if (rom_config.usb_product == null) + rom_config.usb_product = usb_product; return rom_config; } diff --git a/altosuilib/AltosDeviceUIDialog.java b/altosuilib/AltosDeviceUIDialog.java index 93ab178f..8ea9e233 100644 --- a/altosuilib/AltosDeviceUIDialog.java +++ b/altosuilib/AltosDeviceUIDialog.java @@ -24,27 +24,39 @@ import java.awt.event.*; public class AltosDeviceUIDialog extends AltosDeviceDialog { + boolean include_bluetooth; + public AltosDevice[] devices() { java.util.List usb_devices = AltosUSBDevice.list(product); int num_devices = usb_devices.size(); - java.util.List bt_devices = AltosBTKnown.bt_known().list(product); - num_devices += bt_devices.size(); + + java.util.List bt_devices = null; + + if (include_bluetooth) { + bt_devices = AltosBTKnown.bt_known().list(product); + num_devices += bt_devices.size(); + } + AltosDevice[] devices = new AltosDevice[num_devices]; for (int i = 0; i < usb_devices.size(); i++) devices[i] = usb_devices.get(i); - int off = usb_devices.size(); - for (int j = 0; j < bt_devices.size(); j++) - devices[off + j] = bt_devices.get(j); + if (include_bluetooth) { + int off = usb_devices.size(); + for (int j = 0; j < bt_devices.size(); j++) + devices[off + j] = bt_devices.get(j); + } return devices; } public void add_bluetooth() { - JButton manage_bluetooth_button = new JButton("Manage Bluetooth"); - manage_bluetooth_button.setActionCommand("manage"); - manage_bluetooth_button.addActionListener(this); - buttonPane.add(manage_bluetooth_button); - buttonPane.add(Box.createRigidArea(new Dimension(10, 0))); + if (include_bluetooth) { + JButton manage_bluetooth_button = new JButton("Manage Bluetooth"); + manage_bluetooth_button.setActionCommand("manage"); + manage_bluetooth_button.addActionListener(this); + buttonPane.add(manage_bluetooth_button); + buttonPane.add(Box.createRigidArea(new Dimension(10, 0))); + } } public void actionPerformed(ActionEvent e) { @@ -55,16 +67,29 @@ public class AltosDeviceUIDialog extends AltosDeviceDialog { } } - public AltosDeviceUIDialog (Frame in_frame, Component location, int in_product) { + public AltosDeviceUIDialog (Frame in_frame, Component location, int in_product, boolean include_bluetooth) { super(in_frame, location, in_product); + this.include_bluetooth = include_bluetooth; } - public static AltosDevice show (Component frameComp, int product) { + public AltosDeviceUIDialog (Frame in_frame, Component location, int in_product) { + this(in_frame, location, in_product, true); + } + + public static AltosDevice show (Component frameComp, int product, boolean include_bluetooth) { Frame frame = JOptionPane.getFrameForComponent(frameComp); AltosDeviceUIDialog dialog; - dialog = new AltosDeviceUIDialog(frame, frameComp, product); + dialog = new AltosDeviceUIDialog(frame, frameComp, product, include_bluetooth); dialog.setVisible(true); return dialog.getValue(); } + + public static AltosDevice show (Component frameComp, int product) { + return show(frameComp, product, true); + } + + public static AltosUSBDevice show_usb (Component frameComp, int product) { + return (AltosUSBDevice) show(frameComp, product, false); + } } diff --git a/altosuilib/AltosFlashUI.java b/altosuilib/AltosFlashUI.java index b91776aa..ffb39b8c 100644 --- a/altosuilib/AltosFlashUI.java +++ b/altosuilib/AltosFlashUI.java @@ -45,7 +45,7 @@ public class AltosFlashUI File file; // Debug connection - AltosDevice device; + AltosUSBDevice device; AltosLink link; @@ -205,14 +205,20 @@ public class AltosFlashUI } static class AltosHexfileFilter extends javax.swing.filechooser.FileFilter { - int product; String head; String description; - public AltosHexfileFilter(int product, String head, String description) { - this.product = product; - this.head = head; - this.description = description; + public AltosHexfileFilter(String usb_product) { + int l; + + /* Trim off any trailing variants (1.0a vs 1.0) */ + for (l = usb_product.length(); l > 0; l--) { + char c = usb_product.charAt(l-1); + if (c < 'a' || 'z' < c) + break; + } + head = usb_product.substring(0, l).toLowerCase(); + description = String.format("%s Image File", usb_product); } public boolean accept(File file) { @@ -224,14 +230,6 @@ public class AltosFlashUI } } - static AltosHexfileFilter[] filters = { - new AltosHexfileFilter(AltosLib.product_telemetrum, "telemetrum", "TeleMetrum Image"), - new AltosHexfileFilter(AltosLib.product_teledongle, "teledongle", "TeleDongle Image"), - new AltosHexfileFilter(AltosLib.product_telemega, "telemega", "TeleMega Image"), - new AltosHexfileFilter(AltosLib.product_easymini, "easymini", "EasyMini Image"), - new AltosHexfileFilter(AltosLib.product_easymega, "easymega", "EasyMega Image"), - }; - boolean select_source_file() { JFileChooser hexfile_chooser = new JFileChooser(); @@ -241,18 +239,14 @@ public class AltosFlashUI hexfile_chooser.setDialogTitle("Select Flash Image"); - for (int i = 0; i < filters.length; i++) { - hexfile_chooser.addChoosableFileFilter(filters[i]); - } javax.swing.filechooser.FileFilter ihx_filter = new FileNameExtensionFilter("Flash Image", "ihx"); hexfile_chooser.addChoosableFileFilter(ihx_filter); hexfile_chooser.setFileFilter(ihx_filter); if (!is_pair_programmed() && !device.matchProduct(AltosLib.product_altusmetrum)) { - for (int i = 0; i < filters.length; i++) { - if (device != null && device.matchProduct(filters[i].product)) - hexfile_chooser.setFileFilter(filters[i]); - } + AltosHexfileFilter filter = new AltosHexfileFilter(device.usb_product()); + hexfile_chooser.addChoosableFileFilter(filter); + hexfile_chooser.setFileFilter(filter); } int returnVal = hexfile_chooser.showOpenDialog(frame); @@ -270,7 +264,7 @@ public class AltosFlashUI boolean select_device() { int product = AltosLib.product_any; - device = AltosDeviceUIDialog.show(frame, AltosLib.product_any); + device = AltosDeviceUIDialog.show_usb(frame, AltosLib.product_any); if (device == null) return false; @@ -393,10 +387,12 @@ public class AltosFlashUI else programmer = new AltosSelfFlash(ui.file, link, this); - final AltosRomconfig current_config = programmer.target_romconfig(); + final AltosRomconfig current_config = programmer.target_romconfig(device.usb_id(), device.usb_product()); final AltosRomconfig image_config = programmer.image_romconfig(); + System.out.printf("product %s current %s image %s\n", device.usb_product(), current_config, image_config); + final Semaphore await_rom_config = new Semaphore(0); SwingUtilities.invokeLater(new Runnable() { public void run() { @@ -539,7 +535,7 @@ public class AltosFlashUI } if (!matched) { System.out.printf("Identified new device %s\n", d.toShortString()); - device = d; + device = (AltosUSBDevice) d; break; } } diff --git a/altosuilib/AltosUSBDevice.java b/altosuilib/AltosUSBDevice.java index f43d6bef..e4b94eea 100644 --- a/altosuilib/AltosUSBDevice.java +++ b/altosuilib/AltosUSBDevice.java @@ -20,6 +20,7 @@ package org.altusmetrum.altosuilib_13; import java.util.*; import libaltosJNI.*; +import org.altusmetrum.altoslib_13.*; public class AltosUSBDevice extends altos_device implements AltosDevice { @@ -98,6 +99,14 @@ public class AltosUSBDevice extends altos_device implements AltosDevice { return getVendor() ^ getProduct() ^ getSerial() ^ getPath().hashCode(); } + public AltosUsbId usb_id() { + return new AltosUsbId(getVendor(), getProduct()); + } + + public String usb_product() { + return getName(); + } + public boolean equals(Object o) { if (o == null) return false; -- cgit v1.2.3 From 9791ebb256c2892663c072f7989e4b9bd34818a1 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 30 Dec 2018 14:15:51 -0800 Subject: altoslib: Remove spurious debug printf in AltosCalData Signed-off-by: Keith Packard --- altoslib/AltosCalData.java | 2 -- 1 file changed, 2 deletions(-) (limited to 'altoslib') diff --git a/altoslib/AltosCalData.java b/altoslib/AltosCalData.java index c3d79250..22d19def 100644 --- a/altoslib/AltosCalData.java +++ b/altoslib/AltosCalData.java @@ -156,8 +156,6 @@ public class AltosCalData { public double acceleration(double sensor) { double accel; accel = AltosConvert.acceleration_from_sensor(sensor, accel_plus_g, accel_minus_g, ground_accel); - System.out.printf("acceleration %g (+ %g - %g g %g) -> %g\n", - sensor, accel_plus_g, accel_minus_g, ground_accel, accel); return accel; } -- cgit v1.2.3