From d8bf05f7ad55964c9bce0551e58f4ef6c9f721ad Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 5 Aug 2010 13:50:18 -0400 Subject: [PATCH] altosui: Split flight record out of telemetry class This will permit either telemetry or eeprom data to be used to construct the sequence of flight events for reply or data generation. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosConvert.java | 57 +----- ao-tools/altosui/AltosEepromDownload.java | 1 + ao-tools/altosui/AltosEepromMonitor.java | 1 + ao-tools/altosui/AltosEepromReader.java | 120 +++++++++++++ ao-tools/altosui/AltosEepromRecord.java | 70 ++++++++ ao-tools/altosui/AltosGPS.java | 30 ++++ ao-tools/altosui/AltosRecord.java | 208 ++++++++++++++++++++++ ao-tools/altosui/AltosState.java | 38 ++-- ao-tools/altosui/AltosTelemetry.java | 66 +------ ao-tools/altosui/AltosUI.java | 93 ++++++---- ao-tools/altosui/Makefile | 6 +- ao-tools/altosui/Manifest.txt | 2 +- 12 files changed, 517 insertions(+), 175 deletions(-) create mode 100644 ao-tools/altosui/AltosEepromReader.java create mode 100644 ao-tools/altosui/AltosEepromRecord.java create mode 100644 ao-tools/altosui/AltosRecord.java diff --git a/ao-tools/altosui/AltosConvert.java b/ao-tools/altosui/AltosConvert.java index 3be0716c..8cc1df27 100644 --- a/ao-tools/altosui/AltosConvert.java +++ b/ao-tools/altosui/AltosConvert.java @@ -62,7 +62,7 @@ public class AltosConvert { * altitudes are measured with respect to the mean sea level */ static double - cc_altitude_to_pressure(double altitude) + altitude_to_pressure(double altitude) { double base_temperature = LAYER0_BASE_TEMPERATURE; double base_pressure = LAYER0_BASE_PRESSURE; @@ -115,7 +115,7 @@ public class AltosConvert { /* outputs the altitude associated with the given pressure. the altitude returned is measured with respect to the mean sea level */ static double - cc_pressure_to_altitude(double pressure) + pressure_to_altitude(double pressure) { double next_base_temperature = LAYER0_BASE_TEMPERATURE; @@ -178,59 +178,6 @@ public class AltosConvert { return altitude; } - /* - * Values for our MP3H6115A pressure sensor - * - * From the data sheet: - * - * Pressure range: 15-115 kPa - * Voltage at 115kPa: 2.82 - * Output scale: 27mV/kPa - * - * - * 27 mV/kPa * 2047 / 3300 counts/mV = 16.75 counts/kPa - * 2.82V * 2047 / 3.3 counts/V = 1749 counts/115 kPa - */ - - static final double counts_per_kPa = 27 * 2047 / 3300; - static final double counts_at_101_3kPa = 1674.0; - - static double - cc_barometer_to_pressure(double count) - { - return ((count / 16.0) / 2047.0 + 0.095) / 0.009 * 1000.0; - } - - static double - cc_barometer_to_altitude(double baro) - { - double Pa = cc_barometer_to_pressure(baro); - return cc_pressure_to_altitude(Pa); - } - - static final double count_per_mss = 27.0; - - static double - cc_accelerometer_to_acceleration(double accel, double ground_accel) - { - return (ground_accel - accel) / count_per_mss; - } - - /* Value for the CC1111 built-in temperature sensor - * Output voltage at 0°C = 0.755V - * Coefficient = 0.00247V/°C - * Reference voltage = 1.25V - * - * temp = ((value / 32767) * 1.25 - 0.755) / 0.00247 - * = (value - 19791.268) / 32768 * 1.25 / 0.00247 - */ - - static double - cc_thermometer_to_temperature(double thermo) - { - return (thermo - 19791.268) / 32728.0 * 1.25 / 0.00247; - } - static double cc_battery_to_voltage(double battery) { diff --git a/ao-tools/altosui/AltosEepromDownload.java b/ao-tools/altosui/AltosEepromDownload.java index 1f4a278f..f2fcd09e 100644 --- a/ao-tools/altosui/AltosEepromDownload.java +++ b/ao-tools/altosui/AltosEepromDownload.java @@ -31,6 +31,7 @@ import java.util.concurrent.LinkedBlockingQueue; import altosui.Altos; import altosui.AltosSerial; import altosui.AltosSerialMonitor; +import altosui.AltosRecord; import altosui.AltosTelemetry; import altosui.AltosState; import altosui.AltosDeviceDialog; diff --git a/ao-tools/altosui/AltosEepromMonitor.java b/ao-tools/altosui/AltosEepromMonitor.java index e110a354..b88fdd29 100644 --- a/ao-tools/altosui/AltosEepromMonitor.java +++ b/ao-tools/altosui/AltosEepromMonitor.java @@ -30,6 +30,7 @@ import java.util.concurrent.LinkedBlockingQueue; import altosui.AltosSerial; import altosui.AltosSerialMonitor; +import altosui.AltosRecord; import altosui.AltosTelemetry; import altosui.AltosState; import altosui.AltosDeviceDialog; diff --git a/ao-tools/altosui/AltosEepromReader.java b/ao-tools/altosui/AltosEepromReader.java new file mode 100644 index 00000000..6fe9bfe4 --- /dev/null +++ b/ao-tools/altosui/AltosEepromReader.java @@ -0,0 +1,120 @@ +/* + * 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. + */ + +package altosui; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.filechooser.FileNameExtensionFilter; +import javax.swing.table.*; +import java.io.*; +import java.util.*; +import java.text.*; +import java.util.prefs.*; +import java.util.concurrent.LinkedBlockingQueue; + +import altosui.AltosRecord; +import altosui.AltosState; +import altosui.AltosDeviceDialog; +import altosui.AltosPreferences; +import altosui.AltosLog; +import altosui.AltosVoice; +import altosui.AltosEepromMonitor; + +public class AltosEepromReader { + + static final int seen_flight = 1; + static final int seen_sensor = 2; + static final int seen_temp_volt = 4; + static final int seen_deploy = 8; + + static final int seen_basic = seen_flight|seen_sensor|seen_temp_volt|seen_deploy; + + static final int seen_gps_time = 16; + + AltosRecord state; + AltosEepromRecord record; + + int seen; + + int tick; + + boolean done; + + FileInputStream input; + + public AltosRecord read() throws IOException, ParseException { + for (;;) { + if (record == null) { + record = new AltosEepromRecord(AltosRecord.gets(input)); + if (record == null) { + if (done) + return null; + return state; + } + + /* eeprom only records low 16 bits of tick count */ + int tick = record.tick | (state.tick & ~0xffff); + + if (tick < state.tick) { + if (state.tick - tick > 0x8000) + tick += 0x10000; + else + tick = state.tick; + } + + /* Accumulate data in the state record while + * the time stamp is not increasing + */ + + if ((seen & seen_basic) == seen_basic && tick > state.tick) + return new AltosRecord(state); + } + + state.tick = tick; + switch (record.cmd) { + case Altos.AO_LOG_FLIGHT: + state.ground_accel = record.a; + state.flight = record.b; + break; + case Altos.AO_LOG_SENSOR: + state.accel = record.a; + state.pres = record.b; + break; + case Altos.AO_LOG_TEMP_VOLT: + state.temp = record.a; + state.batt = record.b; + break; + case Altos.AO_LOG_DEPLOY: + state.drogue = record.a; + state.main = record.b; + break; + case Altos.AO_LOG_GPS_TIME: + break; + } + record = null; + } + } + + public AltosEepromReader (FileInputStream in_input) { + state = new AltosRecord(); + input = in_input; + seen = 0; + done = false; + } +} diff --git a/ao-tools/altosui/AltosEepromRecord.java b/ao-tools/altosui/AltosEepromRecord.java new file mode 100644 index 00000000..5b359352 --- /dev/null +++ b/ao-tools/altosui/AltosEepromRecord.java @@ -0,0 +1,70 @@ +/* + * 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. + */ + +package altosui; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.filechooser.FileNameExtensionFilter; +import javax.swing.table.*; +import java.io.*; +import java.util.*; +import java.text.*; +import java.util.prefs.*; +import java.util.concurrent.LinkedBlockingQueue; + +import altosui.AltosSerial; +import altosui.AltosSerialMonitor; +import altosui.AltosRecord; +import altosui.AltosTelemetry; +import altosui.AltosState; +import altosui.AltosDeviceDialog; +import altosui.AltosPreferences; +import altosui.AltosLog; +import altosui.AltosVoice; +import altosui.AltosEepromMonitor; + +public class AltosEepromRecord { + public int cmd; + public int tick; + public int a; + public int b; + + public AltosEepromRecord (String line) throws ParseException { + if (line == null) { + cmd = Altos.AO_LOG_INVALID; + } else { + String[] tokens = line.split("\\s+"); + + if (tokens[0].equals("serial-number")) { + cmd = Altos.AO_LOG_SERIAL_NUMBER; + tick = 0; + a = Integer.parseInt(tokens[1]); + b = 0; + } else { + if (tokens.length != 4) + throw new ParseException(line, 0); + cmd = tokens[0].codePointAt(0); + tick = Integer.parseInt(tokens[1]); + a = Integer.parseInt(tokens[2]); + b = Integer.parseInt(tokens[3]); + } + } + } + +} diff --git a/ao-tools/altosui/AltosGPS.java b/ao-tools/altosui/AltosGPS.java index 42f4dc83..6b84d7a5 100644 --- a/ao-tools/altosui/AltosGPS.java +++ b/ao-tools/altosui/AltosGPS.java @@ -166,4 +166,34 @@ public class AltosGPS { ClearGPSTime(); cc_gps_sat = null; } + + public AltosGPS(AltosGPS old) { + nsat = old.nsat; + gps_locked = old.gps_locked; + gps_connected = old.gps_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; + + gps_extended = old.gps_extended; /* has extra data */ + 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 */ + + AltosGPSSat[] cc_gps_sat; /* tracking data */ + 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].svid = old.cc_gps_sat[i].svid; + cc_gps_sat[i].c_n0 = old.cc_gps_sat[i].c_n0; + } + } } diff --git a/ao-tools/altosui/AltosRecord.java b/ao-tools/altosui/AltosRecord.java new file mode 100644 index 00000000..c3e9d211 --- /dev/null +++ b/ao-tools/altosui/AltosRecord.java @@ -0,0 +1,208 @@ +/* + * 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. + */ + +package altosui; + +import java.lang.*; +import java.text.*; +import java.util.HashMap; +import java.io.*; +import altosui.AltosConvert; +import altosui.AltosGPS; + +public class AltosRecord { + int version; + String callsign; + int serial; + int flight; + int rssi; + int status; + String state; + int tick; + int accel; + int pres; + int temp; + int batt; + int drogue; + int main; + int flight_accel; + int ground_accel; + int flight_vel; + int flight_pres; + int ground_pres; + int accel_plus_g; + int accel_minus_g; + AltosGPS gps; + + /* + * Values for our MP3H6115A pressure sensor + * + * From the data sheet: + * + * Pressure range: 15-115 kPa + * Voltage at 115kPa: 2.82 + * Output scale: 27mV/kPa + * + * + * 27 mV/kPa * 2047 / 3300 counts/mV = 16.75 counts/kPa + * 2.82V * 2047 / 3.3 counts/V = 1749 counts/115 kPa + */ + + static final double counts_per_kPa = 27 * 2047 / 3300; + static final double counts_at_101_3kPa = 1674.0; + + static double + barometer_to_pressure(double count) + { + return ((count / 16.0) / 2047.0 + 0.095) / 0.009 * 1000.0; + } + + public double pressure() { + return barometer_to_pressure(pres); + } + + public double ground_pressure() { + return barometer_to_pressure(ground_pres); + } + + public double altitude() { + return AltosConvert.pressure_to_altitude(pressure()); + } + + public double ground_altitude() { + return AltosConvert.pressure_to_altitude(ground_pressure()); + } + + public double height() { + return altitude() - ground_altitude(); + } + + public double battery_voltage() { + return AltosConvert.cc_battery_to_voltage(batt); + } + + public double main_voltage() { + return AltosConvert.cc_ignitor_to_voltage(main); + } + + public double drogue_voltage() { + return AltosConvert.cc_ignitor_to_voltage(drogue); + } + + /* Value for the CC1111 built-in temperature sensor + * Output voltage at 0°C = 0.755V + * Coefficient = 0.00247V/°C + * Reference voltage = 1.25V + * + * temp = ((value / 32767) * 1.25 - 0.755) / 0.00247 + * = (value - 19791.268) / 32768 * 1.25 / 0.00247 + */ + + static double + thermometer_to_temperature(double thermo) + { + return (thermo - 19791.268) / 32728.0 * 1.25 / 0.00247; + } + + public double temperature() { + return thermometer_to_temperature(temp); + } + + double accel_counts_per_mss() { + double counts_per_g = Math.abs(accel_minus_g - accel_plus_g) / 2; + + return counts_per_g / 9.80665; + } + public double acceleration() { + return (accel_plus_g - accel) / accel_counts_per_mss(); + } + + public double accel_speed() { + double speed = flight_vel / (accel_counts_per_mss() * 100.0); + return speed; + } + + public int state() { + System.out.printf("state: %s -> %d\n", state, Altos.state(state)); + return Altos.state(state); + } + + public static String gets(FileInputStream s) throws IOException { + int c; + String line = ""; + + while ((c = s.read()) != -1) { + if (c == '\r') + continue; + if (c == '\n') { + return line; + } + line = line + (char) c; + } + return null; + } + + public AltosRecord(AltosRecord old) { + version = old.version; + callsign = old.callsign; + serial = old.serial; + flight = old.flight; + rssi = old.rssi; + status = old.status; + state = old.state; + tick = old.tick; + accel = old.accel; + pres = old.pres; + temp = old.temp; + batt = old.batt; + drogue = old.drogue; + main = old.main; + flight_accel = old.flight_accel; + ground_accel = old.ground_accel; + flight_vel = old.flight_vel; + flight_pres = old.flight_pres; + ground_pres = old.ground_pres; + accel_plus_g = old.accel_plus_g; + accel_minus_g = old.accel_minus_g; + gps = new AltosGPS(old.gps); + } + + public AltosRecord() { + version = 0; + callsign = "N0CALL"; + serial = 0; + flight = 0; + rssi = 0; + status = 0; + state = "startup"; + tick = 0; + accel = 0; + pres = 0; + temp = 0; + batt = 0; + drogue = 0; + main = 0; + flight_accel = 0; + ground_accel = 0; + flight_vel = 0; + flight_pres = 0; + ground_pres = 0; + accel_plus_g = 0; + accel_minus_g = 0; + gps = new AltosGPS(); + } +} diff --git a/ao-tools/altosui/AltosState.java b/ao-tools/altosui/AltosState.java index 9aa10a08..fc06f839 100644 --- a/ao-tools/altosui/AltosState.java +++ b/ao-tools/altosui/AltosState.java @@ -16,16 +16,16 @@ */ /* - * Track flight state from telemetry data stream + * Track flight state from telemetry or eeprom data stream */ package altosui; -import altosui.AltosTelemetry; +import altosui.AltosRecord; import altosui.AltosGPS; public class AltosState { - AltosTelemetry data; + AltosRecord data; /* derived data */ @@ -71,25 +71,23 @@ public class AltosState { double speak_altitude; - void init (AltosTelemetry cur, AltosState prev_state) { + void init (AltosRecord cur, AltosState prev_state) { int i; - AltosTelemetry prev; - double accel_counts_per_mss; + AltosRecord prev; data = cur; - ground_altitude = AltosConvert.cc_barometer_to_altitude(data.ground_pres); - height = AltosConvert.cc_barometer_to_altitude(data.flight_pres) - ground_altitude; + ground_altitude = data.ground_altitude(); + height = data.altitude() - ground_altitude; report_time = System.currentTimeMillis(); - accel_counts_per_mss = ((data.accel_minus_g - data.accel_plus_g) / 2.0) / 9.80665; - acceleration = (data.ground_accel - data.flight_accel) / accel_counts_per_mss; - speed = data.flight_vel / (accel_counts_per_mss * 100.0); - temperature = AltosConvert.cc_thermometer_to_temperature(data.temp); - drogue_sense = AltosConvert.cc_ignitor_to_voltage(data.drogue); - main_sense = AltosConvert.cc_ignitor_to_voltage(data.main); - battery = AltosConvert.cc_battery_to_voltage(data.batt); + 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(); @@ -125,7 +123,7 @@ public class AltosState { time_change = 0; } - if (state == AltosTelemetry.ao_flight_pad) { + if (state == Altos.ao_flight_pad) { if (data.gps != null && data.gps.gps_locked && data.gps.nsat >= 4) { npad++; if (npad > 1) { @@ -149,8 +147,8 @@ public class AltosState { gps_ready = gps_waiting == 0; - ascent = (AltosTelemetry.ao_flight_boost <= state && - state <= AltosTelemetry.ao_flight_coast); + ascent = (Altos.ao_flight_boost <= state && + state <= Altos.ao_flight_coast); /* Only look at accelerometer data on the way up */ if (ascent && acceleration > max_acceleration) @@ -173,11 +171,11 @@ public class AltosState { } } - public AltosState(AltosTelemetry cur) { + public AltosState(AltosRecord cur) { init(cur, null); } - public AltosState (AltosTelemetry cur, AltosState prev) { + public AltosState (AltosRecord cur, AltosState prev) { init(cur, prev); } } diff --git a/ao-tools/altosui/AltosTelemetry.java b/ao-tools/altosui/AltosTelemetry.java index e13b42e2..f495be1d 100644 --- a/ao-tools/altosui/AltosTelemetry.java +++ b/ao-tools/altosui/AltosTelemetry.java @@ -21,6 +21,7 @@ import java.lang.*; import java.text.*; import java.util.HashMap; import altosui.AltosConvert; +import altosui.AltosRecord; import altosui.AltosGPS; /* @@ -51,72 +52,9 @@ import altosui.AltosGPS; * SAT 10 29 30 24 28 5 25 21 20 15 33 1 23 30 24 18 26 10 29 2 26 */ -public class AltosTelemetry { - int version; - String callsign; - int serial; - int flight; - int rssi; - int status; - String state; - int tick; - int accel; - int pres; - int temp; - int batt; - int drogue; - int main; - int flight_accel; - int ground_accel; - int flight_vel; - int flight_pres; - int ground_pres; - int accel_plus_g; - int accel_minus_g; - AltosGPS gps; - - public static final int ao_flight_startup = 0; - public static final int ao_flight_idle = 1; - public static final int ao_flight_pad = 2; - public static final int ao_flight_boost = 3; - public static final int ao_flight_fast = 4; - public static final int ao_flight_coast = 5; - public static final int ao_flight_drogue = 6; - public static final int ao_flight_main = 7; - public static final int ao_flight_landed = 8; - public static final int ao_flight_invalid = 9; - - static HashMap states = new HashMap(); - { - states.put("startup", ao_flight_startup); - states.put("idle", ao_flight_idle); - states.put("pad", ao_flight_pad); - states.put("boost", ao_flight_boost); - states.put("fast", ao_flight_fast); - states.put("coast", ao_flight_coast); - states.put("drogue", ao_flight_drogue); - states.put("main", ao_flight_main); - states.put("landed", ao_flight_landed); - states.put("invalid", ao_flight_invalid); - } - - public int state() { - if (states.containsKey(state)) - return states.get(state); - return ao_flight_invalid; - } - - public double altitude() { - return AltosConvert.cc_pressure_to_altitude(AltosConvert.cc_barometer_to_pressure(pres)); - } - - public double pad_altitude() { - return AltosConvert.cc_pressure_to_altitude(AltosConvert.cc_barometer_to_pressure(ground_pres)); - } - +public class AltosTelemetry extends AltosRecord { public AltosTelemetry(String line) throws ParseException { String[] words = line.split("\\s+"); - int i = 0; AltosParse.word (words[i++], "VERSION"); diff --git a/ao-tools/altosui/AltosUI.java b/ao-tools/altosui/AltosUI.java index 58f39de5..40663882 100644 --- a/ao-tools/altosui/AltosUI.java +++ b/ao-tools/altosui/AltosUI.java @@ -31,6 +31,7 @@ import java.util.concurrent.LinkedBlockingQueue; import altosui.Altos; import altosui.AltosSerial; import altosui.AltosSerialMonitor; +import altosui.AltosRecord; import altosui.AltosTelemetry; import altosui.AltosState; import altosui.AltosDeviceDialog; @@ -343,7 +344,9 @@ public class AltosUI extends JFrame { class DisplayThread extends Thread { IdleThread idle_thread; - String read() throws InterruptedException { return null; } + String name; + + AltosRecord read() throws InterruptedException, ParseException { return null; } void close() { } @@ -360,18 +363,19 @@ public class AltosUI extends JFrame { info_finish(); idle_thread.start(); try { - while ((line = read()) != null) { + for (;;) { try { - AltosTelemetry t = new AltosTelemetry(line); + AltosRecord record = read(); + if (record == null) + break; old_state = state; - state = new AltosState(t, state); + state = new AltosState(record, state); update(state); show(state); tell(state, old_state); idle_thread.notice(state); } catch (ParseException pp) { - System.out.printf("Parse error on %s\n", line); - System.out.println("exception " + pp); + System.out.printf("Parse error: %d \"%s\"\n", pp.getErrorOffset(), pp.getMessage()); } } } catch (InterruptedException ee) { @@ -387,11 +391,20 @@ public class AltosUI extends JFrame { } } - class DeviceThread extends DisplayThread { + class TelemetryThread extends DisplayThread { + + String readline() throws InterruptedException { return null; } + + AltosRecord read() throws InterruptedException, ParseException { + return new AltosTelemetry(readline()); + } + } + + class DeviceThread extends TelemetryThread { AltosSerial serial; LinkedBlockingQueue telem; - String read() throws InterruptedException { + String readline() throws InterruptedException { return telem.take(); } @@ -404,6 +417,7 @@ public class AltosUI extends JFrame { serial = s; telem = new LinkedBlockingQueue(); serial.add_monitor(telem); + name = "telemetry"; } } @@ -435,40 +449,26 @@ public class AltosUI extends JFrame { stop_display(); } - String readline(FileInputStream s) throws IOException { - int c; - String line = ""; - - while ((c = s.read()) != -1) { - if (c == '\r') - continue; - if (c == '\n') { - return line; - } - line = line + (char) c; - } - return null; - } - /* * Open an existing telemetry file and replay it in realtime */ - class ReplayThread extends DisplayThread { + class ReplayTelemetryThread extends TelemetryThread { FileInputStream replay; - String filename; - ReplayThread(FileInputStream in, String name) { + ReplayTelemetryThread(FileInputStream in, String in_name) { replay = in; - filename = name; + name = in_name; } - String read() { + String readline() { try { - return readline(replay); + String line = AltosRecord.gets(replay); + System.out.printf("telemetry line %s\n", line); + return line; } catch (IOException ee) { JOptionPane.showMessageDialog(AltosUI.this, - filename, + name, "error reading", JOptionPane.ERROR_MESSAGE); } @@ -485,11 +485,32 @@ public class AltosUI extends JFrame { void update(AltosState state) throws InterruptedException { /* Make it run in realtime after the rocket leaves the pad */ - if (state.state > AltosTelemetry.ao_flight_pad) + if (state.state > Altos.ao_flight_pad) Thread.sleep((int) (Math.min(state.time_change,10) * 1000)); } } + class ReplayEepromThread extends DisplayThread { + FileInputStream replay; + + AltosRecord read () { + return null; + } + + void close () { + try { + replay.close(); + } catch (IOException ee) { + } + report(); + } + + ReplayEepromThread(FileInputStream in, String in_name) { + replay = in; + name = in_name; + } + } + Thread display_thread; private void stop_display() { @@ -510,8 +531,8 @@ public class AltosUI extends JFrame { private void Replay() { JFileChooser logfile_chooser = new JFileChooser(); - logfile_chooser.setDialogTitle("Select Telemetry File"); - logfile_chooser.setFileFilter(new FileNameExtensionFilter("Telemetry file", "telem")); + logfile_chooser.setDialogTitle("Select Flight Record File"); + logfile_chooser.setFileFilter(new FileNameExtensionFilter("Flight data file", "eeprom", "telem")); logfile_chooser.setCurrentDirectory(AltosPreferences.logdir()); int returnVal = logfile_chooser.showOpenDialog(AltosUI.this); @@ -522,7 +543,11 @@ public class AltosUI extends JFrame { String filename = file.getName(); try { FileInputStream replay = new FileInputStream(file); - ReplayThread thread = new ReplayThread(replay, filename); + DisplayThread thread; + if (filename.endsWith("eeprom")) + thread = new ReplayEepromThread(replay, filename); + else + thread = new ReplayTelemetryThread(replay, filename); run_display(thread); } catch (FileNotFoundException ee) { JOptionPane.showMessageDialog(AltosUI.this, diff --git a/ao-tools/altosui/Makefile b/ao-tools/altosui/Makefile index 3b88e1c1..3f55db0b 100644 --- a/ao-tools/altosui/Makefile +++ b/ao-tools/altosui/Makefile @@ -2,9 +2,12 @@ CLASSPATH=classes:./* CLASSFILES=\ + Altos.class \ AltosConvert.class \ - AltosEeprom.class \ + AltosEepromDownload.class \ AltosEepromMonitor.class \ + AltosEepromReader.class \ + AltosEepromRecord.class \ AltosFile.class \ AltosFlightInfoTableModel.class \ AltosFlightStatusTableModel.class \ @@ -13,6 +16,7 @@ CLASSFILES=\ AltosLog.class \ AltosParse.class \ AltosPreferences.class \ + AltosRecord.class \ AltosSerialMonitor.class \ AltosSerial.class \ AltosState.class \ diff --git a/ao-tools/altosui/Manifest.txt b/ao-tools/altosui/Manifest.txt index 251ce2a0..504d0de3 100644 --- a/ao-tools/altosui/Manifest.txt +++ b/ao-tools/altosui/Manifest.txt @@ -1,2 +1,2 @@ Main-Class: altosui.AltosUI -Class-Path: freetts.jar +Class-Path: /usr/share/java/freetts.jar -- 2.30.2