Rework for CAN FD support and fixes for asc to log file conversion tools

Detailed change log:

log2asc:
- support CAN FD tags and Classic CAN frames
- support RTR frames including DLC values
- new option '-r' disable the RTR DLC value for potential compatibility reasons
- new option '-f' to use the CANFD format for Classic CAN too

asc2log:
- support CAN FD tags and Classic CAN frames
- be robust against fractions of seconds in date/time string
- fix reading of RTR frames including DLC values in Classic CAN parsing
- fix date/time string detection

cangen:
- new option '-E' to support ESI bit for CAN FD frame generation
(was needed for reference log file generation)
pull/204/head
Oliver Hartkopp 2020-05-10 16:45:21 +02:00 committed by GitHub
commit 41c8ead6c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 338 additions and 113 deletions

314
asc2log.c
View File

@ -57,6 +57,8 @@
#include "lib.h" #include "lib.h"
#define BUFLEN 400 /* CAN FD mode lines can be pretty long */
extern int optind, opterr, optopt; extern int optind, opterr, optopt;
void print_usage(char *prg) void print_usage(char *prg)
@ -68,7 +70,7 @@ void print_usage(char *prg)
fprintf(stderr, "\t-O <outfile>\t(default stdout)\n"); fprintf(stderr, "\t-O <outfile>\t(default stdout)\n");
} }
void prframe(FILE *file, struct timeval *tv, int dev, struct can_frame *cf) { void prframe(FILE *file, struct timeval *tv, int dev, struct canfd_frame *cf, unsigned int max_dlen) {
fprintf(file, "(%ld.%06ld) ", tv->tv_sec, tv->tv_usec); fprintf(file, "(%ld.%06ld) ", tv->tv_sec, tv->tv_usec);
@ -77,11 +79,10 @@ void prframe(FILE *file, struct timeval *tv, int dev, struct can_frame *cf) {
else else
fprintf(file, "canX "); fprintf(file, "canX ");
/* no CAN FD support so far */ fprint_canframe(file, cf, "\n", 0, max_dlen);
fprint_canframe(file, (struct canfd_frame *)cf, "\n", 0, CAN_MAX_DLEN);
} }
void get_can_id(struct can_frame *cf, char *idstring, int base) { void get_can_id(struct canfd_frame *cf, char *idstring, int base) {
if (idstring[strlen(idstring)-1] == 'x') { if (idstring[strlen(idstring)-1] == 'x') {
cf->can_id = CAN_EFF_FLAG; cf->can_id = CAN_EFF_FLAG;
@ -124,14 +125,206 @@ void calc_tv(struct timeval *tv, struct timeval *read_tv,
} }
} }
int get_date(struct timeval *tv, char *date) { void eval_can(char* buf, struct timeval *date_tvp, char timestamps, char base, int dplace, FILE *outfile) {
char ctmp[10]; int interface;
int itmp; static struct timeval tv; /* current frame timestamp */
static struct timeval read_tv; /* frame timestamp from ASC file */
struct canfd_frame cf;
char rtr;
int dlc = 0;
int data[8];
char tmp1[BUFLEN];
int i, items, found;
/* 0.002367 1 390x Rx d 8 17 00 14 00 C0 00 08 00 */
found = 0; /* found valid CAN frame ? */
if (base == 'h') { /* check for CAN frames with hexadecimal values */
items = sscanf(buf, "%ld.%ld %d %s %*s %c %d %x %x %x %x %x %x %x %x",
&read_tv.tv_sec, &read_tv.tv_usec, &interface,
tmp1, &rtr, &dlc,
&data[0], &data[1], &data[2], &data[3],
&data[4], &data[5], &data[6], &data[7]);
if ((items == dlc + 6 ) || /* data frame */
((items == 5) && (rtr == 'r')) || /* RTR without DLC */
((items == 6) && (rtr == 'r'))) { /* RTR with DLC */
found = 1;
get_can_id(&cf, tmp1, 16);
}
} else { /* check for CAN frames with decimal values */
items = sscanf(buf, "%ld.%ld %d %s %*s %c %d %d %d %d %d %d %d %d %d",
&read_tv.tv_sec, &read_tv.tv_usec, &interface,
tmp1, &rtr, &dlc,
&data[0], &data[1], &data[2], &data[3],
&data[4], &data[5], &data[6], &data[7]);
if ((items == dlc + 6 ) || /* data frame */
((items == 5) && (rtr == 'r')) || /* RTR without DLC */
((items == 6) && (rtr == 'r'))) { /* RTR with DLC */
found = 1;
get_can_id(&cf, tmp1, 10);
}
}
if (found) {
if (dlc > CAN_MAX_DLC)
return;
cf.len = dlc;
if (rtr == 'r')
cf.can_id |= CAN_RTR_FLAG;
else
for (i = 0; i < dlc; i++)
cf.data[i] = data[i] & 0xFFU;
calc_tv(&tv, &read_tv, date_tvp, timestamps, dplace);
prframe(outfile, &tv, interface, &cf, CAN_MAX_DLEN);
fflush(outfile);
return;
}
/* check for ErrorFrames */
if (sscanf(buf, "%ld.%ld %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);
fflush(outfile);
}
}
}
void eval_canfd(char* buf, struct timeval *date_tvp, char timestamps, int dplace, FILE *outfile) {
int interface;
static struct timeval tv; /* current frame timestamp */
static struct timeval read_tv; /* frame timestamp from ASC file */
struct canfd_frame cf;
unsigned char brs, esi, ctmp;
unsigned int flags;
int dlc, dlen = 0;
char tmp1[BUFLEN];
char *ptr;
int i;
/* The CANFD format is mainly in hex representation but <DataLength>
and probably some content we skip anyway. Don't trust the docs! */
/* 21.671796 CANFD 1 Tx 11 msgCanFdFr1 1 0 a 16 \
00 00 00 00 00 00 00 00 00 00 00 00 00 00 59 c0 \
100000 214 223040 80000000 46500250 460a0250 20011736 20010205 */
memset(&cf, 0, sizeof(cf));
/* check for valid line without symbolic name */
if (sscanf(buf, "%ld.%ld %*s %d %*s %s %hhx %hhx %x %d ",
&read_tv.tv_sec, &read_tv.tv_usec, &interface,
tmp1, &brs, &esi, &dlc, &dlen) != 8) {
/* check for valid line with a symbolic name */
if (sscanf(buf, "%ld.%ld %*s %d %*s %s %*s %hhx %hhx %x %d ",
&read_tv.tv_sec, &read_tv.tv_usec, &interface,
tmp1, &brs, &esi, &dlc, &dlen) != 8) {
/* no valid CANFD format pattern */
return;
}
}
/* check for allowed (unsigned) value ranges */
if ((dlen > CANFD_MAX_DLEN) || (dlc > CANFD_MAX_DLC) ||
(brs > 1) || (esi > 1))
return;
/* don't trust ASCII content - sanitize data length */
if (dlen != can_dlc2len(can_len2dlc(dlen)))
return;
get_can_id(&cf, tmp1, 16);
/* now search for the beginning of the data[] content */
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;
for (i = 0; i < dlen; i++) {
ctmp = asc2nibble(ptr[0]);
if (ctmp > 0x0F)
return;
cf.data[i] = (ctmp << 4);
ctmp = asc2nibble(ptr[1]);
if (ctmp > 0x0F)
return;
cf.data[i] |= ctmp;
ptr += 3; /* start of next ASCII hex byte */
}
/* skip MessageDuration and MessageLength to get Flags value */
if (sscanf(ptr, " %*x %*x %x ", &flags) != 1)
return;
/* relevant flags in Flags field */
#define ASC_F_RTR 0x00000010
#define ASC_F_FDF 0x00001000
#define ASC_F_BRS 0x00002000
#define ASC_F_ESI 0x00004000
if (flags & ASC_F_FDF) {
dlen = CANFD_MAX_DLEN;
if (flags & ASC_F_BRS)
cf.flags |= CANFD_BRS;
if (flags & ASC_F_ESI)
cf.flags |= CANFD_ESI;
} else {
/* yes. The 'CANFD' format supports classic CAN content! */
dlen = CAN_MAX_DLEN;
if (flags & ASC_F_RTR) {
cf.can_id |= CAN_RTR_FLAG;
/* dlen is always 0 for classic CAN RTR frames
but the DLC value is valid in RTR cases */
cf.len = dlc;
}
}
calc_tv(&tv, &read_tv, date_tvp, timestamps, dplace);
prframe(outfile, &tv, interface, &cf, dlen);
fflush(outfile);
return;
/* No support for really strange CANFD ErrorFrames format m( */
}
int get_date(struct timeval *tv, char *date) {
struct tm tms; struct tm tms;
if (sscanf(date, "%9s %d %9s %9s %d", ctmp, &itmp, ctmp, ctmp, &itmp) == 5) { if (strcasestr(date, " pm ") != NULL) {
/* assume EN/US date due to existing am/pm field */ /* assume EN/US date due to existing am/pm field */
if (!setlocale(LC_TIME, "en_US")) { if (!setlocale(LC_TIME, "en_US")) {
@ -139,22 +332,29 @@ int get_date(struct timeval *tv, char *date) {
return 1; return 1;
} }
if (!strptime(date, "%B %d %r %Y", &tms)) if (!strptime(date, "%B %d %I:%M:%S %p %Y", &tms)) {
return 1; /* The string might contain a milliseconds value which strptime()
does not support. So we read the ms value into the year variable
before parsing the real year value (hack) */
if (!strptime(date, "%B %d %I:%M:%S.%Y %p %Y", &tms))
return 1;
}
} else { } else {
/* assume DE date due to non existing am/pm field */ /* assume DE date due to non existing am/pm field */
if (sscanf(date, "%9s %d %9s %d", ctmp, &itmp, ctmp, &itmp) != 4)
return 1;
if (!setlocale(LC_TIME, "de_DE")) { if (!setlocale(LC_TIME, "de_DE")) {
fprintf(stderr, "Setting locale to 'de_DE' failed!\n"); fprintf(stderr, "Setting locale to 'de_DE' failed!\n");
return 1; return 1;
} }
if (!strptime(date, "%B %d %T %Y", &tms)) if (!strptime(date, "%B %d %H:%M:%S %Y", &tms)) {
return 1; /* The string might contain a milliseconds value which strptime()
does not support. So we read the ms value into the year variable
before parsing the real year value (hack) */
if (!strptime(date, "%B %d %H:%M:%S.%Y %Y", &tms))
return 1;
}
} }
//printf("h %d m %d s %d d %d m %d y %d\n", //printf("h %d m %d s %d d %d m %d y %d\n",
@ -171,24 +371,17 @@ int get_date(struct timeval *tv, char *date) {
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
char buf[100], tmp1[100], tmp2[100]; char buf[BUFLEN], tmp1[BUFLEN], tmp2[BUFLEN];
FILE *infile = stdin; FILE *infile = stdin;
FILE *outfile = stdout; FILE *outfile = stdout;
static int verbose; static int verbose;
struct can_frame cf; static struct timeval tmp_tv; /* tmp frame timestamp from ASC file */
static struct timeval tv; /* current frame timestamp */
static struct timeval read_tv; /* frame timestamp from ASC file */
static struct timeval date_tv; /* date of the ASC file */ static struct timeval date_tv; /* date of the ASC file */
static int dplace; /* decimal place 4, 5 or 6 or uninitialized */ static int dplace; /* decimal place 4, 5 or 6 or uninitialized */
static char base; /* 'd'ec or 'h'ex */ static char base; /* 'd'ec or 'h'ex */
static char timestamps; /* 'a'bsolute or 'r'elative */ static char timestamps; /* 'a'bsolute or 'r'elative */
int opt;
int interface;
char rtr;
int dlc = 0;
int data[8];
int i, found, opt;
while ((opt = getopt(argc, argv, "I:O:v?")) != -1) { while ((opt = getopt(argc, argv, "I:O:v?")) != -1) {
switch (opt) { switch (opt) {
@ -226,7 +419,7 @@ int main(int argc, char **argv)
} }
while (fgets(buf, 99, infile)) { while (fgets(buf, BUFLEN-1, infile)) {
if (!dplace) { /* the representation of a valid CAN frame not known */ if (!dplace) { /* the representation of a valid CAN frame not known */
@ -266,7 +459,7 @@ int main(int argc, char **argv)
} }
/* check for decimal places length in valid CAN frames */ /* check for decimal places length in valid CAN frames */
if (sscanf(buf, "%ld.%s %d ", &tv.tv_sec, tmp2, &i) == 3){ if (sscanf(buf, "%ld.%s %s ", &tmp_tv.tv_sec, tmp2, tmp1) == 3){
dplace = strlen(tmp2); dplace = strlen(tmp2);
if (verbose) if (verbose)
printf("decimal place %d, e.g. '%s'\n", dplace, tmp2); printf("decimal place %d, e.g. '%s'\n", dplace, tmp2);
@ -281,67 +474,12 @@ int main(int argc, char **argv)
/* the representation of a valid CAN frame is known here */ /* the representation of a valid CAN frame is known here */
/* so try to get CAN frames and ErrorFrames and convert them */ /* so try to get CAN frames and ErrorFrames and convert them */
/* 0.002367 1 390x Rx d 8 17 00 14 00 C0 00 08 00 */ /* check classic CAN format or the CANFD tag which can take both types */
if (sscanf(buf, "%ld.%ld %s ", &tmp_tv.tv_sec, &tmp_tv.tv_usec, tmp1) == 3){
found = 0; /* found valid CAN frame ? */ if (!strncmp(tmp1, "CANFD", 5))
eval_canfd(buf, &date_tv, timestamps, dplace, outfile);
if (base == 'h') { /* check for CAN frames with hexadecimal values */ else
eval_can(buf, &date_tv, timestamps, base, dplace, outfile);
if (sscanf(buf, "%ld.%ld %d %s %*s %c %d %x %x %x %x %x %x %x %x",
&read_tv.tv_sec, &read_tv.tv_usec, &interface,
tmp1, &rtr, &dlc,
&data[0], &data[1], &data[2], &data[3],
&data[4], &data[5], &data[6], &data[7]
) == dlc + 6 ) {
found = 1;
get_can_id(&cf, tmp1, 16);
}
} else { /* check for CAN frames with decimal values */
if (sscanf(buf, "%ld.%ld %d %s %*s %c %d %d %d %d %d %d %d %d %d",
&read_tv.tv_sec, &read_tv.tv_usec, &interface,
tmp1, &rtr, &dlc,
&data[0], &data[1], &data[2], &data[3],
&data[4], &data[5], &data[6], &data[7]
) == dlc + 6 ) {
found = 1;
get_can_id(&cf, tmp1, 10);
}
}
if (found) {
if (rtr == 'r')
cf.can_id |= CAN_RTR_FLAG;
cf.can_dlc = dlc & 0x0FU;
for (i=0; i<dlc; i++)
cf.data[i] = data[i] & 0xFFU;
calc_tv(&tv, &read_tv, &date_tv, timestamps, dplace);
prframe(outfile, &tv, interface, &cf);
fflush(outfile);
continue;
}
/* check for ErrorFrames */
if (sscanf(buf, "%ld.%ld %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.can_dlc = CAN_ERR_DLC;
calc_tv(&tv, &read_tv, &date_tv, timestamps, dplace);
prframe(outfile, &tv, interface, &cf);
fflush(outfile);
}
} }
} }
fclose(outfile); fclose(outfile);

View File

@ -89,8 +89,10 @@ void print_usage(char *prg)
fprintf(stderr, " -f (generate CAN FD CAN frames)\n"); fprintf(stderr, " -f (generate CAN FD CAN frames)\n");
fprintf(stderr, " -b (generate CAN FD CAN frames" fprintf(stderr, " -b (generate CAN FD CAN frames"
" with bitrate switch (BRS))\n"); " with bitrate switch (BRS))\n");
fprintf(stderr, " -E (generate CAN FD CAN frames"
" with error state (ESI))\n");
fprintf(stderr, " -R (send RTR frame)\n"); fprintf(stderr, " -R (send RTR frame)\n");
fprintf(stderr, " -m (mix -e -f -b -R frames)\n"); fprintf(stderr, " -m (mix -e -f -b -E -R frames)\n");
fprintf(stderr, " -I <mode> (CAN ID" fprintf(stderr, " -I <mode> (CAN ID"
" generation mode - see below)\n"); " generation mode - see below)\n");
fprintf(stderr, " -L <mode> (CAN data length code (dlc)" fprintf(stderr, " -L <mode> (CAN data length code (dlc)"
@ -145,6 +147,7 @@ int main(int argc, char **argv)
unsigned char extended = 0; unsigned char extended = 0;
unsigned char canfd = 0; unsigned char canfd = 0;
unsigned char brs = 0; unsigned char brs = 0;
unsigned char esi = 0;
unsigned char mix = 0; unsigned char mix = 0;
unsigned char id_mode = MODE_RANDOM; unsigned char id_mode = MODE_RANDOM;
unsigned char data_mode = MODE_RANDOM; unsigned char data_mode = MODE_RANDOM;
@ -181,7 +184,7 @@ int main(int argc, char **argv)
signal(SIGHUP, sigterm); signal(SIGHUP, sigterm);
signal(SIGINT, sigterm); signal(SIGINT, sigterm);
while ((opt = getopt(argc, argv, "ig:ebfmI:L:D:xp:n:c:vRh?")) != -1) { while ((opt = getopt(argc, argv, "ig:ebEfmI:L:D:xp:n:c:vRh?")) != -1) {
switch (opt) { switch (opt) {
case 'i': case 'i':
@ -205,6 +208,11 @@ int main(int argc, char **argv)
canfd = 1; canfd = 1;
break; break;
case 'E':
esi = 1; /* error state indicator implies CAN FD */
canfd = 1;
break;
case 'm': case 'm':
mix = 1; mix = 1;
canfd = 1; /* to switch the socket into CAN FD mode */ canfd = 1; /* to switch the socket into CAN FD mode */
@ -379,6 +387,8 @@ int main(int argc, char **argv)
maxdlen = CANFD_MAX_DLEN; maxdlen = CANFD_MAX_DLEN;
if (brs) if (brs)
frame.flags |= CANFD_BRS; frame.flags |= CANFD_BRS;
if (esi)
frame.flags |= CANFD_ESI;
} else { } else {
mtu = CAN_MTU; mtu = CAN_MTU;
maxdlen = CAN_MAX_DLEN; maxdlen = CAN_MAX_DLEN;
@ -504,8 +514,10 @@ resend:
i = random(); i = random();
extended = i&1; extended = i&1;
canfd = i&2; canfd = i&2;
if (canfd) if (canfd) {
brs = i&4; brs = i&4;
esi = i&8;
}
rtr_frame = ((i&24) == 24); /* reduce RTR frames to 1/4 */ rtr_frame = ((i&24) == 24); /* reduce RTR frames to 1/4 */
} }
} }

119
log2asc.c
View File

@ -67,19 +67,95 @@ void print_usage(char *prg)
fprintf(stderr, " -O <outfile> (default stdout)\n"); fprintf(stderr, " -O <outfile> (default stdout)\n");
fprintf(stderr, " -4 (reduce decimal place to 4 digits)\n"); fprintf(stderr, " -4 (reduce decimal place to 4 digits)\n");
fprintf(stderr, " -n (set newline to cr/lf - default lf)\n"); fprintf(stderr, " -n (set newline to cr/lf - default lf)\n");
fprintf(stderr, " -f (use CANFD format also for Classic CAN)\n");
fprintf(stderr, " -r (supress dlc for RTR frames - pre v8.5 tools)\n");
}
void can_asc(struct canfd_frame *cf, int devno, int nortrdlc, FILE *outfile)
{
int i;
char id[10];
fprintf(outfile, "%-2d ", devno); /* channel number left aligned */
if (cf->can_id & CAN_ERR_FLAG)
fprintf(outfile, "ErrorFrame");
else {
sprintf(id, "%X%c", cf->can_id & CAN_EFF_MASK,
(cf->can_id & CAN_EFF_FLAG)?'x':' ');
fprintf(outfile, "%-15s Rx ", id);
if (cf->can_id & CAN_RTR_FLAG) {
if (nortrdlc)
fprintf(outfile, "r"); /* RTR frame */
else
fprintf(outfile, "r %d", cf->len); /* RTR frame */
} else {
fprintf(outfile, "d %d", cf->len); /* data frame */
for (i = 0; i < cf->len; i++) {
fprintf(outfile, " %02X", cf->data[i]);
}
}
}
}
void canfd_asc(struct canfd_frame *cf, int devno, int mtu, FILE *outfile)
{
int i;
char id[10];
unsigned int flags = 0;
unsigned int dlen = cf->len;
/* relevant flags in Flags field */
#define ASC_F_RTR 0x00000010
#define ASC_F_FDF 0x00001000
#define ASC_F_BRS 0x00002000
#define ASC_F_ESI 0x00004000
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(dlen));
if (mtu == CAN_MTU) {
if (cf->can_id & CAN_RTR_FLAG) {
/* no data length but dlc for RTR frames */
dlen = 0;
flags = ASC_F_RTR;
}
} else {
flags = ASC_F_FDF;
if (cf->flags & CANFD_BRS)
flags |= ASC_F_BRS;
if (cf->flags & CANFD_ESI)
flags |= ASC_F_ESI;
}
fprintf(outfile, "%2d", dlen);
for (i = 0; i < dlen; i++) {
fprintf(outfile, " %02X", cf->data[i]);
}
fprintf(outfile, " %8d %4d %8X 0 0 0 0 0", 130000, 130, flags);
} }
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
static char buf[BUFSZ], device[BUFSZ], ascframe[BUFSZ], id[10]; static char buf[BUFSZ], device[BUFSZ], ascframe[BUFSZ];
struct canfd_frame cf; struct canfd_frame cf;
static struct timeval tv, start_tv; static struct timeval tv, start_tv;
FILE *infile = stdin; FILE *infile = stdin;
FILE *outfile = stdout; FILE *outfile = stdout;
static int maxdev, devno, i, crlf, d4, opt; static int maxdev, devno, i, crlf, fdfmt, nortrdlc, d4, opt, mtu;
while ((opt = getopt(argc, argv, "I:O:4n?")) != -1) { while ((opt = getopt(argc, argv, "I:O:4nfr?")) != -1) {
switch (opt) { switch (opt) {
case 'I': case 'I':
infile = fopen(optarg, "r"); infile = fopen(optarg, "r");
@ -101,6 +177,14 @@ int main(int argc, char **argv)
crlf = 1; crlf = 1;
break; break;
case 'f':
fdfmt = 1;
break;
case 'r':
nortrdlc = 1;
break;
case '4': case '4':
d4 = 1; d4 = 1;
break; break;
@ -162,9 +246,14 @@ int main(int argc, char **argv)
} }
if (devno) { /* only convert for selected CAN devices */ if (devno) { /* only convert for selected CAN devices */
if (parse_canframe(ascframe, &cf) != CAN_MTU) /* no CAN FD support so far */ mtu = parse_canframe(ascframe, &cf);
if ((mtu != CAN_MTU) && (mtu != CANFD_MTU))
return 1; 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_sec = tv.tv_sec - start_tv.tv_sec;
tv.tv_usec = tv.tv_usec - start_tv.tv_usec; tv.tv_usec = tv.tv_usec - start_tv.tv_usec;
if (tv.tv_usec < 0) if (tv.tv_usec < 0)
@ -177,25 +266,11 @@ int main(int argc, char **argv)
else else
fprintf(outfile, "%4ld.%06ld ", tv.tv_sec, tv.tv_usec); fprintf(outfile, "%4ld.%06ld ", tv.tv_sec, tv.tv_usec);
fprintf(outfile, "%-2d ", devno); /* channel number left aligned */ if ((mtu == CAN_MTU) && (fdfmt == 0))
can_asc(&cf, devno, nortrdlc, outfile);
else
canfd_asc(&cf, devno, mtu, outfile);
if (cf.can_id & CAN_ERR_FLAG)
fprintf(outfile, "ErrorFrame");
else {
sprintf(id, "%X%c", cf.can_id & CAN_EFF_MASK,
(cf.can_id & CAN_EFF_FLAG)?'x':' ');
fprintf(outfile, "%-15s Rx ", id);
if (cf.can_id & CAN_RTR_FLAG)
fprintf(outfile, "r"); /* RTR frame */
else {
fprintf(outfile, "d %d", cf.len); /* data frame */
for (i = 0; i < cf.len; i++) {
fprintf(outfile, " %02X", cf.data[i]);
}
}
}
if (crlf) if (crlf)
fprintf(outfile, "\r"); fprintf(outfile, "\r");
fprintf(outfile, "\n"); fprintf(outfile, "\n");