]> rtime.felk.cvut.cz Git - can-utils.git/blobdiff - log2asc.c
isotp[send|recv]: change command line option for padding bytes
[can-utils.git] / log2asc.c
index f26b3a385df854e0bc6feb45642bfde8fc120f72..446c0b6e71852270039091440e51d17c2f3f47aa 100644 (file)
--- a/log2asc.c
+++ b/log2asc.c
@@ -1,7 +1,3 @@
-/*
- *  $Id$
- */
-
 /*
  * log2asc.c - convert compact CAN frame logfile to ASC logfile
  *
@@ -41,7 +37,7 @@
  * 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>
  *
  */
 
@@ -56,6 +52,8 @@
 
 #include "lib.h"
 
+#define BUFSZ 400 /* for one line in the logfile */
+
 extern int optind, opterr, optopt;
 
 void print_usage(char *prg)
@@ -69,15 +67,15 @@ 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");
@@ -103,6 +101,11 @@ int main(int argc, char **argv)
                        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]));
@@ -121,10 +124,22 @@ int main(int argc, char **argv)
        
        //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;
@@ -143,7 +158,7 @@ int main(int argc, char **argv)
                }
 
                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;
@@ -170,9 +185,9 @@ int main(int argc, char **argv)
                                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]);
                                        }
                                }