From 8ea410d34fd5c8f243ac1429556a0e54bea7bac9 Mon Sep 17 00:00:00 2001 From: Pallavi Revanna Date: Fri, 29 May 2020 09:31:42 -0700 Subject: [PATCH] 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. --- asc2log.c | 40 ++++++++++++++++++++++------------------ candump.c | 4 ++-- log2asc.c | 21 ++++++++++++--------- 3 files changed, 36 insertions(+), 29 deletions(-) diff --git a/asc2log.c b/asc2log.c index de619c0..51d174e 100644 --- a/asc2log.c +++ b/asc2log.c @@ -70,7 +70,7 @@ void print_usage(char *prg) fprintf(stderr, "\t-O \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); @@ -79,6 +79,8 @@ void prframe(FILE *file, struct timeval *tv, int dev, struct canfd_frame *cf, un else fprintf(file, "canX "); + fprintf(file, "%s ", msgdir); + 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]; char tmp1[BUFLEN]; int i, items, found; + char msgdir[BUFLEN]; /* 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 */ - 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, - tmp1, &rtr, &dlc, + tmp1, msgdir, &rtr, &dlc, &data[0], &data[1], &data[2], &data[3], &data[4], &data[5], &data[6], &data[7]); - if ((items == dlc + 6 ) || /* data frame */ - ((items == 5) && (rtr == 'r')) || /* RTR without DLC */ - ((items == 6) && (rtr == 'r'))) { /* RTR with DLC */ + if ((items == dlc + 7 ) || /* data frame */ + ((items == 6) && (rtr == 'r')) || /* RTR without DLC */ + ((items == 7) && (rtr == 'r'))) { /* RTR with DLC */ found = 1; get_can_id(&cf, tmp1, 16); } } 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, - tmp1, &rtr, &dlc, + tmp1, msgdir, &rtr, &dlc, &data[0], &data[1], &data[2], &data[3], &data[4], &data[5], &data[6], &data[7]); - if ((items == dlc + 6 ) || /* data frame */ - ((items == 5) && (rtr == 'r')) || /* RTR without DLC */ - ((items == 6) && (rtr == 'r'))) { /* RTR with DLC */ + if ((items == dlc + 7 ) || /* data frame */ + ((items == 6) && (rtr == 'r')) || /* RTR without DLC */ + ((items == 7) && (rtr == 'r'))) { /* RTR with DLC */ found = 1; 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; 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); return; } @@ -203,7 +206,7 @@ void eval_can(char* buf, struct timeval *date_tvp, char timestamps, char base, i cf.len = CAN_ERR_DLC; 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); } } @@ -219,6 +222,7 @@ void eval_canfd(char* buf, struct timeval *date_tvp, char timestamps, int dplace unsigned int flags; int dlc, dlen = 0; char tmp1[BUFLEN]; + char msgdir[BUFLEN]; char *ptr; int i; @@ -232,13 +236,13 @@ void eval_canfd(char* buf, struct timeval *date_tvp, char timestamps, int dplace memset(&cf, 0, sizeof(cf)); /* check for valid line without symbolic name */ - if (sscanf(buf, "%ld.%ld %*s %d %*s %s %hhx %hhx %x %d ", - &read_tv.tv_sec, &read_tv.tv_usec, &interface, + if (sscanf(buf, "%ld.%ld %*s %d %s %s %hhx %hhx %x %d ", + &read_tv.tv_sec, &read_tv.tv_usec, &interface, msgdir, tmp1, &brs, &esi, &dlc, &dlen) != 8) { /* check for valid line with a symbolic name */ - if (sscanf(buf, "%ld.%ld %*s %d %*s %s %*s %hhx %hhx %x %d ", - &read_tv.tv_sec, &read_tv.tv_usec, &interface, + if (sscanf(buf, "%ld.%ld %*s %d %s %s %*s %hhx %hhx %x %d ", + &read_tv.tv_sec, &read_tv.tv_usec, &interface, msgdir, tmp1, &brs, &esi, &dlc, &dlen) != 8) { /* 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); - prframe(outfile, &tv, interface, &cf, dlen); + prframe(outfile, &tv, interface, &cf, dlen, msgdir); fflush(outfile); return; diff --git a/candump.c b/candump.c index 846c706..fb0e75d 100644 --- a/candump.c +++ b/candump.c @@ -706,9 +706,9 @@ int main(int argc, char **argv) /* log CAN frame with absolute timestamp & device */ 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, - max_devname_len, devname[idx], buf); + max_devname_len, devname[idx], (msg.msg_flags & MSG_DONTROUTE)?"Tx":"Rx", buf); } if ((logfrmt) && (silent == SILENT_OFF)){ diff --git a/log2asc.c b/log2asc.c index 3ce800b..4307f1d 100644 --- a/log2asc.c +++ b/log2asc.c @@ -71,7 +71,7 @@ void print_usage(char *prg) 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; char id[10]; @@ -83,7 +83,9 @@ void can_asc(struct canfd_frame *cf, int devno, int nortrdlc, FILE *outfile) else { sprintf(id, "%X%c", cf->can_id & CAN_EFF_MASK, (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 (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; 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_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, (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) { - static char buf[BUFSZ], device[BUFSZ], ascframe[BUFSZ]; + static char buf[BUFSZ], device[BUFSZ], ascframe[BUFSZ], msgdir[BUFSZ]; struct canfd_frame cf; static struct timeval tv, start_tv; @@ -223,8 +226,8 @@ int main(int argc, char **argv) if (buf[0] != '(') continue; - if (sscanf(buf, "(%ld.%ld) %s %s", &tv.tv_sec, &tv.tv_usec, - device, ascframe) != 4) { + if (sscanf(buf, "(%ld.%ld) %s %s %s", &tv.tv_sec, &tv.tv_usec, + device, msgdir, ascframe) != 5) { fprintf(stderr, "incorrect line format in logfile\n"); return 1; } @@ -267,9 +270,9 @@ int main(int argc, char **argv) fprintf(outfile, "%4ld.%06ld ", tv.tv_sec, tv.tv_usec); if ((mtu == CAN_MTU) && (fdfmt == 0)) - can_asc(&cf, devno, nortrdlc, outfile); + can_asc(&cf, devno, nortrdlc, outfile, msgdir); else - canfd_asc(&cf, devno, mtu, outfile); + canfd_asc(&cf, devno, mtu, outfile, msgdir); if (crlf) fprintf(outfile, "\r");