]> rtime.felk.cvut.cz Git - canping.git/blobdiff - src/vca_canping.c
Call vca_open_handle() with "D" flag to setup filters correctly for socketcan
[canping.git] / src / vca_canping.c
index 64ea3c27289fff216dce1aa83fd9253e81dd131d..e468c4da56519f5f0f298fb8409e5b1e06f250da 100644 (file)
@@ -170,8 +170,12 @@ void histogram_fprint(struct histogram *h, FILE *f)
                sum += h->data[i];
        cum = sum;
        for (i = 0; i < h->allocated; i++) {
-               if (h->data[i] != 0)
-                       fprintf(f, "%d %lld\n", i*h->resolution, cum);
+               if (h->data[i] != 0) {
+                       if (!getenv("CANPING_MS"))
+                               fprintf(f, "%d %lld\n", i*h->resolution, cum);
+                       else
+                               fprintf(f, "%g %lld\n", 1e-3*(i*h->resolution), cum);
+               }
                cum -= h->data[i];
        }
 }
@@ -244,8 +248,9 @@ void *master_thread(void *arg)
        struct canfilt_t canfilt; /* filter for received messages */
 
        if (!option_open_once) {
-               /* Open can driver */
-               if(vca_open_handle(&vcah, option_device, NULL, 0) < 0) {
+               /* Open the CAN driver and disable (D) reception of
+                * all messages until we setup a filter below. */
+               if(vca_open_handle(&vcah, option_device, "D", 0) < 0) {
                        perror("open");
                        fprintf(stderr, "Error opening %s (for id %d)\n", option_device, ping_id);
                        exit(EXIT_CANNOT_OPEN); 
@@ -402,8 +407,12 @@ void *master_thread(void *arg)
                int i;
                snprintf(buf, sizeof(buf), "%s-%d.dat", option_save_all_times, ping_id);
                f = fopen(buf, "w");
-               for (i=0; i<option_count; i++)
-                       fprintf(f, "%u\n", td->times[i]);
+               for (i=0; i<option_count; i++) {
+                       if (!getenv("CANPING_MS")) 
+                               fprintf(f, "%u\n", td->times[i]);
+                       else
+                               fprintf(f, "%g\n", 1e-3*td->times[i]);
+               }
                fclose(f);
        }
 
@@ -458,8 +467,9 @@ void *slave_thread(void *arg)
        struct canfilt_t canfilt; /* filter for received messages */
 
        if (!option_open_once) {
-               /* Open the CAN driver */
-               if(vca_open_handle(&vcah, option_device, NULL, 0) < 0) {
+               /* Open the CAN driver and disable (D) reception of
+                * all messages until we setup a filter below. */
+               if(vca_open_handle(&vcah, option_device, "D", 0) < 0) {
                        perror("open");
                        printf("Error opening %s (for id %d)\n", option_device, ping_id);
                        exit(EXIT_CANNOT_OPEN);