summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--altoslib/AltosFlightReader.java2
-rw-r--r--altoslib/AltosState.java3
-rw-r--r--altoslib/AltosTelemetryReader.java32
-rw-r--r--altosui/AltosUI.java11
-rw-r--r--altosuilib/AltosScanUI.java9
-rw-r--r--telegps/TeleGPS.java46
-rw-r--r--telegps/TeleGPSDisplayThread.java14
-rw-r--r--telegps/TeleGPSGraphUI.java70
-rw-r--r--telegps/TeleGPSState.java8
-rw-r--r--telegps/TeleGPSStatus.java26
10 files changed, 142 insertions, 79 deletions
diff --git a/altoslib/AltosFlightReader.java b/altoslib/AltosFlightReader.java
index 790710e0..f252d60b 100644
--- a/altoslib/AltosFlightReader.java
+++ b/altoslib/AltosFlightReader.java
@@ -31,6 +31,8 @@ public abstract class AltosFlightReader {
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 { }
diff --git a/altoslib/AltosState.java b/altoslib/AltosState.java
index e5a0541e..5abc0c2d 100644
--- a/altoslib/AltosState.java
+++ b/altoslib/AltosState.java
@@ -1075,11 +1075,14 @@ public class AltosState extends AltosDataListener {
}
public AltosState() {
+ Thread.dumpStack();
init();
}
public AltosState (AltosCalData cal_data) {
super(cal_data);
+ if (cal_data == null)
+ Thread.dumpStack();
init();
}
}
diff --git a/altoslib/AltosTelemetryReader.java b/altoslib/AltosTelemetryReader.java
index 96113613..1020efb0 100644
--- a/altoslib/AltosTelemetryReader.java
+++ b/altoslib/AltosTelemetryReader.java
@@ -23,13 +23,13 @@ import java.io.*;
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;
@@ -41,14 +41,22 @@ public class AltosTelemetryReader extends AltosFlightReader {
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();
}
diff --git a/altosui/AltosUI.java b/altosui/AltosUI.java
index e7dedffd..b302b670 100644
--- a/altosui/AltosUI.java
+++ b/altosui/AltosUI.java
@@ -311,12 +311,10 @@ public class AltosUI extends AltosUIFrame {
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
@@ -329,6 +327,7 @@ public class AltosUI extends AltosUIFrame {
private static AltosFlightSeries make_series(AltosRecordSet set) {
AltosFlightSeries series = new AltosFlightSeries(set.cal_data());
set.capture_series(series);
+ series.finish();
return series;
}
diff --git a/altosuilib/AltosScanUI.java b/altosuilib/AltosScanUI.java
index ad53f66b..2dc093dc 100644
--- a/altosuilib/AltosScanUI.java
+++ b/altosuilib/AltosScanUI.java
@@ -213,10 +213,11 @@ public class AltosScanUI
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);
diff --git a/telegps/TeleGPS.java b/telegps/TeleGPS.java
index cf2cbd4f..5e500e02 100644
--- a/telegps/TeleGPS.java
+++ b/telegps/TeleGPS.java
@@ -152,7 +152,7 @@ public class TeleGPS
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) {
@@ -287,23 +287,30 @@ public class TeleGPS
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) {
}
@@ -612,7 +619,7 @@ public class TeleGPS
connect(device);
}
- static AltosStateIterable record_iterable(File file) {
+ static AltosRecordSet record_set(File file) {
FileInputStream in;
if (file.getName().endsWith("telem")) {
try {
@@ -624,8 +631,7 @@ public class TeleGPS
} 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);
}
@@ -634,18 +640,18 @@ public class TeleGPS
}
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;
}
diff --git a/telegps/TeleGPSDisplayThread.java b/telegps/TeleGPSDisplayThread.java
index a9c80dc0..c311dd7e 100644
--- a/telegps/TeleGPSDisplayThread.java
+++ b/telegps/TeleGPSDisplayThread.java
@@ -31,7 +31,9 @@ public class TeleGPSDisplayThread extends Thread {
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;
@@ -130,11 +132,12 @@ public class TeleGPSDisplayThread extends Thread {
}
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() {
@@ -144,17 +147,17 @@ public class TeleGPSDisplayThread extends Thread {
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;
}
@@ -173,7 +176,6 @@ public class TeleGPSDisplayThread extends Thread {
listener_state.running = false;
break;
}
- reader.update(state);
show_safely();
told = tell();
idle_thread.notice(told);
diff --git a/telegps/TeleGPSGraphUI.java b/telegps/TeleGPSGraphUI.java
index 55ee370e..3e765640 100644
--- a/telegps/TeleGPSGraphUI.java
+++ b/telegps/TeleGPSGraphUI.java
@@ -34,21 +34,41 @@ import org.jfree.chart.ChartPanel;
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);
}
}
@@ -58,16 +78,35 @@ public class TeleGPSGraphUI extends AltosUIFrame
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();
@@ -75,11 +114,14 @@ public class TeleGPSGraphUI extends AltosUIFrame
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) {
diff --git a/telegps/TeleGPSState.java b/telegps/TeleGPSState.java
index 9ba0b7a5..2e39037c 100644
--- a/telegps/TeleGPSState.java
+++ b/telegps/TeleGPSState.java
@@ -124,10 +124,10 @@ public class TeleGPSState extends AltosUIFlightTab {
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) {
@@ -137,9 +137,7 @@ public class TeleGPSState extends AltosUIFlightTab {
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
diff --git a/telegps/TeleGPSStatus.java b/telegps/TeleGPSStatus.java
index 5479f43a..a6ddd1b0 100644
--- a/telegps/TeleGPSStatus.java
+++ b/telegps/TeleGPSStatus.java
@@ -75,11 +75,13 @@ public class TeleGPSStatus extends JComponent implements AltosFlightDisplay {
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);
@@ -100,12 +102,12 @@ public class TeleGPSStatus extends JComponent implements AltosFlightDisplay {
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;
}
}
@@ -126,12 +128,12 @@ public class TeleGPSStatus extends JComponent implements AltosFlightDisplay {
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;
}
}