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;
92 public int gps_receiver;
94 /* Storage info replies */
95 public int storage_size;
96 public int storage_erase_unit;
98 /* Log listing replies */
99 public int stored_flight;
100 public AltosEepromFlight[] flights;
103 public int tracker_motion;
104 public int tracker_interval;
107 public int accel_zero_along, accel_zero_across, accel_zero_through;
112 public AltosMs5607 ms5607() {
114 ms5607 = new AltosMs5607();
118 public static String get_string(String line, String label) throws ParseException {
119 if (line.startsWith(label)) {
120 String quoted = line.substring(label.length()).trim();
122 if (quoted.startsWith("\""))
123 quoted = quoted.substring(1);
124 if (quoted.endsWith("\""))
125 quoted = quoted.substring(0,quoted.length()-1);
128 throw new ParseException("mismatch", 0);
131 public static int get_int(String line, String label) throws NumberFormatException, ParseException {
132 if (line.startsWith(label)) {
133 String tail = line.substring(label.length()).trim();
134 String[] tokens = tail.split("\\s+");
135 if (tokens.length > 0)
136 return Integer.parseInt(tokens[0]);
138 throw new ParseException("mismatch", 0);
141 public static int[] get_values(String line, String label) throws NumberFormatException, ParseException {
142 if (line.startsWith(label)) {
143 String tail = line.substring(label.length()).trim();
144 String[] tokens = tail.split("\\s+");
145 if (tokens.length > 1) {
146 int[] values = new int[2];
147 values[0] = Integer.parseInt(tokens[0]);
148 values[1] = Integer.parseInt(tokens[1]);
152 throw new ParseException("mismatch", 0);
155 public int log_space() {
156 if (log_space != AltosLib.MISSING)
159 if (storage_size != AltosLib.MISSING) {
160 int space = storage_size;
162 if (storage_erase_unit != AltosLib.MISSING && use_flash_for_config())
163 space -= storage_erase_unit;
165 if (space != AltosLib.MISSING)
171 public int log_available() {
172 switch (log_format) {
173 case AltosLib.AO_LOG_FORMAT_TINY:
177 case AltosLib.AO_LOG_FORMAT_TELEMETRY:
178 case AltosLib.AO_LOG_FORMAT_TELESCIENCE:
181 if (flight_log_max <= 0)
183 int log_max = flight_log_max * 1024;
184 int log_space = log_space();
190 log_used = flights.length * log_max;
193 if (log_used >= log_space)
196 log_avail = (log_space - log_used) / log_max;
202 public int invert_accel_value(int value) {
203 if (value == AltosLib.MISSING)
204 return AltosLib.MISSING;
206 switch (log_format) {
207 case AltosLib.AO_LOG_FORMAT_FULL:
208 return 0x7fff - value;
209 case AltosLib.AO_LOG_FORMAT_TELEMEGA_OLD:
210 case AltosLib.AO_LOG_FORMAT_TELEMEGA:
211 case AltosLib.AO_LOG_FORMAT_TELEMEGA_3:
213 case AltosLib.AO_LOG_FORMAT_TELEMETRUM:
215 * TeleMetrum v2 and later use the same log format, but
216 * have different accelerometers. This is the only place
217 * it matters in altoslib.
219 if (product.startsWith("TeleMetrum-v2"))
222 case AltosLib.AO_LOG_FORMAT_TELEMEGA_4:
223 case AltosLib.AO_LOG_FORMAT_TELEMEGA_5:
224 case AltosLib.AO_LOG_FORMAT_TELEMEGA_6:
225 case AltosLib.AO_LOG_FORMAT_EASYMEGA_2:
226 case AltosLib.AO_LOG_FORMAT_EASYMEGA_3:
227 case AltosLib.AO_LOG_FORMAT_EASYMOTOR:
230 case AltosLib.AO_LOG_FORMAT_EASYTIMER_2:
234 if (product.startsWith("EasyTimer-"))
236 return AltosLib.MISSING;
240 public boolean has_monitor_battery() {
243 if (product.startsWith("TeleBT"))
248 int[] parse_version(String v) {
249 String[] parts = v.split("\\.");
250 int r[] = new int[parts.length];
252 for (int i = 0; i < parts.length; i++) {
254 r[i] = (int) AltosLib.fromdec(parts[i]);
255 } catch (NumberFormatException n) {
263 public boolean altitude_32() {
264 return altitude_32 == 1;
267 public int compare_version(String other) {
268 int[] me = parse_version(version);
269 int[] them = parse_version(other);
271 int l = Math.min(me.length, them.length);
273 for (int i = 0; i < l; i++) {
274 int d = me[i] - them[i];
285 public void reset() {
288 serial = AltosLib.MISSING;
289 flight = AltosLib.MISSING;
290 log_format = AltosLib.AO_LOG_FORMAT_UNKNOWN;
291 log_space = AltosLib.MISSING;
293 config_major = AltosLib.MISSING;
294 config_minor = AltosLib.MISSING;
296 main_deploy = AltosLib.MISSING;
297 apogee_delay = AltosLib.MISSING;
298 apogee_lockout = AltosLib.MISSING;
300 radio_frequency = AltosLib.MISSING;
302 radio_enable = AltosLib.MISSING;
303 radio_calibration = AltosLib.MISSING;
304 radio_channel = AltosLib.MISSING;
305 radio_setting = AltosLib.MISSING;
306 telemetry_rate = AltosLib.MISSING;
308 accel_cal_plus_cooked = AltosLib.MISSING;
309 accel_cal_minus_cooked = AltosLib.MISSING;
310 accel_cal_plus = AltosLib.MISSING;
311 accel_cal_minus = AltosLib.MISSING;
312 pad_orientation = AltosLib.MISSING;
313 accel_cal_adjusted = false;
315 flight_log_max = AltosLib.MISSING;
316 log_fixed = AltosLib.MISSING;
317 ignite_mode = AltosLib.MISSING;
321 pyro = AltosLib.MISSING;
322 npyro = AltosLib.MISSING;
324 pyro_firing_time = AltosLib.MISSING;
326 aprs_interval = AltosLib.MISSING;
327 aprs_ssid = AltosLib.MISSING;
328 aprs_format = AltosLib.MISSING;
329 aprs_offset = AltosLib.MISSING;
331 beep = AltosLib.MISSING;
333 radio_10mw = AltosLib.MISSING;
335 report_feet = AltosLib.MISSING;
337 gps_receiver = AltosLib.MISSING;
339 tracker_motion = AltosLib.MISSING;
340 tracker_interval = AltosLib.MISSING;
342 storage_size = AltosLib.MISSING;
343 storage_erase_unit = AltosLib.MISSING;
347 accel_zero_along = AltosLib.MISSING;
348 accel_zero_across = AltosLib.MISSING;
349 accel_zero_through = AltosLib.MISSING;
352 /* Return + accel calibration relative to a specific pad orientation */
353 public int accel_cal_plus(int pad_orientation) {
355 if (!accel_cal_adjusted)
356 return AltosLib.MISSING;
358 switch (pad_orientation) {
359 case AltosLib.AO_PAD_ORIENTATION_ANTENNA_UP:
360 case AltosLib.AO_PAD_ORIENTATION_WORDS_UPRIGHT:
361 case AltosLib.AO_PAD_ORIENTATION_BIG_PARTS_UP:
362 return accel_cal_plus_cooked;
363 case AltosLib.AO_PAD_ORIENTATION_ANTENNA_DOWN:
364 case AltosLib.AO_PAD_ORIENTATION_WORDS_UPSIDEDOWN:
365 case AltosLib.AO_PAD_ORIENTATION_BIG_PARTS_DOWN:
366 return invert_accel_value(accel_cal_minus_cooked);
368 return AltosLib.MISSING;
372 /* Return - accel calibration relative to a specific pad orientation */
373 public int accel_cal_minus(int pad_orientation) {
375 if (!accel_cal_adjusted)
376 return AltosLib.MISSING;
378 switch (pad_orientation) {
379 case AltosLib.AO_PAD_ORIENTATION_ANTENNA_UP:
380 case AltosLib.AO_PAD_ORIENTATION_WORDS_UPRIGHT:
381 case AltosLib.AO_PAD_ORIENTATION_BIG_PARTS_UP:
382 return accel_cal_minus_cooked;
383 case AltosLib.AO_PAD_ORIENTATION_ANTENNA_DOWN:
384 case AltosLib.AO_PAD_ORIENTATION_WORDS_UPSIDEDOWN:
385 case AltosLib.AO_PAD_ORIENTATION_BIG_PARTS_DOWN:
386 return invert_accel_value(accel_cal_plus_cooked);
388 return AltosLib.MISSING;
392 /* Once we have all of the values from the config data, compute the
393 * accel cal values relative to Antenna Up orientation.
395 private void adjust_accel_cal() {
396 if (!accel_cal_adjusted &&
398 pad_orientation != AltosLib.MISSING &&
399 accel_cal_plus != AltosLib.MISSING &&
400 accel_cal_minus != AltosLib.MISSING)
402 switch (pad_orientation) {
403 case AltosLib.AO_PAD_ORIENTATION_ANTENNA_UP:
404 case AltosLib.AO_PAD_ORIENTATION_WORDS_UPRIGHT:
405 case AltosLib.AO_PAD_ORIENTATION_BIG_PARTS_UP:
406 accel_cal_plus_cooked = accel_cal_plus;
407 accel_cal_minus_cooked = accel_cal_minus;
408 accel_cal_adjusted = true;
410 case AltosLib.AO_PAD_ORIENTATION_ANTENNA_DOWN:
411 case AltosLib.AO_PAD_ORIENTATION_WORDS_UPSIDEDOWN:
412 case AltosLib.AO_PAD_ORIENTATION_BIG_PARTS_DOWN:
413 accel_cal_plus_cooked = invert_accel_value(accel_cal_minus);
414 accel_cal_minus_cooked = invert_accel_value(accel_cal_plus);
415 accel_cal_adjusted = true;
423 public void parse_line(String line) {
425 /* Version replies */
426 try { manufacturer = get_string(line, "manufacturer"); } catch (Exception e) {}
427 try { product = get_string(line, "product"); } catch (Exception e) {}
428 try { serial = get_int(line, "serial-number"); } catch (Exception e) {}
429 try { flight = get_int(line, "current-flight"); } catch (Exception e) {}
430 try { log_format = get_int(line, "log-format"); } catch (Exception e) {}
431 try { log_space = get_int(line, "log-space"); } catch (Exception e) {}
432 try { altitude_32 = get_int(line, "altitude-32"); } catch (Exception e) {}
433 try { version = get_string(line, "software-version"); } catch (Exception e) {}
435 /* Version also contains MS5607 info, which we ignore here */
437 try { ms5607().reserved = get_int(line, "ms5607 reserved:"); } catch (Exception e) {}
438 try { ms5607().sens = get_int(line, "ms5607 sens:"); } catch (Exception e) {}
439 try { ms5607().off = get_int(line, "ms5607 off:"); } catch (Exception e) {}
440 try { ms5607().tcs = get_int(line, "ms5607 tcs:"); } catch (Exception e) {}
441 try { ms5607().tco = get_int(line, "ms5607 tco:"); } catch (Exception e) {}
442 try { ms5607().tref = get_int(line, "ms5607 tref:"); } catch (Exception e) {}
443 try { ms5607().tempsens = get_int(line, "ms5607 tempsens:"); } catch (Exception e) {}
444 try { ms5607().crc = get_int(line, "ms5607 crc:"); } catch (Exception e) {}
446 /* Config show replies */
449 if (line.startsWith("Config version")) {
450 String[] bits = line.split("\\s+");
451 if (bits.length >= 3) {
452 String[] cfg = bits[2].split("\\.");
454 if (cfg.length >= 2) {
455 config_major = Integer.parseInt(cfg[0]);
456 config_minor = Integer.parseInt(cfg[1]);
460 } catch (Exception e) {}
463 try { main_deploy = get_int(line, "Main deploy:"); } catch (Exception e) {}
464 try { apogee_delay = get_int(line, "Apogee delay:"); } catch (Exception e) {}
465 try { apogee_lockout = get_int(line, "Apogee lockout:"); } catch (Exception e) {}
469 radio_frequency = get_int(line, "Frequency:");
470 if (radio_frequency < 0)
471 radio_frequency = 434550;
472 } catch (Exception e) {}
473 try { callsign = get_string(line, "Callsign:"); } catch (Exception e) {}
474 try { radio_enable = get_int(line, "Radio enable:"); } catch (Exception e) {}
475 try { radio_calibration = get_int(line, "Radio cal:"); } catch (Exception e) {}
476 try { telemetry_rate = get_int(line, "Telemetry rate:"); } catch (Exception e) {}
478 /* Old HAS_RADIO values */
479 try { radio_channel = get_int(line, "Radio channel:"); } catch (Exception e) {}
480 try { radio_setting = get_int(line, "Radio setting:"); } catch (Exception e) {}
484 if (line.startsWith("Accel cal")) {
485 String[] bits = line.split("\\s+");
486 if (bits.length >= 6) {
487 accel_cal_plus = Integer.parseInt(bits[3]);
488 accel_cal_minus = Integer.parseInt(bits[5]);
489 accel_cal_adjusted = false;
492 } catch (Exception e) {}
493 try { pad_orientation = get_int(line, "Pad orientation:"); } catch (Exception e) {}
496 try { flight_log_max = get_int(line, "Max flight log:"); } catch (Exception e) {}
497 try { log_fixed = get_int(line, "Log fixed:"); } catch (Exception e) {}
500 try { ignite_mode = get_int(line, "Ignite mode:"); } catch (Exception e) {}
503 try { aes_key = get_string(line, "AES key:"); } catch (Exception e) {}
507 npyro = get_int(line, "Pyro-count:");
508 pyros = new AltosPyro[npyro];
510 } catch (Exception e) {}
511 if (npyro != AltosLib.MISSING) {
513 AltosPyro p = new AltosPyro(pyro, line);
516 } catch (Exception e) {}
518 try { pyro_firing_time = get_int(line, "Pyro time:") / 100.0; } catch (Exception e) {}
521 try { aprs_interval = get_int(line, "APRS interval:"); } catch (Exception e) {}
522 try { aprs_ssid = get_int(line, "APRS SSID:"); } catch (Exception e) {}
523 try { aprs_format = get_int(line, "APRS format:"); } catch (Exception e) {}
524 try { aprs_offset = get_int(line, "APRS offset:"); } catch (Exception e) {}
527 try { beep = get_int(line, "Beeper setting:"); } catch (Exception e) {}
530 try { radio_10mw = get_int(line, "Radio 10mw limit:"); } catch (Exception e) {}
532 try { report_feet = get_int(line, "Report in feet:"); } catch (Exception e) {}
534 try { gps_receiver = get_int(line, "GPS receiver:"); } catch (Exception e) {}
538 int[] values = get_values(line, "Tracker setting:");
539 tracker_motion = values[0];
540 tracker_interval = values[1];
541 } catch (Exception e) {}
543 /* Storage info replies */
544 try { storage_size = get_int(line, "Storage size:"); } catch (Exception e) {}
545 try { storage_erase_unit = get_int(line, "Storage erase unit:"); } catch (Exception e) {}
547 /* Log listing replies */
549 int flight = get_int(line, "flight");
550 String[] tokens = line.split("\\s+");
551 if (tokens.length >= 6) {
552 int start = -1, end = -1;
554 if (tokens[2].equals("start"))
555 start = AltosParse.parse_hex(tokens[3]);
556 if (tokens[4].equals("end"))
557 end = AltosParse.parse_hex(tokens[5]);
558 if (flight != 0 && start >= 0 && end > 0) {
563 len = flights.length;
564 AltosEepromFlight [] new_flights = new AltosEepromFlight[len + 1];
565 for (int i = 0; i < len; i++)
566 new_flights[i] = flights[i];
567 new_flights[len] = new AltosEepromFlight(flight, start, end);
568 flights = new_flights;
569 stored_flight = flights.length;
571 } catch (ParseException pe) { System.out.printf("Parse error %s\n", pe.toString()); }
573 } catch (Exception e) {}
577 if (line.startsWith("IMU cal along")) {
578 String[] bits = line.split("\\s+");
579 if (bits.length >= 8) {
580 accel_zero_along = Integer.parseInt(bits[3]);
581 accel_zero_across = Integer.parseInt(bits[5]);
582 accel_zero_through = Integer.parseInt(bits[7]);
585 } catch (Exception e) {}
588 public AltosConfigData() {
592 private void read_link(AltosLink link, String finished) throws InterruptedException, TimeoutException {
594 String line = link.get_reply();
596 throw new TimeoutException();
597 if (line.contains("Syntax error"))
599 this.parse_line(line);
601 /* signals the end of the version info */
602 if (line.startsWith(finished))
607 public boolean has_frequency() {
608 return radio_frequency != AltosLib.MISSING || radio_setting != AltosLib.MISSING || radio_channel != AltosLib.MISSING;
611 public boolean has_telemetry_rate() {
612 return telemetry_rate != AltosLib.MISSING;
615 public void set_frequency(double freq) {
616 int frequency = radio_frequency;
617 int setting = radio_setting;
619 if (frequency != AltosLib.MISSING) {
620 radio_frequency = (int) Math.floor (freq * 1000 + 0.5);
621 radio_channel = AltosLib.MISSING;
622 } else if (setting != AltosLib.MISSING) {
623 radio_setting =AltosConvert.radio_frequency_to_setting(freq, radio_calibration);
624 radio_channel = AltosLib.MISSING;
626 radio_channel = AltosConvert.radio_frequency_to_channel(freq);
630 public double frequency() {
631 int channel = radio_channel;
632 int setting = radio_setting;
634 if (radio_frequency == AltosLib.MISSING && channel == AltosLib.MISSING && setting == AltosLib.MISSING)
635 return AltosLib.MISSING;
637 if (channel == AltosLib.MISSING)
639 if (setting == AltosLib.MISSING)
642 return AltosConvert.radio_to_frequency(radio_frequency,
648 boolean use_flash_for_config() {
649 if (product.startsWith("TeleMega"))
651 if (product.startsWith("TeleMetrum-v2"))
653 if (product.startsWith("TeleMetrum-v3"))
655 if (product.startsWith("TeleMetrum-v4"))
657 if (product.startsWith("EasyMega"))
663 public boolean mma655x_inverted() throws AltosUnknownProduct {
664 if (product != null) {
665 if (product.startsWith("EasyMega-v1"))
667 if (product.startsWith("TeleMetrum-v2"))
669 if (product.startsWith("TeleMega-v2"))
671 if (product.startsWith("TeleMega-v1"))
674 throw new AltosUnknownProduct(product);
677 public boolean adxl375_inverted() throws AltosUnknownProduct {
678 if (product != null) {
679 if (product.startsWith("EasyMega-v2"))
681 if (product.startsWith("TeleMetrum-v3"))
683 if (product.startsWith("TeleMetrum-v4"))
685 if (product.startsWith("TeleMega-v4"))
687 if (product.startsWith("TeleMega-v5"))
689 if (product.startsWith("TeleMega-v6"))
691 if (product.startsWith("EasyMotor-v2"))
693 if (product.startsWith("EasyMotor-v3"))
696 throw new AltosUnknownProduct(product);
699 public int adxl375_axis() throws AltosUnknownProduct {
700 if (product != null) {
701 if (product.startsWith("EasyMega-v2"))
702 return AltosAdxl375.X_AXIS;
703 if (product.startsWith("TeleMetrum-v3"))
704 return AltosAdxl375.X_AXIS;
705 if (product.startsWith("TeleMetrum-v4"))
706 return AltosAdxl375.X_AXIS;
707 if (product.startsWith("TeleMega-v4"))
708 return AltosAdxl375.X_AXIS;
709 if (product.startsWith("TeleMega-v5"))
710 return AltosAdxl375.X_AXIS;
711 if (product.startsWith("TeleMega-v6"))
712 return AltosAdxl375.X_AXIS;
713 if (product.startsWith("EasyMotor-v2"))
714 return AltosAdxl375.X_AXIS;
715 if (product.startsWith("EasyMotor-v3"))
716 return AltosAdxl375.X_AXIS;
719 throw new AltosUnknownProduct(product);
722 public void get_values(AltosConfigValues source) throws AltosConfigDataException {
725 if (main_deploy != AltosLib.MISSING)
726 main_deploy = source.main_deploy();
727 if (apogee_delay != AltosLib.MISSING)
728 apogee_delay = source.apogee_delay();
729 if (apogee_lockout != AltosLib.MISSING)
730 apogee_lockout = source.apogee_lockout();
734 set_frequency(source.radio_frequency());
735 if (radio_enable != AltosLib.MISSING)
736 radio_enable = source.radio_enable();
737 if (callsign != null)
738 callsign = source.callsign();
739 if (telemetry_rate != AltosLib.MISSING)
740 telemetry_rate = source.telemetry_rate();
743 if (pad_orientation != AltosLib.MISSING)
744 pad_orientation = source.pad_orientation();
746 if (accel_cal_plus_cooked != AltosLib.MISSING)
747 accel_cal_plus_cooked = source.accel_cal_plus();
749 if (accel_cal_minus_cooked != AltosLib.MISSING)
750 accel_cal_minus_cooked = source.accel_cal_minus();
753 if (flight_log_max != AltosLib.MISSING)
754 flight_log_max = source.flight_log_max();
757 if (ignite_mode != AltosLib.MISSING)
758 ignite_mode = source.ignite_mode();
761 if (npyro != AltosLib.MISSING)
762 pyros = source.pyros();
763 if (pyro_firing_time != AltosLib.MISSING)
764 pyro_firing_time = source.pyro_firing_time();
767 if (aprs_interval != AltosLib.MISSING)
768 aprs_interval = source.aprs_interval();
769 if (aprs_ssid != AltosLib.MISSING)
770 aprs_ssid = source.aprs_ssid();
771 if (aprs_format != AltosLib.MISSING)
772 aprs_format = source.aprs_format();
773 if (aprs_offset != AltosLib.MISSING)
774 aprs_offset = source.aprs_offset();
777 if (beep != AltosLib.MISSING)
778 beep = source.beep();
781 if (radio_10mw != AltosLib.MISSING)
782 radio_10mw = source.radio_10mw();
784 if (report_feet != AltosLib.MISSING)
785 report_feet = source.report_feet();
787 if (gps_receiver != AltosLib.MISSING)
788 gps_receiver = source.gps_receiver();
791 if (tracker_motion != AltosLib.MISSING)
792 tracker_motion = source.tracker_motion();
793 if (tracker_interval != AltosLib.MISSING)
794 tracker_interval = source.tracker_interval();
797 public void set_values(AltosConfigValues dest) {
798 dest.set_serial(serial);
799 dest.set_product(product);
800 dest.set_version(version);
801 dest.set_altitude_32(altitude_32);
802 dest.set_main_deploy(main_deploy);
803 dest.set_apogee_delay(apogee_delay);
804 dest.set_apogee_lockout(apogee_lockout);
805 dest.set_radio_calibration(radio_calibration);
806 dest.set_radio_frequency(frequency());
807 dest.set_telemetry_rate(telemetry_rate);
808 boolean max_enabled = true;
810 if (log_space() == 0)
813 if (log_fixed != AltosLib.MISSING)
816 switch (log_format) {
817 case AltosLib.AO_LOG_FORMAT_TINY:
826 dest.set_flight_log_max_enabled(max_enabled);
827 dest.set_radio_enable(radio_enable);
828 dest.set_flight_log_max_limit(log_space() >> 10, storage_erase_unit >> 10);
829 dest.set_flight_log_max(flight_log_max);
830 dest.set_ignite_mode(ignite_mode);
831 dest.set_pad_orientation(pad_orientation);
832 dest.set_accel_cal(accel_cal_plus(AltosLib.AO_PAD_ORIENTATION_ANTENNA_UP),
833 accel_cal_minus(AltosLib.AO_PAD_ORIENTATION_ANTENNA_UP));
834 dest.set_callsign(callsign);
835 if (npyro != AltosLib.MISSING)
836 dest.set_pyros(pyros);
838 dest.set_pyros(null);
839 dest.set_pyro_firing_time(pyro_firing_time);
840 dest.set_aprs_interval(aprs_interval);
841 dest.set_aprs_ssid(aprs_ssid);
842 dest.set_aprs_format(aprs_format);
843 dest.set_aprs_offset(aprs_offset);
845 dest.set_radio_10mw(radio_10mw);
846 dest.set_report_feet(report_feet);
847 dest.set_gps_receiver(gps_receiver);
848 dest.set_tracker_motion(tracker_motion);
849 dest.set_tracker_interval(tracker_interval);
852 public boolean log_has_state() {
853 switch (log_format) {
854 case AltosLib.AO_LOG_FORMAT_TELEGPS:
860 public void save(AltosLink link, boolean remote) throws InterruptedException, TimeoutException {
863 if (main_deploy != AltosLib.MISSING)
864 link.printf("c m %d\n", main_deploy);
865 if (apogee_delay != AltosLib.MISSING)
866 link.printf("c d %d\n", apogee_delay);
867 if (apogee_lockout != AltosLib.MISSING)
868 link.printf("c L %d\n", apogee_lockout);
871 if (has_frequency()) {
872 boolean has_frequency = radio_frequency != AltosLib.MISSING;
873 boolean has_setting = radio_setting != AltosLib.MISSING;
874 double frequency = frequency();
875 link.set_radio_frequency(frequency,
879 /* When remote, reset the dongle frequency at the same time */
880 if (remote && frequency != link.frequency) {
882 link.set_radio_frequency(frequency);
887 if (telemetry_rate != AltosLib.MISSING) {
888 link.printf("c T %d\n", telemetry_rate);
889 if (remote && telemetry_rate != link.telemetry_rate) {
891 link.set_telemetry_rate(telemetry_rate);
896 if (callsign != null) {
897 link.printf("c c %s\n", callsign);
898 if (remote && !callsign.equals(link.callsign)) {
899 System.out.printf("changing link callsign from %s to %s\n", link.callsign, callsign);
901 link.set_callsign(callsign);
906 if (radio_enable != AltosLib.MISSING)
907 link.printf("c e %d\n", radio_enable);
910 /* set orientation first so that we know how to set the accel cal */
911 if (pad_orientation != AltosLib.MISSING)
912 link.printf("c o %d\n", pad_orientation);
913 int plus = accel_cal_plus(pad_orientation);
914 int minus = accel_cal_minus(pad_orientation);
915 if (plus != AltosLib.MISSING && minus != AltosLib.MISSING) {
919 minus = 65536 + minus;
920 if (accel_zero_along != AltosLib.MISSING &&
921 accel_zero_across != AltosLib.MISSING &&
922 accel_zero_through != AltosLib.MISSING)
923 link.printf("c a %d %d %d %d %d\n",
929 link.printf("c a %d %d\n", plus, minus);
933 if (flight_log_max != 0 && flight_log_max != AltosLib.MISSING)
934 link.printf("c l %d\n", flight_log_max);
937 if (ignite_mode != AltosLib.MISSING)
938 link.printf("c i %d\n", ignite_mode);
941 /* UI doesn't support AES key config */
944 if (npyro != AltosLib.MISSING) {
945 for (int p = 0; p < pyros.length; p++) {
946 link.printf("c P %s\n",
947 pyros[p].toString());
950 if (pyro_firing_time != AltosLib.MISSING)
951 link.printf("c I %d\n", (int) (pyro_firing_time * 100.0 + 0.5));
954 if (aprs_interval != AltosLib.MISSING)
955 link.printf("c A %d\n", aprs_interval);
956 if (aprs_ssid != AltosLib.MISSING)
957 link.printf("c S %d\n", aprs_ssid);
958 if (aprs_format != AltosLib.MISSING)
959 link.printf("c C %d\n", aprs_format);
960 if (aprs_offset != AltosLib.MISSING)
961 link.printf("c O %d\n", aprs_offset);
964 if (beep != AltosLib.MISSING)
965 link.printf("c b %d\n", beep);
968 if (radio_10mw != AltosLib.MISSING)
969 link.printf("c p %d\n", radio_10mw);
971 if (report_feet != AltosLib.MISSING)
972 link.printf("c u %d\n", report_feet);
975 if (gps_receiver != AltosLib.MISSING)
976 link.printf("c g %d\n", gps_receiver);
979 if (tracker_motion != AltosLib.MISSING && tracker_interval != AltosLib.MISSING)
980 link.printf("c t %d %d\n", tracker_motion, tracker_interval);
983 /* UI doesn't support accel cal */
985 link.printf("c w\n");
986 read_link(link, "Saved");
989 public AltosConfigData(AltosLink link) throws InterruptedException, TimeoutException {
991 link.printf("c s\nf\nv\n");
992 read_link(link, "software-version");
993 switch (log_format) {
994 case AltosLib.AO_LOG_FORMAT_UNKNOWN:
995 case AltosLib.AO_LOG_FORMAT_NONE:
999 read_link(link, "done");