-/*
- * $Id$
- */
-
/*
* log2asc.c - convert compact CAN frame logfile to ASC logfile
*
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*
- * Send feedback to <socketcan-users@lists.berlios.de>
+ * Send feedback to <linux-can@vger.kernel.org>
*
*/
#include "lib.h"
+#define BUFSZ 400 /* for one line in the logfile */
+
extern int optind, opterr, optopt;
void print_usage(char *prg)
int main(int argc, char **argv)
{
- char buf[100], device[100], ascframe[100], id[10];
+ static char buf[BUFSZ], device[BUFSZ], ascframe[BUFSZ], id[10];
- struct can_frame cf;
+ struct canfd_frame cf;
static struct timeval tv, start_tv;
FILE *infile = stdin;
FILE *outfile = stdout;
static int maxdev, devno, i, crlf, d4, opt;
- while ((opt = getopt(argc, argv, "I:O:4n")) != -1) {
+ while ((opt = getopt(argc, argv, "I:O:4n?")) != -1) {
switch (opt) {
case 'I':
infile = fopen(optarg, "r");
d4 = 1;
break;
+ case '?':
+ print_usage(basename(argv[0]));
+ return 0;
+ break;
+
default:
fprintf(stderr, "Unknown option %c\n", opt);
print_usage(basename(argv[0]));
//printf("Found %d CAN devices!\n", maxdev);
- while (fgets(buf, 99, infile)) {
+ while (fgets(buf, BUFSZ-1, infile)) {
+
+ if (strlen(buf) >= BUFSZ-2) {
+ fprintf(stderr, "line too long for input buffer\n");
+ return 1;
+ }
+
+ /* check for a comment line */
+ if (buf[0] != '(')
+ continue;
+
if (sscanf(buf, "(%ld.%ld) %s %s", &tv.tv_sec, &tv.tv_usec,
- device, ascframe) != 4)
+ device, ascframe) != 4) {
+ fprintf(stderr, "incorrect line format in logfile\n");
return 1;
+ }
if (!start_tv.tv_sec) { /* print banner */
start_tv = tv;
}
if (devno) { /* only convert for selected CAN devices */
- if (parse_canframe(ascframe, &cf))
+ if (parse_canframe(ascframe, &cf) != CAN_MTU) /* no CAN FD support so far */
return 1;
tv.tv_sec = tv.tv_sec - start_tv.tv_sec;
if (cf.can_id & CAN_RTR_FLAG)
fprintf(outfile, "r"); /* RTR frame */
else {
- fprintf(outfile, "d %d", cf.can_dlc); /* data frame */
+ fprintf(outfile, "d %d", cf.len); /* data frame */
- for (i = 0; i < cf.can_dlc; i++) {
+ for (i = 0; i < cf.len; i++) {
fprintf(outfile, " %02X", cf.data[i]);
}
}