From 9a079942cd54a8620a5b00056a6627f8b6a437c5 Mon Sep 17 00:00:00 2001 From: Oliver Hartkopp Date: Sat, 9 May 2020 22:08:19 +0200 Subject: [PATCH] log2asc: support CANFD asc file generation The CANFD asc format adds information about the CAN controllers bitrate settings, CRCs and message length (in bits) and its duration. The plan is to provide static values for these attributes that we can not get from the log file anyway and stay on the 'old style' format for classic CAN frames - which has been successfully tested on the latest tools. The remaining drawback is that the 'old style' format is not able to provide a DLC information for RTR frames. Signed-off-by: Oliver Hartkopp --- log2asc.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/log2asc.c b/log2asc.c index f40ee84..ad9fe8e 100644 --- a/log2asc.c +++ b/log2asc.c @@ -97,6 +97,36 @@ void can_asc(struct canfd_frame *cf, int devno, FILE *outfile) void canfd_asc(struct canfd_frame *cf, int devno, FILE *outfile) { + int i; + char id[10]; + unsigned int flags; + + fprintf(outfile, "CANFD %3d Rx ", devno); /* 3 column channel number right aligned */ + + sprintf(id, "%X%c", cf->can_id & CAN_EFF_MASK, + (cf->can_id & CAN_EFF_FLAG)?'x':' '); + 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(cf->len)); + fprintf(outfile, "%2d", cf->len); + + for (i = 0; i < cf->len; i++) { + fprintf(outfile, " %02X", cf->data[i]); + } + + /* relevant flags in Flags field */ +#define ASC_F_FDF 0x00001000 +#define ASC_F_BRS 0x00002000 +#define ASC_F_ESI 0x00004000 + + flags = ASC_F_FDF; + if (cf->flags & CANFD_BRS) + flags |= ASC_F_BRS; + if (cf->flags & CANFD_ESI) + flags |= ASC_F_ESI; + + fprintf(outfile, " %8d %4d %8X 0 0 0 0 0", 130000, 130, flags); } int main(int argc, char **argv) @@ -196,6 +226,10 @@ int main(int argc, char **argv) if ((mtu != CAN_MTU) && (mtu != CANFD_MTU)) return 1; + /* we don't support error message frames in CAN FD */ + if ((mtu == CANFD_MTU) && (cf.can_id & CAN_ERR_FLAG)) + continue; + tv.tv_sec = tv.tv_sec - start_tv.tv_sec; tv.tv_usec = tv.tv_usec - start_tv.tv_usec; if (tv.tv_usec < 0)