Hax0r graphing to support telem/eeprom files
authorAnthony Towns <aj@erisian.com.au>
Tue, 28 Sep 2010 04:45:01 +0000 (14:45 +1000)
committerAnthony Towns <aj@erisian.com.au>
Tue, 28 Sep 2010 04:45:01 +0000 (14:45 +1000)
ao-tools/altosui/AltosCSV.java
ao-tools/altosui/AltosDataPointReader.java [new file with mode: 0644]
ao-tools/altosui/AltosGraphDataChooser.java
ao-tools/altosui/Makefile.am

index c01d55a..3a9e48f 100644 (file)
@@ -23,7 +23,6 @@ import java.text.*;
 import java.util.*;
 
 import altosui.AltosRecord;
-import altosui.AltosReader;
 
 public class AltosCSV {
        File                    name;
diff --git a/ao-tools/altosui/AltosDataPointReader.java b/ao-tools/altosui/AltosDataPointReader.java
new file mode 100644 (file)
index 0000000..4d7831e
--- /dev/null
@@ -0,0 +1,77 @@
+
+// Copyright (c) 2010 Anthony Towns
+// GPL v2 or later
+
+package altosui;
+
+import java.io.IOException;
+import java.text.ParseException;
+import java.lang.UnsupportedOperationException;
+import java.util.NoSuchElementException;
+import java.util.Iterator;
+
+import altosui.AltosDataPoint;
+import altosui.AltosRecordIterable;
+import altosui.AltosRecord;
+import altosui.AltosState;
+
+class AltosDataPointReader implements Iterable<AltosDataPoint> {
+    Iterator<AltosRecord> iter;
+    AltosState state;
+    AltosRecord record;
+
+    public AltosDataPointReader(Iterable<AltosRecord> reader) {
+        this.iter = reader.iterator();
+        this.state = null;
+    }
+
+    private void read_next_record() 
+        throws NoSuchElementException
+    {
+        record = iter.next();
+        state = new AltosState(record, state);
+    }
+
+    private AltosDataPoint current_dp() {
+        assert this.record != null;
+        
+        return new AltosDataPoint() {
+            public int version() { return record.version; }
+            public int serial() { return record.serial; }
+            public int flight() { return record.flight; }
+            public String callsign() { return record.callsign; }
+            public double time() { return record.time; }
+            public double rssi() { return record.rssi; }
+
+            public int state() { return record.state; }
+            public String state_name() { return record.state(); }
+
+            public double acceleration() { return record.acceleration(); }
+            public double pressure() { return record.raw_pressure(); }
+            public double altitude() { return record.raw_altitude(); }
+            public double height() { return record.raw_height(); }
+            public double accel_speed() { return record.accel_speed(); }
+            public double baro_speed() { return state.baro_speed; }
+            public double temperature() { return record.temperature(); }
+            public double battery_voltage() { return record.battery_voltage(); }
+            public double drogue_voltage() { return record.drogue_voltage(); }
+            public double main_voltage() { return record.main_voltage(); }
+        };
+    }
+
+    public Iterator<AltosDataPoint> iterator() {
+        return new Iterator<AltosDataPoint>() {
+            public void remove() { 
+                throw new UnsupportedOperationException(); 
+            }
+            public boolean hasNext() {
+                return iter.hasNext();
+            }
+            public AltosDataPoint next() {
+                read_next_record();
+                return current_dp();
+            }
+        };
+    }
+}
+
index 1bf2845..667d99f 100644 (file)
@@ -28,10 +28,10 @@ import java.text.*;
 import java.util.prefs.*;
 
 import altosui.AltosPreferences;
-import altosui.AltosReader;
 import altosui.AltosCsvReader;
-import altosui.AltosEepromReader;
-import altosui.AltosTelemetryReader;
+import altosui.AltosDataPointReader;
+import altosui.AltosEepromIterable;
+import altosui.AltosTelemetryIterable;
 
 public class AltosGraphDataChooser extends JFileChooser {
        JFrame  frame;
@@ -56,7 +56,17 @@ public class AltosGraphDataChooser extends JFileChooser {
                                return null;
                        filename = file.getName();
                        try {
-                               return new AltosCsvReader(new FileReader(file));
+                if (filename.endsWith("eeprom")) {
+                    FileInputStream in = new FileInputStream(file);
+                    return new AltosDataPointReader(new AltosEepromIterable(in));
+                } else if (filename.endsWith("telem")) {
+                    FileInputStream in = new FileInputStream(file);
+                    return new AltosDataPointReader(new AltosTelemetryIterable(in));
+                } else if (filename.endsWith("csv")) {
+                                   return new AltosCsvReader(new FileReader(file));
+                } else {
+                    throw new FileNotFoundException();
+                }
                        } catch (FileNotFoundException fe) {
                                JOptionPane.showMessageDialog(frame,
                                                              filename,
@@ -71,7 +81,7 @@ public class AltosGraphDataChooser extends JFileChooser {
                frame = in_frame;
                setDialogTitle("Select Flight Record File");
                setFileFilter(new FileNameExtensionFilter("Flight data file",
-                                                         "csv"));
+                                                         "csv", "telem", "eeprom"));
                setCurrentDirectory(AltosPreferences.logdir());
        }
 }
index ab8ca7d..7510c88 100644 (file)
@@ -5,7 +5,7 @@ man_MANS=altosui.1
 
 altoslibdir=$(libdir)/altos
 
-CLASSPATH_ENV=mkdir -p $(JAVAROOT); CLASSPATH=".:classes:../libaltos:$(JFREECHART)/*:$(FREETTS)/*:/usr/share/java/*"
+CLASSPATH_ENV=mkdir -p $(JAVAROOT); CLASSPATH=".:classes:../libaltos:$(FREETTS)/*:/usr/share/java/*"
 
 bin_SCRIPTS=altosui
 
@@ -53,6 +53,7 @@ altosui_JAVA = \
        AltosTelemetry.java \
        AltosTelemetryIterable.java \
        AltosUI.java \
+    AltosDataPointReader.java \
     AltosCsvReader.java \
     AltosDataPoint.java \
     AltosGraph.java \
@@ -168,7 +169,7 @@ $(FATJAR): classaltosui.stamp Manifest-fat.txt $(FREETTS_CLASS) $(JFREECHART_CLA
 
 Manifest.txt: Makefile
        echo 'Main-Class: altosui.AltosUI' > $@
-       echo "Class-Path: $(FREETTS)/freetts.jar $(JFREECHART)/jfreechart.jar $(JFREECHAR)/jcommon.jar $(JFREECHART)/csv.jar" >> $@
+       echo "Class-Path: $(FREETTS)/freetts.jar $(FREETTS)/jfreechart.jar $(FREETTS)/jcommon.jar $(FREETTS)/csv.jar" >> $@
 
 Manifest-fat.txt:
        echo 'Main-Class: altosui.AltosUI' > $@