2 * Copyright © 2009 Keith Packard <keithp@keithp.com>
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.
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.
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.
29 #define GRAVITY 9.80665
34 #define AO_DATA_RING 64
35 #define ao_data_ring_next(n) (((n) + 1) & (AO_DATA_RING - 1))
36 #define ao_data_ring_prev(n) (((n) - 1) & (AO_DATA_RING - 1))
39 #define AO_M_TO_HEIGHT(m) ((int16_t) (m))
40 #define AO_MS_TO_SPEED(ms) ((int16_t) ((ms) * 16))
41 #define AO_MSS_TO_ACCEL(mss) ((int16_t) ((mss) * 16))
44 #define AO_GPS_NEW_DATA 1
45 #define AO_GPS_NEW_TRACKING 2
49 #if !defined(TELEMEGA) && !defined(TELEMETRUM_V2) && !defined(EASYMINI)
50 #define TELEMETRUM_V1 1
54 #define AO_ADC_NUM_SENSE 6
60 #define AO_CONFIG_MAX_SIZE 1024
61 #define AO_MMA655X_INVERT 0
64 int16_t sense[AO_ADC_NUM_SENSE];
72 #define AO_ADC_NUM_SENSE 2
75 #define AO_MMA655X_INVERT 0
77 #define AO_CONFIG_MAX_SIZE 1024
88 #define AO_ADC_NUM_SENSE 2
91 #define AO_CONFIG_MAX_SIZE 1024
102 * One set of samples read from the A/D converter
105 int16_t accel; /* accelerometer */
106 int16_t pres; /* pressure sensor */
107 int16_t pres_real; /* unclipped */
108 int16_t temp; /* temperature sensor */
109 int16_t v_batt; /* battery voltage */
110 int16_t sense_d; /* drogue continuity sense */
111 int16_t sense_m; /* main continuity sense */
116 #define HAS_ACCEL_REF 0
134 #include <ao_telemetry.h>
135 #include <ao_sample.h>
139 struct ao_telemetry_location ao_gps_first;
140 struct ao_telemetry_location ao_gps_prev;
141 struct ao_telemetry_location ao_gps_static;
143 struct ao_telemetry_satellite ao_gps_tracking;
145 static inline double sqr(double a) { return a * a; }
148 cc_great_circle (double start_lat, double start_lon,
149 double end_lat, double end_lon,
150 double *dist, double *bearing)
152 const double rad = M_PI / 180;
153 const double earth_radius = 6371.2 * 1000; /* in meters */
154 double lat1 = rad * start_lat;
155 double lon1 = rad * -start_lon;
156 double lat2 = rad * end_lat;
157 double lon2 = rad * -end_lon;
159 // double d_lat = lat2 - lat1;
160 double d_lon = lon2 - lon1;
162 /* From http://en.wikipedia.org/wiki/Great-circle_distance */
163 double vdn = sqrt(sqr(cos(lat2) * sin(d_lon)) +
164 sqr(cos(lat1) * sin(lat2) -
165 sin(lat1) * cos(lat2) * cos(d_lon)));
166 double vdd = sin(lat1) * sin(lat2) + cos(lat1) * cos(lat2) * cos(d_lon);
167 double d = atan2(vdn,vdd);
170 if (cos(lat1) < 1e-20) {
179 course = acos((sin(lat2)-sin(lat1)*cos(d)) /
181 if (sin(lon2-lon1) > 0)
182 course = 2 * M_PI-course;
184 *dist = d * earth_radius;
185 *bearing = course * 180/M_PI;
189 ao_distance_from_pad(void)
191 double dist, bearing;
195 cc_great_circle(ao_gps_first.latitude / 1e7,
196 ao_gps_first.longitude / 1e7,
197 ao_gps_static.latitude / 1e7,
198 ao_gps_static.longitude / 1e7,
206 double dist, bearing;
210 if (ao_gps_count < 2)
213 cc_great_circle(ao_gps_prev.latitude / 1e7,
214 ao_gps_prev.longitude / 1e7,
215 ao_gps_static.latitude / 1e7,
216 ao_gps_static.longitude / 1e7,
218 height = AO_TELEMETRY_LOCATION_ALTITUDE(&ao_gps_static) - AO_TELEMETRY_LOCATION_ALTITUDE(&ao_gps_prev);
220 angle = atan2(dist, height);
221 return angle * 180/M_PI;
225 #define to_fix16(x) ((int16_t) ((x) * 65536.0 + 0.5))
226 #define to_fix32(x) ((int32_t) ((x) * 65536.0 + 0.5))
227 #define from_fix(x) ((x) >> 16)
229 #define ACCEL_NOSE_UP (ao_accel_2g >> 2)
231 extern enum ao_flight_state ao_flight_state;
236 volatile struct ao_data ao_data_ring[AO_DATA_RING];
237 volatile uint8_t ao_data_head;
241 #define ao_led_off(l)
242 #define ao_timer_set_adc_interval(i)
243 #define ao_wakeup(wchan) ao_dump_state()
244 #define ao_cmd_register(c)
245 #define ao_usb_disable()
246 #define ao_telemetry_set_interval(x)
247 #define ao_rdf_set(rdf)
248 #define ao_packet_slave_start()
249 #define ao_packet_slave_stop()
253 ao_igniter_drogue = 0,
257 struct ao_data ao_data_static;
266 static ao_k_t ao_k_height;
267 static double simple_speed;
272 return ao_data_static.tick;
276 ao_delay(int16_t interval)
282 ao_ignite(enum ao_igniter igniter)
284 double time = (double) (ao_data_static.tick + tick_offset) / 100;
286 if (igniter == ao_igniter_drogue) {
288 drogue_height = ao_k_height >> 16;
291 main_height = ao_k_height >> 16;
299 #define ao_add_task(t,f,n) ((void) (t))
301 #define ao_log_start()
302 #define ao_log_stop()
304 #define AO_MS_TO_TICKS(ms) ((ms) / 10)
305 #define AO_SEC_TO_TICKS(s) ((s) * 100)
307 #define AO_FLIGHT_TEST
311 struct ao_eeprom *eeprom;
312 uint32_t eeprom_offset;
318 double emulator_error_max = 4;
319 double emulator_height_error_max = 20; /* noise in the baro sensor */
325 ao_sleep(void *wchan);
327 const char * const ao_state_names[] = {
328 "startup", "idle", "pad", "boost", "fast",
329 "coast", "drogue", "main", "landed", "invalid"
337 #define ao_xmemcpy(d,s,c) memcpy(d,s,c)
338 #define ao_xmemset(d,v,c) memset(d,v,c)
339 #define ao_xmemcmp(d,s,c) memcmp(d,s,c)
341 #define AO_NEED_ALTITUDE_TO_PRES 1
342 #if TELEMEGA || TELEMETRUM_V2 || EASYMINI
343 #include "ao_convert_pa.c"
344 #include <ao_ms5607.h>
345 struct ao_ms5607_prom ao_ms5607_prom;
346 #include "ao_ms5607_convert.c"
347 #define AO_PYRO_NUM 4
350 #include "ao_convert.c"
353 #include <ao_config.h>
354 #include <ao_fake_flight.h>
355 #include <ao_eeprom_read.h>
358 #define ao_config_get()
360 struct ao_config ao_config;
362 #define DATA_TO_XDATA(x) (x)
365 extern int16_t ao_ground_accel, ao_flight_accel;
366 extern int16_t ao_accel_2g;
368 typedef int16_t accel_t;
370 uint16_t ao_serial_number;
371 uint16_t ao_flight_number;
373 extern uint16_t ao_sample_tick;
375 extern alt_t ao_sample_height;
376 extern accel_t ao_sample_accel;
377 extern int32_t ao_accel_scale;
378 extern alt_t ao_ground_height;
379 extern alt_t ao_sample_alt;
381 double ao_sample_qangle;
383 int ao_sample_prev_tick;
387 #include "ao_kalman.c"
389 #include "ao_sample.c"
390 #include "ao_flight.c"
392 #define AO_PYRO_NUM 4
402 ao_pyro_pin_set(uint8_t pin, uint8_t value)
404 printf ("set pyro %d %d\n", pin, value);
409 #include "ao_eeprom_read.c"
410 #include "ao_eeprom_read_old.c"
412 #define to_double(f) ((f) / 65536.0)
414 static int ao_records_read = 0;
415 static int ao_eof_read = 0;
417 static int ao_flight_ground_accel;
419 static int ao_flight_started = 0;
420 static int ao_test_max_height;
421 static double ao_test_max_height_time;
422 static int ao_test_main_height;
423 static double ao_test_main_height_time;
424 static double ao_test_landed_time;
425 static double ao_test_landed_height;
426 static double ao_test_landed_time;
427 static int landed_set;
428 static double landed_time;
429 static double landed_height;
432 static struct ao_mpu6000_sample ao_ground_mpu6000;
436 int ao_error_h_sq_avg;
445 double landed_time_error;
447 if (!ao_test_main_height_time) {
448 ao_test_main_height_time = ao_test_max_height_time;
449 ao_test_main_height = ao_test_max_height;
451 drogue_error = fabs(ao_test_max_height_time - drogue_time);
452 main_error = fabs(ao_test_main_height_time - main_time);
453 landed_error = fabs(ao_test_landed_height - landed_height);
454 landed_time_error = ao_test_landed_time - landed_time;
455 if (drogue_error > emulator_error_max || main_error > emulator_error_max) {
457 emulator_app, emulator_name);
459 printf ("\t%s\n", emulator_info);
460 printf ("\tApogee error %g\n", drogue_error);
461 printf ("\tMain error %g\n", main_error);
462 printf ("\tLanded height error %g\n", landed_error);
463 printf ("\tLanded time error %g\n", landed_time_error);
464 printf ("\tActual: apogee: %d at %7.2f main: %d at %7.2f landed %7.2f at %7.2f\n",
465 ao_test_max_height, ao_test_max_height_time,
466 ao_test_main_height, ao_test_main_height_time,
467 ao_test_landed_height, ao_test_landed_time);
468 printf ("\tComputed: apogee: %d at %7.2f main: %d at %7.2f landed %7.2f at %7.2f\n",
469 drogue_height, drogue_time, main_height, main_time,
470 landed_height, landed_time);
483 azel (struct ao_azel *r, struct ao_quaternion *q)
487 r->az = floor (atan2(q->y, q->x) * 180/M_PI + 0.5);
488 v = sqrt (q->x*q->x + q->y*q->y);
489 r->el = floor (atan2(q->z, v) * 180/M_PI + 0.5);
498 ao_data_ring[ao_data_head] = ao_data_static;
499 if (ao_flight_state != ao_flight_startup) {
501 double accel = ((ao_flight_ground_accel - ao_data_accel_cook(&ao_data_static)) * GRAVITY * 2.0) /
502 (ao_config.accel_minus_g - ao_config.accel_plus_g);
509 tick_offset = -ao_data_static.tick;
510 if ((prev_tick - ao_data_static.tick) > 0x400)
511 tick_offset += 65536;
512 simple_speed += accel * (ao_data_static.tick - prev_tick) / 100.0;
513 prev_tick = ao_data_static.tick;
514 time = (double) (ao_data_static.tick + tick_offset) / 100;
516 #if TELEMEGA || TELEMETRUM_V2 || EASYMINI
517 ao_ms5607_convert(&ao_data_static.ms5607_raw, &ao_data_static.ms5607_cooked);
518 double height = ao_pa_to_altitude(ao_data_static.ms5607_cooked.pres) - ao_ground_height;
520 /* Hack to skip baro spike at accidental drogue charge
521 * firing in 2015-09-26-serial-2093-flight-0012.eeprom
522 * so we can test the kalman filter with this data. Just
523 * keep reporting the same baro value across the pressure spike
526 static struct ao_ms5607_sample save;
527 if (ao_serial_number == 2093 && ao_flight_number == 12 && 32.5 < time && time < 33.7) {
528 ao_data_ring[ao_data_head].ms5607_raw = save;
530 save = ao_data_static.ms5607_raw;
534 double height = ao_pres_to_altitude(ao_data_static.adc.pres_real) - ao_ground_height;
537 if (ao_test_max_height < height) {
538 ao_test_max_height = height;
539 ao_test_max_height_time = time;
540 ao_test_landed_height = height;
541 ao_test_landed_time = time;
543 if (height > ao_config.main_deploy) {
544 ao_test_main_height_time = time;
545 ao_test_main_height = height;
548 if (ao_test_landed_height > height) {
549 ao_test_landed_height = height;
550 ao_test_landed_time = time;
553 if (ao_flight_state == ao_flight_landed && !landed_set) {
556 landed_height = height;
561 static struct ao_quaternion ao_ground_mag;
562 static int ao_ground_mag_set;
564 if (!ao_ground_mag_set) {
565 ao_quaternion_init_vector (&ao_ground_mag,
566 ao_data_mag_across(&ao_data_static),
567 ao_data_mag_through(&ao_data_static),
568 ao_data_mag_along(&ao_data_static));
569 ao_quaternion_normalize(&ao_ground_mag, &ao_ground_mag);
570 ao_quaternion_rotate(&ao_ground_mag, &ao_ground_mag, &ao_rotation);
571 ao_ground_mag_set = 1;
574 struct ao_quaternion ao_mag, ao_mag_rot;
576 ao_quaternion_init_vector(&ao_mag,
577 ao_data_mag_across(&ao_data_static),
578 ao_data_mag_through(&ao_data_static),
579 ao_data_mag_along(&ao_data_static));
581 ao_quaternion_normalize(&ao_mag, &ao_mag);
582 ao_quaternion_rotate(&ao_mag_rot, &ao_mag, &ao_rotation);
587 ao_dot = ao_quaternion_dot(&ao_mag_rot, &ao_ground_mag);
589 struct ao_azel ground_azel, mag_azel, rot_azel;
591 azel(&ground_azel, &ao_ground_mag);
592 azel(&mag_azel, &ao_mag);
593 azel(&rot_azel, &ao_mag_rot);
595 ao_mag_angle = floor (acos(ao_dot) * 180 / M_PI + 0.5);
599 static struct ao_quaternion ao_x = { .r = 0, .x = 1, .y = 0, .z = 0 };
600 struct ao_quaternion ao_out;
602 ao_quaternion_rotate(&ao_out, &ao_x, &ao_rotation);
605 int out = floor (atan2(ao_out.y, ao_out.x) * 180 / M_PI);
607 printf ("%7.2f state %-8.8s height %8.4f tilt %4d rot %4d mag_tilt %4d mag_rot %4d\n",
609 ao_state_names[ao_flight_state],
610 ao_k_height / 65536.0,
611 ao_sample_orient, out,
616 printf ("%7.2f state %-8.8s height %8.4f tilt %4d rot %4d dist %12.2f gps_tilt %4d gps_sats %2d\n",
618 ao_state_names[ao_flight_state],
619 ao_k_height / 65536.0,
620 ao_sample_orient, out,
621 ao_distance_from_pad(),
622 (int) floor (ao_gps_angle() + 0.5),
623 (ao_gps_static.flags & 0xf) * 10);
627 printf ("\t\tstate %-8.8s ground az: %4d el %4d mag az %4d el %4d rot az %4d el %4d el_diff %4d az_diff %4d angle %4d tilt %4d ground %8.5f %8.5f %8.5f cur %8.5f %8.5f %8.5f rot %8.5f %8.5f %8.5f\n",
628 ao_state_names[ao_flight_state],
629 ground_azel.az, ground_azel.el,
630 mag_azel.az, mag_azel.el,
631 rot_azel.az, rot_azel.el,
632 ground_azel.el - rot_azel.el,
633 ground_azel.az - rot_azel.az,
649 printf("%7.2f height %8.2f accel %8.3f accel_speed %8.3f "
650 "state %-8.8s k_height %8.2f k_speed %8.3f k_accel %8.3f avg_height %5d drogue %4d main %4d error %5d"
653 "accel_x %8.3f accel_y %8.3f accel_z %8.3f gyro_x %8.3f gyro_y %8.3f gyro_z %8.3f mag_x %8d mag_y %8d, mag_z %8d mag_angle %4d "
659 simple_speed > -100.0 ? simple_speed : -100.0,
660 ao_state_names[ao_flight_state],
661 ao_k_height / 65536.0,
662 ao_k_speed / 65536.0 / 16.0,
663 ao_k_accel / 65536.0 / 16.0,
671 ao_mpu6000_accel(ao_data_static.mpu6000.accel_x),
672 ao_mpu6000_accel(ao_data_static.mpu6000.accel_y),
673 ao_mpu6000_accel(ao_data_static.mpu6000.accel_z),
674 ao_mpu6000_gyro(ao_data_static.mpu6000.gyro_x - ao_ground_mpu6000.gyro_x),
675 ao_mpu6000_gyro(ao_data_static.mpu6000.gyro_y - ao_ground_mpu6000.gyro_y),
676 ao_mpu6000_gyro(ao_data_static.mpu6000.gyro_z - ao_ground_mpu6000.gyro_z),
677 ao_data_static.hmc5883.x,
678 ao_data_static.hmc5883.y,
679 ao_data_static.hmc5883.z,
685 // if (ao_flight_state == ao_flight_landed)
689 ao_data_head = ao_data_ring_next(ao_data_head);
694 uint16(uint8_t *bytes, int off)
696 return (uint16_t) bytes[off] | (((uint16_t) bytes[off+1]) << 8);
700 int16(uint8_t *bytes, int off)
702 return (int16_t) uint16(bytes, off);
706 uint32(uint8_t *bytes, int off)
708 return (uint32_t) bytes[off] | (((uint32_t) bytes[off+1]) << 8) |
709 (((uint32_t) bytes[off+2]) << 16) |
710 (((uint32_t) bytes[off+3]) << 24);
714 int32(uint8_t *bytes, int off)
716 return (int32_t) uint32(bytes, off);
720 uint24(uint8_t *bytes, int off)
722 return (uint32_t) bytes[off] | (((uint32_t) bytes[off+1]) << 8) |
723 (((uint32_t) bytes[off+2]) << 16);
727 int24(uint8_t *bytes, int off)
729 return (int32_t) uint24(bytes, off);
732 static int log_format;
735 ao_sleep(void *wchan)
737 if (wchan == &ao_data_head) {
739 if (ao_flight_state >= ao_flight_boost && ao_flight_state < ao_flight_landed)
743 if (ao_records_read > 2 && ao_flight_state == ao_flight_startup)
747 ao_data_static.mpu6000 = ao_ground_mpu6000;
750 ao_data_static.adc.accel = ao_flight_ground_accel;
759 struct ao_log_mega *log_mega;
762 struct ao_log_metrum *log_metrum;
765 struct ao_log_mini *log_mini;
768 struct ao_log_record *log_record;
771 if (eeprom_offset >= eeprom->len) {
772 if (++ao_eof_read >= 1000)
774 printf ("no more data, exiting simulation\n");
776 ao_data_static.tick += 10;
780 switch (eeprom->log_format) {
782 case AO_LOG_FORMAT_TELEMEGA_OLD:
783 case AO_LOG_FORMAT_TELEMEGA:
784 log_mega = (struct ao_log_mega *) &eeprom->data[eeprom_offset];
785 eeprom_offset += sizeof (*log_mega);
786 switch (log_mega->type) {
788 ao_flight_number = log_mega->u.flight.flight;
789 ao_flight_ground_accel = log_mega->u.flight.ground_accel;
790 ao_flight_started = 1;
791 ao_ground_pres = log_mega->u.flight.ground_pres;
792 ao_ground_height = ao_pa_to_altitude(ao_ground_pres);
793 ao_ground_accel_along = log_mega->u.flight.ground_accel_along;
794 ao_ground_accel_across = log_mega->u.flight.ground_accel_across;
795 ao_ground_accel_through = log_mega->u.flight.ground_accel_through;
796 ao_ground_roll = log_mega->u.flight.ground_roll;
797 ao_ground_pitch = log_mega->u.flight.ground_pitch;
798 ao_ground_yaw = log_mega->u.flight.ground_yaw;
799 ao_ground_mpu6000.accel_x = ao_ground_accel_across;
800 ao_ground_mpu6000.accel_y = ao_ground_accel_along;
801 ao_ground_mpu6000.accel_z = ao_ground_accel_through;
802 ao_ground_mpu6000.gyro_x = ao_ground_pitch >> 9;
803 ao_ground_mpu6000.gyro_y = ao_ground_roll >> 9;
804 ao_ground_mpu6000.gyro_z = ao_ground_yaw >> 9;
809 ao_data_static.tick = log_mega->tick;
810 ao_data_static.ms5607_raw.pres = log_mega->u.sensor.pres;
811 ao_data_static.ms5607_raw.temp = log_mega->u.sensor.temp;
812 ao_data_static.mpu6000.accel_x = log_mega->u.sensor.accel_x;
813 ao_data_static.mpu6000.accel_y = log_mega->u.sensor.accel_y;
814 ao_data_static.mpu6000.accel_z = log_mega->u.sensor.accel_z;
815 ao_data_static.mpu6000.gyro_x = log_mega->u.sensor.gyro_x;
816 ao_data_static.mpu6000.gyro_y = log_mega->u.sensor.gyro_y;
817 ao_data_static.mpu6000.gyro_z = log_mega->u.sensor.gyro_z;
818 ao_data_static.hmc5883.x = log_mega->u.sensor.mag_x;
819 ao_data_static.hmc5883.y = log_mega->u.sensor.mag_y;
820 ao_data_static.hmc5883.z = log_mega->u.sensor.mag_z;
821 ao_data_static.mma655x = log_mega->u.sensor.accel;
822 if (ao_config.pad_orientation != AO_PAD_ORIENTATION_ANTENNA_UP)
823 ao_data_static.mma655x = ao_data_accel_invert(ao_data_static.mma655x);
827 case AO_LOG_TEMP_VOLT:
829 case AO_LOG_GPS_TIME:
830 ao_gps_prev = ao_gps_static;
831 ao_gps_static.tick = log_mega->tick;
832 ao_gps_static.latitude = log_mega->u.gps.latitude;
833 ao_gps_static.longitude = log_mega->u.gps.longitude;
835 int16_t altitude_low = log_mega->u.gps.altitude_low;
836 int16_t altitude_high = log_mega->u.gps.altitude_high;
837 int32_t altitude = altitude_low | ((int32_t) altitude_high << 16);
839 AO_TELEMETRY_LOCATION_SET_ALTITUDE(&ao_gps_static, altitude);
841 ao_gps_static.flags = log_mega->u.gps.flags;
843 ao_gps_first = ao_gps_static;
852 case AO_LOG_FORMAT_TELEMETRUM:
853 log_metrum = (struct ao_log_metrum *) &eeprom->data[eeprom_offset];
854 eeprom_offset += sizeof (*log_metrum);
855 switch (log_metrum->type) {
857 ao_flight_started = 1;
858 ao_flight_number = log_metrum->u.flight.flight;
859 ao_flight_ground_accel = log_metrum->u.flight.ground_accel;
860 ao_ground_pres = log_metrum->u.flight.ground_pres;
861 ao_ground_height = ao_pa_to_altitude(ao_ground_pres);
864 ao_data_static.tick = log_metrum->tick;
865 ao_data_static.ms5607_raw.pres = log_metrum->u.sensor.pres;
866 ao_data_static.ms5607_raw.temp = log_metrum->u.sensor.temp;
867 ao_data_static.mma655x = log_metrum->u.sensor.accel;
875 case AO_LOG_FORMAT_EASYMINI1:
876 case AO_LOG_FORMAT_EASYMINI2:
877 case AO_LOG_FORMAT_TELEMINI3:
878 log_mini = (struct ao_log_mini *) &eeprom->data[eeprom_offset];
879 eeprom_offset += sizeof (*log_mini);
880 switch (log_mini->type) {
882 ao_flight_started = 1;
883 ao_flight_number = log_mini->u.flight.flight;
884 ao_ground_pres = log_mini->u.flight.ground_pres;
885 ao_ground_height = ao_pa_to_altitude(ao_ground_pres);
888 ao_data_static.tick = log_mini->tick;
889 ao_data_static.ms5607_raw.pres = int24(log_mini->u.sensor.pres, 0);
890 ao_data_static.ms5607_raw.temp = int24(log_mini->u.sensor.temp, 0);
898 case AO_LOG_FORMAT_FULL:
899 case AO_LOG_FORMAT_TINY:
900 log_record = (struct ao_log_record *) &eeprom->data[eeprom_offset];
901 eeprom_offset += sizeof (*log_record);
902 switch (log_record->type) {
904 ao_flight_started = 1;
905 ao_flight_ground_accel = log_record->u.flight.ground_accel;
906 ao_flight_number = log_record->u.flight.flight;
909 case 'P': /* ancient telemini */
910 ao_data_static.tick = log_record->tick;
911 ao_data_static.adc.accel = log_record->u.sensor.accel;
912 ao_data_static.adc.pres_real = log_record->u.sensor.pres;
913 ao_data_static.adc.pres = log_record->u.sensor.pres;
917 case AO_LOG_TEMP_VOLT:
918 ao_data_static.tick = log_record->tick;;
919 ao_data_static.adc.temp = log_record->u.temp_volt.temp;
920 ao_data_static.adc.v_batt = log_record->u.temp_volt.v_batt;
926 printf ("invalid log format %d\n", log_format);
934 #define COUNTS_PER_G 264.8
941 static const struct option options[] = {
942 { .name = "summary", .has_arg = 0, .val = 's' },
943 { .name = "debug", .has_arg = 0, .val = 'd' },
944 { .name = "info", .has_arg = 1, .val = 'i' },
948 void run_flight_fixed(char *name, FILE *f, int summary, char *info)
950 emulator_name = name;
952 emulator_info = info;
953 ao_summary = summary;
955 if (strstr(name, ".eeprom") != NULL) {
961 eeprom = ao_eeprom_read(f);
963 eeprom = ao_eeprom_read_old(f);
967 ao_ms5607_prom = eeprom->ms5607_prom;
969 ao_config = eeprom->config;
970 ao_serial_number = eeprom->serial_number;
971 log_format = eeprom->log_format;
980 main (int argc, char **argv)
992 while ((c = getopt_long(argc, argv, "sdi:", options, NULL)) != -1) {
1007 run_flight_fixed("<stdin>", stdin, summary, info);
1009 for (i = optind; i < argc; i++) {
1010 FILE *f = fopen(argv[i], "r");
1015 run_flight_fixed(argv[i], f, summary, info);