]> rtime.felk.cvut.cz Git - lincan.git/blobdiff - lincan/utils/sendburst.c
Header-files cleanup and CAN queue edges and ends locking reimplemented.
[lincan.git] / lincan / utils / sendburst.c
index 0e32b63d083761056ff45882b34276372f9ccbd4..4d715d12ca373414bd874fd7954b0aedc120776e 100644 (file)
 
 int canmsg_flags = 0;
 unsigned long canmsg_id = 5;
 
 int canmsg_flags = 0;
 unsigned long canmsg_id = 5;
+int block = 10;
+int count = 0;
 
 int can_wait_sec = 1;
 
 int can_wait_sec = 1;
+int o_sync_fl = 0;
 
 char *can_dev_name = "/dev/can0";
 
 
 char *can_dev_name = "/dev/can0";
 
@@ -28,7 +31,10 @@ usage(void)
   printf("  -d, --device  <name>     name of CAN device [/dev/can0]\n");
   printf("  -i, --id  <num>          ID of generated messages\n");
   printf("  -f, --flags <num>        CAN filter flags\n");
   printf("  -d, --device  <name>     name of CAN device [/dev/can0]\n");
   printf("  -i, --id  <num>          ID of generated messages\n");
   printf("  -f, --flags <num>        CAN filter flags\n");
+  printf("  -s, --sync               open in synchronous mode\n");
   printf("  -w, --wait <num>         number of seconds to wait between messages\n");
   printf("  -w, --wait <num>         number of seconds to wait between messages\n");
+  printf("  -b, --block <num>        number of messages in  block\n");
+  printf("  -c, --count <num>        number of sent blocks of messages\n");
   printf("  -p, --prefix <str>       string prefix for output\n");
   printf("  -V, --version            show version\n");
   printf("  -h, --help               this usage screen\n");
   printf("  -p, --prefix <str>       string prefix for output\n");
   printf("  -V, --version            show version\n");
   printf("  -h, --help               this usage screen\n");
@@ -40,7 +46,10 @@ int main(int argc, char *argv[])
                { "uldev", 1, 0, 'd' },
                { "id",    1, 0, 'i' },
                { "flags", 1, 0, 'f' },
                { "uldev", 1, 0, 'd' },
                { "id",    1, 0, 'i' },
                { "flags", 1, 0, 'f' },
+               { "sync",  0, 0, 's' },
                { "wait",  1, 0, 'w' },
                { "wait",  1, 0, 'w' },
+               { "block", 1, 0, 'b' },
+               { "count", 1, 0, 'c' },
                { "prefix",1, 0, 'p' },
                { "version",0,0, 'V' },
                { "help",  0, 0, 'h' },
                { "prefix",1, 0, 'p' },
                { "version",0,0, 'V' },
                { "help",  0, 0, 'h' },
@@ -51,7 +60,7 @@ int main(int argc, char *argv[])
        struct canmsg_t sendmsg={0,0,5,0,8,{1,2,3,4,5,6,7,8}};
        int fd, ret,i,j;
 
        struct canmsg_t sendmsg={0,0,5,0,8,{1,2,3,4,5,6,7,8}};
        int fd, ret,i,j;
 
-       while ((opt = getopt_long(argc, argv, "d:i:f:w:p:Vh",
+       while ((opt = getopt_long(argc, argv, "d:i:f:sw:b:c:p:Vh",
                            &long_opts[0], NULL)) != EOF) switch (opt) {
                case 'd':
                        can_dev_name=optarg;
                            &long_opts[0], NULL)) != EOF) switch (opt) {
                case 'd':
                        can_dev_name=optarg;
@@ -62,9 +71,18 @@ int main(int argc, char *argv[])
                case 'f':
                        canmsg_flags = strtol(optarg,NULL,0);
                        break;
                case 'f':
                        canmsg_flags = strtol(optarg,NULL,0);
                        break;
+               case 's':
+                       o_sync_fl = 1;
+                       break;
                case 'w':
                        can_wait_sec = strtol(optarg,NULL,0);
                        break;
                case 'w':
                        can_wait_sec = strtol(optarg,NULL,0);
                        break;
+               case 'b':
+                       block = strtol(optarg,NULL,0);
+                       break;
+               case 'c':
+                       count = strtol(optarg,NULL,0);
+                       break;
                case 'p':
                        prt_prefix_in = optarg;
                        break;
                case 'p':
                        prt_prefix_in = optarg;
                        break;
@@ -77,7 +95,7 @@ int main(int argc, char *argv[])
                        exit(opt == 'h' ? 0 : 1);
        }
 
                        exit(opt == 'h' ? 0 : 1);
        }
 
-       if ((fd=open(can_dev_name, O_RDWR)) < 0) {
+       if ((fd=open(can_dev_name, O_RDWR | (o_sync_fl? O_SYNC:0))) < 0) {
                perror("open");
                printf("Error opening %s\n", can_dev_name);
                exit(1);        
                perror("open");
                printf("Error opening %s\n", can_dev_name);
                exit(1);        
@@ -87,7 +105,7 @@ int main(int argc, char *argv[])
 
        j=0;
        while (1) {
 
        j=0;
        while (1) {
-               for(i=0;i<10;i++) {
+               for(i=0;i<block;i++) {
                        sendmsg.flags=canmsg_flags;
                        sendmsg.id=canmsg_id;
                        sendmsg.data[0]=i;
                        sendmsg.flags=canmsg_flags;
                        sendmsg.id=canmsg_id;
                        sendmsg.data[0]=i;
@@ -98,9 +116,11 @@ int main(int argc, char *argv[])
                                break;
                        }
                }
                                break;
                        }
                }
-               printf("%sSent block of 10 messages #: %u\n", prt_prefix, j);
+               printf("%sSent block of %d messages #: %u\n", prt_prefix, block, j);
                j++;
                usleep(1000000*can_wait_sec);
                j++;
                usleep(1000000*can_wait_sec);
+               if(count)
+                       if(!--count) break;
        }
        close(fd);
        return 0;
        }
        close(fd);
        return 0;