altos: Respect apogee lockout time in flight algorithm
[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 #define ao_xmemcpy(d,s,c) memcpy(d,s,c)
177 #define ao_xmemset(d,v,c) memset(d,v,c)
178 #define ao_xmemcmp(d,s,c) memcmp(d,s,c)
179
180 #include "ao_convert.c"
181
182 struct ao_config {
183         uint16_t        main_deploy;
184         int16_t         accel_plus_g;
185         int16_t         accel_minus_g;
186         uint8_t         pad_orientation;
187         uint16_t        apogee_lockout;
188 };
189
190 #define AO_PAD_ORIENTATION_ANTENNA_UP   0
191 #define AO_PAD_ORIENTATION_ANTENNA_DOWN 1
192
193 #define ao_config_get()
194
195 struct ao_config ao_config;
196
197 #define DATA_TO_XDATA(x) (x)
198
199 #define HAS_FLIGHT 1
200 #define HAS_ADC 1
201 #define HAS_USB 1
202 #define HAS_GPS 1
203 #ifndef HAS_ACCEL
204 #define HAS_ACCEL 1
205 #define HAS_ACCEL_REF 0
206 #endif
207
208 #define GRAVITY 9.80665
209 extern int16_t ao_ground_accel, ao_flight_accel;
210 extern int16_t ao_accel_2g;
211
212 extern uint16_t ao_sample_tick;
213
214 extern int16_t  ao_sample_height;
215 extern int16_t  ao_sample_accel;
216 extern int32_t  ao_accel_scale;
217 extern int16_t  ao_ground_height;
218 extern int16_t  ao_sample_alt;
219
220 int ao_sample_prev_tick;
221 uint16_t        prev_tick;
222
223 #include "ao_kalman.c"
224 #include "ao_sample.c"
225 #include "ao_flight.c"
226
227 #define to_double(f)    ((f) / 65536.0)
228
229 static int      ao_records_read = 0;
230 static int      ao_eof_read = 0;
231 static int      ao_flight_ground_accel;
232 static int      ao_flight_started = 0;
233 static int      ao_test_max_height;
234 static double   ao_test_max_height_time;
235 static int      ao_test_main_height;
236 static double   ao_test_main_height_time;
237 static double   ao_test_landed_time;
238 static double   ao_test_landed_height;
239 static double   ao_test_landed_time;
240 static int      landed_set;
241 static double   landed_time;
242 static double   landed_height;
243
244 void
245 ao_test_exit(void)
246 {
247         double  drogue_error;
248         double  main_error;
249         double  landed_error;
250         double  landed_time_error;
251
252         if (!ao_test_main_height_time) {
253                 ao_test_main_height_time = ao_test_max_height_time;
254                 ao_test_main_height = ao_test_max_height;
255         }
256         drogue_error = fabs(ao_test_max_height_time - drogue_time);
257         main_error = fabs(ao_test_main_height_time - main_time);
258         landed_error = fabs(ao_test_landed_height - landed_height);
259         landed_time_error = ao_test_landed_time - landed_time;
260         if (drogue_error > emulator_error_max || main_error > emulator_error_max ||
261             landed_time_error > emulator_error_max || landed_error > emulator_height_error_max) {
262                 printf ("%s %s\n",
263                         emulator_app, emulator_name);
264                 printf ("\tApogee error %g\n", drogue_error);
265                 printf ("\tMain error %g\n", main_error);
266                 printf ("\tLanded height error %g\n", landed_error);
267                 printf ("\tLanded time error %g\n", landed_time_error);
268                 printf ("\tActual: apogee: %d at %7.2f main: %d at %7.2f landed %7.2f at %7.2f\n",
269                         ao_test_max_height, ao_test_max_height_time,
270                         ao_test_main_height, ao_test_main_height_time,
271                         ao_test_landed_height, ao_test_landed_time);
272                 printf ("\tComputed: apogee: %d at %7.2f main: %d at %7.2f landed %7.2f at %7.2f\n",
273                         drogue_height, drogue_time, main_height, main_time,
274                         landed_height, landed_time);
275                 exit (1);
276         }
277         exit(0);
278 }
279
280 void
281 ao_insert(void)
282 {
283         double  time;
284
285         ao_adc_ring[ao_adc_head] = ao_adc_static;
286         ao_adc_head = ao_adc_ring_next(ao_adc_head);
287         if (ao_flight_state != ao_flight_startup) {
288                 double  height = ao_pres_to_altitude(ao_adc_static.pres_real) - ao_ground_height;
289                 double  accel = ((ao_flight_ground_accel - ao_adc_static.accel) * GRAVITY * 2.0) /
290                         (ao_config.accel_minus_g - ao_config.accel_plus_g);
291
292                 if (!tick_offset)
293                         tick_offset = -ao_adc_static.tick;
294                 if ((prev_tick - ao_adc_static.tick) > 0x400)
295                         tick_offset += 65536;
296                 prev_tick = ao_adc_static.tick;
297                 time = (double) (ao_adc_static.tick + tick_offset) / 100;
298
299                 if (ao_test_max_height < height) {
300                         ao_test_max_height = height;
301                         ao_test_max_height_time = time;
302                         ao_test_landed_height = height;
303                         ao_test_landed_time = time;
304                 }
305                 if (height > ao_config.main_deploy) {
306                         ao_test_main_height_time = time;
307                         ao_test_main_height = height;
308                 }
309
310                 if (ao_test_landed_height > height) {
311                         ao_test_landed_height = height;
312                         ao_test_landed_time = time;
313                 }
314
315                 if (ao_flight_state == ao_flight_landed && !landed_set) {
316                         landed_set = 1;
317                         landed_time = time;
318                         landed_height = height;
319                 }
320
321                 if (!ao_summary) {
322                         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",
323                                time,
324                                height,
325                                accel,
326                                ao_state_names[ao_flight_state],
327                                ao_k_height / 65536.0,
328                                ao_k_speed / 65536.0 / 16.0,
329                                ao_k_accel / 65536.0 / 16.0,
330                                ao_avg_height,
331                                drogue_height,
332                                main_height,
333                                ao_error_h_sq_avg);
334                         
335 //                      if (ao_flight_state == ao_flight_landed)
336 //                              ao_test_exit();
337                 }
338         }
339 }
340
341 #define AO_MAX_CALLSIGN                 8
342 #define AO_MAX_VERSION                  8
343 #define AO_MAX_TELEMETRY                128
344
345 struct ao_telemetry_generic {
346         uint16_t        serial;         /* 0 */
347         uint16_t        tick;           /* 2 */
348         uint8_t         type;           /* 4 */
349         uint8_t         payload[27];    /* 5 */
350         /* 32 */
351 };
352
353 #define AO_TELEMETRY_SENSOR_TELEMETRUM  0x01
354 #define AO_TELEMETRY_SENSOR_TELEMINI    0x02
355 #define AO_TELEMETRY_SENSOR_TELENANO    0x03
356
357 struct ao_telemetry_sensor {
358         uint16_t        serial;         /*  0 */
359         uint16_t        tick;           /*  2 */
360         uint8_t         type;           /*  4 */
361
362         uint8_t         state;          /*  5 flight state */
363         int16_t         accel;          /*  6 accelerometer (TM only) */
364         int16_t         pres;           /*  8 pressure sensor */
365         int16_t         temp;           /* 10 temperature sensor */
366         int16_t         v_batt;         /* 12 battery voltage */
367         int16_t         sense_d;        /* 14 drogue continuity sense (TM/Tm) */
368         int16_t         sense_m;        /* 16 main continuity sense (TM/Tm) */
369
370         int16_t         acceleration;   /* 18 m/s² * 16 */
371         int16_t         speed;          /* 20 m/s * 16 */
372         int16_t         height;         /* 22 m */
373
374         int16_t         ground_pres;    /* 24 average pres on pad */
375         int16_t         ground_accel;   /* 26 average accel on pad */
376         int16_t         accel_plus_g;   /* 28 accel calibration at +1g */
377         int16_t         accel_minus_g;  /* 30 accel calibration at -1g */
378         /* 32 */
379 };
380
381 #define AO_TELEMETRY_CONFIGURATION      0x04
382
383 struct ao_telemetry_configuration {
384         uint16_t        serial;                         /*  0 */
385         uint16_t        tick;                           /*  2 */
386         uint8_t         type;                           /*  4 */
387
388         uint8_t         device;                         /*  5 device type */
389         uint16_t        flight;                         /*  6 flight number */
390         uint8_t         config_major;                   /*  8 Config major version */
391         uint8_t         config_minor;                   /*  9 Config minor version */
392         uint16_t        apogee_delay;                   /* 10 Apogee deploy delay in seconds */
393         uint16_t        main_deploy;                    /* 12 Main deploy alt in meters */
394         uint16_t        flight_log_max;                 /* 14 Maximum flight log size in kB */
395         char            callsign[AO_MAX_CALLSIGN];      /* 16 Radio operator identity */
396         char            version[AO_MAX_VERSION];        /* 24 Software version */
397         /* 32 */
398 };
399
400 #define AO_TELEMETRY_LOCATION           0x05
401
402 #define AO_GPS_MODE_NOT_VALID           'N'
403 #define AO_GPS_MODE_AUTONOMOUS          'A'
404 #define AO_GPS_MODE_DIFFERENTIAL        'D'
405 #define AO_GPS_MODE_ESTIMATED           'E'
406 #define AO_GPS_MODE_MANUAL              'M'
407 #define AO_GPS_MODE_SIMULATED           'S'
408
409 struct ao_telemetry_location {
410         uint16_t        serial;         /*  0 */
411         uint16_t        tick;           /*  2 */
412         uint8_t         type;           /*  4 */
413
414         uint8_t         flags;          /*  5 Number of sats and other flags */
415         int16_t         altitude;       /*  6 GPS reported altitude (m) */
416         int32_t         latitude;       /*  8 latitude (degrees * 10⁷) */
417         int32_t         longitude;      /* 12 longitude (degrees * 10⁷) */
418         uint8_t         year;           /* 16 (- 2000) */
419         uint8_t         month;          /* 17 (1-12) */
420         uint8_t         day;            /* 18 (1-31) */
421         uint8_t         hour;           /* 19 (0-23) */
422         uint8_t         minute;         /* 20 (0-59) */
423         uint8_t         second;         /* 21 (0-59) */
424         uint8_t         pdop;           /* 22 (m * 5) */
425         uint8_t         hdop;           /* 23 (m * 5) */
426         uint8_t         vdop;           /* 24 (m * 5) */
427         uint8_t         mode;           /* 25 */
428         uint16_t        ground_speed;   /* 26 cm/s */
429         int16_t         climb_rate;     /* 28 cm/s */
430         uint8_t         course;         /* 30 degrees / 2 */
431         uint8_t         unused[1];      /* 31 */
432         /* 32 */
433 };
434
435 #define AO_TELEMETRY_SATELLITE          0x06
436
437 struct ao_telemetry_satellite_info {
438         uint8_t         svid;
439         uint8_t         c_n_1;
440 };
441
442 struct ao_telemetry_satellite {
443         uint16_t                                serial;         /*  0 */
444         uint16_t                                tick;           /*  2 */
445         uint8_t                                 type;           /*  4 */
446         uint8_t                                 channels;       /*  5 number of reported sats */
447
448         struct ao_telemetry_satellite_info      sats[12];       /* 6 */
449         uint8_t                                 unused[2];      /* 30 */
450         /* 32 */
451 };
452
453 union ao_telemetry_all {
454         struct ao_telemetry_generic             generic;
455         struct ao_telemetry_sensor              sensor;
456         struct ao_telemetry_configuration       configuration;
457         struct ao_telemetry_location            location;
458         struct ao_telemetry_satellite           satellite;
459 };
460
461 uint16_t
462 uint16(uint8_t *bytes, int off)
463 {
464         off++;
465         return (uint16_t) bytes[off] | (((uint16_t) bytes[off+1]) << 8);
466 }
467
468 int16_t
469 int16(uint8_t *bytes, int off)
470 {
471         return (int16_t) uint16(bytes, off);
472 }
473
474 void
475 ao_sleep(void *wchan)
476 {
477         if (wchan == &ao_adc_head) {
478                 char            type;
479                 uint16_t        tick;
480                 uint16_t        a, b;
481                 int             ret;
482                 uint8_t         bytes[1024];
483                 union ao_telemetry_all  telem;
484                 char            line[1024];
485                 char            *saveptr;
486                 char            *l;
487                 char            *words[64];
488                 int             nword;
489
490                 for (;;) {
491                         if (ao_records_read > 2 && ao_flight_state == ao_flight_startup)
492                         {
493                                 ao_adc_static.accel = ao_flight_ground_accel;
494                                 ao_insert();
495                                 return;
496                         }
497
498                         if (!fgets(line, sizeof (line), emulator_in)) {
499                                 if (++ao_eof_read >= 1000) {
500                                         if (!ao_summary)
501                                                 printf ("no more data, exiting simulation\n");
502                                         ao_test_exit();
503                                 }
504                                 ao_adc_static.tick += 10;
505                                 ao_insert();
506                                 return;
507                         }
508                         l = line;
509                         for (nword = 0; nword < 64; nword++) {
510                                 words[nword] = strtok_r(l, " \t\n", &saveptr);
511                                 l = NULL;
512                                 if (words[nword] == NULL)
513                                         break;
514                         }
515                         if (nword == 4) {
516                                 type = words[0][0];
517                                 tick = strtoul(words[1], NULL, 16);
518                                 a = strtoul(words[2], NULL, 16);
519                                 b = strtoul(words[3], NULL, 16);
520                                 if (type == 'P')
521                                         type = 'A';
522                         } else if (nword >= 6 && strcmp(words[0], "Accel") == 0) {
523                                 ao_config.accel_plus_g = atoi(words[3]);
524                                 ao_config.accel_minus_g = atoi(words[5]);
525                         } else if (nword >= 4 && strcmp(words[0], "Main") == 0) {
526                                 ao_config.main_deploy = atoi(words[2]);
527                         } else if (nword >= 3 && strcmp(words[0], "Apogee") == 0 &&
528                                    strcmp(words[1], "lockout:") == 0) {
529                                 ao_config.apogee_lockout = atoi(words[2]);
530                         } else if (nword >= 36 && strcmp(words[0], "CALL") == 0) {
531                                 tick = atoi(words[10]);
532                                 if (!ao_flight_started) {
533                                         type = 'F';
534                                         a = atoi(words[26]);
535                                         ao_flight_started = 1;
536                                 } else {
537                                         type = 'A';
538                                         a = atoi(words[12]);
539                                         b = atoi(words[14]);
540                                 }
541                         } else if (nword == 3 && strcmp(words[0], "BARO") == 0) {
542                                 tick = strtol(words[1], NULL, 16);
543                                 a = 16384 - 328;
544                                 b = strtol(words[2], NULL, 10);
545                                 type = 'A';
546                                 if (!ao_flight_started) {
547                                         ao_flight_ground_accel = 16384 - 328;
548                                         ao_config.accel_plus_g = 16384 - 328;
549                                         ao_config.accel_minus_g = 16384 + 328;
550                                         ao_flight_started = 1;
551                                 }
552                         } else if (nword == 2 && strcmp(words[0], "TELEM") == 0) {
553                                 __xdata char    *hex = words[1];
554                                 char    elt[3];
555                                 int     i, len;
556                                 uint8_t sum;
557
558                                 len = strlen(hex);
559                                 if (len > sizeof (bytes) * 2) {
560                                         len = sizeof (bytes)*2;
561                                         hex[len] = '\0';
562                                 }
563                                 for (i = 0; i < len; i += 2) {
564                                         elt[0] = hex[i];
565                                         elt[1] = hex[i+1];
566                                         elt[2] = '\0';
567                                         bytes[i/2] = (uint8_t) strtol(elt, NULL, 16);
568                                 }
569                                 len = i/2;
570                                 if (bytes[0] != len - 2) {
571                                         printf ("bad length %d != %d\n", bytes[0], len - 2);
572                                         continue;
573                                 }
574                                 sum = 0x5a;
575                                 for (i = 1; i < len-1; i++)
576                                         sum += bytes[i];
577                                 if (sum != bytes[len-1]) {
578                                         printf ("bad checksum\n");
579                                         continue;
580                                 }
581                                 if ((bytes[len-2] & 0x80) == 0) {
582                                         continue;
583                                 }
584                                 if (len == 36) {
585                                         ao_xmemcpy(&telem, bytes + 1, 32);
586                                         tick = telem.generic.tick;
587                                         switch (telem.generic.type) {
588                                         case AO_TELEMETRY_SENSOR_TELEMETRUM:
589                                         case AO_TELEMETRY_SENSOR_TELEMINI:
590                                         case AO_TELEMETRY_SENSOR_TELENANO:
591                                                 if (!ao_flight_started) {
592                                                         ao_flight_ground_accel = telem.sensor.ground_accel;
593                                                         ao_config.accel_plus_g = telem.sensor.accel_plus_g;
594                                                         ao_config.accel_minus_g = telem.sensor.accel_minus_g;
595                                                         ao_flight_started = 1;
596                                                 }
597                                                 type = 'A';
598                                                 a = telem.sensor.accel;
599                                                 b = telem.sensor.pres;
600                                                 break;
601                                         }
602                                 } else if (len == 99) {
603                                         ao_flight_started = 1;
604                                         tick = uint16(bytes, 21);
605                                         ao_flight_ground_accel = int16(bytes, 7);
606                                         ao_config.accel_plus_g = int16(bytes, 17);
607                                         ao_config.accel_minus_g = int16(bytes, 19);
608                                         type = 'A';
609                                         a = int16(bytes, 23);
610                                         b = int16(bytes, 25);
611                                 } else if (len == 98) {
612                                         ao_flight_started = 1;
613                                         tick = uint16(bytes, 20);
614                                         ao_flight_ground_accel = int16(bytes, 6);
615                                         ao_config.accel_plus_g = int16(bytes, 16);
616                                         ao_config.accel_minus_g = int16(bytes, 18);
617                                         type = 'A';
618                                         a = int16(bytes, 22);
619                                         b = int16(bytes, 24);
620                                 } else {
621                                         printf("unknown len %d\n", len);
622                                         continue;
623                                 }
624                         }
625                         if (type != 'F' && !ao_flight_started)
626                                 continue;
627
628                         switch (type) {
629                         case 'F':
630                                 ao_flight_ground_accel = a;
631                                 if (ao_config.accel_plus_g == 0) {
632                                         ao_config.accel_plus_g = a;
633                                         ao_config.accel_minus_g = a + 530;
634                                 }
635                                 if (ao_config.main_deploy == 0)
636                                         ao_config.main_deploy = 250;
637                                 ao_flight_started = 1;
638                                 break;
639                         case 'S':
640                                 break;
641                         case 'A':
642                                 ao_adc_static.tick = tick;
643                                 ao_adc_static.accel = a;
644                                 ao_adc_static.pres_real = b;
645                                 if (b < AO_MIN_BARO_VALUE)
646                                         b = AO_MIN_BARO_VALUE;
647                                 ao_adc_static.pres = b;
648                                 ao_records_read++;
649                                 ao_insert();
650                                 return;
651                         case 'T':
652                                 ao_adc_static.tick = tick;
653                                 ao_adc_static.temp = a;
654                                 ao_adc_static.v_batt = b;
655                                 break;
656                         case 'D':
657                         case 'G':
658                         case 'N':
659                         case 'W':
660                         case 'H':
661                                 break;
662                         }
663                 }
664
665         }
666 }
667 #define COUNTS_PER_G 264.8
668
669 void
670 ao_dump_state(void)
671 {
672 }
673
674 static const struct option options[] = {
675         { .name = "summary", .has_arg = 0, .val = 's' },
676         { .name = "debug", .has_arg = 0, .val = 'd' },
677         { 0, 0, 0, 0},
678 };
679
680 void run_flight_fixed(char *name, FILE *f, int summary)
681 {
682         emulator_name = name;
683         emulator_in = f;
684         ao_summary = summary;
685         ao_flight_init();
686         ao_flight();
687 }
688
689 int
690 main (int argc, char **argv)
691 {
692         int     summary = 0;
693         int     c;
694         int     i;
695
696 #if HAS_ACCEL
697         emulator_app="full";
698 #else
699         emulator_app="baro";
700 #endif
701         while ((c = getopt_long(argc, argv, "sd", options, NULL)) != -1) {
702                 switch (c) {
703                 case 's':
704                         summary = 1;
705                         break;
706                 case 'd':
707                         ao_flight_debug = 1;
708                         break;
709                 }
710         }
711
712         if (optind == argc)
713                 run_flight_fixed("<stdin>", stdin, summary);
714         else
715                 for (i = optind; i < argc; i++) {
716                         FILE    *f = fopen(argv[i], "r");
717                         if (!f) {
718                                 perror(argv[i]);
719                                 continue;
720                         }
721                         run_flight_fixed(argv[i], f, summary);
722                         fclose(f);
723                 }
724 }