From 6799180bd06420142835a3a67f009da45b0ff7f0 Mon Sep 17 00:00:00 2001 From: Oliver Hartkopp Date: Sun, 22 Nov 2020 19:47:24 +0100 Subject: [PATCH] log asc converter: support len8_dlc for Classical CAN frames The CANFD format in asc logfiles can be used to describe Classical CAN frame content too. As this CANFD format has two different elements to transport the payload length and the 'raw data length code' the new len8_dlc option now allows to support the full qualified conversion. Signed-off-by: Oliver Hartkopp --- asc2log.c | 9 +++++++++ log2asc.c | 12 +++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/asc2log.c b/asc2log.c index af019db..0596498 100644 --- a/asc2log.c +++ b/asc2log.c @@ -327,6 +327,15 @@ void eval_canfd(char* buf, struct timeval *date_tvp, char timestamps, int dplace /* dlen is always 0 for classic CAN RTR frames but the DLC value is valid in RTR cases */ cf.len = dlc; + /* sanitize payload length value */ + if (dlc > CAN_MAX_DLEN) + cf.len = CAN_MAX_DLEN; + } + /* check for extra DLC when having a Classic CAN with 8 bytes payload */ + if ((cf.len == CAN_MAX_DLEN) && (dlc > CAN_MAX_DLEN) && (dlc <= CAN_MAX_RAW_DLC)) { + struct can_frame *ccf = (struct can_frame *)&cf; + + ccf->len8_dlc = dlc; } } diff --git a/log2asc.c b/log2asc.c index 475be4a..6970869 100644 --- a/log2asc.c +++ b/log2asc.c @@ -116,6 +116,7 @@ void canfd_asc(struct canfd_frame *cf, int devno, int mtu, char *extra_info, FIL char *dir = "Rx"; unsigned int flags = 0; unsigned int dlen = cf->len; + unsigned int dlc = can_len2dlc(dlen); /* relevant flags in Flags field */ #define ASC_F_RTR 0x00000010 @@ -137,7 +138,16 @@ void canfd_asc(struct canfd_frame *cf, int devno, int mtu, char *extra_info, FIL fprintf(outfile, "%11s ", id); fprintf(outfile, "%c ", (cf->flags & CANFD_BRS)?'1':'0'); fprintf(outfile, "%c ", (cf->flags & CANFD_ESI)?'1':'0'); - fprintf(outfile, "%x ", can_len2dlc(dlen)); + + /* check for extra DLC when having a Classic CAN with 8 bytes payload */ + if ((mtu == CAN_MTU) && (dlen == CAN_MAX_DLEN)) { + struct can_frame *ccf = (struct can_frame *)cf; + + if ((ccf->len8_dlc > CAN_MAX_DLEN) && (ccf->len8_dlc <= CAN_MAX_RAW_DLC)) + dlc = ccf->len8_dlc; + } + + fprintf(outfile, "%x ", dlc); if (mtu == CAN_MTU) { if (cf->can_id & CAN_RTR_FLAG) {