From afc6a324da7f5cbb0727e7d25708c7c3b885cfd0 Mon Sep 17 00:00:00 2001 From: Oliver Hartkopp Date: Sun, 1 May 2022 12:55:49 +0200 Subject: [PATCH] asc2log: move check for error frames We need to check for different sscanf() failures and the number of read items in the data frames. So move the simple check to the beginning. Signed-off-by: Oliver Hartkopp --- asc2log.c | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/asc2log.c b/asc2log.c index 71be7f8..47b5f7e 100644 --- a/asc2log.c +++ b/asc2log.c @@ -139,6 +139,25 @@ void eval_can(char* buf, struct timeval *date_tvp, char timestamps, char base, i char *extra_info; int i, items, found; + /* check for ErrorFrames */ + if (sscanf(buf, "%lu.%lu %d %s", + &read_tv.tv_sec, &read_tv.tv_usec, + &interface, tmp1) == 4) { + + if (!strncmp(tmp1, "ErrorFrame", strlen("ErrorFrame"))) { + + memset(&cf, 0, sizeof(cf)); + /* do not know more than 'Error' */ + cf.can_id = (CAN_ERR_FLAG | CAN_ERR_BUSERROR); + cf.len = CAN_ERR_DLC; + + calc_tv(&tv, &read_tv, date_tvp, timestamps, dplace); + prframe(outfile, &tv, interface, &cf, CAN_MAX_DLEN, "\n"); + fflush(outfile); + return; + } + } + /* 0.002367 1 390x Rx d 8 17 00 14 00 C0 00 08 00 */ found = 0; /* found valid CAN frame ? */ @@ -197,25 +216,6 @@ void eval_can(char* buf, struct timeval *date_tvp, char timestamps, char base, i calc_tv(&tv, &read_tv, date_tvp, timestamps, dplace); prframe(outfile, &tv, interface, &cf, CAN_MAX_DLEN, extra_info); fflush(outfile); - return; - } - - /* check for ErrorFrames */ - if (sscanf(buf, "%lu.%lu %d %s", - &read_tv.tv_sec, &read_tv.tv_usec, - &interface, tmp1) == 4) { - - if (!strncmp(tmp1, "ErrorFrame", strlen("ErrorFrame"))) { - - memset(&cf, 0, sizeof(cf)); - /* do not know more than 'Error' */ - cf.can_id = (CAN_ERR_FLAG | CAN_ERR_BUSERROR); - cf.len = CAN_ERR_DLC; - - calc_tv(&tv, &read_tv, date_tvp, timestamps, dplace); - prframe(outfile, &tv, interface, &cf, CAN_MAX_DLEN, "\n"); - fflush(outfile); - } } }