how to check CAN frame

1. check buffer size

getsockopt(s, SOL_SOCKET, SO_SNDBUF,&snd_size, &optlen);

setsockopt(s, SOL_SOCKET, SO_SNDBUF,&snd_size, &optlen);

setsockopt(s,SOL_SOCKET,SO_RCVBUF, (char *)&rcv_size, optlen);

//RE:https://blog.csdn.net/fuyuehua22/article/details/38232769
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <assert.h> int main(int argc,char **argv)
{
int err = -; /* 返回值 */
int s = -; /* socket描述符 */
int snd_size = ; /* 发送缓冲区大小 */
int rcv_size = ; /* 接收缓冲区大小 */
socklen_t optlen; /* 选项值长度 */ /*建立一个TCP套接字 */
s = socket(PF_INET,SOCK_STREAM,);
if( s == -){
printf("建立套接字错误\n");
return -;
} /* 先读取缓冲区设置的情况,获得原始发送缓冲区大小*/
optlen = sizeof(snd_size);
err = getsockopt(s, SOL_SOCKET, SO_SNDBUF,&snd_size, &optlen);
if(err<){
printf("获取发送缓冲区大小错误\n");
}
/*打印原始缓冲区设置情况*/ /*获得原始接收缓冲区大小*/
optlen = sizeof(rcv_size);
err = getsockopt(s, SOL_SOCKET, SO_RCVBUF, &rcv_size, &optlen);
if(err<){
printf("获取接收缓冲区大小错误\n");
} printf(" 发送缓冲区原始大小为: %d 字节\n",snd_size);
printf(" 接收缓冲区原始大小为: %d 字节\n",rcv_size); /*设置发送缓冲区大小*/
snd_size = *; /* 发送缓冲区大小为8K */
optlen = sizeof(snd_size);
err = setsockopt(s, SOL_SOCKET, SO_SNDBUF, &snd_size, optlen);
if(err<){
printf("设置发送缓冲区大小错误\n");
} /*设置接收缓冲区大小*/
rcv_size = *; /* 接收缓冲区大小为8K */
optlen = sizeof(rcv_size);
err = setsockopt(s,SOL_SOCKET,SO_RCVBUF, (char *)&rcv_size, optlen);
if(err<){
printf("设置接收缓冲区大小错误\n");
} /*检查上述缓冲区设置的情况,获得修改后发送缓冲区大小 */
optlen = sizeof(snd_size);
err = getsockopt(s, SOL_SOCKET, SO_SNDBUF,&snd_size, &optlen);
if(err<){
printf("获取发送缓冲区大小错误\n");
} /*获得修改后接收缓冲区大小 */
optlen = sizeof(rcv_size);
err = getsockopt(s, SOL_SOCKET, SO_RCVBUF,(char *)&rcv_size, &optlen);
if(err<){
printf("获取接收缓冲区大小错误\n");
} /* 打印结果 */
printf(" 发送缓冲区大小为: %d 字节\n",snd_size);
printf(" 接收缓冲区大小为: %d 字节\n",rcv_size); close(s);
return ;
}

2. 查看统计:

cat /proc/net/can/stats

eg:

nvidia@tegra-ubuntu:~/zrj/laneseg_TRT$ cat /proc/net/can/stats 

    transmitted frames (TXF)
received frames (RXF)
matched frames (RXMF) % total match ratio (RXMR)
frames/s total tx rate (TXR)
frames/s total rx rate (RXR) % current match ratio (CRXMR)
frames/s current tx rate (CTXR)
frames/s current rx rate (CRXR) % max match ratio (MRXMR)
frames/s max tx rate (MTXR)
frames/s max rx rate (MRXR) current receive list entries (CRCV)
maximum receive list entries (MRCV)

3. ifconfig can1

nvidia@tegra-ubuntu:~/zrj/laneseg_TRT$ ifconfig can1
can1 Link encap:UNSPEC HWaddr ---------------
UP RUNNING NOARP MTU: Metric:
RX packets: errors: dropped: overruns: frame:
TX packets: errors: dropped: overruns: carrier:
collisions: txqueuelen:
RX bytes: (589.8 KB) TX bytes: (2.0 MB)
Interrupt:

4. other tools.

CANoe or CANPro etc...

END

上一篇:core dump


下一篇:Flask微型框架入门笔记