diff --git a/candump.c b/candump.c index d70a8b1..87958cd 100644 --- a/candump.c +++ b/candump.c @@ -327,7 +327,7 @@ int main(int argc, char **argv) FILE *logfile = NULL; char fname[83]; /* suggested by -Wformat-overflow= */ const char *logname = NULL; - static char abuf[10000]; /* ASCII buf FIXME - use calculated value */ + static char afrbuf[AFRSZ]; /* ASCII CAN frame buffer size */ static int alen; signal(SIGTERM, sigterm); @@ -831,22 +831,22 @@ int main(int argc, char **argv) /* build common log format output */ if ((log) || ((logfrmt) && (silent == SILENT_OFF))) { - alen = sprint_timestamp(abuf, logtimestamp, + alen = sprint_timestamp(afrbuf, logtimestamp, &tv, &last_tv); - alen += sprintf(abuf + alen, "%*s ", + alen += sprintf(afrbuf + alen, "%*s ", max_devname_len, devname[idx]); - alen += sprint_canframe(abuf + alen, &cu, 0); + alen += sprint_canframe(afrbuf + alen, &cu, 0); } /* write CAN frame in log file style to logfile */ if (log) - fprintf(logfile, "%s%s\n", abuf, extra_info); + fprintf(logfile, "%s%s\n", afrbuf, extra_info); /* print CAN frame in log file style to stdout */ if ((logfrmt) && (silent == SILENT_OFF)) { - printf("%s%s\n", abuf, extra_info); + printf("%s%s\n", afrbuf, extra_info); goto out_fflush; /* no other output to stdout */ } @@ -860,32 +860,32 @@ int main(int argc, char **argv) } /* print (colored) long CAN frame style to stdout */ - alen = sprintf(abuf, " %s", (color > 2) ? col_on[idx % MAXCOL] : ""); - alen += sprint_timestamp(abuf + alen, timestamp, &tv, &last_tv); - alen += sprintf(abuf + alen, " %s%*s", + alen = sprintf(afrbuf, " %s", (color > 2) ? col_on[idx % MAXCOL] : ""); + alen += sprint_timestamp(afrbuf + alen, timestamp, &tv, &last_tv); + alen += sprintf(afrbuf + alen, " %s%*s", (color && (color < 3)) ? col_on[idx % MAXCOL] : "", max_devname_len, devname[idx]); if (extra_msg_info) { if (msg.msg_flags & MSG_DONTROUTE) - alen += sprintf(abuf + alen, " TX %s", + alen += sprintf(afrbuf + alen, " TX %s", extra_m_info[cu.fd.flags & 3]); else - alen += sprintf(abuf + alen, " RX %s", + alen += sprintf(afrbuf + alen, " RX %s", extra_m_info[cu.fd.flags & 3]); } - alen += sprintf(abuf + alen, "%s ", (color == 1) ? col_off : ""); - alen += sprint_long_canframe(abuf + alen, &cu, view); + alen += sprintf(afrbuf + alen, "%s ", (color == 1) ? col_off : ""); + alen += sprint_long_canframe(afrbuf + alen, &cu, view); if ((view & CANLIB_VIEW_ERROR) && (cu.fd.can_id & CAN_ERR_FLAG)) { - alen += sprintf(abuf + alen, "\n\t"); - alen += snprintf_can_error_frame(abuf + alen, - sizeof(abuf) - alen, + alen += sprintf(afrbuf + alen, "\n\t"); + alen += snprintf_can_error_frame(afrbuf + alen, + sizeof(afrbuf) - alen, &cu.fd, "\n\t"); } - printf("%s%s\n", abuf, (color > 1) ? col_off : ""); + printf("%s%s\n", afrbuf, (color > 1) ? col_off : ""); out_fflush: fflush(stdout); } diff --git a/cangen.c b/cangen.c index 11b156f..a2c5c50 100644 --- a/cangen.c +++ b/cangen.c @@ -828,16 +828,17 @@ int main(int argc, char **argv) } if (verbose) { - static char abuf[10000]; /* ASCII buf FIXME - use calculated value */ + static char afrbuf[AFRSZ]; /* ASCII CAN frame buffer size */ + printf(" %s ", argv[optind]); if (verbose > 1) - sprint_long_canframe(abuf, (cu_t *)&frame, (verbose > 2) ? CANLIB_VIEW_ASCII : 0); + sprint_long_canframe(afrbuf, (cu_t *)&frame, (verbose > 2) ? CANLIB_VIEW_ASCII : 0); else - sprint_canframe(abuf, (cu_t *)&frame, 1); + sprint_canframe(afrbuf, (cu_t *)&frame, 1); - printf("%s\n", abuf); + printf("%s\n", afrbuf); } ret = do_send_one(s, &frame, mtu, polltimeout); diff --git a/canplayer.c b/canplayer.c index 4987428..9499077 100644 --- a/canplayer.c +++ b/canplayer.c @@ -239,7 +239,7 @@ int add_assignment(char *mode, int socket, char *txname, char *rxname, int verbo int main(int argc, char **argv) { - static char buf[BUFSZ], device[BUFSZ], ascframe[10000]; + static char buf[BUFSZ], device[BUFSZ], afrbuf[AFRSZ]; struct sockaddr_can addr; struct can_raw_vcid_options vcid_opts = { .flags = CAN_RAW_XL_VCID_TX_PASS, @@ -426,7 +426,7 @@ int main(int argc, char **argv) eof = 0; - if (sscanf(buf, "(%llu.%llu) %s %s", &sec, &usec, device, ascframe) != 4) { + if (sscanf(buf, "(%llu.%llu) %s %s", &sec, &usec, device, afrbuf) != 4) { fprintf(stderr, "incorrect line format in logfile\n"); return 1; } @@ -455,7 +455,7 @@ int main(int argc, char **argv) if (interactive) getchar(); - /* log_tv/device/ascframe are valid here */ + /* log_tv/device/afrbuf are valid here */ if (strlen(device) >= IFNAMSIZ) { fprintf(stderr, "log interface name '%s' too long!", device); @@ -479,9 +479,9 @@ int main(int argc, char **argv) } else if (txidx > 0) { /* only send to valid CAN devices */ - txmtu = parse_canframe(ascframe, &cu); /* dual-use frame */ + txmtu = parse_canframe(afrbuf, &cu); /* dual-use frame */ if (!txmtu) { - fprintf(stderr, "wrong CAN frame format: '%s'!", ascframe); + fprintf(stderr, "wrong CAN frame format: '%s'!", afrbuf); return 1; } @@ -499,8 +499,8 @@ int main(int argc, char **argv) if (verbose) { printf("%s (%s) ", get_txname(device), device); - sprint_long_canframe(ascframe, &cu, CANLIB_VIEW_INDENT_SFF); - printf("%s\n", ascframe); + sprint_long_canframe(afrbuf, &cu, CANLIB_VIEW_INDENT_SFF); + printf("%s\n", afrbuf); } if (count && (--count == 0)) @@ -520,7 +520,7 @@ int main(int argc, char **argv) break; } - if (sscanf(buf, "(%llu.%llu) %s %s", &sec, &usec, device, ascframe) != 4) { + if (sscanf(buf, "(%llu.%llu) %s %s", &sec, &usec, device, afrbuf) != 4) { fprintf(stderr, "incorrect line format in logfile\n"); return 1; } diff --git a/lib.h b/lib.h index 3ddf1e8..a0f2b99 100644 --- a/lib.h +++ b/lib.h @@ -63,17 +63,16 @@ typedef union { struct canxl_frame xl; } cu_t; -/* buffer sizes for CAN frame string representations */ +#define CL_CFSZ 400 /* to be removed */ -#define CL_ID (sizeof("12345678##1")) -#define CL_DATA sizeof(".AA") -#define CL_BINDATA sizeof(".10101010") - - /* CAN FD ASCII hex short representation with DATA_SEPERATORs */ -#define CL_CFSZ (2*CL_ID + 64*CL_DATA) - -/* CAN FD ASCII hex long representation with binary output */ -#define CL_LONGCFSZ (2*CL_ID + sizeof(" [255] ") + (64*CL_BINDATA)) +/* + * The buffer size for ASCII CAN frame string representations + * covers also the 'long' CAN frame output from sprint_long_canframe() + * including (swapped) binary represetations, timestamps, netdevice names, + * lengths and error message details as the CAN XL data is cropped to 64 + * byte (the 'long' CAN frame output is only for display on terminals). + */ +#define AFRSZ 6300 /* 3*2048 (data) + 22 (timestamp) + 18 (netdev) + ID/HDR */ /* CAN DLC to real data length conversion helpers especially for CAN FD */ diff --git a/log2asc.c b/log2asc.c index 87279cd..f87a7bb 100644 --- a/log2asc.c +++ b/log2asc.c @@ -183,7 +183,7 @@ void canfd_asc(struct canfd_frame *cf, int devno, int mtu, char *extra_info, FIL int main(int argc, char **argv) { - static char buf[BUFSZ], device[BUFSZ], ascframe[10000], extra_info[BUFSZ]; + static char buf[BUFSZ], device[BUFSZ], afrbuf[AFRSZ], extra_info[BUFSZ]; static cu_t cu; static struct timeval tv, start_tv; @@ -262,13 +262,13 @@ int main(int argc, char **argv) continue; if (sscanf(buf, "(%llu.%llu) %s %s %s", &sec, &usec, - device, ascframe, extra_info) != 5) { + device, afrbuf, extra_info) != 5) { /* do not evaluate the extra info */ extra_info[0] = 0; if (sscanf(buf, "(%llu.%llu) %s %s", &sec, &usec, - device, ascframe) != 4) { + device, afrbuf) != 4) { fprintf(stderr, "incorrect line format in logfile\n"); return 1; } @@ -295,7 +295,7 @@ int main(int argc, char **argv) if (devno) { /* only convert for selected CAN devices */ - mtu = parse_canframe(ascframe, &cu); + mtu = parse_canframe(afrbuf, &cu); /* convert only CAN CC and CAN FD frames */ if ((mtu != CAN_MTU) && (mtu != CANFD_MTU))