public abstract AltosState read() throws InterruptedException, ParseException, AltosCRCException, IOException;
+ public abstract AltosCalData cal_data();
+
public abstract void close(boolean interrupted);
public void set_frequency(double frequency) throws InterruptedException, TimeoutException { }
}
public AltosState() {
+ Thread.dumpStack();
init();
}
public AltosState (AltosCalData cal_data) {
super(cal_data);
+ if (cal_data == null)
+ Thread.dumpStack();
init();
}
}
import java.util.concurrent.*;
public class AltosTelemetryReader extends AltosFlightReader {
- AltosLink link;
- AltosLog log;
- double frequency;
- int telemetry;
- int telemetry_rate;
- public AltosState state = null;
- public AltosCalData cal_data = null;
+ AltosLink link;
+ AltosLog log;
+ double frequency;
+ int telemetry;
+ int telemetry_rate;
+ private AltosState state = null;
+ private AltosCalData cal_data = null;
LinkedBlockingQueue<AltosLine> telem;
throw new IOException("IO error");
} while (!link.get_monitor());
AltosTelemetry telem = AltosTelemetry.parse(l.line);
- if (cal_data == null)
- cal_data = new AltosCalData();
- if (state == null)
- state = new AltosState(cal_data);
- telem.provide_data(state, cal_data);
+ if (state == null) {
+ System.out.printf("Make state\n");
+ state = new AltosState(cal_data());
+ }
+ telem.provide_data(state, state.cal_data);
return state;
}
+ public AltosCalData cal_data() {
+ if (cal_data == null) {
+ System.out.printf("Make cal data\n");
+ cal_data = new AltosCalData();
+ }
+ return cal_data;
+ }
+
public void flush() {
telem.clear();
}
AltosUI.this);
AltosRecordSet set = chooser.runDialog();
-/* XXX fixme */
-// if (states != null) {
-// AltosFlightReader reader = new AltosReplayReader(states.iterator(),
-// chooser.file());
-// new AltosFlightUI(voice, reader);
-// }
+ if (set != null) {
+ AltosReplayReader reader = new AltosReplayReader(set, chooser.file());
+ new AltosFlightUI(voice, reader);
+ }
}
/* Connect to TeleMetrum, either directly or through
private static AltosFlightSeries make_series(AltosRecordSet set) {
AltosFlightSeries series = new AltosFlightSeries(set.cal_data());
set.capture_series(series);
+ series.finish();
return series;
}
if (state == null)
continue;
packet_count++;
- if (reader.cal_data.flight != AltosLib.MISSING) {
- final AltosScanResult result = new AltosScanResult(reader.cal_data.callsign,
- reader.cal_data.serial,
- reader.cal_data.flight,
+ AltosCalData cal_data = state.cal_data;
+ if (cal_data.flight != AltosLib.MISSING) {
+ final AltosScanResult result = new AltosScanResult(cal_data.callsign,
+ cal_data.serial,
+ cal_data.flight,
frequencies[frequency_index],
telemetry,
rate);
status_update.saved_listener_state = listener_state;
if (state == null)
- state = new AltosState();
+ state = new AltosState(new AltosCalData());
int i = 0;
for (AltosFlightDisplay display : displays) {
new TeleGPSConfig(this);
}
+ private static AltosFlightSeries make_series(AltosRecordSet set) {
+ AltosFlightSeries series = new AltosFlightSeries(set.cal_data());
+ set.capture_series(series);
+ series.finish();
+ return series;
+ }
+
void export() {
- AltosDataChooser chooser;
- chooser = new AltosDataChooser(this);
- AltosStateIterable states = chooser.runDialog();
- if (states == null)
+ AltosDataChooser chooser = new AltosDataChooser(this);
+
+ AltosRecordSet set = chooser.runDialog();
+ if (set == null)
return;
- new AltosCSVUI(this, states, chooser.file());
+ AltosFlightSeries series = make_series(set);
+ new AltosCSVUI(this, series, series.cal_data, chooser.file());
}
void graph() {
- AltosDataChooser chooser;
- chooser = new AltosDataChooser(this);
- AltosStateIterable states = chooser.runDialog();
- if (states == null)
+ AltosDataChooser chooser = new AltosDataChooser(this);
+ AltosRecordSet set = chooser.runDialog();
+ if (set == null)
return;
try {
- new TeleGPSGraphUI(states, chooser.file());
+ new TeleGPSGraphUI(set, chooser.file());
} catch (InterruptedException ie) {
} catch (IOException ie) {
}
connect(device);
}
- static AltosStateIterable record_iterable(File file) {
+ static AltosRecordSet record_set(File file) {
FileInputStream in;
if (file.getName().endsWith("telem")) {
try {
} else {
try {
- AltosEepromFile f = new AltosEepromFile(new FileReader(file));
- return f;
+ return new AltosEepromFile(new FileReader(file));
} catch (Exception e) {
System.out.printf("Failed to open file '%s'\n", file);
}
}
static AltosReplayReader replay_file(File file) {
- AltosStateIterable states = record_iterable(file);
- if (states == null)
+ AltosRecordSet set = record_set(file);
+ if (set == null)
return null;
- return new AltosReplayReader(states.iterator(), file);
+ return new AltosReplayReader(set, file);
}
static boolean process_graph(File file) {
- AltosStateIterable states = record_iterable(file);
- if (states == null)
+ AltosRecordSet set = record_set(file);
+ if (set == null)
return false;
try {
- new TeleGPSGraphUI(states, file);
+ new TeleGPSGraphUI(set, file);
} catch (Exception e) {
return false;
}
IdleThread idle_thread;
AltosVoice voice;
AltosFlightReader reader;
- AltosState old_state, state;
+ AltosState state;
+ int old_state = AltosLib.ao_flight_invalid;
+ boolean old_gps_ready = false;
AltosListenerState listener_state;
AltosFlightDisplay display;
}
public synchronized void notice(boolean spoken) {
- if (old_state != null && old_state.state() != state.state()) {
+ if (old_state != state.state()) {
report_time = now();
this.notify();
} else if (spoken)
set_report_time();
+ old_state = state.state();
}
public IdleThread() {
synchronized boolean tell() {
boolean ret = false;
- if (old_state == null || old_state.gps_ready != state.gps_ready) {
+ if (old_gps_ready != state.gps_ready) {
if (state.gps_ready) {
voice.speak("GPS ready");
ret = true;
}
- else if (old_state != null) {
+ else if (old_gps_ready) {
voice.speak("GPS lost");
ret = true;
}
+ old_gps_ready = state.gps_ready;
}
- old_state = state;
return ret;
}
listener_state.running = false;
break;
}
- reader.update(state);
show_safely();
told = tell();
idle_thread.notice(told);
import org.jfree.chart.JFreeChart;
import org.jfree.ui.RefineryUtilities;
-public class TeleGPSGraphUI extends AltosUIFrame
+public class TeleGPSGraphUI extends AltosUIFrame implements AltosFontListener, AltosUnitsListener
{
JTabbedPane pane;
- AltosGraph graph;
+ AltosGraphNew graph;
AltosUIEnable enable;
AltosUIMap map;
AltosState state;
AltosFlightStats stats;
- AltosGraphDataSet graphDataSet;
AltosFlightStatsTable statsTable;
-
- void fill_map(AltosStateIterable states) {
- for (AltosState state : states) {
- if (state.gps != null && state.gps.locked && state.gps.nsat >= 4)
- map.show(state, null);
+ AltosGPS gps;
+ boolean has_gps;
+
+ void fill_map(AltosFlightSeries flight_series) {
+ boolean any_gps = false;
+ AltosGPSTimeValue gtv_last = null;
+
+ if (flight_series.gps_series != null) {
+ for (AltosGPSTimeValue gtv : flight_series.gps_series) {
+ gtv_last = gtv;
+ AltosGPS gps = gtv.gps;
+ if (gps != null &&
+ gps.locked &&
+ gps.nsat >= 4) {
+ if (map == null)
+ map = new AltosUIMap();
+ map.show(gps, (int) flight_series.value_before(AltosFlightSeries.state_name, gtv.time));
+ this.gps = gps;
+ has_gps = true;
+ }
+ }
+ }
+ if (gtv_last != null) {
+ int state = (int) flight_series.value_after(AltosFlightSeries.state_name, gtv_last.time);
+ if (state == AltosLib.ao_flight_landed)
+ map.show(gtv_last.gps, state);
}
}
TeleGPS.subtract_window();
}
- TeleGPSGraphUI(AltosStateIterable states, File file) throws InterruptedException, IOException {
+ public void font_size_changed(int font_size) {
+ if (map != null)
+ map.font_size_changed(font_size);
+ if (statsTable != null)
+ statsTable.font_size_changed(font_size);
+ }
+
+ public void units_changed(boolean imperial_units) {
+ if (map != null)
+ map.units_changed(imperial_units);
+ if (enable != null)
+ enable.units_changed(imperial_units);
+ }
+
+ TeleGPSGraphUI(AltosRecordSet set, File file) throws InterruptedException, IOException {
super(file.getName());
- state = null;
+ AltosCalData cal_data = set.cal_data();
+
+ AltosUIFlightSeries flight_series = new AltosUIFlightSeries(cal_data);
+ set.capture_series(flight_series);
+ flight_series.finish();
pane = new JTabbedPane();
enable = new AltosUIEnable();
- stats = new AltosFlightStats(states);
- graphDataSet = new AltosGraphDataSet(states);
- graph = new AltosGraph(enable, stats, graphDataSet);
+ stats = new AltosFlightStats(flight_series);
+
+ graph = new AltosGraphNew(enable, stats, flight_series, cal_data);
+
statsTable = new AltosFlightStatsTable(stats);
map = new AltosUIMap();
pane.add("Graph", graph.panel);
pane.add("Configure Graph", enable);
pane.add("Statistics", statsTable);
- fill_map(states);
+ fill_map(flight_series);
pane.add("Map", map);
setContentPane (pane);
+ AltosUIPreferences.register_font_listener(this);
+ AltosPreferences.register_units_listener(this);
+
addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
class FirmwareVersion extends AltosUIIndicator {
public void show(AltosState state, AltosListenerState listener_state) {
- if (state.firmware_version == null)
+ if (state.cal_data.firmware_version == null)
show("Missing");
else
- show(state.firmware_version);
+ show(state.cal_data.firmware_version);
}
public FirmwareVersion(Container container, int y) {
class FlightLogMax extends AltosUIIndicator {
public void show(AltosState state, AltosListenerState listener_state) {
- int storage = state.flight_log_max;
- if (storage == AltosLib.MISSING)
- storage = state.log_space >> 10;
+ int storage = state.cal_data.flight_log_max;
if (storage == AltosLib.MISSING)
show("Missing");
else
String call;
void show(AltosState state, AltosListenerState listener_state) {
- if (state.callsign != call) {
- value.setText(state.callsign);
- call = state.callsign;
+ if (state.cal_data == null)
+ System.out.printf("null cal data?\n");
+ if (state.cal_data.callsign != call) {
+ value.setText(state.cal_data.callsign);
+ call = state.cal_data.callsign;
}
- if (state.callsign == null)
+ if (state.cal_data.callsign == null)
setVisible(false);
else
setVisible(true);
class Serial extends Value {
int serial = -1;
void show(AltosState state, AltosListenerState listener_state) {
- if (state.serial != serial) {
- if (state.serial == AltosLib.MISSING)
+ if (state.cal_data.serial != serial) {
+ if (state.cal_data.serial == AltosLib.MISSING)
value.setText("none");
else
- value.setText(String.format("%d", state.serial));
- serial = state.serial;
+ value.setText(String.format("%d", state.cal_data.serial));
+ serial = state.cal_data.serial;
}
}
int last_flight = -1;
void show(AltosState state, AltosListenerState listener_state) {
- if (state.flight != last_flight) {
- if (state.flight == AltosLib.MISSING)
+ if (state.cal_data.flight != last_flight) {
+ if (state.cal_data.flight == AltosLib.MISSING)
value.setText("none");
else
- value.setText(String.format("%d", state.flight));
- last_flight = state.flight;
+ value.setText(String.format("%d", state.cal_data.flight));
+ last_flight = state.cal_data.flight;
}
}