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 #ifdef CAN_MSG_VERSION_2
61 struct canmsg_t sendmsg={0,0,5,{0,0},8,{1,2,3,4,5,6,7,8}};
62 #else /* CAN_MSG_VERSION_2 */
63 struct canmsg_t sendmsg={0,0,5,0,8,{1,2,3,4,5,6,7,8}};
64 #endif /* CAN_MSG_VERSION_2 */
67 while ((opt = getopt_long(argc, argv, "d:i:f:sw:b:c:p:Vh",
68 &long_opts[0], NULL)) != EOF) switch (opt) {
73 canmsg_id = strtol(optarg,NULL,0);
76 canmsg_flags = strtol(optarg,NULL,0);
82 can_wait_sec = strtol(optarg,NULL,0);
85 block = strtol(optarg,NULL,0);
88 count = strtol(optarg,NULL,0);
91 prt_prefix_in = optarg;
94 fputs("LinCAN utilities v0.2\n", stdout);
99 exit(opt == 'h' ? 0 : 1);
102 if ((fd=open(can_dev_name, O_RDWR | (o_sync_fl? O_SYNC:0))) < 0) {
104 printf("Error opening %s\n", can_dev_name);
108 snprintf(prt_prefix, PRT_PREFIX_SIZE, prt_prefix_in, can_dev_name);
112 for(i=0;i<block;i++) {
113 sendmsg.flags=canmsg_flags;
114 sendmsg.id=canmsg_id;
117 if ((ret=write(fd,&sendmsg,sizeof(struct canmsg_t))) < 0) {
119 printf("%sError sending message\n", prt_prefix);
123 printf("%sSent block of %d messages #: %u\n", prt_prefix, block, j);
125 usleep(1000000*can_wait_sec);