log asc converter: support len8_dlc for Classical CAN frames part 2
In commit 6799180bd0 ("log asc converter: support len8_dlc for Classical
CAN frames") the len8_dlc support was accidentally only implemented for
the new CANFD asc format. This patch adds len8_dlc support for the 'old'
Classical CAN asc format which in fact always supported len8_dlc.
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
pull/365/head
parent
2bdb93924e
commit
81e76a7a0d
37
asc2log.c
37
asc2log.c
|
|
@ -131,8 +131,10 @@ void eval_can(char* buf, struct timeval *date_tvp, char timestamps, char base, i
|
||||||
static struct timeval tv; /* current frame timestamp */
|
static struct timeval tv; /* current frame timestamp */
|
||||||
static struct timeval read_tv; /* frame timestamp from ASC file */
|
static struct timeval read_tv; /* frame timestamp from ASC file */
|
||||||
struct canfd_frame cf;
|
struct canfd_frame cf;
|
||||||
|
struct can_frame *ccf = (struct can_frame *)&cf; /* for len8_dlc */
|
||||||
char rtr;
|
char rtr;
|
||||||
int dlc = 0;
|
int dlc = 0;
|
||||||
|
int len = 0;
|
||||||
int data[8];
|
int data[8];
|
||||||
char tmp1[BUFLEN];
|
char tmp1[BUFLEN];
|
||||||
char dir[3]; /* 'Rx' or 'Tx' plus terminating zero */
|
char dir[3]; /* 'Rx' or 'Tx' plus terminating zero */
|
||||||
|
|
@ -164,7 +166,7 @@ void eval_can(char* buf, struct timeval *date_tvp, char timestamps, char base, i
|
||||||
|
|
||||||
if (base == 'h') { /* check for CAN frames with hexadecimal values */
|
if (base == 'h') { /* check for CAN frames with hexadecimal values */
|
||||||
|
|
||||||
items = sscanf(buf, "%lu.%lu %d %s %2s %c %d %x %x %x %x %x %x %x %x",
|
items = sscanf(buf, "%lu.%lu %d %s %2s %c %x %x %x %x %x %x %x %x %x",
|
||||||
&read_tv.tv_sec, &read_tv.tv_usec, &interface,
|
&read_tv.tv_sec, &read_tv.tv_usec, &interface,
|
||||||
tmp1, dir, &rtr, &dlc,
|
tmp1, dir, &rtr, &dlc,
|
||||||
&data[0], &data[1], &data[2], &data[3],
|
&data[0], &data[1], &data[2], &data[3],
|
||||||
|
|
@ -173,7 +175,17 @@ void eval_can(char* buf, struct timeval *date_tvp, char timestamps, char base, i
|
||||||
if (items < 7 ) /* make sure we've read the dlc */
|
if (items < 7 ) /* make sure we've read the dlc */
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if ((items == dlc + 7 ) || /* data frame */
|
/* dlc is one character hex value 0..F */
|
||||||
|
if (dlc > CAN_MAX_RAW_DLC)
|
||||||
|
return;
|
||||||
|
|
||||||
|
/* retrieve real data length */
|
||||||
|
if (dlc > CAN_MAX_DLC)
|
||||||
|
len = CAN_MAX_DLEN;
|
||||||
|
else
|
||||||
|
len = dlc;
|
||||||
|
|
||||||
|
if ((items == len + 7 ) || /* data frame */
|
||||||
((items == 6) && (rtr == 'r')) || /* RTR without DLC */
|
((items == 6) && (rtr == 'r')) || /* RTR without DLC */
|
||||||
((items == 7) && (rtr == 'r'))) { /* RTR with DLC */
|
((items == 7) && (rtr == 'r'))) { /* RTR with DLC */
|
||||||
found = 1;
|
found = 1;
|
||||||
|
|
@ -182,7 +194,7 @@ void eval_can(char* buf, struct timeval *date_tvp, char timestamps, char base, i
|
||||||
|
|
||||||
} else { /* check for CAN frames with decimal values */
|
} else { /* check for CAN frames with decimal values */
|
||||||
|
|
||||||
items = sscanf(buf, "%lu.%lu %d %s %2s %c %d %d %d %d %d %d %d %d %d",
|
items = sscanf(buf, "%lu.%lu %d %s %2s %c %x %d %d %d %d %d %d %d %d",
|
||||||
&read_tv.tv_sec, &read_tv.tv_usec, &interface,
|
&read_tv.tv_sec, &read_tv.tv_usec, &interface,
|
||||||
tmp1, dir, &rtr, &dlc,
|
tmp1, dir, &rtr, &dlc,
|
||||||
&data[0], &data[1], &data[2], &data[3],
|
&data[0], &data[1], &data[2], &data[3],
|
||||||
|
|
@ -191,7 +203,17 @@ void eval_can(char* buf, struct timeval *date_tvp, char timestamps, char base, i
|
||||||
if (items < 7 ) /* make sure we've read the dlc */
|
if (items < 7 ) /* make sure we've read the dlc */
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if ((items == dlc + 7 ) || /* data frame */
|
/* dlc is one character hex value 0..F */
|
||||||
|
if (dlc > CAN_MAX_RAW_DLC)
|
||||||
|
return;
|
||||||
|
|
||||||
|
/* retrieve real data length */
|
||||||
|
if (dlc > CAN_MAX_DLC)
|
||||||
|
len = CAN_MAX_DLEN;
|
||||||
|
else
|
||||||
|
len = dlc;
|
||||||
|
|
||||||
|
if ((items == len + 7 ) || /* data frame */
|
||||||
((items == 6) && (rtr == 'r')) || /* RTR without DLC */
|
((items == 6) && (rtr == 'r')) || /* RTR without DLC */
|
||||||
((items == 7) && (rtr == 'r'))) { /* RTR with DLC */
|
((items == 7) && (rtr == 'r'))) { /* RTR with DLC */
|
||||||
found = 1;
|
found = 1;
|
||||||
|
|
@ -201,8 +223,9 @@ void eval_can(char* buf, struct timeval *date_tvp, char timestamps, char base, i
|
||||||
|
|
||||||
if (found) {
|
if (found) {
|
||||||
|
|
||||||
|
/* dlc > 8 => len == CAN_MAX_DLEN => fill len8_dlc value */
|
||||||
if (dlc > CAN_MAX_DLC)
|
if (dlc > CAN_MAX_DLC)
|
||||||
return;
|
ccf->len8_dlc = dlc;
|
||||||
|
|
||||||
if (strlen(dir) != 2) /* "Rx" or "Tx" */
|
if (strlen(dir) != 2) /* "Rx" or "Tx" */
|
||||||
return;
|
return;
|
||||||
|
|
@ -212,11 +235,11 @@ void eval_can(char* buf, struct timeval *date_tvp, char timestamps, char base, i
|
||||||
else
|
else
|
||||||
extra_info = " T\n";
|
extra_info = " T\n";
|
||||||
|
|
||||||
cf.len = dlc;
|
cf.len = len;
|
||||||
if (rtr == 'r')
|
if (rtr == 'r')
|
||||||
cf.can_id |= CAN_RTR_FLAG;
|
cf.can_id |= CAN_RTR_FLAG;
|
||||||
else
|
else
|
||||||
for (i = 0; i < dlc; i++)
|
for (i = 0; i < len; i++)
|
||||||
cf.data[i] = data[i] & 0xFFU;
|
cf.data[i] = data[i] & 0xFFU;
|
||||||
|
|
||||||
calc_tv(&tv, &read_tv, date_tvp, timestamps, dplace);
|
calc_tv(&tv, &read_tv, date_tvp, timestamps, dplace);
|
||||||
|
|
|
||||||
15
log2asc.c
15
log2asc.c
|
|
@ -71,11 +71,13 @@ void print_usage(char *prg)
|
||||||
fprintf(stderr, " -r (suppress dlc for RTR frames - pre v8.5 tools)\n");
|
fprintf(stderr, " -r (suppress dlc for RTR frames - pre v8.5 tools)\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void can_asc(struct canfd_frame *cf, int devno, int nortrdlc, char *extra_info, FILE *outfile)
|
void can_asc(struct canfd_frame *cfd, int devno, int nortrdlc, char *extra_info, FILE *outfile)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
char id[10];
|
char id[10];
|
||||||
char *dir = "Rx";
|
char *dir = "Rx";
|
||||||
|
int dlc;
|
||||||
|
struct can_frame *cf = (struct can_frame *)cfd; /* for len8_dlc */
|
||||||
|
|
||||||
fprintf(outfile, "%-2d ", devno); /* channel number left aligned */
|
fprintf(outfile, "%-2d ", devno); /* channel number left aligned */
|
||||||
|
|
||||||
|
|
@ -94,13 +96,20 @@ void can_asc(struct canfd_frame *cf, int devno, int nortrdlc, char *extra_info,
|
||||||
|
|
||||||
fprintf(outfile, "%-15s %s ", id, dir);
|
fprintf(outfile, "%-15s %s ", id, dir);
|
||||||
|
|
||||||
|
if (cf->len == CAN_MAX_DLC &&
|
||||||
|
cf->len8_dlc > CAN_MAX_DLC &&
|
||||||
|
cf->len8_dlc <= CAN_MAX_RAW_DLC)
|
||||||
|
dlc = cf->len8_dlc;
|
||||||
|
else
|
||||||
|
dlc = cf->len;
|
||||||
|
|
||||||
if (cf->can_id & CAN_RTR_FLAG) {
|
if (cf->can_id & CAN_RTR_FLAG) {
|
||||||
if (nortrdlc)
|
if (nortrdlc)
|
||||||
fprintf(outfile, "r"); /* RTR frame */
|
fprintf(outfile, "r"); /* RTR frame */
|
||||||
else
|
else
|
||||||
fprintf(outfile, "r %d", cf->len); /* RTR frame */
|
fprintf(outfile, "r %X", dlc); /* RTR frame */
|
||||||
} else {
|
} else {
|
||||||
fprintf(outfile, "d %d", cf->len); /* data frame */
|
fprintf(outfile, "d %X", dlc); /* data frame */
|
||||||
|
|
||||||
for (i = 0; i < cf->len; i++) {
|
for (i = 0; i < cf->len; i++) {
|
||||||
fprintf(outfile, " %02X", cf->data[i]);
|
fprintf(outfile, " %02X", cf->data[i]);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue