mirror of
https://github.com/linux-can/can-utils.git
synced 2026-09-24 00:51:09 +02:00
- added error frame support in lib.c
- added sprint_* functions for CAN-frame output in lib.c / lib.h - added comments / cosmetics candump.c: - removed support for the output in ASC representation (moved to log2asc.c) - added option '-l' for logfile creation e.g. 'candump-2007-01-01_164123.log' - added funtionality to terminate candump by pressing [ENTER] (not only ^C) - added error frame support - added color support even when reading from 'any' - three different color levels (e.g. -c -c -c) - making use if lib.c cangen.c: - CAN frames generator for testing purposes (e.g. on vcanx) (nice when you're on vacancy at the baltic sea and have no real CAN source :) log2long.c: - convert compact CAN frame representation into user readable representation log2asc.c: - convert compact CAN frame logfile to ASC logfile for 3rd party CAN tools Next step: Create a tool to replay candump logfiles.
This commit is contained in:
@@ -66,8 +66,7 @@
|
||||
#include <linux/can/raw.h>
|
||||
|
||||
#include "terminal.h"
|
||||
|
||||
#define USE_RECVFROM /* use read() or recvfrom() syscall */
|
||||
#include "lib.h"
|
||||
|
||||
#define MAXDEV 6 /* change sscanf()'s manually if changed here */
|
||||
#define ANYDEV "any"
|
||||
@@ -81,8 +80,12 @@
|
||||
#define MAGENTA ATTBOLD FGMAGENTA
|
||||
#define CYAN ATTBOLD FGCYAN
|
||||
|
||||
static const char col_on [MAXDEV][19] = {BOLD, MAGENTA, GREEN, BLUE, CYAN, RED};
|
||||
static const char col_off [] = ATTRESET;
|
||||
const char col_on [MAXDEV][19] = {BOLD, MAGENTA, GREEN, BLUE, CYAN, RED};
|
||||
const char col_off [] = ATTRESET;
|
||||
|
||||
static char devname[MAXDEV][IFNAMSIZ+1];
|
||||
static int dindex[MAXDEV];
|
||||
static int max_devname_len;
|
||||
|
||||
#define MAXANI 8
|
||||
const char anichar[MAXANI] = {'|', '/', '-', '\\', '|', '/', '-', '\\'};
|
||||
@@ -97,16 +100,16 @@ void print_usage(char *prg)
|
||||
fprintf(stderr, "Options: -m <mask> (default 0x00000000)\n");
|
||||
fprintf(stderr, " -v <value> (default 0x00000000)\n");
|
||||
fprintf(stderr, " -i <0|1> (inv_filter)\n");
|
||||
fprintf(stderr, " -e <emask> (mask for error frames)\n");
|
||||
fprintf(stderr, " -t <type> (timestamp: Absolute/Delta/Zero)\n");
|
||||
fprintf(stderr, " -c (color mode)\n");
|
||||
fprintf(stderr, " -a (enable additional ASCII output)\n");
|
||||
fprintf(stderr, " -s <level> (silent mode - 1: animation 2: nothing)\n");
|
||||
fprintf(stderr, " -b <can> (bridge mode - send received frames to <can>)\n");
|
||||
fprintf(stderr, " -a (create ASC compatible output)\n");
|
||||
fprintf(stderr, " -1 (increment interface numbering in ASC mode)\n");
|
||||
fprintf(stderr, " -A (enable ASCII output)\n");
|
||||
fprintf(stderr, " -l (log CAN-frames into file)\n");
|
||||
fprintf(stderr, "\n");
|
||||
fprintf(stderr, "When using more than one CAN interface the options\n");
|
||||
fprintf(stderr, "m/v/i have comma seperated values e.g. '-m 0,7FF,0'\n");
|
||||
fprintf(stderr, "m/v/i/e have comma seperated values e.g. '-m 0,7FF,0'\n");
|
||||
fprintf(stderr, "Use interface name '%s' to receive from all can-interfaces\n", ANYDEV);
|
||||
}
|
||||
|
||||
@@ -115,6 +118,45 @@ void sigterm(int signo)
|
||||
running = 0;
|
||||
}
|
||||
|
||||
int idx2dindex(int ifidx, int socket) {
|
||||
|
||||
int i;
|
||||
struct ifreq ifr;
|
||||
|
||||
for (i=0; i<MAXDEV; i++) {
|
||||
if (dindex[i] == ifidx)
|
||||
return i;
|
||||
}
|
||||
|
||||
/* create new interface index cache entry */
|
||||
|
||||
for (i=0; i < MAXDEV; i++)
|
||||
if (!dindex[i]) /* free entry */
|
||||
break;
|
||||
|
||||
if (i == MAXDEV) {
|
||||
printf("BUG in interface index cache! MAXDEV?\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
dindex[i] = ifidx;
|
||||
|
||||
ifr.ifr_ifindex = ifidx;
|
||||
if (ioctl(socket, SIOCGIFNAME, &ifr) < 0)
|
||||
perror("SIOCGIFNAME");
|
||||
|
||||
if (max_devname_len < strlen(ifr.ifr_name))
|
||||
max_devname_len = strlen(ifr.ifr_name);
|
||||
|
||||
strcpy(devname[i], ifr.ifr_name);
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("new index %d (%s)\n", i, devname[i]);
|
||||
#endif
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
fd_set rdfs;
|
||||
@@ -123,15 +165,13 @@ int main(int argc, char **argv)
|
||||
canid_t mask[MAXDEV] = {0};
|
||||
canid_t value[MAXDEV] = {0};
|
||||
int inv_filter[MAXDEV] = {0};
|
||||
char devname[MAXDEV][IFNAMSIZ];
|
||||
can_err_mask_t err_mask[MAXDEV] = {0};
|
||||
unsigned char timestamp = 0;
|
||||
unsigned char silent = 0;
|
||||
unsigned char silentani = 0;
|
||||
unsigned char color = 0;
|
||||
unsigned char ascii = 0;
|
||||
unsigned char asc = 0;
|
||||
unsigned char asc_inc_channel = 0;
|
||||
int max_devname_len = 0;
|
||||
unsigned char log = 0;
|
||||
int opt, ret;
|
||||
int currmax = 1; /* we assume at least one can bus ;-) */
|
||||
struct sockaddr_can addr;
|
||||
@@ -139,9 +179,8 @@ int main(int argc, char **argv)
|
||||
struct can_frame frame;
|
||||
int nbytes, i, j;
|
||||
struct ifreq ifr;
|
||||
|
||||
time_t currtime;
|
||||
struct timeval tv, last_tv;
|
||||
FILE *logfile = NULL;
|
||||
|
||||
signal(SIGTERM, sigterm);
|
||||
signal(SIGHUP, sigterm);
|
||||
@@ -149,7 +188,7 @@ int main(int argc, char **argv)
|
||||
|
||||
last_tv.tv_sec = 0; /* init */
|
||||
|
||||
while ((opt = getopt(argc, argv, "m:v:i:b:s:ca1At:")) != -1) {
|
||||
while ((opt = getopt(argc, argv, "m:v:i:e:t:cas:b:l")) != -1) {
|
||||
switch (opt) {
|
||||
case 'm':
|
||||
i = sscanf(optarg, "%x,%x,%x,%x,%x,%x",
|
||||
@@ -175,6 +214,36 @@ int main(int argc, char **argv)
|
||||
currmax = i;
|
||||
break;
|
||||
|
||||
case 'e':
|
||||
i = sscanf(optarg, "%x,%x,%x,%x,%x,%x",
|
||||
&err_mask[0], &err_mask[1], &err_mask[2],
|
||||
&err_mask[3], &err_mask[4], &err_mask[5]);
|
||||
if (i > currmax)
|
||||
currmax = i;
|
||||
break;
|
||||
|
||||
case 't':
|
||||
timestamp = optarg[0];
|
||||
if ((timestamp != 'a') && (timestamp != 'A') &&
|
||||
(timestamp != 'd') && (timestamp != 'z')) {
|
||||
printf("%s: unknown timestamp mode '%c' - ignored\n",
|
||||
basename(argv[0]), optarg[0]);
|
||||
timestamp = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'c':
|
||||
color++;
|
||||
break;
|
||||
|
||||
case 'a':
|
||||
ascii = 1;
|
||||
break;
|
||||
|
||||
case 's':
|
||||
silent = atoi(optarg);
|
||||
break;
|
||||
|
||||
case 'b':
|
||||
if (strlen(optarg) >= IFNAMSIZ) {
|
||||
printf("Name of CAN device '%s' is too long!\n\n", optarg);
|
||||
@@ -203,40 +272,14 @@ int main(int argc, char **argv)
|
||||
}
|
||||
break;
|
||||
|
||||
case 's':
|
||||
silent = atoi(optarg);
|
||||
break;
|
||||
|
||||
case 'c':
|
||||
color = 1;
|
||||
break;
|
||||
|
||||
case 'a':
|
||||
asc = 1;
|
||||
break;
|
||||
|
||||
case '1':
|
||||
asc_inc_channel = 1;
|
||||
break;
|
||||
|
||||
case 'A':
|
||||
ascii = 1;
|
||||
break;
|
||||
|
||||
case 't':
|
||||
timestamp = optarg[0];
|
||||
if ((timestamp != 'a') && (timestamp != 'A') && (timestamp != 'd') && (timestamp != 'z')) {
|
||||
printf("%s: unknown timestamp mode '%c' - ignored\n",
|
||||
basename(argv[0]), optarg[0]);
|
||||
timestamp = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case '?':
|
||||
case 'l':
|
||||
log = 1;
|
||||
break;
|
||||
|
||||
default:
|
||||
fprintf(stderr, "Unknown option %c\n", opt);
|
||||
print_usage(basename(argv[0]));
|
||||
exit(1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -262,8 +305,9 @@ int main(int argc, char **argv)
|
||||
for (i=0; i<currmax; i++) {
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("open %d '%s' m%08X v%08X i%d.\n",
|
||||
i, argv[optind+i], mask[i], value[i], inv_filter[i]);
|
||||
printf("open %d '%s' m%08X v%08X i%d e%d.\n",
|
||||
i, argv[optind+i], mask[i], value[i],
|
||||
inv_filter[i], err_mask[i]);
|
||||
#endif
|
||||
|
||||
if ((s[i] = socket(PF_CAN, SOCK_RAW, CAN_RAW)) < 0) {
|
||||
@@ -273,19 +317,24 @@ int main(int argc, char **argv)
|
||||
|
||||
if (mask[i] || value[i]) {
|
||||
|
||||
if (!(asc)) /* this output is not asc compatible! */
|
||||
printf("CAN ID filter[%d] for %s set to mask = %08X, value = %08X %s\n",
|
||||
i, argv[optind+i], mask[i], value[i],
|
||||
(inv_filter[i]) ? "(inv_filter)" : "");
|
||||
printf("CAN ID filter[%d] for %s set to "
|
||||
"mask = %08X, value = %08X %s\n",
|
||||
i, argv[optind+i], mask[i], value[i],
|
||||
(inv_filter[i]) ? "(inv_filter)" : "");
|
||||
|
||||
rfilter.can_id = value[i];
|
||||
rfilter.can_mask = mask[i];
|
||||
if (inv_filter[i])
|
||||
rfilter.can_id |= CAN_INV_FILTER;
|
||||
|
||||
setsockopt(s[i], SOL_CAN_RAW, CAN_RAW_FILTER, &rfilter, sizeof(rfilter));
|
||||
setsockopt(s[i], SOL_CAN_RAW, CAN_RAW_FILTER,
|
||||
&rfilter, sizeof(rfilter));
|
||||
}
|
||||
|
||||
if (err_mask[i])
|
||||
setsockopt(s[i], SOL_CAN_RAW, CAN_RAW_ERR_FILTER,
|
||||
&err_mask[i], sizeof(err_mask[i]));
|
||||
|
||||
j = strlen(argv[optind+i]);
|
||||
|
||||
if (!(j < IFNAMSIZ)) {
|
||||
@@ -293,8 +342,6 @@ int main(int argc, char **argv)
|
||||
return 1;
|
||||
}
|
||||
|
||||
strcpy(devname[i], argv[optind+i]);
|
||||
|
||||
if (j > max_devname_len)
|
||||
max_devname_len = j; /* for nice printing */
|
||||
|
||||
@@ -302,8 +349,10 @@ int main(int argc, char **argv)
|
||||
|
||||
if (strcmp(ANYDEV, argv[optind+i])) {
|
||||
strcpy(ifr.ifr_name, argv[optind+i]);
|
||||
if (ioctl(s[i], SIOCGIFINDEX, &ifr) < 0)
|
||||
if (ioctl(s[i], SIOCGIFINDEX, &ifr) < 0) {
|
||||
perror("SIOCGIFINDEX");
|
||||
exit(1);
|
||||
}
|
||||
addr.can_ifindex = ifr.ifr_ifindex;
|
||||
}
|
||||
else
|
||||
@@ -315,31 +364,39 @@ int main(int argc, char **argv)
|
||||
}
|
||||
}
|
||||
|
||||
if (asc) {
|
||||
char datestring[40];
|
||||
|
||||
/* print banner for ASC mode */
|
||||
|
||||
if (timestamp != 'd') /* delta time is allowed, else ... */
|
||||
timestamp = 'z'; /* ASC-files always start with zero time */
|
||||
if (log) {
|
||||
time_t currtime;
|
||||
struct tm now;
|
||||
char fname[sizeof("candump-2006-11-20_202026.log")+1];
|
||||
|
||||
if (time(&currtime) == (time_t)-1) {
|
||||
perror("time");
|
||||
return 1;
|
||||
}
|
||||
strncpy(datestring, ctime(&currtime), 39); /* copy to private buffer */
|
||||
datestring[strlen(datestring)-1] = 0; /* chop off trailing newline */
|
||||
printf("date %s%s", datestring, ANL); /* print with own new line representation */
|
||||
|
||||
printf("base hex timestamps %s%s", (timestamp == 'd')?"relative":"absolute", ANL);
|
||||
printf("no internal events logged%s", ANL);
|
||||
fflush(stdout);
|
||||
localtime_r(&currtime, &now);
|
||||
|
||||
sprintf(fname, "candump-%04d-%02d-%02d_%02d%02d%02d.log",
|
||||
now.tm_year + 1900,
|
||||
now.tm_mon + 1,
|
||||
now.tm_mday,
|
||||
now.tm_hour,
|
||||
now.tm_min,
|
||||
now.tm_sec);
|
||||
|
||||
printf("\nEnabling Logfile '%s'\n\n", fname);
|
||||
|
||||
logfile = fopen(fname, "w");
|
||||
if (!logfile) {
|
||||
perror("logfile");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
while (running) {
|
||||
|
||||
FD_ZERO(&rdfs);
|
||||
|
||||
FD_SET(0, &rdfs);
|
||||
for (i=0; i<currmax; i++)
|
||||
FD_SET(s[i], &rdfs);
|
||||
|
||||
@@ -349,155 +406,118 @@ int main(int argc, char **argv)
|
||||
continue;
|
||||
}
|
||||
|
||||
for (i=0; i<currmax; i++) {
|
||||
if (FD_ISSET(0, &rdfs)) {
|
||||
running = 0; /* stop with input from stdin */
|
||||
getchar();
|
||||
}
|
||||
|
||||
for (i=0; i<currmax; i++) { /* check all CAN RAW sockets */
|
||||
|
||||
if (FD_ISSET(s[i], &rdfs)) {
|
||||
|
||||
#ifdef USE_RECVFROM
|
||||
socklen_t len = sizeof(addr);
|
||||
if ((nbytes = recvfrom(s[i], &frame, sizeof(struct can_frame), 0, (struct sockaddr*)&addr, &len)) < 0) {
|
||||
#else
|
||||
if ((nbytes = read(s[i], &frame, sizeof(struct can_frame))) < 0) {
|
||||
#endif
|
||||
int idx;
|
||||
|
||||
if ((nbytes = recvfrom(s[i], &frame,
|
||||
sizeof(struct can_frame), 0,
|
||||
(struct sockaddr*)&addr, &len)) < 0) {
|
||||
perror("read");
|
||||
return 1;
|
||||
} else if (nbytes < sizeof(struct can_frame)) {
|
||||
}
|
||||
|
||||
if (nbytes < sizeof(struct can_frame)) {
|
||||
fprintf(stderr, "read: incomplete CAN frame\n");
|
||||
return 1;
|
||||
} else {
|
||||
if (bridge) {
|
||||
if ((nbytes = write(bridge, &frame, sizeof(struct can_frame))) < 0) {
|
||||
perror("bridge write");
|
||||
return 1;
|
||||
} else if (nbytes < sizeof(struct can_frame)) {
|
||||
fprintf(stderr, "bridge write: incomplete CAN frame\n");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (silent){
|
||||
if (silent == 1)
|
||||
printf("%c\b", anichar[silentani%=MAXANI]), silentani++;
|
||||
}
|
||||
else {
|
||||
|
||||
switch (timestamp) {
|
||||
|
||||
case 'a': /* absolute with timestamp */
|
||||
if (ioctl(s[i], SIOCGSTAMP, &tv) < 0)
|
||||
perror("SIOCGSTAMP");
|
||||
if (asc)
|
||||
printf("%4ld.%04ld ", tv.tv_sec, tv.tv_usec/100);
|
||||
else
|
||||
printf("(%ld.%06ld) ", tv.tv_sec, tv.tv_usec);
|
||||
break;
|
||||
|
||||
case 'A': /* absolute with date */
|
||||
{
|
||||
struct tm tm;
|
||||
char timestring[25];
|
||||
if (ioctl(s[i], SIOCGSTAMP, &tv) < 0)
|
||||
perror("SIOCGSTAMP");
|
||||
tm = *localtime(&tv.tv_sec);
|
||||
strftime(timestring, 24, "%Y-%m-%d %H:%M:%S", &tm);
|
||||
if (asc)
|
||||
printf("%s.%04ld ", timestring, tv.tv_usec/100);
|
||||
else
|
||||
printf("(%s.%06ld) ", timestring, tv.tv_usec);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'd': /* delta */
|
||||
case 'z': /* starting with zero */
|
||||
{
|
||||
struct timeval diff;
|
||||
|
||||
if (ioctl(s[i], SIOCGSTAMP, &tv) < 0)
|
||||
perror("SIOCGSTAMP");
|
||||
if (last_tv.tv_sec == 0) /* first init */
|
||||
last_tv = tv;
|
||||
diff.tv_sec = tv.tv_sec - last_tv.tv_sec;
|
||||
diff.tv_usec = tv.tv_usec - last_tv.tv_usec;
|
||||
if (diff.tv_usec < 0)
|
||||
diff.tv_sec--, diff.tv_usec += 1000000;
|
||||
if (diff.tv_sec < 0)
|
||||
diff.tv_sec = diff.tv_usec = 0;
|
||||
if (asc)
|
||||
printf("%4ld.%04ld ", diff.tv_sec, diff.tv_usec/100);
|
||||
else
|
||||
printf("(%ld.%06ld) ", diff.tv_sec, diff.tv_usec);
|
||||
|
||||
if (timestamp == 'd')
|
||||
last_tv = tv; /* update for delta calculation */
|
||||
}
|
||||
break;
|
||||
|
||||
default: /* no timestamp output */
|
||||
break;
|
||||
}
|
||||
|
||||
if (asc) {
|
||||
char id[10];
|
||||
|
||||
printf("%-2d ", i + asc_inc_channel); /* channel number - left aligned */
|
||||
|
||||
sprintf(id, "%X%c", frame.can_id & CAN_EFF_MASK,
|
||||
(frame.can_id & CAN_EFF_FLAG)?'x':' ');
|
||||
printf("%-15s Rx ", id);
|
||||
|
||||
if (frame.can_id & CAN_RTR_FLAG)
|
||||
printf("r"); /* RTR frame: nothing else to print */
|
||||
else {
|
||||
printf("d %d ", frame.can_dlc); /* data frame */
|
||||
|
||||
for (j = 0; j < frame.can_dlc; j++) {
|
||||
printf("%02X ", frame.data[j]);
|
||||
}
|
||||
}
|
||||
printf("%s", ANL);
|
||||
}
|
||||
else {
|
||||
printf(" %s",(color)?col_on[i]:"");
|
||||
#ifdef USE_RECVFROM
|
||||
ifr.ifr_ifindex = addr.can_ifindex;
|
||||
if (ioctl(s[i], SIOCGIFNAME, &ifr) < 0)
|
||||
perror("SIOCGIFNAME");
|
||||
|
||||
if (max_devname_len < strlen(ifr.ifr_name))
|
||||
max_devname_len = strlen(ifr.ifr_name);
|
||||
|
||||
printf("%*s", max_devname_len, ifr.ifr_name);
|
||||
#else
|
||||
printf("%*s", max_devname_len, devname[i]); /* device name */
|
||||
#endif
|
||||
printf("%s ",(color)?col_off:"");
|
||||
if (frame.can_id & CAN_EFF_FLAG)
|
||||
printf("%8X ", frame.can_id & CAN_EFF_MASK);
|
||||
else
|
||||
printf("%3X ", frame.can_id & CAN_SFF_MASK);
|
||||
|
||||
printf("[%d] ", frame.can_dlc);
|
||||
|
||||
for (j = 0; j < frame.can_dlc; j++) {
|
||||
printf("%02X ", frame.data[j]);
|
||||
}
|
||||
if (ascii) {
|
||||
printf("%*s", 3*(8-frame.can_dlc)+3, "'");
|
||||
for (j = 0; j < frame.can_dlc; j++)
|
||||
if ((frame.data[j] > 0x1F) && (frame.data[j] < 0x7F))
|
||||
putchar(frame.data[j]);
|
||||
else
|
||||
putchar('.');
|
||||
printf("' ");
|
||||
}
|
||||
if (frame.can_id & CAN_RTR_FLAG)
|
||||
printf("remote request");
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
if (bridge) {
|
||||
if ((nbytes = write(bridge, &frame,
|
||||
sizeof(struct can_frame))) < 0) {
|
||||
perror("bridge write");
|
||||
return 1;
|
||||
} else if (nbytes < sizeof(struct can_frame)) {
|
||||
fprintf(stderr,"bridge write: incomplete CAN frame\n");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (timestamp || log)
|
||||
if (ioctl(s[i], SIOCGSTAMP, &tv) < 0)
|
||||
perror("SIOCGSTAMP");
|
||||
|
||||
|
||||
idx = idx2dindex(addr.can_ifindex, s[i]);
|
||||
|
||||
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, " ");
|
||||
/* without seperator as logfile use-case is parsing */
|
||||
fprint_canframe(logfile, &frame, "\n", 0);
|
||||
}
|
||||
|
||||
if (silent){
|
||||
if (silent == 1) {
|
||||
printf("%c\b", anichar[silentani%=MAXANI]);
|
||||
silentani++;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
printf(" %s",(color>2)?col_on[idx]:"");
|
||||
|
||||
switch (timestamp) {
|
||||
|
||||
case 'a': /* absolute with timestamp */
|
||||
printf("(%ld.%06ld) ", tv.tv_sec, tv.tv_usec);
|
||||
break;
|
||||
|
||||
case 'A': /* absolute with date */
|
||||
{
|
||||
struct tm tm;
|
||||
char timestring[25];
|
||||
|
||||
tm = *localtime(&tv.tv_sec);
|
||||
strftime(timestring, 24, "%Y-%m-%d %H:%M:%S", &tm);
|
||||
printf("(%s.%06ld) ", timestring, tv.tv_usec);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'd': /* delta */
|
||||
case 'z': /* starting with zero */
|
||||
{
|
||||
struct timeval diff;
|
||||
|
||||
if (last_tv.tv_sec == 0) /* first init */
|
||||
last_tv = tv;
|
||||
diff.tv_sec = tv.tv_sec - last_tv.tv_sec;
|
||||
diff.tv_usec = tv.tv_usec - last_tv.tv_usec;
|
||||
if (diff.tv_usec < 0)
|
||||
diff.tv_sec--, diff.tv_usec += 1000000;
|
||||
if (diff.tv_sec < 0)
|
||||
diff.tv_sec = diff.tv_usec = 0;
|
||||
printf("(%ld.%06ld) ", diff.tv_sec, diff.tv_usec);
|
||||
|
||||
if (timestamp == 'd')
|
||||
last_tv = tv; /* update for delta calculation */
|
||||
}
|
||||
break;
|
||||
|
||||
default: /* no timestamp output */
|
||||
break;
|
||||
}
|
||||
|
||||
printf(" %s",(color && (color<3))?col_on[idx]:"");
|
||||
printf("%*s", max_devname_len, devname[idx]);
|
||||
printf("%s ",(color<2)?col_off:"");
|
||||
|
||||
fprint_long_canframe(stdout, &frame, NULL, ascii);
|
||||
|
||||
printf("%s",(color>1)?col_off:"");
|
||||
printf("\n");
|
||||
}
|
||||
fflush(stdout);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -507,5 +527,8 @@ int main(int argc, char **argv)
|
||||
if (bridge)
|
||||
close(bridge);
|
||||
|
||||
if (log)
|
||||
fclose(logfile);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user