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 public int report_feet;
91 /* Storage info replies */
92 public int storage_size;
93 public int storage_erase_unit;
95 /* Log listing replies */
96 public int stored_flight;
97 public AltosEepromFlight[] flights;
100 public int tracker_motion;
101 public int tracker_interval;
104 public int accel_zero_along, accel_zero_across, accel_zero_through;
109 public AltosMs5607 ms5607() {
111 ms5607 = new AltosMs5607();
115 public static String get_string(String line, String label) throws ParseException {
116 if (line.startsWith(label)) {
117 String quoted = line.substring(label.length()).trim();
119 if (quoted.startsWith("\""))
120 quoted = quoted.substring(1);
121 if (quoted.endsWith("\""))
122 quoted = quoted.substring(0,quoted.length()-1);
125 throw new ParseException("mismatch", 0);
128 public static int get_int(String line, String label) throws NumberFormatException, ParseException {
129 if (line.startsWith(label)) {
130 String tail = line.substring(label.length()).trim();
131 String[] tokens = tail.split("\\s+");
132 if (tokens.length > 0)
133 return Integer.parseInt(tokens[0]);
135 throw new ParseException("mismatch", 0);
138 public static int[] get_values(String line, String label) throws NumberFormatException, ParseException {
139 if (line.startsWith(label)) {
140 String tail = line.substring(label.length()).trim();
141 String[] tokens = tail.split("\\s+");
142 if (tokens.length > 1) {
143 int[] values = new int[2];
144 values[0] = Integer.parseInt(tokens[0]);
145 values[1] = Integer.parseInt(tokens[1]);
149 throw new ParseException("mismatch", 0);
152 public int log_space() {
153 if (log_space != AltosLib.MISSING)
156 if (storage_size != AltosLib.MISSING) {
157 int space = storage_size;
159 if (storage_erase_unit != AltosLib.MISSING && use_flash_for_config())
160 space -= storage_erase_unit;
162 if (space != AltosLib.MISSING)
168 public int log_available() {
169 switch (log_format) {
170 case AltosLib.AO_LOG_FORMAT_TINY:
174 case AltosLib.AO_LOG_FORMAT_TELEMETRY:
175 case AltosLib.AO_LOG_FORMAT_TELESCIENCE:
178 if (flight_log_max <= 0)
180 int log_max = flight_log_max * 1024;
181 int log_space = log_space();
187 log_used = flights.length * log_max;
190 if (log_used >= log_space)
193 log_avail = (log_space - log_used) / log_max;
199 public int invert_accel_value(int value) {
200 if (value == AltosLib.MISSING)
201 return AltosLib.MISSING;
203 switch (log_format) {
204 case AltosLib.AO_LOG_FORMAT_FULL:
205 return 0x7fff - value;
206 case AltosLib.AO_LOG_FORMAT_TELEMEGA_OLD:
207 case AltosLib.AO_LOG_FORMAT_TELEMEGA:
208 case AltosLib.AO_LOG_FORMAT_TELEMEGA_3:
210 case AltosLib.AO_LOG_FORMAT_TELEMETRUM:
212 * TeleMetrum v2 and later use the same log format, but
213 * have different accelerometers. This is the only place
214 * it matters in altoslib.
216 if (product.startsWith("TeleMetrum-v2"))
219 case AltosLib.AO_LOG_FORMAT_TELEMEGA_4:
220 case AltosLib.AO_LOG_FORMAT_TELEMEGA_5:
221 case AltosLib.AO_LOG_FORMAT_TELEMEGA_6:
222 case AltosLib.AO_LOG_FORMAT_EASYMEGA_2:
223 case AltosLib.AO_LOG_FORMAT_EASYMOTOR:
226 case AltosLib.AO_LOG_FORMAT_EASYTIMER_2:
230 if (product.startsWith("EasyTimer-"))
232 return AltosLib.MISSING;
236 public boolean has_monitor_battery() {
239 if (product.startsWith("TeleBT"))
244 int[] parse_version(String v) {
245 String[] parts = v.split("\\.");
246 int r[] = new int[parts.length];
248 for (int i = 0; i < parts.length; i++) {
250 r[i] = (int) AltosLib.fromdec(parts[i]);
251 } catch (NumberFormatException n) {
259 public boolean altitude_32() {
260 return altitude_32 == 1;
263 public int compare_version(String other) {
264 int[] me = parse_version(version);
265 int[] them = parse_version(other);
267 int l = Math.min(me.length, them.length);
269 for (int i = 0; i < l; i++) {
270 int d = me[i] - them[i];
281 public void reset() {
284 serial = AltosLib.MISSING;
285 flight = AltosLib.MISSING;
286 log_format = AltosLib.AO_LOG_FORMAT_UNKNOWN;
287 log_space = AltosLib.MISSING;
289 config_major = AltosLib.MISSING;
290 config_minor = AltosLib.MISSING;
292 main_deploy = AltosLib.MISSING;
293 apogee_delay = AltosLib.MISSING;
294 apogee_lockout = AltosLib.MISSING;
296 radio_frequency = AltosLib.MISSING;
298 radio_enable = AltosLib.MISSING;
299 radio_calibration = AltosLib.MISSING;
300 radio_channel = AltosLib.MISSING;
301 radio_setting = AltosLib.MISSING;
302 telemetry_rate = AltosLib.MISSING;
304 accel_cal_plus_cooked = AltosLib.MISSING;
305 accel_cal_minus_cooked = AltosLib.MISSING;
306 accel_cal_plus = AltosLib.MISSING;
307 accel_cal_minus = AltosLib.MISSING;
308 pad_orientation = AltosLib.MISSING;
309 accel_cal_adjusted = false;
311 flight_log_max = AltosLib.MISSING;
312 log_fixed = AltosLib.MISSING;
313 ignite_mode = AltosLib.MISSING;
317 pyro = AltosLib.MISSING;
318 npyro = AltosLib.MISSING;
320 pyro_firing_time = AltosLib.MISSING;
322 aprs_interval = AltosLib.MISSING;
323 aprs_ssid = AltosLib.MISSING;
324 aprs_format = AltosLib.MISSING;
325 aprs_offset = AltosLib.MISSING;
327 beep = AltosLib.MISSING;
329 radio_10mw = AltosLib.MISSING;
331 report_feet = AltosLib.MISSING;
333 tracker_motion = AltosLib.MISSING;
334 tracker_interval = AltosLib.MISSING;
336 storage_size = AltosLib.MISSING;
337 storage_erase_unit = AltosLib.MISSING;
341 accel_zero_along = AltosLib.MISSING;
342 accel_zero_across = AltosLib.MISSING;
343 accel_zero_through = AltosLib.MISSING;
346 /* Return + accel calibration relative to a specific pad orientation */
347 public int accel_cal_plus(int pad_orientation) {
349 if (!accel_cal_adjusted)
350 return AltosLib.MISSING;
352 switch (pad_orientation) {
353 case AltosLib.AO_PAD_ORIENTATION_ANTENNA_UP:
354 case AltosLib.AO_PAD_ORIENTATION_WORDS_UPRIGHT:
355 case AltosLib.AO_PAD_ORIENTATION_BIG_PARTS_UP:
356 return accel_cal_plus_cooked;
357 case AltosLib.AO_PAD_ORIENTATION_ANTENNA_DOWN:
358 case AltosLib.AO_PAD_ORIENTATION_WORDS_UPSIDEDOWN:
359 case AltosLib.AO_PAD_ORIENTATION_BIG_PARTS_DOWN:
360 return invert_accel_value(accel_cal_minus_cooked);
362 return AltosLib.MISSING;
366 /* Return - accel calibration relative to a specific pad orientation */
367 public int accel_cal_minus(int pad_orientation) {
369 if (!accel_cal_adjusted)
370 return AltosLib.MISSING;
372 switch (pad_orientation) {
373 case AltosLib.AO_PAD_ORIENTATION_ANTENNA_UP:
374 case AltosLib.AO_PAD_ORIENTATION_WORDS_UPRIGHT:
375 case AltosLib.AO_PAD_ORIENTATION_BIG_PARTS_UP:
376 return accel_cal_minus_cooked;
377 case AltosLib.AO_PAD_ORIENTATION_ANTENNA_DOWN:
378 case AltosLib.AO_PAD_ORIENTATION_WORDS_UPSIDEDOWN:
379 case AltosLib.AO_PAD_ORIENTATION_BIG_PARTS_DOWN:
380 return invert_accel_value(accel_cal_plus_cooked);
382 return AltosLib.MISSING;
386 /* Once we have all of the values from the config data, compute the
387 * accel cal values relative to Antenna Up orientation.
389 private void adjust_accel_cal() {
390 if (!accel_cal_adjusted &&
392 pad_orientation != AltosLib.MISSING &&
393 accel_cal_plus != AltosLib.MISSING &&
394 accel_cal_minus != AltosLib.MISSING)
396 switch (pad_orientation) {
397 case AltosLib.AO_PAD_ORIENTATION_ANTENNA_UP:
398 case AltosLib.AO_PAD_ORIENTATION_WORDS_UPRIGHT:
399 case AltosLib.AO_PAD_ORIENTATION_BIG_PARTS_UP:
400 accel_cal_plus_cooked = accel_cal_plus;
401 accel_cal_minus_cooked = accel_cal_minus;
402 accel_cal_adjusted = true;
404 case AltosLib.AO_PAD_ORIENTATION_ANTENNA_DOWN:
405 case AltosLib.AO_PAD_ORIENTATION_WORDS_UPSIDEDOWN:
406 case AltosLib.AO_PAD_ORIENTATION_BIG_PARTS_DOWN:
407 accel_cal_plus_cooked = invert_accel_value(accel_cal_minus);
408 accel_cal_minus_cooked = invert_accel_value(accel_cal_plus);
409 accel_cal_adjusted = true;
417 public void parse_line(String line) {
419 /* Version replies */
420 try { manufacturer = get_string(line, "manufacturer"); } catch (Exception e) {}
421 try { product = get_string(line, "product"); } catch (Exception e) {}
422 try { serial = get_int(line, "serial-number"); } catch (Exception e) {}
423 try { flight = get_int(line, "current-flight"); } catch (Exception e) {}
424 try { log_format = get_int(line, "log-format"); } catch (Exception e) {}
425 try { log_space = get_int(line, "log-space"); } catch (Exception e) {}
426 try { altitude_32 = get_int(line, "altitude-32"); } catch (Exception e) {}
427 try { version = get_string(line, "software-version"); } catch (Exception e) {}
429 /* Version also contains MS5607 info, which we ignore here */
431 try { ms5607().reserved = get_int(line, "ms5607 reserved:"); } catch (Exception e) {}
432 try { ms5607().sens = get_int(line, "ms5607 sens:"); } catch (Exception e) {}
433 try { ms5607().off = get_int(line, "ms5607 off:"); } catch (Exception e) {}
434 try { ms5607().tcs = get_int(line, "ms5607 tcs:"); } catch (Exception e) {}
435 try { ms5607().tco = get_int(line, "ms5607 tco:"); } catch (Exception e) {}
436 try { ms5607().tref = get_int(line, "ms5607 tref:"); } catch (Exception e) {}
437 try { ms5607().tempsens = get_int(line, "ms5607 tempsens:"); } catch (Exception e) {}
438 try { ms5607().crc = get_int(line, "ms5607 crc:"); } catch (Exception e) {}
440 /* Config show replies */
443 if (line.startsWith("Config version")) {
444 String[] bits = line.split("\\s+");
445 if (bits.length >= 3) {
446 String[] cfg = bits[2].split("\\.");
448 if (cfg.length >= 2) {
449 config_major = Integer.parseInt(cfg[0]);
450 config_minor = Integer.parseInt(cfg[1]);
454 } catch (Exception e) {}
457 try { main_deploy = get_int(line, "Main deploy:"); } catch (Exception e) {}
458 try { apogee_delay = get_int(line, "Apogee delay:"); } catch (Exception e) {}
459 try { apogee_lockout = get_int(line, "Apogee lockout:"); } catch (Exception e) {}
463 radio_frequency = get_int(line, "Frequency:");
464 if (radio_frequency < 0)
465 radio_frequency = 434550;
466 } catch (Exception e) {}
467 try { callsign = get_string(line, "Callsign:"); } catch (Exception e) {}
468 try { radio_enable = get_int(line, "Radio enable:"); } catch (Exception e) {}
469 try { radio_calibration = get_int(line, "Radio cal:"); } catch (Exception e) {}
470 try { telemetry_rate = get_int(line, "Telemetry rate:"); } catch (Exception e) {}
472 /* Old HAS_RADIO values */
473 try { radio_channel = get_int(line, "Radio channel:"); } catch (Exception e) {}
474 try { radio_setting = get_int(line, "Radio setting:"); } catch (Exception e) {}
478 if (line.startsWith("Accel cal")) {
479 String[] bits = line.split("\\s+");
480 if (bits.length >= 6) {
481 accel_cal_plus = Integer.parseInt(bits[3]);
482 accel_cal_minus = Integer.parseInt(bits[5]);
483 accel_cal_adjusted = false;
486 } catch (Exception e) {}
487 try { pad_orientation = get_int(line, "Pad orientation:"); } catch (Exception e) {}
490 try { flight_log_max = get_int(line, "Max flight log:"); } catch (Exception e) {}
491 try { log_fixed = get_int(line, "Log fixed:"); } catch (Exception e) {}
494 try { ignite_mode = get_int(line, "Ignite mode:"); } catch (Exception e) {}
497 try { aes_key = get_string(line, "AES key:"); } catch (Exception e) {}
501 npyro = get_int(line, "Pyro-count:");
502 pyros = new AltosPyro[npyro];
504 } catch (Exception e) {}
505 if (npyro != AltosLib.MISSING) {
507 AltosPyro p = new AltosPyro(pyro, line);
510 } catch (Exception e) {}
512 try { pyro_firing_time = get_int(line, "Pyro time:") / 100.0; } catch (Exception e) {}
515 try { aprs_interval = get_int(line, "APRS interval:"); } catch (Exception e) {}
516 try { aprs_ssid = get_int(line, "APRS SSID:"); } catch (Exception e) {}
517 try { aprs_format = get_int(line, "APRS format:"); } catch (Exception e) {}
518 try { aprs_offset = get_int(line, "APRS offset:"); } catch (Exception e) {}
521 try { beep = get_int(line, "Beeper setting:"); } catch (Exception e) {}
524 try { radio_10mw = get_int(line, "Radio 10mw limit:"); } catch (Exception e) {}
526 try { report_feet = get_int(line, "Report in feet:"); } catch (Exception e) {}
530 int[] values = get_values(line, "Tracker setting:");
531 tracker_motion = values[0];
532 tracker_interval = values[1];
533 } catch (Exception e) {}
535 /* Storage info replies */
536 try { storage_size = get_int(line, "Storage size:"); } catch (Exception e) {}
537 try { storage_erase_unit = get_int(line, "Storage erase unit:"); } catch (Exception e) {}
539 /* Log listing replies */
541 int flight = get_int(line, "flight");
542 String[] tokens = line.split("\\s+");
543 if (tokens.length >= 6) {
544 int start = -1, end = -1;
546 if (tokens[2].equals("start"))
547 start = AltosParse.parse_hex(tokens[3]);
548 if (tokens[4].equals("end"))
549 end = AltosParse.parse_hex(tokens[5]);
550 if (flight != 0 && start >= 0 && end > 0) {
555 len = flights.length;
556 AltosEepromFlight [] new_flights = new AltosEepromFlight[len + 1];
557 for (int i = 0; i < len; i++)
558 new_flights[i] = flights[i];
559 new_flights[len] = new AltosEepromFlight(flight, start, end);
560 flights = new_flights;
561 stored_flight = flights.length;
563 } catch (ParseException pe) { System.out.printf("Parse error %s\n", pe.toString()); }
565 } catch (Exception e) {}
569 if (line.startsWith("IMU cal along")) {
570 String[] bits = line.split("\\s+");
571 if (bits.length >= 8) {
572 accel_zero_along = Integer.parseInt(bits[3]);
573 accel_zero_across = Integer.parseInt(bits[5]);
574 accel_zero_through = Integer.parseInt(bits[7]);
577 } catch (Exception e) {}
580 public AltosConfigData() {
584 private void read_link(AltosLink link, String finished) throws InterruptedException, TimeoutException {
586 String line = link.get_reply();
588 throw new TimeoutException();
589 if (line.contains("Syntax error"))
591 this.parse_line(line);
593 /* signals the end of the version info */
594 if (line.startsWith(finished))
599 public boolean has_frequency() {
600 return radio_frequency != AltosLib.MISSING || radio_setting != AltosLib.MISSING || radio_channel != AltosLib.MISSING;
603 public boolean has_telemetry_rate() {
604 return telemetry_rate != AltosLib.MISSING;
607 public void set_frequency(double freq) {
608 int frequency = radio_frequency;
609 int setting = radio_setting;
611 if (frequency != AltosLib.MISSING) {
612 radio_frequency = (int) Math.floor (freq * 1000 + 0.5);
613 radio_channel = AltosLib.MISSING;
614 } else if (setting != AltosLib.MISSING) {
615 radio_setting =AltosConvert.radio_frequency_to_setting(freq, radio_calibration);
616 radio_channel = AltosLib.MISSING;
618 radio_channel = AltosConvert.radio_frequency_to_channel(freq);
622 public double frequency() {
623 int channel = radio_channel;
624 int setting = radio_setting;
626 if (radio_frequency == AltosLib.MISSING && channel == AltosLib.MISSING && setting == AltosLib.MISSING)
627 return AltosLib.MISSING;
629 if (channel == AltosLib.MISSING)
631 if (setting == AltosLib.MISSING)
634 return AltosConvert.radio_to_frequency(radio_frequency,
640 boolean use_flash_for_config() {
641 if (product.startsWith("TeleMega"))
643 if (product.startsWith("TeleMetrum-v2"))
645 if (product.startsWith("TeleMetrum-v3"))
647 if (product.startsWith("TeleMetrum-v4"))
649 if (product.startsWith("EasyMega"))
655 public boolean mma655x_inverted() throws AltosUnknownProduct {
656 if (product != null) {
657 if (product.startsWith("EasyMega-v1"))
659 if (product.startsWith("TeleMetrum-v2"))
661 if (product.startsWith("TeleMega-v2"))
663 if (product.startsWith("TeleMega-v1"))
666 throw new AltosUnknownProduct(product);
669 public boolean adxl375_inverted() throws AltosUnknownProduct {
670 if (product != null) {
671 if (product.startsWith("EasyMega-v2"))
673 if (product.startsWith("TeleMetrum-v3"))
675 if (product.startsWith("TeleMetrum-v4"))
677 if (product.startsWith("TeleMega-v4"))
679 if (product.startsWith("TeleMega-v5"))
681 if (product.startsWith("TeleMega-v6"))
683 if (product.startsWith("EasyMotor-v2"))
685 if (product.startsWith("EasyMotor-v3"))
688 throw new AltosUnknownProduct(product);
691 public int adxl375_axis() throws AltosUnknownProduct {
692 if (product != null) {
693 if (product.startsWith("EasyMega-v2"))
694 return AltosAdxl375.X_AXIS;
695 if (product.startsWith("TeleMetrum-v3"))
696 return AltosAdxl375.X_AXIS;
697 if (product.startsWith("TeleMetrum-v4"))
698 return AltosAdxl375.X_AXIS;
699 if (product.startsWith("TeleMega-v4"))
700 return AltosAdxl375.X_AXIS;
701 if (product.startsWith("TeleMega-v5"))
702 return AltosAdxl375.X_AXIS;
703 if (product.startsWith("TeleMega-v6"))
704 return AltosAdxl375.X_AXIS;
705 if (product.startsWith("EasyMotor-v2"))
706 return AltosAdxl375.X_AXIS;
707 if (product.startsWith("EasyMotor-v3"))
708 return AltosAdxl375.X_AXIS;
711 throw new AltosUnknownProduct(product);
714 public void get_values(AltosConfigValues source) throws AltosConfigDataException {
717 if (main_deploy != AltosLib.MISSING)
718 main_deploy = source.main_deploy();
719 if (apogee_delay != AltosLib.MISSING)
720 apogee_delay = source.apogee_delay();
721 if (apogee_lockout != AltosLib.MISSING)
722 apogee_lockout = source.apogee_lockout();
726 set_frequency(source.radio_frequency());
727 if (radio_enable != AltosLib.MISSING)
728 radio_enable = source.radio_enable();
729 if (callsign != null)
730 callsign = source.callsign();
731 if (telemetry_rate != AltosLib.MISSING)
732 telemetry_rate = source.telemetry_rate();
735 if (pad_orientation != AltosLib.MISSING)
736 pad_orientation = source.pad_orientation();
738 if (accel_cal_plus_cooked != AltosLib.MISSING)
739 accel_cal_plus_cooked = source.accel_cal_plus();
741 if (accel_cal_minus_cooked != AltosLib.MISSING)
742 accel_cal_minus_cooked = source.accel_cal_minus();
745 if (flight_log_max != AltosLib.MISSING)
746 flight_log_max = source.flight_log_max();
749 if (ignite_mode != AltosLib.MISSING)
750 ignite_mode = source.ignite_mode();
753 if (npyro != AltosLib.MISSING)
754 pyros = source.pyros();
755 if (pyro_firing_time != AltosLib.MISSING)
756 pyro_firing_time = source.pyro_firing_time();
759 if (aprs_interval != AltosLib.MISSING)
760 aprs_interval = source.aprs_interval();
761 if (aprs_ssid != AltosLib.MISSING)
762 aprs_ssid = source.aprs_ssid();
763 if (aprs_format != AltosLib.MISSING)
764 aprs_format = source.aprs_format();
765 if (aprs_offset != AltosLib.MISSING)
766 aprs_offset = source.aprs_offset();
769 if (beep != AltosLib.MISSING)
770 beep = source.beep();
773 if (radio_10mw != AltosLib.MISSING)
774 radio_10mw = source.radio_10mw();
776 if (report_feet != AltosLib.MISSING)
777 report_feet = source.report_feet();
780 if (tracker_motion != AltosLib.MISSING)
781 tracker_motion = source.tracker_motion();
782 if (tracker_interval != AltosLib.MISSING)
783 tracker_interval = source.tracker_interval();
786 public void set_values(AltosConfigValues dest) {
787 dest.set_serial(serial);
788 dest.set_product(product);
789 dest.set_version(version);
790 dest.set_altitude_32(altitude_32);
791 dest.set_main_deploy(main_deploy);
792 dest.set_apogee_delay(apogee_delay);
793 dest.set_apogee_lockout(apogee_lockout);
794 dest.set_radio_calibration(radio_calibration);
795 dest.set_radio_frequency(frequency());
796 dest.set_telemetry_rate(telemetry_rate);
797 boolean max_enabled = true;
799 if (log_space() == 0)
802 if (log_fixed != AltosLib.MISSING)
805 switch (log_format) {
806 case AltosLib.AO_LOG_FORMAT_TINY:
815 dest.set_flight_log_max_enabled(max_enabled);
816 dest.set_radio_enable(radio_enable);
817 dest.set_flight_log_max_limit(log_space() >> 10, storage_erase_unit >> 10);
818 dest.set_flight_log_max(flight_log_max);
819 dest.set_ignite_mode(ignite_mode);
820 dest.set_pad_orientation(pad_orientation);
821 dest.set_accel_cal(accel_cal_plus(AltosLib.AO_PAD_ORIENTATION_ANTENNA_UP),
822 accel_cal_minus(AltosLib.AO_PAD_ORIENTATION_ANTENNA_UP));
823 dest.set_callsign(callsign);
824 if (npyro != AltosLib.MISSING)
825 dest.set_pyros(pyros);
827 dest.set_pyros(null);
828 dest.set_pyro_firing_time(pyro_firing_time);
829 dest.set_aprs_interval(aprs_interval);
830 dest.set_aprs_ssid(aprs_ssid);
831 dest.set_aprs_format(aprs_format);
832 dest.set_aprs_offset(aprs_offset);
834 dest.set_radio_10mw(radio_10mw);
835 dest.set_report_feet(report_feet);
836 dest.set_tracker_motion(tracker_motion);
837 dest.set_tracker_interval(tracker_interval);
840 public boolean log_has_state() {
841 switch (log_format) {
842 case AltosLib.AO_LOG_FORMAT_TELEGPS:
848 public void save(AltosLink link, boolean remote) throws InterruptedException, TimeoutException {
851 if (main_deploy != AltosLib.MISSING)
852 link.printf("c m %d\n", main_deploy);
853 if (apogee_delay != AltosLib.MISSING)
854 link.printf("c d %d\n", apogee_delay);
855 if (apogee_lockout != AltosLib.MISSING)
856 link.printf("c L %d\n", apogee_lockout);
859 if (has_frequency()) {
860 boolean has_frequency = radio_frequency != AltosLib.MISSING;
861 boolean has_setting = radio_setting != AltosLib.MISSING;
862 double frequency = frequency();
863 link.set_radio_frequency(frequency,
867 /* When remote, reset the dongle frequency at the same time */
868 if (remote && frequency != link.frequency) {
870 link.set_radio_frequency(frequency);
875 if (telemetry_rate != AltosLib.MISSING) {
876 link.printf("c T %d\n", telemetry_rate);
877 if (remote && telemetry_rate != link.telemetry_rate) {
879 link.set_telemetry_rate(telemetry_rate);
884 if (callsign != null) {
885 link.printf("c c %s\n", callsign);
886 if (remote && !callsign.equals(link.callsign)) {
887 System.out.printf("changing link callsign from %s to %s\n", link.callsign, callsign);
889 link.set_callsign(callsign);
894 if (radio_enable != AltosLib.MISSING)
895 link.printf("c e %d\n", radio_enable);
898 /* set orientation first so that we know how to set the accel cal */
899 if (pad_orientation != AltosLib.MISSING)
900 link.printf("c o %d\n", pad_orientation);
901 int plus = accel_cal_plus(pad_orientation);
902 int minus = accel_cal_minus(pad_orientation);
903 if (plus != AltosLib.MISSING && minus != AltosLib.MISSING) {
907 minus = 65536 + minus;
908 if (accel_zero_along != AltosLib.MISSING &&
909 accel_zero_across != AltosLib.MISSING &&
910 accel_zero_through != AltosLib.MISSING)
911 link.printf("c a %d %d %d %d %d\n",
917 link.printf("c a %d %d\n", plus, minus);
921 if (flight_log_max != 0 && flight_log_max != AltosLib.MISSING)
922 link.printf("c l %d\n", flight_log_max);
925 if (ignite_mode != AltosLib.MISSING)
926 link.printf("c i %d\n", ignite_mode);
929 /* UI doesn't support AES key config */
932 if (npyro != AltosLib.MISSING) {
933 for (int p = 0; p < pyros.length; p++) {
934 link.printf("c P %s\n",
935 pyros[p].toString());
938 if (pyro_firing_time != AltosLib.MISSING)
939 link.printf("c I %d\n", (int) (pyro_firing_time * 100.0 + 0.5));
942 if (aprs_interval != AltosLib.MISSING)
943 link.printf("c A %d\n", aprs_interval);
944 if (aprs_ssid != AltosLib.MISSING)
945 link.printf("c S %d\n", aprs_ssid);
946 if (aprs_format != AltosLib.MISSING)
947 link.printf("c C %d\n", aprs_format);
948 if (aprs_offset != AltosLib.MISSING)
949 link.printf("c O %d\n", aprs_offset);
952 if (beep != AltosLib.MISSING)
953 link.printf("c b %d\n", beep);
956 if (radio_10mw != AltosLib.MISSING)
957 link.printf("c p %d\n", radio_10mw);
960 if (report_feet != AltosLib.MISSING)
961 link.printf("c u %d\n", report_feet);
964 if (tracker_motion != AltosLib.MISSING && tracker_interval != AltosLib.MISSING)
965 link.printf("c t %d %d\n", tracker_motion, tracker_interval);
968 /* UI doesn't support accel cal */
970 link.printf("c w\n");
971 read_link(link, "Saved");
974 public AltosConfigData(AltosLink link) throws InterruptedException, TimeoutException {
976 link.printf("c s\nf\nv\n");
977 read_link(link, "software-version");
978 switch (log_format) {
979 case AltosLib.AO_LOG_FORMAT_UNKNOWN:
980 case AltosLib.AO_LOG_FORMAT_NONE:
984 read_link(link, "done");