7 #include "../include/can.h"
12 int i=0, fd=0, ret=0, count=0;
15 char ch, transmission[MAXL+1], specialfile[MAXL+1]="/dev/can0", emptystring[MAXL+1]="", buf[MAXL+1];
17 struct canmsg_t message;
19 printf("\nThis program allows you to send or receive Can messages.\n");
20 printf("Please answer the following questions:\n\n");
22 while ( (*transmission!='s') && (*transmission!='r') ) {
23 printf("Would you like to send or receive a message?\n");
24 printf("send: <s> | receive: <r> ");
25 strcpy(transmission,emptystring);
27 while ( (ch=getchar()) != '\n' )
28 transmission[count++]=ch;
29 transmission[count]='\0';
32 while ( *remote!='y' && *remote!='n' ) {
33 printf("Should the message be configured for Remote Transmission Requests?\n");
34 printf("yes: <y> | no: <n> ");
35 strcpy(remote,emptystring);
37 while ( (ch=getchar()) != '\n' )
42 message.flags = MSG_RTR;
45 // message.flags |= MSG_EXT; hard code EXT for now
47 if (transmission[0]=='s') {
48 printf("From wich device file would you like to send the message?\n");
51 fgets(buf,MAXL,stdin);
52 buf[strcspn(buf,"\n")]='\0';
54 strncpy(specialfile,buf,MAXL);
55 specialfile[MAXL]='\0';
56 specialfile[MAXL]='\0';
57 printf("Enter the Message ID ");
58 scanf("%lx",&message.id);
59 if(message.id>=(1<<11))
60 message.flags |= MSG_EXT;
61 printf("Enter the Message Length ");
63 message.length=msglen;
64 for (i=0; i<message.length; i++) {
65 printf("Enter data byte [%d] ",i);
66 scanf("%x",(int *)&message.data[i]);
69 if (*transmission=='r') {
70 printf("At which device file would you like to receive the message?\n");
73 fgets(buf,MAXL,stdin);
74 buf[strcspn(buf,"\n")]='\0';
76 strncpy(specialfile,buf,MAXL);
77 specialfile[MAXL]='\0';
78 printf("Enter the Message ID ");
79 scanf("%lx",&message.id);
83 fd=open(specialfile,O_RDWR);
85 printf("Error opening %s\n",specialfile);
89 if (transmission[0]=='s') {
90 printf("Press enter to send message\n");
92 while (getchar() != '\n');
93 ret=write(fd, &message, sizeof(struct canmsg_t));
95 printf("Error sending message from %s\n",specialfile);
97 printf("Message successfully sent from %s\n",specialfile);
100 if (*transmission=='r') {
101 ioctl(fd,CONF_FILTER,message.id);
102 printf("Press enter to receive message or <l>oop\n");
104 while ( loop == 'l') {
106 ret=read(fd, &message, sizeof(struct canmsg_t));
108 printf("Error receiving message on %s\n",
111 printf("Id : %lx\n",message.id);
112 printf("length : %d\n",message.length);
113 printf("flags : 0x%02x\n", message.flags);
114 #ifdef CAN_MSG_VERSION_2
115 printf("time : %lds %ldusec\n", message.timestamp.tv_sec,
116 message.timestamp.tv_usec);
117 #else /* CAN_MSG_VERSION_2 */
118 printf("time : %ld\n", message.timestamp);
119 #endif /* CAN_MSG_VERSION_2 */
120 for (i=0; i<message.length; i++)
121 printf("data%d : %02x\n",i,
128 printf("Error closing %s\n",specialfile);