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
131 #include <ao_telemetry.h>
132 #include <ao_sample.h>
136 struct ao_telemetry_location ao_gps_first;
137 struct ao_telemetry_location ao_gps_prev;
138 struct ao_telemetry_location ao_gps_static;
140 struct ao_telemetry_satellite ao_gps_tracking;
142 static inline double sqr(double a) { return a * a; }
145 cc_great_circle (double start_lat, double start_lon,
146 double end_lat, double end_lon,
147 double *dist, double *bearing)
149 const double rad = M_PI / 180;
150 const double earth_radius = 6371.2 * 1000; /* in meters */
151 double lat1 = rad * start_lat;
152 double lon1 = rad * -start_lon;
153 double lat2 = rad * end_lat;
154 double lon2 = rad * -end_lon;
156 // double d_lat = lat2 - lat1;
157 double d_lon = lon2 - lon1;
159 /* From http://en.wikipedia.org/wiki/Great-circle_distance */
160 double vdn = sqrt(sqr(cos(lat2) * sin(d_lon)) +
161 sqr(cos(lat1) * sin(lat2) -
162 sin(lat1) * cos(lat2) * cos(d_lon)));
163 double vdd = sin(lat1) * sin(lat2) + cos(lat1) * cos(lat2) * cos(d_lon);
164 double d = atan2(vdn,vdd);
167 if (cos(lat1) < 1e-20) {
176 course = acos((sin(lat2)-sin(lat1)*cos(d)) /
178 if (sin(lon2-lon1) > 0)
179 course = 2 * M_PI-course;
181 *dist = d * earth_radius;
182 *bearing = course * 180/M_PI;
186 ao_distance_from_pad(void)
188 double dist, bearing;
192 cc_great_circle(ao_gps_first.latitude / 1e7,
193 ao_gps_first.longitude / 1e7,
194 ao_gps_static.latitude / 1e7,
195 ao_gps_static.longitude / 1e7,
203 double dist, bearing;
207 if (ao_gps_count < 2)
210 cc_great_circle(ao_gps_prev.latitude / 1e7,
211 ao_gps_prev.longitude / 1e7,
212 ao_gps_static.latitude / 1e7,
213 ao_gps_static.longitude / 1e7,
215 height = AO_TELEMETRY_LOCATION_ALTITUDE(&ao_gps_static) - AO_TELEMETRY_LOCATION_ALTITUDE(&ao_gps_prev);
217 angle = atan2(dist, height);
218 return angle * 180/M_PI;
222 #define to_fix16(x) ((int16_t) ((x) * 65536.0 + 0.5))
223 #define to_fix32(x) ((int32_t) ((x) * 65536.0 + 0.5))
224 #define from_fix(x) ((x) >> 16)
226 #define ACCEL_NOSE_UP (ao_accel_2g >> 2)
228 extern enum ao_flight_state ao_flight_state;
233 volatile struct ao_data ao_data_ring[AO_DATA_RING];
234 volatile uint8_t ao_data_head;
238 #define ao_led_off(l)
239 #define ao_timer_set_adc_interval(i)
240 #define ao_wakeup(wchan) ao_dump_state()
241 #define ao_cmd_register(c)
242 #define ao_usb_disable()
243 #define ao_telemetry_set_interval(x)
244 #define ao_rdf_set(rdf)
245 #define ao_packet_slave_start()
246 #define ao_packet_slave_stop()
250 ao_igniter_drogue = 0,
254 struct ao_data ao_data_static;
263 static ao_k_t ao_k_height;
264 static double simple_speed;
269 return ao_data_static.tick;
273 ao_delay(int16_t interval)
279 ao_ignite(enum ao_igniter igniter)
281 double time = (double) (ao_data_static.tick + tick_offset) / 100;
283 if (igniter == ao_igniter_drogue) {
285 drogue_height = ao_k_height >> 16;
288 main_height = ao_k_height >> 16;
296 #define ao_add_task(t,f,n) ((void) (t))
298 #define ao_log_start()
299 #define ao_log_stop()
301 #define AO_MS_TO_TICKS(ms) ((ms) / 10)
302 #define AO_SEC_TO_TICKS(s) ((s) * 100)
304 #define AO_FLIGHT_TEST 1
308 struct ao_eeprom *eeprom;
309 uint32_t eeprom_offset;
315 double emulator_error_max = 4;
316 double emulator_height_error_max = 20; /* noise in the baro sensor */
322 ao_sleep(void *wchan);
324 const char * const ao_state_names[] = {
325 "startup", "idle", "pad", "boost", "fast",
326 "coast", "drogue", "main", "landed", "invalid"
334 #define ao_xmemcpy(d,s,c) memcpy(d,s,c)
335 #define ao_xmemset(d,v,c) memset(d,v,c)
336 #define ao_xmemcmp(d,s,c) memcmp(d,s,c)
338 #define AO_NEED_ALTITUDE_TO_PRES 1
339 #if TELEMEGA || TELEMETRUM_V2 || EASYMINI
340 #include "ao_convert_pa.c"
341 #include <ao_ms5607.h>
342 struct ao_ms5607_prom ao_ms5607_prom;
343 #include "ao_ms5607_convert.c"
345 #define AO_PYRO_NUM 4
349 #include "ao_convert.c"
352 #include <ao_config.h>
353 #include <ao_fake_flight.h>
354 #include <ao_eeprom_read.h>
357 #define ao_config_get()
359 struct ao_config ao_config;
364 extern int16_t ao_ground_accel, ao_flight_accel;
365 extern int16_t ao_accel_2g;
367 typedef int16_t accel_t;
369 uint16_t ao_serial_number;
370 int16_t ao_flight_number;
372 extern uint16_t ao_sample_tick;
374 extern alt_t ao_sample_height;
375 extern accel_t ao_sample_accel;
376 extern int32_t ao_accel_scale;
377 extern alt_t ao_ground_height;
378 extern alt_t ao_sample_alt;
380 double ao_sample_qangle;
382 int ao_sample_prev_tick;
386 #include "ao_kalman.c"
388 #include "ao_sample.c"
389 #include "ao_flight.c"
391 #define AO_PYRO_NUM 4
401 ao_pyro_pin_set(uint8_t pin, uint8_t value)
403 printf ("set pyro %d %d\n", pin, value);
408 #include "ao_eeprom_read.c"
409 #include "ao_eeprom_read_old.c"
411 #define to_double(f) ((f) / 65536.0)
413 static int ao_records_read = 0;
414 static int ao_eof_read = 0;
416 static int ao_flight_ground_accel;
418 static int ao_flight_started = 0;
419 static int ao_test_max_height;
420 static double ao_test_max_height_time;
421 static int ao_test_main_height;
422 static double ao_test_main_height_time;
423 static double ao_test_landed_time;
424 static double ao_test_landed_height;
425 static double ao_test_landed_time;
426 static int landed_set;
427 static double landed_time;
428 static double landed_height;
430 static uint16_t pyros_fired;
434 static struct ao_mpu6000_sample ao_ground_mpu6000;
443 double landed_time_error;
445 if (!ao_test_main_height_time) {
446 ao_test_main_height_time = ao_test_max_height_time;
447 ao_test_main_height = ao_test_max_height;
449 drogue_error = fabs(ao_test_max_height_time - drogue_time);
450 main_error = fabs(ao_test_main_height_time - main_time);
451 landed_error = fabs(ao_test_landed_height - landed_height);
452 landed_time_error = ao_test_landed_time - landed_time;
453 if (drogue_error > emulator_error_max || main_error > emulator_error_max) {
455 emulator_app, emulator_name);
457 printf ("\t%s\n", emulator_info);
458 printf ("\tApogee error %g\n", drogue_error);
459 printf ("\tMain error %g\n", main_error);
460 printf ("\tLanded height error %g\n", landed_error);
461 printf ("\tLanded time error %g\n", landed_time_error);
462 printf ("\tActual: apogee: %d at %7.2f main: %d at %7.2f landed %7.2f at %7.2f\n",
463 ao_test_max_height, ao_test_max_height_time,
464 ao_test_main_height, ao_test_main_height_time,
465 ao_test_landed_height, ao_test_landed_time);
466 printf ("\tComputed: apogee: %d at %7.2f main: %d at %7.2f landed %7.2f at %7.2f\n",
467 drogue_height, drogue_time, main_height, main_time,
468 landed_height, landed_time);
481 azel (struct ao_azel *r, struct ao_quaternion *q)
485 r->az = floor (atan2(q->y, q->x) * 180/M_PI + 0.5);
486 v = sqrt (q->x*q->x + q->y*q->y);
487 r->el = floor (atan2(q->z, v) * 180/M_PI + 0.5);
496 ao_data_ring[ao_data_head] = ao_data_static;
497 if (ao_flight_state != ao_flight_startup) {
499 double accel = ((ao_flight_ground_accel - ao_data_accel(&ao_data_static)) * GRAVITY * 2.0) /
500 (ao_config.accel_minus_g - ao_config.accel_plus_g);
507 tick_offset = -ao_data_static.tick;
508 if ((prev_tick - ao_data_static.tick) > 0x400)
509 tick_offset += 65536;
511 int ticks = ao_data_static.tick - prev_tick;
514 simple_speed += accel * ticks / 100.0;
516 prev_tick = ao_data_static.tick;
517 time = (double) (ao_data_static.tick + tick_offset) / 100;
519 #if TELEMEGA || TELEMETRUM_V2 || EASYMINI
520 ao_ms5607_convert(&ao_data_static.ms5607_raw, &ao_data_static.ms5607_cooked);
521 double height = ao_pa_to_altitude(ao_data_static.ms5607_cooked.pres) - ao_ground_height;
523 /* Hack to skip baro spike at accidental drogue charge
524 * firing in 2015-09-26-serial-2093-flight-0012.eeprom
525 * so we can test the kalman filter with this data. Just
526 * keep reporting the same baro value across the pressure spike
529 static struct ao_ms5607_sample save;
530 if (ao_serial_number == 2093 && ao_flight_number == 12 && 32.5 < time && time < 33.7) {
531 ao_data_ring[ao_data_head].ms5607_raw = save;
533 save = ao_data_static.ms5607_raw;
537 double height = ao_pres_to_altitude(ao_data_static.adc.pres_real) - ao_ground_height;
540 if (ao_test_max_height < height) {
541 ao_test_max_height = height;
542 ao_test_max_height_time = time;
543 ao_test_landed_height = height;
544 ao_test_landed_time = time;
546 if (height > ao_config.main_deploy) {
547 ao_test_main_height_time = time;
548 ao_test_main_height = height;
551 if (ao_test_landed_height > height) {
552 ao_test_landed_height = height;
553 ao_test_landed_time = time;
556 if (ao_flight_state == ao_flight_landed && !landed_set) {
559 landed_height = height;
564 static struct ao_quaternion ao_ground_mag;
565 static int ao_ground_mag_set;
567 if (!ao_ground_mag_set) {
568 ao_quaternion_init_vector (&ao_ground_mag,
569 ao_data_mag_across(&ao_data_static),
570 ao_data_mag_through(&ao_data_static),
571 ao_data_mag_along(&ao_data_static));
572 ao_quaternion_normalize(&ao_ground_mag, &ao_ground_mag);
573 ao_quaternion_rotate(&ao_ground_mag, &ao_ground_mag, &ao_rotation);
574 ao_ground_mag_set = 1;
577 struct ao_quaternion ao_mag, ao_mag_rot;
579 ao_quaternion_init_vector(&ao_mag,
580 ao_data_mag_across(&ao_data_static),
581 ao_data_mag_through(&ao_data_static),
582 ao_data_mag_along(&ao_data_static));
584 ao_quaternion_normalize(&ao_mag, &ao_mag);
585 ao_quaternion_rotate(&ao_mag_rot, &ao_mag, &ao_rotation);
590 ao_dot = ao_quaternion_dot(&ao_mag_rot, &ao_ground_mag);
592 struct ao_azel ground_azel, mag_azel, rot_azel;
594 azel(&ground_azel, &ao_ground_mag);
595 azel(&mag_azel, &ao_mag);
596 azel(&rot_azel, &ao_mag_rot);
598 ao_mag_angle = floor (acos(ao_dot) * 180 / M_PI + 0.5);
602 static struct ao_quaternion ao_x = { .r = 0, .x = 1, .y = 0, .z = 0 };
603 struct ao_quaternion ao_out;
605 ao_quaternion_rotate(&ao_out, &ao_x, &ao_rotation);
608 int out = floor (atan2(ao_out.y, ao_out.x) * 180 / M_PI);
610 printf ("%7.2f state %-8.8s height %8.4f tilt %4d rot %4d mag_tilt %4d mag_rot %4d\n",
612 ao_state_names[ao_flight_state],
613 ao_k_height / 65536.0,
614 ao_sample_orient, out,
619 printf ("%7.2f state %-8.8s height %8.4f tilt %4d rot %4d dist %12.2f gps_tilt %4d gps_sats %2d\n",
621 ao_state_names[ao_flight_state],
622 ao_k_height / 65536.0,
623 ao_sample_orient, out,
624 ao_distance_from_pad(),
625 (int) floor (ao_gps_angle() + 0.5),
626 (ao_gps_static.flags & 0xf) * 10);
630 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",
631 ao_state_names[ao_flight_state],
632 ground_azel.az, ground_azel.el,
633 mag_azel.az, mag_azel.el,
634 rot_azel.az, rot_azel.el,
635 ground_azel.el - rot_azel.el,
636 ground_azel.az - rot_azel.az,
652 printf("%7.2f height %8.2f accel %8.3f accel_speed %8.3f "
653 "state %d k_height %8.2f k_speed %8.3f k_accel %8.3f avg_height %5d drogue %4d main %4d error %5d"
656 "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 "
662 simple_speed > -100.0 ? simple_speed : -100.0,
663 ao_flight_state * 10,
664 ao_k_height / 65536.0,
665 ao_k_speed / 65536.0 / 16.0,
666 ao_k_accel / 65536.0 / 16.0,
674 ao_mpu6000_accel(ao_data_static.mpu6000.accel_x),
675 ao_mpu6000_accel(ao_data_static.mpu6000.accel_y),
676 ao_mpu6000_accel(ao_data_static.mpu6000.accel_z),
677 ao_mpu6000_gyro(ao_data_static.mpu6000.gyro_x - ao_ground_mpu6000.gyro_x),
678 ao_mpu6000_gyro(ao_data_static.mpu6000.gyro_y - ao_ground_mpu6000.gyro_y),
679 ao_mpu6000_gyro(ao_data_static.mpu6000.gyro_z - ao_ground_mpu6000.gyro_z),
680 ao_data_static.hmc5883.x,
681 ao_data_static.hmc5883.y,
682 ao_data_static.hmc5883.z,
688 // if (ao_flight_state == ao_flight_landed)
692 ao_data_head = ao_data_ring_next(ao_data_head);
697 uint16(uint8_t *bytes, int off)
699 return (uint16_t) bytes[off] | (((uint16_t) bytes[off+1]) << 8);
703 int16(uint8_t *bytes, int off)
705 return (int16_t) uint16(bytes, off);
709 uint32(uint8_t *bytes, int off)
711 return (uint32_t) bytes[off] | (((uint32_t) bytes[off+1]) << 8) |
712 (((uint32_t) bytes[off+2]) << 16) |
713 (((uint32_t) bytes[off+3]) << 24);
717 int32(uint8_t *bytes, int off)
719 return (int32_t) uint32(bytes, off);
723 uint24(uint8_t *bytes, int off)
725 return (uint32_t) bytes[off] | (((uint32_t) bytes[off+1]) << 8) |
726 (((uint32_t) bytes[off+2]) << 16);
730 int24(uint8_t *bytes, int off)
732 return (int32_t) uint24(bytes, off);
735 static int log_format;
738 ao_sleep(void *wchan)
740 if (wchan == &ao_data_head) {
742 if (ao_flight_state >= ao_flight_boost && ao_flight_state < ao_flight_landed)
746 if (ao_records_read > 2 && ao_flight_state == ao_flight_startup)
750 ao_data_static.mpu6000 = ao_ground_mpu6000;
753 ao_data_static.adc.accel = ao_flight_ground_accel;
762 struct ao_log_mega *log_mega;
765 struct ao_log_metrum *log_metrum;
768 struct ao_log_mini *log_mini;
771 struct ao_log_record *log_record;
774 if (eeprom_offset >= eeprom->len) {
775 if (++ao_eof_read >= 1000)
777 printf ("no more data, exiting simulation\n");
779 ao_data_static.tick += 10;
783 switch (eeprom->log_format) {
785 case AO_LOG_FORMAT_TELEMEGA_OLD:
786 case AO_LOG_FORMAT_TELEMEGA:
787 log_mega = (struct ao_log_mega *) &eeprom->data[eeprom_offset];
788 eeprom_offset += sizeof (*log_mega);
789 switch (log_mega->type) {
791 ao_flight_number = log_mega->u.flight.flight;
792 ao_flight_ground_accel = log_mega->u.flight.ground_accel;
793 ao_flight_started = 1;
794 ao_ground_pres = log_mega->u.flight.ground_pres;
795 ao_ground_height = ao_pa_to_altitude(ao_ground_pres);
796 ao_ground_accel_along = log_mega->u.flight.ground_accel_along;
797 ao_ground_accel_across = log_mega->u.flight.ground_accel_across;
798 ao_ground_accel_through = log_mega->u.flight.ground_accel_through;
799 ao_ground_roll = log_mega->u.flight.ground_roll;
800 ao_ground_pitch = log_mega->u.flight.ground_pitch;
801 ao_ground_yaw = log_mega->u.flight.ground_yaw;
802 ao_ground_mpu6000.accel_x = ao_ground_accel_across;
803 ao_ground_mpu6000.accel_y = ao_ground_accel_along;
804 ao_ground_mpu6000.accel_z = ao_ground_accel_through;
805 ao_ground_mpu6000.gyro_x = ao_ground_pitch >> 9;
806 ao_ground_mpu6000.gyro_y = ao_ground_roll >> 9;
807 ao_ground_mpu6000.gyro_z = ao_ground_yaw >> 9;
812 ao_data_static.tick = log_mega->tick;
813 ao_data_static.ms5607_raw.pres = log_mega->u.sensor.pres;
814 ao_data_static.ms5607_raw.temp = log_mega->u.sensor.temp;
815 ao_data_static.mpu6000.accel_x = log_mega->u.sensor.accel_x;
816 ao_data_static.mpu6000.accel_y = log_mega->u.sensor.accel_y;
817 ao_data_static.mpu6000.accel_z = log_mega->u.sensor.accel_z;
818 ao_data_static.mpu6000.gyro_x = log_mega->u.sensor.gyro_x;
819 ao_data_static.mpu6000.gyro_y = log_mega->u.sensor.gyro_y;
820 ao_data_static.mpu6000.gyro_z = log_mega->u.sensor.gyro_z;
821 ao_data_static.hmc5883.x = log_mega->u.sensor.mag_x;
822 ao_data_static.hmc5883.y = log_mega->u.sensor.mag_y;
823 ao_data_static.hmc5883.z = log_mega->u.sensor.mag_z;
824 ao_data_static.mma655x = log_mega->u.sensor.accel;
825 if (ao_config.pad_orientation != AO_PAD_ORIENTATION_ANTENNA_UP)
826 ao_data_static.mma655x = ao_data_accel_invert(ao_data_static.mma655x);
830 case AO_LOG_TEMP_VOLT:
831 if (pyros_fired != log_mega->u.volt.pyro) {
832 printf("pyro changed %x -> %x\n", pyros_fired, log_mega->u.volt.pyro);
833 pyros_fired = log_mega->u.volt.pyro;
836 case AO_LOG_GPS_TIME:
837 ao_gps_prev = ao_gps_static;
838 ao_gps_static.tick = log_mega->tick;
839 ao_gps_static.latitude = log_mega->u.gps.latitude;
840 ao_gps_static.longitude = log_mega->u.gps.longitude;
842 int16_t altitude_low = log_mega->u.gps.altitude_low;
843 int16_t altitude_high = log_mega->u.gps.altitude_high;
844 int32_t altitude = altitude_low | ((int32_t) altitude_high << 16);
846 AO_TELEMETRY_LOCATION_SET_ALTITUDE(&ao_gps_static, altitude);
848 ao_gps_static.flags = log_mega->u.gps.flags;
850 ao_gps_first = ao_gps_static;
859 case AO_LOG_FORMAT_TELEMETRUM:
860 log_metrum = (struct ao_log_metrum *) &eeprom->data[eeprom_offset];
861 eeprom_offset += sizeof (*log_metrum);
862 switch (log_metrum->type) {
864 ao_flight_started = 1;
865 ao_flight_number = log_metrum->u.flight.flight;
866 ao_flight_ground_accel = log_metrum->u.flight.ground_accel;
867 ao_ground_pres = log_metrum->u.flight.ground_pres;
868 ao_ground_height = ao_pa_to_altitude(ao_ground_pres);
871 ao_data_static.tick = log_metrum->tick;
872 ao_data_static.ms5607_raw.pres = log_metrum->u.sensor.pres;
873 ao_data_static.ms5607_raw.temp = log_metrum->u.sensor.temp;
874 ao_data_static.mma655x = log_metrum->u.sensor.accel;
882 case AO_LOG_FORMAT_EASYMINI1:
883 case AO_LOG_FORMAT_EASYMINI2:
884 case AO_LOG_FORMAT_TELEMINI3:
885 log_mini = (struct ao_log_mini *) &eeprom->data[eeprom_offset];
886 eeprom_offset += sizeof (*log_mini);
887 switch (log_mini->type) {
889 ao_flight_started = 1;
890 ao_flight_number = log_mini->u.flight.flight;
891 ao_ground_pres = log_mini->u.flight.ground_pres;
892 ao_ground_height = ao_pa_to_altitude(ao_ground_pres);
895 ao_data_static.tick = log_mini->tick;
896 ao_data_static.ms5607_raw.pres = int24(log_mini->u.sensor.pres, 0);
897 ao_data_static.ms5607_raw.temp = int24(log_mini->u.sensor.temp, 0);
905 case AO_LOG_FORMAT_FULL:
906 case AO_LOG_FORMAT_TINY:
907 log_record = (struct ao_log_record *) &eeprom->data[eeprom_offset];
908 eeprom_offset += sizeof (*log_record);
909 switch (log_record->type) {
911 ao_flight_started = 1;
912 ao_flight_ground_accel = log_record->u.flight.ground_accel;
913 ao_flight_number = log_record->u.flight.flight;
916 case 'P': /* ancient telemini */
917 ao_data_static.tick = log_record->tick;
918 ao_data_static.adc.accel = log_record->u.sensor.accel;
919 ao_data_static.adc.pres_real = log_record->u.sensor.pres;
920 ao_data_static.adc.pres = log_record->u.sensor.pres;
924 case AO_LOG_TEMP_VOLT:
925 ao_data_static.tick = log_record->tick;;
926 ao_data_static.adc.temp = log_record->u.temp_volt.temp;
927 ao_data_static.adc.v_batt = log_record->u.temp_volt.v_batt;
933 printf ("invalid log format %d\n", log_format);
941 #define COUNTS_PER_G 264.8
948 static const struct option options[] = {
949 { .name = "summary", .has_arg = 0, .val = 's' },
950 { .name = "debug", .has_arg = 0, .val = 'd' },
951 { .name = "info", .has_arg = 1, .val = 'i' },
955 void run_flight_fixed(char *name, FILE *f, int summary, char *info)
957 emulator_name = name;
959 emulator_info = info;
960 ao_summary = summary;
962 if (strstr(name, ".eeprom") != NULL) {
968 eeprom = ao_eeprom_read(f);
970 eeprom = ao_eeprom_read_old(f);
974 ao_ms5607_prom = eeprom->ms5607_prom;
976 ao_config = eeprom->config;
977 ao_serial_number = eeprom->serial_number;
978 log_format = eeprom->log_format;
987 main (int argc, char **argv)
999 while ((c = getopt_long(argc, argv, "sdpi:", options, NULL)) != -1) {
1005 ao_flight_debug = 1;
1019 run_flight_fixed("<stdin>", stdin, summary, info);
1021 for (i = optind; i < argc; i++) {
1022 FILE *f = fopen(argv[i], "r");
1027 run_flight_fixed(argv[i], f, summary, info);