asc2log: make use of sscanf consumed characters feature
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>pull/573/head
parent
0e9c53f6d3
commit
4d8b247258
43
asc2log.c
43
asc2log.c
|
|
@ -265,6 +265,7 @@ static void eval_canfd(char* buf, struct timeval *date_tvp, char timestamps,
|
||||||
char *extra_info;
|
char *extra_info;
|
||||||
char *ptr;
|
char *ptr;
|
||||||
int i;
|
int i;
|
||||||
|
int n = 0; /* sscanf consumed characters */
|
||||||
unsigned long long sec, usec;
|
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 */
|
/* 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,
|
&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 */
|
/* 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,
|
&sec, &usec, &interface,
|
||||||
dir, tmp1, &brs, &esi, &dlc, &dlen) != 9) {
|
dir, tmp1, &brs, &esi, &dlc, &dlen, &n) != 9) {
|
||||||
|
|
||||||
/* no valid CANFD format pattern */
|
/* no valid CANFD format pattern */
|
||||||
return;
|
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);
|
get_can_id(&cf.can_id, tmp1, 16);
|
||||||
|
|
||||||
/* now search for the beginning of the data[] content */
|
ptr = buf + n; /* start of ASCII hex frame data */
|
||||||
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 */
|
|
||||||
|
|
||||||
cf.len = dlen;
|
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 */
|
static struct timeval read_tv; /* frame timestamp from ASC file */
|
||||||
struct canxl_frame cf = { 0 };
|
struct canxl_frame cf = { 0 };
|
||||||
unsigned char sdt, vcid, secbit, ctmp;
|
unsigned char sdt, vcid, secbit, ctmp;
|
||||||
unsigned int af, sbc, pcrc, flags;
|
unsigned int af, flags;
|
||||||
int dlc, dlen = 0;
|
int dlc, dlen = 0;
|
||||||
char tmp1[BUFLEN];
|
char tmp1[BUFLEN];
|
||||||
char dir[5]; /* 'Rx'/'Tx'/'TxRq' plus terminating zero */
|
char dir[5]; /* 'Rx'/'Tx'/'TxRq' plus terminating zero */
|
||||||
char *extra_info;
|
char *extra_info;
|
||||||
char *ptr;
|
char *ptr;
|
||||||
int i;
|
int i;
|
||||||
|
int n = 0; /* sscanf consumed characters */
|
||||||
unsigned long long sec, usec;
|
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 */
|
"%llu.%llu %*s %d %4s " /* time, CANXL, channel, direction */
|
||||||
"%*s %*s %*s %s " /* frame format, msg dur, bit count, ID */
|
"%*s %*s %*s %s " /* frame format, msg dur, bit count, ID */
|
||||||
"%hhx %hhx %x %d " /* SDT, SEC, DLC, Datalen */
|
"%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,
|
&sec, &usec, &interface, dir,
|
||||||
tmp1,
|
tmp1,
|
||||||
&sdt, &secbit, &dlc, &dlen,
|
&sdt, &secbit, &dlc, &dlen,
|
||||||
&sbc, &pcrc, &vcid, &af) != 13) {
|
&vcid, &af, &n) != 11) {
|
||||||
/* check for valid line with a symbolic name */
|
/* check for valid line with a symbolic name */
|
||||||
if (sscanf(buf,
|
if (sscanf(buf,
|
||||||
"%llu.%llu %*s %d %4s " /* time, CANXL, channel, direction */
|
"%llu.%llu %*s %d %4s " /* time, CANXL, channel, direction */
|
||||||
"%*s %*s %*s %s " /* frame format, msg dur, bit count, ID */
|
"%*s %*s %*s %s " /* frame format, msg dur, bit count, ID */
|
||||||
"%*s %hhx %hhx %x %d " /* sym name, SDT, SEC, DLC, Datalen */
|
"%*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,
|
&sec, &usec, &interface, dir,
|
||||||
tmp1,
|
tmp1,
|
||||||
&sdt, &secbit, &dlc, &dlen,
|
&sdt, &secbit, &dlc, &dlen,
|
||||||
&sbc, &pcrc, &vcid, &af) != 13) {
|
&vcid, &af, &n) != 11) {
|
||||||
|
|
||||||
/* no valid CANXL format pattern */
|
/* no valid CANXL format pattern */
|
||||||
return;
|
return;
|
||||||
|
|
@ -449,8 +443,7 @@ static void eval_canxl_xl(char* buf, struct timeval *date_tvp, char timestamps,
|
||||||
read_tv.tv_usec = usec;
|
read_tv.tv_usec = usec;
|
||||||
|
|
||||||
/* check for allowed (unsigned) value ranges */
|
/* check for allowed (unsigned) value ranges */
|
||||||
if ((dlen > CANXL_MAX_DLEN) || (dlc > CANXL_MAX_DLC) ||
|
if ((dlen > CANXL_MAX_DLEN) || (dlc > CANXL_MAX_DLC) || (secbit > 1))
|
||||||
(sbc > 7) || (secbit > 1))
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
cf.sdt = sdt;
|
cf.sdt = sdt;
|
||||||
|
|
@ -484,15 +477,7 @@ static void eval_canxl_xl(char* buf, struct timeval *date_tvp, char timestamps,
|
||||||
if (vcid)
|
if (vcid)
|
||||||
cf.prio |= (vcid << CANXL_VCID_OFFSET);
|
cf.prio |= (vcid << CANXL_VCID_OFFSET);
|
||||||
|
|
||||||
/* now search for the beginning of the data[] content */
|
ptr = buf + n; /* start of ASCII hex frame data */
|
||||||
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 */
|
|
||||||
|
|
||||||
cf.len = dlen;
|
cf.len = dlen;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue