?? send.c
字號:
#include "adv_can.h" /* Library function declaration */#include <sys/types.h>#include <sys/stat.h>#include <unistd.h>#include <fcntl.h>#include <stdio.h>#include <sys/ioctl.h>#include <string.h>/*-------------------------------------------------------------------------- * parameter : * 1:port should be "0" or "1" * 2:protocol "a" for 2.0A, "b" for 2.0B * 3:frame "s" for standard, "e" for extend --------------------------------------------------------------------------*//* define can controller interrupt connect to PC irq number */int main(int argv, char **arg){ int fd=0; /* declare the can card segment address */ CAN_STRUCT can; can_msg_t msg; char name[20]; int i,j; memset(name, 0 , 20); if(argv != 4) { printf("argument error!\n"); return 0; } sprintf(name, "/dev/can%c", *arg[1]); if((fd = open(name, O_RDWR))<=0) { printf("cannot open %s\n", name); return -1; } /*---- reset can controller */ ioctl(fd, IOCTL_RESET_CAN, NULL); if(*arg[2] =='a') can.protocol=CAN_PROTOCOL_20A; else if(*arg[2] =='b') can.protocol=CAN_PROTOCOL_20B; else {printf("arg 2 error\n"); return -1;} can.accode[0]=0x0; can.accode[1]=0x0; can.accode[2]=0x0; can.accode[3]=0x0; can.accmask[0]=0xff; can.accmask[1]=0xff; can.accmask[2]=0xff; can.accmask[3]=0xff; can.speed=CAN_125K; /* baud rate 125Kbps */ can.interruptmask=0xff; can.filtertype = 0; //0 for single filter*, 1 double filter if(ioctl(fd,IOCTL_SET_CAN,&can) <= 0) { printf("\n\n can controller port configure is error\n"); close(fd); return 0; } msg.dlen = 8; if(*arg[3] =='s') msg.ff=PELICAN_SFF; else if(*arg[3] =='e') msg.ff=PELICAN_EFF; else if(*arg[3] =='r') { msg.rtr = 1; msg.dlen = 0;} else if(*arg[3] =='x') { msg.rtr = 1; msg.ff=PELICAN_SFF;msg.dlen = 0;} else if(*arg[3] =='y') { msg.rtr = 1; msg.ff=PELICAN_EFF;msg.dlen = 0;} else {printf("arg 3 error\n"); return -1;} msg.id = 15; for(i=0;i<8;i++) msg.data[i] = 0; for(j=0;j<100;j++) { msg.id=j; for(i=0;i<8;i++) msg.data[i] = i; if(write(fd, &msg, CAN_MSG_LEN)) printf("send message OK %d\n",j); else printf("send message failed\n"); } /*---- reset can controller */ //ioctl(fd,IOCTL_RESET_CAN,0); close(fd); return 1;}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -