+ public void reset() {
+ manufacturer = null;
+ product = null;
+ serial = AltosLib.MISSING;
+ flight = AltosLib.MISSING;
+ log_format = AltosLib.AO_LOG_FORMAT_UNKNOWN;
+ log_space = AltosLib.MISSING;
+ version = "unknown";
+ config_major = AltosLib.MISSING;
+ config_minor = AltosLib.MISSING;
+
+ main_deploy = AltosLib.MISSING;
+ apogee_delay = AltosLib.MISSING;
+ apogee_lockout = AltosLib.MISSING;
+
+ radio_frequency = AltosLib.MISSING;
+ callsign = null;
+ radio_enable = AltosLib.MISSING;
+ radio_calibration = AltosLib.MISSING;
+ radio_channel = AltosLib.MISSING;
+ radio_setting = AltosLib.MISSING;
+ telemetry_rate = AltosLib.MISSING;
+
+ accel_cal_plus_cooked = AltosLib.MISSING;
+ accel_cal_minus_cooked = AltosLib.MISSING;
+ accel_cal_plus_raw = AltosLib.MISSING;
+ accel_cal_minus_raw = AltosLib.MISSING;
+ pad_orientation = AltosLib.MISSING;
+ accel_cal_adjusted = false;
+
+ flight_log_max = AltosLib.MISSING;
+ log_fixed = AltosLib.MISSING;
+ ignite_mode = AltosLib.MISSING;
+
+ aes_key = null;
+
+ pyro = AltosLib.MISSING;
+ npyro = AltosLib.MISSING;
+ pyros = null;
+ pyro_firing_time = AltosLib.MISSING;
+
+ aprs_interval = AltosLib.MISSING;
+ aprs_ssid = AltosLib.MISSING;
+ aprs_format = AltosLib.MISSING;
+
+ beep = AltosLib.MISSING;
+
+ tracker_motion = AltosLib.MISSING;
+ tracker_interval = AltosLib.MISSING;
+
+ storage_size = AltosLib.MISSING;
+ storage_erase_unit = AltosLib.MISSING;
+ stored_flight = AltosLib.MISSING;
+
+ accel_zero_along = AltosLib.MISSING;
+ accel_zero_across = AltosLib.MISSING;
+ accel_zero_through = AltosLib.MISSING;
+ }
+
+ /* Return + accel calibration relative to a specific pad orientation */
+ public int accel_cal_plus(int pad_orientation) {
+ switch (pad_orientation) {
+ case AltosLib.AO_PAD_ORIENTATION_ANTENNA_UP:
+ return accel_cal_plus_cooked;
+ case AltosLib.AO_PAD_ORIENTATION_ANTENNA_DOWN:
+ return invert_accel_value(accel_cal_minus_cooked);
+ default:
+ return AltosLib.MISSING;
+ }
+ }
+
+ /* Return - accel calibration relative to a specific pad orientation */
+ public int accel_cal_minus(int pad_orientation) {
+ switch (pad_orientation) {
+ case AltosLib.AO_PAD_ORIENTATION_ANTENNA_UP:
+ return accel_cal_minus_cooked;
+ case AltosLib.AO_PAD_ORIENTATION_ANTENNA_DOWN:
+ return invert_accel_value(accel_cal_plus_cooked);
+ default:
+ return AltosLib.MISSING;
+ }
+ }
+
+ /* Once we have all of the values from the config data, compute the
+ * accel cal values relative to Antenna Up orientation.
+ */
+ private void adjust_accel_cal() {
+ if (!accel_cal_adjusted &&
+ pad_orientation != AltosLib.MISSING &&
+ accel_cal_plus_raw != AltosLib.MISSING &&
+ accel_cal_minus_raw != AltosLib.MISSING &&
+ log_format != AltosLib.AO_LOG_FORMAT_UNKNOWN)
+ {
+ switch (pad_orientation) {
+ case AltosLib.AO_PAD_ORIENTATION_ANTENNA_UP:
+ accel_cal_plus_cooked = accel_cal_plus_raw;
+ accel_cal_minus_cooked = accel_cal_minus_raw;
+ accel_cal_adjusted = true;
+ break;
+ case AltosLib.AO_PAD_ORIENTATION_ANTENNA_DOWN:
+ accel_cal_plus_cooked = invert_accel_value(accel_cal_minus_raw);
+ accel_cal_minus_cooked = invert_accel_value(accel_cal_plus_raw);
+ accel_cal_adjusted = true;
+ break;
+ default:
+ break;
+ }
+ }
+ }
+
+ public void parse_line(String 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 { log_space = get_int(line, "log-space"); } catch (Exception e) {}
+ try { altitude_32 = get_int(line, "altitude-32"); } catch (Exception e) {}
+ try { version = get_string(line, "software-version"); } catch (Exception e) {}
+
+ /* Version also contains MS5607 info, which we ignore here */
+
+ try { ms5607().reserved = get_int(line, "ms5607 reserved:"); } catch (Exception e) {}
+ try { ms5607().sens = get_int(line, "ms5607 sens:"); } catch (Exception e) {}
+ try { ms5607().off = get_int(line, "ms5607 off:"); } catch (Exception e) {}
+ try { ms5607().tcs = get_int(line, "ms5607 tcs:"); } catch (Exception e) {}
+ try { ms5607().tco = get_int(line, "ms5607 tco:"); } catch (Exception e) {}
+ try { ms5607().tref = get_int(line, "ms5607 tref:"); } catch (Exception e) {}
+ try { ms5607().tempsens = get_int(line, "ms5607 tempsens:"); } catch (Exception e) {}
+ try { ms5607().crc = get_int(line, "ms5607 crc:"); } catch (Exception e) {}
+
+ /* Config show replies */
+
+ try {
+ if (line.startsWith("Config version")) {
+ String[] bits = line.split("\\s+");
+ if (bits.length >= 3) {
+ String[] cfg = bits[2].split("\\.");
+
+ if (cfg.length >= 2) {
+ config_major = Integer.parseInt(cfg[0]);
+ config_minor = Integer.parseInt(cfg[1]);
+ }
+ }
+ }
+ } catch (Exception e) {}
+
+ /* 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) {}
+ try { telemetry_rate = get_int(line, "Telemetry rate:"); } 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_raw = Integer.parseInt(bits[3]);
+ accel_cal_minus_raw = Integer.parseInt(bits[5]);
+ accel_cal_adjusted = false;
+ }
+ }
+ } 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) {}
+ try { log_fixed = get_int(line, "Log fixed:"); } 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 != AltosLib.MISSING) {
+ try {
+ AltosPyro p = new AltosPyro(pyro, line);
+ if (pyro < npyro)
+ pyros[pyro++] = p;
+ } catch (Exception e) {}
+ }
+ try { pyro_firing_time = get_int(line, "Pyro time:") / 100.0; } catch (Exception e) {}
+
+ /* HAS_APRS */
+ try { aprs_interval = get_int(line, "APRS interval:"); } catch (Exception e) {}
+ try { aprs_ssid = get_int(line, "APRS SSID:"); } catch (Exception e) {}
+ try { aprs_format = get_int(line, "APRS format:"); } catch (Exception e) {}
+
+ /* HAS_BEEP */
+ try { beep = get_int(line, "Beeper setting:"); } catch (Exception e) {}
+
+ /* HAS_TRACKER */
+ try {
+ int[] values = get_values(line, "Tracker setting:");
+ tracker_motion = values[0];
+ tracker_interval = values[1];
+ } 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) {}
+
+ /* HAS_GYRO */
+ try {
+ if (line.startsWith("IMU cal along")) {
+ String[] bits = line.split("\\s+");
+ if (bits.length >= 8) {
+ accel_zero_along = Integer.parseInt(bits[3]);
+ accel_zero_across = Integer.parseInt(bits[5]);
+ accel_zero_through = Integer.parseInt(bits[7]);
+ }
+ }
+ } catch (Exception e) {}
+
+ /* Fix accel cal as soon as all of the necessary values appear */
+ adjust_accel_cal();
+ }
+
+ public AltosConfigData() {
+ reset();
+ }
+
+ private void read_link(AltosLink link, String finished) throws InterruptedException, TimeoutException {