diff options
Diffstat (limited to 'altoslib')
-rw-r--r-- | altoslib/AltosConfigData.java | 426 | ||||
-rw-r--r-- | altoslib/AltosConfigValues.java | 79 | ||||
-rw-r--r-- | altoslib/AltosLink.java | 8 | ||||
-rw-r--r-- | altoslib/AltosMs5607.java | 37 | ||||
-rw-r--r-- | altoslib/AltosMs5607Query.java | 33 | ||||
-rw-r--r-- | altoslib/AltosState.java | 3 | ||||
-rw-r--r-- | altoslib/Makefile.am | 1 |
7 files changed, 488 insertions, 99 deletions
diff --git a/altoslib/AltosConfigData.java b/altoslib/AltosConfigData.java index 45a88783..99b8e39d 100644 --- a/altoslib/AltosConfigData.java +++ b/altoslib/AltosConfigData.java @@ -26,31 +26,56 @@ public class AltosConfigData implements Iterable<String> { /* Version information */ public String manufacturer; public String product; - public String version; - public int log_format; public int serial; + public int flight; + public int log_format; + public String version; /* Strings returned */ public LinkedList<String> lines; /* Config information */ - public int config_major; - public int config_minor; + /* HAS_FLIGHT*/ public int main_deploy; public int apogee_delay; - public int radio_channel; - public int radio_setting; + public int apogee_lockout; + + /* HAS_RADIO */ public int radio_frequency; public String callsign; - public int accel_cal_plus, accel_cal_minus; + public int radio_enable; public int radio_calibration; + /* Old HAS_RADIO values */ + public int radio_channel; + public int radio_setting; + + /* HAS_ACCEL */ + public int accel_cal_plus, accel_cal_minus; + public int pad_orientation; + + /* HAS_LOG */ public int flight_log_max; + + /* HAS_IGNITE */ public int ignite_mode; - public int stored_flight; + + /* HAS_AES */ + public String aes_key; + + /* AO_PYRO_NUM */ + public AltosPyro[] pyros; + public int npyro; + public int pyro; + + /* HAS_APRS */ + public int aprs_interval; + + /* Storage info replies */ public int storage_size; public int storage_erase_unit; - public AltosPyro[] pyros; + /* Log listing replies */ + public int stored_flight; public static String get_string(String line, String label) throws ParseException { if (line.startsWith(label)) { @@ -85,6 +110,9 @@ public class AltosConfigData implements Iterable<String> { if (stored_flight == 0) return 1; return 0; + case AltosLib.AO_LOG_FORMAT_TELEMETRY: + case AltosLib.AO_LOG_FORMAT_TELESCIENCE: + return 1; default: if (flight_log_max <= 0) return 1; @@ -111,7 +139,7 @@ public class AltosConfigData implements Iterable<String> { return r; } - + public int compare_version(String other) { int[] me = parse_version(version); int[] them = parse_version(other); @@ -130,71 +158,343 @@ public class AltosConfigData implements Iterable<String> { return 0; } - public AltosConfigData(AltosLink link) throws InterruptedException, TimeoutException { - link.printf("c s\nf\nl\nv\n"); + public void reset() { lines = new LinkedList<String>(); - radio_setting = 0; - radio_frequency = 0; - stored_flight = 0; - serial = -1; + + manufacturer = "unknown"; + product = "unknown"; + serial = 0; + flight = 0; + log_format = AltosLib.AO_LOG_FORMAT_UNKNOWN; + version = "unknown"; + + main_deploy = -1; + apogee_delay = -1; + apogee_lockout = -1; + + radio_frequency = -1; + callsign = null; + radio_enable = -1; + radio_calibration = -1; + radio_channel = -1; + radio_setting = -1; + + accel_cal_plus = -1; + accel_cal_minus = -1; + pad_orientation = -1; + + flight_log_max = -1; + ignite_mode = -1; + + aes_key = ""; + + pyro = 0; + npyro = 0; pyros = null; - int npyro = 0; - int pyro = 0; + aprs_interval = -1; + + storage_size = -1; + storage_erase_unit = -1; + stored_flight = -1; + } + + public void parse_line(String line) { + lines.add(line); + /* Version replies */ + try { manufacturer = get_string(line, "manufacturer"); } catch (Exception e) {} + try { product = get_string(line, "product"); } catch (Exception e) {} + try { serial = get_int(line, "serial-number"); } catch (Exception e) {} + try { flight = get_int(line, "current-flight"); } catch (Exception e) {} + try { log_format = get_int(line, "log-format"); } catch (Exception e) {} + try { version = get_string(line, "software-version"); } catch (Exception e) {} + + /* Version also contains MS5607 info, which we ignore here */ + + /* Config show replies */ + + /* HAS_FLIGHT */ + try { main_deploy = get_int(line, "Main deploy:"); } catch (Exception e) {} + try { apogee_delay = get_int(line, "Apogee delay:"); } catch (Exception e) {} + try { apogee_lockout = get_int(line, "Apogee lockout:"); } catch (Exception e) {} + + /* HAS_RADIO */ + try { + radio_frequency = get_int(line, "Frequency:"); + if (radio_frequency < 0) + radio_frequency = 434550; + } catch (Exception e) {} + try { callsign = get_string(line, "Callsign:"); } catch (Exception e) {} + try { radio_enable = get_int(line, "Radio enable:"); } catch (Exception e) {} + try { radio_calibration = get_int(line, "Radio cal:"); } catch (Exception e) {} + + /* Old HAS_RADIO values */ + try { radio_channel = get_int(line, "Radio channel:"); } catch (Exception e) {} + try { radio_setting = get_int(line, "Radio setting:"); } catch (Exception e) {} + + /* HAS_ACCEL */ + try { + if (line.startsWith("Accel cal")) { + String[] bits = line.split("\\s+"); + if (bits.length >= 6) { + accel_cal_plus = Integer.parseInt(bits[3]); + accel_cal_minus = Integer.parseInt(bits[5]); + } + } + } catch (Exception e) {} + try { pad_orientation = get_int(line, "Pad orientation:"); } catch (Exception e) {} + + /* HAS_LOG */ + try { flight_log_max = get_int(line, "Max flight log:"); } catch (Exception e) {} + + /* HAS_IGNITE */ + try { ignite_mode = get_int(line, "Ignite mode:"); } catch (Exception e) {} + + /* HAS_AES */ + try { aes_key = get_string(line, "AES key:"); } catch (Exception e) {} + + /* AO_PYRO_NUM */ + try { + npyro = get_int(line, "Pyro-count:"); + pyros = new AltosPyro[npyro]; + pyro = 0; + } catch (Exception e) {} + if (npyro > 0) { + try { + AltosPyro p = new AltosPyro(pyro, line); + if (pyro < npyro) + pyros[pyro++] = p; + } catch (Exception e) {} + } + + /* HAS_APRS */ + try { aprs_interval = get_int(line, "APRS interval:"); } catch (Exception e) {} + + /* Storage info replies */ + try { storage_size = get_int(line, "Storage size:"); } catch (Exception e) {} + try { storage_erase_unit = get_int(line, "Storage erase unit"); } catch (Exception e) {} + + /* Log listing replies */ + try { get_int(line, "flight"); stored_flight++; } catch (Exception e) {} + } + + public AltosConfigData() { + reset(); + } + + private void read_link(AltosLink link, String finished) throws InterruptedException, TimeoutException { for (;;) { String line = link.get_reply(); if (line == null) throw new TimeoutException(); if (line.contains("Syntax error")) continue; - lines.add(line); - if (pyro < npyro - 1) { - if (pyros == null) - pyros = new AltosPyro[npyro]; - try { - pyros[pyro] = new AltosPyro(pyro, line); - } catch (ParseException e) { - } - ++pyro; - continue; - } - try { serial = get_int(line, "serial-number"); } catch (Exception e) {} - try { log_format = get_int(line, "log-format"); } catch (Exception e) {} - try { main_deploy = get_int(line, "Main deploy:"); } catch (Exception e) {} - try { apogee_delay = get_int(line, "Apogee delay:"); } catch (Exception e) {} - try { radio_channel = get_int(line, "Radio channel:"); } catch (Exception e) {} - try { radio_setting = get_int(line, "Radio setting:"); } catch (Exception e) {} - try { - radio_frequency = get_int(line, "Frequency:"); - if (radio_frequency < 0) - radio_frequency = 434550; - } catch (Exception e) {} - try { - if (line.startsWith("Accel cal")) { - String[] bits = line.split("\\s+"); - if (bits.length >= 6) { - accel_cal_plus = Integer.parseInt(bits[3]); - accel_cal_minus = Integer.parseInt(bits[5]); - } - } - } catch (Exception e) {} - try { radio_calibration = get_int(line, "Radio cal:"); } catch (Exception e) {} - try { flight_log_max = get_int(line, "Max flight log:"); } catch (Exception e) {} - try { ignite_mode = get_int(line, "Ignite mode:"); } catch (Exception e) {} - try { callsign = get_string(line, "Callsign:"); } catch (Exception e) {} - try { version = get_string(line,"software-version"); } catch (Exception e) {} - try { product = get_string(line,"product"); } catch (Exception e) {} - try { manufacturer = get_string(line,"manufacturer"); } catch (Exception e) {} - - try { get_int(line, "flight"); stored_flight++; } catch (Exception e) {} - try { storage_size = get_int(line, "Storage size:"); } catch (Exception e) {} - try { storage_erase_unit = get_int(line, "Storage erase unit"); } catch (Exception e) {} - try { npyro = get_int(line, "Pyro-count:"); pyro = 0; } catch (Exception e) {} + this.parse_line(line); /* signals the end of the version info */ - if (line.startsWith("software-version")) + if (line.startsWith(finished)) break; } } -}
\ No newline at end of file + public boolean has_frequency() { + return radio_frequency >= 0 || radio_setting >= 0 || radio_channel >= 0; + } + + public void set_frequency(double freq) { + int frequency = radio_frequency; + int setting = radio_setting; + + if (frequency > 0) { + radio_frequency = (int) Math.floor (freq * 1000 + 0.5); + radio_channel = -1; + } else if (setting > 0) { + radio_setting =AltosConvert.radio_frequency_to_setting(freq, + radio_calibration); + radio_channel = -1; + } else { + radio_channel = AltosConvert.radio_frequency_to_channel(freq); + } + } + + public double frequency() { + int channel = radio_channel; + int setting = radio_setting; + if (channel < 0) + channel = 0; + if (setting < 0) + setting = 0; + + return AltosConvert.radio_to_frequency(radio_frequency, + setting, + radio_calibration, + channel); + } + + public int log_limit() { + if (storage_size > 0 && storage_erase_unit > 0) { + int log_limit = storage_size - storage_erase_unit; + if (log_limit > 0) + return log_limit / 1024; + } + return 1024; + } + + public void get_values(AltosConfigValues source) { + + /* HAS_FLIGHT */ + if (main_deploy >= 0) + main_deploy = source.main_deploy(); + if (apogee_delay >= 0) + apogee_delay = source.apogee_delay(); + if (apogee_lockout >= 0) + apogee_lockout = source.apogee_lockout(); + + /* HAS_RADIO */ + if (has_frequency()) + set_frequency(source.radio_frequency()); + if (radio_enable >= 0) + radio_enable = source.radio_enable(); + if (callsign != null) + callsign = source.callsign(); + if (radio_calibration >= 0) + radio_calibration = source.radio_calibration(); + + /* HAS_ACCEL */ + if (pad_orientation >= 0) + pad_orientation = source.pad_orientation(); + + /* HAS_LOG */ + if (flight_log_max >= 0) + flight_log_max = source.flight_log_max(); + + /* HAS_IGNITE */ + if (ignite_mode >= 0) + ignite_mode = source.ignite_mode(); + + /* AO_PYRO_NUM */ + if (npyro > 0) + pyros = source.pyros(); + + if (aprs_interval >= 0) + aprs_interval = source.aprs_interval(); + } + + public void set_values(AltosConfigValues dest) { + dest.set_serial(serial); + dest.set_product(product); + dest.set_version(version); + dest.set_main_deploy(main_deploy); + dest.set_apogee_delay(apogee_delay); + dest.set_apogee_lockout(apogee_lockout); + dest.set_radio_calibration(radio_calibration); + dest.set_radio_frequency(frequency()); + boolean max_enabled = true; + switch (log_format) { + case AltosLib.AO_LOG_FORMAT_TINY: + max_enabled = false; + break; + default: + if (stored_flight >= 0) + max_enabled = false; + break; + } + dest.set_flight_log_max_enabled(max_enabled); + dest.set_radio_enable(radio_enable); + dest.set_flight_log_max_limit(log_limit()); + dest.set_flight_log_max(flight_log_max); + dest.set_ignite_mode(ignite_mode); + dest.set_pad_orientation(pad_orientation); + dest.set_callsign(callsign); + if (npyro > 0) + dest.set_pyros(pyros); + else + dest.set_pyros(null); + dest.set_aprs_interval(aprs_interval); + } + + public void save(AltosLink link, boolean remote) throws InterruptedException, TimeoutException { + + /* HAS_FLIGHT */ + if (main_deploy >= 0) + link.printf("c m %d\n", main_deploy); + if (apogee_delay >= 0) + link.printf("c d %d\n", apogee_delay); + if (apogee_lockout >= 0) + link.printf("c L %d\n", apogee_lockout); + + /* Don't mess with radio calibration when remote */ + if (radio_calibration > 0 && !remote) + link.printf("c f %d\n", radio_calibration); + + /* HAS_RADIO */ + if (has_frequency()) { + boolean has_frequency = radio_frequency >= 0; + boolean has_setting = radio_setting > 0; + double frequency = frequency(); + link.set_radio_frequency(frequency, + has_frequency, + has_setting, + radio_calibration); + /* When remote, reset the dongle frequency at the same time */ + if (remote) { + link.stop_remote(); + link.set_radio_frequency(frequency); + link.start_remote(); + } + } + + if (callsign != null) + link.printf("c c %s\n", callsign); + if (radio_enable >= 0) + link.printf("c e %d\n", radio_enable); + + /* HAS_ACCEL */ + /* UI doesn't support accel cal */ + if (pad_orientation >= 0) + link.printf("c o %d\n", pad_orientation); + + /* HAS_LOG */ + if (flight_log_max != 0) + link.printf("c l %d\n", flight_log_max); + + /* HAS_IGNITE */ + if (ignite_mode >= 0) + link.printf("c i %d\n", ignite_mode); + + /* HAS_AES */ + /* UI doesn't support AES key config */ + + /* AO_PYRO_NUM */ + if (pyros.length > 0) { + for (int p = 0; p < pyros.length; p++) { + link.printf("c P %s\n", + pyros[p].toString()); + } + } + + /* HAS_APRS */ + if (aprs_interval >= 0) + link.printf("c A %d\n", aprs_interval); + + link.printf("c w\n"); + link.flush_output(); + } + + public AltosConfigData(AltosLink link) throws InterruptedException, TimeoutException { + reset(); + link.printf("c s\nf\nv\n"); + read_link(link, "software-version"); + System.out.printf("Log format %d\n", log_format); + switch (log_format) { + case AltosLib.AO_LOG_FORMAT_FULL: + case AltosLib.AO_LOG_FORMAT_TINY: + case AltosLib.AO_LOG_FORMAT_MEGAMETRUM: + link.printf("l\n"); + read_link(link, "done"); + default: + break; + } + } + +} diff --git a/altoslib/AltosConfigValues.java b/altoslib/AltosConfigValues.java new file mode 100644 index 00000000..40d5217e --- /dev/null +++ b/altoslib/AltosConfigValues.java @@ -0,0 +1,79 @@ +/* + * Copyright © 2012 Keith Packard <keithp@keithp.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ + +package org.altusmetrum.AltosLib; + +public interface AltosConfigValues { + /* set and get all of the dialog values */ + public abstract void set_product(String product); + + public abstract void set_version(String version); + + public abstract void set_serial(int serial); + + public abstract void set_main_deploy(int new_main_deploy); + + public abstract int main_deploy(); + + public abstract void set_apogee_delay(int new_apogee_delay); + + public abstract int apogee_delay(); + + public abstract void set_apogee_lockout(int new_apogee_lockout); + + public abstract int apogee_lockout(); + + public abstract void set_radio_frequency(double new_radio_frequency); + + public abstract double radio_frequency(); + + public abstract void set_radio_calibration(int new_radio_calibration); + + public abstract int radio_calibration(); + + public abstract void set_radio_enable(int new_radio_enable); + + public abstract int radio_enable(); + + public abstract void set_callsign(String new_callsign); + + public abstract String callsign(); + + public abstract void set_flight_log_max(int new_flight_log_max); + + public abstract void set_flight_log_max_enabled(boolean enable); + + public abstract int flight_log_max(); + + public abstract void set_flight_log_max_limit(int flight_log_max_limit); + + public abstract void set_ignite_mode(int new_ignite_mode); + + public abstract int ignite_mode(); + + public abstract void set_pad_orientation(int new_pad_orientation); + + public abstract int pad_orientation(); + + public abstract void set_pyros(AltosPyro[] new_pyros); + + public abstract AltosPyro[] pyros(); + + public abstract int aprs_interval(); + + public abstract void set_aprs_interval(int new_aprs_interval); +} diff --git a/altoslib/AltosLink.java b/altoslib/AltosLink.java index 6d510563..1b722026 100644 --- a/altoslib/AltosLink.java +++ b/altoslib/AltosLink.java @@ -284,8 +284,8 @@ public abstract class AltosLink implements Runnable { frequency = in_frequency; config_data(); set_radio_frequency(frequency, - config_data.radio_frequency != 0, - config_data.radio_setting != 0, + config_data.radio_frequency > 0, + config_data.radio_setting > 0, config_data.radio_calibration); } @@ -339,10 +339,10 @@ public abstract class AltosLink implements Runnable { 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); + if (debug) + System.out.printf("start remote %7.3f\n", frequency); set_radio_frequency(frequency); set_callsign(AltosPreferences.callsign()); printf("p\nE 0\n"); diff --git a/altoslib/AltosMs5607.java b/altoslib/AltosMs5607.java index 148a9f92..318fea4d 100644 --- a/altoslib/AltosMs5607.java +++ b/altoslib/AltosMs5607.java @@ -82,6 +82,43 @@ public class AltosMs5607 { return pa; } + public boolean parse_line(String line) { + String[] items = line.split("\\s+"); + if (line.startsWith("Pressure:")) { + if (items.length >= 2) + raw_pres = Integer.parseInt(items[1]); + } else if (line.startsWith("Temperature:")) { + if (items.length >= 2) + raw_temp = Integer.parseInt(items[1]); + } else if (line.startsWith("ms5607 reserved:")) { + if (items.length >= 3) + reserved = Integer.parseInt(items[2]); + } else if (line.startsWith("ms5607 sens:")) { + if (items.length >= 3) + sens = Integer.parseInt(items[2]); + } else if (line.startsWith("ms5607 off:")) { + if (items.length >= 3) + off = Integer.parseInt(items[2]); + } else if (line.startsWith("ms5607 tcs:")) { + if (items.length >= 3) + tcs = Integer.parseInt(items[2]); + } else if (line.startsWith("ms5607 tco:")) { + if (items.length >= 3) + tco = Integer.parseInt(items[2]); + } else if (line.startsWith("ms5607 tref:")) { + if (items.length >= 3) + tref = Integer.parseInt(items[2]); + } else if (line.startsWith("ms5607 tempsens:")) { + if (items.length >= 3) + tempsens = Integer.parseInt(items[2]); + } else if (line.startsWith("ms5607 crc:")) { + if (items.length >= 3) + crc = Integer.parseInt(items[2]); + } else if (line.startsWith("Altitude")) + return false; + return true; + } + public AltosMs5607() { raw_pres = AltosRecord.MISSING; raw_temp = AltosRecord.MISSING; diff --git a/altoslib/AltosMs5607Query.java b/altoslib/AltosMs5607Query.java index 3c746795..1aaec334 100644 --- a/altoslib/AltosMs5607Query.java +++ b/altoslib/AltosMs5607Query.java @@ -27,38 +27,7 @@ class AltosMs5607Query extends AltosMs5607 { if (line == null) { throw new TimeoutException(); } - String[] items = line.split("\\s+"); - if (line.startsWith("Pressure:")) { - if (items.length >= 2) - raw_pres = Integer.parseInt(items[1]); - } else if (line.startsWith("Temperature:")) { - if (items.length >= 2) - raw_temp = Integer.parseInt(items[1]); - } else if (line.startsWith("ms5607 reserved:")) { - if (items.length >= 3) - reserved = Integer.parseInt(items[2]); - } else if (line.startsWith("ms5607 sens:")) { - if (items.length >= 3) - sens = Integer.parseInt(items[2]); - } else if (line.startsWith("ms5607 off:")) { - if (items.length >= 3) - off = Integer.parseInt(items[2]); - } else if (line.startsWith("ms5607 tcs:")) { - if (items.length >= 3) - tcs = Integer.parseInt(items[2]); - } else if (line.startsWith("ms5607 tco:")) { - if (items.length >= 3) - tco = Integer.parseInt(items[2]); - } else if (line.startsWith("ms5607 tref:")) { - if (items.length >= 3) - tref = Integer.parseInt(items[2]); - } else if (line.startsWith("ms5607 tempsens:")) { - if (items.length >= 3) - tempsens = Integer.parseInt(items[2]); - } else if (line.startsWith("ms5607 crc:")) { - if (items.length >= 3) - crc = Integer.parseInt(items[2]); - } else if (line.startsWith("Altitude")) + if (!parse_line(line)) break; } convert(); diff --git a/altoslib/AltosState.java b/altoslib/AltosState.java index f28dd1c6..218c598a 100644 --- a/altoslib/AltosState.java +++ b/altoslib/AltosState.java @@ -92,6 +92,9 @@ public class AltosState { public void init (AltosRecord cur, AltosState prev_state) { data = cur; + /* Discard previous state if it was for a different board */ + if (prev_state != null && prev_state.data.serial != data.serial) + prev_state = null; ground_altitude = data.ground_altitude(); altitude = data.altitude(); diff --git a/altoslib/Makefile.am b/altoslib/Makefile.am index 2579a650..0086bc65 100644 --- a/altoslib/Makefile.am +++ b/altoslib/Makefile.am @@ -12,6 +12,7 @@ AltosLibdir = $(datadir)/java AltosLib_JAVA = \ $(SRC)/AltosLib.java \ $(SRC)/AltosConfigData.java \ + $(SRC)/AltosConfigValues.java \ $(SRC)/AltosConvert.java \ $(SRC)/AltosCRCException.java \ $(SRC)/AltosEepromChunk.java \ |