altosui: Support MM telemetry packets
authorKeith Packard <keithp@keithp.com>
Thu, 21 Jun 2012 16:50:18 +0000 (09:50 -0700)
committerKeith Packard <keithp@keithp.com>
Thu, 21 Jun 2012 16:50:18 +0000 (09:50 -0700)
Required restructuring the whole telemetry system to provide abstract
interfaces to flight data.

Signed-off-by: Keith Packard <keithp@keithp.com>
18 files changed:
altoslib/AltosEepromIterable.java
altoslib/AltosEepromMegaIterable.java
altoslib/AltosLib.java
altoslib/AltosMs5607.java
altoslib/AltosRecord.java
altoslib/AltosRecordMM.java [new file with mode: 0644]
altoslib/AltosRecordTM.java [new file with mode: 0644]
altoslib/AltosTelemetry.java
altoslib/AltosTelemetryIterable.java
altoslib/AltosTelemetryRecord.java
altoslib/AltosTelemetryRecordLegacy.java
altoslib/AltosTelemetryRecordMegaData.java [new file with mode: 0644]
altoslib/AltosTelemetryRecordMegaSensor.java [new file with mode: 0644]
altoslib/AltosTelemetryRecordRaw.java
altoslib/AltosTelemetryRecordSensor.java
altoslib/Makefile.am
altosui/AltosCSV.java
altosui/AltosIdleMonitorUI.java

index a923d63b8cad55765d473464a67a41b93ec46f04..f8acdc1685b45db38b71ef2fccfc1261d46c3761 100644 (file)
@@ -104,7 +104,7 @@ public class AltosEepromIterable extends AltosRecordIterable {
                }
        }
 
