/* 1. The packet router */
#include
#include
#include
#include
#include
#include
#include
#include
#include
Int main ()
{
Int s nbytes;
Struct sockaddr_can addr.
Struct ifreq ifr.
Struct can_frame frame [2]={{0}};
S=socket (PF_CAN SOCK_RAW, CAN_RAW);//create a socket
Strcpy (ifr) ifr_name, "can0");
The ioctl (s, SIOCGIFINDEX, & amp; Ifr);//specified can0 equipment
Addr. Can_family=AF_CAN;
Addr. Can_ifindex=ifr. Ifr_ifindex;
Bind (s, (struct sockaddr *) & amp; Addr, sizeof (addr));//to bind the socket and can0
//disable filtering rules, this process does not receive a message, only responsible for sending
The setsockopt (s, SOL_CAN_RAW CAN_RAW_FILTER, NULL, 0).
//generated two message
Frame [0]. Can_id=0 x11;
Frame [0]. Can_dlc=1;
Frame [0]. Data [0]='Y'
Frame [0]. Can_id=0 x22;
Frame [0]. Can_dlc=1;
Frame [0]. Data [0]='N';
//cycle to send two message
While (1)
{
Nbytes=write (s, & amp; Frame [0], sizeof (frame [0]));//send frame [0]
If (nbytes!=sizeof (frame) [0])
{
Printf (" Send Error frame [0] \ n!" );
break;//send error from the
}
Sleep (1);
Nbytes=write (s, & amp; Frame [1], sizeof (frame [1]));//send frame [1]
If (nbytes!=sizeof (frame) [0])
{
Printf (" Send Error frame [1] \ n!" );
break;
}
Sleep (1);
}
Close (s);
return 0;
}
In this program was set up to send the extension of the frame ID 0 x0cf11f05, I put the cross compile IMX6Q development board run on Linux system (run), sent via easyarm cantest software can message, receive the ID of the display boards to 0 x8cf11f05, display is not correct, and I tried, when sending message ID 0 x1cf11f05, receive show 0 x9cf11f05, and extended the frame ID range of 0-0 x1fffffff, preliminary analysis is much more in front of the ID two 10, what a great god know the reason? Or have a better analysis results? Thank you for your attention!
Below is the screenshots:
Sends a packet capture
Receives information screenshots on board
CodePudding user response:
I tried, I, too, and check the information, and it extended frame is the first byte of the 7th FF, are in the extended frame 1, likewise, in the standard frame is 0, don't know what to say so OK,
CAN go to the expansion of the search CAN frame the frame information format,
CodePudding user response:
Bit31 is extended frame tagging CAN_EFF_FLAG, taking extended frame ID remember with mask CAN_EFF_MASK with it
CodePudding user response:
And bloggers have the same problem, want to talk about