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.
28 #define log ao_log_data
30 #define GRAVITY 9.80665
35 #define AO_DATA_RING 64
36 #define ao_data_ring_next(n) (((n) + 1) & (AO_DATA_RING - 1))
37 #define ao_data_ring_prev(n) (((n) - 1) & (AO_DATA_RING - 1))
40 #define AO_M_TO_HEIGHT(m) ((int16_t) (m))
41 #define AO_MS_TO_SPEED(ms) ((int16_t) ((ms) * 16))
42 #define AO_MSS_TO_ACCEL(mss) ((int16_t) ((mss) * 16))
45 #define AO_GPS_NEW_DATA 1
46 #define AO_GPS_NEW_TRACKING 2
50 #if !defined(TELEMEGA) && !defined(TELEMETRUM_V2) && !defined(EASYMINI)
51 #define TELEMETRUM_V1 1
55 #define AO_ADC_NUM_SENSE 6
61 #define AO_CONFIG_MAX_SIZE 1024
62 #define AO_MMA655X_INVERT 0
65 int16_t sense[AO_ADC_NUM_SENSE];
73 #define AO_ADC_NUM_SENSE 2
76 #define AO_MMA655X_INVERT 0
78 #define AO_CONFIG_MAX_SIZE 1024
89 #define AO_ADC_NUM_SENSE 2
92 #define AO_CONFIG_MAX_SIZE 1024
103 * One set of samples read from the A/D converter
106 int16_t accel; /* accelerometer */
107 int16_t pres; /* pressure sensor */
108 int16_t pres_real; /* unclipped */
109 int16_t temp; /* temperature sensor */
110 int16_t v_batt; /* battery voltage */
111 int16_t sense_d; /* drogue continuity sense */
112 int16_t sense_m; /* main continuity sense */
117 #define HAS_ACCEL_REF 0
135 #include <ao_telemetry.h>
136 #include <ao_sample.h>
140 struct ao_telemetry_location ao_gps_first;
141 struct ao_telemetry_location ao_gps_prev;
142 struct ao_telemetry_location ao_gps_static;
144 struct ao_telemetry_satellite ao_gps_tracking;
146 static inline double sqr(double a) { return a * a; }
149 cc_great_circle (double start_lat, double start_lon,
150 double end_lat, double end_lon,
151 double *dist, double *bearing)
153 const double rad = M_PI / 180;
154 const double earth_radius = 6371.2 * 1000; /* in meters */
155 double lat1 = rad * start_lat;
156 double lon1 = rad * -start_lon;
157 double lat2 = rad * end_lat;
158 double lon2 = rad * -end_lon;
160 // double d_lat = lat2 - lat1;
161 double d_lon = lon2 - lon1;
163 /* From http://en.wikipedia.org/wiki/Great-circle_distance */
164 double vdn = sqrt(sqr(cos(lat2) * sin(d_lon)) +
165 sqr(cos(lat1) * sin(lat2) -
166 sin(lat1) * cos(lat2) * cos(d_lon)));
167 double vdd = sin(lat1) * sin(lat2) + cos(lat1) * cos(lat2) * cos(d_lon);
168 double d = atan2(vdn,vdd);
171 if (cos(lat1) < 1e-20) {
180 course = acos((sin(lat2)-sin(lat1)*cos(d)) /
182 if (sin(lon2-lon1) > 0)
183 course = 2 * M_PI-course;
185 *dist = d * earth_radius;
186 *bearing = course * 180/M_PI;
190 ao_distance_from_pad(void)
192 double dist, bearing;
196 cc_great_circle(ao_gps_first.latitude / 1e7,
197 ao_gps_first.longitude / 1e7,
198 ao_gps_static.latitude / 1e7,
199 ao_gps_static.longitude / 1e7,
207 double dist, bearing;
211 if (ao_gps_count < 2)
214 cc_great_circle(ao_gps_prev.latitude / 1e7,
215 ao_gps_prev.longitude / 1e7,
216 ao_gps_static.latitude / 1e7,
217 ao_gps_static.longitude / 1e7,
219 height = AO_TELEMETRY_LOCATION_ALTITUDE(&ao_gps_static) - AO_TELEMETRY_LOCATION_ALTITUDE(&ao_gps_prev);
221 angle = atan2(dist, height);
222 return angle * 180/M_PI;
226 #define to_fix16(x) ((int16_t) ((x) * 65536.0 + 0.5))
227 #define to_fix32(x) ((int32_t) ((x) * 65536.0 + 0.5))
228 #define from_fix(x) ((x) >> 16)
230 #define ACCEL_NOSE_UP (ao_accel_2g >> 2)
232 extern enum ao_flight_state ao_flight_state;
237 volatile struct ao_data ao_data_ring[AO_DATA_RING];
238 volatile uint8_t ao_data_head;
242 #define ao_led_off(l)
243 #define ao_timer_set_adc_interval(i)
244 #define ao_wakeup(wchan) ao_dump_state()
245 #define ao_cmd_register(c)
246 #define ao_usb_disable()
247 #define ao_telemetry_set_interval(x)
248 #define ao_rdf_set(rdf)
249 #define ao_packet_slave_start()
250 #define ao_packet_slave_stop()
254 ao_igniter_drogue = 0,
258 struct ao_data ao_data_static;
267 static ao_k_t ao_k_height;
268 static double simple_speed;
273 return ao_data_static.tick;
277 ao_delay(int16_t interval)
283 ao_ignite(enum ao_igniter igniter)
285 double time = (double) (ao_data_static.tick + tick_offset) / 100;
287 if (igniter == ao_igniter_drogue) {
289 drogue_height = ao_k_height >> 16;
292 main_height = ao_k_height >> 16;
300 #define ao_add_task(t,f,n) ((void) (t))
302 #define ao_log_start()
303 #define ao_log_stop()
305 #define AO_MS_TO_TICKS(ms) ((ms) / 10)
306 #define AO_SEC_TO_TICKS(s) ((s) * 100)
308 #define AO_FLIGHT_TEST
312 struct ao_eeprom *eeprom;
313 uint32_t eeprom_offset;
319 double emulator_error_max = 4;
320 double emulator_height_error_max = 20; /* noise in the baro sensor */
326 ao_sleep(void *wchan);
328 const char * const ao_state_names[] = {
329 "startup", "idle", "pad", "boost", "fast",
330 "coast", "drogue", "main", "landed", "invalid"
338 #define ao_xmemcpy(d,s,c) memcpy(d,s,c)
339 #define ao_xmemset(d,v,c) memset(d,v,c)
340 #define ao_xmemcmp(d,s,c) memcmp(d,s,c)
342 #define AO_NEED_ALTITUDE_TO_PRES 1
343 #if TELEMEGA || TELEMETRUM_V2 || EASYMINI
344 #include "ao_convert_pa.c"
345 #include <ao_ms5607.h>
346 struct ao_ms5607_prom ao_ms5607_prom;
347 #include "ao_ms5607_convert.c"
349 #define AO_PYRO_NUM 4
353 #include "ao_convert.c"
356 #include <ao_config.h>
357 #include <ao_fake_flight.h>
358 #include <ao_eeprom_read.h>
361 #define ao_config_get()
363 struct ao_config ao_config;
365 #define DATA_TO_XDATA(x) (x)
368 extern int16_t ao_ground_accel, ao_flight_accel;
369 extern int16_t ao_accel_2g;
371 typedef int16_t accel_t;
373 uint16_t ao_serial_number;
374 int16_t ao_flight_number;
376 extern uint16_t ao_sample_tick;
378 extern alt_t ao_sample_height;
379 extern accel_t ao_sample_accel;
380 extern int32_t ao_accel_scale;
381 extern alt_t ao_ground_height;
382 extern alt_t ao_sample_alt;
384 double ao_sample_qangle;
386 int ao_sample_prev_tick;
390 #include "ao_kalman.c"
392 #include "ao_sample.c"
393 #include "ao_flight.c"
395 #define AO_PYRO_NUM 4
405 ao_pyro_pin_set(uint8_t pin, uint8_t value)
407 printf ("set pyro %d %d\n", pin, value);
412 #include "ao_eeprom_read.c"
413 #include "ao_eeprom_read_old.c"
415 #define to_double(f) ((f) / 65536.0)
417 static int ao_records_read = 0;
418 static int ao_eof_read = 0;
420 static int ao_flight_ground_accel;
422 static int ao_flight_started = 0;
423 static int ao_test_max_height;
424 static double ao_test_max_height_time;
425 static int ao_test_main_height;
426 static double ao_test_main_height_time;
427 static double ao_test_landed_time;
428 static double ao_test_landed_height;
429 static double ao_test_landed_time;
430 static int landed_set;
431 static double landed_time;
432 static double landed_height;
434 static uint16_t pyros_fired;
438 static struct ao_mpu6000_sample ao_ground_mpu6000;
442 int ao_error_h_sq_avg;
451 double landed_time_error;
453 if (!ao_test_main_height_time) {
454 ao_test_main_height_time = ao_test_max_height_time;
455 ao_test_main_height = ao_test_max_height;
457 drogue_error = fabs(ao_test_max_height_time - drogue_time);
458 main_error = fabs(ao_test_main_height_time - main_time);
459 landed_error = fabs(ao_test_landed_height - landed_height);
460 landed_time_error = ao_test_landed_time - landed_time;
461 if (drogue_error > emulator_error_max || main_error > emulator_error_max) {
463 emulator_app, emulator_name);
465 printf ("\t%s\n", emulator_info);
466 printf ("\tApogee error %g\n", drogue_error);
467 printf ("\tMain error %g\n", main_error);
468 printf ("\tLanded height error %g\n", landed_error);
469 printf ("\tLanded time error %g\n", landed_time_error);
470 printf ("\tActual: apogee: %d at %7.2f main: %d at %7.2f landed %7.2f at %7.2f\n",
471 ao_test_max_height, ao_test_max_height_time,
472 ao_test_main_height, ao_test_main_height_time,
473 ao_test_landed_height, ao_test_landed_time);
474 printf ("\tComputed: apogee: %d at %7.2f main: %d at %7.2f landed %7.2f at %7.2f\n",
475 drogue_height, drogue_time, main_height, main_time,
476 landed_height, landed_time);
489 azel (struct ao_azel *r, struct ao_quaternion *q)
493 r->az = floor (atan2(q->y, q->x) * 180/M_PI + 0.5);
494 v = sqrt (q->x*q->x + q->y*q->y);
495 r->el = floor (atan2(q->z, v) * 180/M_PI + 0.5);
504 ao_data_ring[ao_data_head] = ao_data_static;
505 if (ao_flight_state != ao_flight_startup) {
507 double accel = ((ao_flight_ground_accel - ao_data_accel(&ao_data_static)) * GRAVITY * 2.0) /
508 (ao_config.accel_minus_g - ao_config.accel_plus_g);
515 tick_offset = -ao_data_static.tick;
516 if ((prev_tick - ao_data_static.tick) > 0x400)
517 tick_offset += 65536;
519 int ticks = ao_data_static.tick - prev_tick;
522 simple_speed += accel * ticks / 100.0;
524 prev_tick = ao_data_static.tick;
525 time = (double) (ao_data_static.tick + tick_offset) / 100;
527 #if TELEMEGA || TELEMETRUM_V2 || EASYMINI
528 ao_ms5607_convert(&ao_data_static.ms5607_raw, &ao_data_static.ms5607_cooked);
529 double height = ao_pa_to_altitude(ao_data_static.ms5607_cooked.pres) - ao_ground_height;
531 /* Hack to skip baro spike at accidental drogue charge
532 * firing in 2015-09-26-serial-2093-flight-0012.eeprom
533 * so we can test the kalman filter with this data. Just
534 * keep reporting the same baro value across the pressure spike
537 static struct ao_ms5607_sample save;
538 if (ao_serial_number == 2093 && ao_flight_number == 12 && 32.5 < time && time < 33.7) {
539 ao_data_ring[ao_data_head].ms5607_raw = save;
541 save = ao_data_static.ms5607_raw;
545 double height = ao_pres_to_altitude(ao_data_static.adc.pres_real) - ao_ground_height;
548 if (ao_test_max_height < height) {
549 ao_test_max_height = height;
550 ao_test_max_height_time = time;
551 ao_test_landed_height = height;
552 ao_test_landed_time = time;
554 if (height > ao_config.main_deploy) {
555 ao_test_main_height_time = time;
556 ao_test_main_height = height;
559 if (ao_test_landed_height > height) {
560 ao_test_landed_height = height;
561 ao_test_landed_time = time;
564 if (ao_flight_state == ao_flight_landed && !landed_set) {
567 landed_height = height;
572 static struct ao_quaternion ao_ground_mag;
573 static int ao_ground_mag_set;
575 if (!ao_ground_mag_set) {
576 ao_quaternion_init_vector (&ao_ground_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));
580 ao_quaternion_normalize(&ao_ground_mag, &ao_ground_mag);
581 ao_quaternion_rotate(&ao_ground_mag, &ao_ground_mag, &ao_rotation);
582 ao_ground_mag_set = 1;
585 struct ao_quaternion ao_mag, ao_mag_rot;
587 ao_quaternion_init_vector(&ao_mag,
588 ao_data_mag_across(&ao_data_static),
589 ao_data_mag_through(&ao_data_static),
590 ao_data_mag_along(&ao_data_static));
592 ao_quaternion_normalize(&ao_mag, &ao_mag);
593 ao_quaternion_rotate(&ao_mag_rot, &ao_mag, &ao_rotation);
598 ao_dot = ao_quaternion_dot(&ao_mag_rot, &ao_ground_mag);
600 struct ao_azel ground_azel, mag_azel, rot_azel;
602 azel(&ground_azel, &ao_ground_mag);
603 azel(&mag_azel, &ao_mag);
604 azel(&rot_azel, &ao_mag_rot);
606 ao_mag_angle = floor (acos(ao_dot) * 180 / M_PI + 0.5);
610 static struct ao_quaternion ao_x = { .r = 0, .x = 1, .y = 0, .z = 0 };
611 struct ao_quaternion ao_out;
613 ao_quaternion_rotate(&ao_out, &ao_x, &ao_rotation);
616 int out = floor (atan2(ao_out.y, ao_out.x) * 180 / M_PI);
618 printf ("%7.2f state %-8.8s height %8.4f tilt %4d rot %4d mag_tilt %4d mag_rot %4d\n",
620 ao_state_names[ao_flight_state],
621 ao_k_height / 65536.0,
622 ao_sample_orient, out,
627 printf ("%7.2f state %-8.8s height %8.4f tilt %4d rot %4d dist %12.2f gps_tilt %4d gps_sats %2d\n",
629 ao_state_names[ao_flight_state],
630 ao_k_height / 65536.0,
631 ao_sample_orient, out,
632 ao_distance_from_pad(),
633 (int) floor (ao_gps_angle() + 0.5),
634 (ao_gps_static.flags & 0xf) * 10);
638 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",
639 ao_state_names[ao_flight_state],
640 ground_azel.az, ground_azel.el,
641 mag_azel.az, mag_azel.el,
642 rot_azel.az, rot_azel.el,
643 ground_azel.el - rot_azel.el,
644 ground_azel.az - rot_azel.az,
660 printf("%7.2f height %8.2f accel %8.3f accel_speed %8.3f "
661 "state %d k_height %8.2f k_speed %8.3f k_accel %8.3f avg_height %5d drogue %4d main %4d error %5d"
664 "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 "
670 simple_speed > -100.0 ? simple_speed : -100.0,
671 ao_flight_state * 10,
672 ao_k_height / 65536.0,
673 ao_k_speed / 65536.0 / 16.0,
674 ao_k_accel / 65536.0 / 16.0,
682 ao_mpu6000_accel(ao_data_static.mpu6000.accel_x),
683 ao_mpu6000_accel(ao_data_static.mpu6000.accel_y),
684 ao_mpu6000_accel(ao_data_static.mpu6000.accel_z),
685 ao_mpu6000_gyro(ao_data_static.mpu6000.gyro_x - ao_ground_mpu6000.gyro_x),
686 ao_mpu6000_gyro(ao_data_static.mpu6000.gyro_y - ao_ground_mpu6000.gyro_y),
687 ao_mpu6000_gyro(ao_data_static.mpu6000.gyro_z - ao_ground_mpu6000.gyro_z),
688 ao_data_static.hmc5883.x,
689 ao_data_static.hmc5883.y,
690 ao_data_static.hmc5883.z,
696 // if (ao_flight_state == ao_flight_landed)
700 ao_data_head = ao_data_ring_next(ao_data_head);
705 uint16(uint8_t *bytes, int off)
707 return (uint16_t) bytes[off] | (((uint16_t) bytes[off+1]) << 8);
711 int16(uint8_t *bytes, int off)
713 return (int16_t) uint16(bytes, off);
717 uint32(uint8_t *bytes, int off)
719 return (uint32_t) bytes[off] | (((uint32_t) bytes[off+1]) << 8) |
720 (((uint32_t) bytes[off+2]) << 16) |
721 (((uint32_t) bytes[off+3]) << 24);
725 int32(uint8_t *bytes, int off)
727 return (int32_t) uint32(bytes, off);
731 uint24(uint8_t *bytes, int off)
733 return (uint32_t) bytes[off] | (((uint32_t) bytes[off+1]) << 8) |
734 (((uint32_t) bytes[off+2]) << 16);
738 int24(uint8_t *bytes, int off)
740 return (int32_t) uint24(bytes, off);
743 static int log_format;
746 ao_sleep(void *wchan)
748 if (wchan == &ao_data_head) {
750 if (ao_flight_state >= ao_flight_boost && ao_flight_state < ao_flight_landed)
754 if (ao_records_read > 2 && ao_flight_state == ao_flight_startup)
758 ao_data_static.mpu6000 = ao_ground_mpu6000;
761 ao_data_static.adc.accel = ao_flight_ground_accel;
770 struct ao_log_mega *log_mega;
773 struct ao_log_metrum *log_metrum;
776 struct ao_log_mini *log_mini;
779 struct ao_log_record *log_record;
782 if (eeprom_offset >= eeprom->len) {
783 if (++ao_eof_read >= 1000)
785 printf ("no more data, exiting simulation\n");
787 ao_data_static.tick += 10;
791 switch (eeprom->log_format) {
793 case AO_LOG_FORMAT_TELEMEGA_OLD:
794 case AO_LOG_FORMAT_TELEMEGA:
795 log_mega = (struct ao_log_mega *) &eeprom->data[eeprom_offset];
796 eeprom_offset += sizeof (*log_mega);
797 switch (log_mega->type) {
799 ao_flight_number = log_mega->u.flight.flight;
800 ao_flight_ground_accel = log_mega->u.flight.ground_accel;
801 ao_flight_started = 1;
802 ao_ground_pres = log_mega->u.flight.ground_pres;
803 ao_ground_height = ao_pa_to_altitude(ao_ground_pres);
804 ao_ground_accel_along = log_mega->u.flight.ground_accel_along;
805 ao_ground_accel_across = log_mega->u.flight.ground_accel_across;
806 ao_ground_accel_through = log_mega->u.flight.ground_accel_through;
807 ao_ground_roll = log_mega->u.flight.ground_roll;
808 ao_ground_pitch = log_mega->u.flight.ground_pitch;
809 ao_ground_yaw = log_mega->u.flight.ground_yaw;
810 ao_ground_mpu6000.accel_x = ao_ground_accel_across;
811 ao_ground_mpu6000.accel_y = ao_ground_accel_along;
812 ao_ground_mpu6000.accel_z = ao_ground_accel_through;
813 ao_ground_mpu6000.gyro_x = ao_ground_pitch >> 9;
814 ao_ground_mpu6000.gyro_y = ao_ground_roll >> 9;
815 ao_ground_mpu6000.gyro_z = ao_ground_yaw >> 9;
820 ao_data_static.tick = log_mega->tick;
821 ao_data_static.ms5607_raw.pres = log_mega->u.sensor.pres;
822 ao_data_static.ms5607_raw.temp = log_mega->u.sensor.temp;
823 ao_data_static.mpu6000.accel_x = log_mega->u.sensor.accel_x;
824 ao_data_static.mpu6000.accel_y = log_mega->u.sensor.accel_y;
825 ao_data_static.mpu6000.accel_z = log_mega->u.sensor.accel_z;
826 ao_data_static.mpu6000.gyro_x = log_mega->u.sensor.gyro_x;
827 ao_data_static.mpu6000.gyro_y = log_mega->u.sensor.gyro_y;
828 ao_data_static.mpu6000.gyro_z = log_mega->u.sensor.gyro_z;
829 ao_data_static.hmc5883.x = log_mega->u.sensor.mag_x;
830 ao_data_static.hmc5883.y = log_mega->u.sensor.mag_y;
831 ao_data_static.hmc5883.z = log_mega->u.sensor.mag_z;
832 ao_data_static.mma655x = log_mega->u.sensor.accel;
833 if (ao_config.pad_orientation != AO_PAD_ORIENTATION_ANTENNA_UP)
834 ao_data_static.mma655x = ao_data_accel_invert(ao_data_static.mma655x);
838 case AO_LOG_TEMP_VOLT:
839 if (pyros_fired != log_mega->u.volt.pyro) {
840 printf("pyro changed %x -> %x\n", pyros_fired, log_mega->u.volt.pyro);
841 pyros_fired = log_mega->u.volt.pyro;
844 case AO_LOG_GPS_TIME:
845 ao_gps_prev = ao_gps_static;
846 ao_gps_static.tick = log_mega->tick;
847 ao_gps_static.latitude = log_mega->u.gps.latitude;
848 ao_gps_static.longitude = log_mega->u.gps.longitude;
850 int16_t altitude_low = log_mega->u.gps.altitude_low;
851 int16_t altitude_high = log_mega->u.gps.altitude_high;
852 int32_t altitude = altitude_low | ((int32_t) altitude_high << 16);
854 AO_TELEMETRY_LOCATION_SET_ALTITUDE(&ao_gps_static, altitude);
856 ao_gps_static.flags = log_mega->u.gps.flags;
858 ao_gps_first = ao_gps_static;
867 case AO_LOG_FORMAT_TELEMETRUM:
868 log_metrum = (struct ao_log_metrum *) &eeprom->data[eeprom_offset];
869 eeprom_offset += sizeof (*log_metrum);
870 switch (log_metrum->type) {
872 ao_flight_started = 1;
873 ao_flight_number = log_metrum->u.flight.flight;
874 ao_flight_ground_accel = log_metrum->u.flight.ground_accel;
875 ao_ground_pres = log_metrum->u.flight.ground_pres;
876 ao_ground_height = ao_pa_to_altitude(ao_ground_pres);
879 ao_data_static.tick = log_metrum->tick;
880 ao_data_static.ms5607_raw.pres = log_metrum->u.sensor.pres;
881 ao_data_static.ms5607_raw.temp = log_metrum->u.sensor.temp;
882 ao_data_static.mma655x = log_metrum->u.sensor.accel;
890 case AO_LOG_FORMAT_EASYMINI1:
891 case AO_LOG_FORMAT_EASYMINI2:
892 case AO_LOG_FORMAT_TELEMINI3:
893 log_mini = (struct ao_log_mini *) &eeprom->data[eeprom_offset];
894 eeprom_offset += sizeof (*log_mini);
895 switch (log_mini->type) {
897 ao_flight_started = 1;
898 ao_flight_number = log_mini->u.flight.flight;
899 ao_ground_pres = log_mini->u.flight.ground_pres;
900 ao_ground_height = ao_pa_to_altitude(ao_ground_pres);
903 ao_data_static.tick = log_mini->tick;
904 ao_data_static.ms5607_raw.pres = int24(log_mini->u.sensor.pres, 0);
905 ao_data_static.ms5607_raw.temp = int24(log_mini->u.sensor.temp, 0);
913 case AO_LOG_FORMAT_FULL:
914 case AO_LOG_FORMAT_TINY:
915 log_record = (struct ao_log_record *) &eeprom->data[eeprom_offset];
916 eeprom_offset += sizeof (*log_record);
917 switch (log_record->type) {
919 ao_flight_started = 1;
920 ao_flight_ground_accel = log_record->u.flight.ground_accel;
921 ao_flight_number = log_record->u.flight.flight;
924 case 'P': /* ancient telemini */
925 ao_data_static.tick = log_record->tick;
926 ao_data_static.adc.accel = log_record->u.sensor.accel;
927 ao_data_static.adc.pres_real = log_record->u.sensor.pres;
928 ao_data_static.adc.pres = log_record->u.sensor.pres;
932 case AO_LOG_TEMP_VOLT:
933 ao_data_static.tick = log_record->tick;;
934 ao_data_static.adc.temp = log_record->u.temp_volt.temp;
935 ao_data_static.adc.v_batt = log_record->u.temp_volt.v_batt;
941 printf ("invalid log format %d\n", log_format);
949 #define COUNTS_PER_G 264.8
956 static const struct option options[] = {
957 { .name = "summary", .has_arg = 0, .val = 's' },
958 { .name = "debug", .has_arg = 0, .val = 'd' },
959 { .name = "info", .has_arg = 1, .val = 'i' },
963 void run_flight_fixed(char *name, FILE *f, int summary, char *info)
965 emulator_name = name;
967 emulator_info = info;
968 ao_summary = summary;
970 if (strstr(name, ".eeprom") != NULL) {
976 eeprom = ao_eeprom_read(f);
978 eeprom = ao_eeprom_read_old(f);
982 ao_ms5607_prom = eeprom->ms5607_prom;
984 ao_config = eeprom->config;
985 ao_serial_number = eeprom->serial_number;
986 log_format = eeprom->log_format;
995 main (int argc, char **argv)
1003 emulator_app="full";
1005 emulator_app="baro";
1007 while ((c = getopt_long(argc, argv, "sdpi:", options, NULL)) != -1) {
1013 ao_flight_debug = 1;
1027 run_flight_fixed("<stdin>", stdin, summary, info);
1029 for (i = optind; i < argc; i++) {
1030 FILE *f = fopen(argv[i], "r");
1035 run_flight_fixed(argv[i], f, summary, info);