From 69e6df07976a56b49e07c242cd6e5b2cbd2a578d Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 23 Feb 2012 17:00:48 +1300 Subject: Move altoslib sources to top dir No sense having them live deep in the file system. Signed-off-by: Keith Packard --- altoslib/AltosState.java | 210 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 210 insertions(+) create mode 100644 altoslib/AltosState.java (limited to 'altoslib/AltosState.java') diff --git a/altoslib/AltosState.java b/altoslib/AltosState.java new file mode 100644 index 00000000..0645e448 --- /dev/null +++ b/altoslib/AltosState.java @@ -0,0 +1,210 @@ +/* + * Copyright © 2010 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; version 2 of the License. + * + * 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. + */ + +/* + * Track flight state from telemetry or eeprom data stream + */ + +package org.altusmetrum.AltosLib; + +public class AltosState { + public AltosRecord data; + + /* derived data */ + + public long report_time; + + public double time; + public double time_change; + public int tick; + + public int state; + public boolean landed; + public boolean ascent; /* going up? */ + public boolean boost; /* under power */ + + public double ground_altitude; + public double height; + public double speed; + public double acceleration; + public double battery; + public double temperature; + public double main_sense; + public double drogue_sense; + public double baro_speed; + + public double max_height; + public double max_acceleration; + public double max_speed; + public double max_baro_speed; + + public AltosGPS gps; + + public AltosIMU imu; + public AltosMag mag; + + public static final int MIN_PAD_SAMPLES = 10; + + public int npad; + public int ngps; + public int gps_waiting; + public boolean gps_ready; + + public AltosGreatCircle from_pad; + public double elevation; /* from pad */ + public double range; /* total distance */ + + public double gps_height; + + public int speak_tick; + public double speak_altitude; + + public void init (AltosRecord cur, AltosState prev_state) { + int i; + AltosRecord prev; + + data = cur; + + ground_altitude = data.ground_altitude(); + height = data.filtered_height(); + + report_time = System.currentTimeMillis(); + + acceleration = data.acceleration(); + speed = data.accel_speed(); + temperature = data.temperature(); + drogue_sense = data.drogue_voltage(); + main_sense = data.main_voltage(); + battery = data.battery_voltage(); + tick = data.tick; + state = data.state; + + if (prev_state != null) { + + /* Preserve any existing gps data */ + npad = prev_state.npad; + ngps = prev_state.ngps; + gps = prev_state.gps; + pad_lat = prev_state.pad_lat; + pad_lon = prev_state.pad_lon; + pad_alt = prev_state.pad_alt; + max_height = prev_state.max_height; + max_acceleration = prev_state.max_acceleration; + max_speed = prev_state.max_speed; + max_baro_speed = prev_state.max_baro_speed; + imu = prev_state.imu; + mag = prev_state.mag; + + /* make sure the clock is monotonic */ + while (tick < prev_state.tick) + tick += 65536; + + time_change = (tick - prev_state.tick) / 100.0; + + /* compute barometric speed */ + + double height_change = height - prev_state.height; + if (data.speed != AltosRecord.MISSING) + baro_speed = data.speed; + else { + if (time_change > 0) + baro_speed = (prev_state.baro_speed * 3 + (height_change / time_change)) / 4.0; + else + baro_speed = prev_state.baro_speed; + } + } else { + npad = 0; + ngps = 0; + gps = null; + baro_speed = 0; + time_change = 0; + } + + time = tick / 100.0; + + if (cur.new_gps && (state == AltosLib.ao_flight_pad || state == AltosLib.ao_flight_idle)) { + + /* Track consecutive 'good' gps reports, waiting for 10 of them */ + if (data.gps != null && data.gps.locked && data.gps.nsat >= 4) + npad++; + else + npad = 0; + + /* Average GPS data while on the pad */ + if (data.gps != null && data.gps.locked && data.gps.nsat >= 4) { + if (ngps > 1) { + /* filter pad position */ + pad_lat = (pad_lat * 31.0 + data.gps.lat) / 32.0; + pad_lon = (pad_lon * 31.0 + data.gps.lon) / 32.0; + pad_alt = (pad_alt * 31.0 + data.gps.alt) / 32.0; + } else { + pad_lat = data.gps.lat; + pad_lon = data.gps.lon; + pad_alt = data.gps.alt; + } + ngps++; + } + } + + gps_waiting = MIN_PAD_SAMPLES - npad; + if (gps_waiting < 0) + gps_waiting = 0; + + gps_ready = gps_waiting == 0; + + ascent = (AltosLib.ao_flight_boost <= state && + state <= AltosLib.ao_flight_coast); + boost = (AltosLib.ao_flight_boost == state); + + /* Only look at accelerometer data under boost */ + if (boost && acceleration > max_acceleration) + max_acceleration = acceleration; + if (boost && speed > max_speed) + max_speed = speed; + if (boost && baro_speed > max_baro_speed) + max_baro_speed = baro_speed; + + if (height > max_height) + max_height = height; + if (data.gps != null) { + if (gps == null || !gps.locked || data.gps.locked) + gps = data.gps; + if (ngps > 0 && gps.locked) { + from_pad = new AltosGreatCircle(pad_lat, pad_lon, gps.lat, gps.lon); + } + } + elevation = 0; + range = -1; + if (ngps > 0) { + gps_height = gps.alt - pad_alt; + if (from_pad != null) { + elevation = Math.atan2(height, from_pad.distance) * 180 / Math.PI; + range = Math.sqrt(height * height + from_pad.distance * from_pad.distance); + } + } else { + gps_height = 0; + } + } + + public AltosState(AltosRecord cur) { + init(cur, null); + } + + public AltosState (AltosRecord cur, AltosState prev) { + init(cur, prev); + } +} -- cgit v1.2.3 From f86dac643081987c8994ab57a96640d5e91b342a Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 2 Jun 2012 19:59:40 -0700 Subject: altoslib: Clean up random rebase failures Signed-off-by: Keith Packard --- altoslib/AltosConfigData.java | 2 +- altoslib/AltosEepromIterable.java | 16 ++++---- altoslib/AltosIMU.java | 2 +- altoslib/AltosLib.java | 11 ++++++ altoslib/AltosMag.java | 2 +- altoslib/AltosMs5607.java | 2 +- altoslib/AltosRecord.java | 1 - altoslib/AltosState.java | 2 + altoslib/AltosTelemetryReader.java | 8 ++-- altoslib/AltosTelemetryRecord.java | 15 +++---- altoslib/AltosTelemetryRecordLegacy.java | 4 +- altosui/Altos.java | 67 -------------------------------- altosui/AltosSerial.java | 3 -- altosui/Makefile.am | 3 -- 14 files changed, 39 insertions(+), 99 deletions(-) (limited to 'altoslib/AltosState.java') diff --git a/altoslib/AltosConfigData.java b/altoslib/AltosConfigData.java index 4ad4e58a..fa6a72b5 100644 --- a/altoslib/AltosConfigData.java +++ b/altoslib/AltosConfigData.java @@ -104,7 +104,7 @@ public class AltosConfigData implements Iterable { for (int i = 0; i < parts.length; i++) { try { - r[i] = Altos.fromdec(parts[i]); + r[i] = AltosLib.fromdec(parts[i]); } catch (NumberFormatException n) { r[i] = 0; } diff --git a/altoslib/AltosEepromIterable.java b/altoslib/AltosEepromIterable.java index f1397c7b..a923d63b 100644 --- a/altoslib/AltosEepromIterable.java +++ b/altoslib/AltosEepromIterable.java @@ -318,28 +318,28 @@ public class AltosEepromIterable extends AltosRecordIterable { case AltosLib.AO_LOG_SOFTWARE_VERSION: out.printf ("# Software version: %s\n", record.data); break; - case Altos.AO_LOG_BARO_RESERVED: + case AltosLib.AO_LOG_BARO_RESERVED: out.printf ("# Baro reserved: %d\n", record.a); break; - case Altos.AO_LOG_BARO_SENS: + case AltosLib.AO_LOG_BARO_SENS: out.printf ("# Baro sens: %d\n", record.a); break; - case Altos.AO_LOG_BARO_OFF: + case AltosLib.AO_LOG_BARO_OFF: out.printf ("# Baro off: %d\n", record.a); break; - case Altos.AO_LOG_BARO_TCS: + case AltosLib.AO_LOG_BARO_TCS: out.printf ("# Baro tcs: %d\n", record.a); break; - case Altos.AO_LOG_BARO_TCO: + case AltosLib.AO_LOG_BARO_TCO: out.printf ("# Baro tco: %d\n", record.a); break; - case Altos.AO_LOG_BARO_TREF: + case AltosLib.AO_LOG_BARO_TREF: out.printf ("# Baro tref: %d\n", record.a); break; - case Altos.AO_LOG_BARO_TEMPSENS: + case AltosLib.AO_LOG_BARO_TEMPSENS: out.printf ("# Baro tempsens: %d\n", record.a); break; - case Altos.AO_LOG_BARO_CRC: + case AltosLib.AO_LOG_BARO_CRC: out.printf ("# Baro crc: %d\n", record.a); break; } diff --git a/altoslib/AltosIMU.java b/altoslib/AltosIMU.java index 88e36544..c0eaf139 100644 --- a/altoslib/AltosIMU.java +++ b/altoslib/AltosIMU.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package altoslib; +package org.altusmetrum.AltosLib; public class AltosIMU { public int accel_x; diff --git a/altoslib/AltosLib.java b/altoslib/AltosLib.java index 2921d040..27d72079 100644 --- a/altoslib/AltosLib.java +++ b/altoslib/AltosLib.java @@ -50,6 +50,17 @@ public class AltosLib { public static final int AO_LOG_PRODUCT = 2001; public static final int AO_LOG_SERIAL_NUMBER = 2002; public static final int AO_LOG_LOG_FORMAT = 2003; + + /* Added for header fields in megametrum files */ + public static final int AO_LOG_BARO_RESERVED = 3000; + public static final int AO_LOG_BARO_SENS = 3001; + public static final int AO_LOG_BARO_OFF = 3002; + public static final int AO_LOG_BARO_TCS = 3004; + public static final int AO_LOG_BARO_TCO = 3005; + public static final int AO_LOG_BARO_TREF = 3006; + public static final int AO_LOG_BARO_TEMPSENS = 3007; + public static final int AO_LOG_BARO_CRC = 3008; + public static final int AO_LOG_SOFTWARE_VERSION = 9999; /* Added to flag invalid records */ diff --git a/altoslib/AltosMag.java b/altoslib/AltosMag.java index 45f1924c..0f8399ab 100644 --- a/altoslib/AltosMag.java +++ b/altoslib/AltosMag.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package altoslib; +package org.altusmetrum.AltosLib; public class AltosMag { public int x; diff --git a/altoslib/AltosMs5607.java b/altoslib/AltosMs5607.java index 253e2f9b..a7b902e2 100644 --- a/altoslib/AltosMs5607.java +++ b/altoslib/AltosMs5607.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package altoslib; +package org.altusmetrum.AltosLib; public class AltosMs5607 { public int reserved; diff --git a/altoslib/AltosRecord.java b/altoslib/AltosRecord.java index e4915af0..10ef3061 100644 --- a/altoslib/AltosRecord.java +++ b/altoslib/AltosRecord.java @@ -82,7 +82,6 @@ public class AltosRecord implements Comparable { public AltosRecordCompanion companion; ->>>>>>> 5a249bc... altosui: Complete split out of separate java library /* * Values for our MP3H6115A pressure sensor * diff --git a/altoslib/AltosState.java b/altoslib/AltosState.java index 0645e448..68c7611f 100644 --- a/altoslib/AltosState.java +++ b/altoslib/AltosState.java @@ -70,6 +70,8 @@ public class AltosState { public double gps_height; + public double pad_lat, pad_lon, pad_alt; + public int speak_tick; public double speak_altitude; diff --git a/altoslib/AltosTelemetryReader.java b/altoslib/AltosTelemetryReader.java index 67ac1b65..112e008e 100644 --- a/altoslib/AltosTelemetryReader.java +++ b/altoslib/AltosTelemetryReader.java @@ -59,19 +59,19 @@ public class AltosTelemetryReader extends AltosFlightReader { try { /* Version 1.0 or later firmware supports all telemetry formats */ - if (serial.config_data().compare_version("1.0") >= 0) + if (link.config_data().compare_version("1.0") >= 0) return true; /* Version 0.9 firmware only supports 0.9 telemetry */ - if (serial.config_data().compare_version("0.9") >= 0) { - if (telemetry == Altos.ao_telemetry_0_9) + if (link.config_data().compare_version("0.9") >= 0) { + if (telemetry == AltosLib.ao_telemetry_0_9) return true; else return false; } /* Version 0.8 firmware only supports 0.8 telemetry */ - if (telemetry == Altos.ao_telemetry_0_8) + if (telemetry == AltosLib.ao_telemetry_0_8) return true; else return false; diff --git a/altoslib/AltosTelemetryRecord.java b/altoslib/AltosTelemetryRecord.java index 367c148d..4292dae8 100644 --- a/altoslib/AltosTelemetryRecord.java +++ b/altoslib/AltosTelemetryRecord.java @@ -16,6 +16,7 @@ */ package org.altusmetrum.AltosLib; +import java.text.*; public abstract class AltosTelemetryRecord { @@ -47,7 +48,7 @@ public abstract class AltosTelemetryRecord { int[] bytes; try { - bytes = Altos.hexbytes(hex); + bytes = AltosLib.hexbytes(hex); } catch (NumberFormatException ne) { throw new ParseException(ne.getMessage(), 0); } @@ -60,16 +61,16 @@ public abstract class AltosTelemetryRecord { if (!cksum(bytes)) throw new ParseException(String.format("invalid line \"%s\"", hex), 0); - int rssi = Altos.int8(bytes, bytes.length - 3) / 2 - 74; - int status = Altos.uint8(bytes, bytes.length - 2); + int rssi = AltosLib.int8(bytes, bytes.length - 3) / 2 - 74; + int status = AltosLib.uint8(bytes, bytes.length - 2); if ((status & PKT_APPEND_STATUS_1_CRC_OK) == 0) throw new AltosCRCException(rssi); /* length, data ..., rssi, status, checksum -- 4 bytes extra */ switch (bytes.length) { - case Altos.ao_telemetry_standard_len + 4: - int type = Altos.uint8(bytes, 4 + 1); + case AltosLib.ao_telemetry_standard_len + 4: + int type = AltosLib.uint8(bytes, 4 + 1); switch (type) { case packet_type_TM_sensor: case packet_type_Tm_sensor: @@ -93,10 +94,10 @@ public abstract class AltosTelemetryRecord { break; } break; - case Altos.ao_telemetry_0_9_len + 4: + case AltosLib.ao_telemetry_0_9_len + 4: r = new AltosTelemetryRecordLegacy(bytes, rssi, status); break; - case Altos.ao_telemetry_0_8_len + 4: + case AltosLib.ao_telemetry_0_8_len + 4: r = new AltosTelemetryRecordLegacy(bytes, rssi, status); break; default: diff --git a/altoslib/AltosTelemetryRecordLegacy.java b/altoslib/AltosTelemetryRecordLegacy.java index 8e3713cc..85071d9c 100644 --- a/altoslib/AltosTelemetryRecordLegacy.java +++ b/altoslib/AltosTelemetryRecordLegacy.java @@ -241,7 +241,7 @@ public class AltosTelemetryRecordLegacy extends AltosTelemetryRecord { record.serial = map.get_int(AO_TELEM_SERIAL, AltosRecord.MISSING); record.flight = map.get_int(AO_TELEM_FLIGHT, AltosRecord.MISSING); record.rssi = map.get_int(AO_TELEM_RSSI, AltosRecord.MISSING); - record.state = Altos.state(map.get_string(AO_TELEM_STATE, "invalid")); + record.state = AltosLib.state(map.get_string(AO_TELEM_STATE, "invalid")); record.tick = map.get_int(AO_TELEM_TICK, 0); /* raw sensor values */ @@ -300,7 +300,7 @@ public class AltosTelemetryRecordLegacy extends AltosTelemetryRecord { record.status = AltosParse.parse_hex(words[i++]); AltosParse.word(words[i++], "STATE"); - record.state = Altos.state(words[i++]); + record.state = AltosLib.state(words[i++]); record.tick = AltosParse.parse_int(words[i++]); diff --git a/altosui/Altos.java b/altosui/Altos.java index 380796cc..334ddb07 100644 --- a/altosui/Altos.java +++ b/altosui/Altos.java @@ -28,73 +28,6 @@ import org.altusmetrum.AltosLib.*; public class Altos extends AltosLib { - /* Added for header fields in eeprom files */ - static final int AO_LOG_CONFIG_VERSION = 1000; - static final int AO_LOG_MAIN_DEPLOY = 1001; - static final int AO_LOG_APOGEE_DELAY = 1002; - static final int AO_LOG_RADIO_CHANNEL = 1003; - static final int AO_LOG_CALLSIGN = 1004; - static final int AO_LOG_ACCEL_CAL = 1005; - static final int AO_LOG_RADIO_CAL = 1006; - static final int AO_LOG_MAX_FLIGHT_LOG = 1007; - static final int AO_LOG_MANUFACTURER = 2000; - static final int AO_LOG_PRODUCT = 2001; - static final int AO_LOG_SERIAL_NUMBER = 2002; - static final int AO_LOG_LOG_FORMAT = 2003; - - /* Added for header fields in megametrum files */ - static final int AO_LOG_BARO_RESERVED = 3000; - static final int AO_LOG_BARO_SENS = 3001; - static final int AO_LOG_BARO_OFF = 3002; - static final int AO_LOG_BARO_TCS = 3004; - static final int AO_LOG_BARO_TCO = 3005; - static final int AO_LOG_BARO_TREF = 3006; - static final int AO_LOG_BARO_TEMPSENS = 3007; - static final int AO_LOG_BARO_CRC = 3008; - - static final int AO_LOG_SOFTWARE_VERSION = 9999; - - /* Added to flag invalid records */ - static final int AO_LOG_INVALID = -1; - - /* Flight state numbers and names */ - static final int ao_flight_startup = 0; - static final int ao_flight_idle = 1; - static final int ao_flight_pad = 2; - static final int ao_flight_boost = 3; - static final int ao_flight_fast = 4; - static final int ao_flight_coast = 5; - static final int ao_flight_drogue = 6; - static final int ao_flight_main = 7; - static final int ao_flight_landed = 8; - static final int ao_flight_invalid = 9; - - /* Telemetry modes */ - static final int ao_telemetry_off = 0; - static final int ao_telemetry_min = 1; - static final int ao_telemetry_standard = 1; - static final int ao_telemetry_0_9 = 2; - static final int ao_telemetry_0_8 = 3; - static final int ao_telemetry_max = 3; - - static final String[] ao_telemetry_name = { - "Off", "Standard Telemetry", "TeleMetrum v0.9", "TeleMetrum v0.8" - }; - - static final String launch_sites_url = "http://www.altusmetrum.org/AltOS/launch-sites.txt"; - - static final int ao_telemetry_standard_len = 32; - static final int ao_telemetry_0_9_len = 95; - static final int ao_telemetry_0_8_len = 94; - - static final int[] ao_telemetry_len = { - 0, 32, 95, 94 - }; - - static HashMap string_to_state = new HashMap(); - - static boolean map_initialized = false; - static final int tab_elt_pad = 5; static Font label_font; diff --git a/altosui/AltosSerial.java b/altosui/AltosSerial.java index 54cdcba7..3abdb645 100644 --- a/altosui/AltosSerial.java +++ b/altosui/AltosSerial.java @@ -264,7 +264,6 @@ public class AltosSerial extends AltosLink implements Runnable { flush_output(); } -<<<<<<< HEAD private int telemetry_len() { return Altos.telemetry_len(telemetry); } @@ -386,8 +385,6 @@ public class AltosSerial extends AltosLink implements Runnable { remote = false; } -======= ->>>>>>> bc5e669... altosui: Pull most of AltosSerial into AltosLink public void set_frame(Frame in_frame) { frame = in_frame; } diff --git a/altosui/Makefile.am b/altosui/Makefile.am index 0a6ae59e..9fc7b5b3 100644 --- a/altosui/Makefile.am +++ b/altosui/Makefile.am @@ -27,8 +27,6 @@ altosui_JAVA = \ AltosConfigureUI.java \ AltosConfigTD.java \ AltosConfigTDUI.java \ - AltosConvert.java \ - AltosCRCException.java \ AltosCSV.java \ AltosCSVUI.java \ AltosDebug.java \ @@ -42,7 +40,6 @@ altosui_JAVA = \ AltosEepromList.java \ AltosEepromManage.java \ AltosEepromMonitor.java \ - AltosEepromTeleScience.java \ AltosEepromMega.java \ AltosEepromMegaIterable.java \ AltosEepromSelect.java \ -- cgit v1.2.3 From 97c1cfee929a35dd1596dc02ce519b80132f3c5c Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 17 Jul 2012 20:43:31 -0700 Subject: altoslib: Don't use MISSING values in max computations Early telemetry state may be missing critical data, don't use MISSING values in computing max ranges. Signed-off-by: Keith Packard --- altoslib/AltosState.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'altoslib/AltosState.java') diff --git a/altoslib/AltosState.java b/altoslib/AltosState.java index 68c7611f..e20ec9a7 100644 --- a/altoslib/AltosState.java +++ b/altoslib/AltosState.java @@ -160,7 +160,8 @@ public class AltosState { } ngps++; } - } + } else + pad_alt = ground_altitude; gps_waiting = MIN_PAD_SAMPLES - npad; if (gps_waiting < 0) @@ -173,14 +174,14 @@ public class AltosState { boost = (AltosLib.ao_flight_boost == state); /* Only look at accelerometer data under boost */ - if (boost && acceleration > max_acceleration) + if (boost && acceleration > max_acceleration && acceleration != AltosRecord.MISSING) max_acceleration = acceleration; - if (boost && speed > max_speed) + if (boost && speed > max_speed && speed != AltosRecord.MISSING) max_speed = speed; - if (boost && baro_speed > max_baro_speed) + if (boost && baro_speed > max_baro_speed && baro_speed != AltosRecord.MISSING) max_baro_speed = baro_speed; - if (height > max_height) + if (height > max_height && height != AltosRecord.MISSING) max_height = height; if (data.gps != null) { if (gps == null || !gps.locked || data.gps.locked) -- cgit v1.2.3 From 0bf21399d3d47d58410df4c6ce89fc20fcd42c89 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 29 Jul 2012 19:34:00 -0700 Subject: altosui: Handle Monitor Idle errors better Deal with missing data by checking for MISSING in more places. Handle serial communication failures during send by reporting back from libaltos. Signed-off-by: Keith Packard --- altoslib/AltosIdleMonitor.java | 67 +++++++++++++++++------------------------- altoslib/AltosLink.java | 20 +++++++++++-- altoslib/AltosRecord.java | 2 +- altoslib/AltosRecordTM.java | 16 +++++----- altoslib/AltosState.java | 2 ++ altosui/AltosSerial.java | 14 +++++++-- altosui/libaltos/libaltos.c | 4 +-- 7 files changed, 70 insertions(+), 55 deletions(-) (limited to 'altoslib/AltosState.java') diff --git a/altoslib/AltosIdleMonitor.java b/altoslib/AltosIdleMonitor.java index 57c4da71..27ea3a2b 100644 --- a/altoslib/AltosIdleMonitor.java +++ b/altoslib/AltosIdleMonitor.java @@ -23,16 +23,10 @@ import java.text.*; import java.util.prefs.*; import java.util.concurrent.*; -class AltosSensorTM { - int tick; - int accel; - int pres; - int temp; - int batt; - int drogue; - int main; +class AltosSensorTM extends AltosRecordTM { - public AltosSensorTM(AltosLink link) throws InterruptedException, TimeoutException { + public AltosSensorTM(AltosLink link, AltosConfigData config_data) throws InterruptedException, TimeoutException { + super(); link.printf("a\n"); for (;;) { String line = link.get_reply_no_dialog(5000); @@ -82,6 +76,10 @@ class AltosSensorTM { } break; } + ground_accel = config_data.accel_cal_plus; + ground_pres = pres; + accel_plus_g = config_data.accel_cal_plus; + accel_minus_g = config_data.accel_cal_minus; } } @@ -253,7 +251,7 @@ class AltosGPSQuery extends AltosGPS { if (line.startsWith("Date:")) { if (bits.length < 2) continue; - String[] d = bits[1].split(":"); + String[] d = bits[1].split("/"); if (d.length < 3) continue; year = Integer.parseInt(d[0]) + 2000; @@ -264,7 +262,7 @@ class AltosGPSQuery extends AltosGPS { if (line.startsWith("Time:")) { if (bits.length < 2) continue; - String[] d = bits[1].split("/"); + String[] d = bits[1].split(":"); if (d.length < 3) continue; hour = Integer.parseInt(d[0]); @@ -339,8 +337,7 @@ public class AltosIdleMonitor extends Thread { } void update_state() throws InterruptedException, TimeoutException { - AltosRecord record; - int rssi; + AltosRecord record = null; try { if (remote) { @@ -350,20 +347,7 @@ public class AltosIdleMonitor extends Thread { link.flush_input(); config_data = new AltosConfigData(link); if (config_data.product.startsWith("TeleMetrum")) { - AltosRecordTM record_tm = new AltosRecordTM(); - AltosSensorTM sensor = new AltosSensorTM(link); - record_tm.accel = sensor.accel; - record_tm.pres = sensor.pres; - record_tm.batt = sensor.batt; - record_tm.temp = sensor.temp; - record_tm.drogue = sensor.drogue; - record_tm.main = sensor.main; - record_tm.ground_accel = record_tm.accel; - record_tm.ground_pres = record_tm.pres; - record_tm.accel_plus_g = config_data.accel_cal_plus; - record_tm.accel_minus_g = config_data.accel_cal_minus; - record_tm.tick = sensor.tick; - record = record_tm; + record = new AltosSensorTM(link, config_data); } else if (config_data.product.startsWith("MegaMetrum")) { AltosRecordMM record_mm = new AltosRecordMM(); AltosSensorMM sensor = new AltosSensorMM(link); @@ -390,24 +374,27 @@ public class AltosIdleMonitor extends Thread { record = new AltosRecord(); gps = new AltosGPSQuery(link, config_data); + + record.version = 0; + record.callsign = config_data.callsign; + record.serial = config_data.serial; + record.flight = config_data.log_available() > 0 ? 255 : 0; + record.status = 0; + record.state = AltosLib.ao_flight_idle; + record.gps = gps; + record.new_gps = true; + state = new AltosState (record, state); } finally { if (remote) { link.stop_remote(); - rssi = AltosRSSI(); - } else - rssi = 0; + if (record != null) + record.rssi = AltosRSSI(); + } else { + if (record != null) + record.rssi = 0; + } } - record.version = 0; - record.callsign = config_data.callsign; - record.serial = config_data.serial; - record.flight = config_data.log_available() > 0 ? 255 : 0; - record.rssi = rssi; - record.status = 0; - record.state = AltosLib.ao_flight_idle; - - record.gps = gps; - state = new AltosState (record, state); } public void set_frequency(double in_frequency) { diff --git a/altoslib/AltosLink.java b/altoslib/AltosLink.java index d59e73ba..fd5db7e9 100644 --- a/altoslib/AltosLink.java +++ b/altoslib/AltosLink.java @@ -101,15 +101,23 @@ public abstract class AltosLink { try { for (;;) { c = getchar(); - if (Thread.interrupted()) + if (Thread.interrupted()) { + if (debug) + System.out.printf("INTERRUPTED\n"); break; + } if (c == ERROR) { + if (debug) + System.out.printf("ERROR\n"); add_telem (new AltosLine()); add_reply (new AltosLine()); break; } - if (c == TIMEOUT) + if (c == TIMEOUT) { + if (debug) + System.out.printf("TIMEOUT\n"); continue; + } if (c == '\r') continue; synchronized(this) { @@ -180,6 +188,14 @@ public abstract class AltosLink { reply_queue.put (line); } + public void abort_reply() { + try { + add_telem (new AltosLine()); + add_reply (new AltosLine()); + } catch (InterruptedException e) { + } + } + public void add_string(String line) throws InterruptedException { if (line.startsWith("TELEM") || line.startsWith("VERSION") || line.startsWith("CRC")) { add_telem(new AltosLine(line)); diff --git a/altoslib/AltosRecord.java b/altoslib/AltosRecord.java index e468f84b..8722bc05 100644 --- a/altoslib/AltosRecord.java +++ b/altoslib/AltosRecord.java @@ -127,7 +127,7 @@ public class AltosRecord implements Comparable , Cloneable { double p = filtered_pressure(); if (p == MISSING) - return MISSING; + return raw_altitude(); return AltosConvert.pressure_to_altitude(p); } diff --git a/altoslib/AltosRecordTM.java b/altoslib/AltosRecordTM.java index afb70790..37accef6 100644 --- a/altoslib/AltosRecordTM.java +++ b/altoslib/AltosRecordTM.java @@ -177,14 +177,14 @@ public class AltosRecordTM extends AltosRecord { drogue = MISSING; main = MISSING; - flight_accel = 0; - flight_vel = 0; - flight_pres = 0; - - ground_accel = 0; - ground_pres = 0; - accel_plus_g = 0; - accel_minus_g = 0; + flight_accel = MISSING; + flight_vel = MISSING; + flight_pres = MISSING; + + ground_accel = MISSING; + ground_pres = MISSING; + accel_plus_g = MISSING; + accel_minus_g = MISSING; } public AltosRecordTM(AltosRecord old) { diff --git a/altoslib/AltosState.java b/altoslib/AltosState.java index e20ec9a7..3b37a3d4 100644 --- a/altoslib/AltosState.java +++ b/altoslib/AltosState.java @@ -38,6 +38,7 @@ public class AltosState { public boolean boost; /* under power */ public double ground_altitude; + public double altitude; public double height; public double speed; public double acceleration; @@ -82,6 +83,7 @@ public class AltosState { data = cur; ground_altitude = data.ground_altitude(); + altitude = data.raw_altitude(); height = data.filtered_height(); report_time = System.currentTimeMillis(); diff --git a/altosui/AltosSerial.java b/altosui/AltosSerial.java index c4e9c697..8b692fa9 100644 --- a/altosui/AltosSerial.java +++ b/altosui/AltosSerial.java @@ -54,13 +54,19 @@ public class AltosSerial extends AltosLink implements Runnable { Frame frame; public int getchar() { + if (altos == null) + return ERROR; return libaltos.altos_getchar(altos, 0); } public void flush_output() { super.flush_output(); if (altos != null) { - libaltos.altos_flush(altos); + if (libaltos.altos_flush(altos) != 0) { + libaltos.altos_close(altos); + altos = null; + abort_reply(); + } } } @@ -155,7 +161,11 @@ public class AltosSerial extends AltosLink implements Runnable { private void putc(char c) { if (altos != null) - libaltos.altos_putchar(altos, c); + if (libaltos.altos_putchar(altos, c) != 0) { + libaltos.altos_close(altos); + altos = null; + abort_reply(); + } } public void print(String data) { diff --git a/altosui/libaltos/libaltos.c b/altosui/libaltos/libaltos.c index 1cc27cbe..515432f9 100644 --- a/altosui/libaltos/libaltos.c +++ b/altosui/libaltos/libaltos.c @@ -221,7 +221,7 @@ altos_flush(struct altos_file *file) #endif if (ret < 0) { altos_set_last_posix_error(); - return -errno; + return -last_error.code; } if (ret) { memmove(file->out_data, file->out_data + ret, @@ -247,7 +247,7 @@ altos_putchar(struct altos_file *file, char c) ret = 0; if (file->out_used == USB_BUF_SIZE) ret = altos_flush(file); - return 0; + return ret; } #ifdef USE_POLL -- cgit v1.2.3 From b02c17b26e028a6f3a46781211a86a18272da4d0 Mon Sep 17 00:00:00 2001 From: Mike Beattie Date: Fri, 7 Sep 2012 17:34:17 +1200 Subject: altoslib: comment out un-used variables Signed-off-by: Mike Beattie --- altoslib/AltosEepromIterable.java | 2 +- altoslib/AltosEepromMegaIterable.java | 2 +- altoslib/AltosIgnite.java | 2 +- altoslib/AltosMs5607.java | 2 +- altoslib/AltosState.java | 4 ++-- 5 files changed, 6 insertions(+), 6 deletions(-) (limited to 'altoslib/AltosState.java') diff --git a/altoslib/AltosEepromIterable.java b/altoslib/AltosEepromIterable.java index fc308c34..107ad9f0 100644 --- a/altoslib/AltosEepromIterable.java +++ b/altoslib/AltosEepromIterable.java @@ -236,7 +236,7 @@ public class AltosEepromIterable extends AltosRecordIterable { Iterator iterator = records.iterator(); AltosOrderedRecord record = null; AltosRecordTM state = new AltosRecordTM(); - boolean last_reported = false; + //boolean last_reported = false; EepromState eeprom = new EepromState(); state.state = AltosLib.ao_flight_pad; diff --git a/altoslib/AltosEepromMegaIterable.java b/altoslib/AltosEepromMegaIterable.java index be20ba63..aeb9135d 100644 --- a/altoslib/AltosEepromMegaIterable.java +++ b/altoslib/AltosEepromMegaIterable.java @@ -283,7 +283,7 @@ public class AltosEepromMegaIterable extends AltosRecordIterable { Iterator iterator = records.iterator(); AltosOrderedMegaRecord record = null; AltosRecordMM state = new AltosRecordMM(); - boolean last_reported = false; + //boolean last_reported = false; EepromState eeprom = new EepromState(); state.state = AltosLib.ao_flight_pad; diff --git a/altoslib/AltosIgnite.java b/altoslib/AltosIgnite.java index cc814337..e89f1b65 100644 --- a/altoslib/AltosIgnite.java +++ b/altoslib/AltosIgnite.java @@ -95,7 +95,7 @@ public class AltosIgnite { int status = Unknown; if (link == null) return status; - string_ref status_name = new string_ref(); + //string_ref status_name = new string_ref(); try { start_link(); link.printf("t\n"); diff --git a/altoslib/AltosMs5607.java b/altoslib/AltosMs5607.java index 5fd997d8..268e89f6 100644 --- a/altoslib/AltosMs5607.java +++ b/altoslib/AltosMs5607.java @@ -37,7 +37,7 @@ public class AltosMs5607 { int TEMP; long OFF; long SENS; - int P; + //int P; dT = raw_temp - ((int) tref << 8); diff --git a/altoslib/AltosState.java b/altoslib/AltosState.java index 3b37a3d4..2806812e 100644 --- a/altoslib/AltosState.java +++ b/altoslib/AltosState.java @@ -77,8 +77,8 @@ public class AltosState { public double speak_altitude; public void init (AltosRecord cur, AltosState prev_state) { - int i; - AltosRecord prev; + //int i; + //AltosRecord prev; data = cur; -- cgit v1.2.3