-       void update_state(AltosRecord state, AltosEepromRecord record, EepromState eeprom) {
+       void update_state(AltosRecordTM state, AltosEepromRecord record, EepromState eeprom) {
                state.tick = record.tick;
                switch (record.cmd) {
                case AltosLib.AO_LOG_FLIGHT:
@@ -237,7 +237,7 @@ public class AltosEepromIterable extends AltosRecordIterable {
                LinkedList<AltosRecord>         list = new LinkedList<AltosRecord>();
                Iterator<AltosOrderedRecord>    iterator = records.iterator();
                AltosOrderedRecord              record = null;
-               AltosRecord                     state = new AltosRecord();
+               AltosRecordTM                   state = new AltosRecordTM();
                boolean                         last_reported = false;
                EepromState                     eeprom = new EepromState();
 
@@ -254,13 +254,13 @@ public class AltosEepromIterable extends AltosRecordIterable {
                while (iterator.hasNext()) {
                        record = iterator.next();
                        if ((eeprom.seen & seen_basic) == seen_basic && record.tick != state.tick) {
-                               AltosRecord r = new AltosRecord(state);
+                               AltosRecordTM r = state.clone();
                                r.time = (r.tick - eeprom.boost_tick) / 100.0;
                                list.add(r);
                        }
                        update_state(state, record, eeprom);
                }
-               AltosRecord r = new AltosRecord(state);
+               AltosRecordTM r = state.clone();
                r.time = (r.tick - eeprom.boost_tick) / 100.0;
                list.add(r);
        return list;
@@ -399,7 +399,7 @@ public class AltosEepromIterable extends AltosRecordIterable {
 
                try {
                        for (;;) {
-                               String line = AltosRecord.gets(input);
+                               String line = AltosLib.gets(input);
                                if (line == null)
                                        break;
                                AltosOrderedRecord record = new AltosOrderedRecord(line, index++, prev_tick, prev_tick_valid);
index 28a298b3cb829a3e73e8877308ed6e728665d404..f62cc45bac38ed3bec280b9cef1d3cd58b9058ef 100644 (file)
@@ -108,7 +108,7 @@ public class AltosEepromMegaIterable extends AltosRecordIterable {
                }
        }
 
-       void update_state(AltosRecord state, AltosEepromMega record, EepromState eeprom) {
+       void update_state(AltosRecordMM state, AltosEepromMega record, EepromState eeprom) {
                state.tick = record.tick;
                switch (record.cmd) {
                case AltosLib.AO_LOG_FLIGHT:
@@ -122,7 +122,8 @@ public class AltosEepromMegaIterable extends AltosRecordIterable {
                        break;
                case AltosLib.AO_LOG_SENSOR:
                        state.accel = record.accel();
-                       state.pres = baro.set(record.pres(), record.temp());
+                       baro.set(record.pres(), record.temp());
+                       state.pres = baro.pa;
                        state.temp = baro.cc;
                        state.imu = new AltosIMU();
                        state.imu.accel_x = record.accel_x();
@@ -161,15 +162,20 @@ public class AltosEepromMegaIterable extends AltosRecordIterable {
                        eeprom.seen |= seen_sensor;
                        break;
                case AltosLib.AO_LOG_TEMP_VOLT:
-                       state.batt = record.v_batt();
+                       state.v_batt = record.v_batt();
+                       state.v_pyro = record.v_pbatt();
+                       for (int i = 0; i < AltosRecordMM.num_sense; i++)
+                               state.sense[i] = record.sense(i);
                        eeprom.seen |= seen_temp_volt;
                        break;
-               case AltosLib.AO_LOG_DEPLOY:
-                       state.drogue = record.a;
-                       state.main = record.b;
-                       eeprom.seen |= seen_deploy;
-                       has_ignite = true;
-                       break;
+//
+//             case AltosLib.AO_LOG_DEPLOY:
+//                     state.drogue = record.a;
+//                     state.main = record.b;
+//                     eeprom.seen |= seen_deploy;
+//                     has_ignite = true;
+//                     break;
+
                case AltosLib.AO_LOG_STATE:
                        state.state = record.state();
                        break;
@@ -278,7 +284,7 @@ public class AltosEepromMegaIterable extends AltosRecordIterable {
                LinkedList<AltosRecord>         list = new LinkedList<AltosRecord>();
                Iterator<AltosOrderedMegaRecord>        iterator = records.iterator();
                AltosOrderedMegaRecord          record = null;
-               AltosRecord                     state = new AltosRecord();
+               AltosRecordMM                   state = new AltosRecordMM();
                boolean                         last_reported = false;
                EepromState                     eeprom = new EepromState();
 
@@ -295,13 +301,13 @@ public class AltosEepromMegaIterable extends AltosRecordIterable {
                while (iterator.hasNext()) {
                        record = iterator.next();
                        if ((eeprom.seen & seen_basic) == seen_basic && record.tick != state.tick) {
-                               AltosRecord r = new AltosRecord(state);
+                               AltosRecordMM r = state.clone();
                                r.time = (r.tick - eeprom.boost_tick) / 100.0;
                                list.add(r);
                        }
                        update_state(state, record, eeprom);
                }
-               AltosRecord r = new AltosRecord(state);
+               AltosRecordMM r = state.clone();
                r.time = (r.tick - eeprom.boost_tick) / 100.0;
                list.add(r);
                return list;
@@ -442,7 +448,7 @@ public class AltosEepromMegaIterable extends AltosRecordIterable {
 
                try {
                        for (;;) {
-                               String line = AltosRecord.gets(input);
+                               String line = AltosLib.gets(input);
                                if (line == null)
                                        break;
                                AltosOrderedMegaRecord record = new AltosOrderedMegaRecord(line, index++, prev_tick, prev_tick_valid);
index 4a779c551731e59bd5224b86497fb9be5dcc1733..2402331e59351cde28a76ff9be2693a6ddd739cb 100644 (file)
@@ -20,6 +20,7 @@ package org.altusmetrum.AltosLib;
 import java.awt.*;
 import java.util.*;
 import java.text.*;
+import java.io.*;
 import java.nio.charset.Charset;
 
 public class AltosLib {
@@ -304,6 +305,10 @@ public class AltosLib {
                        (bytes[i+3] << 24);
        }
 
+       public static int int32(int[] bytes, int i) {
+               return (int) uint32(bytes, i);
+       }
+
        public static final Charset     unicode_set = Charset.forName("UTF-8");
 
        public static String string(int[] bytes, int s, int l) {
@@ -375,6 +380,21 @@ public class AltosLib {
                return v * sign;
        }
 
+       public static String gets(FileInputStream s) throws IOException {
+               int c;
+               String  line = "";
+
+               while ((c = s.read()) != -1) {
+                       if (c == '\r')
+                               continue;
+                       if (c == '\n') {
+                               return line;
+                       }
+                       line = line + (char) c;
+               }
+               return null;
+       }
+
        public static String replace_extension(String input, String extension) {
                int dot = input.lastIndexOf(".");
                if (dot > 0)
index a7b902e21fb0418055653a4c2eba2356345b8815..5fd997d8ab73f8d64393c7cdc353ba1199a22738 100644 (file)
@@ -73,4 +73,11 @@ public class AltosMs5607 {
                convert();
                return pa;
        }
+
+       public AltosMs5607() {
+               raw_pres = AltosRecord.MISSING;
+               raw_temp = AltosRecord.MISSING;
+               pa = AltosRecord.MISSING;
+               cc = AltosRecord.MISSING;
+       }
 }
index 10ef30613d32a31c037e1d8c9974b58e9d761fbb..e468f84b425b705a1b6a498d309679c11449b18d 100644 (file)
@@ -22,8 +22,7 @@ import java.text.*;
 import java.util.HashMap;
 import java.io.*;
 
-public class AltosRecord implements Comparable <AltosRecord> {
-       public final static int MISSING = 0x7fffffff;
+public class AltosRecord implements Comparable <AltosRecord>, Cloneable {
 
        public static final int seen_flight = 1;
        public static final int seen_sensor = 2;
@@ -33,8 +32,13 @@ public class AltosRecord implements Comparable <AltosRecord> {
        public static final int seen_gps_lat = 32;
        public static final int seen_gps_lon = 64;
        public static final int seen_companion = 128;
-       public int                      seen;
 
+       public int      seen;
+       
+       public final static int MISSING = 0x7fffffff;
+
+       /* Every AltosRecord implementation provides these fields */
+       
        public int      version;
        public String   callsign;
        public int      serial;
@@ -44,31 +48,13 @@ public class AltosRecord implements Comparable <AltosRecord> {
        public int      state;
        public int      tick;
 
-       public int      accel;
-       public int      pres;
-       public int      temp;
-       public int      batt;
-       public int      drogue;
-       public int      main;
-
-       public int      ground_accel;
-       public int      ground_pres;
-       public int      accel_plus_g;
-       public int      accel_minus_g;
-
-       public double   acceleration;
-       public double   speed;
-       public double   height;
-
-       public int      flight_accel;
-       public int      flight_vel;
-       public int      flight_pres;
+       /* Current flight dynamic state */
+       public double   acceleration;   /* m/s² */
+       public double   speed;          /* m/s */
+       public double   height;         /* m */
 
        public AltosGPS gps;
-       public boolean          new_gps;
-
-       public AltosIMU imu;
-       public AltosMag mag;
+       public boolean  new_gps;
 
        public double   time;   /* seconds since boost */
 
@@ -83,45 +69,42 @@ public class AltosRecord implements Comparable <AltosRecord> {
        public AltosRecordCompanion companion;
 
        /*
-        * Values for our MP3H6115A pressure sensor
-        *
-        * From the data sheet:
+        * Abstract methods that convert record data
+        * to standard units:
         *
-        * Pressure range: 15-115 kPa
-        * Voltage at 115kPa: 2.82
-        * Output scale: 27mV/kPa
-        *
-        *
-        * 27 mV/kPa * 2047 / 3300 counts/mV = 16.75 counts/kPa
-        * 2.82V * 2047 / 3.3 counts/V = 1749 counts/115 kPa
+        *      pressure:       Pa
+        *      voltage:        V
+        *      acceleration:   m/s²
+        *      speed:          m/s
+        *      height:         m
+        *      temperature:    °C
         */
 
-       public static final double counts_per_kPa = 27 * 2047 / 3300;
-       public static final double counts_at_101_3kPa = 1674.0;
+       public double raw_pressure() { return MISSING; }
 
-       public static double
-       barometer_to_pressure(double count)
-       {
-               return ((count / 16.0) / 2047.0 + 0.095) / 0.009 * 1000.0;
-       }
+       public double filtered_pressure() { return MISSING; }
 
-       public double raw_pressure() {
-               if (pres == MISSING)
-                       return MISSING;
-               return barometer_to_pressure(pres);
-       }
+       public double ground_pressure() { return MISSING; }
 
-       public double filtered_pressure() {
-               if (flight_pres == MISSING)
-                       return MISSING;
-               return barometer_to_pressure(flight_pres);
-       }
+       public double battery_voltage() { return MISSING; }
 
-       public double ground_pressure() {
-               if (ground_pres == MISSING)
-                       return MISSING;
-               return barometer_to_pressure(ground_pres);
-       }
+       public double main_voltage() { return MISSING; }
+
+       public double drogue_voltage() { return MISSING; }
+
+       public double temperature() { return MISSING; }
+       
+       public double acceleration() { return MISSING; }
+
+       public double accel_speed() { return MISSING; }
+
+       public AltosIMU imu() { return null; }
+
+       public AltosMag mag() { return null; }
+
+       /*
+        * Convert various pressure values to altitude
+        */
 
        public double raw_altitude() {
                double p = raw_pressure();
@@ -138,8 +121,9 @@ public class AltosRecord implements Comparable <AltosRecord> {
        }
 
        public double filtered_altitude() {
-               if (height != MISSING && ground_pres != MISSING)
-                       return height + ground_altitude();
+               double  ga = ground_altitude();
+               if (height != MISSING && ga != MISSING)
+                       return height + ga;
 
                double  p = filtered_pressure();
                if (p == MISSING)
@@ -167,94 +151,17 @@ public class AltosRecord implements Comparable <AltosRecord> {
                return r - g;
        }
 
-       public double battery_voltage() {
-               if (batt == MISSING)
-                       return MISSING;
-               return AltosConvert.cc_battery_to_voltage(batt);
-       }
-
-       public double main_voltage() {
-               if (main == MISSING)
-                       return MISSING;
-               return AltosConvert.cc_ignitor_to_voltage(main);
-       }
-
-       public double drogue_voltage() {
-               if (drogue == MISSING)
-                       return MISSING;
-               return AltosConvert.cc_ignitor_to_voltage(drogue);
-       }
-
-       /* Value for the CC1111 built-in temperature sensor
-        * Output voltage at 0°C = 0.755V
-        * Coefficient = 0.00247V/°C
-        * Reference voltage = 1.25V
-        *
-        * temp = ((value / 32767) * 1.25 - 0.755) / 0.00247
-        *      = (value - 19791.268) / 32768 * 1.25 / 0.00247
-        */
-
-       public static double
-       thermometer_to_temperature(double thermo)
-       {
-               return (thermo - 19791.268) / 32728.0 * 1.25 / 0.00247;
-       }
-
-       public double temperature() {
-               if (temp == MISSING)
-                       return MISSING;
-               return thermometer_to_temperature(temp);
-       }
-
-       public double accel_counts_per_mss() {
-               double  counts_per_g = Math.abs(accel_minus_g - accel_plus_g) / 2;
-
-               return counts_per_g / 9.80665;
-       }
-
-       public double acceleration() {
-               if (acceleration != MISSING)
-                       return acceleration;
-
-               if (ground_accel == MISSING || accel == MISSING)
-                       return MISSING;
-               return (ground_accel - accel) / accel_counts_per_mss();
-       }
-
-       public double accel_speed() {
-               if (speed != MISSING)
-                       return speed;
-               if (flight_vel == MISSING)
-                       return MISSING;
-               return flight_vel / (accel_counts_per_mss() * 100.0);
-       }
-
        public String state() {
                return AltosLib.state_name(state);
        }
 
-       public static String gets(FileInputStream s) throws IOException {
-               int c;
-               String  line = "";
-
-               while ((c = s.read()) != -1) {
-                       if (c == '\r')
-                               continue;
-                       if (c == '\n') {
-                               return line;
-                       }
-                       line = line + (char) c;
-               }
-               return null;
-       }
-
        public int compareTo(AltosRecord o) {
                return tick - o.tick;
        }
 
-       public AltosRecord(AltosRecord old) {
-               version = old.version;
+       public void copy(AltosRecord old) {
                seen = old.seen;
+               version = old.version;
                callsign = old.callsign;
                serial = old.serial;
                flight = old.flight;
@@ -262,32 +169,27 @@ public class AltosRecord implements Comparable <AltosRecord> {
                status = old.status;
                state = old.state;
                tick = old.tick;
-               accel = old.accel;
-               pres = old.pres;
-               temp = old.temp;
-               batt = old.batt;
-               drogue = old.drogue;
-               main = old.main;
-               flight_accel = old.flight_accel;
-               ground_accel = old.ground_accel;
-               flight_vel = old.flight_vel;
-               flight_pres = old.flight_pres;
-               ground_pres = old.ground_pres;
-               accel_plus_g = old.accel_plus_g;
-               accel_minus_g = old.accel_minus_g;
                acceleration = old.acceleration;
                speed = old.speed;
                height = old.height;
                gps = new AltosGPS(old.gps);
                new_gps = false;
                companion = old.companion;
-               imu = old.imu;
-               mag = old.mag;
+       }
+
+       public AltosRecord clone() {
+               try {
+                       AltosRecord n = (AltosRecord) super.clone();
+                       n.copy(this);
+                       return n;
+               } catch (CloneNotSupportedException e) {
+                       return null;
+               }
        }
 
        public AltosRecord() {
-               version = 0;
                seen = 0;
+               version = 0;
                callsign = "N0CALL";
                serial = 0;
                flight = 0;
@@ -295,19 +197,6 @@ public class AltosRecord implements Comparable <AltosRecord> {
                status = 0;
                state = AltosLib.ao_flight_startup;
                tick = 0;
-               accel = MISSING;
-               pres = MISSING;
-               temp = MISSING;
-               batt = MISSING;
-               drogue = MISSING;
-               main = MISSING;
-               flight_accel = 0;
-               ground_accel = 0;
-               flight_vel = 0;
-               flight_pres = 0;
-               ground_pres = 0;
-               accel_plus_g = 0;
-               accel_minus_g = 0;
                acceleration = MISSING;
                speed = MISSING;
                height = MISSING;
diff --git a/altoslib/AltosRecordMM.java b/altoslib/AltosRecordMM.java
new file mode 100644 (file)
index 0000000..8b3d745
--- /dev/null
@@ -0,0 +1,186 @@
+/*
+ * Copyright © 2012 Keith Packard <keithp@keithp.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+
+package org.altusmetrum.AltosLib;
+
+public class AltosRecordMM extends AltosRecord {
+
+       public int      accel;
+       public int      pres;
+       public int      temp;
+       
+       public int      v_batt;
+       public int      v_pyro;
+       public int      sense[];
+
+       public int      ground_accel;
+       public int      ground_pres;
+       public int      accel_plus_g;
+       public int      accel_minus_g;
+
+       public int      flight_accel;
+       public int      flight_vel;
+       public int      flight_pres;
+
+       public final static int num_sense = 6;
+
+       public AltosIMU imu;
+       public AltosMag mag;
+
+       static double adc(int raw) {
+               return raw / 4095.0;
+       }
+
+       public double raw_pressure() {
+               if (pres != MISSING)
+                       return pres / 100.0;
+               return MISSING;
+       }
+
+       public double filtered_pressure() {
+               return raw_pressure();
+       }
+
+       public double ground_pressure() {
+               if (ground_pres != MISSING)
+                       return ground_pres / 100.0;
+               return MISSING;
+       }
+
+       public double battery_voltage() {
+               if (v_batt != MISSING)
+                       return 3.3 * adc(v_batt) * 27.0 / (15.0 + 27.0);
+               return MISSING;
+       }
+
+       static double pyro(int raw) {
+               if (raw != MISSING)
+                       return 3.3 * adc(raw) * 27.0 / (100.0 + 27.0);
+               return MISSING;
+       }
+
+       public double main_voltage() {
+               return pyro(sense[1]);
+       }
+
+       public double drogue_voltage() {
+               return pyro(sense[0]);
+       }
+
+       public double temperature() {
+               if (temp != MISSING)
+                       return temp / 100.0;
+               return MISSING;
+       }
+       
+       public AltosIMU imu() { return imu; }
+
+       public AltosMag mag() { return mag; }
+
+       double accel_counts_per_mss() {
+               double  counts_per_g = Math.abs(accel_minus_g - accel_plus_g) / 2;
+
+               return counts_per_g / 9.80665;
+       }
+
+       public double acceleration() {
+               System.out.printf("MM record acceleration %g ground_accel %d accel %d accel_minus_g %d accel_plus_g %d\n",
+                                 acceleration, ground_accel, accel, accel_minus_g, accel_plus_g);
+               if (acceleration != MISSING)
+                       return acceleration;
+
+               if (ground_accel == MISSING || accel == MISSING)
+                       return MISSING;
+
+               if (accel_minus_g == MISSING || accel_plus_g == MISSING)
+                       return MISSING;
+
+               return (ground_accel - accel) / accel_counts_per_mss();
+       }
+
+       public double accel_speed() {
+               return speed;
+       }
+
+       public void copy (AltosRecordMM old) {
+               super.copy(old);
+
+               accel = old.accel;
+               pres = old.pres;
+               temp = old.temp;
+
+               v_batt = old.v_batt;
+               v_pyro = old.v_pyro;
+               sense = new int[num_sense];
+               
+               for (int i = 0; i < num_sense; i++)
+                       sense[i] = old.sense[i];
+
+               ground_accel = old.ground_accel;
+               ground_pres = old.ground_pres;
+               accel_plus_g = old.accel_plus_g;
+               accel_minus_g = old.accel_minus_g;
+               
+               flight_accel = old.flight_accel;
+               flight_vel = old.flight_vel;
+               flight_pres = old.flight_pres;
+
+               imu = old.imu;
+               mag = old.mag;
+       }
+
+       public AltosRecordMM clone() {
+               AltosRecordMM n = (AltosRecordMM) super.clone();
+               n.copy(this);
+               return n;
+       }
+
+       void make_missing() {
+
+               accel = MISSING;
+               pres = MISSING;
+               temp = MISSING;
+
+               v_batt = MISSING;
+               v_pyro = MISSING;
+               sense = new int[num_sense];
+               for (int i = 0; i < num_sense; i++)
+                       sense[i] = MISSING;
+
+               ground_accel = MISSING;
+               ground_pres = MISSING;
+               accel_plus_g = MISSING;
+               accel_minus_g = MISSING;
+
+               flight_accel = 0;
+               flight_vel = 0;
+               flight_pres = 0;
+
+               imu = new AltosIMU();
+               mag = new AltosMag();
+       }
+
+       public AltosRecordMM(AltosRecord old) {
+               super.copy(old);
+               make_missing();
+       }
+
+       public AltosRecordMM() {
+               super();
+               make_missing();
+       }
+}
diff --git a/altoslib/AltosRecordTM.java b/altoslib/AltosRecordTM.java
new file mode 100644 (file)
index 0000000..afb7079
--- /dev/null
@@ -0,0 +1,199 @@
+/*
+ * Copyright © 2012 Keith Packard <keithp@keithp.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+
+package org.altusmetrum.AltosLib;
+
+public class AltosRecordTM extends AltosRecord {
+       public int      accel;
+       public int      pres;
+       public int      temp;
+       public int      batt;
+       public int      drogue;
+       public int      main;
+
+       public int      ground_accel;
+       public int      ground_pres;
+       public int      accel_plus_g;
+       public int      accel_minus_g;
+
+       public int      flight_accel;
+       public int      flight_vel;
+       public int      flight_pres;
+
+       /*
+        * Values for our MP3H6115A pressure sensor
+        *
+        * From the data sheet:
+        *
+        * Pressure range: 15-115 kPa
+        * Voltage at 115kPa: 2.82
+        * Output scale: 27mV/kPa
+        *
+        *
+        * 27 mV/kPa * 2047 / 3300 counts/mV = 16.75 counts/kPa
+        * 2.82V * 2047 / 3.3 counts/V = 1749 counts/115 kPa
+        */
+
+       static final double counts_per_kPa = 27 * 2047 / 3300;
+       static final double counts_at_101_3kPa = 1674.0;
+
+       static double
+       barometer_to_pressure(double count)
+       {
+               return ((count / 16.0) / 2047.0 + 0.095) / 0.009 * 1000.0;
+       }
+
+       public double raw_pressure() {
+               if (pres == MISSING)
+                       return MISSING;
+               return barometer_to_pressure(pres);
+       }
+
+       public double filtered_pressure() {
+               if (flight_pres == MISSING)
+                       return MISSING;
+               return barometer_to_pressure(flight_pres);
+       }
+
+       public double ground_pressure() {
+               if (ground_pres == MISSING)
+                       return MISSING;
+               return barometer_to_pressure(ground_pres);
+       }
+
+       public double battery_voltage() {
+               if (batt == MISSING)
+                       return MISSING;
+               return AltosConvert.cc_battery_to_voltage(batt);
+       }
+
+       public double main_voltage() {
+               if (main == MISSING)
+                       return MISSING;
+               return AltosConvert.cc_ignitor_to_voltage(main);
+       }
+
+       public double drogue_voltage() {
+               if (drogue == MISSING)
+                       return MISSING;
+               return AltosConvert.cc_ignitor_to_voltage(drogue);
+       }
+
+       /* Value for the CC1111 built-in temperature sensor
+        * Output voltage at 0°C = 0.755V
+        * Coefficient = 0.00247V/°C
+        * Reference voltage = 1.25V
+        *
+        * temp = ((value / 32767) * 1.25 - 0.755) / 0.00247
+        *      = (value - 19791.268) / 32768 * 1.25 / 0.00247
+        */
+
+       static double
+       thermometer_to_temperature(double thermo)
+       {
+               return (thermo - 19791.268) / 32728.0 * 1.25 / 0.00247;
+       }
+
+       public double temperature() {
+               if (temp == MISSING)
+                       return MISSING;
+               return thermometer_to_temperature(temp);
+       }
+
+       double accel_counts_per_mss() {
+               double  counts_per_g = Math.abs(accel_minus_g - accel_plus_g) / 2;
+
+               return counts_per_g / 9.80665;
+       }
+
+       public double acceleration() {
+               if (acceleration != MISSING)
+                       return acceleration;
+
+               if (ground_accel == MISSING || accel == MISSING)
+                       return MISSING;
+               return (ground_accel - accel) / accel_counts_per_mss();
+       }
+
+       public double accel_speed() {
+               if (speed != MISSING)
+                       return speed;
+               if (flight_vel == MISSING)
+                       return MISSING;
+               return flight_vel / (accel_counts_per_mss() * 100.0);
+       }
+
+       public void copy(AltosRecordTM old) {
+               super.copy(old);
+
+               version = old.version;
+               callsign = old.callsign;
+               serial = old.serial;
+               flight = old.flight;
+               rssi = old.rssi;
+               status = old.status;
+               state = old.state;
+               tick = old.tick;
+               accel = old.accel;
+               pres = old.pres;
+               temp = old.temp;
+               batt = old.batt;
+               drogue = old.drogue;
+               main = old.main;
+               flight_accel = old.flight_accel;
+               ground_accel = old.ground_accel;
+               flight_vel = old.flight_vel;
+               flight_pres = old.flight_pres;
+               ground_pres = old.ground_pres;
+               accel_plus_g = old.accel_plus_g;
+               accel_minus_g = old.accel_minus_g;
+       }
+
+       public AltosRecordTM clone() {
+               AltosRecordTM   n = (AltosRecordTM) super.clone();
+               n.copy(this);
+               return n;
+       }
+
+       void make_missing() {
+               accel = MISSING;
+               pres = MISSING;
+               temp = MISSING;
+               batt = MISSING;
+               drogue = MISSING;
+               main = MISSING;
+
+               flight_accel = 0;
+               flight_vel = 0;
+               flight_pres = 0;
+
+               ground_accel = 0;
+               ground_pres = 0;
+               accel_plus_g = 0;
+               accel_minus_g = 0;
+       }
+
+       public AltosRecordTM(AltosRecord old) {
+               super.copy(old);
+               make_missing();
+       }
+
+       public AltosRecordTM() {
+               super();
+               make_missing();
+       }
+}
index 04abb1f3b0f7c57072ca19cecf14ad61b05e0ae2..ee2448246db8348b0d1272315ad8b8045357cc77 100644 (file)
@@ -84,7 +84,7 @@ import java.util.HashMap;
  *
  */
 
-public class AltosTelemetry extends AltosRecord {
+public abstract class AltosTelemetry extends AltosRecord {
 
        /*
         * General header fields
index f4b4029f176eabb8aa16ce0537cbb3a8c115ff17..e95c15e0b5026438a8f856ff3ff18b5d0cffd596 100644 (file)
@@ -45,7 +45,7 @@ public class AltosTelemetryIterable extends AltosRecordIterable {
 
                try {
                        for (;;) {
-                               String line = AltosRecord.gets(input);
+                               String line = AltosLib.gets(input);
                                if (line == null) {
                                        break;
                                }
@@ -67,11 +67,11 @@ public class AltosTelemetryIterable extends AltosRecordIterable {
                                                saw_boost = true;
                                                boost_tick = record.tick;
                                        }
-                                       if (record.accel != AltosRecord.MISSING)
+                                       if (record.acceleration() != AltosRecord.MISSING)
                                                has_accel = true;
                                        if (record.gps != null)
                                                has_gps = true;
-                                       if (record.main != AltosRecord.MISSING)
+                                       if (record.main_voltage() != AltosRecord.MISSING)
                                                has_ignite = true;
                                        if (previous != null && previous.tick != record.tick)
                                                records.add(previous);
index 6b6a252d0b1f0e375abd49ecef17a6e73cd98792..6a8cfd35ac74a2c50caf83fc38c1c3e91e82d702 100644 (file)
@@ -43,6 +43,7 @@ public abstract class AltosTelemetryRecord {
        final static int packet_type_satellite = 0x06;
        final static int packet_type_companion = 0x07;
        final static int packet_type_MM_sensor = 0x08;
+       final static int packet_type_MM_data = 0x09;
        
        static AltosTelemetryRecord parse_hex(String hex)  throws ParseException, AltosCRCException {
                AltosTelemetryRecord    r;
@@ -76,7 +77,6 @@ public abstract class AltosTelemetryRecord {
                        case packet_type_TM_sensor:
                        case packet_type_Tm_sensor:
                        case packet_type_Tn_sensor:
-                       case packet_type_MM_sensor:
                                r = new AltosTelemetryRecordSensor(bytes, rssi);
                                break;
                        case packet_type_configuration:
@@ -91,6 +91,12 @@ public abstract class AltosTelemetryRecord {
                        case packet_type_companion:
                                r = new AltosTelemetryRecordCompanion(bytes);
                                break;
+                       case packet_type_MM_sensor:
+                               r = new AltosTelemetryRecordMegaSensor(bytes, rssi);
+                               break;
+                       case packet_type_MM_data:
+                               r = new AltosTelemetryRecordMegaData(bytes);
+                               break;
                        default:
                                r = new AltosTelemetryRecordRaw(bytes);
                                break;
index 85071d9c42116e758e7179e8283e857466366ca9..3976a07a93744b8f65bd6873c461e741dc3fbb89 100644 (file)
@@ -232,7 +232,7 @@ public class AltosTelemetryRecordLegacy extends AltosTelemetryRecord {
        final static String AO_TELEM_SAT_SVID   = "s_v";
        final static String AO_TELEM_SAT_C_N_0  = "s_c";
 
-       AltosRecord     record;
+       AltosRecordTM   record;
 
        private void parse_v4(String[] words, int i) throws ParseException {
                AltosTelemetryMap       map = new AltosTelemetryMap(words, i);
@@ -366,7 +366,7 @@ public class AltosTelemetryRecordLegacy extends AltosTelemetryRecord {
                String[] words = line.split("\\s+");
                int     i = 0;
 
-               record = new AltosRecord();
+               record = new AltosRecordTM();
 
                if (words[i].equals("CRC") && words[i+1].equals("INVALID")) {
                        i += 2;
@@ -388,7 +388,7 @@ public class AltosTelemetryRecordLegacy extends AltosTelemetryRecord {
        }
 
        /*
-        * Given a hex dump of a legacy telemetry line, construct an AltosRecord from that
+        * Given a hex dump of a legacy telemetry line, construct an AltosRecordTM from that
         */
 
        int[]   bytes;
@@ -422,7 +422,7 @@ public class AltosTelemetryRecordLegacy extends AltosTelemetryRecord {
        static final int AO_GPS_COURSE_VALID    = (1 << 7);
 
        public AltosTelemetryRecordLegacy(int[] in_bytes, int in_rssi, int in_status) {
-               record = new AltosRecord();
+               record = new AltosRecordTM();
 
                bytes = in_bytes;
                record.version = 4;
diff --git a/altoslib/AltosTelemetryRecordMegaData.java b/altoslib/AltosTelemetryRecordMegaData.java
new file mode 100644 (file)
index 0000000..cc35cd8
--- /dev/null
@@ -0,0 +1,96 @@
+/*
+ * Copyright © 2011 Keith Packard <keithp@keithp.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+
+package org.altusmetrum.AltosLib;
+
+
+public class AltosTelemetryRecordMegaData extends AltosTelemetryRecordRaw {
+
+       int     state;
+       
+       int     v_batt;
+       int     v_pyro;
+       int     sense[];
+
+       int     ground_pres;
+       int     ground_accel;
+       int     accel_plus_g;
+       int     accel_minus_g;
+
+       int     acceleration;
+       int     speed;
+       int     height;
+
+       public AltosTelemetryRecordMegaData(int[] in_bytes) {
+               super(in_bytes);
+
+               state = int8(5);
+
+               v_batt = int16(6);
+               v_pyro = int16(8);
+
+               sense = new int[6];     
+
+               for (int i = 0; i < 6; i++) {
+                       sense[i] = int8(10 + i) << 4;
+                       sense[i] |= sense[i] >> 8;
+               }
+
+               ground_pres = int32(16);
+               ground_accel = int16(20);
+               accel_plus_g = int16(22);
+               accel_minus_g = int16(24);
+
+               acceleration = int16(26);
+               speed = int16(28);
+               height = int16(30);
+       }
+
+       public AltosRecord update_state(AltosRecord previous) {
+               AltosRecord     n = super.update_state(previous);
+
+               AltosRecordMM   next;
+               if (!(n instanceof AltosRecordMM)) {
+                       System.out.printf("data making record MM\n");
+                       next = new AltosRecordMM(n);
+               } else {
+                       System.out.printf ("data already has MM\n");
+                       next = (AltosRecordMM) n;
+               }
+
+               next.state = state;
+
+               next.v_batt = v_batt;
+               next.v_pyro = v_pyro;
+
+               for (int i = 0; i < 6; i++)
+                       next.sense[i] = sense[i];
+
+               next.ground_accel = ground_accel;
+               next.ground_pres = ground_pres;
+               next.accel_plus_g = accel_plus_g;
+               next.accel_minus_g = accel_minus_g;
+
+               next.acceleration = acceleration / 16.0;
+               next.speed = speed / 16.0;
+               next.height = height;
+
+               next.seen |= AltosRecord.seen_flight | AltosRecord.seen_temp_volt;
+
+               return next;
+       }
+}
diff --git a/altoslib/AltosTelemetryRecordMegaSensor.java b/altoslib/AltosTelemetryRecordMegaSensor.java
new file mode 100644 (file)
index 0000000..85a32d1
--- /dev/null
@@ -0,0 +1,98 @@
+/*
+ * Copyright © 2011 Keith Packard <keithp@keithp.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+
+package org.altusmetrum.AltosLib;
+
+
+public class AltosTelemetryRecordMegaSensor extends AltosTelemetryRecordRaw {
+       int     accel;
+       int     pres;
+       int     temp;
+
+       int     accel_x;
+       int     accel_y;
+       int     accel_z;
+
+       int     gyro_x;
+       int     gyro_y;
+       int     gyro_z;
+
+       int     mag_x;
+       int     mag_y;
+       int     mag_z;
+
+       int     rssi;
+
+       public AltosTelemetryRecordMegaSensor(int[] in_bytes, int in_rssi) {
+               super(in_bytes);
+
+               accel         = int16(6);
+               pres          = int32(8);
+               temp          = int16(12);
+
+               accel_x       = int16(14);
+               accel_y       = int16(16);
+               accel_z       = int16(18);
+
+               gyro_x        = int16(20);
+               gyro_y        = int16(22);
+               gyro_z        = int16(24);
+
+               mag_x         = int16(26);
+               mag_y         = int16(28);
+               mag_z         = int16(30);
+
+               rssi          = in_rssi;
+               System.out.printf ("telem record accel: %d\n", accel);
+       }
+
+       public AltosRecord update_state(AltosRecord previous) {
+               AltosRecord     n = super.update_state(previous);
+
+               AltosRecordMM   next;
+               if (!(n instanceof AltosRecordMM)) {
+                       System.out.printf("sensor making MM\n");
+                       next = new AltosRecordMM(n);
+               } else {
+                       System.out.printf("sensor has MM\n");
+                       next = (AltosRecordMM) n;
+               }
+
+               System.out.printf("telem update_state accel: %d\n", accel);
+               next.accel = accel;
+               next.pres = pres;
+               next.temp = temp;
+
+               next.imu.accel_x = accel_x;
+               next.imu.accel_y = accel_y;
+               next.imu.accel_z = accel_z;
+
+               next.imu.gyro_x = gyro_x;
+               next.imu.gyro_y = gyro_y;
+               next.imu.gyro_z = gyro_z;
+
+               next.mag.x = mag_x;
+               next.mag.y = mag_y;
+               next.mag.z = mag_z;
+
+               next.rssi = rssi;
+
+               next.seen |= AltosRecord.seen_sensor;
+
+               return next;
+       }
+}
index 43d0f17a4562456d54eeba072e01a20c6437cb1e..dc1b8947d4ff665f074967293e04a7519dc41336 100644 (file)
@@ -49,6 +49,10 @@ public class AltosTelemetryRecordRaw extends AltosTelemetryRecord {
                return AltosLib.uint32(bytes, off + 1);
        }
 
+       public int int32(int off) {
+               return AltosLib.int32(bytes, off + 1);
+       }
+
        public String string(int off, int l) {
                return AltosLib.string(bytes, off + 1, l);
        }
@@ -63,7 +67,7 @@ public class AltosTelemetryRecordRaw extends AltosTelemetryRecord {
        public AltosRecord update_state(AltosRecord previous) {
                AltosRecord     next;
                if (previous != null)
-                       next = new AltosRecord(previous);
+                       next = previous.clone();
                else
                        next = new AltosRecord();
                next.serial = serial;
index cfaf90b03ccfb0b3b811b62008cdf4c27ef63c67..319a91b39d78df1195a9f64860973170bb3d79ee 100644 (file)
@@ -61,8 +61,14 @@ public class AltosTelemetryRecordSensor extends AltosTelemetryRecordRaw {
                rssi          = in_rssi;
        }
 
-       public AltosRecord update_state(AltosRecord previous) {
-               AltosRecord     next = super.update_state(previous);
+       public AltosRecord update_state(AltosRecord prev) {
+               AltosRecord     n = super.update_state(prev);
+
+               AltosRecordTM   next;
+               if (!(n instanceof AltosRecordTM))
+                       next = new AltosRecordTM(n);
+               else
+                       next = (AltosRecordTM) n;
 
                next.state = state;
                if (type == packet_type_TM_sensor)
index f644d46af4aaa0d0bf253ca8f832f19234d97ae9..ac97c9cb83452894347f379e374be401c3ef0eb5 100644 (file)
@@ -35,6 +35,8 @@ AltosLib_JAVA = \
        $(SRC)/AltosRecordCompanion.java \
        $(SRC)/AltosRecordIterable.java \
        $(SRC)/AltosRecord.java \
+       $(SRC)/AltosRecordTM.java \
+       $(SRC)/AltosRecordMM.java \
        $(SRC)/AltosReplayReader.java \
        $(SRC)/AltosState.java \
        $(SRC)/AltosTelemetry.java \
@@ -50,6 +52,8 @@ AltosLib_JAVA = \
        $(SRC)/AltosTelemetryRecordRaw.java \
        $(SRC)/AltosTelemetryRecordSatellite.java \
        $(SRC)/AltosTelemetryRecordSensor.java \
+       $(SRC)/AltosTelemetryRecordMegaSensor.java \
+       $(SRC)/AltosTelemetryRecordMegaData.java \
        $(SRC)/AltosMs5607.java \
        $(SRC)/AltosIMU.java \
        $(SRC)/AltosMag.java
index be86a4544855d602655646b39b6664d7dd405290..c876d9cabe9a1073fb37eb62641ead19acc8e28c 100644 (file)
@@ -146,8 +146,8 @@ public class AltosCSV implements AltosWriter {
        }
 
        void write_advanced(AltosRecord record) {
-               AltosIMU        imu = record.imu;
-               AltosMag        mag = record.mag;
+               AltosIMU        imu = record.imu();
+               AltosMag        mag = record.mag();
 
                if (imu == null)
                        imu = new AltosIMU();
@@ -263,7 +263,7 @@ public class AltosCSV implements AltosWriter {
                write_general(record); out.printf(",");
                write_flight(record); out.printf(",");
                write_basic(record); out.printf(",");
-               if (record.imu != null || record.mag != null)
+               if (record.imu() != null || record.mag() != null)
                        write_advanced(record);
                if (record.gps != null) {
                        out.printf(",");
@@ -287,7 +287,7 @@ public class AltosCSV implements AltosWriter {
                if (record.state == Altos.ao_flight_startup)
                        return;
                if (!header_written) {
-                       write_header(record.imu != null || record.mag != null,
+                       write_header(record.imu() != null || record.mag() != null,
                                     record.gps != null, record.companion != null);
                        header_written = true;
                }
index 2ee909374a313d50492dd3e2ffb42e167696218a..949e392675b352b9a08a79afbc22f40f9b4e1197 100644 (file)
@@ -204,17 +204,18 @@ class AltosIdleMonitor extends Thread {
                record.state = Altos.ao_flight_idle;
 
                record.tick = adc.tick;
-               record.accel = adc.accel;
-               record.pres = adc.pres;
-               record.batt = adc.batt;
-               record.temp = adc.temp;
-               record.drogue = adc.drogue;
-               record.main = adc.main;
-
-               record.ground_accel = record.accel;
-               record.ground_pres = record.pres;
-               record.accel_plus_g = config_data.accel_cal_plus;
-               record.accel_minus_g = config_data.accel_cal_minus;
+
+//             record.accel = adc.accel;
+//             record.pres = adc.pres;
+//             record.batt = adc.batt;
+//             record.temp = adc.temp;
+//             record.drogue = adc.drogue;
+//             record.main = adc.main;
+
+//             record.ground_accel = record.accel;
+//             record.ground_pres = record.pres;
+//             record.accel_plus_g = config_data.accel_cal_plus;
+//             record.accel_minus_g = config_data.accel_cal_minus;
                record.acceleration = 0;
                record.speed = 0;
                record.height = 0;