From f1284e83aa20a90874860e72b7a7bd312d4f76fe Mon Sep 17 00:00:00 2001 From: Oliver Hartkopp Date: Sun, 7 Jan 2007 11:19:37 +0000 Subject: [PATCH] Added option '-L' to candump to create the compact logfile output on stdout. Now you can forward CAN frames e.g. via netcat with candump and canplayer: candump can0 can1 -L | canplayer vcan3=can0 vcan0=can1 -t OK, maybe it would be reasonable to write a short program for this application. But for some tests all this can be done with existing commandline tools. In addition the filtering possibilities of candump can be used here. --- candump.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/candump.c b/candump.c index 83ac4bb..a622006 100644 --- a/candump.c +++ b/candump.c @@ -107,6 +107,7 @@ void print_usage(char *prg) fprintf(stderr, " -s (silent mode - 1: animation 2: nothing)\n"); fprintf(stderr, " -b (bridge mode - send received frames to )\n"); fprintf(stderr, " -l (log CAN-frames into file)\n"); + fprintf(stderr, " -L (use log file format on stdout)\n"); fprintf(stderr, "\n"); fprintf(stderr, "When using more than one CAN interface the options\n"); fprintf(stderr, "m/v/i/e have comma seperated values e.g. '-m 0,7FF,0'\n"); @@ -172,6 +173,7 @@ int main(int argc, char **argv) unsigned char color = 0; unsigned char ascii = 0; unsigned char log = 0; + unsigned char logfrmt = 0; int opt, ret; int currmax = 1; /* we assume at least one can bus ;-) */ struct sockaddr_can addr; @@ -188,7 +190,7 @@ int main(int argc, char **argv) last_tv.tv_sec = 0; /* init */ - while ((opt = getopt(argc, argv, "m:v:i:e:t:cas:b:l")) != -1) { + while ((opt = getopt(argc, argv, "m:v:i:e:t:cas:b:lL")) != -1) { switch (opt) { case 'm': i = sscanf(optarg, "%x,%x,%x,%x,%x,%x", @@ -276,6 +278,10 @@ int main(int argc, char **argv) log = 1; break; + case 'L': + logfrmt = 1; + break; + default: fprintf(stderr, "Unknown option %c\n", opt); print_usage(basename(argv[0])); @@ -441,7 +447,7 @@ int main(int argc, char **argv) } } - if (timestamp || log) + if (timestamp || log || logfrmt) if (ioctl(s[i], SIOCGSTAMP, &tv) < 0) perror("SIOCGSTAMP"); @@ -451,18 +457,25 @@ int main(int argc, char **argv) if (log) { /* log CAN frame with absolute timestamp & device */ fprintf(logfile, "(%ld.%06ld) ", tv.tv_sec, tv.tv_usec); - fprintf(logfile, "%*s", max_devname_len, devname[idx]); - fprintf(logfile, " "); + fprintf(logfile, "%*s ", max_devname_len, devname[idx]); /* without seperator as logfile use-case is parsing */ fprint_canframe(logfile, &frame, "\n", 0); } + if (logfrmt) { + /* print CAN frame in log file style to stdout */ + printf("(%ld.%06ld) ", tv.tv_sec, tv.tv_usec); + printf("%*s ", max_devname_len, devname[idx]); + fprint_canframe(stdout, &frame, "\n", 0); + continue; /* no other output to stdout */ + } + if (silent){ if (silent == 1) { printf("%c\b", anichar[silentani%=MAXANI]); silentani++; } - continue; + continue; /* no other output to stdout */ } printf(" %s", (color>2)?col_on[idx]:"");