src: Add easymini-v3.0
[fw/altos] / ao-tools / ao-eeprom / ao-eeprom.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; either version 2 of the License, or
7  * (at your option) any later version.
8  *
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.
13  *
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.
17  */
18
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <stdbool.h>
22 #include <unistd.h>
23 #include <getopt.h>
24 #include <ao-eeprom-read.h>
25 #include <ao-atmosphere.h>
26
27 static const struct option options[] = {
28         { .name = "raw", .has_arg = 0, .val = 'r' },
29         { .name = "csum", .has_arg = 0, .val = 'c' },
30         { .name = "verbose", .has_arg = 0, .val = 'v' },
31         { .name = "len", .has_arg = 1, .val = 'l' },
32         { 0, 0, 0, 0},
33 };
34
35 static void usage(char *program)
36 {
37         fprintf(stderr, "usage: %s [--raw] [--csum] [--verbose] [--len <record-len>] {flight.eeprom} ...\n", program);
38         exit(1);
39 }
40
41 static bool
42 ao_csum_valid(uint8_t *d, int len)
43 {
44         uint8_t sum = 0x5a;
45         int i;
46         for (i = 0; i < len; i++)
47                 sum += d[i];
48         return sum == 0;
49 }
50
51 static void
52 ao_ms5607(uint32_t pres, uint32_t temp, struct ao_eeprom *eeprom, bool is_ms5611)
53 {
54         struct ao_ms5607_sample ms5607_sample = { .pres = pres, .temp = temp };
55         struct ao_ms5607_value ms5607_value;
56
57         ao_ms5607_convert(&ms5607_sample, &ms5607_value,
58                           &eeprom->ms5607_prom, is_ms5611);
59         printf(" pres %9u %7.3f kPa  %7.1f m temp %9u %6.2f °C",
60                pres,
61                ms5607_value.pres / 1000.0,
62                ao_pressure_to_altitude(ms5607_value.pres),
63                temp,
64                ms5607_value.temp / 100.0);
65 }
66
67 #define GRAVITY 9.80665
68
69 static void
70 ao_accel(int16_t accel, struct ao_eeprom *eeprom)
71 {
72         double accel_2g = eeprom->config.accel_minus_g - eeprom->config.accel_plus_g;
73         double accel_scale = GRAVITY * 2.0 / accel_2g;
74         printf(" accel %6d %7.2f m/s²",
75                accel, (eeprom->config.accel_plus_g - accel) * accel_scale);
76 }
77
78 static const char *state_names[] = {
79         "startup",
80         "idle",
81         "pad",
82         "boost",
83         "fast",
84         "coast",
85         "drogue",
86         "main",
87         "landed",
88         "invalid"
89 };
90
91 #define NUM_STATE       (sizeof state_names/sizeof state_names[0])
92
93 static const char *
94 ao_state_name(uint16_t state)
95 {
96         if (state < NUM_STATE)
97                 return state_names[state];
98         return "UNKNOWN";
99 }
100
101 static void
102 ao_state(uint16_t state, uint16_t reason)
103 {
104         printf(" state %5u %s reason %5u",
105                state, ao_state_name(state), reason);
106 }
107
108 static double
109 ao_adc_to_volts(int16_t value, int16_t max_adc, double ref, double r1, double r2)
110 {
111         return ref * ((double) value / max_adc) * (r1 + r2) / r2;
112 }
113
114 static void
115 ao_volts(const char *name, int16_t value, int16_t max_adc, double ref, double r1, double r2)
116 {
117         printf(" %s %5d",
118                name, value);
119         if (r1 && r2 && ref)
120                 printf(" %6.3f V", ao_adc_to_volts(value, max_adc, ref, r1, r2));
121 }
122
123 static double lb_to_n(double lb)
124 {
125         return lb / 0.22480894;
126 }
127
128 static double psi_to_pa(double psi)
129 {
130         return psi * 6894.76;
131 }
132
133 static double
134 ao_volts_to_newtons(double volts)
135 {
136         /* this is a total guess */
137         return lb_to_n(volts * 57.88645 * GRAVITY);
138 }
139
140 static void
141 ao_thrust(int16_t value, int16_t max_adc, double ref, double r1, double r2)
142 {
143         printf(" thrust %5d", value);
144         if (r1 && r2 && ref) {
145                 double volts = ao_adc_to_volts(value, max_adc, ref, r1, r2);
146                 printf(" %6.3f V %8.1f N", volts, ao_volts_to_newtons(volts));
147         }
148 }
149
150 static void
151 ao_pressure(int16_t value, int16_t max_adc, double ref, double r1, double r2)
152 {
153         printf(" pressure %5d", value);
154         if (r1 && r2 && ref) {
155                 double volts = ao_adc_to_volts(value, max_adc, ref, r1, r2);
156                 if (volts < 0.5) volts = 0.5;
157                 if (volts > 4.5) volts = 4.5;
158
159                 double psi = (volts - 0.5) / 4.0 * 2500.0;
160                 double pa = psi_to_pa(psi);
161                 printf(" %9.3f kPa", pa / 1000.0);
162         }
163 }
164
165 #if 0
166 static uint16_t
167 uint16(uint8_t *bytes, int off)
168 {
169         return (uint16_t) bytes[off] | (((uint16_t) bytes[off+1]) << 8);
170 }
171
172 static int16_t
173 int16(uint8_t *bytes, int off)
174 {
175         return (int16_t) uint16(bytes, off);
176 }
177
178 static uint32_t
179 uint32(uint8_t *bytes, int off)
180 {
181         return (uint32_t) bytes[off] | (((uint32_t) bytes[off+1]) << 8) |
182                 (((uint32_t) bytes[off+2]) << 16) |
183                 (((uint32_t) bytes[off+3]) << 24);
184 }
185
186 static int32_t
187 int32(uint8_t *bytes, int off)
188 {
189         return (int32_t) uint32(bytes, off);
190 }
191 #endif
192
193 static uint32_t
194 uint24(uint8_t *bytes, int off)
195 {
196         return (uint32_t) bytes[off] | (((uint32_t) bytes[off+1]) << 8) |
197                 (((uint32_t) bytes[off+2]) << 16);
198 }
199
200 static int32_t
201 int24(uint8_t *bytes, int off)
202 {
203         return (int32_t) uint24(bytes, off);
204 }
205
206 int
207 main (int argc, char **argv)
208 {
209         struct ao_eeprom        *eeprom;
210         FILE                    *file;
211         int                     c;
212         bool                    raw = false;
213         bool                    csum = false;
214         bool                    verbose = false;
215         int                     arg_len = 0;
216         char                    *end;
217         int                     ret = 0;
218         int                     i;
219
220         while ((c = getopt_long(argc, argv, "rcvl:", options, NULL)) != -1) {
221                 switch (c) {
222                 case 'r':
223                         raw = true;
224                         break;
225                 case 'c':
226                         csum = true;
227                         break;
228                 case 'v':
229                         verbose = true;
230                         break;
231                 case 'l':
232                         arg_len = strtol(optarg, &end, 0);
233                         if (!*optarg || *end)
234                                 usage(argv[0]);
235                         break;
236                 default:
237                         usage(argv[0]);
238                         break;
239                 }
240         }
241         for (i = optind; i < argc; i++) {
242                 file = fopen(argv[i], "r");
243                 if (!file) {
244                         perror(argv[i]);
245                         ret++;
246                         continue;
247                 }
248                 eeprom = ao_eeprom_read(file);
249                 fclose(file);
250                 if (!eeprom) {
251                         perror(argv[i]);
252                         ret++;
253                         continue;
254                 }
255                 int     len = 0;
256                 bool    is_ms5611 = false;
257
258                 int64_t current_tick = 0;
259                 int64_t first_tick = 0x7fffffffffffffffLL;
260
261                 double  sense_r1 = 0.0, sense_r2 = 0.0;
262                 double  batt_r1 = 0.0, batt_r2 = 0.0;
263                 double  adc_ref = 0.0;
264                 int16_t max_adc = 0;
265
266                 switch (eeprom->log_format) {
267                 case AO_LOG_FORMAT_TELEMEGA_OLD:
268                         len = 32;
269                         break;
270                 case AO_LOG_FORMAT_EASYMINI1:
271                         len = 16;
272                         max_adc = 32767;
273                         if (eeprom->serial_number < 1000)
274                                 adc_ref = 3.0;
275                         else
276                                 adc_ref = 3.3;
277                         batt_r1 = sense_r1 = 100e3;
278                         batt_r2 = sense_r2 = 27e3;
279                         break;
280                 case AO_LOG_FORMAT_TELEMETRUM:
281                         len = 16;
282                         max_adc = 4095;
283                         adc_ref = 3.3;
284                         batt_r1 = 5600;
285                         batt_r2 = 10000;
286                         sense_r1 = 100e3;
287                         sense_r2 = 27e3;
288                         break;
289                 case AO_LOG_FORMAT_TELEMINI2:
290                         len = 16;
291                         break;
292                 case AO_LOG_FORMAT_TELEGPS:
293                         len = 32;
294                         break;
295                 case AO_LOG_FORMAT_TELEMEGA:
296                         len = 32;
297                         max_adc = 4095;
298                         adc_ref = 3.3;
299                         batt_r1 = 5600;
300                         batt_r2 = 10000;
301                         sense_r1 = 100e3;
302                         sense_r2 = 27e3;
303                         break;
304                 case AO_LOG_FORMAT_DETHERM:
305                         len = 16;
306                         break;
307                 case AO_LOG_FORMAT_TELEMINI3:
308                         len = 16;
309                         max_adc = 4095;
310                         adc_ref = 3.3;
311                         batt_r1 = 5600;
312                         batt_r2 = 10000;
313                         sense_r1 = 100e3;
314                         sense_r2 = 27e3;
315                         break;
316                 case AO_LOG_FORMAT_TELEFIRETWO:
317                         len = 32;
318                         max_adc = 4095;
319                         adc_ref = 3.3;
320                         sense_r1 = batt_r1 = 5600;
321                         sense_r2 = batt_r2 = 10000;
322                         break;
323                 case AO_LOG_FORMAT_EASYMINI2:
324                         len = 16;
325                         max_adc = 4095;
326                         adc_ref = 3.3;
327                         batt_r1 = sense_r1 = 100e3;
328                         batt_r2 = sense_r2 = 27e3;
329                         break;
330                 case AO_LOG_FORMAT_TELEMEGA_3:
331                         len = 32;
332                         max_adc = 4095;
333                         adc_ref = 3.3;
334                         batt_r1 = 5600;
335                         batt_r2 = 10000;
336                         sense_r1 = 100e3;
337                         sense_r2 = 27e3;
338                         break;
339                 case AO_LOG_FORMAT_EASYMEGA_2:
340                         len = 32;
341                         max_adc = 4095;
342                         adc_ref = 3.3;
343                         batt_r1 = 5600;
344                         batt_r2 = 10000;
345                         sense_r1 = 100e3;
346                         sense_r2 = 27e3;
347                         break;
348                 case AO_LOG_FORMAT_TELESTATIC:
349                         len = 32;
350                         break;
351                 case AO_LOG_FORMAT_MICROPEAK2:
352                         len = 2;
353                         break;
354                 case AO_LOG_FORMAT_TELEMEGA_4:
355                         len = 32;
356                         break;
357                         max_adc= 4095;
358                         adc_ref = 3.3;
359                         batt_r1 = 5600;
360                         batt_r2 = 10000;
361                         sense_r1 = 100e3;
362                         sense_r2 = 27e3;
363                         break;
364                 }
365                 if (arg_len)
366                         len = arg_len;
367                 if (verbose)
368                         printf("config major %d minor %d log format %d total %u len %d\n",
369                                eeprom->config.major,
370                                eeprom->config.minor,
371                                eeprom->log_format,
372                                eeprom->len,
373                                len);
374
375                 uint32_t        pos;
376                 for (pos = 0; pos < eeprom->len; pos += len) {
377                         int i;
378                         if (raw) {
379                                 printf("%9u", pos);
380                                 for (i = 0; i < len; i++)
381                                         printf(" %02x", eeprom->data[pos + i]);
382                         } else {
383                                 struct ao_log_mega *log_mega;
384                                 struct ao_log_mini *log_mini;
385                                 struct ao_log_metrum *log_metrum;
386                                 struct ao_log_gps *log_gps;
387                                 struct ao_log_firetwo *log_firetwo;
388
389                                 if (!csum && !ao_csum_valid(&eeprom->data[pos], len)) {
390                                         if (verbose)
391                                                 printf("\tchecksum error at %d\n", pos);
392                                         continue;
393                                 }
394
395                                 struct ao_log_header *log_header = (struct ao_log_header *) &eeprom->data[pos];
396
397                                 if (first_tick == 0x7fffffffffffffffLL) {
398                                         current_tick = first_tick = log_header->tick;
399                                 } else {
400                                         int16_t diff = (int16_t) (log_header->tick - (uint16_t) current_tick);
401
402                                         current_tick += diff;
403                                 }
404                                 printf("type %c tick %5u %6.2f S", log_header->type, log_header->tick, (current_tick - first_tick) / 100.0);
405
406                                 switch (eeprom->log_format) {
407                                 case AO_LOG_FORMAT_TELEMEGA_OLD:
408                                 case AO_LOG_FORMAT_TELEMEGA:
409                                 case AO_LOG_FORMAT_TELEMEGA_3:
410                                 case AO_LOG_FORMAT_EASYMEGA_2:
411                                 case AO_LOG_FORMAT_TELEMEGA_4:
412                                         log_mega = (struct ao_log_mega *) &eeprom->data[pos];
413                                         switch (log_mega->type) {
414                                         case AO_LOG_FLIGHT:
415                                                 printf(" serial %5u flight %5u ground_accel %6d ground_pres %9u kPa  %7.1f  %7.1f m",
416                                                        eeprom->serial_number,
417                                                        log_mega->u.flight.flight,
418                                                        log_mega->u.flight.ground_accel,
419                                                        log_mega->u.flight.ground_pres,
420                                                        log_mega->u.flight.ground_pres / 1000.0,
421                                                        ao_pressure_to_altitude(log_mega->u.flight.ground_pres));
422
423                                                 printf(" along %6d aross %6d through %6d",
424                                                        log_mega->u.flight.ground_accel_along,
425                                                        log_mega->u.flight.ground_accel_across,
426                                                        log_mega->u.flight.ground_accel_through);
427                                                 printf(" roll %6d pitch %6d yaw %6d",
428                                                        log_mega->u.flight.ground_roll,
429                                                        log_mega->u.flight.ground_pitch,
430                                                        log_mega->u.flight.ground_yaw);
431                                                 break;
432                                         case AO_LOG_STATE:
433                                                 ao_state(log_mega->u.state.state,
434                                                          log_mega->u.state.reason);
435                                                 break;
436                                         case AO_LOG_SENSOR:
437                                                 ao_ms5607(log_mega->u.sensor.pres,
438                                                           log_mega->u.sensor.temp,
439                                                           eeprom, is_ms5611);
440                                                 printf(" accel_x %6d accel_y %6d accel_z %6d",
441                                                        log_mega->u.sensor.accel_x,
442                                                        log_mega->u.sensor.accel_y,
443                                                        log_mega->u.sensor.accel_z);
444                                                 printf (" gyro_x %6d gyro_y %6d gyro_z %6d",
445                                                        log_mega->u.sensor.gyro_x,
446                                                        log_mega->u.sensor.gyro_y,
447                                                        log_mega->u.sensor.gyro_z);
448                                                 printf (" mag_x %6d mag_y %6d mag_z %6d",
449                                                        log_mega->u.sensor.mag_x,
450                                                        log_mega->u.sensor.mag_y,
451                                                        log_mega->u.sensor.mag_z);
452                                                 ao_accel(log_mega->u.sensor.accel, eeprom);
453                                                 break;
454                                         case AO_LOG_TEMP_VOLT:
455                                                 ao_volts("v_batt",
456                                                          log_mega->u.volt.v_batt,
457                                                          max_adc,
458                                                          adc_ref,
459                                                          batt_r1, batt_r2);
460                                                 ao_volts("v_pbatt",
461                                                          log_mega->u.volt.v_pbatt,
462                                                          max_adc,
463                                                          adc_ref,
464                                                          sense_r1, sense_r2);
465                                                 printf(" n_sense %1d",
466                                                        log_mega->u.volt.n_sense);
467                                                 for (i = 0; i < log_mega->u.volt.n_sense; i++) {
468                                                         char name[10];
469                                                         sprintf(name, "sense%d", i);
470                                                         ao_volts(name,
471                                                                  log_mega->u.volt.sense[i],
472                                                                  max_adc,
473                                                                  adc_ref,
474                                                                  sense_r1, sense_r2);
475                                                 }
476                                                 printf(" pyro %04x", log_mega->u.volt.pyro);
477                                                 break;
478                                         case AO_LOG_GPS_TIME:
479                                                 printf(" lat %10.7f ° lon %10.7f ° alt %8d m",
480                                                        log_mega->u.gps.latitude / 10000000.0,
481                                                        log_mega->u.gps.longitude/ 10000000.0,
482                                                        (int32_t) (log_mega->u.gps.altitude_low |
483                                                                   (log_mega->u.gps.altitude_high << 16)));
484                                                 printf(" time %02d:%02d:%02d %04d-%02d-%02d flags %02x",
485                                                        log_mega->u.gps.hour,
486                                                        log_mega->u.gps.minute,
487                                                        log_mega->u.gps.second,
488                                                        log_mega->u.gps.year + 2000,
489                                                        log_mega->u.gps.month,
490                                                        log_mega->u.gps.day,
491                                                        log_mega->u.gps.flags);
492                                                 printf(" course %3d ground_speed %5u climb_rate %6d pdop %3d hdop %3d vdop %3d mode %3d",
493                                                        log_mega->u.gps.course,
494                                                        log_mega->u.gps.ground_speed,
495                                                        log_mega->u.gps.climb_rate,
496                                                        log_mega->u.gps.pdop,
497                                                        log_mega->u.gps.hdop,
498                                                        log_mega->u.gps.vdop,
499                                                        log_mega->u.gps.mode);
500                                                 break;
501                                         case AO_LOG_GPS_SAT:
502                                                 printf(" channels %2d",
503                                                        log_mega->u.gps_sat.channels);
504                                                 for (i = 0; i < 12; i++) {
505                                                         printf(" svid %3d c_n %2d",
506                                                                log_mega->u.gps_sat.sats[i].svid,
507                                                                log_mega->u.gps_sat.sats[i].c_n);
508                                                 }
509                                                 break;
510                                         }
511                                         break;
512                                 case AO_LOG_FORMAT_EASYMINI1:
513                                 case AO_LOG_FORMAT_EASYMINI2:
514                                 case AO_LOG_FORMAT_TELEMINI2:
515                                 case AO_LOG_FORMAT_TELEMINI3:
516                                         log_mini = (struct ao_log_mini *) &eeprom->data[pos];
517                                         switch (log_mini->type) {
518                                         case AO_LOG_FLIGHT:
519                                                 printf(" serial %5u flight %5u ground_pres %9u kPa  %7.1f  %7.1f m",
520                                                        eeprom->serial_number,
521                                                        log_mini->u.flight.flight,
522                                                        log_mini->u.flight.ground_pres,
523                                                        log_mini->u.flight.ground_pres / 1000.0,
524                                                        ao_pressure_to_altitude(log_mini->u.flight.ground_pres));
525                                                 break;
526                                         case AO_LOG_STATE:
527                                                 ao_state(log_mini->u.state.state,
528                                                          log_mini->u.state.reason);
529                                                 break;
530                                         case AO_LOG_SENSOR:
531                                                 ao_ms5607(int24(log_mini->u.sensor.pres, 0),
532                                                           int24(log_mini->u.sensor.temp, 0),
533                                                           eeprom, is_ms5611);
534                                                 ao_volts("sense_a",
535                                                          log_mini->u.sensor.sense_a, max_adc,
536                                                          adc_ref, sense_r1, sense_r2);
537                                                 ao_volts("sense_m",
538                                                          log_mini->u.sensor.sense_m, max_adc,
539                                                          adc_ref, sense_r1, sense_r2);
540                                                 ao_volts("v_batt",
541                                                          log_mini->u.sensor.v_batt, max_adc,
542                                                          adc_ref, batt_r1, batt_r2);
543                                                 break;
544                                         } /*  */
545                                         break;
546                                 case AO_LOG_FORMAT_TELEMETRUM:
547                                         log_metrum = (struct ao_log_metrum *) &eeprom->data[pos];
548                                         switch (log_metrum->type) {
549                                         case AO_LOG_FLIGHT:
550                                                 printf(" serial %5u flight %5u ground_accel %6d ground_pres %9u kPa  %7.1f  %7.1f m ground_temp %9u",
551                                                        eeprom->serial_number,
552                                                        log_metrum->u.flight.flight,
553                                                        log_metrum->u.flight.ground_accel,
554                                                        log_metrum->u.flight.ground_pres,
555                                                        log_metrum->u.flight.ground_pres / 1000.0,
556                                                        ao_pressure_to_altitude(log_metrum->u.flight.ground_pres),
557                                                        log_metrum->u.flight.ground_temp);
558                                                 break;
559                                         case AO_LOG_SENSOR:
560                                                 ao_ms5607(log_metrum->u.sensor.pres,
561                                                           log_metrum->u.sensor.temp,
562                                                           eeprom, is_ms5611);
563                                                 ao_accel(log_metrum->u.sensor.accel, eeprom);
564                                                 break;
565                                         case AO_LOG_TEMP_VOLT:
566                                                 ao_volts("v_batt",
567                                                          log_metrum->u.volt.v_batt, max_adc,
568                                                          adc_ref, batt_r1, batt_r2);
569                                                 ao_volts("sense_a",
570                                                          log_metrum->u.volt.sense_a, max_adc,
571                                                          adc_ref, sense_r1, sense_r2);
572                                                 ao_volts("sense_m",
573                                                          log_metrum->u.volt.sense_m, max_adc,
574                                                          adc_ref, sense_r1, sense_r2);
575                                                 break;
576                                         case AO_LOG_DEPLOY:
577                                                 break;
578                                         case AO_LOG_STATE:
579                                                 ao_state(log_metrum->u.state.state,
580                                                          log_metrum->u.state.reason);
581                                                 break;
582                                         case AO_LOG_GPS_TIME:
583                                                 printf(" time %02d:%02d:%02d 20%02d-%02d-%02d flags %02x pdop %3u",
584                                                        log_metrum->u.gps_time.hour,
585                                                        log_metrum->u.gps_time.minute,
586                                                        log_metrum->u.gps_time.second,
587                                                        log_metrum->u.gps_time.year,
588                                                        log_metrum->u.gps_time.month,
589                                                        log_metrum->u.gps_time.day,
590                                                        log_metrum->u.gps_time.flags,
591                                                        log_metrum->u.gps_time.pdop);
592                                                 break;
593                                         case AO_LOG_GPS_SAT:
594                                                 printf(" channels %2d more %1d",
595                                                        log_metrum->u.gps_sat.channels,
596                                                        log_metrum->u.gps_sat.more);
597                                                 for (i = 0; i < 4; i++) {
598                                                         printf(" svid %3d c_n %2d",
599                                                                log_metrum->u.gps_sat.sats[i].svid,
600                                                                log_metrum->u.gps_sat.sats[i].c_n);
601                                                 }
602                                                 break;
603                                         case AO_LOG_GPS_POS:
604                                                 printf(" lat %10.7f° lon %10.7f° alt %8d m",
605                                                        log_metrum->u.gps.latitude / 10000000.0,
606                                                        log_metrum->u.gps.longitude/ 10000000.0,
607                                                        (int32_t) (log_metrum->u.gps.altitude_low |
608                                                                   (log_metrum->u.gps.altitude_high << 16)));
609                                                 break;
610                                         default:
611                                                 printf(" unknown");
612                                         }
613                                         break;
614                                 case AO_LOG_FORMAT_TELEFIRETWO:
615                                         log_firetwo = (struct ao_log_firetwo *) &eeprom->data[pos];
616                                         switch (log_firetwo->type) {
617                                         case AO_LOG_FLIGHT:
618                                                 printf(" serial %5u flight %5u",
619                                                        eeprom->serial_number,
620                                                        log_firetwo->u.flight.flight);
621                                                 break;
622                                         case AO_LOG_STATE:
623                                                 ao_state(log_firetwo->u.state.state,
624                                                          log_firetwo->u.state.reason);
625                                                 break;
626                                         case AO_LOG_SENSOR:
627                                                 ao_pressure(log_firetwo->u.sensor.pressure,
628                                                             max_adc, adc_ref,
629                                                             sense_r1, sense_r2);
630                                                 ao_thrust(log_firetwo->u.sensor.thrust,
631                                                           max_adc, adc_ref,
632                                                           sense_r1, sense_r2);
633                                                 for (i = 0; i < 4; i++) {
634                                                         char name[20];
635                                                         sprintf(name, "thermistor%d", i);
636                                                         ao_volts(name,
637                                                                  log_firetwo->u.sensor.thermistor[i],
638                                                                  max_adc, adc_ref,
639                                                                  sense_r1, sense_r2);
640                                                 }
641                                                 break;
642                                         }
643                                         break;
644                                 case AO_LOG_FORMAT_TELEGPS:
645                                         log_gps = (struct ao_log_gps *) &eeprom->data[pos];
646                                         switch (log_gps->type) {
647                                         case AO_LOG_GPS_TIME:
648                                                 printf(" lat %10.7f ° lon %10.7f ° alt %8d m",
649                                                        log_gps->u.gps.latitude / 10000000.0,
650                                                        log_gps->u.gps.longitude/ 10000000.0,
651                                                        (int32_t) (log_gps->u.gps.altitude_low |
652                                                                   (log_gps->u.gps.altitude_high << 16)));
653                                                 printf(" time %02d:%02d:%02d %04d-%02d-%02d flags %02x",
654                                                        log_gps->u.gps.hour,
655                                                        log_gps->u.gps.minute,
656                                                        log_gps->u.gps.second,
657                                                        log_gps->u.gps.year + 2000,
658                                                        log_gps->u.gps.month,
659                                                        log_gps->u.gps.day,
660                                                        log_gps->u.gps.flags);
661                                                 printf(" course %3d ground_speed %5u climb_rate %6d pdop %3d hdop %3d vdop %3d mode %3d",
662                                                        log_gps->u.gps.course,
663                                                        log_gps->u.gps.ground_speed,
664                                                        log_gps->u.gps.climb_rate,
665                                                        log_gps->u.gps.pdop,
666                                                        log_gps->u.gps.hdop,
667                                                        log_gps->u.gps.vdop,
668                                                        log_gps->u.gps.mode);
669                                                 break;
670                                         case AO_LOG_GPS_SAT:
671                                                 printf(" channels %2d",
672                                                        log_gps->u.gps_sat.channels);
673                                                 for (i = 0; i < 12; i++) {
674                                                         printf(" svid %3d c_n %2d",
675                                                                log_gps->u.gps_sat.sats[i].svid,
676                                                                log_gps->u.gps_sat.sats[i].c_n);
677                                                 }
678                                                 break;
679                                         default:
680                                                 printf (" unknown");
681                                                 break;
682                                         }
683                                         break;
684                                 case AO_LOG_FORMAT_DETHERM:
685                                         break;
686                                 }
687                         }
688                         printf("\n");
689                 }
690         }
691         return ret;
692 }