From 6827d0a7c59d606ea05387465f1ad4d914babd49 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 11 Jun 2013 16:31:20 -0700 Subject: altosui: Use preferred units for main deployment height configuration Show and accept values in the preferred units; create a separate list of preferred values for each set of units Signed-off-by: Keith Packard --- altoslib/AltosConvert.java | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'altoslib/AltosConvert.java') diff --git a/altoslib/AltosConvert.java b/altoslib/AltosConvert.java index a42b36c4..8cd478e2 100644 --- a/altoslib/AltosConvert.java +++ b/altoslib/AltosConvert.java @@ -242,6 +242,10 @@ public class AltosConvert { return meters * (100 / (2.54 * 12)); } + public static double feet_to_meters(double feet) { + return feet * 12 * 2.54 / 100.0; + } + public static double meters_to_miles(double meters) { return meters_to_feet(meters) / 5280; } -- cgit v1.2.3 From de8d9c5630ae46378c50faf97f7d2e97fe139e30 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 29 Aug 2013 19:24:51 -0500 Subject: altoslib, altosui: Restructured state management now does TM eeprom files Removed uses of AltosRecord from AltosState, now just need to rewrite the other AltosState changing code to match Signed-off-by: Keith Packard --- altoslib/AltosConvert.java | 6 + altoslib/AltosEepromFile.java | 64 ++++- altoslib/AltosEepromHeader.java | 13 +- altoslib/AltosEepromHeaderIterable.java | 2 +- altoslib/AltosEepromIterable.java | 72 +++++- altoslib/AltosEepromMini.java | 17 ++ altoslib/AltosEepromMiniIterable.java | 2 +- altoslib/AltosEepromTM.java | 249 ++++++++----------- altoslib/AltosFlightReader.java | 2 +- altoslib/AltosGPS.java | 10 +- altoslib/AltosIMU.java | 1 + altoslib/AltosLib.java | 4 +- altoslib/AltosRecord.java | 8 + altoslib/AltosReplayReader.java | 6 +- altoslib/AltosState.java | 425 ++++++++++++++++++++------------ altoslib/AltosStateIterable.java | 29 +++ altoslib/AltosTelemetryReader.java | 6 +- altoslib/Makefile.am | 3 +- altosui/AltosAscent.java | 17 +- altosui/AltosCSV.java | 113 +++++---- altosui/AltosCSVUI.java | 8 +- altosui/AltosCompanionInfo.java | 4 +- altosui/AltosDataChooser.java | 12 +- altosui/AltosDescent.java | 17 +- altosui/AltosDisplayThread.java | 12 +- altosui/AltosEepromDownload.java | 5 +- altosui/AltosFlightStats.java | 99 ++++---- altosui/AltosFlightStatsTable.java | 8 +- altosui/AltosFlightStatus.java | 14 +- altosui/AltosFlightUI.java | 2 +- altosui/AltosGraphDataPoint.java | 17 +- altosui/AltosGraphDataSet.java | 31 ++- altosui/AltosGraphUI.java | 13 +- altosui/AltosInfoTable.java | 20 +- altosui/AltosKML.java | 56 +++-- altosui/AltosLanded.java | 14 +- altosui/AltosPad.java | 28 +-- altosui/AltosScanUI.java | 12 +- altosui/AltosSiteMap.java | 21 +- altosui/AltosUI.java | 106 ++++---- altosui/AltosWriter.java | 4 +- 41 files changed, 907 insertions(+), 645 deletions(-) create mode 100644 altoslib/AltosStateIterable.java (limited to 'altoslib/AltosConvert.java') diff --git a/altoslib/AltosConvert.java b/altoslib/AltosConvert.java index 8cd478e2..a1e2cdca 100644 --- a/altoslib/AltosConvert.java +++ b/altoslib/AltosConvert.java @@ -190,6 +190,12 @@ public class AltosConvert { return ignite / 32767 * 15.0; } + public static double + barometer_to_pressure(double count) + { + return ((count / 16.0) / 2047.0 + 0.095) / 0.009 * 1000.0; + } + public static double radio_to_frequency(int freq, int setting, int cal, int channel) { double f; diff --git a/altoslib/AltosEepromFile.java b/altoslib/AltosEepromFile.java index 48d2543c..bcc7171e 100644 --- a/altoslib/AltosEepromFile.java +++ b/altoslib/AltosEepromFile.java @@ -21,11 +21,47 @@ import java.io.*; import java.util.*; import java.text.*; -public class AltosEepromFile { +class AltosEepromIterator implements Iterator { + AltosState state; + Iterator body; + AltosEeprom next; + boolean seen; + + public boolean hasNext() { + return !seen || body.hasNext(); + } + + public AltosState next() { + if (seen) { + AltosState n = state.clone(); + AltosEeprom e = body.next(); + + e.update_state(n); + state = n; + } + seen = true; + return state; + } + + public void remove () { + } + + public AltosEepromIterator(AltosState start, Iterator body) { + this.state = start; + this.body = body; + this.seen = false; + } +} + +public class AltosEepromFile extends AltosStateIterable { AltosEepromIterable headers; AltosEepromIterable body; + public void write_comments(PrintStream out) { + headers.write(out); + } + public void write(PrintStream out) { headers.write(out); body.write(out); @@ -38,14 +74,38 @@ public class AltosEepromFile { switch (state.log_format) { case AltosLib.AO_LOG_FORMAT_FULL: + body = new AltosEepromIterable(AltosEepromTM.read(input)); + break; case AltosLib.AO_LOG_FORMAT_TINY: case AltosLib.AO_LOG_FORMAT_TELEMETRY: case AltosLib.AO_LOG_FORMAT_TELESCIENCE: case AltosLib.AO_LOG_FORMAT_TELEMEGA: break; - case AltosLib.AO_LOG_FORMAT_MINI: + case AltosLib.AO_LOG_FORMAT_TELEMINI: + case AltosLib.AO_LOG_FORMAT_EASYMINI: body = new AltosEepromIterable(AltosEepromMini.read(input)); break; } } + + int boost_tick (AltosState start) { + AltosState state = start.clone(); + for (AltosEeprom eeprom : body) { + eeprom.update_state(state); + if (state.state >= AltosLib.ao_flight_boost) + return state.tick; + } + return 0; + } + + public Iterator iterator() { + + AltosState state = headers.state(); + Iterator i = body.iterator(); + + while (i.hasNext() && !state.valid()) + i.next().update_state(state); + state.set_boost_tick(boost_tick(state)); + return new AltosEepromIterator(state, i); + } } \ No newline at end of file diff --git a/altoslib/AltosEepromHeader.java b/altoslib/AltosEepromHeader.java index b2343dc6..a06f05ed 100644 --- a/altoslib/AltosEepromHeader.java +++ b/altoslib/AltosEepromHeader.java @@ -43,8 +43,7 @@ public class AltosEepromHeader extends AltosEeprom { state.callsign = data; break; case AltosLib.AO_LOG_ACCEL_CAL: - state.accel_plus_g = config_a; - state.accel_minus_g = config_b; + state.set_accel_g(config_a, config_b); break; case AltosLib.AO_LOG_RADIO_CAL: break; @@ -56,30 +55,38 @@ public class AltosEepromHeader extends AltosEeprom { state.log_format = config_a; break; case AltosLib.AO_LOG_SERIAL_NUMBER: - state.serial = config_a; + state.set_serial(config_a); break; case AltosLib.AO_LOG_BARO_RESERVED: + state.make_baro(); state.baro.reserved = config_a; break; case AltosLib.AO_LOG_BARO_SENS: + state.make_baro(); state.baro.sens = config_a; break; case AltosLib.AO_LOG_BARO_OFF: + state.make_baro(); state.baro.off = config_a; break; case AltosLib.AO_LOG_BARO_TCS: + state.make_baro(); state.baro.tcs = config_a; break; case AltosLib.AO_LOG_BARO_TCO: + state.make_baro(); state.baro.tco = config_a; break; case AltosLib.AO_LOG_BARO_TREF: + state.make_baro(); state.baro.tref = config_a; break; case AltosLib.AO_LOG_BARO_TEMPSENS: + state.make_baro(); state.baro.tempsens = config_a; break; case AltosLib.AO_LOG_BARO_CRC: + state.make_baro(); state.baro.crc = config_a; break; case AltosLib.AO_LOG_SOFTWARE_VERSION: diff --git a/altoslib/AltosEepromHeaderIterable.java b/altoslib/AltosEepromHeaderIterable.java index fe9e05d9..01953f0e 100644 --- a/altoslib/AltosEepromHeaderIterable.java +++ b/altoslib/AltosEepromHeaderIterable.java @@ -29,7 +29,7 @@ public class AltosEepromHeaderIterable implements Iterable { } public AltosState state() { - AltosState state = new AltosState(null); + AltosState state = new AltosState(); for (AltosEepromHeader header : headers) header.update_state(state); diff --git a/altoslib/AltosEepromIterable.java b/altoslib/AltosEepromIterable.java index 470a7a8a..8e6a2313 100644 --- a/altoslib/AltosEepromIterable.java +++ b/altoslib/AltosEepromIterable.java @@ -21,6 +21,74 @@ import java.io.*; import java.util.*; import java.text.*; +class AltosEepromOrdered implements Comparable { + AltosEeprom eeprom; + int index; + int tick; + + int cmdi() { + if (eeprom.cmd == AltosLib.AO_LOG_FLIGHT) + return 0; + return 1; + } + + public int compareTo(AltosEepromOrdered o) { + int cmd_diff = cmdi() - o.cmdi(); + + if (cmd_diff != 0) + return cmd_diff; + + int tick_diff = tick - o.tick; + + if (tick_diff != 0) + return tick_diff; + return index - o.index; + } + + AltosEepromOrdered (AltosEeprom eeprom, int index, int tick) { + this.eeprom = eeprom; + this.index = index; + this.tick = tick; + } +} + +class AltosEepromOrderedIterator implements Iterator { + TreeSet olist; + Iterator oiterator; + + public AltosEepromOrderedIterator(Iterable eeproms) { + olist = new TreeSet(); + + int tick = 0; + int index = 0; + boolean first = true; + + for (AltosEeprom e : eeproms) { + int t = e.tick; + if (first) + tick = t; + else { + while (t < tick - 32767) + t += 65536; + tick = t; + } + olist.add(new AltosEepromOrdered(e, index++, tick)); + } + oiterator = olist.iterator(); + } + + public boolean hasNext() { + return oiterator.hasNext(); + } + + public AltosEeprom next() { + return oiterator.next().eeprom; + } + + public void remove () { + } +} + public class AltosEepromIterable implements Iterable { public LinkedList eeproms; @@ -30,7 +98,7 @@ public class AltosEepromIterable implements Iterable { } public AltosState state() { - AltosState state = new AltosState(null); + AltosState state = new AltosState(); for (AltosEeprom header : eeproms) header.update_state(state); @@ -44,6 +112,6 @@ public class AltosEepromIterable implements Iterable { public Iterator iterator() { if (eeproms == null) eeproms = new LinkedList(); - return eeproms.iterator(); + return new AltosEepromOrderedIterator(eeproms); } } \ No newline at end of file diff --git a/altoslib/AltosEepromMini.java b/altoslib/AltosEepromMini.java index ced87680..1e0ff1b9 100644 --- a/altoslib/AltosEepromMini.java +++ b/altoslib/AltosEepromMini.java @@ -55,13 +55,30 @@ public class AltosEepromMini extends AltosEeprom { public int sense_m() { return data16(8); } public int v_batt() { return data16(10); } + double voltage(AltosState state, int sensor) { + double supply; + + if (state.log_format == AltosLib.AO_LOG_FORMAT_EASYMINI) + supply = 3.0; + else + supply = 3.3; + return sensor / 32767.0 * supply * 127/27; + } + public void update_state(AltosState state) { switch (cmd) { case AltosLib.AO_LOG_FLIGHT: + state.set_flight(flight()); + state.set_ground_pressure(ground_pres()); break; case AltosLib.AO_LOG_STATE: + state.set_state(state()); break; case AltosLib.AO_LOG_SENSOR: + state.set_ms5607(pres(), temp()); + state.set_apogee_voltage(voltage(state, sense_a())); + state.set_main_voltage(voltage(state, sense_m())); + state.set_battery_voltage(voltage(state, v_batt())); break; } } diff --git a/altoslib/AltosEepromMiniIterable.java b/altoslib/AltosEepromMiniIterable.java index 1f221187..495495eb 100644 --- a/altoslib/AltosEepromMiniIterable.java +++ b/altoslib/AltosEepromMiniIterable.java @@ -21,7 +21,7 @@ import java.io.*; import java.util.*; import java.text.*; -public class AltosEepromMiniIterable extends AltosRecordIterable { +public class AltosEepromMiniIterable implements Iterable { static final int seen_flight = 1; static final int seen_sensor = 2; diff --git a/altoslib/AltosEepromTM.java b/altoslib/AltosEepromTM.java index fc7ec321..6945468b 100644 --- a/altoslib/AltosEepromTM.java +++ b/altoslib/AltosEepromTM.java @@ -17,134 +17,119 @@ package org.altusmetrum.altoslib_1; +import java.io.*; +import java.util.*; import java.text.*; -public class AltosEepromTM implements AltosStateUpdate { +public class AltosEepromTM extends AltosEeprom { public int cmd; public int tick; public int a; public int b; - public String data; public boolean tick_valid; public static final int record_length = 8; + static double + thermometer_to_temperature(double thermo) + { + return (thermo - 19791.268) / 32728.0 * 1.25 / 0.00247; + } + + public void write(PrintStream out) { + out.printf("%c %4x %4x %4x\n", cmd, tick, a, b); + } + public void update_state(AltosState state) { - state.set_tick(tick); + AltosGPS gps; + + /* Flush any pending GPS changes */ + if (state.gps_pending) { + switch (cmd) { + case AltosLib.AO_LOG_GPS_LAT: + case AltosLib.AO_LOG_GPS_LON: + case AltosLib.AO_LOG_GPS_ALT: + case AltosLib.AO_LOG_GPS_SAT: + case AltosLib.AO_LOG_GPS_DATE: + break; + default: + state.set_temp_gps(); + break; + } + } + switch (cmd) { case AltosLib.AO_LOG_FLIGHT: - state.ground_accel = a; - state.flight = b; + state.set_state(AltosLib.ao_flight_pad); + state.set_ground_accel(a); + state.set_flight(b); state.set_boost_tick(tick); - state.time = 0; break; case AltosLib.AO_LOG_SENSOR: - state.set_telemetrum(a, b); + state.set_tick(tick); + state.set_accel(a); + double pressure = AltosConvert.barometer_to_pressure(b); + state.set_pressure(pressure); break; case AltosLib.AO_LOG_PRESSURE: - state.set_telemetrum(AltosState.MISSING, b); + state.set_tick(tick); + state.set_pressure(AltosConvert.barometer_to_pressure(b)); break; case AltosLib.AO_LOG_TEMP_VOLT: -/* - - record.temp = a; - record.batt = b; - eeprom_state.seen |= AltosRecord.seen_temp_volt; -*/ + state.set_tick(tick); + state.set_temperature(thermometer_to_temperature(a)); + state.set_battery_voltage(AltosConvert.cc_battery_to_voltage(b)); break; case AltosLib.AO_LOG_DEPLOY: -/* - record.drogue = a; - record.main = b; - eeprom_state.seen |= AltosRecord.seen_deploy; - has_ignite = true; -*/ + state.set_tick(tick); + state.set_apogee_voltage(AltosConvert.cc_ignitor_to_voltage(a)); + state.set_main_voltage(AltosConvert.cc_ignitor_to_voltage(b)); break; case AltosLib.AO_LOG_STATE: - state.state = a; - break; -// case AltosLib.AO_LOG_GPS_TIME: -// eeprom_state.gps_tick = record.tick; -// eeprom_state.seen |= AltosRecord.seen_gps_time; -// AltosGPS old = state.gps; -// AltosGPS gps = new AltosGPS(); -// -// /* GPS date doesn't get repeated through the file */ -// if (old != null) { -// gps.year = old.year; -// gps.month = old.month; -// gps.day = old.day; -// } -// gps.hour = (a & 0xff); -// gps.minute = (a >> 8); -// gps.second = (b & 0xff); -// -// int flags = (b >> 8); -// gps.connected = (flags & AltosLib.AO_GPS_RUNNING) != 0; -// gps.locked = (flags & AltosLib.AO_GPS_VALID) != 0; -// gps.nsat = (flags & AltosLib.AO_GPS_NUM_SAT_MASK) >> -// AltosLib.AO_GPS_NUM_SAT_SHIFT; -// state.temp_gps = gps; -// break; -// case AltosLib.AO_LOG_GPS_LAT: -// int lat32 = a | (b << 16); -// if (state.temp_gps == null) -// state.temp_gps = new AltosGPS(); -// state.temp_gps.lat = (double) lat32 / 1e7; -// break; -// case AltosLib.AO_LOG_GPS_LON: -// int lon32 = a | (b << 16); -// if (state.temp_gps == null) -// state.temp_gps = new AltosGPS(); -// state.temp_gps.lon = (double) lon32 / 1e7; -// break; -// case AltosLib.AO_LOG_GPS_ALT: -// if (state.temp_gps == null) -// state.temp_gps = new AltosGPS(); -// state.temp_gps.alt = a; -// break; -// case AltosLib.AO_LOG_GPS_SAT: -// if (record.tick == eeprom_state.gps_tick) { -// int svid = a; -// int c_n0 = b >> 8; -// if (record.gps == null) -// record.gps = new AltosGPS(); -// record.gps.add_sat(svid, c_n0); -// } -// break; -// case AltosLib.AO_LOG_GPS_DATE: -// if (record.gps == null) -// record.gps = new AltosGPS(); -// record.gps.year = (a & 0xff) + 2000; -// record.gps.month = a >> 8; -// record.gps.day = b & 0xff; -// break; - - case AltosLib.AO_LOG_CONFIG_VERSION: - break; - case AltosLib.AO_LOG_MAIN_DEPLOY: - break; - case AltosLib.AO_LOG_APOGEE_DELAY: - break; - case AltosLib.AO_LOG_RADIO_CHANNEL: - break; - case AltosLib.AO_LOG_CALLSIGN: - state.callsign = data; + state.set_tick(tick); + state.set_state(a); break; - case AltosLib.AO_LOG_ACCEL_CAL: - state.accel_plus_g = a; - state.accel_minus_g = b; + case AltosLib.AO_LOG_GPS_TIME: + gps = state.make_temp_gps(); + + gps.hour = (a & 0xff); + gps.minute = (a >> 8); + gps.second = (b & 0xff); + + int flags = (b >> 8); + + gps.connected = (flags & AltosLib.AO_GPS_RUNNING) != 0; + gps.locked = (flags & AltosLib.AO_GPS_VALID) != 0; + gps.nsat = (flags & AltosLib.AO_GPS_NUM_SAT_MASK) >> + AltosLib.AO_GPS_NUM_SAT_SHIFT; break; - case AltosLib.AO_LOG_RADIO_CAL: + case AltosLib.AO_LOG_GPS_LAT: + gps = state.make_temp_gps(); + + int lat32 = a | (b << 16); + gps.lat = (double) lat32 / 1e7; break; - case AltosLib.AO_LOG_MANUFACTURER: + case AltosLib.AO_LOG_GPS_LON: + gps = state.make_temp_gps(); + + int lon32 = a | (b << 16); + gps.lon = (double) lon32 / 1e7; break; - case AltosLib.AO_LOG_PRODUCT: + case AltosLib.AO_LOG_GPS_ALT: + gps = state.make_temp_gps(); + gps.alt = a; break; - case AltosLib.AO_LOG_SERIAL_NUMBER: - state.serial = a; + case AltosLib.AO_LOG_GPS_SAT: + gps = state.make_temp_gps(); + int svid = a; + int c_n0 = b >> 8; + gps.add_sat(svid, c_n0); break; - case AltosLib.AO_LOG_SOFTWARE_VERSION: + case AltosLib.AO_LOG_GPS_DATE: + gps = state.make_temp_gps(); + gps.year = (a & 0xff) + 2000; + gps.month = a >> 8; + gps.day = b & 0xff; break; } } @@ -166,8 +151,6 @@ public class AltosEepromTM implements AltosStateUpdate { tick = chunk.data16(start + 2); a = chunk.data16(start + 4); b = chunk.data16(start + 6); - - data = null; } public AltosEepromTM (String line) { @@ -175,10 +158,8 @@ public class AltosEepromTM implements AltosStateUpdate { tick = 0; a = 0; b = 0; - data = null; if (line == null) { cmd = AltosLib.AO_LOG_INVALID; - data = ""; } else { try { String[] tokens = line.split("\\s+"); @@ -186,7 +167,6 @@ public class AltosEepromTM implements AltosStateUpdate { if (tokens[0].length() == 1) { if (tokens.length != 4) { cmd = AltosLib.AO_LOG_INVALID; - data = line; } else { cmd = tokens[0].codePointAt(0); tick = Integer.parseInt(tokens[1],16); @@ -194,53 +174,11 @@ public class AltosEepromTM implements AltosStateUpdate { a = Integer.parseInt(tokens[2],16); b = Integer.parseInt(tokens[3],16); } - } else if (tokens[0].equals("Config") && tokens[1].equals("version:")) { - cmd = AltosLib.AO_LOG_CONFIG_VERSION; - data = tokens[2]; - } else if (tokens[0].equals("Main") && tokens[1].equals("deploy:")) { - cmd = AltosLib.AO_LOG_MAIN_DEPLOY; - a = Integer.parseInt(tokens[2]); - } else if (tokens[0].equals("Apogee") && tokens[1].equals("delay:")) { - cmd = AltosLib.AO_LOG_APOGEE_DELAY; - a = Integer.parseInt(tokens[2]); - } else if (tokens[0].equals("Radio") && tokens[1].equals("channel:")) { - cmd = AltosLib.AO_LOG_RADIO_CHANNEL; - a = Integer.parseInt(tokens[2]); - } else if (tokens[0].equals("Callsign:")) { - cmd = AltosLib.AO_LOG_CALLSIGN; - data = tokens[1].replaceAll("\"",""); - } else if (tokens[0].equals("Accel") && tokens[1].equals("cal")) { - cmd = AltosLib.AO_LOG_ACCEL_CAL; - a = Integer.parseInt(tokens[3]); - b = Integer.parseInt(tokens[5]); - } else if (tokens[0].equals("Radio") && tokens[1].equals("cal:")) { - cmd = AltosLib.AO_LOG_RADIO_CAL; - a = Integer.parseInt(tokens[2]); - } else if (tokens[0].equals("Max") && tokens[1].equals("flight") && tokens[2].equals("log:")) { - cmd = AltosLib.AO_LOG_MAX_FLIGHT_LOG; - a = Integer.parseInt(tokens[3]); - } else if (tokens[0].equals("manufacturer")) { - cmd = AltosLib.AO_LOG_MANUFACTURER; - data = tokens[1]; - } else if (tokens[0].equals("product")) { - cmd = AltosLib.AO_LOG_PRODUCT; - data = tokens[1]; - } else if (tokens[0].equals("serial-number")) { - cmd = AltosLib.AO_LOG_SERIAL_NUMBER; - a = Integer.parseInt(tokens[1]); - } else if (tokens[0].equals("log-format")) { - cmd = AltosLib.AO_LOG_LOG_FORMAT; - a = Integer.parseInt(tokens[1]); - } else if (tokens[0].equals("software-version")) { - cmd = AltosLib.AO_LOG_SOFTWARE_VERSION; - data = tokens[1]; } else { cmd = AltosLib.AO_LOG_INVALID; - data = line; } } catch (NumberFormatException ne) { -v cmd = AltosLib.AO_LOG_INVALID; - data = line; + cmd = AltosLib.AO_LOG_INVALID; } } } @@ -252,4 +190,23 @@ v cmd = AltosLib.AO_LOG_INVALID; a = in_a; b = in_b; } + + static public LinkedList read(FileInputStream input) { + LinkedList tms = new LinkedList(); + + for (;;) { + try { + String line = AltosLib.gets(input); + if (line == null) + break; + AltosEepromTM tm = new AltosEepromTM(line); + tms.add(tm); + } catch (IOException ie) { + break; + } + } + + return tms; + } + } diff --git a/altoslib/AltosFlightReader.java b/altoslib/AltosFlightReader.java index 34526658..5a415274 100644 --- a/altoslib/AltosFlightReader.java +++ b/altoslib/AltosFlightReader.java @@ -28,7 +28,7 @@ public class AltosFlightReader { public void init() { } - public AltosRecord read() throws InterruptedException, ParseException, AltosCRCException, IOException { return null; } + public AltosState read() throws InterruptedException, ParseException, AltosCRCException, IOException { return null; } public void close(boolean interrupted) { } diff --git a/altoslib/AltosGPS.java b/altoslib/AltosGPS.java index f7929a4c..eb384e4d 100644 --- a/altoslib/AltosGPS.java +++ b/altoslib/AltosGPS.java @@ -28,7 +28,7 @@ public class AltosGPS implements Cloneable { public boolean connected; public double lat; /* degrees (+N -S) */ public double lon; /* degrees (+E -W) */ - public int alt; /* m */ + public double alt; /* m */ public int year; public int month; public int day; @@ -222,7 +222,7 @@ public class AltosGPS implements Cloneable { g.nsat = nsat; g.locked = locked; g.connected = connected; - g.lat = lat; g./* degrees (+N -S) */ + g.lat = lat; /* degrees (+N -S) */ g.lon = lon; /* degrees (+E -W) */ g.alt = alt; /* m */ g.year = year; @@ -242,11 +242,11 @@ public class AltosGPS implements Cloneable { if (cc_gps_sat != null) { g.cc_gps_sat = new AltosGPSSat[cc_gps_sat.length]; for (int i = 0; i < cc_gps_sat.length; i++) { - g.cc_gps_sat[i] = new AltosGPSSat(); - g.cc_gps_sat[i].svid = cc_gps_sat[i].svid; - g.cc_gps_sat[i].c_n0 = cc_gps_sat[i].c_n0; + g.cc_gps_sat[i] = new AltosGPSSat(cc_gps_sat[i].svid, + cc_gps_sat[i].c_n0); } } + return g; } public AltosGPS(AltosGPS old) { diff --git a/altoslib/AltosIMU.java b/altoslib/AltosIMU.java index 46df35bf..c5ebbb16 100644 --- a/altoslib/AltosIMU.java +++ b/altoslib/AltosIMU.java @@ -37,5 +37,6 @@ public class AltosIMU implements Cloneable { n.gyro_y = gyro_y; n.gyro_z = gyro_z; return n; + } } \ No newline at end of file diff --git a/altoslib/AltosLib.java b/altoslib/AltosLib.java index d60ef492..4ca8ad9d 100644 --- a/altoslib/AltosLib.java +++ b/altoslib/AltosLib.java @@ -218,7 +218,9 @@ public class AltosLib { public static final int AO_LOG_FORMAT_TELEMETRY = 3; public static final int AO_LOG_FORMAT_TELESCIENCE = 4; public static final int AO_LOG_FORMAT_TELEMEGA = 5; - public static final int AO_LOG_FORMAT_MINI = 6; + public static final int AO_LOG_FORMAT_EASYMINI = 6; + public static final int AO_LOG_FORMAT_TELEMETRUM = 7; + public static final int AO_LOG_FORMAT_TELEMINI = 8; public static final int AO_LOG_FORMAT_NONE = 127; public static boolean isspace(int c) { diff --git a/altoslib/AltosRecord.java b/altoslib/AltosRecord.java index 5e4ed927..0c8e1db9 100644 --- a/altoslib/AltosRecord.java +++ b/altoslib/AltosRecord.java @@ -56,6 +56,10 @@ public class AltosRecord implements Comparable , Cloneable { public int flight_log_max; public String firmware_version; + public double accel_plus_g, accel_minus_g; + public double ground_accel; + public double accel; + public AltosRecordCompanion companion; /* Telemetry sources have these values recorded from the flight computer */ @@ -167,5 +171,9 @@ public class AltosRecord implements Comparable , Cloneable { kalman_acceleration = MISSING; kalman_speed = MISSING; kalman_height = MISSING; + + accel_plus_g = MISSING; + accel_minus_g = MISSING; + } } diff --git a/altoslib/AltosReplayReader.java b/altoslib/AltosReplayReader.java index a7e30370..0c14dee4 100644 --- a/altoslib/AltosReplayReader.java +++ b/altoslib/AltosReplayReader.java @@ -25,10 +25,10 @@ import java.util.*; */ public class AltosReplayReader extends AltosFlightReader { - Iterator iterator; + Iterator iterator; File file; - public AltosRecord read() { + public AltosState read() { if (iterator.hasNext()) return iterator.next(); return null; @@ -45,7 +45,7 @@ public class AltosReplayReader extends AltosFlightReader { public File backing_file() { return file; } - public AltosReplayReader(Iterator in_iterator, File in_file) { + public AltosReplayReader(Iterator in_iterator, File in_file) { iterator = in_iterator; file = in_file; name = file.getName(); diff --git a/altoslib/AltosState.java b/altoslib/AltosState.java index b40b744f..daf06c19 100644 --- a/altoslib/AltosState.java +++ b/altoslib/AltosState.java @@ -22,22 +22,35 @@ package org.altusmetrum.altoslib_1; public class AltosState implements Cloneable { - public AltosRecord data; + public AltosRecord record; + + public static final int set_position = 1; + public static final int set_gps = 2; + public static final int set_data = 4; + + public int set; /* derived data */ public long report_time; public double time; + public double prev_time; public double time_change; public int tick; + public int boost_tick; public int state; + public int flight; + public int serial; public boolean landed; public boolean ascent; /* going up? */ public boolean boost; /* under power */ + public int rssi; + public int status; public double ground_altitude; + public double ground_pressure; public double altitude; public double height; public double pressure; @@ -60,6 +73,8 @@ public class AltosState implements Cloneable { public double kalman_height, kalman_speed, kalman_acceleration; public AltosGPS gps; + public AltosGPS temp_gps; + public boolean gps_pending; public int gps_sequence; public AltosIMU imu; @@ -91,10 +106,11 @@ public class AltosState implements Cloneable { public double ground_accel; public int log_format; - public int serial; public AltosMs5607 baro; + public AltosRecordCompanion companion; + public double speed() { return speed; } @@ -112,17 +128,25 @@ public class AltosState implements Cloneable { } public void init() { - data = new AltosRecord(); + record = null; + + set = 0; report_time = System.currentTimeMillis(); time = AltosRecord.MISSING; time_change = AltosRecord.MISSING; + prev_time = AltosRecord.MISSING; tick = AltosRecord.MISSING; + boost_tick = AltosRecord.MISSING; state = AltosLib.ao_flight_invalid; + flight = AltosRecord.MISSING; landed = false; boost = false; + rssi = AltosRecord.MISSING; + status = 0; ground_altitude = AltosRecord.MISSING; + ground_pressure = AltosRecord.MISSING; altitude = AltosRecord.MISSING; height = AltosRecord.MISSING; pressure = AltosRecord.MISSING; @@ -138,21 +162,20 @@ public class AltosState implements Cloneable { apogee_voltage = AltosRecord.MISSING; main_voltage = AltosRecord.MISSING; - - accel_speed = AltosRecord.MISSING; - baro_speed = AltosRecord.MISSING; + speed = AltosRecord.MISSING; kalman_height = AltosRecord.MISSING; kalman_speed = AltosRecord.MISSING; kalman_acceleration = AltosRecord.MISSING; - max_baro_speed = 0; - max_accel_speed = 0; + max_speed = 0; max_height = 0; max_acceleration = 0; gps = null; + temp_gps = null; gps_sequence = 0; + gps_pending = false; imu = null; mag = null; @@ -165,7 +188,7 @@ public class AltosState implements Cloneable { range = AltosRecord.MISSING; gps_height = AltosRecord.MISSING; - pat_lat = AltosRecord.MISSING; + pad_lat = AltosRecord.MISSING; pad_lon = AltosRecord.MISSING; pad_alt = AltosRecord.MISSING; @@ -176,15 +199,18 @@ public class AltosState implements Cloneable { accel_plus_g = AltosRecord.MISSING; accel_minus_g = AltosRecord.MISSING; + accel = AltosRecord.MISSING; + ground_accel = AltosRecord.MISSING; log_format = AltosRecord.MISSING; serial = AltosRecord.MISSING; baro = null; + companion = null; } void copy(AltosState old) { - data = null; + record = null; if (old == null) { init(); @@ -193,13 +219,19 @@ public class AltosState implements Cloneable { report_time = old.report_time; time = old.time; - time_change = old.time_change; + time_change = 0; tick = old.tick; + boost_tick = old.boost_tick; state = old.state; + flight = old.flight; landed = old.landed; ascent = old.ascent; boost = old.boost; + rssi = old.rssi; + status = old.status; + + set = 0; ground_altitude = old.ground_altitude; altitude = old.altitude; @@ -211,17 +243,16 @@ public class AltosState implements Cloneable { temperature = old.temperature; apogee_voltage = old.apogee_voltage; main_voltage = old.main_voltage; - accel_speed = old.accel_speed; - baro_speed = old.baro_speed; + speed = old.speed; prev_height = old.height; prev_speed = old.speed; prev_acceleration = old.acceleration; + prev_time = old.time; max_height = old.max_height; max_acceleration = old.max_acceleration; - max_accel_speed = old.max_accel_speed; - max_baro_speed = old.max_baro_speed; + max_speed = old.max_speed; kalman_height = old.kalman_height; kalman_speed = old.kalman_speed; @@ -231,7 +262,12 @@ public class AltosState implements Cloneable { gps = old.gps.clone(); else gps = null; + if (old.temp_gps != null) + temp_gps = old.temp_gps.clone(); + else + temp_gps = null; gps_sequence = old.gps_sequence; + gps_pending = old.gps_pending; if (old.imu != null) imu = old.imu.clone(); @@ -268,14 +304,14 @@ public class AltosState implements Cloneable { accel_plus_g = old.accel_plus_g; accel_minus_g = old.accel_minus_g; + accel = old.accel; + ground_accel = old.ground_accel; + log_format = old.log_format; serial = old.serial; baro = old.baro; - } - - double ground_altitude() { - + companion = old.companion; } double altitude() { @@ -289,8 +325,12 @@ public class AltosState implements Cloneable { void update_vertical_pos() { double alt = altitude(); - if (state == AltosLib.ao_flight_pad) { - + + if (state == AltosLib.ao_flight_pad && alt != AltosRecord.MISSING && ground_pressure == AltosRecord.MISSING) { + if (ground_altitude == AltosRecord.MISSING) + ground_altitude = alt; + else + ground_altitude = (ground_altitude * 7 + alt) / 8; } if (kalman_height != AltosRecord.MISSING) @@ -300,6 +340,9 @@ public class AltosState implements Cloneable { else height = AltosRecord.MISSING; + if (height != AltosRecord.MISSING && height > max_height) + max_height = height; + update_speed(); } @@ -348,12 +391,14 @@ public class AltosState implements Cloneable { } } } + if (boost && speed != AltosRecord.MISSING && speed > max_speed) + max_speed = speed; } void update_accel() { if (accel == AltosRecord.MISSING) return; - if (ground_Accel == AltosRecord.MISSING) + if (ground_accel == AltosRecord.MISSING) return; if (accel_plus_g == AltosRecord.MISSING) return; @@ -364,9 +409,60 @@ public class AltosState implements Cloneable { double counts_per_mss = counts_per_g / 9.80665; acceleration = (ground_accel - accel) / counts_per_mss; + + /* Only look at accelerometer data under boost */ + if (boost && acceleration != AltosRecord.MISSING && (max_acceleration == AltosRecord.MISSING || acceleration > max_acceleration)) + max_acceleration = acceleration; update_speed(); } + void update_time() { + if (tick != AltosRecord.MISSING) { + time = tick / 100.0; + if (prev_time != AltosRecord.MISSING) + time_change = time - prev_time; + } + } + + void update_gps() { + elevation = 0; + range = -1; + gps_height = 0; + + if (gps == null) + return; + + if (gps.locked && gps.nsat >= 4) { + /* Track consecutive 'good' gps reports, waiting for 10 of them */ + if (state == AltosLib.ao_flight_pad) { + set_npad(npad+1); + if (pad_lat != AltosRecord.MISSING) { + pad_lat = (pad_lat * 31 + gps.lat) / 32; + pad_lon = (pad_lon * 31 + gps.lon) / 32; + pad_alt = (pad_alt * 31 + gps.alt) / 32; + } + } + if (pad_lat == AltosRecord.MISSING) { + pad_lat = gps.lat; + pad_lon = gps.lon; + pad_alt = gps.alt; + } + } + if (gps.lat != 0 && gps.lon != 0 && + pad_lat != AltosRecord.MISSING && + pad_lon != AltosRecord.MISSING) + { + double h = height; + + if (h == AltosRecord.MISSING) + h = 0; + from_pad = new AltosGreatCircle(pad_lat, pad_lon, 0, gps.lat, gps.lon, h); + elevation = from_pad.elevation; + range = from_pad.range; + gps_height = gps.alt - pad_alt; + } + } + public void set_tick(int tick) { if (tick != AltosRecord.MISSING) { if (this.tick != AltosRecord.MISSING) { @@ -380,6 +476,15 @@ public class AltosState implements Cloneable { } } + public void set_boost_tick(int boost_tick) { + if (boost_tick != AltosRecord.MISSING) + this.boost_tick = boost_tick; + } + + public String state_name() { + return AltosLib.state_name(state); + } + public void set_state(int state) { if (state != AltosLib.ao_flight_invalid) { this.state = state; @@ -390,10 +495,47 @@ public class AltosState implements Cloneable { } + public void set_flight(int flight) { + + /* When the flight changes, reset the state */ + if (flight != AltosRecord.MISSING) { + if (this.flight != AltosRecord.MISSING && + this.flight != flight) { + init(); + } + this.flight = flight; + } + } + + public void set_serial(int serial) { + /* When the serial changes, reset the state */ + if (serial != AltosRecord.MISSING) { + if (this.serial != AltosRecord.MISSING && + this.serial != serial) { + init(); + } + this.serial = serial; + } + } + + public int rssi() { + if (rssi == AltosRecord.MISSING) + return 0; + return rssi; + } + + public void set_rssi(int rssi, int status) { + if (rssi != AltosRecord.MISSING) { + this.rssi = rssi; + this.status = status; + } + } + public void set_altitude(double altitude) { if (altitude != AltosRecord.MISSING) { this.altitude = altitude; update_vertical_pos(); + set |= set_position; } } @@ -404,11 +546,24 @@ public class AltosState implements Cloneable { } } + public void set_ground_pressure (double pressure) { + if (pressure != AltosRecord.MISSING) { + this.ground_pressure = pressure; + set_ground_altitude(AltosConvert.pressure_to_altitude(pressure)); + update_vertical_pos(); + } + } + public void set_gps(AltosGPS gps, int sequence) { if (gps != null) { + System.out.printf ("gps date: %d-%d-%d time %d:%d:%d\n", + gps.year, gps.month, gps.day, + gps.hour, gps.minute, gps.second); this.gps = gps.clone(); gps_sequence = sequence; + update_gps(); update_vertical_pos(); + set |= set_gps; } } @@ -417,7 +572,6 @@ public class AltosState implements Cloneable { kalman_height = height; kalman_speed = speed; kalman_acceleration = acceleration; - baro_speed = accel_speed = speed; update_vertical_pos(); } } @@ -429,6 +583,29 @@ public class AltosState implements Cloneable { } } + public void make_baro() { + if (baro == null) + baro = new AltosMs5607(); + } + + public void set_ms5607(int pres, int temp) { + if (baro != null) { + baro.set(pres, temp); + + set_pressure(baro.pa); + set_temperature(baro.cc / 100.0); + } + } + + public void make_companion (int nchannels) { + if (companion == null) + companion = new AltosRecordCompanion(nchannels); + } + + public void set_companion(AltosRecordCompanion companion) { + this.companion = companion; + } + public void set_accel_g(double accel_plus_g, double accel_minus_g) { if (accel_plus_g != AltosRecord.MISSING) { this.accel_plus_g = accel_plus_g; @@ -451,36 +628,77 @@ public class AltosState implements Cloneable { } public void set_temperature(double temperature) { - if (temperature != AltosRecord.MISSING) + if (temperature != AltosRecord.MISSING) { this.temperature = temperature; + set |= set_data; + } } public void set_battery_voltage(double battery_voltage) { - if (battery_voltage != AltosRecord.MISSING) + if (battery_voltage != AltosRecord.MISSING) { this.battery_voltage = battery_voltage; + set |= set_data; + } } public void set_pyro_voltage(double pyro_voltage) { - if (pyro_voltage != AltosRecord.MISSING) + if (pyro_voltage != AltosRecord.MISSING) { this.pyro_voltage = pyro_voltage; + set |= set_data; + } } public void set_apogee_voltage(double apogee_voltage) { - if (apogee_voltage != AltosRecord.MISSING) + if (apogee_voltage != AltosRecord.MISSING) { this.apogee_voltage = apogee_voltage; + set |= set_data; + } } public void set_main_voltage(double main_voltage) { - if (main_voltage != AltosRecord.MISSING) + if (main_voltage != AltosRecord.MISSING) { this.main_voltage = main_voltage; + set |= set_data; + } + } + + + public double time_since_boost() { + if (tick == AltosRecord.MISSING) + return 0.0; + + if (boost_tick != AltosRecord.MISSING) { + return (tick - boost_tick) / 100.0; + } + return tick / 100.0; + } + + public boolean valid() { + return tick != AltosRecord.MISSING && serial != AltosRecord.MISSING; + } + + public AltosGPS make_temp_gps() { + if (temp_gps == null) { + temp_gps = new AltosGPS(gps); + temp_gps.cc_gps_sat = null; + } + gps_pending = true; + return temp_gps; + } + + public void set_temp_gps() { + set_gps(temp_gps, gps_sequence + 1); + gps_pending = false; + temp_gps = null; } public void init (AltosRecord cur, AltosState prev_state) { + System.out.printf ("init\n"); if (cur == null) cur = new AltosRecord(); - data = cur; + record = cur; /* Discard previous state if it was for a different board */ if (prev_state != null && prev_state.serial != cur.serial) @@ -488,146 +706,35 @@ public class AltosState implements Cloneable { copy(prev_state); - set_ground_altitude(data.ground_altitude()); - set_altitude(data.altitude()); + set_ground_altitude(cur.ground_altitude()); + set_altitude(cur.altitude()); - set_kalman(data.kalman_height, data.kalman_speed, data.kalman_acceleration); + set_kalman(cur.kalman_height, cur.kalman_speed, cur.kalman_acceleration); report_time = System.currentTimeMillis(); - set_temperature(data.temperature()); - set_apogee_voltage(data.drogue_voltage()); - set_main_voltage(data.main_voltage()); - set_battery_voltage(data.battery_voltage()); - - set_pressure(data.pressure()); - - set_tick(data.tick); - set_state(data.state); + set_temperature(cur.temperature()); + set_apogee_voltage(cur.drogue_voltage()); + set_main_voltage(cur.main_voltage()); + set_battery_voltage(cur.battery_voltage()); - set_accel_g (data.accel_minus_g, data.accel_plus_g); - set_ground_accel(data.ground_accel); - set_accel (data.accel); + set_pressure(cur.pressure()); - set_gps(data.gps, data.gps_sequence); + set_tick(cur.tick); + set_state(cur.state); - if (prev_state != null) { + set_accel_g (cur.accel_minus_g, cur.accel_plus_g); + set_ground_accel(cur.ground_accel); + set_accel (cur.accel); - if (data.kalman_speed != AltosRecord.MISSING) { - baro_speed = accel_speed = data.kalman_speed; - } else { - /* compute barometric speed */ - - double height_change = height - prev_state.height; - - double prev_baro_speed = prev_state.baro_speed; - if (prev_baro_speed == AltosRecord.MISSING) - prev_baro_speed = 0; - - if (time_change > 0) - baro_speed = (prev_baro_speed * 3 + (height_change / time_change)) / 4.0; - else - baro_speed = prev_state.baro_speed; + if (cur.gps_sequence != gps_sequence) + set_gps(cur.gps, cur.gps_sequence); - double prev_accel_speed = prev_state.accel_speed; - - if (prev_accel_speed == AltosRecord.MISSING) - prev_accel_speed = 0; - - if (acceleration == AltosRecord.MISSING) { - /* Fill in mising acceleration value */ - accel_speed = baro_speed; - - if (time_change > 0 && accel_speed != AltosRecord.MISSING) - acceleration = (accel_speed - prev_accel_speed) / time_change; - else - acceleration = prev_state.acceleration; - } else { - /* compute accelerometer speed */ - accel_speed = prev_accel_speed + acceleration * time_change; - } - } - } else { - npad = 0; - ngps = 0; - gps = null; - gps_sequence = 0; - baro_speed = AltosRecord.MISSING; - accel_speed = AltosRecord.MISSING; - pad_alt = AltosRecord.MISSING; - max_baro_speed = 0; - max_accel_speed = 0; - max_height = 0; - max_acceleration = 0; - time_change = 0; - baro = new AltosMs5607(); - callsign = ""; - accel_plus_g = AltosRecord.MISSING; - accel_minus_g = AltosRecord.MISSING; - log_format = AltosRecord.MISSING; - serial = AltosRecord.MISSING; - } - - time = tick / 100.0; - - if (data.gps != null && data.gps_sequence != gps_sequence && (state < AltosLib.ao_flight_boost)) { - - /* Track consecutive 'good' gps reports, waiting for 10 of them */ - if (data.gps != null && data.gps.locked && data.gps.nsat >= 4) - set_npad(npad+1); - else - set_npad(0); - - /* Average GPS data while on the pad */ - if (data.gps != null && data.gps.locked && data.gps.nsat >= 4) { - if (ngps > 1 && state == AltosLib.ao_flight_pad) { - /* filter pad position */ - pad_lat = (pad_lat * 31.0 + data.gps.lat) / 32.0; - pad_lon = (pad_lon * 31.0 + data.gps.lon) / 32.0; - pad_alt = (pad_alt * 31.0 + data.gps.alt) / 32.0; - } else { - pad_lat = data.gps.lat; - pad_lon = data.gps.lon; - pad_alt = data.gps.alt; - } - ngps++; - } - } else { - if (ngps == 0 && ground_altitude != AltosRecord.MISSING) - pad_alt = ground_altitude; - } - - gps_sequence = data.gps_sequence; - - /* Only look at accelerometer data under boost */ - if (boost && acceleration != AltosRecord.MISSING && (max_acceleration == AltosRecord.MISSING || acceleration > max_acceleration)) - max_acceleration = acceleration; - if (boost && accel_speed != AltosRecord.MISSING && accel_speed > max_accel_speed) - max_accel_speed = accel_speed; - if (boost && baro_speed != AltosRecord.MISSING && baro_speed > max_baro_speed) - max_baro_speed = baro_speed; - - if (height != AltosRecord.MISSING && height > max_height) - max_height = height; - elevation = 0; - range = -1; - gps_height = 0; - if (data.gps != null) { - gps = data.gps; - if (ngps > 0 && gps.locked) { - double h = height; - - if (h == AltosRecord.MISSING) h = 0; - from_pad = new AltosGreatCircle(pad_lat, pad_lon, 0, gps.lat, gps.lon, h); - elevation = from_pad.elevation; - range = from_pad.range; - gps_height = gps.alt - pad_alt; - } - } } public AltosState clone() { - AltosState s = new AltosState(data, this); + AltosState s = new AltosState(); + s.copy(this); return s; } @@ -638,4 +745,8 @@ public class AltosState implements Cloneable { public AltosState (AltosRecord cur, AltosState prev) { init(cur, prev); } + + public AltosState () { + init(); + } } diff --git a/altoslib/AltosStateIterable.java b/altoslib/AltosStateIterable.java new file mode 100644 index 00000000..db4a2568 --- /dev/null +++ b/altoslib/AltosStateIterable.java @@ -0,0 +1,29 @@ +/* + * Copyright © 2013 Keith Packard + * + * 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_1; + +import java.io.*; +import java.util.*; + +public abstract class AltosStateIterable implements Iterable { + + public void write_comments (PrintStream out) { + } + + public abstract void write(PrintStream out); +} diff --git a/altoslib/AltosTelemetryReader.java b/altoslib/AltosTelemetryReader.java index b4293c73..3915927c 100644 --- a/altoslib/AltosTelemetryReader.java +++ b/altoslib/AltosTelemetryReader.java @@ -27,16 +27,18 @@ public class AltosTelemetryReader extends AltosFlightReader { AltosRecord previous; double frequency; int telemetry; + AltosState state = null; LinkedBlockingQueue telem; - public AltosRecord read() throws InterruptedException, ParseException, AltosCRCException, IOException { + public AltosState read() throws InterruptedException, ParseException, AltosCRCException, IOException { AltosLine l = telem.take(); if (l.line == null) throw new IOException("IO error"); AltosRecord next = AltosTelemetry.parse(l.line, previous); previous = next; - return next; + state = new AltosState (next, state); + return state; } public void flush() { diff --git a/altoslib/Makefile.am b/altoslib/Makefile.am index 8a41b90c..bbcca906 100644 --- a/altoslib/Makefile.am +++ b/altoslib/Makefile.am @@ -20,6 +20,7 @@ altoslib_JAVA = \ AltosEeprom.java \ AltosEepromChunk.java \ AltosEepromFile.java \ + AltosEepromTM.java \ AltosEepromHeader.java \ AltosEepromIterable.java \ AltosEepromLog.java \ @@ -28,7 +29,6 @@ altoslib_JAVA = \ AltosEepromRecord.java \ AltosEepromTeleScience.java \ AltosEepromMini.java \ - AltosEepromMiniIterable.java \ AltosEepromOldIterable.java \ AltosFile.java \ AltosFlash.java \ @@ -69,6 +69,7 @@ altoslib_JAVA = \ AltosSensorMM.java \ AltosSensorTM.java \ AltosState.java \ + AltosStateIterable.java \ AltosStateUpdate.java \ AltosTelemetry.java \ AltosTelemetryIterable.java \ diff --git a/altosui/AltosAscent.java b/altosui/AltosAscent.java index 4da4d591..f8435037 100644 --- a/altosui/AltosAscent.java +++ b/altosui/AltosAscent.java @@ -251,10 +251,7 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay { class Speed extends AscentValueHold { void show (AltosState state, AltosListenerState listener_state) { - double speed = state.accel_speed; - if (!state.ascent) - speed = state.baro_speed; - show(AltosConvert.speed, speed); + show(AltosConvert.speed, state.speed); } public Speed (GridBagLayout layout, int y) { super (layout, y, "Speed"); @@ -287,8 +284,8 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay { class Apogee extends AscentStatus { void show (AltosState state, AltosListenerState listener_state) { - show("%4.2f V", state.drogue_sense); - lights.set(state.drogue_sense > 3.2); + show("%4.2f V", state.apogee_voltage); + lights.set(state.apogee_voltage > 3.7); } public Apogee (GridBagLayout layout, int y) { super(layout, y, "Apogee Igniter Voltage"); @@ -299,8 +296,8 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay { class Main extends AscentStatus { void show (AltosState state, AltosListenerState listener_state) { - show("%4.2f V", state.main_sense); - lights.set(state.main_sense > 3.2); + show("%4.2f V", state.main_voltage); + lights.set(state.main_voltage > 3.7); } public Main (GridBagLayout layout, int y) { super(layout, y, "Main Igniter Voltage"); @@ -368,11 +365,11 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay { lon.hide(); } height.show(state, listener_state); - if (state.main_sense != AltosRecord.MISSING) + if (state.main_voltage != AltosRecord.MISSING) main.show(state, listener_state); else main.hide(); - if (state.drogue_sense != AltosRecord.MISSING) + if (state.apogee_voltage != AltosRecord.MISSING) apogee.show(state, listener_state); else apogee.hide(); diff --git a/altosui/AltosCSV.java b/altosui/AltosCSV.java index 0676f99d..0b5a74e9 100644 --- a/altosui/AltosCSV.java +++ b/altosui/AltosCSV.java @@ -27,7 +27,7 @@ public class AltosCSV implements AltosWriter { boolean header_written; boolean seen_boost; int boost_tick; - LinkedList pad_records; + LinkedList pad_states; AltosState state; static final int ALTOS_CSV_VERSION = 5; @@ -105,47 +105,47 @@ public class AltosCSV implements AltosWriter { out.printf("version,serial,flight,call,time,clock,rssi,lqi"); } - void write_general(AltosRecord record) { + void write_general(AltosState state) { out.printf("%s, %d, %d, %s, %8.2f, %8.2f, %4d, %3d", - ALTOS_CSV_VERSION, record.serial, record.flight, record.callsign, - (double) record.time, (double) record.tick / 100.0, - record.rssi, - record.status & 0x7f); + ALTOS_CSV_VERSION, state.serial, state.flight, state.callsign, + (double) state.time, (double) state.tick / 100.0, + state.rssi, + state.status & 0x7f); } void write_flight_header() { out.printf("state,state_name"); } - void write_flight(AltosRecord record) { - out.printf("%d,%8s", record.state, record.state()); + void write_flight(AltosState state) { + out.printf("%d,%8s", state.state, state.state_name()); } void write_basic_header() { out.printf("acceleration,pressure,altitude,height,accel_speed,baro_speed,temperature,battery_voltage,drogue_voltage,main_voltage"); } - void write_basic(AltosRecord record) { + void write_basic(AltosState state) { out.printf("%8.2f,%10.2f,%8.2f,%8.2f,%8.2f,%8.2f,%5.1f,%5.2f,%5.2f,%5.2f", - record.acceleration(), - record.pressure(), - record.altitude(), - record.height(), - state.accel_speed, - state.baro_speed, - record.temperature(), - record.battery_voltage(), - record.drogue_voltage(), - record.main_voltage()); + state.acceleration, + state.pressure, + state.altitude, + state.height, + state.speed, + state.speed, + state.temperature, + state.battery_voltage, + state.apogee_voltage, + state.main_voltage); } void write_advanced_header() { out.printf("accel_x,accel_y,accel_z,gyro_x,gyro_y,gyro_z"); } - void write_advanced(AltosRecord record) { - AltosIMU imu = record.imu(); - AltosMag mag = record.mag(); + void write_advanced(AltosState state) { + AltosIMU imu = state.imu; + AltosMag mag = state.mag; if (imu == null) imu = new AltosIMU(); @@ -161,8 +161,8 @@ public class AltosCSV implements AltosWriter { out.printf("connected,locked,nsat,latitude,longitude,altitude,year,month,day,hour,minute,second,pad_dist,pad_range,pad_az,pad_el,hdop"); } - void write_gps(AltosRecord record) { - AltosGPS gps = record.gps; + void write_gps(AltosState state) { + AltosGPS gps = state.gps; if (gps == null) gps = new AltosGPS(); @@ -198,8 +198,8 @@ public class AltosCSV implements AltosWriter { } } - void write_gps_sat(AltosRecord record) { - AltosGPS gps = record.gps; + void write_gps_sat(AltosState state) { + AltosGPS gps = state.gps; for(int i = 1; i <= 32; i++) { int c_n0 = 0; if (gps != null && gps.cc_gps_sat != null) { @@ -221,8 +221,8 @@ public class AltosCSV implements AltosWriter { out.printf(",companion_%02d", i); } - void write_companion(AltosRecord record) { - AltosRecordCompanion companion = record.companion; + void write_companion(AltosState state) { + AltosRecordCompanion companion = state.companion; int channels_written = 0; if (companion == null) { @@ -256,50 +256,49 @@ public class AltosCSV implements AltosWriter { out.printf ("\n"); } - void write_one(AltosRecord record) { - state = new AltosState(record, state); - write_general(record); out.printf(","); - write_flight(record); out.printf(","); - write_basic(record); out.printf(","); - if (record.imu() != null || record.mag() != null) - write_advanced(record); - if (record.gps != null) { + void write_one(AltosState state) { + write_general(state); out.printf(","); + write_flight(state); out.printf(","); + write_basic(state); out.printf(","); + if (state.imu != null || state.mag != null) + write_advanced(state); + if (state.gps != null) { out.printf(","); - write_gps(record); out.printf(","); - write_gps_sat(record); + write_gps(state); out.printf(","); + write_gps_sat(state); } - if (record.companion != null) { + if (state.companion != null) { out.printf(","); - write_companion(record); + write_companion(state); } out.printf ("\n"); } void flush_pad() { - while (!pad_records.isEmpty()) { - write_one (pad_records.remove()); + while (!pad_states.isEmpty()) { + write_one (pad_states.remove()); } } - public void write(AltosRecord record) { - if (record.state == Altos.ao_flight_startup) + public void write(AltosState state) { + if (state.state == Altos.ao_flight_startup) return; if (!header_written) { - write_header(record.imu() != null || record.mag() != null, - record.gps != null, record.companion != null); + write_header(state.imu != null || state.mag != null, + state.gps != null, state.companion != null); header_written = true; } if (!seen_boost) { - if (record.state >= Altos.ao_flight_boost) { + if (state.state >= Altos.ao_flight_boost) { seen_boost = true; - boost_tick = record.tick; + boost_tick = state.tick; flush_pad(); } } if (seen_boost) - write_one(record); + write_one(state); else - pad_records.add(record); + pad_states.add(state); } public PrintStream out() { @@ -307,23 +306,23 @@ public class AltosCSV implements AltosWriter { } public void close() { - if (!pad_records.isEmpty()) { - boost_tick = pad_records.element().tick; + if (!pad_states.isEmpty()) { + boost_tick = pad_states.element().tick; flush_pad(); } out.close(); } - public void write(AltosRecordIterable iterable) { - iterable.write_comments(out()); - for (AltosRecord r : iterable) - write(r); + public void write(AltosStateIterable states) { + states.write_comments(out()); + for (AltosState state : states) + write(state); } public AltosCSV(PrintStream in_out, File in_name) { name = in_name; out = in_out; - pad_records = new LinkedList(); + pad_states = new LinkedList(); } public AltosCSV(File in_name) throws FileNotFoundException { diff --git a/altosui/AltosCSVUI.java b/altosui/AltosCSVUI.java index 42508346..4b48bdf6 100644 --- a/altosui/AltosCSVUI.java +++ b/altosui/AltosCSVUI.java @@ -31,7 +31,7 @@ public class AltosCSVUI JFileChooser csv_chooser; JPanel accessory; JComboBox combo_box; - AltosRecordIterable iterable; + Iterable states; AltosWriter writer; static String[] combo_box_items = { "Comma Separated Values (.CSV)", "Googleearth Data (.KML)" }; @@ -55,8 +55,8 @@ public class AltosCSVUI set_default_file(); } - public AltosCSVUI(JFrame frame, AltosRecordIterable in_iterable, File source_file) { - iterable = in_iterable; + public AltosCSVUI(JFrame frame, AltosStateIterable states, File source_file) { + this.states = states; csv_chooser = new JFileChooser(source_file); accessory = new JPanel(); @@ -91,7 +91,7 @@ public class AltosCSVUI writer = new AltosCSV(file); else writer = new AltosKML(file); - writer.write(iterable); + writer.write(states); writer.close(); } catch (FileNotFoundException ee) { JOptionPane.showMessageDialog(frame, diff --git a/altosui/AltosCompanionInfo.java b/altosui/AltosCompanionInfo.java index ebe1d1f9..1ed2c425 100644 --- a/altosui/AltosCompanionInfo.java +++ b/altosui/AltosCompanionInfo.java @@ -86,8 +86,8 @@ public class AltosCompanionInfo extends JTable { public void show(AltosState state, AltosListenerState listener_state) { if (state == null) return; - if (state.data.companion != null) - companion = state.data.companion; + if (state.companion != null) + companion = state.companion; info_reset(); info_add_row(0, "Companion board", "%s", board_name()); if (companion != null) { diff --git a/altosui/AltosDataChooser.java b/altosui/AltosDataChooser.java index c7b561d5..af6c245b 100644 --- a/altosui/AltosDataChooser.java +++ b/altosui/AltosDataChooser.java @@ -36,7 +36,7 @@ public class AltosDataChooser extends JFileChooser { return file; } - public AltosRecordIterable runDialog() { + public AltosStateIterable runDialog() { int ret; ret = showOpenDialog(frame); @@ -48,16 +48,10 @@ public class AltosDataChooser extends JFileChooser { try { if (filename.endsWith("eeprom")) { FileInputStream in = new FileInputStream(file); - return new AltosEepromIterable(in); + return new AltosEepromFile(in); } else if (filename.endsWith("telem")) { FileInputStream in = new FileInputStream(file); - return new AltosTelemetryIterable(in); - } else if (filename.endsWith("mega")) { - FileInputStream in = new FileInputStream(file); - return new AltosEepromMegaIterable(in); - } else if (filename.endsWith("mini")) { - FileInputStream in = new FileInputStream(file); - return new AltosEepromMiniIterable(in); + return null; // new AltosTelemetryIterable(in); } else { throw new FileNotFoundException(); } diff --git a/altosui/AltosDescent.java b/altosui/AltosDescent.java index 29d33ddc..2b6575cb 100644 --- a/altosui/AltosDescent.java +++ b/altosui/AltosDescent.java @@ -256,10 +256,7 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay { class Speed extends DescentValue { void show (AltosState state, AltosListenerState listener_state) { - double speed = state.accel_speed; - if (!state.ascent) - speed = state.baro_speed; - show(AltosConvert.speed, speed); + show(AltosConvert.speed, state.speed); } public Speed (GridBagLayout layout, int x, int y) { super (layout, x, y, "Speed"); @@ -325,8 +322,8 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay { class Apogee extends DescentStatus { void show (AltosState state, AltosListenerState listener_state) { - show("%4.2f V", state.drogue_sense); - lights.set(state.drogue_sense > 3.2); + show("%4.2f V", state.apogee_voltage); + lights.set(state.apogee_voltage > 3.7); } public Apogee (GridBagLayout layout, int y) { super(layout, y, "Apogee Igniter Voltage"); @@ -337,8 +334,8 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay { class Main extends DescentStatus { void show (AltosState state, AltosListenerState listener_state) { - show("%4.2f V", state.main_sense); - lights.set(state.main_sense > 3.2); + show("%4.2f V", state.main_voltage); + lights.set(state.main_voltage > 3.7); } public Main (GridBagLayout layout, int y) { super(layout, y, "Main Igniter Voltage"); @@ -430,11 +427,11 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay { lat.hide(); lon.hide(); } - if (state.main_sense != AltosRecord.MISSING) + if (state.main_voltage != AltosRecord.MISSING) main.show(state, listener_state); else main.hide(); - if (state.drogue_sense != AltosRecord.MISSING) + if (state.apogee_voltage != AltosRecord.MISSING) apogee.show(state, listener_state); else apogee.hide(); diff --git a/altosui/AltosDisplayThread.java b/altosui/AltosDisplayThread.java index 095bed99..70144fb2 100644 --- a/altosui/AltosDisplayThread.java +++ b/altosui/AltosDisplayThread.java @@ -113,7 +113,7 @@ public class AltosDisplayThread extends Thread { System.currentTimeMillis() - state.report_time >= 15000 || state.state == Altos.ao_flight_landed)) { - if (Math.abs(state.baro_speed) < 20 && state.height < 100) + if (Math.abs(state.speed) < 20 && state.height < 100) voice.speak("rocket landed safely"); else voice.speak("rocket may have crashed"); @@ -181,11 +181,11 @@ public class AltosDisplayThread extends Thread { synchronized boolean tell() { boolean ret = false; if (old_state == null || old_state.state != state.state) { - voice.speak(state.data.state()); + voice.speak(state.state_name()); if ((old_state == null || old_state.state <= Altos.ao_flight_boost) && state.state > Altos.ao_flight_boost) { voice.speak("max speed: %s.", - AltosConvert.speed.say_units(state.max_accel_speed + 0.5)); + AltosConvert.speed.say_units(state.max_speed + 0.5)); ret = true; } else if ((old_state == null || old_state.state < Altos.ao_flight_drogue) && state.state >= Altos.ao_flight_drogue) { @@ -218,11 +218,9 @@ public class AltosDisplayThread extends Thread { try { for (;;) { try { - AltosRecord record = reader.read(); - if (record == null) + state = reader.read(); + if (state == null) break; - old_state = state; - state = new AltosState(record, state); reader.update(state); show_safely(); told = tell(); diff --git a/altosui/AltosEepromDownload.java b/altosui/AltosEepromDownload.java index 46715db6..95b17e2a 100644 --- a/altosui/AltosEepromDownload.java +++ b/altosui/AltosEepromDownload.java @@ -418,8 +418,9 @@ public class AltosEepromDownload implements Runnable { extension = "mega"; CaptureMega(eechunk); break; - case AltosLib.AO_LOG_FORMAT_MINI: - extension = "mini"; + case AltosLib.AO_LOG_FORMAT_EASYMINI: + case AltosLib.AO_LOG_FORMAT_TELEMINI: + extension = "eeprom"; CaptureMini(eechunk); break; } diff --git a/altosui/AltosFlightStats.java b/altosui/AltosFlightStats.java index dee31a8d..50deb6c8 100644 --- a/altosui/AltosFlightStats.java +++ b/altosui/AltosFlightStats.java @@ -24,8 +24,7 @@ public class AltosFlightStats { double max_height; double max_speed; double max_acceleration; - double[] state_accel_speed = new double[Altos.ao_flight_invalid + 1]; - double[] state_baro_speed = new double[Altos.ao_flight_invalid + 1]; + double[] state_speed = new double[Altos.ao_flight_invalid + 1]; double[] state_accel = new double[Altos.ao_flight_invalid + 1]; int[] state_count = new int[Altos.ao_flight_invalid + 1]; double[] state_start = new double[Altos.ao_flight_invalid + 1]; @@ -40,15 +39,18 @@ public class AltosFlightStats { boolean has_other_adc; boolean has_rssi; - double landed_time(AltosRecordIterable iterable) { - AltosState state = null; - for (AltosRecord record : iterable) { - state = new AltosState(record, state); + double landed_time(AltosStateIterable states) { + AltosState state = null; + for (AltosState s : states) { + state = s; if (state.state == Altos.ao_flight_landed) break; } + if (state == null) + return 0; + double landed_height = state.height; state = null; @@ -57,8 +59,8 @@ public class AltosFlightStats { double landed_time = -1000; - for (AltosRecord record : iterable) { - state = new AltosState(record, state); + for (AltosState s : states) { + state = s; if (state.height > landed_height + 10) { above = true; @@ -74,80 +76,70 @@ public class AltosFlightStats { return landed_time; } - double boost_time(AltosRecordIterable iterable) { - double boost_time = -1000; - - AltosState state = null; + double boost_time(AltosStateIterable states) { + double boost_time = AltosRecord.MISSING; + AltosState state = null; - for (AltosRecord record : iterable) { - state = new AltosState(record, state); - + for (AltosState s : states) { + state = s; if (state.acceleration < 1) boost_time = state.time; if (state.state >= Altos.ao_flight_boost) break; } - if (boost_time == -1000) + if (state == null) + return 0; + + if (boost_time == AltosRecord.MISSING) boost_time = state.time; return boost_time; } - public AltosFlightStats(AltosRecordIterable iterable) throws InterruptedException, IOException { - AltosState state = null; - AltosState new_state = null; - double boost_time = boost_time(iterable); + public AltosFlightStats(AltosStateIterable states) throws InterruptedException, IOException { + double boost_time = boost_time(states); double end_time = 0; - double landed_time = landed_time(iterable); + double landed_time = landed_time(states); - year = month = day = -1; - hour = minute = second = -1; - serial = flight = -1; - lat = lon = -1; + year = month = day = AltosRecord.MISSING; + hour = minute = second = AltosRecord.MISSING; + serial = flight = AltosRecord.MISSING; + lat = lon = AltosRecord.MISSING; has_gps = false; has_other_adc = false; has_rssi = false; - for (AltosRecord record : iterable) { - if (serial < 0) - serial = record.serial; - if ((record.seen & AltosRecord.seen_flight) != 0 && flight < 0) - flight = record.flight; - if ((record.seen & AltosRecord.seen_temp_volt) != 0) + for (AltosState state : states) { + if (serial == AltosRecord.MISSING && state.serial != AltosRecord.MISSING) + serial = state.serial; + if (flight == AltosRecord.MISSING && state.flight != AltosRecord.MISSING) + flight = state.flight; + if (state.battery_voltage != AltosRecord.MISSING) has_other_adc = true; - if (record.rssi != 0) + if (state.rssi != AltosRecord.MISSING) has_rssi = true; - new_state = new AltosState(record, state); - end_time = new_state.time; - state = new_state; + end_time = state.time; if (state.time >= boost_time && state.state < Altos.ao_flight_boost) state.state = Altos.ao_flight_boost; if (state.time >= landed_time && state.state < Altos.ao_flight_landed) state.state = Altos.ao_flight_landed; + if (state.gps != null && state.gps.locked) { + year = state.gps.year; + month = state.gps.month; + day = state.gps.day; + hour = state.gps.hour; + minute = state.gps.minute; + second = state.gps.second; + } if (0 <= state.state && state.state < Altos.ao_flight_invalid) { - if (state.state >= Altos.ao_flight_boost) { - if (state.gps != null && state.gps.locked && - year < 0) { - year = state.gps.year; - month = state.gps.month; - day = state.gps.day; - hour = state.gps.hour; - minute = state.gps.minute; - second = state.gps.second; - } - } state_accel[state.state] += state.acceleration; - state_accel_speed[state.state] += state.accel_speed; - state_baro_speed[state.state] += state.baro_speed; + state_speed[state.state] += state.speed; state_count[state.state]++; if (state_start[state.state] == 0.0) state_start[state.state] = state.time; if (state_end[state.state] < state.time) state_end[state.state] = state.time; max_height = state.max_height; - if (state.max_accel_speed != 0) - max_speed = state.max_accel_speed; - else - max_speed = state.max_baro_speed; + max_speed = state.max_speed; max_acceleration = state.max_acceleration; } if (state.gps != null && state.gps.locked && state.gps.nsat >= 4) { @@ -162,8 +154,7 @@ public class AltosFlightStats { } for (int s = Altos.ao_flight_startup; s <= Altos.ao_flight_landed; s++) { if (state_count[s] > 0) { - state_accel_speed[s] /= state_count[s]; - state_baro_speed[s] /= state_count[s]; + state_speed[s] /= state_count[s]; state_accel[s] /= state_count[s]; } if (state_start[s] == 0) diff --git a/altosui/AltosFlightStatsTable.java b/altosui/AltosFlightStatsTable.java index a35b5f63..f8a2d4de 100644 --- a/altosui/AltosFlightStatsTable.java +++ b/altosui/AltosFlightStatsTable.java @@ -106,11 +106,11 @@ public class AltosFlightStatsTable extends JComponent { String.format("%5.0f G", AltosConvert.meters_to_g(stats.state_accel[Altos.ao_flight_boost]))); } new FlightStat(layout, y++, "Drogue descent rate", - String.format("%5.0f m/s", stats.state_baro_speed[Altos.ao_flight_drogue]), - String.format("%5.0f ft/s", AltosConvert.meters_to_feet(stats.state_baro_speed[Altos.ao_flight_drogue]))); + String.format("%5.0f m/s", stats.state_speed[Altos.ao_flight_drogue]), + String.format("%5.0f ft/s", AltosConvert.meters_to_feet(stats.state_speed[Altos.ao_flight_drogue]))); new FlightStat(layout, y++, "Main descent rate", - String.format("%5.0f m/s", stats.state_baro_speed[Altos.ao_flight_main]), - String.format("%5.0f ft/s", AltosConvert.meters_to_feet(stats.state_baro_speed[Altos.ao_flight_main]))); + String.format("%5.0f m/s", stats.state_speed[Altos.ao_flight_main]), + String.format("%5.0f ft/s", AltosConvert.meters_to_feet(stats.state_speed[Altos.ao_flight_main]))); new FlightStat(layout, y++, "Ascent time", String.format("%6.1f s %s", stats.state_end[AltosLib.ao_flight_boost] - stats.state_start[AltosLib.ao_flight_boost], AltosLib.state_name(Altos.ao_flight_boost)), diff --git a/altosui/AltosFlightStatus.java b/altosui/AltosFlightStatus.java index d2910414..0be7bb51 100644 --- a/altosui/AltosFlightStatus.java +++ b/altosui/AltosFlightStatus.java @@ -65,7 +65,7 @@ public class AltosFlightStatus extends JComponent implements AltosFlightDisplay class Call extends FlightValue { void show(AltosState state, AltosListenerState listener_state) { - value.setText(state.data.callsign); + value.setText(state.callsign); } public Call (GridBagLayout layout, int x) { super (layout, x, "Callsign"); @@ -76,10 +76,10 @@ public class AltosFlightStatus extends JComponent implements AltosFlightDisplay class Serial extends FlightValue { void show(AltosState state, AltosListenerState listener_state) { - if (state.data.serial == AltosRecord.MISSING) + if (state.serial == AltosRecord.MISSING) value.setText("none"); else - value.setText(String.format("%d", state.data.serial)); + value.setText(String.format("%d", state.serial)); } public Serial (GridBagLayout layout, int x) { super (layout, x, "Serial"); @@ -90,10 +90,10 @@ public class AltosFlightStatus extends JComponent implements AltosFlightDisplay class Flight extends FlightValue { void show(AltosState state, AltosListenerState listener_state) { - if (state.data.flight == AltosRecord.MISSING) + if (state.flight == AltosRecord.MISSING) value.setText("none"); else - value.setText(String.format("%d", state.data.flight)); + value.setText(String.format("%d", state.flight)); } public Flight (GridBagLayout layout, int x) { super (layout, x, "Flight"); @@ -104,7 +104,7 @@ public class AltosFlightStatus extends JComponent implements AltosFlightDisplay class FlightState extends FlightValue { void show(AltosState state, AltosListenerState listener_state) { - value.setText(state.data.state()); + value.setText(state.state_name()); } public FlightState (GridBagLayout layout, int x) { super (layout, x, "State"); @@ -115,7 +115,7 @@ public class AltosFlightStatus extends JComponent implements AltosFlightDisplay class RSSI extends FlightValue { void show(AltosState state, AltosListenerState listener_state) { - value.setText(String.format("%d", state.data.rssi)); + value.setText(String.format("%d", state.rssi())); } public RSSI (GridBagLayout layout, int x) { super (layout, x, "RSSI"); diff --git a/altosui/AltosFlightUI.java b/altosui/AltosFlightUI.java index 6d010d23..423cf10c 100644 --- a/altosui/AltosFlightUI.java +++ b/altosui/AltosFlightUI.java @@ -130,7 +130,7 @@ public class AltosFlightUI extends AltosUIFrame implements AltosFlightDisplay, A flightStatus.show(state, listener_state); flightInfo.show(state, listener_state); - if (state.data.companion != null) { + if (state.companion != null) { if (!has_companion) { pane.add("Companion", companion); has_companion= true; diff --git a/altosui/AltosGraphDataPoint.java b/altosui/AltosGraphDataPoint.java index 7454f447..537efc44 100644 --- a/altosui/AltosGraphDataPoint.java +++ b/altosui/AltosGraphDataPoint.java @@ -42,9 +42,10 @@ public class AltosGraphDataPoint implements AltosUIDataPoint { public static final int data_pressure = 15; public double x() throws AltosUIDataMissing { - if (state.data.time < -2) + double time = state.time_since_boost(); + if (time < -2) throw new AltosUIDataMissing(-1); - return state.data.time; + return time; } public double y(int index) throws AltosUIDataMissing { @@ -63,16 +64,16 @@ public class AltosGraphDataPoint implements AltosUIDataPoint { y = state.temperature; break; case data_battery_voltage: - y = state.battery; + y = state.battery_voltage; break; case data_drogue_voltage: - y = state.drogue_sense; + y = state.apogee_voltage; break; case data_main_voltage: - y = state.main_sense; + y = state.main_voltage; break; case data_rssi: - y = state.data.rssi; + y = state.rssi; break; case data_gps_height: y = state.gps_height; @@ -106,7 +107,7 @@ public class AltosGraphDataPoint implements AltosUIDataPoint { public int id(int index) { if (index == data_state) { - int s = state.data.state; + int s = state.state; if (s < Altos.ao_flight_boost || s > Altos.ao_flight_landed) return -1; return s; @@ -116,7 +117,7 @@ public class AltosGraphDataPoint implements AltosUIDataPoint { public String id_name(int index) { if (index == data_state) - return state.data.state(); + return state.state_name(); return ""; } diff --git a/altosui/AltosGraphDataSet.java b/altosui/AltosGraphDataSet.java index dc047e9a..1e469c8a 100644 --- a/altosui/AltosGraphDataSet.java +++ b/altosui/AltosGraphDataSet.java @@ -25,34 +25,31 @@ import org.altusmetrum.altosuilib_1.*; class AltosGraphIterator implements Iterator { AltosGraphDataSet dataSet; - Iterator iterator; - - AltosState state; + Iterator iterator; public boolean hasNext() { return iterator.hasNext(); } public AltosUIDataPoint next() { - state = new AltosState(iterator.next(), state); + AltosState state = iterator.next(); - if ((state.data.seen & AltosRecord.seen_flight) != 0) { - if (dataSet.callsign == null && state.data.callsign != null) - dataSet.callsign = state.data.callsign; + if (state.flight != AltosRecord.MISSING) { + if (dataSet.callsign == null && state.callsign != null) + dataSet.callsign = state.callsign; - if (dataSet.serial == 0 && state.data.serial != 0) - dataSet.serial = state.data.serial; + if (dataSet.serial == 0 && state.serial != 0) + dataSet.serial = state.serial; - if (dataSet.flight == 0 && state.data.flight != 0) - dataSet.flight = state.data.flight; + if (dataSet.flight == 0 && state.flight != 0) + dataSet.flight = state.flight; } return new AltosGraphDataPoint(state); } - public AltosGraphIterator (Iterator iterator, AltosGraphDataSet dataSet) { + public AltosGraphIterator (Iterator iterator, AltosGraphDataSet dataSet) { this.iterator = iterator; - this.state = null; this.dataSet = dataSet; } @@ -64,7 +61,7 @@ class AltosGraphIterable implements Iterable { AltosGraphDataSet dataSet; public Iterator iterator() { - return new AltosGraphIterator(dataSet.records.iterator(), dataSet); + return new AltosGraphIterator(dataSet.states.iterator(), dataSet); } public AltosGraphIterable(AltosGraphDataSet dataSet) { @@ -76,7 +73,7 @@ public class AltosGraphDataSet implements AltosUIDataSet { String callsign; int serial; int flight; - AltosRecordIterable records; + AltosStateIterable states; public String name() { if (callsign != null) @@ -89,8 +86,8 @@ public class AltosGraphDataSet implements AltosUIDataSet { return new AltosGraphIterable(this); } - public AltosGraphDataSet (AltosRecordIterable records) { - this.records = records; + public AltosGraphDataSet (AltosStateIterable states) { + this.states = states; this.callsign = null; this.serial = 0; this.flight = 0; diff --git a/altosui/AltosGraphUI.java b/altosui/AltosGraphUI.java index d8b8f6dd..376e9910 100644 --- a/altosui/AltosGraphUI.java +++ b/altosui/AltosGraphUI.java @@ -28,10 +28,9 @@ public class AltosGraphUI extends AltosUIFrame AltosFlightStatsTable statsTable; boolean has_gps; - void fill_map(AltosRecordIterable records) { + void fill_map(AltosStateIterable states) { boolean any_gps = false; - for (AltosRecord record : records) { - state = new AltosState(record, state); + for (AltosState state : states) { if (state.gps != null && state.gps.locked && state.gps.nsat >= 4) { if (map == null) map = new AltosSiteMap(); @@ -41,7 +40,7 @@ public class AltosGraphUI extends AltosUIFrame } } - AltosGraphUI(AltosRecordIterable records, File file) throws InterruptedException, IOException { + AltosGraphUI(AltosStateIterable states, File file) throws InterruptedException, IOException { super(file.getName()); state = null; @@ -49,8 +48,8 @@ public class AltosGraphUI extends AltosUIFrame enable = new AltosUIEnable(); - stats = new AltosFlightStats(records); - graphDataSet = new AltosGraphDataSet(records); + stats = new AltosFlightStats(states); + graphDataSet = new AltosGraphDataSet(states); graph = new AltosGraph(enable, stats, graphDataSet); @@ -61,7 +60,7 @@ public class AltosGraphUI extends AltosUIFrame pane.add("Flight Statistics", statsTable); has_gps = false; - fill_map(records); + fill_map(states); if (has_gps) pane.add("Map", map); diff --git a/altosui/AltosInfoTable.java b/altosui/AltosInfoTable.java index 3d16faf2..8601d76f 100644 --- a/altosui/AltosInfoTable.java +++ b/altosui/AltosInfoTable.java @@ -122,15 +122,15 @@ public class AltosInfoTable extends JTable { if (state.speed() != AltosRecord.MISSING) info_add_row(0, "Speed", "%8.1f m/s", state.speed()); if (state.speed() != AltosRecord.MISSING) - info_add_row(0, "Max Speed", "%8.1f m/s", state.max_accel_speed); + info_add_row(0, "Max Speed", "%8.1f m/s", state.max_speed); if (state.temperature != AltosRecord.MISSING) info_add_row(0, "Temperature", "%9.2f °C", state.temperature); - if (state.battery != AltosRecord.MISSING) - info_add_row(0, "Battery", "%9.2f V", state.battery); - if (state.drogue_sense != AltosRecord.MISSING) - info_add_row(0, "Drogue", "%9.2f V", state.drogue_sense); - if (state.main_sense != AltosRecord.MISSING) - info_add_row(0, "Main", "%9.2f V", state.main_sense); + if (state.battery_voltage != AltosRecord.MISSING) + info_add_row(0, "Battery", "%9.2f V", state.battery_voltage); + if (state.apogee_voltage != AltosRecord.MISSING) + info_add_row(0, "Drogue", "%9.2f V", state.apogee_voltage); + if (state.main_voltage != AltosRecord.MISSING) + info_add_row(0, "Main", "%9.2f V", state.main_voltage); } if (listener_state != null) { info_add_row(0, "CRC Errors", "%6d", listener_state.crc_errors); @@ -148,13 +148,13 @@ public class AltosInfoTable extends JTable { else info_add_row(1, "GPS state", "wait (%d)", state.gps_waiting); - if (state.data.gps.locked) + if (state.gps.locked) info_add_row(1, "GPS", " locked"); - else if (state.data.gps.connected) + else if (state.gps.connected) info_add_row(1, "GPS", " unlocked"); else info_add_row(1, "GPS", " missing"); - info_add_row(1, "Satellites", "%6d", state.data.gps.nsat); + info_add_row(1, "Satellites", "%6d", state.gps.nsat); info_add_deg(1, "Latitude", state.gps.lat, 'N', 'S'); info_add_deg(1, "Longitude", state.gps.lon, 'E', 'W'); info_add_row(1, "GPS altitude", "%6d", state.gps.alt); diff --git a/altosui/AltosKML.java b/altosui/AltosKML.java index 140f3f07..b79f5c9e 100644 --- a/altosui/AltosKML.java +++ b/altosui/AltosKML.java @@ -24,8 +24,8 @@ public class AltosKML implements AltosWriter { File name; PrintStream out; - int state = -1; - AltosRecord prev = null; + int flight_state = -1; + AltosState prev = null; double gps_start_altitude; static final String[] kml_state_colors = { @@ -83,7 +83,7 @@ public class AltosKML implements AltosWriter { "\n" + "\n"; - void start (AltosRecord record) { + void start (AltosState record) { out.printf(kml_header_start, record.flight, record.serial); out.printf("Date: %04d-%02d-%02d\n", record.gps.year, record.gps.month, record.gps.day); @@ -94,30 +94,30 @@ public class AltosKML implements AltosWriter { boolean started = false; - void state_start(AltosRecord record) { - String state_name = Altos.state_name(record.state); - out.printf(kml_style_start, state_name, kml_state_colors[record.state]); + void state_start(AltosState state) { + String state_name = Altos.state_name(state.state); + out.printf(kml_style_start, state_name, kml_state_colors[state.state]); out.printf("\tState: %s\n", state_name); out.printf("%s", kml_style_end); out.printf(kml_placemark_start, state_name, state_name); } - void state_end(AltosRecord record) { + void state_end(AltosState state) { out.printf("%s", kml_placemark_end); } - void coord(AltosRecord record) { - AltosGPS gps = record.gps; + void coord(AltosState state) { + AltosGPS gps = state.gps; double altitude; - if (record.height() != AltosRecord.MISSING) - altitude = record.height() + gps_start_altitude; + if (state.height != AltosRecord.MISSING) + altitude = state.height + gps_start_altitude; else altitude = gps.alt; out.printf(kml_coord_fmt, gps.lon, gps.lat, altitude, (double) gps.alt, - record.time, gps.nsat); + state.time, gps.nsat); } void end() { @@ -132,38 +132,40 @@ public class AltosKML implements AltosWriter { } } - public void write(AltosRecord record) { - AltosGPS gps = record.gps; + public void write(AltosState state) { + AltosGPS gps = state.gps; if (gps == null) return; - if ((record.seen & (AltosRecord.seen_gps_lat)) == 0) + if (gps.lat == AltosRecord.MISSING) return; - if ((record.seen & (AltosRecord.seen_gps_lon)) == 0) + if (gps.lon == AltosRecord.MISSING) return; if (!started) { - start(record); + start(state); started = true; gps_start_altitude = gps.alt; } - if (prev != null && prev.gps_sequence == record.gps_sequence) + if (prev != null && prev.gps_sequence == state.gps_sequence) return; - if (record.state != state) { - state = record.state; + if (state.state != flight_state) { + flight_state = state.state; if (prev != null) { - coord(record); + coord(state); state_end(prev); } - state_start(record); + state_start(state); } - coord(record); - prev = record; + coord(state); + prev = state; } - public void write(AltosRecordIterable iterable) { - for (AltosRecord record : iterable) - write(record); + public void write(AltosStateIterable states) { + for (AltosState state : states) { + if ((state.set & AltosState.set_gps) != 0) + write(state); + } } public AltosKML(File in_name) throws FileNotFoundException { diff --git a/altosui/AltosLanded.java b/altosui/AltosLanded.java index 9dab52c4..38f273cf 100644 --- a/altosui/AltosLanded.java +++ b/altosui/AltosLanded.java @@ -243,24 +243,18 @@ public class AltosLanded extends JComponent implements AltosFlightDisplay, Actio if (file != null) { String filename = file.getName(); try { - AltosRecordIterable records = null; + AltosStateIterable states = null; if (filename.endsWith("eeprom")) { FileInputStream in = new FileInputStream(file); - records = new AltosEepromIterable(in); + states = new AltosEepromFile(in); } else if (filename.endsWith("telem")) { FileInputStream in = new FileInputStream(file); - records = new AltosTelemetryIterable(in); - } else if (filename.endsWith("mega")) { - FileInputStream in = new FileInputStream(file); - records = new AltosEepromMegaIterable(in); - } else if (filename.endsWith("mini")) { - FileInputStream in = new FileInputStream(file); - records = new AltosEepromMiniIterable(in); + states = null; // new AltosTelemetryIterable(in); } else { throw new FileNotFoundException(filename); } try { - new AltosGraphUI(records, file); + new AltosGraphUI(states, file); } catch (InterruptedException ie) { } catch (IOException ie) { } diff --git a/altosui/AltosPad.java b/altosui/AltosPad.java index e2316a13..fed009cc 100644 --- a/altosui/AltosPad.java +++ b/altosui/AltosPad.java @@ -176,11 +176,11 @@ public class AltosPad extends JComponent implements AltosFlightDisplay { class Battery extends LaunchStatus { void show (AltosState state, AltosListenerState listener_state) { - if (state == null || state.battery == AltosRecord.MISSING) + if (state == null || state.battery_voltage == AltosRecord.MISSING) hide(); else { - show("%4.2f V", state.battery); - lights.set(state.battery > 3.7); + show("%4.2f V", state.battery_voltage); + lights.set(state.battery_voltage > 3.7); } } public Battery (GridBagLayout layout, int y) { @@ -192,11 +192,11 @@ public class AltosPad extends JComponent implements AltosFlightDisplay { class Apogee extends LaunchStatus { void show (AltosState state, AltosListenerState listener_state) { - if (state == null || state.drogue_sense == AltosRecord.MISSING) + if (state == null || state.apogee_voltage == AltosRecord.MISSING) hide(); else { - show("%4.2f V", state.drogue_sense); - lights.set(state.drogue_sense > 3.2); + show("%4.2f V", state.apogee_voltage); + lights.set(state.apogee_voltage > 3.7); } } public Apogee (GridBagLayout layout, int y) { @@ -208,11 +208,11 @@ public class AltosPad extends JComponent implements AltosFlightDisplay { class Main extends LaunchStatus { void show (AltosState state, AltosListenerState listener_state) { - if (state == null || state.main_sense == AltosRecord.MISSING) + if (state == null || state.main_voltage == AltosRecord.MISSING) hide(); else { - show("%4.2f V", state.main_sense); - lights.set(state.main_sense > 3.2); + show("%4.2f V", state.main_voltage); + lights.set(state.main_voltage > 3.7); } } public Main (GridBagLayout layout, int y) { @@ -224,19 +224,19 @@ public class AltosPad extends JComponent implements AltosFlightDisplay { class LoggingReady extends LaunchStatus { void show (AltosState state, AltosListenerState listener_state) { - if (state == null || state.data.flight == AltosRecord.MISSING) { + if (state == null || state.flight == AltosRecord.MISSING) { hide(); } else { - if (state.data.flight != 0) { - if (state.data.state <= Altos.ao_flight_pad) + if (state.flight != 0) { + if (state.state <= Altos.ao_flight_pad) show("Ready to record"); - else if (state.data.state < Altos.ao_flight_landed) + else if (state.state < Altos.ao_flight_landed) show("Recording data"); else show("Recorded data"); } else show("Storage full"); - lights.set(state.data.flight != 0); + lights.set(state.flight != 0); } } public LoggingReady (GridBagLayout layout, int y) { diff --git a/altosui/AltosScanUI.java b/altosui/AltosScanUI.java index 0c903873..224e1e61 100644 --- a/altosui/AltosScanUI.java +++ b/altosui/AltosScanUI.java @@ -184,13 +184,13 @@ public class AltosScanUI try { for (;;) { try { - AltosRecord record = reader.read(); - if (record == null) + AltosState state = reader.read(); + if (state == null) continue; - if ((record.seen & AltosRecord.seen_flight) != 0) { - final AltosScanResult result = new AltosScanResult(record.callsign, - record.serial, - record.flight, + if (state.flight != AltosRecord.MISSING) { + final AltosScanResult result = new AltosScanResult(state.callsign, + state.serial, + state.flight, frequencies[frequency_index], telemetry); Runnable r = new Runnable() { diff --git a/altosui/AltosSiteMap.java b/altosui/AltosSiteMap.java index 23085f3e..c0926919 100644 --- a/altosui/AltosSiteMap.java +++ b/altosui/AltosSiteMap.java @@ -271,27 +271,34 @@ public class AltosSiteMap extends JScrollPane implements AltosFlightDisplay { int last_state = -1; public void show(double lat, double lon) { - initMaps(lat, lon); - scrollRocketToVisible(pt(lat, lon)); + System.out.printf ("show %g %g\n", lat, lon); + return; +// initMaps(lat, lon); +// scrollRocketToVisible(pt(lat, lon)); } public void show(final AltosState state, final AltosListenerState listener_state) { // if insufficient gps data, nothing to update - if (!state.gps.locked && state.gps.nsat < 4) + AltosGPS gps = state.gps; + + if (gps == null) + return; + + if (!gps.locked && gps.nsat < 4) return; if (!initialised) { - if (state.pad_lat != 0 || state.pad_lon != 0) { + if (state.pad_lat != AltosRecord.MISSING && state.pad_lon != AltosRecord.MISSING) { initMaps(state.pad_lat, state.pad_lon); initialised = true; - } else if (state.gps.lat != 0 || state.gps.lon != 0) { - initMaps(state.gps.lat, state.gps.lon); + } else if (gps.lat != AltosRecord.MISSING && gps.lon != AltosRecord.MISSING) { + initMaps(gps.lat, gps.lon); initialised = true; } else { return; } } - final Point2D.Double pt = pt(state.gps.lat, state.gps.lon); + final Point2D.Double pt = pt(gps.lat, gps.lon); if (last_pt == pt && last_state == state.state) return; diff --git a/altosui/AltosUI.java b/altosui/AltosUI.java index 4362e36c..6d5ce185 100644 --- a/altosui/AltosUI.java +++ b/altosui/AltosUI.java @@ -290,9 +290,9 @@ public class AltosUI extends AltosUIFrame { AltosDataChooser chooser = new AltosDataChooser( AltosUI.this); - AltosRecordIterable iterable = chooser.runDialog(); - if (iterable != null) { - AltosFlightReader reader = new AltosReplayReader(iterable.iterator(), + Iterable states = chooser.runDialog(); + if (states != null) { + AltosFlightReader reader = new AltosReplayReader(states.iterator(), chooser.file()); new AltosFlightUI(voice, reader); } @@ -312,10 +312,10 @@ public class AltosUI extends AltosUIFrame { private void ExportData() { AltosDataChooser chooser; chooser = new AltosDataChooser(this); - AltosRecordIterable record_reader = chooser.runDialog(); - if (record_reader == null) + AltosStateIterable states = chooser.runDialog(); + if (states == null) return; - new AltosCSVUI(AltosUI.this, record_reader, chooser.file()); + new AltosCSVUI(AltosUI.this, states, chooser.file()); } /* Load a flight log CSV file and display a pretty graph. @@ -324,11 +324,11 @@ public class AltosUI extends AltosUIFrame { private void GraphData() { AltosDataChooser chooser; chooser = new AltosDataChooser(this); - AltosRecordIterable record_reader = chooser.runDialog(); - if (record_reader == null) + AltosStateIterable states = chooser.runDialog(); + if (states == null) return; try { - new AltosGraphUI(record_reader, chooser.file()); + new AltosGraphUI(states, chooser.file()); } catch (InterruptedException ie) { } catch (IOException ie) { } @@ -345,19 +345,15 @@ public class AltosUI extends AltosUIFrame { } } - static AltosRecordIterable open_logfile(File file) { + static AltosStateIterable open_logfile(File file) { try { FileInputStream in; in = new FileInputStream(file); if (file.getName().endsWith("eeprom")) - return new AltosEepromIterable(in); - else if (file.getName().endsWith("mega")) - return new AltosEepromMegaIterable(in); - else if (file.getName().endsWith("mini")) - return new AltosEepromMiniIterable(in); + return new AltosEepromFile(in); else - return new AltosTelemetryIterable(in); + return null; // new AltosTelemetryIterable(in); } catch (FileNotFoundException fe) { System.out.printf("%s\n", fe.getMessage()); return null; @@ -388,10 +384,11 @@ public class AltosUI extends AltosUIFrame { static final int process_graph = 3; static final int process_replay = 4; static final int process_summary = 5; + static final int process_cat = 6; static boolean process_csv(File input) { - AltosRecordIterable iterable = open_logfile(input); - if (iterable == null) + AltosStateIterable states = open_logfile(input); + if (states == null) return false; File output = Altos.replace_extension(input,".csv"); @@ -403,15 +400,15 @@ public class AltosUI extends AltosUIFrame { AltosWriter writer = open_csv(output); if (writer == null) return false; - writer.write(iterable); + writer.write(states); writer.close(); } return true; } static boolean process_kml(File input) { - AltosRecordIterable iterable = open_logfile(input); - if (iterable == null) + AltosStateIterable states = open_logfile(input); + if (states == null) return false; File output = Altos.replace_extension(input,".kml"); @@ -423,13 +420,13 @@ public class AltosUI extends AltosUIFrame { AltosWriter writer = open_kml(output); if (writer == null) return false; - writer.write(iterable); + writer.write(states); writer.close(); return true; } } - static AltosRecordIterable record_iterable(File file) { + static AltosStateIterable record_iterable(File file) { FileInputStream in; try { in = new FileInputStream(file); @@ -437,25 +434,18 @@ public class AltosUI extends AltosUIFrame { System.out.printf("Failed to open file '%s'\n", file); return null; } - AltosRecordIterable recs; - //AltosReplayReader reader; if (file.getName().endsWith("eeprom")) { - recs = new AltosEepromIterable(in); - } else if (file.getName().endsWith("mega")) { - recs = new AltosEepromMegaIterable(in); - } else if (file.getName().endsWith("mini")) { - recs = new AltosEepromMiniIterable(in); + return new AltosEepromFile(in); } else { - recs = new AltosTelemetryIterable(in); + return null; // new AltosTelemetryIterable(in); } - return recs; } static AltosReplayReader replay_file(File file) { - AltosRecordIterable recs = record_iterable(file); - if (recs == null) + AltosStateIterable states = record_iterable(file); + if (states == null) return null; - return new AltosReplayReader(recs.iterator(), file); + return new AltosReplayReader(states.iterator(), file); } static boolean process_replay(File file) { @@ -468,11 +458,11 @@ public class AltosUI extends AltosUIFrame { } static boolean process_graph(File file) { - AltosRecordIterable recs = record_iterable(file); - if (recs == null) + AltosStateIterable states = record_iterable(file); + if (states == null) return false; try { - new AltosGraphUI(recs, file); + new AltosGraphUI(states, file); return true; } catch (InterruptedException ie) { } catch (IOException ie) { @@ -481,11 +471,11 @@ public class AltosUI extends AltosUIFrame { } static boolean process_summary(File file) { - AltosRecordIterable iterable = record_iterable(file); - if (iterable == null) + AltosStateIterable states = record_iterable(file); + if (states == null) return false; try { - AltosFlightStats stats = new AltosFlightStats(iterable); + AltosFlightStats stats = new AltosFlightStats(states); if (stats.serial > 0) System.out.printf("Serial: %5d\n", stats.serial); if (stats.flight > 0) @@ -510,11 +500,11 @@ public class AltosUI extends AltosUIFrame { AltosConvert.meters_to_g(stats.max_acceleration)); } System.out.printf("Drogue rate: %6.0f m/s %6.0f ft/s\n", - stats.state_baro_speed[Altos.ao_flight_drogue], - AltosConvert.meters_to_feet(stats.state_baro_speed[Altos.ao_flight_drogue])); + stats.state_speed[Altos.ao_flight_drogue], + AltosConvert.meters_to_feet(stats.state_speed[Altos.ao_flight_drogue])); System.out.printf("Main rate: %6.0f m/s %6.0f ft/s\n", - stats.state_baro_speed[Altos.ao_flight_main], - AltosConvert.meters_to_feet(stats.state_baro_speed[Altos.ao_flight_main])); + stats.state_speed[Altos.ao_flight_main], + AltosConvert.meters_to_feet(stats.state_speed[Altos.ao_flight_main])); System.out.printf("Flight time: %6.0f s\n", stats.state_end[Altos.ao_flight_main] - stats.state_start[Altos.ao_flight_boost]); @@ -525,6 +515,27 @@ public class AltosUI extends AltosUIFrame { return false; } + static boolean process_cat(File file) { + try { + FileInputStream input = new FileInputStream(file); + AltosEepromFile eef = new AltosEepromFile(input); + + for (AltosState state : eef) { + if ((state.set & AltosState.set_gps) != 0) + System.out.printf ("time %g lat %g lon %g alt %g\n", + state.time_since_boost(), + state.gps.lat, + state.gps.lon, + state.gps.alt); + } + + } catch (Exception e) { + System.out.printf("Failed to open file '%s'\n", file); + return false; + } + return true; + } + public static void help(int code) { System.out.printf("Usage: altosui [OPTION]... [FILE]...\n"); System.out.printf(" Options:\n"); @@ -574,6 +585,8 @@ public class AltosUI extends AltosUIFrame { process = process_graph; else if (args[i].equals("--summary")) process = process_summary; + else if (args[i].equals("--cat")) + process = process_cat; else if (args[i].startsWith("--")) help(1); else { @@ -600,6 +613,9 @@ public class AltosUI extends AltosUIFrame { if (!process_summary(file)) ++errors; break; + case process_cat: + if (!process_cat(file)) + ++errors; } } } diff --git a/altosui/AltosWriter.java b/altosui/AltosWriter.java index 2f70b472..8de11bc9 100644 --- a/altosui/AltosWriter.java +++ b/altosui/AltosWriter.java @@ -22,9 +22,9 @@ import org.altusmetrum.altoslib_1.*; public interface AltosWriter { - public void write(AltosRecord record); + public void write(AltosState state); - public void write(AltosRecordIterable iterable); + public void write(AltosStateIterable states); public void close(); } -- cgit v1.2.3 From 77dc89ed5b7bf8f5b3fa3b6131660f1a98f583ea Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 31 Aug 2013 23:11:39 -0500 Subject: altoslib/altosui: Further AltosState transition work Parses most eeprom and telem records now; altosui updated to show from AltosState info. Signed-off-by: Keith Packard --- altoslib/AltosConvert.java | 22 ++ altoslib/AltosEeprom.java | 45 +++- altoslib/AltosEepromChunk.java | 26 +++ altoslib/AltosEepromFile.java | 5 + altoslib/AltosEepromGPS.java | 178 ++++++++++++++++ altoslib/AltosEepromHeader.java | 6 +- altoslib/AltosEepromMega.java | 262 +++++++++++------------ altoslib/AltosEepromMetrum.java | 2 + altoslib/AltosEepromMetrum2.java | 178 ++++++++++++++++ altoslib/AltosEepromMini.java | 20 +- altoslib/AltosEepromTM.java | 14 +- altoslib/AltosEepromTeleScience.java | 2 + altoslib/AltosGPS.java | 10 +- altoslib/AltosLib.java | 1 + altoslib/AltosState.java | 129 +++++++++--- altoslib/AltosTelemetry.java | 44 +--- altoslib/AltosTelemetryConfiguration.java | 55 +++++ altoslib/AltosTelemetryLegacy.java | 2 +- altoslib/AltosTelemetryLocation.java | 88 ++++++++ altoslib/AltosTelemetryMegaData.java | 85 ++++++++ altoslib/AltosTelemetryMegaSensor.java | 84 ++++++++ altoslib/AltosTelemetryMetrumData.java | 42 ++++ altoslib/AltosTelemetryMetrumSensor.java | 69 ++++++ altoslib/AltosTelemetryRaw.java | 28 +++ altoslib/AltosTelemetrySatellite.java | 50 +++++ altoslib/AltosTelemetrySensor.java | 80 +++++++ altoslib/AltosTelemetryStandard.java | 106 ++++++++++ altoslib/Makefile.am | 34 ++- altosui/AltosAscent.java | 4 +- altosui/AltosDescent.java | 4 +- altosui/AltosDisplayThread.java | 2 +- altosui/AltosEepromDownload.java | 340 ++++-------------------------- altosui/AltosFlightStatus.java | 2 +- altosui/AltosFlightUI.java | 2 +- altosui/AltosIdleMonitorUI.java | 8 +- altosui/AltosInfoTable.java | 30 +-- altosui/AltosLanded.java | 5 +- altosui/AltosPad.java | 74 ++++--- altosui/AltosUI.java | 15 +- src/core/ao_log.h | 3 +- 40 files changed, 1552 insertions(+), 604 deletions(-) create mode 100644 altoslib/AltosEepromGPS.java create mode 100644 altoslib/AltosEepromMetrum2.java create mode 100644 altoslib/AltosTelemetryConfiguration.java create mode 100644 altoslib/AltosTelemetryLocation.java create mode 100644 altoslib/AltosTelemetryMegaData.java create mode 100644 altoslib/AltosTelemetryMegaSensor.java create mode 100644 altoslib/AltosTelemetryMetrumData.java create mode 100644 altoslib/AltosTelemetryMetrumSensor.java create mode 100644 altoslib/AltosTelemetryRaw.java create mode 100644 altoslib/AltosTelemetrySatellite.java create mode 100644 altoslib/AltosTelemetrySensor.java create mode 100644 altoslib/AltosTelemetryStandard.java (limited to 'altoslib/AltosConvert.java') diff --git a/altoslib/AltosConvert.java b/altoslib/AltosConvert.java index a1e2cdca..cf2bc59f 100644 --- a/altoslib/AltosConvert.java +++ b/altoslib/AltosConvert.java @@ -196,6 +196,28 @@ public class AltosConvert { return ((count / 16.0) / 2047.0 + 0.095) / 0.009 * 1000.0; } + static double + thermometer_to_temperature(double thermo) + { + return (thermo - 19791.268) / 32728.0 * 1.25 / 0.00247; + } + + static double mega_adc(int raw) { + return raw / 4095.0; + } + + static public double mega_battery_voltage(int v_batt) { + if (v_batt != AltosRecord.MISSING) + return 3.3 * mega_adc(v_batt) * (15.0 + 27.0) / 27.0; + return AltosRecord.MISSING; + } + + static double mega_pyro_voltage(int raw) { + if (raw != AltosRecord.MISSING) + return 3.3 * mega_adc(raw) * (100.0 + 27.0) / 27.0; + return AltosRecord.MISSING; + } + public static double radio_to_frequency(int freq, int setting, int cal, int channel) { double f; diff --git a/altoslib/AltosEeprom.java b/altoslib/AltosEeprom.java index 31646c7e..081b3be1 100644 --- a/altoslib/AltosEeprom.java +++ b/altoslib/AltosEeprom.java @@ -27,8 +27,26 @@ public abstract class AltosEeprom implements AltosStateUpdate { public int data8[]; public boolean valid; + public int data8(int i) { + return data8[i]; + } + + public int data16(int i) { + return ((data8[i] | (data8[i+1] << 8)) << 16) >> 16; + } + + public int data24(int i) { + return data8[i] | (data8[i+1] << 8) | (data8[i+2] << 16); + } + + public int data32(int i) { + return data8[i] | (data8[i+1] << 8) | (data8[i+2] << 16) | (data8[i+3] << 24); + } + public final static int header_length = 4; + public abstract int record_length(); + public abstract void update_state(AltosState state); public void write(PrintStream out) { @@ -40,14 +58,28 @@ public abstract class AltosEeprom implements AltosStateUpdate { out.printf ("\n"); } - void parse_chunk(AltosEepromChunk chunk, int start, int record_length) throws ParseException { + public String string() { + String s; + + s = String.format("%c %04x", cmd, tick); + if (data8 != null) { + for (int i = 0; i < data8.length; i++) { + String d = String.format(" %02x", data8[i]); + s = s.concat(d); + } + } + s = s.concat("\n"); + return s; + } + + void parse_chunk(AltosEepromChunk chunk, int start) throws ParseException { cmd = chunk.data(start); - int data_length = record_length - header_length; + int data_length = record_length() - header_length; - valid = !chunk.erased(start, record_length); + valid = !chunk.erased(start, record_length()); if (valid) { - if (AltosConvert.checksum(chunk.data, start, record_length) != 0) + if (AltosConvert.checksum(chunk.data, start, record_length()) != 0) throw new ParseException(String.format("invalid checksum at 0x%x", chunk.address + start), 0); } else { @@ -61,12 +93,12 @@ public abstract class AltosEeprom implements AltosStateUpdate { data8[i] = chunk.data(start + header_length + i); } - void parse_string(String line, int record_length) { + void parse_string(String line) { valid = false; tick = 0; cmd = AltosLib.AO_LOG_INVALID; - int data_length = record_length - header_length; + int data_length = record_length() - header_length; if (line == null) return; @@ -79,6 +111,7 @@ public abstract class AltosEeprom implements AltosStateUpdate { tick = Integer.parseInt(tokens[1],16); valid = true; data8 = new int[data_length]; + for (int i = 0; i < data_length; i++) data8[i] = Integer.parseInt(tokens[2 + i],16); } diff --git a/altoslib/AltosEepromChunk.java b/altoslib/AltosEepromChunk.java index b1bba3bb..1709352b 100644 --- a/altoslib/AltosEepromChunk.java +++ b/altoslib/AltosEepromChunk.java @@ -62,6 +62,32 @@ public class AltosEepromChunk { return true; } + public AltosEeprom eeprom(int offset, int log_format) { + AltosEeprom eeprom = null; + try { + switch (log_format) { + case AltosLib.AO_LOG_FORMAT_FULL: + eeprom = new AltosEepromTM(this, offset); + break; + case AltosLib.AO_LOG_FORMAT_TINY: + case AltosLib.AO_LOG_FORMAT_TELEMETRY: + case AltosLib.AO_LOG_FORMAT_TELESCIENCE: + case AltosLib.AO_LOG_FORMAT_TELEMEGA: + eeprom = new AltosEepromMega(this, offset); + break; + case AltosLib.AO_LOG_FORMAT_TELEMETRUM: + eeprom = new AltosEepromMetrum2(this, offset); + break; + case AltosLib.AO_LOG_FORMAT_TELEMINI: + case AltosLib.AO_LOG_FORMAT_EASYMINI: + eeprom = new AltosEepromMini(this, offset); + break; + } + } catch (ParseException e) { + } + return eeprom; + } + public AltosEepromChunk(AltosLink link, int block, boolean flush) throws TimeoutException, InterruptedException { diff --git a/altoslib/AltosEepromFile.java b/altoslib/AltosEepromFile.java index 2f4c54d7..367b6791 100644 --- a/altoslib/AltosEepromFile.java +++ b/altoslib/AltosEepromFile.java @@ -72,6 +72,7 @@ public class AltosEepromFile extends AltosStateIterable { headers = new AltosEepromIterable(AltosEepromHeader.read(input)); start = headers.state(); + start.set_state(AltosLib.ao_flight_pad); switch (start.log_format) { case AltosLib.AO_LOG_FORMAT_FULL: @@ -81,6 +82,10 @@ public class AltosEepromFile extends AltosStateIterable { case AltosLib.AO_LOG_FORMAT_TELEMETRY: case AltosLib.AO_LOG_FORMAT_TELESCIENCE: case AltosLib.AO_LOG_FORMAT_TELEMEGA: + body = new AltosEepromIterable(AltosEepromMega.read(input)); + break; + case AltosLib.AO_LOG_FORMAT_TELEMETRUM: + body = new AltosEepromIterable(AltosEepromMetrum2.read(input)); break; case AltosLib.AO_LOG_FORMAT_TELEMINI: case AltosLib.AO_LOG_FORMAT_EASYMINI: diff --git a/altoslib/AltosEepromGPS.java b/altoslib/AltosEepromGPS.java new file mode 100644 index 00000000..d8e47a6e --- /dev/null +++ b/altoslib/AltosEepromGPS.java @@ -0,0 +1,178 @@ +/* + * Copyright © 2011 Keith Packard + * + * 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_1; + +import java.io.*; +import java.util.*; +import java.text.*; + +public class AltosEepromGPS extends AltosEeprom { + public static final int record_length = 16; + + public int record_length() { return record_length; } + + /* AO_LOG_FLIGHT elements */ + public int flight() { return data16(0); } + public int ground_accel() { return data16(2); } + public int ground_pres() { return data32(4); } + public int ground_temp() { return data32(8); } + + /* AO_LOG_STATE elements */ + public int state() { return data16(0); } + public int reason() { return data16(2); } + + /* AO_LOG_SENSOR elements */ + public int pres() { return data32(0); } + public int temp() { return data32(4); } + public int accel() { return data16(8); } + + /* AO_LOG_TEMP_VOLT elements */ + public int v_batt() { return data16(0); } + public int sense_a() { return data16(2); } + public int sense_m() { return data16(4); } + + /* AO_LOG_GPS_POS elements */ + public int latitude() { return data32(0); } + public int longitude() { return data32(4); } + public int altitude() { return data16(8); } + + /* AO_LOG_GPS_TIME elements */ + public int hour() { return data8(0); } + public int minute() { return data8(1); } + public int second() { return data8(2); } + public int flags() { return data8(3); } + public int year() { return data8(4); } + public int month() { return data8(5); } + public int day() { return data8(6); } + + /* AO_LOG_GPS_SAT elements */ + public int nsat() { return data8(0); } + public int more() { return data8(1); } + public int svid(int n) { return data8(2 + n * 2); } + public int c_n(int n) { return data8(2 + n * 2 + 1); } + + public AltosEepromMetrum2 (AltosEepromChunk chunk, int start) throws ParseException { + parse_chunk(chunk, start); + } + + public void update_state(AltosState state) { + AltosGPS gps; + + /* Flush any pending GPS changes */ + if (state.gps_pending) { + switch (cmd) { + case AltosLib.AO_LOG_GPS_POS: + case AltosLib.AO_LOG_GPS_LAT: + case AltosLib.AO_LOG_GPS_LON: + case AltosLib.AO_LOG_GPS_ALT: + case AltosLib.AO_LOG_GPS_SAT: + case AltosLib.AO_LOG_GPS_DATE: + break; + default: + state.set_temp_gps(); + break; + } + } + + if (cmd != AltosLib.AO_LOG_FLIGHT) + state.set_tick(tick); + switch (cmd) { + case AltosLib.AO_LOG_FLIGHT: + state.set_boost_tick(tick); + state.set_flight(flight()); + state.set_ground_accel(ground_accel()); + state.set_ground_pressure(ground_pres()); +// state.set_temperature(ground_temp() / 100.0); + break; + case AltosLib.AO_LOG_STATE: + state.set_state(state()); + break; + case AltosLib.AO_LOG_SENSOR: + state.set_ms5607(pres(), temp()); + state.set_accel(accel()); + + break; + case AltosLib.AO_LOG_TEMP_VOLT: + state.set_battery_voltage(AltosConvert.mega_battery_voltage(v_batt())); + + state.set_apogee_voltage(AltosConvert.mega_pyro_voltage(sense_a())); + state.set_main_voltage(AltosConvert.mega_pyro_voltage(sense_m())); + + break; + case AltosLib.AO_LOG_GPS_POS: + gps = state.make_temp_gps(); + gps.lat = latitude() / 1e7; + gps.lon = longitude() / 1e7; + gps.alt = altitude(); + break; + case AltosLib.AO_LOG_GPS_TIME: + gps = state.make_temp_gps(); + + gps.hour = hour(); + gps.minute = minute(); + gps.second = second(); + + int flags = flags(); + + gps.connected = (flags & AltosLib.AO_GPS_RUNNING) != 0; + gps.locked = (flags & AltosLib.AO_GPS_VALID) != 0; + gps.nsat = (flags & AltosLib.AO_GPS_NUM_SAT_MASK) >> + AltosLib.AO_GPS_NUM_SAT_SHIFT; + + gps.year = year(); + gps.month = month(); + gps.day = day(); + break; + case AltosLib.AO_LOG_GPS_SAT: + state.set_tick(tick); + gps = state.make_temp_gps(); + + int n = nsat(); + for (int i = 0; i < n; i++) + gps.add_sat(svid(i), c_n(i)); + break; + } + } + + public AltosEepromMetrum2 (String line) { + parse_string(line); + } + + static public LinkedList read(FileInputStream input) { + LinkedList megas = new LinkedList(); + + for (;;) { + try { + String line = AltosLib.gets(input); + if (line == null) + break; + try { + AltosEepromMetrum2 mega = new AltosEepromMetrum2(line); + if (mega.cmd != AltosLib.AO_LOG_INVALID) + megas.add(mega); + } catch (Exception e) { + System.out.printf ("exception\n"); + } + } catch (IOException ie) { + break; + } + } + + return megas; + } +} diff --git a/altoslib/AltosEepromHeader.java b/altoslib/AltosEepromHeader.java index a06f05ed..35a03a12 100644 --- a/altoslib/AltosEepromHeader.java +++ b/altoslib/AltosEepromHeader.java @@ -29,6 +29,9 @@ public class AltosEepromHeader extends AltosEeprom { public boolean last; public boolean valid; + public int record_length () { return 0; } + + /* XXX pull rest of config data to state */ public void update_state(AltosState state) { switch (cmd) { case AltosLib.AO_LOG_CONFIG_VERSION: @@ -40,7 +43,7 @@ public class AltosEepromHeader extends AltosEeprom { case AltosLib.AO_LOG_RADIO_CHANNEL: break; case AltosLib.AO_LOG_CALLSIGN: - state.callsign = data; + state.set_callsign(data); break; case AltosLib.AO_LOG_ACCEL_CAL: state.set_accel_g(config_a, config_b); @@ -90,6 +93,7 @@ public class AltosEepromHeader extends AltosEeprom { state.baro.crc = config_a; break; case AltosLib.AO_LOG_SOFTWARE_VERSION: + state.set_firmware_version(data); break; } } diff --git a/altoslib/AltosEepromMega.java b/altoslib/AltosEepromMega.java index 0804c392..e8f9b1fc 100644 --- a/altoslib/AltosEepromMega.java +++ b/altoslib/AltosEepromMega.java @@ -17,32 +17,14 @@ package org.altusmetrum.altoslib_1; +import java.io.*; +import java.util.*; import java.text.*; -public class AltosEepromMega { - public int cmd; - public int tick; - public boolean valid; - public String data; - public int config_a, config_b; - - public int data8[]; - +public class AltosEepromMega extends AltosEeprom { public static final int record_length = 32; - static final int header_length = 4; - static final int data_length = record_length - header_length; - - public int data8(int i) { - return data8[i]; - } - public int data16(int i) { - return ((data8[i] | (data8[i+1] << 8)) << 16) >> 16; - } - - public int data32(int i) { - return data8[i] | (data8[i+1] << 8) | (data8[i+2] << 16) | (data8[i+3] << 24); - } + public int record_length() { return record_length; } /* AO_LOG_FLIGHT elements */ public int flight() { return data16(0); } @@ -68,7 +50,7 @@ public class AltosEepromMega { public int mag_z() { return data16(24); } public int accel() { return data16(26); } - /* AO_LOG_VOLT elements */ + /* AO_LOG_TEMP_VOLT elements */ public int v_batt() { return data16(0); } public int v_pbatt() { return data16(2); } public int nsense() { return data16(4); } @@ -91,131 +73,137 @@ public class AltosEepromMega { public int nsat() { return data16(0); } public int svid(int n) { return data8(2 + n * 2); } public int c_n(int n) { return data8(2 + n * 2 + 1); } + public AltosEepromMega (AltosEepromChunk chunk, int start) throws ParseException { - cmd = chunk.data(start); - - valid = !chunk.erased(start, record_length); - if (valid) { - if (AltosConvert.checksum(chunk.data, start, record_length) != 0) - throw new ParseException(String.format("invalid checksum at 0x%x", - chunk.address + start), 0); - } else { - cmd = AltosLib.AO_LOG_INVALID; - } + parse_chunk(chunk, start); + } - tick = chunk.data16(start+2); + public void update_state(AltosState state) { + AltosGPS gps; + + /* Flush any pending GPS changes */ + if (state.gps_pending) { + switch (cmd) { + case AltosLib.AO_LOG_GPS_LAT: + case AltosLib.AO_LOG_GPS_LON: + case AltosLib.AO_LOG_GPS_ALT: + case AltosLib.AO_LOG_GPS_SAT: + case AltosLib.AO_LOG_GPS_DATE: + break; + default: + state.set_temp_gps(); + break; + } + } - data8 = new int[data_length]; - for (int i = 0; i < data_length; i++) - data8[i] = chunk.data(start + header_length + i); + switch (cmd) { + case AltosLib.AO_LOG_FLIGHT: + state.set_boost_tick(tick); + state.set_flight(flight()); + state.set_ground_accel(ground_accel()); + state.set_ground_pressure(ground_pres()); + state.set_temperature(ground_temp() / 100.0); + break; + case AltosLib.AO_LOG_STATE: + state.set_tick(tick); + state.set_state(state()); + break; + case AltosLib.AO_LOG_SENSOR: + state.set_tick(tick); + state.set_ms5607(pres(), temp()); + + AltosIMU imu = new AltosIMU(); + imu.accel_x = accel_x(); + imu.accel_y = accel_y(); + imu.accel_z = accel_z(); + + imu.gyro_x = gyro_x(); + imu.gyro_y = gyro_y(); + imu.gyro_z = gyro_z(); + state.imu = imu; + + AltosMag mag = new AltosMag(); + mag.x = mag_x(); + mag.y = mag_y(); + mag.z = mag_z(); + + state.mag = mag; + + state.set_accel(accel()); + + break; + case AltosLib.AO_LOG_TEMP_VOLT: + state.set_battery_voltage(AltosConvert.mega_battery_voltage(v_batt())); + state.set_pyro_voltage(AltosConvert.mega_pyro_voltage(v_pbatt())); + + int nsense = nsense(); + + state.set_apogee_voltage(AltosConvert.mega_pyro_voltage(sense(nsense-2))); + state.set_main_voltage(AltosConvert.mega_pyro_voltage(sense(nsense-1))); + + double voltages[] = new double[nsense-2]; + for (int i = 0; i < nsense-2; i++) + voltages[i] = AltosConvert.mega_pyro_voltage(sense(i)); + + state.set_ignitor_voltage(voltages); + break; + case AltosLib.AO_LOG_GPS_TIME: + state.set_tick(tick); + gps = state.make_temp_gps(); + gps.lat = latitude() / 1e7; + gps.lon = longitude() / 1e7; + gps.alt = altitude(); + + gps.hour = hour(); + gps.minute = minute(); + gps.second = second(); + + int flags = flags(); + + gps.connected = (flags & AltosLib.AO_GPS_RUNNING) != 0; + gps.locked = (flags & AltosLib.AO_GPS_VALID) != 0; + gps.nsat = (flags & AltosLib.AO_GPS_NUM_SAT_MASK) >> + AltosLib.AO_GPS_NUM_SAT_SHIFT; + + gps.year = year(); + gps.month = month(); + gps.day = day(); + break; + case AltosLib.AO_LOG_GPS_SAT: + state.set_tick(tick); + gps = state.make_temp_gps(); + + int n = nsat(); + for (int i = 0; i < n; i++) + gps.add_sat(svid(i), c_n(i)); + break; + } } public AltosEepromMega (String line) { - valid = false; - tick = 0; + parse_string(line); + } - if (line == null) { - cmd = AltosLib.AO_LOG_INVALID; - line = ""; - } else { + static public LinkedList read(FileInputStream input) { + LinkedList megas = new LinkedList(); + + for (;;) { try { - String[] tokens = line.split("\\s+"); - - if (tokens[0].length() == 1) { - if (tokens.length != 2 + data_length) { - cmd = AltosLib.AO_LOG_INVALID; - data = line; - } else { - cmd = tokens[0].codePointAt(0); - tick = Integer.parseInt(tokens[1],16); - valid = true; - data8 = new int[data_length]; - for (int i = 0; i < data_length; i++) - data8[i] = Integer.parseInt(tokens[2 + i],16); - } - } else if (tokens[0].equals("Config") && tokens[1].equals("version:")) { - cmd = AltosLib.AO_LOG_CONFIG_VERSION; - data = tokens[2]; - } else if (tokens[0].equals("Main") && tokens[1].equals("deploy:")) { - cmd = AltosLib.AO_LOG_MAIN_DEPLOY; - config_a = Integer.parseInt(tokens[2]); - } else if (tokens[0].equals("Apogee") && tokens[1].equals("delay:")) { - cmd = AltosLib.AO_LOG_APOGEE_DELAY; - config_a = Integer.parseInt(tokens[2]); - } else if (tokens[0].equals("Radio") && tokens[1].equals("channel:")) { - cmd = AltosLib.AO_LOG_RADIO_CHANNEL; - config_a = Integer.parseInt(tokens[2]); - } else if (tokens[0].equals("Callsign:")) { - cmd = AltosLib.AO_LOG_CALLSIGN; - data = tokens[1].replaceAll("\"",""); - } else if (tokens[0].equals("Accel") && tokens[1].equals("cal")) { - cmd = AltosLib.AO_LOG_ACCEL_CAL; - config_a = Integer.parseInt(tokens[3]); - config_b = Integer.parseInt(tokens[5]); - } else if (tokens[0].equals("Radio") && tokens[1].equals("cal:")) { - cmd = AltosLib.AO_LOG_RADIO_CAL; - config_a = Integer.parseInt(tokens[2]); - } else if (tokens[0].equals("Max") && tokens[1].equals("flight") && tokens[2].equals("log:")) { - cmd = AltosLib.AO_LOG_MAX_FLIGHT_LOG; - config_a = Integer.parseInt(tokens[3]); - } else if (tokens[0].equals("manufacturer")) { - cmd = AltosLib.AO_LOG_MANUFACTURER; - data = tokens[1]; - } else if (tokens[0].equals("product")) { - cmd = AltosLib.AO_LOG_PRODUCT; - data = tokens[1]; - } else if (tokens[0].equals("serial-number")) { - cmd = AltosLib.AO_LOG_SERIAL_NUMBER; - config_a = Integer.parseInt(tokens[1]); - } else if (tokens[0].equals("log-format")) { - cmd = AltosLib.AO_LOG_LOG_FORMAT; - config_a = Integer.parseInt(tokens[1]); - } else if (tokens[0].equals("software-version")) { - cmd = AltosLib.AO_LOG_SOFTWARE_VERSION; - data = tokens[1]; - } else if (tokens[0].equals("ms5607")) { - if (tokens[1].equals("reserved:")) { - cmd = AltosLib.AO_LOG_BARO_RESERVED; - config_a = Integer.parseInt(tokens[2]); - } else if (tokens[1].equals("sens:")) { - cmd = AltosLib.AO_LOG_BARO_SENS; - config_a = Integer.parseInt(tokens[2]); - } else if (tokens[1].equals("off:")) { - cmd = AltosLib.AO_LOG_BARO_OFF; - config_a = Integer.parseInt(tokens[2]); - } else if (tokens[1].equals("tcs:")) { - cmd = AltosLib.AO_LOG_BARO_TCS; - config_a = Integer.parseInt(tokens[2]); - } else if (tokens[1].equals("tco:")) { - cmd = AltosLib.AO_LOG_BARO_TCO; - config_a = Integer.parseInt(tokens[2]); - } else if (tokens[1].equals("tref:")) { - cmd = AltosLib.AO_LOG_BARO_TREF; - config_a = Integer.parseInt(tokens[2]); - } else if (tokens[1].equals("tempsens:")) { - cmd = AltosLib.AO_LOG_BARO_TEMPSENS; - config_a = Integer.parseInt(tokens[2]); - } else if (tokens[1].equals("crc:")) { - cmd = AltosLib.AO_LOG_BARO_CRC; - config_a = Integer.parseInt(tokens[2]); - } else { - cmd = AltosLib.AO_LOG_INVALID; - data = line; - } - } else { - cmd = AltosLib.AO_LOG_INVALID; - data = line; + String line = AltosLib.gets(input); + if (line == null) + break; + try { + AltosEepromMega mega = new AltosEepromMega(line); + if (mega.cmd != AltosLib.AO_LOG_INVALID) + megas.add(mega); + } catch (Exception e) { + System.out.printf ("exception\n"); } - } catch (NumberFormatException ne) { - cmd = AltosLib.AO_LOG_INVALID; - data = line; + } catch (IOException ie) { + break; } } - } - public AltosEepromMega(int in_cmd, int in_tick) { - cmd = in_cmd; - tick = in_tick; - valid = true; + return megas; } } diff --git a/altoslib/AltosEepromMetrum.java b/altoslib/AltosEepromMetrum.java index 72887032..e035e5fd 100644 --- a/altoslib/AltosEepromMetrum.java +++ b/altoslib/AltosEepromMetrum.java @@ -32,6 +32,8 @@ public class AltosEepromMetrum { static final int header_length = 4; static final int data_length = record_length - header_length; + public int record_length() { return record_length; } + public int data8(int i) { return data8[i]; } diff --git a/altoslib/AltosEepromMetrum2.java b/altoslib/AltosEepromMetrum2.java new file mode 100644 index 00000000..5a616e6c --- /dev/null +++ b/altoslib/AltosEepromMetrum2.java @@ -0,0 +1,178 @@ +/* + * Copyright © 2011 Keith Packard + * + * 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_1; + +import java.io.*; +import java.util.*; +import java.text.*; + +public class AltosEepromMetrum2 extends AltosEeprom { + public static final int record_length = 16; + + public int record_length() { return record_length; } + + /* AO_LOG_FLIGHT elements */ + public int flight() { return data16(0); } + public int ground_accel() { return data16(2); } + public int ground_pres() { return data32(4); } + public int ground_temp() { return data32(8); } + + /* AO_LOG_STATE elements */ + public int state() { return data16(0); } + public int reason() { return data16(2); } + + /* AO_LOG_SENSOR elements */ + public int pres() { return data32(0); } + public int temp() { return data32(4); } + public int accel() { return data16(8); } + + /* AO_LOG_TEMP_VOLT elements */ + public int v_batt() { return data16(0); } + public int sense_a() { return data16(2); } + public int sense_m() { return data16(4); } + + /* AO_LOG_GPS_POS elements */ + public int latitude() { return data32(0); } + public int longitude() { return data32(4); } + public int altitude() { return data16(8); } + + /* AO_LOG_GPS_TIME elements */ + public int hour() { return data8(0); } + public int minute() { return data8(1); } + public int second() { return data8(2); } + public int flags() { return data8(3); } + public int year() { return data8(4); } + public int month() { return data8(5); } + public int day() { return data8(6); } + + /* AO_LOG_GPS_SAT elements */ + public int nsat() { return data8(0); } + public int more() { return data8(1); } + public int svid(int n) { return data8(2 + n * 2); } + public int c_n(int n) { return data8(2 + n * 2 + 1); } + + public AltosEepromMetrum2 (AltosEepromChunk chunk, int start) throws ParseException { + parse_chunk(chunk, start); + } + + public void update_state(AltosState state) { + AltosGPS gps; + + /* Flush any pending GPS changes */ + if (state.gps_pending) { + switch (cmd) { + case AltosLib.AO_LOG_GPS_POS: + case AltosLib.AO_LOG_GPS_LAT: + case AltosLib.AO_LOG_GPS_LON: + case AltosLib.AO_LOG_GPS_ALT: + case AltosLib.AO_LOG_GPS_SAT: + case AltosLib.AO_LOG_GPS_DATE: + break; + default: + state.set_temp_gps(); + break; + } + } + + if (cmd != AltosLib.AO_LOG_FLIGHT) + state.set_tick(tick); + switch (cmd) { + case AltosLib.AO_LOG_FLIGHT: + state.set_boost_tick(tick); + state.set_flight(flight()); + state.set_ground_accel(ground_accel()); + state.set_ground_pressure(ground_pres()); +// state.set_temperature(ground_temp() / 100.0); + break; + case AltosLib.AO_LOG_STATE: + state.set_state(state()); + break; + case AltosLib.AO_LOG_SENSOR: + state.set_ms5607(pres(), temp()); + state.set_accel(accel()); + + break; + case AltosLib.AO_LOG_TEMP_VOLT: + state.set_battery_voltage(AltosConvert.mega_battery_voltage(v_batt())); + + state.set_apogee_voltage(AltosConvert.mega_pyro_voltage(sense_a())); + state.set_main_voltage(AltosConvert.mega_pyro_voltage(sense_m())); + + break; + case AltosLib.AO_LOG_GPS_POS: + gps = state.make_temp_gps(); + gps.lat = latitude() / 1e7; + gps.lon = longitude() / 1e7; + gps.alt = altitude(); + break; + case AltosLib.AO_LOG_GPS_TIME: + gps = state.make_temp_gps(); + + gps.hour = hour(); + gps.minute = minute(); + gps.second = second(); + + int flags = flags(); + + gps.connected = (flags & AltosLib.AO_GPS_RUNNING) != 0; + gps.locked = (flags & AltosLib.AO_GPS_VALID) != 0; + gps.nsat = (flags & AltosLib.AO_GPS_NUM_SAT_MASK) >> + AltosLib.AO_GPS_NUM_SAT_SHIFT; + + gps.year = year(); + gps.month = month(); + gps.day = day(); + break; + case AltosLib.AO_LOG_GPS_SAT: + state.set_tick(tick); + gps = state.make_temp_gps(); + + int n = nsat(); + for (int i = 0; i < n; i++) + gps.add_sat(svid(i), c_n(i)); + break; + } + } + + public AltosEepromMetrum2 (String line) { + parse_string(line); + } + + static public LinkedList read(FileInputStream input) { + LinkedList megas = new LinkedList(); + + for (;;) { + try { + String line = AltosLib.gets(input); + if (line == null) + break; + try { + AltosEepromMetrum2 mega = new AltosEepromMetrum2(line); + if (mega.cmd != AltosLib.AO_LOG_INVALID) + megas.add(mega); + } catch (Exception e) { + System.out.printf ("exception\n"); + } + } catch (IOException ie) { + break; + } + } + + return megas; + } +} diff --git a/altoslib/AltosEepromMini.java b/altoslib/AltosEepromMini.java index 1e0ff1b9..15ec1929 100644 --- a/altoslib/AltosEepromMini.java +++ b/altoslib/AltosEepromMini.java @@ -24,21 +24,7 @@ import java.text.*; public class AltosEepromMini extends AltosEeprom { public static final int record_length = 16; - public int data8(int i) { - return data8[i]; - } - - public int data16(int i) { - return ((data8[i] | (data8[i+1] << 8)) << 16) >> 16; - } - - public int data24(int i) { - return data8[i] | (data8[i+1] << 8) | (data8[i+2] << 16); - } - - public int data32(int i) { - return data8[i] | (data8[i+1] << 8) | (data8[i+2] << 16) | (data8[i+3] << 24); - } + public int record_length() { return record_length; } /* AO_LOG_FLIGHT elements */ public int flight() { return data16(0); } @@ -84,11 +70,11 @@ public class AltosEepromMini extends AltosEeprom { } public AltosEepromMini (AltosEepromChunk chunk, int start) throws ParseException { - parse_chunk(chunk, start, record_length); + parse_chunk(chunk, start); } public AltosEepromMini (String line) { - parse_string(line, record_length); + parse_string(line); } public AltosEepromMini(int in_cmd, int in_tick) { diff --git a/altoslib/AltosEepromTM.java b/altoslib/AltosEepromTM.java index 6945468b..461a7a9c 100644 --- a/altoslib/AltosEepromTM.java +++ b/altoslib/AltosEepromTM.java @@ -30,16 +30,16 @@ public class AltosEepromTM extends AltosEeprom { public static final int record_length = 8; - static double - thermometer_to_temperature(double thermo) - { - return (thermo - 19791.268) / 32728.0 * 1.25 / 0.00247; - } - public void write(PrintStream out) { out.printf("%c %4x %4x %4x\n", cmd, tick, a, b); } + public int record_length() { return record_length; } + + public String string() { + return String.format("%c %4x %4x %4x\n", cmd, tick, a, b); + } + public void update_state(AltosState state) { AltosGPS gps; @@ -77,7 +77,7 @@ public class AltosEepromTM extends AltosEeprom { break; case AltosLib.AO_LOG_TEMP_VOLT: state.set_tick(tick); - state.set_temperature(thermometer_to_temperature(a)); + state.set_temperature(AltosConvert.thermometer_to_temperature(a)); state.set_battery_voltage(AltosConvert.cc_battery_to_voltage(b)); break; case AltosLib.AO_LOG_DEPLOY: diff --git a/altoslib/AltosEepromTeleScience.java b/altoslib/AltosEepromTeleScience.java index 2a828cf3..bacd66b5 100644 --- a/altoslib/AltosEepromTeleScience.java +++ b/altoslib/AltosEepromTeleScience.java @@ -33,6 +33,8 @@ public class AltosEepromTeleScience { static final int max_data = 12; public static final int record_length = 32; + public int record_length() { return record_length; } + public AltosEepromTeleScience (AltosEepromChunk chunk, int start) throws ParseException { type = chunk.data(start); diff --git a/altoslib/AltosGPS.java b/altoslib/AltosGPS.java index 399e95b1..a8c19e4a 100644 --- a/altoslib/AltosGPS.java +++ b/altoslib/AltosGPS.java @@ -65,8 +65,8 @@ public class AltosGPS implements Cloneable { } public void ClearGPSTime() { - year = month = day = 0; - hour = minute = second = 0; + year = month = day = AltosRecord.MISSING; + hour = minute = second = AltosRecord.MISSING; } public AltosGPS(AltosTelemetryMap map) throws ParseException { @@ -212,6 +212,9 @@ public class AltosGPS implements Cloneable { } public AltosGPS() { + lat = AltosRecord.MISSING; + lon = AltosRecord.MISSING; + alt = AltosRecord.MISSING; ClearGPSTime(); cc_gps_sat = null; } @@ -280,6 +283,9 @@ public class AltosGPS implements Cloneable { } } } else { + lat = AltosRecord.MISSING; + lon = AltosRecord.MISSING; + alt = AltosRecord.MISSING; ClearGPSTime(); cc_gps_sat = null; } diff --git a/altoslib/AltosLib.java b/altoslib/AltosLib.java index 4ca8ad9d..d6d78ca8 100644 --- a/altoslib/AltosLib.java +++ b/altoslib/AltosLib.java @@ -28,6 +28,7 @@ public class AltosLib { public static final int AO_LOG_TEMP_VOLT = 'T'; public static final int AO_LOG_DEPLOY = 'D'; public static final int AO_LOG_STATE = 'S'; + public static final int AO_LOG_GPS_POS = 'P'; public static final int AO_LOG_GPS_TIME = 'G'; public static final int AO_LOG_GPS_LAT = 'N'; public static final int AO_LOG_GPS_LON = 'W'; diff --git a/altoslib/AltosState.java b/altoslib/AltosState.java index aa3de432..b80d7b2e 100644 --- a/altoslib/AltosState.java +++ b/altoslib/AltosState.java @@ -32,7 +32,7 @@ public class AltosState implements Cloneable { /* derived data */ - public long report_time; + public long received_time; public double time; public double prev_time; @@ -48,6 +48,12 @@ public class AltosState implements Cloneable { public boolean boost; /* under power */ public int rssi; public int status; + public int device_type; + public int config_major; + public int config_minor; + public int apogee_delay; + public int main_deploy; + public int flight_log_max; public double ground_altitude; public double ground_pressure; @@ -61,11 +67,16 @@ public class AltosState implements Cloneable { public double apogee_voltage; public double main_voltage; public double speed; + public double ignitor_voltage[]; public double prev_height; public double prev_speed; public double prev_acceleration; + public double prev_max_height; + public double prev_max_acceleration; + public double prev_max_speed; + public double max_height; public double max_acceleration; public double max_speed; @@ -100,6 +111,8 @@ public class AltosState implements Cloneable { public double speak_altitude; public String callsign; + public String firmware_version; + public double accel_plus_g; public double accel_minus_g; public double accel; @@ -133,7 +146,7 @@ public class AltosState implements Cloneable { set = 0; - report_time = System.currentTimeMillis(); + received_time = System.currentTimeMillis(); time = AltosRecord.MISSING; time_change = AltosRecord.MISSING; prev_time = AltosRecord.MISSING; @@ -145,6 +158,12 @@ public class AltosState implements Cloneable { boost = false; rssi = AltosRecord.MISSING; status = 0; + device_type = AltosRecord.MISSING; + config_major = AltosRecord.MISSING; + config_minor = AltosRecord.MISSING; + apogee_delay = AltosRecord.MISSING; + main_deploy = AltosRecord.MISSING; + flight_log_max = AltosRecord.MISSING; ground_altitude = AltosRecord.MISSING; ground_pressure = AltosRecord.MISSING; @@ -158,10 +177,15 @@ public class AltosState implements Cloneable { prev_speed = AltosRecord.MISSING; prev_acceleration = AltosRecord.MISSING; + prev_max_height = 0; + prev_max_speed = 0; + prev_max_acceleration = 0; + battery_voltage = AltosRecord.MISSING; pyro_voltage = AltosRecord.MISSING; apogee_voltage = AltosRecord.MISSING; main_voltage = AltosRecord.MISSING; + ignitor_voltage = null; speed = AltosRecord.MISSING; @@ -219,7 +243,7 @@ public class AltosState implements Cloneable { return; } - report_time = old.report_time; + received_time = old.received_time; time = old.time; time_change = 0; tick = old.tick; @@ -232,6 +256,12 @@ public class AltosState implements Cloneable { boost = old.boost; rssi = old.rssi; status = old.status; + device_type = old.device_type; + config_major = old.config_major; + config_minor = old.config_minor; + apogee_delay = old.apogee_delay; + main_deploy = old.main_deploy; + flight_log_max = old.flight_log_max; set = 0; @@ -245,11 +275,16 @@ public class AltosState implements Cloneable { temperature = old.temperature; apogee_voltage = old.apogee_voltage; main_voltage = old.main_voltage; + ignitor_voltage = old.ignitor_voltage; speed = old.speed; prev_height = old.height; prev_speed = old.speed; prev_acceleration = old.acceleration; + + prev_max_height = old.max_height; + prev_max_speed = old.max_speed; + prev_max_acceleration = old.max_acceleration; prev_time = old.time; max_height = old.max_height; @@ -343,7 +378,7 @@ public class AltosState implements Cloneable { else height = AltosRecord.MISSING; - if (height != AltosRecord.MISSING && height > max_height) + if (height != AltosRecord.MISSING && height > prev_max_height) max_height = height; update_speed(); @@ -394,31 +429,34 @@ public class AltosState implements Cloneable { } } } - if (boost && speed != AltosRecord.MISSING && speed > max_speed) + if (boost && speed != AltosRecord.MISSING && speed > prev_max_speed) max_speed = speed; } void update_accel() { - double ground = ground_accel; - - if (ground == AltosRecord.MISSING) - ground = ground_accel_avg; - if (accel == AltosRecord.MISSING) - return; - if (ground == AltosRecord.MISSING) - return; - if (accel_plus_g == AltosRecord.MISSING) - return; - if (accel_minus_g == AltosRecord.MISSING) - return; - - double counts_per_g = (accel_minus_g - accel_plus_g) / 2.0; - double counts_per_mss = counts_per_g / 9.80665; - - acceleration = (ground - accel) / counts_per_mss; + if (kalman_acceleration != AltosRecord.MISSING) { + acceleration = kalman_acceleration; + } else { + double ground = ground_accel; + + if (ground == AltosRecord.MISSING) + ground = ground_accel_avg; + if (accel == AltosRecord.MISSING) + return; + if (ground == AltosRecord.MISSING) + return; + if (accel_plus_g == AltosRecord.MISSING) + return; + if (accel_minus_g == AltosRecord.MISSING) + return; + + double counts_per_g = (accel_minus_g - accel_plus_g) / 2.0; + double counts_per_mss = counts_per_g / 9.80665; + acceleration = (ground - accel) / counts_per_mss; + } /* Only look at accelerometer data under boost */ - if (boost && acceleration != AltosRecord.MISSING && (max_acceleration == AltosRecord.MISSING || acceleration > max_acceleration)) + if (boost && acceleration != AltosRecord.MISSING && acceleration > prev_max_acceleration) max_acceleration = acceleration; update_speed(); } @@ -502,6 +540,26 @@ public class AltosState implements Cloneable { } + public void set_device_type(int device_type) { + this.device_type = device_type; + } + + public void set_config(int major, int minor, int apogee_delay, int main_deploy, int flight_log_max) { + config_major = major; + config_minor = minor; + this.apogee_delay = apogee_delay; + this.main_deploy = main_deploy; + this.flight_log_max = flight_log_max; + } + + public void set_callsign(String callsign) { + this.callsign = callsign; + } + + public void set_firmware_version(String version) { + firmware_version = version; + } + public void set_flight(int flight) { /* When the flight changes, reset the state */ @@ -538,6 +596,10 @@ public class AltosState implements Cloneable { } } + public void set_received_time(long ms) { + received_time = ms; + } + public void set_altitude(double altitude) { if (altitude != AltosRecord.MISSING) { this.altitude = altitude; @@ -577,6 +639,8 @@ public class AltosState implements Cloneable { kalman_speed = speed; kalman_acceleration = acceleration; update_vertical_pos(); + update_speed(); + update_accel(); } } @@ -672,6 +736,9 @@ public class AltosState implements Cloneable { } } + public void set_ignitor_voltage(double[] voltage) { + this.ignitor_voltage = voltage; + } public double time_since_boost() { if (tick == AltosRecord.MISSING) @@ -702,6 +769,13 @@ public class AltosState implements Cloneable { temp_gps = null; } + public AltosState clone() { + AltosState s = new AltosState(); + s.copy(this); + return s; + } + + public void init (AltosRecord cur, AltosState prev_state) { System.out.printf ("init\n"); @@ -721,7 +795,7 @@ public class AltosState implements Cloneable { set_kalman(cur.kalman_height, cur.kalman_speed, cur.kalman_acceleration); - report_time = System.currentTimeMillis(); + received_time = System.currentTimeMillis(); set_temperature(cur.temperature()); set_apogee_voltage(cur.drogue_voltage()); @@ -742,12 +816,6 @@ public class AltosState implements Cloneable { } - public AltosState clone() { - AltosState s = new AltosState(); - s.copy(this); - return s; - } - public AltosState(AltosRecord cur) { init(cur, null); } @@ -756,6 +824,7 @@ public class AltosState implements Cloneable { init(cur, prev); } + public AltosState () { init(); } diff --git a/altoslib/AltosTelemetry.java b/altoslib/AltosTelemetry.java index b84455d3..82e5400e 100644 --- a/altoslib/AltosTelemetry.java +++ b/altoslib/AltosTelemetry.java @@ -43,6 +43,10 @@ public abstract class AltosTelemetry implements AltosStateUpdate { } public void update_state(AltosState state) { + state.set_serial(serial); + state.set_tick(tick); + state.set_rssi(rssi, status); + state.set_received_time(received_time); } final static int PKT_APPEND_STATUS_1_CRC_OK = (1 << 7); @@ -56,9 +60,11 @@ public abstract class AltosTelemetry implements AltosStateUpdate { final static int packet_type_location = 0x05; 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; - final static int packet_type_Mini = 0x10; + final static int packet_type_mega_sensor = 0x08; + final static int packet_type_mega_data = 0x09; + final static int packet_type_metrum_sensor = 0x0a; + final static int packet_type_metrum_data = 0x0b; + final static int packet_type_mini = 0x10; static AltosTelemetry parse_hex(String hex) throws ParseException, AltosCRCException { AltosTelemetry telem = null; @@ -87,37 +93,7 @@ public abstract class AltosTelemetry implements AltosStateUpdate { /* length, data ..., rssi, status, checksum -- 4 bytes extra */ switch (bytes.length) { case AltosLib.ao_telemetry_standard_len + 4: - int type = AltosLib.uint8(bytes, 4 + 1); -/* - switch (type) { - case packet_type_TM_sensor: - case packet_type_Tm_sensor: - case packet_type_Tn_sensor: - telem = new AltosTelemetrySensor(bytes); - break; - case packet_type_configuration: - telem = new AltosTelemetryConfiguration(bytes); - break; - case packet_type_location: - telem = new AltosTelemetryLocation(bytes); - break; - case packet_type_satellite: - telem = new AltosTelemetrySatellite(bytes); - break; - case packet_type_companion: - telem = new AltosTelemetryCompanion(bytes); - break; - case packet_type_MM_sensor: - telem = new AltosTelemetryMegaSensor(bytes); - break; - case packet_type_MM_data: - telem = new AltosTelemetryMegaData(bytes); - break; - default: - telem = new AltosTelemetryRaw(bytes); - break; - } -*/ + telem = AltosTelemetryStandard.parse_hex(bytes); break; case AltosLib.ao_telemetry_0_9_len + 4: telem = new AltosTelemetryLegacy(bytes); diff --git a/altoslib/AltosTelemetryConfiguration.java b/altoslib/AltosTelemetryConfiguration.java new file mode 100644 index 00000000..4c9bdd1f --- /dev/null +++ b/altoslib/AltosTelemetryConfiguration.java @@ -0,0 +1,55 @@ +/* + * Copyright © 2011 Keith Packard + * + * 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_1; + + +public class AltosTelemetryConfiguration extends AltosTelemetryStandard { + int device_type; + int flight; + int config_major; + int config_minor; + int apogee_delay; + int main_deploy; + int flight_log_max; + String callsign; + String version; + + public AltosTelemetryConfiguration(int[] bytes) { + super(bytes); + + device_type = uint8(5); + flight = uint16(6); + config_major = uint8(8); + config_minor = uint8(9); + apogee_delay = uint16(10); + main_deploy = uint16(12); + flight_log_max = uint16(14); + callsign = string(16, 8); + version = string(24, 8); + } + + public void update_state(AltosState state) { + super.update_state(state); + state.set_device_type(device_type); + state.set_flight(flight); + state.set_config(config_major, config_minor, apogee_delay, main_deploy, flight_log_max); + + state.set_callsign(callsign); + state.set_firmware_version(version); + } +} diff --git a/altoslib/AltosTelemetryLegacy.java b/altoslib/AltosTelemetryLegacy.java index 45e5c315..95cbbeed 100644 --- a/altoslib/AltosTelemetryLegacy.java +++ b/altoslib/AltosTelemetryLegacy.java @@ -546,7 +546,7 @@ public class AltosTelemetryLegacy extends AltosTelemetry { state.set_accel(accel); if (kalman_height != AltosRecord.MISSING) state.set_kalman(kalman_height, kalman_speed, kalman_acceleration); - state.set_temperature(AltosEepromTM.thermometer_to_temperature(temp)); + state.set_temperature(AltosConvert.thermometer_to_temperature(temp)); state.set_battery_voltage(AltosConvert.cc_battery_to_voltage(batt)); state.set_apogee_voltage(AltosConvert.cc_ignitor_to_voltage(apogee)); state.set_main_voltage(AltosConvert.cc_ignitor_to_voltage(main)); diff --git a/altoslib/AltosTelemetryLocation.java b/altoslib/AltosTelemetryLocation.java new file mode 100644 index 00000000..fa3c24d0 --- /dev/null +++ b/altoslib/AltosTelemetryLocation.java @@ -0,0 +1,88 @@ +/* + * Copyright © 2011 Keith Packard + * + * 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_1; + + +public class AltosTelemetryLocation extends AltosTelemetryStandard { + int flags; + int altitude; + int latitude; + int longitude; + int year; + int month; + int day; + int hour; + int minute; + int second; + int pdop; + int hdop; + int vdop; + int mode; + int ground_speed; + int climb_rate; + int course; + + public AltosTelemetryLocation(int[] bytes) { + super(bytes); + + flags = uint8(5); + altitude = int16(6); + latitude = uint32(8); + longitude = uint32(12); + year = uint8(16); + month = uint8(17); + day = uint8(18); + hour = uint8(19); + minute = uint8(20); + second = uint8(21); + pdop = uint8(22); + hdop = uint8(23); + vdop = uint8(24); + mode = uint8(25); + ground_speed = uint16(26); + climb_rate = int16(28); + course = uint8(30); + } + + public void update_state(AltosState state) { + super.update_state(state); + AltosGPS gps = state.make_temp_gps(); + + gps.nsat = flags & 0xf; + gps.locked = (flags & (1 << 4)) != 0; + gps.connected = (flags & (1 << 5)) != 0; + + if (gps.locked) { + gps.lat = latitude * 1.0e-7; + gps.lon = longitude * 1.0e-7; + gps.alt = altitude; + gps.year = 2000 + year; + gps.month = month; + gps.day = day; + gps.hour = hour; + gps.minute = minute; + gps.second = second; + gps.ground_speed = ground_speed * 1.0e-2; + gps.course = course * 2; + gps.climb_rate = climb_rate * 1.0e-2; + gps.hdop = hdop; + gps.vdop = vdop; + } + state.set_temp_gps(); + } +} diff --git a/altoslib/AltosTelemetryMegaData.java b/altoslib/AltosTelemetryMegaData.java new file mode 100644 index 00000000..5e6cd580 --- /dev/null +++ b/altoslib/AltosTelemetryMegaData.java @@ -0,0 +1,85 @@ +/* + * Copyright © 2011 Keith Packard + * + * 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_1; + +public class AltosTelemetryMegaData extends AltosTelemetryStandard { + 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 AltosTelemetryMegaData(int[] bytes) { + super(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 void update_state(AltosState state) { + super.update_state(state); + + state.set_state(this.state); + + state.set_battery_voltage(AltosConvert.mega_battery_voltage(v_batt)); + state.set_pyro_voltage(AltosConvert.mega_pyro_voltage(v_pyro)); + + state.set_apogee_voltage(AltosConvert.mega_pyro_voltage(sense[4])); + state.set_main_voltage(AltosConvert.mega_pyro_voltage(sense[5])); + + double voltages[] = new double[4]; + for (int i = 0; i < 4; i++) + voltages[i] = AltosConvert.mega_pyro_voltage(sense[i]); + + state.set_ignitor_voltage(voltages); + + state.set_ground_accel(ground_accel); + state.set_ground_pressure(ground_pres); + state.set_accel_g(accel_plus_g, accel_minus_g); + + state.set_kalman(height, speed/16.0, acceleration / 16.0); + } +} + diff --git a/altoslib/AltosTelemetryMegaSensor.java b/altoslib/AltosTelemetryMegaSensor.java new file mode 100644 index 00000000..7c385cfd --- /dev/null +++ b/altoslib/AltosTelemetryMegaSensor.java @@ -0,0 +1,84 @@ +/* + * Copyright © 2011 Keith Packard + * + * 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_1; + +public class AltosTelemetryMegaSensor extends AltosTelemetryStandard { + 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; + + public AltosTelemetryMegaSensor(int[] bytes) { + super(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); + } + + public void update_state(AltosState state) { + super.update_state(state); + + state.set_accel(accel); + state.set_pressure(pres); + state.set_temperature(temp / 100.0); + + AltosIMU imu = new AltosIMU(); + + imu.accel_x = accel_x; + imu.accel_y = accel_y; + imu.accel_z = accel_z; + + imu.gyro_x = gyro_x; + imu.gyro_y = gyro_y; + imu.gyro_z = gyro_z; + + state.imu = imu; + + AltosMag mag = new AltosMag(); + + mag.x = mag_x; + mag.y = mag_y; + mag.z = mag_z; + + state.mag = mag; + } +} diff --git a/altoslib/AltosTelemetryMetrumData.java b/altoslib/AltosTelemetryMetrumData.java new file mode 100644 index 00000000..d419ab80 --- /dev/null +++ b/altoslib/AltosTelemetryMetrumData.java @@ -0,0 +1,42 @@ +/* + * Copyright © 2011 Keith Packard + * + * 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_1; + + +public class AltosTelemetryMetrumData extends AltosTelemetryStandard { + + int ground_pres; + int ground_accel; + int accel_plus_g; + int accel_minus_g; + + public AltosTelemetryMetrumData(int[] bytes) { + super(bytes); + + ground_pres = int32(8); + ground_accel = int16(12); + accel_plus_g = int16(14); + accel_minus_g = int16(16); + } + + public void update_state(AltosState state) { + state.set_ground_accel(ground_accel); + state.set_accel_g(accel_plus_g, accel_minus_g); + state.set_ground_pressure(ground_pres); + } +} diff --git a/altoslib/AltosTelemetryMetrumSensor.java b/altoslib/AltosTelemetryMetrumSensor.java new file mode 100644 index 00000000..59d34dba --- /dev/null +++ b/altoslib/AltosTelemetryMetrumSensor.java @@ -0,0 +1,69 @@ +/* + * Copyright © 2011 Keith Packard + * + * 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_1; + + +public class AltosTelemetryMetrumSensor extends AltosTelemetryStandard { + int state; + + int accel; + int pres; + int temp; + + int acceleration; + int speed; + int height; + + int v_batt; + int sense_a; + int sense_m; + + public AltosTelemetryMetrumSensor(int[] bytes) { + super(bytes); + + state = int8(5); + accel = int16(6); + pres = int32(8); + temp = int16(12); + + acceleration = int16(14); + speed = int16(16); + height = int16(18); + + v_batt = int16(20); + sense_a = int16(22); + sense_m = int16(24); + } + + public void update_state(AltosState state) { + super.update_state(state); + + state.set_state(this.state); + + state.set_accel(accel); + state.set_ms5607(pres, temp); + + state.set_kalman(height, speed/16.0, acceleration/16.0); + + state.set_battery_voltage(AltosConvert.mega_battery_voltage(v_batt)); + + state.set_apogee_voltage(AltosConvert.mega_pyro_voltage(sense_a)); + state.set_main_voltage(AltosConvert.mega_pyro_voltage(sense_m)); + System.out.printf ("sense_a %d apogee voltage %g\n", sense_a, state.apogee_voltage); + } +} diff --git a/altoslib/AltosTelemetryRaw.java b/altoslib/AltosTelemetryRaw.java new file mode 100644 index 00000000..9ef7787e --- /dev/null +++ b/altoslib/AltosTelemetryRaw.java @@ -0,0 +1,28 @@ +/* + * Copyright © 2011 Keith Packard + * + * 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_1; + +public class AltosTelemetryRaw extends AltosTelemetryStandard { + public AltosTelemetryRaw(int[] bytes) { + super(bytes); + } + + public void update_state(AltosState state) { + super.update_state(state); + } +} diff --git a/altoslib/AltosTelemetrySatellite.java b/altoslib/AltosTelemetrySatellite.java new file mode 100644 index 00000000..3f70f212 --- /dev/null +++ b/altoslib/AltosTelemetrySatellite.java @@ -0,0 +1,50 @@ +/* + * Copyright © 2011 Keith Packard + * + * 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_1; + +public class AltosTelemetrySatellite extends AltosTelemetryStandard { + int channels; + AltosGPSSat[] sats; + + public AltosTelemetrySatellite(int[] bytes) { + super(bytes); + + channels = uint8(5); + if (channels > 12) + channels = 12; + if (channels == 0) + sats = null; + else { + sats = new AltosGPSSat[channels]; + for (int i = 0; i < channels; i++) { + int svid = uint8(6 + i * 2 + 0); + int c_n_1 = uint8(6 + i * 2 + 1); + sats[i] = new AltosGPSSat(svid, c_n_1); + } + } + } + + public void update_state(AltosState state) { + super.update_state(state); + + AltosGPS gps = state.make_temp_gps(); + + gps.cc_gps_sat = sats; + state.set_temp_gps(); + } +} diff --git a/altoslib/AltosTelemetrySensor.java b/altoslib/AltosTelemetrySensor.java new file mode 100644 index 00000000..f89e56c3 --- /dev/null +++ b/altoslib/AltosTelemetrySensor.java @@ -0,0 +1,80 @@ +/* + * Copyright © 2011 Keith Packard + * + * 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_1; + + +public class AltosTelemetrySensor extends AltosTelemetryStandard { + int state; + int accel; + int pres; + int temp; + int v_batt; + int sense_d; + int sense_m; + + int acceleration; + int speed; + int height; + + int ground_accel; + int ground_pres; + int accel_plus_g; + int accel_minus_g; + + public AltosTelemetrySensor(int[] bytes) { + super(bytes); + state = uint8(5); + + accel = int16(6); + pres = int16(8); + temp = int16(10); + v_batt = int16(12); + sense_d = int16(14); + sense_m = int16(16); + + acceleration = int16(18); + speed = int16(20); + height = int16(22); + + ground_pres = int16(24); + ground_accel = int16(26); + accel_plus_g = int16(28); + accel_minus_g = int16(30); + } + + public void update_state(AltosState state) { + super.update_state(state); + + state.set_state(this.state); + if (type == packet_type_TM_sensor) { + state.set_ground_accel(ground_accel); + state.set_accel_g(accel_plus_g, accel_minus_g); + state.set_accel(accel); + } + state.set_ground_pressure(AltosConvert.barometer_to_pressure(ground_pres)); + state.set_pressure(AltosConvert.barometer_to_pressure(pres)); + state.set_temperature(AltosConvert.thermometer_to_temperature(temp)); + state.set_battery_voltage(AltosConvert.cc_battery_to_voltage(v_batt)); + if (type == packet_type_TM_sensor || type == packet_type_Tm_sensor) { + state.set_apogee_voltage(AltosConvert.cc_ignitor_to_voltage(sense_d)); + state.set_main_voltage(AltosConvert.cc_ignitor_to_voltage(sense_m)); + } + + state.set_kalman(height, speed/16.0, acceleration / 16.0); + } +} diff --git a/altoslib/AltosTelemetryStandard.java b/altoslib/AltosTelemetryStandard.java new file mode 100644 index 00000000..fa86bf8e --- /dev/null +++ b/altoslib/AltosTelemetryStandard.java @@ -0,0 +1,106 @@ +/* + * Copyright © 2011 Keith Packard + * + * 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_1; + +public abstract class AltosTelemetryStandard extends AltosTelemetry { + int[] bytes; + int type; + + public int int8(int off) { + return AltosLib.int8(bytes, off + 1); + } + + public int uint8(int off) { + return AltosLib.uint8(bytes, off + 1); + } + + public int int16(int off) { + return AltosLib.int16(bytes, off + 1); + } + + public int uint16(int off) { + return AltosLib.uint16(bytes, off + 1); + } + + public int uint32(int off) { + 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 static AltosTelemetry parse_hex(int[] bytes) { + int type = AltosLib.uint8(bytes, 4 + 1); + + AltosTelemetry telem; + switch (type) { + case packet_type_TM_sensor: + case packet_type_Tm_sensor: + case packet_type_Tn_sensor: + telem = new AltosTelemetrySensor(bytes); + break; + case packet_type_configuration: + telem = new AltosTelemetryConfiguration(bytes); + break; + case packet_type_location: + telem = new AltosTelemetryLocation(bytes); + break; + case packet_type_satellite: + telem = new AltosTelemetrySatellite(bytes); + break; +/* + case packet_type_companion: + telem = new AltosTelemetryCompanion(bytes); + break; +*/ + case packet_type_mega_sensor: + telem = new AltosTelemetryMegaSensor(bytes); + break; + case packet_type_mega_data: + telem = new AltosTelemetryMegaData(bytes); + break; + case packet_type_metrum_sensor: + telem = new AltosTelemetryMetrumSensor(bytes); + break; + case packet_type_metrum_data: + telem = new AltosTelemetryMetrumData(bytes); + break; + default: + telem = new AltosTelemetryRaw(bytes); + break; + } + return telem; + } + + public AltosTelemetryStandard(int[] bytes) { + this.bytes = bytes; + + serial = uint16(0); + tick = uint16(2); + type = uint8(4); + } + + public void update_state(AltosState state) { + super.update_state(state); + } +} diff --git a/altoslib/Makefile.am b/altoslib/Makefile.am index 59e0ec1c..87d4d898 100644 --- a/altoslib/Makefile.am +++ b/altoslib/Makefile.am @@ -10,7 +10,19 @@ SRC=. altoslibdir = $(datadir)/java +record_files = \ + AltosEepromRecord.java \ + AltosEepromTeleScience.java \ + AltosRecordCompanion.java \ + AltosRecordIterable.java \ + AltosRecord.java \ + AltosRecordNone.java \ + AltosRecordTM.java \ + AltosRecordMM.java \ + AltosRecordMini.java + altoslib_JAVA = \ + $(record_files) \ AltosLib.java \ AltosConfigData.java \ AltosConfigValues.java \ @@ -25,11 +37,8 @@ altoslib_JAVA = \ AltosEepromIterable.java \ AltosEepromLog.java \ AltosEepromMega.java \ - AltosEepromMegaIterable.java \ - AltosEepromRecord.java \ - AltosEepromTeleScience.java \ + AltosEepromMetrum2.java \ AltosEepromMini.java \ - AltosEepromOldIterable.java \ AltosFile.java \ AltosFlash.java \ AltosFlashListener.java \ @@ -57,13 +66,6 @@ altoslib_JAVA = \ AltosParse.java \ AltosPreferences.java \ AltosPreferencesBackend.java \ - AltosRecordCompanion.java \ - AltosRecordIterable.java \ - AltosRecord.java \ - AltosRecordNone.java \ - AltosRecordTM.java \ - AltosRecordMM.java \ - AltosRecordMini.java \ AltosReplayReader.java \ AltosRomconfig.java \ AltosSensorMM.java \ @@ -72,11 +74,21 @@ altoslib_JAVA = \ AltosStateIterable.java \ AltosStateUpdate.java \ AltosTelemetry.java \ + AltosTelemetryConfiguration.java \ AltosTelemetryFile.java \ AltosTelemetryIterable.java \ AltosTelemetryLegacy.java \ + AltosTelemetryLocation.java \ AltosTelemetryMap.java \ + AltosTelemetryMegaSensor.java \ + AltosTelemetryMegaData.java \ + AltosTelemetryMetrumSensor.java \ + AltosTelemetryMetrumData.java \ AltosTelemetryReader.java \ + AltosTelemetryRaw.java \ + AltosTelemetrySensor.java \ + AltosTelemetrySatellite.java \ + AltosTelemetryStandard.java \ AltosUnitsListener.java \ AltosMs5607.java \ AltosIMU.java \ diff --git a/altosui/AltosAscent.java b/altosui/AltosAscent.java index f8435037..ceba2d1d 100644 --- a/altosui/AltosAscent.java +++ b/altosui/AltosAscent.java @@ -308,7 +308,7 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay { class Lat extends AscentValue { void show (AltosState state, AltosListenerState listener_state) { - if (state.gps != null) + if (state.gps != null && state.gps.connected && state.gps.lat != AltosRecord.MISSING) show(pos(state.gps.lat,"N", "S")); else show("???"); @@ -322,7 +322,7 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay { class Lon extends AscentValue { void show (AltosState state, AltosListenerState listener_state) { - if (state.gps != null) + if (state.gps != null && state.gps.connected && state.gps.lon != AltosRecord.MISSING) show(pos(state.gps.lon,"E", "W")); else show("???"); diff --git a/altosui/AltosDescent.java b/altosui/AltosDescent.java index 2b6575cb..35efce16 100644 --- a/altosui/AltosDescent.java +++ b/altosui/AltosDescent.java @@ -278,7 +278,7 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay { class Lat extends DescentValue { void show (AltosState state, AltosListenerState listener_state) { - if (state.gps != null && state.gps.connected) + if (state.gps != null && state.gps.connected && state.gps.lat != AltosRecord.MISSING) show(pos(state.gps.lat,"N", "S")); else show("???"); @@ -292,7 +292,7 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay { class Lon extends DescentValue { void show (AltosState state, AltosListenerState listener_state) { - if (state.gps != null && state.gps.connected) + if (state.gps != null && state.gps.connected && state.gps.lon != AltosRecord.MISSING) show(pos(state.gps.lon,"W", "E")); else show("???"); diff --git a/altosui/AltosDisplayThread.java b/altosui/AltosDisplayThread.java index 70144fb2..7a750c86 100644 --- a/altosui/AltosDisplayThread.java +++ b/altosui/AltosDisplayThread.java @@ -110,7 +110,7 @@ public class AltosDisplayThread extends Thread { */ if (state.state >= Altos.ao_flight_drogue && (last || - System.currentTimeMillis() - state.report_time >= 15000 || + System.currentTimeMillis() - state.received_time >= 15000 || state.state == Altos.ao_flight_landed)) { if (Math.abs(state.speed) < 20 && state.height < 100) diff --git a/altosui/AltosEepromDownload.java b/altosui/AltosEepromDownload.java index 95b17e2a..931b55fd 100644 --- a/altosui/AltosEepromDownload.java +++ b/altosui/AltosEepromDownload.java @@ -33,9 +33,6 @@ public class AltosEepromDownload implements Runnable { Thread eeprom_thread; AltosEepromMonitor monitor; - int flight; - int serial; - int year, month, day; boolean want_file; FileWriter eeprom_file; LinkedList eeprom_pending; @@ -44,7 +41,7 @@ public class AltosEepromDownload implements Runnable { ActionListener listener; boolean success; ParseException parse_exception; - String extension; + AltosState state; private void FlushPending() throws IOException { for (String s : flights.config_data) { @@ -59,15 +56,19 @@ public class AltosEepromDownload implements Runnable { private void CheckFile(boolean force) throws IOException { if (eeprom_file != null) return; - if (force || (flight != 0 && want_file)) { + if (force || (state.flight != 0 && want_file)) { AltosFile eeprom_name; - - if (extension == null) - extension = "data"; - if (year != 0 && month != 0 && day != 0) - eeprom_name = new AltosFile(year, month, day, serial, flight, extension); - else - eeprom_name = new AltosFile(serial, flight, extension); + AltosGPS gps = state.gps; + + if (gps != null && + gps.year != AltosRecord.MISSING && + gps.month != AltosRecord.MISSING && + gps.day != AltosRecord.MISSING) + { + eeprom_name = new AltosFile(gps.year, gps.month, gps.day, + state.serial, state.flight, "eeprom"); + } else + eeprom_name = new AltosFile(state.serial, state.flight, "eeprom"); eeprom_file = new FileWriter(eeprom_name); if (eeprom_file != null) { @@ -78,270 +79,49 @@ public class AltosEepromDownload implements Runnable { } } - void Log(AltosEepromRecord r) throws IOException { + boolean done; + boolean start; + + void LogEeprom(AltosEeprom r) throws IOException { if (r.cmd != Altos.AO_LOG_INVALID) { - String log_line = String.format("%c %4x %4x %4x\n", - r.cmd, r.tick, r.a, r.b); + String line = r.string(); if (eeprom_file != null) - eeprom_file.write(log_line); + eeprom_file.write(line); else - eeprom_pending.add(log_line); + eeprom_pending.add(line); } } - void set_serial(int in_serial) { - serial = in_serial; - monitor.set_serial(serial); - } - - void set_flight(int in_flight) { - flight = in_flight; - monitor.set_flight(flight); - } - - boolean done; - int state; - - void CaptureFull(AltosEepromChunk eechunk) throws IOException { - boolean any_valid = false; - - extension = "eeprom"; - set_serial(flights.config_data.serial); - for (int i = 0; i < AltosEepromChunk.chunk_size && !done; i += AltosEepromRecord.record_length) { - try { - AltosEepromRecord r = new AltosEepromRecord(eechunk, i); - if (r.cmd == Altos.AO_LOG_FLIGHT) - set_flight(r.b); - - /* Monitor state transitions to update display */ - if (r.cmd == Altos.AO_LOG_STATE && r.a <= Altos.ao_flight_landed) { - state = r.a; - if (state > Altos.ao_flight_pad) - want_file = true; - } - - if (r.cmd == Altos.AO_LOG_GPS_DATE) { - year = 2000 + (r.a & 0xff); - month = (r.a >> 8) & 0xff; - day = (r.b & 0xff); - want_file = true; - } - if (r.cmd == Altos.AO_LOG_STATE && r.a == Altos.ao_flight_landed) - done = true; - if (r.cmd != AltosLib.AO_LOG_INVALID) - any_valid = true; - Log(r); - } catch (ParseException pe) { - if (parse_exception == null) - parse_exception = pe; - } - } - - if (!any_valid) - done = true; - - CheckFile(false); - } - - boolean start; - int tiny_tick; - - void CaptureTiny (AltosEepromChunk eechunk) throws IOException { + void CaptureEeprom(AltosEepromChunk eechunk, int log_format) throws IOException { boolean any_valid = false; - extension = "eeprom"; - set_serial(flights.config_data.serial); - for (int i = 0; i < eechunk.data.length && !done; i += 2) { - int v = eechunk.data16(i); - AltosEepromRecord r; - - if (i == 0 && start) { - tiny_tick = 0; - start = false; - set_flight(v); - r = new AltosEepromRecord(Altos.AO_LOG_FLIGHT, tiny_tick, 0, v); - any_valid = true; - } else { - int s = v ^ 0x8000; - - if (Altos.ao_flight_startup <= s && s <= Altos.ao_flight_invalid) { - state = s; - r = new AltosEepromRecord(Altos.AO_LOG_STATE, tiny_tick, state, 0); - if (state == Altos.ao_flight_landed) - done = true; - state = s; - any_valid = true; - } else { - if (v != 0xffff) - any_valid = true; - - r = new AltosEepromRecord(Altos.AO_LOG_PRESSURE, tiny_tick, 0, v); - - /* - * The flight software records ascent data every 100ms, and descent - * data every 1s. - */ - if (state < Altos.ao_flight_drogue) - tiny_tick += 10; - else - tiny_tick += 100; - } - } - Log(r); - } - CheckFile(false); - if (!any_valid) - done = true; - } - - void LogTeleScience(AltosEepromTeleScience r) throws IOException { - if (r.type != Altos.AO_LOG_INVALID) { - String log_line = String.format("%c %4x %4x %d %5d %5d %5d %5d %5d %5d %5d %5d %5d %5d %5d %5d\n", - r.type, r.tick, r.tm_tick, r.tm_state, - r.data[0], r.data[1], r.data[2], r.data[3], - r.data[4], r.data[5], r.data[6], r.data[7], - r.data[8], r.data[9], r.data[10], r.data[11]); - if (eeprom_file != null) - eeprom_file.write(log_line); - else - eeprom_pending.add(log_line); - } - } - - boolean telescience_start; - - void CaptureTeleScience (AltosEepromChunk eechunk) throws IOException { - boolean any_valid = false; - - extension = "science"; - for (int i = 0; i < AltosEepromChunk.chunk_size && !done; i += AltosEepromTeleScience.record_length) { - try { - AltosEepromTeleScience r = new AltosEepromTeleScience(eechunk, i); - if (r.type == AltosEepromTeleScience.AO_LOG_TELESCIENCE_START) { - if (telescience_start) { - done = true; - break; - } - set_serial(r.data[0]); - set_flight(r.data[1]); - telescience_start = true; - } else { - if (!telescience_start) - break; - } - state = r.tm_state; - want_file =true; - any_valid = true; - LogTeleScience(r); - } catch (ParseException pe) { - if (parse_exception == null) - parse_exception = pe; - } - } + int record_length = 8; - CheckFile(false); - if (!any_valid) - done = true; - } + state.set_serial(flights.config_data.serial); - void LogMega(AltosEepromMega r) throws IOException { - if (r.cmd != Altos.AO_LOG_INVALID) { - String log_line = String.format("%c %4x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x\n", - r.cmd, r.tick, - r.data8[0], r.data8[1], r.data8[2], r.data8[3], - r.data8[4], r.data8[5], r.data8[6], r.data8[7], - r.data8[8], r.data8[9], r.data8[10], r.data8[11], - r.data8[12], r.data8[13], r.data8[14], r.data8[15], - r.data8[16], r.data8[17], r.data8[18], r.data8[19], - r.data8[20], r.data8[21], r.data8[22], r.data8[23], - r.data8[24], r.data8[25], r.data8[26], r.data8[27]); - if (eeprom_file != null) - eeprom_file.write(log_line); - else - eeprom_pending.add(log_line); - } - } + for (int i = 0; i < AltosEepromChunk.chunk_size && !done; i += record_length) { + AltosEeprom r = eechunk.eeprom(i, log_format); - void CaptureMega(AltosEepromChunk eechunk) throws IOException { - boolean any_valid = false; + record_length = r.record_length(); - extension = "mega"; - set_serial(flights.config_data.serial); - for (int i = 0; i < AltosEepromChunk.chunk_size && !done; i += AltosEepromMega.record_length) { - try { - AltosEepromMega r = new AltosEepromMega(eechunk, i); - if (r.cmd == Altos.AO_LOG_FLIGHT) - set_flight(r.data16(0)); - - /* Monitor state transitions to update display */ - if (r.cmd == Altos.AO_LOG_STATE && r.data16(0) <= Altos.ao_flight_landed) { - state = r.data16(0); - if (state > Altos.ao_flight_pad) - want_file = true; - } + r.update_state(state); - if (r.cmd == Altos.AO_LOG_GPS_TIME) { - year = 2000 + r.data8(14); - month = r.data8(15); - day = r.data8(16); + /* Monitor state transitions to update display */ + if (state.state != AltosLib.ao_flight_invalid && + state.state <= AltosLib.ao_flight_landed) + { + if (state.state > Altos.ao_flight_pad) want_file = true; - } - - if (r.cmd == Altos.AO_LOG_STATE && r.data16(0) == Altos.ao_flight_landed) + if (state.state == AltosLib.ao_flight_landed) done = true; - if (r.cmd != AltosLib.AO_LOG_INVALID) - any_valid = true; - LogMega(r); - } catch (ParseException pe) { - if (parse_exception == null) - parse_exception = pe; } - } - if (!any_valid) - done = true; - CheckFile(false); - } - - void LogMini(AltosEepromMini r) throws IOException { - if (r.cmd != Altos.AO_LOG_INVALID) { - String log_line = String.format("%c %4x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x\n", - r.cmd, r.tick, - r.data8[0], r.data8[1], r.data8[2], r.data8[3], - r.data8[4], r.data8[5], r.data8[6], r.data8[7], - r.data8[8], r.data8[9], r.data8[10], r.data8[11]); - if (eeprom_file != null) - eeprom_file.write(log_line); - else - eeprom_pending.add(log_line); - } - } + if (state.gps != null) + want_file = true; - void CaptureMini(AltosEepromChunk eechunk) throws IOException { - boolean any_valid = false; - - extension = "mini"; - set_serial(flights.config_data.serial); - for (int i = 0; i < AltosEepromChunk.chunk_size && !done; i += AltosEepromMini.record_length) { - try { - AltosEepromMini r = new AltosEepromMini(eechunk, i); - if (r.cmd == Altos.AO_LOG_FLIGHT) - set_flight(r.data16(0)); - - /* Monitor state transitions to update display */ - if (r.cmd == Altos.AO_LOG_STATE && r.data16(0) <= Altos.ao_flight_landed) { - state = r.data16(0); - if (state > Altos.ao_flight_pad) - want_file = true; - } - - if (r.cmd == Altos.AO_LOG_STATE && r.data16(0) == Altos.ao_flight_landed) - done = true; + if (r.valid) { any_valid = true; - LogMini(r); - } catch (ParseException pe) { - if (parse_exception == null) - parse_exception = pe; + LogEeprom(r); } } if (!any_valid) @@ -350,15 +130,12 @@ public class AltosEepromDownload implements Runnable { CheckFile(false); } - void CaptureTelemetry(AltosEepromChunk eechunk) throws IOException { - - } - void CaptureLog(AltosEepromLog log) throws IOException, InterruptedException, TimeoutException { int block, state_block = 0; int log_format = flights.config_data.log_format; - state = 0; + state = new AltosState(); + done = false; start = true; @@ -366,10 +143,6 @@ public class AltosEepromDownload implements Runnable { throw new IOException("no serial number found"); /* Reset per-capture variables */ - flight = 0; - year = 0; - month = 0; - day = 0; want_file = false; eeprom_file = null; eeprom_pending = new LinkedList(); @@ -377,9 +150,12 @@ public class AltosEepromDownload implements Runnable { /* Set serial number in the monitor dialog window */ /* Now scan the eeprom, reading blocks of data and converting to .eeprom file form */ - state = 0; state_block = log.start_block; + state_block = log.start_block; for (block = log.start_block; !done && block < log.end_block; block++) { - monitor.set_value(AltosLib.state_name(state), state, block - state_block, block - log.start_block); + monitor.set_value(state.state_name(), + state.state, + block - state_block, + block - log.start_block); AltosEepromChunk eechunk = new AltosEepromChunk(serial_line, block, block == log.start_block); @@ -397,33 +173,7 @@ public class AltosEepromDownload implements Runnable { } } - switch (log_format) { - case AltosLib.AO_LOG_FORMAT_FULL: - extension = "eeprom"; - CaptureFull(eechunk); - break; - case AltosLib.AO_LOG_FORMAT_TINY: - extension = "eeprom"; - CaptureTiny(eechunk); - break; - case AltosLib.AO_LOG_FORMAT_TELEMETRY: - extension = "telem"; - CaptureTelemetry(eechunk); - break; - case AltosLib.AO_LOG_FORMAT_TELESCIENCE: - extension = "science"; - CaptureTeleScience(eechunk); - break; - case AltosLib.AO_LOG_FORMAT_TELEMEGA: - extension = "mega"; - CaptureMega(eechunk); - break; - case AltosLib.AO_LOG_FORMAT_EASYMINI: - case AltosLib.AO_LOG_FORMAT_TELEMINI: - extension = "eeprom"; - CaptureMini(eechunk); - break; - } + CaptureEeprom (eechunk, log_format); } CheckFile(true); if (eeprom_file != null) { diff --git a/altosui/AltosFlightStatus.java b/altosui/AltosFlightStatus.java index 0be7bb51..6383e5b9 100644 --- a/altosui/AltosFlightStatus.java +++ b/altosui/AltosFlightStatus.java @@ -126,7 +126,7 @@ public class AltosFlightStatus extends JComponent implements AltosFlightDisplay class LastPacket extends FlightValue { void show(AltosState state, AltosListenerState listener_state) { - long secs = (System.currentTimeMillis() - state.report_time + 500) / 1000; + long secs = (System.currentTimeMillis() - state.received_time + 500) / 1000; value.setText(String.format("%d", secs)); } public LastPacket(GridBagLayout layout, int x) { diff --git a/altosui/AltosFlightUI.java b/altosui/AltosFlightUI.java index 423cf10c..1c450ce3 100644 --- a/altosui/AltosFlightUI.java +++ b/altosui/AltosFlightUI.java @@ -102,7 +102,7 @@ public class AltosFlightUI extends AltosUIFrame implements AltosFlightDisplay, A status_update.saved_state = state; if (state == null) - state = new AltosState(new AltosRecord()); + state = new AltosState(); pad.show(state, listener_state); diff --git a/altosui/AltosIdleMonitorUI.java b/altosui/AltosIdleMonitorUI.java index bbab017f..f6a91de8 100644 --- a/altosui/AltosIdleMonitorUI.java +++ b/altosui/AltosIdleMonitorUI.java @@ -65,13 +65,13 @@ public class AltosIdleMonitorUI extends AltosUIFrame implements AltosFlightDispl public void show(AltosState state, AltosListenerState listener_state) { status_update.saved_state = state; - try { +// try { pad.show(state, listener_state); flightStatus.show(state, listener_state); flightInfo.show(state, listener_state); - } catch (Exception e) { - System.out.print("Show exception" + e); - } +// } catch (Exception e) { +// System.out.print("Show exception " + e); +// } } public void update(final AltosState state, final AltosListenerState listener_state) { diff --git a/altosui/AltosInfoTable.java b/altosui/AltosInfoTable.java index 8601d76f..8906920b 100644 --- a/altosui/AltosInfoTable.java +++ b/altosui/AltosInfoTable.java @@ -155,10 +155,14 @@ public class AltosInfoTable extends JTable { else info_add_row(1, "GPS", " missing"); info_add_row(1, "Satellites", "%6d", state.gps.nsat); - info_add_deg(1, "Latitude", state.gps.lat, 'N', 'S'); - info_add_deg(1, "Longitude", state.gps.lon, 'E', 'W'); - info_add_row(1, "GPS altitude", "%6d", state.gps.alt); - info_add_row(1, "GPS height", "%6.0f", state.gps_height); + if (state.gps.lat != AltosRecord.MISSING) + info_add_deg(1, "Latitude", state.gps.lat, 'N', 'S'); + if (state.gps.lon != AltosRecord.MISSING) + info_add_deg(1, "Longitude", state.gps.lon, 'E', 'W'); + if (state.gps.alt != AltosRecord.MISSING) + info_add_row(1, "GPS altitude", "%8.1f", state.gps.alt); + if (state.gps_height != AltosRecord.MISSING) + info_add_row(1, "GPS height", "%8.1f", state.gps_height); /* The SkyTraq GPS doesn't report these values */ /* @@ -195,14 +199,16 @@ public class AltosInfoTable extends JTable { info_add_deg(1, "Pad longitude", state.pad_lon, 'E', 'W'); info_add_row(1, "Pad GPS alt", "%6.0f m", state.pad_alt); } - info_add_row(1, "GPS date", "%04d-%02d-%02d", - state.gps.year, - state.gps.month, - state.gps.day); - info_add_row(1, "GPS time", " %02d:%02d:%02d", - state.gps.hour, - state.gps.minute, - state.gps.second); + if (state.gps.year != AltosRecord.MISSING) + info_add_row(1, "GPS date", "%04d-%02d-%02d", + state.gps.year, + state.gps.month, + state.gps.day); + if (state.gps.hour != AltosRecord.MISSING) + info_add_row(1, "GPS time", " %02d:%02d:%02d", + state.gps.hour, + state.gps.minute, + state.gps.second); //int nsat_vis = 0; int c; diff --git a/altosui/AltosLanded.java b/altosui/AltosLanded.java index 38f273cf..4cdaa3df 100644 --- a/altosui/AltosLanded.java +++ b/altosui/AltosLanded.java @@ -103,7 +103,8 @@ public class AltosLanded extends JComponent implements AltosFlightDisplay, Actio class Lat extends LandedValue { void show (AltosState state, AltosListenerState listener_state) { - if (state.gps != null && state.gps.connected) + show(); + if (state.gps != null && state.gps.connected && state.gps.lat != AltosRecord.MISSING) show(pos(state.gps.lat,"N", "S")); else show("???"); @@ -118,7 +119,7 @@ public class AltosLanded extends JComponent implements AltosFlightDisplay, Actio class Lon extends LandedValue { void show (AltosState state, AltosListenerState listener_state) { show(); - if (state.gps != null && state.gps.connected) + if (state.gps != null && state.gps.connected && state.gps.lon != AltosRecord.MISSING) show(pos(state.gps.lon,"E", "W")); else show("???"); diff --git a/altosui/AltosPad.java b/altosui/AltosPad.java index fed009cc..e9c973de 100644 --- a/altosui/AltosPad.java +++ b/altosui/AltosPad.java @@ -310,17 +310,23 @@ public class AltosPad extends JComponent implements AltosFlightDisplay { class PadLat extends LaunchValue { void show (AltosState state, AltosListenerState listener_state) { - if (state == null || state.gps == null) { - hide(); - } else { - if (state.state < AltosLib.ao_flight_pad) { - show(pos(state.gps.lat,"N", "S")); - set_label("Latitude"); - } else { - show(pos(state.pad_lat,"N", "S")); - set_label("Pad Latitude"); + double lat = AltosRecord.MISSING; + String label = null; + + if (state != null) { + if (state.state < AltosLib.ao_flight_pad && state.gps != null && state.gps.lat != AltosRecord.MISSING) { + lat = state.gps.lat; + label = "Latitude"; + } else { + lat = state.pad_lat; + label = "Pad Latitude"; } } + if (lat != AltosRecord.MISSING) { + show(pos(lat,"E", "W")); + set_label(label); + } else + hide(); } public PadLat (GridBagLayout layout, int y) { super (layout, y, "Pad Latitude"); @@ -331,17 +337,23 @@ public class AltosPad extends JComponent implements AltosFlightDisplay { class PadLon extends LaunchValue { void show (AltosState state, AltosListenerState listener_state) { - if (state == null || state.gps == null) { - hide(); - } else { - if (state.state < AltosLib.ao_flight_pad) { - show(pos(state.gps.lon,"E", "W")); - set_label("Longitude"); - } else { - show(pos(state.pad_lon,"E", "W")); - set_label("Pad Longitude"); + double lon = AltosRecord.MISSING; + String label = null; + + if (state != null) { + if (state.state < AltosLib.ao_flight_pad && state.gps != null && state.gps.lon != AltosRecord.MISSING) { + lon = state.gps.lon; + label = "Longitude"; + } else { + lon = state.pad_lon; + label = "Pad Longitude"; } } + if (lon != AltosRecord.MISSING) { + show(pos(lon,"E", "W")); + set_label(label); + } else + hide(); } public PadLon (GridBagLayout layout, int y) { super (layout, y, "Pad Longitude"); @@ -352,21 +364,23 @@ public class AltosPad extends JComponent implements AltosFlightDisplay { class PadAlt extends LaunchValue { void show (AltosState state, AltosListenerState listener_state) { - if (state == null) - hide(); - else { - if (state.state < AltosLib.ao_flight_pad && state.gps != null) { - show("%4.0f m", state.gps.alt); - set_label("Altitude"); + double alt = AltosRecord.MISSING; + String label = null; + + if (state != null) { + if (state.state < AltosLib.ao_flight_pad && state.gps != null && state.gps.alt != AltosRecord.MISSING) { + alt = state.gps.alt; + label = "Altitude"; } else { - if (state.pad_alt == AltosRecord.MISSING) - hide(); - else { - show("%4.0f m", state.pad_alt); - set_label("Pad Altitude"); - } + alt = state.pad_alt; + label = "Pad Altitude"; } } + if (alt != AltosRecord.MISSING) { + show("%4.0f m", state.gps.alt); + set_label(label); + } else + hide(); } public PadAlt (GridBagLayout layout, int y) { super (layout, y, "Pad Altitude"); diff --git a/altosui/AltosUI.java b/altosui/AltosUI.java index b47df0d9..151f68fd 100644 --- a/altosui/AltosUI.java +++ b/altosui/AltosUI.java @@ -350,10 +350,10 @@ public class AltosUI extends AltosUIFrame { FileInputStream in; in = new FileInputStream(file); - if (file.getName().endsWith("eeprom")) - return new AltosEepromFile(in); - else + if (file.getName().endsWith("telem")) return new AltosTelemetryFile(in); + else + return new AltosEepromFile(in); } catch (FileNotFoundException fe) { System.out.printf("%s\n", fe.getMessage()); return null; @@ -434,11 +434,10 @@ public class AltosUI extends AltosUIFrame { System.out.printf("Failed to open file '%s'\n", file); return null; } - if (file.getName().endsWith("eeprom")) { - return new AltosEepromFile(in); - } else { + if (file.getName().endsWith("telem")) return new AltosTelemetryFile(in); - } + else + return new AltosEepromFile(in); } static AltosReplayReader replay_file(File file) { @@ -521,6 +520,8 @@ public class AltosUI extends AltosUIFrame { System.out.printf ("process cat\n"); for (AltosState state : eef) { + System.out.printf ("tick %d state %d height %g\n", + state.tick, state.state, state.height); if ((state.set & AltosState.set_gps) != 0) System.out.printf ("time %g lat %g lon %g alt %g\n", state.time_since_boost(), diff --git a/src/core/ao_log.h b/src/core/ao_log.h index a2f342d7..4b09faeb 100644 --- a/src/core/ao_log.h +++ b/src/core/ao_log.h @@ -276,7 +276,8 @@ struct ao_log_metrum { uint16_t flight; /* 4 */ int16_t ground_accel; /* 6 */ uint32_t ground_pres; /* 8 */ - } flight; /* 12 */ + uint32_t ground_temp; /* 12 */ + } flight; /* 16 */ /* AO_LOG_STATE */ struct { uint16_t state; /* 4 */ -- cgit v1.2.3 From 5b976a6651f4eb05d30afc08b9e1f27c7e52ae00 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 5 Sep 2013 11:33:48 -0700 Subject: altoslib: Finish AltosState changes. Update version number. Removes all of the AltosRecord bits, changes the monitor idle bits to have per-object state updaters. Signed-off-by: Keith Packard --- .../org/altusmetrum/AltosDroid/AltosBluetooth.java | 2 +- .../src/org/altusmetrum/AltosDroid/AltosDroid.java | 8 +- .../AltosDroid/AltosDroidPreferences.java | 2 +- .../org/altusmetrum/AltosDroid/AltosDroidTab.java | 2 +- .../src/org/altusmetrum/AltosDroid/AltosVoice.java | 2 +- .../src/org/altusmetrum/AltosDroid/TabAscent.java | 6 +- .../src/org/altusmetrum/AltosDroid/TabDescent.java | 6 +- .../src/org/altusmetrum/AltosDroid/TabLanded.java | 2 +- .../src/org/altusmetrum/AltosDroid/TabMap.java | 2 +- .../src/org/altusmetrum/AltosDroid/TabPad.java | 10 +- .../altusmetrum/AltosDroid/TelemetryLogger.java | 2 +- .../altusmetrum/AltosDroid/TelemetryReader.java | 2 +- .../altusmetrum/AltosDroid/TelemetryService.java | 2 +- altoslib/AltosAccel.java | 2 +- altoslib/AltosCRCException.java | 2 +- altoslib/AltosCompanion.java | 2 +- altoslib/AltosConfigData.java | 2 +- altoslib/AltosConfigValues.java | 2 +- altoslib/AltosConvert.java | 22 +- altoslib/AltosDebug.java | 2 +- altoslib/AltosDistance.java | 2 +- altoslib/AltosEeprom.java | 2 +- altoslib/AltosEepromBody.java | 2 +- altoslib/AltosEepromBodyIterable.java | 2 +- altoslib/AltosEepromChunk.java | 2 +- altoslib/AltosEepromFile.java | 7 +- altoslib/AltosEepromGPS.java | 2 +- altoslib/AltosEepromHeader.java | 2 +- altoslib/AltosEepromHeaderIterable.java | 2 +- altoslib/AltosEepromIterable.java | 2 +- altoslib/AltosEepromLog.java | 6 +- altoslib/AltosEepromMega.java | 2 +- altoslib/AltosEepromMegaIterable.java | 2 +- altoslib/AltosEepromMetrum.java | 2 +- altoslib/AltosEepromMetrum2.java | 2 +- altoslib/AltosEepromMetrumIterable.java | 2 +- altoslib/AltosEepromMini.java | 9 +- altoslib/AltosEepromMiniIterable.java | 2 +- altoslib/AltosEepromOldIterable.java | 2 +- altoslib/AltosEepromRecord.java | 135 --------- altoslib/AltosEepromTM.java | 2 +- altoslib/AltosEepromTeleScience.java | 57 ---- altoslib/AltosFile.java | 4 +- altoslib/AltosFlash.java | 2 +- altoslib/AltosFlashListener.java | 2 +- altoslib/AltosFlightReader.java | 4 +- altoslib/AltosFrequency.java | 2 +- altoslib/AltosGPS.java | 107 ++++++- altoslib/AltosGPSQuery.java | 97 ------- altoslib/AltosGPSSat.java | 2 +- altoslib/AltosGreatCircle.java | 2 +- altoslib/AltosHeight.java | 2 +- altoslib/AltosHexfile.java | 2 +- altoslib/AltosIMU.java | 56 +++- altoslib/AltosIMUQuery.java | 46 --- altoslib/AltosIdle.java | 39 +++ altoslib/AltosIdleFetch.java | 149 ++++++++++ altoslib/AltosIdleMonitor.java | 115 ++------ altoslib/AltosIdleMonitorListener.java | 2 +- altoslib/AltosIgnite.java | 2 +- altoslib/AltosLib.java | 4 +- altoslib/AltosLine.java | 2 +- altoslib/AltosLink.java | 13 +- altoslib/AltosListenerState.java | 4 +- altoslib/AltosLog.java | 2 +- altoslib/AltosMag.java | 48 ++- altoslib/AltosMma655x.java | 69 +++++ altoslib/AltosMs5607.java | 57 +++- altoslib/AltosMs5607Query.java | 36 --- altoslib/AltosOrderedMegaRecord.java | 52 ---- altoslib/AltosOrderedMetrumRecord.java | 2 +- altoslib/AltosOrderedMiniRecord.java | 52 ---- altoslib/AltosOrderedRecord.java | 63 ---- altoslib/AltosParse.java | 2 +- altoslib/AltosPreferences.java | 2 +- altoslib/AltosPreferencesBackend.java | 2 +- altoslib/AltosPyro.java | 2 +- altoslib/AltosRecord.java | 179 ------------ altoslib/AltosRecordCompanion.java | 38 --- altoslib/AltosRecordIterable.java | 29 -- altoslib/AltosRecordMM.java | 178 ------------ altoslib/AltosRecordMini.java | 133 --------- altoslib/AltosRecordNone.java | 38 --- altoslib/AltosRecordTM.java | 186 ------------ altoslib/AltosRecordTM2.java | 2 +- altoslib/AltosReplayReader.java | 2 +- altoslib/AltosRomconfig.java | 2 +- altoslib/AltosSelfFlash.java | 2 +- altoslib/AltosSensorEMini.java | 70 +++++ altoslib/AltosSensorMM.java | 2 +- altoslib/AltosSensorMega.java | 109 +++++++ altoslib/AltosSensorMetrum.java | 13 +- altoslib/AltosSensorTM.java | 36 ++- altoslib/AltosSpeed.java | 2 +- altoslib/AltosState.java | 321 ++++++++++----------- altoslib/AltosStateIterable.java | 2 +- altoslib/AltosStateUpdate.java | 2 +- altoslib/AltosTelemetry.java | 2 +- altoslib/AltosTelemetryConfiguration.java | 2 +- altoslib/AltosTelemetryFile.java | 7 +- altoslib/AltosTelemetryIterable.java | 65 ++++- altoslib/AltosTelemetryLegacy.java | 66 ++--- altoslib/AltosTelemetryLocation.java | 2 +- altoslib/AltosTelemetryMap.java | 2 +- altoslib/AltosTelemetryMegaData.java | 2 +- altoslib/AltosTelemetryMegaSensor.java | 2 +- altoslib/AltosTelemetryMetrumData.java | 2 +- altoslib/AltosTelemetryMetrumSensor.java | 2 +- altoslib/AltosTelemetryRaw.java | 2 +- altoslib/AltosTelemetryReader.java | 5 +- altoslib/AltosTelemetryRecord.java | 2 +- altoslib/AltosTelemetryRecordCompanion.java | 2 +- altoslib/AltosTelemetryRecordConfiguration.java | 2 +- altoslib/AltosTelemetryRecordGeneral.java | 2 +- altoslib/AltosTelemetryRecordLegacy.java | 58 ++-- altoslib/AltosTelemetryRecordLocation.java | 2 +- altoslib/AltosTelemetryRecordMegaData.java | 2 +- altoslib/AltosTelemetryRecordMegaSensor.java | 2 +- altoslib/AltosTelemetryRecordMetrumData.java | 2 +- altoslib/AltosTelemetryRecordMetrumSensor.java | 2 +- altoslib/AltosTelemetryRecordMini.java | 2 +- altoslib/AltosTelemetryRecordRaw.java | 2 +- altoslib/AltosTelemetryRecordSatellite.java | 2 +- altoslib/AltosTelemetryRecordSensor.java | 14 +- altoslib/AltosTelemetrySatellite.java | 2 +- altoslib/AltosTelemetrySensor.java | 2 +- altoslib/AltosTelemetryStandard.java | 2 +- altoslib/AltosTemperature.java | 2 +- altoslib/AltosUnits.java | 2 +- altoslib/AltosUnitsListener.java | 2 +- altoslib/Makefile.am | 26 +- altosui/Altos.java | 2 +- altosui/AltosAscent.java | 16 +- altosui/AltosBTKnown.java | 2 +- altosui/AltosCSV.java | 4 +- altosui/AltosCSVUI.java | 2 +- altosui/AltosCompanionInfo.java | 6 +- altosui/AltosConfig.java | 2 +- altosui/AltosConfigFreqUI.java | 2 +- altosui/AltosConfigPyroUI.java | 2 +- altosui/AltosConfigTD.java | 2 +- altosui/AltosConfigTDUI.java | 2 +- altosui/AltosConfigUI.java | 2 +- altosui/AltosDataChooser.java | 2 +- altosui/AltosDescent.java | 10 +- altosui/AltosDisplayThread.java | 2 +- altosui/AltosEepromDelete.java | 2 +- altosui/AltosEepromDownload.java | 8 +- altosui/AltosEepromList.java | 2 +- altosui/AltosEepromManage.java | 2 +- altosui/AltosEepromSelect.java | 2 +- altosui/AltosFlashUI.java | 2 +- altosui/AltosFlightDisplay.java | 2 +- altosui/AltosFlightStats.java | 22 +- altosui/AltosFlightStatsTable.java | 10 +- altosui/AltosFlightStatus.java | 6 +- altosui/AltosFlightStatusTableModel.java | 2 +- altosui/AltosFlightStatusUpdate.java | 2 +- altosui/AltosFlightUI.java | 2 +- altosui/AltosFreqList.java | 2 +- altosui/AltosGraph.java | 2 +- altosui/AltosGraphDataPoint.java | 6 +- altosui/AltosGraphDataSet.java | 4 +- altosui/AltosGraphUI.java | 2 +- altosui/AltosIdleMonitorUI.java | 2 +- altosui/AltosIgniteUI.java | 2 +- altosui/AltosInfoTable.java | 44 +-- altosui/AltosKML.java | 8 +- altosui/AltosLanded.java | 6 +- altosui/AltosPad.java | 32 +- altosui/AltosRomconfigUI.java | 2 +- altosui/AltosScanUI.java | 4 +- altosui/AltosSerial.java | 2 +- altosui/AltosSiteMap.java | 6 +- altosui/AltosSiteMapTile.java | 2 +- altosui/AltosUI.java | 4 +- altosui/AltosUIPreferencesBackend.java | 2 +- altosui/AltosWriter.java | 2 +- altosuilib/AltosUIAxis.java | 2 +- altosuilib/AltosUIEnable.java | 2 +- altosuilib/AltosUIGraph.java | 2 +- altosuilib/AltosUIGrapher.java | 2 +- altosuilib/AltosUILib.java | 2 +- altosuilib/AltosUIMarker.java | 2 +- altosuilib/AltosUIPreferences.java | 2 +- altosuilib/AltosUIPreferencesBackend.java | 2 +- altosuilib/AltosUISeries.java | 21 +- configure.ac | 2 +- micropeak/MicroData.java | 2 +- micropeak/MicroDownload.java | 2 +- micropeak/MicroExport.java | 2 +- micropeak/MicroFile.java | 2 +- micropeak/MicroFileChooser.java | 2 +- micropeak/MicroGraph.java | 2 +- micropeak/MicroPeak.java | 2 +- micropeak/MicroRaw.java | 2 +- micropeak/MicroSave.java | 2 +- micropeak/MicroStats.java | 2 +- micropeak/MicroStatsTable.java | 2 +- 199 files changed, 1367 insertions(+), 1968 deletions(-) delete mode 100644 altoslib/AltosEepromRecord.java delete mode 100644 altoslib/AltosEepromTeleScience.java delete mode 100644 altoslib/AltosGPSQuery.java delete mode 100644 altoslib/AltosIMUQuery.java create mode 100644 altoslib/AltosIdle.java create mode 100644 altoslib/AltosIdleFetch.java create mode 100644 altoslib/AltosMma655x.java delete mode 100644 altoslib/AltosMs5607Query.java delete mode 100644 altoslib/AltosOrderedMegaRecord.java delete mode 100644 altoslib/AltosOrderedMiniRecord.java delete mode 100644 altoslib/AltosOrderedRecord.java delete mode 100644 altoslib/AltosRecord.java delete mode 100644 altoslib/AltosRecordCompanion.java delete mode 100644 altoslib/AltosRecordIterable.java delete mode 100644 altoslib/AltosRecordMM.java delete mode 100644 altoslib/AltosRecordMini.java delete mode 100644 altoslib/AltosRecordNone.java delete mode 100644 altoslib/AltosRecordTM.java create mode 100644 altoslib/AltosSensorEMini.java create mode 100644 altoslib/AltosSensorMega.java (limited to 'altoslib/AltosConvert.java') diff --git a/altosdroid/src/org/altusmetrum/AltosDroid/AltosBluetooth.java b/altosdroid/src/org/altusmetrum/AltosDroid/AltosBluetooth.java index 0aea06f1..0ed31437 100644 --- a/altosdroid/src/org/altusmetrum/AltosDroid/AltosBluetooth.java +++ b/altosdroid/src/org/altusmetrum/AltosDroid/AltosBluetooth.java @@ -31,7 +31,7 @@ import android.os.Handler; //import android.os.Message; import android.util.Log; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; public class AltosBluetooth extends AltosLink { diff --git a/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroid.java b/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroid.java index e10982f7..6f378777 100644 --- a/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroid.java +++ b/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroid.java @@ -49,7 +49,7 @@ import android.widget.Toast; import android.app.AlertDialog; import android.location.Location; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; public class AltosDroid extends FragmentActivity { // Debugging @@ -266,7 +266,7 @@ public class AltosDroid extends FragmentActivity { static String pos(double p, String pos, String neg) { String h = pos; - if (p == AltosRecord.MISSING) + if (p == AltosLib.MISSING) return ""; if (p < 0) { h = neg; @@ -278,13 +278,13 @@ public class AltosDroid extends FragmentActivity { } static String number(String format, double value) { - if (value == AltosRecord.MISSING) + if (value == AltosLib.MISSING) return ""; return String.format(format, value); } static String integer(String format, int value) { - if (value == AltosRecord.MISSING) + if (value == AltosLib.MISSING) return ""; return String.format(format, value); } diff --git a/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroidPreferences.java b/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroidPreferences.java index fd4b0768..59fef842 100644 --- a/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroidPreferences.java +++ b/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroidPreferences.java @@ -23,7 +23,7 @@ import android.content.Context; import android.content.SharedPreferences; import android.os.Environment; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; public class AltosDroidPreferences implements AltosPreferencesBackend { public final static String NAME = "org.altusmetrum.AltosDroid"; diff --git a/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroidTab.java b/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroidTab.java index 6ebb47f7..c652a169 100644 --- a/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroidTab.java +++ b/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroidTab.java @@ -17,7 +17,7 @@ package org.altusmetrum.AltosDroid; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; import android.location.Location; public interface AltosDroidTab { diff --git a/altosdroid/src/org/altusmetrum/AltosDroid/AltosVoice.java b/altosdroid/src/org/altusmetrum/AltosDroid/AltosVoice.java index b3dba626..df7409c4 100644 --- a/altosdroid/src/org/altusmetrum/AltosDroid/AltosVoice.java +++ b/altosdroid/src/org/altusmetrum/AltosDroid/AltosVoice.java @@ -21,7 +21,7 @@ package org.altusmetrum.AltosDroid; import android.speech.tts.TextToSpeech; import android.speech.tts.TextToSpeech.OnInitListener; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; public class AltosVoice { diff --git a/altosdroid/src/org/altusmetrum/AltosDroid/TabAscent.java b/altosdroid/src/org/altusmetrum/AltosDroid/TabAscent.java index 0e141ae4..69bc68c9 100644 --- a/altosdroid/src/org/altusmetrum/AltosDroid/TabAscent.java +++ b/altosdroid/src/org/altusmetrum/AltosDroid/TabAscent.java @@ -17,7 +17,7 @@ package org.altusmetrum.AltosDroid; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; import android.app.Activity; import android.os.Bundle; @@ -103,10 +103,10 @@ public class TabAscent extends Fragment implements AltosDroidTab { } mApogeeVoltageView.setText(AltosDroid.number("%4.2f V", state.drogue_sense)); - mApogeeLights.set(state.drogue_sense > 3.2, state.drogue_sense == AltosRecord.MISSING); + mApogeeLights.set(state.drogue_sense > 3.2, state.drogue_sense == AltosLib.MISSING); mMainVoltageView.setText(AltosDroid.number("%4.2f V", state.main_sense)); - mMainLights.set(state.main_sense > 3.2, state.main_sense == AltosRecord.MISSING); + mMainLights.set(state.main_sense > 3.2, state.main_sense == AltosLib.MISSING); } } } diff --git a/altosdroid/src/org/altusmetrum/AltosDroid/TabDescent.java b/altosdroid/src/org/altusmetrum/AltosDroid/TabDescent.java index 09e7169b..ee09ea88 100644 --- a/altosdroid/src/org/altusmetrum/AltosDroid/TabDescent.java +++ b/altosdroid/src/org/altusmetrum/AltosDroid/TabDescent.java @@ -17,7 +17,7 @@ package org.altusmetrum.AltosDroid; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; import android.app.Activity; import android.os.Bundle; @@ -112,10 +112,10 @@ public class TabDescent extends Fragment implements AltosDroidTab { } mApogeeVoltageView.setText(AltosDroid.number("%4.2f V", state.drogue_sense)); - mApogeeLights.set(state.drogue_sense > 3.2, state.drogue_sense == AltosRecord.MISSING); + mApogeeLights.set(state.drogue_sense > 3.2, state.drogue_sense == AltosLib.MISSING); mMainVoltageView.setText(AltosDroid.number("%4.2f V", state.main_sense)); - mMainLights.set(state.main_sense > 3.2, state.main_sense == AltosRecord.MISSING); + mMainLights.set(state.main_sense > 3.2, state.main_sense == AltosLib.MISSING); } } diff --git a/altosdroid/src/org/altusmetrum/AltosDroid/TabLanded.java b/altosdroid/src/org/altusmetrum/AltosDroid/TabLanded.java index f42b46b5..a57ae514 100644 --- a/altosdroid/src/org/altusmetrum/AltosDroid/TabLanded.java +++ b/altosdroid/src/org/altusmetrum/AltosDroid/TabLanded.java @@ -17,7 +17,7 @@ package org.altusmetrum.AltosDroid; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; import android.app.Activity; import android.os.Bundle; diff --git a/altosdroid/src/org/altusmetrum/AltosDroid/TabMap.java b/altosdroid/src/org/altusmetrum/AltosDroid/TabMap.java index d831f117..a4e224aa 100644 --- a/altosdroid/src/org/altusmetrum/AltosDroid/TabMap.java +++ b/altosdroid/src/org/altusmetrum/AltosDroid/TabMap.java @@ -19,7 +19,7 @@ package org.altusmetrum.AltosDroid; import java.util.Arrays; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; import com.google.android.gms.maps.CameraUpdateFactory; import com.google.android.gms.maps.GoogleMap; diff --git a/altosdroid/src/org/altusmetrum/AltosDroid/TabPad.java b/altosdroid/src/org/altusmetrum/AltosDroid/TabPad.java index 066c1353..f9d30b34 100644 --- a/altosdroid/src/org/altusmetrum/AltosDroid/TabPad.java +++ b/altosdroid/src/org/altusmetrum/AltosDroid/TabPad.java @@ -17,7 +17,7 @@ package org.altusmetrum.AltosDroid; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; import android.app.Activity; import android.os.Bundle; @@ -104,13 +104,13 @@ public class TabPad extends Fragment implements AltosDroidTab { public void update_ui(AltosState state, AltosGreatCircle from_receiver, Location receiver) { if (state != null) { mBatteryVoltageView.setText(AltosDroid.number("%4.2f V", state.battery)); - mBatteryLights.set(state.battery > 3.7, state.battery == AltosRecord.MISSING); + mBatteryLights.set(state.battery > 3.7, state.battery == AltosLib.MISSING); mApogeeVoltageView.setText(AltosDroid.number("%4.2f V", state.drogue_sense)); - mApogeeLights.set(state.drogue_sense > 3.2, state.drogue_sense == AltosRecord.MISSING); + mApogeeLights.set(state.drogue_sense > 3.2, state.drogue_sense == AltosLib.MISSING); mMainVoltageView.setText(AltosDroid.number("%4.2f V", state.main_sense)); - mMainLights.set(state.main_sense > 3.2, state.main_sense == AltosRecord.MISSING); + mMainLights.set(state.main_sense > 3.2, state.main_sense == AltosLib.MISSING); if (state.data.flight != 0) { if (state.data.state <= AltosLib.ao_flight_pad) @@ -122,7 +122,7 @@ public class TabPad extends Fragment implements AltosDroidTab { } else { mDataLoggingView.setText("Storage full"); } - mDataLoggingLights.set(state.data.flight != 0, state.data.flight == AltosRecord.MISSING); + mDataLoggingLights.set(state.data.flight != 0, state.data.flight == AltosLib.MISSING); if (state.gps != null) { mGPSLockedView.setText(AltosDroid.integer("%4d sats", state.gps.nsat)); diff --git a/altosdroid/src/org/altusmetrum/AltosDroid/TelemetryLogger.java b/altosdroid/src/org/altusmetrum/AltosDroid/TelemetryLogger.java index 3ece04ac..4d793413 100644 --- a/altosdroid/src/org/altusmetrum/AltosDroid/TelemetryLogger.java +++ b/altosdroid/src/org/altusmetrum/AltosDroid/TelemetryLogger.java @@ -1,6 +1,6 @@ package org.altusmetrum.AltosDroid; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; import android.content.BroadcastReceiver; import android.content.Context; diff --git a/altosdroid/src/org/altusmetrum/AltosDroid/TelemetryReader.java b/altosdroid/src/org/altusmetrum/AltosDroid/TelemetryReader.java index 716ec589..e37019fd 100644 --- a/altosdroid/src/org/altusmetrum/AltosDroid/TelemetryReader.java +++ b/altosdroid/src/org/altusmetrum/AltosDroid/TelemetryReader.java @@ -25,7 +25,7 @@ import java.util.concurrent.*; import android.util.Log; import android.os.Handler; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; public class TelemetryReader extends Thread { diff --git a/altosdroid/src/org/altusmetrum/AltosDroid/TelemetryService.java b/altosdroid/src/org/altusmetrum/AltosDroid/TelemetryService.java index 940ad792..76efa749 100644 --- a/altosdroid/src/org/altusmetrum/AltosDroid/TelemetryService.java +++ b/altosdroid/src/org/altusmetrum/AltosDroid/TelemetryService.java @@ -44,7 +44,7 @@ import android.location.LocationManager; import android.location.LocationListener; import android.location.Criteria; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; public class TelemetryService extends Service implements LocationListener { diff --git a/altoslib/AltosAccel.java b/altoslib/AltosAccel.java index d02b3238..08eba359 100644 --- a/altoslib/AltosAccel.java +++ b/altoslib/AltosAccel.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2; public class AltosAccel extends AltosUnits { diff --git a/altoslib/AltosCRCException.java b/altoslib/AltosCRCException.java index 76e79add..be2ec4fe 100644 --- a/altoslib/AltosCRCException.java +++ b/altoslib/AltosCRCException.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2; public class AltosCRCException extends Exception { public int rssi; diff --git a/altoslib/AltosCompanion.java b/altoslib/AltosCompanion.java index 1572fdae..57bb21af 100644 --- a/altoslib/AltosCompanion.java +++ b/altoslib/AltosCompanion.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2; public class AltosCompanion { public final static int board_id_telescience = 0x0a; diff --git a/altoslib/AltosConfigData.java b/altoslib/AltosConfigData.java index 2ca5a7a5..d92f42c3 100644 --- a/altoslib/AltosConfigData.java +++ b/altoslib/AltosConfigData.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2; import java.util.*; import java.text.*; diff --git a/altoslib/AltosConfigValues.java b/altoslib/AltosConfigValues.java index 027d10f4..fd5584c2 100644 --- a/altoslib/AltosConfigValues.java +++ b/altoslib/AltosConfigValues.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2; public interface AltosConfigValues { /* set and get all of the dialog values */ diff --git a/altoslib/AltosConvert.java b/altoslib/AltosConvert.java index cf2bc59f..760d9eb9 100644 --- a/altoslib/AltosConvert.java +++ b/altoslib/AltosConvert.java @@ -18,7 +18,7 @@ /* * Sensor data conversion functions */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2; public class AltosConvert { /* @@ -207,15 +207,27 @@ public class AltosConvert { } static public double mega_battery_voltage(int v_batt) { - if (v_batt != AltosRecord.MISSING) + if (v_batt != AltosLib.MISSING) return 3.3 * mega_adc(v_batt) * (15.0 + 27.0) / 27.0; - return AltosRecord.MISSING; + return AltosLib.MISSING; } static double mega_pyro_voltage(int raw) { - if (raw != AltosRecord.MISSING) + if (raw != AltosLib.MISSING) return 3.3 * mega_adc(raw) * (100.0 + 27.0) / 27.0; - return AltosRecord.MISSING; + return AltosLib.MISSING; + } + + static double tele_mini_voltage(int sensor) { + double supply = 3.3; + + return sensor / 32767.0 * supply * 127/27; + } + + static double easy_mini_voltage(int sensor) { + double supply = 3.0; + + return sensor / 32767.0 * supply * 127/27; } public static double radio_to_frequency(int freq, int setting, int cal, int channel) { diff --git a/altoslib/AltosDebug.java b/altoslib/AltosDebug.java index 4d8e3ae7..76c13d57 100644 --- a/altoslib/AltosDebug.java +++ b/altoslib/AltosDebug.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2; import java.io.*; diff --git a/altoslib/AltosDistance.java b/altoslib/AltosDistance.java index 25028ac7..56257165 100644 --- a/altoslib/AltosDistance.java +++ b/altoslib/AltosDistance.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2; public class AltosDistance extends AltosUnits { diff --git a/altoslib/AltosEeprom.java b/altoslib/AltosEeprom.java index 3a996ae0..dd5993c7 100644 --- a/altoslib/AltosEeprom.java +++ b/altoslib/AltosEeprom.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2; import java.io.*; import java.util.*; diff --git a/altoslib/AltosEepromBody.java b/altoslib/AltosEepromBody.java index 60aa8881..444102ce 100644 --- a/altoslib/AltosEepromBody.java +++ b/altoslib/AltosEepromBody.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2; import java.io.*; import java.util.*; diff --git a/altoslib/AltosEepromBodyIterable.java b/altoslib/AltosEepromBodyIterable.java index 33dc0ac8..4d32c66a 100644 --- a/altoslib/AltosEepromBodyIterable.java +++ b/altoslib/AltosEepromBodyIterable.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2; import java.io.*; import java.util.*; diff --git a/altoslib/AltosEepromChunk.java b/altoslib/AltosEepromChunk.java index 1709352b..918481fa 100644 --- a/altoslib/AltosEepromChunk.java +++ b/altoslib/AltosEepromChunk.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2; import java.text.*; import java.util.concurrent.*; diff --git a/altoslib/AltosEepromFile.java b/altoslib/AltosEepromFile.java index 082c23ca..f87bf916 100644 --- a/altoslib/AltosEepromFile.java +++ b/altoslib/AltosEepromFile.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2; import java.io.*; import java.util.*; @@ -100,6 +100,7 @@ public class AltosEepromFile extends AltosStateIterable { AltosState state = start.clone(); for (AltosEeprom eeprom : body) { eeprom.update_state(state); + state.finish_update(); if (state.state >= AltosLib.ao_flight_boost) { start.set_boost_tick(state.tick); break; @@ -111,8 +112,10 @@ public class AltosEepromFile extends AltosStateIterable { AltosState state = start.clone(); Iterator i = body.iterator(); - while (i.hasNext() && !state.valid()) + while (i.hasNext() && !state.valid()) { i.next().update_state(state); + state.finish_update(); + } return new AltosEepromIterator(state, i); } } \ No newline at end of file diff --git a/altoslib/AltosEepromGPS.java b/altoslib/AltosEepromGPS.java index f97fbbf9..43ed3392 100644 --- a/altoslib/AltosEepromGPS.java +++ b/altoslib/AltosEepromGPS.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2; import java.io.*; import java.util.*; diff --git a/altoslib/AltosEepromHeader.java b/altoslib/AltosEepromHeader.java index 35a03a12..0aeb78dd 100644 --- a/altoslib/AltosEepromHeader.java +++ b/altoslib/AltosEepromHeader.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2; import java.io.*; import java.util.*; diff --git a/altoslib/AltosEepromHeaderIterable.java b/altoslib/AltosEepromHeaderIterable.java index 01953f0e..920a4382 100644 --- a/altoslib/AltosEepromHeaderIterable.java +++ b/altoslib/AltosEepromHeaderIterable.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2; import java.io.*; import java.util.*; diff --git a/altoslib/AltosEepromIterable.java b/altoslib/AltosEepromIterable.java index 1e0f7f75..fc793579 100644 --- a/altoslib/AltosEepromIterable.java +++ b/altoslib/AltosEepromIterable.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2; import java.io.*; import java.util.*; diff --git a/altoslib/AltosEepromLog.java b/altoslib/AltosEepromLog.java index 20026c6d..95c0c3f6 100644 --- a/altoslib/AltosEepromLog.java +++ b/altoslib/AltosEepromLog.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2; import java.text.*; import java.util.concurrent.*; @@ -72,9 +72,9 @@ public class AltosEepromLog { for (block = in_start_block; block < in_end_block; block++) { AltosEepromChunk eechunk = new AltosEepromChunk(link, block, block == in_start_block); - for (int i = 0; i < AltosEepromChunk.chunk_size; i += AltosEepromRecord.record_length) { + for (int i = 0; i < AltosEepromChunk.chunk_size; i += AltosEepromTM.record_length) { try { - AltosEepromRecord r = new AltosEepromRecord(eechunk, i); + AltosEepromTM r = new AltosEepromTM(eechunk, i); if (r.cmd == AltosLib.AO_LOG_FLIGHT) { flight = r.b; diff --git a/altoslib/AltosEepromMega.java b/altoslib/AltosEepromMega.java index b85c04bf..7a4ee52d 100644 --- a/altoslib/AltosEepromMega.java +++ b/altoslib/AltosEepromMega.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2; import java.io.*; import java.util.*; diff --git a/altoslib/AltosEepromMegaIterable.java b/altoslib/AltosEepromMegaIterable.java index 5736f937..8243aa88 100644 --- a/altoslib/AltosEepromMegaIterable.java +++ b/altoslib/AltosEepromMegaIterable.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2; import java.io.*; import java.util.*; diff --git a/altoslib/AltosEepromMetrum.java b/altoslib/AltosEepromMetrum.java index e035e5fd..7b2fcb3c 100644 --- a/altoslib/AltosEepromMetrum.java +++ b/altoslib/AltosEepromMetrum.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2; import java.text.*; diff --git a/altoslib/AltosEepromMetrum2.java b/altoslib/AltosEepromMetrum2.java index ea38edf2..c1d62c0c 100644 --- a/altoslib/AltosEepromMetrum2.java +++ b/altoslib/AltosEepromMetrum2.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2; import java.io.*; import java.util.*; diff --git a/altoslib/AltosEepromMetrumIterable.java b/altoslib/AltosEepromMetrumIterable.java index 0387319e..de4cc919 100644 --- a/altoslib/AltosEepromMetrumIterable.java +++ b/altoslib/AltosEepromMetrumIterable.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2; import java.io.*; import java.util.*; diff --git a/altoslib/AltosEepromMini.java b/altoslib/AltosEepromMini.java index e0eedb73..a09a62ce 100644 --- a/altoslib/AltosEepromMini.java +++ b/altoslib/AltosEepromMini.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2; import java.io.*; import java.util.*; @@ -42,13 +42,10 @@ public class AltosEepromMini extends AltosEeprom { public int v_batt() { return data16(10); } double voltage(AltosState state, int sensor) { - double supply; - if (state.log_format == AltosLib.AO_LOG_FORMAT_EASYMINI) - supply = 3.0; + return AltosConvert.easy_mini_voltage(sensor); else - supply = 3.3; - return sensor / 32767.0 * supply * 127/27; + return AltosConvert.tele_mini_voltage(sensor); } public void update_state(AltosState state) { diff --git a/altoslib/AltosEepromMiniIterable.java b/altoslib/AltosEepromMiniIterable.java index 495495eb..31e667d8 100644 --- a/altoslib/AltosEepromMiniIterable.java +++ b/altoslib/AltosEepromMiniIterable.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2; import java.io.*; import java.util.*; diff --git a/altoslib/AltosEepromOldIterable.java b/altoslib/AltosEepromOldIterable.java index ef82828b..43b2362b 100644 --- a/altoslib/AltosEepromOldIterable.java +++ b/altoslib/AltosEepromOldIterable.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2; import java.io.*; import java.util.*; diff --git a/altoslib/AltosEepromRecord.java b/altoslib/AltosEepromRecord.java deleted file mode 100644 index 70ac1113..00000000 --- a/altoslib/AltosEepromRecord.java +++ /dev/null @@ -1,135 +0,0 @@ -/* - * Copyright © 2010 Keith Packard - * - * 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_1; - -import java.text.*; - -public class AltosEepromRecord { - public int cmd; - public int tick; - public int a; - public int b; - public String data; - public boolean tick_valid; - - public static final int record_length = 8; - - public AltosEepromRecord (AltosEepromChunk chunk, int start) throws ParseException { - - cmd = chunk.data(start); - tick_valid = true; - - tick_valid = !chunk.erased(start, record_length); - if (tick_valid) { - if (AltosConvert.checksum(chunk.data, start, record_length) != 0) - throw new ParseException(String.format("invalid checksum at 0x%x", - chunk.address + start), 0); - } else { - cmd = AltosLib.AO_LOG_INVALID; - } - - tick = chunk.data16(start + 2); - a = chunk.data16(start + 4); - b = chunk.data16(start + 6); - - data = null; - } - - public AltosEepromRecord (String line) { - tick_valid = false; - tick = 0; - a = 0; - b = 0; - data = null; - if (line == null) { - cmd = AltosLib.AO_LOG_INVALID; - data = ""; - } else { - try { - String[] tokens = line.split("\\s+"); - - if (tokens[0].length() == 1) { - if (tokens.length != 4) { - cmd = AltosLib.AO_LOG_INVALID; - data = line; - } else { - cmd = tokens[0].codePointAt(0); - tick = Integer.parseInt(tokens[1],16); - tick_valid = true; - a = Integer.parseInt(tokens[2],16); - b = Integer.parseInt(tokens[3],16); - } - } else if (tokens[0].equals("Config") && tokens[1].equals("version:")) { - cmd = AltosLib.AO_LOG_CONFIG_VERSION; - data = tokens[2]; - } else if (tokens[0].equals("Main") && tokens[1].equals("deploy:")) { - cmd = AltosLib.AO_LOG_MAIN_DEPLOY; - a = Integer.parseInt(tokens[2]); - } else if (tokens[0].equals("Apogee") && tokens[1].equals("delay:")) { - cmd = AltosLib.AO_LOG_APOGEE_DELAY; - a = Integer.parseInt(tokens[2]); - } else if (tokens[0].equals("Radio") && tokens[1].equals("channel:")) { - cmd = AltosLib.AO_LOG_RADIO_CHANNEL; - a = Integer.parseInt(tokens[2]); - } else if (tokens[0].equals("Callsign:")) { - cmd = AltosLib.AO_LOG_CALLSIGN; - data = tokens[1].replaceAll("\"",""); - } else if (tokens[0].equals("Accel") && tokens[1].equals("cal")) { - cmd = AltosLib.AO_LOG_ACCEL_CAL; - a = Integer.parseInt(tokens[3]); - b = Integer.parseInt(tokens[5]); - } else if (tokens[0].equals("Radio") && tokens[1].equals("cal:")) { - cmd = AltosLib.AO_LOG_RADIO_CAL; - a = Integer.parseInt(tokens[2]); - } else if (tokens[0].equals("Max") && tokens[1].equals("flight") && tokens[2].equals("log:")) { - cmd = AltosLib.AO_LOG_MAX_FLIGHT_LOG; - a = Integer.parseInt(tokens[3]); - } else if (tokens[0].equals("manufacturer")) { - cmd = AltosLib.AO_LOG_MANUFACTURER; - data = tokens[1]; - } else if (tokens[0].equals("product")) { - cmd = AltosLib.AO_LOG_PRODUCT; - data = tokens[1]; - } else if (tokens[0].equals("serial-number")) { - cmd = AltosLib.AO_LOG_SERIAL_NUMBER; - a = Integer.parseInt(tokens[1]); - } else if (tokens[0].equals("log-format")) { - cmd = AltosLib.AO_LOG_LOG_FORMAT; - a = Integer.parseInt(tokens[1]); - } else if (tokens[0].equals("software-version")) { - cmd = AltosLib.AO_LOG_SOFTWARE_VERSION; - data = tokens[1]; - } else { - cmd = AltosLib.AO_LOG_INVALID; - data = line; - } - } catch (NumberFormatException ne) { - cmd = AltosLib.AO_LOG_INVALID; - data = line; - } - } - } - - public AltosEepromRecord(int in_cmd, int in_tick, int in_a, int in_b) { - tick_valid = true; - cmd = in_cmd; - tick = in_tick; - a = in_a; - b = in_b; - } -} diff --git a/altoslib/AltosEepromTM.java b/altoslib/AltosEepromTM.java index 2bb9d974..a38c2dae 100644 --- a/altoslib/AltosEepromTM.java +++ b/altoslib/AltosEepromTM.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2; import java.io.*; import java.util.*; diff --git a/altoslib/AltosEepromTeleScience.java b/altoslib/AltosEepromTeleScience.java deleted file mode 100644 index bacd66b5..00000000 --- a/altoslib/AltosEepromTeleScience.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright © 2011 Keith Packard - * - * 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_1; - -import java.text.*; - -public class AltosEepromTeleScience { - public int type; - public int tick; - public int tm_state; - public int tm_tick; - public int[] data; - public boolean valid; - - public static final int AO_LOG_TELESCIENCE_START = 's'; - public static final int AO_LOG_TELESCIENCE_DATA = 'd'; - - static final int max_data = 12; - public static final int record_length = 32; - - public int record_length() { return record_length; } - - public AltosEepromTeleScience (AltosEepromChunk chunk, int start) throws ParseException { - type = chunk.data(start); - - valid = !chunk.erased(start, record_length); - if (valid) { - if (AltosConvert.checksum(chunk.data, start, record_length) != 0) - throw new ParseException(String.format("invalid checksum at 0x%x", - chunk.address + start), 0); - } else { - type = AltosLib.AO_LOG_INVALID; - } - - tick = chunk.data16(start+2); - tm_tick = chunk.data16(start+4); - tm_state = chunk.data(start+6); - data = new int[max_data]; - for (int i = 0; i < max_data; i++) - data[i] = chunk.data16(start + 8 + i * 2); - } -} diff --git a/altoslib/AltosFile.java b/altoslib/AltosFile.java index 54c54824..9802f883 100644 --- a/altoslib/AltosFile.java +++ b/altoslib/AltosFile.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2; import java.io.File; import java.util.*; @@ -23,7 +23,7 @@ import java.util.*; public class AltosFile extends File { static String number(int n) { - if (n == AltosRecord.MISSING) + if (n == AltosLib.MISSING) return "unk"; else return String.format("%03d", n); diff --git a/altoslib/AltosFlash.java b/altoslib/AltosFlash.java index 010274b9..d8069157 100644 --- a/altoslib/AltosFlash.java +++ b/altoslib/AltosFlash.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2; import java.io.*; diff --git a/altoslib/AltosFlashListener.java b/altoslib/AltosFlashListener.java index ab50b74a..777ae635 100644 --- a/altoslib/AltosFlashListener.java +++ b/altoslib/AltosFlashListener.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2; public interface AltosFlashListener { public void position(String label, int percent); diff --git a/altoslib/AltosFlightReader.java b/altoslib/AltosFlightReader.java index 5a415274..4a722e42 100644 --- a/altoslib/AltosFlightReader.java +++ b/altoslib/AltosFlightReader.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2; import java.text.*; import java.io.*; @@ -48,5 +48,5 @@ public class AltosFlightReader { public boolean has_monitor_battery() { return false; } - public double monitor_battery() { return AltosRecord.MISSING; } + public double monitor_battery() { return AltosLib.MISSING; } } diff --git a/altoslib/AltosFrequency.java b/altoslib/AltosFrequency.java index 484a2fd9..ece7525a 100644 --- a/altoslib/AltosFrequency.java +++ b/altoslib/AltosFrequency.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2; public class AltosFrequency { public double frequency; diff --git a/altoslib/AltosGPS.java b/altoslib/AltosGPS.java index a8c19e4a..1d5b0755 100644 --- a/altoslib/AltosGPS.java +++ b/altoslib/AltosGPS.java @@ -15,13 +15,14 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2; import java.text.*; +import java.util.concurrent.*; public class AltosGPS implements Cloneable { - public final static int MISSING = AltosRecord.MISSING; + public final static int MISSING = AltosLib.MISSING; public int nsat; public boolean locked; @@ -65,8 +66,8 @@ public class AltosGPS implements Cloneable { } public void ClearGPSTime() { - year = month = day = AltosRecord.MISSING; - hour = minute = second = AltosRecord.MISSING; + year = month = day = AltosLib.MISSING; + hour = minute = second = AltosLib.MISSING; } public AltosGPS(AltosTelemetryMap map) throws ParseException { @@ -91,9 +92,9 @@ public class AltosGPS implements Cloneable { second = map.get_int(AltosTelemetryLegacy.AO_TELEM_GPS_SECOND, 0); ground_speed = map.get_double(AltosTelemetryLegacy.AO_TELEM_GPS_HORIZONTAL_SPEED, - AltosRecord.MISSING, 1/100.0); + AltosLib.MISSING, 1/100.0); course = map.get_int(AltosTelemetryLegacy.AO_TELEM_GPS_COURSE, - AltosRecord.MISSING); + AltosLib.MISSING); hdop = map.get_double(AltosTelemetryLegacy.AO_TELEM_GPS_HDOP, MISSING, 1.0); vdop = map.get_double(AltosTelemetryLegacy.AO_TELEM_GPS_VDOP, MISSING, 1.0); h_error = map.get_int(AltosTelemetryLegacy.AO_TELEM_GPS_HERROR, MISSING); @@ -107,6 +108,62 @@ public class AltosGPS implements Cloneable { } } + public boolean parse_string (String line, boolean says_done) { + String[] bits = line.split("\\s+"); + if (bits.length == 0) + return false; + if (line.startsWith("Date:")) { + if (bits.length < 2) + return false; + String[] d = bits[1].split("/"); + if (d.length < 3) + return false; + year = Integer.parseInt(d[0]) + 2000; + month = Integer.parseInt(d[1]); + day = Integer.parseInt(d[2]); + } else if (line.startsWith("Time:")) { + if (bits.length < 2) + return false; + String[] d = bits[1].split(":"); + if (d.length < 3) + return false; + hour = Integer.parseInt(d[0]); + minute = Integer.parseInt(d[1]); + second = Integer.parseInt(d[2]); + } else if (line.startsWith("Lat/Lon:")) { + if (bits.length < 3) + return false; + lat = Integer.parseInt(bits[1]) * 1.0e-7; + lon = Integer.parseInt(bits[2]) * 1.0e-7; + } else if (line.startsWith("Alt:")) { + if (bits.length < 2) + return false; + alt = Integer.parseInt(bits[1]); + } else if (line.startsWith("Flags:")) { + if (bits.length < 2) + return false; + int status = Integer.decode(bits[1]); + connected = (status & AltosLib.AO_GPS_RUNNING) != 0; + locked = (status & AltosLib.AO_GPS_VALID) != 0; + if (!says_done) + return false; + } else if (line.startsWith("Sats:")) { + if (bits.length < 2) + return false; + nsat = Integer.parseInt(bits[1]); + cc_gps_sat = new AltosGPSSat[nsat]; + for (int i = 0; i < nsat; i++) { + int svid = Integer.parseInt(bits[2+i*2]); + int cc_n0 = Integer.parseInt(bits[3+i*2]); + cc_gps_sat[i] = new AltosGPSSat(svid, cc_n0); + } + } else if (line.startsWith("done")) { + return false; + } else + return false; + return true; + } + public AltosGPS(String[] words, int i, int version) throws ParseException { AltosParse.word(words[i++], "GPS"); nsat = AltosParse.parse_int(words[i++]); @@ -212,9 +269,9 @@ public class AltosGPS implements Cloneable { } public AltosGPS() { - lat = AltosRecord.MISSING; - lon = AltosRecord.MISSING; - alt = AltosRecord.MISSING; + lat = AltosLib.MISSING; + lon = AltosLib.MISSING; + alt = AltosLib.MISSING; ClearGPSTime(); cc_gps_sat = null; } @@ -283,11 +340,37 @@ public class AltosGPS implements Cloneable { } } } else { - lat = AltosRecord.MISSING; - lon = AltosRecord.MISSING; - alt = AltosRecord.MISSING; + lat = AltosLib.MISSING; + lon = AltosLib.MISSING; + alt = AltosLib.MISSING; ClearGPSTime(); cc_gps_sat = null; } } + + static public void update_state(AltosState state, AltosLink link, AltosConfigData config_data) { + try { + AltosGPS gps = new AltosGPS(link, config_data); + + if (gps != null) { + state.set_gps(gps, state.gps_sequence++); + return; + } + } catch (TimeoutException te) { + } catch (InterruptedException ie) { + } + state.set_gps(null, 0); + } + + public AltosGPS (AltosLink link, AltosConfigData config_data) throws TimeoutException, InterruptedException { + boolean says_done = config_data.compare_version("1.0") >= 0; + link.printf("g\n"); + for (;;) { + String line = link.get_reply_no_dialog(5000); + if (line == null) + throw new TimeoutException(); + if (!parse_string(line, says_done)) + break; + } + } } diff --git a/altoslib/AltosGPSQuery.java b/altoslib/AltosGPSQuery.java deleted file mode 100644 index deb9d201..00000000 --- a/altoslib/AltosGPSQuery.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright © 2012 Keith Packard - * - * 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_1; - -import java.util.concurrent.*; - -class AltosGPSQuery extends AltosGPS { - public AltosGPSQuery (AltosLink link, AltosConfigData config_data) - throws TimeoutException, InterruptedException { - boolean says_done = config_data.compare_version("1.0") >= 0; - link.printf("g\n"); - for (;;) { - String line = link.get_reply_no_dialog(5000); - if (line == null) - throw new TimeoutException(); - String[] bits = line.split("\\s+"); - if (bits.length == 0) - continue; - if (line.startsWith("Date:")) { - if (bits.length < 2) - continue; - String[] d = bits[1].split(":"); - if (d.length < 3) - continue; - year = Integer.parseInt(d[0]) + 2000; - month = Integer.parseInt(d[1]); - day = Integer.parseInt(d[2]); - continue; - } - if (line.startsWith("Time:")) { - if (bits.length < 2) - continue; - String[] d = bits[1].split("/"); - if (d.length < 3) - continue; - hour = Integer.parseInt(d[0]); - minute = Integer.parseInt(d[1]); - second = Integer.parseInt(d[2]); - continue; - } - if (line.startsWith("Lat/Lon:")) { - if (bits.length < 3) - continue; - lat = Integer.parseInt(bits[1]) * 1.0e-7; - lon = Integer.parseInt(bits[2]) * 1.0e-7; - continue; - } - if (line.startsWith("Alt:")) { - if (bits.length < 2) - continue; - alt = Integer.parseInt(bits[1]); - continue; - } - if (line.startsWith("Flags:")) { - if (bits.length < 2) - continue; - int status = Integer.decode(bits[1]); - connected = (status & AltosLib.AO_GPS_RUNNING) != 0; - locked = (status & AltosLib.AO_GPS_VALID) != 0; - if (!says_done) - break; - continue; - } - if (line.startsWith("Sats:")) { - if (bits.length < 2) - continue; - nsat = Integer.parseInt(bits[1]); - cc_gps_sat = new AltosGPSSat[nsat]; - for (int i = 0; i < nsat; i++) { - int svid = Integer.parseInt(bits[2+i*2]); - int cc_n0 = Integer.parseInt(bits[3+i*2]); - cc_gps_sat[i] = new AltosGPSSat(svid, cc_n0); - } - } - if (line.startsWith("done")) - break; - if (line.startsWith("Syntax error")) - break; - } - } -} - diff --git a/altoslib/AltosGPSSat.java b/altoslib/AltosGPSSat.java index 8714dd8a..0e17d7f2 100644 --- a/altoslib/AltosGPSSat.java +++ b/altoslib/AltosGPSSat.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2; public class AltosGPSSat { public int svid; diff --git a/altoslib/AltosGreatCircle.java b/altoslib/AltosGreatCircle.java index 770c3c6c..2c84bf4a 100644 --- a/altoslib/AltosGreatCircle.java +++ b/altoslib/AltosGreatCircle.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2; import java.lang.Math; diff --git a/altoslib/AltosHeight.java b/altoslib/AltosHeight.java index 96f5722b..1d2e4dbc 100644 --- a/altoslib/AltosHeight.java +++ b/altoslib/AltosHeight.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2; public class AltosHeight extends AltosUnits { diff --git a/altoslib/AltosHexfile.java b/altoslib/AltosHexfile.java index 2140228a..90352927 100644 --- a/altoslib/AltosHexfile.java +++ b/altoslib/AltosHexfile.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2; import java.io.*; import java.util.LinkedList; diff --git a/altoslib/AltosIMU.java b/altoslib/AltosIMU.java index c5ebbb16..c231dda7 100644 --- a/altoslib/AltosIMU.java +++ b/altoslib/AltosIMU.java @@ -15,7 +15,9 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2; + +import java.util.concurrent.*; public class AltosIMU implements Cloneable { public int accel_x; @@ -26,6 +28,23 @@ public class AltosIMU implements Cloneable { public int gyro_y; public int gyro_z; + public boolean parse_string(String line) { + if (!line.startsWith("Accel:")) + return false; + + String[] items = line.split("\\s+"); + + if (items.length >= 8) { + accel_x = Integer.parseInt(items[1]); + accel_y = Integer.parseInt(items[2]); + accel_z = Integer.parseInt(items[3]); + gyro_x = Integer.parseInt(items[5]); + gyro_y = Integer.parseInt(items[6]); + gyro_z = Integer.parseInt(items[7]); + } + return true; + } + public AltosIMU clone() { AltosIMU n = new AltosIMU(); @@ -38,5 +57,38 @@ public class AltosIMU implements Cloneable { n.gyro_z = gyro_z; return n; } + + static public void update_state(AltosState state, AltosLink link, AltosConfigData config_data) { + try { + AltosIMU imu = new AltosIMU(link); + + if (imu != null) + state.set_imu(imu); + } catch (TimeoutException te) { + } catch (InterruptedException ie) { + } + } + + public AltosIMU() { + accel_x = AltosLib.MISSING; + accel_y = AltosLib.MISSING; + accel_z = AltosLib.MISSING; + + gyro_x = AltosLib.MISSING; + gyro_y = AltosLib.MISSING; + gyro_z = AltosLib.MISSING; + } + + public AltosIMU(AltosLink link) throws InterruptedException, TimeoutException { + this(); + link.printf("I\n"); + for (;;) { + String line = link.get_reply_no_dialog(5000); + if (line == null) { + throw new TimeoutException(); + } + if (parse_string(line)) + break; + } + } } - \ No newline at end of file diff --git a/altoslib/AltosIMUQuery.java b/altoslib/AltosIMUQuery.java deleted file mode 100644 index 4ea5d963..00000000 --- a/altoslib/AltosIMUQuery.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright © 2012 Keith Packard - * - * 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_1; - -import java.util.concurrent.TimeoutException; - -class AltosIMUQuery extends AltosIMU { - - public AltosIMUQuery (AltosLink link) throws InterruptedException, TimeoutException { - link.printf("I\n"); - for (;;) { - String line = link.get_reply_no_dialog(5000); - if (line == null) { - throw new TimeoutException(); - } - if (!line.startsWith("Accel:")) - continue; - String[] items = line.split("\\s+"); - if (items.length >= 8) { - accel_x = Integer.parseInt(items[1]); - accel_y = Integer.parseInt(items[2]); - accel_z = Integer.parseInt(items[3]); - gyro_x = Integer.parseInt(items[5]); - gyro_y = Integer.parseInt(items[6]); - gyro_z = Integer.parseInt(items[7]); - } - break; - } - } -} - diff --git a/altoslib/AltosIdle.java b/altoslib/AltosIdle.java new file mode 100644 index 00000000..456a9247 --- /dev/null +++ b/altoslib/AltosIdle.java @@ -0,0 +1,39 @@ +/* + * Copyright © 2013 Keith Packard + * + * 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_2; + +import java.io.*; +import java.util.*; +import java.text.*; +import java.util.concurrent.*; + +public abstract class AltosIdle { + AltosLink link; + AltosConfigData config_data; + + public void printf(String format, Object ... arguments) { + link.printf(format, arguments); + } + + public abstract void update_state(AltosState state) throws InterruptedException, TimeoutException; + + public AltosIdle(AltosLink link, AltosConfigData config_data) { + this.link = link; + this.config_data = config_data; + } +} diff --git a/altoslib/AltosIdleFetch.java b/altoslib/AltosIdleFetch.java new file mode 100644 index 00000000..42943c07 --- /dev/null +++ b/altoslib/AltosIdleFetch.java @@ -0,0 +1,149 @@ +/* + * Copyright © 2013 Keith Packard + * + * 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_2; + +import java.io.*; +import java.util.*; +import java.text.*; +import java.util.concurrent.*; + +class AltosIdler { + String prefix; + int[] idlers; + + static final int idle_gps = 0; + static final int idle_imu = 1; + static final int idle_mag = 2; + static final int idle_ms5607 = 3; + static final int idle_mma655x = 4; + + + static final int idle_sensor_tm = 10; + static final int idle_sensor_metrum = 11; + static final int idle_sensor_mega = 12; + static final int idle_sensor_emini = 13; + + public void update_state(AltosState state, AltosLink link, AltosConfigData config_data) throws InterruptedException, TimeoutException { + for (int idler : idlers) { + AltosIdle idle = null; + switch (idler) { + case idle_gps: + AltosGPS.update_state(state, link, config_data); + break; + case idle_imu: + AltosIMU.update_state(state, link, config_data); + break; + case idle_mag: + AltosMag.update_state(state, link, config_data); + break; + case idle_ms5607: + AltosMs5607.update_state(state, link, config_data); + break; + case idle_mma655x: + AltosMma655x.update_state(state, link, config_data); + break; + case idle_sensor_tm: + AltosSensorTM.update_state(state, link, config_data); + break; + case idle_sensor_metrum: + AltosSensorMetrum.update_state(state, link, config_data); + break; + case idle_sensor_mega: + AltosSensorMega.update_state(state, link, config_data); + break; + case idle_sensor_emini: + AltosSensorEMini.update_state(state, link, config_data); + break; + } + if (idle != null) + idle.update_state(state); + } + } + + public boolean matches(AltosConfigData config_data) { + return config_data.product.startsWith(prefix); + } + + public AltosIdler(String prefix, int ... idlers) { + this.prefix = prefix; + this.idlers = idlers; + } +} + + +public class AltosIdleFetch implements AltosStateUpdate { + + static final AltosIdler[] idlers = { + + new AltosIdler("EasyMini", + AltosIdler.idle_ms5607, + AltosIdler.idle_sensor_emini), + + new AltosIdler("TeleMini-v1", + AltosIdler.idle_sensor_tm), + + new AltosIdler("TeleMini-v2", + AltosIdler.idle_ms5607, + AltosIdler.idle_sensor_tm), + + new AltosIdler("TeleMetrum-v1", + AltosIdler.idle_gps, + AltosIdler.idle_sensor_tm), + + new AltosIdler("TeleMetrum-v2", + AltosIdler.idle_gps, + AltosIdler.idle_ms5607, AltosIdler.idle_mma655x, + AltosIdler.idle_sensor_metrum), + + new AltosIdler("TeleMega", + AltosIdler.idle_gps, + AltosIdler.idle_ms5607, AltosIdler.idle_mma655x, + AltosIdler.idle_imu, AltosIdler.idle_mag, + AltosIdler.idle_sensor_mega), + }; + + AltosLink link; + + double frequency; + String callsign; + + public void update_state(AltosState state) { + try { + AltosConfigData config_data = new AltosConfigData(link); + state.set_state(AltosLib.ao_flight_startup); + state.set_serial(config_data.serial); + state.set_callsign(config_data.callsign); + state.set_ground_accel(config_data.accel_cal_plus); + state.set_accel_g(config_data.accel_cal_plus, config_data.accel_cal_minus); + for (AltosIdler idler : idlers) { + if (idler.matches(config_data)) { + idler.update_state(state, link, config_data); + break; + } + } + state.set_received_time(System.currentTimeMillis()); + } catch (InterruptedException ie) { + } catch (TimeoutException te) { + } + + } + + public AltosIdleFetch(AltosLink link) { + this.link = link; + } +} diff --git a/altoslib/AltosIdleMonitor.java b/altoslib/AltosIdleMonitor.java index b3ce5b20..d858845a 100644 --- a/altoslib/AltosIdleMonitor.java +++ b/altoslib/AltosIdleMonitor.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2; import java.io.*; import java.util.concurrent.*; @@ -24,11 +24,13 @@ import java.util.concurrent.*; public class AltosIdleMonitor extends Thread { AltosLink link; AltosIdleMonitorListener listener; - AltosState state; + + AltosIdleFetch fetch; + boolean remote; double frequency; String callsign; - AltosState previous_state; + AltosListenerState listener_state; AltosConfigData config_data; AltosGPS gps; @@ -47,86 +49,35 @@ public class AltosIdleMonitor extends Thread { return rssi; } - boolean has_sensor_tm(AltosConfigData config_data) { - return config_data.product.startsWith("TeleMetrum") || config_data.product.startsWith("TeleMini"); - } - - boolean has_sensor_mm(AltosConfigData config_data) { - return config_data.product.startsWith("TeleMega"); - } - - boolean has_gps(AltosConfigData config_data) { - return config_data.product.startsWith("TeleMetrum") || config_data.product.startsWith("TeleMega"); + void start_link() throws InterruptedException, TimeoutException { + if (remote) { + link.set_radio_frequency(frequency); + link.set_callsign(callsign); + link.start_remote(); + } else + link.flush_input(); } - AltosRecord sensor_mm(AltosConfigData config_data) throws InterruptedException, TimeoutException { - AltosRecordMM record_mm = new AltosRecordMM(); - AltosSensorMM sensor = new AltosSensorMM(link); - AltosMs5607 ms5607 = new AltosMs5607Query(link); - AltosIMU imu = new AltosIMUQuery(link); - - record_mm.accel_plus_g = config_data.accel_cal_plus; - record_mm.accel_minus_g = config_data.accel_cal_minus; - - record_mm.ground_accel = sensor.accel; - record_mm.accel = sensor.accel; - record_mm.ground_pres = ms5607.pa; - record_mm.pres = ms5607.pa; - record_mm.temp = ms5607.cc; - - record_mm.v_batt = sensor.v_batt; - record_mm.v_pyro = sensor.v_pyro; - record_mm.sense = sensor.sense; - - record_mm.imu = imu; - - return record_mm; + void stop_link() throws InterruptedException, TimeoutException { + if (remote) + link.stop_remote(); } - void update_state() throws InterruptedException, TimeoutException { - AltosRecord record = null; + void update_state(AltosState state) throws InterruptedException, TimeoutException { + boolean worked = false; try { - if (remote) { - link.set_radio_frequency(frequency); - link.set_callsign(callsign); - link.start_remote(); - } else - link.flush_input(); - config_data = new AltosConfigData(link); - - if (has_sensor_tm(config_data)) - record = new AltosSensorTM(link, config_data); - else if (has_sensor_mm(config_data)) - record = sensor_mm(config_data); - else - record = new AltosRecordNone(); - - if (has_gps(config_data)) - gps = new AltosGPSQuery(link, config_data); - - record.version = 0; - record.callsign = config_data.callsign; - record.serial = config_data.serial; - record.flight = config_data.log_available() > 0 ? 255 : 0; - record.status = 0; - record.state = AltosLib.ao_flight_idle; - record.gps = gps; - record.gps_sequence++; - state = new AltosState (record, state); + start_link(); + fetch.update_state(state); + worked = true; } finally { - if (remote) { - link.stop_remote(); - if (record != null) { - record.rssi = link.rssi(); - listener_state.battery = link.monitor_battery(); - } - } else { - if (record != null) - record.rssi = 0; + stop_link(); + if (worked) { + if (remote) + state.set_rssi(link.rssi(), 0); + listener_state.battery = link.monitor_battery(); } } - } public void set_frequency(double in_frequency) { @@ -139,10 +90,6 @@ public class AltosIdleMonitor extends Thread { link.abort_reply(); } - public void post_state() { - listener.update(state, listener_state); - } - public void abort() { if (isAlive()) { interrupt(); @@ -155,18 +102,20 @@ public class AltosIdleMonitor extends Thread { } public void run() { + AltosState state = new AltosState(); try { - for (;;) { + while (!link.has_error) { try { - update_state(); - post_state(); + link.config_data(); + update_state(state); + listener.update(state, listener_state); } catch (TimeoutException te) { } Thread.sleep(1000); } } catch (InterruptedException ie) { - link.close(); } + link.close(); } public AltosIdleMonitor(AltosIdleMonitorListener in_listener, AltosLink in_link, boolean in_remote) @@ -174,7 +123,7 @@ public class AltosIdleMonitor extends Thread { listener = in_listener; link = in_link; remote = in_remote; - state = null; listener_state = new AltosListenerState(); + fetch = new AltosIdleFetch(link); } } diff --git a/altoslib/AltosIdleMonitorListener.java b/altoslib/AltosIdleMonitorListener.java index 27e36dea..0b03b897 100644 --- a/altoslib/AltosIdleMonitorListener.java +++ b/altoslib/AltosIdleMonitorListener.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2; public interface AltosIdleMonitorListener { public void update(AltosState state, AltosListenerState listener_state); diff --git a/altoslib/AltosIgnite.java b/altoslib/AltosIgnite.java index 85905900..42169989 100644 --- a/altoslib/AltosIgnite.java +++ b/altoslib/AltosIgnite.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2; import java.io.*; import java.util.concurrent.*; diff --git a/altoslib/AltosLib.java b/altoslib/AltosLib.java index d6d78ca8..f8a3974a 100644 --- a/altoslib/AltosLib.java +++ b/altoslib/AltosLib.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2; import java.util.*; import java.io.*; @@ -63,6 +63,8 @@ public class AltosLib { public static final int AO_LOG_SOFTWARE_VERSION = 9999; + public final static int MISSING = 0x7fffffff; + /* Added to flag invalid records */ public static final int AO_LOG_INVALID = -1; diff --git a/altoslib/AltosLine.java b/altoslib/AltosLine.java index b3bd20f9..e5dd13fc 100644 --- a/altoslib/AltosLine.java +++ b/altoslib/AltosLine.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2; public class AltosLine { public String line; diff --git a/altoslib/AltosLink.java b/altoslib/AltosLink.java index 159ebfe1..b1bf525b 100644 --- a/altoslib/AltosLink.java +++ b/altoslib/AltosLink.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2; import java.io.*; import java.util.concurrent.*; @@ -32,6 +32,9 @@ public abstract class AltosLink implements Runnable { public static boolean debug = false; public static void set_debug(boolean in_debug) { debug = in_debug; } + + public boolean has_error; + LinkedList pending_output = new LinkedList(); public LinkedList> monitors = new LinkedList> ();; @@ -107,6 +110,7 @@ public abstract class AltosLink implements Runnable { if (c == ERROR) { if (debug) System.out.printf("ERROR\n"); + has_error = true; add_telem (new AltosLine()); add_reply (new AltosLine()); break; @@ -399,7 +403,7 @@ public abstract class AltosLink implements Runnable { } public double monitor_battery() { - int monitor_batt = AltosRecord.MISSING; + int monitor_batt = AltosLib.MISSING; if (config_data.has_monitor_battery()) { try { @@ -416,12 +420,13 @@ public abstract class AltosLink implements Runnable { } catch (TimeoutException te) { } } - if (monitor_batt == AltosRecord.MISSING) - return AltosRecord.MISSING; + if (monitor_batt == AltosLib.MISSING) + return AltosLib.MISSING; return AltosConvert.cc_battery_to_voltage(monitor_batt); } public AltosLink() { callsign = ""; + has_error = false; } } diff --git a/altoslib/AltosListenerState.java b/altoslib/AltosListenerState.java index 2fb4673e..01dd7afb 100644 --- a/altoslib/AltosListenerState.java +++ b/altoslib/AltosListenerState.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2; public class AltosListenerState { public int crc_errors; @@ -23,6 +23,6 @@ public class AltosListenerState { public AltosListenerState() { crc_errors = 0; - battery = AltosRecord.MISSING; + battery = AltosLib.MISSING; } } diff --git a/altoslib/AltosLog.java b/altoslib/AltosLog.java index 7f69bb65..17b04970 100644 --- a/altoslib/AltosLog.java +++ b/altoslib/AltosLog.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2; import java.io.*; import java.text.ParseException; diff --git a/altoslib/AltosMag.java b/altoslib/AltosMag.java index cb6826f3..56add8f3 100644 --- a/altoslib/AltosMag.java +++ b/altoslib/AltosMag.java @@ -15,13 +15,29 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2; + +import java.util.concurrent.*; public class AltosMag implements Cloneable { public int x; public int y; public int z; + public boolean parse_string(String line) { + if (!line.startsWith("X:")) + return false; + + String[] items = line.split("\\s+"); + + if (items.length >= 6) { + x = Integer.parseInt(items[1]); + y = Integer.parseInt(items[3]); + z = Integer.parseInt(items[5]); + } + return true; + } + public AltosMag clone() { AltosMag n = new AltosMag(); @@ -30,5 +46,35 @@ public class AltosMag implements Cloneable { n.z = z; return n; } + + public AltosMag() { + x = AltosLib.MISSING; + y = AltosLib.MISSING; + z = AltosLib.MISSING; + } + + static public void update_state(AltosState state, AltosLink link, AltosConfigData config_data) { + try { + AltosMag mag = new AltosMag(link); + + if (mag != null) + state.set_mag(mag); + } catch (TimeoutException te) { + } catch (InterruptedException ie) { + } + } + + public AltosMag(AltosLink link) throws InterruptedException, TimeoutException { + this(); + link.printf("M\n"); + for (;;) { + String line = link.get_reply_no_dialog(5000); + if (line == null) { + throw new TimeoutException(); + } + if (parse_string(line)) + break; + } + } } \ No newline at end of file diff --git a/altoslib/AltosMma655x.java b/altoslib/AltosMma655x.java new file mode 100644 index 00000000..8dc947db --- /dev/null +++ b/altoslib/AltosMma655x.java @@ -0,0 +1,69 @@ +/* + * Copyright © 2012 Keith Packard + * + * 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_2; + +import java.util.concurrent.*; + +public class AltosMma655x implements Cloneable { + + int accel; + + public boolean parse_line(String line) { + String[] items = line.split("\\s+"); + if (line.startsWith("MMA655X value:")) { + if (items.length >= 3) + accel = Integer.parseInt(items[1]); + } else + return false; + return true; + } + + public AltosMma655x() { + accel = AltosLib.MISSING; + } + + public AltosMma655x clone() { + AltosMma655x n = new AltosMma655x(); + + n.accel = accel; + return n; + } + + static public void update_state(AltosState state, AltosLink link, AltosConfigData config_data) { + try { + AltosMma655x mma655x = new AltosMma655x(link); + + if (mma655x != null) + state.set_accel(mma655x.accel); + } catch (TimeoutException te) { + } catch (InterruptedException ie) { + } + } + + public AltosMma655x(AltosLink link) throws InterruptedException, TimeoutException { + this(); + link.printf("A\n"); + for (;;) { + String line = link.get_reply_no_dialog(5000); + if (line == null) + throw new TimeoutException(); + if (!parse_line(line)) + break; + } + } +} diff --git a/altoslib/AltosMs5607.java b/altoslib/AltosMs5607.java index 606916b7..b29fa9ae 100644 --- a/altoslib/AltosMs5607.java +++ b/altoslib/AltosMs5607.java @@ -15,7 +15,9 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2; + +import java.util.concurrent.*; public class AltosMs5607 { public int reserved; @@ -83,10 +85,13 @@ public class AltosMs5607 { } public boolean parse_line(String line) { + System.out.printf ("parse %s\n", line); String[] items = line.split("\\s+"); if (line.startsWith("Pressure:")) { - if (items.length >= 2) + if (items.length >= 2) { raw_pres = Integer.parseInt(items[1]); + System.out.printf ("raw_pres %d\n", raw_pres); + } } else if (line.startsWith("Temperature:")) { if (items.length >= 2) raw_temp = Integer.parseInt(items[1]); @@ -94,8 +99,11 @@ public class AltosMs5607 { if (items.length >= 3) reserved = Integer.parseInt(items[2]); } else if (line.startsWith("ms5607 sens:")) { - if (items.length >= 3) + System.out.printf ("found sens length %d\n", items.length); + if (items.length >= 3) { sens = Integer.parseInt(items[2]); + System.out.printf ("sens %d\n", sens); + } } else if (line.startsWith("ms5607 off:")) { if (items.length >= 3) off = Integer.parseInt(items[2]); @@ -114,15 +122,48 @@ public class AltosMs5607 { } else if (line.startsWith("ms5607 crc:")) { if (items.length >= 3) crc = Integer.parseInt(items[2]); - } else if (line.startsWith("Altitude")) + } else if (line.startsWith("Altitude:")) { return false; + } return true; } + static public void update_state(AltosState state, AltosLink link, AltosConfigData config_data) { + try { + AltosMs5607 ms5607 = new AltosMs5607(link); + + if (ms5607 != null) { + state.set_ms5607(ms5607); + return; + } + } catch (TimeoutException te) { + } catch (InterruptedException ie) { + } + } + public AltosMs5607() { - raw_pres = AltosRecord.MISSING; - raw_temp = AltosRecord.MISSING; - pa = AltosRecord.MISSING; - cc = AltosRecord.MISSING; + raw_pres = AltosLib.MISSING; + raw_temp = AltosLib.MISSING; + pa = AltosLib.MISSING; + cc = AltosLib.MISSING; + } + + public AltosMs5607 (AltosLink link) throws InterruptedException, TimeoutException { + this(); + link.printf("c s\nB\n"); + for (;;) { + String line = link.get_reply_no_dialog(5000); + if (line == null) { + throw new TimeoutException(); + } + if (!parse_line(line)) { + System.out.printf ("stop parsing at %s\n", line); + break; + } + } + System.out.printf ("sens %d off %d tcs %d tco %d tref %d tempsens %d crc %d pres %d temp %d\n", + sens, off, tcs, tco, tref, tempsens, crc, raw_pres, raw_temp); + convert(); + System.out.printf ("pa %d cc %d\n", pa, cc); } } diff --git a/altoslib/AltosMs5607Query.java b/altoslib/AltosMs5607Query.java deleted file mode 100644 index d39dbf26..00000000 --- a/altoslib/AltosMs5607Query.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright © 2012 Keith Packard - * - * 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_1; - -import java.util.concurrent.TimeoutException; - -class AltosMs5607Query extends AltosMs5607 { - public AltosMs5607Query (AltosLink link) throws InterruptedException, TimeoutException { - link.printf("v\nB\n"); - for (;;) { - String line = link.get_reply_no_dialog(5000); - if (line == null) { - throw new TimeoutException(); - } - if (!parse_line(line)) - break; - } - convert(); - } -} - diff --git a/altoslib/AltosOrderedMegaRecord.java b/altoslib/AltosOrderedMegaRecord.java deleted file mode 100644 index b20a5bbd..00000000 --- a/altoslib/AltosOrderedMegaRecord.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright © 2010 Keith Packard - * - * 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_1; - -import java.text.ParseException; - -/* - * AltosRecords with an index field so they can be sorted by tick while preserving - * the original ordering for elements with matching ticks - */ -class AltosOrderedMegaRecord extends AltosEepromMega implements Comparable { - - public int index; - - public AltosOrderedMegaRecord(String line, int in_index, int prev_tick, boolean prev_tick_valid) - throws ParseException { - super(line); - if (prev_tick_valid) { - tick |= (prev_tick & ~0xffff); - if (tick < prev_tick) { - if (prev_tick - tick > 0x8000) - tick += 0x10000; - } else { - if (tick - prev_tick > 0x8000) - tick -= 0x10000; - } - } - index = in_index; - } - - public int compareTo(AltosOrderedMegaRecord o) { - int tick_diff = tick - o.tick; - if (tick_diff != 0) - return tick_diff; - return index - o.index; - } -} diff --git a/altoslib/AltosOrderedMetrumRecord.java b/altoslib/AltosOrderedMetrumRecord.java index 02cdf1fe..cc034bff 100644 --- a/altoslib/AltosOrderedMetrumRecord.java +++ b/altoslib/AltosOrderedMetrumRecord.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2; import java.text.ParseException; diff --git a/altoslib/AltosOrderedMiniRecord.java b/altoslib/AltosOrderedMiniRecord.java deleted file mode 100644 index 96888941..00000000 --- a/altoslib/AltosOrderedMiniRecord.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright © 2010 Keith Packard - * - * 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_1; - -import java.text.ParseException; - -/* - * AltosRecords with an index field so they can be sorted by tick while preserving - * the original ordering for elements with matching ticks - */ -class AltosOrderedMiniRecord extends AltosEepromMini implements Comparable { - - public int index; - - public AltosOrderedMiniRecord(String line, int in_index, int prev_tick, boolean prev_tick_valid) - throws ParseException { - super(line); - if (prev_tick_valid) { - tick |= (prev_tick & ~0xffff); - if (tick < prev_tick) { - if (prev_tick - tick > 0x8000) - tick += 0x10000; - } else { - if (tick - prev_tick > 0x8000) - tick -= 0x10000; - } - } - index = in_index; - } - - public int compareTo(AltosOrderedMiniRecord o) { - int tick_diff = tick - o.tick; - if (tick_diff != 0) - return tick_diff; - return index - o.index; - } -} diff --git a/altoslib/AltosOrderedRecord.java b/altoslib/AltosOrderedRecord.java deleted file mode 100644 index 63507d39..00000000 --- a/altoslib/AltosOrderedRecord.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright © 2010 Keith Packard - * - * 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_1; - -import java.text.ParseException; - -/* - * AltosRecords with an index field so they can be sorted by tick while preserving - * the original ordering for elements with matching ticks - */ -class AltosOrderedRecord extends AltosEepromRecord implements Comparable { - - public int index; - - public AltosOrderedRecord(String line, int in_index, int prev_tick, boolean prev_tick_valid) - throws ParseException { - super(line); - if (prev_tick_valid) { - tick |= (prev_tick & ~0xffff); - if (tick < prev_tick) { - if (prev_tick - tick > 0x8000) - tick += 0x10000; - } else { - if (tick - prev_tick > 0x8000) - tick -= 0x10000; - } - } - index = in_index; - } - - public AltosOrderedRecord(int in_cmd, int in_tick, int in_a, int in_b, int in_index) { - super(in_cmd, in_tick, in_a, in_b); - index = in_index; - } - - public String toString() { - return String.format("%d.%d %04x %04x %04x", - cmd, index, tick, a, b); - } - - public int compareTo(AltosOrderedRecord o) { - int tick_diff = tick - o.tick; - if (tick_diff != 0) - return tick_diff; - return index - o.index; - } -} - diff --git a/altoslib/AltosParse.java b/altoslib/AltosParse.java index 66bbeed5..ca96a8f9 100644 --- a/altoslib/AltosParse.java +++ b/altoslib/AltosParse.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2; import java.text.*; diff --git a/altoslib/AltosPreferences.java b/altoslib/AltosPreferences.java index 088ca3d7..c4051f9b 100644 --- a/altoslib/AltosPreferences.java +++ b/altoslib/AltosPreferences.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2; import java.io.*; import java.util.*; diff --git a/altoslib/AltosPreferencesBackend.java b/altoslib/AltosPreferencesBackend.java index fb8a235a..1ea28b01 100644 --- a/altoslib/AltosPreferencesBackend.java +++ b/altoslib/AltosPreferencesBackend.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2; import java.io.File; diff --git a/altoslib/AltosPyro.java b/altoslib/AltosPyro.java index 4dbb4223..0142eac8 100644 --- a/altoslib/AltosPyro.java +++ b/altoslib/AltosPyro.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2; import java.util.*; import java.text.*; diff --git a/altoslib/AltosRecord.java b/altoslib/AltosRecord.java deleted file mode 100644 index 0c8e1db9..00000000 --- a/altoslib/AltosRecord.java +++ /dev/null @@ -1,179 +0,0 @@ -/* - * Copyright © 2010 Keith Packard - * - * 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_1; - -public class AltosRecord implements Comparable , Cloneable { - - public static final int seen_flight = 1; - public static final int seen_sensor = 2; - public static final int seen_temp_volt = 4; - public static final int seen_deploy = 8; - public static final int seen_gps_time = 16; - 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 final static int MISSING = 0x7fffffff; - - /* Every AltosRecord implementation provides these fields */ - - public int version; - public String callsign; - public int serial; - public int flight; - public int rssi; - public int status; - public int state; - public int tick; - - public AltosGPS gps; - public int gps_sequence; - - public double time; /* seconds since boost */ - - public int device_type; - public int config_major; - public int config_minor; - public int apogee_delay; - public int main_deploy; - public int flight_log_max; - public String firmware_version; - - public double accel_plus_g, accel_minus_g; - public double ground_accel; - public double accel; - - public AltosRecordCompanion companion; - - /* Telemetry sources have these values recorded from the flight computer */ - public double kalman_height; - public double kalman_speed; - public double kalman_acceleration; - - /* - * Abstract methods that convert record data - * to standard units: - * - * pressure: Pa - * voltage: V - * acceleration: m/s² - * speed: m/s - * height: m - * temperature: °C - */ - - public double pressure() { return MISSING; } - public double ground_pressure() { return MISSING; } - public double acceleration() { return MISSING; } - - public double altitude() { - double p = pressure(); - - if (p == MISSING) - return MISSING; - return AltosConvert.pressure_to_altitude(p); - } - - public double ground_altitude() { - double p = ground_pressure(); - - if (p == MISSING) - return MISSING; - return AltosConvert.pressure_to_altitude(p); - } - - public double height() { - double g = ground_altitude(); - double a = altitude(); - - if (g == MISSING) - return MISSING; - if (a == MISSING) - return MISSING; - return a - g; - } - - public double battery_voltage() { return MISSING; } - - public double main_voltage() { return MISSING; } - - public double drogue_voltage() { return MISSING; } - - public double temperature() { return MISSING; } - - public AltosIMU imu() { return null; } - - public AltosMag mag() { return null; } - - public String state() { - return AltosLib.state_name(state); - } - - public int compareTo(AltosRecord o) { - return tick - o.tick; - } - - public AltosRecord clone() { - AltosRecord n = new AltosRecord(); - n.copy(this); - return n; - } - - public void copy(AltosRecord old) { - seen = old.seen; - version = old.version; - callsign = old.callsign; - serial = old.serial; - flight = old.flight; - rssi = old.rssi; - status = old.status; - state = old.state; - tick = old.tick; - gps = new AltosGPS(old.gps); - gps_sequence = old.gps_sequence; - companion = old.companion; - kalman_acceleration = old.kalman_acceleration; - kalman_speed = old.kalman_speed; - kalman_height = old.kalman_height; - } - - public AltosRecord() { - seen = 0; - version = 0; - callsign = "N0CALL"; - serial = MISSING; - flight = MISSING; - rssi = 0; - status = 0; - state = AltosLib.ao_flight_startup; - tick = 0; - gps = null; - gps_sequence = 0; - companion = null; - - kalman_acceleration = MISSING; - kalman_speed = MISSING; - kalman_height = MISSING; - - accel_plus_g = MISSING; - accel_minus_g = MISSING; - - } -} diff --git a/altoslib/AltosRecordCompanion.java b/altoslib/AltosRecordCompanion.java deleted file mode 100644 index b153fb5b..00000000 --- a/altoslib/AltosRecordCompanion.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright © 2011 Keith Packard - * - * 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_1; - -public class AltosRecordCompanion { - public final static int board_id_telescience = 0x0a; - public final static int MAX_CHANNELS = 12; - - public int tick; - public int board_id; - public int update_period; - public int channels; - public int[] companion_data; - - public AltosRecordCompanion(int in_channels) { - channels = in_channels; - if (channels < 0) - channels = 0; - if (channels > MAX_CHANNELS) - channels = MAX_CHANNELS; - companion_data = new int[channels]; - } -} diff --git a/altoslib/AltosRecordIterable.java b/altoslib/AltosRecordIterable.java deleted file mode 100644 index 62dbdfe3..00000000 --- a/altoslib/AltosRecordIterable.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright © 2010 Keith Packard - * - * 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_1; - -import java.io.*; -import java.util.*; - -public abstract class AltosRecordIterable implements Iterable { - public abstract Iterator iterator(); - public void write_comments(PrintStream out) { } - public boolean has_accel() { return false; } - public boolean has_gps() { return false; } - public boolean has_ignite() { return false; }; -} diff --git a/altoslib/AltosRecordMM.java b/altoslib/AltosRecordMM.java deleted file mode 100644 index d697111c..00000000 --- a/altoslib/AltosRecordMM.java +++ /dev/null @@ -1,178 +0,0 @@ -/* - * Copyright © 2012 Keith Packard - * - * 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_1; - -public class AltosRecordMM extends AltosRecord { - - /* Sensor values */ - 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 pressure() { - if (pres != MISSING) - return pres; - return MISSING; - } - - public double ground_pressure() { - if (ground_pres != MISSING) - return ground_pres; - return MISSING; - } - - public double battery_voltage() { - if (v_batt != MISSING) - return 3.3 * adc(v_batt) * (15.0 + 27.0) / 27.0; - return MISSING; - } - - static double pyro(int raw) { - if (raw != MISSING) - return 3.3 * adc(raw) * (100.0 + 27.0) / 27.0; - return MISSING; - } - - public double main_voltage() { - return pyro(sense[5]); - } - - public double drogue_voltage() { - return pyro(sense[4]); - } - - 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() { - 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 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() { - return new AltosRecordMM(this); - } - - 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(AltosRecordMM old) { - copy(old); - } - - public AltosRecordMM() { - super(); - make_missing(); - } -} diff --git a/altoslib/AltosRecordMini.java b/altoslib/AltosRecordMini.java deleted file mode 100644 index dacd89b8..00000000 --- a/altoslib/AltosRecordMini.java +++ /dev/null @@ -1,133 +0,0 @@ -/* - * Copyright © 2012 Keith Packard - * - * 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_1; - -public class AltosRecordMini extends AltosRecord { - - /* Sensor values */ - public int pres; - public int temp; - - public int sense_a; - public int sense_m; - public int v_batt; - - public int ground_pres; - - public int flight_accel; - public int flight_vel; - public int flight_height; - - public int flight_pres; - - static double adc(int raw) { - return raw / 4095.0; - } - - public double pressure() { - if (pres != MISSING) - return pres; - return MISSING; - } - - public double temperature() { - if (temp != MISSING) - return temp; - return MISSING; - } - - public double ground_pressure() { - if (ground_pres != MISSING) - return ground_pres; - return MISSING; - } - - public double battery_voltage() { - if (v_batt != MISSING) - return 3.3 * adc(v_batt) * (15.0 + 27.0) / 27.0; - return MISSING; - } - - static double pyro(int raw) { - if (raw != MISSING) - return 3.3 * adc(raw) * (100.0 + 27.0) / 27.0; - return MISSING; - } - - public double main_voltage() { - return pyro(sense_m); - } - - public double apogee_voltage() { - return pyro(sense_a); - } - - public void copy (AltosRecordMini old) { - super.copy(old); - - pres = old.pres; - temp = old.temp; - - sense_a = old.sense_a; - sense_m = old.sense_m; - v_batt = old.v_batt; - - ground_pres = old.ground_pres; - - flight_accel = old.flight_accel; - flight_vel = old.flight_vel; - flight_height = old.flight_height; - flight_pres = old.flight_pres; - } - - - - public AltosRecordMini clone() { - return new AltosRecordMini(this); - } - - void make_missing() { - - pres = MISSING; - - sense_a = MISSING; - sense_m = MISSING; - v_batt = MISSING; - - ground_pres = MISSING; - - flight_accel = 0; - flight_vel = 0; - flight_height = 0; - flight_pres = 0; - } - - public AltosRecordMini(AltosRecord old) { - super.copy(old); - make_missing(); - } - - public AltosRecordMini(AltosRecordMini old) { - copy(old); - } - - public AltosRecordMini() { - super(); - make_missing(); - } -} diff --git a/altoslib/AltosRecordNone.java b/altoslib/AltosRecordNone.java deleted file mode 100644 index a95b6a9c..00000000 --- a/altoslib/AltosRecordNone.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright © 2012 Keith Packard - * - * 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_1; - -public class AltosRecordNone extends AltosRecord { - - public double pressure() { return MISSING; } - public double ground_pressure() { return MISSING; } - public double temperature() { return MISSING; } - public double acceleration() { return MISSING; } - - public AltosRecordNone(AltosRecord old) { - super.copy(old); - } - - public AltosRecordNone clone() { - return new AltosRecordNone(this); - } - - public AltosRecordNone() { - super(); - } -} diff --git a/altoslib/AltosRecordTM.java b/altoslib/AltosRecordTM.java deleted file mode 100644 index c6cf3646..00000000 --- a/altoslib/AltosRecordTM.java +++ /dev/null @@ -1,186 +0,0 @@ -/* - * Copyright © 2012 Keith Packard - * - * 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_1; - -public class AltosRecordTM extends AltosRecord { - - /* Sensor values */ - 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 pressure() { - if (pres == MISSING) - return MISSING; - return barometer_to_pressure(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 (ground_accel == MISSING || accel == MISSING) - return MISSING; - return (ground_accel - accel) / accel_counts_per_mss(); - } - - 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() { - return new AltosRecordTM(this); - } - - void make_missing() { - accel = MISSING; - pres = MISSING; - temp = MISSING; - batt = MISSING; - drogue = MISSING; - main = MISSING; - - flight_accel = MISSING; - flight_vel = MISSING; - flight_pres = MISSING; - - ground_accel = MISSING; - ground_pres = MISSING; - accel_plus_g = MISSING; - accel_minus_g = MISSING; - } - - public AltosRecordTM(AltosRecord old) { - super.copy(old); - make_missing(); - } - - public AltosRecordTM(AltosRecordTM old) { - copy(old); - } - - public AltosRecordTM() { - super(); - make_missing(); - } -} diff --git a/altoslib/AltosRecordTM2.java b/altoslib/AltosRecordTM2.java index 0cd54f2c..da2d948c 100644 --- a/altoslib/AltosRecordTM2.java +++ b/altoslib/AltosRecordTM2.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2; public class AltosRecordTM2 extends AltosRecord { diff --git a/altoslib/AltosReplayReader.java b/altoslib/AltosReplayReader.java index 0c14dee4..f65caaa0 100644 --- a/altoslib/AltosReplayReader.java +++ b/altoslib/AltosReplayReader.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2; import java.io.*; import java.util.*; diff --git a/altoslib/AltosRomconfig.java b/altoslib/AltosRomconfig.java index 0800a2c4..e9d3147e 100644 --- a/altoslib/AltosRomconfig.java +++ b/altoslib/AltosRomconfig.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2; import java.io.*; diff --git a/altoslib/AltosSelfFlash.java b/altoslib/AltosSelfFlash.java index 07917d5d..0ae797a0 100644 --- a/altoslib/AltosSelfFlash.java +++ b/altoslib/AltosSelfFlash.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2; import java.io.*; diff --git a/altoslib/AltosSensorEMini.java b/altoslib/AltosSensorEMini.java new file mode 100644 index 00000000..cbc65143 --- /dev/null +++ b/altoslib/AltosSensorEMini.java @@ -0,0 +1,70 @@ +/* + * Copyright © 2012 Keith Packard + * + * 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_2; + +import java.util.concurrent.TimeoutException; + +public class AltosSensorEMini { + public int tick; + public int apogee; + public int main; + public int batt; + + static public void update_state(AltosState state, AltosLink link, AltosConfigData config_data) { + try { + AltosSensorEMini sensor_emini = new AltosSensorEMini(link); + + if (sensor_emini == null) + return; + state.set_battery_voltage(AltosConvert.easy_mini_voltage(sensor_emini.batt)); + state.set_apogee_voltage(AltosConvert.easy_mini_voltage(sensor_emini.apogee)); + state.set_main_voltage(AltosConvert.easy_mini_voltage(sensor_emini.main)); + + } catch (TimeoutException te) { + } catch (InterruptedException ie) { + } + } + + public AltosSensorEMini(AltosLink link) throws InterruptedException, TimeoutException { + String[] items = link.adc(); + for (int i = 0; i < items.length;) { + if (items[i].equals("tick:")) { + tick = Integer.parseInt(items[i+1]); + i += 2; + continue; + } + if (items[i].equals("apogee:")) { + apogee = Integer.parseInt(items[i+1]); + i += 2; + continue; + } + if (items[i].equals("main:")) { + main = Integer.parseInt(items[i+1]); + i += 2; + continue; + } + if (items[i].equals("batt:")) { + batt = Integer.parseInt(items[i+1]); + i += 2; + continue; + } + i++; + } + } +} + diff --git a/altoslib/AltosSensorMM.java b/altoslib/AltosSensorMM.java index 6d1b61c0..0ef42cf6 100644 --- a/altoslib/AltosSensorMM.java +++ b/altoslib/AltosSensorMM.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2; import java.util.concurrent.TimeoutException; diff --git a/altoslib/AltosSensorMega.java b/altoslib/AltosSensorMega.java new file mode 100644 index 00000000..3afb8a64 --- /dev/null +++ b/altoslib/AltosSensorMega.java @@ -0,0 +1,109 @@ +/* + * Copyright © 2013 Keith Packard + * + * 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_2; + +import java.util.concurrent.TimeoutException; + +class AltosSensorMega { + int tick; + int[] sense; + int v_batt; + int v_pbatt; + int temp; + + public AltosSensorMega() { + sense = new int[6]; + } + + public AltosSensorMega(AltosLink link) throws InterruptedException, TimeoutException { + this(); + String[] items = link.adc(); + for (int i = 0; i < items.length;) { + if (items[i].equals("tick:")) { + tick = Integer.parseInt(items[i+1]); + i += 2; + continue; + } + if (items[i].equals("A:")) { + sense[0] = Integer.parseInt(items[i+1]); + i += 2; + continue; + } + if (items[i].equals("B:")) { + sense[1] = Integer.parseInt(items[i+1]); + i += 2; + continue; + } + if (items[i].equals("C:")) { + sense[2] = Integer.parseInt(items[i+1]); + i += 2; + continue; + } + if (items[i].equals("D:")) { + sense[3] = Integer.parseInt(items[i+1]); + i += 2; + continue; + } + if (items[i].equals("drogue:")) { + sense[4] = Integer.parseInt(items[i+1]); + i += 2; + continue; + } + if (items[i].equals("main:")) { + sense[5] = Integer.parseInt(items[i+1]); + i += 2; + continue; + } + if (items[i].equals("batt:")) { + v_batt = Integer.parseInt(items[i+1]); + i += 2; + continue; + } + if (items[i].equals("pbatt:")) { + v_pbatt = Integer.parseInt(items[i+1]); + i += 2; + continue; + } + if (items[i].equals("temp:")) { + temp = Integer.parseInt(items[i+1]); + i += 2; + continue; + } + i++; + } + } + + static public void update_state(AltosState state, AltosLink link, AltosConfigData config_data) { + try { + AltosSensorMega sensor_mega = new AltosSensorMega(link); + + state.set_battery_voltage(AltosConvert.mega_battery_voltage(sensor_mega.v_batt)); + state.set_apogee_voltage(AltosConvert.mega_pyro_voltage(sensor_mega.sense[4])); + state.set_main_voltage(AltosConvert.mega_pyro_voltage(sensor_mega.sense[5])); + + double[] ignitor_voltage = new double[4]; + for (int i = 0; i < 4; i++) + ignitor_voltage[i] = AltosConvert.mega_pyro_voltage(sensor_mega.sense[i]); + state.set_ignitor_voltage(ignitor_voltage); + + } catch (TimeoutException te) { + } catch (InterruptedException ie) { + } + } +} + diff --git a/altoslib/AltosSensorMetrum.java b/altoslib/AltosSensorMetrum.java index 686c78a8..4a51d492 100644 --- a/altoslib/AltosSensorMetrum.java +++ b/altoslib/AltosSensorMetrum.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2; import java.util.concurrent.TimeoutException; @@ -51,5 +51,16 @@ class AltosSensorMetrum { i++; } } + + static public void update_state(AltosState state, AltosLink link, AltosConfigData config_data) { + try { + AltosSensorMetrum sensor_metrum = new AltosSensorMetrum(link); + state.set_battery_voltage(AltosConvert.mega_battery_voltage(sensor_metrum.v_batt)); + state.set_apogee_voltage(AltosConvert.mega_pyro_voltage(sensor_metrum.sense_a)); + state.set_main_voltage(AltosConvert.mega_pyro_voltage(sensor_metrum.sense_m)); + } catch (TimeoutException te) { + } catch (InterruptedException ie) { + } + } } diff --git a/altoslib/AltosSensorTM.java b/altoslib/AltosSensorTM.java index 754dc5bb..2696a308 100644 --- a/altoslib/AltosSensorTM.java +++ b/altoslib/AltosSensorTM.java @@ -15,14 +15,38 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2; import java.util.concurrent.TimeoutException; -class AltosSensorTM extends AltosRecordTM { +public class AltosSensorTM { + public int tick; + public int accel; + public int pres; + public int temp; + public int batt; + public int drogue; + public int main; - public AltosSensorTM(AltosLink link, AltosConfigData config_data) throws InterruptedException, TimeoutException { - super(); + static public void update_state(AltosState state, AltosLink link, AltosConfigData config_data) { + try { + AltosSensorTM sensor_tm = new AltosSensorTM(link); + + if (sensor_tm == null) + return; + state.set_accel(sensor_tm.accel); + state.set_pressure(AltosConvert.barometer_to_pressure(sensor_tm.pres)); + state.set_temperature(AltosConvert.thermometer_to_temperature(sensor_tm.temp)); + state.set_battery_voltage(AltosConvert.cc_battery_to_voltage(sensor_tm.batt)); + state.set_apogee_voltage(AltosConvert.cc_ignitor_to_voltage(sensor_tm.drogue)); + state.set_main_voltage(AltosConvert.cc_ignitor_to_voltage(sensor_tm.main)); + + } catch (TimeoutException te) { + } catch (InterruptedException ie) { + } + } + + public AltosSensorTM(AltosLink link) throws InterruptedException, TimeoutException { String[] items = link.adc(); for (int i = 0; i < items.length;) { if (items[i].equals("tick:")) { @@ -62,10 +86,6 @@ class AltosSensorTM extends AltosRecordTM { } i++; } - ground_accel = config_data.accel_cal_plus; - ground_pres = pres; - accel_plus_g = config_data.accel_cal_plus; - accel_minus_g = config_data.accel_cal_minus; } } diff --git a/altoslib/AltosSpeed.java b/altoslib/AltosSpeed.java index 6fb624fb..9b9f7240 100644 --- a/altoslib/AltosSpeed.java +++ b/altoslib/AltosSpeed.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2; public class AltosSpeed extends AltosUnits { diff --git a/altoslib/AltosState.java b/altoslib/AltosState.java index 1c400bab..dba9bff8 100644 --- a/altoslib/AltosState.java +++ b/altoslib/AltosState.java @@ -19,10 +19,9 @@ * Track flight state from telemetry or eeprom data stream */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2; public class AltosState implements Cloneable { - public AltosRecord record; public static final int set_position = 1; public static final int set_gps = 2; @@ -53,9 +52,9 @@ public class AltosState implements Cloneable { private double max_rate = 1000.0; void set(double new_value, double time) { - if (new_value != AltosRecord.MISSING) { + if (new_value != AltosLib.MISSING) { value = new_value; - if (max_value == AltosRecord.MISSING || value > max_value) { + if (max_value == AltosLib.MISSING || value > max_value) { max_value = value; } set_time = time; @@ -63,7 +62,7 @@ public class AltosState implements Cloneable { } void set_filtered(double new_value, double time) { - if (prev_value != AltosRecord.MISSING) + if (prev_value != AltosLib.MISSING) new_value = (prev_value * 15.0 + new_value) / 16.0; set(new_value, time); } @@ -81,25 +80,25 @@ public class AltosState implements Cloneable { } double change() { - if (value != AltosRecord.MISSING && prev_value != AltosRecord.MISSING) + if (value != AltosLib.MISSING && prev_value != AltosLib.MISSING) return value - prev_value; - return AltosRecord.MISSING; + return AltosLib.MISSING; } double rate() { double c = change(); double t = set_time - prev_set_time; - if (c != AltosRecord.MISSING && t != 0) + if (c != AltosLib.MISSING && t != 0) return c / t; - return AltosRecord.MISSING; + return AltosLib.MISSING; } double integrate() { - if (value == AltosRecord.MISSING) - return AltosRecord.MISSING; - if (prev_value == AltosRecord.MISSING) - return AltosRecord.MISSING; + if (value == AltosLib.MISSING) + return AltosLib.MISSING; + if (prev_value == AltosLib.MISSING) + return AltosLib.MISSING; return (value + prev_value) / 2 * (set_time - prev_set_time); } @@ -111,13 +110,13 @@ public class AltosState implements Cloneable { void set_derivative(AltosValue in) { double n = in.rate(); - if (n == AltosRecord.MISSING) + if (n == AltosLib.MISSING) return; double p = prev_value; double pt = prev_set_time; - if (p == AltosRecord.MISSING) { + if (p == AltosLib.MISSING) { p = 0; pt = in.time() - 0.01; } @@ -150,9 +149,9 @@ public class AltosState implements Cloneable { void set_integral(AltosValue in) { double change = in.integrate(); - if (change != AltosRecord.MISSING) { + if (change != AltosLib.MISSING) { double prev = prev_value; - if (prev == AltosRecord.MISSING) + if (prev == AltosLib.MISSING) prev = 0; set(prev + change, in.time()); } @@ -166,10 +165,15 @@ public class AltosState implements Cloneable { max_value = old.max_value; } + void finish_update() { + prev_value = value; + prev_set_time = set_time; + } + AltosValue() { - value = AltosRecord.MISSING; - prev_value = AltosRecord.MISSING; - max_value = AltosRecord.MISSING; + value = AltosLib.MISSING; + prev_value = AltosLib.MISSING; + max_value = AltosLib.MISSING; } } @@ -179,45 +183,45 @@ public class AltosState implements Cloneable { double value() { double v = measured.value(); - if (v != AltosRecord.MISSING) + if (v != AltosLib.MISSING) return v; return computed.value(); } boolean is_measured() { - return measured.value() != AltosRecord.MISSING; + return measured.value() != AltosLib.MISSING; } double max() { double m = measured.max(); - if (m != AltosRecord.MISSING) + if (m != AltosLib.MISSING) return m; return computed.max(); } double prev_value() { - if (measured.value != AltosRecord.MISSING && measured.prev_value != AltosRecord.MISSING) + if (measured.value != AltosLib.MISSING && measured.prev_value != AltosLib.MISSING) return measured.prev_value; return computed.prev_value; } AltosValue altos_value() { - if (measured.value() != AltosRecord.MISSING) + if (measured.value() != AltosLib.MISSING) return measured; return computed; } double change() { double c = measured.change(); - if (c == AltosRecord.MISSING) + if (c == AltosLib.MISSING) c = computed.change(); return c; } double rate() { double r = measured.rate(); - if (r == AltosRecord.MISSING) + if (r == AltosLib.MISSING) r = computed.rate(); return r; } @@ -251,6 +255,11 @@ public class AltosState implements Cloneable { computed.copy(old.computed); } + void finish_update() { + measured.finish_update(); + computed.finish_update(); + } + AltosCValue() { measured = new AltosValue(); computed = new AltosValue(); @@ -273,8 +282,8 @@ public class AltosState implements Cloneable { public int flight_log_max; private double pressure_to_altitude(double p) { - if (p == AltosRecord.MISSING) - return AltosRecord.MISSING; + if (p == AltosLib.MISSING) + return AltosLib.MISSING; return AltosConvert.pressure_to_altitude(p); } @@ -334,18 +343,18 @@ public class AltosState implements Cloneable { public double altitude() { double a = altitude.value(); - if (a != AltosRecord.MISSING) + if (a != AltosLib.MISSING) return a; if (gps != null) return gps.alt; - return AltosRecord.MISSING; + return AltosLib.MISSING; } public double max_altitude() { double a = altitude.max(); - if (a != AltosRecord.MISSING) + if (a != AltosLib.MISSING) return a; - return AltosRecord.MISSING; + return AltosLib.MISSING; } public void set_altitude(double new_altitude) { @@ -374,26 +383,26 @@ public class AltosState implements Cloneable { public double height() { double k = kalman_height.value(); - if (k != AltosRecord.MISSING) + if (k != AltosLib.MISSING) return k; double a = altitude(); double g = ground_altitude(); - if (a != AltosRecord.MISSING && g != AltosRecord.MISSING) + if (a != AltosLib.MISSING && g != AltosLib.MISSING) return a - g; - return AltosRecord.MISSING; + return AltosLib.MISSING; } public double max_height() { double k = kalman_height.max(); - if (k != AltosRecord.MISSING) + if (k != AltosLib.MISSING) return k; double a = altitude.max(); double g = ground_altitude(); - if (a != AltosRecord.MISSING && g != AltosRecord.MISSING) + if (a != AltosLib.MISSING && g != AltosLib.MISSING) return a - g; - return AltosRecord.MISSING; + return AltosLib.MISSING; } class AltosSpeed extends AltosCValue { @@ -421,10 +430,16 @@ public class AltosState implements Cloneable { private AltosSpeed speed; public double speed() { + double v = kalman_speed.value(); + if (v != AltosLib.MISSING) + return v; return speed.value(); } public double max_speed() { + double v = kalman_speed.max(); + if (v != AltosLib.MISSING) + return v; return speed.max(); } @@ -503,7 +518,7 @@ public class AltosState implements Cloneable { public AltosMs5607 baro; - public AltosRecordCompanion companion; + public AltosCompanion companion; public void set_npad(int npad) { this.npad = npad; @@ -514,29 +529,27 @@ public class AltosState implements Cloneable { } public void init() { - record = null; - set = 0; received_time = System.currentTimeMillis(); - time = AltosRecord.MISSING; - time_change = AltosRecord.MISSING; - prev_time = AltosRecord.MISSING; - tick = AltosRecord.MISSING; - prev_tick = AltosRecord.MISSING; - boost_tick = AltosRecord.MISSING; + time = AltosLib.MISSING; + time_change = AltosLib.MISSING; + prev_time = AltosLib.MISSING; + tick = AltosLib.MISSING; + prev_tick = AltosLib.MISSING; + boost_tick = AltosLib.MISSING; state = AltosLib.ao_flight_invalid; - flight = AltosRecord.MISSING; + flight = AltosLib.MISSING; landed = false; boost = false; - rssi = AltosRecord.MISSING; + rssi = AltosLib.MISSING; status = 0; - device_type = AltosRecord.MISSING; - config_major = AltosRecord.MISSING; - config_minor = AltosRecord.MISSING; - apogee_delay = AltosRecord.MISSING; - main_deploy = AltosRecord.MISSING; - flight_log_max = AltosRecord.MISSING; + device_type = AltosLib.MISSING; + config_major = AltosLib.MISSING; + config_minor = AltosLib.MISSING; + apogee_delay = AltosLib.MISSING; + main_deploy = AltosLib.MISSING; + flight_log_max = AltosLib.MISSING; ground_altitude = new AltosCValue(); ground_pressure = new AltosGroundPressure(); @@ -545,11 +558,11 @@ public class AltosState implements Cloneable { speed = new AltosSpeed(); acceleration = new AltosAccel(); - temperature = AltosRecord.MISSING; - battery_voltage = AltosRecord.MISSING; - pyro_voltage = AltosRecord.MISSING; - apogee_voltage = AltosRecord.MISSING; - main_voltage = AltosRecord.MISSING; + temperature = AltosLib.MISSING; + battery_voltage = AltosLib.MISSING; + pyro_voltage = AltosLib.MISSING; + apogee_voltage = AltosLib.MISSING; + main_voltage = AltosLib.MISSING; ignitor_voltage = null; kalman_height = new AltosValue(); @@ -569,36 +582,48 @@ public class AltosState implements Cloneable { ngps = 0; from_pad = null; - elevation = AltosRecord.MISSING; - range = AltosRecord.MISSING; - gps_height = AltosRecord.MISSING; + elevation = AltosLib.MISSING; + range = AltosLib.MISSING; + gps_height = AltosLib.MISSING; - pad_lat = AltosRecord.MISSING; - pad_lon = AltosRecord.MISSING; - pad_alt = AltosRecord.MISSING; + pad_lat = AltosLib.MISSING; + pad_lon = AltosLib.MISSING; + pad_alt = AltosLib.MISSING; - speak_tick = AltosRecord.MISSING; - speak_altitude = AltosRecord.MISSING; + speak_tick = AltosLib.MISSING; + speak_altitude = AltosLib.MISSING; callsign = null; - accel_plus_g = AltosRecord.MISSING; - accel_minus_g = AltosRecord.MISSING; - accel = AltosRecord.MISSING; + accel_plus_g = AltosLib.MISSING; + accel_minus_g = AltosLib.MISSING; + accel = AltosLib.MISSING; - ground_accel = AltosRecord.MISSING; - ground_accel_avg = AltosRecord.MISSING; + ground_accel = AltosLib.MISSING; + ground_accel_avg = AltosLib.MISSING; - log_format = AltosRecord.MISSING; - serial = AltosRecord.MISSING; + log_format = AltosLib.MISSING; + serial = AltosLib.MISSING; baro = null; companion = null; } - void copy(AltosState old) { + void finish_update() { + prev_tick = tick; - record = null; + ground_altitude.finish_update(); + altitude.finish_update(); + pressure.finish_update(); + speed.finish_update(); + acceleration.finish_update(); + + kalman_height.finish_update(); + kalman_speed.finish_update(); + kalman_acceleration.finish_update(); + } + + void copy(AltosState old) { if (old == null) { init(); @@ -718,25 +743,25 @@ public class AltosState implements Cloneable { /* Track consecutive 'good' gps reports, waiting for 10 of them */ if (state == AltosLib.ao_flight_pad) { set_npad(npad+1); - if (pad_lat != AltosRecord.MISSING) { + if (pad_lat != AltosLib.MISSING) { pad_lat = (pad_lat * 31 + gps.lat) / 32; pad_lon = (pad_lon * 31 + gps.lon) / 32; pad_alt = (pad_alt * 31 + gps.alt) / 32; } } - if (pad_lat == AltosRecord.MISSING) { + if (pad_lat == AltosLib.MISSING) { pad_lat = gps.lat; pad_lon = gps.lon; pad_alt = gps.alt; } } if (gps.lat != 0 && gps.lon != 0 && - pad_lat != AltosRecord.MISSING && - pad_lon != AltosRecord.MISSING) + pad_lat != AltosLib.MISSING && + pad_lon != AltosLib.MISSING) { double h = height(); - if (h == AltosRecord.MISSING) + if (h == AltosLib.MISSING) h = 0; from_pad = new AltosGreatCircle(pad_lat, pad_lon, 0, gps.lat, gps.lon, h); elevation = from_pad.elevation; @@ -746,9 +771,9 @@ public class AltosState implements Cloneable { } public void set_tick(int new_tick) { - if (new_tick != AltosRecord.MISSING) { - if (prev_tick != AltosRecord.MISSING) { - while (new_tick < prev_tick - 32767) { + if (new_tick != AltosLib.MISSING) { + if (prev_tick != AltosLib.MISSING) { + while (new_tick < prev_tick - 1000) { new_tick += 65536; } } @@ -758,7 +783,7 @@ public class AltosState implements Cloneable { } public void set_boost_tick(int boost_tick) { - if (boost_tick != AltosRecord.MISSING) + if (boost_tick != AltosLib.MISSING) this.boost_tick = boost_tick; } @@ -799,8 +824,8 @@ public class AltosState implements Cloneable { public void set_flight(int flight) { /* When the flight changes, reset the state */ - if (flight != AltosRecord.MISSING) { - if (this.flight != AltosRecord.MISSING && + if (flight != AltosLib.MISSING && flight != 0) { + if (this.flight != AltosLib.MISSING && this.flight != flight) { init(); } @@ -810,8 +835,8 @@ public class AltosState implements Cloneable { public void set_serial(int serial) { /* When the serial changes, reset the state */ - if (serial != AltosRecord.MISSING) { - if (this.serial != AltosRecord.MISSING && + if (serial != AltosLib.MISSING) { + if (this.serial != AltosLib.MISSING && this.serial != serial) { init(); } @@ -820,13 +845,13 @@ public class AltosState implements Cloneable { } public int rssi() { - if (rssi == AltosRecord.MISSING) + if (rssi == AltosLib.MISSING) return 0; return rssi; } public void set_rssi(int rssi, int status) { - if (rssi != AltosRecord.MISSING) { + if (rssi != AltosLib.MISSING) { this.rssi = rssi; this.status = status; } @@ -845,9 +870,29 @@ public class AltosState implements Cloneable { } } - public void make_baro() { + public void set_imu(AltosIMU imu) { + if (imu != null) + imu = imu.clone(); + this.imu = imu; + } + + public void set_mag(AltosMag mag) { + this.mag = mag.clone(); + } + + public AltosMs5607 make_baro() { if (baro == null) baro = new AltosMs5607(); + return baro; + } + + public void set_ms5607(AltosMs5607 ms5607) { + baro = ms5607; + + if (baro != null) { + set_pressure(baro.pa); + set_temperature(baro.cc / 100.0); + } } public void set_ms5607(int pres, int temp) { @@ -861,25 +906,25 @@ public class AltosState implements Cloneable { public void make_companion (int nchannels) { if (companion == null) - companion = new AltosRecordCompanion(nchannels); + companion = new AltosCompanion(nchannels); } - public void set_companion(AltosRecordCompanion companion) { + public void set_companion(AltosCompanion companion) { this.companion = companion; } void update_accel() { double ground = ground_accel; - if (ground == AltosRecord.MISSING) + if (ground == AltosLib.MISSING) ground = ground_accel_avg; - if (accel == AltosRecord.MISSING) + if (accel == AltosLib.MISSING) return; - if (ground == AltosRecord.MISSING) + if (ground == AltosLib.MISSING) return; - if (accel_plus_g == AltosRecord.MISSING) + if (accel_plus_g == AltosLib.MISSING) return; - if (accel_minus_g == AltosRecord.MISSING) + if (accel_minus_g == AltosLib.MISSING) return; double counts_per_g = (accel_minus_g - accel_plus_g) / 2.0; @@ -888,7 +933,7 @@ public class AltosState implements Cloneable { } public void set_accel_g(double accel_plus_g, double accel_minus_g) { - if (accel_plus_g != AltosRecord.MISSING) { + if (accel_plus_g != AltosLib.MISSING) { this.accel_plus_g = accel_plus_g; this.accel_minus_g = accel_minus_g; update_accel(); @@ -896,17 +941,17 @@ public class AltosState implements Cloneable { } public void set_ground_accel(double ground_accel) { - if (ground_accel != AltosRecord.MISSING) { + if (ground_accel != AltosLib.MISSING) { this.ground_accel = ground_accel; update_accel(); } } public void set_accel(double accel) { - if (accel != AltosRecord.MISSING) { + if (accel != AltosLib.MISSING) { this.accel = accel; if (state == AltosLib.ao_flight_pad) { - if (ground_accel_avg == AltosRecord.MISSING) + if (ground_accel_avg == AltosLib.MISSING) ground_accel_avg = accel; else ground_accel_avg = (ground_accel_avg * 7 + accel) / 8; @@ -916,35 +961,35 @@ public class AltosState implements Cloneable { } public void set_temperature(double temperature) { - if (temperature != AltosRecord.MISSING) { + if (temperature != AltosLib.MISSING) { this.temperature = temperature; set |= set_data; } } public void set_battery_voltage(double battery_voltage) { - if (battery_voltage != AltosRecord.MISSING) { + if (battery_voltage != AltosLib.MISSING) { this.battery_voltage = battery_voltage; set |= set_data; } } public void set_pyro_voltage(double pyro_voltage) { - if (pyro_voltage != AltosRecord.MISSING) { + if (pyro_voltage != AltosLib.MISSING) { this.pyro_voltage = pyro_voltage; set |= set_data; } } public void set_apogee_voltage(double apogee_voltage) { - if (apogee_voltage != AltosRecord.MISSING) { + if (apogee_voltage != AltosLib.MISSING) { this.apogee_voltage = apogee_voltage; set |= set_data; } } public void set_main_voltage(double main_voltage) { - if (main_voltage != AltosRecord.MISSING) { + if (main_voltage != AltosLib.MISSING) { this.main_voltage = main_voltage; set |= set_data; } @@ -955,17 +1000,17 @@ public class AltosState implements Cloneable { } public double time_since_boost() { - if (tick == AltosRecord.MISSING) + if (tick == AltosLib.MISSING) return 0.0; - if (boost_tick != AltosRecord.MISSING) { + if (boost_tick != AltosLib.MISSING) { return (tick - boost_tick) / 100.0; } return tick / 100.0; } public boolean valid() { - return tick != AltosRecord.MISSING && serial != AltosRecord.MISSING; + return tick != AltosLib.MISSING && serial != AltosLib.MISSING; } public AltosGPS make_temp_gps(boolean sats) { @@ -993,56 +1038,6 @@ public class AltosState implements Cloneable { return s; } - - public void init (AltosRecord cur, AltosState prev_state) { - - System.out.printf ("init\n"); - if (cur == null) - cur = new AltosRecord(); - - record = cur; - - /* Discard previous state if it was for a different board */ - if (prev_state != null && prev_state.serial != cur.serial) - prev_state = null; - - copy(prev_state); - - set_ground_altitude(cur.ground_altitude()); - set_altitude(cur.altitude()); - - set_kalman(cur.kalman_height, cur.kalman_speed, cur.kalman_acceleration); - - received_time = System.currentTimeMillis(); - - set_temperature(cur.temperature()); - set_apogee_voltage(cur.drogue_voltage()); - set_main_voltage(cur.main_voltage()); - set_battery_voltage(cur.battery_voltage()); - - set_pressure(cur.pressure()); - - set_tick(cur.tick); - set_state(cur.state); - - set_accel_g (cur.accel_minus_g, cur.accel_plus_g); - set_ground_accel(cur.ground_accel); - set_accel (cur.accel); - - if (cur.gps_sequence != gps_sequence) - set_gps(cur.gps, cur.gps_sequence); - - } - - public AltosState(AltosRecord cur) { - init(cur, null); - } - - public AltosState (AltosRecord cur, AltosState prev) { - init(cur, prev); - } - - public AltosState () { init(); } diff --git a/altoslib/AltosStateIterable.java b/altoslib/AltosStateIterable.java index db4a2568..6d637419 100644 --- a/altoslib/AltosStateIterable.java +++ b/altoslib/AltosStateIterable.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2; import java.io.*; import java.util.*; diff --git a/altoslib/AltosStateUpdate.java b/altoslib/AltosStateUpdate.java index 50460e21..ec4f7609 100644 --- a/altoslib/AltosStateUpdate.java +++ b/altoslib/AltosStateUpdate.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2; public interface AltosStateUpdate { public void update_state(AltosState state); diff --git a/altoslib/AltosTelemetry.java b/altoslib/AltosTelemetry.java index 642e7421..03ca9f80 100644 --- a/altoslib/AltosTelemetry.java +++ b/altoslib/AltosTelemetry.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2; import java.text.*; diff --git a/altoslib/AltosTelemetryConfiguration.java b/altoslib/AltosTelemetryConfiguration.java index 4c9bdd1f..e5d444dd 100644 --- a/altoslib/AltosTelemetryConfiguration.java +++ b/altoslib/AltosTelemetryConfiguration.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2; public class AltosTelemetryConfiguration extends AltosTelemetryStandard { diff --git a/altoslib/AltosTelemetryFile.java b/altoslib/AltosTelemetryFile.java index 33872688..7566d946 100644 --- a/altoslib/AltosTelemetryFile.java +++ b/altoslib/AltosTelemetryFile.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2; import java.io.*; import java.util.*; @@ -72,16 +72,14 @@ public class AltosTelemetryFile extends AltosStateIterable { /* Find boost tick */ AltosState state = start.clone(); - System.out.printf ("Searching for boost\n"); for (AltosTelemetry telem : telems) { telem.update_state(state); + state.finish_update(); if (state.state != AltosLib.ao_flight_invalid && state.state >= AltosLib.ao_flight_boost) { - System.out.printf ("boost tick %d\n", state.tick); start.set_boost_tick(state.tick); break; } } - System.out.printf ("Found boost %d\n", start.boost_tick); } public Iterator iterator() { @@ -91,6 +89,7 @@ public class AltosTelemetryFile extends AltosStateIterable { while (i.hasNext() && !state.valid()) { AltosTelemetry t = i.next(); t.update_state(state); + state.finish_update(); } return new AltosTelemetryIterator(state, i); } diff --git a/altoslib/AltosTelemetryIterable.java b/altoslib/AltosTelemetryIterable.java index b7489f77..8075b8a3 100644 --- a/altoslib/AltosTelemetryIterable.java +++ b/altoslib/AltosTelemetryIterable.java @@ -15,17 +15,78 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2; import java.io.*; import java.util.*; import java.text.*; +class AltosTelemetryOrdered implements Comparable { + AltosTelemetry telem; + int index; + int tick; + + public int compareTo(AltosTelemetryOrdered o) { + int tick_diff = tick - o.tick; + + if (tick_diff != 0) + return tick_diff; + return index - o.index; + } + + AltosTelemetryOrdered (AltosTelemetry telem, int index, int tick) { + this.telem = telem; + this.index = index; + this.tick = tick; + } +} + +class AltosTelemetryOrderedIterator implements Iterator { + TreeSet olist; + Iterator oiterator; + + public AltosTelemetryOrderedIterator(Iterable telems) { + olist = new TreeSet(); + + int tick = 0; + int index = 0; + boolean first = true; + + for (AltosTelemetry e : telems) { + int t = e.tick; + if (first) + tick = t; + else { + while (t < tick - 32767) + t += 65536; + tick = t; + } + olist.add(new AltosTelemetryOrdered(e, index++, tick)); + first = false; + } + + oiterator = olist.iterator(); + } + + public boolean hasNext() { + return oiterator.hasNext(); + } + + public AltosTelemetry next() { + return oiterator.next().telem; + } + + public void remove () { + } +} + public class AltosTelemetryIterable implements Iterable { LinkedList telems; public Iterator iterator () { - return telems.iterator(); + if (telems == null) + telems = new LinkedList(); + return new AltosTelemetryOrderedIterator(telems); } public AltosTelemetryIterable (FileInputStream input) { diff --git a/altoslib/AltosTelemetryLegacy.java b/altoslib/AltosTelemetryLegacy.java index 95cbbeed..132b9e80 100644 --- a/altoslib/AltosTelemetryLegacy.java +++ b/altoslib/AltosTelemetryLegacy.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2; import java.text.*; @@ -264,34 +264,34 @@ public class AltosTelemetryLegacy extends AltosTelemetry { AltosTelemetryMap map = new AltosTelemetryMap(words, i); callsign = map.get_string(AO_TELEM_CALL, "N0CALL"); - serial = map.get_int(AO_TELEM_SERIAL, AltosRecord.MISSING); - flight = map.get_int(AO_TELEM_FLIGHT, AltosRecord.MISSING); - rssi = map.get_int(AO_TELEM_RSSI, AltosRecord.MISSING); + serial = map.get_int(AO_TELEM_SERIAL, AltosLib.MISSING); + flight = map.get_int(AO_TELEM_FLIGHT, AltosLib.MISSING); + rssi = map.get_int(AO_TELEM_RSSI, AltosLib.MISSING); state = AltosLib.state(map.get_string(AO_TELEM_STATE, "invalid")); tick = map.get_int(AO_TELEM_TICK, 0); /* raw sensor values */ - accel = map.get_int(AO_TELEM_RAW_ACCEL, AltosRecord.MISSING); - pres = map.get_int(AO_TELEM_RAW_BARO, AltosRecord.MISSING); - temp = map.get_int(AO_TELEM_RAW_THERMO, AltosRecord.MISSING); - batt = map.get_int(AO_TELEM_RAW_BATT, AltosRecord.MISSING); - apogee = map.get_int(AO_TELEM_RAW_DROGUE, AltosRecord.MISSING); - main = map.get_int(AO_TELEM_RAW_MAIN, AltosRecord.MISSING); + accel = map.get_int(AO_TELEM_RAW_ACCEL, AltosLib.MISSING); + pres = map.get_int(AO_TELEM_RAW_BARO, AltosLib.MISSING); + temp = map.get_int(AO_TELEM_RAW_THERMO, AltosLib.MISSING); + batt = map.get_int(AO_TELEM_RAW_BATT, AltosLib.MISSING); + apogee = map.get_int(AO_TELEM_RAW_DROGUE, AltosLib.MISSING); + main = map.get_int(AO_TELEM_RAW_MAIN, AltosLib.MISSING); /* sensor calibration information */ - ground_accel = map.get_int(AO_TELEM_CAL_ACCEL_GROUND, AltosRecord.MISSING); - ground_pres = map.get_int(AO_TELEM_CAL_BARO_GROUND, AltosRecord.MISSING); - accel_plus_g = map.get_int(AO_TELEM_CAL_ACCEL_PLUS, AltosRecord.MISSING); - accel_minus_g = map.get_int(AO_TELEM_CAL_ACCEL_MINUS, AltosRecord.MISSING); + ground_accel = map.get_int(AO_TELEM_CAL_ACCEL_GROUND, AltosLib.MISSING); + ground_pres = map.get_int(AO_TELEM_CAL_BARO_GROUND, AltosLib.MISSING); + accel_plus_g = map.get_int(AO_TELEM_CAL_ACCEL_PLUS, AltosLib.MISSING); + accel_minus_g = map.get_int(AO_TELEM_CAL_ACCEL_MINUS, AltosLib.MISSING); /* flight computer values */ - kalman_acceleration = map.get_double(AO_TELEM_KALMAN_ACCEL, AltosRecord.MISSING, 1/16.0); - kalman_speed = map.get_double(AO_TELEM_KALMAN_SPEED, AltosRecord.MISSING, 1/16.0); - kalman_height = map.get_int(AO_TELEM_KALMAN_HEIGHT, AltosRecord.MISSING); + kalman_acceleration = map.get_double(AO_TELEM_KALMAN_ACCEL, AltosLib.MISSING, 1/16.0); + kalman_speed = map.get_double(AO_TELEM_KALMAN_SPEED, AltosLib.MISSING, 1/16.0); + kalman_height = map.get_int(AO_TELEM_KALMAN_HEIGHT, AltosLib.MISSING); - flight_accel = map.get_int(AO_TELEM_ADHOC_ACCEL, AltosRecord.MISSING); - flight_vel = map.get_int(AO_TELEM_ADHOC_SPEED, AltosRecord.MISSING); - flight_pres = map.get_int(AO_TELEM_ADHOC_BARO, AltosRecord.MISSING); + flight_accel = map.get_int(AO_TELEM_ADHOC_ACCEL, AltosLib.MISSING); + flight_vel = map.get_int(AO_TELEM_ADHOC_SPEED, AltosLib.MISSING); + flight_pres = map.get_int(AO_TELEM_ADHOC_BARO, AltosLib.MISSING); if (map.has(AO_TELEM_GPS_STATE)) gps = new AltosGPS(map); @@ -363,13 +363,13 @@ public class AltosTelemetryLegacy extends AltosTelemetry { kalman_speed = ((short) flight_vel) / 16.0; kalman_acceleration = flight_accel / 16.0; kalman_height = flight_pres; - flight_vel = AltosRecord.MISSING; - flight_pres = AltosRecord.MISSING; - flight_accel = AltosRecord.MISSING; + flight_vel = AltosLib.MISSING; + flight_pres = AltosLib.MISSING; + flight_accel = AltosLib.MISSING; } else { - kalman_speed = AltosRecord.MISSING; - kalman_acceleration = AltosRecord.MISSING; - kalman_height = AltosRecord.MISSING; + kalman_speed = AltosLib.MISSING; + kalman_acceleration = AltosLib.MISSING; + kalman_height = AltosLib.MISSING; } AltosParse.word(words[i++], "gp:"); @@ -480,16 +480,16 @@ public class AltosTelemetryLegacy extends AltosTelemetry { kalman_acceleration = int16(5); kalman_speed = int16(9); kalman_height = int16(13); - flight_accel = AltosRecord.MISSING; - flight_vel = AltosRecord.MISSING; - flight_pres = AltosRecord.MISSING; + flight_accel = AltosLib.MISSING; + flight_vel = AltosLib.MISSING; + flight_pres = AltosLib.MISSING; } else { flight_accel = int16(5); flight_vel = uint32(9); flight_pres = int16(13); - kalman_acceleration = AltosRecord.MISSING; - kalman_speed = AltosRecord.MISSING; - kalman_height = AltosRecord.MISSING; + kalman_acceleration = AltosLib.MISSING; + kalman_speed = AltosLib.MISSING; + kalman_height = AltosLib.MISSING; } gps = null; @@ -544,7 +544,7 @@ public class AltosTelemetryLegacy extends AltosTelemetry { state.set_pressure(AltosConvert.barometer_to_pressure(pres)); state.set_accel_g(accel_plus_g, accel_minus_g); state.set_accel(accel); - if (kalman_height != AltosRecord.MISSING) + if (kalman_height != AltosLib.MISSING) state.set_kalman(kalman_height, kalman_speed, kalman_acceleration); state.set_temperature(AltosConvert.thermometer_to_temperature(temp)); state.set_battery_voltage(AltosConvert.cc_battery_to_voltage(batt)); diff --git a/altoslib/AltosTelemetryLocation.java b/altoslib/AltosTelemetryLocation.java index 50b9dcfc..6e880914 100644 --- a/altoslib/AltosTelemetryLocation.java +++ b/altoslib/AltosTelemetryLocation.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2; public class AltosTelemetryLocation extends AltosTelemetryStandard { diff --git a/altoslib/AltosTelemetryMap.java b/altoslib/AltosTelemetryMap.java index 7cca98b0..37883a1c 100644 --- a/altoslib/AltosTelemetryMap.java +++ b/altoslib/AltosTelemetryMap.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2; import java.text.*; import java.util.HashMap; diff --git a/altoslib/AltosTelemetryMegaData.java b/altoslib/AltosTelemetryMegaData.java index 5e6cd580..f5cc01d0 100644 --- a/altoslib/AltosTelemetryMegaData.java +++ b/altoslib/AltosTelemetryMegaData.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2; public class AltosTelemetryMegaData extends AltosTelemetryStandard { int state; diff --git a/altoslib/AltosTelemetryMegaSensor.java b/altoslib/AltosTelemetryMegaSensor.java index 7c385cfd..23b67af8 100644 --- a/altoslib/AltosTelemetryMegaSensor.java +++ b/altoslib/AltosTelemetryMegaSensor.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2; public class AltosTelemetryMegaSensor extends AltosTelemetryStandard { int accel; diff --git a/altoslib/AltosTelemetryMetrumData.java b/altoslib/AltosTelemetryMetrumData.java index d419ab80..b6239971 100644 --- a/altoslib/AltosTelemetryMetrumData.java +++ b/altoslib/AltosTelemetryMetrumData.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2; public class AltosTelemetryMetrumData extends AltosTelemetryStandard { diff --git a/altoslib/AltosTelemetryMetrumSensor.java b/altoslib/AltosTelemetryMetrumSensor.java index 59d34dba..72d2f564 100644 --- a/altoslib/AltosTelemetryMetrumSensor.java +++ b/altoslib/AltosTelemetryMetrumSensor.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2; public class AltosTelemetryMetrumSensor extends AltosTelemetryStandard { diff --git a/altoslib/AltosTelemetryRaw.java b/altoslib/AltosTelemetryRaw.java index 9ef7787e..dbe70fe9 100644 --- a/altoslib/AltosTelemetryRaw.java +++ b/altoslib/AltosTelemetryRaw.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2; public class AltosTelemetryRaw extends AltosTelemetryStandard { public AltosTelemetryRaw(int[] bytes) { diff --git a/altoslib/AltosTelemetryReader.java b/altoslib/AltosTelemetryReader.java index b1cc009c..dfbad5fb 100644 --- a/altoslib/AltosTelemetryReader.java +++ b/altoslib/AltosTelemetryReader.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2; import java.text.*; import java.io.*; @@ -24,7 +24,6 @@ import java.util.concurrent.*; public class AltosTelemetryReader extends AltosFlightReader { AltosLink link; AltosLog log; - AltosRecord previous; double frequency; int telemetry; AltosState state = null; @@ -49,7 +48,6 @@ public class AltosTelemetryReader extends AltosFlightReader { } public void reset() { - previous = null; flush(); } @@ -126,7 +124,6 @@ public class AltosTelemetryReader extends AltosFlightReader { try { log = new AltosLog(link); name = link.name; - previous = null; telem = new LinkedBlockingQueue(); frequency = AltosPreferences.frequency(link.serial); set_frequency(frequency); diff --git a/altoslib/AltosTelemetryRecord.java b/altoslib/AltosTelemetryRecord.java index a744e61a..a46c1a33 100644 --- a/altoslib/AltosTelemetryRecord.java +++ b/altoslib/AltosTelemetryRecord.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2; import java.text.*; public abstract class AltosTelemetryRecord { diff --git a/altoslib/AltosTelemetryRecordCompanion.java b/altoslib/AltosTelemetryRecordCompanion.java index 2231df13..9c38ba0a 100644 --- a/altoslib/AltosTelemetryRecordCompanion.java +++ b/altoslib/AltosTelemetryRecordCompanion.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2; public class AltosTelemetryRecordCompanion extends AltosTelemetryRecordRaw { diff --git a/altoslib/AltosTelemetryRecordConfiguration.java b/altoslib/AltosTelemetryRecordConfiguration.java index 47fc3488..48474fa5 100644 --- a/altoslib/AltosTelemetryRecordConfiguration.java +++ b/altoslib/AltosTelemetryRecordConfiguration.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2; public class AltosTelemetryRecordConfiguration extends AltosTelemetryRecordRaw { diff --git a/altoslib/AltosTelemetryRecordGeneral.java b/altoslib/AltosTelemetryRecordGeneral.java index 08cd6065..258678c7 100644 --- a/altoslib/AltosTelemetryRecordGeneral.java +++ b/altoslib/AltosTelemetryRecordGeneral.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2; import java.text.*; diff --git a/altoslib/AltosTelemetryRecordLegacy.java b/altoslib/AltosTelemetryRecordLegacy.java index f2d3f868..5f86d671 100644 --- a/altoslib/AltosTelemetryRecordLegacy.java +++ b/altoslib/AltosTelemetryRecordLegacy.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2; import java.text.*; @@ -236,34 +236,34 @@ public class AltosTelemetryRecordLegacy extends AltosTelemetryRecord { AltosTelemetryMap map = new AltosTelemetryMap(words, i); record.callsign = map.get_string(AO_TELEM_CALL, "N0CALL"); - record.serial = map.get_int(AO_TELEM_SERIAL, AltosRecord.MISSING); - record.flight = map.get_int(AO_TELEM_FLIGHT, AltosRecord.MISSING); - record.rssi = map.get_int(AO_TELEM_RSSI, AltosRecord.MISSING); + record.serial = map.get_int(AO_TELEM_SERIAL, AltosLib.MISSING); + record.flight = map.get_int(AO_TELEM_FLIGHT, AltosLib.MISSING); + record.rssi = map.get_int(AO_TELEM_RSSI, AltosLib.MISSING); record.state = AltosLib.state(map.get_string(AO_TELEM_STATE, "invalid")); record.tick = map.get_int(AO_TELEM_TICK, 0); /* raw sensor values */ - record.accel = map.get_int(AO_TELEM_RAW_ACCEL, AltosRecord.MISSING); - record.pres = map.get_int(AO_TELEM_RAW_BARO, AltosRecord.MISSING); - record.temp = map.get_int(AO_TELEM_RAW_THERMO, AltosRecord.MISSING); - record.batt = map.get_int(AO_TELEM_RAW_BATT, AltosRecord.MISSING); - record.drogue = map.get_int(AO_TELEM_RAW_DROGUE, AltosRecord.MISSING); - record.main = map.get_int(AO_TELEM_RAW_MAIN, AltosRecord.MISSING); + record.accel = map.get_int(AO_TELEM_RAW_ACCEL, AltosLib.MISSING); + record.pres = map.get_int(AO_TELEM_RAW_BARO, AltosLib.MISSING); + record.temp = map.get_int(AO_TELEM_RAW_THERMO, AltosLib.MISSING); + record.batt = map.get_int(AO_TELEM_RAW_BATT, AltosLib.MISSING); + record.drogue = map.get_int(AO_TELEM_RAW_DROGUE, AltosLib.MISSING); + record.main = map.get_int(AO_TELEM_RAW_MAIN, AltosLib.MISSING); /* sensor calibration information */ - record.ground_accel = map.get_int(AO_TELEM_CAL_ACCEL_GROUND, AltosRecord.MISSING); - record.ground_pres = map.get_int(AO_TELEM_CAL_BARO_GROUND, AltosRecord.MISSING); - record.accel_plus_g = map.get_int(AO_TELEM_CAL_ACCEL_PLUS, AltosRecord.MISSING); - record.accel_minus_g = map.get_int(AO_TELEM_CAL_ACCEL_MINUS, AltosRecord.MISSING); + record.ground_accel = map.get_int(AO_TELEM_CAL_ACCEL_GROUND, AltosLib.MISSING); + record.ground_pres = map.get_int(AO_TELEM_CAL_BARO_GROUND, AltosLib.MISSING); + record.accel_plus_g = map.get_int(AO_TELEM_CAL_ACCEL_PLUS, AltosLib.MISSING); + record.accel_minus_g = map.get_int(AO_TELEM_CAL_ACCEL_MINUS, AltosLib.MISSING); /* flight computer values */ - record.kalman_acceleration = map.get_double(AO_TELEM_KALMAN_ACCEL, AltosRecord.MISSING, 1/16.0); - record.kalman_speed = map.get_double(AO_TELEM_KALMAN_SPEED, AltosRecord.MISSING, 1/16.0); - record.kalman_height = map.get_int(AO_TELEM_KALMAN_HEIGHT, AltosRecord.MISSING); + record.kalman_acceleration = map.get_double(AO_TELEM_KALMAN_ACCEL, AltosLib.MISSING, 1/16.0); + record.kalman_speed = map.get_double(AO_TELEM_KALMAN_SPEED, AltosLib.MISSING, 1/16.0); + record.kalman_height = map.get_int(AO_TELEM_KALMAN_HEIGHT, AltosLib.MISSING); - record.flight_accel = map.get_int(AO_TELEM_ADHOC_ACCEL, AltosRecord.MISSING); - record.flight_vel = map.get_int(AO_TELEM_ADHOC_SPEED, AltosRecord.MISSING); - record.flight_pres = map.get_int(AO_TELEM_ADHOC_BARO, AltosRecord.MISSING); + record.flight_accel = map.get_int(AO_TELEM_ADHOC_ACCEL, AltosLib.MISSING); + record.flight_vel = map.get_int(AO_TELEM_ADHOC_SPEED, AltosLib.MISSING); + record.flight_pres = map.get_int(AO_TELEM_ADHOC_BARO, AltosLib.MISSING); if (map.has(AO_TELEM_GPS_STATE)) { record.gps = new AltosGPS(map); @@ -337,9 +337,9 @@ public class AltosTelemetryRecordLegacy extends AltosTelemetryRecord { record.kalman_speed = ((short) record.flight_vel) / 16.0; record.kalman_acceleration = record.flight_accel / 16.0; record.kalman_height = record.flight_pres; - record.flight_vel = AltosRecord.MISSING; - record.flight_pres = AltosRecord.MISSING; - record.flight_accel = AltosRecord.MISSING; + record.flight_vel = AltosLib.MISSING; + record.flight_pres = AltosLib.MISSING; + record.flight_accel = AltosLib.MISSING; } AltosParse.word(words[i++], "gp:"); @@ -458,16 +458,16 @@ public class AltosTelemetryRecordLegacy extends AltosTelemetryRecord { record.kalman_acceleration = int16(5); record.kalman_speed = int16(9); record.kalman_height = int16(13); - record.flight_accel = AltosRecord.MISSING; - record.flight_vel = AltosRecord.MISSING; - record.flight_pres = AltosRecord.MISSING; + record.flight_accel = AltosLib.MISSING; + record.flight_vel = AltosLib.MISSING; + record.flight_pres = AltosLib.MISSING; } else { record.flight_accel = int16(5); record.flight_vel = uint32(9); record.flight_pres = int16(13); - record.kalman_acceleration = AltosRecord.MISSING; - record.kalman_speed = AltosRecord.MISSING; - record.kalman_height = AltosRecord.MISSING; + record.kalman_acceleration = AltosLib.MISSING; + record.kalman_speed = AltosLib.MISSING; + record.kalman_height = AltosLib.MISSING; } record.gps = null; diff --git a/altoslib/AltosTelemetryRecordLocation.java b/altoslib/AltosTelemetryRecordLocation.java index 0236d291..0eea8361 100644 --- a/altoslib/AltosTelemetryRecordLocation.java +++ b/altoslib/AltosTelemetryRecordLocation.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2; public class AltosTelemetryRecordLocation extends AltosTelemetryRecordRaw { diff --git a/altoslib/AltosTelemetryRecordMegaData.java b/altoslib/AltosTelemetryRecordMegaData.java index a484ef4e..ee9442d2 100644 --- a/altoslib/AltosTelemetryRecordMegaData.java +++ b/altoslib/AltosTelemetryRecordMegaData.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2; public class AltosTelemetryRecordMegaData extends AltosTelemetryRecordRaw { diff --git a/altoslib/AltosTelemetryRecordMegaSensor.java b/altoslib/AltosTelemetryRecordMegaSensor.java index 2a4b17a4..234cda27 100644 --- a/altoslib/AltosTelemetryRecordMegaSensor.java +++ b/altoslib/AltosTelemetryRecordMegaSensor.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2; public class AltosTelemetryRecordMegaSensor extends AltosTelemetryRecordRaw { diff --git a/altoslib/AltosTelemetryRecordMetrumData.java b/altoslib/AltosTelemetryRecordMetrumData.java index 70179b28..ade2494f 100644 --- a/altoslib/AltosTelemetryRecordMetrumData.java +++ b/altoslib/AltosTelemetryRecordMetrumData.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2; public class AltosTelemetryRecordMetrumData extends AltosTelemetryRecordRaw { diff --git a/altoslib/AltosTelemetryRecordMetrumSensor.java b/altoslib/AltosTelemetryRecordMetrumSensor.java index e41242c5..d6d29b15 100644 --- a/altoslib/AltosTelemetryRecordMetrumSensor.java +++ b/altoslib/AltosTelemetryRecordMetrumSensor.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2; public class AltosTelemetryRecordMetrumSensor extends AltosTelemetryRecordRaw { diff --git a/altoslib/AltosTelemetryRecordMini.java b/altoslib/AltosTelemetryRecordMini.java index 75a66c16..3c290208 100644 --- a/altoslib/AltosTelemetryRecordMini.java +++ b/altoslib/AltosTelemetryRecordMini.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2; public class AltosTelemetryRecordMini extends AltosTelemetryRecordRaw { diff --git a/altoslib/AltosTelemetryRecordRaw.java b/altoslib/AltosTelemetryRecordRaw.java index f94789bb..93d0ca50 100644 --- a/altoslib/AltosTelemetryRecordRaw.java +++ b/altoslib/AltosTelemetryRecordRaw.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2; public class AltosTelemetryRecordRaw extends AltosTelemetryRecord { int[] bytes; diff --git a/altoslib/AltosTelemetryRecordSatellite.java b/altoslib/AltosTelemetryRecordSatellite.java index 9835389b..5de16ab4 100644 --- a/altoslib/AltosTelemetryRecordSatellite.java +++ b/altoslib/AltosTelemetryRecordSatellite.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2; public class AltosTelemetryRecordSatellite extends AltosTelemetryRecordRaw { int channels; diff --git a/altoslib/AltosTelemetryRecordSensor.java b/altoslib/AltosTelemetryRecordSensor.java index e0e92c13..d1d9dd7e 100644 --- a/altoslib/AltosTelemetryRecordSensor.java +++ b/altoslib/AltosTelemetryRecordSensor.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2; public class AltosTelemetryRecordSensor extends AltosTelemetryRecordRaw { @@ -70,7 +70,7 @@ public class AltosTelemetryRecordSensor extends AltosTelemetryRecordRaw { if (type == packet_type_TM_sensor) next.accel = accel; else - next.accel = AltosRecord.MISSING; + next.accel = AltosLib.MISSING; next.pres = pres; next.temp = temp; next.batt = v_batt; @@ -78,8 +78,8 @@ public class AltosTelemetryRecordSensor extends AltosTelemetryRecordRaw { next.drogue = sense_d; next.main = sense_m; } else { - next.drogue = AltosRecord.MISSING; - next.main = AltosRecord.MISSING; + next.drogue = AltosLib.MISSING; + next.main = AltosLib.MISSING; } next.kalman_acceleration = acceleration / 16.0; @@ -92,9 +92,9 @@ public class AltosTelemetryRecordSensor extends AltosTelemetryRecordRaw { next.accel_plus_g = accel_plus_g; next.accel_minus_g = accel_minus_g; } else { - next.ground_accel = AltosRecord.MISSING; - next.accel_plus_g = AltosRecord.MISSING; - next.accel_minus_g = AltosRecord.MISSING; + next.ground_accel = AltosLib.MISSING; + next.accel_plus_g = AltosLib.MISSING; + next.accel_minus_g = AltosLib.MISSING; } next.seen |= AltosRecord.seen_sensor | AltosRecord.seen_temp_volt; diff --git a/altoslib/AltosTelemetrySatellite.java b/altoslib/AltosTelemetrySatellite.java index bd94740f..fde3d86d 100644 --- a/altoslib/AltosTelemetrySatellite.java +++ b/altoslib/AltosTelemetrySatellite.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2; public class AltosTelemetrySatellite extends AltosTelemetryStandard { int channels; diff --git a/altoslib/AltosTelemetrySensor.java b/altoslib/AltosTelemetrySensor.java index f89e56c3..e1106440 100644 --- a/altoslib/AltosTelemetrySensor.java +++ b/altoslib/AltosTelemetrySensor.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2; public class AltosTelemetrySensor extends AltosTelemetryStandard { diff --git a/altoslib/AltosTelemetryStandard.java b/altoslib/AltosTelemetryStandard.java index fa86bf8e..fbcc970c 100644 --- a/altoslib/AltosTelemetryStandard.java +++ b/altoslib/AltosTelemetryStandard.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2; public abstract class AltosTelemetryStandard extends AltosTelemetry { int[] bytes; diff --git a/altoslib/AltosTemperature.java b/altoslib/AltosTemperature.java index 2749eac0..0105fe53 100644 --- a/altoslib/AltosTemperature.java +++ b/altoslib/AltosTemperature.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2; public class AltosTemperature extends AltosUnits { diff --git a/altoslib/AltosUnits.java b/altoslib/AltosUnits.java index b8b3254c..ee74f916 100644 --- a/altoslib/AltosUnits.java +++ b/altoslib/AltosUnits.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2; public abstract class AltosUnits { diff --git a/altoslib/AltosUnitsListener.java b/altoslib/AltosUnitsListener.java index 61a181a4..1e3ad655 100644 --- a/altoslib/AltosUnitsListener.java +++ b/altoslib/AltosUnitsListener.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2; public interface AltosUnitsListener { public void units_changed(boolean imperial_units); diff --git a/altoslib/Makefile.am b/altoslib/Makefile.am index 87d4d898..62159bcc 100644 --- a/altoslib/Makefile.am +++ b/altoslib/Makefile.am @@ -10,20 +10,9 @@ SRC=. altoslibdir = $(datadir)/java -record_files = \ - AltosEepromRecord.java \ - AltosEepromTeleScience.java \ - AltosRecordCompanion.java \ - AltosRecordIterable.java \ - AltosRecord.java \ - AltosRecordNone.java \ - AltosRecordTM.java \ - AltosRecordMM.java \ - AltosRecordMini.java - altoslib_JAVA = \ - $(record_files) \ AltosLib.java \ + AltosCompanion.java \ AltosConfigData.java \ AltosConfigValues.java \ AltosConvert.java \ @@ -45,31 +34,32 @@ altoslib_JAVA = \ AltosFlightReader.java \ AltosFrequency.java \ AltosGPS.java \ - AltosGPSQuery.java \ AltosGPSSat.java \ AltosGreatCircle.java \ AltosHexfile.java \ + AltosIdle.java \ + AltosIdleFetch.java \ AltosIdleMonitor.java \ AltosIdleMonitorListener.java \ AltosIgnite.java \ AltosIMU.java \ - AltosIMUQuery.java \ AltosLine.java \ AltosLink.java \ AltosListenerState.java \ AltosLog.java \ + AltosMag.java \ + AltosMma655x.java \ AltosMs5607.java \ - AltosMs5607Query.java \ - AltosOrderedRecord.java \ - AltosOrderedMegaRecord.java \ - AltosOrderedMiniRecord.java \ AltosParse.java \ AltosPreferences.java \ AltosPreferencesBackend.java \ AltosReplayReader.java \ AltosRomconfig.java \ AltosSensorMM.java \ + AltosSensorEMini.java \ AltosSensorTM.java \ + AltosSensorMega.java \ + AltosSensorMetrum.java \ AltosState.java \ AltosStateIterable.java \ AltosStateUpdate.java \ diff --git a/altosui/Altos.java b/altosui/Altos.java index d25736bf..07280b4a 100644 --- a/altosui/Altos.java +++ b/altosui/Altos.java @@ -20,7 +20,7 @@ package altosui; import java.awt.*; import libaltosJNI.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; import org.altusmetrum.altosuilib_1.*; public class Altos extends AltosUILib { diff --git a/altosui/AltosAscent.java b/altosui/AltosAscent.java index 20474f52..1d9af546 100644 --- a/altosui/AltosAscent.java +++ b/altosui/AltosAscent.java @@ -19,7 +19,7 @@ package altosui; import java.awt.*; import javax.swing.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; public class AltosAscent extends JComponent implements AltosFlightDisplay { GridBagLayout layout; @@ -179,7 +179,7 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay { void reset() { value.setText(""); max_value.setText(""); - max = AltosRecord.MISSING; + max = AltosLib.MISSING; } void set_font() { @@ -189,12 +189,12 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay { } void show(AltosUnits units, double v) { - if (v == AltosRecord.MISSING) { + if (v == AltosLib.MISSING) { value.setText("Missing"); max_value.setText("Missing"); } else { value.setText(units.show(8, v)); - if (v > max || max == AltosRecord.MISSING) { + if (v > max || max == AltosLib.MISSING) { max_value.setText(units.show(8, v)); max = v; } @@ -308,7 +308,7 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay { class Lat extends AscentValue { void show (AltosState state, AltosListenerState listener_state) { - if (state.gps != null && state.gps.connected && state.gps.lat != AltosRecord.MISSING) + if (state.gps != null && state.gps.connected && state.gps.lat != AltosLib.MISSING) show(pos(state.gps.lat,"N", "S")); else show("???"); @@ -322,7 +322,7 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay { class Lon extends AscentValue { void show (AltosState state, AltosListenerState listener_state) { - if (state.gps != null && state.gps.connected && state.gps.lon != AltosRecord.MISSING) + if (state.gps != null && state.gps.connected && state.gps.lon != AltosLib.MISSING) show(pos(state.gps.lon,"E", "W")); else show("???"); @@ -365,11 +365,11 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay { lon.hide(); } height.show(state, listener_state); - if (state.main_voltage != AltosRecord.MISSING) + if (state.main_voltage != AltosLib.MISSING) main.show(state, listener_state); else main.hide(); - if (state.apogee_voltage != AltosRecord.MISSING) + if (state.apogee_voltage != AltosLib.MISSING) apogee.show(state, listener_state); else apogee.hide(); diff --git a/altosui/AltosBTKnown.java b/altosui/AltosBTKnown.java index 1d42365b..a1652ec4 100644 --- a/altosui/AltosBTKnown.java +++ b/altosui/AltosBTKnown.java @@ -17,7 +17,7 @@ package altosui; import java.util.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; import org.altusmetrum.altosuilib_1.*; public class AltosBTKnown implements Iterable { diff --git a/altosui/AltosCSV.java b/altosui/AltosCSV.java index bcff393f..7598eca0 100644 --- a/altosui/AltosCSV.java +++ b/altosui/AltosCSV.java @@ -19,7 +19,7 @@ package altosui; import java.io.*; import java.util.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; public class AltosCSV implements AltosWriter { File name; @@ -222,7 +222,7 @@ public class AltosCSV implements AltosWriter { } void write_companion(AltosState state) { - AltosRecordCompanion companion = state.companion; + AltosCompanion companion = state.companion; int channels_written = 0; if (companion == null) { diff --git a/altosui/AltosCSVUI.java b/altosui/AltosCSVUI.java index 4b48bdf6..c41ea74b 100644 --- a/altosui/AltosCSVUI.java +++ b/altosui/AltosCSVUI.java @@ -21,7 +21,7 @@ import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.io.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; import org.altusmetrum.altosuilib_1.*; public class AltosCSVUI diff --git a/altosui/AltosCompanionInfo.java b/altosui/AltosCompanionInfo.java index 1ed2c425..1f446700 100644 --- a/altosui/AltosCompanionInfo.java +++ b/altosui/AltosCompanionInfo.java @@ -19,7 +19,7 @@ package altosui; import java.awt.*; import javax.swing.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; public class AltosCompanionInfo extends JTable { private AltosFlightInfoTableModel model; @@ -70,13 +70,13 @@ public class AltosCompanionInfo extends JTable { model.clear(); } - AltosRecordCompanion companion; + AltosCompanion companion; public String board_name() { if (companion == null) return "None"; switch (companion.board_id) { - case AltosRecordCompanion.board_id_telescience: + case AltosCompanion.board_id_telescience: return "TeleScience"; default: return String.format("%02x\n", companion.board_id); diff --git a/altosui/AltosConfig.java b/altosui/AltosConfig.java index 4927d3f8..a6e6094f 100644 --- a/altosui/AltosConfig.java +++ b/altosui/AltosConfig.java @@ -22,7 +22,7 @@ import javax.swing.*; import java.io.*; import java.util.concurrent.*; import java.text.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; import org.altusmetrum.altosuilib_1.*; public class AltosConfig implements ActionListener { diff --git a/altosui/AltosConfigFreqUI.java b/altosui/AltosConfigFreqUI.java index c90b168f..555af3b6 100644 --- a/altosui/AltosConfigFreqUI.java +++ b/altosui/AltosConfigFreqUI.java @@ -21,7 +21,7 @@ import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.util.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; import org.altusmetrum.altosuilib_1.*; class AltosEditFreqUI extends AltosUIDialog implements ActionListener { diff --git a/altosui/AltosConfigPyroUI.java b/altosui/AltosConfigPyroUI.java index 3cac56c3..2f5c199d 100644 --- a/altosui/AltosConfigPyroUI.java +++ b/altosui/AltosConfigPyroUI.java @@ -21,7 +21,7 @@ import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; import org.altusmetrum.altosuilib_1.*; public class AltosConfigPyroUI diff --git a/altosui/AltosConfigTD.java b/altosui/AltosConfigTD.java index 16c9e357..f879ff88 100644 --- a/altosui/AltosConfigTD.java +++ b/altosui/AltosConfigTD.java @@ -21,7 +21,7 @@ import java.awt.event.*; import javax.swing.*; import java.io.*; import java.util.concurrent.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; import org.altusmetrum.altosuilib_1.*; public class AltosConfigTD implements ActionListener { diff --git a/altosui/AltosConfigTDUI.java b/altosui/AltosConfigTDUI.java index 125780a9..b5a6cd7c 100644 --- a/altosui/AltosConfigTDUI.java +++ b/altosui/AltosConfigTDUI.java @@ -21,7 +21,7 @@ import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; import org.altusmetrum.altosuilib_1.*; public class AltosConfigTDUI diff --git a/altosui/AltosConfigUI.java b/altosui/AltosConfigUI.java index 9723e660..a6d27977 100644 --- a/altosui/AltosConfigUI.java +++ b/altosui/AltosConfigUI.java @@ -21,7 +21,7 @@ import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; import org.altusmetrum.altosuilib_1.*; public class AltosConfigUI diff --git a/altosui/AltosDataChooser.java b/altosui/AltosDataChooser.java index af6c245b..0d0b0b0a 100644 --- a/altosui/AltosDataChooser.java +++ b/altosui/AltosDataChooser.java @@ -20,7 +20,7 @@ package altosui; import javax.swing.*; import javax.swing.filechooser.FileNameExtensionFilter; import java.io.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; import org.altusmetrum.altosuilib_1.*; public class AltosDataChooser extends JFileChooser { diff --git a/altosui/AltosDescent.java b/altosui/AltosDescent.java index e85717bb..77776ff2 100644 --- a/altosui/AltosDescent.java +++ b/altosui/AltosDescent.java @@ -19,7 +19,7 @@ package altosui; import java.awt.*; import javax.swing.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; public class AltosDescent extends JComponent implements AltosFlightDisplay { GridBagLayout layout; @@ -278,7 +278,7 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay { class Lat extends DescentValue { void show (AltosState state, AltosListenerState listener_state) { - if (state.gps != null && state.gps.connected && state.gps.lat != AltosRecord.MISSING) + if (state.gps != null && state.gps.connected && state.gps.lat != AltosLib.MISSING) show(pos(state.gps.lat,"N", "S")); else show("???"); @@ -292,7 +292,7 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay { class Lon extends DescentValue { void show (AltosState state, AltosListenerState listener_state) { - if (state.gps != null && state.gps.connected && state.gps.lon != AltosRecord.MISSING) + if (state.gps != null && state.gps.connected && state.gps.lon != AltosLib.MISSING) show(pos(state.gps.lon,"W", "E")); else show("???"); @@ -427,11 +427,11 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay { lat.hide(); lon.hide(); } - if (state.main_voltage != AltosRecord.MISSING) + if (state.main_voltage != AltosLib.MISSING) main.show(state, listener_state); else main.hide(); - if (state.apogee_voltage != AltosRecord.MISSING) + if (state.apogee_voltage != AltosLib.MISSING) apogee.show(state, listener_state); else apogee.hide(); diff --git a/altosui/AltosDisplayThread.java b/altosui/AltosDisplayThread.java index c894c2d0..37f6adf9 100644 --- a/altosui/AltosDisplayThread.java +++ b/altosui/AltosDisplayThread.java @@ -21,7 +21,7 @@ import java.awt.*; import javax.swing.*; import java.io.*; import java.text.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; public class AltosDisplayThread extends Thread { diff --git a/altosui/AltosEepromDelete.java b/altosui/AltosEepromDelete.java index e81a35d1..9984d1a2 100644 --- a/altosui/AltosEepromDelete.java +++ b/altosui/AltosEepromDelete.java @@ -21,7 +21,7 @@ import java.awt.event.*; import javax.swing.*; import java.io.*; import java.util.concurrent.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; public class AltosEepromDelete implements Runnable { AltosEepromList flights; diff --git a/altosui/AltosEepromDownload.java b/altosui/AltosEepromDownload.java index 931b55fd..c3bdd159 100644 --- a/altosui/AltosEepromDownload.java +++ b/altosui/AltosEepromDownload.java @@ -23,7 +23,7 @@ import java.io.*; import java.util.*; import java.text.*; import java.util.concurrent.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; public class AltosEepromDownload implements Runnable { @@ -61,9 +61,9 @@ public class AltosEepromDownload implements Runnable { AltosGPS gps = state.gps; if (gps != null && - gps.year != AltosRecord.MISSING && - gps.month != AltosRecord.MISSING && - gps.day != AltosRecord.MISSING) + gps.year != AltosLib.MISSING && + gps.month != AltosLib.MISSING && + gps.day != AltosLib.MISSING) { eeprom_name = new AltosFile(gps.year, gps.month, gps.day, state.serial, state.flight, "eeprom"); diff --git a/altosui/AltosEepromList.java b/altosui/AltosEepromList.java index a63d173d..258c421a 100644 --- a/altosui/AltosEepromList.java +++ b/altosui/AltosEepromList.java @@ -21,7 +21,7 @@ import java.io.*; import java.util.*; import java.text.*; import java.util.concurrent.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; /* * Temporary structure to hold the list of stored flights; diff --git a/altosui/AltosEepromManage.java b/altosui/AltosEepromManage.java index 7a721196..b2d8a130 100644 --- a/altosui/AltosEepromManage.java +++ b/altosui/AltosEepromManage.java @@ -21,7 +21,7 @@ import java.awt.event.*; import javax.swing.*; import java.io.*; import java.util.concurrent.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; import org.altusmetrum.altosuilib_1.*; public class AltosEepromManage implements ActionListener { diff --git a/altosui/AltosEepromSelect.java b/altosui/AltosEepromSelect.java index a451aa3a..8f86eebf 100644 --- a/altosui/AltosEepromSelect.java +++ b/altosui/AltosEepromSelect.java @@ -21,7 +21,7 @@ import javax.swing.*; import javax.swing.border.*; import java.awt.*; import java.awt.event.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; import org.altusmetrum.altosuilib_1.*; class AltosEepromItem implements ActionListener { diff --git a/altosui/AltosFlashUI.java b/altosui/AltosFlashUI.java index f4e52218..6eccface 100644 --- a/altosui/AltosFlashUI.java +++ b/altosui/AltosFlashUI.java @@ -23,7 +23,7 @@ import javax.swing.*; import javax.swing.filechooser.FileNameExtensionFilter; import java.io.*; import java.util.concurrent.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; import org.altusmetrum.altosuilib_1.*; public class AltosFlashUI diff --git a/altosui/AltosFlightDisplay.java b/altosui/AltosFlightDisplay.java index 4f4c158e..289ddd01 100644 --- a/altosui/AltosFlightDisplay.java +++ b/altosui/AltosFlightDisplay.java @@ -17,7 +17,7 @@ package altosui; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; public interface AltosFlightDisplay { void reset(); diff --git a/altosui/AltosFlightStats.java b/altosui/AltosFlightStats.java index f278012f..11a3f1a9 100644 --- a/altosui/AltosFlightStats.java +++ b/altosui/AltosFlightStats.java @@ -18,7 +18,7 @@ package altosui; import java.io.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; public class AltosFlightStats { double max_height; @@ -77,7 +77,7 @@ public class AltosFlightStats { } double boost_time(AltosStateIterable states) { - double boost_time = AltosRecord.MISSING; + double boost_time = AltosLib.MISSING; AltosState state = null; for (AltosState s : states) { @@ -90,7 +90,7 @@ public class AltosFlightStats { if (state == null) return 0; - if (boost_time == AltosRecord.MISSING) + if (boost_time == AltosLib.MISSING) boost_time = state.time; return boost_time; } @@ -101,21 +101,21 @@ public class AltosFlightStats { double end_time = 0; double landed_time = landed_time(states); - year = month = day = AltosRecord.MISSING; - hour = minute = second = AltosRecord.MISSING; - serial = flight = AltosRecord.MISSING; - lat = lon = AltosRecord.MISSING; + year = month = day = AltosLib.MISSING; + hour = minute = second = AltosLib.MISSING; + serial = flight = AltosLib.MISSING; + lat = lon = AltosLib.MISSING; has_gps = false; has_other_adc = false; has_rssi = false; for (AltosState state : states) { - if (serial == AltosRecord.MISSING && state.serial != AltosRecord.MISSING) + if (serial == AltosLib.MISSING && state.serial != AltosLib.MISSING) serial = state.serial; - if (flight == AltosRecord.MISSING && state.flight != AltosRecord.MISSING) + if (flight == AltosLib.MISSING && state.flight != AltosLib.MISSING) flight = state.flight; - if (state.battery_voltage != AltosRecord.MISSING) + if (state.battery_voltage != AltosLib.MISSING) has_other_adc = true; - if (state.rssi != AltosRecord.MISSING) + if (state.rssi != AltosLib.MISSING) has_rssi = true; end_time = state.time; if (state.time >= boost_time && state.state < Altos.ao_flight_boost) diff --git a/altosui/AltosFlightStatsTable.java b/altosui/AltosFlightStatsTable.java index b5a92683..db875b3b 100644 --- a/altosui/AltosFlightStatsTable.java +++ b/altosui/AltosFlightStatsTable.java @@ -19,7 +19,7 @@ package altosui; import java.awt.*; import javax.swing.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; public class AltosFlightStatsTable extends JComponent { GridBagLayout layout; @@ -76,15 +76,15 @@ public class AltosFlightStatsTable extends JComponent { int y = 0; new FlightStat(layout, y++, "Serial", String.format("%d", stats.serial)); new FlightStat(layout, y++, "Flight", String.format("%d", stats.flight)); - if (stats.year != AltosRecord.MISSING && stats.hour != AltosRecord.MISSING) + if (stats.year != AltosLib.MISSING && stats.hour != AltosLib.MISSING) new FlightStat(layout, y++, "Date/Time", String.format("%04d-%02d-%02d", stats.year, stats.month, stats.day), String.format("%02d:%02d:%02d UTC", stats.hour, stats.minute, stats.second)); else { - if (stats.year != AltosRecord.MISSING) + if (stats.year != AltosLib.MISSING) new FlightStat(layout, y++, "Date", String.format("%04d-%02d-%02d", stats.year, stats.month, stats.day)); - if (stats.hour != AltosRecord.MISSING) + if (stats.hour != AltosLib.MISSING) new FlightStat(layout, y++, "Time", String.format("%02d:%02d:%02d UTC", stats.hour, stats.minute, stats.second)); } @@ -95,7 +95,7 @@ public class AltosFlightStatsTable extends JComponent { String.format("%5.0f m/s", stats.max_speed), String.format("%5.0f mph", AltosConvert.meters_to_mph(stats.max_speed)), String.format("Mach %4.1f", AltosConvert.meters_to_mach(stats.max_speed))); - if (stats.max_acceleration != AltosRecord.MISSING) { + if (stats.max_acceleration != AltosLib.MISSING) { new FlightStat(layout, y++, "Maximum boost acceleration", String.format("%5.0f m/s²", stats.max_acceleration), String.format("%5.0f ft/s²", AltosConvert.meters_to_feet(stats.max_acceleration)), diff --git a/altosui/AltosFlightStatus.java b/altosui/AltosFlightStatus.java index 6383e5b9..9d575e4c 100644 --- a/altosui/AltosFlightStatus.java +++ b/altosui/AltosFlightStatus.java @@ -19,7 +19,7 @@ package altosui; import java.awt.*; import javax.swing.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; public class AltosFlightStatus extends JComponent implements AltosFlightDisplay { GridBagLayout layout; @@ -76,7 +76,7 @@ public class AltosFlightStatus extends JComponent implements AltosFlightDisplay class Serial extends FlightValue { void show(AltosState state, AltosListenerState listener_state) { - if (state.serial == AltosRecord.MISSING) + if (state.serial == AltosLib.MISSING) value.setText("none"); else value.setText(String.format("%d", state.serial)); @@ -90,7 +90,7 @@ public class AltosFlightStatus extends JComponent implements AltosFlightDisplay class Flight extends FlightValue { void show(AltosState state, AltosListenerState listener_state) { - if (state.flight == AltosRecord.MISSING) + if (state.flight == AltosLib.MISSING) value.setText("none"); else value.setText(String.format("%d", state.flight)); diff --git a/altosui/AltosFlightStatusTableModel.java b/altosui/AltosFlightStatusTableModel.java index 6a327841..08154fda 100644 --- a/altosui/AltosFlightStatusTableModel.java +++ b/altosui/AltosFlightStatusTableModel.java @@ -27,7 +27,7 @@ import java.util.*; import java.text.*; import java.util.prefs.*; import java.util.concurrent.LinkedBlockingQueue; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; public class AltosFlightStatusTableModel extends AbstractTableModel { private String[] columnNames = { diff --git a/altosui/AltosFlightStatusUpdate.java b/altosui/AltosFlightStatusUpdate.java index 962a08f7..7821a777 100644 --- a/altosui/AltosFlightStatusUpdate.java +++ b/altosui/AltosFlightStatusUpdate.java @@ -18,7 +18,7 @@ package altosui; import java.awt.event.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; public class AltosFlightStatusUpdate implements ActionListener { diff --git a/altosui/AltosFlightUI.java b/altosui/AltosFlightUI.java index 1c450ce3..c151177e 100644 --- a/altosui/AltosFlightUI.java +++ b/altosui/AltosFlightUI.java @@ -21,7 +21,7 @@ import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.util.concurrent.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; import org.altusmetrum.altosuilib_1.*; public class AltosFlightUI extends AltosUIFrame implements AltosFlightDisplay, AltosFontListener { diff --git a/altosui/AltosFreqList.java b/altosui/AltosFreqList.java index 7464ac3e..917ac364 100644 --- a/altosui/AltosFreqList.java +++ b/altosui/AltosFreqList.java @@ -18,7 +18,7 @@ package altosui; import javax.swing.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; import org.altusmetrum.altosuilib_1.*; public class AltosFreqList extends JComboBox { diff --git a/altosui/AltosGraph.java b/altosui/AltosGraph.java index a73e3fd8..e6cd7bd8 100644 --- a/altosui/AltosGraph.java +++ b/altosui/AltosGraph.java @@ -22,7 +22,7 @@ import java.util.ArrayList; import java.awt.*; import javax.swing.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; import org.altusmetrum.altosuilib_1.*; import org.jfree.ui.*; diff --git a/altosui/AltosGraphDataPoint.java b/altosui/AltosGraphDataPoint.java index 85a19b00..d8191f5d 100644 --- a/altosui/AltosGraphDataPoint.java +++ b/altosui/AltosGraphDataPoint.java @@ -18,7 +18,7 @@ package altosui; import org.altusmetrum.altosuilib_1.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; public class AltosGraphDataPoint implements AltosUIDataPoint { @@ -49,7 +49,7 @@ public class AltosGraphDataPoint implements AltosUIDataPoint { } public double y(int index) throws AltosUIDataMissing { - double y = AltosRecord.MISSING; + double y = AltosLib.MISSING; switch (index) { case data_height: y = state.height(); @@ -100,7 +100,7 @@ public class AltosGraphDataPoint implements AltosUIDataPoint { y = state.pressure(); break; } - if (y == AltosRecord.MISSING) + if (y == AltosLib.MISSING) throw new AltosUIDataMissing(index); return y; } diff --git a/altosui/AltosGraphDataSet.java b/altosui/AltosGraphDataSet.java index 1e469c8a..4e6c46d1 100644 --- a/altosui/AltosGraphDataSet.java +++ b/altosui/AltosGraphDataSet.java @@ -20,7 +20,7 @@ package altosui; import java.lang.*; import java.io.*; import java.util.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; import org.altusmetrum.altosuilib_1.*; class AltosGraphIterator implements Iterator { @@ -34,7 +34,7 @@ class AltosGraphIterator implements Iterator { public AltosUIDataPoint next() { AltosState state = iterator.next(); - if (state.flight != AltosRecord.MISSING) { + if (state.flight != AltosLib.MISSING) { if (dataSet.callsign == null && state.callsign != null) dataSet.callsign = state.callsign; diff --git a/altosui/AltosGraphUI.java b/altosui/AltosGraphUI.java index 376e9910..c42f7b5f 100644 --- a/altosui/AltosGraphUI.java +++ b/altosui/AltosGraphUI.java @@ -9,7 +9,7 @@ import java.util.ArrayList; import java.awt.*; import javax.swing.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; import org.altusmetrum.altosuilib_1.*; import org.jfree.chart.ChartPanel; diff --git a/altosui/AltosIdleMonitorUI.java b/altosui/AltosIdleMonitorUI.java index f6a91de8..f4e16243 100644 --- a/altosui/AltosIdleMonitorUI.java +++ b/altosui/AltosIdleMonitorUI.java @@ -23,7 +23,7 @@ import javax.swing.*; import javax.swing.event.*; import java.io.*; import java.util.concurrent.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; import org.altusmetrum.altosuilib_1.*; public class AltosIdleMonitorUI extends AltosUIFrame implements AltosFlightDisplay, AltosFontListener, AltosIdleMonitorListener, DocumentListener { diff --git a/altosui/AltosIgniteUI.java b/altosui/AltosIgniteUI.java index 14d4eebc..c8024aae 100644 --- a/altosui/AltosIgniteUI.java +++ b/altosui/AltosIgniteUI.java @@ -23,7 +23,7 @@ import javax.swing.*; import java.io.*; import java.text.*; import java.util.concurrent.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; import org.altusmetrum.altosuilib_1.*; public class AltosIgniteUI diff --git a/altosui/AltosInfoTable.java b/altosui/AltosInfoTable.java index cf4642bc..d7871aa6 100644 --- a/altosui/AltosInfoTable.java +++ b/altosui/AltosInfoTable.java @@ -20,7 +20,7 @@ package altosui; import java.awt.*; import javax.swing.*; import javax.swing.table.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; public class AltosInfoTable extends JTable { private AltosFlightInfoTableModel model; @@ -107,40 +107,44 @@ public class AltosInfoTable extends JTable { public void show(AltosState state, AltosListenerState listener_state) { info_reset(); if (state != null) { - if (state.altitude() != AltosRecord.MISSING) + if (state.altitude() != AltosLib.MISSING) info_add_row(0, "Altitude", "%6.0f m", state.altitude()); - if (state.ground_altitude() != AltosRecord.MISSING) + if (state.ground_altitude() != AltosLib.MISSING) info_add_row(0, "Pad altitude", "%6.0f m", state.ground_altitude()); - if (state.height() != AltosRecord.MISSING) + if (state.height() != AltosLib.MISSING) info_add_row(0, "Height", "%6.0f m", state.height()); - if (state.max_height() != AltosRecord.MISSING) + if (state.max_height() != AltosLib.MISSING) info_add_row(0, "Max height", "%6.0f m", state.max_height()); - if (state.acceleration() != AltosRecord.MISSING) + if (state.acceleration() != AltosLib.MISSING) info_add_row(0, "Acceleration", "%8.1f m/s²", state.acceleration()); - if (state.max_acceleration() != AltosRecord.MISSING) + if (state.max_acceleration() != AltosLib.MISSING) info_add_row(0, "Max acceleration", "%8.1f m/s²", state.max_acceleration()); - if (state.speed() != AltosRecord.MISSING) + if (state.speed() != AltosLib.MISSING) info_add_row(0, "Speed", "%8.1f m/s", state.speed()); - if (state.max_speed() != AltosRecord.MISSING) + if (state.max_speed() != AltosLib.MISSING) info_add_row(0, "Max Speed", "%8.1f m/s", state.max_speed()); - if (state.temperature != AltosRecord.MISSING) + if (state.temperature != AltosLib.MISSING) info_add_row(0, "Temperature", "%9.2f °C", state.temperature); - if (state.battery_voltage != AltosRecord.MISSING) + if (state.battery_voltage != AltosLib.MISSING) info_add_row(0, "Battery", "%9.2f V", state.battery_voltage); - if (state.apogee_voltage != AltosRecord.MISSING) + if (state.apogee_voltage != AltosLib.MISSING) info_add_row(0, "Drogue", "%9.2f V", state.apogee_voltage); - if (state.main_voltage != AltosRecord.MISSING) + if (state.main_voltage != AltosLib.MISSING) info_add_row(0, "Main", "%9.2f V", state.main_voltage); } if (listener_state != null) { info_add_row(0, "CRC Errors", "%6d", listener_state.crc_errors); - if (listener_state.battery != AltosRecord.MISSING) + if (listener_state.battery != AltosLib.MISSING) info_add_row(0, "Receiver Battery", "%9.2f", listener_state.battery); } if (state != null) { if (state.gps == null || !state.gps.connected) { + if (state.gps == null) + System.out.printf ("null gps\n"); + else + System.out.printf ("not connected gps\n"); info_add_row(1, "GPS", "not available"); } else { if (state.gps_ready) @@ -155,13 +159,13 @@ public class AltosInfoTable extends JTable { else info_add_row(1, "GPS", " missing"); info_add_row(1, "Satellites", "%6d", state.gps.nsat); - if (state.gps.lat != AltosRecord.MISSING) + if (state.gps.lat != AltosLib.MISSING) info_add_deg(1, "Latitude", state.gps.lat, 'N', 'S'); - if (state.gps.lon != AltosRecord.MISSING) + if (state.gps.lon != AltosLib.MISSING) info_add_deg(1, "Longitude", state.gps.lon, 'E', 'W'); - if (state.gps.alt != AltosRecord.MISSING) + if (state.gps.alt != AltosLib.MISSING) info_add_row(1, "GPS altitude", "%8.1f", state.gps.alt); - if (state.gps_height != AltosRecord.MISSING) + if (state.gps_height != AltosLib.MISSING) info_add_row(1, "GPS height", "%8.1f", state.gps_height); /* The SkyTraq GPS doesn't report these values */ @@ -199,12 +203,12 @@ public class AltosInfoTable extends JTable { info_add_deg(1, "Pad longitude", state.pad_lon, 'E', 'W'); info_add_row(1, "Pad GPS alt", "%6.0f m", state.pad_alt); } - if (state.gps.year != AltosRecord.MISSING) + if (state.gps.year != AltosLib.MISSING) info_add_row(1, "GPS date", "%04d-%02d-%02d", state.gps.year, state.gps.month, state.gps.day); - if (state.gps.hour != AltosRecord.MISSING) + if (state.gps.hour != AltosLib.MISSING) info_add_row(1, "GPS time", " %02d:%02d:%02d", state.gps.hour, state.gps.minute, diff --git a/altosui/AltosKML.java b/altosui/AltosKML.java index 8679178f..fbb0ece4 100644 --- a/altosui/AltosKML.java +++ b/altosui/AltosKML.java @@ -18,7 +18,7 @@ package altosui; import java.io.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; public class AltosKML implements AltosWriter { @@ -110,7 +110,7 @@ public class AltosKML implements AltosWriter { AltosGPS gps = state.gps; double altitude; - if (state.height() != AltosRecord.MISSING) + if (state.height() != AltosLib.MISSING) altitude = state.height() + gps_start_altitude; else altitude = gps.alt; @@ -138,9 +138,9 @@ public class AltosKML implements AltosWriter { if (gps == null) return; - if (gps.lat == AltosRecord.MISSING) + if (gps.lat == AltosLib.MISSING) return; - if (gps.lon == AltosRecord.MISSING) + if (gps.lon == AltosLib.MISSING) return; if (!started) { start(state); diff --git a/altosui/AltosLanded.java b/altosui/AltosLanded.java index 630527a0..139b81b6 100644 --- a/altosui/AltosLanded.java +++ b/altosui/AltosLanded.java @@ -21,7 +21,7 @@ import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.io.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; public class AltosLanded extends JComponent implements AltosFlightDisplay, ActionListener { GridBagLayout layout; @@ -104,7 +104,7 @@ public class AltosLanded extends JComponent implements AltosFlightDisplay, Actio class Lat extends LandedValue { void show (AltosState state, AltosListenerState listener_state) { show(); - if (state.gps != null && state.gps.connected && state.gps.lat != AltosRecord.MISSING) + if (state.gps != null && state.gps.connected && state.gps.lat != AltosLib.MISSING) show(pos(state.gps.lat,"N", "S")); else show("???"); @@ -119,7 +119,7 @@ public class AltosLanded extends JComponent implements AltosFlightDisplay, Actio class Lon extends LandedValue { void show (AltosState state, AltosListenerState listener_state) { show(); - if (state.gps != null && state.gps.connected && state.gps.lon != AltosRecord.MISSING) + if (state.gps != null && state.gps.connected && state.gps.lon != AltosLib.MISSING) show(pos(state.gps.lon,"E", "W")); else show("???"); diff --git a/altosui/AltosPad.java b/altosui/AltosPad.java index e9c973de..b35bd23a 100644 --- a/altosui/AltosPad.java +++ b/altosui/AltosPad.java @@ -19,7 +19,7 @@ package altosui; import java.awt.*; import javax.swing.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; public class AltosPad extends JComponent implements AltosFlightDisplay { GridBagLayout layout; @@ -176,7 +176,7 @@ public class AltosPad extends JComponent implements AltosFlightDisplay { class Battery extends LaunchStatus { void show (AltosState state, AltosListenerState listener_state) { - if (state == null || state.battery_voltage == AltosRecord.MISSING) + if (state == null || state.battery_voltage == AltosLib.MISSING) hide(); else { show("%4.2f V", state.battery_voltage); @@ -192,7 +192,7 @@ public class AltosPad extends JComponent implements AltosFlightDisplay { class Apogee extends LaunchStatus { void show (AltosState state, AltosListenerState listener_state) { - if (state == null || state.apogee_voltage == AltosRecord.MISSING) + if (state == null || state.apogee_voltage == AltosLib.MISSING) hide(); else { show("%4.2f V", state.apogee_voltage); @@ -208,7 +208,7 @@ public class AltosPad extends JComponent implements AltosFlightDisplay { class Main extends LaunchStatus { void show (AltosState state, AltosListenerState listener_state) { - if (state == null || state.main_voltage == AltosRecord.MISSING) + if (state == null || state.main_voltage == AltosLib.MISSING) hide(); else { show("%4.2f V", state.main_voltage); @@ -224,7 +224,7 @@ public class AltosPad extends JComponent implements AltosFlightDisplay { class LoggingReady extends LaunchStatus { void show (AltosState state, AltosListenerState listener_state) { - if (state == null || state.flight == AltosRecord.MISSING) { + if (state == null || state.flight == AltosLib.MISSING) { hide(); } else { if (state.flight != 0) { @@ -283,7 +283,7 @@ public class AltosPad extends JComponent implements AltosFlightDisplay { class ReceiverBattery extends LaunchStatus { void show (AltosState state, AltosListenerState listener_state) { - if (listener_state == null || listener_state.battery == AltosRecord.MISSING) + if (listener_state == null || listener_state.battery == AltosLib.MISSING) hide(); else { show("%4.2f V", listener_state.battery); @@ -310,11 +310,11 @@ public class AltosPad extends JComponent implements AltosFlightDisplay { class PadLat extends LaunchValue { void show (AltosState state, AltosListenerState listener_state) { - double lat = AltosRecord.MISSING; + double lat = AltosLib.MISSING; String label = null; if (state != null) { - if (state.state < AltosLib.ao_flight_pad && state.gps != null && state.gps.lat != AltosRecord.MISSING) { + if (state.state < AltosLib.ao_flight_pad && state.gps != null && state.gps.lat != AltosLib.MISSING) { lat = state.gps.lat; label = "Latitude"; } else { @@ -322,8 +322,8 @@ public class AltosPad extends JComponent implements AltosFlightDisplay { label = "Pad Latitude"; } } - if (lat != AltosRecord.MISSING) { - show(pos(lat,"E", "W")); + if (lat != AltosLib.MISSING) { + show(pos(lat,"N", "S")); set_label(label); } else hide(); @@ -337,11 +337,11 @@ public class AltosPad extends JComponent implements AltosFlightDisplay { class PadLon extends LaunchValue { void show (AltosState state, AltosListenerState listener_state) { - double lon = AltosRecord.MISSING; + double lon = AltosLib.MISSING; String label = null; if (state != null) { - if (state.state < AltosLib.ao_flight_pad && state.gps != null && state.gps.lon != AltosRecord.MISSING) { + if (state.state < AltosLib.ao_flight_pad && state.gps != null && state.gps.lon != AltosLib.MISSING) { lon = state.gps.lon; label = "Longitude"; } else { @@ -349,7 +349,7 @@ public class AltosPad extends JComponent implements AltosFlightDisplay { label = "Pad Longitude"; } } - if (lon != AltosRecord.MISSING) { + if (lon != AltosLib.MISSING) { show(pos(lon,"E", "W")); set_label(label); } else @@ -364,11 +364,11 @@ public class AltosPad extends JComponent implements AltosFlightDisplay { class PadAlt extends LaunchValue { void show (AltosState state, AltosListenerState listener_state) { - double alt = AltosRecord.MISSING; + double alt = AltosLib.MISSING; String label = null; if (state != null) { - if (state.state < AltosLib.ao_flight_pad && state.gps != null && state.gps.alt != AltosRecord.MISSING) { + if (state.state < AltosLib.ao_flight_pad && state.gps != null && state.gps.alt != AltosLib.MISSING) { alt = state.gps.alt; label = "Altitude"; } else { @@ -376,7 +376,7 @@ public class AltosPad extends JComponent implements AltosFlightDisplay { label = "Pad Altitude"; } } - if (alt != AltosRecord.MISSING) { + if (alt != AltosLib.MISSING) { show("%4.0f m", state.gps.alt); set_label(label); } else diff --git a/altosui/AltosRomconfigUI.java b/altosui/AltosRomconfigUI.java index 909e72a0..6f9d9dc6 100644 --- a/altosui/AltosRomconfigUI.java +++ b/altosui/AltosRomconfigUI.java @@ -20,7 +20,7 @@ package altosui; import java.awt.*; import java.awt.event.*; import javax.swing.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; import org.altusmetrum.altosuilib_1.*; public class AltosRomconfigUI diff --git a/altosui/AltosScanUI.java b/altosui/AltosScanUI.java index 224e1e61..a5ccb15a 100644 --- a/altosui/AltosScanUI.java +++ b/altosui/AltosScanUI.java @@ -25,7 +25,7 @@ import java.io.*; import java.util.*; import java.text.*; import java.util.concurrent.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; import org.altusmetrum.altosuilib_1.*; class AltosScanResult { @@ -187,7 +187,7 @@ public class AltosScanUI AltosState state = reader.read(); if (state == null) continue; - if (state.flight != AltosRecord.MISSING) { + if (state.flight != AltosLib.MISSING) { final AltosScanResult result = new AltosScanResult(state.callsign, state.serial, state.flight, diff --git a/altosui/AltosSerial.java b/altosui/AltosSerial.java index e869f1ab..697ad539 100644 --- a/altosui/AltosSerial.java +++ b/altosui/AltosSerial.java @@ -25,7 +25,7 @@ import java.io.*; import java.util.*; import java.awt.*; import javax.swing.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; import org.altusmetrum.altosuilib_1.*; import libaltosJNI.*; diff --git a/altosui/AltosSiteMap.java b/altosui/AltosSiteMap.java index c0926919..9491ce2b 100644 --- a/altosui/AltosSiteMap.java +++ b/altosui/AltosSiteMap.java @@ -23,7 +23,7 @@ import java.io.*; import java.lang.Math; import java.awt.geom.Point2D; import java.util.concurrent.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; import org.altusmetrum.altosuilib_1.*; public class AltosSiteMap extends JScrollPane implements AltosFlightDisplay { @@ -287,10 +287,10 @@ public class AltosSiteMap extends JScrollPane implements AltosFlightDisplay { return; if (!initialised) { - if (state.pad_lat != AltosRecord.MISSING && state.pad_lon != AltosRecord.MISSING) { + if (state.pad_lat != AltosLib.MISSING && state.pad_lon != AltosLib.MISSING) { initMaps(state.pad_lat, state.pad_lon); initialised = true; - } else if (gps.lat != AltosRecord.MISSING && gps.lon != AltosRecord.MISSING) { + } else if (gps.lat != AltosLib.MISSING && gps.lon != AltosLib.MISSING) { initMaps(gps.lat, gps.lon); initialised = true; } else { diff --git a/altosui/AltosSiteMapTile.java b/altosui/AltosSiteMapTile.java index 365e4b6c..172e6397 100644 --- a/altosui/AltosSiteMapTile.java +++ b/altosui/AltosSiteMapTile.java @@ -22,7 +22,7 @@ import java.awt.image.*; import javax.swing.*; import java.awt.geom.Point2D; import java.awt.geom.Line2D; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; public class AltosSiteMapTile extends JLayeredPane { JLabel mapLabel; diff --git a/altosui/AltosUI.java b/altosui/AltosUI.java index 31d5a54d..9dad8718 100644 --- a/altosui/AltosUI.java +++ b/altosui/AltosUI.java @@ -22,7 +22,7 @@ import java.awt.event.*; import javax.swing.*; import java.io.*; import java.util.concurrent.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; import org.altusmetrum.altosuilib_1.*; public class AltosUI extends AltosUIFrame { @@ -492,7 +492,7 @@ public class AltosUI extends AltosUIFrame { stats.max_speed, AltosConvert.meters_to_feet(stats.max_speed), AltosConvert.meters_to_mach(stats.max_speed)); - if (stats.max_acceleration != AltosRecord.MISSING) { + if (stats.max_acceleration != AltosLib.MISSING) { System.out.printf("Max accel: %6.0f m/s² %6.0f ft/s² %6.2f g\n", stats.max_acceleration, AltosConvert.meters_to_feet(stats.max_acceleration), diff --git a/altosui/AltosUIPreferencesBackend.java b/altosui/AltosUIPreferencesBackend.java index 0dac9fc7..fb5f8520 100644 --- a/altosui/AltosUIPreferencesBackend.java +++ b/altosui/AltosUIPreferencesBackend.java @@ -19,7 +19,7 @@ package altosui; import java.io.File; import java.util.prefs.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; import javax.swing.filechooser.FileSystemView; public class AltosUIPreferencesBackend implements AltosPreferencesBackend { diff --git a/altosui/AltosWriter.java b/altosui/AltosWriter.java index 8de11bc9..d664d6e8 100644 --- a/altosui/AltosWriter.java +++ b/altosui/AltosWriter.java @@ -17,7 +17,7 @@ package altosui; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; public interface AltosWriter { diff --git a/altosuilib/AltosUIAxis.java b/altosuilib/AltosUIAxis.java index 867b0384..a38cba63 100644 --- a/altosuilib/AltosUIAxis.java +++ b/altosuilib/AltosUIAxis.java @@ -22,7 +22,7 @@ import java.util.ArrayList; import java.awt.*; import javax.swing.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; import org.jfree.ui.*; import org.jfree.chart.*; diff --git a/altosuilib/AltosUIEnable.java b/altosuilib/AltosUIEnable.java index 55486dea..84803c0e 100644 --- a/altosuilib/AltosUIEnable.java +++ b/altosuilib/AltosUIEnable.java @@ -23,7 +23,7 @@ import javax.swing.*; import java.io.*; import java.util.concurrent.*; import java.util.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; import org.jfree.ui.*; import org.jfree.chart.*; diff --git a/altosuilib/AltosUIGraph.java b/altosuilib/AltosUIGraph.java index 5f3a2eef..ef0cc677 100644 --- a/altosuilib/AltosUIGraph.java +++ b/altosuilib/AltosUIGraph.java @@ -22,7 +22,7 @@ import java.util.ArrayList; import java.awt.*; import javax.swing.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; import org.jfree.ui.*; import org.jfree.chart.*; diff --git a/altosuilib/AltosUIGrapher.java b/altosuilib/AltosUIGrapher.java index 8f0ce801..d826072f 100644 --- a/altosuilib/AltosUIGrapher.java +++ b/altosuilib/AltosUIGrapher.java @@ -22,7 +22,7 @@ import java.util.ArrayList; import java.awt.*; import javax.swing.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; import org.jfree.ui.*; import org.jfree.chart.*; diff --git a/altosuilib/AltosUILib.java b/altosuilib/AltosUILib.java index 1b121405..9fcaf6d4 100644 --- a/altosuilib/AltosUILib.java +++ b/altosuilib/AltosUILib.java @@ -20,7 +20,7 @@ package org.altusmetrum.altosuilib_1; import java.awt.*; import libaltosJNI.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; public class AltosUILib extends AltosLib { diff --git a/altosuilib/AltosUIMarker.java b/altosuilib/AltosUIMarker.java index 0949be6f..e4262abd 100644 --- a/altosuilib/AltosUIMarker.java +++ b/altosuilib/AltosUIMarker.java @@ -22,7 +22,7 @@ import java.util.ArrayList; import java.awt.*; import javax.swing.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; import org.jfree.ui.*; import org.jfree.chart.*; diff --git a/altosuilib/AltosUIPreferences.java b/altosuilib/AltosUIPreferences.java index 49321bce..fc14f24b 100644 --- a/altosuilib/AltosUIPreferences.java +++ b/altosuilib/AltosUIPreferences.java @@ -21,7 +21,7 @@ import java.io.*; import java.util.*; import java.awt.Component; import javax.swing.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; public class AltosUIPreferences extends AltosPreferences { diff --git a/altosuilib/AltosUIPreferencesBackend.java b/altosuilib/AltosUIPreferencesBackend.java index 8a5386c3..55da8d48 100644 --- a/altosuilib/AltosUIPreferencesBackend.java +++ b/altosuilib/AltosUIPreferencesBackend.java @@ -19,7 +19,7 @@ package org.altusmetrum.altosuilib_1; import java.io.File; import java.util.prefs.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; import javax.swing.filechooser.FileSystemView; public class AltosUIPreferencesBackend implements AltosPreferencesBackend { diff --git a/altosuilib/AltosUISeries.java b/altosuilib/AltosUISeries.java index ac09a3cc..ff430d1a 100644 --- a/altosuilib/AltosUISeries.java +++ b/altosuilib/AltosUISeries.java @@ -22,7 +22,7 @@ import java.util.ArrayList; import java.awt.*; import javax.swing.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; import org.jfree.ui.*; import org.jfree.chart.*; @@ -34,6 +34,20 @@ import org.jfree.chart.labels.*; import org.jfree.data.xy.*; import org.jfree.data.*; +class AltosUITime extends AltosUnits { + public double value(double v) { return v; } + public String show_units() { return "s"; } + public String say_units() { return "seconds"; } + + public int show_fraction(int width) { + if (width < 5) + return 0; + return width - 5; + } + + public int say_fraction() { return 0; } +} + public class AltosUISeries extends XYSeries implements AltosUIGrapher { AltosUIAxis axis; String label; @@ -47,11 +61,12 @@ public class AltosUISeries extends XYSeries implements AltosUIGrapher { axis.set_units(); StandardXYToolTipGenerator ttg; - String example = units.graph_format(4); + String time_example = (new AltosUITime()).graph_format(7); + String example = units.graph_format(7); ttg = new StandardXYToolTipGenerator(String.format("{1}s: {2}%s ({0})", units.show_units()), - new java.text.DecimalFormat(example), + new java.text.DecimalFormat(time_example), new java.text.DecimalFormat(example)); renderer.setBaseToolTipGenerator(ttg); } diff --git a/configure.ac b/configure.ac index 4d0a2ef6..e88109f9 100644 --- a/configure.ac +++ b/configure.ac @@ -31,7 +31,7 @@ dnl ========================================================================== dnl Java library versions ALTOSUILIB_VERSION=1 -ALTOSLIB_VERSION=1 +ALTOSLIB_VERSION=2 AC_SUBST(ALTOSLIB_VERSION) AC_DEFINE(ALTOSLIB_VERSION,$ALTOSLIB_VERSION,[Version of the AltosLib package]) diff --git a/micropeak/MicroData.java b/micropeak/MicroData.java index 4c0ed4c3..07806fa4 100644 --- a/micropeak/MicroData.java +++ b/micropeak/MicroData.java @@ -20,7 +20,7 @@ package org.altusmetrum.micropeak; import java.lang.*; import java.io.*; import java.util.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; import org.altusmetrum.altosuilib_1.*; class MicroIterator implements Iterator { diff --git a/micropeak/MicroDownload.java b/micropeak/MicroDownload.java index bd6795f8..a9095f9c 100644 --- a/micropeak/MicroDownload.java +++ b/micropeak/MicroDownload.java @@ -23,7 +23,7 @@ import javax.swing.*; import java.io.*; import java.util.concurrent.*; import java.util.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; import org.altusmetrum.altosuilib_1.*; public class MicroDownload extends AltosUIDialog implements Runnable, ActionListener { diff --git a/micropeak/MicroExport.java b/micropeak/MicroExport.java index 20a6f79a..5af767c6 100644 --- a/micropeak/MicroExport.java +++ b/micropeak/MicroExport.java @@ -23,7 +23,7 @@ import java.util.ArrayList; import java.awt.*; import javax.swing.*; import javax.swing.filechooser.FileNameExtensionFilter; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; import org.altusmetrum.altosuilib_1.*; public class MicroExport extends JFileChooser { diff --git a/micropeak/MicroFile.java b/micropeak/MicroFile.java index cdd42e66..2b02e20a 100644 --- a/micropeak/MicroFile.java +++ b/micropeak/MicroFile.java @@ -19,7 +19,7 @@ package org.altusmetrum.micropeak; import java.io.*; import java.util.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; import org.altusmetrum.altosuilib_1.*; public class MicroFile { diff --git a/micropeak/MicroFileChooser.java b/micropeak/MicroFileChooser.java index d52eab2c..3ca128ee 100644 --- a/micropeak/MicroFileChooser.java +++ b/micropeak/MicroFileChooser.java @@ -20,7 +20,7 @@ package org.altusmetrum.micropeak; import javax.swing.*; import javax.swing.filechooser.FileNameExtensionFilter; import java.io.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; import org.altusmetrum.altosuilib_1.*; public class MicroFileChooser extends JFileChooser { diff --git a/micropeak/MicroGraph.java b/micropeak/MicroGraph.java index 50508a61..fba62907 100644 --- a/micropeak/MicroGraph.java +++ b/micropeak/MicroGraph.java @@ -22,7 +22,7 @@ import java.util.ArrayList; import java.awt.*; import javax.swing.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; import org.altusmetrum.altosuilib_1.*; import org.jfree.ui.*; diff --git a/micropeak/MicroPeak.java b/micropeak/MicroPeak.java index cb1c68cb..27a8db02 100644 --- a/micropeak/MicroPeak.java +++ b/micropeak/MicroPeak.java @@ -23,7 +23,7 @@ import javax.swing.*; import java.io.*; import java.util.concurrent.*; import java.util.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; import org.altusmetrum.altosuilib_1.*; public class MicroPeak extends MicroFrame implements ActionListener, ItemListener { diff --git a/micropeak/MicroRaw.java b/micropeak/MicroRaw.java index 7337a1de..0520fa71 100644 --- a/micropeak/MicroRaw.java +++ b/micropeak/MicroRaw.java @@ -20,7 +20,7 @@ package org.altusmetrum.micropeak; import java.awt.*; import java.io.*; import javax.swing.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; import org.altusmetrum.altosuilib_1.*; public class MicroRaw extends JTextArea { diff --git a/micropeak/MicroSave.java b/micropeak/MicroSave.java index 99f621ce..1f1ef3cb 100644 --- a/micropeak/MicroSave.java +++ b/micropeak/MicroSave.java @@ -24,7 +24,7 @@ import javax.swing.filechooser.FileNameExtensionFilter; import java.io.*; import java.util.concurrent.*; import java.util.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; import org.altusmetrum.altosuilib_1.*; public class MicroSave extends JFileChooser { diff --git a/micropeak/MicroStats.java b/micropeak/MicroStats.java index 99479cb4..32d94432 100644 --- a/micropeak/MicroStats.java +++ b/micropeak/MicroStats.java @@ -18,7 +18,7 @@ package org.altusmetrum.micropeak; import java.io.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; import org.altusmetrum.altosuilib_1.*; public class MicroStats { diff --git a/micropeak/MicroStatsTable.java b/micropeak/MicroStatsTable.java index 145bb70e..4400a317 100644 --- a/micropeak/MicroStatsTable.java +++ b/micropeak/MicroStatsTable.java @@ -19,7 +19,7 @@ package org.altusmetrum.micropeak; import java.awt.*; import javax.swing.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_2.*; import org.altusmetrum.altosuilib_1.*; public class MicroStatsTable extends JComponent implements AltosFontListener { -- cgit v1.2.3 From 82b42935d047d2f7c2f7a63a3efb72a3f1d5594e Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 25 Nov 2013 00:02:06 -0800 Subject: altosui: Handle units in pyro config. This lets you edit the pyro configuration using imperial units if desired. Signed-off-by: Keith Packard --- altoslib/AltosAccel.java | 20 +++++--- altoslib/AltosConvert.java | 12 +++++ altoslib/AltosDistance.java | 26 +++++++---- altoslib/AltosHeight.java | 21 ++++----- altoslib/AltosPyro.java | 68 +++++++++++++++++---------- altoslib/AltosSpeed.java | 20 +++++--- altoslib/AltosTemperature.java | 20 +++++--- altoslib/AltosUnits.java | 77 +++++++++++++++++++++++++------ altosui/AltosConfigPyroUI.java | 102 ++++++++++++++++++++++++++++++++++++----- altosui/AltosConfigUI.java | 15 ++++-- altosui/AltosGraph.java | 48 ++++++++++++------- 11 files changed, 315 insertions(+), 114 deletions(-) (limited to 'altoslib/AltosConvert.java') diff --git a/altoslib/AltosAccel.java b/altoslib/AltosAccel.java index 08eba359..b838d30b 100644 --- a/altoslib/AltosAccel.java +++ b/altoslib/AltosAccel.java @@ -19,25 +19,31 @@ package org.altusmetrum.altoslib_2; public class AltosAccel extends AltosUnits { - public double value(double v) { - if (AltosConvert.imperial_units) + public double value(double v, boolean imperial_units) { + if (imperial_units) return AltosConvert.meters_to_feet(v); return v; } - public String show_units() { - if (AltosConvert.imperial_units) + public double inverse(double v, boolean imperial_units) { + if (imperial_units) + return AltosConvert.feet_to_meters(v); + return v; + } + + public String show_units(boolean imperial_units) { + if (imperial_units) return "ft/s²"; return "m/s²"; } - public String say_units() { - if (AltosConvert.imperial_units) + public String say_units(boolean imperial_units) { + if (imperial_units) return "feet per second squared"; return "meters per second squared"; } - public int show_fraction(int width) { + public int show_fraction(int width, boolean imperial_units) { return width / 9; } } \ No newline at end of file diff --git a/altoslib/AltosConvert.java b/altoslib/AltosConvert.java index 760d9eb9..8d0b74dd 100644 --- a/altoslib/AltosConvert.java +++ b/altoslib/AltosConvert.java @@ -290,10 +290,18 @@ public class AltosConvert { return meters_to_feet(meters) / 5280; } + public static double miles_to_meters(double miles) { + return feet_to_meters(miles * 5280); + } + public static double meters_to_mph(double mps) { return meters_to_miles(mps) * 3600; } + public static double mph_to_meters(double mps) { + return miles_to_meters(mps) / 3600; + } + public static double meters_to_mach(double meters) { return meters / 343; /* something close to mach at usual rocket sites */ } @@ -306,6 +314,10 @@ public class AltosConvert { return c * 9/5 + 32; } + public static double f_to_c(double c) { + return (c - 32) * 5/9; + } + public static boolean imperial_units = false; public static AltosDistance distance = new AltosDistance(); diff --git a/altoslib/AltosDistance.java b/altoslib/AltosDistance.java index 56257165..8d359feb 100644 --- a/altoslib/AltosDistance.java +++ b/altoslib/AltosDistance.java @@ -19,32 +19,38 @@ package org.altusmetrum.altoslib_2; public class AltosDistance extends AltosUnits { - public double value(double v) { - if (AltosConvert.imperial_units) + public double value(double v, boolean imperial_units) { + if (imperial_units) return AltosConvert.meters_to_miles(v); return v; } - public String show_units() { - if (AltosConvert.imperial_units) + public double inverse(double v, boolean imperial_units) { + if (imperial_units) + return AltosConvert.miles_to_meters(v); + return v; + } + + public String show_units(boolean imperial_units) { + if (imperial_units) return "miles"; return "m"; } - public String say_units() { - if (AltosConvert.imperial_units) + public String say_units(boolean imperial_units) { + if (imperial_units) return "miles"; return "meters"; } - public int show_fraction(int width) { - if (AltosConvert.imperial_units) + public int show_fraction(int width, boolean imperial_units) { + if (imperial_units) return width / 3; return width / 9; } - public int say_fraction() { - if (AltosConvert.imperial_units) + public int say_fraction(boolean imperial_units) { + if (imperial_units) return 1; return 0; } diff --git a/altoslib/AltosHeight.java b/altoslib/AltosHeight.java index 1d2e4dbc..84bd42d9 100644 --- a/altoslib/AltosHeight.java +++ b/altoslib/AltosHeight.java @@ -19,32 +19,31 @@ package org.altusmetrum.altoslib_2; public class AltosHeight extends AltosUnits { - public double value(double v) { - if (AltosConvert.imperial_units) + public double value(double v, boolean imperial_units) { + if (imperial_units) return AltosConvert.meters_to_feet(v); return v; } - public double parse(String s) throws NumberFormatException { - double v = Double.parseDouble(s); - if (AltosConvert.imperial_units) - v = AltosConvert.feet_to_meters(v); + public double inverse(double v, boolean imperial_units) { + if (imperial_units) + return AltosConvert.feet_to_meters(v); return v; } - public String show_units() { - if (AltosConvert.imperial_units) + public String show_units(boolean imperial_units) { + if (imperial_units) return "ft"; return "m"; } - public String say_units() { - if (AltosConvert.imperial_units) + public String say_units(boolean imperial_units) { + if (imperial_units) return "feet"; return "meters"; } - public int show_fraction(int width) { + public int show_fraction(int width, boolean imperial_units) { return width / 9; } } \ No newline at end of file diff --git a/altoslib/AltosPyro.java b/altoslib/AltosPyro.java index 0142eac8..a219468c 100644 --- a/altoslib/AltosPyro.java +++ b/altoslib/AltosPyro.java @@ -28,24 +28,24 @@ public class AltosPyro { public static final int pyro_accel_greater = 0x00000002; public static final String pyro_accel_less_string = "a<"; public static final String pyro_accel_greater_string = "a>"; - public static final String pyro_accel_less_name = "Acceleration less than (m/s²)"; - public static final String pyro_accel_greater_name = "Acceleration greater than (m/s²)"; + public static final String pyro_accel_less_name = "Acceleration less than"; + public static final String pyro_accel_greater_name = "Acceleration greater than"; public static final double pyro_accel_scale = 16.0; public static final int pyro_speed_less = 0x00000004; public static final int pyro_speed_greater = 0x00000008; public static final String pyro_speed_less_string = "s<"; public static final String pyro_speed_greater_string = "s>"; - public static final String pyro_speed_less_name = "Speed less than (m/s)"; - public static final String pyro_speed_greater_name = "Speed greater than (m/s)"; + public static final String pyro_speed_less_name = "Speed less than"; + public static final String pyro_speed_greater_name = "Speed greater than"; public static final double pyro_speed_scale = 16.0; public static final int pyro_height_less = 0x00000010; public static final int pyro_height_greater = 0x00000020; public static final String pyro_height_less_string = "h<"; public static final String pyro_height_greater_string = "h>"; - public static final String pyro_height_less_name = "Height less than (m)"; - public static final String pyro_height_greater_name = "Height greater than (m)"; + public static final String pyro_height_less_name = "Height less than"; + public static final String pyro_height_greater_name = "Height greater than"; public static final double pyro_height_scale = 1.0; public static final int pyro_orient_less = 0x00000040; @@ -102,12 +102,16 @@ public class AltosPyro { private static HashMap pyro_to_name = new HashMap(); + private static HashMap pyro_to_units = new HashMap(); + private static HashMap pyro_to_scale = new HashMap(); - private static void insert_map(int flag, String string, String name, double scale) { + private static void insert_map(int flag, String string, String name, AltosUnits units, double scale) { string_to_pyro.put(string, flag); pyro_to_string.put(flag, string); pyro_to_name.put(flag, name); + if (units != null) + pyro_to_units.put(flag, units); pyro_to_scale.put(flag, scale); } @@ -124,8 +128,22 @@ public class AltosPyro { } public static String pyro_to_name(int flag) { - if (pyro_to_name.containsKey(flag)) - return pyro_to_name.get(flag); + String name; + AltosUnits units = null; + if (!pyro_to_name.containsKey(flag)) + return null; + + name = pyro_to_name.get(flag); + if (pyro_to_units.containsKey(flag)) + units = pyro_to_units.get(flag); + if (units == null) + return name; + return String.format ("%s (%s)", name, units.show_units()); + } + + public static AltosUnits pyro_to_units(int flag) { + if (pyro_to_units.containsKey(flag)) + return pyro_to_units.get(flag); return null; } @@ -136,29 +154,29 @@ public class AltosPyro { } private static void initialize_maps() { - insert_map(pyro_accel_less, pyro_accel_less_string, pyro_accel_less_name, pyro_accel_scale); - insert_map(pyro_accel_greater, pyro_accel_greater_string, pyro_accel_greater_name, pyro_accel_scale); + insert_map(pyro_accel_less, pyro_accel_less_string, pyro_accel_less_name, AltosConvert.accel, pyro_accel_scale); + insert_map(pyro_accel_greater, pyro_accel_greater_string, pyro_accel_greater_name, AltosConvert.accel, pyro_accel_scale); - insert_map(pyro_speed_less, pyro_speed_less_string, pyro_speed_less_name, pyro_speed_scale); - insert_map(pyro_speed_greater, pyro_speed_greater_string, pyro_speed_greater_name, pyro_speed_scale); + insert_map(pyro_speed_less, pyro_speed_less_string, pyro_speed_less_name, AltosConvert.speed, pyro_speed_scale); + insert_map(pyro_speed_greater, pyro_speed_greater_string, pyro_speed_greater_name, AltosConvert.speed, pyro_speed_scale); - insert_map(pyro_height_less, pyro_height_less_string, pyro_height_less_name, pyro_height_scale); - insert_map(pyro_height_greater, pyro_height_greater_string, pyro_height_greater_name, pyro_height_scale); + insert_map(pyro_height_less, pyro_height_less_string, pyro_height_less_name, AltosConvert.height, pyro_height_scale); + insert_map(pyro_height_greater, pyro_height_greater_string, pyro_height_greater_name, AltosConvert.height, pyro_height_scale); - insert_map(pyro_orient_less, pyro_orient_less_string, pyro_orient_less_name, pyro_orient_scale); - insert_map(pyro_orient_greater, pyro_orient_greater_string, pyro_orient_greater_name, pyro_orient_scale); + insert_map(pyro_orient_less, pyro_orient_less_string, pyro_orient_less_name, null, pyro_orient_scale); + insert_map(pyro_orient_greater, pyro_orient_greater_string, pyro_orient_greater_name, null, pyro_orient_scale); - insert_map(pyro_time_less, pyro_time_less_string, pyro_time_less_name, pyro_time_scale); - insert_map(pyro_time_greater, pyro_time_greater_string, pyro_time_greater_name, pyro_time_scale); + insert_map(pyro_time_less, pyro_time_less_string, pyro_time_less_name, null, pyro_time_scale); + insert_map(pyro_time_greater, pyro_time_greater_string, pyro_time_greater_name, null, pyro_time_scale); - insert_map(pyro_ascending, pyro_ascending_string, pyro_ascending_name, 1.0); - insert_map(pyro_descending, pyro_descending_string, pyro_descending_name, 1.0); + insert_map(pyro_ascending, pyro_ascending_string, pyro_ascending_name, null, 1.0); + insert_map(pyro_descending, pyro_descending_string, pyro_descending_name, null, 1.0); - insert_map(pyro_after_motor, pyro_after_motor_string, pyro_after_motor_name, 1.0); - insert_map(pyro_delay, pyro_delay_string, pyro_delay_name, pyro_delay_scale); + insert_map(pyro_after_motor, pyro_after_motor_string, pyro_after_motor_name, null, 1.0); + insert_map(pyro_delay, pyro_delay_string, pyro_delay_name, null, pyro_delay_scale); - insert_map(pyro_state_less, pyro_state_less_string, pyro_state_less_name, 1.0); - insert_map(pyro_state_greater_or_equal, pyro_state_greater_or_equal_string, pyro_state_greater_or_equal_name, 1.0); + insert_map(pyro_state_less, pyro_state_less_string, pyro_state_less_name, null, 1.0); + insert_map(pyro_state_greater_or_equal, pyro_state_greater_or_equal_string, pyro_state_greater_or_equal_name, null, 1.0); } { diff --git a/altoslib/AltosSpeed.java b/altoslib/AltosSpeed.java index 9b9f7240..6618c539 100644 --- a/altoslib/AltosSpeed.java +++ b/altoslib/AltosSpeed.java @@ -19,25 +19,31 @@ package org.altusmetrum.altoslib_2; public class AltosSpeed extends AltosUnits { - public double value(double v) { - if (AltosConvert.imperial_units) + public double value(double v, boolean imperial_units) { + if (imperial_units) return AltosConvert.meters_to_mph(v); return v; } - public String show_units() { - if (AltosConvert.imperial_units) + public double inverse(double v, boolean imperial_units) { + if (imperial_units) + return AltosConvert.mph_to_meters(v); + return v; + } + + public String show_units(boolean imperial_units) { + if (imperial_units) return "mph"; return "m/s"; } - public String say_units() { - if (AltosConvert.imperial_units) + public String say_units(boolean imperial_units) { + if (imperial_units) return "miles per hour"; return "meters per second"; } - public int show_fraction(int width) { + public int show_fraction(int width, boolean imperial_units) { return width / 9; } } \ No newline at end of file diff --git a/altoslib/AltosTemperature.java b/altoslib/AltosTemperature.java index 0105fe53..a636533f 100644 --- a/altoslib/AltosTemperature.java +++ b/altoslib/AltosTemperature.java @@ -19,25 +19,31 @@ package org.altusmetrum.altoslib_2; public class AltosTemperature extends AltosUnits { - public double value(double v) { - if (AltosConvert.imperial_units) + public double value(double v, boolean imperial_units) { + if (imperial_units) return AltosConvert.c_to_f(v); return v; } - public String show_units() { - if (AltosConvert.imperial_units) + public double inverse(double v, boolean imperial_units) { + if (imperial_units) + return AltosConvert.f_to_c(v); + return v; + } + + public String show_units(boolean imperial_units) { + if (imperial_units) return "°F"; return "°C"; } - public String say_units() { - if (AltosConvert.imperial_units) + public String say_units(boolean imperial_units) { + if (imperial_units) return "degrees farenheit"; return "degrees celsius"; } - public int show_fraction(int width) { + public int show_fraction(int width, boolean imperial_units) { return width / 3; } } diff --git a/altoslib/AltosUnits.java b/altoslib/AltosUnits.java index ee74f916..8f9ccded 100644 --- a/altoslib/AltosUnits.java +++ b/altoslib/AltosUnits.java @@ -19,43 +19,90 @@ package org.altusmetrum.altoslib_2; public abstract class AltosUnits { - public abstract double value(double v); + public abstract double value(double v, boolean imperial_units); - public abstract String show_units(); + public abstract double inverse(double v, boolean imperial_units); - public abstract String say_units(); + public abstract String show_units(boolean imperial_units); - public abstract int show_fraction(int width); + public abstract String say_units(boolean imperial_units); - int say_fraction() { + public abstract int show_fraction(int width, boolean imperial_units); + + public double parse(String s, boolean imperial_units) throws NumberFormatException { + double v = Double.parseDouble(s); + return inverse(v, imperial_units); + } + + public double parse(String s) throws NumberFormatException { + return parse(s, AltosConvert.imperial_units); + } + + public double value(double v) { + return value(v, AltosConvert.imperial_units); + } + + public double inverse(double v) { + return inverse(v, AltosConvert.imperial_units); + } + + public String show_units() { + return show_units(AltosConvert.imperial_units); + } + + public String say_units() { + return say_units(AltosConvert.imperial_units); + } + + public int show_fraction(int width) { + return show_fraction(width, AltosConvert.imperial_units); + } + + int say_fraction(boolean imperial_units) { return 0; } - private String show_format(int width) { - return String.format("%%%d.%df %s", width, show_fraction(width), show_units()); + private String show_format(int width, boolean imperial_units) { + return String.format("%%%d.%df %s", width, show_fraction(width, imperial_units), show_units(imperial_units)); + } + + private String say_format(boolean imperial_units) { + return String.format("%%1.%df", say_fraction(imperial_units)); } - private String say_format() { - return String.format("%%1.%df", say_fraction()); + private String say_units_format(boolean imperial_units) { + return String.format("%%1.%df %s", say_fraction(imperial_units), say_units(imperial_units)); } - private String say_units_format() { - return String.format("%%1.%df %s", say_fraction(), say_units()); + public String graph_format(int width, boolean imperial_units) { + return String.format(String.format("%%%d.%df", width, show_fraction(width, imperial_units)), 0.0); } public String graph_format(int width) { - return String.format(String.format("%%%d.%df", width, show_fraction(width)), 0.0); + return graph_format(width, AltosConvert.imperial_units); + } + + public String show(int width, double v, boolean imperial_units) { + return String.format(show_format(width, imperial_units), value(v, imperial_units)); } public String show(int width, double v) { - return String.format(show_format(width), value(v)); + return show(width, v, AltosConvert.imperial_units); + } + + public String say(double v, boolean imperial_units) { + return String.format(say_format(imperial_units), value(v, imperial_units)); } public String say(double v) { - return String.format(say_format(), value(v)); + return say(v, AltosConvert.imperial_units); + } + + public String say_units(double v, boolean imperial_units) { + return String.format(say_units_format(imperial_units), value(v, imperial_units)); } public String say_units(double v) { - return String.format(say_units_format(), value(v)); + return say_units(v, AltosConvert.imperial_units); } } \ No newline at end of file diff --git a/altosui/AltosConfigPyroUI.java b/altosui/AltosConfigPyroUI.java index 2f5c199d..81d12111 100644 --- a/altosui/AltosConfigPyroUI.java +++ b/altosui/AltosConfigPyroUI.java @@ -26,7 +26,7 @@ import org.altusmetrum.altosuilib_1.*; public class AltosConfigPyroUI extends AltosUIDialog - implements ItemListener, DocumentListener + implements ItemListener, DocumentListener, AltosUnitsListener { AltosConfigUI owner; Container pane; @@ -45,13 +45,14 @@ public class AltosConfigPyroUI } } - class PyroItem implements ItemListener, DocumentListener + class PyroItem implements ItemListener, DocumentListener, AltosUnitsListener { public int flag; public JRadioButton enable; public JTextField value; public JComboBox combo; AltosConfigPyroUI ui; + boolean setting; public void set_enable(boolean enable) { if (value != null) @@ -62,36 +63,59 @@ public class AltosConfigPyroUI public void itemStateChanged(ItemEvent e) { set_enable(enable.isSelected()); - ui.set_dirty(); + if (!setting) + ui.set_dirty(); } public void changedUpdate(DocumentEvent e) { - ui.set_dirty(); + if (!setting) + ui.set_dirty(); } public void insertUpdate(DocumentEvent e) { - ui.set_dirty(); + if (!setting) + ui.set_dirty(); } public void removeUpdate(DocumentEvent e) { - ui.set_dirty(); + if (!setting) + ui.set_dirty(); + } + + public void units_changed(boolean imperial_units) { + AltosUnits units = AltosPyro.pyro_to_units(flag); + + if (units != null) { + try { + double v = units.parse(value.getText(), !imperial_units); + set(enabled(), v); + } catch (NumberFormatException ne) { + set(enabled(), 0.0); + } + } } public void set(boolean new_enable, double new_value) { + setting = true; enable.setSelected(new_enable); set_enable(new_enable); if (value != null) { double scale = AltosPyro.pyro_to_scale(flag); + double unit_value = new_value; + AltosUnits units = AltosPyro.pyro_to_units(flag); + if (units != null) + unit_value = units.value(new_value); String format = "%6.0f"; if (scale >= 10) format = "%6.1f"; else if (scale >= 100) format = "%6.2f"; - value.setText(String.format(format, new_value)); + value.setText(String.format(format, unit_value)); } if (combo != null) if (new_value >= AltosLib.ao_flight_boost && new_value <= AltosLib.ao_flight_landed) combo.setSelectedIndex((int) new_value - AltosLib.ao_flight_boost); + setting = false; } public boolean enabled() { @@ -99,8 +123,12 @@ public class AltosConfigPyroUI } public double value() { - if (value != null) + if (value != null) { + AltosUnits units = AltosPyro.pyro_to_units(flag); + if (units != null) + return units.parse(value.getText()); return Double.parseDouble(value.getText()); + } if (combo != null) return combo.getSelectedIndex() + AltosLib.ao_flight_boost; return 0; @@ -143,7 +171,7 @@ public class AltosConfigPyroUI } } - class PyroColumn { + class PyroColumn implements AltosUnitsListener { public PyroItem[] items; public JLabel label; int channel; @@ -166,17 +194,25 @@ public class AltosConfigPyroUI for (int flag = 1; flag < AltosPyro.pyro_all; flag <<= 1) { if ((AltosPyro.pyro_all & flag) != 0) { if (items[row].enabled()) { - System.out.printf ("Flag %x enabled\n", flag); p.flags |= flag; p.set_value(flag, items[row].value()); } row++; } } - System.out.printf ("Pyro %x %s\n", p.flags, p.toString()); return p; } + public void units_changed(boolean imperial_units) { + int row = 0; + for (int flag = 1; flag < AltosPyro.pyro_all; flag <<= 1) { + if ((AltosPyro.pyro_all & flag) != 0) { + items[row].units_changed(imperial_units); + row++; + } + } + } + public PyroColumn(AltosConfigPyroUI ui, int x, int y, int in_channel) { channel = in_channel; @@ -209,6 +245,7 @@ public class AltosConfigPyroUI } PyroColumn[] columns; + JLabel[] labels; public void set_pyros(AltosPyro[] pyros) { for (int i = 0; i < pyros.length; i++) { @@ -244,6 +281,34 @@ public class AltosConfigPyroUI owner.set_dirty(); } + public void units_changed(boolean imperial_units) { + for (int c = 0; c < columns.length; c++) + columns[c].units_changed(imperial_units); + int r = 0; + for (int flag = 1; flag <= AltosPyro.pyro_all; flag <<= 1) { + String n = AltosPyro.pyro_to_name(flag); + if (n != null) { + labels[r].setText(n); + r++; + } + } + } + + /* A window listener to catch closing events and tell the config code */ + class ConfigListener extends WindowAdapter { + AltosConfigPyroUI ui; + AltosConfigUI owner; + + public ConfigListener(AltosConfigPyroUI this_ui, AltosConfigUI this_owner) { + ui = this_ui; + owner = this_owner; + } + + public void windowClosing(WindowEvent e) { + ui.setVisible(false); + } + } + public AltosConfigPyroUI(AltosConfigUI in_owner, AltosPyro[] pyros) { super(in_owner, "Configure Pyro Channels", false); @@ -255,6 +320,13 @@ public class AltosConfigPyroUI pane = getContentPane(); pane.setLayout(new GridBagLayout()); + int nrow = 0; + for (int flag = 1; flag < AltosPyro.pyro_all; flag <<= 1) + if ((flag & AltosPyro.pyro_all) != 0) + nrow++; + + labels = new JLabel[nrow]; + int row = 1; for (int flag = 1; flag <= AltosPyro.pyro_all; flag <<= 1) { @@ -270,6 +342,7 @@ public class AltosConfigPyroUI c.insets = il; JLabel label = new JLabel(n); pane.add(label, c); + labels[row-1] = label; row++; } } @@ -280,6 +353,13 @@ public class AltosConfigPyroUI columns[i] = new PyroColumn(this, i*2 + 1, 0, i); columns[i].set(pyros[i]); } + addWindowListener(new ConfigListener(this, owner)); + AltosPreferences.register_units_listener(this); + } + + public void dispose() { + AltosPreferences.unregister_units_listener(this); + super.dispose(); } public void make_visible() { diff --git a/altosui/AltosConfigUI.java b/altosui/AltosConfigUI.java index a6d27977..e07984b9 100644 --- a/altosui/AltosConfigUI.java +++ b/altosui/AltosConfigUI.java @@ -185,7 +185,7 @@ public class AltosConfigUI void set_pad_orientation_tool_tip() { if (pad_orientation_value.isEnabled()) - pad_orientation_value.setToolTipText("How will TeleMetrum be mounted in the airframe"); + pad_orientation_value.setToolTipText("How will the computer be mounted in the airframe"); else { if (is_telemetrum()) pad_orientation_value.setToolTipText("Older TeleMetrum firmware must fly antenna forward"); @@ -198,7 +198,7 @@ public class AltosConfigUI /* Build the UI using a grid bag */ public AltosConfigUI(JFrame in_owner, boolean remote) { - super (in_owner, "Configure TeleMetrum", false); + super (in_owner, "Configure Flight Computer", false); owner = in_owner; GridBagConstraints c; @@ -661,7 +661,10 @@ public class AltosConfigUI AltosConfigPyroUI pyro_ui; public void dispose() { + if (pyro_ui != null) + pyro_ui.dispose(); AltosPreferences.unregister_units_listener(this); + super.dispose(); } /* Listen for events from our buttons */ @@ -669,10 +672,10 @@ public class AltosConfigUI String cmd = e.getActionCommand(); if (cmd.equals("Pyro")) { - if (pyro_ui == null && pyros != null) { + if (pyro_ui == null && pyros != null) pyro_ui = new AltosConfigPyroUI(this, pyros); + if (pyro_ui != null) pyro_ui.make_visible(); - } return; } @@ -757,9 +760,11 @@ public class AltosConfigUI } public void units_changed(boolean imperial_units) { + String v = main_deploy_value.getSelectedItem().toString(); main_deploy_label.setText(get_main_deploy_label()); set_main_deploy_values(); - listener.actionPerformed(new ActionEvent(this, 0, "Reset")); + int m = (int) (AltosConvert.height.parse(v, !imperial_units) + 0.5); + set_main_deploy(m); } public void set_apogee_delay(int new_apogee_delay) { diff --git a/altosui/AltosGraph.java b/altosui/AltosGraph.java index e6cd7bd8..c505d2d8 100644 --- a/altosui/AltosGraph.java +++ b/altosui/AltosGraph.java @@ -37,76 +37,92 @@ import org.jfree.data.*; class AltosVoltage extends AltosUnits { - public double value(double v) { + public double value(double v, boolean imperial_units) { return v; } - public String show_units() { + public double inverse(double v, boolean imperial_units) { + return v; + } + + public String show_units(boolean imperial_units) { return "V"; } - public String say_units() { + public String say_units(boolean imperial_units) { return "volts"; } - public int show_fraction(int width) { + public int show_fraction(int width, boolean imperial_units) { return width / 2; } } class AltosNsat extends AltosUnits { - public double value(double v) { + public double value(double v, boolean imperial_units) { + return v; + } + + public double inverse(double v, boolean imperial_units) { return v; } - public String show_units() { + public String show_units(boolean imperial_units) { return "Sats"; } - public String say_units() { + public String say_units(boolean imperial_units) { return "Satellites"; } - public int show_fraction(int width) { + public int show_fraction(int width, boolean imperial_units) { return 0; } } class AltosPressure extends AltosUnits { - public double value(double p) { + public double value(double p, boolean imperial_units) { return p; } - public String show_units() { + public double inverse(double p, boolean imperial_units) { + return p; + } + + public String show_units(boolean imperial_units) { return "Pa"; } - public String say_units() { + public String say_units(boolean imperial_units) { return "pascals"; } - public int show_fraction(int width) { + public int show_fraction(int width, boolean imperial_units) { return 0; } } class AltosDbm extends AltosUnits { - public double value(double d) { + public double value(double d, boolean imperial_units) { + return d; + } + + public double inverse(double d, boolean imperial_units) { return d; } - public String show_units() { + public String show_units(boolean imperial_units) { return "dBm"; } - public String say_units() { + public String say_units(boolean imperial_units) { return "D B M"; } - public int show_fraction(int width) { + public int show_fraction(int width, boolean imperial_units) { return 0; } } -- cgit v1.2.3