From 69e6df07976a56b49e07c242cd6e5b2cbd2a578d Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 23 Feb 2012 17:00:48 +1300 Subject: Move altoslib sources to top dir No sense having them live deep in the file system. Signed-off-by: Keith Packard --- altoslib/AltosLib.java | 348 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 348 insertions(+) create mode 100644 altoslib/AltosLib.java (limited to 'altoslib/AltosLib.java') diff --git a/altoslib/AltosLib.java b/altoslib/AltosLib.java new file mode 100644 index 00000000..2921d040 --- /dev/null +++ b/altoslib/AltosLib.java @@ -0,0 +1,348 @@ +/* + * 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; + +import java.awt.*; +import java.util.*; +import java.text.*; +import java.nio.charset.Charset; + +public class AltosLib { + /* EEProm command letters */ + public static final int AO_LOG_FLIGHT = 'F'; + public static final int AO_LOG_SENSOR = 'A'; + 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_TIME = 'G'; + public static final int AO_LOG_GPS_LAT = 'N'; + public static final int AO_LOG_GPS_LON = 'W'; + public static final int AO_LOG_GPS_ALT = 'H'; + public static final int AO_LOG_GPS_SAT = 'V'; + public static final int AO_LOG_GPS_DATE = 'Y'; + public static final int AO_LOG_PRESSURE = 'P'; + + /* Added for header fields in eeprom files */ + public static final int AO_LOG_CONFIG_VERSION = 1000; + public static final int AO_LOG_MAIN_DEPLOY = 1001; + public static final int AO_LOG_APOGEE_DELAY = 1002; + public static final int AO_LOG_RADIO_CHANNEL = 1003; + public static final int AO_LOG_CALLSIGN = 1004; + public static final int AO_LOG_ACCEL_CAL = 1005; + public static final int AO_LOG_RADIO_CAL = 1006; + public static final int AO_LOG_MAX_FLIGHT_LOG = 1007; + public static final int AO_LOG_MANUFACTURER = 2000; + public static final int AO_LOG_PRODUCT = 2001; + public static final int AO_LOG_SERIAL_NUMBER = 2002; + public static final int AO_LOG_LOG_FORMAT = 2003; + public static final int AO_LOG_SOFTWARE_VERSION = 9999; + + /* Added to flag invalid records */ + public static final int AO_LOG_INVALID = -1; + + /* Flight state numbers and names */ + public static final int ao_flight_startup = 0; + public static final int ao_flight_idle = 1; + public static final int ao_flight_pad = 2; + public static final int ao_flight_boost = 3; + public static final int ao_flight_fast = 4; + public static final int ao_flight_coast = 5; + public static final int ao_flight_drogue = 6; + public static final int ao_flight_main = 7; + public static final int ao_flight_landed = 8; + public static final int ao_flight_invalid = 9; + + /* Telemetry modes */ + public static final int ao_telemetry_off = 0; + public static final int ao_telemetry_min = 1; + public static final int ao_telemetry_standard = 1; + public static final int ao_telemetry_0_9 = 2; + public static final int ao_telemetry_0_8 = 3; + public static final int ao_telemetry_max = 3; + + public static final String[] ao_telemetry_name = { + "Off", "Standard Telemetry", "TeleMetrum v0.9", "TeleMetrum v0.8" + }; + + public static final String launch_sites_url = "http://www.altusmetrum.org/AltOS/launch-sites.txt"; + + public static final int ao_telemetry_standard_len = 32; + public static final int ao_telemetry_0_9_len = 95; + public static final int ao_telemetry_0_8_len = 94; + + public static final int[] ao_telemetry_len = { + 0, 32, 95, 94 + }; + + public static HashMap string_to_state = new HashMap(); + + public static boolean map_initialized = false; + + public static void initialize_map() + { + string_to_state.put("startup", ao_flight_startup); + string_to_state.put("idle", ao_flight_idle); + string_to_state.put("pad", ao_flight_pad); + string_to_state.put("boost", ao_flight_boost); + string_to_state.put("fast", ao_flight_fast); + string_to_state.put("coast", ao_flight_coast); + string_to_state.put("drogue", ao_flight_drogue); + string_to_state.put("apogee", ao_flight_coast); + string_to_state.put("main", ao_flight_main); + string_to_state.put("landed", ao_flight_landed); + string_to_state.put("invalid", ao_flight_invalid); + map_initialized = true; + } + + public static int telemetry_len(int telemetry) { + if (telemetry <= ao_telemetry_max) + return ao_telemetry_len[telemetry]; + throw new IllegalArgumentException(String.format("Invalid telemetry %d", + telemetry)); + } + + public static String telemetry_name(int telemetry) { + if (telemetry <= ao_telemetry_max) + return ao_telemetry_name[telemetry]; + throw new IllegalArgumentException(String.format("Invalid telemetry %d", + telemetry)); + } + + public static String[] state_to_string = { + "startup", + "idle", + "pad", + "boost", + "fast", + "coast", + "drogue", + "main", + "landed", + "invalid", + }; + + public static String[] state_to_string_capital = { + "Startup", + "Idle", + "Pad", + "Boost", + "Fast", + "Coast", + "Drogue", + "Main", + "Landed", + "Invalid", + }; + + public static int state(String state) { + if (!map_initialized) + initialize_map(); + if (string_to_state.containsKey(state)) + return string_to_state.get(state); + return ao_flight_invalid; + } + + public static String state_name(int state) { + if (state < 0 || state_to_string.length <= state) + return "invalid"; + return state_to_string[state]; + } + + public static final int AO_GPS_VALID = (1 << 4); + public static final int AO_GPS_RUNNING = (1 << 5); + public static final int AO_GPS_DATE_VALID = (1 << 6); + public static final int AO_GPS_NUM_SAT_SHIFT = 0; + public static final int AO_GPS_NUM_SAT_MASK = 0xf; + + public static final int AO_LOG_FORMAT_UNKNOWN = 0; + public static final int AO_LOG_FORMAT_FULL = 1; + public static final int AO_LOG_FORMAT_TINY = 2; + 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_NONE = 127; + + public static boolean isspace(int c) { + switch (c) { + case ' ': + case '\t': + return true; + } + return false; + } + + public static boolean ishex(int c) { + if ('0' <= c && c <= '9') + return true; + if ('a' <= c && c <= 'f') + return true; + if ('A' <= c && c <= 'F') + return true; + return false; + } + + public static boolean ishex(String s) { + for (int i = 0; i < s.length(); i++) + if (!ishex(s.charAt(i))) + return false; + return true; + } + + public static int fromhex(int c) { + if ('0' <= c && c <= '9') + return c - '0'; + if ('a' <= c && c <= 'f') + return c - 'a' + 10; + if ('A' <= c && c <= 'F') + return c - 'A' + 10; + return -1; + } + + public static int fromhex(String s) throws NumberFormatException { + int c, v = 0; + for (int i = 0; i < s.length(); i++) { + c = s.charAt(i); + if (!ishex(c)) { + if (i == 0) + throw new NumberFormatException(String.format("invalid hex \"%s\"", s)); + return v; + } + v = v * 16 + fromhex(c); + } + return v; + } + + public static boolean isdec(int c) { + if ('0' <= c && c <= '9') + return true; + return false; + } + + public static boolean isdec(String s) { + for (int i = 0; i < s.length(); i++) + if (!isdec(s.charAt(i))) + return false; + return true; + } + + public static int fromdec(int c) { + if ('0' <= c && c <= '9') + return c - '0'; + return -1; + } + + public static int int8(int[] bytes, int i) { + return (int) (byte) bytes[i]; + } + + public static int uint8(int[] bytes, int i) { + return bytes[i]; + } + + public static int int16(int[] bytes, int i) { + return (int) (short) (bytes[i] + (bytes[i+1] << 8)); + } + + public static int uint16(int[] bytes, int i) { + return bytes[i] + (bytes[i+1] << 8); + } + + public static int uint32(int[] bytes, int i) { + return bytes[i] + + (bytes[i+1] << 8) + + (bytes[i+2] << 16) + + (bytes[i+3] << 24); + } + + public static final Charset unicode_set = Charset.forName("UTF-8"); + + public static String string(int[] bytes, int s, int l) { + if (s + l > bytes.length) { + if (s > bytes.length) { + s = bytes.length; + l = 0; + } else { + l = bytes.length - s; + } + } + + int i; + for (i = l - 1; i >= 0; i--) + if (bytes[s+i] != 0) + break; + + l = i + 1; + byte[] b = new byte[l]; + + for (i = 0; i < l; i++) + b[i] = (byte) bytes[s+i]; + String n = new String(b, unicode_set); + return n; + } + + public static int hexbyte(String s, int i) { + int c0, c1; + + if (s.length() < i + 2) + throw new NumberFormatException(String.format("invalid hex \"%s\"", s)); + c0 = s.charAt(i); + if (!ishex(c0)) + throw new NumberFormatException(String.format("invalid hex \"%c\"", c0)); + c1 = s.charAt(i+1); + if (!ishex(c1)) + throw new NumberFormatException(String.format("invalid hex \"%c\"", c1)); + return fromhex(c0) * 16 + fromhex(c1); + } + + public static int[] hexbytes(String s) { + int n; + int[] r; + int i; + + if ((s.length() & 1) != 0) + throw new NumberFormatException(String.format("invalid line \"%s\"", s)); + n = s.length() / 2; + r = new int[n]; + for (i = 0; i < n; i++) + r[i] = hexbyte(s, i * 2); + return r; + } + + public static int fromdec(String s) throws NumberFormatException { + int c, v = 0; + int sign = 1; + for (int i = 0; i < s.length(); i++) { + c = s.charAt(i); + if (i == 0 && c == '-') { + sign = -1; + } else if (!isdec(c)) { + if (i == 0) + throw new NumberFormatException(String.format("invalid number \"%s\"", s)); + return v; + } else + v = v * 10 + fromdec(c); + } + return v * sign; + } + + public static String replace_extension(String input, String extension) { + int dot = input.lastIndexOf("."); + if (dot > 0) + input = input.substring(0,dot); + return input.concat(extension); + } +} -- cgit v1.2.3 From f86dac643081987c8994ab57a96640d5e91b342a Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 2 Jun 2012 19:59:40 -0700 Subject: altoslib: Clean up random rebase failures Signed-off-by: Keith Packard --- altoslib/AltosConfigData.java | 2 +- altoslib/AltosEepromIterable.java | 16 ++++---- altoslib/AltosIMU.java | 2 +- altoslib/AltosLib.java | 11 ++++++ altoslib/AltosMag.java | 2 +- altoslib/AltosMs5607.java | 2 +- altoslib/AltosRecord.java | 1 - altoslib/AltosState.java | 2 + altoslib/AltosTelemetryReader.java | 8 ++-- altoslib/AltosTelemetryRecord.java | 15 +++---- altoslib/AltosTelemetryRecordLegacy.java | 4 +- altosui/Altos.java | 67 -------------------------------- altosui/AltosSerial.java | 3 -- altosui/Makefile.am | 3 -- 14 files changed, 39 insertions(+), 99 deletions(-) (limited to 'altoslib/AltosLib.java') diff --git a/altoslib/AltosConfigData.java b/altoslib/AltosConfigData.java index 4ad4e58a..fa6a72b5 100644 --- a/altoslib/AltosConfigData.java +++ b/altoslib/AltosConfigData.java @@ -104,7 +104,7 @@ public class AltosConfigData implements Iterable { for (int i = 0; i < parts.length; i++) { try { - r[i] = Altos.fromdec(parts[i]); + r[i] = AltosLib.fromdec(parts[i]); } catch (NumberFormatException n) { r[i] = 0; } diff --git a/altoslib/AltosEepromIterable.java b/altoslib/AltosEepromIterable.java index f1397c7b..a923d63b 100644 --- a/altoslib/AltosEepromIterable.java +++ b/altoslib/AltosEepromIterable.java @@ -318,28 +318,28 @@ public class AltosEepromIterable extends AltosRecordIterable { case AltosLib.AO_LOG_SOFTWARE_VERSION: out.printf ("# Software version: %s\n", record.data); break; - case Altos.AO_LOG_BARO_RESERVED: + case AltosLib.AO_LOG_BARO_RESERVED: out.printf ("# Baro reserved: %d\n", record.a); break; - case Altos.AO_LOG_BARO_SENS: + case AltosLib.AO_LOG_BARO_SENS: out.printf ("# Baro sens: %d\n", record.a); break; - case Altos.AO_LOG_BARO_OFF: + case AltosLib.AO_LOG_BARO_OFF: out.printf ("# Baro off: %d\n", record.a); break; - case Altos.AO_LOG_BARO_TCS: + case AltosLib.AO_LOG_BARO_TCS: out.printf ("# Baro tcs: %d\n", record.a); break; - case Altos.AO_LOG_BARO_TCO: + case AltosLib.AO_LOG_BARO_TCO: out.printf ("# Baro tco: %d\n", record.a); break; - case Altos.AO_LOG_BARO_TREF: + case AltosLib.AO_LOG_BARO_TREF: out.printf ("# Baro tref: %d\n", record.a); break; - case Altos.AO_LOG_BARO_TEMPSENS: + case AltosLib.AO_LOG_BARO_TEMPSENS: out.printf ("# Baro tempsens: %d\n", record.a); break; - case Altos.AO_LOG_BARO_CRC: + case AltosLib.AO_LOG_BARO_CRC: out.printf ("# Baro crc: %d\n", record.a); break; } diff --git a/altoslib/AltosIMU.java b/altoslib/AltosIMU.java index 88e36544..c0eaf139 100644 --- a/altoslib/AltosIMU.java +++ b/altoslib/AltosIMU.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package altoslib; +package org.altusmetrum.AltosLib; public class AltosIMU { public int accel_x; diff --git a/altoslib/AltosLib.java b/altoslib/AltosLib.java index 2921d040..27d72079 100644 --- a/altoslib/AltosLib.java +++ b/altoslib/AltosLib.java @@ -50,6 +50,17 @@ public class AltosLib { public static final int AO_LOG_PRODUCT = 2001; public static final int AO_LOG_SERIAL_NUMBER = 2002; public static final int AO_LOG_LOG_FORMAT = 2003; + + /* Added for header fields in megametrum files */ + public static final int AO_LOG_BARO_RESERVED = 3000; + public static final int AO_LOG_BARO_SENS = 3001; + public static final int AO_LOG_BARO_OFF = 3002; + public static final int AO_LOG_BARO_TCS = 3004; + public static final int AO_LOG_BARO_TCO = 3005; + public static final int AO_LOG_BARO_TREF = 3006; + public static final int AO_LOG_BARO_TEMPSENS = 3007; + public static final int AO_LOG_BARO_CRC = 3008; + public static final int AO_LOG_SOFTWARE_VERSION = 9999; /* Added to flag invalid records */ diff --git a/altoslib/AltosMag.java b/altoslib/AltosMag.java index 45f1924c..0f8399ab 100644 --- a/altoslib/AltosMag.java +++ b/altoslib/AltosMag.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package altoslib; +package org.altusmetrum.AltosLib; public class AltosMag { public int x; diff --git a/altoslib/AltosMs5607.java b/altoslib/AltosMs5607.java index 253e2f9b..a7b902e2 100644 --- a/altoslib/AltosMs5607.java +++ b/altoslib/AltosMs5607.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package altoslib; +package org.altusmetrum.AltosLib; public class AltosMs5607 { public int reserved; diff --git a/altoslib/AltosRecord.java b/altoslib/AltosRecord.java index e4915af0..10ef3061 100644 --- a/altoslib/AltosRecord.java +++ b/altoslib/AltosRecord.java @@ -82,7 +82,6 @@ public class AltosRecord implements Comparable { public AltosRecordCompanion companion; ->>>>>>> 5a249bc... altosui: Complete split out of separate java library /* * Values for our MP3H6115A pressure sensor * diff --git a/altoslib/AltosState.java b/altoslib/AltosState.java index 0645e448..68c7611f 100644 --- a/altoslib/AltosState.java +++ b/altoslib/AltosState.java @@ -70,6 +70,8 @@ public class AltosState { public double gps_height; + public double pad_lat, pad_lon, pad_alt; + public int speak_tick; public double speak_altitude; diff --git a/altoslib/AltosTelemetryReader.java b/altoslib/AltosTelemetryReader.java index 67ac1b65..112e008e 100644 --- a/altoslib/AltosTelemetryReader.java +++ b/altoslib/AltosTelemetryReader.java @@ -59,19 +59,19 @@ public class AltosTelemetryReader extends AltosFlightReader { try { /* Version 1.0 or later firmware supports all telemetry formats */ - if (serial.config_data().compare_version("1.0") >= 0) + if (link.config_data().compare_version("1.0") >= 0) return true; /* Version 0.9 firmware only supports 0.9 telemetry */ - if (serial.config_data().compare_version("0.9") >= 0) { - if (telemetry == Altos.ao_telemetry_0_9) + if (link.config_data().compare_version("0.9") >= 0) { + if (telemetry == AltosLib.ao_telemetry_0_9) return true; else return false; } /* Version 0.8 firmware only supports 0.8 telemetry */ - if (telemetry == Altos.ao_telemetry_0_8) + if (telemetry == AltosLib.ao_telemetry_0_8) return true; else return false; diff --git a/altoslib/AltosTelemetryRecord.java b/altoslib/AltosTelemetryRecord.java index 367c148d..4292dae8 100644 --- a/altoslib/AltosTelemetryRecord.java +++ b/altoslib/AltosTelemetryRecord.java @@ -16,6 +16,7 @@ */ package org.altusmetrum.AltosLib; +import java.text.*; public abstract class AltosTelemetryRecord { @@ -47,7 +48,7 @@ public abstract class AltosTelemetryRecord { int[] bytes; try { - bytes = Altos.hexbytes(hex); + bytes = AltosLib.hexbytes(hex); } catch (NumberFormatException ne) { throw new ParseException(ne.getMessage(), 0); } @@ -60,16 +61,16 @@ public abstract class AltosTelemetryRecord { if (!cksum(bytes)) throw new ParseException(String.format("invalid line \"%s\"", hex), 0); - int rssi = Altos.int8(bytes, bytes.length - 3) / 2 - 74; - int status = Altos.uint8(bytes, bytes.length - 2); + int rssi = AltosLib.int8(bytes, bytes.length - 3) / 2 - 74; + int status = AltosLib.uint8(bytes, bytes.length - 2); if ((status & PKT_APPEND_STATUS_1_CRC_OK) == 0) throw new AltosCRCException(rssi); /* length, data ..., rssi, status, checksum -- 4 bytes extra */ switch (bytes.length) { - case Altos.ao_telemetry_standard_len + 4: - int type = Altos.uint8(bytes, 4 + 1); + 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: @@ -93,10 +94,10 @@ public abstract class AltosTelemetryRecord { break; } break; - case Altos.ao_telemetry_0_9_len + 4: + case AltosLib.ao_telemetry_0_9_len + 4: r = new AltosTelemetryRecordLegacy(bytes, rssi, status); break; - case Altos.ao_telemetry_0_8_len + 4: + case AltosLib.ao_telemetry_0_8_len + 4: r = new AltosTelemetryRecordLegacy(bytes, rssi, status); break; default: diff --git a/altoslib/AltosTelemetryRecordLegacy.java b/altoslib/AltosTelemetryRecordLegacy.java index 8e3713cc..85071d9c 100644 --- a/altoslib/AltosTelemetryRecordLegacy.java +++ b/altoslib/AltosTelemetryRecordLegacy.java @@ -241,7 +241,7 @@ public class AltosTelemetryRecordLegacy extends AltosTelemetryRecord { 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.state = Altos.state(map.get_string(AO_TELEM_STATE, "invalid")); + record.state = AltosLib.state(map.get_string(AO_TELEM_STATE, "invalid")); record.tick = map.get_int(AO_TELEM_TICK, 0); /* raw sensor values */ @@ -300,7 +300,7 @@ public class AltosTelemetryRecordLegacy extends AltosTelemetryRecord { record.status = AltosParse.parse_hex(words[i++]); AltosParse.word(words[i++], "STATE"); - record.state = Altos.state(words[i++]); + record.state = AltosLib.state(words[i++]); record.tick = AltosParse.parse_int(words[i++]); diff --git a/altosui/Altos.java b/altosui/Altos.java index 380796cc..334ddb07 100644 --- a/altosui/Altos.java +++ b/altosui/Altos.java @@ -28,73 +28,6 @@ import org.altusmetrum.AltosLib.*; public class Altos extends AltosLib { - /* Added for header fields in eeprom files */ - static final int AO_LOG_CONFIG_VERSION = 1000; - static final int AO_LOG_MAIN_DEPLOY = 1001; - static final int AO_LOG_APOGEE_DELAY = 1002; - static final int AO_LOG_RADIO_CHANNEL = 1003; - static final int AO_LOG_CALLSIGN = 1004; - static final int AO_LOG_ACCEL_CAL = 1005; - static final int AO_LOG_RADIO_CAL = 1006; - static final int AO_LOG_MAX_FLIGHT_LOG = 1007; - static final int AO_LOG_MANUFACTURER = 2000; - static final int AO_LOG_PRODUCT = 2001; - static final int AO_LOG_SERIAL_NUMBER = 2002; - static final int AO_LOG_LOG_FORMAT = 2003; - - /* Added for header fields in megametrum files */ - static final int AO_LOG_BARO_RESERVED = 3000; - static final int AO_LOG_BARO_SENS = 3001; - static final int AO_LOG_BARO_OFF = 3002; - static final int AO_LOG_BARO_TCS = 3004; - static final int AO_LOG_BARO_TCO = 3005; - static final int AO_LOG_BARO_TREF = 3006; - static final int AO_LOG_BARO_TEMPSENS = 3007; - static final int AO_LOG_BARO_CRC = 3008; - - static final int AO_LOG_SOFTWARE_VERSION = 9999; - - /* Added to flag invalid records */ - static final int AO_LOG_INVALID = -1; - - /* Flight state numbers and names */ - static final int ao_flight_startup = 0; - static final int ao_flight_idle = 1; - static final int ao_flight_pad = 2; - static final int ao_flight_boost = 3; - static final int ao_flight_fast = 4; - static final int ao_flight_coast = 5; - static final int ao_flight_drogue = 6; - static final int ao_flight_main = 7; - static final int ao_flight_landed = 8; - static final int ao_flight_invalid = 9; - - /* Telemetry modes */ - static final int ao_telemetry_off = 0; - static final int ao_telemetry_min = 1; - static final int ao_telemetry_standard = 1; - static final int ao_telemetry_0_9 = 2; - static final int ao_telemetry_0_8 = 3; - static final int ao_telemetry_max = 3; - - static final String[] ao_telemetry_name = { - "Off", "Standard Telemetry", "TeleMetrum v0.9", "TeleMetrum v0.8" - }; - - static final String launch_sites_url = "http://www.altusmetrum.org/AltOS/launch-sites.txt"; - - static final int ao_telemetry_standard_len = 32; - static final int ao_telemetry_0_9_len = 95; - static final int ao_telemetry_0_8_len = 94; - - static final int[] ao_telemetry_len = { - 0, 32, 95, 94 - }; - - static HashMap string_to_state = new HashMap(); - - static boolean map_initialized = false; - static final int tab_elt_pad = 5; static Font label_font; diff --git a/altosui/AltosSerial.java b/altosui/AltosSerial.java index 54cdcba7..3abdb645 100644 --- a/altosui/AltosSerial.java +++ b/altosui/AltosSerial.java @@ -264,7 +264,6 @@ public class AltosSerial extends AltosLink implements Runnable { flush_output(); } -<<<<<<< HEAD private int telemetry_len() { return Altos.telemetry_len(telemetry); } @@ -386,8 +385,6 @@ public class AltosSerial extends AltosLink implements Runnable { remote = false; } -======= ->>>>>>> bc5e669... altosui: Pull most of AltosSerial into AltosLink public void set_frame(Frame in_frame) { frame = in_frame; } diff --git a/altosui/Makefile.am b/altosui/Makefile.am index 0a6ae59e..9fc7b5b3 100644 --- a/altosui/Makefile.am +++ b/altosui/Makefile.am @@ -27,8 +27,6 @@ altosui_JAVA = \ AltosConfigureUI.java \ AltosConfigTD.java \ AltosConfigTDUI.java \ - AltosConvert.java \ - AltosCRCException.java \ AltosCSV.java \ AltosCSVUI.java \ AltosDebug.java \ @@ -42,7 +40,6 @@ altosui_JAVA = \ AltosEepromList.java \ AltosEepromManage.java \ AltosEepromMonitor.java \ - AltosEepromTeleScience.java \ AltosEepromMega.java \ AltosEepromMegaIterable.java \ AltosEepromSelect.java \ -- cgit v1.2.3 From b8c363d9411fd5e79e3f806894dbc12bcc106b88 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 4 Jun 2012 20:56:25 -0700 Subject: altosui: More changes to migrate code to altoslib Signed-off-by: Keith Packard --- altoslib/AltosLib.java | 1 + altosui/Altos.java | 184 --------------------------------------- altosui/AltosEepromDownload.java | 10 +-- 3 files changed, 6 insertions(+), 189 deletions(-) (limited to 'altoslib/AltosLib.java') diff --git a/altoslib/AltosLib.java b/altoslib/AltosLib.java index 27d72079..e74eaf99 100644 --- a/altoslib/AltosLib.java +++ b/altoslib/AltosLib.java @@ -185,6 +185,7 @@ public class AltosLib { public static final int AO_LOG_FORMAT_TINY = 2; 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_MEGAMETRUM = 5; public static final int AO_LOG_FORMAT_NONE = 127; public static boolean isspace(int c) { diff --git a/altosui/Altos.java b/altosui/Altos.java index 351927ee..78e56970 100644 --- a/altosui/Altos.java +++ b/altosui/Altos.java @@ -86,190 +86,6 @@ public class Altos extends AltosLib { return state_to_string[state]; } - static final int AO_GPS_VALID = (1 << 4); - static final int AO_GPS_RUNNING = (1 << 5); - static final int AO_GPS_DATE_VALID = (1 << 6); - static final int AO_GPS_NUM_SAT_SHIFT = 0; - static final int AO_GPS_NUM_SAT_MASK = 0xf; - - static final int AO_LOG_FORMAT_UNKNOWN = 0; - static final int AO_LOG_FORMAT_FULL = 1; - static final int AO_LOG_FORMAT_TINY = 2; - static final int AO_LOG_FORMAT_TELEMETRY = 3; - static final int AO_LOG_FORMAT_TELESCIENCE = 4; - static final int AO_LOG_FORMAT_MEGAMETRUM = 5; - static final int AO_LOG_FORMAT_NONE = 127; - - static boolean isspace(int c) { - switch (c) { - case ' ': - case '\t': - return true; - } - return false; - } - - static boolean ishex(int c) { - if ('0' <= c && c <= '9') - return true; - if ('a' <= c && c <= 'f') - return true; - if ('A' <= c && c <= 'F') - return true; - return false; - } - - static boolean ishex(String s) { - for (int i = 0; i < s.length(); i++) - if (!ishex(s.charAt(i))) - return false; - return true; - } - - static int fromhex(int c) { - if ('0' <= c && c <= '9') - return c - '0'; - if ('a' <= c && c <= 'f') - return c - 'a' + 10; - if ('A' <= c && c <= 'F') - return c - 'A' + 10; - return -1; - } - - static int fromhex(String s) throws NumberFormatException { - int c, v = 0; - for (int i = 0; i < s.length(); i++) { - c = s.charAt(i); - if (!ishex(c)) { - if (i == 0) - throw new NumberFormatException(String.format("invalid hex \"%s\"", s)); - return v; - } - v = v * 16 + fromhex(c); - } - return v; - } - - static boolean isdec(int c) { - if ('0' <= c && c <= '9') - return true; - return false; - } - - static boolean isdec(String s) { - for (int i = 0; i < s.length(); i++) - if (!isdec(s.charAt(i))) - return false; - return true; - } - - static int fromdec(int c) { - if ('0' <= c && c <= '9') - return c - '0'; - return -1; - } - - static int int8(int[] bytes, int i) { - return (int) (byte) bytes[i]; - } - - static int uint8(int[] bytes, int i) { - return bytes[i]; - } - - static int int16(int[] bytes, int i) { - return (int) (short) (bytes[i] + (bytes[i+1] << 8)); - } - - static int uint16(int[] bytes, int i) { - return bytes[i] + (bytes[i+1] << 8); - } - - static int uint32(int[] bytes, int i) { - return bytes[i] + - (bytes[i+1] << 8) + - (bytes[i+2] << 16) + - (bytes[i+3] << 24); - } - - static final Charset unicode_set = Charset.forName("UTF-8"); - - static String string(int[] bytes, int s, int l) { - if (s + l > bytes.length) { - if (s > bytes.length) { - s = bytes.length; - l = 0; - } else { - l = bytes.length - s; - } - } - - int i; - for (i = l - 1; i >= 0; i--) - if (bytes[s+i] != 0) - break; - - l = i + 1; - byte[] b = new byte[l]; - - for (i = 0; i < l; i++) - b[i] = (byte) bytes[s+i]; - String n = new String(b, unicode_set); - return n; - } - - static int hexbyte(String s, int i) { - int c0, c1; - - if (s.length() < i + 2) - throw new NumberFormatException(String.format("invalid hex \"%s\"", s)); - c0 = s.charAt(i); - if (!Altos.ishex(c0)) - throw new NumberFormatException(String.format("invalid hex \"%c\"", c0)); - c1 = s.charAt(i+1); - if (!Altos.ishex(c1)) - throw new NumberFormatException(String.format("invalid hex \"%c\"", c1)); - return Altos.fromhex(c0) * 16 + Altos.fromhex(c1); - } - - static int[] hexbytes(String s) { - int n; - int[] r; - int i; - - if ((s.length() & 1) != 0) - throw new NumberFormatException(String.format("invalid line \"%s\"", s)); - n = s.length() / 2; - r = new int[n]; - for (i = 0; i < n; i++) - r[i] = Altos.hexbyte(s, i * 2); - return r; - } - - static int fromdec(String s) throws NumberFormatException { - int c, v = 0; - int sign = 1; - for (int i = 0; i < s.length(); i++) { - c = s.charAt(i); - if (i == 0 && c == '-') { - sign = -1; - } else if (!isdec(c)) { - if (i == 0) - throw new NumberFormatException(String.format("invalid number \"%s\"", s)); - return v; - } else - v = v * 10 + fromdec(c); - } - return v * sign; - } - - static String replace_extension(String input, String extension) { - int dot = input.lastIndexOf("."); - if (dot > 0) - input = input.substring(0,dot); - return input.concat(extension); - } - static public boolean initialized = false; static public boolean loaded_library = false; diff --git a/altosui/AltosEepromDownload.java b/altosui/AltosEepromDownload.java index 080bfc99..d1e5fdf0 100644 --- a/altosui/AltosEepromDownload.java +++ b/altosui/AltosEepromDownload.java @@ -357,23 +357,23 @@ public class AltosEepromDownload implements Runnable { } switch (log_format) { - case Altos.AO_LOG_FORMAT_FULL: + case AltosLib.AO_LOG_FORMAT_FULL: extension = "eeprom"; CaptureFull(eechunk); break; - case Altos.AO_LOG_FORMAT_TINY: + case AltosLib.AO_LOG_FORMAT_TINY: extension = "eeprom"; CaptureTiny(eechunk); break; - case Altos.AO_LOG_FORMAT_TELEMETRY: + case AltosLib.AO_LOG_FORMAT_TELEMETRY: extension = "telem"; CaptureTelemetry(eechunk); break; - case Altos.AO_LOG_FORMAT_TELESCIENCE: + case AltosLib.AO_LOG_FORMAT_TELESCIENCE: extension = "science"; CaptureTeleScience(eechunk); break; - case Altos.AO_LOG_FORMAT_MEGAMETRUM: + case AltosLib.AO_LOG_FORMAT_MEGAMETRUM: extension = "mega"; CaptureMega(eechunk); } -- cgit v1.2.3 From 55747ce210d7d80d5b4fdaaf9dc7ee0f7bc8b0a3 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 17 Jun 2012 18:58:56 -0700 Subject: altosui: Move product definitions from AltosUI to AltosLib Signed-off-by: Keith Packard --- altoslib/AltosLib.java | 24 ++++++++++++ altosui/Altos.java | 85 ------------------------------------------ altosui/AltosBTDevice.java | 1 + altosui/AltosBTKnown.java | 10 ++++- altosui/AltosConfig.java | 2 +- altosui/AltosConfigureUI.java | 2 +- altosui/AltosDeviceDialog.java | 4 +- altosui/AltosUI.java | 1 + 8 files changed, 39 insertions(+), 90 deletions(-) (limited to 'altoslib/AltosLib.java') diff --git a/altoslib/AltosLib.java b/altoslib/AltosLib.java index e74eaf99..4a779c55 100644 --- a/altoslib/AltosLib.java +++ b/altoslib/AltosLib.java @@ -78,6 +78,30 @@ public class AltosLib { public static final int ao_flight_landed = 8; public static final int ao_flight_invalid = 9; + /* USB product IDs */ + public final static int vendor_altusmetrum = 0xfffe; + + public final static int product_altusmetrum = 0x000a; + public final static int product_telemetrum = 0x000b; + public final static int product_teledongle = 0x000c; + public final static int product_teleterra = 0x000d; + public final static int product_telebt = 0x000e; + public final static int product_telelaunch = 0x000f; + public final static int product_telelco = 0x0010; + public final static int product_telescience = 0x0011; + public final static int product_telepyro =0x0012; + public final static int product_megametrum = 0x0023; + public final static int product_megadongle = 0x0024; + public final static int product_altusmetrum_min = 0x000a; + public final static int product_altusmetrum_max = 0x0024; + + public final static int product_any = 0x10000; + public final static int product_basestation = 0x10000 + 1; + public final static int product_altimeter = 0x10000 + 2; + + /* Bluetooth "identifier" (bluetooth sucks) */ + public final static String bt_product_telebt = "TeleBT"; + /* Telemetry modes */ public static final int ao_telemetry_off = 0; public static final int ao_telemetry_min = 1; diff --git a/altosui/Altos.java b/altosui/Altos.java index 78e56970..e60b3aaa 100644 --- a/altosui/Altos.java +++ b/altosui/Altos.java @@ -108,89 +108,4 @@ public class Altos extends AltosLib { } return loaded_library; } - - static int usb_vendor_altusmetrum() { - load_library(); - return 0xfffe; - } - - static int usb_product_altusmetrum() { - load_library(); - return 0x000a; - } - - static int usb_product_altusmetrum_min() { - load_library(); - return 0x000a; - } - - static int usb_product_altusmetrum_max() { - load_library(); - return 0x0013; - } - - static int usb_product_telemetrum() { - load_library(); - return 0x000b; - } - - static int usb_product_teledongle() { - load_library(); - return 0x000c; - } - - static int usb_product_teleterra() { - load_library(); - return 0x000d; - } - - static int usb_product_telebt() { - load_library(); - return 0x000e; - } - - static int usb_product_telelaunch() { - load_library(); - return 0x000f; - } - - static int usb_product_telelco() { - load_library(); - return 0x0010; - } - - static int usb_product_telescience() { - load_library(); - return 0x0011; - } - - static int usb_product_telepyro() { - load_library(); - return 0x0012; - } - - public final static int vendor_altusmetrum = usb_vendor_altusmetrum(); - public final static int product_altusmetrum = usb_product_altusmetrum(); - public final static int product_telemetrum = usb_product_telemetrum(); - public final static int product_teledongle = usb_product_teledongle(); - public final static int product_teleterra = usb_product_teleterra(); - public final static int product_telebt = usb_product_telebt(); - public final static int product_telelaunch = usb_product_telelaunch(); - public final static int product_tele10 = usb_product_telelco(); - public final static int product_telescience = usb_product_telescience(); - public final static int product_telepyro = usb_product_telepyro(); - public final static int product_altusmetrum_min = usb_product_altusmetrum_min(); - public final static int product_altusmetrum_max = usb_product_altusmetrum_max(); - - public final static int product_any = 0x10000; - public final static int product_basestation = 0x10000 + 1; - - static String bt_product_telebt() { - load_library(); - return "TeleBT"; - } - - public final static String bt_product_telebt = bt_product_telebt(); - - public static AltosBTKnown bt_known = new AltosBTKnown(); } diff --git a/altosui/AltosBTDevice.java b/altosui/AltosBTDevice.java index 55b8f8fc..f6926b10 100644 --- a/altosui/AltosBTDevice.java +++ b/altosui/AltosBTDevice.java @@ -116,6 +116,7 @@ public class AltosBTDevice extends altos_bt_device implements AltosDevice { } public AltosBTDevice(String name, String addr) { + Altos.load_library(); libaltos.altos_bt_fill_in(name, addr,this); } diff --git a/altosui/AltosBTKnown.java b/altosui/AltosBTKnown.java index e30be057..021e4d0b 100644 --- a/altosui/AltosBTKnown.java +++ b/altosui/AltosBTKnown.java @@ -94,4 +94,12 @@ public class AltosBTKnown implements Iterable { bt_pref = AltosUIPreferences.bt_devices(); load(); } -} \ No newline at end of file + + static AltosBTKnown known; + + static public AltosBTKnown bt_known() { + if (known == null) + known = new AltosBTKnown(); + return known; + } +} diff --git a/altosui/AltosConfig.java b/altosui/AltosConfig.java index 35fef080..cae41858 100644 --- a/altosui/AltosConfig.java +++ b/altosui/AltosConfig.java @@ -491,7 +491,7 @@ public class AltosConfig implements ActionListener { try { serial_line = new AltosSerial(device); try { - if (!device.matchProduct(Altos.product_telemetrum)) + if (!device.matchProduct(Altos.product_altimeter)) remote = true; init_ui(); } catch (InterruptedException ie) { diff --git a/altosui/AltosConfigureUI.java b/altosui/AltosConfigureUI.java index deb179d6..d0ed9325 100644 --- a/altosui/AltosConfigureUI.java +++ b/altosui/AltosConfigureUI.java @@ -344,7 +344,7 @@ public class AltosConfigureUI manage_bluetooth = new JButton("Manage Bluetooth"); manage_bluetooth.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { - AltosBTManage.show(owner, Altos.bt_known); + AltosBTManage.show(owner, AltosBTKnown.bt_known()); } }); c.gridx = 0; diff --git a/altosui/AltosDeviceDialog.java b/altosui/AltosDeviceDialog.java index e53e75c1..fa9d0013 100644 --- a/altosui/AltosDeviceDialog.java +++ b/altosui/AltosDeviceDialog.java @@ -41,7 +41,7 @@ public class AltosDeviceDialog extends AltosDialog implements ActionListener { private AltosDevice[] devices() { java.util.List usb_devices = AltosUSBDevice.list(product); int num_devices = usb_devices.size(); - java.util.List bt_devices = Altos.bt_known.list(product); + java.util.List bt_devices = AltosBTKnown.bt_known().list(product); num_devices += bt_devices.size(); AltosDevice[] devices = new AltosDevice[num_devices]; @@ -169,7 +169,7 @@ public class AltosDeviceDialog extends AltosDialog implements ActionListener { if ("select".equals(e.getActionCommand())) value = (AltosDevice)(list.getSelectedValue()); if ("manage".equals(e.getActionCommand())) { - AltosBTManage.show(frame, Altos.bt_known); + AltosBTManage.show(frame, AltosBTKnown.bt_known()); update_devices(); return; } diff --git a/altosui/AltosUI.java b/altosui/AltosUI.java index 538f8734..926d66f0 100644 --- a/altosui/AltosUI.java +++ b/altosui/AltosUI.java @@ -538,6 +538,7 @@ public class AltosUI extends AltosFrame { } public static void main(final String[] args) { + load_library(null); try { UIManager.setLookAndFeel(AltosUIPreferences.look_and_feel()); } catch (Exception e) { -- cgit v1.2.3 From 6f421818fd7062f03bfaf9e606d6a4cfdcb13b49 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 21 Jun 2012 09:50:18 -0700 Subject: altosui: Support MM telemetry packets Required restructuring the whole telemetry system to provide abstract interfaces to flight data. Signed-off-by: Keith Packard --- altoslib/AltosEepromIterable.java | 10 +- altoslib/AltosEepromMegaIterable.java | 32 ++-- altoslib/AltosLib.java | 20 +++ altoslib/AltosMs5607.java | 7 + altoslib/AltosRecord.java | 225 +++++++-------------------- altoslib/AltosRecordMM.java | 186 ++++++++++++++++++++++ altoslib/AltosRecordTM.java | 199 +++++++++++++++++++++++ altoslib/AltosTelemetry.java | 2 +- altoslib/AltosTelemetryIterable.java | 6 +- altoslib/AltosTelemetryRecord.java | 8 +- altoslib/AltosTelemetryRecordLegacy.java | 8 +- altoslib/AltosTelemetryRecordMegaData.java | 96 ++++++++++++ altoslib/AltosTelemetryRecordMegaSensor.java | 98 ++++++++++++ altoslib/AltosTelemetryRecordRaw.java | 6 +- altoslib/AltosTelemetryRecordSensor.java | 10 +- altoslib/Makefile.am | 4 + altosui/AltosCSV.java | 8 +- altosui/AltosIdleMonitorUI.java | 23 +-- 18 files changed, 735 insertions(+), 213 deletions(-) create mode 100644 altoslib/AltosRecordMM.java create mode 100644 altoslib/AltosRecordTM.java create mode 100644 altoslib/AltosTelemetryRecordMegaData.java create mode 100644 altoslib/AltosTelemetryRecordMegaSensor.java (limited to 'altoslib/AltosLib.java') diff --git a/altoslib/AltosEepromIterable.java b/altoslib/AltosEepromIterable.java index a923d63b..f8acdc16 100644 --- a/altoslib/AltosEepromIterable.java +++ b/altoslib/AltosEepromIterable.java @@ -104,7 +104,7 @@ public class AltosEepromIterable extends AltosRecordIterable { } } - void update_state(AltosRecord state, AltosEepromRecord record, EepromState eeprom) { + void update_state(AltosRecordTM state, AltosEepromRecord record, EepromState eeprom) { state.tick = record.tick; switch (record.cmd) { case AltosLib.AO_LOG_FLIGHT: @@ -237,7 +237,7 @@ public class AltosEepromIterable extends AltosRecordIterable { LinkedList list = new LinkedList(); Iterator iterator = records.iterator(); AltosOrderedRecord record = null; - AltosRecord state = new AltosRecord(); + AltosRecordTM state = new AltosRecordTM(); boolean last_reported = false; EepromState eeprom = new EepromState(); @@ -254,13 +254,13 @@ public class AltosEepromIterable extends AltosRecordIterable { while (iterator.hasNext()) { record = iterator.next(); if ((eeprom.seen & seen_basic) == seen_basic && record.tick != state.tick) { - AltosRecord r = new AltosRecord(state); + AltosRecordTM r = state.clone(); r.time = (r.tick - eeprom.boost_tick) / 100.0; list.add(r); } update_state(state, record, eeprom); } - AltosRecord r = new AltosRecord(state); + AltosRecordTM r = state.clone(); r.time = (r.tick - eeprom.boost_tick) / 100.0; list.add(r); return list; @@ -399,7 +399,7 @@ public class AltosEepromIterable extends AltosRecordIterable { try { for (;;) { - String line = AltosRecord.gets(input); + String line = AltosLib.gets(input); if (line == null) break; AltosOrderedRecord record = new AltosOrderedRecord(line, index++, prev_tick, prev_tick_valid); diff --git a/altoslib/AltosEepromMegaIterable.java b/altoslib/AltosEepromMegaIterable.java index 28a298b3..f62cc45b 100644 --- a/altoslib/AltosEepromMegaIterable.java +++ b/altoslib/AltosEepromMegaIterable.java @@ -108,7 +108,7 @@ public class AltosEepromMegaIterable extends AltosRecordIterable { } } - void update_state(AltosRecord state, AltosEepromMega record, EepromState eeprom) { + void update_state(AltosRecordMM state, AltosEepromMega record, EepromState eeprom) { state.tick = record.tick; switch (record.cmd) { case AltosLib.AO_LOG_FLIGHT: @@ -122,7 +122,8 @@ public class AltosEepromMegaIterable extends AltosRecordIterable { break; case AltosLib.AO_LOG_SENSOR: state.accel = record.accel(); - state.pres = baro.set(record.pres(), record.temp()); + baro.set(record.pres(), record.temp()); + state.pres = baro.pa; state.temp = baro.cc; state.imu = new AltosIMU(); state.imu.accel_x = record.accel_x(); @@ -161,15 +162,20 @@ public class AltosEepromMegaIterable extends AltosRecordIterable { eeprom.seen |= seen_sensor; break; case AltosLib.AO_LOG_TEMP_VOLT: - state.batt = record.v_batt(); + state.v_batt = record.v_batt(); + state.v_pyro = record.v_pbatt(); + for (int i = 0; i < AltosRecordMM.num_sense; i++) + state.sense[i] = record.sense(i); eeprom.seen |= seen_temp_volt; break; - case AltosLib.AO_LOG_DEPLOY: - state.drogue = record.a; - state.main = record.b; - eeprom.seen |= seen_deploy; - has_ignite = true; - break; +// +// case AltosLib.AO_LOG_DEPLOY: +// state.drogue = record.a; +// state.main = record.b; +// eeprom.seen |= seen_deploy; +// has_ignite = true; +// break; + case AltosLib.AO_LOG_STATE: state.state = record.state(); break; @@ -278,7 +284,7 @@ public class AltosEepromMegaIterable extends AltosRecordIterable { LinkedList list = new LinkedList(); Iterator iterator = records.iterator(); AltosOrderedMegaRecord record = null; - AltosRecord state = new AltosRecord(); + AltosRecordMM state = new AltosRecordMM(); boolean last_reported = false; EepromState eeprom = new EepromState(); @@ -295,13 +301,13 @@ public class AltosEepromMegaIterable extends AltosRecordIterable { while (iterator.hasNext()) { record = iterator.next(); if ((eeprom.seen & seen_basic) == seen_basic && record.tick != state.tick) { - AltosRecord r = new AltosRecord(state); + AltosRecordMM r = state.clone(); r.time = (r.tick - eeprom.boost_tick) / 100.0; list.add(r); } update_state(state, record, eeprom); } - AltosRecord r = new AltosRecord(state); + AltosRecordMM r = state.clone(); r.time = (r.tick - eeprom.boost_tick) / 100.0; list.add(r); return list; @@ -442,7 +448,7 @@ public class AltosEepromMegaIterable extends AltosRecordIterable { try { for (;;) { - String line = AltosRecord.gets(input); + String line = AltosLib.gets(input); if (line == null) break; AltosOrderedMegaRecord record = new AltosOrderedMegaRecord(line, index++, prev_tick, prev_tick_valid); diff --git a/altoslib/AltosLib.java b/altoslib/AltosLib.java index 4a779c55..2402331e 100644 --- a/altoslib/AltosLib.java +++ b/altoslib/AltosLib.java @@ -20,6 +20,7 @@ package org.altusmetrum.AltosLib; import java.awt.*; import java.util.*; import java.text.*; +import java.io.*; import java.nio.charset.Charset; public class AltosLib { @@ -304,6 +305,10 @@ public class AltosLib { (bytes[i+3] << 24); } + public static int int32(int[] bytes, int i) { + return (int) uint32(bytes, i); + } + public static final Charset unicode_set = Charset.forName("UTF-8"); public static String string(int[] bytes, int s, int l) { @@ -375,6 +380,21 @@ public class AltosLib { return v * sign; } + public static String gets(FileInputStream s) throws IOException { + int c; + String line = ""; + + while ((c = s.read()) != -1) { + if (c == '\r') + continue; + if (c == '\n') { + return line; + } + line = line + (char) c; + } + return null; + } + public static String replace_extension(String input, String extension) { int dot = input.lastIndexOf("."); if (dot > 0) diff --git a/altoslib/AltosMs5607.java b/altoslib/AltosMs5607.java index a7b902e2..5fd997d8 100644 --- a/altoslib/AltosMs5607.java +++ b/altoslib/AltosMs5607.java @@ -73,4 +73,11 @@ public class AltosMs5607 { convert(); return pa; } + + public AltosMs5607() { + raw_pres = AltosRecord.MISSING; + raw_temp = AltosRecord.MISSING; + pa = AltosRecord.MISSING; + cc = AltosRecord.MISSING; + } } diff --git a/altoslib/AltosRecord.java b/altoslib/AltosRecord.java index 10ef3061..e468f84b 100644 --- a/altoslib/AltosRecord.java +++ b/altoslib/AltosRecord.java @@ -22,8 +22,7 @@ import java.text.*; import java.util.HashMap; import java.io.*; -public class AltosRecord implements Comparable { - public final static int MISSING = 0x7fffffff; +public class AltosRecord implements Comparable , Cloneable { public static final int seen_flight = 1; public static final int seen_sensor = 2; @@ -33,8 +32,13 @@ public class AltosRecord implements Comparable { public static final int seen_gps_lat = 32; public static final int seen_gps_lon = 64; public static final int seen_companion = 128; - public int seen; + public int seen; + + public final static int MISSING = 0x7fffffff; + + /* Every AltosRecord implementation provides these fields */ + public int version; public String callsign; public int serial; @@ -44,31 +48,13 @@ public class AltosRecord implements Comparable { public int state; public int tick; - public int accel; - public int pres; - public int temp; - public int batt; - public int drogue; - public int main; - - public int ground_accel; - public int ground_pres; - public int accel_plus_g; - public int accel_minus_g; - - public double acceleration; - public double speed; - public double height; - - public int flight_accel; - public int flight_vel; - public int flight_pres; + /* Current flight dynamic state */ + public double acceleration; /* m/s² */ + public double speed; /* m/s */ + public double height; /* m */ public AltosGPS gps; - public boolean new_gps; - - public AltosIMU imu; - public AltosMag mag; + public boolean new_gps; public double time; /* seconds since boost */ @@ -83,45 +69,42 @@ public class AltosRecord implements Comparable { public AltosRecordCompanion companion; /* - * Values for our MP3H6115A pressure sensor - * - * From the data sheet: + * Abstract methods that convert record data + * to standard units: * - * Pressure range: 15-115 kPa - * Voltage at 115kPa: 2.82 - * Output scale: 27mV/kPa - * - * - * 27 mV/kPa * 2047 / 3300 counts/mV = 16.75 counts/kPa - * 2.82V * 2047 / 3.3 counts/V = 1749 counts/115 kPa + * pressure: Pa + * voltage: V + * acceleration: m/s² + * speed: m/s + * height: m + * temperature: °C */ - public static final double counts_per_kPa = 27 * 2047 / 3300; - public static final double counts_at_101_3kPa = 1674.0; + public double raw_pressure() { return MISSING; } - public static double - barometer_to_pressure(double count) - { - return ((count / 16.0) / 2047.0 + 0.095) / 0.009 * 1000.0; - } + public double filtered_pressure() { return MISSING; } - public double raw_pressure() { - if (pres == MISSING) - return MISSING; - return barometer_to_pressure(pres); - } + public double ground_pressure() { return MISSING; } - public double filtered_pressure() { - if (flight_pres == MISSING) - return MISSING; - return barometer_to_pressure(flight_pres); - } + public double battery_voltage() { return MISSING; } - public double ground_pressure() { - if (ground_pres == MISSING) - return MISSING; - return barometer_to_pressure(ground_pres); - } + public double main_voltage() { return MISSING; } + + public double drogue_voltage() { return MISSING; } + + public double temperature() { return MISSING; } + + public double acceleration() { return MISSING; } + + public double accel_speed() { return MISSING; } + + public AltosIMU imu() { return null; } + + public AltosMag mag() { return null; } + + /* + * Convert various pressure values to altitude + */ public double raw_altitude() { double p = raw_pressure(); @@ -138,8 +121,9 @@ public class AltosRecord implements Comparable { } public double filtered_altitude() { - if (height != MISSING && ground_pres != MISSING) - return height + ground_altitude(); + double ga = ground_altitude(); + if (height != MISSING && ga != MISSING) + return height + ga; double p = filtered_pressure(); if (p == MISSING) @@ -167,94 +151,17 @@ public class AltosRecord implements Comparable { return r - g; } - public double battery_voltage() { - if (batt == MISSING) - return MISSING; - return AltosConvert.cc_battery_to_voltage(batt); - } - - public double main_voltage() { - if (main == MISSING) - return MISSING; - return AltosConvert.cc_ignitor_to_voltage(main); - } - - public double drogue_voltage() { - if (drogue == MISSING) - return MISSING; - return AltosConvert.cc_ignitor_to_voltage(drogue); - } - - /* Value for the CC1111 built-in temperature sensor - * Output voltage at 0°C = 0.755V - * Coefficient = 0.00247V/°C - * Reference voltage = 1.25V - * - * temp = ((value / 32767) * 1.25 - 0.755) / 0.00247 - * = (value - 19791.268) / 32768 * 1.25 / 0.00247 - */ - - public static double - thermometer_to_temperature(double thermo) - { - return (thermo - 19791.268) / 32728.0 * 1.25 / 0.00247; - } - - public double temperature() { - if (temp == MISSING) - return MISSING; - return thermometer_to_temperature(temp); - } - - public double accel_counts_per_mss() { - double counts_per_g = Math.abs(accel_minus_g - accel_plus_g) / 2; - - return counts_per_g / 9.80665; - } - - public double acceleration() { - if (acceleration != MISSING) - return acceleration; - - if (ground_accel == MISSING || accel == MISSING) - return MISSING; - return (ground_accel - accel) / accel_counts_per_mss(); - } - - public double accel_speed() { - if (speed != MISSING) - return speed; - if (flight_vel == MISSING) - return MISSING; - return flight_vel / (accel_counts_per_mss() * 100.0); - } - public String state() { return AltosLib.state_name(state); } - public static String gets(FileInputStream s) throws IOException { - int c; - String line = ""; - - while ((c = s.read()) != -1) { - if (c == '\r') - continue; - if (c == '\n') { - return line; - } - line = line + (char) c; - } - return null; - } - public int compareTo(AltosRecord o) { return tick - o.tick; } - public AltosRecord(AltosRecord old) { - version = old.version; + public void copy(AltosRecord old) { seen = old.seen; + version = old.version; callsign = old.callsign; serial = old.serial; flight = old.flight; @@ -262,32 +169,27 @@ public class AltosRecord implements Comparable { status = old.status; state = old.state; tick = old.tick; - accel = old.accel; - pres = old.pres; - temp = old.temp; - batt = old.batt; - drogue = old.drogue; - main = old.main; - flight_accel = old.flight_accel; - ground_accel = old.ground_accel; - flight_vel = old.flight_vel; - flight_pres = old.flight_pres; - ground_pres = old.ground_pres; - accel_plus_g = old.accel_plus_g; - accel_minus_g = old.accel_minus_g; acceleration = old.acceleration; speed = old.speed; height = old.height; gps = new AltosGPS(old.gps); new_gps = false; companion = old.companion; - imu = old.imu; - mag = old.mag; + } + + public AltosRecord clone() { + try { + AltosRecord n = (AltosRecord) super.clone(); + n.copy(this); + return n; + } catch (CloneNotSupportedException e) { + return null; + } } public AltosRecord() { - version = 0; seen = 0; + version = 0; callsign = "N0CALL"; serial = 0; flight = 0; @@ -295,19 +197,6 @@ public class AltosRecord implements Comparable { status = 0; state = AltosLib.ao_flight_startup; tick = 0; - accel = MISSING; - pres = MISSING; - temp = MISSING; - batt = MISSING; - drogue = MISSING; - main = MISSING; - flight_accel = 0; - ground_accel = 0; - flight_vel = 0; - flight_pres = 0; - ground_pres = 0; - accel_plus_g = 0; - accel_minus_g = 0; acceleration = MISSING; speed = MISSING; height = MISSING; diff --git a/altoslib/AltosRecordMM.java b/altoslib/AltosRecordMM.java new file mode 100644 index 00000000..8b3d745a --- /dev/null +++ b/altoslib/AltosRecordMM.java @@ -0,0 +1,186 @@ +/* + * 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; + +public class AltosRecordMM extends AltosRecord { + + public int accel; + public int pres; + public int temp; + + public int v_batt; + public int v_pyro; + public int sense[]; + + public int ground_accel; + public int ground_pres; + public int accel_plus_g; + public int accel_minus_g; + + public int flight_accel; + public int flight_vel; + public int flight_pres; + + public final static int num_sense = 6; + + public AltosIMU imu; + public AltosMag mag; + + static double adc(int raw) { + return raw / 4095.0; + } + + public double raw_pressure() { + if (pres != MISSING) + return pres / 100.0; + return MISSING; + } + + public double filtered_pressure() { + return raw_pressure(); + } + + public double ground_pressure() { + if (ground_pres != MISSING) + return ground_pres / 100.0; + return MISSING; + } + + public double battery_voltage() { + if (v_batt != MISSING) + return 3.3 * adc(v_batt) * 27.0 / (15.0 + 27.0); + return MISSING; + } + + static double pyro(int raw) { + if (raw != MISSING) + return 3.3 * adc(raw) * 27.0 / (100.0 + 27.0); + return MISSING; + } + + public double main_voltage() { + return pyro(sense[1]); + } + + public double drogue_voltage() { + return pyro(sense[0]); + } + + public double temperature() { + if (temp != MISSING) + return temp / 100.0; + return MISSING; + } + + public AltosIMU imu() { return imu; } + + public AltosMag mag() { return mag; } + + double accel_counts_per_mss() { + double counts_per_g = Math.abs(accel_minus_g - accel_plus_g) / 2; + + return counts_per_g / 9.80665; + } + + public double acceleration() { + System.out.printf("MM record acceleration %g ground_accel %d accel %d accel_minus_g %d accel_plus_g %d\n", + acceleration, ground_accel, accel, accel_minus_g, accel_plus_g); + if (acceleration != MISSING) + return acceleration; + + if (ground_accel == MISSING || accel == MISSING) + return MISSING; + + if (accel_minus_g == MISSING || accel_plus_g == MISSING) + return MISSING; + + return (ground_accel - accel) / accel_counts_per_mss(); + } + + public double accel_speed() { + return speed; + } + + public void copy (AltosRecordMM old) { + super.copy(old); + + accel = old.accel; + pres = old.pres; + temp = old.temp; + + v_batt = old.v_batt; + v_pyro = old.v_pyro; + sense = new int[num_sense]; + + for (int i = 0; i < num_sense; i++) + sense[i] = old.sense[i]; + + ground_accel = old.ground_accel; + ground_pres = old.ground_pres; + accel_plus_g = old.accel_plus_g; + accel_minus_g = old.accel_minus_g; + + flight_accel = old.flight_accel; + flight_vel = old.flight_vel; + flight_pres = old.flight_pres; + + imu = old.imu; + mag = old.mag; + } + + public AltosRecordMM clone() { + AltosRecordMM n = (AltosRecordMM) super.clone(); + n.copy(this); + return n; + } + + void make_missing() { + + accel = MISSING; + pres = MISSING; + temp = MISSING; + + v_batt = MISSING; + v_pyro = MISSING; + sense = new int[num_sense]; + for (int i = 0; i < num_sense; i++) + sense[i] = MISSING; + + ground_accel = MISSING; + ground_pres = MISSING; + accel_plus_g = MISSING; + accel_minus_g = MISSING; + + flight_accel = 0; + flight_vel = 0; + flight_pres = 0; + + imu = new AltosIMU(); + mag = new AltosMag(); + } + + public AltosRecordMM(AltosRecord old) { + super.copy(old); + make_missing(); + } + + public AltosRecordMM() { + super(); + make_missing(); + } +} diff --git a/altoslib/AltosRecordTM.java b/altoslib/AltosRecordTM.java new file mode 100644 index 00000000..afb70790 --- /dev/null +++ b/altoslib/AltosRecordTM.java @@ -0,0 +1,199 @@ +/* + * 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; + +public class AltosRecordTM extends AltosRecord { + public int accel; + public int pres; + public int temp; + public int batt; + public int drogue; + public int main; + + public int ground_accel; + public int ground_pres; + public int accel_plus_g; + public int accel_minus_g; + + public int flight_accel; + public int flight_vel; + public int flight_pres; + + /* + * Values for our MP3H6115A pressure sensor + * + * From the data sheet: + * + * Pressure range: 15-115 kPa + * Voltage at 115kPa: 2.82 + * Output scale: 27mV/kPa + * + * + * 27 mV/kPa * 2047 / 3300 counts/mV = 16.75 counts/kPa + * 2.82V * 2047 / 3.3 counts/V = 1749 counts/115 kPa + */ + + static final double counts_per_kPa = 27 * 2047 / 3300; + static final double counts_at_101_3kPa = 1674.0; + + static double + barometer_to_pressure(double count) + { + return ((count / 16.0) / 2047.0 + 0.095) / 0.009 * 1000.0; + } + + public double raw_pressure() { + if (pres == MISSING) + return MISSING; + return barometer_to_pressure(pres); + } + + public double filtered_pressure() { + if (flight_pres == MISSING) + return MISSING; + return barometer_to_pressure(flight_pres); + } + + public double ground_pressure() { + if (ground_pres == MISSING) + return MISSING; + return barometer_to_pressure(ground_pres); + } + + public double battery_voltage() { + if (batt == MISSING) + return MISSING; + return AltosConvert.cc_battery_to_voltage(batt); + } + + public double main_voltage() { + if (main == MISSING) + return MISSING; + return AltosConvert.cc_ignitor_to_voltage(main); + } + + public double drogue_voltage() { + if (drogue == MISSING) + return MISSING; + return AltosConvert.cc_ignitor_to_voltage(drogue); + } + + /* Value for the CC1111 built-in temperature sensor + * Output voltage at 0°C = 0.755V + * Coefficient = 0.00247V/°C + * Reference voltage = 1.25V + * + * temp = ((value / 32767) * 1.25 - 0.755) / 0.00247 + * = (value - 19791.268) / 32768 * 1.25 / 0.00247 + */ + + static double + thermometer_to_temperature(double thermo) + { + return (thermo - 19791.268) / 32728.0 * 1.25 / 0.00247; + } + + public double temperature() { + if (temp == MISSING) + return MISSING; + return thermometer_to_temperature(temp); + } + + double accel_counts_per_mss() { + double counts_per_g = Math.abs(accel_minus_g - accel_plus_g) / 2; + + return counts_per_g / 9.80665; + } + + public double acceleration() { + if (acceleration != MISSING) + return acceleration; + + if (ground_accel == MISSING || accel == MISSING) + return MISSING; + return (ground_accel - accel) / accel_counts_per_mss(); + } + + public double accel_speed() { + if (speed != MISSING) + return speed; + if (flight_vel == MISSING) + return MISSING; + return flight_vel / (accel_counts_per_mss() * 100.0); + } + + public void copy(AltosRecordTM old) { + super.copy(old); + + version = old.version; + callsign = old.callsign; + serial = old.serial; + flight = old.flight; + rssi = old.rssi; + status = old.status; + state = old.state; + tick = old.tick; + accel = old.accel; + pres = old.pres; + temp = old.temp; + batt = old.batt; + drogue = old.drogue; + main = old.main; + flight_accel = old.flight_accel; + ground_accel = old.ground_accel; + flight_vel = old.flight_vel; + flight_pres = old.flight_pres; + ground_pres = old.ground_pres; + accel_plus_g = old.accel_plus_g; + accel_minus_g = old.accel_minus_g; + } + + public AltosRecordTM clone() { + AltosRecordTM n = (AltosRecordTM) super.clone(); + n.copy(this); + return n; + } + + void make_missing() { + accel = MISSING; + pres = MISSING; + temp = MISSING; + batt = MISSING; + drogue = MISSING; + main = MISSING; + + flight_accel = 0; + flight_vel = 0; + flight_pres = 0; + + ground_accel = 0; + ground_pres = 0; + accel_plus_g = 0; + accel_minus_g = 0; + } + + public AltosRecordTM(AltosRecord old) { + super.copy(old); + make_missing(); + } + + public AltosRecordTM() { + super(); + make_missing(); + } +} diff --git a/altoslib/AltosTelemetry.java b/altoslib/AltosTelemetry.java index 04abb1f3..ee244824 100644 --- a/altoslib/AltosTelemetry.java +++ b/altoslib/AltosTelemetry.java @@ -84,7 +84,7 @@ import java.util.HashMap; * */ -public class AltosTelemetry extends AltosRecord { +public abstract class AltosTelemetry extends AltosRecord { /* * General header fields diff --git a/altoslib/AltosTelemetryIterable.java b/altoslib/AltosTelemetryIterable.java index f4b4029f..e95c15e0 100644 --- a/altoslib/AltosTelemetryIterable.java +++ b/altoslib/AltosTelemetryIterable.java @@ -45,7 +45,7 @@ public class AltosTelemetryIterable extends AltosRecordIterable { try { for (;;) { - String line = AltosRecord.gets(input); + String line = AltosLib.gets(input); if (line == null) { break; } @@ -67,11 +67,11 @@ public class AltosTelemetryIterable extends AltosRecordIterable { saw_boost = true; boost_tick = record.tick; } - if (record.accel != AltosRecord.MISSING) + if (record.acceleration() != AltosRecord.MISSING) has_accel = true; if (record.gps != null) has_gps = true; - if (record.main != AltosRecord.MISSING) + if (record.main_voltage() != AltosRecord.MISSING) has_ignite = true; if (previous != null && previous.tick != record.tick) records.add(previous); diff --git a/altoslib/AltosTelemetryRecord.java b/altoslib/AltosTelemetryRecord.java index 6b6a252d..6a8cfd35 100644 --- a/altoslib/AltosTelemetryRecord.java +++ b/altoslib/AltosTelemetryRecord.java @@ -43,6 +43,7 @@ public abstract class AltosTelemetryRecord { final static int packet_type_satellite = 0x06; final static int packet_type_companion = 0x07; final static int packet_type_MM_sensor = 0x08; + final static int packet_type_MM_data = 0x09; static AltosTelemetryRecord parse_hex(String hex) throws ParseException, AltosCRCException { AltosTelemetryRecord r; @@ -76,7 +77,6 @@ public abstract class AltosTelemetryRecord { case packet_type_TM_sensor: case packet_type_Tm_sensor: case packet_type_Tn_sensor: - case packet_type_MM_sensor: r = new AltosTelemetryRecordSensor(bytes, rssi); break; case packet_type_configuration: @@ -91,6 +91,12 @@ public abstract class AltosTelemetryRecord { case packet_type_companion: r = new AltosTelemetryRecordCompanion(bytes); break; + case packet_type_MM_sensor: + r = new AltosTelemetryRecordMegaSensor(bytes, rssi); + break; + case packet_type_MM_data: + r = new AltosTelemetryRecordMegaData(bytes); + break; default: r = new AltosTelemetryRecordRaw(bytes); break; diff --git a/altoslib/AltosTelemetryRecordLegacy.java b/altoslib/AltosTelemetryRecordLegacy.java index 85071d9c..3976a07a 100644 --- a/altoslib/AltosTelemetryRecordLegacy.java +++ b/altoslib/AltosTelemetryRecordLegacy.java @@ -232,7 +232,7 @@ public class AltosTelemetryRecordLegacy extends AltosTelemetryRecord { final static String AO_TELEM_SAT_SVID = "s_v"; final static String AO_TELEM_SAT_C_N_0 = "s_c"; - AltosRecord record; + AltosRecordTM record; private void parse_v4(String[] words, int i) throws ParseException { AltosTelemetryMap map = new AltosTelemetryMap(words, i); @@ -366,7 +366,7 @@ public class AltosTelemetryRecordLegacy extends AltosTelemetryRecord { String[] words = line.split("\\s+"); int i = 0; - record = new AltosRecord(); + record = new AltosRecordTM(); if (words[i].equals("CRC") && words[i+1].equals("INVALID")) { i += 2; @@ -388,7 +388,7 @@ public class AltosTelemetryRecordLegacy extends AltosTelemetryRecord { } /* - * Given a hex dump of a legacy telemetry line, construct an AltosRecord from that + * Given a hex dump of a legacy telemetry line, construct an AltosRecordTM from that */ int[] bytes; @@ -422,7 +422,7 @@ public class AltosTelemetryRecordLegacy extends AltosTelemetryRecord { static final int AO_GPS_COURSE_VALID = (1 << 7); public AltosTelemetryRecordLegacy(int[] in_bytes, int in_rssi, int in_status) { - record = new AltosRecord(); + record = new AltosRecordTM(); bytes = in_bytes; record.version = 4; diff --git a/altoslib/AltosTelemetryRecordMegaData.java b/altoslib/AltosTelemetryRecordMegaData.java new file mode 100644 index 00000000..cc35cd83 --- /dev/null +++ b/altoslib/AltosTelemetryRecordMegaData.java @@ -0,0 +1,96 @@ +/* + * 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; + + +public class AltosTelemetryRecordMegaData extends AltosTelemetryRecordRaw { + + int state; + + int v_batt; + int v_pyro; + int sense[]; + + int ground_pres; + int ground_accel; + int accel_plus_g; + int accel_minus_g; + + int acceleration; + int speed; + int height; + + public AltosTelemetryRecordMegaData(int[] in_bytes) { + super(in_bytes); + + state = int8(5); + + v_batt = int16(6); + v_pyro = int16(8); + + sense = new int[6]; + + for (int i = 0; i < 6; i++) { + sense[i] = int8(10 + i) << 4; + sense[i] |= sense[i] >> 8; + } + + ground_pres = int32(16); + ground_accel = int16(20); + accel_plus_g = int16(22); + accel_minus_g = int16(24); + + acceleration = int16(26); + speed = int16(28); + height = int16(30); + } + + public AltosRecord update_state(AltosRecord previous) { + AltosRecord n = super.update_state(previous); + + AltosRecordMM next; + if (!(n instanceof AltosRecordMM)) { + System.out.printf("data making record MM\n"); + next = new AltosRecordMM(n); + } else { + System.out.printf ("data already has MM\n"); + next = (AltosRecordMM) n; + } + + next.state = state; + + next.v_batt = v_batt; + next.v_pyro = v_pyro; + + for (int i = 0; i < 6; i++) + next.sense[i] = sense[i]; + + next.ground_accel = ground_accel; + next.ground_pres = ground_pres; + next.accel_plus_g = accel_plus_g; + next.accel_minus_g = accel_minus_g; + + next.acceleration = acceleration / 16.0; + next.speed = speed / 16.0; + next.height = height; + + next.seen |= AltosRecord.seen_flight | AltosRecord.seen_temp_volt; + + return next; + } +} diff --git a/altoslib/AltosTelemetryRecordMegaSensor.java b/altoslib/AltosTelemetryRecordMegaSensor.java new file mode 100644 index 00000000..85a32d12 --- /dev/null +++ b/altoslib/AltosTelemetryRecordMegaSensor.java @@ -0,0 +1,98 @@ +/* + * 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; + + +public class AltosTelemetryRecordMegaSensor extends AltosTelemetryRecordRaw { + int accel; + int pres; + int temp; + + int accel_x; + int accel_y; + int accel_z; + + int gyro_x; + int gyro_y; + int gyro_z; + + int mag_x; + int mag_y; + int mag_z; + + int rssi; + + public AltosTelemetryRecordMegaSensor(int[] in_bytes, int in_rssi) { + super(in_bytes); + + accel = int16(6); + pres = int32(8); + temp = int16(12); + + accel_x = int16(14); + accel_y = int16(16); + accel_z = int16(18); + + gyro_x = int16(20); + gyro_y = int16(22); + gyro_z = int16(24); + + mag_x = int16(26); + mag_y = int16(28); + mag_z = int16(30); + + rssi = in_rssi; + System.out.printf ("telem record accel: %d\n", accel); + } + + public AltosRecord update_state(AltosRecord previous) { + AltosRecord n = super.update_state(previous); + + AltosRecordMM next; + if (!(n instanceof AltosRecordMM)) { + System.out.printf("sensor making MM\n"); + next = new AltosRecordMM(n); + } else { + System.out.printf("sensor has MM\n"); + next = (AltosRecordMM) n; + } + + System.out.printf("telem update_state accel: %d\n", accel); + next.accel = accel; + next.pres = pres; + next.temp = temp; + + next.imu.accel_x = accel_x; + next.imu.accel_y = accel_y; + next.imu.accel_z = accel_z; + + next.imu.gyro_x = gyro_x; + next.imu.gyro_y = gyro_y; + next.imu.gyro_z = gyro_z; + + next.mag.x = mag_x; + next.mag.y = mag_y; + next.mag.z = mag_z; + + next.rssi = rssi; + + next.seen |= AltosRecord.seen_sensor; + + return next; + } +} diff --git a/altoslib/AltosTelemetryRecordRaw.java b/altoslib/AltosTelemetryRecordRaw.java index 43d0f17a..dc1b8947 100644 --- a/altoslib/AltosTelemetryRecordRaw.java +++ b/altoslib/AltosTelemetryRecordRaw.java @@ -49,6 +49,10 @@ public class AltosTelemetryRecordRaw extends AltosTelemetryRecord { return AltosLib.uint32(bytes, off + 1); } + public int int32(int off) { + return AltosLib.int32(bytes, off + 1); + } + public String string(int off, int l) { return AltosLib.string(bytes, off + 1, l); } @@ -63,7 +67,7 @@ public class AltosTelemetryRecordRaw extends AltosTelemetryRecord { public AltosRecord update_state(AltosRecord previous) { AltosRecord next; if (previous != null) - next = new AltosRecord(previous); + next = previous.clone(); else next = new AltosRecord(); next.serial = serial; diff --git a/altoslib/AltosTelemetryRecordSensor.java b/altoslib/AltosTelemetryRecordSensor.java index cfaf90b0..319a91b3 100644 --- a/altoslib/AltosTelemetryRecordSensor.java +++ b/altoslib/AltosTelemetryRecordSensor.java @@ -61,8 +61,14 @@ public class AltosTelemetryRecordSensor extends AltosTelemetryRecordRaw { rssi = in_rssi; } - public AltosRecord update_state(AltosRecord previous) { - AltosRecord next = super.update_state(previous); + public AltosRecord update_state(AltosRecord prev) { + AltosRecord n = super.update_state(prev); + + AltosRecordTM next; + if (!(n instanceof AltosRecordTM)) + next = new AltosRecordTM(n); + else + next = (AltosRecordTM) n; next.state = state; if (type == packet_type_TM_sensor) diff --git a/altoslib/Makefile.am b/altoslib/Makefile.am index f644d46a..ac97c9cb 100644 --- a/altoslib/Makefile.am +++ b/altoslib/Makefile.am @@ -35,6 +35,8 @@ AltosLib_JAVA = \ $(SRC)/AltosRecordCompanion.java \ $(SRC)/AltosRecordIterable.java \ $(SRC)/AltosRecord.java \ + $(SRC)/AltosRecordTM.java \ + $(SRC)/AltosRecordMM.java \ $(SRC)/AltosReplayReader.java \ $(SRC)/AltosState.java \ $(SRC)/AltosTelemetry.java \ @@ -50,6 +52,8 @@ AltosLib_JAVA = \ $(SRC)/AltosTelemetryRecordRaw.java \ $(SRC)/AltosTelemetryRecordSatellite.java \ $(SRC)/AltosTelemetryRecordSensor.java \ + $(SRC)/AltosTelemetryRecordMegaSensor.java \ + $(SRC)/AltosTelemetryRecordMegaData.java \ $(SRC)/AltosMs5607.java \ $(SRC)/AltosIMU.java \ $(SRC)/AltosMag.java diff --git a/altosui/AltosCSV.java b/altosui/AltosCSV.java index be86a454..c876d9ca 100644 --- a/altosui/AltosCSV.java +++ b/altosui/AltosCSV.java @@ -146,8 +146,8 @@ public class AltosCSV implements AltosWriter { } void write_advanced(AltosRecord record) { - AltosIMU imu = record.imu; - AltosMag mag = record.mag; + AltosIMU imu = record.imu(); + AltosMag mag = record.mag(); if (imu == null) imu = new AltosIMU(); @@ -263,7 +263,7 @@ public class AltosCSV implements AltosWriter { write_general(record); out.printf(","); write_flight(record); out.printf(","); write_basic(record); out.printf(","); - if (record.imu != null || record.mag != null) + if (record.imu() != null || record.mag() != null) write_advanced(record); if (record.gps != null) { out.printf(","); @@ -287,7 +287,7 @@ public class AltosCSV implements AltosWriter { if (record.state == Altos.ao_flight_startup) return; if (!header_written) { - write_header(record.imu != null || record.mag != null, + write_header(record.imu() != null || record.mag() != null, record.gps != null, record.companion != null); header_written = true; } diff --git a/altosui/AltosIdleMonitorUI.java b/altosui/AltosIdleMonitorUI.java index 2ee90937..949e3926 100644 --- a/altosui/AltosIdleMonitorUI.java +++ b/altosui/AltosIdleMonitorUI.java @@ -204,17 +204,18 @@ class AltosIdleMonitor extends Thread { record.state = Altos.ao_flight_idle; record.tick = adc.tick; - record.accel = adc.accel; - record.pres = adc.pres; - record.batt = adc.batt; - record.temp = adc.temp; - record.drogue = adc.drogue; - record.main = adc.main; - - record.ground_accel = record.accel; - record.ground_pres = record.pres; - record.accel_plus_g = config_data.accel_cal_plus; - record.accel_minus_g = config_data.accel_cal_minus; + +// record.accel = adc.accel; +// record.pres = adc.pres; +// record.batt = adc.batt; +// record.temp = adc.temp; +// record.drogue = adc.drogue; +// record.main = adc.main; + +// record.ground_accel = record.accel; +// record.ground_pres = record.pres; +// record.accel_plus_g = config_data.accel_cal_plus; +// record.accel_minus_g = config_data.accel_cal_minus; record.acceleration = 0; record.speed = 0; record.height = 0; -- cgit v1.2.3 From 20bc23ddb90f8a6da1f7ea70f02cf3a038059d32 Mon Sep 17 00:00:00 2001 From: Mike Beattie Date: Fri, 7 Sep 2012 17:32:07 +1200 Subject: altoslib: Remove un-needed imports Signed-off-by: Mike Beattie --- altoslib/AltosConfigData.java | 3 --- altoslib/AltosEepromChunk.java | 2 -- altoslib/AltosEepromIterable.java | 2 -- altoslib/AltosEepromLog.java | 3 --- altoslib/AltosEepromMega.java | 4 ---- altoslib/AltosEepromMegaIterable.java | 2 -- altoslib/AltosEepromRecord.java | 4 ---- altoslib/AltosEepromTeleScience.java | 4 ---- altoslib/AltosFile.java | 1 - altoslib/AltosFlightReader.java | 1 - altoslib/AltosFrequency.java | 4 ---- altoslib/AltosGPS.java | 1 - altoslib/AltosIdleMonitor.java | 3 --- altoslib/AltosIdleMonitorListener.java | 6 ------ altoslib/AltosIdleRecordTM.java | 4 ---- altoslib/AltosLib.java | 2 -- altoslib/AltosLink.java | 2 -- altoslib/AltosLog.java | 2 -- altoslib/AltosParse.java | 1 - altoslib/AltosPreferences.java | 4 ---- altoslib/AltosRecord.java | 5 ----- altoslib/AltosReplayReader.java | 3 --- altoslib/AltosTelemetry.java | 2 -- altoslib/AltosTelemetryMap.java | 1 - altoslib/AltosTelemetryReader.java | 1 - altoslib/AltosTelemetryRecordGeneral.java | 2 -- altoslib/AltosTelemetryRecordLegacy.java | 2 -- altoslib/AltosTelemetryRecordRaw.java | 4 ---- 28 files changed, 75 deletions(-) (limited to 'altoslib/AltosLib.java') diff --git a/altoslib/AltosConfigData.java b/altoslib/AltosConfigData.java index ecc2d0aa..c6e92e62 100644 --- a/altoslib/AltosConfigData.java +++ b/altoslib/AltosConfigData.java @@ -17,12 +17,9 @@ package org.altusmetrum.AltosLib; -import java.io.*; import java.util.*; import java.text.*; -import java.util.prefs.*; import java.util.concurrent.*; -import org.altusmetrum.AltosLib.*; public class AltosConfigData implements Iterable { diff --git a/altoslib/AltosEepromChunk.java b/altoslib/AltosEepromChunk.java index 6d889723..77b22fe2 100644 --- a/altoslib/AltosEepromChunk.java +++ b/altoslib/AltosEepromChunk.java @@ -17,8 +17,6 @@ package org.altusmetrum.AltosLib; -import java.io.*; -import java.util.*; import java.text.*; import java.util.concurrent.*; diff --git a/altoslib/AltosEepromIterable.java b/altoslib/AltosEepromIterable.java index f8acdc16..fc308c34 100644 --- a/altoslib/AltosEepromIterable.java +++ b/altoslib/AltosEepromIterable.java @@ -20,8 +20,6 @@ package org.altusmetrum.AltosLib; import java.io.*; import java.util.*; import java.text.*; -import java.util.prefs.*; -import java.util.concurrent.LinkedBlockingQueue; /* * AltosRecords with an index field so they can be sorted by tick while preserving diff --git a/altoslib/AltosEepromLog.java b/altoslib/AltosEepromLog.java index 7fca4bd9..e27c382a 100644 --- a/altoslib/AltosEepromLog.java +++ b/altoslib/AltosEepromLog.java @@ -17,10 +17,7 @@ package org.altusmetrum.AltosLib; -import java.io.*; -import java.util.*; import java.text.*; -import java.util.prefs.*; import java.util.concurrent.*; /* diff --git a/altoslib/AltosEepromMega.java b/altoslib/AltosEepromMega.java index 2628279e..26bacf8d 100644 --- a/altoslib/AltosEepromMega.java +++ b/altoslib/AltosEepromMega.java @@ -17,11 +17,7 @@ package org.altusmetrum.AltosLib; -import java.io.*; -import java.util.*; import java.text.*; -import java.util.prefs.*; -import java.util.concurrent.*; public class AltosEepromMega { public int cmd; diff --git a/altoslib/AltosEepromMegaIterable.java b/altoslib/AltosEepromMegaIterable.java index f62cc45b..be20ba63 100644 --- a/altoslib/AltosEepromMegaIterable.java +++ b/altoslib/AltosEepromMegaIterable.java @@ -20,8 +20,6 @@ package org.altusmetrum.AltosLib; import java.io.*; import java.util.*; import java.text.*; -import java.util.prefs.*; -import java.util.concurrent.LinkedBlockingQueue; /* * AltosRecords with an index field so they can be sorted by tick while preserving diff --git a/altoslib/AltosEepromRecord.java b/altoslib/AltosEepromRecord.java index 1e845f46..c7ced6a3 100644 --- a/altoslib/AltosEepromRecord.java +++ b/altoslib/AltosEepromRecord.java @@ -17,11 +17,7 @@ package org.altusmetrum.AltosLib; -import java.io.*; -import java.util.*; import java.text.*; -import java.util.prefs.*; -import java.util.concurrent.*; public class AltosEepromRecord { public int cmd; diff --git a/altoslib/AltosEepromTeleScience.java b/altoslib/AltosEepromTeleScience.java index 1758fa34..02ce4553 100644 --- a/altoslib/AltosEepromTeleScience.java +++ b/altoslib/AltosEepromTeleScience.java @@ -17,11 +17,7 @@ package org.altusmetrum.AltosLib; -import java.io.*; -import java.util.*; import java.text.*; -import java.util.prefs.*; -import java.util.concurrent.*; public class AltosEepromTeleScience { public int type; diff --git a/altoslib/AltosFile.java b/altoslib/AltosFile.java index d2e4f2f7..1ab00b38 100644 --- a/altoslib/AltosFile.java +++ b/altoslib/AltosFile.java @@ -17,7 +17,6 @@ package org.altusmetrum.AltosLib; -import java.lang.*; import java.io.File; import java.util.*; diff --git a/altoslib/AltosFlightReader.java b/altoslib/AltosFlightReader.java index 3fdea469..cbd64153 100644 --- a/altoslib/AltosFlightReader.java +++ b/altoslib/AltosFlightReader.java @@ -17,7 +17,6 @@ package org.altusmetrum.AltosLib; -import java.lang.*; import java.text.*; import java.io.*; import java.util.concurrent.*; diff --git a/altoslib/AltosFrequency.java b/altoslib/AltosFrequency.java index f08ff116..e20f03b7 100644 --- a/altoslib/AltosFrequency.java +++ b/altoslib/AltosFrequency.java @@ -17,10 +17,6 @@ package org.altusmetrum.AltosLib; -import java.io.*; -import java.util.*; -import java.text.*; - public class AltosFrequency { public double frequency; public String description; diff --git a/altoslib/AltosGPS.java b/altoslib/AltosGPS.java index f078a469..2c2fd36b 100644 --- a/altoslib/AltosGPS.java +++ b/altoslib/AltosGPS.java @@ -17,7 +17,6 @@ package org.altusmetrum.AltosLib; -import java.lang.*; import java.text.*; public class AltosGPS { diff --git a/altoslib/AltosIdleMonitor.java b/altoslib/AltosIdleMonitor.java index 27ea3a2b..d83c4450 100644 --- a/altoslib/AltosIdleMonitor.java +++ b/altoslib/AltosIdleMonitor.java @@ -18,9 +18,6 @@ package org.altusmetrum.AltosLib; import java.io.*; -import java.util.*; -import java.text.*; -import java.util.prefs.*; import java.util.concurrent.*; class AltosSensorTM extends AltosRecordTM { diff --git a/altoslib/AltosIdleMonitorListener.java b/altoslib/AltosIdleMonitorListener.java index 3c18bfaa..9f9ababf 100644 --- a/altoslib/AltosIdleMonitorListener.java +++ b/altoslib/AltosIdleMonitorListener.java @@ -17,12 +17,6 @@ package org.altusmetrum.AltosLib; -import java.io.*; -import java.util.*; -import java.text.*; -import java.util.prefs.*; -import java.util.concurrent.*; - public interface AltosIdleMonitorListener { public void update(AltosState state); } \ No newline at end of file diff --git a/altoslib/AltosIdleRecordTM.java b/altoslib/AltosIdleRecordTM.java index 112b847e..d48ff7e4 100644 --- a/altoslib/AltosIdleRecordTM.java +++ b/altoslib/AltosIdleRecordTM.java @@ -17,10 +17,6 @@ package org.altusmetrum.AltosLib; -import java.io.*; -import java.util.*; -import java.text.*; -import java.util.prefs.*; import java.util.concurrent.*; class AltosADCTM { diff --git a/altoslib/AltosLib.java b/altoslib/AltosLib.java index 2402331e..8d383f12 100644 --- a/altoslib/AltosLib.java +++ b/altoslib/AltosLib.java @@ -17,9 +17,7 @@ package org.altusmetrum.AltosLib; -import java.awt.*; import java.util.*; -import java.text.*; import java.io.*; import java.nio.charset.Charset; diff --git a/altoslib/AltosLink.java b/altoslib/AltosLink.java index 415c3c64..6d510563 100644 --- a/altoslib/AltosLink.java +++ b/altoslib/AltosLink.java @@ -17,11 +17,9 @@ package org.altusmetrum.AltosLib; -import java.lang.*; import java.io.*; import java.util.concurrent.*; import java.util.*; -import java.text.*; public abstract class AltosLink implements Runnable { diff --git a/altoslib/AltosLog.java b/altoslib/AltosLog.java index 55a25bb4..3c124700 100644 --- a/altoslib/AltosLog.java +++ b/altoslib/AltosLog.java @@ -18,8 +18,6 @@ package org.altusmetrum.AltosLib; import java.io.*; -import java.lang.*; -import java.util.*; import java.text.ParseException; import java.util.concurrent.LinkedBlockingQueue; diff --git a/altoslib/AltosParse.java b/altoslib/AltosParse.java index 7d832f1a..e938a177 100644 --- a/altoslib/AltosParse.java +++ b/altoslib/AltosParse.java @@ -18,7 +18,6 @@ package org.altusmetrum.AltosLib; import java.text.*; -import java.lang.*; public class AltosParse { public static boolean isdigit(char c) { diff --git a/altoslib/AltosPreferences.java b/altoslib/AltosPreferences.java index 9ab80cf5..13fee46d 100644 --- a/altoslib/AltosPreferences.java +++ b/altoslib/AltosPreferences.java @@ -19,11 +19,7 @@ package org.altusmetrum.AltosLib; import java.io.*; import java.util.*; -import java.text.*; import java.util.prefs.*; -import java.util.concurrent.LinkedBlockingQueue; -import java.awt.Component; -import javax.swing.*; import javax.swing.filechooser.FileSystemView; public class AltosPreferences { diff --git a/altoslib/AltosRecord.java b/altoslib/AltosRecord.java index 8722bc05..dd741716 100644 --- a/altoslib/AltosRecord.java +++ b/altoslib/AltosRecord.java @@ -17,11 +17,6 @@ package org.altusmetrum.AltosLib; -import java.lang.*; -import java.text.*; -import java.util.HashMap; -import java.io.*; - public class AltosRecord implements Comparable , Cloneable { public static final int seen_flight = 1; diff --git a/altoslib/AltosReplayReader.java b/altoslib/AltosReplayReader.java index 1585f9eb..50bef07a 100644 --- a/altoslib/AltosReplayReader.java +++ b/altoslib/AltosReplayReader.java @@ -19,9 +19,6 @@ package org.altusmetrum.AltosLib; import java.io.*; import java.util.*; -import java.text.*; -import java.util.prefs.*; -import java.util.concurrent.LinkedBlockingQueue; /* * Open an existing telemetry file and replay it in realtime diff --git a/altoslib/AltosTelemetry.java b/altoslib/AltosTelemetry.java index ee244824..15534158 100644 --- a/altoslib/AltosTelemetry.java +++ b/altoslib/AltosTelemetry.java @@ -17,9 +17,7 @@ package org.altusmetrum.AltosLib; -import java.lang.*; import java.text.*; -import java.util.HashMap; /* * Telemetry data contents diff --git a/altoslib/AltosTelemetryMap.java b/altoslib/AltosTelemetryMap.java index 003cb6a9..bc1486d8 100644 --- a/altoslib/AltosTelemetryMap.java +++ b/altoslib/AltosTelemetryMap.java @@ -16,7 +16,6 @@ */ package org.altusmetrum.AltosLib; -import java.lang.*; import java.text.*; import java.util.HashMap; diff --git a/altoslib/AltosTelemetryReader.java b/altoslib/AltosTelemetryReader.java index bdb44eef..94fa560b 100644 --- a/altoslib/AltosTelemetryReader.java +++ b/altoslib/AltosTelemetryReader.java @@ -17,7 +17,6 @@ package org.altusmetrum.AltosLib; -import java.lang.*; import java.text.*; import java.io.*; import java.util.concurrent.*; diff --git a/altoslib/AltosTelemetryRecordGeneral.java b/altoslib/AltosTelemetryRecordGeneral.java index 5e157a54..a53280cf 100644 --- a/altoslib/AltosTelemetryRecordGeneral.java +++ b/altoslib/AltosTelemetryRecordGeneral.java @@ -17,9 +17,7 @@ package org.altusmetrum.AltosLib; -import java.lang.*; import java.text.*; -import java.util.HashMap; public class AltosTelemetryRecordGeneral { diff --git a/altoslib/AltosTelemetryRecordLegacy.java b/altoslib/AltosTelemetryRecordLegacy.java index 3976a07a..b11fed58 100644 --- a/altoslib/AltosTelemetryRecordLegacy.java +++ b/altoslib/AltosTelemetryRecordLegacy.java @@ -17,9 +17,7 @@ package org.altusmetrum.AltosLib; -import java.lang.*; import java.text.*; -import java.util.HashMap; /* * Telemetry data contents diff --git a/altoslib/AltosTelemetryRecordRaw.java b/altoslib/AltosTelemetryRecordRaw.java index dc1b8947..fbb373d5 100644 --- a/altoslib/AltosTelemetryRecordRaw.java +++ b/altoslib/AltosTelemetryRecordRaw.java @@ -17,10 +17,6 @@ package org.altusmetrum.AltosLib; -import java.lang.*; -import java.text.*; -import java.util.HashMap; - public class AltosTelemetryRecordRaw extends AltosTelemetryRecord { int[] bytes; int serial; -- cgit v1.2.3 From 9682e9e6fe730417a77b47795fbe1f06c9a51177 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 9 Sep 2012 12:29:32 -0700 Subject: altosui: Use helper functions to access arrays in AltosLib class These deal with out-of-range values correctly, instead of causing exceptions that will just break stuff. Signed-off-by: Keith Packard --- altoslib/AltosLib.java | 18 ++++++++++++------ altosui/Altos.java | 14 -------------- altosui/AltosFlightStatsTable.java | 2 +- altosui/AltosScanUI.java | 2 +- 4 files changed, 14 insertions(+), 22 deletions(-) (limited to 'altoslib/AltosLib.java') diff --git a/altoslib/AltosLib.java b/altoslib/AltosLib.java index 2402331e..d36b2ff7 100644 --- a/altoslib/AltosLib.java +++ b/altoslib/AltosLib.java @@ -111,7 +111,7 @@ public class AltosLib { public static final int ao_telemetry_0_8 = 3; public static final int ao_telemetry_max = 3; - public static final String[] ao_telemetry_name = { + private static final String[] ao_telemetry_name = { "Off", "Standard Telemetry", "TeleMetrum v0.9", "TeleMetrum v0.8" }; @@ -121,13 +121,13 @@ public class AltosLib { public static final int ao_telemetry_0_9_len = 95; public static final int ao_telemetry_0_8_len = 94; - public static final int[] ao_telemetry_len = { + private static final int[] ao_telemetry_len = { 0, 32, 95, 94 }; - public static HashMap string_to_state = new HashMap(); + private static HashMap string_to_state = new HashMap(); - public static boolean map_initialized = false; + private static boolean map_initialized = false; public static void initialize_map() { @@ -159,7 +159,7 @@ public class AltosLib { telemetry)); } - public static String[] state_to_string = { + private static String[] state_to_string = { "startup", "idle", "pad", @@ -172,7 +172,7 @@ public class AltosLib { "invalid", }; - public static String[] state_to_string_capital = { + private static String[] state_to_string_capital = { "Startup", "Idle", "Pad", @@ -199,6 +199,12 @@ public class AltosLib { return state_to_string[state]; } + public static String state_name_capital(int state) { + if (state < 0 || state_to_string.length <= state) + return "invalid"; + return state_to_string_capital[state]; + } + public static final int AO_GPS_VALID = (1 << 4); public static final int AO_GPS_RUNNING = (1 << 5); public static final int AO_GPS_DATE_VALID = (1 << 6); diff --git a/altosui/Altos.java b/altosui/Altos.java index e60b3aaa..cd17a93e 100644 --- a/altosui/Altos.java +++ b/altosui/Altos.java @@ -72,20 +72,6 @@ public class Altos extends AltosLib { static final int text_width = 20; - static public int state(String state) { - if (!map_initialized) - initialize_map(); - if (string_to_state.containsKey(state)) - return string_to_state.get(state); - return ao_flight_invalid; - } - - static public String state_name(int state) { - if (state < 0 || state_to_string.length <= state) - return "invalid"; - return state_to_string[state]; - } - static public boolean initialized = false; static public boolean loaded_library = false; diff --git a/altosui/AltosFlightStatsTable.java b/altosui/AltosFlightStatsTable.java index c311b231..14e3bf8f 100644 --- a/altosui/AltosFlightStatsTable.java +++ b/altosui/AltosFlightStatsTable.java @@ -103,7 +103,7 @@ public class AltosFlightStatsTable extends JComponent { 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]))); for (int s = Altos.ao_flight_boost; s <= Altos.ao_flight_main; s++) { - new FlightStat(layout, y++, String.format("%s time", Altos.state_to_string_capital[s]), + new FlightStat(layout, y++, String.format("%s time", AltosLib.state_name_capital(s)), String.format("%6.2f s", stats.state_end[s] - stats.state_start[s])); } new FlightStat(layout, y++, "Flight Time", diff --git a/altosui/AltosScanUI.java b/altosui/AltosScanUI.java index ef6389b6..9da1290f 100644 --- a/altosui/AltosScanUI.java +++ b/altosui/AltosScanUI.java @@ -427,7 +427,7 @@ public class AltosScanUI telemetry_boxes = new JCheckBox[Altos.ao_telemetry_max - Altos.ao_telemetry_min + 1]; for (int k = Altos.ao_telemetry_min; k <= Altos.ao_telemetry_max; k++) { int j = k - Altos.ao_telemetry_min; - telemetry_boxes[j] = new JCheckBox(Altos.ao_telemetry_name[k]); + telemetry_boxes[j] = new JCheckBox(AltosLib.telemetry_name(k)); c.gridy = 3 + j; pane.add(telemetry_boxes[j], c); telemetry_boxes[j].setActionCommand("telemetry"); -- cgit v1.2.3