altoslib: Compute speed at entry to each state
[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 call 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                 /* HAS_LOG */
529                 if (flight_log_max != AltosLib.MISSING)
530                         flight_log_max = source.flight_log_max();
531
532                 /* HAS_IGNITE */
533                 if (ignite_mode != AltosLib.MISSING)
534                         ignite_mode = source.ignite_mode();
535
536                 /* AO_PYRO_NUM */
537                 if (npyro != AltosLib.MISSING)
538                         pyros = source.pyros();
539                 if (pyro_firing_time != AltosLib.MISSING)
540                         pyro_firing_time = source.pyro_firing_time();
541
542                 /* HAS_APRS */
543                 if (aprs_interval != AltosLib.MISSING)
544                         aprs_interval = source.aprs_interval();
545                 if (aprs_ssid != AltosLib.MISSING)
546                         aprs_ssid = source.aprs_ssid();
547                 if (aprs_format != AltosLib.MISSING)
548                         aprs_format = source.aprs_format();
549
550                 /* HAS_BEEP */
551                 if (beep != AltosLib.MISSING)
552                         beep = source.beep();
553                 /* HAS_TRACKER */
554                 if (tracker_motion != AltosLib.MISSING)
555                         tracker_motion = source.tracker_motion();
556                 if (tracker_interval != AltosLib.MISSING)
557                         tracker_interval = source.tracker_interval();
558         }
559
560         public void set_values(AltosConfigValues dest) {
561                 dest.set_serial(serial);
562                 dest.set_product(product);
563                 dest.set_version(version);
564                 dest.set_altitude_32(altitude_32);
565                 dest.set_main_deploy(main_deploy);
566                 dest.set_apogee_delay(apogee_delay);
567                 dest.set_apogee_lockout(apogee_lockout);
568                 dest.set_radio_calibration(radio_calibration);
569                 dest.set_radio_frequency(frequency());
570                 dest.set_telemetry_rate(telemetry_rate);
571                 boolean max_enabled = true;
572
573                 if (log_space() == 0)
574                         max_enabled = false;
575
576                 if (log_fixed != AltosLib.MISSING)
577                         max_enabled = false;
578
579                 switch (log_format) {
580                 case AltosLib.AO_LOG_FORMAT_TINY:
581                         max_enabled = false;
582                         break;
583                 default:
584                         if (stored_flight != AltosLib.MISSING)
585                                 max_enabled = false;
586                         break;
587                 }
588
589                 dest.set_flight_log_max_enabled(max_enabled);
590                 dest.set_radio_enable(radio_enable);
591                 dest.set_flight_log_max_limit(log_space() / 1024);
592                 dest.set_flight_log_max(flight_log_max);
593                 dest.set_ignite_mode(ignite_mode);
594                 dest.set_pad_orientation(pad_orientation);
595                 dest.set_callsign(callsign);
596                 if (npyro != AltosLib.MISSING)
597                         dest.set_pyros(pyros);
598                 else
599                         dest.set_pyros(null);
600                 dest.set_pyro_firing_time(pyro_firing_time);
601                 dest.set_aprs_interval(aprs_interval);
602                 dest.set_aprs_ssid(aprs_ssid);
603                 dest.set_aprs_format(aprs_format);
604                 dest.set_beep(beep);
605                 dest.set_tracker_motion(tracker_motion);
606                 dest.set_tracker_interval(tracker_interval);
607         }
608
609         public boolean log_has_state() {
610                 switch (log_format) {
611                 case AltosLib.AO_LOG_FORMAT_TELEGPS:
612                         return false;
613                 }
614                 return true;
615         }
616
617         public void save(AltosLink link, boolean remote) throws InterruptedException, TimeoutException {
618
619                 /* HAS_FLIGHT */
620                 if (main_deploy != AltosLib.MISSING)
621                         link.printf("c m %d\n", main_deploy);
622                 if (apogee_delay != AltosLib.MISSING)
623                         link.printf("c d %d\n", apogee_delay);
624                 if (apogee_lockout != AltosLib.MISSING)
625                         link.printf("c L %d\n", apogee_lockout);
626
627                 /* HAS_RADIO */
628                 if (has_frequency()) {
629                         boolean has_frequency = radio_frequency != AltosLib.MISSING;
630                         boolean has_setting = radio_setting != AltosLib.MISSING;
631                         double frequency = frequency();
632                         link.set_radio_frequency(frequency,
633                                                         has_frequency,
634                                                         has_setting,
635                                                         radio_calibration);
636                         /* When remote, reset the dongle frequency at the same time */
637                         if (remote) {
638                                 link.flush_output();
639                                 link.stop_remote();
640                                 link.set_radio_frequency(frequency);
641                                 link.flush_output();
642                                 link.start_remote();
643                         }
644                 }
645
646                 if (telemetry_rate != AltosLib.MISSING) {
647                         link.printf("c T %d\n", telemetry_rate);
648                         if (remote) {
649                                 link.flush_output();
650                                 link.stop_remote();
651                                 link.set_telemetry_rate(telemetry_rate);
652                                 link.flush_output();
653                                 link.start_remote();
654                         }
655                 }
656
657                 if (callsign != null) {
658                         link.printf("c c %s\n", callsign);
659                         if (remote) {
660                                 link.flush_output();
661                                 link.stop_remote();
662                                 link.set_callsign(callsign);
663                                 link.flush_output();
664                                 link.start_remote();
665                         }
666                 }
667
668                 if (radio_enable != AltosLib.MISSING)
669                         link.printf("c e %d\n", radio_enable);
670
671                 /* HAS_ACCEL */
672                 /* UI doesn't support accel cal */
673                 if (pad_orientation != AltosLib.MISSING)
674                         link.printf("c o %d\n", pad_orientation);
675
676                 /* HAS_LOG */
677                 if (flight_log_max != 0)
678                         link.printf("c l %d\n", flight_log_max);
679
680                 /* HAS_IGNITE */
681                 if (ignite_mode != AltosLib.MISSING)
682                         link.printf("c i %d\n", ignite_mode);
683
684                 /* HAS_AES */
685                 /* UI doesn't support AES key config */
686
687                 /* AO_PYRO_NUM */
688                 if (npyro != AltosLib.MISSING) {
689                         for (int p = 0; p < pyros.length; p++) {
690                                 link.printf("c P %s\n",
691                                                    pyros[p].toString());
692                         }
693                 }
694                 if (pyro_firing_time != AltosLib.MISSING)
695                         link.printf("c I %d\n", (int) (pyro_firing_time * 100.0 + 0.5));
696
697                 /* HAS_APRS */
698                 if (aprs_interval != AltosLib.MISSING)
699                         link.printf("c A %d\n", aprs_interval);
700                 if (aprs_ssid != AltosLib.MISSING)
701                         link.printf("c S %d\n", aprs_ssid);
702                 if (aprs_format != AltosLib.MISSING)
703                         link.printf("c C %d\n", aprs_format);
704
705                 /* HAS_BEEP */
706                 if (beep != AltosLib.MISSING)
707                         link.printf("c b %d\n", beep);
708
709                 /* HAS_TRACKER */
710                 if (tracker_motion != AltosLib.MISSING && tracker_interval != AltosLib.MISSING)
711                         link.printf("c t %d %d\n", tracker_motion, tracker_interval);
712
713                 /* HAS_GYRO */
714                 /* UI doesn't support accel cal */
715
716                 link.printf("c w\n");
717                 link.flush_output();
718         }
719
720         public AltosConfigData(AltosLink link) throws InterruptedException, TimeoutException {
721                 reset();
722                 link.printf("c s\nf\nv\n");
723                 read_link(link, "software-version");
724                 switch (log_format) {
725                 case AltosLib.AO_LOG_FORMAT_UNKNOWN:
726                 case AltosLib.AO_LOG_FORMAT_NONE:
727                         break;
728                 default:
729                         link.printf("l\n");
730                         read_link(link, "done");
731                         break;
732                 }
733         }
734 }