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 <socketcan@hartkopp.net>
pull/269/head
Oliver Hartkopp 2020-11-22 19:47:24 +01:00
parent 11edd1d05e
commit 6799180bd0
2 changed files with 20 additions and 1 deletions

View File

@ -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;
}
}

View File

@ -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) {