dc036867047cf278432aa99b7b35be0ccb244d6f
[fw/altos] / altoslib / AltosConfigData.java
1 /*
2  * Copyright © 2011 Keith Packard <keithp@keithp.com>
3  *
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.
8  *
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.
13  *
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.
17  */
18
19 package org.altusmetrum.altoslib_12;
20
21 import java.util.*;
22 import java.text.*;
23 import java.util.concurrent.*;
24
25 public class AltosConfigData {
26
27         /* Version information */
28         public String   manufacturer;
29         public String   product;
30         public int      serial;
31         public int      flight;
32         public int      log_format;
33         public int      log_space;
34         public String   version;
35         public int      altitude_32;
36         public int      config_major, config_minor;
37
38         /* Config information */
39         /* HAS_FLIGHT*/
40         public int      main_deploy;
41         public int      apogee_delay;
42         public int      apogee_lockout;
43
44         /* HAS_RADIO */
45         public int      radio_frequency;
46         public String   callsign;
47         public int      radio_enable;
48         public int      radio_calibration;
49         public int      telemetry_rate;
50         /* Old HAS_RADIO values */
51         public int      radio_channel;
52         public int      radio_setting;
53
54         /* HAS_ACCEL */
55         public int      accel_cal_plus, accel_cal_minus;
56         public int      pad_orientation;
57
58         /* HAS_LOG */
59         public int      flight_log_max;
60         public int      log_fixed;
61
62         /* HAS_IGNITE */
63         public int      ignite_mode;
64
65         /* HAS_AES */
66         public String   aes_key;
67
68         /* AO_PYRO_NUM */
69         public AltosPyro[]      pyros;
70         public int              npyro;
71         public int              pyro;
72         public double           pyro_firing_time;
73
74         /* HAS_APRS */
75         public int              aprs_interval;
76         public int              aprs_ssid;
77         public int              aprs_format;
78
79         /* HAS_BEEP */
80         public int              beep;
81
82         /* Storage info replies */
83         public int      storage_size;
84         public int      storage_erase_unit;
85
86         /* Log listing replies */
87         public int      stored_flight;
88
89         /* HAS_TRACKER */
90         public int      tracker_motion;
91         public int      tracker_interval;
92
93         /* HAS_GYRO */
94         public int      accel_zero_along, accel_zero_across, accel_zero_through;
95
96         /* ms5607 data */
97         AltosMs5607     ms5607;
98
99         public AltosMs5607 ms5607() {
100                 if (ms5607 == null)
101                         ms5607 = new AltosMs5607();
102                 return ms5607;
103         }
104
105         public static String get_string(String line, String label) throws  ParseException {
106                 if (line.startsWith(label)) {
107                         String  quoted = line.substring(label.length()).trim();
108
109                         if (quoted.startsWith("\""))
110                                 quoted = quoted.substring(1);
111                         if (quoted.endsWith("\""))
112                                 quoted = quoted.substring(0,quoted.length()-1);
113                         return quoted;
114                 }
115                 throw new ParseException("mismatch", 0);
116         }
117
118         public static int get_int(String line, String label) throws NumberFormatException, ParseException {
119                 if (line.startsWith(label)) {
120                         String tail = line.substring(label.length()).trim();
121                         String[] tokens = tail.split("\\s+");
122                         if (tokens.length > 0)
123                                 return  Integer.parseInt(tokens[0]);
124                 }
125                 throw new ParseException("mismatch", 0);
126         }
127
128         public static int[] get_values(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 > 1) {
133                                 int[]   values = new int[2];
134                                 values[0] = Integer.parseInt(tokens[0]);
135                                 values[1] = Integer.parseInt(tokens[1]);
136                                 return values;
137                         }
138                 }
139                 throw new ParseException("mismatch", 0);
140         }
141
142         public int log_space() {
143                 if (log_space != AltosLib.MISSING)
144                         return log_space;
145
146                 if (storage_size != AltosLib.MISSING) {
147                         int     space = storage_size;
148
149                         if (storage_erase_unit != AltosLib.MISSING && use_flash_for_config())
150                                 space -= storage_erase_unit;
151
152                         if (space != AltosLib.MISSING)
153                                 return space;
154                 }
155                 return 0;
156         }
157
158         public int log_available() {
159                 switch (log_format) {
160                 case AltosLib.AO_LOG_FORMAT_TINY:
161                         if (stored_flight == 0)
162                                 return 1;
163                         return 0;
164                 case AltosLib.AO_LOG_FORMAT_TELEMETRY:
165                 case AltosLib.AO_LOG_FORMAT_TELESCIENCE:
166                         return 1;
167                 default:
168                         if (flight_log_max <= 0)
169                                 return 1;
170                         int     log_max = flight_log_max * 1024;
171                         int     log_space = log_space();
172                         int     log_used;
173
174                         if (stored_flight <= 0)
175                                 log_used = 0;
176                         else
177                                 log_used = stored_flight * log_max;
178                         int     log_avail;
179
180                         if (log_used >= log_space)
181                                 log_avail = 0;
182                         else
183                                 log_avail = (log_space - log_used) / log_max;
184
185                         return log_avail;
186                 }
187         }
188
189         public boolean has_monitor_battery() {
190                 if (product.startsWith("TeleBT"))
191                         return true;
192                 return false;
193         }
194
195         int[] parse_version(String v) {
196                 String[] parts = v.split("\\.");
197                 int r[] = new int[parts.length];
198
199                 for (int i = 0; i < parts.length; i++) {
200                         try {
201                                 r[i] = (int) AltosLib.fromdec(parts[i]);
202                         } catch (NumberFormatException n) {
203                                 r[i] = 0;
204                         }
205                 }
206
207                 return r;
208         }
209
210         public boolean altitude_32() {
211                 return altitude_32 == 1;
212         }
213
214         public int compare_version(String other) {
215                 int[]   me = parse_version(version);
216                 int[]   them = parse_version(other);
217
218                 int     l = Math.min(me.length, them.length);
219
220                 for (int i = 0; i < l; i++) {
221                         int     d = me[i] - them[i];
222                         if (d != 0)
223                                 return d;
224                 }
225                 if (me.length > l)
226                         return 1;
227                 if (them.length > l)
228                         return -1;
229                 return 0;
230         }
231
232         public void reset() {
233                 manufacturer = null;
234                 product = null;
235                 serial = AltosLib.MISSING;
236                 flight = AltosLib.MISSING;
237                 log_format = AltosLib.AO_LOG_FORMAT_UNKNOWN;
238                 log_space = AltosLib.MISSING;
239                 version = "unknown";
240                 config_major = AltosLib.MISSING;
241                 config_minor = AltosLib.MISSING;
242
243                 main_deploy = AltosLib.MISSING;
244                 apogee_delay = AltosLib.MISSING;
245                 apogee_lockout = AltosLib.MISSING;
246
247                 radio_frequency = AltosLib.MISSING;
248                 callsign = null;
249                 radio_enable = AltosLib.MISSING;
250                 radio_calibration = AltosLib.MISSING;
251                 radio_channel = AltosLib.MISSING;
252                 radio_setting = AltosLib.MISSING;
253                 telemetry_rate = AltosLib.MISSING;
254
255                 accel_cal_plus = AltosLib.MISSING;
256                 accel_cal_minus = AltosLib.MISSING;
257                 pad_orientation = AltosLib.MISSING;
258
259                 flight_log_max = AltosLib.MISSING;
260                 log_fixed = AltosLib.MISSING;
261                 ignite_mode = AltosLib.MISSING;
262
263                 aes_key = null;
264
265                 pyro = AltosLib.MISSING;
266                 npyro = AltosLib.MISSING;
267                 pyros = null;
268                 pyro_firing_time = AltosLib.MISSING;
269
270                 aprs_interval = AltosLib.MISSING;
271                 aprs_ssid = AltosLib.MISSING;
272                 aprs_format = AltosLib.MISSING;
273
274                 beep = AltosLib.MISSING;
275
276                 tracker_motion = AltosLib.MISSING;
277                 tracker_interval = AltosLib.MISSING;
278
279                 storage_size = AltosLib.MISSING;
280                 storage_erase_unit = AltosLib.MISSING;
281                 stored_flight = AltosLib.MISSING;
282
283                 accel_zero_along = AltosLib.MISSING;
284                 accel_zero_across = AltosLib.MISSING;
285                 accel_zero_through = AltosLib.MISSING;
286         }
287
288         public void parse_line(String line) {
289
290                 /* Version replies */
291                 try { manufacturer = get_string(line, "manufacturer"); } catch (Exception e) {}
292                 try { product = get_string(line, "product"); } catch (Exception e) {}
293                 try { serial = get_int(line, "serial-number"); } catch (Exception e) {}
294                 try { flight = get_int(line, "current-flight"); } catch (Exception e) {}
295                 try { log_format = get_int(line, "log-format"); } catch (Exception e) {}
296                 try { log_space = get_int(line, "log-space"); } catch (Exception e) {}
297                 try { altitude_32 = get_int(line, "altitude-32"); } catch (Exception e) {}
298                 try { version = get_string(line, "software-version"); } catch (Exception e) {}
299
300                 /* Version also contains MS5607 info, which we ignore here */
301
302                 try { ms5607().reserved = get_int(line, "ms5607 reserved:"); } catch (Exception e) {}
303                 try { ms5607().sens = get_int(line, "ms5607 sens:"); } catch (Exception e) {}
304                 try { ms5607().off = get_int(line, "ms5607 off:"); } catch (Exception e) {}
305                 try { ms5607().tcs = get_int(line, "ms5607 tcs:"); } catch (Exception e) {}
306                 try { ms5607().tco = get_int(line, "ms5607 tco:"); } catch (Exception e) {}
307                 try { ms5607().tref = get_int(line, "ms5607 tref:"); } catch (Exception e) {}
308                 try { ms5607().tempsens = get_int(line, "ms5607 tempsens:"); } catch (Exception e) {}
309                 try { ms5607().crc = get_int(line, "ms5607 crc:"); } catch (Exception e) {}
310
311                 /* Config show replies */
312
313                 try {
314                         if (line.startsWith("Config version")) {
315                                 String[] bits = line.split("\\s+");
316                                 if (bits.length >= 3) {
317                                         String[] cfg = bits[2].split("\\.");
318
319                                         if (cfg.length >= 2) {
320                                                 config_major = Integer.parseInt(cfg[0]);
321                                                 config_minor = Integer.parseInt(cfg[1]);
322                                         }
323                                 }
324                         }
325                 } catch (Exception e) {}
326
327                 /* HAS_FLIGHT */
328                 try { main_deploy = get_int(line, "Main deploy:"); } catch (Exception e) {}
329                 try { apogee_delay = get_int(line, "Apogee delay:"); } catch (Exception e) {}
330                 try { apogee_lockout = get_int(line, "Apogee lockout:"); } catch (Exception e) {}
331
332                 /* HAS_RADIO */
333                 try {
334                         radio_frequency = get_int(line, "Frequency:");
335                         if (radio_frequency < 0)
336                                 radio_frequency = 434550;
337                 } catch (Exception e) {}
338                 try { callsign = get_string(line, "Callsign:"); } catch (Exception e) {}
339                 try { radio_enable = get_int(line, "Radio enable:"); } catch (Exception e) {}
340                 try { radio_calibration = get_int(line, "Radio cal:"); } catch (Exception e) {}
341                 try { telemetry_rate = get_int(line, "Telemetry rate:"); } catch (Exception e) {}
342
343                 /* Old HAS_RADIO values */
344                 try { radio_channel = get_int(line, "Radio channel:"); } catch (Exception e) {}
345                 try { radio_setting = get_int(line, "Radio setting:"); } catch (Exception e) {}
346
347                 /* HAS_ACCEL */
348                 try {
349                         if (line.startsWith("Accel cal")) {
350                                 String[] bits = line.split("\\s+");
351                                 if (bits.length >= 6) {
352                                         accel_cal_plus = Integer.parseInt(bits[3]);
353                                         accel_cal_minus = Integer.parseInt(bits[5]);
354                                 }
355                         }
356                 } catch (Exception e) {}
357                 try { pad_orientation = get_int(line, "Pad orientation:"); } catch (Exception e) {}
358
359                 /* HAS_LOG */
360                 try { flight_log_max = get_int(line, "Max flight log:"); } catch (Exception e) {}
361                 try { log_fixed = get_int(line, "Log fixed:"); } catch (Exception e) {}
362
363                 /* HAS_IGNITE */
364                 try { ignite_mode = get_int(line, "Ignite mode:"); } catch (Exception e) {}
365
366                 /* HAS_AES */
367                 try { aes_key = get_string(line, "AES key:"); } catch (Exception e) {}
368
369                 /* AO_PYRO_NUM */
370                 try {
371                         npyro = get_int(line, "Pyro-count:");
372                         pyros = new AltosPyro[npyro];
373                         pyro = 0;
374                 } catch (Exception e) {}
375                 if (npyro != AltosLib.MISSING) {
376                         try {
377                                 AltosPyro p = new AltosPyro(pyro, line);
378                                 if (pyro < npyro)
379                                         pyros[pyro++] = p;
380                         } catch (Exception e) {}
381                 }
382                 try { pyro_firing_time = get_int(line, "Pyro time:") / 100.0; } catch (Exception e) {}
383
384                 /* HAS_APRS */
385                 try { aprs_interval = get_int(line, "APRS interval:"); } catch (Exception e) {}
386                 try { aprs_ssid = get_int(line, "APRS SSID:"); } catch (Exception e) {}
387                 try { aprs_format = get_int(line, "APRS format:"); } catch (Exception e) {}
388
389                 /* HAS_BEEP */
390                 try { beep = get_int(line, "Beeper setting:"); } catch (Exception e) {}
391
392                 /* HAS_TRACKER */
393                 try {
394                         int[] values = get_values(line, "Tracker setting:");
395                         tracker_motion = values[0];
396                         tracker_interval = values[1];
397                 } catch (Exception e) {}
398
399                 /* Storage info replies */
400                 try { storage_size = get_int(line, "Storage size:"); } catch (Exception e) {}
401                 try { storage_erase_unit = get_int(line, "Storage erase unit:"); } catch (Exception e) {}
402
403                 /* Log listing replies */
404                 try { get_int(line, "flight"); stored_flight++; }  catch (Exception e) {}
405
406                 /* HAS_GYRO */
407                 try {
408                         if (line.startsWith("IMU cal along")) {
409                                 String[] bits = line.split("\\s+");
410                                 if (bits.length >= 8) {
411                                         accel_zero_along = Integer.parseInt(bits[3]);
412                                         accel_zero_across = Integer.parseInt(bits[5]);
413                                         accel_zero_through = Integer.parseInt(bits[7]);
414                                 }
415                         }
416                 } catch (Exception e) {}
417         }
418
419         public AltosConfigData() {
420                 reset();
421         }
422
423         private void read_link(AltosLink link, String finished) throws InterruptedException, TimeoutException {
424                 for (;;) {
425                         String line = link.get_reply();
426                         if (line == null)
427                                 throw new TimeoutException();
428                         if (line.contains("Syntax error"))
429                                 continue;
430                         this.parse_line(line);
431
432                         /* signals the end of the version info */
433                         if (line.startsWith(finished))
434                                 break;
435                 }
436         }
437
438         public boolean has_frequency() {
439                 return radio_frequency != AltosLib.MISSING || radio_setting != AltosLib.MISSING || radio_channel != AltosLib.MISSING;
440         }
441
442         public boolean has_telemetry_rate() {
443                 return telemetry_rate != AltosLib.MISSING;
444         }
445
446         public void set_frequency(double freq) {
447                 int     frequency = radio_frequency;
448                 int     setting = radio_setting;
449
450                 if (frequency != AltosLib.MISSING) {
451                         radio_frequency = (int) Math.floor (freq * 1000 + 0.5);
452                         radio_channel = AltosLib.MISSING;
453                 } else if (setting != AltosLib.MISSING) {
454                         radio_setting =AltosConvert.radio_frequency_to_setting(freq, radio_calibration);
455                         radio_channel = AltosLib.MISSING;
456                 } else {
457                         radio_channel = AltosConvert.radio_frequency_to_channel(freq);
458                 }
459         }
460
461         public double frequency() {
462                 int     channel = radio_channel;
463                 int     setting = radio_setting;
464
465                 if (radio_frequency == AltosLib.MISSING && channel == AltosLib.MISSING && setting == AltosLib.MISSING)
466                         return AltosLib.MISSING;
467
468                 if (channel == AltosLib.MISSING)
469                         channel = 0;
470                 if (setting == AltosLib.MISSING)
471                         setting = 0;
472
473                 return AltosConvert.radio_to_frequency(radio_frequency,
474                                                        setting,
475                                                        radio_calibration,
476                                                        channel);
477         }
478
479         boolean use_flash_for_config() {
480                 if (product.startsWith("TeleMega"))
481                         return false;
482                 if (product.startsWith("TeleMetrum-v2"))
483                         return false;
484                 if (product.startsWith("EasyMega"))
485                         return false;
486                 return true;
487         }
488
489
490         public boolean mma655x_inverted() throws AltosUnknownProduct {
491                 if (product != null) {
492                         if (product.startsWith("EasyMega-v1"))
493                                 return false;
494                         if (product.startsWith("TeleMetrum-v2"))
495                                 return true;
496                         if (product.startsWith("TeleMega-v2"))
497                                 return false;
498                         if (product.startsWith("TeleMega-v1"))
499                                 return false;
500                 }
501                 throw new AltosUnknownProduct(product);
502         }
503
504         public void get_values(AltosConfigValues source) throws AltosConfigDataException {
505
506                 /* HAS_FLIGHT */
507                 if (main_deploy != AltosLib.MISSING)
508                         main_deploy = source.main_deploy();
509                 if (apogee_delay != AltosLib.MISSING)
510                         apogee_delay = source.apogee_delay();
511                 if (apogee_lockout != AltosLib.MISSING)
512                         apogee_lockout = source.apogee_lockout();
513
514                 /* HAS_RADIO */
515                 if (has_frequency())
516                         set_frequency(source.radio_frequency());
517                 if (radio_enable != AltosLib.MISSING)
518                         radio_enable = source.radio_enable();
519                 if (callsign != null)
520                         callsign = source.callsign();
521                 if (telemetry_rate != AltosLib.MISSING)
522                         telemetry_rate = source.telemetry_rate();
523
524                 /* HAS_ACCEL */
525                 if (pad_orientation != AltosLib.MISSING)
526                         pad_orientation = source.pad_orientation();
527
528                 if (accel_cal_plus != AltosLib.MISSING)
529                         accel_cal_plus = source.accel_cal_plus();
530
531                 if (accel_cal_minus != AltosLib.MISSING)
532                         accel_cal_minus = source.accel_cal_minus();
533
534                 /* HAS_LOG */
535                 if (flight_log_max != AltosLib.MISSING)
536                         flight_log_max = source.flight_log_max();
537
538                 /* HAS_IGNITE */
539                 if (ignite_mode != AltosLib.MISSING)
540                         ignite_mode = source.ignite_mode();
541
542                 /* AO_PYRO_NUM */
543                 if (npyro != AltosLib.MISSING)
544                         pyros = source.pyros();
545                 if (pyro_firing_time != AltosLib.MISSING)
546                         pyro_firing_time = source.pyro_firing_time();
547
548                 /* HAS_APRS */
549                 if (aprs_interval != AltosLib.MISSING)
550                         aprs_interval = source.aprs_interval();
551                 if (aprs_ssid != AltosLib.MISSING)
552                         aprs_ssid = source.aprs_ssid();
553                 if (aprs_format != AltosLib.MISSING)
554                         aprs_format = source.aprs_format();
555
556                 /* HAS_BEEP */
557                 if (beep != AltosLib.MISSING)
558                         beep = source.beep();
559                 /* HAS_TRACKER */
560                 if (tracker_motion != AltosLib.MISSING)
561                         tracker_motion = source.tracker_motion();
562                 if (tracker_interval != AltosLib.MISSING)
563                         tracker_interval = source.tracker_interval();
564         }
565
566         public void set_values(AltosConfigValues dest) {
567                 dest.set_serial(serial);
568                 dest.set_product(product);
569                 dest.set_version(version);
570                 dest.set_altitude_32(altitude_32);
571                 dest.set_main_deploy(main_deploy);
572                 dest.set_apogee_delay(apogee_delay);
573                 dest.set_apogee_lockout(apogee_lockout);
574                 dest.set_radio_calibration(radio_calibration);
575                 dest.set_radio_frequency(frequency());
576                 dest.set_telemetry_rate(telemetry_rate);
577                 boolean max_enabled = true;
578
579                 if (log_space() == 0)
580                         max_enabled = false;
581
582                 if (log_fixed != AltosLib.MISSING)
583                         max_enabled = false;
584
585                 switch (log_format) {
586                 case AltosLib.AO_LOG_FORMAT_TINY:
587                         max_enabled = false;
588                         break;
589                 default:
590                         if (stored_flight != AltosLib.MISSING)
591                                 max_enabled = false;
592                         break;
593                 }
594
595                 dest.set_flight_log_max_enabled(max_enabled);
596                 dest.set_radio_enable(radio_enable);
597                 dest.set_flight_log_max_limit(log_space() / 1024);
598                 dest.set_flight_log_max(flight_log_max);
599                 dest.set_ignite_mode(ignite_mode);
600                 dest.set_pad_orientation(pad_orientation);
601                 dest.set_accel_cal(accel_cal_plus, accel_cal_minus);
602                 dest.set_callsign(callsign);
603                 if (npyro != AltosLib.MISSING)
604                         dest.set_pyros(pyros);
605                 else
606                         dest.set_pyros(null);
607                 dest.set_pyro_firing_time(pyro_firing_time);
608                 dest.set_aprs_interval(aprs_interval);
609                 dest.set_aprs_ssid(aprs_ssid);
610                 dest.set_aprs_format(aprs_format);
611                 dest.set_beep(beep);
612                 dest.set_tracker_motion(tracker_motion);
613                 dest.set_tracker_interval(tracker_interval);
614         }
615
616         public boolean log_has_state() {
617                 switch (log_format) {
618                 case AltosLib.AO_LOG_FORMAT_TELEGPS:
619                         return false;
620                 }
621                 return true;
622         }
623
624         public void save(AltosLink link, boolean remote) throws InterruptedException, TimeoutException {
625
626                 /* HAS_FLIGHT */
627                 if (main_deploy != AltosLib.MISSING)
628                         link.printf("c m %d\n", main_deploy);
629                 if (apogee_delay != AltosLib.MISSING)
630                         link.printf("c d %d\n", apogee_delay);
631                 if (apogee_lockout != AltosLib.MISSING)
632                         link.printf("c L %d\n", apogee_lockout);
633
634                 /* HAS_RADIO */
635                 if (has_frequency()) {
636                         boolean has_frequency = radio_frequency != AltosLib.MISSING;
637                         boolean has_setting = radio_setting != AltosLib.MISSING;
638                         double frequency = frequency();
639                         link.set_radio_frequency(frequency,
640                                                         has_frequency,
641                                                         has_setting,
642                                                         radio_calibration);
643                         /* When remote, reset the dongle frequency at the same time */
644                         if (remote) {
645                                 link.flush_output();
646                                 link.stop_remote();
647                                 link.set_radio_frequency(frequency);
648                                 link.flush_output();
649                                 link.start_remote();
650                         }
651                 }
652
653                 if (telemetry_rate != AltosLib.MISSING) {
654                         link.printf("c T %d\n", telemetry_rate);
655                         if (remote) {
656                                 link.flush_output();
657                                 link.stop_remote();
658                                 link.set_telemetry_rate(telemetry_rate);
659                                 link.flush_output();
660                                 link.start_remote();
661                         }
662                 }
663
664                 if (callsign != null) {
665                         link.printf("c c %s\n", callsign);
666                         if (remote) {
667                                 link.flush_output();
668                                 link.stop_remote();
669                                 link.set_callsign(callsign);
670                                 link.flush_output();
671                                 link.start_remote();
672                         }
673                 }
674
675                 if (radio_enable != AltosLib.MISSING)
676                         link.printf("c e %d\n", radio_enable);
677
678                 /* HAS_ACCEL */
679                 if (pad_orientation != AltosLib.MISSING)
680                         link.printf("c o %d\n", pad_orientation);
681                 if (accel_cal_plus != AltosLib.MISSING && accel_cal_minus != AltosLib.MISSING)
682                         link.printf("c a %d %d\n", accel_cal_plus, accel_cal_minus);
683
684                 /* HAS_LOG */
685                 if (flight_log_max != 0)
686                         link.printf("c l %d\n", flight_log_max);
687
688                 /* HAS_IGNITE */
689                 if (ignite_mode != AltosLib.MISSING)
690                         link.printf("c i %d\n", ignite_mode);
691
692                 /* HAS_AES */
693                 /* UI doesn't support AES key config */
694
695                 /* AO_PYRO_NUM */
696                 if (npyro != AltosLib.MISSING) {
697                         for (int p = 0; p < pyros.length; p++) {
698                                 link.printf("c P %s\n",
699                                                    pyros[p].toString());
700                         }
701                 }
702                 if (pyro_firing_time != AltosLib.MISSING)
703                         link.printf("c I %d\n", (int) (pyro_firing_time * 100.0 + 0.5));
704
705                 /* HAS_APRS */
706                 if (aprs_interval != AltosLib.MISSING)
707                         link.printf("c A %d\n", aprs_interval);
708                 if (aprs_ssid != AltosLib.MISSING)
709                         link.printf("c S %d\n", aprs_ssid);
710                 if (aprs_format != AltosLib.MISSING)
711                         link.printf("c C %d\n", aprs_format);
712
713                 /* HAS_BEEP */
714                 if (beep != AltosLib.MISSING)
715                         link.printf("c b %d\n", beep);
716
717                 /* HAS_TRACKER */
718                 if (tracker_motion != AltosLib.MISSING && tracker_interval != AltosLib.MISSING)
719                         link.printf("c t %d %d\n", tracker_motion, tracker_interval);
720
721                 /* HAS_GYRO */
722                 /* UI doesn't support accel cal */
723
724                 link.printf("c w\n");
725                 link.flush_output();
726         }
727
728         public AltosConfigData(AltosLink link) throws InterruptedException, TimeoutException {
729                 reset();
730                 link.printf("c s\nf\nv\n");
731                 read_link(link, "software-version");
732                 switch (log_format) {
733                 case AltosLib.AO_LOG_FORMAT_UNKNOWN:
734                 case AltosLib.AO_LOG_FORMAT_NONE:
735                         break;
736                 default:
737                         link.printf("l\n");
738                         read_link(link, "done");
739                         break;
740                 }
741         }
742 }