Added CAN message direction (Tx or Rx) for log file recording in candump.

Log file converters log2asc and asc2log are updated to parse the message direction.
pull/213/head
Pallavi Revanna 2020-05-29 09:31:42 -07:00
parent da42cf4bb5
commit 8ea410d34f
3 changed files with 36 additions and 29 deletions

View File

@ -70,7 +70,7 @@ void print_usage(char *prg)
fprintf(stderr, "\t-O <outfile>\t(default stdout)\n"); fprintf(stderr, "\t-O <outfile>\t(default stdout)\n");
} }
void prframe(FILE *file, struct timeval *tv, int dev, struct canfd_frame *cf, unsigned int max_dlen) { void prframe(FILE *file, struct timeval *tv, int dev, struct canfd_frame *cf, unsigned int max_dlen, char *msgdir) {
fprintf(file, "(%ld.%06ld) ", tv->tv_sec, tv->tv_usec); fprintf(file, "(%ld.%06ld) ", tv->tv_sec, tv->tv_usec);
@ -79,6 +79,8 @@ void prframe(FILE *file, struct timeval *tv, int dev, struct canfd_frame *cf, un
else else
fprintf(file, "canX "); fprintf(file, "canX ");
fprintf(file, "%s ", msgdir);
fprint_canframe(file, cf, "\n", 0, max_dlen); fprint_canframe(file, cf, "\n", 0, max_dlen);
} }
@ -136,6 +138,7 @@ void eval_can(char* buf, struct timeval *date_tvp, char timestamps, char base, i
int data[8]; int data[8];
char tmp1[BUFLEN]; char tmp1[BUFLEN];
int i, items, found; int i, items, found;
char msgdir[BUFLEN];
/* 0.002367 1 390x Rx d 8 17 00 14 00 C0 00 08 00 */ /* 0.002367 1 390x Rx d 8 17 00 14 00 C0 00 08 00 */
@ -143,30 +146,30 @@ void eval_can(char* buf, struct timeval *date_tvp, char timestamps, char base, i
if (base == 'h') { /* check for CAN frames with hexadecimal values */ if (base == 'h') { /* check for CAN frames with hexadecimal values */
items = sscanf(buf, "%ld.%ld %d %s %*s %c %d %x %x %x %x %x %x %x %x", items = sscanf(buf, "%ld.%ld %d %s %s %c %d %x %x %x %x %x %x %x %x",
&read_tv.tv_sec, &read_tv.tv_usec, &interface, &read_tv.tv_sec, &read_tv.tv_usec, &interface,
tmp1, &rtr, &dlc, tmp1, msgdir, &rtr, &dlc,
&data[0], &data[1], &data[2], &data[3], &data[0], &data[1], &data[2], &data[3],
&data[4], &data[5], &data[6], &data[7]); &data[4], &data[5], &data[6], &data[7]);
if ((items == dlc + 6 ) || /* data frame */ if ((items == dlc + 7 ) || /* data frame */
((items == 5) && (rtr == 'r')) || /* RTR without DLC */ ((items == 6) && (rtr == 'r')) || /* RTR without DLC */
((items == 6) && (rtr == 'r'))) { /* RTR with DLC */ ((items == 7) && (rtr == 'r'))) { /* RTR with DLC */
found = 1; found = 1;
get_can_id(&cf, tmp1, 16); get_can_id(&cf, tmp1, 16);
} }
} else { /* check for CAN frames with decimal values */ } else { /* check for CAN frames with decimal values */
items = sscanf(buf, "%ld.%ld %d %s %*s %c %d %d %d %d %d %d %d %d %d", items = sscanf(buf, "%ld.%ld %d %s %s %c %d %d %d %d %d %d %d %d %d",
&read_tv.tv_sec, &read_tv.tv_usec, &interface, &read_tv.tv_sec, &read_tv.tv_usec, &interface,
tmp1, &rtr, &dlc, tmp1, msgdir, &rtr, &dlc,
&data[0], &data[1], &data[2], &data[3], &data[0], &data[1], &data[2], &data[3],
&data[4], &data[5], &data[6], &data[7]); &data[4], &data[5], &data[6], &data[7]);
if ((items == dlc + 6 ) || /* data frame */ if ((items == dlc + 7 ) || /* data frame */
((items == 5) && (rtr == 'r')) || /* RTR without DLC */ ((items == 6) && (rtr == 'r')) || /* RTR without DLC */
((items == 6) && (rtr == 'r'))) { /* RTR with DLC */ ((items == 7) && (rtr == 'r'))) { /* RTR with DLC */
found = 1; found = 1;
get_can_id(&cf, tmp1, 10); get_can_id(&cf, tmp1, 10);
} }
@ -185,7 +188,7 @@ void eval_can(char* buf, struct timeval *date_tvp, char timestamps, char base, i
cf.data[i] = data[i] & 0xFFU; cf.data[i] = data[i] & 0xFFU;
calc_tv(&tv, &read_tv, date_tvp, timestamps, dplace); calc_tv(&tv, &read_tv, date_tvp, timestamps, dplace);
prframe(outfile, &tv, interface, &cf, CAN_MAX_DLEN); prframe(outfile, &tv, interface, &cf, CAN_MAX_DLEN, msgdir);
fflush(outfile); fflush(outfile);
return; return;
} }
@ -203,7 +206,7 @@ void eval_can(char* buf, struct timeval *date_tvp, char timestamps, char base, i
cf.len = CAN_ERR_DLC; cf.len = CAN_ERR_DLC;
calc_tv(&tv, &read_tv, date_tvp, timestamps, dplace); calc_tv(&tv, &read_tv, date_tvp, timestamps, dplace);
prframe(outfile, &tv, interface, &cf, CAN_MAX_DLEN); prframe(outfile, &tv, interface, &cf, CAN_MAX_DLEN, msgdir);
fflush(outfile); fflush(outfile);
} }
} }
@ -219,6 +222,7 @@ void eval_canfd(char* buf, struct timeval *date_tvp, char timestamps, int dplace
unsigned int flags; unsigned int flags;
int dlc, dlen = 0; int dlc, dlen = 0;
char tmp1[BUFLEN]; char tmp1[BUFLEN];
char msgdir[BUFLEN];
char *ptr; char *ptr;
int i; int i;
@ -232,13 +236,13 @@ void eval_canfd(char* buf, struct timeval *date_tvp, char timestamps, int dplace
memset(&cf, 0, sizeof(cf)); memset(&cf, 0, sizeof(cf));
/* check for valid line without symbolic name */ /* check for valid line without symbolic name */
if (sscanf(buf, "%ld.%ld %*s %d %*s %s %hhx %hhx %x %d ", if (sscanf(buf, "%ld.%ld %*s %d %s %s %hhx %hhx %x %d ",
&read_tv.tv_sec, &read_tv.tv_usec, &interface, &read_tv.tv_sec, &read_tv.tv_usec, &interface, msgdir,
tmp1, &brs, &esi, &dlc, &dlen) != 8) { tmp1, &brs, &esi, &dlc, &dlen) != 8) {
/* check for valid line with a symbolic name */ /* check for valid line with a symbolic name */
if (sscanf(buf, "%ld.%ld %*s %d %*s %s %*s %hhx %hhx %x %d ", if (sscanf(buf, "%ld.%ld %*s %d %s %s %*s %hhx %hhx %x %d ",
&read_tv.tv_sec, &read_tv.tv_usec, &interface, &read_tv.tv_sec, &read_tv.tv_usec, &interface, msgdir,
tmp1, &brs, &esi, &dlc, &dlen) != 8) { tmp1, &brs, &esi, &dlc, &dlen) != 8) {
/* no valid CANFD format pattern */ /* no valid CANFD format pattern */
@ -313,7 +317,7 @@ void eval_canfd(char* buf, struct timeval *date_tvp, char timestamps, int dplace
} }
calc_tv(&tv, &read_tv, date_tvp, timestamps, dplace); calc_tv(&tv, &read_tv, date_tvp, timestamps, dplace);
prframe(outfile, &tv, interface, &cf, dlen); prframe(outfile, &tv, interface, &cf, dlen, msgdir);
fflush(outfile); fflush(outfile);
return; return;

View File

@ -706,9 +706,9 @@ int main(int argc, char **argv)
/* log CAN frame with absolute timestamp & device */ /* log CAN frame with absolute timestamp & device */
sprint_canframe(buf, &frame, 0, maxdlen); sprint_canframe(buf, &frame, 0, maxdlen);
fprintf(logfile, "(%010ld.%06ld) %*s %s\n", fprintf(logfile, "(%010ld.%06ld) %*s %s %s\n",
tv.tv_sec, tv.tv_usec, tv.tv_sec, tv.tv_usec,
max_devname_len, devname[idx], buf); max_devname_len, devname[idx], (msg.msg_flags & MSG_DONTROUTE)?"Tx":"Rx", buf);
} }
if ((logfrmt) && (silent == SILENT_OFF)){ if ((logfrmt) && (silent == SILENT_OFF)){

View File

@ -71,7 +71,7 @@ void print_usage(char *prg)
fprintf(stderr, " -r (supress dlc for RTR frames - pre v8.5 tools)\n"); fprintf(stderr, " -r (supress dlc for RTR frames - pre v8.5 tools)\n");
} }
void can_asc(struct canfd_frame *cf, int devno, int nortrdlc, FILE *outfile) void can_asc(struct canfd_frame *cf, int devno, int nortrdlc, FILE *outfile, char *msgdir)
{ {
int i; int i;
char id[10]; char id[10];
@ -83,7 +83,9 @@ void can_asc(struct canfd_frame *cf, int devno, int nortrdlc, FILE *outfile)
else { else {
sprintf(id, "%X%c", cf->can_id & CAN_EFF_MASK, sprintf(id, "%X%c", cf->can_id & CAN_EFF_MASK,
(cf->can_id & CAN_EFF_FLAG)?'x':' '); (cf->can_id & CAN_EFF_FLAG)?'x':' ');
fprintf(outfile, "%-15s Rx ", id);
fprintf(outfile, "%-15s ", id);
fprintf(outfile, "%s ", msgdir); /* message direction (Tx or Rx) */
if (cf->can_id & CAN_RTR_FLAG) { if (cf->can_id & CAN_RTR_FLAG) {
if (nortrdlc) if (nortrdlc)
@ -100,7 +102,7 @@ void can_asc(struct canfd_frame *cf, int devno, int nortrdlc, FILE *outfile)
} }
} }
void canfd_asc(struct canfd_frame *cf, int devno, int mtu, FILE *outfile) void canfd_asc(struct canfd_frame *cf, int devno, int mtu, FILE *outfile, char *msgdir)
{ {
int i; int i;
char id[10]; char id[10];
@ -113,7 +115,8 @@ void canfd_asc(struct canfd_frame *cf, int devno, int mtu, FILE *outfile)
#define ASC_F_BRS 0x00002000 #define ASC_F_BRS 0x00002000
#define ASC_F_ESI 0x00004000 #define ASC_F_ESI 0x00004000
fprintf(outfile, "CANFD %3d Rx ", devno); /* 3 column channel number right aligned */ fprintf(outfile, "CANFD %3d ", devno); /* 3 column channel number right aligned */
fprintf(outfile, "%s ", msgdir); /* message direction (Tx or Rx) */
sprintf(id, "%X%c", cf->can_id & CAN_EFF_MASK, sprintf(id, "%X%c", cf->can_id & CAN_EFF_MASK,
(cf->can_id & CAN_EFF_FLAG)?'x':' '); (cf->can_id & CAN_EFF_FLAG)?'x':' ');
@ -147,7 +150,7 @@ void canfd_asc(struct canfd_frame *cf, int devno, int mtu, FILE *outfile)
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
static char buf[BUFSZ], device[BUFSZ], ascframe[BUFSZ]; static char buf[BUFSZ], device[BUFSZ], ascframe[BUFSZ], msgdir[BUFSZ];
struct canfd_frame cf; struct canfd_frame cf;
static struct timeval tv, start_tv; static struct timeval tv, start_tv;
@ -223,8 +226,8 @@ int main(int argc, char **argv)
if (buf[0] != '(') if (buf[0] != '(')
continue; continue;
if (sscanf(buf, "(%ld.%ld) %s %s", &tv.tv_sec, &tv.tv_usec, if (sscanf(buf, "(%ld.%ld) %s %s %s", &tv.tv_sec, &tv.tv_usec,
device, ascframe) != 4) { device, msgdir, ascframe) != 5) {
fprintf(stderr, "incorrect line format in logfile\n"); fprintf(stderr, "incorrect line format in logfile\n");
return 1; return 1;
} }
@ -267,9 +270,9 @@ int main(int argc, char **argv)
fprintf(outfile, "%4ld.%06ld ", tv.tv_sec, tv.tv_usec); fprintf(outfile, "%4ld.%06ld ", tv.tv_sec, tv.tv_usec);
if ((mtu == CAN_MTU) && (fdfmt == 0)) if ((mtu == CAN_MTU) && (fdfmt == 0))
can_asc(&cf, devno, nortrdlc, outfile); can_asc(&cf, devno, nortrdlc, outfile, msgdir);
else else
canfd_asc(&cf, devno, mtu, outfile); canfd_asc(&cf, devno, mtu, outfile, msgdir);
if (crlf) if (crlf)
fprintf(outfile, "\r"); fprintf(outfile, "\r");