diff --git a/asc2log.c b/asc2log.c index 060c4d3..fe69598 100644 --- a/asc2log.c +++ b/asc2log.c @@ -265,6 +265,7 @@ static void eval_canfd(char* buf, struct timeval *date_tvp, char timestamps, char *extra_info; char *ptr; int i; + int n = 0; /* sscanf consumed characters */ unsigned long long sec, usec; /* @@ -279,14 +280,14 @@ static void eval_canfd(char* buf, struct timeval *date_tvp, char timestamps, */ /* check for valid line without symbolic name */ - if (sscanf(buf, "%llu.%llu %*s %d %4s %s %hhx %hhx %x %d ", + if (sscanf(buf, "%llu.%llu %*s %d %4s %s %hhx %hhx %x %d %n", &sec, &usec, &interface, - dir, tmp1, &brs, &esi, &dlc, &dlen) != 9) { + dir, tmp1, &brs, &esi, &dlc, &dlen, &n) != 9) { /* check for valid line with a symbolic name */ - if (sscanf(buf, "%llu.%llu %*s %d %4s %s %*s %hhx %hhx %x %d ", + if (sscanf(buf, "%llu.%llu %*s %d %4s %s %*s %hhx %hhx %x %d %n", &sec, &usec, &interface, - dir, tmp1, &brs, &esi, &dlc, &dlen) != 9) { + dir, tmp1, &brs, &esi, &dlc, &dlen, &n) != 9) { /* no valid CANFD format pattern */ return; @@ -322,15 +323,7 @@ static void eval_canfd(char* buf, struct timeval *date_tvp, char timestamps, get_can_id(&cf.can_id, tmp1, 16); - /* now search for the beginning of the data[] content */ - sprintf(tmp1, " %x %x %x %2d ", brs, esi, dlc, dlen); - - /* search for the pattern generated by real data */ - ptr = strcasestr(buf, tmp1); - if (ptr == NULL) - return; - - ptr += strlen(tmp1); /* start of ASCII hex frame data */ + ptr = buf + n; /* start of ASCII hex frame data */ cf.len = dlen; @@ -402,13 +395,14 @@ static void eval_canxl_xl(char* buf, struct timeval *date_tvp, char timestamps, static struct timeval read_tv; /* frame timestamp from ASC file */ struct canxl_frame cf = { 0 }; unsigned char sdt, vcid, secbit, ctmp; - unsigned int af, sbc, pcrc, flags; + unsigned int af, flags; int dlc, dlen = 0; char tmp1[BUFLEN]; char dir[5]; /* 'Rx'/'Tx'/'TxRq' plus terminating zero */ char *extra_info; char *ptr; int i; + int n = 0; /* sscanf consumed characters */ unsigned long long sec, usec; /* @@ -424,21 +418,21 @@ static void eval_canxl_xl(char* buf, struct timeval *date_tvp, char timestamps, "%llu.%llu %*s %d %4s " /* time, CANXL, channel, direction */ "%*s %*s %*s %s " /* frame format, msg dur, bit count, ID */ "%hhx %hhx %x %d " /* SDT, SEC, DLC, Datalen */ - "%x %x %hhx %x ", /* stuff bit count, crc, VCID, AF */ + "%*s %*s %hhx %x %n", /* stuff bit count, crc, VCID, AF */ &sec, &usec, &interface, dir, tmp1, &sdt, &secbit, &dlc, &dlen, - &sbc, &pcrc, &vcid, &af) != 13) { + &vcid, &af, &n) != 11) { /* check for valid line with a symbolic name */ if (sscanf(buf, "%llu.%llu %*s %d %4s " /* time, CANXL, channel, direction */ "%*s %*s %*s %s " /* frame format, msg dur, bit count, ID */ "%*s %hhx %hhx %x %d " /* sym name, SDT, SEC, DLC, Datalen */ - "%x %x %hhx %x ", /* stuff bit count, crc, VCID, AF */ + "%*s %*s %hhx %x %n", /* stuff bit count, crc, VCID, AF */ &sec, &usec, &interface, dir, tmp1, &sdt, &secbit, &dlc, &dlen, - &sbc, &pcrc, &vcid, &af) != 13) { + &vcid, &af, &n) != 11) { /* no valid CANXL format pattern */ return; @@ -449,8 +443,7 @@ static void eval_canxl_xl(char* buf, struct timeval *date_tvp, char timestamps, read_tv.tv_usec = usec; /* check for allowed (unsigned) value ranges */ - if ((dlen > CANXL_MAX_DLEN) || (dlc > CANXL_MAX_DLC) || - (sbc > 7) || (secbit > 1)) + if ((dlen > CANXL_MAX_DLEN) || (dlc > CANXL_MAX_DLC) || (secbit > 1)) return; cf.sdt = sdt; @@ -484,15 +477,7 @@ static void eval_canxl_xl(char* buf, struct timeval *date_tvp, char timestamps, if (vcid) cf.prio |= (vcid << CANXL_VCID_OFFSET); - /* now search for the beginning of the data[] content */ - sprintf(tmp1, " %x %04x %02x %08x ", sbc, pcrc, vcid, af); - - /* search for the pattern generated by real data */ - ptr = strcasestr(buf, tmp1); - if (ptr == NULL) - return; - - ptr += strlen(tmp1); /* start of ASCII hex frame data */ + ptr = buf + n; /* start of ASCII hex frame data */ cf.len = dlen;