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