diff options
107 files changed, 1466 insertions, 1341 deletions
diff --git a/altosui/Altos.java b/altosui/Altos.java index aa2fd77a..b9d6598a 100644 --- a/altosui/Altos.java +++ b/altosui/Altos.java @@ -24,76 +24,9 @@ import java.nio.charset.Charset; import libaltosJNI.*; -public class Altos { - /* EEProm command letters */ - static final int AO_LOG_FLIGHT = 'F'; - static final int AO_LOG_SENSOR = 'A'; - static final int AO_LOG_TEMP_VOLT = 'T'; - static final int AO_LOG_DEPLOY = 'D'; - static final int AO_LOG_STATE = 'S'; - static final int AO_LOG_GPS_TIME = 'G'; - static final int AO_LOG_GPS_LAT = 'N'; - static final int AO_LOG_GPS_LON = 'W'; - static final int AO_LOG_GPS_ALT = 'H'; - static final int AO_LOG_GPS_SAT = 'V'; - static final int AO_LOG_GPS_DATE = 'Y'; - static final int AO_LOG_PRESSURE = 'P'; +import org.altusmetrum.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; - 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,Integer> string_to_state = new HashMap<String,Integer>(); - - static boolean map_initialized = false; +public class Altos extends AltosLib { static final int tab_elt_pad = 5; @@ -139,259 +72,6 @@ public class Altos { static final int text_width = 20; - 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; - } - - 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)); - } - - 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)); - } - - static String[] state_to_string = { - "startup", - "idle", - "pad", - "boost", - "fast", - "coast", - "drogue", - "main", - "landed", - "invalid", - }; - - static String[] state_to_string_capital = { - "Startup", - "Idle", - "Pad", - "Boost", - "Fast", - "Coast", - "Drogue", - "Main", - "Landed", - "Invalid", - }; - - 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 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_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/AltosAscent.java b/altosui/AltosAscent.java index c8e5f3af..38b3b30f 100644 --- a/altosui/AltosAscent.java +++ b/altosui/AltosAscent.java @@ -27,6 +27,7 @@ import java.util.*; import java.text.*; import java.util.prefs.*; import java.util.concurrent.LinkedBlockingQueue; +import org.altusmetrum.AltosLib.*; public class AltosAscent extends JComponent implements AltosFlightDisplay { GridBagLayout layout; diff --git a/altosui/AltosBTKnown.java b/altosui/AltosBTKnown.java index 95830637..e30be057 100644 --- a/altosui/AltosBTKnown.java +++ b/altosui/AltosBTKnown.java @@ -23,7 +23,7 @@ import java.util.prefs.*; public class AltosBTKnown implements Iterable<AltosBTDevice> { LinkedList<AltosBTDevice> devices = new LinkedList<AltosBTDevice>(); - Preferences bt_pref = AltosPreferences.bt_devices(); + Preferences bt_pref = AltosUIPreferences.bt_devices(); private String get_address(String name) { return bt_pref.get(name, ""); @@ -57,7 +57,7 @@ public class AltosBTKnown implements Iterable<AltosBTDevice> { } private void flush() { - AltosPreferences.flush_preferences(); + AltosUIPreferences.flush_preferences(); } public void set(Iterable<AltosBTDevice> new_devices) { @@ -91,7 +91,7 @@ public class AltosBTKnown implements Iterable<AltosBTDevice> { public AltosBTKnown() { devices = new LinkedList<AltosBTDevice>(); - bt_pref = AltosPreferences.bt_devices(); + bt_pref = AltosUIPreferences.bt_devices(); load(); } }
\ No newline at end of file diff --git a/altosui/AltosBTManage.java b/altosui/AltosBTManage.java index 6d460701..d2899d65 100644 --- a/altosui/AltosBTManage.java +++ b/altosui/AltosBTManage.java @@ -29,6 +29,7 @@ import java.util.*; import java.text.*; import java.util.prefs.*; import java.util.concurrent.*; +import org.altusmetrum.AltosLib.*; import libaltosJNI.*; diff --git a/altosui/AltosCSV.java b/altosui/AltosCSV.java index cf649db0..9510524c 100644 --- a/altosui/AltosCSV.java +++ b/altosui/AltosCSV.java @@ -21,6 +21,7 @@ import java.lang.*; import java.io.*; import java.text.*; import java.util.*; +import org.altusmetrum.AltosLib.*; public class AltosCSV implements AltosWriter { File name; diff --git a/altosui/AltosCSVUI.java b/altosui/AltosCSVUI.java index 6d3e9065..2702668b 100644 --- a/altosui/AltosCSVUI.java +++ b/altosui/AltosCSVUI.java @@ -27,6 +27,7 @@ import java.util.*; import java.text.*; import java.util.prefs.*; import java.util.concurrent.LinkedBlockingQueue; +import org.altusmetrum.AltosLib.*; public class AltosCSVUI extends AltosDialog diff --git a/altosui/AltosChannelMenu.java b/altosui/AltosChannelMenu.java index abbb86f4..0249a0bd 100644 --- a/altosui/AltosChannelMenu.java +++ b/altosui/AltosChannelMenu.java @@ -27,6 +27,7 @@ import java.util.*; import java.text.*; import java.util.prefs.*; import java.util.concurrent.LinkedBlockingQueue; +import org.altusmetrum.AltosLib.*; public class AltosChannelMenu extends JComboBox implements ActionListener { int channel; diff --git a/altosui/AltosCompanionInfo.java b/altosui/AltosCompanionInfo.java index 82bde623..4ba8fe98 100644 --- a/altosui/AltosCompanionInfo.java +++ b/altosui/AltosCompanionInfo.java @@ -27,6 +27,7 @@ import java.util.*; import java.text.*; import java.util.prefs.*; import java.util.concurrent.LinkedBlockingQueue; +import org.altusmetrum.AltosLib.*; public class AltosCompanionInfo extends JTable { private AltosFlightInfoTableModel model; diff --git a/altosui/AltosConfig.java b/altosui/AltosConfig.java index 93def70d..64dfa670 100644 --- a/altosui/AltosConfig.java +++ b/altosui/AltosConfig.java @@ -27,6 +27,7 @@ import java.util.*; import java.text.*; import java.util.prefs.*; import java.util.concurrent.*; +import org.altusmetrum.AltosLib.*; import libaltosJNI.*; @@ -287,7 +288,7 @@ public class AltosConfig implements ActionListener { if (remote) { serial_line.stop_remote(); serial_line.set_radio_frequency(frequency); - AltosPreferences.set_frequency(device.getSerial(), frequency); + AltosUIPreferences.set_frequency(device.getSerial(), frequency); serial_line.start_remote(); } serial_line.printf("c c %s\n", callsign.get()); diff --git a/altosui/AltosConfigFreqUI.java b/altosui/AltosConfigFreqUI.java index c6eabc53..7958a21c 100644 --- a/altosui/AltosConfigFreqUI.java +++ b/altosui/AltosConfigFreqUI.java @@ -29,6 +29,7 @@ import java.util.*; import java.text.*; import java.util.prefs.*; import java.util.concurrent.*; +import org.altusmetrum.AltosLib.*; class AltosEditFreqUI extends AltosDialog implements ActionListener { Frame frame; @@ -246,7 +247,7 @@ public class AltosConfigFreqUI extends AltosDialog implements ActionListener { FrequencyList frequencies; void save_frequencies() { - AltosPreferences.set_common_frequencies(frequencies.frequencies()); + AltosUIPreferences.set_common_frequencies(frequencies.frequencies()); } JButton add, edit, remove; @@ -411,7 +412,7 @@ public class AltosConfigFreqUI extends AltosDialog implements ActionListener { Frame frame = JOptionPane.getFrameForComponent(frameComp); AltosConfigFreqUI dialog; - dialog = new AltosConfigFreqUI(frame, AltosPreferences.common_frequencies()); + dialog = new AltosConfigFreqUI(frame, AltosUIPreferences.common_frequencies()); dialog.setVisible(true); } diff --git a/altosui/AltosConfigUI.java b/altosui/AltosConfigUI.java index 9fef8e3b..8ae2998d 100644 --- a/altosui/AltosConfigUI.java +++ b/altosui/AltosConfigUI.java @@ -28,6 +28,7 @@ import java.util.*; import java.text.*; import java.util.prefs.*; import java.util.concurrent.LinkedBlockingQueue; +import org.altusmetrum.AltosLib.*; import libaltosJNI.*; @@ -393,7 +394,7 @@ public class AltosConfigUI c.anchor = GridBagConstraints.LINE_START; c.insets = ir; c.ipady = 5; - callsign_value = new JTextField(AltosPreferences.callsign()); + callsign_value = new JTextField(AltosUIPreferences.callsign()); callsign_value.getDocument().addDocumentListener(this); pane.add(callsign_value, c); callsign_value.setToolTipText("Callsign reported in telemetry data"); @@ -636,7 +637,7 @@ public class AltosConfigUI product_value.getText(), serial_value.getText()); AltosFrequency new_frequency = new AltosFrequency(new_radio_frequency, description); - AltosPreferences.add_common_frequency(new_frequency); + AltosUIPreferences.add_common_frequency(new_frequency); radio_frequency_value.insertItemAt(new_frequency, i); } diff --git a/altosui/AltosConfigureUI.java b/altosui/AltosConfigureUI.java index 06b5745c..deb179d6 100644 --- a/altosui/AltosConfigureUI.java +++ b/altosui/AltosConfigureUI.java @@ -30,6 +30,7 @@ import java.text.*; import java.util.prefs.*; import java.util.concurrent.LinkedBlockingQueue; import javax.swing.plaf.basic.*; +import org.altusmetrum.AltosLib.*; class DelegatingRenderer implements ListCellRenderer { @@ -105,7 +106,7 @@ public class AltosConfigureUI /* DocumentListener interface methods */ public void changedUpdate(DocumentEvent e) { - AltosPreferences.set_callsign(callsign_value.getText()); + AltosUIPreferences.set_callsign(callsign_value.getText()); } public void insertUpdate(DocumentEvent e) { @@ -158,12 +159,12 @@ public class AltosConfigureUI c.anchor = GridBagConstraints.WEST; pane.add(new JLabel("Voice"), c); - enable_voice = new JRadioButton("Enable", AltosPreferences.voice()); + enable_voice = new JRadioButton("Enable", AltosUIPreferences.voice()); enable_voice.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JRadioButton item = (JRadioButton) e.getSource(); boolean enabled = item.isSelected(); - AltosPreferences.set_voice(enabled); + AltosUIPreferences.set_voice(enabled); if (enabled) voice.speak_always("Enable voice."); else @@ -202,11 +203,11 @@ public class AltosConfigureUI c.anchor = GridBagConstraints.WEST; pane.add(new JLabel("Log Directory"), c); - configure_log = new JButton(AltosPreferences.logdir().getPath()); + configure_log = new JButton(AltosUIPreferences.logdir().getPath()); configure_log.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { - AltosPreferences.ConfigureLog(); - configure_log.setText(AltosPreferences.logdir().getPath()); + AltosUIPreferences.ConfigureLog(); + configure_log.setText(AltosUIPreferences.logdir().getPath()); } }); c.gridx = 1; @@ -225,7 +226,7 @@ public class AltosConfigureUI c.anchor = GridBagConstraints.WEST; pane.add(new JLabel("Callsign"), c); - callsign_value = new JTextField(AltosPreferences.callsign()); + callsign_value = new JTextField(AltosUIPreferences.callsign()); callsign_value.getDocument().addDocumentListener(this); c.gridx = 1; c.gridy = row++; @@ -244,13 +245,13 @@ public class AltosConfigureUI pane.add(new JLabel("Font size"), c); font_size_value = new JComboBox(font_size_names); - int font_size = AltosPreferences.font_size(); + int font_size = AltosUIPreferences.font_size(); font_size_value.setSelectedIndex(font_size - Altos.font_size_small); font_size_value.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { int size = font_size_value.getSelectedIndex() + Altos.font_size_small; - AltosPreferences.set_font_size(size); + AltosUIPreferences.set_font_size(size); } }); c.gridx = 1; @@ -295,7 +296,7 @@ public class AltosConfigureUI DelegatingRenderer.install(look_and_feel_value); - String look_and_feel = AltosPreferences.look_and_feel(); + String look_and_feel = AltosUIPreferences.look_and_feel(); for (int i = 0; i < look_and_feels.length; i++) if (look_and_feel.equals(look_and_feels[i].getClassName())) look_and_feel_value.setSelectedIndex(i); @@ -304,7 +305,7 @@ public class AltosConfigureUI public void actionPerformed(ActionEvent e) { int id = look_and_feel_value.getSelectedIndex(); - AltosPreferences.set_look_and_feel(look_and_feels[id].getClassName()); + AltosUIPreferences.set_look_and_feel(look_and_feels[id].getClassName()); } }); c.gridx = 1; @@ -323,12 +324,12 @@ public class AltosConfigureUI c.anchor = GridBagConstraints.WEST; pane.add(new JLabel("Serial Debug"), c); - serial_debug = new JRadioButton("Enable", AltosPreferences.serial_debug()); + serial_debug = new JRadioButton("Enable", AltosUIPreferences.serial_debug()); serial_debug.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JRadioButton item = (JRadioButton) e.getSource(); boolean enabled = item.isSelected(); - AltosPreferences.set_serial_debug(enabled); + AltosUIPreferences.set_serial_debug(enabled); } }); serial_debug.setToolTipText("Enable/Disable USB I/O getting sent to the console"); diff --git a/altosui/AltosDataChooser.java b/altosui/AltosDataChooser.java index d81ca6d1..290de794 100644 --- a/altosui/AltosDataChooser.java +++ b/altosui/AltosDataChooser.java @@ -26,6 +26,7 @@ import java.io.*; import java.util.*; import java.text.*; import java.util.prefs.*; +import org.altusmetrum.AltosLib.*; public class AltosDataChooser extends JFileChooser { JFrame frame; @@ -74,6 +75,6 @@ public class AltosDataChooser extends JFileChooser { setDialogTitle("Select Flight Record File"); setFileFilter(new FileNameExtensionFilter("Flight data file", "telem", "eeprom")); - setCurrentDirectory(AltosPreferences.logdir()); + setCurrentDirectory(AltosUIPreferences.logdir()); } } diff --git a/altosui/AltosDataPointReader.java b/altosui/AltosDataPointReader.java index c3aabb0c..821b0771 100644 --- a/altosui/AltosDataPointReader.java +++ b/altosui/AltosDataPointReader.java @@ -9,6 +9,7 @@ import java.text.ParseException; import java.lang.UnsupportedOperationException; import java.util.NoSuchElementException; import java.util.Iterator; +import org.altusmetrum.AltosLib.*; class AltosDataPointReader implements Iterable<AltosDataPoint> { Iterator<AltosRecord> iter; diff --git a/altosui/AltosDebug.java b/altosui/AltosDebug.java index ce1cf5dd..23e38bc0 100644 --- a/altosui/AltosDebug.java +++ b/altosui/AltosDebug.java @@ -21,6 +21,7 @@ import java.lang.*; import java.io.*; import java.util.concurrent.*; import java.util.*; +import org.altusmetrum.AltosLib.*; import libaltosJNI.*; diff --git a/altosui/AltosDescent.java b/altosui/AltosDescent.java index 0fcd690b..664c5ea6 100644 --- a/altosui/AltosDescent.java +++ b/altosui/AltosDescent.java @@ -27,6 +27,7 @@ import java.util.*; import java.text.*; import java.util.prefs.*; import java.util.concurrent.LinkedBlockingQueue; +import org.altusmetrum.AltosLib.*; public class AltosDescent extends JComponent implements AltosFlightDisplay { GridBagLayout layout; diff --git a/altosui/AltosDialog.java b/altosui/AltosDialog.java index c30b5757..ff38c3e4 100644 --- a/altosui/AltosDialog.java +++ b/altosui/AltosDialog.java @@ -27,12 +27,13 @@ import java.util.*; import java.text.*; import java.util.prefs.*; import java.util.concurrent.*; +import org.altusmetrum.AltosLib.*; import libaltosJNI.*; class AltosDialogListener extends WindowAdapter { public void windowClosing (WindowEvent e) { - AltosPreferences.unregister_ui_listener((AltosDialog) e.getWindow()); + AltosUIPreferences.unregister_ui_listener((AltosDialog) e.getWindow()); } } @@ -44,19 +45,19 @@ public class AltosDialog extends JDialog implements AltosUIListener { } public AltosDialog() { - AltosPreferences.register_ui_listener(this); + AltosUIPreferences.register_ui_listener(this); addWindowListener(new AltosDialogListener()); } public AltosDialog(Frame frame, String label, boolean modal) { super(frame, label, modal); - AltosPreferences.register_ui_listener(this); + AltosUIPreferences.register_ui_listener(this); addWindowListener(new AltosDialogListener()); } public AltosDialog(Frame frame, boolean modal) { super(frame, modal); - AltosPreferences.register_ui_listener(this); + AltosUIPreferences.register_ui_listener(this); addWindowListener(new AltosDialogListener()); } } diff --git a/altosui/AltosDisplayThread.java b/altosui/AltosDisplayThread.java index ce8d9159..03ce4efd 100644 --- a/altosui/AltosDisplayThread.java +++ b/altosui/AltosDisplayThread.java @@ -27,6 +27,7 @@ import java.util.*; import java.text.*; import java.util.prefs.*; import java.util.concurrent.LinkedBlockingQueue; +import org.altusmetrum.AltosLib.*; public class AltosDisplayThread extends Thread { diff --git a/altosui/AltosEepromDelete.java b/altosui/AltosEepromDelete.java index a9d77788..d619f3ea 100644 --- a/altosui/AltosEepromDelete.java +++ b/altosui/AltosEepromDelete.java @@ -27,6 +27,7 @@ import java.util.*; import java.text.*; import java.util.prefs.*; import java.util.concurrent.*; +import org.altusmetrum.AltosLib.*; import libaltosJNI.*; diff --git a/altosui/AltosEepromDownload.java b/altosui/AltosEepromDownload.java index e7e52466..44d5dbbc 100644 --- a/altosui/AltosEepromDownload.java +++ b/altosui/AltosEepromDownload.java @@ -27,6 +27,7 @@ import java.util.*; import java.text.*; import java.util.prefs.*; import java.util.concurrent.*; +import org.altusmetrum.AltosLib.*; import libaltosJNI.*; diff --git a/altosui/AltosEepromList.java b/altosui/AltosEepromList.java index da4b1166..c0b59c67 100644 --- a/altosui/AltosEepromList.java +++ b/altosui/AltosEepromList.java @@ -27,6 +27,7 @@ import java.util.*; import java.text.*; import java.util.prefs.*; import java.util.concurrent.*; +import org.altusmetrum.AltosLib.*; import libaltosJNI.*; diff --git a/altosui/AltosEepromManage.java b/altosui/AltosEepromManage.java index 083c7372..8e1e1a35 100644 --- a/altosui/AltosEepromManage.java +++ b/altosui/AltosEepromManage.java @@ -27,6 +27,7 @@ import java.util.*; import java.text.*; import java.util.prefs.*; import java.util.concurrent.*; +import org.altusmetrum.AltosLib.*; import libaltosJNI.*; diff --git a/altosui/AltosEepromMonitor.java b/altosui/AltosEepromMonitor.java index 34f5b891..75643442 100644 --- a/altosui/AltosEepromMonitor.java +++ b/altosui/AltosEepromMonitor.java @@ -27,6 +27,7 @@ import java.util.*; import java.text.*; import java.util.prefs.*; import java.util.concurrent.LinkedBlockingQueue; +import org.altusmetrum.AltosLib.*; public class AltosEepromMonitor extends AltosDialog { diff --git a/altosui/AltosEepromSelect.java b/altosui/AltosEepromSelect.java index ebafc4c8..492b635c 100644 --- a/altosui/AltosEepromSelect.java +++ b/altosui/AltosEepromSelect.java @@ -27,6 +27,7 @@ import libaltosJNI.libaltos; import libaltosJNI.altos_device; import libaltosJNI.SWIGTYPE_p_altos_file; import libaltosJNI.SWIGTYPE_p_altos_list; +import org.altusmetrum.AltosLib.*; class AltosEepromItem implements ActionListener { AltosEepromLog log; diff --git a/altosui/AltosFlash.java b/altosui/AltosFlash.java index e91e9806..bd0c8a50 100644 --- a/altosui/AltosFlash.java +++ b/altosui/AltosFlash.java @@ -27,6 +27,7 @@ import java.util.*; import java.text.*; import java.util.prefs.*; import java.util.concurrent.LinkedBlockingQueue; +import org.altusmetrum.AltosLib.*; public class AltosFlash { File file; diff --git a/altosui/AltosFlashUI.java b/altosui/AltosFlashUI.java index 704ce35c..4ab73a6d 100644 --- a/altosui/AltosFlashUI.java +++ b/altosui/AltosFlashUI.java @@ -27,6 +27,7 @@ import java.util.*; import java.text.*; import java.util.prefs.*; import java.util.concurrent.*; +import org.altusmetrum.AltosLib.*; public class AltosFlashUI extends AltosDialog @@ -161,7 +162,7 @@ public class AltosFlashUI boolean select_source_file() { JFileChooser hexfile_chooser = new JFileChooser(); - File firmwaredir = AltosPreferences.firmwaredir(); + File firmwaredir = AltosUIPreferences.firmwaredir(); if (firmwaredir != null) hexfile_chooser.setCurrentDirectory(firmwaredir); @@ -174,7 +175,7 @@ public class AltosFlashUI file = hexfile_chooser.getSelectedFile(); if (file == null) return false; - AltosPreferences.set_firmwaredir(file.getParentFile()); + AltosUIPreferences.set_firmwaredir(file.getParentFile()); return true; } diff --git a/altosui/AltosFlightDisplay.java b/altosui/AltosFlightDisplay.java index f633c8e6..826f9522 100644 --- a/altosui/AltosFlightDisplay.java +++ b/altosui/AltosFlightDisplay.java @@ -17,6 +17,8 @@ package altosui; +import org.altusmetrum.AltosLib.*; + public interface AltosFlightDisplay { void reset(); diff --git a/altosui/AltosFlightInfoTableModel.java b/altosui/AltosFlightInfoTableModel.java index e23eff68..77969a89 100644 --- a/altosui/AltosFlightInfoTableModel.java +++ b/altosui/AltosFlightInfoTableModel.java @@ -27,6 +27,7 @@ import java.util.*; import java.text.*; import java.util.prefs.*; import java.util.concurrent.LinkedBlockingQueue; +import org.altusmetrum.AltosLib.*; public class AltosFlightInfoTableModel extends AbstractTableModel { final static private String[] columnNames = {"Field", "Value"}; diff --git a/altosui/AltosFlightStats.java b/altosui/AltosFlightStats.java index 72d12600..22f3e479 100644 --- a/altosui/AltosFlightStats.java +++ b/altosui/AltosFlightStats.java @@ -27,6 +27,7 @@ import java.util.*; import java.text.*; import java.util.prefs.*; import java.util.concurrent.*; +import org.altusmetrum.AltosLib.*; public class AltosFlightStats { double max_height; diff --git a/altosui/AltosFlightStatsTable.java b/altosui/AltosFlightStatsTable.java index 2d34c6e2..c311b231 100644 --- a/altosui/AltosFlightStatsTable.java +++ b/altosui/AltosFlightStatsTable.java @@ -27,6 +27,7 @@ import java.util.*; import java.text.*; import java.util.prefs.*; import java.util.concurrent.*; +import org.altusmetrum.AltosLib.*; public class AltosFlightStatsTable extends JComponent { GridBagLayout layout; diff --git a/altosui/AltosFlightStatus.java b/altosui/AltosFlightStatus.java index ed273384..cc22f0ab 100644 --- a/altosui/AltosFlightStatus.java +++ b/altosui/AltosFlightStatus.java @@ -27,6 +27,7 @@ import java.util.*; import java.text.*; import java.util.prefs.*; import java.util.concurrent.LinkedBlockingQueue; +import org.altusmetrum.AltosLib.*; public class AltosFlightStatus extends JComponent implements AltosFlightDisplay { GridBagLayout layout; diff --git a/altosui/AltosFlightStatusTableModel.java b/altosui/AltosFlightStatusTableModel.java index 4c24b6ac..75bf16eb 100644 --- a/altosui/AltosFlightStatusTableModel.java +++ b/altosui/AltosFlightStatusTableModel.java @@ -27,6 +27,7 @@ import java.util.*; import java.text.*; import java.util.prefs.*; import java.util.concurrent.LinkedBlockingQueue; +import org.altusmetrum.AltosLib.*; public class AltosFlightStatusTableModel extends AbstractTableModel { private String[] columnNames = {"Height (m)", "State", "RSSI (dBm)", "Speed (m/s)" }; diff --git a/altosui/AltosFlightUI.java b/altosui/AltosFlightUI.java index d166c9ae..c2363094 100644 --- a/altosui/AltosFlightUI.java +++ b/altosui/AltosFlightUI.java @@ -27,6 +27,7 @@ import java.util.*; import java.text.*; import java.util.prefs.*; import java.util.concurrent.*; +import org.altusmetrum.AltosLib.*; public class AltosFlightUI extends AltosFrame implements AltosFlightDisplay, AltosFontListener { AltosVoice voice; @@ -152,7 +153,7 @@ public class AltosFlightUI extends AltosFrame implements AltosFlightDisplay, Alt JComboBox telemetries; public AltosFlightUI(AltosVoice in_voice, AltosFlightReader in_reader, final int serial) { - AltosPreferences.set_component(this); + AltosUIPreferences.set_component(this); voice = in_voice; reader = in_reader; @@ -171,7 +172,7 @@ public class AltosFlightUI extends AltosFrame implements AltosFlightDisplay, Alt /* Stick channel selector at top of table for telemetry monitoring */ if (serial >= 0) { // Channel menu - frequencies = new AltosFreqList(AltosPreferences.frequency(serial)); + frequencies = new AltosFreqList(AltosUIPreferences.frequency(serial)); frequencies.set_product("Monitor"); frequencies.set_serial(serial); frequencies.addActionListener(new ActionListener() { @@ -198,7 +199,7 @@ public class AltosFlightUI extends AltosFrame implements AltosFlightDisplay, Alt telemetries = new JComboBox(); for (int i = 1; i <= Altos.ao_telemetry_max; i++) telemetries.addItem(Altos.telemetry_name(i)); - int telemetry = AltosPreferences.telemetry(serial); + int telemetry = AltosUIPreferences.telemetry(serial); if (telemetry <= Altos.ao_telemetry_off || telemetry > Altos.ao_telemetry_max) telemetry = Altos.ao_telemetry_standard; @@ -270,7 +271,7 @@ public class AltosFlightUI extends AltosFrame implements AltosFlightDisplay, Alt setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); - AltosPreferences.register_font_listener(this); + AltosUIPreferences.register_font_listener(this); addWindowListener(new WindowAdapter() { @Override @@ -278,7 +279,7 @@ public class AltosFlightUI extends AltosFrame implements AltosFlightDisplay, Alt disconnect(); setVisible(false); dispose(); - AltosPreferences.unregister_font_listener(AltosFlightUI.this); + AltosUIPreferences.unregister_font_listener(AltosFlightUI.this); if (exit_on_close) System.exit(0); } diff --git a/altosui/AltosFrame.java b/altosui/AltosFrame.java index f8cc4f52..70598634 100644 --- a/altosui/AltosFrame.java +++ b/altosui/AltosFrame.java @@ -27,12 +27,13 @@ import java.util.*; import java.text.*; import java.util.prefs.*; import java.util.concurrent.*; +import org.altusmetrum.AltosLib.*; import libaltosJNI.*; class AltosFrameListener extends WindowAdapter { public void windowClosing (WindowEvent e) { - AltosPreferences.unregister_ui_listener((AltosFrame) e.getWindow()); + AltosUIPreferences.unregister_ui_listener((AltosFrame) e.getWindow()); } } @@ -44,13 +45,13 @@ public class AltosFrame extends JFrame implements AltosUIListener { } public AltosFrame() { - AltosPreferences.register_ui_listener(this); + AltosUIPreferences.register_ui_listener(this); addWindowListener(new AltosFrameListener()); } public AltosFrame(String name) { super(name); - AltosPreferences.register_ui_listener(this); + AltosUIPreferences.register_ui_listener(this); addWindowListener(new AltosFrameListener()); } } diff --git a/altosui/AltosFreqList.java b/altosui/AltosFreqList.java index 59b0e127..1bbc97c6 100644 --- a/altosui/AltosFreqList.java +++ b/altosui/AltosFreqList.java @@ -27,6 +27,7 @@ import java.util.*; import java.text.*; import java.util.prefs.*; import java.util.concurrent.LinkedBlockingQueue; +import org.altusmetrum.AltosLib.*; public class AltosFreqList extends JComboBox { @@ -52,7 +53,7 @@ public class AltosFreqList extends JComboBox { } String description = String.format("%s serial %d", product, serial); AltosFrequency frequency = new AltosFrequency(new_frequency, description); - AltosPreferences.add_common_frequency(frequency); + AltosUIPreferences.add_common_frequency(frequency); insertItemAt(frequency, i); setMaximumRowCount(getItemCount()); } @@ -73,7 +74,7 @@ public class AltosFreqList extends JComboBox { } public AltosFreqList () { - super(AltosPreferences.common_frequencies()); + super(AltosUIPreferences.common_frequencies()); setMaximumRowCount(getItemCount()); setEditable(false); product = "Unknown"; diff --git a/altosui/AltosGraph.java b/altosui/AltosGraph.java index fbcefd61..54d2bb0b 100644 --- a/altosui/AltosGraph.java +++ b/altosui/AltosGraph.java @@ -8,6 +8,7 @@ import java.io.*; import org.jfree.chart.JFreeChart; import org.jfree.chart.ChartUtilities; +import org.altusmetrum.AltosLib.*; abstract class AltosGraph { public String filename; diff --git a/altosui/AltosGraphTime.java b/altosui/AltosGraphTime.java index 6a084b2c..0955f6e6 100644 --- a/altosui/AltosGraphTime.java +++ b/altosui/AltosGraphTime.java @@ -12,6 +12,7 @@ import java.text.*; import java.awt.Color; import java.util.ArrayList; import java.util.HashMap; +import org.altusmetrum.AltosLib.*; import org.jfree.chart.ChartUtilities; import org.jfree.chart.JFreeChart; diff --git a/altosui/AltosGraphUI.java b/altosui/AltosGraphUI.java index c30dc476..527a7d28 100644 --- a/altosui/AltosGraphUI.java +++ b/altosui/AltosGraphUI.java @@ -12,6 +12,7 @@ import java.awt.event.*; import javax.swing.*; import javax.swing.filechooser.FileNameExtensionFilter; import javax.swing.table.*; +import org.altusmetrum.AltosLib.*; import org.jfree.chart.ChartPanel; import org.jfree.chart.ChartUtilities; diff --git a/altosui/AltosHexfile.java b/altosui/AltosHexfile.java index 19e35ae1..d52b46c3 100644 --- a/altosui/AltosHexfile.java +++ b/altosui/AltosHexfile.java @@ -23,6 +23,7 @@ import java.util.concurrent.LinkedBlockingQueue; import java.util.LinkedList; import java.util.Iterator; import java.util.Arrays; +import org.altusmetrum.AltosLib.*; class HexFileInputStream extends PushbackInputStream { public int line; diff --git a/altosui/AltosIdleMonitorUI.java b/altosui/AltosIdleMonitorUI.java index a5f41e25..cde8e237 100644 --- a/altosui/AltosIdleMonitorUI.java +++ b/altosui/AltosIdleMonitorUI.java @@ -27,6 +27,7 @@ import java.util.*; import java.text.*; import java.util.prefs.*; import java.util.concurrent.*; +import org.altusmetrum.AltosLib.*; class AltosADC { int tick; @@ -333,12 +334,12 @@ public class AltosIdleMonitorUI extends AltosFrame implements AltosFlightDisplay /* Stick frequency selector at top of table for telemetry monitoring */ if (remote && serial >= 0) { // Frequency menu - frequencies = new AltosFreqList(AltosPreferences.frequency(serial)); + frequencies = new AltosFreqList(AltosUIPreferences.frequency(serial)); frequencies.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { double frequency = frequencies.frequency(); thread.set_frequency(frequency); - AltosPreferences.set_frequency(device.getSerial(), + AltosUIPreferences.set_frequency(device.getSerial(), frequency); } }); @@ -382,7 +383,7 @@ public class AltosIdleMonitorUI extends AltosFrame implements AltosFlightDisplay setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); - AltosPreferences.register_font_listener(this); + AltosUIPreferences.register_font_listener(this); addWindowListener(new WindowAdapter() { @Override @@ -390,7 +391,7 @@ public class AltosIdleMonitorUI extends AltosFrame implements AltosFlightDisplay disconnect(); setVisible(false); dispose(); - AltosPreferences.unregister_font_listener(AltosIdleMonitorUI.this); + AltosUIPreferences.unregister_font_listener(AltosIdleMonitorUI.this); } }); diff --git a/altosui/AltosIgnite.java b/altosui/AltosIgnite.java index 3e52ea36..c0cd44f1 100644 --- a/altosui/AltosIgnite.java +++ b/altosui/AltosIgnite.java @@ -25,6 +25,7 @@ import javax.swing.*; import javax.swing.filechooser.FileNameExtensionFilter; import javax.swing.table.*; import javax.swing.event.*; +import org.altusmetrum.AltosLib.*; public class AltosIgnite { AltosDevice device; diff --git a/altosui/AltosIgniteUI.java b/altosui/AltosIgniteUI.java index 8623cbef..076d99b2 100644 --- a/altosui/AltosIgniteUI.java +++ b/altosui/AltosIgniteUI.java @@ -28,6 +28,7 @@ import java.util.*; import java.text.*; import java.util.prefs.*; import java.util.concurrent.*; +import org.altusmetrum.AltosLib.*; public class AltosIgniteUI extends AltosDialog diff --git a/altosui/AltosInfoTable.java b/altosui/AltosInfoTable.java index c023369e..aa6a6d4e 100644 --- a/altosui/AltosInfoTable.java +++ b/altosui/AltosInfoTable.java @@ -27,6 +27,7 @@ import java.util.*; import java.text.*; import java.util.prefs.*; import java.util.concurrent.LinkedBlockingQueue; +import org.altusmetrum.AltosLib.*; public class AltosInfoTable extends JTable { private AltosFlightInfoTableModel model; diff --git a/altosui/AltosKML.java b/altosui/AltosKML.java index 6bdbecca..2993607b 100644 --- a/altosui/AltosKML.java +++ b/altosui/AltosKML.java @@ -21,6 +21,7 @@ import java.lang.*; import java.io.*; import java.text.*; import java.util.*; +import org.altusmetrum.AltosLib.*; public class AltosKML implements AltosWriter { diff --git a/altosui/AltosLanded.java b/altosui/AltosLanded.java index 4dd9a2dd..a47e1cbd 100644 --- a/altosui/AltosLanded.java +++ b/altosui/AltosLanded.java @@ -27,6 +27,7 @@ import java.util.*; import java.text.*; import java.util.prefs.*; import java.util.concurrent.LinkedBlockingQueue; +import org.altusmetrum.AltosLib.*; public class AltosLanded extends JComponent implements AltosFlightDisplay, ActionListener { GridBagLayout layout; diff --git a/altosui/AltosLaunch.java b/altosui/AltosLaunch.java index 77f681b8..0e493b91 100644 --- a/altosui/AltosLaunch.java +++ b/altosui/AltosLaunch.java @@ -25,6 +25,7 @@ import javax.swing.*; import javax.swing.filechooser.FileNameExtensionFilter; import javax.swing.table.*; import javax.swing.event.*; +import org.altusmetrum.AltosLib.*; public class AltosLaunch { AltosDevice device; diff --git a/altosui/AltosLaunchUI.java b/altosui/AltosLaunchUI.java index 73fae16b..eb76243d 100644 --- a/altosui/AltosLaunchUI.java +++ b/altosui/AltosLaunchUI.java @@ -28,6 +28,7 @@ import java.util.*; import java.text.*; import java.util.prefs.*; import java.util.concurrent.*; +import org.altusmetrum.AltosLib.*; class FireButton extends JButton { protected void processMouseEvent(MouseEvent e) { @@ -316,7 +317,7 @@ public class AltosLaunchUI void set_serial() { try { launcher_serial = Integer.parseInt(launcher_serial_text.getText()); - AltosPreferences.set_launcher_serial(launcher_serial); + AltosUIPreferences.set_launcher_serial(launcher_serial); send_command("set_remote"); } catch (NumberFormatException ne) { launcher_serial_text.setText(String.format("%d", launcher_serial)); @@ -326,7 +327,7 @@ public class AltosLaunchUI void set_channel() { try { launcher_channel = Integer.parseInt(launcher_channel_text.getText()); - AltosPreferences.set_launcher_serial(launcher_channel); + AltosUIPreferences.set_launcher_serial(launcher_channel); send_command("set_remote"); } catch (NumberFormatException ne) { launcher_channel_text.setText(String.format("%d", launcher_channel)); @@ -388,8 +389,8 @@ public class AltosLaunchUI public AltosLaunchUI(JFrame in_owner) { - launcher_channel = AltosPreferences.launcher_channel(); - launcher_serial = AltosPreferences.launcher_serial(); + launcher_channel = AltosUIPreferences.launcher_channel(); + launcher_serial = AltosUIPreferences.launcher_serial(); owner = in_owner; armed_status = AltosLaunch.Unknown; igniter_status = AltosLaunch.Unknown; diff --git a/altosui/AltosLed.java b/altosui/AltosLed.java index e08e9960..1358cd48 100644 --- a/altosui/AltosLed.java +++ b/altosui/AltosLed.java @@ -27,6 +27,7 @@ import java.util.*; import java.text.*; import java.util.prefs.*; import java.util.concurrent.LinkedBlockingQueue; +import org.altusmetrum.AltosLib.*; public class AltosLed extends JLabel { ImageIcon on, off; diff --git a/altosui/AltosLights.java b/altosui/AltosLights.java index 2fa38412..8bd9e7de 100644 --- a/altosui/AltosLights.java +++ b/altosui/AltosLights.java @@ -27,6 +27,7 @@ import java.util.*; import java.text.*; import java.util.prefs.*; import java.util.concurrent.LinkedBlockingQueue; +import org.altusmetrum.AltosLib.*; public class AltosLights extends JComponent { diff --git a/altosui/AltosPad.java b/altosui/AltosPad.java index 6ef66f7a..0a3f3d65 100644 --- a/altosui/AltosPad.java +++ b/altosui/AltosPad.java @@ -27,6 +27,7 @@ import java.util.*; import java.text.*; import java.util.prefs.*; import java.util.concurrent.LinkedBlockingQueue; +import org.altusmetrum.AltosLib.*; public class AltosPad extends JComponent implements AltosFlightDisplay { GridBagLayout layout; diff --git a/altosui/AltosReader.java b/altosui/AltosReader.java deleted file mode 100644 index b9280a0c..00000000 --- a/altosui/AltosReader.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright © 2010 Keith Packard <keithp@keithp.com> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. - */ - -package altosui; - -import java.io.*; -import java.util.*; -import java.text.*; - -public class AltosReader { - public AltosRecord read() throws IOException, ParseException { return null; } - public void close() { } - public void write_comments(PrintStream out) { } -} diff --git a/altosui/AltosRomconfig.java b/altosui/AltosRomconfig.java index 55056b5e..0a283e51 100644 --- a/altosui/AltosRomconfig.java +++ b/altosui/AltosRomconfig.java @@ -17,6 +17,7 @@ package altosui; import java.io.*; +import org.altusmetrum.AltosLib.*; public class AltosRomconfig { public boolean valid; diff --git a/altosui/AltosRomconfigUI.java b/altosui/AltosRomconfigUI.java index e4e38c9c..306b8623 100644 --- a/altosui/AltosRomconfigUI.java +++ b/altosui/AltosRomconfigUI.java @@ -27,6 +27,7 @@ import java.io.*; import java.util.*; import java.text.*; import java.util.prefs.*; +import org.altusmetrum.AltosLib.*; public class AltosRomconfigUI extends AltosDialog diff --git a/altosui/AltosScanUI.java b/altosui/AltosScanUI.java index e188834e..44eeda6d 100644 --- a/altosui/AltosScanUI.java +++ b/altosui/AltosScanUI.java @@ -28,6 +28,7 @@ import java.util.*; import java.text.*; import java.util.prefs.*; import java.util.concurrent.*; +import org.altusmetrum.AltosLib.*; class AltosScanResult { String callsign; @@ -207,7 +208,7 @@ public class AltosScanUI } void next() throws InterruptedException, TimeoutException { - reader.serial.set_monitor(false); + reader.set_monitor(false); Thread.sleep(100); ++frequency_index; if (frequency_index >= frequencies.length || @@ -223,7 +224,7 @@ public class AltosScanUI } set_frequency(); set_label(); - reader.serial.set_monitor(true); + reader.set_monitor(true); } @@ -267,7 +268,7 @@ public class AltosScanUI scanning_telemetry |= (1 << Altos.ao_telemetry_standard); telemetry_boxes[Altos.ao_telemetry_standard - Altos.ao_telemetry_min].setSelected(true); } - AltosPreferences.set_scanning_telemetry(scanning_telemetry); + AltosUIPreferences.set_scanning_telemetry(scanning_telemetry); } if (cmd.equals("monitor")) { @@ -311,7 +312,7 @@ public class AltosScanUI if (device == null) return false; try { - reader = new AltosTelemetryReader(device); + reader = new AltosTelemetryReader(new AltosSerial(device)); set_frequency(); set_telemetry(); try { @@ -359,7 +360,7 @@ public class AltosScanUI owner = in_owner; - frequencies = AltosPreferences.common_frequencies(); + frequencies = AltosUIPreferences.common_frequencies(); frequency_index = 0; telemetry = Altos.ao_telemetry_min; @@ -400,7 +401,7 @@ public class AltosScanUI c.gridy = 2; pane.add(telemetry_label, c); - int scanning_telemetry = AltosPreferences.scanning_telemetry(); + int scanning_telemetry = AltosUIPreferences.scanning_telemetry(); 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; diff --git a/altosui/AltosSerial.java b/altosui/AltosSerial.java index 4cf306d0..9ed4afdb 100644 --- a/altosui/AltosSerial.java +++ b/altosui/AltosSerial.java @@ -31,6 +31,7 @@ import java.awt.event.*; import javax.swing.*; import javax.swing.filechooser.FileNameExtensionFilter; import javax.swing.table.*; +import org.altusmetrum.AltosLib.*; import libaltosJNI.*; @@ -40,33 +41,19 @@ import libaltosJNI.*; * threads. */ -public class AltosSerial implements Runnable { +public class AltosSerial extends AltosLink implements Runnable { static java.util.List<String> devices_opened = Collections.synchronizedList(new LinkedList<String>()); AltosDevice device; SWIGTYPE_p_altos_file altos; - LinkedList<LinkedBlockingQueue<AltosLine>> monitors; - LinkedBlockingQueue<AltosLine> reply_queue; Thread input_thread; - String line; - byte[] line_bytes; - int line_count; - boolean monitor_mode; - int telemetry; - double frequency; - static boolean debug; - boolean remote; - LinkedList<String> pending_output = new LinkedList<String>(); Frame frame; - AltosConfigData config_data; - - static void set_debug(boolean new_debug) { - debug = new_debug; - } public void run () { int c; + byte[] line_bytes = null; + int line_count = 0; try { for (;;) { @@ -74,11 +61,8 @@ public class AltosSerial implements Runnable { if (Thread.interrupted()) break; if (c == libaltosConstants.LIBALTOS_ERROR) { - for (int e = 0; e < monitors.size(); e++) { - LinkedBlockingQueue<AltosLine> q = monitors.get(e); - q.put(new AltosLine()); - } - reply_queue.put (new AltosLine()); + add_telem (new AltosLine()); + add_reply (new AltosLine()); break; } if (c == libaltosConstants.LIBALTOS_TIMEOUT) @@ -88,25 +72,8 @@ public class AltosSerial implements Runnable { synchronized(this) { if (c == '\n') { if (line_count != 0) { - try { - line = new String(line_bytes, 0, line_count, "UTF-8"); - } catch (UnsupportedEncodingException ue) { - line = ""; - for (int i = 0; i < line_count; i++) - line = line + line_bytes[i]; - } - if (debug) - System.out.printf("\t\t\t\t\t%s\n", line); - if (line.startsWith("TELEM") || line.startsWith("VERSION") || line.startsWith("CRC")) { - for (int e = 0; e < monitors.size(); e++) { - LinkedBlockingQueue<AltosLine> q = monitors.get(e); - q.put(new AltosLine (line)); - } - } else { - reply_queue.put(new AltosLine (line)); - } + add_bytes(line_bytes, line_count); line_count = 0; - line = ""; } } else { if (line_bytes == null) { @@ -126,10 +93,8 @@ public class AltosSerial implements Runnable { } public void flush_output() { + super.flush_output(); if (altos != null) { - for (String s : pending_output) - System.out.print(s); - pending_output.clear(); libaltos.altos_flush(altos); } } @@ -188,22 +153,10 @@ public class AltosSerial implements Runnable { } public void flush_input() throws InterruptedException { - flush_output(); - boolean got_some; - - int timeout = 100; if (remote) - timeout = 500; - do { - Thread.sleep(timeout); - got_some = !reply_queue.isEmpty(); - synchronized(this) { - if (!"VERSION".startsWith(line) && - !line.startsWith("VERSION")) - line = ""; - reply_queue.clear(); - } - } while (got_some); + flush_input(500); + else + flush_input(100); } int in_reply; @@ -244,29 +197,6 @@ public class AltosSerial implements Runnable { return reply; } - public String get_reply() throws InterruptedException { - return get_reply(5000); - } - - public String get_reply_no_dialog(int timeout) throws InterruptedException, TimeoutException { - flush_output(); - AltosLine line = reply_queue.poll(timeout, TimeUnit.MILLISECONDS); - if (line != null) - return line.line; - return null; - } - - public void add_monitor(LinkedBlockingQueue<AltosLine> q) { - set_monitor(true); - monitors.add(q); - } - - public void remove_monitor(LinkedBlockingQueue<AltosLine> q) { - monitors.remove(q); - if (monitors.isEmpty()) - set_monitor(false); - } - public void close() { if (remote) { try { @@ -305,16 +235,10 @@ public class AltosSerial implements Runnable { } public void print(String data) { - if (debug) - pending_output.add(data); for (int i = 0; i < data.length(); i++) putc(data.charAt(i)); } - public void printf(String format, Object ... arguments) { - print(String.format(format, arguments)); - } - private void open() throws FileNotFoundException, AltosSerialInUseException { synchronized (devices_opened) { if (devices_opened.contains(device.getPath())) @@ -337,120 +261,15 @@ public class AltosSerial implements Runnable { flush_output(); } - private int telemetry_len() { - return Altos.telemetry_len(telemetry); - } - - private void set_channel(int channel) { - if (altos != null) { - if (monitor_mode) - printf("m 0\nc r %d\nm %x\n", - channel, telemetry_len()); - else - printf("c r %d\n", channel); - flush_output(); - } - } - - private void set_radio_setting(int setting) { - if (altos != null) { - if (monitor_mode) - printf("m 0\nc R %d\nm %x\n", - setting, telemetry_len()); - else - printf("c R %d\n", setting); - flush_output(); - } - } - - public void set_radio_frequency(double frequency, - boolean has_setting, - int cal) { - if (debug) - System.out.printf("set_radio_frequency %7.3f %b %d\n", frequency, has_setting, cal); - if (has_setting) - set_radio_setting(AltosConvert.radio_frequency_to_setting(frequency, cal)); - else - set_channel(AltosConvert.radio_frequency_to_channel(frequency)); - } - - public void set_radio_frequency(double in_frequency) throws InterruptedException, TimeoutException { - frequency = in_frequency; - config_data(); - set_radio_frequency(frequency, - config_data.radio_setting != 0, - config_data.radio_calibration); - } - - public void set_telemetry(int in_telemetry) { - telemetry = in_telemetry; - if (altos != null) { - if (monitor_mode) - printf("m 0\nm %x\n", telemetry_len()); - flush_output(); - } - } - - void set_monitor(boolean monitor) { - monitor_mode = monitor; - if (altos != null) { - if (monitor) - printf("m %x\n", telemetry_len()); - else - printf("m 0\n"); - flush_output(); - } - } - - public void set_callsign(String callsign) { - if (altos != null) { - printf ("c c %s\n", callsign); - flush_output(); - } - } - - public AltosConfigData config_data() throws InterruptedException, TimeoutException { - if (config_data == null) - config_data = new AltosConfigData(this); - return config_data; - } - - public void start_remote() throws TimeoutException, InterruptedException { - if (debug) - System.out.printf("start remote %7.3f\n", frequency); - if (frequency == 0.0) - frequency = AltosPreferences.frequency(device.getSerial()); - set_radio_frequency(frequency); - set_callsign(AltosPreferences.callsign()); - printf("p\nE 0\n"); - flush_input(); - remote = true; - } - - public void stop_remote() throws InterruptedException { - if (debug) - System.out.printf("stop remote\n"); - try { - flush_input(); - } finally { - printf ("~\n"); - flush_output(); - } - remote = false; - } - public void set_frame(Frame in_frame) { frame = in_frame; } public AltosSerial(AltosDevice in_device) throws FileNotFoundException, AltosSerialInUseException { device = in_device; - line = ""; - monitor_mode = false; frame = null; - telemetry = Altos.ao_telemetry_standard; - monitors = new LinkedList<LinkedBlockingQueue<AltosLine>> (); - reply_queue = new LinkedBlockingQueue<AltosLine> (); + serial = device.getSerial(); + name = device.toShortString(); open(); } } diff --git a/altosui/AltosSerialMonitor.java b/altosui/AltosSerialMonitor.java deleted file mode 100644 index ad0e9295..00000000 --- a/altosui/AltosSerialMonitor.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright © 2010 Keith Packard <keithp@keithp.com> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. - */ - -package altosui; - -public interface AltosSerialMonitor { - void data(String data); -} diff --git a/altosui/AltosSiteMap.java b/altosui/AltosSiteMap.java index c258b3e5..25077173 100644 --- a/altosui/AltosSiteMap.java +++ b/altosui/AltosSiteMap.java @@ -31,6 +31,7 @@ import java.util.prefs.*; import java.lang.Math; import java.awt.geom.Point2D; import java.awt.geom.Line2D; +import org.altusmetrum.AltosLib.*; public class AltosSiteMap extends JScrollPane implements AltosFlightDisplay { // preferred vertical step in a tile in naut. miles @@ -249,7 +250,7 @@ public class AltosSiteMap extends JScrollPane implements AltosFlightDisplay { char chlng = lng < 0 ? 'W' : 'E'; if (lat < 0) lat = -lat; if (lng < 0) lng = -lng; - return new File(AltosPreferences.mapdir(), + return new File(AltosUIPreferences.mapdir(), String.format("map-%c%.6f,%c%.6f-%d.png", chlat, lat, chlng, lng, zoom)); } diff --git a/altosui/AltosSiteMapCache.java b/altosui/AltosSiteMapCache.java index 2e62cc45..f729a298 100644 --- a/altosui/AltosSiteMapCache.java +++ b/altosui/AltosSiteMapCache.java @@ -29,6 +29,7 @@ import java.text.*; import java.util.prefs.*; import java.net.URL; import java.net.URLConnection; +import org.altusmetrum.AltosLib.*; public class AltosSiteMapCache extends JLabel { public static boolean fetchMap(File file, String url) { diff --git a/altosui/AltosSiteMapPreload.java b/altosui/AltosSiteMapPreload.java index 5de7a05e..676b0790 100644 --- a/altosui/AltosSiteMapPreload.java +++ b/altosui/AltosSiteMapPreload.java @@ -33,6 +33,7 @@ import java.awt.geom.Point2D; import java.awt.geom.Line2D; import java.net.URL; import java.net.URLConnection; +import org.altusmetrum.AltosLib.*; class AltosMapPos extends Box { AltosUI owner; diff --git a/altosui/AltosSiteMapTile.java b/altosui/AltosSiteMapTile.java index 9e62bb47..34550219 100644 --- a/altosui/AltosSiteMapTile.java +++ b/altosui/AltosSiteMapTile.java @@ -30,6 +30,7 @@ import java.util.prefs.*; import java.lang.Math; import java.awt.geom.Point2D; import java.awt.geom.Line2D; +import org.altusmetrum.AltosLib.*; public class AltosSiteMapTile extends JLayeredPane { JLabel mapLabel; diff --git a/altosui/AltosUI.java b/altosui/AltosUI.java index 8799d560..125653d3 100644 --- a/altosui/AltosUI.java +++ b/altosui/AltosUI.java @@ -27,6 +27,7 @@ import java.util.*; import java.text.*; import java.util.prefs.*; import java.util.concurrent.*; +import org.altusmetrum.AltosLib.*; import libaltosJNI.*; @@ -47,7 +48,7 @@ public class AltosUI extends AltosFrame { void telemetry_window(AltosDevice device) { try { - AltosFlightReader reader = new AltosTelemetryReader(device); + AltosFlightReader reader = new AltosTelemetryReader(new AltosSerial(device)); if (reader != null) new AltosFlightUI(voice, reader, device.getSerial()); } catch (FileNotFoundException ee) { @@ -108,7 +109,7 @@ public class AltosUI extends AltosFrame { if (imgURL != null) setIconImage(new ImageIcon(imgURL).getImage()); - AltosPreferences.set_component(this); + AltosUIPreferences.set_component(this); pane = getContentPane(); gridbag = new GridBagLayout(); @@ -253,9 +254,9 @@ public class AltosUI extends AltosFrame { String result; result = JOptionPane.showInputDialog(AltosUI.this, "Configure Callsign", - AltosPreferences.callsign()); + AltosUIPreferences.callsign()); if (result != null) - AltosPreferences.set_callsign(result); + AltosUIPreferences.set_callsign(result); } void ConfigureTeleMetrum() { @@ -519,7 +520,7 @@ public class AltosUI extends AltosFrame { public static void main(final String[] args) { try { - UIManager.setLookAndFeel(AltosPreferences.look_and_feel()); + UIManager.setLookAndFeel(AltosUIPreferences.look_and_feel()); } catch (Exception e) { } /* Handle batch-mode */ diff --git a/altosui/AltosUIPreferences.java b/altosui/AltosUIPreferences.java new file mode 100644 index 00000000..10ab26c3 --- /dev/null +++ b/altosui/AltosUIPreferences.java @@ -0,0 +1,176 @@ +/* + * Copyright © 2011 Keith Packard <keithp@keithp.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ + +package altosui; + +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; +import org.altusmetrum.AltosLib.*; + +public class AltosUIPreferences extends AltosPreferences { + + /* font size preferences name */ + final static String fontSizePreference = "FONT-SIZE"; + + /* Look&Feel preference name */ + final static String lookAndFeelPreference = "LOOK-AND-FEEL"; + + /* UI Component to pop dialogs up */ + static Component component; + + static LinkedList<AltosFontListener> font_listeners; + + static int font_size = Altos.font_size_medium; + + static LinkedList<AltosUIListener> ui_listeners; + + static String look_and_feel = null; + + /* Serial debug */ + static boolean serial_debug; + + public static void init() { + font_listeners = new LinkedList<AltosFontListener>(); + + font_size = preferences.getInt(fontSizePreference, Altos.font_size_medium); + Altos.set_fonts(font_size); + look_and_feel = preferences.get(lookAndFeelPreference, UIManager.getSystemLookAndFeelClassName()); + + ui_listeners = new LinkedList<AltosUIListener>(); + serial_debug = preferences.getBoolean(serialDebugPreference, false); + AltosLink.set_debug(serial_debug); + } + + static { init(); } + + static void set_component(Component in_component) { + component = in_component; + } + + private static boolean check_dir(File dir) { + if (!dir.exists()) { + if (!dir.mkdirs()) { + JOptionPane.showMessageDialog(component, + dir.getName(), + "Cannot create directory", + JOptionPane.ERROR_MESSAGE); + return false; + } + } else if (!dir.isDirectory()) { + JOptionPane.showMessageDialog(component, + dir.getName(), + "Is not a directory", + JOptionPane.ERROR_MESSAGE); + return false; + } + return true; + } + + /* Configure the log directory. This is where all telemetry and eeprom files + * will be written to, and where replay will look for telemetry files + */ + public static void ConfigureLog() { + JFileChooser logdir_chooser = new JFileChooser(logdir.getParentFile()); + + logdir_chooser.setDialogTitle("Configure Data Logging Directory"); + logdir_chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); + + if (logdir_chooser.showDialog(component, "Select Directory") == JFileChooser.APPROVE_OPTION) { + File dir = logdir_chooser.getSelectedFile(); + if (check_dir(dir)) + set_logdir(dir); + } + } + public static int font_size() { + return font_size; + } + + static void set_fonts() { + } + + public static void set_font_size(int new_font_size) { + font_size = new_font_size; + synchronized (preferences) { + preferences.putInt(fontSizePreference, font_size); + flush_preferences(); + Altos.set_fonts(font_size); + for (AltosFontListener l : font_listeners) + l.font_size_changed(font_size); + } + } + + public static void register_font_listener(AltosFontListener l) { + synchronized (preferences) { + font_listeners.add(l); + } + } + + public static void unregister_font_listener(AltosFontListener l) { + synchronized (preferences) { + font_listeners.remove(l); + } + } + + public static void set_look_and_feel(String new_look_and_feel) { + look_and_feel = new_look_and_feel; + try { + UIManager.setLookAndFeel(look_and_feel); + } catch (Exception e) { + } + synchronized(preferences) { + preferences.put(lookAndFeelPreference, look_and_feel); + flush_preferences(); + for (AltosUIListener l : ui_listeners) + l.ui_changed(look_and_feel); + } + } + + public static String look_and_feel() { + return look_and_feel; + } + + public static void register_ui_listener(AltosUIListener l) { + synchronized(preferences) { + ui_listeners.add(l); + } + } + + public static void unregister_ui_listener(AltosUIListener l) { + synchronized (preferences) { + ui_listeners.remove(l); + } + } + public static void set_serial_debug(boolean new_serial_debug) { + serial_debug = new_serial_debug; + AltosLink.set_debug(serial_debug); + synchronized (preferences) { + preferences.putBoolean(serialDebugPreference, serial_debug); + flush_preferences(); + } + } + + public static boolean serial_debug() { + return serial_debug; + } + +}
\ No newline at end of file diff --git a/altosui/AltosVoice.java b/altosui/AltosVoice.java index ac13ee14..ab74e0b3 100644 --- a/altosui/AltosVoice.java +++ b/altosui/AltosVoice.java @@ -65,7 +65,7 @@ public class AltosVoice implements Runnable { } public void speak(String s) { - if (AltosPreferences.voice()) + if (AltosUIPreferences.voice()) speak_always(s); } diff --git a/altosui/AltosWriter.java b/altosui/AltosWriter.java index a172dff0..b7375204 100644 --- a/altosui/AltosWriter.java +++ b/altosui/AltosWriter.java @@ -21,6 +21,8 @@ import java.lang.*; import java.io.*; import java.text.*; import java.util.*; +import org.altusmetrum.AltosLib.*; + public interface AltosWriter { diff --git a/altosui/GrabNDrag.java b/altosui/GrabNDrag.java index e6b87b58..c350efec 100644 --- a/altosui/GrabNDrag.java +++ b/altosui/GrabNDrag.java @@ -27,6 +27,7 @@ import javax.swing.table.*; import java.io.*; import java.util.*; import java.text.*; +import org.altusmetrum.AltosLib.*; class GrabNDrag extends MouseInputAdapter { private JComponent scroll; diff --git a/altosui/Makefile.am b/altosui/Makefile.am index fc024fff..a5003635 100644 --- a/altosui/Makefile.am +++ b/altosui/Makefile.am @@ -1,4 +1,4 @@ -SUBDIRS=libaltos +SUBDIRS=libaltos altoslib JAVAROOT=classes AM_JAVACFLAGS=-encoding UTF-8 -Xlint:deprecation @@ -6,7 +6,7 @@ man_MANS=altosui.1 altoslibdir=$(libdir)/altos -CLASSPATH_ENV=mkdir -p $(JAVAROOT); CLASSPATH=".:classes:libaltos:$(FREETTS)/*:/usr/share/java/*" +CLASSPATH_ENV=mkdir -p $(JAVAROOT); CLASSPATH=".:classes:altoslib/bin:libaltos:$(FREETTS)/*:/usr/share/java/*" bin_SCRIPTS=altosui @@ -22,12 +22,9 @@ altosui_JAVA = \ AltosChannelMenu.java \ AltosCompanionInfo.java \ AltosConfig.java \ - AltosConfigData.java \ AltosConfigFreqUI.java \ AltosConfigUI.java \ AltosConfigureUI.java \ - AltosConvert.java \ - AltosCRCException.java \ AltosCSV.java \ AltosCSVUI.java \ AltosDebug.java \ @@ -36,33 +33,22 @@ altosui_JAVA = \ AltosDevice.java \ AltosUSBDevice.java \ AltosDisplayThread.java \ - AltosEepromChunk.java \ AltosEepromDelete.java \ AltosEepromDownload.java \ AltosEepromList.java \ - AltosEepromLog.java \ AltosEepromManage.java \ AltosEepromMonitor.java \ - AltosEepromIterable.java \ - AltosEepromRecord.java \ - AltosEepromTeleScience.java \ AltosEepromSelect.java \ - AltosFile.java \ AltosFlash.java \ AltosFlashUI.java \ AltosFlightDisplay.java \ AltosFlightInfoTableModel.java \ - AltosFlightReader.java \ AltosFlightStats.java \ AltosFlightStatsTable.java \ AltosFlightStatus.java \ AltosFlightUI.java \ AltosFontListener.java \ - AltosFrequency.java \ AltosFreqList.java \ - AltosGPS.java \ - AltosGPSSat.java \ - AltosGreatCircle.java \ AltosHexfile.java \ Altos.java \ AltosIdleMonitorUI.java \ @@ -75,40 +61,17 @@ altosui_JAVA = \ AltosLanded.java \ AltosLed.java \ AltosLights.java \ - AltosLine.java \ - AltosLog.java \ AltosPad.java \ - AltosParse.java \ - AltosPreferences.java \ - AltosReader.java \ - AltosRecord.java \ - AltosRecordCompanion.java \ - AltosRecordIterable.java \ - AltosTelemetryReader.java \ - AltosTelemetryRecord.java \ - AltosTelemetryRecordGeneral.java \ - AltosTelemetryRecordRaw.java \ - AltosTelemetryRecordSensor.java \ - AltosTelemetryRecordConfiguration.java \ - AltosTelemetryRecordLocation.java \ - AltosTelemetryRecordSatellite.java \ - AltosTelemetryRecordCompanion.java \ - AltosTelemetryRecordLegacy.java \ - AltosTelemetryMap.java \ - AltosReplayReader.java \ + AltosUIPreferences.java \ AltosRomconfig.java \ AltosRomconfigUI.java \ AltosScanUI.java \ AltosSerial.java \ AltosSerialInUseException.java \ - AltosSerialMonitor.java \ AltosSiteMap.java \ AltosSiteMapPreload.java \ AltosSiteMapCache.java \ AltosSiteMapTile.java \ - AltosState.java \ - AltosTelemetry.java \ - AltosTelemetryIterable.java \ AltosUI.java \ AltosUIListener.java \ AltosFrame.java \ @@ -139,6 +102,9 @@ FREETTS_CLASS= \ en_us.jar \ freetts.jar +ALTOSLIB_CLASS=\ + AltosLib.jar + LIBALTOS= \ libaltos.so \ libaltos.dylib \ @@ -191,7 +157,7 @@ LINUX_DIST=Altos-Linux-$(VERSION).tar.bz2 MACOSX_DIST=Altos-Mac-$(VERSION).zip WINDOWS_DIST=Altos-Windows-$(VERSION_DASH).exe -FAT_FILES=$(FATJAR) $(FREETTS_CLASS) $(JFREECHART_CLASS) $(JCOMMON_CLASS) +FAT_FILES=$(FATJAR) $(ALTOSLIB_CLASS) $(FREETTS_CLASS) $(JFREECHART_CLASS) $(JCOMMON_CLASS) LINUX_FILES=$(FAT_FILES) libaltos.so $(FIRMWARE) $(DOC) LINUX_EXTRA=altosui-fat @@ -205,7 +171,7 @@ all-local: classes/altosui $(JAR) altosui altosui-test altosui-jdb clean-local: -rm -rf classes $(JAR) $(FATJAR) \ - $(LINUX_DIST) $(MACOSX_DIST) windows $(WINDOWS_DIST) $(FREETTS_CLASS) \ + $(LINUX_DIST) $(MACOSX_DIST) windows $(WINDOWS_DIST) $(ALTOSLIB_CLASS) $(FREETTS_CLASS) \ $(JFREECHART_CLASS) $(JCOMMON_CLASS) $(LIBALTOS) Manifest.txt Manifest-fat.txt altos-windows.log \ altosui altosui-test altosui-jdb macosx linux @@ -247,13 +213,13 @@ install-altosuiJAVA: altosui.jar classes/altosui: mkdir -p classes/altosui -$(JAR): classaltosui.stamp Manifest.txt $(JAVA_ICON) +$(JAR): classaltosui.stamp Manifest.txt $(JAVA_ICON) $(ALTOSLIB_CLASS) jar cfm $@ Manifest.txt \ $(ICONJAR) \ -C classes altosui \ -C libaltos libaltosJNI -$(FATJAR): classaltosui.stamp Manifest-fat.txt $(FREETTS_CLASS) $(JFREECHART_CLASS) $(JCOMMON_CLASS) $(LIBALTOS) $(JAVA_ICON) +$(FATJAR): classaltosui.stamp Manifest-fat.txt $(ALTOSLIB_CLASS) $(FREETTS_CLASS) $(JFREECHART_CLASS) $(JCOMMON_CLASS) $(LIBALTOS) $(JAVA_ICON) jar cfm $@ Manifest-fat.txt \ $(ICONJAR) \ -C classes altosui \ @@ -261,11 +227,11 @@ $(FATJAR): classaltosui.stamp Manifest-fat.txt $(FREETTS_CLASS) $(JFREECHART_CLA Manifest.txt: Makefile echo 'Main-Class: altosui.AltosUI' > $@ - echo "Class-Path: $(FREETTS)/freetts.jar $(JFREECHART)/jfreechart.jar $(JCOMMON)/jcommon.jar" >> $@ + echo "Class-Path: AltosLib.jar $(FREETTS)/freetts.jar $(JFREECHART)/jfreechart.jar $(JCOMMON)/jcommon.jar" >> $@ Manifest-fat.txt: echo 'Main-Class: altosui.AltosUI' > $@ - echo "Class-Path: freetts.jar jfreechart.jar jcommon.jar" >> $@ + echo "Class-Path: AltosLib.jar freetts.jar jfreechart.jar jcommon.jar" >> $@ altosui: Makefile echo "#!/bin/sh" > $@ @@ -274,7 +240,7 @@ altosui: Makefile altosui-test: Makefile echo "#!/bin/sh" > $@ - echo 'exec java -cp "$(FREETTS)/*:$(JFREECHART)/*:$(JCOMMON)/*" -Djava.library.path="libaltos/.libs" -jar altosui.jar "$$@"' >> $@ + echo 'exec java -cp "./*:$(FREETTS)/*:$(JFREECHART)/*:$(JCOMMON)/*" -Djava.library.path="libaltos/.libs" -jar altosui.jar "$$@"' >> $@ chmod +x $@ altosui-jdb: Makefile @@ -308,6 +274,10 @@ build-altos-dll: build-altos64-dll: +cd libaltos && make altos64.dll +$(ALTOSLIB_CLASS): + -rm -f "$@" + $(LN_S) altoslib/"$@" . + $(FREETTS_CLASS): -rm -f "$@" $(LN_S) "$(FREETTS)"/"$@" . @@ -336,9 +306,11 @@ $(MACOSX_DIST): $(MACOSX_FILES) $(MACOSX_EXTRA) cp -a AltosUI.app macosx/ mkdir -p macosx/AltOS macosx/AltosUI.app/Contents/Resources/Java cp -p $(FATJAR) macosx/AltosUI.app/Contents/Resources/Java/altosui.jar - cp -p $(FREETTS_CLASS) libaltos.dylib macosx/AltosUI.app/Contents/Resources/Java - cp -p $(JFREECHART_CLASS) libaltos.dylib macosx/AltosUI.app/Contents/Resources/Java - cp -p $(JCOMMON_CLASS) libaltos.dylib macosx/AltosUI.app/Contents/Resources/Java + cp -p libaltos.dylib macosx/AltosUI.app/Contents/Resources/Java + cp -p $(ALTOSLIB_CLASS) macosx/AltosUI.app/Contents/Resources/Java + cp -p $(FREETTS_CLASS) macosx/AltosUI.app/Contents/Resources/Java + cp -p $(JFREECHART_CLASS) macosx/AltosUI.app/Contents/Resources/Java + cp -p $(JCOMMON_CLASS) macosx/AltosUI.app/Contents/Resources/Java cp -p $(MACOSX_EXTRA) macosx/AltOS cd macosx && zip -r ../$@ AltosUI.app AltOS diff --git a/altosui/altoslib/.gitignore b/altosui/altoslib/.gitignore new file mode 100644 index 00000000..ad2f8cbf --- /dev/null +++ b/altosui/altoslib/.gitignore @@ -0,0 +1 @@ +classAltosLib.stamp diff --git a/altosui/altoslib/Makefile.am b/altosui/altoslib/Makefile.am new file mode 100644 index 00000000..2ddd24e6 --- /dev/null +++ b/altosui/altoslib/Makefile.am @@ -0,0 +1,69 @@ +AM_JAVACFLAGS=-encoding UTF-8 -Xlint:deprecation + +JAVAROOT=bin + +CLASSPATH_ENV=mkdir -p $(JAVAROOT); CLASSPATH="bin:$(FREETTS)/*:/usr/share/java/*" + +SRC=src/org/altusmetrum/AltosLib +BIN=bin/org/altusmetrum/AltosLib + +AltosLibdir = $(datadir)/java + +AltosLib_JAVA = \ + $(SRC)/AltosLib.java \ + $(SRC)/AltosConfigData.java \ + $(SRC)/AltosConvert.java \ + $(SRC)/AltosCRCException.java \ + $(SRC)/AltosEepromChunk.java \ + $(SRC)/AltosEepromIterable.java \ + $(SRC)/AltosEepromLog.java \ + $(SRC)/AltosEepromRecord.java \ + $(SRC)/AltosEepromTeleScience.java \ + $(SRC)/AltosFile.java \ + $(SRC)/AltosFlightReader.java \ + $(SRC)/AltosFrequency.java \ + $(SRC)/AltosGPS.java \ + $(SRC)/AltosGPSSat.java \ + $(SRC)/AltosGreatCircle.java \ + $(SRC)/AltosLine.java \ + $(SRC)/AltosLink.java \ + $(SRC)/AltosLog.java \ + $(SRC)/AltosParse.java \ + $(SRC)/AltosPreferences.java \ + $(SRC)/AltosRecordCompanion.java \ + $(SRC)/AltosRecordIterable.java \ + $(SRC)/AltosRecord.java \ + $(SRC)/AltosReplayReader.java \ + $(SRC)/AltosState.java \ + $(SRC)/AltosTelemetry.java \ + $(SRC)/AltosTelemetryIterable.java \ + $(SRC)/AltosTelemetryMap.java \ + $(SRC)/AltosTelemetryReader.java \ + $(SRC)/AltosTelemetryRecordCompanion.java \ + $(SRC)/AltosTelemetryRecordConfiguration.java \ + $(SRC)/AltosTelemetryRecordGeneral.java \ + $(SRC)/AltosTelemetryRecord.java \ + $(SRC)/AltosTelemetryRecordLegacy.java \ + $(SRC)/AltosTelemetryRecordLocation.java \ + $(SRC)/AltosTelemetryRecordRaw.java \ + $(SRC)/AltosTelemetryRecordSatellite.java \ + $(SRC)/AltosTelemetryRecordSensor.java + +JAR=AltosLib.jar + +all-local: $(JAR) + +clean-local: + -rm -rf bin $(JAR) + +install-AltosLibJAVA: $(JAR) + @$(NORMAL_INSTALL) + test -z "$(AltosLibdir)" || $(MKDIR_P) "$(DESTDIR)$(AltosLibdir)" + echo " $(INSTALL_DATA)" "$<" "'$(DESTDIR)$(AltosLibdir)/$(JAR)"; \ + $(INSTALL_DATA) "$<" "$(DESTDIR)$(AltosLibdir)" + +bin: + mkdir -p bin + +$(JAR): classAltosLib.stamp + jar cf $@ -C bin org diff --git a/altosui/AltosCRCException.java b/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosCRCException.java index 4a529bcf..101c5363 100644 --- a/altosui/AltosCRCException.java +++ b/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosCRCException.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package altosui; +package org.altusmetrum.AltosLib; public class AltosCRCException extends Exception { public int rssi; diff --git a/altosui/AltosConfigData.java b/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosConfigData.java index c14dc5a1..55ade0a0 100644 --- a/altosui/AltosConfigData.java +++ b/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosConfigData.java @@ -15,50 +15,44 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package altosui; +package org.altusmetrum.AltosLib; -import java.awt.*; -import java.awt.event.*; -import javax.swing.*; -import javax.swing.filechooser.FileNameExtensionFilter; -import javax.swing.table.*; import java.io.*; import java.util.*; import java.text.*; import java.util.prefs.*; import java.util.concurrent.*; - -import libaltosJNI.*; +import org.altusmetrum.AltosLib.*; public class AltosConfigData implements Iterable<String> { /* Version information */ - String manufacturer; - String product; - String version; - int log_format; - int serial; + public String manufacturer; + public String product; + public String version; + public int log_format; + public int serial; /* Strings returned */ - LinkedList<String> lines; + public LinkedList<String> lines; /* Config information */ - int config_major; - int config_minor; - int main_deploy; - int apogee_delay; - int radio_channel; - int radio_setting; - String callsign; - int accel_cal_plus, accel_cal_minus; - int radio_calibration; - int flight_log_max; - int ignite_mode; - int stored_flight; - int storage_size; - int storage_erase_unit; - - static String get_string(String line, String label) throws ParseException { + public int config_major; + public int config_minor; + public int main_deploy; + public int apogee_delay; + public int radio_channel; + public int radio_setting; + public String callsign; + public int accel_cal_plus, accel_cal_minus; + public int radio_calibration; + public int flight_log_max; + public int ignite_mode; + public int stored_flight; + public int storage_size; + public int storage_erase_unit; + + public static String get_string(String line, String label) throws ParseException { if (line.startsWith(label)) { String quoted = line.substring(label.length()).trim(); @@ -71,7 +65,7 @@ public class AltosConfigData implements Iterable<String> { throw new ParseException("mismatch", 0); } - static int get_int(String line, String label) throws NumberFormatException, ParseException { + public static int get_int(String line, String label) throws NumberFormatException, ParseException { if (line.startsWith(label)) { String tail = line.substring(label.length()).trim(); String[] tokens = tail.split("\\s+"); @@ -87,7 +81,7 @@ public class AltosConfigData implements Iterable<String> { public int log_available() { switch (log_format) { - case Altos.AO_LOG_FORMAT_TINY: + case AltosLib.AO_LOG_FORMAT_TINY: if (stored_flight == 0) return 1; return 0; @@ -103,13 +97,13 @@ public class AltosConfigData implements Iterable<String> { } } - public AltosConfigData(AltosSerial serial_line) throws InterruptedException, TimeoutException { - serial_line.printf("c s\nf\nl\nv\n"); + public AltosConfigData(AltosLink link) throws InterruptedException, TimeoutException { + link.printf("c s\nf\nl\nv\n"); lines = new LinkedList<String>(); radio_setting = 0; stored_flight = 0; for (;;) { - String line = serial_line.get_reply(); + String line = link.get_reply(); if (line == null) throw new TimeoutException(); if (line.contains("Syntax error")) diff --git a/altosui/AltosConvert.java b/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosConvert.java index db7039ec..d2aa629c 100644 --- a/altosui/AltosConvert.java +++ b/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosConvert.java @@ -18,7 +18,7 @@ /* * Sensor data conversion functions */ -package altosui; +package org.altusmetrum.AltosLib; public class AltosConvert { /* @@ -41,27 +41,27 @@ public class AltosConvert { * in Joules/(kilogram-Kelvin). */ - static final double GRAVITATIONAL_ACCELERATION = -9.80665; - static final double AIR_GAS_CONSTANT = 287.053; - static final double NUMBER_OF_LAYERS = 7; - static final double MAXIMUM_ALTITUDE = 84852.0; - static final double MINIMUM_PRESSURE = 0.3734; - static final double LAYER0_BASE_TEMPERATURE = 288.15; - static final double LAYER0_BASE_PRESSURE = 101325; + public static final double GRAVITATIONAL_ACCELERATION = -9.80665; + public static final double AIR_GAS_CONSTANT = 287.053; + public static final double NUMBER_OF_LAYERS = 7; + public static final double MAXIMUM_ALTITUDE = 84852.0; + public static final double MINIMUM_PRESSURE = 0.3734; + public static final double LAYER0_BASE_TEMPERATURE = 288.15; + public static final double LAYER0_BASE_PRESSURE = 101325; /* lapse rate and base altitude for each layer in the atmosphere */ - static final double[] lapse_rate = { + public static final double[] lapse_rate = { -0.0065, 0.0, 0.001, 0.0028, 0.0, -0.0028, -0.002 }; - static final int[] base_altitude = { + public static final int[] base_altitude = { 0, 11000, 20000, 32000, 47000, 51000, 71000 }; /* outputs atmospheric pressure associated with the given altitude. * altitudes are measured with respect to the mean sea level */ - static double + public static double altitude_to_pressure(double altitude) { double base_temperature = LAYER0_BASE_TEMPERATURE; @@ -114,7 +114,7 @@ public class AltosConvert { /* outputs the altitude associated with the given pressure. the altitude returned is measured with respect to the mean sea level */ - static double + public static double pressure_to_altitude(double pressure) { @@ -178,19 +178,19 @@ public class AltosConvert { return altitude; } - static double + public static double cc_battery_to_voltage(double battery) { return battery / 32767.0 * 5.0; } - static double + public static double cc_ignitor_to_voltage(double ignite) { return ignite / 32767 * 15.0; } - static double radio_to_frequency(int setting, int cal, int channel) { + public static double radio_to_frequency(int setting, int cal, int channel) { double f; if (setting <= 0) @@ -201,13 +201,13 @@ public class AltosConvert { return f + channel * 0.100; } - static int radio_frequency_to_setting(double frequency, int cal) { + public static int radio_frequency_to_setting(double frequency, int cal) { double set = frequency / 434.550 * cal; return (int) Math.floor (set + 0.5); } - static int radio_frequency_to_channel(double frequency) { + public static int radio_frequency_to_channel(double frequency) { int channel = (int) Math.floor ((frequency - 434.550) / 0.100 + 0.5); if (channel < 0) @@ -217,11 +217,11 @@ public class AltosConvert { return channel; } - static double radio_channel_to_frequency(int channel) { + public static double radio_channel_to_frequency(int channel) { return 434.550 + channel * 0.100; } - static int[] ParseHex(String line) { + public static int[] ParseHex(String line) { String[] tokens = line.split("\\s+"); int[] array = new int[tokens.length]; @@ -234,19 +234,19 @@ public class AltosConvert { return array; } - static double meters_to_feet(double meters) { + public static double meters_to_feet(double meters) { return meters * (100 / (2.54 * 12)); } - static double meters_to_mach(double meters) { + public static double meters_to_mach(double meters) { return meters / 343; /* something close to mach at usual rocket sites */ } - static double meters_to_g(double meters) { + public static double meters_to_g(double meters) { return meters / 9.80665; } - static int checksum(int[] data, int start, int length) { + public static int checksum(int[] data, int start, int length) { int csum = 0x5a; for (int i = 0; i < length; i++) csum += data[i + start]; diff --git a/altosui/AltosEepromChunk.java b/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosEepromChunk.java index 59767c2a..0568c462 100644 --- a/altosui/AltosEepromChunk.java +++ b/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosEepromChunk.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package altosui; +package org.altusmetrum.AltosLib; import java.io.*; import java.util.*; @@ -24,8 +24,8 @@ import java.util.concurrent.*; public class AltosEepromChunk { - static final int chunk_size = 256; - static final int per_line = 8; + public static final int chunk_size = 256; + public static final int per_line = 8; public int data[]; public int address; @@ -44,22 +44,22 @@ public class AltosEepromChunk { return array; } - int data(int offset) { + public int data(int offset) { return data[offset]; } - int data16(int offset) { + public int data16(int offset) { return data[offset] | (data[offset + 1] << 8); } - boolean erased(int start, int len) { + public boolean erased(int start, int len) { for (int i = 0; i < len; i++) if (data[start+i] != 0xff) return false; return true; } - public AltosEepromChunk(AltosSerial serial_line, int block, boolean flush) + public AltosEepromChunk(AltosLink link, int block, boolean flush) throws TimeoutException, InterruptedException { int offset; @@ -67,12 +67,12 @@ public class AltosEepromChunk { data = new int[chunk_size]; address = block * chunk_size; if (flush) - serial_line.flush_input(); - serial_line.printf("e %x\n", block); + link.flush_input(); + link.printf("e %x\n", block); for (offset = 0; offset < chunk_size; offset += per_line) { try { - String line = serial_line.get_reply(5000); + String line = link.get_reply(5000); if (line == null) throw new TimeoutException(); diff --git a/altosui/AltosEepromIterable.java b/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosEepromIterable.java index d8205816..4e5c0b7b 100644 --- a/altosui/AltosEepromIterable.java +++ b/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosEepromIterable.java @@ -15,13 +15,8 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package altosui; +package org.altusmetrum.AltosLib; -import java.awt.*; -import java.awt.event.*; -import javax.swing.*; -import javax.swing.filechooser.FileNameExtensionFilter; -import javax.swing.table.*; import java.io.*; import java.util.*; import java.text.*; @@ -111,17 +106,17 @@ public class AltosEepromIterable extends AltosRecordIterable { void update_state(AltosRecord state, AltosEepromRecord record, EepromState eeprom) { state.tick = record.tick; switch (record.cmd) { - case Altos.AO_LOG_FLIGHT: + case AltosLib.AO_LOG_FLIGHT: eeprom.seen |= seen_flight; state.ground_accel = record.a; state.flight_accel = record.a; state.flight = record.b; eeprom.boost_tick = record.tick; break; - case Altos.AO_LOG_SENSOR: + case AltosLib.AO_LOG_SENSOR: state.accel = record.a; state.pres = record.b; - if (state.state < Altos.ao_flight_boost) { + if (state.state < AltosLib.ao_flight_boost) { eeprom.n_pad_samples++; eeprom.ground_pres += state.pres; state.ground_pres = (int) (eeprom.ground_pres / eeprom.n_pad_samples); @@ -134,7 +129,7 @@ public class AltosEepromIterable extends AltosRecordIterable { eeprom.seen |= seen_sensor; has_accel = true; break; - case Altos.AO_LOG_PRESSURE: + case AltosLib.AO_LOG_PRESSURE: state.pres = record.b; state.flight_pres = state.pres; if (eeprom.n_pad_samples == 0) { @@ -143,21 +138,21 @@ public class AltosEepromIterable extends AltosRecordIterable { } eeprom.seen |= seen_sensor; break; - case Altos.AO_LOG_TEMP_VOLT: + case AltosLib.AO_LOG_TEMP_VOLT: state.temp = record.a; state.batt = record.b; eeprom.seen |= seen_temp_volt; break; - case Altos.AO_LOG_DEPLOY: + case AltosLib.AO_LOG_DEPLOY: state.drogue = record.a; state.main = record.b; eeprom.seen |= seen_deploy; has_ignite = true; break; - case Altos.AO_LOG_STATE: + case AltosLib.AO_LOG_STATE: state.state = record.a; break; - case Altos.AO_LOG_GPS_TIME: + case AltosLib.AO_LOG_GPS_TIME: eeprom.gps_tick = state.tick; AltosGPS old = state.gps; state.gps = new AltosGPS(); @@ -173,62 +168,62 @@ public class AltosEepromIterable extends AltosRecordIterable { state.gps.second = (record.b & 0xff); int flags = (record.b >> 8); - state.gps.connected = (flags & Altos.AO_GPS_RUNNING) != 0; - state.gps.locked = (flags & Altos.AO_GPS_VALID) != 0; - state.gps.nsat = (flags & Altos.AO_GPS_NUM_SAT_MASK) >> - Altos.AO_GPS_NUM_SAT_SHIFT; + state.gps.connected = (flags & AltosLib.AO_GPS_RUNNING) != 0; + state.gps.locked = (flags & AltosLib.AO_GPS_VALID) != 0; + state.gps.nsat = (flags & AltosLib.AO_GPS_NUM_SAT_MASK) >> + AltosLib.AO_GPS_NUM_SAT_SHIFT; state.new_gps = true; has_gps = true; break; - case Altos.AO_LOG_GPS_LAT: + case AltosLib.AO_LOG_GPS_LAT: int lat32 = record.a | (record.b << 16); state.gps.lat = (double) lat32 / 1e7; break; - case Altos.AO_LOG_GPS_LON: + case AltosLib.AO_LOG_GPS_LON: int lon32 = record.a | (record.b << 16); state.gps.lon = (double) lon32 / 1e7; break; - case Altos.AO_LOG_GPS_ALT: + case AltosLib.AO_LOG_GPS_ALT: state.gps.alt = record.a; break; - case Altos.AO_LOG_GPS_SAT: + case AltosLib.AO_LOG_GPS_SAT: if (state.tick == eeprom.gps_tick) { int svid = record.a; int c_n0 = record.b >> 8; state.gps.add_sat(svid, c_n0); } break; - case Altos.AO_LOG_GPS_DATE: + case AltosLib.AO_LOG_GPS_DATE: state.gps.year = (record.a & 0xff) + 2000; state.gps.month = record.a >> 8; state.gps.day = record.b & 0xff; break; - case Altos.AO_LOG_CONFIG_VERSION: + case AltosLib.AO_LOG_CONFIG_VERSION: break; - case Altos.AO_LOG_MAIN_DEPLOY: + case AltosLib.AO_LOG_MAIN_DEPLOY: break; - case Altos.AO_LOG_APOGEE_DELAY: + case AltosLib.AO_LOG_APOGEE_DELAY: break; - case Altos.AO_LOG_RADIO_CHANNEL: + case AltosLib.AO_LOG_RADIO_CHANNEL: break; - case Altos.AO_LOG_CALLSIGN: + case AltosLib.AO_LOG_CALLSIGN: state.callsign = record.data; break; - case Altos.AO_LOG_ACCEL_CAL: + case AltosLib.AO_LOG_ACCEL_CAL: state.accel_plus_g = record.a; state.accel_minus_g = record.b; break; - case Altos.AO_LOG_RADIO_CAL: + case AltosLib.AO_LOG_RADIO_CAL: break; - case Altos.AO_LOG_MANUFACTURER: + case AltosLib.AO_LOG_MANUFACTURER: break; - case Altos.AO_LOG_PRODUCT: + case AltosLib.AO_LOG_PRODUCT: break; - case Altos.AO_LOG_SERIAL_NUMBER: + case AltosLib.AO_LOG_SERIAL_NUMBER: state.serial = record.a; break; - case Altos.AO_LOG_SOFTWARE_VERSION: + case AltosLib.AO_LOG_SOFTWARE_VERSION: break; } state.seen |= eeprom.seen; @@ -242,7 +237,7 @@ public class AltosEepromIterable extends AltosRecordIterable { boolean last_reported = false; EepromState eeprom = new EepromState(); - state.state = Altos.ao_flight_pad; + state.state = AltosLib.ao_flight_pad; state.accel_plus_g = 15758; state.accel_minus_g = 16294; @@ -283,40 +278,40 @@ public class AltosEepromIterable extends AltosRecordIterable { while (iterator.hasNext()) { AltosOrderedRecord record = iterator.next(); switch (record.cmd) { - case Altos.AO_LOG_CONFIG_VERSION: + case AltosLib.AO_LOG_CONFIG_VERSION: out.printf("# Config version: %s\n", record.data); break; - case Altos.AO_LOG_MAIN_DEPLOY: + case AltosLib.AO_LOG_MAIN_DEPLOY: out.printf("# Main deploy: %s\n", record.a); break; - case Altos.AO_LOG_APOGEE_DELAY: + case AltosLib.AO_LOG_APOGEE_DELAY: out.printf("# Apogee delay: %s\n", record.a); break; - case Altos.AO_LOG_RADIO_CHANNEL: + case AltosLib.AO_LOG_RADIO_CHANNEL: out.printf("# Radio channel: %s\n", record.a); break; - case Altos.AO_LOG_CALLSIGN: + case AltosLib.AO_LOG_CALLSIGN: out.printf("# Callsign: %s\n", record.data); break; - case Altos.AO_LOG_ACCEL_CAL: + case AltosLib.AO_LOG_ACCEL_CAL: out.printf ("# Accel cal: %d %d\n", record.a, record.b); break; - case Altos.AO_LOG_RADIO_CAL: + case AltosLib.AO_LOG_RADIO_CAL: out.printf ("# Radio cal: %d\n", record.a); break; - case Altos.AO_LOG_MAX_FLIGHT_LOG: + case AltosLib.AO_LOG_MAX_FLIGHT_LOG: out.printf ("# Max flight log: %d\n", record.a); break; - case Altos.AO_LOG_MANUFACTURER: + case AltosLib.AO_LOG_MANUFACTURER: out.printf ("# Manufacturer: %s\n", record.data); break; - case Altos.AO_LOG_PRODUCT: + case AltosLib.AO_LOG_PRODUCT: out.printf ("# Product: %s\n", record.data); break; - case Altos.AO_LOG_SERIAL_NUMBER: + case AltosLib.AO_LOG_SERIAL_NUMBER: out.printf ("# Serial number: %d\n", record.a); break; - case Altos.AO_LOG_SOFTWARE_VERSION: + case AltosLib.AO_LOG_SOFTWARE_VERSION: out.printf ("# Software version: %s\n", record.data); break; } @@ -339,10 +334,10 @@ public class AltosEepromIterable extends AltosRecordIterable { int seconds = hour * 3600 + minute * 60 + second; /* Make sure this looks like a good GPS value */ - if ((flags & Altos.AO_GPS_NUM_SAT_MASK) >> Altos.AO_GPS_NUM_SAT_SHIFT < 4) - flags = (flags & ~Altos.AO_GPS_NUM_SAT_MASK) | (4 << Altos.AO_GPS_NUM_SAT_SHIFT); - flags |= Altos.AO_GPS_RUNNING; - flags |= Altos.AO_GPS_VALID; + if ((flags & AltosLib.AO_GPS_NUM_SAT_MASK) >> AltosLib.AO_GPS_NUM_SAT_SHIFT < 4) + flags = (flags & ~AltosLib.AO_GPS_NUM_SAT_MASK) | (4 << AltosLib.AO_GPS_NUM_SAT_SHIFT); + flags |= AltosLib.AO_GPS_RUNNING; + flags |= AltosLib.AO_GPS_VALID; int new_seconds = seconds + diff; if (new_seconds < 0) @@ -382,12 +377,12 @@ public class AltosEepromIterable extends AltosRecordIterable { AltosOrderedRecord record = new AltosOrderedRecord(line, index++, prev_tick, prev_tick_valid); if (record == null) break; - if (record.cmd == Altos.AO_LOG_INVALID) + if (record.cmd == AltosLib.AO_LOG_INVALID) continue; prev_tick = record.tick; - if (record.cmd < Altos.AO_LOG_CONFIG_VERSION) + if (record.cmd < AltosLib.AO_LOG_CONFIG_VERSION) prev_tick_valid = true; - if (record.cmd == Altos.AO_LOG_FLIGHT) { + if (record.cmd == AltosLib.AO_LOG_FLIGHT) { flight_record = record; continue; } @@ -398,19 +393,19 @@ public class AltosEepromIterable extends AltosRecordIterable { * record. Detect the loss of the GPS date and fix up the * missing time records */ - if (record.cmd == Altos.AO_LOG_GPS_DATE) { + if (record.cmd == AltosLib.AO_LOG_GPS_DATE) { gps_date_record = record; continue; } /* go back and fix up any missing time values */ - if (record.cmd == Altos.AO_LOG_GPS_TIME) { + if (record.cmd == AltosLib.AO_LOG_GPS_TIME) { last_gps_time = record; if (missing_time) { Iterator<AltosOrderedRecord> iterator = records.iterator(); while (iterator.hasNext()) { AltosOrderedRecord old = iterator.next(); - if (old.cmd == Altos.AO_LOG_GPS_TIME && + if (old.cmd == AltosLib.AO_LOG_GPS_TIME && old.a == -1 && old.b == -1) { update_time(record, old); @@ -420,9 +415,9 @@ public class AltosEepromIterable extends AltosRecordIterable { } } - if (record.cmd == Altos.AO_LOG_GPS_LAT) { + if (record.cmd == AltosLib.AO_LOG_GPS_LAT) { if (last_gps_time == null || last_gps_time.tick != record.tick) { - AltosOrderedRecord add_gps_time = new AltosOrderedRecord(Altos.AO_LOG_GPS_TIME, + AltosOrderedRecord add_gps_time = new AltosOrderedRecord(AltosLib.AO_LOG_GPS_TIME, record.tick, -1, -1, index-1); if (last_gps_time != null) @@ -437,8 +432,8 @@ public class AltosEepromIterable extends AltosRecordIterable { records.add(record); /* Bail after reading the 'landed' record; we're all done */ - if (record.cmd == Altos.AO_LOG_STATE && - record.a == Altos.ao_flight_landed) + if (record.cmd == AltosLib.AO_LOG_STATE && + record.a == AltosLib.ao_flight_landed) break; } } catch (IOException io) { diff --git a/altosui/AltosEepromLog.java b/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosEepromLog.java index ee77e5c8..83b776b7 100644 --- a/altosui/AltosEepromLog.java +++ b/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosEepromLog.java @@ -15,39 +15,32 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package altosui; +package org.altusmetrum.AltosLib; -import java.awt.*; -import java.awt.event.*; -import javax.swing.*; -import javax.swing.filechooser.FileNameExtensionFilter; -import javax.swing.table.*; import java.io.*; import java.util.*; import java.text.*; import java.util.prefs.*; import java.util.concurrent.*; -import libaltosJNI.*; - /* * Extract a bit of information from an eeprom-stored flight log. */ public class AltosEepromLog { - int serial; - boolean has_flight; - int flight; - int start_block; - int end_block; + public int serial; + public boolean has_flight; + public int flight; + public int start_block; + public int end_block; - int year, month, day; + public int year, month, day; - boolean download; - boolean delete; + public boolean download; + public boolean delete; public AltosEepromLog(AltosConfigData config_data, - AltosSerial serial_line, + AltosLink link, int in_flight, int in_start_block, int in_end_block) throws InterruptedException, TimeoutException { @@ -71,8 +64,8 @@ public class AltosEepromLog { /* * Look in TeleMetrum log data for date */ - if (config_data.log_format == Altos.AO_LOG_FORMAT_UNKNOWN || - config_data.log_format == Altos.AO_LOG_FORMAT_FULL) + if (config_data.log_format == AltosLib.AO_LOG_FORMAT_UNKNOWN || + config_data.log_format == AltosLib.AO_LOG_FORMAT_FULL) { /* * Only look in the first two blocks so that this @@ -82,17 +75,17 @@ public class AltosEepromLog { in_end_block = in_start_block + 2; for (block = in_start_block; block < in_end_block; block++) { - AltosEepromChunk eechunk = new AltosEepromChunk(serial_line, block, block == in_start_block); + AltosEepromChunk eechunk = new AltosEepromChunk(link, block, block == in_start_block); for (int i = 0; i < eechunk.chunk_size; i += AltosEepromRecord.record_length) { try { AltosEepromRecord r = new AltosEepromRecord(eechunk, i); - if (r.cmd == Altos.AO_LOG_FLIGHT) { + if (r.cmd == AltosLib.AO_LOG_FLIGHT) { flight = r.b; has_flight = true; } - if (r.cmd == Altos.AO_LOG_GPS_DATE) { + if (r.cmd == AltosLib.AO_LOG_GPS_DATE) { year = 2000 + (r.a & 0xff); month = (r.a >> 8) & 0xff; day = (r.b & 0xff); diff --git a/altosui/AltosEepromRecord.java b/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosEepromRecord.java index d8a07951..1e845f46 100644 --- a/altosui/AltosEepromRecord.java +++ b/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosEepromRecord.java @@ -15,21 +15,14 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package altosui; +package org.altusmetrum.AltosLib; -import java.awt.*; -import java.awt.event.*; -import javax.swing.*; -import javax.swing.filechooser.FileNameExtensionFilter; -import javax.swing.table.*; import java.io.*; import java.util.*; import java.text.*; import java.util.prefs.*; import java.util.concurrent.*; -import libaltosJNI.*; - public class AltosEepromRecord { public int cmd; public int tick; @@ -38,7 +31,7 @@ public class AltosEepromRecord { public String data; public boolean tick_valid; - static final int record_length = 8; + public static final int record_length = 8; public AltosEepromRecord (AltosEepromChunk chunk, int start) throws ParseException { @@ -51,7 +44,7 @@ public class AltosEepromRecord { throw new ParseException(String.format("invalid checksum at 0x%x", chunk.address + start), 0); } else { - cmd = Altos.AO_LOG_INVALID; + cmd = AltosLib.AO_LOG_INVALID; } tick = chunk.data16(start + 2); @@ -68,7 +61,7 @@ public class AltosEepromRecord { b = 0; data = null; if (line == null) { - cmd = Altos.AO_LOG_INVALID; + cmd = AltosLib.AO_LOG_INVALID; data = ""; } else { try { @@ -76,7 +69,7 @@ public class AltosEepromRecord { if (tokens[0].length() == 1) { if (tokens.length != 4) { - cmd = Altos.AO_LOG_INVALID; + cmd = AltosLib.AO_LOG_INVALID; data = line; } else { cmd = tokens[0].codePointAt(0); @@ -86,51 +79,51 @@ public class AltosEepromRecord { b = Integer.parseInt(tokens[3],16); } } else if (tokens[0].equals("Config") && tokens[1].equals("version:")) { - cmd = Altos.AO_LOG_CONFIG_VERSION; + cmd = AltosLib.AO_LOG_CONFIG_VERSION; data = tokens[2]; } else if (tokens[0].equals("Main") && tokens[1].equals("deploy:")) { - cmd = Altos.AO_LOG_MAIN_DEPLOY; + cmd = AltosLib.AO_LOG_MAIN_DEPLOY; a = Integer.parseInt(tokens[2]); } else if (tokens[0].equals("Apogee") && tokens[1].equals("delay:")) { - cmd = Altos.AO_LOG_APOGEE_DELAY; + cmd = AltosLib.AO_LOG_APOGEE_DELAY; a = Integer.parseInt(tokens[2]); } else if (tokens[0].equals("Radio") && tokens[1].equals("channel:")) { - cmd = Altos.AO_LOG_RADIO_CHANNEL; + cmd = AltosLib.AO_LOG_RADIO_CHANNEL; a = Integer.parseInt(tokens[2]); } else if (tokens[0].equals("Callsign:")) { - cmd = Altos.AO_LOG_CALLSIGN; + cmd = AltosLib.AO_LOG_CALLSIGN; data = tokens[1].replaceAll("\"",""); } else if (tokens[0].equals("Accel") && tokens[1].equals("cal")) { - cmd = Altos.AO_LOG_ACCEL_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 = Altos.AO_LOG_RADIO_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 = Altos.AO_LOG_MAX_FLIGHT_LOG; + cmd = AltosLib.AO_LOG_MAX_FLIGHT_LOG; a = Integer.parseInt(tokens[3]); } else if (tokens[0].equals("manufacturer")) { - cmd = Altos.AO_LOG_MANUFACTURER; + cmd = AltosLib.AO_LOG_MANUFACTURER; data = tokens[1]; } else if (tokens[0].equals("product")) { - cmd = Altos.AO_LOG_PRODUCT; + cmd = AltosLib.AO_LOG_PRODUCT; data = tokens[1]; } else if (tokens[0].equals("serial-number")) { - cmd = Altos.AO_LOG_SERIAL_NUMBER; + cmd = AltosLib.AO_LOG_SERIAL_NUMBER; a = Integer.parseInt(tokens[1]); } else if (tokens[0].equals("log-format")) { - cmd = Altos.AO_LOG_LOG_FORMAT; + cmd = AltosLib.AO_LOG_LOG_FORMAT; a = Integer.parseInt(tokens[1]); } else if (tokens[0].equals("software-version")) { - cmd = Altos.AO_LOG_SOFTWARE_VERSION; + cmd = AltosLib.AO_LOG_SOFTWARE_VERSION; data = tokens[1]; } else { - cmd = Altos.AO_LOG_INVALID; + cmd = AltosLib.AO_LOG_INVALID; data = line; } } catch (NumberFormatException ne) { - cmd = Altos.AO_LOG_INVALID; + cmd = AltosLib.AO_LOG_INVALID; data = line; } } diff --git a/altosui/AltosEepromTeleScience.java b/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosEepromTeleScience.java index ee1840b0..1758fa34 100644 --- a/altosui/AltosEepromTeleScience.java +++ b/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosEepromTeleScience.java @@ -15,13 +15,8 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package altosui; +package org.altusmetrum.AltosLib; -import java.awt.*; -import java.awt.event.*; -import javax.swing.*; -import javax.swing.filechooser.FileNameExtensionFilter; -import javax.swing.table.*; import java.io.*; import java.util.*; import java.text.*; @@ -29,18 +24,18 @@ import java.util.prefs.*; import java.util.concurrent.*; public class AltosEepromTeleScience { - int type; - int tick; - int tm_state; - int tm_tick; - int[] data; - boolean valid; + public int type; + public int tick; + public int tm_state; + public int tm_tick; + public int[] data; + public boolean valid; - static final int AO_LOG_TELESCIENCE_START = 's'; - static final int AO_LOG_TELESCIENCE_DATA = 'd'; + public static final int AO_LOG_TELESCIENCE_START = 's'; + public static final int AO_LOG_TELESCIENCE_DATA = 'd'; static final int max_data = 12; - static final int record_length = 32; + public static final int record_length = 32; public AltosEepromTeleScience (AltosEepromChunk chunk, int start) throws ParseException { type = chunk.data(start); @@ -51,7 +46,7 @@ public class AltosEepromTeleScience { throw new ParseException(String.format("invalid checksum at 0x%x", chunk.address + start), 0); } else { - type = Altos.AO_LOG_INVALID; + type = AltosLib.AO_LOG_INVALID; } tick = chunk.data16(start+2); diff --git a/altosui/AltosFile.java b/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosFile.java index 2e33b271..d2e4f2f7 100644 --- a/altosui/AltosFile.java +++ b/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosFile.java @@ -15,13 +15,13 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package altosui; +package org.altusmetrum.AltosLib; import java.lang.*; import java.io.File; import java.util.*; -class AltosFile extends File { +public class AltosFile extends File { public AltosFile(int year, int month, int day, int serial, int flight, String extension) { super (AltosPreferences.logdir(), diff --git a/altosui/AltosFlightReader.java b/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosFlightReader.java index 47df375d..04bd79a7 100644 --- a/altosui/AltosFlightReader.java +++ b/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosFlightReader.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package altosui; +package org.altusmetrum.AltosLib; import java.lang.*; import java.text.*; @@ -23,25 +23,25 @@ import java.io.*; import java.util.concurrent.*; public class AltosFlightReader { - String name; + public String name; - int serial; + public int serial; - void init() { } + public void init() { } - AltosRecord read() throws InterruptedException, ParseException, AltosCRCException, IOException { return null; } + public AltosRecord read() throws InterruptedException, ParseException, AltosCRCException, IOException { return null; } - void close(boolean interrupted) { } + public void close(boolean interrupted) { } - void set_frequency(double frequency) throws InterruptedException, TimeoutException { } + public void set_frequency(double frequency) throws InterruptedException, TimeoutException { } - void save_frequency() { } + public void save_frequency() { } - void set_telemetry(int telemetry) { } + public void set_telemetry(int telemetry) { } - void save_telemetry() { } + public void save_telemetry() { } - void update(AltosState state) throws InterruptedException { } + public void update(AltosState state) throws InterruptedException { } - File backing_file() { return null; } + public File backing_file() { return null; } } diff --git a/altosui/AltosFrequency.java b/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosFrequency.java index 0617ce74..57cb9c48 100644 --- a/altosui/AltosFrequency.java +++ b/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosFrequency.java @@ -15,24 +15,15 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package altosui; - -import java.awt.*; -import java.awt.event.*; -import javax.swing.*; -import javax.swing.filechooser.FileNameExtensionFilter; -import javax.swing.table.*; -import javax.swing.event.*; -import javax.swing.plaf.basic.*; +package org.altusmetrum.AltosLib; + import java.io.*; import java.util.*; import java.text.*; -import java.util.prefs.*; -import java.util.concurrent.*; public class AltosFrequency { - double frequency; - String description; + public double frequency; + public String description; public String toString() { return String.format("%7.3f MHz %-20.20s", diff --git a/altosui/AltosGPS.java b/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosGPS.java index b5df7c9a..f078a469 100644 --- a/altosui/AltosGPS.java +++ b/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosGPS.java @@ -15,39 +15,39 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package altosui; +package org.altusmetrum.AltosLib; import java.lang.*; import java.text.*; public class AltosGPS { - final static int MISSING = AltosRecord.MISSING; - - int nsat; - boolean locked; - boolean connected; - double lat; /* degrees (+N -S) */ - double lon; /* degrees (+E -W) */ - int alt; /* m */ - int year; - int month; - int day; - int hour; - int minute; - int second; - - double ground_speed; /* m/s */ - int course; /* degrees */ - double climb_rate; /* m/s */ - double hdop; /* unitless */ - double vdop; /* unitless */ - int h_error; /* m */ - int v_error; /* m */ - - AltosGPSSat[] cc_gps_sat; /* tracking data */ - - void ParseGPSDate(String date) throws ParseException { + public final static int MISSING = AltosRecord.MISSING; + + public int nsat; + public boolean locked; + public boolean connected; + public double lat; /* degrees (+N -S) */ + public double lon; /* degrees (+E -W) */ + public int alt; /* m */ + public int year; + public int month; + public int day; + public int hour; + public int minute; + public int second; + + public double ground_speed; /* m/s */ + public int course; /* degrees */ + public double climb_rate; /* m/s */ + public double hdop; /* unitless */ + public double vdop; /* unitless */ + public int h_error; /* m */ + public int v_error; /* m */ + + public AltosGPSSat[] cc_gps_sat; /* tracking data */ + + public void ParseGPSDate(String date) throws ParseException { String[] ymd = date.split("-"); if (ymd.length != 3) throw new ParseException("error parsing GPS date " + date + " got " + ymd.length, 0); @@ -56,7 +56,7 @@ public class AltosGPS { day = AltosParse.parse_int(ymd[2]); } - void ParseGPSTime(String time) throws ParseException { + public void ParseGPSTime(String time) throws ParseException { String[] hms = time.split(":"); if (hms.length != 3) throw new ParseException("Error parsing GPS time " + time + " got " + hms.length, 0); @@ -65,7 +65,7 @@ public class AltosGPS { second = AltosParse.parse_int(hms[2]); } - void ClearGPSTime() { + public void ClearGPSTime() { year = month = day = 0; hour = minute = second = 0; } diff --git a/altosui/AltosGPSSat.java b/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosGPSSat.java index fb125651..faa1ec8d 100644 --- a/altosui/AltosGPSSat.java +++ b/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosGPSSat.java @@ -15,11 +15,11 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package altosui; +package org.altusmetrum.AltosLib; public class AltosGPSSat { - int svid; - int c_n0; + public int svid; + public int c_n0; public AltosGPSSat(int s, int c) { svid = s; diff --git a/altosui/AltosGreatCircle.java b/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosGreatCircle.java index fb1b6ab3..76b71859 100644 --- a/altosui/AltosGreatCircle.java +++ b/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosGreatCircle.java @@ -15,43 +15,44 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package altosui; +package org.altusmetrum.AltosLib; import java.lang.Math; public class AltosGreatCircle { - double distance; - double bearing; + public double distance; + public double bearing; double sqr(double a) { return a * a; } static final double rad = Math.PI / 180; static final double earth_radius = 6371.2 * 1000; /* in meters */ - static int BEARING_LONG = 0; - static int BEARING_SHORT = 1; - static int BEARING_VOICE = 2; - String bearing_words(int length) { - String [][] bearing_string = { - { - "North", "North North East", "North East", "East North East", - "East", "East South East", "South East", "South South East", - "South", "South South West", "South West", "West South West", - "West", "West North West", "North West", "North North West" - }, { - "N", "NNE", "NE", "ENE", - "E", "ESE", "SE", "SSE", - "S", "SSW", "SW", "WSW", - "W", "WNW", "NW", "NNW" - }, { - "north", "nor nor east", "north east", "east nor east", - "east", "east sow east", "south east", "sow sow east", - "south", "sow sow west", "south west", "west sow west", - "west", "west nor west", "north west", "nor nor west " - } - }; - return bearing_string[length][(int)((bearing / 90 * 8 + 1) / 2)%16]; - } + public static final int BEARING_LONG = 0; + public static final int BEARING_SHORT = 1; + public static final int BEARING_VOICE = 2; + + public String bearing_words(int length) { + String [][] bearing_string = { + { + "North", "North North East", "North East", "East North East", + "East", "East South East", "South East", "South South East", + "South", "South South West", "South West", "West South West", + "West", "West North West", "North West", "North North West" + }, { + "N", "NNE", "NE", "ENE", + "E", "ESE", "SE", "SSE", + "S", "SSW", "SW", "WSW", + "W", "WNW", "NW", "NNW" + }, { + "north", "nor nor east", "north east", "east nor east", + "east", "east sow east", "south east", "sow sow east", + "south", "sow sow west", "south west", "west sow west", + "west", "west nor west", "north west", "nor nor west " + } + }; + return bearing_string[length][(int)((bearing / 90 * 8 + 1) / 2)%16]; + } public AltosGreatCircle (double start_lat, double start_lon, double end_lat, double end_lon) diff --git a/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosLib.java b/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosLib.java new file mode 100644 index 00000000..2921d040 --- /dev/null +++ b/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosLib.java @@ -0,0 +1,348 @@ +/* + * Copyright © 2010 Keith Packard <keithp@keithp.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ + +package org.altusmetrum.AltosLib; + +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,Integer> string_to_state = new HashMap<String,Integer>(); + + 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); + } +} diff --git a/altosui/AltosLine.java b/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosLine.java index 86e9d4c6..5627795a 100644 --- a/altosui/AltosLine.java +++ b/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosLine.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package altosui; +package org.altusmetrum.AltosLib; public class AltosLine { public String line; diff --git a/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosLink.java b/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosLink.java new file mode 100644 index 00000000..9b80e916 --- /dev/null +++ b/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosLink.java @@ -0,0 +1,238 @@ +/* + * Copyright © 2011 Keith Packard <keithp@keithp.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ + +package org.altusmetrum.AltosLib; + +import java.lang.*; +import java.io.*; +import java.util.concurrent.*; +import java.util.*; +import java.text.*; + +public abstract class AltosLink { + public abstract void print(String data); + public abstract void close(); + + public static boolean debug = false; + public static void set_debug(boolean in_debug) { debug = in_debug; } + LinkedList<String> pending_output = new LinkedList<String>(); + + public LinkedList<LinkedBlockingQueue<AltosLine>> monitors = new LinkedList<LinkedBlockingQueue<AltosLine>> ();; + public LinkedBlockingQueue<AltosLine> reply_queue = new LinkedBlockingQueue<AltosLine>(); + + public void add_monitor(LinkedBlockingQueue<AltosLine> q) { + set_monitor(true); + monitors.add(q); + } + + public void remove_monitor(LinkedBlockingQueue<AltosLine> q) { + monitors.remove(q); + if (monitors.isEmpty()) + set_monitor(false); + } + + public void printf(String format, Object ... arguments) { + String line = String.format(format, arguments); + if (debug) + pending_output.add(line); + print(line); + } + + public String get_reply_no_dialog(int timeout) throws InterruptedException, TimeoutException { + flush_output(); + AltosLine line = reply_queue.poll(timeout, TimeUnit.MILLISECONDS); + if (line != null) + return line.line; + return null; + } + + public String get_reply(int timeout) throws InterruptedException { + try { + return get_reply_no_dialog(timeout); + } catch (TimeoutException te) { + return null; + } + } + + public String get_reply() throws InterruptedException { + return get_reply(5000); + } + + public void add_telem(AltosLine line) throws InterruptedException { + for (int e = 0; e < monitors.size(); e++) { + LinkedBlockingQueue<AltosLine> q = monitors.get(e); + q.put(line); + } + } + + public void add_reply(AltosLine line) throws InterruptedException { + reply_queue.put (line); + } + + public void add_string(String line) throws InterruptedException { + if (line.startsWith("TELEM") || line.startsWith("VERSION") || line.startsWith("CRC")) { + add_telem(new AltosLine(line)); + } else { + add_reply(new AltosLine(line)); + } + } + + public void add_bytes(byte[] bytes, int len) throws InterruptedException { + String line; + try { + line = new String(bytes, 0, len, "UTF-8"); + } catch (UnsupportedEncodingException ue) { + line = ""; + for (int i = 0; i < len; i++) + line = line + bytes[i]; + } + if (debug) + System.out.printf("\t\t\t\t\t%s\n", line); + add_string(line); + } + + public void flush_output() { + for (String s : pending_output) + System.out.print(s); + pending_output.clear(); + } + + public void flush_input(int timeout) throws InterruptedException { + flush_output(); + boolean got_some; + + do { + Thread.sleep(timeout); + got_some = !reply_queue.isEmpty(); + reply_queue.clear(); + } while (got_some); + } + + + public void flush_input() throws InterruptedException { + flush_input(100); + } + + + /* + * Various command-level operations on + * the link + */ + public boolean monitor_mode = false; + public int telemetry = AltosLib.ao_telemetry_standard; + public double frequency; + AltosConfigData config_data; + + private int telemetry_len() { + return AltosLib.telemetry_len(telemetry); + } + + public void set_telemetry(int in_telemetry) { + telemetry = in_telemetry; + if (monitor_mode) + printf("m 0\nm %x\n", telemetry_len()); + flush_output(); + } + + public void set_monitor(boolean monitor) { + monitor_mode = monitor; + if (monitor) + printf("m %x\n", telemetry_len()); + else + printf("m 0\n"); + flush_output(); + } + + private void set_channel(int channel) { + if (monitor_mode) + printf("m 0\nc r %d\nm %x\n", + channel, telemetry_len()); + else + printf("c r %d\n", channel); + flush_output(); + } + + private void set_radio_setting(int setting) { + if (monitor_mode) + printf("m 0\nc R %d\nm %x\n", + setting, telemetry_len()); + else + printf("c R %d\n", setting); + flush_output(); + } + + public void set_radio_frequency(double frequency, + boolean has_setting, + int cal) { + if (debug) + System.out.printf("set_radio_frequency %7.3f %b %d\n", frequency, has_setting, cal); + if (has_setting) + set_radio_setting(AltosConvert.radio_frequency_to_setting(frequency, cal)); + else + set_channel(AltosConvert.radio_frequency_to_channel(frequency)); + } + + public AltosConfigData config_data() throws InterruptedException, TimeoutException { + if (config_data == null) + config_data = new AltosConfigData(this); + return config_data; + } + + public void set_radio_frequency(double in_frequency) throws InterruptedException, TimeoutException { + frequency = in_frequency; + config_data(); + set_radio_frequency(frequency, + config_data.radio_setting != 0, + config_data.radio_calibration); + } + + public void set_callsign(String callsign) { + printf ("c c %s\n", callsign); + flush_output(); + } + + public boolean remote; + public int serial; + public String name; + + public void start_remote() throws TimeoutException, InterruptedException { + if (debug) + System.out.printf("start remote %7.3f\n", frequency); + if (frequency == 0.0) + frequency = AltosPreferences.frequency(serial); + set_radio_frequency(frequency); + set_callsign(AltosPreferences.callsign()); + printf("p\nE 0\n"); + flush_input(); + remote = true; + } + + public void stop_remote() throws InterruptedException { + if (debug) + System.out.printf("stop remote\n"); + try { + flush_input(); + } finally { + printf ("~\n"); + flush_output(); + } + remote = false; + } + + public AltosLink() { + } +} diff --git a/altosui/AltosLog.java b/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosLog.java index a5f1830d..08c45ca8 100644 --- a/altosui/AltosLog.java +++ b/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosLog.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package altosui; +package org.altusmetrum.AltosLib; import java.io.*; import java.lang.*; @@ -113,10 +113,10 @@ class AltosLog implements Runnable { close(); } - public AltosLog (AltosSerial s) { + public AltosLog (AltosLink link) { pending_queue = new LinkedBlockingQueue<String> (); input_queue = new LinkedBlockingQueue<AltosLine> (); - s.add_monitor(input_queue); + link.add_monitor(input_queue); serial = -1; flight = -1; log_file = null; diff --git a/altosui/AltosParse.java b/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosParse.java index fbfcaaee..7d832f1a 100644 --- a/altosui/AltosParse.java +++ b/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosParse.java @@ -15,33 +15,33 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package altosui; +package org.altusmetrum.AltosLib; import java.text.*; import java.lang.*; public class AltosParse { - static boolean isdigit(char c) { + public static boolean isdigit(char c) { return '0' <= c && c <= '9'; } - static int parse_int(String v) throws ParseException { + public static int parse_int(String v) throws ParseException { try { - return Altos.fromdec(v); + return AltosLib.fromdec(v); } catch (NumberFormatException e) { throw new ParseException("error parsing int " + v, 0); } } - static int parse_hex(String v) throws ParseException { + public static int parse_hex(String v) throws ParseException { try { - return Altos.fromhex(v); + return AltosLib.fromhex(v); } catch (NumberFormatException e) { throw new ParseException("error parsing hex " + v, 0); } } - static double parse_double(String v) throws ParseException { + public static double parse_double(String v) throws ParseException { try { return Double.parseDouble(v); } catch (NumberFormatException e) { @@ -49,7 +49,7 @@ public class AltosParse { } } - static double parse_coord(String coord) throws ParseException { + public static double parse_coord(String coord) throws ParseException { String[] dsf = coord.split("\\D+"); if (dsf.length != 3) { @@ -65,13 +65,13 @@ public class AltosParse { return r; } - static String strip_suffix(String v, String suffix) { + public static String strip_suffix(String v, String suffix) { if (v.endsWith(suffix)) return v.substring(0, v.length() - suffix.length()); return v; } - static void word(String v, String m) throws ParseException { + public static void word(String v, String m) throws ParseException { if (!v.equals(m)) { throw new ParseException("error matching '" + v + "' '" + m + "'", 0); } diff --git a/altosui/AltosPreferences.java b/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosPreferences.java index cc2b1a95..43c7088d 100644 --- a/altosui/AltosPreferences.java +++ b/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosPreferences.java @@ -15,7 +15,8 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package altosui; +package org.altusmetrum.AltosLib; + import java.io.*; import java.util.*; import java.text.*; @@ -25,98 +26,78 @@ import java.awt.Component; import javax.swing.*; import javax.swing.filechooser.FileSystemView; -class AltosPreferences { - static Preferences preferences; +public class AltosPreferences { + public static Preferences preferences; /* logdir preference name */ - final static String logdirPreference = "LOGDIR"; + public final static String logdirPreference = "LOGDIR"; /* channel preference name */ - final static String channelPreferenceFormat = "CHANNEL-%d"; + public final static String channelPreferenceFormat = "CHANNEL-%d"; /* frequency preference name */ - final static String frequencyPreferenceFormat = "FREQUENCY-%d"; + public final static String frequencyPreferenceFormat = "FREQUENCY-%d"; /* telemetry format preference name */ - final static String telemetryPreferenceFormat = "TELEMETRY-%d"; + public final static String telemetryPreferenceFormat = "TELEMETRY-%d"; /* voice preference name */ - final static String voicePreference = "VOICE"; + public final static String voicePreference = "VOICE"; /* callsign preference name */ - final static String callsignPreference = "CALLSIGN"; + public final static String callsignPreference = "CALLSIGN"; /* firmware directory preference name */ - final static String firmwaredirPreference = "FIRMWARE"; + public final static String firmwaredirPreference = "FIRMWARE"; /* serial debug preference name */ - final static String serialDebugPreference = "SERIAL-DEBUG"; + public final static String serialDebugPreference = "SERIAL-DEBUG"; /* scanning telemetry preferences name */ - final static String scanningTelemetryPreference = "SCANNING-TELEMETRY"; - - /* font size preferences name */ - final static String fontSizePreference = "FONT-SIZE"; + public final static String scanningTelemetryPreference = "SCANNING-TELEMETRY"; /* Launcher serial preference name */ - final static String launcherSerialPreference = "LAUNCHER-SERIAL"; + public final static String launcherSerialPreference = "LAUNCHER-SERIAL"; /* Launcher channel preference name */ - final static String launcherChannelPreference = "LAUNCHER-CHANNEL"; + public final static String launcherChannelPreference = "LAUNCHER-CHANNEL"; - /* Look&Feel preference name */ - final static String lookAndFeelPreference = "LOOK-AND-FEEL"; - /* Default logdir is ~/TeleMetrum */ - final static String logdirName = "TeleMetrum"; - - /* UI Component to pop dialogs up */ - static Component component; + public final static String logdirName = "TeleMetrum"; /* Log directory */ - static File logdir; + public static File logdir; /* Map directory -- hangs of logdir */ - static File mapdir; + public static File mapdir; /* Frequency (map serial to frequency) */ - static Hashtable<Integer, Double> frequencies; + public static Hashtable<Integer, Double> frequencies; /* Telemetry (map serial to telemetry format) */ - static Hashtable<Integer, Integer> telemetries; + public static Hashtable<Integer, Integer> telemetries; /* Voice preference */ - static boolean voice; + public static boolean voice; /* Callsign preference */ - static String callsign; + public static String callsign; /* Firmware directory */ - static File firmwaredir; - - /* Serial debug */ - static boolean serial_debug; + public static File firmwaredir; /* Scanning telemetry */ - static int scanning_telemetry; - - static LinkedList<AltosFontListener> font_listeners; - - static int font_size = Altos.font_size_medium; - - static LinkedList<AltosUIListener> ui_listeners; - - static String look_and_feel = null; + public static int scanning_telemetry; /* List of frequencies */ - final static String common_frequencies_node_name = "COMMON-FREQUENCIES"; - static AltosFrequency[] common_frequencies; + public final static String common_frequencies_node_name = "COMMON-FREQUENCIES"; + public static AltosFrequency[] common_frequencies; - final static String frequency_count = "COUNT"; - final static String frequency_format = "FREQUENCY-%d"; - final static String description_format = "DESCRIPTION-%d"; + public final static String frequency_count = "COUNT"; + public final static String frequency_format = "FREQUENCY-%d"; + public final static String description_format = "DESCRIPTION-%d"; - static AltosFrequency[] load_common_frequencies() { + public static AltosFrequency[] load_common_frequencies() { AltosFrequency[] frequencies = null; boolean existing = false; try { @@ -147,7 +128,7 @@ class AltosPreferences { return frequencies; } - static void save_common_frequencies(AltosFrequency[] frequencies) { + public static void save_common_frequencies(AltosFrequency[] frequencies) { Preferences node = preferences.node(common_frequencies_node_name); node.putInt(frequency_count, frequencies.length); @@ -156,9 +137,9 @@ class AltosPreferences { node.put(String.format(description_format, i), frequencies[i].description); } } - static int launcher_serial; + public static int launcher_serial; - static int launcher_channel; + public static int launcher_channel; public static void init() { preferences = Preferences.userRoot().node("/org/altusmetrum/altosui"); @@ -185,12 +166,7 @@ class AltosPreferences { callsign = preferences.get(callsignPreference,"N0CALL"); - scanning_telemetry = preferences.getInt(scanningTelemetryPreference,(1 << Altos.ao_telemetry_standard)); - - font_listeners = new LinkedList<AltosFontListener>(); - - font_size = preferences.getInt(fontSizePreference, Altos.font_size_medium); - Altos.set_fonts(font_size); + scanning_telemetry = preferences.getInt(scanningTelemetryPreference,(1 << AltosLib.ao_telemetry_standard)); launcher_serial = preferences.getInt(launcherSerialPreference, 0); @@ -202,32 +178,24 @@ class AltosPreferences { else firmwaredir = null; - serial_debug = preferences.getBoolean(serialDebugPreference, false); - AltosSerial.set_debug(serial_debug); - common_frequencies = load_common_frequencies(); - look_and_feel = preferences.get(lookAndFeelPreference, UIManager.getSystemLookAndFeelClassName()); - - ui_listeners = new LinkedList<AltosUIListener>(); } static { init(); } - static void set_component(Component in_component) { - component = in_component; - } - - static void flush_preferences() { + public static void flush_preferences() { try { preferences.flush(); } catch (BackingStoreException ee) { +/* if (component != null) JOptionPane.showMessageDialog(component, preferences.absolutePath(), "Cannot save prefernces", JOptionPane.ERROR_MESSAGE); else +*/ System.err.printf("Cannot save preferences\n"); } } @@ -243,41 +211,6 @@ class AltosPreferences { } } - private static boolean check_dir(File dir) { - if (!dir.exists()) { - if (!dir.mkdirs()) { - JOptionPane.showMessageDialog(component, - dir.getName(), - "Cannot create directory", - JOptionPane.ERROR_MESSAGE); - return false; - } - } else if (!dir.isDirectory()) { - JOptionPane.showMessageDialog(component, - dir.getName(), - "Is not a directory", - JOptionPane.ERROR_MESSAGE); - return false; - } - return true; - } - - /* Configure the log directory. This is where all telemetry and eeprom files - * will be written to, and where replay will look for telemetry files - */ - public static void ConfigureLog() { - JFileChooser logdir_chooser = new JFileChooser(logdir.getParentFile()); - - logdir_chooser.setDialogTitle("Configure Data Logging Directory"); - logdir_chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); - - if (logdir_chooser.showDialog(component, "Select Directory") == JFileChooser.APPROVE_OPTION) { - File dir = logdir_chooser.getSelectedFile(); - if (check_dir(dir)) - set_logdir(dir); - } - } - public static File logdir() { return logdir; } @@ -318,7 +251,7 @@ class AltosPreferences { if (telemetries.containsKey(serial)) return telemetries.get(serial); int telemetry = preferences.getInt(String.format(telemetryPreferenceFormat, serial), - Altos.ao_telemetry_standard); + AltosLib.ao_telemetry_standard); telemetries.put(serial, telemetry); return telemetry; } @@ -371,78 +304,6 @@ class AltosPreferences { return firmwaredir; } - public static int font_size() { - return font_size; - } - - static void set_fonts() { - } - - public static void set_font_size(int new_font_size) { - font_size = new_font_size; - synchronized (preferences) { - preferences.putInt(fontSizePreference, font_size); - flush_preferences(); - Altos.set_fonts(font_size); - for (AltosFontListener l : font_listeners) - l.font_size_changed(font_size); - } - } - - public static void register_font_listener(AltosFontListener l) { - synchronized (preferences) { - font_listeners.add(l); - } - } - - public static void unregister_font_listener(AltosFontListener l) { - synchronized (preferences) { - font_listeners.remove(l); - } - } - - public static void set_look_and_feel(String new_look_and_feel) { - look_and_feel = new_look_and_feel; - try { - UIManager.setLookAndFeel(look_and_feel); - } catch (Exception e) { - } - synchronized(preferences) { - preferences.put(lookAndFeelPreference, look_and_feel); - flush_preferences(); - for (AltosUIListener l : ui_listeners) - l.ui_changed(look_and_feel); - } - } - - public static String look_and_feel() { - return look_and_feel; - } - - public static void register_ui_listener(AltosUIListener l) { - synchronized(preferences) { - ui_listeners.add(l); - } - } - - public static void unregister_ui_listener(AltosUIListener l) { - synchronized (preferences) { - ui_listeners.remove(l); - } - } - public static void set_serial_debug(boolean new_serial_debug) { - serial_debug = new_serial_debug; - AltosSerial.set_debug(serial_debug); - synchronized (preferences) { - preferences.putBoolean(serialDebugPreference, serial_debug); - flush_preferences(); - } - } - - public static boolean serial_debug() { - return serial_debug; - } - public static void set_launcher_serial(int new_launcher_serial) { launcher_serial = new_launcher_serial; System.out.printf("set launcher serial to %d\n", new_launcher_serial); diff --git a/altosui/AltosRecord.java b/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosRecord.java index 4dfa98be..08d87410 100644 --- a/altosui/AltosRecord.java +++ b/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosRecord.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package altosui; +package org.altusmetrum.AltosLib; import java.lang.*; import java.text.*; @@ -23,61 +23,62 @@ import java.util.HashMap; import java.io.*; public class AltosRecord implements Comparable <AltosRecord> { - final static int MISSING = 0x7fffffff; - - static final int seen_flight = 1; - static final int seen_sensor = 2; - static final int seen_temp_volt = 4; - static final int seen_deploy = 8; - static final int seen_gps_time = 16; - static final int seen_gps_lat = 32; - static final int seen_gps_lon = 64; - static final int seen_companion = 128; - int seen; - - int version; - String callsign; - int serial; - int flight; - int rssi; - int status; - int state; - int tick; - - int accel; - int pres; - int temp; - int batt; - int drogue; - int main; - - int ground_accel; - int ground_pres; - int accel_plus_g; - int accel_minus_g; - - double acceleration; - double speed; - double height; - - int flight_accel; - int flight_vel; - int flight_pres; - - AltosGPS gps; - boolean new_gps; - - double time; /* seconds since boost */ - - int device_type; - int config_major; - int config_minor; - int apogee_delay; - int main_deploy; - int flight_log_max; - String firmware_version; - - AltosRecordCompanion companion; + public final static int MISSING = 0x7fffffff; + + 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 int version; + public String callsign; + public int serial; + public int flight; + public int rssi; + public int status; + 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; + + public AltosGPS gps; + public boolean new_gps; + + 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 AltosRecordCompanion companion; + /* * Values for our MP3H6115A pressure sensor * @@ -92,10 +93,10 @@ public class AltosRecord implements Comparable <AltosRecord> { * 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; + public static final double counts_per_kPa = 27 * 2047 / 3300; + public static final double counts_at_101_3kPa = 1674.0; - static double + public static double barometer_to_pressure(double count) { return ((count / 16.0) / 2047.0 + 0.095) / 0.009 * 1000.0; @@ -190,7 +191,7 @@ public class AltosRecord implements Comparable <AltosRecord> { * = (value - 19791.268) / 32768 * 1.25 / 0.00247 */ - static double + public static double thermometer_to_temperature(double thermo) { return (thermo - 19791.268) / 32728.0 * 1.25 / 0.00247; @@ -202,7 +203,7 @@ public class AltosRecord implements Comparable <AltosRecord> { return thermometer_to_temperature(temp); } - double accel_counts_per_mss() { + 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; @@ -226,7 +227,7 @@ public class AltosRecord implements Comparable <AltosRecord> { } public String state() { - return Altos.state_name(state); + return AltosLib.state_name(state); } public static String gets(FileInputStream s) throws IOException { @@ -287,7 +288,7 @@ public class AltosRecord implements Comparable <AltosRecord> { flight = 0; rssi = 0; status = 0; - state = Altos.ao_flight_startup; + state = AltosLib.ao_flight_startup; tick = 0; accel = MISSING; pres = MISSING; diff --git a/altosui/AltosRecordCompanion.java b/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosRecordCompanion.java index 0a8f9f4b..c8cc6cac 100644 --- a/altosui/AltosRecordCompanion.java +++ b/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosRecordCompanion.java @@ -15,17 +15,17 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package altosui; +package org.altusmetrum.AltosLib; public class AltosRecordCompanion { - final static int board_id_telescience = 0x0a; - final static int MAX_CHANNELS = 12; + public final static int board_id_telescience = 0x0a; + public final static int MAX_CHANNELS = 12; - int tick; - int board_id; - int update_period; - int channels; - int[] companion_data; + 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; diff --git a/altosui/AltosRecordIterable.java b/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosRecordIterable.java index 45843b92..ed1787ed 100644 --- a/altosui/AltosRecordIterable.java +++ b/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosRecordIterable.java @@ -15,18 +15,10 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package altosui; +package org.altusmetrum.AltosLib; -import java.awt.*; -import java.awt.event.*; -import javax.swing.*; -import javax.swing.filechooser.FileNameExtensionFilter; -import javax.swing.table.*; import java.io.*; import java.util.*; -import java.text.*; -import java.util.prefs.*; -import java.util.concurrent.LinkedBlockingQueue; public abstract class AltosRecordIterable implements Iterable<AltosRecord> { public abstract Iterator<AltosRecord> iterator(); diff --git a/altosui/AltosReplayReader.java b/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosReplayReader.java index eed56cff..1585f9eb 100644 --- a/altosui/AltosReplayReader.java +++ b/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosReplayReader.java @@ -15,13 +15,8 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package altosui; +package org.altusmetrum.AltosLib; -import java.awt.*; -import java.awt.event.*; -import javax.swing.*; -import javax.swing.filechooser.FileNameExtensionFilter; -import javax.swing.table.*; import java.io.*; import java.util.*; import java.text.*; @@ -45,9 +40,9 @@ public class AltosReplayReader extends AltosFlightReader { public void close (boolean interrupted) { } - void update(AltosState state) throws InterruptedException { + public void update(AltosState state) throws InterruptedException { /* Make it run in realtime after the rocket leaves the pad */ - if (state.state > Altos.ao_flight_pad) + if (state.state > AltosLib.ao_flight_pad) Thread.sleep((int) (Math.min(state.time_change,10) * 1000)); } diff --git a/altosui/AltosState.java b/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosState.java index da498bc1..893e19a9 100644 --- a/altosui/AltosState.java +++ b/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosState.java @@ -19,62 +19,62 @@ * Track flight state from telemetry or eeprom data stream */ -package altosui; +package org.altusmetrum.AltosLib; public class AltosState { - AltosRecord data; + public AltosRecord data; /* derived data */ - long report_time; + public long report_time; - double time; - double time_change; - int tick; + public double time; + public double time_change; + public int tick; - int state; - boolean landed; - boolean ascent; /* going up? */ - boolean boost; /* under power */ + public int state; + public boolean landed; + public boolean ascent; /* going up? */ + public boolean boost; /* under power */ - double ground_altitude; - double height; - double speed; - double acceleration; - double battery; - double temperature; - double main_sense; - double drogue_sense; - double baro_speed; + public double ground_altitude; + public double height; + public double speed; + public double acceleration; + public double battery; + public double temperature; + public double main_sense; + public double drogue_sense; + public double baro_speed; - double max_height; - double max_acceleration; - double max_speed; - double max_baro_speed; + public double max_height; + public double max_acceleration; + public double max_speed; + public double max_baro_speed; - AltosGPS gps; + public AltosGPS gps; - double pad_lat; - double pad_lon; - double pad_alt; + public double pad_lat; + public double pad_lon; + public double pad_alt; - static final int MIN_PAD_SAMPLES = 10; + public static final int MIN_PAD_SAMPLES = 10; - int npad; - int ngps; - int gps_waiting; - boolean gps_ready; + public int npad; + public int ngps; + public int gps_waiting; + public boolean gps_ready; - AltosGreatCircle from_pad; - double elevation; /* from pad */ - double range; /* total distance */ + public AltosGreatCircle from_pad; + public double elevation; /* from pad */ + public double range; /* total distance */ - double gps_height; + public double gps_height; - int speak_tick; - double speak_altitude; + public int speak_tick; + public double speak_altitude; - void init (AltosRecord cur, AltosState prev_state) { + public void init (AltosRecord cur, AltosState prev_state) { int i; AltosRecord prev; @@ -135,7 +135,7 @@ public class AltosState { time = tick / 100.0; - if (cur.new_gps && (state == Altos.ao_flight_pad || state == Altos.ao_flight_idle)) { + if (cur.new_gps && (state == AltosLib.ao_flight_pad || state == AltosLib.ao_flight_idle)) { /* Track consecutive 'good' gps reports, waiting for 10 of them */ if (data.gps != null && data.gps.locked && data.gps.nsat >= 4) @@ -165,9 +165,9 @@ public class AltosState { gps_ready = gps_waiting == 0; - ascent = (Altos.ao_flight_boost <= state && - state <= Altos.ao_flight_coast); - boost = (Altos.ao_flight_boost == state); + ascent = (AltosLib.ao_flight_boost <= state && + state <= AltosLib.ao_flight_coast); + boost = (AltosLib.ao_flight_boost == state); /* Only look at accelerometer data under boost */ if (boost && acceleration > max_acceleration) diff --git a/altosui/AltosTelemetry.java b/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosTelemetry.java index a05269f4..beac072e 100644 --- a/altosui/AltosTelemetry.java +++ b/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosTelemetry.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package altosui; +package org.altusmetrum.AltosLib; import java.lang.*; import java.text.*; diff --git a/altosui/AltosTelemetryIterable.java b/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosTelemetryIterable.java index 278cbfb7..73026bf7 100644 --- a/altosui/AltosTelemetryIterable.java +++ b/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosTelemetryIterable.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package altosui; +package org.altusmetrum.AltosLib; import java.io.*; import java.util.*; @@ -62,7 +62,7 @@ public class AltosTelemetryIterable extends AltosRecordIterable { current_tick = tick; record.tick = current_tick; } - if (!saw_boost && record.state >= Altos.ao_flight_boost) + if (!saw_boost && record.state >= AltosLib.ao_flight_boost) { saw_boost = true; boost_tick = record.tick; diff --git a/altosui/AltosTelemetryMap.java b/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosTelemetryMap.java index d906100f..003cb6a9 100644 --- a/altosui/AltosTelemetryMap.java +++ b/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosTelemetryMap.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package altosui; +package org.altusmetrum.AltosLib; import java.lang.*; import java.text.*; import java.util.HashMap; diff --git a/altosui/AltosTelemetryReader.java b/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosTelemetryReader.java index 1f327a67..ae4dd554 100644 --- a/altosui/AltosTelemetryReader.java +++ b/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosTelemetryReader.java @@ -15,16 +15,15 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package altosui; +package org.altusmetrum.AltosLib; import java.lang.*; import java.text.*; import java.io.*; import java.util.concurrent.*; -class AltosTelemetryReader extends AltosFlightReader { - AltosDevice device; - AltosSerial serial; +public class AltosTelemetryReader extends AltosFlightReader { + AltosLink link; AltosLog log; AltosRecord previous; double frequency; @@ -32,7 +31,7 @@ class AltosTelemetryReader extends AltosFlightReader { LinkedBlockingQueue<AltosLine> telem; - AltosRecord read() throws InterruptedException, ParseException, AltosCRCException, IOException { + public AltosRecord read() throws InterruptedException, ParseException, AltosCRCException, IOException { AltosLine l = telem.take(); if (l.line == null) throw new IOException("IO error"); @@ -41,52 +40,53 @@ class AltosTelemetryReader extends AltosFlightReader { return next; } - void flush() { + public void flush() { telem.clear(); } - void close(boolean interrupted) { - serial.remove_monitor(telem); + public void close(boolean interrupted) { + link.remove_monitor(telem); log.close(); - serial.close(); + link.close(); } public void set_frequency(double in_frequency) throws InterruptedException, TimeoutException { frequency = in_frequency; - serial.set_radio_frequency(frequency); + link.set_radio_frequency(frequency); } - void save_frequency() { - AltosPreferences.set_frequency(device.getSerial(), frequency); + public void save_frequency() { + AltosPreferences.set_frequency(link.serial, frequency); } - void set_telemetry(int in_telemetry) { + public void set_telemetry(int in_telemetry) { telemetry = in_telemetry; - serial.set_telemetry(telemetry); + link.set_telemetry(telemetry); } - void save_telemetry() { - AltosPreferences.set_telemetry(device.getSerial(), telemetry); + public void save_telemetry() { + AltosPreferences.set_telemetry(link.serial, telemetry); } - File backing_file() { + public void set_monitor(boolean monitor) { + link.set_monitor(monitor); + } + + public File backing_file() { return log.file(); } - public AltosTelemetryReader (AltosDevice in_device) - throws FileNotFoundException, AltosSerialInUseException, IOException, InterruptedException, TimeoutException { - device = in_device; - serial = new AltosSerial(device); - log = new AltosLog(serial); - name = device.toShortString(); + public AltosTelemetryReader (AltosLink in_link) + throws IOException, InterruptedException, TimeoutException { + link = in_link; + log = new AltosLog(link); + name = link.name; previous = null; - telem = new LinkedBlockingQueue<AltosLine>(); - frequency = AltosPreferences.frequency(device.getSerial()); + frequency = AltosPreferences.frequency(link.serial); set_frequency(frequency); - telemetry = AltosPreferences.telemetry(device.getSerial()); + telemetry = AltosPreferences.telemetry(link.serial); set_telemetry(telemetry); - serial.set_callsign(AltosPreferences.callsign()); - serial.add_monitor(telem); + link.add_monitor(telem); } } diff --git a/altosui/AltosTelemetryRecord.java b/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosTelemetryRecord.java index cfac309a..017d5be9 100644 --- a/altosui/AltosTelemetryRecord.java +++ b/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosTelemetryRecord.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package altosui; +package org.altusmetrum.AltosLib; public interface AltosTelemetryRecord { diff --git a/altosui/AltosTelemetryRecordCompanion.java b/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosTelemetryRecordCompanion.java index 52d7f4cf..6ad17244 100644 --- a/altosui/AltosTelemetryRecordCompanion.java +++ b/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosTelemetryRecordCompanion.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package altosui; +package org.altusmetrum.AltosLib; public class AltosTelemetryRecordCompanion extends AltosTelemetryRecordRaw { diff --git a/altosui/AltosTelemetryRecordConfiguration.java b/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosTelemetryRecordConfiguration.java index b029d120..25242edc 100644 --- a/altosui/AltosTelemetryRecordConfiguration.java +++ b/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosTelemetryRecordConfiguration.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package altosui; +package org.altusmetrum.AltosLib; public class AltosTelemetryRecordConfiguration extends AltosTelemetryRecordRaw { diff --git a/altosui/AltosTelemetryRecordGeneral.java b/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosTelemetryRecordGeneral.java index 722baba3..5e157a54 100644 --- a/altosui/AltosTelemetryRecordGeneral.java +++ b/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosTelemetryRecordGeneral.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package altosui; +package org.altusmetrum.AltosLib; import java.lang.*; import java.text.*; diff --git a/altosui/AltosTelemetryRecordLegacy.java b/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosTelemetryRecordLegacy.java index f2f63358..2dac5ca4 100644 --- a/altosui/AltosTelemetryRecordLegacy.java +++ b/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosTelemetryRecordLegacy.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package altosui; +package org.altusmetrum.AltosLib; import java.lang.*; import java.text.*; @@ -239,7 +239,7 @@ public class AltosTelemetryRecordLegacy extends AltosRecord implements AltosTele serial = map.get_int(AO_TELEM_SERIAL, MISSING); flight = map.get_int(AO_TELEM_FLIGHT, MISSING); rssi = map.get_int(AO_TELEM_RSSI, MISSING); - state = Altos.state(map.get_string(AO_TELEM_STATE, "invalid")); + state = AltosLib.state(map.get_string(AO_TELEM_STATE, "invalid")); tick = map.get_int(AO_TELEM_TICK, 0); /* raw sensor values */ @@ -298,7 +298,7 @@ public class AltosTelemetryRecordLegacy extends AltosRecord implements AltosTele status = AltosParse.parse_hex(words[i++]); AltosParse.word(words[i++], "STATE"); - state = Altos.state(words[i++]); + state = AltosLib.state(words[i++]); tick = AltosParse.parse_int(words[i++]); @@ -391,22 +391,22 @@ public class AltosTelemetryRecordLegacy extends AltosRecord implements AltosTele int adjust; private int int8(int i) { - return Altos.int8(bytes, i + 1 + adjust); + return AltosLib.int8(bytes, i + 1 + adjust); } private int uint8(int i) { - return Altos.uint8(bytes, i + 1 + adjust); + return AltosLib.uint8(bytes, i + 1 + adjust); } private int int16(int i) { - return Altos.int16(bytes, i + 1 + adjust); + return AltosLib.int16(bytes, i + 1 + adjust); } private int uint16(int i) { - return Altos.uint16(bytes, i + 1 + adjust); + return AltosLib.uint16(bytes, i + 1 + adjust); } private int uint32(int i) { - return Altos.uint32(bytes, i + 1 + adjust); + return AltosLib.uint32(bytes, i + 1 + adjust); } private String string(int i, int l) { - return Altos.string(bytes, i + 1 + adjust, l); + return AltosLib.string(bytes, i + 1 + adjust, l); } static final int AO_GPS_NUM_SAT_MASK = (0xf << 0); @@ -422,7 +422,7 @@ public class AltosTelemetryRecordLegacy extends AltosRecord implements AltosTele version = 4; adjust = 0; - if (bytes.length == Altos.ao_telemetry_0_8_len + 4) { + if (bytes.length == AltosLib.ao_telemetry_0_8_len + 4) { serial = uint8(0); adjust = -1; } else diff --git a/altosui/AltosTelemetryRecordLocation.java b/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosTelemetryRecordLocation.java index 80db454d..cddb773d 100644 --- a/altosui/AltosTelemetryRecordLocation.java +++ b/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosTelemetryRecordLocation.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package altosui; +package org.altusmetrum.AltosLib; public class AltosTelemetryRecordLocation extends AltosTelemetryRecordRaw { diff --git a/altosui/AltosTelemetryRecordRaw.java b/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosTelemetryRecordRaw.java index fb2b495c..4c0c4972 100644 --- a/altosui/AltosTelemetryRecordRaw.java +++ b/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosTelemetryRecordRaw.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package altosui; +package org.altusmetrum.AltosLib; import java.lang.*; import java.text.*; @@ -52,7 +52,7 @@ public class AltosTelemetryRecordRaw implements AltosTelemetryRecord { int[] bytes; try { - bytes = Altos.hexbytes(hex); + bytes = AltosLib.hexbytes(hex); } catch (NumberFormatException ne) { throw new ParseException(ne.getMessage(), 0); } @@ -65,16 +65,16 @@ public class AltosTelemetryRecordRaw implements 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: @@ -98,10 +98,10 @@ public class AltosTelemetryRecordRaw implements 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: @@ -111,27 +111,27 @@ public class AltosTelemetryRecordRaw implements AltosTelemetryRecord { } public int int8(int off) { - return Altos.int8(bytes, off + 1); + return AltosLib.int8(bytes, off + 1); } public int uint8(int off) { - return Altos.uint8(bytes, off + 1); + return AltosLib.uint8(bytes, off + 1); } public int int16(int off) { - return Altos.int16(bytes, off + 1); + return AltosLib.int16(bytes, off + 1); } public int uint16(int off) { - return Altos.uint16(bytes, off + 1); + return AltosLib.uint16(bytes, off + 1); } public int uint32(int off) { - return Altos.uint32(bytes, off + 1); + return AltosLib.uint32(bytes, off + 1); } public String string(int off, int l) { - return Altos.string(bytes, off + 1, l); + return AltosLib.string(bytes, off + 1, l); } public AltosTelemetryRecordRaw(int[] in_bytes) { diff --git a/altosui/AltosTelemetryRecordSatellite.java b/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosTelemetryRecordSatellite.java index 2dd782ad..2526afb6 100644 --- a/altosui/AltosTelemetryRecordSatellite.java +++ b/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosTelemetryRecordSatellite.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package altosui; +package org.altusmetrum.AltosLib; public class AltosTelemetryRecordSatellite extends AltosTelemetryRecordRaw { int channels; diff --git a/altosui/AltosTelemetryRecordSensor.java b/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosTelemetryRecordSensor.java index 96fee81f..cfaf90b0 100644 --- a/altosui/AltosTelemetryRecordSensor.java +++ b/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosTelemetryRecordSensor.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package altosui; +package org.altusmetrum.AltosLib; public class AltosTelemetryRecordSensor extends AltosTelemetryRecordRaw { diff --git a/configure.ac b/configure.ac index 19db6d27..6446f651 100644 --- a/configure.ac +++ b/configure.ac @@ -113,6 +113,7 @@ AC_OUTPUT([ Makefile altosui/Makefile altosui/AltosVersion.java +altosui/altoslib/Makefile altosui/libaltos/Makefile ao-tools/Makefile ao-tools/lib/Makefile |