From c46e832b28820d7c5be4efaacbbd7c0607927fe5 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 5 Sep 2009 22:03:31 -0700 Subject: Add simple post-flight analysis tool (ao-postflight) This tool reads either an eeprom or telem log file and displays some rudimentary data (max accel/alt for each flight stage). Signed-off-by: Keith Packard --- ao-tools/lib/cc-log.c | 114 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 ao-tools/lib/cc-log.c (limited to 'ao-tools/lib/cc-log.c') diff --git a/ao-tools/lib/cc-log.c b/ao-tools/lib/cc-log.c new file mode 100644 index 00000000..dd8177f4 --- /dev/null +++ b/ao-tools/lib/cc-log.c @@ -0,0 +1,114 @@ +/* + * Copyright © 2009 Keith Packard + * + * 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; version 2 of the License. + * + * 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 +#include +#include +#include +#include +#include "cc.h" + +static char *cc_file_dir; + +#define ALTOS_DIR_PATH "/apps/aoview/log_dir" +#define DEFAULT_DIR "AltOS" + +static void +cc_file_save_conf(void) +{ + GConfClient *gconf_client; + + g_type_init(); + gconf_client = gconf_client_get_default(); + if (gconf_client) + { + gconf_client_set_string(gconf_client, + ALTOS_DIR_PATH, + cc_file_dir, + NULL); + g_object_unref(G_OBJECT(gconf_client)); + } +} + +static void +cc_file_load_conf(void) +{ + char *file_dir; + GConfClient *gconf_client; + + g_type_init(); + gconf_client = gconf_client_get_default(); + if (gconf_client) + { + file_dir = gconf_client_get_string(gconf_client, + ALTOS_DIR_PATH, + NULL); + g_object_unref(G_OBJECT(gconf_client)); + if (file_dir) + cc_file_dir = strdup(file_dir); + } +} + +void +cc_set_log_dir(char *dir) +{ + cc_file_dir = strdup(dir); + cc_file_save_conf(); +} + +char * +cc_get_log_dir(void) +{ + cc_file_load_conf(); + if (!cc_file_dir) { + cc_file_dir = cc_fullname(getenv("HOME"), DEFAULT_DIR); + cc_file_save_conf(); + } + return cc_file_dir; +} + +char * +cc_make_filename(int serial, char *ext) +{ + char base[50]; + struct tm tm; + time_t now; + char *full; + int r; + int sequence; + + now = time(NULL); + (void) localtime_r(&now, &tm); + cc_mkdir(cc_get_log_dir()); + sequence = 0; + for (;;) { + snprintf(base, sizeof (base), "%04d-%02d-%02d-serial-%03d-flight-%03d.%s", + tm.tm_year + 1900, + tm.tm_mon + 1, + tm.tm_mday, + serial, + sequence, + ext); + full = cc_fullname(cc_get_log_dir(), base); + r = access(full, F_OK); + if (r < 0) + return full; + free(full); + sequence++; + } + +} -- cgit v1.2.3 From d6ba07e885bdc62ba64719c9d8cc42fcecbcb09d Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 22 Nov 2009 01:10:44 -0800 Subject: 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 --- ao-tools/ao-dumplog/ao-dumplog.c | 32 +++++++++++++++-------- ao-tools/ao-view/aoview_eeprom.c | 2 ++ ao-tools/ao-view/aoview_file.c | 53 +++++++++++++++++++-------------------- ao-tools/ao-view/aoview_log.c | 12 +++++++++ ao-tools/ao-view/aoview_monitor.c | 1 + ao-tools/lib/cc-log.c | 23 +++++++++++------ ao-tools/lib/cc.h | 2 +- 7 files changed, 78 insertions(+), 47 deletions(-) (limited to 'ao-tools/lib/cc-log.c') 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 #include #include +#include #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]); 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; } } @@ -195,6 +180,20 @@ aoview_file_get_serial(struct aoview_file *file) return file->serial; } +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) { 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 @@ -38,6 +38,18 @@ aoview_log_get_serial(void) return aoview_file_get_serial(aoview_log); } +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, ...) { 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); } diff --git a/ao-tools/lib/cc-log.c b/ao-tools/lib/cc-log.c index dd8177f4..ed51f87e 100644 --- a/ao-tools/lib/cc-log.c +++ b/ao-tools/lib/cc-log.c @@ -82,9 +82,10 @@ cc_get_log_dir(void) } char * -cc_make_filename(int serial, char *ext) +cc_make_filename(int serial, int flight, char *ext) { char base[50]; + char seq[20]; struct tm tm; time_t now; char *full; @@ -96,13 +97,19 @@ cc_make_filename(int serial, char *ext) cc_mkdir(cc_get_log_dir()); sequence = 0; for (;;) { - snprintf(base, sizeof (base), "%04d-%02d-%02d-serial-%03d-flight-%03d.%s", - tm.tm_year + 1900, - tm.tm_mon + 1, - tm.tm_mday, - serial, - sequence, - ext); + if (sequence) + snprintf(seq, sizeof(seq), "-seq-%03d", sequence); + else + seq[0] = '\0'; + + snprintf(base, sizeof (base), "%04d-%02d-%02d-serial-%03d-flight-%03d%s.%s", + tm.tm_year + 1900, + tm.tm_mon + 1, + tm.tm_mday, + serial, + flight, + seq, + ext); full = cc_fullname(cc_get_log_dir(), base); r = access(full, F_OK); if (r < 0) diff --git a/ao-tools/lib/cc.h b/ao-tools/lib/cc.h index 46b16a8e..ede46aa0 100644 --- a/ao-tools/lib/cc.h +++ b/ao-tools/lib/cc.h @@ -61,7 +61,7 @@ char * cc_get_log_dir(void); char * -cc_make_filename(int serial, char *ext); +cc_make_filename(int serial, int flight, char *ext); /* * For sequential data which are not evenly spaced -- cgit v1.2.3