diff options
author | Keith Packard <keithp@keithp.com> | 2009-11-22 01:10:44 -0800 |
---|---|---|
committer | Keith Packard <keithp@keithp.com> | 2009-11-22 01:10:44 -0800 |
commit | d6ba07e885bdc62ba64719c9d8cc42fcecbcb09d (patch) | |
tree | 61cb9db84c208b96c828e38223827bc23d25c4c4 /ao-tools/ao-dumplog | |
parent | 06cebd1026dc1bd6ee51526fa2d02905df3b3b37 (diff) |
Automatically extract flight number for eeprom and telem filenames.
Extract flight number from either telemetry or eeprom files and use
that in the resulting filenames. To ensure that files remain unique,
add a new field, -seq-%03d. This is appended only when the sequence
number is non-zero as it shouldn't occur in normal usage.
This also eliminates some duplicate filename creation code in the
library and aoview sources.
Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'ao-tools/ao-dumplog')
-rw-r--r-- | ao-tools/ao-dumplog/ao-dumplog.c | 32 |
1 files changed, 21 insertions, 11 deletions
diff --git a/ao-tools/ao-dumplog/ao-dumplog.c b/ao-tools/ao-dumplog/ao-dumplog.c index b3a0a25a..440a02b5 100644 --- a/ao-tools/ao-dumplog/ao-dumplog.c +++ b/ao-tools/ao-dumplog/ao-dumplog.c @@ -20,6 +20,7 @@ #include <stdlib.h> #include <unistd.h> #include <getopt.h> +#include <string.h> #include "cc-usb.h" #include "cc.h" @@ -62,6 +63,7 @@ static const char *state_names[] = { "invalid" }; + int main (int argc, char **argv) { @@ -72,7 +74,8 @@ main (int argc, char **argv) char line[8192]; FILE *out; char *filename; - int serial_number; + int serial_number = 0; + int flight = 0; char cmd; int tick, a, b; int block; @@ -84,6 +87,7 @@ main (int argc, char **argv) int remote = 0; int any_valid; int invalid; + char serial_line[8192]; while ((c = getopt_long(argc, argv, "T:D:R", options, NULL)) != -1) { switch (c) { @@ -121,24 +125,17 @@ main (int argc, char **argv) out = NULL; for (;;) { cc_usb_getline(cc, line, sizeof (line)); - if (sscanf(line, "serial-number %u", &serial_number) == 1) { - filename = cc_make_filename(serial_number, "eeprom"); - out = fopen (filename, "w"); - if (!out) { - perror(filename); - } - fprintf (out, "%s\n", line); - } + if (sscanf(line, "serial-number %u", &serial_number) == 1) + strcpy(serial_line, line); if (!strncmp(line, "software-version", 16)) break; } - if (!out) { + if (!serial_number) { fprintf(stderr, "no serial number found\n"); cc_usb_close(cc); exit(1); } printf ("Serial number: %d\n", serial_number); - printf ("File name: %s\n", filename); done = 0; column = 0; for (block = 0; !done && block < 511; block++) { @@ -170,6 +167,19 @@ main (int argc, char **argv) tick = data[2] + (data[3] << 8); a = data[4] + (data[5] << 8); b = data[6] + (data[7] << 8); + if (cmd == 'F') { + flight = b; + filename = cc_make_filename(serial_number, flight, "eeprom"); + printf ("Flight: %d\n", flight); + printf ("File name: %s\n", filename); + out = fopen (filename, "w"); + if (!out) { + perror(filename); + exit(1); + } + fprintf(out, "%s\n", serial_line); + } + if (cmd == 'S' && a <= 8) { if (column) putchar('\n'); printf("%s\n", state_names[a]); |