]> rtime.felk.cvut.cz Git - can-utils.git/blobdiff - asc2log.c
configure: switch to new libtool-2.0 macro
[can-utils.git] / asc2log.c
index fffce6e2d018db684d572033b2eb01a78ce6cef9..548fc7ee400680bc38f16f630f5fbe5db2a1747d 100644 (file)
--- a/asc2log.c
+++ b/asc2log.c
@@ -1,7 +1,3 @@
-/*
- *  $Id$
- */
-
 /*
  * asc2log.c - convert ASC logfile to compact CAN frame 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>
  *
  */
 
@@ -73,11 +69,14 @@ void print_usage(char *prg)
 void prframe(FILE *file, struct timeval *tv, int dev, struct can_frame *cf) {
 
        fprintf(file, "(%ld.%06ld) ", tv->tv_sec, tv->tv_usec);
+
        if (dev > 0)
                fprintf(file, "can%d ", dev-1);
        else
                fprintf(file, "canX ");
-       fprint_canframe(file, cf, "\n", 0);
+
+       /* no CAN FD support so far */
+       fprint_canframe(file, (struct canfd_frame *)cf, "\n", 0, CAN_MAX_DLEN);
 }
 
 void get_can_id(struct can_frame *cf, char *idstring, int base) {
@@ -97,6 +96,9 @@ void calc_tv(struct timeval *tv, struct timeval *read_tv,
        if (dplace == 4) /* shift values having only 4 decimal places */
                read_tv->tv_usec *= 100;                /* and need for 6 */
 
+       if (dplace == 5) /* shift values having only 5 decimal places */
+               read_tv->tv_usec *= 10;                /* and need for 6 */
+
        if (timestamps == 'a') { /* absolute */
 
                tv->tv_sec  = date_tv->tv_sec  + read_tv->tv_sec;
@@ -130,8 +132,10 @@ int get_date(struct timeval *tv, char *date) {
        if (sscanf(date, "%9s %d %9s %9s %d", ctmp, &itmp, ctmp, ctmp, &itmp) == 5) {
                /* assume EN/US date due to existing am/pm field */
 
-               if (!setlocale(LC_TIME, "en_US"))
+               if (!setlocale(LC_TIME, "en_US")) {
+                       fprintf(stderr, "Setting locale to 'en_US' failed!\n");
                        return 1;
+               }
 
                if (!strptime(date, "%B %d %r %Y", &tms))
                        return 1;
@@ -142,8 +146,10 @@ int get_date(struct timeval *tv, char *date) {
                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");
                        return 1;
+               }
 
                if (!strptime(date, "%B %d %T %Y", &tms))
                        return 1;
@@ -172,7 +178,7 @@ int main(int argc, char **argv)
        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 int dplace; /* decimal place 4 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 timestamps; /* 'a'bsolute or 'r'elative */
 
@@ -182,7 +188,7 @@ int main(int argc, char **argv)
        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) {
                case 'I':
                        infile = fopen(optarg, "r");
@@ -204,6 +210,11 @@ int main(int argc, char **argv)
                        verbose = 1;
                        break;
 
+               case '?':
+                       print_usage(basename(argv[0]));
+                       return 0;
+                       break;
+
                default:
                        fprintf(stderr, "Unknown option %c\n", opt);
                        print_usage(basename(argv[0]));
@@ -257,8 +268,8 @@ int main(int argc, char **argv)
                                dplace = strlen(tmp2);
                                if (verbose)
                                        printf("decimal place %d, e.g. '%s'\n", dplace, tmp2);
-                               if ((dplace != 4) && (dplace != 6)) {
-                                       printf("invalid dplace %d (must be 4 or 6)!\n", dplace);
+                               if (dplace < 4 || dplace > 6) {
+                                       printf("invalid dplace %d (must be 4, 5 or 6)!\n", dplace);
                                        return 1;
                                }
                        } else