2 * Copyright © 2011 Keith Packard <keithp@keithp.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
19 package org.altusmetrum.altoslib_14;
23 import java.util.concurrent.*;
25 /* Don't change the field names in this structure; they're part of all .eeprom files */
26 public class AltosConfigData {
28 /* Version information */
29 public String manufacturer;
30 public String product;
33 public int log_format;
35 public String version;
36 public int altitude_32;
37 public int config_major, config_minor;
39 /* Config information */
41 public int main_deploy;
42 public int apogee_delay;
43 public int apogee_lockout;
46 public int radio_frequency;
47 public String callsign;
48 public int radio_enable;
49 public int radio_calibration;
50 public int telemetry_rate;
51 /* Old HAS_RADIO values */
52 public int radio_channel;
53 public int radio_setting;
56 public int accel_cal_plus, accel_cal_minus;
57 private int accel_cal_plus_cooked, accel_cal_minus_cooked;
58 private boolean accel_cal_adjusted;
59 public int pad_orientation;
62 public int flight_log_max;
66 public int ignite_mode;
69 public String aes_key;
72 public AltosPyro[] pyros;
75 public double pyro_firing_time;
78 public int aprs_interval;
80 public int aprs_format;
81 public int aprs_offset;
87 public int radio_10mw;
89 /* Storage info replies */
90 public int storage_size;
91 public int storage_erase_unit;
93 /* Log listing replies */
94 public int stored_flight;
95 public AltosEepromFlight[] flights;
98 public int tracker_motion;
99 public int tracker_interval;
102 public int accel_zero_along, accel_zero_across, accel_zero_through;
107 public AltosMs5607 ms5607() {
109 ms5607 = new AltosMs5607();
113 public static String get_string(String line, String label) throws ParseException {
114 if (line.startsWith(label)) {
115 String quoted = line.substring(label.length()).trim();
117 if (quoted.startsWith("\""))
118 quoted = quoted.substring(1);
119 if (quoted.endsWith("\""))
120 quoted = quoted.substring(0,quoted.length()-1);
123 throw new ParseException("mismatch", 0);
126 public static int get_int(String line, String label) throws NumberFormatException, ParseException {
127 if (line.startsWith(label)) {
128 String tail = line.substring(label.length()).trim();
129 String[] tokens = tail.split("\\s+");
130 if (tokens.length > 0)
131 return Integer.parseInt(tokens[0]);
133 throw new ParseException("mismatch", 0);
136 public static int[] get_values(String line, String label) throws NumberFormatException, ParseException {
137 if (line.startsWith(label)) {
138 String tail = line.substring(label.length()).trim();
139 String[] tokens = tail.split("\\s+");
140 if (tokens.length > 1) {
141 int[] values = new int[2];
142 values[0] = Integer.parseInt(tokens[0]);
143 values[1] = Integer.parseInt(tokens[1]);
147 throw new ParseException("mismatch", 0);
150 public int log_space() {
151 if (log_space != AltosLib.MISSING)
154 if (storage_size != AltosLib.MISSING) {
155 int space = storage_size;
157 if (storage_erase_unit != AltosLib.MISSING && use_flash_for_config())
158 space -= storage_erase_unit;
160 if (space != AltosLib.MISSING)
166 public int log_available() {
167 switch (log_format) {
168 case AltosLib.AO_LOG_FORMAT_TINY:
172 case AltosLib.AO_LOG_FORMAT_TELEMETRY:
173 case AltosLib.AO_LOG_FORMAT_TELESCIENCE:
176 if (flight_log_max <= 0)
178 int log_max = flight_log_max * 1024;
179 int log_space = log_space();
185 log_used = flights.length * log_max;
188 if (log_used >= log_space)
191 log_avail = (log_space - log_used) / log_max;
197 public int invert_accel_value(int value) {
198 if (value == AltosLib.MISSING)
199 return AltosLib.MISSING;
201 switch (log_format) {
202 case AltosLib.AO_LOG_FORMAT_FULL:
203 return 0x7fff - value;
204 case AltosLib.AO_LOG_FORMAT_TELEMEGA_OLD:
205 case AltosLib.AO_LOG_FORMAT_TELEMEGA:
206 case AltosLib.AO_LOG_FORMAT_TELEMEGA_3:
208 case AltosLib.AO_LOG_FORMAT_TELEMETRUM:
210 * TeleMetrum v2 and later use the same log format, but
211 * have different accelerometers. This is the only place
212 * it matters in altoslib.
214 if (product.startsWith("TeleMetrum-v2"))
217 case AltosLib.AO_LOG_FORMAT_TELEMEGA_4:
218 case AltosLib.AO_LOG_FORMAT_EASYMEGA_2:
219 case AltosLib.AO_LOG_FORMAT_EASYMOTOR:
222 if (product.startsWith("EasyTimer-"))
224 return AltosLib.MISSING;
228 public boolean has_monitor_battery() {
231 if (product.startsWith("TeleBT"))
236 int[] parse_version(String v) {
237 String[] parts = v.split("\\.");
238 int r[] = new int[parts.length];
240 for (int i = 0; i < parts.length; i++) {
242 r[i] = (int) AltosLib.fromdec(parts[i]);
243 } catch (NumberFormatException n) {
251 public boolean altitude_32() {
252 return altitude_32 == 1;
255 public int compare_version(String other) {
256 int[] me = parse_version(version);
257 int[] them = parse_version(other);
259 int l = Math.min(me.length, them.length);
261 for (int i = 0; i < l; i++) {
262 int d = me[i] - them[i];
273 public void reset() {
276 serial = AltosLib.MISSING;
277 flight = AltosLib.MISSING;
278 log_format = AltosLib.AO_LOG_FORMAT_UNKNOWN;
279 log_space = AltosLib.MISSING;
281 config_major = AltosLib.MISSING;
282 config_minor = AltosLib.MISSING;
284 main_deploy = AltosLib.MISSING;
285 apogee_delay = AltosLib.MISSING;
286 apogee_lockout = AltosLib.MISSING;
288 radio_frequency = AltosLib.MISSING;
290 radio_enable = AltosLib.MISSING;
291 radio_calibration = AltosLib.MISSING;
292 radio_channel = AltosLib.MISSING;
293 radio_setting = AltosLib.MISSING;
294 telemetry_rate = AltosLib.MISSING;
296 accel_cal_plus_cooked = AltosLib.MISSING;
297 accel_cal_minus_cooked = AltosLib.MISSING;
298 accel_cal_plus = AltosLib.MISSING;
299 accel_cal_minus = AltosLib.MISSING;
300 pad_orientation = AltosLib.MISSING;
301 accel_cal_adjusted = false;
303 flight_log_max = AltosLib.MISSING;
304 log_fixed = AltosLib.MISSING;
305 ignite_mode = AltosLib.MISSING;
309 pyro = AltosLib.MISSING;
310 npyro = AltosLib.MISSING;
312 pyro_firing_time = AltosLib.MISSING;
314 aprs_interval = AltosLib.MISSING;
315 aprs_ssid = AltosLib.MISSING;
316 aprs_format = AltosLib.MISSING;
317 aprs_offset = AltosLib.MISSING;
319 beep = AltosLib.MISSING;
321 radio_10mw = AltosLib.MISSING;
323 tracker_motion = AltosLib.MISSING;
324 tracker_interval = AltosLib.MISSING;
326 storage_size = AltosLib.MISSING;
327 storage_erase_unit = AltosLib.MISSING;
331 accel_zero_along = AltosLib.MISSING;
332 accel_zero_across = AltosLib.MISSING;
333 accel_zero_through = AltosLib.MISSING;
336 /* Return + accel calibration relative to a specific pad orientation */
337 public int accel_cal_plus(int pad_orientation) {
339 if (!accel_cal_adjusted)
340 return AltosLib.MISSING;
342 switch (pad_orientation) {
343 case AltosLib.AO_PAD_ORIENTATION_ANTENNA_UP:
344 case AltosLib.AO_PAD_ORIENTATION_WORDS_UPRIGHT:
345 case AltosLib.AO_PAD_ORIENTATION_BIG_PARTS_UP:
346 return accel_cal_plus_cooked;
347 case AltosLib.AO_PAD_ORIENTATION_ANTENNA_DOWN:
348 case AltosLib.AO_PAD_ORIENTATION_WORDS_UPSIDEDOWN:
349 case AltosLib.AO_PAD_ORIENTATION_BIG_PARTS_DOWN:
350 return invert_accel_value(accel_cal_minus_cooked);
352 return AltosLib.MISSING;
356 /* Return - accel calibration relative to a specific pad orientation */
357 public int accel_cal_minus(int pad_orientation) {
359 if (!accel_cal_adjusted)
360 return AltosLib.MISSING;
362 switch (pad_orientation) {
363 case AltosLib.AO_PAD_ORIENTATION_ANTENNA_UP:
364 case AltosLib.AO_PAD_ORIENTATION_WORDS_UPRIGHT:
365 case AltosLib.AO_PAD_ORIENTATION_BIG_PARTS_UP:
366 return accel_cal_minus_cooked;
367 case AltosLib.AO_PAD_ORIENTATION_ANTENNA_DOWN:
368 case AltosLib.AO_PAD_ORIENTATION_WORDS_UPSIDEDOWN:
369 case AltosLib.AO_PAD_ORIENTATION_BIG_PARTS_DOWN:
370 return invert_accel_value(accel_cal_plus_cooked);
372 return AltosLib.MISSING;
376 /* Once we have all of the values from the config data, compute the
377 * accel cal values relative to Antenna Up orientation.
379 private void adjust_accel_cal() {
380 if (!accel_cal_adjusted &&
382 pad_orientation != AltosLib.MISSING &&
383 accel_cal_plus != AltosLib.MISSING &&
384 accel_cal_minus != AltosLib.MISSING)
386 switch (pad_orientation) {
387 case AltosLib.AO_PAD_ORIENTATION_ANTENNA_UP:
388 case AltosLib.AO_PAD_ORIENTATION_WORDS_UPRIGHT:
389 case AltosLib.AO_PAD_ORIENTATION_BIG_PARTS_UP:
390 accel_cal_plus_cooked = accel_cal_plus;
391 accel_cal_minus_cooked = accel_cal_minus;
392 accel_cal_adjusted = true;
394 case AltosLib.AO_PAD_ORIENTATION_ANTENNA_DOWN:
395 case AltosLib.AO_PAD_ORIENTATION_WORDS_UPSIDEDOWN:
396 case AltosLib.AO_PAD_ORIENTATION_BIG_PARTS_DOWN:
397 accel_cal_plus_cooked = invert_accel_value(accel_cal_minus);
398 accel_cal_minus_cooked = invert_accel_value(accel_cal_plus);
399 accel_cal_adjusted = true;
407 public void parse_line(String line) {
409 /* Version replies */
410 try { manufacturer = get_string(line, "manufacturer"); } catch (Exception e) {}
411 try { product = get_string(line, "product"); } catch (Exception e) {}
412 try { serial = get_int(line, "serial-number"); } catch (Exception e) {}
413 try { flight = get_int(line, "current-flight"); } catch (Exception e) {}
414 try { log_format = get_int(line, "log-format"); } catch (Exception e) {}
415 try { log_space = get_int(line, "log-space"); } catch (Exception e) {}
416 try { altitude_32 = get_int(line, "altitude-32"); } catch (Exception e) {}
417 try { version = get_string(line, "software-version"); } catch (Exception e) {}
419 /* Version also contains MS5607 info, which we ignore here */
421 try { ms5607().reserved = get_int(line, "ms5607 reserved:"); } catch (Exception e) {}
422 try { ms5607().sens = get_int(line, "ms5607 sens:"); } catch (Exception e) {}
423 try { ms5607().off = get_int(line, "ms5607 off:"); } catch (Exception e) {}
424 try { ms5607().tcs = get_int(line, "ms5607 tcs:"); } catch (Exception e) {}
425 try { ms5607().tco = get_int(line, "ms5607 tco:"); } catch (Exception e) {}
426 try { ms5607().tref = get_int(line, "ms5607 tref:"); } catch (Exception e) {}
427 try { ms5607().tempsens = get_int(line, "ms5607 tempsens:"); } catch (Exception e) {}
428 try { ms5607().crc = get_int(line, "ms5607 crc:"); } catch (Exception e) {}
430 /* Config show replies */
433 if (line.startsWith("Config version")) {
434 String[] bits = line.split("\\s+");
435 if (bits.length >= 3) {
436 String[] cfg = bits[2].split("\\.");
438 if (cfg.length >= 2) {
439 config_major = Integer.parseInt(cfg[0]);
440 config_minor = Integer.parseInt(cfg[1]);
444 } catch (Exception e) {}
447 try { main_deploy = get_int(line, "Main deploy:"); } catch (Exception e) {}
448 try { apogee_delay = get_int(line, "Apogee delay:"); } catch (Exception e) {}
449 try { apogee_lockout = get_int(line, "Apogee lockout:"); } catch (Exception e) {}
453 radio_frequency = get_int(line, "Frequency:");
454 if (radio_frequency < 0)
455 radio_frequency = 434550;
456 } catch (Exception e) {}
457 try { callsign = get_string(line, "Callsign:"); } catch (Exception e) {}
458 try { radio_enable = get_int(line, "Radio enable:"); } catch (Exception e) {}
459 try { radio_calibration = get_int(line, "Radio cal:"); } catch (Exception e) {}
460 try { telemetry_rate = get_int(line, "Telemetry rate:"); } catch (Exception e) {}
462 /* Old HAS_RADIO values */
463 try { radio_channel = get_int(line, "Radio channel:"); } catch (Exception e) {}
464 try { radio_setting = get_int(line, "Radio setting:"); } catch (Exception e) {}
468 if (line.startsWith("Accel cal")) {
469 String[] bits = line.split("\\s+");
470 if (bits.length >= 6) {
471 accel_cal_plus = Integer.parseInt(bits[3]);
472 accel_cal_minus = Integer.parseInt(bits[5]);
473 accel_cal_adjusted = false;
476 } catch (Exception e) {}
477 try { pad_orientation = get_int(line, "Pad orientation:"); } catch (Exception e) {}
480 try { flight_log_max = get_int(line, "Max flight log:"); } catch (Exception e) {}
481 try { log_fixed = get_int(line, "Log fixed:"); } catch (Exception e) {}
484 try { ignite_mode = get_int(line, "Ignite mode:"); } catch (Exception e) {}
487 try { aes_key = get_string(line, "AES key:"); } catch (Exception e) {}
491 npyro = get_int(line, "Pyro-count:");
492 pyros = new AltosPyro[npyro];
494 } catch (Exception e) {}
495 if (npyro != AltosLib.MISSING) {
497 AltosPyro p = new AltosPyro(pyro, line);
500 } catch (Exception e) {}
502 try { pyro_firing_time = get_int(line, "Pyro time:") / 100.0; } catch (Exception e) {}
505 try { aprs_interval = get_int(line, "APRS interval:"); } catch (Exception e) {}
506 try { aprs_ssid = get_int(line, "APRS SSID:"); } catch (Exception e) {}
507 try { aprs_format = get_int(line, "APRS format:"); } catch (Exception e) {}
508 try { aprs_offset = get_int(line, "APRS offset:"); } catch (Exception e) {}
511 try { beep = get_int(line, "Beeper setting:"); } catch (Exception e) {}
514 try { radio_10mw = get_int(line, "Radio 10mw limit:"); } catch (Exception e) {}
518 int[] values = get_values(line, "Tracker setting:");
519 tracker_motion = values[0];
520 tracker_interval = values[1];
521 } catch (Exception e) {}
523 /* Storage info replies */
524 try { storage_size = get_int(line, "Storage size:"); } catch (Exception e) {}
525 try { storage_erase_unit = get_int(line, "Storage erase unit:"); } catch (Exception e) {}
527 /* Log listing replies */
529 int flight = get_int(line, "flight");
530 String[] tokens = line.split("\\s+");
531 if (tokens.length >= 6) {
532 int start = -1, end = -1;
534 if (tokens[2].equals("start"))
535 start = AltosParse.parse_hex(tokens[3]);
536 if (tokens[4].equals("end"))
537 end = AltosParse.parse_hex(tokens[5]);
538 if (flight != 0 && start >= 0 && end > 0) {
543 len = flights.length;
544 AltosEepromFlight [] new_flights = new AltosEepromFlight[len + 1];
545 for (int i = 0; i < len; i++)
546 new_flights[i] = flights[i];
547 new_flights[len] = new AltosEepromFlight(flight, start, end);
548 flights = new_flights;
549 stored_flight = flights.length;
551 } catch (ParseException pe) { System.out.printf("Parse error %s\n", pe.toString()); }
553 } catch (Exception e) {}
557 if (line.startsWith("IMU cal along")) {
558 String[] bits = line.split("\\s+");
559 if (bits.length >= 8) {
560 accel_zero_along = Integer.parseInt(bits[3]);
561 accel_zero_across = Integer.parseInt(bits[5]);
562 accel_zero_through = Integer.parseInt(bits[7]);
565 } catch (Exception e) {}
568 public AltosConfigData() {
572 private void read_link(AltosLink link, String finished) throws InterruptedException, TimeoutException {
574 String line = link.get_reply();
576 throw new TimeoutException();
577 if (line.contains("Syntax error"))
579 this.parse_line(line);
581 /* signals the end of the version info */
582 if (line.startsWith(finished))
587 public boolean has_frequency() {
588 return radio_frequency != AltosLib.MISSING || radio_setting != AltosLib.MISSING || radio_channel != AltosLib.MISSING;
591 public boolean has_telemetry_rate() {
592 return telemetry_rate != AltosLib.MISSING;
595 public void set_frequency(double freq) {
596 int frequency = radio_frequency;
597 int setting = radio_setting;
599 if (frequency != AltosLib.MISSING) {
600 radio_frequency = (int) Math.floor (freq * 1000 + 0.5);
601 radio_channel = AltosLib.MISSING;
602 } else if (setting != AltosLib.MISSING) {
603 radio_setting =AltosConvert.radio_frequency_to_setting(freq, radio_calibration);
604 radio_channel = AltosLib.MISSING;
606 radio_channel = AltosConvert.radio_frequency_to_channel(freq);
610 public double frequency() {
611 int channel = radio_channel;
612 int setting = radio_setting;
614 if (radio_frequency == AltosLib.MISSING && channel == AltosLib.MISSING && setting == AltosLib.MISSING)
615 return AltosLib.MISSING;
617 if (channel == AltosLib.MISSING)
619 if (setting == AltosLib.MISSING)
622 return AltosConvert.radio_to_frequency(radio_frequency,
628 boolean use_flash_for_config() {
629 if (product.startsWith("TeleMega"))
631 if (product.startsWith("TeleMetrum-v2"))
633 if (product.startsWith("TeleMetrum-v3"))
635 if (product.startsWith("EasyMega"))
641 public boolean mma655x_inverted() throws AltosUnknownProduct {
642 if (product != null) {
643 if (product.startsWith("EasyMega-v1"))
645 if (product.startsWith("TeleMetrum-v2"))
647 if (product.startsWith("TeleMega-v2"))
649 if (product.startsWith("TeleMega-v1"))
652 throw new AltosUnknownProduct(product);
655 public boolean adxl375_inverted() throws AltosUnknownProduct {
656 if (product != null) {
657 if (product.startsWith("EasyMega-v2"))
659 if (product.startsWith("TeleMetrum-v3"))
661 if (product.startsWith("TeleMega-v4"))
663 if (product.startsWith("EasyMotor-v2"))
665 if (product.startsWith("EasyMotor-v3"))
668 throw new AltosUnknownProduct(product);
671 public int adxl375_axis() throws AltosUnknownProduct {
672 if (product != null) {
673 if (product.startsWith("EasyMega-v2"))
674 return AltosAdxl375.X_AXIS;
675 if (product.startsWith("TeleMetrum-v3"))
676 return AltosAdxl375.X_AXIS;
677 if (product.startsWith("TeleMega-v4"))
678 return AltosAdxl375.X_AXIS;
679 if (product.startsWith("EasyMotor-v2"))
680 return AltosAdxl375.X_AXIS;
681 if (product.startsWith("EasyMotor-v3"))
682 return AltosAdxl375.X_AXIS;
685 throw new AltosUnknownProduct(product);
688 public void get_values(AltosConfigValues source) throws AltosConfigDataException {
691 if (main_deploy != AltosLib.MISSING)
692 main_deploy = source.main_deploy();
693 if (apogee_delay != AltosLib.MISSING)
694 apogee_delay = source.apogee_delay();
695 if (apogee_lockout != AltosLib.MISSING)
696 apogee_lockout = source.apogee_lockout();
700 set_frequency(source.radio_frequency());
701 if (radio_enable != AltosLib.MISSING)
702 radio_enable = source.radio_enable();
703 if (callsign != null)
704 callsign = source.callsign();
705 if (telemetry_rate != AltosLib.MISSING)
706 telemetry_rate = source.telemetry_rate();
709 if (pad_orientation != AltosLib.MISSING)
710 pad_orientation = source.pad_orientation();
712 if (accel_cal_plus_cooked != AltosLib.MISSING)
713 accel_cal_plus_cooked = source.accel_cal_plus();
715 if (accel_cal_minus_cooked != AltosLib.MISSING)
716 accel_cal_minus_cooked = source.accel_cal_minus();
719 if (flight_log_max != AltosLib.MISSING)
720 flight_log_max = source.flight_log_max();
723 if (ignite_mode != AltosLib.MISSING)
724 ignite_mode = source.ignite_mode();
727 if (npyro != AltosLib.MISSING)
728 pyros = source.pyros();
729 if (pyro_firing_time != AltosLib.MISSING)
730 pyro_firing_time = source.pyro_firing_time();
733 if (aprs_interval != AltosLib.MISSING)
734 aprs_interval = source.aprs_interval();
735 if (aprs_ssid != AltosLib.MISSING)
736 aprs_ssid = source.aprs_ssid();
737 if (aprs_format != AltosLib.MISSING)
738 aprs_format = source.aprs_format();
739 if (aprs_offset != AltosLib.MISSING)
740 aprs_offset = source.aprs_offset();
743 if (beep != AltosLib.MISSING)
744 beep = source.beep();
747 if (radio_10mw != AltosLib.MISSING)
748 radio_10mw = source.radio_10mw();
751 if (tracker_motion != AltosLib.MISSING)
752 tracker_motion = source.tracker_motion();
753 if (tracker_interval != AltosLib.MISSING)
754 tracker_interval = source.tracker_interval();
757 public void set_values(AltosConfigValues dest) {
758 dest.set_serial(serial);
759 dest.set_product(product);
760 dest.set_version(version);
761 dest.set_altitude_32(altitude_32);
762 dest.set_main_deploy(main_deploy);
763 dest.set_apogee_delay(apogee_delay);
764 dest.set_apogee_lockout(apogee_lockout);
765 dest.set_radio_calibration(radio_calibration);
766 dest.set_radio_frequency(frequency());
767 dest.set_telemetry_rate(telemetry_rate);
768 boolean max_enabled = true;
770 if (log_space() == 0)
773 if (log_fixed != AltosLib.MISSING)
776 switch (log_format) {
777 case AltosLib.AO_LOG_FORMAT_TINY:
786 dest.set_flight_log_max_enabled(max_enabled);
787 dest.set_radio_enable(radio_enable);
788 dest.set_flight_log_max_limit(log_space() >> 10, storage_erase_unit >> 10);
789 dest.set_flight_log_max(flight_log_max);
790 dest.set_ignite_mode(ignite_mode);
791 dest.set_pad_orientation(pad_orientation);
792 dest.set_accel_cal(accel_cal_plus(AltosLib.AO_PAD_ORIENTATION_ANTENNA_UP),
793 accel_cal_minus(AltosLib.AO_PAD_ORIENTATION_ANTENNA_UP));
794 dest.set_callsign(callsign);
795 if (npyro != AltosLib.MISSING)
796 dest.set_pyros(pyros);
798 dest.set_pyros(null);
799 dest.set_pyro_firing_time(pyro_firing_time);
800 dest.set_aprs_interval(aprs_interval);
801 dest.set_aprs_ssid(aprs_ssid);
802 dest.set_aprs_format(aprs_format);
803 dest.set_aprs_offset(aprs_offset);
805 dest.set_radio_10mw(radio_10mw);
806 dest.set_tracker_motion(tracker_motion);
807 dest.set_tracker_interval(tracker_interval);
810 public boolean log_has_state() {
811 switch (log_format) {
812 case AltosLib.AO_LOG_FORMAT_TELEGPS:
818 public void save(AltosLink link, boolean remote) throws InterruptedException, TimeoutException {
821 if (main_deploy != AltosLib.MISSING)
822 link.printf("c m %d\n", main_deploy);
823 if (apogee_delay != AltosLib.MISSING)
824 link.printf("c d %d\n", apogee_delay);
825 if (apogee_lockout != AltosLib.MISSING)
826 link.printf("c L %d\n", apogee_lockout);
829 if (has_frequency()) {
830 boolean has_frequency = radio_frequency != AltosLib.MISSING;
831 boolean has_setting = radio_setting != AltosLib.MISSING;
832 double frequency = frequency();
833 link.set_radio_frequency(frequency,
837 /* When remote, reset the dongle frequency at the same time */
838 if (remote && frequency != link.frequency) {
840 link.set_radio_frequency(frequency);
845 if (telemetry_rate != AltosLib.MISSING) {
846 link.printf("c T %d\n", telemetry_rate);
847 if (remote && telemetry_rate != link.telemetry_rate) {
849 link.set_telemetry_rate(telemetry_rate);
854 if (callsign != null) {
855 link.printf("c c %s\n", callsign);
856 if (remote && !callsign.equals(link.callsign)) {
857 System.out.printf("changing link callsign from %s to %s\n", link.callsign, callsign);
859 link.set_callsign(callsign);
864 if (radio_enable != AltosLib.MISSING)
865 link.printf("c e %d\n", radio_enable);
868 /* set orientation first so that we know how to set the accel cal */
869 if (pad_orientation != AltosLib.MISSING)
870 link.printf("c o %d\n", pad_orientation);
871 int plus = accel_cal_plus(pad_orientation);
872 int minus = accel_cal_minus(pad_orientation);
873 if (plus != AltosLib.MISSING && minus != AltosLib.MISSING) {
877 minus = 65536 + minus;
878 if (accel_zero_along != AltosLib.MISSING &&
879 accel_zero_across != AltosLib.MISSING &&
880 accel_zero_through != AltosLib.MISSING)
881 link.printf("c a %d %d %d %d %d\n",
887 link.printf("c a %d %d\n", plus, minus);
891 if (flight_log_max != 0 && flight_log_max != AltosLib.MISSING)
892 link.printf("c l %d\n", flight_log_max);
895 if (ignite_mode != AltosLib.MISSING)
896 link.printf("c i %d\n", ignite_mode);
899 /* UI doesn't support AES key config */
902 if (npyro != AltosLib.MISSING) {
903 for (int p = 0; p < pyros.length; p++) {
904 link.printf("c P %s\n",
905 pyros[p].toString());
908 if (pyro_firing_time != AltosLib.MISSING)
909 link.printf("c I %d\n", (int) (pyro_firing_time * 100.0 + 0.5));
912 if (aprs_interval != AltosLib.MISSING)
913 link.printf("c A %d\n", aprs_interval);
914 if (aprs_ssid != AltosLib.MISSING)
915 link.printf("c S %d\n", aprs_ssid);
916 if (aprs_format != AltosLib.MISSING)
917 link.printf("c C %d\n", aprs_format);
918 if (aprs_offset != AltosLib.MISSING)
919 link.printf("c O %d\n", aprs_offset);
922 if (beep != AltosLib.MISSING)
923 link.printf("c b %d\n", beep);
926 if (radio_10mw != AltosLib.MISSING)
927 link.printf("c p %d\n", radio_10mw);
930 if (tracker_motion != AltosLib.MISSING && tracker_interval != AltosLib.MISSING)
931 link.printf("c t %d %d\n", tracker_motion, tracker_interval);
934 /* UI doesn't support accel cal */
936 link.printf("c w\n");
937 read_link(link, "Saved");
940 public AltosConfigData(AltosLink link) throws InterruptedException, TimeoutException {
942 link.printf("c s\nf\nv\n");
943 read_link(link, "software-version");
944 switch (log_format) {
945 case AltosLib.AO_LOG_FORMAT_UNKNOWN:
946 case AltosLib.AO_LOG_FORMAT_NONE:
950 read_link(link, "done");