}
}
- 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:
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();
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;
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);
}
}
- 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:
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();
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;
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();
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;
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);
import java.awt.*;
import java.util.*;
import java.text.*;
+import java.io.*;
import java.nio.charset.Charset;
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) {
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)
convert();
return pa;
}
+
+ public AltosMs5607() {
+ raw_pres = AltosRecord.MISSING;
+ raw_temp = AltosRecord.MISSING;
+ pa = AltosRecord.MISSING;
+ cc = AltosRecord.MISSING;
+ }
}
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;
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;
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 */
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();
}
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)
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;
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;
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;
--- /dev/null
+/*
+ * 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();
+ }
+}
--- /dev/null
+/*
+ * 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();
+ }
+}
*
*/
-public class AltosTelemetry extends AltosRecord {
+public abstract class AltosTelemetry extends AltosRecord {
/*
* General header fields
try {
for (;;) {
- String line = AltosRecord.gets(input);
+ String line = AltosLib.gets(input);
if (line == null) {
break;
}
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);
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;
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:
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;
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);
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;
}
/*
- * 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;
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;
--- /dev/null
+/*
+ * 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;
+ }
+}
--- /dev/null
+/*
+ * 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;
+ }
+}
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);
}
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;
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)
$(SRC)/AltosRecordCompanion.java \
$(SRC)/AltosRecordIterable.java \
$(SRC)/AltosRecord.java \
+ $(SRC)/AltosRecordTM.java \
+ $(SRC)/AltosRecordMM.java \
$(SRC)/AltosReplayReader.java \
$(SRC)/AltosState.java \
$(SRC)/AltosTelemetry.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
}
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();
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(",");
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;
}
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;