diff --git a/asc2log.c b/asc2log.c index cecaa9f..9d61184 100644 --- a/asc2log.c +++ b/asc2log.c @@ -57,6 +57,8 @@ #include "lib.h" +#define BUFLEN 400 /* CAN FD mode lines can be pretty long */ + extern int optind, opterr, optopt; void print_usage(char *prg) @@ -124,6 +126,85 @@ void calc_tv(struct timeval *tv, struct timeval *read_tv, } } +void eval_can(char* buf, struct timeval *date_tvp, char timestamps, char base, int dplace, FILE *outfile) { + + int interface; + static struct timeval tv; /* current frame timestamp */ + static struct timeval read_tv; /* frame timestamp from ASC file */ + struct can_frame cf; + char rtr; + int dlc = 0; + int data[8]; + char tmp1[BUFLEN]; + int i, found; + + /* 0.002367 1 390x Rx d 8 17 00 14 00 C0 00 08 00 */ + + found = 0; /* found valid CAN frame ? */ + + if (base == 'h') { /* check for CAN frames with hexadecimal values */ + + if (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, + &data[0], &data[1], &data[2], &data[3], + &data[4], &data[5], &data[6], &data[7] + ) == dlc + 6 ) { + + found = 1; + get_can_id(&cf, tmp1, 16); + } + + } else { /* check for CAN frames with decimal values */ + + if (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, + &data[0], &data[1], &data[2], &data[3], + &data[4], &data[5], &data[6], &data[7] + ) == dlc + 6 ) { + + found = 1; + get_can_id(&cf, tmp1, 10); + } + } + + if (found) { + if (rtr == 'r') + cf.can_id |= CAN_RTR_FLAG; + + cf.can_dlc = dlc & 0x0FU; + for (i=0; i