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;
86 /* Storage info replies */
87 public int storage_size;
88 public int storage_erase_unit;
90 /* Log listing replies */
91 public int stored_flight;
92 public AltosEepromFlight[] flights;
95 public int tracker_motion;
96 public int tracker_interval;
99 public int accel_zero_along, accel_zero_across, accel_zero_through;
104 public AltosMs5607 ms5607() {
106 ms5607 = new AltosMs5607();
110 public static String get_string(String line, String label) throws ParseException {
111 if (line.startsWith(label)) {
112 String quoted = line.substring(label.length()).trim();
114 if (quoted.startsWith("\""))
115 quoted = quoted.substring(1);
116 if (quoted.endsWith("\""))
117 quoted = quoted.substring(0,quoted.length()-1);
120 throw new ParseException("mismatch", 0);
123 public static int get_int(String line, String label) throws NumberFormatException, ParseException {
124 if (line.startsWith(label)) {
125 String tail = line.substring(label.length()).trim();
126 String[] tokens = tail.split("\\s+");
127 if (tokens.length > 0)
128 return Integer.parseInt(tokens[0]);
130 throw new ParseException("mismatch", 0);
133 public static int[] get_values(String line, String label) throws NumberFormatException, ParseException {
134 if (line.startsWith(label)) {
135 String tail = line.substring(label.length()).trim();
136 String[] tokens = tail.split("\\s+");
137 if (tokens.length > 1) {
138 int[] values = new int[2];
139 values[0] = Integer.parseInt(tokens[0]);
140 values[1] = Integer.parseInt(tokens[1]);
144 throw new ParseException("mismatch", 0);
147 public int log_space() {
148 if (log_space != AltosLib.MISSING)
151 if (storage_size != AltosLib.MISSING) {
152 int space = storage_size;
154 if (storage_erase_unit != AltosLib.MISSING && use_flash_for_config())
155 space -= storage_erase_unit;
157 if (space != AltosLib.MISSING)
163 public int log_available() {
164 switch (log_format) {
165 case AltosLib.AO_LOG_FORMAT_TINY:
169 case AltosLib.AO_LOG_FORMAT_TELEMETRY:
170 case AltosLib.AO_LOG_FORMAT_TELESCIENCE:
173 if (flight_log_max <= 0)
175 int log_max = flight_log_max * 1024;
176 int log_space = log_space();
182 log_used = flights.length * log_max;
185 if (log_used >= log_space)
188 log_avail = (log_space - log_used) / log_max;
194 public int invert_accel_value(int value) {
195 if (value == AltosLib.MISSING)
196 return AltosLib.MISSING;
198 switch (log_format) {
199 case AltosLib.AO_LOG_FORMAT_FULL:
200 return 0x7fff - value;
201 case AltosLib.AO_LOG_FORMAT_TELEMEGA_OLD:
202 case AltosLib.AO_LOG_FORMAT_TELEMEGA:
203 case AltosLib.AO_LOG_FORMAT_TELEMEGA_3:
205 case AltosLib.AO_LOG_FORMAT_TELEMETRUM:
207 * TeleMetrum v2 and later use the same log format, but
208 * have different accelerometers. This is the only place
209 * it matters in altoslib.
211 if (product.startsWith("TeleMetrum-v2"))
214 case AltosLib.AO_LOG_FORMAT_TELEMEGA_4:
215 case AltosLib.AO_LOG_FORMAT_EASYMEGA_2:
216 case AltosLib.AO_LOG_FORMAT_EASYMOTOR:
219 if (product.startsWith("EasyTimer-"))
221 return AltosLib.MISSING;
225 public boolean has_monitor_battery() {
226 if (product.startsWith("TeleBT"))
231 int[] parse_version(String v) {
232 String[] parts = v.split("\\.");
233 int r[] = new int[parts.length];
235 for (int i = 0; i < parts.length; i++) {
237 r[i] = (int) AltosLib.fromdec(parts[i]);
238 } catch (NumberFormatException n) {
246 public boolean altitude_32() {
247 return altitude_32 == 1;
250 public int compare_version(String other) {
251 int[] me = parse_version(version);
252 int[] them = parse_version(other);
254 int l = Math.min(me.length, them.length);
256 for (int i = 0; i < l; i++) {
257 int d = me[i] - them[i];
268 public void reset() {
271 serial = AltosLib.MISSING;
272 flight = AltosLib.MISSING;
273 log_format = AltosLib.AO_LOG_FORMAT_UNKNOWN;
274 log_space = AltosLib.MISSING;
276 config_major = AltosLib.MISSING;
277 config_minor = AltosLib.MISSING;
279 main_deploy = AltosLib.MISSING;
280 apogee_delay = AltosLib.MISSING;
281 apogee_lockout = AltosLib.MISSING;
283 radio_frequency = AltosLib.MISSING;
285 radio_enable = AltosLib.MISSING;
286 radio_calibration = AltosLib.MISSING;
287 radio_channel = AltosLib.MISSING;
288 radio_setting = AltosLib.MISSING;
289 telemetry_rate = AltosLib.MISSING;
291 accel_cal_plus_cooked = AltosLib.MISSING;
292 accel_cal_minus_cooked = AltosLib.MISSING;
293 accel_cal_plus = AltosLib.MISSING;
294 accel_cal_minus = AltosLib.MISSING;
295 pad_orientation = AltosLib.MISSING;
296 accel_cal_adjusted = false;
298 flight_log_max = AltosLib.MISSING;
299 log_fixed = AltosLib.MISSING;
300 ignite_mode = AltosLib.MISSING;
304 pyro = AltosLib.MISSING;
305 npyro = AltosLib.MISSING;
307 pyro_firing_time = AltosLib.MISSING;
309 aprs_interval = AltosLib.MISSING;
310 aprs_ssid = AltosLib.MISSING;
311 aprs_format = AltosLib.MISSING;
312 aprs_offset = AltosLib.MISSING;
314 beep = AltosLib.MISSING;
316 tracker_motion = AltosLib.MISSING;
317 tracker_interval = AltosLib.MISSING;
319 storage_size = AltosLib.MISSING;
320 storage_erase_unit = AltosLib.MISSING;
324 accel_zero_along = AltosLib.MISSING;
325 accel_zero_across = AltosLib.MISSING;
326 accel_zero_through = AltosLib.MISSING;
329 /* Return + accel calibration relative to a specific pad orientation */
330 public int accel_cal_plus(int pad_orientation) {
332 if (!accel_cal_adjusted)
333 return AltosLib.MISSING;
335 switch (pad_orientation) {
336 case AltosLib.AO_PAD_ORIENTATION_ANTENNA_UP:
337 case AltosLib.AO_PAD_ORIENTATION_WORDS_UPRIGHT:
338 case AltosLib.AO_PAD_ORIENTATION_BIG_PARTS_UP:
339 return accel_cal_plus_cooked;
340 case AltosLib.AO_PAD_ORIENTATION_ANTENNA_DOWN:
341 case AltosLib.AO_PAD_ORIENTATION_WORDS_UPSIDEDOWN:
342 case AltosLib.AO_PAD_ORIENTATION_BIG_PARTS_DOWN:
343 return invert_accel_value(accel_cal_minus_cooked);
345 return AltosLib.MISSING;
349 /* Return - accel calibration relative to a specific pad orientation */
350 public int accel_cal_minus(int pad_orientation) {
352 if (!accel_cal_adjusted)
353 return AltosLib.MISSING;
355 switch (pad_orientation) {
356 case AltosLib.AO_PAD_ORIENTATION_ANTENNA_UP:
357 case AltosLib.AO_PAD_ORIENTATION_WORDS_UPRIGHT:
358 case AltosLib.AO_PAD_ORIENTATION_BIG_PARTS_UP:
359 return accel_cal_minus_cooked;
360 case AltosLib.AO_PAD_ORIENTATION_ANTENNA_DOWN:
361 case AltosLib.AO_PAD_ORIENTATION_WORDS_UPSIDEDOWN:
362 case AltosLib.AO_PAD_ORIENTATION_BIG_PARTS_DOWN:
363 return invert_accel_value(accel_cal_plus_cooked);
365 return AltosLib.MISSING;
369 /* Once we have all of the values from the config data, compute the
370 * accel cal values relative to Antenna Up orientation.
372 private void adjust_accel_cal() {
373 if (!accel_cal_adjusted &&
375 pad_orientation != AltosLib.MISSING &&
376 accel_cal_plus != AltosLib.MISSING &&
377 accel_cal_minus != AltosLib.MISSING)
379 switch (pad_orientation) {
380 case AltosLib.AO_PAD_ORIENTATION_ANTENNA_UP:
381 case AltosLib.AO_PAD_ORIENTATION_WORDS_UPRIGHT:
382 case AltosLib.AO_PAD_ORIENTATION_BIG_PARTS_UP:
383 accel_cal_plus_cooked = accel_cal_plus;
384 accel_cal_minus_cooked = accel_cal_minus;
385 accel_cal_adjusted = true;
387 case AltosLib.AO_PAD_ORIENTATION_ANTENNA_DOWN:
388 case AltosLib.AO_PAD_ORIENTATION_WORDS_UPSIDEDOWN:
389 case AltosLib.AO_PAD_ORIENTATION_BIG_PARTS_DOWN:
390 accel_cal_plus_cooked = invert_accel_value(accel_cal_minus);
391 accel_cal_minus_cooked = invert_accel_value(accel_cal_plus);
392 accel_cal_adjusted = true;
400 public void parse_line(String line) {
402 /* Version replies */
403 try { manufacturer = get_string(line, "manufacturer"); } catch (Exception e) {}
404 try { product = get_string(line, "product"); } catch (Exception e) {}
405 try { serial = get_int(line, "serial-number"); } catch (Exception e) {}
406 try { flight = get_int(line, "current-flight"); } catch (Exception e) {}
407 try { log_format = get_int(line, "log-format"); } catch (Exception e) {}
408 try { log_space = get_int(line, "log-space"); } catch (Exception e) {}
409 try { altitude_32 = get_int(line, "altitude-32"); } catch (Exception e) {}
410 try { version = get_string(line, "software-version"); } catch (Exception e) {}
412 /* Version also contains MS5607 info, which we ignore here */
414 try { ms5607().reserved = get_int(line, "ms5607 reserved:"); } catch (Exception e) {}
415 try { ms5607().sens = get_int(line, "ms5607 sens:"); } catch (Exception e) {}
416 try { ms5607().off = get_int(line, "ms5607 off:"); } catch (Exception e) {}
417 try { ms5607().tcs = get_int(line, "ms5607 tcs:"); } catch (Exception e) {}
418 try { ms5607().tco = get_int(line, "ms5607 tco:"); } catch (Exception e) {}
419 try { ms5607().tref = get_int(line, "ms5607 tref:"); } catch (Exception e) {}
420 try { ms5607().tempsens = get_int(line, "ms5607 tempsens:"); } catch (Exception e) {}
421 try { ms5607().crc = get_int(line, "ms5607 crc:"); } catch (Exception e) {}
423 /* Config show replies */
426 if (line.startsWith("Config version")) {
427 String[] bits = line.split("\\s+");
428 if (bits.length >= 3) {
429 String[] cfg = bits[2].split("\\.");
431 if (cfg.length >= 2) {
432 config_major = Integer.parseInt(cfg[0]);
433 config_minor = Integer.parseInt(cfg[1]);
437 } catch (Exception e) {}
440 try { main_deploy = get_int(line, "Main deploy:"); } catch (Exception e) {}
441 try { apogee_delay = get_int(line, "Apogee delay:"); } catch (Exception e) {}
442 try { apogee_lockout = get_int(line, "Apogee lockout:"); } catch (Exception e) {}
446 radio_frequency = get_int(line, "Frequency:");
447 if (radio_frequency < 0)
448 radio_frequency = 434550;
449 } catch (Exception e) {}
450 try { callsign = get_string(line, "Callsign:"); } catch (Exception e) {}
451 try { radio_enable = get_int(line, "Radio enable:"); } catch (Exception e) {}
452 try { radio_calibration = get_int(line, "Radio cal:"); } catch (Exception e) {}
453 try { telemetry_rate = get_int(line, "Telemetry rate:"); } catch (Exception e) {}
455 /* Old HAS_RADIO values */
456 try { radio_channel = get_int(line, "Radio channel:"); } catch (Exception e) {}
457 try { radio_setting = get_int(line, "Radio setting:"); } catch (Exception e) {}
461 if (line.startsWith("Accel cal")) {
462 String[] bits = line.split("\\s+");
463 if (bits.length >= 6) {
464 accel_cal_plus = Integer.parseInt(bits[3]);
465 accel_cal_minus = Integer.parseInt(bits[5]);
466 accel_cal_adjusted = false;
469 } catch (Exception e) {}
470 try { pad_orientation = get_int(line, "Pad orientation:"); } catch (Exception e) {}
473 try { flight_log_max = get_int(line, "Max flight log:"); } catch (Exception e) {}
474 try { log_fixed = get_int(line, "Log fixed:"); } catch (Exception e) {}
477 try { ignite_mode = get_int(line, "Ignite mode:"); } catch (Exception e) {}
480 try { aes_key = get_string(line, "AES key:"); } catch (Exception e) {}
484 npyro = get_int(line, "Pyro-count:");
485 pyros = new AltosPyro[npyro];
487 } catch (Exception e) {}
488 if (npyro != AltosLib.MISSING) {
490 AltosPyro p = new AltosPyro(pyro, line);
493 } catch (Exception e) {}
495 try { pyro_firing_time = get_int(line, "Pyro time:") / 100.0; } catch (Exception e) {}
498 try { aprs_interval = get_int(line, "APRS interval:"); } catch (Exception e) {}
499 try { aprs_ssid = get_int(line, "APRS SSID:"); } catch (Exception e) {}
500 try { aprs_format = get_int(line, "APRS format:"); } catch (Exception e) {}
501 try { aprs_offset = get_int(line, "APRS offset:"); } catch (Exception e) {}
504 try { beep = get_int(line, "Beeper setting:"); } catch (Exception e) {}
508 int[] values = get_values(line, "Tracker setting:");
509 tracker_motion = values[0];
510 tracker_interval = values[1];
511 } catch (Exception e) {}
513 /* Storage info replies */
514 try { storage_size = get_int(line, "Storage size:"); } catch (Exception e) {}
515 try { storage_erase_unit = get_int(line, "Storage erase unit:"); } catch (Exception e) {}
517 /* Log listing replies */
519 int flight = get_int(line, "flight");
520 String[] tokens = line.split("\\s+");
521 if (tokens.length >= 6) {
522 int start = -1, end = -1;
524 if (tokens[2].equals("start"))
525 start = AltosParse.parse_hex(tokens[3]);
526 if (tokens[4].equals("end"))
527 end = AltosParse.parse_hex(tokens[5]);
528 if (flight != 0 && start >= 0 && end > 0) {
533 len = flights.length;
534 AltosEepromFlight [] new_flights = new AltosEepromFlight[len + 1];
535 for (int i = 0; i < len; i++)
536 new_flights[i] = flights[i];
537 new_flights[len] = new AltosEepromFlight(flight, start, end);
538 flights = new_flights;
539 stored_flight = flights.length;
541 } catch (ParseException pe) { System.out.printf("Parse error %s\n", pe.toString()); }
543 } catch (Exception e) {}
547 if (line.startsWith("IMU cal along")) {
548 String[] bits = line.split("\\s+");
549 if (bits.length >= 8) {
550 accel_zero_along = Integer.parseInt(bits[3]);
551 accel_zero_across = Integer.parseInt(bits[5]);
552 accel_zero_through = Integer.parseInt(bits[7]);
555 } catch (Exception e) {}
558 public AltosConfigData() {
562 private void read_link(AltosLink link, String finished) throws InterruptedException, TimeoutException {
564 String line = link.get_reply();
566 throw new TimeoutException();
567 if (line.contains("Syntax error"))
569 this.parse_line(line);
571 /* signals the end of the version info */
572 if (line.startsWith(finished))
577 public boolean has_frequency() {
578 return radio_frequency != AltosLib.MISSING || radio_setting != AltosLib.MISSING || radio_channel != AltosLib.MISSING;
581 public boolean has_telemetry_rate() {
582 return telemetry_rate != AltosLib.MISSING;
585 public void set_frequency(double freq) {
586 int frequency = radio_frequency;
587 int setting = radio_setting;
589 if (frequency != AltosLib.MISSING) {
590 radio_frequency = (int) Math.floor (freq * 1000 + 0.5);
591 radio_channel = AltosLib.MISSING;
592 } else if (setting != AltosLib.MISSING) {
593 radio_setting =AltosConvert.radio_frequency_to_setting(freq, radio_calibration);
594 radio_channel = AltosLib.MISSING;
596 radio_channel = AltosConvert.radio_frequency_to_channel(freq);
600 public double frequency() {
601 int channel = radio_channel;
602 int setting = radio_setting;
604 if (radio_frequency == AltosLib.MISSING && channel == AltosLib.MISSING && setting == AltosLib.MISSING)
605 return AltosLib.MISSING;
607 if (channel == AltosLib.MISSING)
609 if (setting == AltosLib.MISSING)
612 return AltosConvert.radio_to_frequency(radio_frequency,
618 boolean use_flash_for_config() {
619 if (product.startsWith("TeleMega"))
621 if (product.startsWith("TeleMetrum-v2"))
623 if (product.startsWith("TeleMetrum-v3"))
625 if (product.startsWith("EasyMega"))
631 public boolean mma655x_inverted() throws AltosUnknownProduct {
632 if (product != null) {
633 if (product.startsWith("EasyMega-v1"))
635 if (product.startsWith("TeleMetrum-v2"))
637 if (product.startsWith("TeleMega-v2"))
639 if (product.startsWith("TeleMega-v1"))
642 throw new AltosUnknownProduct(product);
645 public boolean adxl375_inverted() throws AltosUnknownProduct {
646 if (product != null) {
647 if (product.startsWith("EasyMega-v2"))
649 if (product.startsWith("TeleMetrum-v3"))
651 if (product.startsWith("TeleMega-v4"))
653 if (product.startsWith("EasyMotor-v2"))
656 throw new AltosUnknownProduct(product);
659 public int adxl375_axis() throws AltosUnknownProduct {
660 if (product != null) {
661 if (product.startsWith("EasyMega-v2"))
662 return AltosAdxl375.X_AXIS;
663 if (product.startsWith("TeleMetrum-v3"))
664 return AltosAdxl375.X_AXIS;
665 if (product.startsWith("TeleMega-v4"))
666 return AltosAdxl375.X_AXIS;
667 if (product.startsWith("EasyMotor-v2"))
668 return AltosAdxl375.X_AXIS;
671 throw new AltosUnknownProduct(product);
674 public void get_values(AltosConfigValues source) throws AltosConfigDataException {
677 if (main_deploy != AltosLib.MISSING)
678 main_deploy = source.main_deploy();
679 if (apogee_delay != AltosLib.MISSING)
680 apogee_delay = source.apogee_delay();
681 if (apogee_lockout != AltosLib.MISSING)
682 apogee_lockout = source.apogee_lockout();
686 set_frequency(source.radio_frequency());
687 if (radio_enable != AltosLib.MISSING)
688 radio_enable = source.radio_enable();
689 if (callsign != null)
690 callsign = source.callsign();
691 if (telemetry_rate != AltosLib.MISSING)
692 telemetry_rate = source.telemetry_rate();
695 if (pad_orientation != AltosLib.MISSING)
696 pad_orientation = source.pad_orientation();
698 if (accel_cal_plus_cooked != AltosLib.MISSING)
699 accel_cal_plus_cooked = source.accel_cal_plus();
701 if (accel_cal_minus_cooked != AltosLib.MISSING)
702 accel_cal_minus_cooked = source.accel_cal_minus();
705 if (flight_log_max != AltosLib.MISSING)
706 flight_log_max = source.flight_log_max();
709 if (ignite_mode != AltosLib.MISSING)
710 ignite_mode = source.ignite_mode();
713 if (npyro != AltosLib.MISSING)
714 pyros = source.pyros();
715 if (pyro_firing_time != AltosLib.MISSING)
716 pyro_firing_time = source.pyro_firing_time();
719 if (aprs_interval != AltosLib.MISSING)
720 aprs_interval = source.aprs_interval();
721 if (aprs_ssid != AltosLib.MISSING)
722 aprs_ssid = source.aprs_ssid();
723 if (aprs_format != AltosLib.MISSING)
724 aprs_format = source.aprs_format();
725 if (aprs_offset != AltosLib.MISSING)
726 aprs_offset = source.aprs_offset();
729 if (beep != AltosLib.MISSING)
730 beep = source.beep();
732 if (tracker_motion != AltosLib.MISSING)
733 tracker_motion = source.tracker_motion();
734 if (tracker_interval != AltosLib.MISSING)
735 tracker_interval = source.tracker_interval();
738 public void set_values(AltosConfigValues dest) {
739 dest.set_serial(serial);
740 dest.set_product(product);
741 dest.set_version(version);
742 dest.set_altitude_32(altitude_32);
743 dest.set_main_deploy(main_deploy);
744 dest.set_apogee_delay(apogee_delay);
745 dest.set_apogee_lockout(apogee_lockout);
746 dest.set_radio_calibration(radio_calibration);
747 dest.set_radio_frequency(frequency());
748 dest.set_telemetry_rate(telemetry_rate);
749 boolean max_enabled = true;
751 if (log_space() == 0)
754 if (log_fixed != AltosLib.MISSING)
757 switch (log_format) {
758 case AltosLib.AO_LOG_FORMAT_TINY:
767 dest.set_flight_log_max_enabled(max_enabled);
768 dest.set_radio_enable(radio_enable);
769 dest.set_flight_log_max_limit(log_space() >> 10, storage_erase_unit >> 10);
770 dest.set_flight_log_max(flight_log_max);
771 dest.set_ignite_mode(ignite_mode);
772 dest.set_pad_orientation(pad_orientation);
773 dest.set_accel_cal(accel_cal_plus(AltosLib.AO_PAD_ORIENTATION_ANTENNA_UP),
774 accel_cal_minus(AltosLib.AO_PAD_ORIENTATION_ANTENNA_UP));
775 dest.set_callsign(callsign);
776 if (npyro != AltosLib.MISSING)
777 dest.set_pyros(pyros);
779 dest.set_pyros(null);
780 dest.set_pyro_firing_time(pyro_firing_time);
781 dest.set_aprs_interval(aprs_interval);
782 dest.set_aprs_ssid(aprs_ssid);
783 dest.set_aprs_format(aprs_format);
784 dest.set_aprs_offset(aprs_offset);
786 dest.set_tracker_motion(tracker_motion);
787 dest.set_tracker_interval(tracker_interval);
790 public boolean log_has_state() {
791 switch (log_format) {
792 case AltosLib.AO_LOG_FORMAT_TELEGPS:
798 public void save(AltosLink link, boolean remote) throws InterruptedException, TimeoutException {
801 if (main_deploy != AltosLib.MISSING)
802 link.printf("c m %d\n", main_deploy);
803 if (apogee_delay != AltosLib.MISSING)
804 link.printf("c d %d\n", apogee_delay);
805 if (apogee_lockout != AltosLib.MISSING)
806 link.printf("c L %d\n", apogee_lockout);
809 if (has_frequency()) {
810 boolean has_frequency = radio_frequency != AltosLib.MISSING;
811 boolean has_setting = radio_setting != AltosLib.MISSING;
812 double frequency = frequency();
813 link.set_radio_frequency(frequency,
817 /* When remote, reset the dongle frequency at the same time */
818 if (remote && frequency != link.frequency) {
820 link.set_radio_frequency(frequency);
825 if (telemetry_rate != AltosLib.MISSING) {
826 link.printf("c T %d\n", telemetry_rate);
827 if (remote && telemetry_rate != link.telemetry_rate) {
829 link.set_telemetry_rate(telemetry_rate);
834 if (callsign != null) {
835 link.printf("c c %s\n", callsign);
836 if (remote && !callsign.equals(link.callsign)) {
837 System.out.printf("changing link callsign from %s to %s\n", link.callsign, callsign);
839 link.set_callsign(callsign);
844 if (radio_enable != AltosLib.MISSING)
845 link.printf("c e %d\n", radio_enable);
848 /* set orientation first so that we know how to set the accel cal */
849 if (pad_orientation != AltosLib.MISSING)
850 link.printf("c o %d\n", pad_orientation);
851 int plus = accel_cal_plus(pad_orientation);
852 int minus = accel_cal_minus(pad_orientation);
853 if (plus != AltosLib.MISSING && minus != AltosLib.MISSING) {
857 minus = 65536 + minus;
858 if (accel_zero_along != AltosLib.MISSING &&
859 accel_zero_across != AltosLib.MISSING &&
860 accel_zero_through != AltosLib.MISSING)
861 link.printf("c a %d %d %d %d %d\n",
867 link.printf("c a %d %d\n", plus, minus);
871 if (flight_log_max != 0 && flight_log_max != AltosLib.MISSING)
872 link.printf("c l %d\n", flight_log_max);
875 if (ignite_mode != AltosLib.MISSING)
876 link.printf("c i %d\n", ignite_mode);
879 /* UI doesn't support AES key config */
882 if (npyro != AltosLib.MISSING) {
883 for (int p = 0; p < pyros.length; p++) {
884 link.printf("c P %s\n",
885 pyros[p].toString());
888 if (pyro_firing_time != AltosLib.MISSING)
889 link.printf("c I %d\n", (int) (pyro_firing_time * 100.0 + 0.5));
892 if (aprs_interval != AltosLib.MISSING)
893 link.printf("c A %d\n", aprs_interval);
894 if (aprs_ssid != AltosLib.MISSING)
895 link.printf("c S %d\n", aprs_ssid);
896 if (aprs_format != AltosLib.MISSING)
897 link.printf("c C %d\n", aprs_format);
898 if (aprs_offset != AltosLib.MISSING)
899 link.printf("c O %d\n", aprs_offset);
902 if (beep != AltosLib.MISSING)
903 link.printf("c b %d\n", beep);
906 if (tracker_motion != AltosLib.MISSING && tracker_interval != AltosLib.MISSING)
907 link.printf("c t %d %d\n", tracker_motion, tracker_interval);
910 /* UI doesn't support accel cal */
912 link.printf("c w\n");
913 read_link(link, "Saved");
916 public AltosConfigData(AltosLink link) throws InterruptedException, TimeoutException {
918 link.printf("c s\nf\nv\n");
919 read_link(link, "software-version");
920 switch (log_format) {
921 case AltosLib.AO_LOG_FORMAT_UNKNOWN:
922 case AltosLib.AO_LOG_FORMAT_NONE:
926 read_link(link, "done");