diff options
Diffstat (limited to 'altosui')
47 files changed, 544 insertions, 766 deletions
diff --git a/altosui/Altos.java b/altosui/Altos.java index d25736bf..07280b4a 100644 --- a/altosui/Altos.java +++ b/altosui/Altos.java @@ -20,7 +20,7 @@ package altosui; import java.awt.*; import libaltosJNI.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; import org.altusmetrum.altosuilib_1.*; public class Altos extends AltosUILib { diff --git a/altosui/AltosAscent.java b/altosui/AltosAscent.java index 4da4d591..1d9af546 100644 --- a/altosui/AltosAscent.java +++ b/altosui/AltosAscent.java @@ -19,7 +19,7 @@ package altosui; import java.awt.*; import javax.swing.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; public class AltosAscent extends JComponent implements AltosFlightDisplay { GridBagLayout layout; @@ -179,7 +179,7 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay { void reset() { value.setText(""); max_value.setText(""); - max = AltosRecord.MISSING; + max = AltosLib.MISSING; } void set_font() { @@ -189,12 +189,12 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay { } void show(AltosUnits units, double v) { - if (v == AltosRecord.MISSING) { + if (v == AltosLib.MISSING) { value.setText("Missing"); max_value.setText("Missing"); } else { value.setText(units.show(8, v)); - if (v > max || max == AltosRecord.MISSING) { + if (v > max || max == AltosLib.MISSING) { max_value.setText(units.show(8, v)); max = v; } @@ -240,7 +240,7 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay { class Height extends AscentValueHold { void show (AltosState state, AltosListenerState listener_state) { - show(AltosConvert.height, state.height); + show(AltosConvert.height, state.height()); } public Height (GridBagLayout layout, int y) { super (layout, y, "Height"); @@ -251,10 +251,7 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay { class Speed extends AscentValueHold { void show (AltosState state, AltosListenerState listener_state) { - double speed = state.accel_speed; - if (!state.ascent) - speed = state.baro_speed; - show(AltosConvert.speed, speed); + show(AltosConvert.speed, state.speed()); } public Speed (GridBagLayout layout, int y) { super (layout, y, "Speed"); @@ -265,7 +262,7 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay { class Accel extends AscentValueHold { void show (AltosState state, AltosListenerState listener_state) { - show(AltosConvert.accel, state.acceleration); + show(AltosConvert.accel, state.acceleration()); } public Accel (GridBagLayout layout, int y) { super (layout, y, "Acceleration"); @@ -287,8 +284,8 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay { class Apogee extends AscentStatus { void show (AltosState state, AltosListenerState listener_state) { - show("%4.2f V", state.drogue_sense); - lights.set(state.drogue_sense > 3.2); + show("%4.2f V", state.apogee_voltage); + lights.set(state.apogee_voltage > 3.7); } public Apogee (GridBagLayout layout, int y) { super(layout, y, "Apogee Igniter Voltage"); @@ -299,8 +296,8 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay { class Main extends AscentStatus { void show (AltosState state, AltosListenerState listener_state) { - show("%4.2f V", state.main_sense); - lights.set(state.main_sense > 3.2); + show("%4.2f V", state.main_voltage); + lights.set(state.main_voltage > 3.7); } public Main (GridBagLayout layout, int y) { super(layout, y, "Main Igniter Voltage"); @@ -311,7 +308,7 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay { class Lat extends AscentValue { void show (AltosState state, AltosListenerState listener_state) { - if (state.gps != null) + if (state.gps != null && state.gps.connected && state.gps.lat != AltosLib.MISSING) show(pos(state.gps.lat,"N", "S")); else show("???"); @@ -325,7 +322,7 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay { class Lon extends AscentValue { void show (AltosState state, AltosListenerState listener_state) { - if (state.gps != null) + if (state.gps != null && state.gps.connected && state.gps.lon != AltosLib.MISSING) show(pos(state.gps.lon,"E", "W")); else show("???"); @@ -368,11 +365,11 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay { lon.hide(); } height.show(state, listener_state); - if (state.main_sense != AltosRecord.MISSING) + if (state.main_voltage != AltosLib.MISSING) main.show(state, listener_state); else main.hide(); - if (state.drogue_sense != AltosRecord.MISSING) + if (state.apogee_voltage != AltosLib.MISSING) apogee.show(state, listener_state); else apogee.hide(); diff --git a/altosui/AltosBTKnown.java b/altosui/AltosBTKnown.java index 1d42365b..a1652ec4 100644 --- a/altosui/AltosBTKnown.java +++ b/altosui/AltosBTKnown.java @@ -17,7 +17,7 @@ package altosui; import java.util.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; import org.altusmetrum.altosuilib_1.*; public class AltosBTKnown implements Iterable<AltosBTDevice> { diff --git a/altosui/AltosCSV.java b/altosui/AltosCSV.java index 0676f99d..7598eca0 100644 --- a/altosui/AltosCSV.java +++ b/altosui/AltosCSV.java @@ -19,7 +19,7 @@ package altosui; import java.io.*; import java.util.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; public class AltosCSV implements AltosWriter { File name; @@ -27,7 +27,7 @@ public class AltosCSV implements AltosWriter { boolean header_written; boolean seen_boost; int boost_tick; - LinkedList<AltosRecord> pad_records; + LinkedList<AltosState> pad_states; AltosState state; static final int ALTOS_CSV_VERSION = 5; @@ -105,47 +105,47 @@ public class AltosCSV implements AltosWriter { out.printf("version,serial,flight,call,time,clock,rssi,lqi"); } - void write_general(AltosRecord record) { + void write_general(AltosState state) { out.printf("%s, %d, %d, %s, %8.2f, %8.2f, %4d, %3d", - ALTOS_CSV_VERSION, record.serial, record.flight, record.callsign, - (double) record.time, (double) record.tick / 100.0, - record.rssi, - record.status & 0x7f); + ALTOS_CSV_VERSION, state.serial, state.flight, state.callsign, + (double) state.time, (double) state.tick / 100.0, + state.rssi, + state.status & 0x7f); } void write_flight_header() { out.printf("state,state_name"); } - void write_flight(AltosRecord record) { - out.printf("%d,%8s", record.state, record.state()); + void write_flight(AltosState state) { + out.printf("%d,%8s", state.state, state.state_name()); } void write_basic_header() { out.printf("acceleration,pressure,altitude,height,accel_speed,baro_speed,temperature,battery_voltage,drogue_voltage,main_voltage"); } - void write_basic(AltosRecord record) { + void write_basic(AltosState state) { out.printf("%8.2f,%10.2f,%8.2f,%8.2f,%8.2f,%8.2f,%5.1f,%5.2f,%5.2f,%5.2f", - record.acceleration(), - record.pressure(), - record.altitude(), - record.height(), - state.accel_speed, - state.baro_speed, - record.temperature(), - record.battery_voltage(), - record.drogue_voltage(), - record.main_voltage()); + state.acceleration(), + state.pressure(), + state.altitude(), + state.height(), + state.speed(), + state.speed(), + state.temperature, + state.battery_voltage, + state.apogee_voltage, + state.main_voltage); } void write_advanced_header() { out.printf("accel_x,accel_y,accel_z,gyro_x,gyro_y,gyro_z"); } - void write_advanced(AltosRecord record) { - AltosIMU imu = record.imu(); - AltosMag mag = record.mag(); + void write_advanced(AltosState state) { + AltosIMU imu = state.imu; + AltosMag mag = state.mag; if (imu == null) imu = new AltosIMU(); @@ -161,8 +161,8 @@ public class AltosCSV implements AltosWriter { out.printf("connected,locked,nsat,latitude,longitude,altitude,year,month,day,hour,minute,second,pad_dist,pad_range,pad_az,pad_el,hdop"); } - void write_gps(AltosRecord record) { - AltosGPS gps = record.gps; + void write_gps(AltosState state) { + AltosGPS gps = state.gps; if (gps == null) gps = new AltosGPS(); @@ -170,7 +170,7 @@ public class AltosCSV implements AltosWriter { if (from_pad == null) from_pad = new AltosGreatCircle(); - out.printf("%2d,%2d,%3d,%12.7f,%12.7f,%6d,%5d,%3d,%3d,%3d,%3d,%3d,%9.0f,%9.0f,%4.0f,%4.0f,%6.1f", + out.printf("%2d,%2d,%3d,%12.7f,%12.7f,%8.1f,%5d,%3d,%3d,%3d,%3d,%3d,%9.0f,%9.0f,%4.0f,%4.0f,%6.1f", gps.connected?1:0, gps.locked?1:0, gps.nsat, @@ -198,8 +198,8 @@ public class AltosCSV implements AltosWriter { } } - void write_gps_sat(AltosRecord record) { - AltosGPS gps = record.gps; + void write_gps_sat(AltosState state) { + AltosGPS gps = state.gps; for(int i = 1; i <= 32; i++) { int c_n0 = 0; if (gps != null && gps.cc_gps_sat != null) { @@ -221,8 +221,8 @@ public class AltosCSV implements AltosWriter { out.printf(",companion_%02d", i); } - void write_companion(AltosRecord record) { - AltosRecordCompanion companion = record.companion; + void write_companion(AltosState state) { + AltosCompanion companion = state.companion; int channels_written = 0; if (companion == null) { @@ -256,50 +256,49 @@ public class AltosCSV implements AltosWriter { out.printf ("\n"); } - void write_one(AltosRecord record) { - state = new AltosState(record, state); - write_general(record); out.printf(","); - write_flight(record); out.printf(","); - write_basic(record); out.printf(","); - if (record.imu() != null || record.mag() != null) - write_advanced(record); - if (record.gps != null) { + void write_one(AltosState state) { + write_general(state); out.printf(","); + write_flight(state); out.printf(","); + write_basic(state); out.printf(","); + if (state.imu != null || state.mag != null) + write_advanced(state); + if (state.gps != null) { out.printf(","); - write_gps(record); out.printf(","); - write_gps_sat(record); + write_gps(state); out.printf(","); + write_gps_sat(state); } - if (record.companion != null) { + if (state.companion != null) { out.printf(","); - write_companion(record); + write_companion(state); } out.printf ("\n"); } void flush_pad() { - while (!pad_records.isEmpty()) { - write_one (pad_records.remove()); + while (!pad_states.isEmpty()) { + write_one (pad_states.remove()); } } - public void write(AltosRecord record) { - if (record.state == Altos.ao_flight_startup) + public void write(AltosState state) { + if (state.state == Altos.ao_flight_startup) return; if (!header_written) { - write_header(record.imu() != null || record.mag() != null, - record.gps != null, record.companion != null); + write_header(state.imu != null || state.mag != null, + state.gps != null, state.companion != null); header_written = true; } if (!seen_boost) { - if (record.state >= Altos.ao_flight_boost) { + if (state.state >= Altos.ao_flight_boost) { seen_boost = true; - boost_tick = record.tick; + boost_tick = state.tick; flush_pad(); } } if (seen_boost) - write_one(record); + write_one(state); else - pad_records.add(record); + pad_states.add(state); } public PrintStream out() { @@ -307,23 +306,23 @@ public class AltosCSV implements AltosWriter { } public void close() { - if (!pad_records.isEmpty()) { - boost_tick = pad_records.element().tick; + if (!pad_states.isEmpty()) { + boost_tick = pad_states.element().tick; flush_pad(); } out.close(); } - public void write(AltosRecordIterable iterable) { - iterable.write_comments(out()); - for (AltosRecord r : iterable) - write(r); + public void write(AltosStateIterable states) { + states.write_comments(out()); + for (AltosState state : states) + write(state); } public AltosCSV(PrintStream in_out, File in_name) { name = in_name; out = in_out; - pad_records = new LinkedList<AltosRecord>(); + pad_states = new LinkedList<AltosState>(); } public AltosCSV(File in_name) throws FileNotFoundException { diff --git a/altosui/AltosCSVUI.java b/altosui/AltosCSVUI.java index 42508346..c41ea74b 100644 --- a/altosui/AltosCSVUI.java +++ b/altosui/AltosCSVUI.java @@ -21,7 +21,7 @@ import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.io.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; import org.altusmetrum.altosuilib_1.*; public class AltosCSVUI @@ -31,7 +31,7 @@ public class AltosCSVUI JFileChooser csv_chooser; JPanel accessory; JComboBox combo_box; - AltosRecordIterable iterable; + Iterable<AltosState> states; AltosWriter writer; static String[] combo_box_items = { "Comma Separated Values (.CSV)", "Googleearth Data (.KML)" }; @@ -55,8 +55,8 @@ public class AltosCSVUI set_default_file(); } - public AltosCSVUI(JFrame frame, AltosRecordIterable in_iterable, File source_file) { - iterable = in_iterable; + public AltosCSVUI(JFrame frame, AltosStateIterable states, File source_file) { + this.states = states; csv_chooser = new JFileChooser(source_file); accessory = new JPanel(); @@ -91,7 +91,7 @@ public class AltosCSVUI writer = new AltosCSV(file); else writer = new AltosKML(file); - writer.write(iterable); + writer.write(states); writer.close(); } catch (FileNotFoundException ee) { JOptionPane.showMessageDialog(frame, diff --git a/altosui/AltosCompanionInfo.java b/altosui/AltosCompanionInfo.java index ebe1d1f9..1f446700 100644 --- a/altosui/AltosCompanionInfo.java +++ b/altosui/AltosCompanionInfo.java @@ -19,7 +19,7 @@ package altosui; import java.awt.*; import javax.swing.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; public class AltosCompanionInfo extends JTable { private AltosFlightInfoTableModel model; @@ -70,13 +70,13 @@ public class AltosCompanionInfo extends JTable { model.clear(); } - AltosRecordCompanion companion; + AltosCompanion companion; public String board_name() { if (companion == null) return "None"; switch (companion.board_id) { - case AltosRecordCompanion.board_id_telescience: + case AltosCompanion.board_id_telescience: return "TeleScience"; default: return String.format("%02x\n", companion.board_id); @@ -86,8 +86,8 @@ public class AltosCompanionInfo extends JTable { public void show(AltosState state, AltosListenerState listener_state) { if (state == null) return; - if (state.data.companion != null) - companion = state.data.companion; + if (state.companion != null) + companion = state.companion; info_reset(); info_add_row(0, "Companion board", "%s", board_name()); if (companion != null) { diff --git a/altosui/AltosConfig.java b/altosui/AltosConfig.java index 4927d3f8..a6e6094f 100644 --- a/altosui/AltosConfig.java +++ b/altosui/AltosConfig.java @@ -22,7 +22,7 @@ import javax.swing.*; import java.io.*; import java.util.concurrent.*; import java.text.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; import org.altusmetrum.altosuilib_1.*; public class AltosConfig implements ActionListener { diff --git a/altosui/AltosConfigFreqUI.java b/altosui/AltosConfigFreqUI.java index c90b168f..555af3b6 100644 --- a/altosui/AltosConfigFreqUI.java +++ b/altosui/AltosConfigFreqUI.java @@ -21,7 +21,7 @@ import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.util.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; import org.altusmetrum.altosuilib_1.*; class AltosEditFreqUI extends AltosUIDialog implements ActionListener { diff --git a/altosui/AltosConfigPyroUI.java b/altosui/AltosConfigPyroUI.java index 3cac56c3..2f5c199d 100644 --- a/altosui/AltosConfigPyroUI.java +++ b/altosui/AltosConfigPyroUI.java @@ -21,7 +21,7 @@ import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; import org.altusmetrum.altosuilib_1.*; public class AltosConfigPyroUI diff --git a/altosui/AltosConfigTD.java b/altosui/AltosConfigTD.java index 16c9e357..f879ff88 100644 --- a/altosui/AltosConfigTD.java +++ b/altosui/AltosConfigTD.java @@ -21,7 +21,7 @@ import java.awt.event.*; import javax.swing.*; import java.io.*; import java.util.concurrent.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; import org.altusmetrum.altosuilib_1.*; public class AltosConfigTD implements ActionListener { diff --git a/altosui/AltosConfigTDUI.java b/altosui/AltosConfigTDUI.java index 125780a9..b5a6cd7c 100644 --- a/altosui/AltosConfigTDUI.java +++ b/altosui/AltosConfigTDUI.java @@ -21,7 +21,7 @@ import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; import org.altusmetrum.altosuilib_1.*; public class AltosConfigTDUI diff --git a/altosui/AltosConfigUI.java b/altosui/AltosConfigUI.java index 9723e660..a6d27977 100644 --- a/altosui/AltosConfigUI.java +++ b/altosui/AltosConfigUI.java @@ -21,7 +21,7 @@ import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; import org.altusmetrum.altosuilib_1.*; public class AltosConfigUI diff --git a/altosui/AltosDataChooser.java b/altosui/AltosDataChooser.java index c7b561d5..c0d66682 100644 --- a/altosui/AltosDataChooser.java +++ b/altosui/AltosDataChooser.java @@ -20,7 +20,7 @@ package altosui; import javax.swing.*; import javax.swing.filechooser.FileNameExtensionFilter; import java.io.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; import org.altusmetrum.altosuilib_1.*; public class AltosDataChooser extends JFileChooser { @@ -36,7 +36,7 @@ public class AltosDataChooser extends JFileChooser { return file; } - public AltosRecordIterable runDialog() { + public AltosStateIterable runDialog() { int ret; ret = showOpenDialog(frame); @@ -48,16 +48,10 @@ public class AltosDataChooser extends JFileChooser { try { if (filename.endsWith("eeprom")) { FileInputStream in = new FileInputStream(file); - return new AltosEepromIterable(in); + return new AltosEepromFile(in); } else if (filename.endsWith("telem")) { FileInputStream in = new FileInputStream(file); - return new AltosTelemetryIterable(in); - } else if (filename.endsWith("mega")) { - FileInputStream in = new FileInputStream(file); - return new AltosEepromMegaIterable(in); - } else if (filename.endsWith("mini")) { - FileInputStream in = new FileInputStream(file); - return new AltosEepromMiniIterable(in); + return new AltosTelemetryFile(in); } else { throw new FileNotFoundException(); } diff --git a/altosui/AltosDescent.java b/altosui/AltosDescent.java index 29d33ddc..77776ff2 100644 --- a/altosui/AltosDescent.java +++ b/altosui/AltosDescent.java @@ -19,7 +19,7 @@ package altosui; import java.awt.*; import javax.swing.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; public class AltosDescent extends JComponent implements AltosFlightDisplay { GridBagLayout layout; @@ -245,7 +245,7 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay { class Height extends DescentValue { void show (AltosState state, AltosListenerState listener_state) { - show(AltosConvert.height, state.height); + show(AltosConvert.height, state.height()); } public Height (GridBagLayout layout, int x, int y) { super (layout, x, y, "Height"); @@ -256,10 +256,7 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay { class Speed extends DescentValue { void show (AltosState state, AltosListenerState listener_state) { - double speed = state.accel_speed; - if (!state.ascent) - speed = state.baro_speed; - show(AltosConvert.speed, speed); + show(AltosConvert.speed, state.speed()); } public Speed (GridBagLayout layout, int x, int y) { super (layout, x, y, "Speed"); @@ -281,7 +278,7 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay { class Lat extends DescentValue { void show (AltosState state, AltosListenerState listener_state) { - if (state.gps != null && state.gps.connected) + if (state.gps != null && state.gps.connected && state.gps.lat != AltosLib.MISSING) show(pos(state.gps.lat,"N", "S")); else show("???"); @@ -295,7 +292,7 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay { class Lon extends DescentValue { void show (AltosState state, AltosListenerState listener_state) { - if (state.gps != null && state.gps.connected) + if (state.gps != null && state.gps.connected && state.gps.lon != AltosLib.MISSING) show(pos(state.gps.lon,"W", "E")); else show("???"); @@ -325,8 +322,8 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay { class Apogee extends DescentStatus { void show (AltosState state, AltosListenerState listener_state) { - show("%4.2f V", state.drogue_sense); - lights.set(state.drogue_sense > 3.2); + show("%4.2f V", state.apogee_voltage); + lights.set(state.apogee_voltage > 3.7); } public Apogee (GridBagLayout layout, int y) { super(layout, y, "Apogee Igniter Voltage"); @@ -337,8 +334,8 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay { class Main extends DescentStatus { void show (AltosState state, AltosListenerState listener_state) { - show("%4.2f V", state.main_sense); - lights.set(state.main_sense > 3.2); + show("%4.2f V", state.main_voltage); + lights.set(state.main_voltage > 3.7); } public Main (GridBagLayout layout, int y) { super(layout, y, "Main Igniter Voltage"); @@ -430,11 +427,11 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay { lat.hide(); lon.hide(); } - if (state.main_sense != AltosRecord.MISSING) + if (state.main_voltage != AltosLib.MISSING) main.show(state, listener_state); else main.hide(); - if (state.drogue_sense != AltosRecord.MISSING) + if (state.apogee_voltage != AltosLib.MISSING) apogee.show(state, listener_state); else apogee.hide(); diff --git a/altosui/AltosDisplayThread.java b/altosui/AltosDisplayThread.java index 095bed99..37f6adf9 100644 --- a/altosui/AltosDisplayThread.java +++ b/altosui/AltosDisplayThread.java @@ -21,7 +21,7 @@ import java.awt.*; import javax.swing.*; import java.io.*; import java.text.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; public class AltosDisplayThread extends Thread { @@ -92,14 +92,14 @@ public class AltosDisplayThread extends Thread { state.range >= 0) { voice.speak("Height %s, bearing %s %d, elevation %d, range %s.\n", - AltosConvert.height.say(state.height), + AltosConvert.height.say(state.height()), state.from_pad.bearing_words( AltosGreatCircle.BEARING_VOICE), (int) (state.from_pad.bearing + 0.5), (int) (state.elevation + 0.5), AltosConvert.distance.say(state.range)); } else if (state.state > Altos.ao_flight_pad) { - voice.speak(AltosConvert.height.say_units(state.height)); + voice.speak(AltosConvert.height.say_units(state.height())); } else { reported_landing = 0; } @@ -110,10 +110,10 @@ public class AltosDisplayThread extends Thread { */ if (state.state >= Altos.ao_flight_drogue && (last || - System.currentTimeMillis() - state.report_time >= 15000 || + System.currentTimeMillis() - state.received_time >= 15000 || state.state == Altos.ao_flight_landed)) { - if (Math.abs(state.baro_speed) < 20 && state.height < 100) + if (Math.abs(state.speed()) < 20 && state.height() < 100) voice.speak("rocket landed safely"); else voice.speak("rocket may have crashed"); @@ -181,16 +181,16 @@ public class AltosDisplayThread extends Thread { synchronized boolean tell() { boolean ret = false; if (old_state == null || old_state.state != state.state) { - voice.speak(state.data.state()); + voice.speak(state.state_name()); if ((old_state == null || old_state.state <= Altos.ao_flight_boost) && state.state > Altos.ao_flight_boost) { voice.speak("max speed: %s.", - AltosConvert.speed.say_units(state.max_accel_speed + 0.5)); + AltosConvert.speed.say_units(state.max_speed() + 0.5)); ret = true; } else if ((old_state == null || old_state.state < Altos.ao_flight_drogue) && state.state >= Altos.ao_flight_drogue) { voice.speak("max height: %s.", - AltosConvert.height.say_units(state.max_height + 0.5)); + AltosConvert.height.say_units(state.max_height() + 0.5)); ret = true; } } @@ -218,11 +218,9 @@ public class AltosDisplayThread extends Thread { try { for (;;) { try { - AltosRecord record = reader.read(); - if (record == null) + state = reader.read(); + if (state == null) break; - old_state = state; - state = new AltosState(record, state); reader.update(state); show_safely(); told = tell(); diff --git a/altosui/AltosEepromDelete.java b/altosui/AltosEepromDelete.java index e81a35d1..9984d1a2 100644 --- a/altosui/AltosEepromDelete.java +++ b/altosui/AltosEepromDelete.java @@ -21,7 +21,7 @@ import java.awt.event.*; import javax.swing.*; import java.io.*; import java.util.concurrent.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; public class AltosEepromDelete implements Runnable { AltosEepromList flights; diff --git a/altosui/AltosEepromDownload.java b/altosui/AltosEepromDownload.java index 46715db6..6e2fd061 100644 --- a/altosui/AltosEepromDownload.java +++ b/altosui/AltosEepromDownload.java @@ -23,7 +23,7 @@ import java.io.*; import java.util.*; import java.text.*; import java.util.concurrent.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; public class AltosEepromDownload implements Runnable { @@ -33,9 +33,6 @@ public class AltosEepromDownload implements Runnable { Thread eeprom_thread; AltosEepromMonitor monitor; - int flight; - int serial; - int year, month, day; boolean want_file; FileWriter eeprom_file; LinkedList<String> eeprom_pending; @@ -44,7 +41,7 @@ public class AltosEepromDownload implements Runnable { ActionListener listener; boolean success; ParseException parse_exception; - String extension; + AltosState state; private void FlushPending() throws IOException { for (String s : flights.config_data) { @@ -59,15 +56,19 @@ public class AltosEepromDownload implements Runnable { private void CheckFile(boolean force) throws IOException { if (eeprom_file != null) return; - if (force || (flight != 0 && want_file)) { + if (force || (state.flight != 0 && want_file)) { AltosFile eeprom_name; - - if (extension == null) - extension = "data"; - if (year != 0 && month != 0 && day != 0) - eeprom_name = new AltosFile(year, month, day, serial, flight, extension); - else - eeprom_name = new AltosFile(serial, flight, extension); + AltosGPS gps = state.gps; + + if (gps != null && + gps.year != AltosLib.MISSING && + gps.month != AltosLib.MISSING && + gps.day != AltosLib.MISSING) + { + eeprom_name = new AltosFile(gps.year, gps.month, gps.day, + state.serial, state.flight, "eeprom"); + } else + eeprom_name = new AltosFile(state.serial, state.flight, "eeprom"); eeprom_file = new FileWriter(eeprom_name); if (eeprom_file != null) { @@ -78,270 +79,57 @@ public class AltosEepromDownload implements Runnable { } } - void Log(AltosEepromRecord r) throws IOException { + boolean done; + boolean start; + + void LogEeprom(AltosEeprom r) throws IOException { if (r.cmd != Altos.AO_LOG_INVALID) { - String log_line = String.format("%c %4x %4x %4x\n", - r.cmd, r.tick, r.a, r.b); + String line = r.string(); if (eeprom_file != null) - eeprom_file.write(log_line); + eeprom_file.write(line); else - eeprom_pending.add(log_line); + eeprom_pending.add(line); } } - void set_serial(int in_serial) { - serial = in_serial; - monitor.set_serial(serial); - } - - void set_flight(int in_flight) { - flight = in_flight; - monitor.set_flight(flight); - } - - boolean done; - int state; - - void CaptureFull(AltosEepromChunk eechunk) throws IOException { - boolean any_valid = false; - - extension = "eeprom"; - set_serial(flights.config_data.serial); - for (int i = 0; i < AltosEepromChunk.chunk_size && !done; i += AltosEepromRecord.record_length) { - try { - AltosEepromRecord r = new AltosEepromRecord(eechunk, i); - if (r.cmd == Altos.AO_LOG_FLIGHT) - set_flight(r.b); - - /* Monitor state transitions to update display */ - if (r.cmd == Altos.AO_LOG_STATE && r.a <= Altos.ao_flight_landed) { - state = r.a; - if (state > Altos.ao_flight_pad) - want_file = true; - } - - if (r.cmd == Altos.AO_LOG_GPS_DATE) { - year = 2000 + (r.a & 0xff); - month = (r.a >> 8) & 0xff; - day = (r.b & 0xff); - want_file = true; - } - if (r.cmd == Altos.AO_LOG_STATE && r.a == Altos.ao_flight_landed) - done = true; - if (r.cmd != AltosLib.AO_LOG_INVALID) - any_valid = true; - Log(r); - } catch (ParseException pe) { - if (parse_exception == null) - parse_exception = pe; - } - } - - if (!any_valid) - done = true; - - CheckFile(false); - } - - boolean start; - int tiny_tick; - - void CaptureTiny (AltosEepromChunk eechunk) throws IOException { + void CaptureEeprom(AltosEepromChunk eechunk, int log_format) throws IOException { boolean any_valid = false; + boolean got_flight = false; - extension = "eeprom"; - set_serial(flights.config_data.serial); - for (int i = 0; i < eechunk.data.length && !done; i += 2) { - int v = eechunk.data16(i); - AltosEepromRecord r; - - if (i == 0 && start) { - tiny_tick = 0; - start = false; - set_flight(v); - r = new AltosEepromRecord(Altos.AO_LOG_FLIGHT, tiny_tick, 0, v); - any_valid = true; - } else { - int s = v ^ 0x8000; - - if (Altos.ao_flight_startup <= s && s <= Altos.ao_flight_invalid) { - state = s; - r = new AltosEepromRecord(Altos.AO_LOG_STATE, tiny_tick, state, 0); - if (state == Altos.ao_flight_landed) - done = true; - state = s; - any_valid = true; - } else { - if (v != 0xffff) - any_valid = true; - - r = new AltosEepromRecord(Altos.AO_LOG_PRESSURE, tiny_tick, 0, v); - - /* - * The flight software records ascent data every 100ms, and descent - * data every 1s. - */ - if (state < Altos.ao_flight_drogue) - tiny_tick += 10; - else - tiny_tick += 100; - } - } - Log(r); - } - CheckFile(false); - if (!any_valid) - done = true; - } + int record_length = 8; - void LogTeleScience(AltosEepromTeleScience r) throws IOException { - if (r.type != Altos.AO_LOG_INVALID) { - String log_line = String.format("%c %4x %4x %d %5d %5d %5d %5d %5d %5d %5d %5d %5d %5d %5d %5d\n", - r.type, r.tick, r.tm_tick, r.tm_state, - r.data[0], r.data[1], r.data[2], r.data[3], - r.data[4], r.data[5], r.data[6], r.data[7], - r.data[8], r.data[9], r.data[10], r.data[11]); - if (eeprom_file != null) - eeprom_file.write(log_line); - else - eeprom_pending.add(log_line); - } - } - - boolean telescience_start; - - void CaptureTeleScience (AltosEepromChunk eechunk) throws IOException { - boolean any_valid = false; - - extension = "science"; - for (int i = 0; i < AltosEepromChunk.chunk_size && !done; i += AltosEepromTeleScience.record_length) { - try { - AltosEepromTeleScience r = new AltosEepromTeleScience(eechunk, i); - if (r.type == AltosEepromTeleScience.AO_LOG_TELESCIENCE_START) { - if (telescience_start) { - done = true; - break; - } - set_serial(r.data[0]); - set_flight(r.data[1]); - telescience_start = true; - } else { - if (!telescience_start) - break; - } - state = r.tm_state; - want_file =true; - any_valid = true; - LogTeleScience(r); - } catch (ParseException pe) { - if (parse_exception == null) - parse_exception = pe; - } - } + state.set_serial(flights.config_data.serial); + monitor.set_serial(flights.config_data.serial); - CheckFile(false); - if (!any_valid) - done = true; - } + for (int i = 0; i < AltosEepromChunk.chunk_size && !done; i += record_length) { + AltosEeprom r = eechunk.eeprom(i, log_format, state); - void LogMega(AltosEepromMega r) throws IOException { - if (r.cmd != Altos.AO_LOG_INVALID) { - String log_line = String.format("%c %4x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x\n", - r.cmd, r.tick, - r.data8[0], r.data8[1], r.data8[2], r.data8[3], - r.data8[4], r.data8[5], r.data8[6], r.data8[7], - r.data8[8], r.data8[9], r.data8[10], r.data8[11], - r.data8[12], r.data8[13], r.data8[14], r.data8[15], - r.data8[16], r.data8[17], r.data8[18], r.data8[19], - r.data8[20], r.data8[21], r.data8[22], r.data8[23], - r.data8[24], r.data8[25], r.data8[26], r.data8[27]); - if (eeprom_file != null) - eeprom_file.write(log_line); - else - eeprom_pending.add(log_line); - } - } + if (r == null) + continue; - void CaptureMega(AltosEepromChunk eechunk) throws IOException { - boolean any_valid = false; + record_length = r.record_length(); - extension = "mega"; - set_serial(flights.config_data.serial); - for (int i = 0; i < AltosEepromChunk.chunk_size && !done; i += AltosEepromMega.record_length) { - try { - AltosEepromMega r = new AltosEepromMega(eechunk, i); - if (r.cmd == Altos.AO_LOG_FLIGHT) - set_flight(r.data16(0)); - - /* Monitor state transitions to update display */ - if (r.cmd == Altos.AO_LOG_STATE && r.data16(0) <= Altos.ao_flight_landed) { - state = r.data16(0); - if (state > Altos.ao_flight_pad) - want_file = true; - } + r.update_state(state); - if (r.cmd == Altos.AO_LOG_GPS_TIME) { - year = 2000 + r.data8(14); - month = r.data8(15); - day = r.data8(16); - want_file = true; - } + if (!got_flight && state.flight != AltosLib.MISSING) + monitor.set_flight(state.flight); - if (r.cmd == Altos.AO_LOG_STATE && r.data16(0) == Altos.ao_flight_landed) + /* Monitor state transitions to update display */ + if (state.state != AltosLib.ao_flight_invalid && + state.state <= AltosLib.ao_flight_landed) + { + if (state.state > Altos.ao_flight_pad) + want_file = true; + if (state.state == AltosLib.ao_flight_landed) done = true; - if (r.cmd != AltosLib.AO_LOG_INVALID) - any_valid = true; - LogMega(r); - } catch (ParseException pe) { - if (parse_exception == null) - parse_exception = pe; } - } - if (!any_valid) - done = true; - CheckFile(false); - } - - void LogMini(AltosEepromMini r) throws IOException { - if (r.cmd != Altos.AO_LOG_INVALID) { - String log_line = String.format("%c %4x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x\n", - r.cmd, r.tick, - r.data8[0], r.data8[1], r.data8[2], r.data8[3], - r.data8[4], r.data8[5], r.data8[6], r.data8[7], - r.data8[8], r.data8[9], r.data8[10], r.data8[11]); - if (eeprom_file != null) - eeprom_file.write(log_line); - else - eeprom_pending.add(log_line); - } - } - - void CaptureMini(AltosEepromChunk eechunk) throws IOException { - boolean any_valid = false; + if (state.gps != null) + want_file = true; - extension = "mini"; - set_serial(flights.config_data.serial); - for (int i = 0; i < AltosEepromChunk.chunk_size && !done; i += AltosEepromMini.record_length) { - try { - AltosEepromMini r = new AltosEepromMini(eechunk, i); - if (r.cmd == Altos.AO_LOG_FLIGHT) - set_flight(r.data16(0)); - - /* Monitor state transitions to update display */ - if (r.cmd == Altos.AO_LOG_STATE && r.data16(0) <= Altos.ao_flight_landed) { - state = r.data16(0); - if (state > Altos.ao_flight_pad) - want_file = true; - } - - if (r.cmd == Altos.AO_LOG_STATE && r.data16(0) == Altos.ao_flight_landed) - done = true; + if (r.valid) { any_valid = true; - LogMini(r); - } catch (ParseException pe) { - if (parse_exception == null) - parse_exception = pe; + LogEeprom(r); } } if (!any_valid) @@ -350,15 +138,12 @@ public class AltosEepromDownload implements Runnable { CheckFile(false); } - void CaptureTelemetry(AltosEepromChunk eechunk) throws IOException { - - } - void CaptureLog(AltosEepromLog log) throws IOException, InterruptedException, TimeoutException { int block, state_block = 0; int log_format = flights.config_data.log_format; - state = 0; + state = new AltosState(); + done = false; start = true; @@ -366,10 +151,6 @@ public class AltosEepromDownload implements Runnable { throw new IOException("no serial number found"); /* Reset per-capture variables */ - flight = 0; - year = 0; - month = 0; - day = 0; want_file = false; eeprom_file = null; eeprom_pending = new LinkedList<String>(); @@ -377,9 +158,12 @@ public class AltosEepromDownload implements Runnable { /* Set serial number in the monitor dialog window */ /* Now scan the eeprom, reading blocks of data and converting to .eeprom file form */ - state = 0; state_block = log.start_block; + state_block = log.start_block; for (block = log.start_block; !done && block < log.end_block; block++) { - monitor.set_value(AltosLib.state_name(state), state, block - state_block, block - log.start_block); + monitor.set_value(state.state_name(), + state.state, + block - state_block, + block - log.start_block); AltosEepromChunk eechunk = new AltosEepromChunk(serial_line, block, block == log.start_block); @@ -397,32 +181,7 @@ public class AltosEepromDownload implements Runnable { } } - switch (log_format) { - case AltosLib.AO_LOG_FORMAT_FULL: - extension = "eeprom"; - CaptureFull(eechunk); - break; - case AltosLib.AO_LOG_FORMAT_TINY: - extension = "eeprom"; - CaptureTiny(eechunk); - break; - case AltosLib.AO_LOG_FORMAT_TELEMETRY: - extension = "telem"; - CaptureTelemetry(eechunk); - break; - case AltosLib.AO_LOG_FORMAT_TELESCIENCE: - extension = "science"; - CaptureTeleScience(eechunk); - break; - case AltosLib.AO_LOG_FORMAT_TELEMEGA: - extension = "mega"; - CaptureMega(eechunk); - break; - case AltosLib.AO_LOG_FORMAT_MINI: - extension = "mini"; - CaptureMini(eechunk); - break; - } + CaptureEeprom (eechunk, log_format); } CheckFile(true); if (eeprom_file != null) { @@ -480,7 +239,10 @@ public class AltosEepromDownload implements Runnable { serial_line.device.toShortString(), JOptionPane.ERROR_MESSAGE); } catch (InterruptedException ie) { - System.out.printf("download interrupted\n"); + show_message(String.format("Connection to \"%s\" interrupted", + serial_line.device.toShortString()), + "Connection Interrupted", + JOptionPane.ERROR_MESSAGE); } catch (TimeoutException te) { show_message(String.format("Connection to \"%s\" failed", serial_line.device.toShortString()), diff --git a/altosui/AltosEepromList.java b/altosui/AltosEepromList.java index a63d173d..258c421a 100644 --- a/altosui/AltosEepromList.java +++ b/altosui/AltosEepromList.java @@ -21,7 +21,7 @@ import java.io.*; import java.util.*; import java.text.*; import java.util.concurrent.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; /* * Temporary structure to hold the list of stored flights; diff --git a/altosui/AltosEepromManage.java b/altosui/AltosEepromManage.java index 7a721196..b2d8a130 100644 --- a/altosui/AltosEepromManage.java +++ b/altosui/AltosEepromManage.java @@ -21,7 +21,7 @@ import java.awt.event.*; import javax.swing.*; import java.io.*; import java.util.concurrent.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; import org.altusmetrum.altosuilib_1.*; public class AltosEepromManage implements ActionListener { diff --git a/altosui/AltosEepromSelect.java b/altosui/AltosEepromSelect.java index a451aa3a..8f86eebf 100644 --- a/altosui/AltosEepromSelect.java +++ b/altosui/AltosEepromSelect.java @@ -21,7 +21,7 @@ import javax.swing.*; import javax.swing.border.*; import java.awt.*; import java.awt.event.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; import org.altusmetrum.altosuilib_1.*; class AltosEepromItem implements ActionListener { diff --git a/altosui/AltosFlashUI.java b/altosui/AltosFlashUI.java index f4e52218..6eccface 100644 --- a/altosui/AltosFlashUI.java +++ b/altosui/AltosFlashUI.java @@ -23,7 +23,7 @@ import javax.swing.*; import javax.swing.filechooser.FileNameExtensionFilter; import java.io.*; import java.util.concurrent.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; import org.altusmetrum.altosuilib_1.*; public class AltosFlashUI diff --git a/altosui/AltosFlightDisplay.java b/altosui/AltosFlightDisplay.java index 4f4c158e..289ddd01 100644 --- a/altosui/AltosFlightDisplay.java +++ b/altosui/AltosFlightDisplay.java @@ -17,7 +17,7 @@ package altosui; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; public interface AltosFlightDisplay { void reset(); diff --git a/altosui/AltosFlightStats.java b/altosui/AltosFlightStats.java index dee31a8d..11a3f1a9 100644 --- a/altosui/AltosFlightStats.java +++ b/altosui/AltosFlightStats.java @@ -18,14 +18,13 @@ package altosui; import java.io.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; public class AltosFlightStats { double max_height; double max_speed; double max_acceleration; - double[] state_accel_speed = new double[Altos.ao_flight_invalid + 1]; - double[] state_baro_speed = new double[Altos.ao_flight_invalid + 1]; + double[] state_speed = new double[Altos.ao_flight_invalid + 1]; double[] state_accel = new double[Altos.ao_flight_invalid + 1]; int[] state_count = new int[Altos.ao_flight_invalid + 1]; double[] state_start = new double[Altos.ao_flight_invalid + 1]; @@ -40,16 +39,19 @@ public class AltosFlightStats { boolean has_other_adc; boolean has_rssi; - double landed_time(AltosRecordIterable iterable) { - AltosState state = null; - for (AltosRecord record : iterable) { - state = new AltosState(record, state); + double landed_time(AltosStateIterable states) { + AltosState state = null; + for (AltosState s : states) { + state = s; if (state.state == Altos.ao_flight_landed) break; } - double landed_height = state.height; + if (state == null) + return 0; + + double landed_height = state.height(); state = null; @@ -57,13 +59,13 @@ public class AltosFlightStats { double landed_time = -1000; - for (AltosRecord record : iterable) { - state = new AltosState(record, state); + for (AltosState s : states) { + state = s; - if (state.height > landed_height + 10) { + if (state.height() > landed_height + 10) { above = true; } else { - if (above && state.height < landed_height + 2) { + if (above && state.height() < landed_height + 2) { above = false; landed_time = state.time; } @@ -74,81 +76,71 @@ public class AltosFlightStats { return landed_time; } - double boost_time(AltosRecordIterable iterable) { - double boost_time = -1000; - - AltosState state = null; + double boost_time(AltosStateIterable states) { + double boost_time = AltosLib.MISSING; + AltosState state = null; - for (AltosRecord record : iterable) { - state = new AltosState(record, state); - - if (state.acceleration < 1) + for (AltosState s : states) { + state = s; + if (state.acceleration() < 1) boost_time = state.time; if (state.state >= Altos.ao_flight_boost) break; } - if (boost_time == -1000) + if (state == null) + return 0; + + if (boost_time == AltosLib.MISSING) boost_time = state.time; return boost_time; } - public AltosFlightStats(AltosRecordIterable iterable) throws InterruptedException, IOException { - AltosState state = null; - AltosState new_state = null; - double boost_time = boost_time(iterable); + public AltosFlightStats(AltosStateIterable states) throws InterruptedException, IOException { + double boost_time = boost_time(states); double end_time = 0; - double landed_time = landed_time(iterable); + double landed_time = landed_time(states); - year = month = day = -1; - hour = minute = second = -1; - serial = flight = -1; - lat = lon = -1; + year = month = day = AltosLib.MISSING; + hour = minute = second = AltosLib.MISSING; + serial = flight = AltosLib.MISSING; + lat = lon = AltosLib.MISSING; has_gps = false; has_other_adc = false; has_rssi = false; - for (AltosRecord record : iterable) { - if (serial < 0) - serial = record.serial; - if ((record.seen & AltosRecord.seen_flight) != 0 && flight < 0) - flight = record.flight; - if ((record.seen & AltosRecord.seen_temp_volt) != 0) + for (AltosState state : states) { + if (serial == AltosLib.MISSING && state.serial != AltosLib.MISSING) + serial = state.serial; + if (flight == AltosLib.MISSING && state.flight != AltosLib.MISSING) + flight = state.flight; + if (state.battery_voltage != AltosLib.MISSING) has_other_adc = true; - if (record.rssi != 0) + if (state.rssi != AltosLib.MISSING) has_rssi = true; - new_state = new AltosState(record, state); - end_time = new_state.time; - state = new_state; + end_time = state.time; if (state.time >= boost_time && state.state < Altos.ao_flight_boost) state.state = Altos.ao_flight_boost; if (state.time >= landed_time && state.state < Altos.ao_flight_landed) state.state = Altos.ao_flight_landed; + if (state.gps != null && state.gps.locked) { + year = state.gps.year; + month = state.gps.month; + day = state.gps.day; + hour = state.gps.hour; + minute = state.gps.minute; + second = state.gps.second; + } if (0 <= state.state && state.state < Altos.ao_flight_invalid) { - if (state.state >= Altos.ao_flight_boost) { - if (state.gps != null && state.gps.locked && - year < 0) { - year = state.gps.year; - month = state.gps.month; - day = state.gps.day; - hour = state.gps.hour; - minute = state.gps.minute; - second = state.gps.second; - } - } - state_accel[state.state] += state.acceleration; - state_accel_speed[state.state] += state.accel_speed; - state_baro_speed[state.state] += state.baro_speed; + state_accel[state.state] += state.acceleration(); + state_speed[state.state] += state.speed(); state_count[state.state]++; if (state_start[state.state] == 0.0) state_start[state.state] = state.time; if (state_end[state.state] < state.time) state_end[state.state] = state.time; - max_height = state.max_height; - if (state.max_accel_speed != 0) - max_speed = state.max_accel_speed; - else - max_speed = state.max_baro_speed; - max_acceleration = state.max_acceleration; + max_height = state.max_height(); + max_speed = state.max_speed(); + max_acceleration = state.max_acceleration(); } if (state.gps != null && state.gps.locked && state.gps.nsat >= 4) { if (state.state <= Altos.ao_flight_pad) { @@ -162,8 +154,7 @@ public class AltosFlightStats { } for (int s = Altos.ao_flight_startup; s <= Altos.ao_flight_landed; s++) { if (state_count[s] > 0) { - state_accel_speed[s] /= state_count[s]; - state_baro_speed[s] /= state_count[s]; + state_speed[s] /= state_count[s]; state_accel[s] /= state_count[s]; } if (state_start[s] == 0) diff --git a/altosui/AltosFlightStatsTable.java b/altosui/AltosFlightStatsTable.java index a35b5f63..db875b3b 100644 --- a/altosui/AltosFlightStatsTable.java +++ b/altosui/AltosFlightStatsTable.java @@ -19,7 +19,7 @@ package altosui; import java.awt.*; import javax.swing.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; public class AltosFlightStatsTable extends JComponent { GridBagLayout layout; @@ -76,15 +76,15 @@ public class AltosFlightStatsTable extends JComponent { int y = 0; new FlightStat(layout, y++, "Serial", String.format("%d", stats.serial)); new FlightStat(layout, y++, "Flight", String.format("%d", stats.flight)); - if (stats.year > 0 && stats.hour > 0) + if (stats.year != AltosLib.MISSING && stats.hour != AltosLib.MISSING) new FlightStat(layout, y++, "Date/Time", String.format("%04d-%02d-%02d", stats.year, stats.month, stats.day), String.format("%02d:%02d:%02d UTC", stats.hour, stats.minute, stats.second)); else { - if (stats.year > 0) + if (stats.year != AltosLib.MISSING) new FlightStat(layout, y++, "Date", String.format("%04d-%02d-%02d", stats.year, stats.month, stats.day)); - if (stats.hour > 0) + if (stats.hour != AltosLib.MISSING) new FlightStat(layout, y++, "Time", String.format("%02d:%02d:%02d UTC", stats.hour, stats.minute, stats.second)); } @@ -95,7 +95,7 @@ public class AltosFlightStatsTable extends JComponent { String.format("%5.0f m/s", stats.max_speed), String.format("%5.0f mph", AltosConvert.meters_to_mph(stats.max_speed)), String.format("Mach %4.1f", AltosConvert.meters_to_mach(stats.max_speed))); - if (stats.max_acceleration != AltosRecord.MISSING) { + if (stats.max_acceleration != AltosLib.MISSING) { new FlightStat(layout, y++, "Maximum boost acceleration", String.format("%5.0f m/s²", stats.max_acceleration), String.format("%5.0f ft/s²", AltosConvert.meters_to_feet(stats.max_acceleration)), @@ -106,11 +106,11 @@ public class AltosFlightStatsTable extends JComponent { String.format("%5.0f G", AltosConvert.meters_to_g(stats.state_accel[Altos.ao_flight_boost]))); } new FlightStat(layout, y++, "Drogue descent rate", - String.format("%5.0f m/s", stats.state_baro_speed[Altos.ao_flight_drogue]), - String.format("%5.0f ft/s", AltosConvert.meters_to_feet(stats.state_baro_speed[Altos.ao_flight_drogue]))); + String.format("%5.0f m/s", stats.state_speed[Altos.ao_flight_drogue]), + String.format("%5.0f ft/s", AltosConvert.meters_to_feet(stats.state_speed[Altos.ao_flight_drogue]))); new FlightStat(layout, y++, "Main descent rate", - String.format("%5.0f m/s", stats.state_baro_speed[Altos.ao_flight_main]), - String.format("%5.0f ft/s", AltosConvert.meters_to_feet(stats.state_baro_speed[Altos.ao_flight_main]))); + String.format("%5.0f m/s", stats.state_speed[Altos.ao_flight_main]), + String.format("%5.0f ft/s", AltosConvert.meters_to_feet(stats.state_speed[Altos.ao_flight_main]))); new FlightStat(layout, y++, "Ascent time", String.format("%6.1f s %s", stats.state_end[AltosLib.ao_flight_boost] - stats.state_start[AltosLib.ao_flight_boost], AltosLib.state_name(Altos.ao_flight_boost)), diff --git a/altosui/AltosFlightStatus.java b/altosui/AltosFlightStatus.java index d2910414..9d575e4c 100644 --- a/altosui/AltosFlightStatus.java +++ b/altosui/AltosFlightStatus.java @@ -19,7 +19,7 @@ package altosui; import java.awt.*; import javax.swing.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; public class AltosFlightStatus extends JComponent implements AltosFlightDisplay { GridBagLayout layout; @@ -65,7 +65,7 @@ public class AltosFlightStatus extends JComponent implements AltosFlightDisplay class Call extends FlightValue { void show(AltosState state, AltosListenerState listener_state) { - value.setText(state.data.callsign); + value.setText(state.callsign); } public Call (GridBagLayout layout, int x) { super (layout, x, "Callsign"); @@ -76,10 +76,10 @@ public class AltosFlightStatus extends JComponent implements AltosFlightDisplay class Serial extends FlightValue { void show(AltosState state, AltosListenerState listener_state) { - if (state.data.serial == AltosRecord.MISSING) + if (state.serial == AltosLib.MISSING) value.setText("none"); else - value.setText(String.format("%d", state.data.serial)); + value.setText(String.format("%d", state.serial)); } public Serial (GridBagLayout layout, int x) { super (layout, x, "Serial"); @@ -90,10 +90,10 @@ public class AltosFlightStatus extends JComponent implements AltosFlightDisplay class Flight extends FlightValue { void show(AltosState state, AltosListenerState listener_state) { - if (state.data.flight == AltosRecord.MISSING) + if (state.flight == AltosLib.MISSING) value.setText("none"); else - value.setText(String.format("%d", state.data.flight)); + value.setText(String.format("%d", state.flight)); } public Flight (GridBagLayout layout, int x) { super (layout, x, "Flight"); @@ -104,7 +104,7 @@ public class AltosFlightStatus extends JComponent implements AltosFlightDisplay class FlightState extends FlightValue { void show(AltosState state, AltosListenerState listener_state) { - value.setText(state.data.state()); + value.setText(state.state_name()); } public FlightState (GridBagLayout layout, int x) { super (layout, x, "State"); @@ -115,7 +115,7 @@ public class AltosFlightStatus extends JComponent implements AltosFlightDisplay class RSSI extends FlightValue { void show(AltosState state, AltosListenerState listener_state) { - value.setText(String.format("%d", state.data.rssi)); + value.setText(String.format("%d", state.rssi())); } public RSSI (GridBagLayout layout, int x) { super (layout, x, "RSSI"); @@ -126,7 +126,7 @@ public class AltosFlightStatus extends JComponent implements AltosFlightDisplay class LastPacket extends FlightValue { void show(AltosState state, AltosListenerState listener_state) { - long secs = (System.currentTimeMillis() - state.report_time + 500) / 1000; + long secs = (System.currentTimeMillis() - state.received_time + 500) / 1000; value.setText(String.format("%d", secs)); } public LastPacket(GridBagLayout layout, int x) { diff --git a/altosui/AltosFlightStatusTableModel.java b/altosui/AltosFlightStatusTableModel.java index 6a327841..08154fda 100644 --- a/altosui/AltosFlightStatusTableModel.java +++ b/altosui/AltosFlightStatusTableModel.java @@ -27,7 +27,7 @@ import java.util.*; import java.text.*; import java.util.prefs.*; import java.util.concurrent.LinkedBlockingQueue; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; public class AltosFlightStatusTableModel extends AbstractTableModel { private String[] columnNames = { diff --git a/altosui/AltosFlightStatusUpdate.java b/altosui/AltosFlightStatusUpdate.java index 962a08f7..7821a777 100644 --- a/altosui/AltosFlightStatusUpdate.java +++ b/altosui/AltosFlightStatusUpdate.java @@ -18,7 +18,7 @@ package altosui; import java.awt.event.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; public class AltosFlightStatusUpdate implements ActionListener { diff --git a/altosui/AltosFlightUI.java b/altosui/AltosFlightUI.java index 6d010d23..c151177e 100644 --- a/altosui/AltosFlightUI.java +++ b/altosui/AltosFlightUI.java @@ -21,7 +21,7 @@ import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.util.concurrent.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; import org.altusmetrum.altosuilib_1.*; public class AltosFlightUI extends AltosUIFrame implements AltosFlightDisplay, AltosFontListener { @@ -102,7 +102,7 @@ public class AltosFlightUI extends AltosUIFrame implements AltosFlightDisplay, A status_update.saved_state = state; if (state == null) - state = new AltosState(new AltosRecord()); + state = new AltosState(); pad.show(state, listener_state); @@ -130,7 +130,7 @@ public class AltosFlightUI extends AltosUIFrame implements AltosFlightDisplay, A flightStatus.show(state, listener_state); flightInfo.show(state, listener_state); - if (state.data.companion != null) { + if (state.companion != null) { if (!has_companion) { pane.add("Companion", companion); has_companion= true; diff --git a/altosui/AltosFreqList.java b/altosui/AltosFreqList.java index 7464ac3e..917ac364 100644 --- a/altosui/AltosFreqList.java +++ b/altosui/AltosFreqList.java @@ -18,7 +18,7 @@ package altosui; import javax.swing.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; import org.altusmetrum.altosuilib_1.*; public class AltosFreqList extends JComboBox { diff --git a/altosui/AltosGraph.java b/altosui/AltosGraph.java index a73e3fd8..e6cd7bd8 100644 --- a/altosui/AltosGraph.java +++ b/altosui/AltosGraph.java @@ -22,7 +22,7 @@ import java.util.ArrayList; import java.awt.*; import javax.swing.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; import org.altusmetrum.altosuilib_1.*; import org.jfree.ui.*; diff --git a/altosui/AltosGraphDataPoint.java b/altosui/AltosGraphDataPoint.java index 7454f447..d8191f5d 100644 --- a/altosui/AltosGraphDataPoint.java +++ b/altosui/AltosGraphDataPoint.java @@ -18,7 +18,7 @@ package altosui; import org.altusmetrum.altosuilib_1.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; public class AltosGraphDataPoint implements AltosUIDataPoint { @@ -42,37 +42,38 @@ public class AltosGraphDataPoint implements AltosUIDataPoint { public static final int data_pressure = 15; public double x() throws AltosUIDataMissing { - if (state.data.time < -2) + double time = state.time_since_boost(); + if (time < -2) throw new AltosUIDataMissing(-1); - return state.data.time; + return time; } public double y(int index) throws AltosUIDataMissing { - double y = AltosRecord.MISSING; + double y = AltosLib.MISSING; switch (index) { case data_height: - y = state.height; + y = state.height(); break; case data_speed: y = state.speed(); break; case data_accel: - y = state.acceleration; + y = state.acceleration(); break; case data_temp: y = state.temperature; break; case data_battery_voltage: - y = state.battery; + y = state.battery_voltage; break; case data_drogue_voltage: - y = state.drogue_sense; + y = state.apogee_voltage; break; case data_main_voltage: - y = state.main_sense; + y = state.main_voltage; break; case data_rssi: - y = state.data.rssi; + y = state.rssi; break; case data_gps_height: y = state.gps_height; @@ -96,17 +97,17 @@ public class AltosGraphDataPoint implements AltosUIDataPoint { y = state.from_pad.distance; break; case data_pressure: - y = state.pressure; + y = state.pressure(); break; } - if (y == AltosRecord.MISSING) + if (y == AltosLib.MISSING) throw new AltosUIDataMissing(index); return y; } public int id(int index) { if (index == data_state) { - int s = state.data.state; + int s = state.state; if (s < Altos.ao_flight_boost || s > Altos.ao_flight_landed) return -1; return s; @@ -116,7 +117,7 @@ public class AltosGraphDataPoint implements AltosUIDataPoint { public String id_name(int index) { if (index == data_state) - return state.data.state(); + return state.state_name(); return ""; } diff --git a/altosui/AltosGraphDataSet.java b/altosui/AltosGraphDataSet.java index dc047e9a..4e6c46d1 100644 --- a/altosui/AltosGraphDataSet.java +++ b/altosui/AltosGraphDataSet.java @@ -20,39 +20,36 @@ package altosui; import java.lang.*; import java.io.*; import java.util.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; import org.altusmetrum.altosuilib_1.*; class AltosGraphIterator implements Iterator<AltosUIDataPoint> { AltosGraphDataSet dataSet; - Iterator<AltosRecord> iterator; - - AltosState state; + Iterator<AltosState> iterator; public boolean hasNext() { return iterator.hasNext(); } public AltosUIDataPoint next() { - state = new AltosState(iterator.next(), state); + AltosState state = iterator.next(); - if ((state.data.seen & AltosRecord.seen_flight) != 0) { - if (dataSet.callsign == null && state.data.callsign != null) - dataSet.callsign = state.data.callsign; + if (state.flight != AltosLib.MISSING) { + if (dataSet.callsign == null && state.callsign != null) + dataSet.callsign = state.callsign; - if (dataSet.serial == 0 && state.data.serial != 0) - dataSet.serial = state.data.serial; + if (dataSet.serial == 0 && state.serial != 0) + dataSet.serial = state.serial; - if (dataSet.flight == 0 && state.data.flight != 0) - dataSet.flight = state.data.flight; + if (dataSet.flight == 0 && state.flight != 0) + dataSet.flight = state.flight; } return new AltosGraphDataPoint(state); } - public AltosGraphIterator (Iterator<AltosRecord> iterator, AltosGraphDataSet dataSet) { + public AltosGraphIterator (Iterator<AltosState> iterator, AltosGraphDataSet dataSet) { this.iterator = iterator; - this.state = null; this.dataSet = dataSet; } @@ -64,7 +61,7 @@ class AltosGraphIterable implements Iterable<AltosUIDataPoint> { AltosGraphDataSet dataSet; public Iterator<AltosUIDataPoint> iterator() { - return new AltosGraphIterator(dataSet.records.iterator(), dataSet); + return new AltosGraphIterator(dataSet.states.iterator(), dataSet); } public AltosGraphIterable(AltosGraphDataSet dataSet) { @@ -76,7 +73,7 @@ public class AltosGraphDataSet implements AltosUIDataSet { String callsign; int serial; int flight; - AltosRecordIterable records; + AltosStateIterable states; public String name() { if (callsign != null) @@ -89,8 +86,8 @@ public class AltosGraphDataSet implements AltosUIDataSet { return new AltosGraphIterable(this); } - public AltosGraphDataSet (AltosRecordIterable records) { - this.records = records; + public AltosGraphDataSet (AltosStateIterable states) { + this.states = states; this.callsign = null; this.serial = 0; this.flight = 0; diff --git a/altosui/AltosGraphUI.java b/altosui/AltosGraphUI.java index d8b8f6dd..c42f7b5f 100644 --- a/altosui/AltosGraphUI.java +++ b/altosui/AltosGraphUI.java @@ -9,7 +9,7 @@ import java.util.ArrayList; import java.awt.*; import javax.swing.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; import org.altusmetrum.altosuilib_1.*; import org.jfree.chart.ChartPanel; @@ -28,10 +28,9 @@ public class AltosGraphUI extends AltosUIFrame AltosFlightStatsTable statsTable; boolean has_gps; - void fill_map(AltosRecordIterable records) { + void fill_map(AltosStateIterable states) { boolean any_gps = false; - for (AltosRecord record : records) { - state = new AltosState(record, state); + for (AltosState state : states) { if (state.gps != null && state.gps.locked && state.gps.nsat >= 4) { if (map == null) map = new AltosSiteMap(); @@ -41,7 +40,7 @@ public class AltosGraphUI extends AltosUIFrame } } - AltosGraphUI(AltosRecordIterable records, File file) throws InterruptedException, IOException { + AltosGraphUI(AltosStateIterable states, File file) throws InterruptedException, IOException { super(file.getName()); state = null; @@ -49,8 +48,8 @@ public class AltosGraphUI extends AltosUIFrame enable = new AltosUIEnable(); - stats = new AltosFlightStats(records); - graphDataSet = new AltosGraphDataSet(records); + stats = new AltosFlightStats(states); + graphDataSet = new AltosGraphDataSet(states); graph = new AltosGraph(enable, stats, graphDataSet); @@ -61,7 +60,7 @@ public class AltosGraphUI extends AltosUIFrame pane.add("Flight Statistics", statsTable); has_gps = false; - fill_map(records); + fill_map(states); if (has_gps) pane.add("Map", map); diff --git a/altosui/AltosIdleMonitorUI.java b/altosui/AltosIdleMonitorUI.java index bbab017f..f4e16243 100644 --- a/altosui/AltosIdleMonitorUI.java +++ b/altosui/AltosIdleMonitorUI.java @@ -23,7 +23,7 @@ import javax.swing.*; import javax.swing.event.*; import java.io.*; import java.util.concurrent.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; import org.altusmetrum.altosuilib_1.*; public class AltosIdleMonitorUI extends AltosUIFrame implements AltosFlightDisplay, AltosFontListener, AltosIdleMonitorListener, DocumentListener { @@ -65,13 +65,13 @@ public class AltosIdleMonitorUI extends AltosUIFrame implements AltosFlightDispl public void show(AltosState state, AltosListenerState listener_state) { status_update.saved_state = state; - try { +// try { pad.show(state, listener_state); flightStatus.show(state, listener_state); flightInfo.show(state, listener_state); - } catch (Exception e) { - System.out.print("Show exception" + e); - } +// } catch (Exception e) { +// System.out.print("Show exception " + e); +// } } public void update(final AltosState state, final AltosListenerState listener_state) { diff --git a/altosui/AltosIgniteUI.java b/altosui/AltosIgniteUI.java index 14d4eebc..c8024aae 100644 --- a/altosui/AltosIgniteUI.java +++ b/altosui/AltosIgniteUI.java @@ -23,7 +23,7 @@ import javax.swing.*; import java.io.*; import java.text.*; import java.util.concurrent.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; import org.altusmetrum.altosuilib_1.*; public class AltosIgniteUI diff --git a/altosui/AltosInfoTable.java b/altosui/AltosInfoTable.java index 3d16faf2..feafed21 100644 --- a/altosui/AltosInfoTable.java +++ b/altosui/AltosInfoTable.java @@ -20,7 +20,7 @@ package altosui; import java.awt.*; import javax.swing.*; import javax.swing.table.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; public class AltosInfoTable extends JTable { private AltosFlightInfoTableModel model; @@ -107,35 +107,37 @@ public class AltosInfoTable extends JTable { public void show(AltosState state, AltosListenerState listener_state) { info_reset(); if (state != null) { - if (state.altitude != AltosRecord.MISSING) - info_add_row(0, "Altitude", "%6.0f m", state.altitude); - if (state.ground_altitude != AltosRecord.MISSING) - info_add_row(0, "Pad altitude", "%6.0f m", state.ground_altitude); - if (state.height != AltosRecord.MISSING) - info_add_row(0, "Height", "%6.0f m", state.height); - if (state.height != AltosRecord.MISSING) - info_add_row(0, "Max height", "%6.0f m", state.max_height); - if (state.acceleration != AltosRecord.MISSING) - info_add_row(0, "Acceleration", "%8.1f m/s²", state.acceleration); - if (state.acceleration != AltosRecord.MISSING) - info_add_row(0, "Max acceleration", "%8.1f m/s²", state.max_acceleration); - if (state.speed() != AltosRecord.MISSING) + if (state.device_type != AltosLib.MISSING) + info_add_row(0, "Device", "%s", AltosLib.product_name(state.device_type)); + if (state.altitude() != AltosLib.MISSING) + info_add_row(0, "Altitude", "%6.0f m", state.altitude()); + if (state.ground_altitude() != AltosLib.MISSING) + info_add_row(0, "Pad altitude", "%6.0f m", state.ground_altitude()); + if (state.height() != AltosLib.MISSING) + info_add_row(0, "Height", "%6.0f m", state.height()); + if (state.max_height() != AltosLib.MISSING) + info_add_row(0, "Max height", "%6.0f m", state.max_height()); + if (state.acceleration() != AltosLib.MISSING) + info_add_row(0, "Acceleration", "%8.1f m/s²", state.acceleration()); + if (state.max_acceleration() != AltosLib.MISSING) + info_add_row(0, "Max acceleration", "%8.1f m/s²", state.max_acceleration()); + if (state.speed() != AltosLib.MISSING) info_add_row(0, "Speed", "%8.1f m/s", state.speed()); - if (state.speed() != AltosRecord.MISSING) - info_add_row(0, "Max Speed", "%8.1f m/s", state.max_accel_speed); - if (state.temperature != AltosRecord.MISSING) + if (state.max_speed() != AltosLib.MISSING) + info_add_row(0, "Max Speed", "%8.1f m/s", state.max_speed()); + if (state.temperature != AltosLib.MISSING) info_add_row(0, "Temperature", "%9.2f °C", state.temperature); - if (state.battery != AltosRecord.MISSING) - info_add_row(0, "Battery", "%9.2f V", state.battery); - if (state.drogue_sense != AltosRecord.MISSING) - info_add_row(0, "Drogue", "%9.2f V", state.drogue_sense); - if (state.main_sense != AltosRecord.MISSING) - info_add_row(0, "Main", "%9.2f V", state.main_sense); + if (state.battery_voltage != AltosLib.MISSING) + info_add_row(0, "Battery", "%9.2f V", state.battery_voltage); + if (state.apogee_voltage != AltosLib.MISSING) + info_add_row(0, "Drogue", "%9.2f V", state.apogee_voltage); + if (state.main_voltage != AltosLib.MISSING) + info_add_row(0, "Main", "%9.2f V", state.main_voltage); } if (listener_state != null) { info_add_row(0, "CRC Errors", "%6d", listener_state.crc_errors); - if (listener_state.battery != AltosRecord.MISSING) + if (listener_state.battery != AltosLib.MISSING) info_add_row(0, "Receiver Battery", "%9.2f", listener_state.battery); } @@ -148,17 +150,21 @@ public class AltosInfoTable extends JTable { else info_add_row(1, "GPS state", "wait (%d)", state.gps_waiting); - if (state.data.gps.locked) + if (state.gps.locked) info_add_row(1, "GPS", " locked"); - else if (state.data.gps.connected) + else if (state.gps.connected) info_add_row(1, "GPS", " unlocked"); else info_add_row(1, "GPS", " missing"); - info_add_row(1, "Satellites", "%6d", state.data.gps.nsat); - info_add_deg(1, "Latitude", state.gps.lat, 'N', 'S'); - info_add_deg(1, "Longitude", state.gps.lon, 'E', 'W'); - info_add_row(1, "GPS altitude", "%6d", state.gps.alt); - info_add_row(1, "GPS height", "%6.0f", state.gps_height); + info_add_row(1, "Satellites", "%6d", state.gps.nsat); + if (state.gps.lat != AltosLib.MISSING) + info_add_deg(1, "Latitude", state.gps.lat, 'N', 'S'); + if (state.gps.lon != AltosLib.MISSING) + info_add_deg(1, "Longitude", state.gps.lon, 'E', 'W'); + if (state.gps.alt != AltosLib.MISSING) + info_add_row(1, "GPS altitude", "%8.1f", state.gps.alt); + if (state.gps_height != AltosLib.MISSING) + info_add_row(1, "GPS height", "%8.1f", state.gps_height); /* The SkyTraq GPS doesn't report these values */ /* @@ -195,14 +201,16 @@ public class AltosInfoTable extends JTable { info_add_deg(1, "Pad longitude", state.pad_lon, 'E', 'W'); info_add_row(1, "Pad GPS alt", "%6.0f m", state.pad_alt); } - info_add_row(1, "GPS date", "%04d-%02d-%02d", - state.gps.year, - state.gps.month, - state.gps.day); - info_add_row(1, "GPS time", " %02d:%02d:%02d", - state.gps.hour, - state.gps.minute, - state.gps.second); + if (state.gps.year != AltosLib.MISSING) + info_add_row(1, "GPS date", "%04d-%02d-%02d", + state.gps.year, + state.gps.month, + state.gps.day); + if (state.gps.hour != AltosLib.MISSING) + info_add_row(1, "GPS time", " %02d:%02d:%02d", + state.gps.hour, + state.gps.minute, + state.gps.second); //int nsat_vis = 0; int c; diff --git a/altosui/AltosKML.java b/altosui/AltosKML.java index 140f3f07..fbb0ece4 100644 --- a/altosui/AltosKML.java +++ b/altosui/AltosKML.java @@ -18,14 +18,14 @@ package altosui; import java.io.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; public class AltosKML implements AltosWriter { File name; PrintStream out; - int state = -1; - AltosRecord prev = null; + int flight_state = -1; + AltosState prev = null; double gps_start_altitude; static final String[] kml_state_colors = { @@ -83,7 +83,7 @@ public class AltosKML implements AltosWriter { "</Document>\n" + "</kml>\n"; - void start (AltosRecord record) { + void start (AltosState record) { out.printf(kml_header_start, record.flight, record.serial); out.printf("Date: %04d-%02d-%02d\n", record.gps.year, record.gps.month, record.gps.day); @@ -94,30 +94,30 @@ public class AltosKML implements AltosWriter { boolean started = false; - void state_start(AltosRecord record) { - String state_name = Altos.state_name(record.state); - out.printf(kml_style_start, state_name, kml_state_colors[record.state]); + void state_start(AltosState state) { + String state_name = Altos.state_name(state.state); + out.printf(kml_style_start, state_name, kml_state_colors[state.state]); out.printf("\tState: %s\n", state_name); out.printf("%s", kml_style_end); out.printf(kml_placemark_start, state_name, state_name); } - void state_end(AltosRecord record) { + void state_end(AltosState state) { out.printf("%s", kml_placemark_end); } - void coord(AltosRecord record) { - AltosGPS gps = record.gps; + void coord(AltosState state) { + AltosGPS gps = state.gps; double altitude; - if (record.height() != AltosRecord.MISSING) - altitude = record.height() + gps_start_altitude; + if (state.height() != AltosLib.MISSING) + altitude = state.height() + gps_start_altitude; else altitude = gps.alt; out.printf(kml_coord_fmt, gps.lon, gps.lat, altitude, (double) gps.alt, - record.time, gps.nsat); + state.time, gps.nsat); } void end() { @@ -132,38 +132,40 @@ public class AltosKML implements AltosWriter { } } - public void write(AltosRecord record) { - AltosGPS gps = record.gps; + public void write(AltosState state) { + AltosGPS gps = state.gps; if (gps == null) return; - if ((record.seen & (AltosRecord.seen_gps_lat)) == 0) + if (gps.lat == AltosLib.MISSING) return; - if ((record.seen & (AltosRecord.seen_gps_lon)) == 0) + if (gps.lon == AltosLib.MISSING) return; if (!started) { - start(record); + start(state); started = true; gps_start_altitude = gps.alt; } - if (prev != null && prev.gps_sequence == record.gps_sequence) + if (prev != null && prev.gps_sequence == state.gps_sequence) return; - if (record.state != state) { - state = record.state; + if (state.state != flight_state) { + flight_state = state.state; if (prev != null) { - coord(record); + coord(state); state_end(prev); } - state_start(record); + state_start(state); } - coord(record); - prev = record; + coord(state); + prev = state; } - public void write(AltosRecordIterable iterable) { - for (AltosRecord record : iterable) - write(record); + public void write(AltosStateIterable states) { + for (AltosState state : states) { + if ((state.set & AltosState.set_gps) != 0) + write(state); + } } public AltosKML(File in_name) throws FileNotFoundException { diff --git a/altosui/AltosLanded.java b/altosui/AltosLanded.java index 9dab52c4..cc2053e0 100644 --- a/altosui/AltosLanded.java +++ b/altosui/AltosLanded.java @@ -21,7 +21,7 @@ import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.io.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; public class AltosLanded extends JComponent implements AltosFlightDisplay, ActionListener { GridBagLayout layout; @@ -103,7 +103,8 @@ public class AltosLanded extends JComponent implements AltosFlightDisplay, Actio class Lat extends LandedValue { void show (AltosState state, AltosListenerState listener_state) { - if (state.gps != null && state.gps.connected) + show(); + if (state.gps != null && state.gps.connected && state.gps.lat != AltosLib.MISSING) show(pos(state.gps.lat,"N", "S")); else show("???"); @@ -118,7 +119,7 @@ public class AltosLanded extends JComponent implements AltosFlightDisplay, Actio class Lon extends LandedValue { void show (AltosState state, AltosListenerState listener_state) { show(); - if (state.gps != null && state.gps.connected) + if (state.gps != null && state.gps.connected && state.gps.lon != AltosLib.MISSING) show(pos(state.gps.lon,"E", "W")); else show("???"); @@ -162,7 +163,7 @@ public class AltosLanded extends JComponent implements AltosFlightDisplay, Actio class Height extends LandedValue { void show (AltosState state, AltosListenerState listener_state) { - show(AltosConvert.height, state.max_height); + show(AltosConvert.height, state.max_height()); } public Height (GridBagLayout layout, int y) { super (layout, y, "Maximum Height"); @@ -184,7 +185,7 @@ public class AltosLanded extends JComponent implements AltosFlightDisplay, Actio class Accel extends LandedValue { void show (AltosState state, AltosListenerState listener_state) { - show(AltosConvert.accel, state.max_acceleration); + show(AltosConvert.accel, state.max_acceleration()); } public Accel (GridBagLayout layout, int y) { super (layout, y, "Maximum Acceleration"); @@ -243,24 +244,18 @@ public class AltosLanded extends JComponent implements AltosFlightDisplay, Actio if (file != null) { String filename = file.getName(); try { - AltosRecordIterable records = null; + AltosStateIterable states = null; if (filename.endsWith("eeprom")) { FileInputStream in = new FileInputStream(file); - records = new AltosEepromIterable(in); + states = new AltosEepromFile(in); } else if (filename.endsWith("telem")) { FileInputStream in = new FileInputStream(file); - records = new AltosTelemetryIterable(in); - } else if (filename.endsWith("mega")) { - FileInputStream in = new FileInputStream(file); - records = new AltosEepromMegaIterable(in); - } else if (filename.endsWith("mini")) { - FileInputStream in = new FileInputStream(file); - records = new AltosEepromMiniIterable(in); + states = new AltosTelemetryFile(in); } else { throw new FileNotFoundException(filename); } try { - new AltosGraphUI(records, file); + new AltosGraphUI(states, file); } catch (InterruptedException ie) { } catch (IOException ie) { } diff --git a/altosui/AltosPad.java b/altosui/AltosPad.java index e2316a13..b35bd23a 100644 --- a/altosui/AltosPad.java +++ b/altosui/AltosPad.java @@ -19,7 +19,7 @@ package altosui; import java.awt.*; import javax.swing.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; public class AltosPad extends JComponent implements AltosFlightDisplay { GridBagLayout layout; @@ -176,11 +176,11 @@ public class AltosPad extends JComponent implements AltosFlightDisplay { class Battery extends LaunchStatus { void show (AltosState state, AltosListenerState listener_state) { - if (state == null || state.battery == AltosRecord.MISSING) + if (state == null || state.battery_voltage == AltosLib.MISSING) hide(); else { - show("%4.2f V", state.battery); - lights.set(state.battery > 3.7); + show("%4.2f V", state.battery_voltage); + lights.set(state.battery_voltage > 3.7); } } public Battery (GridBagLayout layout, int y) { @@ -192,11 +192,11 @@ public class AltosPad extends JComponent implements AltosFlightDisplay { class Apogee extends LaunchStatus { void show (AltosState state, AltosListenerState listener_state) { - if (state == null || state.drogue_sense == AltosRecord.MISSING) + if (state == null || state.apogee_voltage == AltosLib.MISSING) hide(); else { - show("%4.2f V", state.drogue_sense); - lights.set(state.drogue_sense > 3.2); + show("%4.2f V", state.apogee_voltage); + lights.set(state.apogee_voltage > 3.7); } } public Apogee (GridBagLayout layout, int y) { @@ -208,11 +208,11 @@ public class AltosPad extends JComponent implements AltosFlightDisplay { class Main extends LaunchStatus { void show (AltosState state, AltosListenerState listener_state) { - if (state == null || state.main_sense == AltosRecord.MISSING) + if (state == null || state.main_voltage == AltosLib.MISSING) hide(); else { - show("%4.2f V", state.main_sense); - lights.set(state.main_sense > 3.2); + show("%4.2f V", state.main_voltage); + lights.set(state.main_voltage > 3.7); } } public Main (GridBagLayout layout, int y) { @@ -224,19 +224,19 @@ public class AltosPad extends JComponent implements AltosFlightDisplay { class LoggingReady extends LaunchStatus { void show (AltosState state, AltosListenerState listener_state) { - if (state == null || state.data.flight == AltosRecord.MISSING) { + if (state == null || state.flight == AltosLib.MISSING) { hide(); } else { - if (state.data.flight != 0) { - if (state.data.state <= Altos.ao_flight_pad) + if (state.flight != 0) { + if (state.state <= Altos.ao_flight_pad) show("Ready to record"); - else if (state.data.state < Altos.ao_flight_landed) + else if (state.state < Altos.ao_flight_landed) show("Recording data"); else show("Recorded data"); } else show("Storage full"); - lights.set(state.data.flight != 0); + lights.set(state.flight != 0); } } public LoggingReady (GridBagLayout layout, int y) { @@ -283,7 +283,7 @@ public class AltosPad extends JComponent implements AltosFlightDisplay { class ReceiverBattery extends LaunchStatus { void show (AltosState state, AltosListenerState listener_state) { - if (listener_state == null || listener_state.battery == AltosRecord.MISSING) + if (listener_state == null || listener_state.battery == AltosLib.MISSING) hide(); else { show("%4.2f V", listener_state.battery); @@ -310,17 +310,23 @@ public class AltosPad extends JComponent implements AltosFlightDisplay { class PadLat extends LaunchValue { void show (AltosState state, AltosListenerState listener_state) { - if (state == null || state.gps == null) { - hide(); - } else { - if (state.state < AltosLib.ao_flight_pad) { - show(pos(state.gps.lat,"N", "S")); - set_label("Latitude"); - } else { - show(pos(state.pad_lat,"N", "S")); - set_label("Pad Latitude"); + double lat = AltosLib.MISSING; + String label = null; + + if (state != null) { + if (state.state < AltosLib.ao_flight_pad && state.gps != null && state.gps.lat != AltosLib.MISSING) { + lat = state.gps.lat; + label = "Latitude"; + } else { + lat = state.pad_lat; + label = "Pad Latitude"; } } + if (lat != AltosLib.MISSING) { + show(pos(lat,"N", "S")); + set_label(label); + } else + hide(); } public PadLat (GridBagLayout layout, int y) { super (layout, y, "Pad Latitude"); @@ -331,17 +337,23 @@ public class AltosPad extends JComponent implements AltosFlightDisplay { class PadLon extends LaunchValue { void show (AltosState state, AltosListenerState listener_state) { - if (state == null || state.gps == null) { - hide(); - } else { - if (state.state < AltosLib.ao_flight_pad) { - show(pos(state.gps.lon,"E", "W")); - set_label("Longitude"); - } else { - show(pos(state.pad_lon,"E", "W")); - set_label("Pad Longitude"); + double lon = AltosLib.MISSING; + String label = null; + + if (state != null) { + if (state.state < AltosLib.ao_flight_pad && state.gps != null && state.gps.lon != AltosLib.MISSING) { + lon = state.gps.lon; + label = "Longitude"; + } else { + lon = state.pad_lon; + label = "Pad Longitude"; } } + if (lon != AltosLib.MISSING) { + show(pos(lon,"E", "W")); + set_label(label); + } else + hide(); } public PadLon (GridBagLayout layout, int y) { super (layout, y, "Pad Longitude"); @@ -352,21 +364,23 @@ public class AltosPad extends JComponent implements AltosFlightDisplay { class PadAlt extends LaunchValue { void show (AltosState state, AltosListenerState listener_state) { - if (state == null) - hide(); - else { - if (state.state < AltosLib.ao_flight_pad && state.gps != null) { - show("%4.0f m", state.gps.alt); - set_label("Altitude"); + double alt = AltosLib.MISSING; + String label = null; + + if (state != null) { + if (state.state < AltosLib.ao_flight_pad && state.gps != null && state.gps.alt != AltosLib.MISSING) { + alt = state.gps.alt; + label = "Altitude"; } else { - if (state.pad_alt == AltosRecord.MISSING) - hide(); - else { - show("%4.0f m", state.pad_alt); - set_label("Pad Altitude"); - } + alt = state.pad_alt; + label = "Pad Altitude"; } } + if (alt != AltosLib.MISSING) { + show("%4.0f m", state.gps.alt); + set_label(label); + } else + hide(); } public PadAlt (GridBagLayout layout, int y) { super (layout, y, "Pad Altitude"); diff --git a/altosui/AltosRomconfigUI.java b/altosui/AltosRomconfigUI.java index 909e72a0..6f9d9dc6 100644 --- a/altosui/AltosRomconfigUI.java +++ b/altosui/AltosRomconfigUI.java @@ -20,7 +20,7 @@ package altosui; import java.awt.*; import java.awt.event.*; import javax.swing.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; import org.altusmetrum.altosuilib_1.*; public class AltosRomconfigUI diff --git a/altosui/AltosScanUI.java b/altosui/AltosScanUI.java index 0c903873..a5ccb15a 100644 --- a/altosui/AltosScanUI.java +++ b/altosui/AltosScanUI.java @@ -25,7 +25,7 @@ import java.io.*; import java.util.*; import java.text.*; import java.util.concurrent.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; import org.altusmetrum.altosuilib_1.*; class AltosScanResult { @@ -184,13 +184,13 @@ public class AltosScanUI try { for (;;) { try { - AltosRecord record = reader.read(); - if (record == null) + AltosState state = reader.read(); + if (state == null) continue; - if ((record.seen & AltosRecord.seen_flight) != 0) { - final AltosScanResult result = new AltosScanResult(record.callsign, - record.serial, - record.flight, + if (state.flight != AltosLib.MISSING) { + final AltosScanResult result = new AltosScanResult(state.callsign, + state.serial, + state.flight, frequencies[frequency_index], telemetry); Runnable r = new Runnable() { diff --git a/altosui/AltosSerial.java b/altosui/AltosSerial.java index e869f1ab..697ad539 100644 --- a/altosui/AltosSerial.java +++ b/altosui/AltosSerial.java @@ -25,7 +25,7 @@ import java.io.*; import java.util.*; import java.awt.*; import javax.swing.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; import org.altusmetrum.altosuilib_1.*; import libaltosJNI.*; diff --git a/altosui/AltosSiteMap.java b/altosui/AltosSiteMap.java index 23085f3e..9491ce2b 100644 --- a/altosui/AltosSiteMap.java +++ b/altosui/AltosSiteMap.java @@ -23,7 +23,7 @@ import java.io.*; import java.lang.Math; import java.awt.geom.Point2D; import java.util.concurrent.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; import org.altusmetrum.altosuilib_1.*; public class AltosSiteMap extends JScrollPane implements AltosFlightDisplay { @@ -271,27 +271,34 @@ public class AltosSiteMap extends JScrollPane implements AltosFlightDisplay { int last_state = -1; public void show(double lat, double lon) { - initMaps(lat, lon); - scrollRocketToVisible(pt(lat, lon)); + System.out.printf ("show %g %g\n", lat, lon); + return; +// initMaps(lat, lon); +// scrollRocketToVisible(pt(lat, lon)); } public void show(final AltosState state, final AltosListenerState listener_state) { // if insufficient gps data, nothing to update - if (!state.gps.locked && state.gps.nsat < 4) + AltosGPS gps = state.gps; + + if (gps == null) + return; + + if (!gps.locked && gps.nsat < 4) return; if (!initialised) { - if (state.pad_lat != 0 || state.pad_lon != 0) { + if (state.pad_lat != AltosLib.MISSING && state.pad_lon != AltosLib.MISSING) { initMaps(state.pad_lat, state.pad_lon); initialised = true; - } else if (state.gps.lat != 0 || state.gps.lon != 0) { - initMaps(state.gps.lat, state.gps.lon); + } else if (gps.lat != AltosLib.MISSING && gps.lon != AltosLib.MISSING) { + initMaps(gps.lat, gps.lon); initialised = true; } else { return; } } - final Point2D.Double pt = pt(state.gps.lat, state.gps.lon); + final Point2D.Double pt = pt(gps.lat, gps.lon); if (last_pt == pt && last_state == state.state) return; diff --git a/altosui/AltosSiteMapTile.java b/altosui/AltosSiteMapTile.java index 365e4b6c..172e6397 100644 --- a/altosui/AltosSiteMapTile.java +++ b/altosui/AltosSiteMapTile.java @@ -22,7 +22,7 @@ import java.awt.image.*; import javax.swing.*; import java.awt.geom.Point2D; import java.awt.geom.Line2D; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; public class AltosSiteMapTile extends JLayeredPane { JLabel mapLabel; diff --git a/altosui/AltosUI.java b/altosui/AltosUI.java index 4362e36c..9dad8718 100644 --- a/altosui/AltosUI.java +++ b/altosui/AltosUI.java @@ -22,7 +22,7 @@ import java.awt.event.*; import javax.swing.*; import java.io.*; import java.util.concurrent.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; import org.altusmetrum.altosuilib_1.*; public class AltosUI extends AltosUIFrame { @@ -290,9 +290,9 @@ public class AltosUI extends AltosUIFrame { AltosDataChooser chooser = new AltosDataChooser( AltosUI.this); - AltosRecordIterable iterable = chooser.runDialog(); - if (iterable != null) { - AltosFlightReader reader = new AltosReplayReader(iterable.iterator(), + Iterable<AltosState> states = chooser.runDialog(); + if (states != null) { + AltosFlightReader reader = new AltosReplayReader(states.iterator(), chooser.file()); new AltosFlightUI(voice, reader); } @@ -312,10 +312,10 @@ public class AltosUI extends AltosUIFrame { private void ExportData() { AltosDataChooser chooser; chooser = new AltosDataChooser(this); - AltosRecordIterable record_reader = chooser.runDialog(); - if (record_reader == null) + AltosStateIterable states = chooser.runDialog(); + if (states == null) return; - new AltosCSVUI(AltosUI.this, record_reader, chooser.file()); + new AltosCSVUI(AltosUI.this, states, chooser.file()); } /* Load a flight log CSV file and display a pretty graph. @@ -324,11 +324,11 @@ public class AltosUI extends AltosUIFrame { private void GraphData() { AltosDataChooser chooser; chooser = new AltosDataChooser(this); - AltosRecordIterable record_reader = chooser.runDialog(); - if (record_reader == null) + AltosStateIterable states = chooser.runDialog(); + if (states == null) return; try { - new AltosGraphUI(record_reader, chooser.file()); + new AltosGraphUI(states, chooser.file()); } catch (InterruptedException ie) { } catch (IOException ie) { } @@ -345,19 +345,15 @@ public class AltosUI extends AltosUIFrame { } } - static AltosRecordIterable open_logfile(File file) { + static AltosStateIterable open_logfile(File file) { try { FileInputStream in; in = new FileInputStream(file); - if (file.getName().endsWith("eeprom")) - return new AltosEepromIterable(in); - else if (file.getName().endsWith("mega")) - return new AltosEepromMegaIterable(in); - else if (file.getName().endsWith("mini")) - return new AltosEepromMiniIterable(in); + if (file.getName().endsWith("telem")) + return new AltosTelemetryFile(in); else - return new AltosTelemetryIterable(in); + return new AltosEepromFile(in); } catch (FileNotFoundException fe) { System.out.printf("%s\n", fe.getMessage()); return null; @@ -388,10 +384,11 @@ public class AltosUI extends AltosUIFrame { static final int process_graph = 3; static final int process_replay = 4; static final int process_summary = 5; + static final int process_cat = 6; static boolean process_csv(File input) { - AltosRecordIterable iterable = open_logfile(input); - if (iterable == null) + AltosStateIterable states = open_logfile(input); + if (states == null) return false; File output = Altos.replace_extension(input,".csv"); @@ -403,15 +400,15 @@ public class AltosUI extends AltosUIFrame { AltosWriter writer = open_csv(output); if (writer == null) return false; - writer.write(iterable); + writer.write(states); writer.close(); } return true; } static boolean process_kml(File input) { - AltosRecordIterable iterable = open_logfile(input); - if (iterable == null) + AltosStateIterable states = open_logfile(input); + if (states == null) return false; File output = Altos.replace_extension(input,".kml"); @@ -423,13 +420,13 @@ public class AltosUI extends AltosUIFrame { AltosWriter writer = open_kml(output); if (writer == null) return false; - writer.write(iterable); + writer.write(states); writer.close(); return true; } } - static AltosRecordIterable record_iterable(File file) { + static AltosStateIterable record_iterable(File file) { FileInputStream in; try { in = new FileInputStream(file); @@ -437,25 +434,17 @@ public class AltosUI extends AltosUIFrame { System.out.printf("Failed to open file '%s'\n", file); return null; } - AltosRecordIterable recs; - //AltosReplayReader reader; - if (file.getName().endsWith("eeprom")) { - recs = new AltosEepromIterable(in); - } else if (file.getName().endsWith("mega")) { - recs = new AltosEepromMegaIterable(in); - } else if (file.getName().endsWith("mini")) { - recs = new AltosEepromMiniIterable(in); - } else { - recs = new AltosTelemetryIterable(in); - } - return recs; + if (file.getName().endsWith("telem")) + return new AltosTelemetryFile(in); + else + return new AltosEepromFile(in); } static AltosReplayReader replay_file(File file) { - AltosRecordIterable recs = record_iterable(file); - if (recs == null) + AltosStateIterable states = record_iterable(file); + if (states == null) return null; - return new AltosReplayReader(recs.iterator(), file); + return new AltosReplayReader(states.iterator(), file); } static boolean process_replay(File file) { @@ -468,11 +457,11 @@ public class AltosUI extends AltosUIFrame { } static boolean process_graph(File file) { - AltosRecordIterable recs = record_iterable(file); - if (recs == null) + AltosStateIterable states = record_iterable(file); + if (states == null) return false; try { - new AltosGraphUI(recs, file); + new AltosGraphUI(states, file); return true; } catch (InterruptedException ie) { } catch (IOException ie) { @@ -481,11 +470,11 @@ public class AltosUI extends AltosUIFrame { } static boolean process_summary(File file) { - AltosRecordIterable iterable = record_iterable(file); - if (iterable == null) + AltosStateIterable states = record_iterable(file); + if (states == null) return false; try { - AltosFlightStats stats = new AltosFlightStats(iterable); + AltosFlightStats stats = new AltosFlightStats(states); if (stats.serial > 0) System.out.printf("Serial: %5d\n", stats.serial); if (stats.flight > 0) @@ -503,18 +492,18 @@ public class AltosUI extends AltosUIFrame { stats.max_speed, AltosConvert.meters_to_feet(stats.max_speed), AltosConvert.meters_to_mach(stats.max_speed)); - if (stats.max_acceleration != AltosRecord.MISSING) { + if (stats.max_acceleration != AltosLib.MISSING) { System.out.printf("Max accel: %6.0f m/s² %6.0f ft/s² %6.2f g\n", stats.max_acceleration, AltosConvert.meters_to_feet(stats.max_acceleration), AltosConvert.meters_to_g(stats.max_acceleration)); } System.out.printf("Drogue rate: %6.0f m/s %6.0f ft/s\n", - stats.state_baro_speed[Altos.ao_flight_drogue], - AltosConvert.meters_to_feet(stats.state_baro_speed[Altos.ao_flight_drogue])); + stats.state_speed[Altos.ao_flight_drogue], + AltosConvert.meters_to_feet(stats.state_speed[Altos.ao_flight_drogue])); System.out.printf("Main rate: %6.0f m/s %6.0f ft/s\n", - stats.state_baro_speed[Altos.ao_flight_main], - AltosConvert.meters_to_feet(stats.state_baro_speed[Altos.ao_flight_main])); + stats.state_speed[Altos.ao_flight_main], + AltosConvert.meters_to_feet(stats.state_speed[Altos.ao_flight_main])); System.out.printf("Flight time: %6.0f s\n", stats.state_end[Altos.ao_flight_main] - stats.state_start[Altos.ao_flight_boost]); @@ -525,6 +514,29 @@ public class AltosUI extends AltosUIFrame { return false; } + static boolean process_cat(File file) { + try { + AltosStateIterable eef = record_iterable(file); + + System.out.printf ("process cat\n"); + for (AltosState state : eef) { + System.out.printf ("tick %d state %d height %g\n", + state.tick, state.state, state.height()); + if ((state.set & AltosState.set_gps) != 0) + System.out.printf ("time %g lat %g lon %g alt %g\n", + state.time_since_boost(), + state.gps.lat, + state.gps.lon, + state.gps.alt); + } + + } catch (Exception e) { + System.out.printf("Failed to open file '%s'\n", file); + return false; + } + return true; + } + public static void help(int code) { System.out.printf("Usage: altosui [OPTION]... [FILE]...\n"); System.out.printf(" Options:\n"); @@ -574,6 +586,8 @@ public class AltosUI extends AltosUIFrame { process = process_graph; else if (args[i].equals("--summary")) process = process_summary; + else if (args[i].equals("--cat")) + process = process_cat; else if (args[i].startsWith("--")) help(1); else { @@ -600,6 +614,9 @@ public class AltosUI extends AltosUIFrame { if (!process_summary(file)) ++errors; break; + case process_cat: + if (!process_cat(file)) + ++errors; } } } diff --git a/altosui/AltosUIPreferencesBackend.java b/altosui/AltosUIPreferencesBackend.java index 0dac9fc7..fb5f8520 100644 --- a/altosui/AltosUIPreferencesBackend.java +++ b/altosui/AltosUIPreferencesBackend.java @@ -19,7 +19,7 @@ package altosui; import java.io.File; import java.util.prefs.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; import javax.swing.filechooser.FileSystemView; public class AltosUIPreferencesBackend implements AltosPreferencesBackend { diff --git a/altosui/AltosWriter.java b/altosui/AltosWriter.java index 2f70b472..d664d6e8 100644 --- a/altosui/AltosWriter.java +++ b/altosui/AltosWriter.java @@ -17,14 +17,14 @@ package altosui; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; public interface AltosWriter { - public void write(AltosRecord record); + public void write(AltosState state); - public void write(AltosRecordIterable iterable); + public void write(AltosStateIterable states); public void close(); } |
