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 public boolean has_radio() {
249 return product.startsWith("Tele");
252 int[] parse_version(String v) {
253 String[] parts = v.split("\\.");
254 int r[] = new int[parts.length];
256 for (int i = 0; i < parts.length; i++) {
258 r[i] = (int) AltosLib.fromdec(parts[i]);
259 } catch (NumberFormatException n) {
267 public boolean altitude_32() {
268 return altitude_32 == 1;
271 public int compare_version(String other) {
272 int[] me = parse_version(version);
273 int[] them = parse_version(other);
275 int l = Math.min(me.length, them.length);
277 for (int i = 0; i < l; i++) {
278 int d = me[i] - them[i];
289 public void reset() {
292 serial = AltosLib.MISSING;
293 flight = AltosLib.MISSING;
294 log_format = AltosLib.AO_LOG_FORMAT_UNKNOWN;
295 log_space = AltosLib.MISSING;
297 config_major = AltosLib.MISSING;
298 config_minor = AltosLib.MISSING;
300 main_deploy = AltosLib.MISSING;
301 apogee_delay = AltosLib.MISSING;
302 apogee_lockout = AltosLib.MISSING;
304 radio_frequency = AltosLib.MISSING;
306 radio_enable = AltosLib.MISSING;
307 radio_calibration = AltosLib.MISSING;
308 radio_channel = AltosLib.MISSING;
309 radio_setting = AltosLib.MISSING;
310 telemetry_rate = AltosLib.MISSING;
312 accel_cal_plus_cooked = AltosLib.MISSING;
313 accel_cal_minus_cooked = AltosLib.MISSING;
314 accel_cal_plus = AltosLib.MISSING;
315 accel_cal_minus = AltosLib.MISSING;
316 pad_orientation = AltosLib.MISSING;
317 accel_cal_adjusted = false;
319 flight_log_max = AltosLib.MISSING;
320 log_fixed = AltosLib.MISSING;
321 ignite_mode = AltosLib.MISSING;
325 pyro = AltosLib.MISSING;
326 npyro = AltosLib.MISSING;
328 pyro_firing_time = AltosLib.MISSING;
330 aprs_interval = AltosLib.MISSING;
331 aprs_ssid = AltosLib.MISSING;
332 aprs_format = AltosLib.MISSING;
333 aprs_offset = AltosLib.MISSING;
335 beep = AltosLib.MISSING;
337 radio_10mw = AltosLib.MISSING;
339 report_feet = AltosLib.MISSING;
341 gps_receiver = AltosLib.MISSING;
343 tracker_motion = AltosLib.MISSING;
344 tracker_interval = AltosLib.MISSING;
346 storage_size = AltosLib.MISSING;
347 storage_erase_unit = AltosLib.MISSING;
351 accel_zero_along = AltosLib.MISSING;
352 accel_zero_across = AltosLib.MISSING;
353 accel_zero_through = AltosLib.MISSING;
356 /* Return + accel calibration relative to a specific pad orientation */
357 public int accel_cal_plus(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_plus_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_minus_cooked);
372 return AltosLib.MISSING;
376 /* Return - accel calibration relative to a specific pad orientation */
377 public int accel_cal_minus(int pad_orientation) {
379 if (!accel_cal_adjusted)
380 return AltosLib.MISSING;
382 switch (pad_orientation) {
383 case AltosLib.AO_PAD_ORIENTATION_ANTENNA_UP:
384 case AltosLib.AO_PAD_ORIENTATION_WORDS_UPRIGHT:
385 case AltosLib.AO_PAD_ORIENTATION_BIG_PARTS_UP:
386 return accel_cal_minus_cooked;
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 return invert_accel_value(accel_cal_plus_cooked);
392 return AltosLib.MISSING;
396 /* Once we have all of the values from the config data, compute the
397 * accel cal values relative to Antenna Up orientation.
399 private void adjust_accel_cal() {
400 if (!accel_cal_adjusted &&
402 pad_orientation != AltosLib.MISSING &&
403 accel_cal_plus != AltosLib.MISSING &&
404 accel_cal_minus != AltosLib.MISSING)
406 switch (pad_orientation) {
407 case AltosLib.AO_PAD_ORIENTATION_ANTENNA_UP:
408 case AltosLib.AO_PAD_ORIENTATION_WORDS_UPRIGHT:
409 case AltosLib.AO_PAD_ORIENTATION_BIG_PARTS_UP:
410 accel_cal_plus_cooked = accel_cal_plus;
411 accel_cal_minus_cooked = accel_cal_minus;
412 accel_cal_adjusted = true;
414 case AltosLib.AO_PAD_ORIENTATION_ANTENNA_DOWN:
415 case AltosLib.AO_PAD_ORIENTATION_WORDS_UPSIDEDOWN:
416 case AltosLib.AO_PAD_ORIENTATION_BIG_PARTS_DOWN:
417 accel_cal_plus_cooked = invert_accel_value(accel_cal_minus);
418 accel_cal_minus_cooked = invert_accel_value(accel_cal_plus);
419 accel_cal_adjusted = true;
427 public void parse_line(String line) {
429 /* Version replies */
430 try { manufacturer = get_string(line, "manufacturer"); } catch (Exception e) {}
431 try { product = get_string(line, "product"); } catch (Exception e) {}
432 try { serial = get_int(line, "serial-number"); } catch (Exception e) {}
433 try { flight = get_int(line, "current-flight"); } catch (Exception e) {}
434 try { log_format = get_int(line, "log-format"); } catch (Exception e) {}
435 try { log_space = get_int(line, "log-space"); } catch (Exception e) {}
436 try { altitude_32 = get_int(line, "altitude-32"); } catch (Exception e) {}
437 try { version = get_string(line, "software-version"); } catch (Exception e) {}
439 /* Version also contains MS5607 info, which we ignore here */
441 try { ms5607().reserved = get_int(line, "ms5607 reserved:"); } catch (Exception e) {}
442 try { ms5607().sens = get_int(line, "ms5607 sens:"); } catch (Exception e) {}
443 try { ms5607().off = get_int(line, "ms5607 off:"); } catch (Exception e) {}
444 try { ms5607().tcs = get_int(line, "ms5607 tcs:"); } catch (Exception e) {}
445 try { ms5607().tco = get_int(line, "ms5607 tco:"); } catch (Exception e) {}
446 try { ms5607().tref = get_int(line, "ms5607 tref:"); } catch (Exception e) {}
447 try { ms5607().tempsens = get_int(line, "ms5607 tempsens:"); } catch (Exception e) {}
448 try { ms5607().crc = get_int(line, "ms5607 crc:"); } catch (Exception e) {}
450 /* Config show replies */
453 if (line.startsWith("Config version")) {
454 String[] bits = line.split("\\s+");
455 if (bits.length >= 3) {
456 String[] cfg = bits[2].split("\\.");
458 if (cfg.length >= 2) {
459 config_major = Integer.parseInt(cfg[0]);
460 config_minor = Integer.parseInt(cfg[1]);
464 } catch (Exception e) {}
467 try { main_deploy = get_int(line, "Main deploy:"); } catch (Exception e) {}
468 try { apogee_delay = get_int(line, "Apogee delay:"); } catch (Exception e) {}
469 try { apogee_lockout = get_int(line, "Apogee lockout:"); } catch (Exception e) {}
473 radio_frequency = get_int(line, "Frequency:");
474 if (radio_frequency < 0)
475 radio_frequency = 434550;
476 } catch (Exception e) {}
477 try { callsign = get_string(line, "Callsign:"); } catch (Exception e) {}
478 try { radio_enable = get_int(line, "Radio enable:"); } catch (Exception e) {}
479 try { radio_calibration = get_int(line, "Radio cal:"); } catch (Exception e) {}
480 try { telemetry_rate = get_int(line, "Telemetry rate:"); } catch (Exception e) {}
482 /* Old HAS_RADIO values */
483 try { radio_channel = get_int(line, "Radio channel:"); } catch (Exception e) {}
484 try { radio_setting = get_int(line, "Radio setting:"); } catch (Exception e) {}
488 if (line.startsWith("Accel cal")) {
489 String[] bits = line.split("\\s+");
490 if (bits.length >= 6) {
491 accel_cal_plus = Integer.parseInt(bits[3]);
492 accel_cal_minus = Integer.parseInt(bits[5]);
493 accel_cal_adjusted = false;
496 } catch (Exception e) {}
497 try { pad_orientation = get_int(line, "Pad orientation:"); } catch (Exception e) {}
500 try { flight_log_max = get_int(line, "Max flight log:"); } catch (Exception e) {}
501 try { log_fixed = get_int(line, "Log fixed:"); } catch (Exception e) {}
504 try { ignite_mode = get_int(line, "Ignite mode:"); } catch (Exception e) {}
507 try { aes_key = get_string(line, "AES key:"); } catch (Exception e) {}
511 npyro = get_int(line, "Pyro-count:");
512 pyros = new AltosPyro[npyro];
514 } catch (Exception e) {}
515 if (npyro != AltosLib.MISSING) {
517 AltosPyro p = new AltosPyro(pyro, line);
520 } catch (Exception e) {}
522 try { pyro_firing_time = get_int(line, "Pyro time:") / 100.0; } catch (Exception e) {}
525 try { aprs_interval = get_int(line, "APRS interval:"); } catch (Exception e) {}
526 try { aprs_ssid = get_int(line, "APRS SSID:"); } catch (Exception e) {}
527 try { aprs_format = get_int(line, "APRS format:"); } catch (Exception e) {}
528 try { aprs_offset = get_int(line, "APRS offset:"); } catch (Exception e) {}
531 try { beep = get_int(line, "Beeper setting:"); } catch (Exception e) {}
534 try { radio_10mw = get_int(line, "Radio 10mw limit:"); } catch (Exception e) {}
536 try { report_feet = get_int(line, "Report in feet:"); } catch (Exception e) {}
538 try { gps_receiver = get_int(line, "GPS receiver:"); } catch (Exception e) {}
542 int[] values = get_values(line, "Tracker setting:");
543 tracker_motion = values[0];
544 tracker_interval = values[1];
545 } catch (Exception e) {}
547 /* Storage info replies */
548 try { storage_size = get_int(line, "Storage size:"); } catch (Exception e) {}
549 try { storage_erase_unit = get_int(line, "Storage erase unit:"); } catch (Exception e) {}
551 /* Log listing replies */
553 int flight = get_int(line, "flight");
554 String[] tokens = line.split("\\s+");
555 if (tokens.length >= 6) {
556 int start = -1, end = -1;
558 if (tokens[2].equals("start"))
559 start = AltosParse.parse_hex(tokens[3]);
560 if (tokens[4].equals("end"))
561 end = AltosParse.parse_hex(tokens[5]);
562 if (flight != 0 && start >= 0 && end > 0) {
567 len = flights.length;
568 AltosEepromFlight [] new_flights = new AltosEepromFlight[len + 1];
569 for (int i = 0; i < len; i++)
570 new_flights[i] = flights[i];
571 new_flights[len] = new AltosEepromFlight(flight, start, end);
572 flights = new_flights;
573 stored_flight = flights.length;
575 } catch (ParseException pe) { System.out.printf("Parse error %s\n", pe.toString()); }
577 } catch (Exception e) {}
581 if (line.startsWith("IMU cal along")) {
582 String[] bits = line.split("\\s+");
583 if (bits.length >= 8) {
584 accel_zero_along = Integer.parseInt(bits[3]);
585 accel_zero_across = Integer.parseInt(bits[5]);
586 accel_zero_through = Integer.parseInt(bits[7]);
589 } catch (Exception e) {}
592 public AltosConfigData() {
596 private void read_link(AltosLink link, String finished) throws InterruptedException, TimeoutException {
598 String line = link.get_reply();
600 throw new TimeoutException();
601 if (line.contains("Syntax error"))
603 this.parse_line(line);
605 /* signals the end of the version info */
606 if (line.startsWith(finished))
611 public boolean has_frequency() {
612 return radio_frequency != AltosLib.MISSING || radio_setting != AltosLib.MISSING || radio_channel != AltosLib.MISSING;
615 public boolean has_telemetry_rate() {
616 return telemetry_rate != AltosLib.MISSING;
619 public void set_frequency(double freq) {
620 int frequency = radio_frequency;
621 int setting = radio_setting;
623 if (frequency != AltosLib.MISSING) {
624 radio_frequency = (int) Math.floor (freq * 1000 + 0.5);
625 radio_channel = AltosLib.MISSING;
626 } else if (setting != AltosLib.MISSING) {
627 radio_setting =AltosConvert.radio_frequency_to_setting(freq, radio_calibration);
628 radio_channel = AltosLib.MISSING;
630 radio_channel = AltosConvert.radio_frequency_to_channel(freq);
634 public double frequency() {
635 int channel = radio_channel;
636 int setting = radio_setting;
638 if (radio_frequency == AltosLib.MISSING && channel == AltosLib.MISSING && setting == AltosLib.MISSING)
639 return AltosLib.MISSING;
641 if (channel == AltosLib.MISSING)
643 if (setting == AltosLib.MISSING)
646 return AltosConvert.radio_to_frequency(radio_frequency,
652 boolean use_flash_for_config() {
653 if (product.startsWith("TeleMega"))
655 if (product.startsWith("TeleMetrum-v2"))
657 if (product.startsWith("TeleMetrum-v3"))
659 if (product.startsWith("TeleMetrum-v4"))
661 if (product.startsWith("EasyMega"))
667 public boolean mma655x_inverted() throws AltosUnknownProduct {
668 if (product != null) {
669 if (product.startsWith("EasyMega-v1"))
671 if (product.startsWith("TeleMetrum-v2"))
673 if (product.startsWith("TeleMega-v2"))
675 if (product.startsWith("TeleMega-v1"))
678 throw new AltosUnknownProduct(product);
681 public boolean adxl375_inverted() throws AltosUnknownProduct {
682 if (product != null) {
683 if (product.startsWith("EasyMega-v2"))
685 if (product.startsWith("TeleMetrum-v3"))
687 if (product.startsWith("TeleMetrum-v4"))
689 if (product.startsWith("TeleMega-v4"))
691 if (product.startsWith("TeleMega-v5"))
693 if (product.startsWith("TeleMega-v6"))
695 if (product.startsWith("EasyMotor-v2"))
697 if (product.startsWith("EasyMotor-v3"))
700 throw new AltosUnknownProduct(product);
703 public int adxl375_axis() throws AltosUnknownProduct {
704 if (product != null) {
705 if (product.startsWith("EasyMega-v2"))
706 return AltosAdxl375.X_AXIS;
707 if (product.startsWith("TeleMetrum-v3"))
708 return AltosAdxl375.X_AXIS;
709 if (product.startsWith("TeleMetrum-v4"))
710 return AltosAdxl375.X_AXIS;
711 if (product.startsWith("TeleMega-v4"))
712 return AltosAdxl375.X_AXIS;
713 if (product.startsWith("TeleMega-v5"))
714 return AltosAdxl375.X_AXIS;
715 if (product.startsWith("TeleMega-v6"))
716 return AltosAdxl375.X_AXIS;
717 if (product.startsWith("EasyMotor-v2"))
718 return AltosAdxl375.X_AXIS;
719 if (product.startsWith("EasyMotor-v3"))
720 return AltosAdxl375.X_AXIS;
723 throw new AltosUnknownProduct(product);
726 public void get_values(AltosConfigValues source) throws AltosConfigDataException {
729 if (main_deploy != AltosLib.MISSING)
730 main_deploy = source.main_deploy();
731 if (apogee_delay != AltosLib.MISSING)
732 apogee_delay = source.apogee_delay();
733 if (apogee_lockout != AltosLib.MISSING)
734 apogee_lockout = source.apogee_lockout();
738 set_frequency(source.radio_frequency());
739 if (radio_enable != AltosLib.MISSING)
740 radio_enable = source.radio_enable();
741 if (callsign != null)
742 callsign = source.callsign();
743 if (telemetry_rate != AltosLib.MISSING)
744 telemetry_rate = source.telemetry_rate();
747 if (pad_orientation != AltosLib.MISSING)
748 pad_orientation = source.pad_orientation();
750 if (accel_cal_plus_cooked != AltosLib.MISSING)
751 accel_cal_plus_cooked = source.accel_cal_plus();
753 if (accel_cal_minus_cooked != AltosLib.MISSING)
754 accel_cal_minus_cooked = source.accel_cal_minus();
757 if (flight_log_max != AltosLib.MISSING)
758 flight_log_max = source.flight_log_max();
761 if (ignite_mode != AltosLib.MISSING)
762 ignite_mode = source.ignite_mode();
765 if (npyro != AltosLib.MISSING)
766 pyros = source.pyros();
767 if (pyro_firing_time != AltosLib.MISSING)
768 pyro_firing_time = source.pyro_firing_time();
771 if (aprs_interval != AltosLib.MISSING)
772 aprs_interval = source.aprs_interval();
773 if (aprs_ssid != AltosLib.MISSING)
774 aprs_ssid = source.aprs_ssid();
775 if (aprs_format != AltosLib.MISSING)
776 aprs_format = source.aprs_format();
777 if (aprs_offset != AltosLib.MISSING)
778 aprs_offset = source.aprs_offset();
781 if (beep != AltosLib.MISSING)
782 beep = source.beep();
785 if (radio_10mw != AltosLib.MISSING)
786 radio_10mw = source.radio_10mw();
788 if (report_feet != AltosLib.MISSING)
789 report_feet = source.report_feet();
791 if (gps_receiver != AltosLib.MISSING)
792 gps_receiver = source.gps_receiver();
795 if (tracker_motion != AltosLib.MISSING)
796 tracker_motion = source.tracker_motion();
797 if (tracker_interval != AltosLib.MISSING)
798 tracker_interval = source.tracker_interval();
801 public void set_values(AltosConfigValues dest) {
802 dest.set_serial(serial);
803 dest.set_product(product);
804 dest.set_version(version);
805 dest.set_altitude_32(altitude_32);
806 dest.set_main_deploy(main_deploy);
807 dest.set_apogee_delay(apogee_delay);
808 dest.set_apogee_lockout(apogee_lockout);
809 dest.set_radio_calibration(radio_calibration);
810 dest.set_radio_frequency(frequency());
811 dest.set_telemetry_rate(telemetry_rate);
812 boolean max_enabled = true;
814 if (log_space() == 0)
817 if (log_fixed != AltosLib.MISSING)
820 switch (log_format) {
821 case AltosLib.AO_LOG_FORMAT_TINY:
830 dest.set_flight_log_max_enabled(max_enabled);
831 dest.set_radio_enable(radio_enable);
832 dest.set_flight_log_max_limit(log_space() >> 10, storage_erase_unit >> 10);
833 dest.set_flight_log_max(flight_log_max);
834 dest.set_ignite_mode(ignite_mode);
835 dest.set_pad_orientation(pad_orientation);
836 dest.set_accel_cal(accel_cal_plus(AltosLib.AO_PAD_ORIENTATION_ANTENNA_UP),
837 accel_cal_minus(AltosLib.AO_PAD_ORIENTATION_ANTENNA_UP));
838 dest.set_callsign(callsign);
839 if (npyro != AltosLib.MISSING)
840 dest.set_pyros(pyros);
842 dest.set_pyros(null);
843 dest.set_pyro_firing_time(pyro_firing_time);
844 dest.set_aprs_interval(aprs_interval);
845 dest.set_aprs_ssid(aprs_ssid);
846 dest.set_aprs_format(aprs_format);
847 dest.set_aprs_offset(aprs_offset);
849 dest.set_radio_10mw(radio_10mw);
850 dest.set_report_feet(report_feet);
851 dest.set_gps_receiver(gps_receiver);
852 dest.set_tracker_motion(tracker_motion);
853 dest.set_tracker_interval(tracker_interval);
856 public boolean log_has_state() {
857 switch (log_format) {
858 case AltosLib.AO_LOG_FORMAT_TELEGPS:
864 public void save(AltosLink link, boolean remote) throws InterruptedException, TimeoutException {
867 if (main_deploy != AltosLib.MISSING)
868 link.printf("c m %d\n", main_deploy);
869 if (apogee_delay != AltosLib.MISSING)
870 link.printf("c d %d\n", apogee_delay);
871 if (apogee_lockout != AltosLib.MISSING)
872 link.printf("c L %d\n", apogee_lockout);
875 if (has_frequency()) {
876 boolean has_frequency = radio_frequency != AltosLib.MISSING;
877 boolean has_setting = radio_setting != AltosLib.MISSING;
878 double frequency = frequency();
879 link.set_radio_frequency(frequency,
883 /* When remote, reset the dongle frequency at the same time */
884 if (remote && frequency != link.frequency) {
886 link.set_radio_frequency(frequency);
891 if (telemetry_rate != AltosLib.MISSING) {
892 link.printf("c T %d\n", telemetry_rate);
893 if (remote && telemetry_rate != link.telemetry_rate) {
895 link.set_telemetry_rate(telemetry_rate);
900 if (callsign != null) {
901 link.printf("c c %s\n", callsign);
902 if (remote && !callsign.equals(link.callsign)) {
903 System.out.printf("changing link callsign from %s to %s\n", link.callsign, callsign);
905 link.set_callsign(callsign);
910 if (radio_enable != AltosLib.MISSING)
911 link.printf("c e %d\n", radio_enable);
914 /* set orientation first so that we know how to set the accel cal */
915 if (pad_orientation != AltosLib.MISSING)
916 link.printf("c o %d\n", pad_orientation);
917 int plus = accel_cal_plus(pad_orientation);
918 int minus = accel_cal_minus(pad_orientation);
919 if (plus != AltosLib.MISSING && minus != AltosLib.MISSING) {
923 minus = 65536 + minus;
924 if (accel_zero_along != AltosLib.MISSING &&
925 accel_zero_across != AltosLib.MISSING &&
926 accel_zero_through != AltosLib.MISSING)
927 link.printf("c a %d %d %d %d %d\n",
933 link.printf("c a %d %d\n", plus, minus);
937 if (flight_log_max != 0 && flight_log_max != AltosLib.MISSING)
938 link.printf("c l %d\n", flight_log_max);
941 if (ignite_mode != AltosLib.MISSING)
942 link.printf("c i %d\n", ignite_mode);
945 /* UI doesn't support AES key config */
948 if (npyro != AltosLib.MISSING) {
949 for (int p = 0; p < pyros.length; p++) {
950 link.printf("c P %s\n",
951 pyros[p].toString());
954 if (pyro_firing_time != AltosLib.MISSING)
955 link.printf("c I %d\n", (int) (pyro_firing_time * 100.0 + 0.5));
958 if (aprs_interval != AltosLib.MISSING)
959 link.printf("c A %d\n", aprs_interval);
960 if (aprs_ssid != AltosLib.MISSING)
961 link.printf("c S %d\n", aprs_ssid);
962 if (aprs_format != AltosLib.MISSING)
963 link.printf("c C %d\n", aprs_format);
964 if (aprs_offset != AltosLib.MISSING)
965 link.printf("c O %d\n", aprs_offset);
968 if (beep != AltosLib.MISSING)
969 link.printf("c b %d\n", beep);
972 if (radio_10mw != AltosLib.MISSING)
973 link.printf("c p %d\n", radio_10mw);
975 if (report_feet != AltosLib.MISSING)
976 link.printf("c u %d\n", report_feet);
979 if (gps_receiver != AltosLib.MISSING)
980 link.printf("c g %d\n", gps_receiver);
983 if (tracker_motion != AltosLib.MISSING && tracker_interval != AltosLib.MISSING)
984 link.printf("c t %d %d\n", tracker_motion, tracker_interval);
987 /* UI doesn't support accel cal */
989 link.printf("c w\n");
990 read_link(link, "Saved");
993 public AltosConfigData(AltosLink link) throws InterruptedException, TimeoutException {
995 link.printf("c s\nf\nv\n");
996 read_link(link, "software-version");
997 switch (log_format) {
998 case AltosLib.AO_LOG_FORMAT_UNKNOWN:
999 case AltosLib.AO_LOG_FORMAT_NONE:
1003 read_link(link, "done");