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-view | |
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-view')
-rw-r--r-- | ao-tools/ao-view/aoview_eeprom.c | 2 | ||||
-rw-r--r-- | ao-tools/ao-view/aoview_file.c | 53 | ||||
-rw-r--r-- | ao-tools/ao-view/aoview_log.c | 12 | ||||
-rw-r--r-- | ao-tools/ao-view/aoview_monitor.c | 1 |
4 files changed, 41 insertions, 27 deletions
diff --git a/ao-tools/ao-view/aoview_eeprom.c b/ao-tools/ao-view/aoview_eeprom.c index 34e2deed..447b83a4 100644 --- a/ao-tools/ao-view/aoview_eeprom.c +++ b/ao-tools/ao-view/aoview_eeprom.c @@ -66,6 +66,8 @@ aoview_eeprom_parse(struct aoview_serial *serial, if (sscanf(line, "serial-number %u", &serial_number) == 1) { aoview_file_set_serial(eeprom_file, serial_number); } else if (sscanf(line, "%c %x %x %x", &cmd, &tick, &a, &b) == 4) { + if (cmd == 'F') + aoview_file_set_flight(eeprom_file, b); aoview_file_printf(eeprom_file, "%s\n", line); if (cmd == 'S' && a == 8) { aoview_eeprom_done(serial); diff --git a/ao-tools/ao-view/aoview_file.c b/ao-tools/ao-view/aoview_file.c index 5288c2f7..292887a0 100644 --- a/ao-tools/ao-view/aoview_file.c +++ b/ao-tools/ao-view/aoview_file.c @@ -28,6 +28,7 @@ struct aoview_file { char *name; int failed; int serial; + int flight; int sequence; }; @@ -94,6 +95,7 @@ gboolean aoview_file_start(struct aoview_file *file) { char base[50]; + char seq[20]; struct tm tm; time_t now; char *full; @@ -105,34 +107,17 @@ aoview_file_start(struct aoview_file *file) if (file->failed) return FALSE; - now = time(NULL); - (void) localtime_r(&now, &tm); - aoview_mkdir(aoview_file_dir); - for (;;) { - snprintf(base, sizeof (base), "%04d-%02d-%02d-serial-%03d-flight-%03d.%s", - tm.tm_year + 1900, - tm.tm_mon + 1, - tm.tm_mday, - file->serial, - file->sequence, - file->ext); - full = aoview_fullname(aoview_file_dir, base); - r = access(full, F_OK); - if (r < 0) { - file->file = fopen(full, "w"); - if (!file->file) { - aoview_file_open_failed(full); - free(full); - file->failed = 1; - return FALSE; - } else { - setlinebuf(file->file); - file->name = full; - return TRUE; - } - } + full = cc_make_filename(file->serial, file->flight, file->ext); + file->file = fopen(full, "w"); + if (!file->file) { + aoview_file_open_failed(full); free(full); - file->sequence++; + file->failed = 1; + return FALSE; + } else { + setlinebuf(file->file); + file->name = full; + return TRUE; } } @@ -196,6 +181,20 @@ aoview_file_get_serial(struct aoview_file *file) } void +aoview_file_set_flight(struct aoview_file *file, int flight) +{ + if (flight != file->flight) + aoview_file_finish(file); + file->flight = flight; +} + +int +aoview_file_get_flight(struct aoview_file *file) +{ + return file->flight; +} + +void aoview_file_init(GladeXML *xml) { GConfClient *gconf_client; diff --git a/ao-tools/ao-view/aoview_log.c b/ao-tools/ao-view/aoview_log.c index 1b89c28c..2880ecb1 100644 --- a/ao-tools/ao-view/aoview_log.c +++ b/ao-tools/ao-view/aoview_log.c @@ -39,6 +39,18 @@ aoview_log_get_serial(void) } void +aoview_log_set_flight(int flight) +{ + aoview_file_set_flight(aoview_log, flight); +} + +int +aoview_log_get_flight(void) +{ + return aoview_file_get_flight(aoview_log); +} + +void aoview_log_printf(char *format, ...) { va_list ap; diff --git a/ao-tools/ao-view/aoview_monitor.c b/ao-tools/ao-view/aoview_monitor.c index 3d235e44..4d7e7a9f 100644 --- a/ao-tools/ao-view/aoview_monitor.c +++ b/ao-tools/ao-view/aoview_monitor.c @@ -68,6 +68,7 @@ aoview_monitor_callback(gpointer user_data, if (monitor_pos) { if (aoview_monitor_parse(monitor_line)) { aoview_log_set_serial(aostate.data.serial); + aoview_log_set_flight(aostate.data.flight); if (aoview_log_get_serial()) aoview_log_printf ("%s\n", monitor_line); } |