9 #include "../include/can.h"
12 unsigned long canmsg_id = 5;
19 char *can_dev_name = "/dev/can0";
21 #define PRT_PREFIX_SIZE 40
22 char prt_prefix[PRT_PREFIX_SIZE];
24 char *prt_prefix_in = "CAN %s : ";
30 printf("usage: sendburst\n");
31 printf(" -d, --device <name> name of CAN device [/dev/can0]\n");
32 printf(" -i, --id <num> ID of generated messages\n");
33 printf(" -f, --flags <num> CAN filter flags\n");
34 printf(" -s, --sync open in synchronous mode\n");
35 printf(" -w, --wait <num> number of seconds to wait between messages\n");
36 printf(" -b, --block <num> number of messages in block\n");
37 printf(" -c, --count <num> number of sent blocks of messages\n");
38 printf(" -p, --prefix <str> string prefix for output\n");
39 printf(" -V, --version show version\n");
40 printf(" -h, --help this usage screen\n");
43 int main(int argc, char *argv[])
45 static struct option long_opts[] = {
46 { "uldev", 1, 0, 'd' },
48 { "flags", 1, 0, 'f' },
49 { "sync", 0, 0, 's' },
50 { "wait", 1, 0, 'w' },
51 { "block", 1, 0, 'b' },
52 { "count", 1, 0, 'c' },
53 { "prefix",1, 0, 'p' },
54 { "version",0,0, 'V' },
55 { "help", 0, 0, 'h' },
60 struct canmsg_t sendmsg={0,0,5,0,8,{1,2,3,4,5,6,7,8}};
63 while ((opt = getopt_long(argc, argv, "d:i:f:sw:b:c:p:Vh",
64 &long_opts[0], NULL)) != EOF) switch (opt) {
69 canmsg_id = strtol(optarg,NULL,0);
72 canmsg_flags = strtol(optarg,NULL,0);
78 can_wait_sec = strtol(optarg,NULL,0);
81 block = strtol(optarg,NULL,0);
84 count = strtol(optarg,NULL,0);
87 prt_prefix_in = optarg;
90 fputs("LinCAN utilities v0.2\n", stdout);
95 exit(opt == 'h' ? 0 : 1);
98 if ((fd=open(can_dev_name, O_RDWR | (o_sync_fl? O_SYNC:0))) < 0) {
100 printf("Error opening %s\n", can_dev_name);
104 snprintf(prt_prefix, PRT_PREFIX_SIZE, prt_prefix_in, can_dev_name);
108 for(i=0;i<block;i++) {
109 sendmsg.flags=canmsg_flags;
110 sendmsg.id=canmsg_id;
113 if ((ret=write(fd,&sendmsg,sizeof(struct canmsg_t))) < 0) {
115 printf("%sError sending message\n", prt_prefix);
119 printf("%sSent block of %d messages #: %u\n", prt_prefix, block, j);
121 usleep(1000000*can_wait_sec);