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