]> rtime.felk.cvut.cz Git - can-utils.git/blobdiff - candump.c
can-calc-bit-timint: rename bitrate -> bitrate_nominal
[can-utils.git] / candump.c
index b67f3f8ecdf460b324a5e6fc60930fbec1197098..5daf6222ca7d2d8e6a6beb4a4b598acf0d231ecd 100644 (file)
--- a/candump.c
+++ b/candump.c
@@ -43,6 +43,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <stdint.h>
 #include <unistd.h>
 #include <string.h>
 #include <signal.h>
@@ -130,6 +131,7 @@ void print_usage(char *prg)
        fprintf(stderr, " <can_id>:<can_mask> (matches when <received_can_id> & mask == can_id & mask)\n");
        fprintf(stderr, " <can_id>~<can_mask> (matches when <received_can_id> & mask != can_id & mask)\n");
        fprintf(stderr, " #<error_mask>       (set error frame filter, see include/linux/can/error.h)\n");
+       fprintf(stderr, " [j|J]               (join the given CAN filters - logical AND semantic)\n");
        fprintf(stderr, "\nCAN IDs, masks and data content are given and expected in hexadecimal values.\n");
        fprintf(stderr, "When can_id and can_mask are both 8 digits, they are assumed to be 29 bit EFF.\n");
        fprintf(stderr, "Without any given filter all data frames are received ('0:0' default filter).\n");
@@ -217,6 +219,7 @@ int main(int argc, char **argv)
        int rcvbuf_size = 0;
        int opt, ret;
        int currmax, numfilter;
+       int join_filter;
        char *ptr, *nptr;
        struct sockaddr_can addr;
        char ctrlmsg[CMSG_SPACE(sizeof(struct timeval)) + CMSG_SPACE(sizeof(__u32))];
@@ -466,6 +469,7 @@ int main(int argc, char **argv)
 
                        numfilter = 0;
                        err_mask = 0;
+                       join_filter = 0;
 
                        while (nptr) {
 
@@ -483,6 +487,8 @@ int main(int argc, char **argv)
                                        rfilter[numfilter].can_id |= CAN_INV_FILTER;
                                        rfilter[numfilter].can_mask &= ~CAN_ERR_FLAG;
                                        numfilter++;
+                               } else if (*ptr == 'j' || *ptr == 'J') {
+                                       join_filter = 1;
                                } else if (sscanf(ptr, "#%x", &err_mask) != 1) { 
                                        fprintf(stderr, "Error in filter option parsing: '%s'\n", ptr);
                                        return 1;
@@ -493,6 +499,12 @@ int main(int argc, char **argv)
                                setsockopt(s[i], SOL_CAN_RAW, CAN_RAW_ERR_FILTER,
                                           &err_mask, sizeof(err_mask));
 
+                       if (join_filter && setsockopt(s[i], SOL_CAN_RAW, CAN_RAW_JOIN_FILTERS,
+                                                     &join_filter, sizeof(join_filter)) < 0) {
+                               perror("setsockopt CAN_RAW_JOIN_FILTERS not supported by your Linux Kernel");
+                               return 1;
+                       }
+
                        if (numfilter)
                                setsockopt(s[i], SOL_CAN_RAW, CAN_RAW_FILTER,
                                           rfilter, numfilter * sizeof(struct can_filter));
@@ -673,12 +685,7 @@ int main(int argc, char **argv)
                                /* check for (unlikely) dropped frames on this specific socket */
                                if (dropcnt[i] != last_dropcnt[i]) {
 
-                                       __u32 frames;
-
-                                       if (dropcnt[i] > last_dropcnt[i])
-                                               frames = dropcnt[i] - last_dropcnt[i];
-                                       else
-                                               frames = 4294967295U - last_dropcnt[i] + dropcnt[i]; /* 4294967295U == UINT32_MAX */
+                                       __u32 frames = dropcnt[i] - last_dropcnt[i];
 
                                        if (silent != SILENT_ON)
                                                printf("DROPCOUNT: dropped %d CAN frame%s on '%s' socket (total drops %d)\n",