1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
|
/*
* Copyright © 2009 Keith Packard <keithp@keithp.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <unistd.h>
#include <getopt.h>
#include <ao-eeprom-read.h>
#include <ao-atmosphere.h>
static const struct option options[] = {
{ .name = "raw", .has_arg = 0, .val = 'r' },
{ .name = "csum", .has_arg = 0, .val = 'c' },
{ .name = "verbose", .has_arg = 0, .val = 'v' },
{ .name = "len", .has_arg = 1, .val = 'l' },
{ 0, 0, 0, 0},
};
static void usage(char *program)
{
fprintf(stderr, "usage: %s [--raw] [--csum] [--verbose] [--len <record-len>] {flight.eeprom} ...\n", program);
exit(1);
}
static bool
ao_csum_valid(uint8_t *d, int len)
{
uint8_t sum = 0x5a;
int i;
for (i = 0; i < len; i++)
sum += d[i];
return sum == 0;
}
static void
ao_ms5607(uint32_t pres, uint32_t temp, struct ao_eeprom *eeprom, bool is_ms5611)
{
struct ao_ms5607_sample ms5607_sample = { .pres = pres, .temp = temp };
struct ao_ms5607_value ms5607_value;
ao_ms5607_convert(&ms5607_sample, &ms5607_value,
&eeprom->ms5607_prom, is_ms5611);
printf(" pres %9u temp %9u (%7.3f kPa %6.2f°C %7.1f m)",
pres,
temp,
ms5607_value.pres / 1000.0,
ms5607_value.temp / 100.0,
ao_pressure_to_altitude(ms5607_value.pres));
}
#define GRAVITY 9.80665
static void
ao_accel(int16_t accel, struct ao_eeprom *eeprom)
{
double accel_2g = eeprom->config.accel_minus_g - eeprom->config.accel_plus_g;
double accel_scale = GRAVITY * 2.0 / accel_2g;
printf(" accel %6d (%7.2f m/s²)",
accel, (eeprom->config.accel_plus_g - accel) * accel_scale);
}
static const char *state_names[] = {
"startup",
"idle",
"pad",
"boost",
"fast",
"coast",
"drogue",
"main",
"landed",
"invalid"
};
#define NUM_STATE (sizeof state_names/sizeof state_names[0])
static const char *
ao_state_name(uint16_t state)
{
if (state < NUM_STATE)
return state_names[state];
return "UNKNOWN";
}
static void
ao_state(uint16_t state, uint16_t reason)
{
printf(" state %5u %s reason %5u",
state, ao_state_name(state), reason);
}
static void
ao_volts(const char *name, int16_t value, int16_t max_adc, double ref, double r1, double r2)
{
printf(" %s %5d",
name, value);
if (r1 && r2 && ref)
printf("(%6.3f V)",
ref * ((double) value / max_adc) * (r1 + r2) / r2);
}
#if 0
static uint16_t
uint16(uint8_t *bytes, int off)
{
return (uint16_t) bytes[off] | (((uint16_t) bytes[off+1]) << 8);
}
static int16_t
int16(uint8_t *bytes, int off)
{
return (int16_t) uint16(bytes, off);
}
static uint32_t
uint32(uint8_t *bytes, int off)
{
return (uint32_t) bytes[off] | (((uint32_t) bytes[off+1]) << 8) |
(((uint32_t) bytes[off+2]) << 16) |
(((uint32_t) bytes[off+3]) << 24);
}
static int32_t
int32(uint8_t *bytes, int off)
{
return (int32_t) uint32(bytes, off);
}
#endif
static uint32_t
uint24(uint8_t *bytes, int off)
{
return (uint32_t) bytes[off] | (((uint32_t) bytes[off+1]) << 8) |
(((uint32_t) bytes[off+2]) << 16);
}
static int32_t
int24(uint8_t *bytes, int off)
{
return (int32_t) uint24(bytes, off);
}
int
main (int argc, char **argv)
{
struct ao_eeprom *eeprom;
FILE *file;
int c;
bool raw = false;
bool csum = false;
bool verbose = false;
int arg_len = 0;
char *end;
int ret = 0;
int i;
while ((c = getopt_long(argc, argv, "rcvl:", options, NULL)) != -1) {
switch (c) {
case 'r':
raw = true;
break;
case 'c':
csum = true;
break;
case 'v':
verbose = true;
break;
case 'l':
arg_len = strtol(optarg, &end, 0);
if (!*optarg || *end)
usage(argv[0]);
break;
default:
usage(argv[0]);
break;
}
}
for (i = optind; i < argc; i++) {
file = fopen(argv[i], "r");
if (!file) {
perror(argv[i]);
ret++;
continue;
}
eeprom = ao_eeprom_read(file);
fclose(file);
if (!eeprom) {
perror(argv[i]);
ret++;
continue;
}
int len = 0;
bool is_ms5611 = false;
double sense_r1 = 0.0, sense_r2 = 0.0;
double batt_r1 = 0.0, batt_r2 = 0.0;
double adc_ref = 0.0;
int16_t max_adc = 0;
switch (eeprom->log_format) {
case AO_LOG_FORMAT_TELEMEGA_OLD:
len = 32;
break;
case AO_LOG_FORMAT_EASYMINI1:
len = 16;
max_adc = 32767;
if (eeprom->serial_number < 1000)
adc_ref = 3.0;
else
adc_ref = 3.3;
batt_r1 = sense_r1 = 100e3;
batt_r2 = sense_r2 = 27e3;
break;
case AO_LOG_FORMAT_TELEMETRUM:
len = 16;
max_adc = 4095;
adc_ref = 3.3;
batt_r1 = 5600;
batt_r2 = 10000;
sense_r1 = 100e3;
sense_r2 = 27e3;
break;
case AO_LOG_FORMAT_TELEMINI2:
len = 16;
break;
case AO_LOG_FORMAT_TELEGPS:
len = 32;
break;
case AO_LOG_FORMAT_TELEMEGA:
len = 32;
max_adc = 4095;
adc_ref = 3.3;
batt_r1 = 5600;
batt_r2 = 10000;
sense_r1 = 100e3;
sense_r2 = 27e3;
break;
case AO_LOG_FORMAT_DETHERM:
len = 16;
break;
case AO_LOG_FORMAT_TELEMINI3:
len = 16;
max_adc = 4095;
adc_ref = 3.3;
batt_r1 = 5600;
batt_r2 = 10000;
sense_r1 = 100e3;
sense_r2 = 27e3;
break;
case AO_LOG_FORMAT_TELEFIRETWO:
len = 32;
break;
case AO_LOG_FORMAT_EASYMINI2:
len = 16;
max_adc = 4095;
adc_ref = 3.3;
batt_r1 = sense_r1 = 100e3;
batt_r2 = sense_r2 = 27e3;
break;
case AO_LOG_FORMAT_TELEMEGA_3:
len = 32;
max_adc = 4095;
adc_ref = 3.3;
batt_r1 = 5600;
batt_r2 = 10000;
sense_r1 = 100e3;
sense_r2 = 27e3;
break;
case AO_LOG_FORMAT_EASYMEGA_2:
len = 32;
max_adc = 4095;
adc_ref = 3.3;
batt_r1 = 5600;
batt_r2 = 10000;
sense_r1 = 100e3;
sense_r2 = 27e3;
break;
case AO_LOG_FORMAT_TELESTATIC:
len = 32;
break;
case AO_LOG_FORMAT_MICROPEAK2:
len = 2;
break;
}
if (arg_len)
len = arg_len;
printf("config major %d minor %d log format %d total %u len %d\n",
eeprom->config.major,
eeprom->config.minor,
eeprom->log_format,
eeprom->len,
len);
uint32_t pos;
for (pos = 0; pos < eeprom->len; pos += len) {
int i;
if (raw) {
printf("%9u", pos);
for (i = 0; i < len; i++)
printf(" %02x", eeprom->data[pos + i]);
} else {
struct ao_log_mega *log_mega;
struct ao_log_mini *log_mini;
struct ao_log_metrum *log_metrum;
struct ao_log_gps *log_gps;
if (!csum && !ao_csum_valid(&eeprom->data[pos], len)) {
if (verbose)
printf("\tchecksum error at %d\n", pos);
continue;
}
struct ao_log_header *log_header = (struct ao_log_header *) &eeprom->data[pos];
printf("type %c tick %5u", log_header->type, log_header->tick);
switch (eeprom->log_format) {
case AO_LOG_FORMAT_TELEMEGA_OLD:
case AO_LOG_FORMAT_TELEMEGA:
case AO_LOG_FORMAT_TELEMEGA_3:
case AO_LOG_FORMAT_EASYMEGA_2:
log_mega = (struct ao_log_mega *) &eeprom->data[pos];
switch (log_mega->type) {
case AO_LOG_FLIGHT:
printf(" serial %5u flight %5u ground_accel %6d ground_pres %9u",
eeprom->serial_number,
log_mega->u.flight.flight,
log_mega->u.flight.ground_accel,
log_mega->u.flight.ground_pres);
printf(" along %6d aross %6d through %6d",
log_mega->u.flight.ground_accel_along,
log_mega->u.flight.ground_accel_across,
log_mega->u.flight.ground_accel_through);
printf(" roll %6d pitch %6d yaw %6d",
log_mega->u.flight.ground_roll,
log_mega->u.flight.ground_pitch,
log_mega->u.flight.ground_yaw);
break;
case AO_LOG_STATE:
ao_state(log_mega->u.state.state,
log_mega->u.state.reason);
break;
case AO_LOG_SENSOR:
ao_ms5607(log_mega->u.sensor.pres,
log_mega->u.sensor.temp,
eeprom, is_ms5611);
printf(" accel_x %6d accel_y %6d accel_z %6d",
log_mega->u.sensor.accel_x,
log_mega->u.sensor.accel_y,
log_mega->u.sensor.accel_z);
printf (" gyro_x %6d gyro_y %6d gyro_z %6d",
log_mega->u.sensor.gyro_x,
log_mega->u.sensor.gyro_y,
log_mega->u.sensor.gyro_z);
printf (" mag_x %6d mag_y %6d mag_z %6d",
log_mega->u.sensor.mag_x,
log_mega->u.sensor.mag_y,
log_mega->u.sensor.mag_z);
ao_accel(log_mega->u.sensor.accel, eeprom);
break;
case AO_LOG_TEMP_VOLT:
ao_volts("v_batt",
log_mega->u.volt.v_batt,
max_adc,
adc_ref,
batt_r1, batt_r2);
ao_volts("v_pbatt",
log_mega->u.volt.v_pbatt,
max_adc,
adc_ref,
sense_r1, sense_r2);
printf(" n_sense %1d",
log_mega->u.volt.n_sense);
for (i = 0; i < log_mega->u.volt.n_sense; i++) {
char name[10];
sprintf(name, "sense%d", i);
ao_volts(name,
log_mega->u.volt.sense[i],
max_adc,
adc_ref,
sense_r1, sense_r2);
}
printf(" pyro %04x", log_mega->u.volt.pyro);
break;
case AO_LOG_GPS_TIME:
printf(" lat %10.7f° lon %10.7f° alt %8d m",
log_mega->u.gps.latitude / 10000000.0,
log_mega->u.gps.longitude/ 10000000.0,
(int32_t) (log_mega->u.gps.altitude_low |
(log_mega->u.gps.altitude_high << 16)));
printf(" time %02d:%02d:%02d 20%02d-%02d-%02d flags %02x",
log_mega->u.gps.hour,
log_mega->u.gps.minute,
log_mega->u.gps.second,
log_mega->u.gps.year,
log_mega->u.gps.month,
log_mega->u.gps.day,
log_mega->u.gps.flags);
printf(" course %3d ground_speed %5u climb_rate %6d pdop %3d hdop %3d vdop %3d mode %3d",
log_mega->u.gps.course,
log_mega->u.gps.ground_speed,
log_mega->u.gps.climb_rate,
log_mega->u.gps.pdop,
log_mega->u.gps.hdop,
log_mega->u.gps.vdop,
log_mega->u.gps.mode);
break;
case AO_LOG_GPS_SAT:
printf(" channels %2d",
log_mega->u.gps_sat.channels);
for (i = 0; i < 12; i++) {
printf(" svid %3d c_n %2d",
log_mega->u.gps_sat.sats[i].svid,
log_mega->u.gps_sat.sats[i].c_n);
}
break;
}
break;
case AO_LOG_FORMAT_EASYMINI1:
case AO_LOG_FORMAT_EASYMINI2:
case AO_LOG_FORMAT_TELEMINI2:
case AO_LOG_FORMAT_TELEMINI3:
log_mini = (struct ao_log_mini *) &eeprom->data[pos];
switch (log_mini->type) {
case AO_LOG_FLIGHT:
printf(" serial %5u flight %5u ground_pres %9u",
eeprom->serial_number,
log_mini->u.flight.flight,
log_mini->u.flight.ground_pres);
break;
case AO_LOG_STATE:
ao_state(log_mini->u.state.state,
log_mini->u.state.reason);
break;
case AO_LOG_SENSOR:
ao_ms5607(int24(log_mini->u.sensor.pres, 0),
int24(log_mini->u.sensor.temp, 0),
eeprom, is_ms5611);
ao_volts("sense_a",
log_mini->u.sensor.sense_a, max_adc,
adc_ref, sense_r1, sense_r2);
ao_volts("sense_m",
log_mini->u.sensor.sense_m, max_adc,
adc_ref, sense_r1, sense_r2);
ao_volts("v_batt",
log_mini->u.sensor.v_batt, max_adc,
adc_ref, batt_r1, batt_r2);
break;
} /* */
break;
case AO_LOG_FORMAT_TELEMETRUM:
log_metrum = (struct ao_log_metrum *) &eeprom->data[pos];
switch (log_metrum->type) {
case AO_LOG_FLIGHT:
printf(" serial %5u flight %5u ground_accel %6d ground_pres %9u ground_temp %9u",
eeprom->serial_number,
log_metrum->u.flight.flight,
log_metrum->u.flight.ground_accel,
log_metrum->u.flight.ground_pres,
log_metrum->u.flight.ground_temp);
break;
case AO_LOG_SENSOR:
ao_ms5607(log_metrum->u.sensor.pres,
log_metrum->u.sensor.temp,
eeprom, is_ms5611);
ao_accel(log_metrum->u.sensor.accel, eeprom);
break;
case AO_LOG_TEMP_VOLT:
ao_volts("v_batt",
log_metrum->u.volt.v_batt, max_adc,
adc_ref, batt_r1, batt_r2);
ao_volts("sense_a",
log_metrum->u.volt.sense_a, max_adc,
adc_ref, sense_r1, sense_r2);
ao_volts("sense_m",
log_metrum->u.volt.sense_m, max_adc,
adc_ref, sense_r1, sense_r2);
break;
case AO_LOG_DEPLOY:
break;
case AO_LOG_STATE:
ao_state(log_metrum->u.state.state,
log_metrum->u.state.reason);
break;
case AO_LOG_GPS_TIME:
printf(" time %02d:%02d:%02d 20%02d-%02d-%02d flags %02x pdop %3u",
log_metrum->u.gps_time.hour,
log_metrum->u.gps_time.minute,
log_metrum->u.gps_time.second,
log_metrum->u.gps_time.year,
log_metrum->u.gps_time.month,
log_metrum->u.gps_time.day,
log_metrum->u.gps_time.flags,
log_metrum->u.gps_time.pdop);
break;
case AO_LOG_GPS_SAT:
printf(" channels %2d more %1d",
log_metrum->u.gps_sat.channels,
log_metrum->u.gps_sat.more);
for (i = 0; i < 4; i++) {
printf(" svid %3d c_n %2d",
log_metrum->u.gps_sat.sats[i].svid,
log_metrum->u.gps_sat.sats[i].c_n);
}
break;
case AO_LOG_GPS_POS:
printf(" lat %10.7f° lon %10.7f° alt %8d m",
log_metrum->u.gps.latitude / 10000000.0,
log_metrum->u.gps.longitude/ 10000000.0,
(int32_t) (log_metrum->u.gps.altitude_low |
(log_metrum->u.gps.altitude_high << 16)));
break;
default:
printf(" unknown");
}
break;
case AO_LOG_FORMAT_TELEGPS:
log_gps = (struct ao_log_gps *) &eeprom->data[pos];
(void) log_gps;
break;
case AO_LOG_FORMAT_DETHERM:
break;
}
}
printf("\n");
}
}
return ret;
}
|