19 #include <sys/types.h> 20 #include <sys/socket.h> 21 #include <sys/ioctl.h> 25 #include <linux/can.h> 26 #include <linux/can/raw.h> 32 printf(
"CSockCanScan\n");
39 struct can_frame sockmsg;
42 int sock = ppcs->sock;
45 printf(
"Start Sock Component\n");
46 while (ppcs->run_can) {
49 nbytes = read(
sock, &sockmsg,
sizeof(
struct can_frame));
56 if (nbytes <
sizeof(
struct can_frame)) {
60 cmsg.
c_id = sockmsg.can_id;
62 cmsg.
c_dlc = sockmsg.can_dlc;
63 memcpy(&cmsg.
c_data[0],&sockmsg.data[0],8);
64 ppcs->cb->FireOnChange(
sock, &cmsg);
96 unsigned int tseg1 = 0;
97 unsigned int tseg2 = 0;
99 unsigned int noSamp = 0;
100 unsigned int syncmode = 0;
101 struct sockaddr_can addr;
111 com = strchr(
name,
':');
119 printf(
"Device %s %s\n",
name,com);
121 numPar = sscanf(parameters,
"%d %d %d %d %d %d",&br,&tseg1,&tseg2,&sjw,&noSamp,&syncmode);
128 sock = socket(PF_CAN, SOCK_RAW, CAN_RAW);
131 perror(
"Cannot open the socket");
134 memset(&ifr.ifr_name, 0,
sizeof(ifr.ifr_name));
135 strncpy(ifr.ifr_name, com,
sizeof(com));
137 if (ioctl(
sock, SIOCGIFINDEX, &ifr) < 0) {
138 perror(
"SIOCGIFINDEX");
142 addr.can_family = AF_CAN;
143 addr.can_ifindex = ifr.ifr_ifindex;
145 if (bind(
sock, (
struct sockaddr *)&addr,
sizeof(addr)) < 0) {
168 struct can_frame frame;
171 unsigned char *buf = message;
172 frame.can_id = cobID;
176 printf(
"Send Message %d %d\n",cobID,len);
183 memcpy(frame.data,buf,l1);
185 nbytes = write(
sock, &frame,
sizeof(
struct can_frame));
186 if (nbytes <
sizeof(
struct can_frame)) {
197 struct can_frame frame;
199 frame.can_id = cobID + CAN_RTR_FLAG ;
201 printf(
"Remote Request %d\n",cobID);
202 nbytes = write(
sock, &frame,
sizeof(
struct can_frame));