Merge remote-tracking branch 'origin/master' into multiarch
[fw/altos] / src / test / ao_flight_test.c
1 /*
2  * Copyright © 2009 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; version 2 of the License.
7  *
8  * This program is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11  * General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License along
14  * with this program; if not, write to the Free Software Foundation, Inc.,
15  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
16  */
17
18 #define _GNU_SOURCE
19
20 #include <stdint.h>
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
24 #include <getopt.h>
25 #include <math.h>
26
27 #define AO_HERTZ        100
28
29 #define AO_ADC_RING     64
30 #define ao_adc_ring_next(n)     (((n) + 1) & (AO_ADC_RING - 1))
31 #define ao_adc_ring_prev(n)     (((n) - 1) & (AO_ADC_RING - 1))
32
33 #define AO_M_TO_HEIGHT(m)       ((int16_t) (m))
34 #define AO_MS_TO_SPEED(ms)      ((int16_t) ((ms) * 16))
35 #define AO_MSS_TO_ACCEL(mss)    ((int16_t) ((mss) * 16))
36
37 /*
38  * One set of samples read from the A/D converter
39  */
40 struct ao_adc {
41         uint16_t        tick;           /* tick when the sample was read */
42         int16_t         accel;          /* accelerometer */
43         int16_t         pres;           /* pressure sensor */
44         int16_t         pres_real;      /* unclipped */
45         int16_t         temp;           /* temperature sensor */
46         int16_t         v_batt;         /* battery voltage */
47         int16_t         sense_d;        /* drogue continuity sense */
48         int16_t         sense_m;        /* main continuity sense */
49 };
50
51 #define __pdata
52 #define __data
53 #define __xdata
54 #define __code
55 #define __reentrant
56
57 #define to_fix16(x) ((int16_t) ((x) * 65536.0 + 0.5))
58 #define to_fix32(x) ((int32_t) ((x) * 65536.0 + 0.5))
59 #define from_fix(x)     ((x) >> 16)
60
61 /*
62  * Above this height, the baro sensor doesn't work
63  */
64 #define AO_MAX_BARO_HEIGHT      12000
65 #define AO_BARO_SATURATE        13000
66 #define AO_MIN_BARO_VALUE       ao_altitude_to_pres(AO_BARO_SATURATE)
67
68 /*
69  * Above this speed, baro measurements are unreliable
70  */
71 #define AO_MAX_BARO_SPEED       200
72
73 #define ACCEL_NOSE_UP   (ao_accel_2g >> 2)
74
75 enum ao_flight_state {
76         ao_flight_startup = 0,
77         ao_flight_idle = 1,
78         ao_flight_pad = 2,
79         ao_flight_boost = 3,
80         ao_flight_fast = 4,
81         ao_flight_coast = 5,
82         ao_flight_drogue = 6,
83         ao_flight_main = 7,
84         ao_flight_landed = 8,
85         ao_flight_invalid = 9
86 };
87
88 extern enum ao_flight_state ao_flight_state;
89
90 #define FALSE 0
91 #define TRUE 1
92
93 struct ao_adc ao_adc_ring[AO_ADC_RING];
94 uint8_t ao_adc_head;
95 int     ao_summary = 0;
96
97 #define ao_led_on(l)
98 #define ao_led_off(l)
99 #define ao_timer_set_adc_interval(i)
100 #define ao_wakeup(wchan) ao_dump_state()
101 #define ao_cmd_register(c)
102 #define ao_usb_disable()
103 #define ao_telemetry_set_interval(x)
104 #define ao_rdf_set(rdf)
105 #define ao_packet_slave_start()
106 #define ao_packet_slave_stop()
107
108 enum ao_igniter {
109         ao_igniter_drogue = 0,
110         ao_igniter_main = 1
111 };
112
113 struct ao_adc ao_adc_static;
114
115 int     drogue_height;
116 double  drogue_time;
117 int     main_height;
118 double  main_time;
119
120 int     tick_offset;
121
122 static int32_t  ao_k_height;
123
124 void
125 ao_ignite(enum ao_igniter igniter)
126 {
127         double time = (double) (ao_adc_static.tick + tick_offset) / 100;
128
129         if (igniter == ao_igniter_drogue) {
130                 drogue_time = time;
131                 drogue_height = ao_k_height >> 16;
132         } else {
133                 main_time = time;
134                 main_height = ao_k_height >> 16;
135         }
136 }
137
138 struct ao_task {
139         int dummy;
140 };
141
142 #define ao_add_task(t,f,n)
143
144 #define ao_log_start()
145 #define ao_log_stop()
146
147 #define AO_MS_TO_TICKS(ms)      ((ms) / 10)
148 #define AO_SEC_TO_TICKS(s)      ((s) * 100)
149
150 #define AO_FLIGHT_TEST
151
152 int     ao_flight_debug;
153
154 FILE *emulator_in;
155 char *emulator_app;
156 char *emulator_name;
157 double emulator_error_max = 4;
158 double emulator_height_error_max = 20;  /* noise in the baro sensor */
159
160 void
161 ao_dump_state(void);
162
163 void
164 ao_sleep(void *wchan);
165
166 const char const * const ao_state_names[] = {
167         "startup", "idle", "pad", "boost", "fast",
168         "coast", "drogue", "main", "landed", "invalid"
169 };
170
171 struct ao_cmds {
172         void            (*func)(void);
173         const char      *help;
174 };
175
176 #include "ao_convert.c"
177
178 struct ao_config {
179         uint16_t        main_deploy;
180         int16_t         accel_plus_g;
181         int16_t         accel_minus_g;
182         uint8_t         pad_orientation;
183 };
184
185 #define AO_PAD_ORIENTATION_ANTENNA_UP   0
186 #define AO_PAD_ORIENTATION_ANTENNA_DOWN 1
187
188 #define ao_config_get()
189
190 struct ao_config ao_config;
191
192 #define DATA_TO_XDATA(x) (x)
193
194 #define HAS_FLIGHT 1
195 #define HAS_ADC 1
196 #define HAS_USB 1
197 #define HAS_GPS 1
198 #ifndef HAS_ACCEL
199 #define HAS_ACCEL 1
200 #define HAS_ACCEL_REF 0
201 #endif
202
203 #define GRAVITY 9.80665
204 extern int16_t ao_ground_accel, ao_flight_accel;
205 extern int16_t ao_accel_2g;
206
207 extern uint16_t ao_sample_tick;
208
209 extern int16_t  ao_sample_height;
210 extern int16_t  ao_sample_accel;
211 extern int32_t  ao_accel_scale;
212 extern int16_t  ao_ground_height;
213 extern int16_t  ao_sample_alt;
214
215 int ao_sample_prev_tick;
216 uint16_t        prev_tick;
217
218 #include "ao_kalman.c"
219 #include "ao_sample.c"
220 #include "ao_flight.c"
221
222 #define to_double(f)    ((f) / 65536.0)
223
224 static int      ao_records_read = 0;
225 static int      ao_eof_read = 0;
226 static int      ao_flight_ground_accel;
227 static int      ao_flight_started = 0;
228 static int      ao_test_max_height;
229 static double   ao_test_max_height_time;
230 static int      ao_test_main_height;
231 static double   ao_test_main_height_time;
232 static double   ao_test_landed_time;
233 static double   ao_test_landed_height;
234 static double   ao_test_landed_time;
235 static int      landed_set;
236 static double   landed_time;
237 static double   landed_height;
238
239 void
240 ao_test_exit(void)
241 {
242         double  drogue_error;
243         double  main_error;
244         double  landed_error;
245         double  landed_time_error;
246
247         if (!ao_test_main_height_time) {
248                 ao_test_main_height_time = ao_test_max_height_time;
249                 ao_test_main_height = ao_test_max_height;
250         }
251         drogue_error = fabs(ao_test_max_height_time - drogue_time);
252         main_error = fabs(ao_test_main_height_time - main_time);
253         landed_error = fabs(ao_test_landed_height - landed_height);
254         landed_time_error = ao_test_landed_time - landed_time;
255         if (drogue_error > emulator_error_max || main_error > emulator_error_max ||
256             landed_time_error > emulator_error_max || landed_error > emulator_height_error_max) {
257                 printf ("%s %s\n",
258                         emulator_app, emulator_name);
259                 printf ("\tApogee error %g\n", drogue_error);
260                 printf ("\tMain error %g\n", main_error);
261                 printf ("\tLanded height error %g\n", landed_error);
262                 printf ("\tLanded time error %g\n", landed_time_error);
263                 printf ("\tActual: apogee: %d at %7.2f main: %d at %7.2f landed %7.2f at %7.2f\n",
264                         ao_test_max_height, ao_test_max_height_time,
265                         ao_test_main_height, ao_test_main_height_time,
266                         ao_test_landed_height, ao_test_landed_time);
267                 printf ("\tComputed: apogee: %d at %7.2f main: %d at %7.2f landed %7.2f at %7.2f\n",
268                         drogue_height, drogue_time, main_height, main_time,
269                         landed_height, landed_time);
270                 exit (1);
271         }
272         exit(0);
273 }
274
275 void
276 ao_insert(void)
277 {
278         double  time;
279
280         ao_adc_ring[ao_adc_head] = ao_adc_static;
281         ao_adc_head = ao_adc_ring_next(ao_adc_head);
282         if (ao_flight_state != ao_flight_startup) {
283                 double  height = ao_pres_to_altitude(ao_adc_static.pres_real) - ao_ground_height;
284                 double  accel = ((ao_flight_ground_accel - ao_adc_static.accel) * GRAVITY * 2.0) /
285                         (ao_config.accel_minus_g - ao_config.accel_plus_g);
286
287                 if (!tick_offset)
288                         tick_offset = -ao_adc_static.tick;
289                 if ((prev_tick - ao_adc_static.tick) > 0x400)
290                         tick_offset += 65536;
291                 prev_tick = ao_adc_static.tick;
292                 time = (double) (ao_adc_static.tick + tick_offset) / 100;
293
294                 if (ao_test_max_height < height) {
295                         ao_test_max_height = height;
296                         ao_test_max_height_time = time;
297                         ao_test_landed_height = height;
298                         ao_test_landed_time = time;
299                 }
300                 if (height > ao_config.main_deploy) {
301                         ao_test_main_height_time = time;
302                         ao_test_main_height = height;
303                 }
304
305                 if (ao_test_landed_height > height) {
306                         ao_test_landed_height = height;
307                         ao_test_landed_time = time;
308                 }
309
310                 if (ao_flight_state == ao_flight_landed && !landed_set) {
311                         landed_set = 1;
312                         landed_time = time;
313                         landed_height = height;
314                 }
315
316                 if (!ao_summary) {
317                         printf("%7.2f height %8.2f accel %8.3f state %-8.8s k_height %8.2f k_speed %8.3f k_accel %8.3f avg_height %5d drogue %4d main %4d error %5d\n",
318                                time,
319                                height,
320                                accel,
321                                ao_state_names[ao_flight_state],
322                                ao_k_height / 65536.0,
323                                ao_k_speed / 65536.0 / 16.0,
324                                ao_k_accel / 65536.0 / 16.0,
325                                ao_avg_height,
326                                drogue_height,
327                                main_height,
328                                ao_error_h_sq_avg);
329                         
330 //                      if (ao_flight_state == ao_flight_landed)
331 //                              ao_test_exit();
332                 }
333         }
334 }
335
336 #define AO_MAX_CALLSIGN                 8
337 #define AO_MAX_VERSION                  8
338 #define AO_MAX_TELEMETRY                128
339
340 struct ao_telemetry_generic {
341         uint16_t        serial;         /* 0 */
342         uint16_t        tick;           /* 2 */
343         uint8_t         type;           /* 4 */
344         uint8_t         payload[27];    /* 5 */
345         /* 32 */
346 };
347
348 #define AO_TELEMETRY_SENSOR_TELEMETRUM  0x01
349 #define AO_TELEMETRY_SENSOR_TELEMINI    0x02
350 #define AO_TELEMETRY_SENSOR_TELENANO    0x03
351
352 struct ao_telemetry_sensor {
353         uint16_t        serial;         /*  0 */
354         uint16_t        tick;           /*  2 */
355         uint8_t         type;           /*  4 */
356
357         uint8_t         state;          /*  5 flight state */
358         int16_t         accel;          /*  6 accelerometer (TM only) */
359         int16_t         pres;           /*  8 pressure sensor */
360         int16_t         temp;           /* 10 temperature sensor */
361         int16_t         v_batt;         /* 12 battery voltage */
362         int16_t         sense_d;        /* 14 drogue continuity sense (TM/Tm) */
363         int16_t         sense_m;        /* 16 main continuity sense (TM/Tm) */
364
365         int16_t         acceleration;   /* 18 m/s² * 16 */
366         int16_t         speed;          /* 20 m/s * 16 */
367         int16_t         height;         /* 22 m */
368
369         int16_t         ground_pres;    /* 24 average pres on pad */
370         int16_t         ground_accel;   /* 26 average accel on pad */
371         int16_t         accel_plus_g;   /* 28 accel calibration at +1g */
372         int16_t         accel_minus_g;  /* 30 accel calibration at -1g */
373         /* 32 */
374 };
375
376 #define AO_TELEMETRY_CONFIGURATION      0x04
377
378 struct ao_telemetry_configuration {
379         uint16_t        serial;                         /*  0 */
380         uint16_t        tick;                           /*  2 */
381         uint8_t         type;                           /*  4 */
382
383         uint8_t         device;                         /*  5 device type */
384         uint16_t        flight;                         /*  6 flight number */
385         uint8_t         config_major;                   /*  8 Config major version */
386         uint8_t         config_minor;                   /*  9 Config minor version */
387         uint16_t        apogee_delay;                   /* 10 Apogee deploy delay in seconds */
388         uint16_t        main_deploy;                    /* 12 Main deploy alt in meters */
389         uint16_t        flight_log_max;                 /* 14 Maximum flight log size in kB */
390         char            callsign[AO_MAX_CALLSIGN];      /* 16 Radio operator identity */
391         char            version[AO_MAX_VERSION];        /* 24 Software version */
392         /* 32 */
393 };
394
395 #define AO_TELEMETRY_LOCATION           0x05
396
397 #define AO_GPS_MODE_NOT_VALID           'N'
398 #define AO_GPS_MODE_AUTONOMOUS          'A'
399 #define AO_GPS_MODE_DIFFERENTIAL        'D'
400 #define AO_GPS_MODE_ESTIMATED           'E'
401 #define AO_GPS_MODE_MANUAL              'M'
402 #define AO_GPS_MODE_SIMULATED           'S'
403
404 struct ao_telemetry_location {
405         uint16_t        serial;         /*  0 */
406         uint16_t        tick;           /*  2 */
407         uint8_t         type;           /*  4 */
408
409         uint8_t         flags;          /*  5 Number of sats and other flags */
410         int16_t         altitude;       /*  6 GPS reported altitude (m) */
411         int32_t         latitude;       /*  8 latitude (degrees * 10⁷) */
412         int32_t         longitude;      /* 12 longitude (degrees * 10⁷) */
413         uint8_t         year;           /* 16 (- 2000) */
414         uint8_t         month;          /* 17 (1-12) */
415         uint8_t         day;            /* 18 (1-31) */
416         uint8_t         hour;           /* 19 (0-23) */
417         uint8_t         minute;         /* 20 (0-59) */
418         uint8_t         second;         /* 21 (0-59) */
419         uint8_t         pdop;           /* 22 (m * 5) */
420         uint8_t         hdop;           /* 23 (m * 5) */
421         uint8_t         vdop;           /* 24 (m * 5) */
422         uint8_t         mode;           /* 25 */
423         uint16_t        ground_speed;   /* 26 cm/s */
424         int16_t         climb_rate;     /* 28 cm/s */
425         uint8_t         course;         /* 30 degrees / 2 */
426         uint8_t         unused[1];      /* 31 */
427         /* 32 */
428 };
429
430 #define AO_TELEMETRY_SATELLITE          0x06
431
432 struct ao_telemetry_satellite_info {
433         uint8_t         svid;
434         uint8_t         c_n_1;
435 };
436
437 struct ao_telemetry_satellite {
438         uint16_t                                serial;         /*  0 */
439         uint16_t                                tick;           /*  2 */
440         uint8_t                                 type;           /*  4 */
441         uint8_t                                 channels;       /*  5 number of reported sats */
442
443         struct ao_telemetry_satellite_info      sats[12];       /* 6 */
444         uint8_t                                 unused[2];      /* 30 */
445         /* 32 */
446 };
447
448 union ao_telemetry_all {
449         struct ao_telemetry_generic             generic;
450         struct ao_telemetry_sensor              sensor;
451         struct ao_telemetry_configuration       configuration;
452         struct ao_telemetry_location            location;
453         struct ao_telemetry_satellite           satellite;
454 };
455
456 uint16_t
457 uint16(uint8_t *bytes, int off)
458 {
459         off++;
460         return (uint16_t) bytes[off] | (((uint16_t) bytes[off+1]) << 8);
461 }
462
463 int16_t
464 int16(uint8_t *bytes, int off)
465 {
466         return (int16_t) uint16(bytes, off);
467 }
468
469 void
470 ao_sleep(void *wchan)
471 {
472         if (wchan == &ao_adc_head) {
473                 char            type;
474                 uint16_t        tick;
475                 uint16_t        a, b;
476                 int             ret;
477                 uint8_t         bytes[1024];
478                 union ao_telemetry_all  telem;
479                 char            line[1024];
480                 char            *saveptr;
481                 char            *l;
482                 char            *words[64];
483                 int             nword;
484
485                 for (;;) {
486                         if (ao_records_read > 2 && ao_flight_state == ao_flight_startup)
487                         {
488                                 ao_adc_static.accel = ao_flight_ground_accel;
489                                 ao_insert();
490                                 return;
491                         }
492
493                         if (!fgets(line, sizeof (line), emulator_in)) {
494                                 if (++ao_eof_read >= 1000) {
495                                         if (!ao_summary)
496                                                 printf ("no more data, exiting simulation\n");
497                                         ao_test_exit();
498                                 }
499                                 ao_adc_static.tick += 10;
500                                 ao_insert();
501                                 return;
502                         }
503                         l = line;
504                         for (nword = 0; nword < 64; nword++) {
505                                 words[nword] = strtok_r(l, " \t\n", &saveptr);
506                                 l = NULL;
507                                 if (words[nword] == NULL)
508                                         break;
509                         }
510                         if (nword == 4) {
511                                 type = words[0][0];
512                                 tick = strtoul(words[1], NULL, 16);
513                                 a = strtoul(words[2], NULL, 16);
514                                 b = strtoul(words[3], NULL, 16);
515                                 if (type == 'P')
516                                         type = 'A';
517                         } else if (nword >= 6 && strcmp(words[0], "Accel") == 0) {
518                                 ao_config.accel_plus_g = atoi(words[3]);
519                                 ao_config.accel_minus_g = atoi(words[5]);
520                         } else if (nword >= 4 && strcmp(words[0], "Main") == 0) {
521                                 ao_config.main_deploy = atoi(words[2]);
522                         } else if (nword >= 36 && strcmp(words[0], "CALL") == 0) {
523                                 tick = atoi(words[10]);
524                                 if (!ao_flight_started) {
525                                         type = 'F';
526                                         a = atoi(words[26]);
527                                         ao_flight_started = 1;
528                                 } else {
529                                         type = 'A';
530                                         a = atoi(words[12]);
531                                         b = atoi(words[14]);
532                                 }
533                         } else if (nword == 3 && strcmp(words[0], "BARO") == 0) {
534                                 tick = strtol(words[1], NULL, 16);
535                                 a = 16384 - 328;
536                                 b = strtol(words[2], NULL, 10);
537                                 type = 'A';
538                                 if (!ao_flight_started) {
539                                         ao_flight_ground_accel = 16384 - 328;
540                                         ao_config.accel_plus_g = 16384 - 328;
541                                         ao_config.accel_minus_g = 16384 + 328;
542                                         ao_flight_started = 1;
543                                 }
544                         } else if (nword == 2 && strcmp(words[0], "TELEM") == 0) {
545                                 char    *hex = words[1];
546                                 char    elt[3];
547                                 int     i, len;
548                                 uint8_t sum;
549
550                                 len = strlen(hex);
551                                 if (len > sizeof (bytes) * 2) {
552                                         len = sizeof (bytes)*2;
553                                         hex[len] = '\0';
554                                 }
555                                 for (i = 0; i < len; i += 2) {
556                                         elt[0] = hex[i];
557                                         elt[1] = hex[i+1];
558                                         elt[2] = '\0';
559                                         bytes[i/2] = (uint8_t) strtol(elt, NULL, 16);
560                                 }
561                                 len = i/2;
562                                 if (bytes[0] != len - 2) {
563                                         printf ("bad length %d != %d\n", bytes[0], len - 2);
564                                         continue;
565                                 }
566                                 sum = 0x5a;
567                                 for (i = 1; i < len-1; i++)
568                                         sum += bytes[i];
569                                 if (sum != bytes[len-1]) {
570                                         printf ("bad checksum\n");
571                                         continue;
572                                 }
573                                 if ((bytes[len-2] & 0x80) == 0) {
574                                         continue;
575                                 }
576                                 if (len == 36) {
577                                         memcpy(&telem, bytes + 1, 32);
578                                         tick = telem.generic.tick;
579                                         switch (telem.generic.type) {
580                                         case AO_TELEMETRY_SENSOR_TELEMETRUM:
581                                         case AO_TELEMETRY_SENSOR_TELEMINI:
582                                         case AO_TELEMETRY_SENSOR_TELENANO:
583                                                 if (!ao_flight_started) {
584                                                         ao_flight_ground_accel = telem.sensor.ground_accel;
585                                                         ao_config.accel_plus_g = telem.sensor.accel_plus_g;
586                                                         ao_config.accel_minus_g = telem.sensor.accel_minus_g;
587                                                         ao_flight_started = 1;
588                                                 }
589                                                 type = 'A';
590                                                 a = telem.sensor.accel;
591                                                 b = telem.sensor.pres;
592                                                 break;
593                                         }
594                                 } else if (len == 99) {
595                                         ao_flight_started = 1;
596                                         tick = uint16(bytes, 21);
597                                         ao_flight_ground_accel = int16(bytes, 7);
598                                         ao_config.accel_plus_g = int16(bytes, 17);
599                                         ao_config.accel_minus_g = int16(bytes, 19);
600                                         type = 'A';
601                                         a = int16(bytes, 23);
602                                         b = int16(bytes, 25);
603                                 } else if (len == 98) {
604                                         ao_flight_started = 1;
605                                         tick = uint16(bytes, 20);
606                                         ao_flight_ground_accel = int16(bytes, 6);
607                                         ao_config.accel_plus_g = int16(bytes, 16);
608                                         ao_config.accel_minus_g = int16(bytes, 18);
609                                         type = 'A';
610                                         a = int16(bytes, 22);
611                                         b = int16(bytes, 24);
612                                 } else {
613                                         printf("unknown len %d\n", len);
614                                         continue;
615                                 }
616                         }
617                         if (type != 'F' && !ao_flight_started)
618                                 continue;
619
620                         switch (type) {
621                         case 'F':
622                                 ao_flight_ground_accel = a;
623                                 if (ao_config.accel_plus_g == 0) {
624                                         ao_config.accel_plus_g = a;
625                                         ao_config.accel_minus_g = a + 530;
626                                 }
627                                 if (ao_config.main_deploy == 0)
628                                         ao_config.main_deploy = 250;
629                                 ao_flight_started = 1;
630                                 break;
631                         case 'S':
632                                 break;
633                         case 'A':
634                                 ao_adc_static.tick = tick;
635                                 ao_adc_static.accel = a;
636                                 ao_adc_static.pres_real = b;
637                                 if (b < AO_MIN_BARO_VALUE)
638                                         b = AO_MIN_BARO_VALUE;
639                                 ao_adc_static.pres = b;
640                                 ao_records_read++;
641                                 ao_insert();
642                                 return;
643                         case 'T':
644                                 ao_adc_static.tick = tick;
645                                 ao_adc_static.temp = a;
646                                 ao_adc_static.v_batt = b;
647                                 break;
648                         case 'D':
649                         case 'G':
650                         case 'N':
651                         case 'W':
652                         case 'H':
653                                 break;
654                         }
655                 }
656
657         }
658 }
659 #define COUNTS_PER_G 264.8
660
661 void
662 ao_dump_state(void)
663 {
664 }
665
666 static const struct option options[] = {
667         { .name = "summary", .has_arg = 0, .val = 's' },
668         { .name = "debug", .has_arg = 0, .val = 'd' },
669         { 0, 0, 0, 0},
670 };
671
672 void run_flight_fixed(char *name, FILE *f, int summary)
673 {
674         emulator_name = name;
675         emulator_in = f;
676         ao_summary = summary;
677         ao_flight_init();
678         ao_flight();
679 }
680
681 int
682 main (int argc, char **argv)
683 {
684         int     summary = 0;
685         int     c;
686         int     i;
687
688 #if HAS_ACCEL
689         emulator_app="full";
690 #else
691         emulator_app="baro";
692 #endif
693         while ((c = getopt_long(argc, argv, "sd", options, NULL)) != -1) {
694                 switch (c) {
695                 case 's':
696                         summary = 1;
697                         break;
698                 case 'd':
699                         ao_flight_debug = 1;
700                         break;
701                 }
702         }
703
704         if (optind == argc)
705                 run_flight_fixed("<stdin>", stdin, summary);
706         else
707                 for (i = optind; i < argc; i++) {
708                         FILE    *f = fopen(argv[i], "r");
709                         if (!f) {
710                                 perror(argv[i]);
711                                 continue;
712                         }
713                         run_flight_fixed(argv[i], f, summary);
714                         fclose(f);
715                 }
716 }