diff options
author | Keith Packard <keithp@keithp.com> | 2013-04-09 00:28:05 -0700 |
---|---|---|
committer | Keith Packard <keithp@keithp.com> | 2013-04-09 00:30:36 -0700 |
commit | 398c02b945a58634c8932f07df2c2be8438da7d1 (patch) | |
tree | 2741e99555d58e9509271da719d039516e16819f /altoslib | |
parent | 08eb1e3e1abb1aa4f5ea92b781a2ff8f480006c5 (diff) |
altoslib/altosui: Carry receiver status around in AltosListenerState
This moves the crc_errors into the new structure and adds a receiver
battery voltage value there as well. Now the receiver status can be
monitored separately from the flight status. That also means that code
receiving state updates should be prepared to accept missing listener
or flight state values.
Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'altoslib')
-rw-r--r-- | altoslib/AltosConfigData.java | 6 | ||||
-rw-r--r-- | altoslib/AltosFlightReader.java | 4 | ||||
-rw-r--r-- | altoslib/AltosGPS.java | 57 | ||||
-rw-r--r-- | altoslib/AltosIdleMonitor.java | 6 | ||||
-rw-r--r-- | altoslib/AltosLink.java | 57 | ||||
-rw-r--r-- | altoslib/AltosListenerState.java | 28 | ||||
-rw-r--r-- | altoslib/AltosRecord.java | 24 | ||||
-rw-r--r-- | altoslib/AltosSensorMM.java | 122 | ||||
-rw-r--r-- | altoslib/AltosSensorTM.java | 80 | ||||
-rw-r--r-- | altoslib/AltosState.java | 21 | ||||
-rw-r--r-- | altoslib/AltosTelemetryReader.java | 8 | ||||
-rw-r--r-- | altoslib/Makefile.am | 1 |
12 files changed, 261 insertions, 153 deletions
diff --git a/altoslib/AltosConfigData.java b/altoslib/AltosConfigData.java index 45b95646..57605607 100644 --- a/altoslib/AltosConfigData.java +++ b/altoslib/AltosConfigData.java @@ -135,6 +135,12 @@ public class AltosConfigData implements Iterable<String> { } } + public boolean has_monitor_battery() { + if (product.startsWith("TeleBT")) + return true; + return false; + } + int[] parse_version(String v) { String[] parts = v.split("\\."); int r[] = new int[parts.length]; diff --git a/altoslib/AltosFlightReader.java b/altoslib/AltosFlightReader.java index 3039b4dc..34526658 100644 --- a/altoslib/AltosFlightReader.java +++ b/altoslib/AltosFlightReader.java @@ -45,4 +45,8 @@ public class AltosFlightReader { public boolean supports_telemetry(int telemetry) { return false; } public File backing_file() { return null; } + + public boolean has_monitor_battery() { return false; } + + public double monitor_battery() { return AltosRecord.MISSING; } } diff --git a/altoslib/AltosGPS.java b/altoslib/AltosGPS.java index 068d8c9c..f23842f3 100644 --- a/altoslib/AltosGPS.java +++ b/altoslib/AltosGPS.java @@ -217,33 +217,38 @@ public class AltosGPS { } public AltosGPS(AltosGPS old) { - nsat = old.nsat; - locked = old.locked; - connected = old.connected; - lat = old.lat; /* degrees (+N -S) */ - lon = old.lon; /* degrees (+E -W) */ - alt = old.alt; /* m */ - year = old.year; - month = old.month; - day = old.day; - hour = old.hour; - minute = old.minute; - second = old.second; - - ground_speed = old.ground_speed; /* m/s */ - course = old.course; /* degrees */ - climb_rate = old.climb_rate; /* m/s */ - hdop = old.hdop; /* unitless? */ - h_error = old.h_error; /* m */ - v_error = old.v_error; /* m */ - - if (old.cc_gps_sat != null) { - cc_gps_sat = new AltosGPSSat[old.cc_gps_sat.length]; - for (int i = 0; i < old.cc_gps_sat.length; i++) { - cc_gps_sat[i] = new AltosGPSSat(); - cc_gps_sat[i].svid = old.cc_gps_sat[i].svid; - cc_gps_sat[i].c_n0 = old.cc_gps_sat[i].c_n0; + if (old != null) { + nsat = old.nsat; + locked = old.locked; + connected = old.connected; + lat = old.lat; /* degrees (+N -S) */ + lon = old.lon; /* degrees (+E -W) */ + alt = old.alt; /* m */ + year = old.year; + month = old.month; + day = old.day; + hour = old.hour; + minute = old.minute; + second = old.second; + + ground_speed = old.ground_speed; /* m/s */ + course = old.course; /* degrees */ + climb_rate = old.climb_rate; /* m/s */ + hdop = old.hdop; /* unitless? */ + h_error = old.h_error; /* m */ + v_error = old.v_error; /* m */ + + if (old.cc_gps_sat != null) { + cc_gps_sat = new AltosGPSSat[old.cc_gps_sat.length]; + for (int i = 0; i < old.cc_gps_sat.length; i++) { + cc_gps_sat[i] = new AltosGPSSat(); + cc_gps_sat[i].svid = old.cc_gps_sat[i].svid; + cc_gps_sat[i].c_n0 = old.cc_gps_sat[i].c_n0; + } } + } else { + ClearGPSTime(); + cc_gps_sat = null; } } } diff --git a/altoslib/AltosIdleMonitor.java b/altoslib/AltosIdleMonitor.java index f2f75bbb..ec51b9c1 100644 --- a/altoslib/AltosIdleMonitor.java +++ b/altoslib/AltosIdleMonitor.java @@ -116,8 +116,10 @@ public class AltosIdleMonitor extends Thread { } finally { if (remote) { link.stop_remote(); - if (record != null) - record.rssi = AltosRSSI(); + if (record != null) { + record.rssi = link.rssi(); + record.monitor_battery = link.monitor_battery(); + } } else { if (record != null) record.rssi = 0; diff --git a/altoslib/AltosLink.java b/altoslib/AltosLink.java index 9eb25ce0..159ebfe1 100644 --- a/altoslib/AltosLink.java +++ b/altoslib/AltosLink.java @@ -364,6 +364,63 @@ public abstract class AltosLink implements Runnable { remote = false; } + public int rssi() throws TimeoutException, InterruptedException { + if (remote) + return 0; + printf("s\n"); + String line = get_reply_no_dialog(5000); + if (line == null) + throw new TimeoutException(); + String[] items = line.split("\\s+"); + if (items.length < 2) + return 0; + if (!items[0].equals("RSSI:")) + return 0; + int rssi = Integer.parseInt(items[1]); + return rssi; + } + + public String[] adc() throws TimeoutException, InterruptedException { + printf("a\n"); + for (;;) { + String line = get_reply_no_dialog(5000); + if (line == null) { + throw new TimeoutException(); + } + if (!line.startsWith("tick:")) + continue; + String[] items = line.split("\\s+"); + return items; + } + } + + public boolean has_monitor_battery() { + return config_data.has_monitor_battery(); + } + + public double monitor_battery() { + int monitor_batt = AltosRecord.MISSING; + + if (config_data.has_monitor_battery()) { + try { + String[] items = adc(); + for (int i = 0; i < items.length;) { + if (items[i].equals("batt")) { + monitor_batt = Integer.parseInt(items[i+1]); + i += 2; + continue; + } + i++; + } + } catch (InterruptedException ie) { + } catch (TimeoutException te) { + } + } + if (monitor_batt == AltosRecord.MISSING) + return AltosRecord.MISSING; + return AltosConvert.cc_battery_to_voltage(monitor_batt); + } + public AltosLink() { callsign = ""; } diff --git a/altoslib/AltosListenerState.java b/altoslib/AltosListenerState.java new file mode 100644 index 00000000..2fb4673e --- /dev/null +++ b/altoslib/AltosListenerState.java @@ -0,0 +1,28 @@ +/* + * Copyright © 2013 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; 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. + */ + +package org.altusmetrum.altoslib_1; + +public class AltosListenerState { + public int crc_errors; + public double battery; + + public AltosListenerState() { + crc_errors = 0; + battery = AltosRecord.MISSING; + } +} diff --git a/altoslib/AltosRecord.java b/altoslib/AltosRecord.java index f8c44cc5..7046b9f1 100644 --- a/altoslib/AltosRecord.java +++ b/altoslib/AltosRecord.java @@ -17,7 +17,7 @@ package org.altusmetrum.altoslib_1; -public abstract class AltosRecord implements Comparable <AltosRecord>, Cloneable { +public class AltosRecord implements Comparable <AltosRecord>, Cloneable { public static final int seen_flight = 1; public static final int seen_sensor = 2; @@ -75,15 +75,17 @@ public abstract class AltosRecord implements Comparable <AltosRecord>, Cloneable * temperature: °C */ - abstract public double pressure(); - abstract public double ground_pressure(); - abstract public double acceleration(); + public double pressure() { return MISSING; } + public double ground_pressure() { return MISSING; } + public double acceleration() { return MISSING; } public double altitude() { double p = pressure(); - if (p == MISSING) + if (p == MISSING) { + System.out.printf ("altitude missing\n"); return MISSING; + } return AltosConvert.pressure_to_altitude(p); } @@ -126,7 +128,11 @@ public abstract class AltosRecord implements Comparable <AltosRecord>, Cloneable return tick - o.tick; } - abstract public AltosRecord clone(); + public AltosRecord clone() { + AltosRecord n = new AltosRecord(); + n.copy(this); + return n; + } public void copy(AltosRecord old) { seen = old.seen; @@ -150,13 +156,13 @@ public abstract class AltosRecord implements Comparable <AltosRecord>, Cloneable seen = 0; version = 0; callsign = "N0CALL"; - serial = 0; - flight = 0; + serial = MISSING; + flight = MISSING; rssi = 0; status = 0; state = AltosLib.ao_flight_startup; tick = 0; - gps = new AltosGPS(); + gps = null; new_gps = false; companion = null; diff --git a/altoslib/AltosSensorMM.java b/altoslib/AltosSensorMM.java index 8372d047..6d1b61c0 100644 --- a/altoslib/AltosSensorMM.java +++ b/altoslib/AltosSensorMM.java @@ -28,75 +28,65 @@ class AltosSensorMM { int accel_ref; public AltosSensorMM(AltosLink link) throws InterruptedException, TimeoutException { - link.printf("a\n"); - for (;;) { - String line = link.get_reply_no_dialog(5000); - if (line == null) { - throw new TimeoutException(); + String[] items = link.adc(); + sense = new int[6]; + for (int i = 0; i < items.length;) { + if (items[i].equals("tick:")) { + tick = Integer.parseInt(items[i+1]); + i += 2; + continue; + } + if (items[i].equals("0:")) { + sense[0] = Integer.parseInt(items[i+1]); + i += 2; + continue; + } + if (items[i].equals("1:")) { + sense[1] = Integer.parseInt(items[i+1]); + i += 2; + continue; + } + if (items[i].equals("2:")) { + sense[2] = Integer.parseInt(items[i+1]); + i += 2; + continue; + } + if (items[i].equals("3:")) { + sense[3] = Integer.parseInt(items[i+1]); + i += 2; + continue; + } + if (items[i].equals("4:")) { + sense[4] = Integer.parseInt(items[i+1]); + i += 2; + continue; + } + if (items[i].equals("5:")) { + sense[5] = Integer.parseInt(items[i+1]); + i += 2; + continue; + } + if (items[i].equals("6:")) { + v_batt = Integer.parseInt(items[i+1]); + i += 2; + continue; + } + if (items[i].equals("7:")) { + v_pyro = Integer.parseInt(items[i+1]); + i += 2; + continue; + } + if (items[i].equals("8:")) { + accel = Integer.parseInt(items[i+1]); + i += 2; + continue; } - if (!line.startsWith("tick:")) + if (items[i].equals("9:")) { + accel_ref = Integer.parseInt(items[i+1]); + i += 2; continue; - String[] items = line.split("\\s+"); - sense = new int[6]; - for (int i = 0; i < items.length;) { - if (items[i].equals("tick:")) { - tick = Integer.parseInt(items[i+1]); - i += 2; - continue; - } - if (items[i].equals("0:")) { - sense[0] = Integer.parseInt(items[i+1]); - i += 2; - continue; - } - if (items[i].equals("1:")) { - sense[1] = Integer.parseInt(items[i+1]); - i += 2; - continue; - } - if (items[i].equals("2:")) { - sense[2] = Integer.parseInt(items[i+1]); - i += 2; - continue; - } - if (items[i].equals("3:")) { - sense[3] = Integer.parseInt(items[i+1]); - i += 2; - continue; - } - if (items[i].equals("4:")) { - sense[4] = Integer.parseInt(items[i+1]); - i += 2; - continue; - } - if (items[i].equals("5:")) { - sense[5] = Integer.parseInt(items[i+1]); - i += 2; - continue; - } - if (items[i].equals("6:")) { - v_batt = Integer.parseInt(items[i+1]); - i += 2; - continue; - } - if (items[i].equals("7:")) { - v_pyro = Integer.parseInt(items[i+1]); - i += 2; - continue; - } - if (items[i].equals("8:")) { - accel = Integer.parseInt(items[i+1]); - i += 2; - continue; - } - if (items[i].equals("9:")) { - accel_ref = Integer.parseInt(items[i+1]); - i += 2; - continue; - } - i++; } - break; + i++; } } } diff --git a/altoslib/AltosSensorTM.java b/altoslib/AltosSensorTM.java index f5fa83a5..754dc5bb 100644 --- a/altoslib/AltosSensorTM.java +++ b/altoslib/AltosSensorTM.java @@ -23,54 +23,44 @@ class AltosSensorTM extends AltosRecordTM { public AltosSensorTM(AltosLink link, AltosConfigData config_data) throws InterruptedException, TimeoutException { super(); - link.printf("a\n"); - for (;;) { - String line = link.get_reply_no_dialog(5000); - if (line == null) { - throw new TimeoutException(); + String[] items = link.adc(); + for (int i = 0; i < items.length;) { + if (items[i].equals("tick:")) { + tick = Integer.parseInt(items[i+1]); + i += 2; + continue; + } + if (items[i].equals("accel:")) { + accel = Integer.parseInt(items[i+1]); + i += 2; + continue; + } + if (items[i].equals("pres:")) { + pres = Integer.parseInt(items[i+1]); + i += 2; + continue; + } + if (items[i].equals("temp:")) { + temp = Integer.parseInt(items[i+1]); + i += 2; + continue; + } + if (items[i].equals("batt:")) { + batt = Integer.parseInt(items[i+1]); + i += 2; + continue; + } + if (items[i].equals("drogue:")) { + drogue = Integer.parseInt(items[i+1]); + i += 2; + continue; } - if (!line.startsWith("tick:")) + if (items[i].equals("main:")) { + main = Integer.parseInt(items[i+1]); + i += 2; continue; - String[] items = line.split("\\s+"); - for (int i = 0; i < items.length;) { - if (items[i].equals("tick:")) { - tick = Integer.parseInt(items[i+1]); - i += 2; - continue; - } - if (items[i].equals("accel:")) { - accel = Integer.parseInt(items[i+1]); - i += 2; - continue; - } - if (items[i].equals("pres:")) { - pres = Integer.parseInt(items[i+1]); - i += 2; - continue; - } - if (items[i].equals("temp:")) { - temp = Integer.parseInt(items[i+1]); - i += 2; - continue; - } - if (items[i].equals("batt:")) { - batt = Integer.parseInt(items[i+1]); - i += 2; - continue; - } - if (items[i].equals("drogue:")) { - drogue = Integer.parseInt(items[i+1]); - i += 2; - continue; - } - if (items[i].equals("main:")) { - main = Integer.parseInt(items[i+1]); - i += 2; - continue; - } - i++; } - break; + i++; } ground_accel = config_data.accel_cal_plus; ground_pres = pres; diff --git a/altoslib/AltosState.java b/altoslib/AltosState.java index 8a3bbd4c..f1bcb1c1 100644 --- a/altoslib/AltosState.java +++ b/altoslib/AltosState.java @@ -155,30 +155,41 @@ public class AltosState { /* compute barometric speed */ double height_change = height - prev_state.height; + + double prev_baro_speed = prev_state.baro_speed; + if (prev_baro_speed == AltosRecord.MISSING) + prev_baro_speed = 0; + if (time_change > 0) - baro_speed = (prev_state.baro_speed * 3 + (height_change / time_change)) / 4.0; + baro_speed = (prev_baro_speed * 3 + (height_change / time_change)) / 4.0; else baro_speed = prev_state.baro_speed; + double prev_accel_speed = prev_state.accel_speed; + + if (prev_accel_speed == AltosRecord.MISSING) + prev_accel_speed = 0; + if (acceleration == AltosRecord.MISSING) { /* Fill in mising acceleration value */ accel_speed = baro_speed; - if (time_change > 0) - acceleration = (accel_speed - prev_state.accel_speed) / time_change; + + if (time_change > 0 && accel_speed != AltosRecord.MISSING) + acceleration = (accel_speed - prev_accel_speed) / time_change; else acceleration = prev_state.acceleration; } else { /* compute accelerometer speed */ - accel_speed = prev_state.accel_speed + acceleration * time_change; + accel_speed = prev_accel_speed + acceleration * time_change; } } - } else { npad = 0; ngps = 0; gps = null; baro_speed = AltosRecord.MISSING; accel_speed = AltosRecord.MISSING; + pad_alt = AltosRecord.MISSING; max_baro_speed = 0; max_accel_speed = 0; max_height = 0; diff --git a/altoslib/AltosTelemetryReader.java b/altoslib/AltosTelemetryReader.java index f365b821..b4293c73 100644 --- a/altoslib/AltosTelemetryReader.java +++ b/altoslib/AltosTelemetryReader.java @@ -107,6 +107,14 @@ public class AltosTelemetryReader extends AltosFlightReader { return log.file(); } + public boolean has_monitor_battery() { + return link.has_monitor_battery(); + } + + public double monitor_battery() { + return link.monitor_battery(); + } + public AltosTelemetryReader (AltosLink in_link) throws IOException, InterruptedException, TimeoutException { link = in_link; diff --git a/altoslib/Makefile.am b/altoslib/Makefile.am index 8e5701ad..30a9d954 100644 --- a/altoslib/Makefile.am +++ b/altoslib/Makefile.am @@ -37,6 +37,7 @@ altoslib_JAVA = \ AltosIMUQuery.java \ AltosLine.java \ AltosLink.java \ + AltosListenerState.java \ AltosLog.java \ AltosMs5607.java \ AltosMs5607Query.java \ |