cb46b6c6349924e2db04109005a278eb9cd66b8d
[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_11;
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 > 0)
144                         return log_space;
145
146                 if (storage_size > 0) {
147                         int     space = storage_size;
148
149                         if (storage_erase_unit > 0 && use_flash_for_config())
150                                 space -= storage_erase_unit;
151
152                         if (space > 0)
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 = 0;
266                 npyro = 0;
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                                                 System.out.printf("major %s minor %s\n", cfg[0], cfg[1]);
321                                                 config_major = Integer.parseInt(cfg[0]);
322                                                 config_minor = Integer.parseInt(cfg[1]);
323                                         }
324                                 }
325                         }
326                 } catch (Exception e) {}
327
328                 /* HAS_FLIGHT */
329                 try { main_deploy = get_int(line, "Main deploy:"); } catch (Exception e) {}
330                 try { apogee_delay = get_int(line, "Apogee delay:"); } catch (Exception e) {}
331                 try { apogee_lockout = get_int(line, "Apogee lockout:"); } catch (Exception e) {}
332
333                 /* HAS_RADIO */
334                 try {
335                         radio_frequency = get_int(line, "Frequency:");
336                         if (radio_frequency < 0)
337                                 radio_frequency = 434550;
338                 } catch (Exception e) {}
339                 try { callsign = get_string(line, "Callsign:"); } catch (Exception e) {}
340                 try { radio_enable = get_int(line, "Radio enable:"); } catch (Exception e) {}
341                 try { radio_calibration = get_int(line, "Radio cal:"); } catch (Exception e) {}
342                 try { telemetry_rate = get_int(line, "Telemetry rate:"); } catch (Exception e) {}
343
344                 /* Old HAS_RADIO values */
345                 try { radio_channel = get_int(line, "Radio channel:"); } catch (Exception e) {}
346                 try { radio_setting = get_int(line, "Radio setting:"); } catch (Exception e) {}
347
348                 /* HAS_ACCEL */
349                 try {
350                         if (line.startsWith("Accel cal")) {
351                                 String[] bits = line.split("\\s+");
352                                 if (bits.length >= 6) {
353                                         accel_cal_plus = Integer.parseInt(bits[3]);
354                                         accel_cal_minus = Integer.parseInt(bits[5]);
355                                 }
356                         }
357                 } catch (Exception e) {}
358                 try { pad_orientation = get_int(line, "Pad orientation:"); } catch (Exception e) {}
359
360                 /* HAS_LOG */
361                 try { flight_log_max = get_int(line, "Max flight log:"); } catch (Exception e) {}
362                 try { log_fixed = get_int(line, "Log fixed:"); } catch (Exception e) {}
363
364                 /* HAS_IGNITE */
365                 try { ignite_mode = get_int(line, "Ignite mode:"); } catch (Exception e) {}
366
367                 /* HAS_AES */
368                 try { aes_key = get_string(line, "AES key:"); } catch (Exception e) {}
369
370                 /* AO_PYRO_NUM */
371                 try {
372                         npyro = get_int(line, "Pyro-count:");
373                         pyros = new AltosPyro[npyro];
374                         pyro = 0;
375                 } catch (Exception e) {}
376                 if (npyro > 0) {
377                         try {
378                                 AltosPyro p = new AltosPyro(pyro, line);
379                                 if (pyro < npyro)
380                                         pyros[pyro++] = p;
381                         } catch (Exception e) {}
382                 }
383                 try { pyro_firing_time = get_int(line, "Pyro time:") / 100.0; } catch (Exception e) {}
384
385                 /* HAS_APRS */
386                 try { aprs_interval = get_int(line, "APRS interval:"); } catch (Exception e) {}
387                 try { aprs_ssid = get_int(line, "APRS SSID:"); } catch (Exception e) {}
388                 try { aprs_format = get_int(line, "APRS format:"); } catch (Exception e) {}
389
390                 /* HAS_BEEP */
391                 try { beep = get_int(line, "Beeper setting:"); } catch (Exception e) {}
392
393                 /* HAS_TRACKER */
394                 try {
395                         int[] values = get_values(line, "Tracker setting:");
396                         tracker_motion = values[0];
397                         tracker_interval = values[1];
398                 } catch (Exception e) {}
399
400                 /* Storage info replies */
401                 try { storage_size = get_int(line, "Storage size:"); } catch (Exception e) {}
402                 try { storage_erase_unit = get_int(line, "Storage erase unit:"); } catch (Exception e) {}
403
404                 /* Log listing replies */
405                 try { get_int(line, "flight"); stored_flight++; }  catch (Exception e) {}
406
407                 /* HAS_GYRO */
408                 try {
409                         if (line.startsWith("IMU call along")) {
410                                 String[] bits = line.split("\\s+");
411                                 if (bits.length >= 8) {
412                                         accel_zero_along = Integer.parseInt(bits[3]);
413                                         accel_zero_across = Integer.parseInt(bits[5]);
414                                         accel_zero_through = Integer.parseInt(bits[7]);
415                                 }
416                         }
417                 } catch (Exception e) {}
418         }
419
420         public AltosConfigData() {
421                 reset();
422         }
423
424         private void read_link(AltosLink link, String finished) throws InterruptedException, TimeoutException {
425                 for (;;) {
426                         String line = link.get_reply();
427                         if (line == null)
428                                 throw new TimeoutException();
429                         if (line.contains("Syntax error"))
430                                 continue;
431                         this.parse_line(line);
432
433                         /* signals the end of the version info */
434                         if (line.startsWith(finished))
435                                 break;
436                 }
437         }
438
439         public boolean has_frequency() {
440                 return radio_frequency >= 0 || radio_setting >= 0 || radio_channel >= 0;
441         }
442
443         public boolean has_telemetry_rate() {
444                 return telemetry_rate >= 0;
445         }
446
447         public void set_frequency(double freq) {
448                 int     frequency = radio_frequency;
449                 int     setting = radio_setting;
450
451                 if (frequency > 0) {
452                         radio_frequency = (int) Math.floor (freq * 1000 + 0.5);
453                         radio_channel = AltosLib.MISSING;
454                 } else if (setting > 0) {
455                         radio_setting =AltosConvert.radio_frequency_to_setting(freq,
456                                                                                     radio_calibration);
457                         radio_channel = AltosLib.MISSING;
458                 } else {
459                         radio_channel = AltosConvert.radio_frequency_to_channel(freq);
460                 }
461         }
462
463         public double frequency() {
464                 int     channel = radio_channel;
465                 int     setting = radio_setting;
466
467                 if (radio_frequency < 0 && channel < 0 && setting < 0)
468                         return AltosLib.MISSING;
469
470                 if (channel < 0)
471                         channel = 0;
472                 if (setting < 0)
473                         setting = 0;
474
475                 return AltosConvert.radio_to_frequency(radio_frequency,
476                                                        setting,
477                                                        radio_calibration,
478                                                        channel);
479         }
480
481         boolean use_flash_for_config() {
482                 if (product.startsWith("TeleMega"))
483                         return false;
484                 if (product.startsWith("TeleMetrum-v2"))
485                         return false;
486                 if (product.startsWith("EasyMega"))
487                         return false;
488                 return true;
489         }
490
491
492         public boolean mma655x_inverted() throws AltosUnknownProduct {
493                 if (product.startsWith("EasyMega-v1"))
494                         return false;
495                 if (product.startsWith("TeleMetrum-v2"))
496                         return true;
497                 if (product.startsWith("TeleMega-v2"))
498                         return false;
499                 if (product.startsWith("TeleMega-v1"))
500                         return false;
501                 throw new AltosUnknownProduct(product);
502         }
503
504         public void get_values(AltosConfigValues source) throws AltosConfigDataException {
505
506                 /* HAS_FLIGHT */
507                 if (main_deploy >= 0)
508                         main_deploy = source.main_deploy();
509                 if (apogee_delay >= 0)
510                         apogee_delay = source.apogee_delay();
511                 if (apogee_lockout >= 0)
512                         apogee_lockout = source.apogee_lockout();
513
514                 /* HAS_RADIO */
515                 if (has_frequency())
516                         set_frequency(source.radio_frequency());
517                 if (radio_enable >= 0)
518                         radio_enable = source.radio_enable();
519                 if (callsign != null)
520                         callsign = source.callsign();
521                 if (telemetry_rate >= 0)
522                         telemetry_rate = source.telemetry_rate();
523
524                 /* HAS_ACCEL */
525                 if (pad_orientation >= 0)
526                         pad_orientation = source.pad_orientation();
527
528                 /* HAS_LOG */
529                 if (flight_log_max >= 0)
530                         flight_log_max = source.flight_log_max();
531
532                 /* HAS_IGNITE */
533                 if (ignite_mode >= 0)
534                         ignite_mode = source.ignite_mode();
535
536                 /* AO_PYRO_NUM */
537                 if (npyro > 0)
538                         pyros = source.pyros();
539                 if (pyro_firing_time >= 0)
540                         pyro_firing_time = source.pyro_firing_time();
541
542                 /* HAS_APRS */
543                 if (aprs_interval >= 0)
544                         aprs_interval = source.aprs_interval();
545                 if (aprs_ssid >= 0)
546                         aprs_ssid = source.aprs_ssid();
547                 if (aprs_format >= 0)
548                         aprs_format = source.aprs_format();
549
550                 /* HAS_BEEP */
551                 if (beep >= 0)
552                         beep = source.beep();
553                 /* HAS_TRACKER */
554                 if (tracker_motion >= 0)
555                         tracker_motion = source.tracker_motion();
556                 if (tracker_interval >= 0)
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 > 0)
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 > 0)
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 > 0)
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 >= 0)
621                         link.printf("c m %d\n", main_deploy);
622                 if (apogee_delay >= 0)
623                         link.printf("c d %d\n", apogee_delay);
624                 if (apogee_lockout >= 0)
625                         link.printf("c L %d\n", apogee_lockout);
626
627                 /* HAS_RADIO */
628                 if (has_frequency()) {
629                         boolean has_frequency = radio_frequency >= 0;
630                         boolean has_setting = radio_setting > 0;
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 >= 0) {
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 >= 0)
669                         link.printf("c e %d\n", radio_enable);
670
671                 /* HAS_ACCEL */
672                 /* UI doesn't support accel cal */
673                 if (pad_orientation >= 0)
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 >= 0)
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 > 0) {
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 >= 0)
695                         link.printf("c I %d\n", (int) (pyro_firing_time * 100.0 + 0.5));
696
697                 /* HAS_APRS */
698                 if (aprs_interval >= 0)
699                         link.printf("c A %d\n", aprs_interval);
700                 if (aprs_ssid >= 0)
701                         link.printf("c S %d\n", aprs_ssid);
702                 if (aprs_format >= 0)
703                         link.printf("c C %d\n", aprs_format);
704
705                 /* HAS_BEEP */
706                 if (beep >= 0)
707                         link.printf("c b %d\n", beep);
708
709                 /* HAS_TRACKER */
710                 if (tracker_motion >= 0 && tracker_interval >= 0)
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 }