how to check CAN frame
Posted 鹅要长大
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 = -1; /* 返回值 */ int s = -1; /* socket描述符 */ int snd_size = 0; /* 发送缓冲区大小 */ int rcv_size = 0; /* 接收缓冲区大小 */ socklen_t optlen; /* 选项值长度 */ /*建立一个TCP套接字 */ s = socket(PF_INET,SOCK_STREAM,0); if( s == -1){ printf("建立套接字错误\n"); return -1; } /* 先读取缓冲区设置的情况,获得原始发送缓冲区大小*/ optlen = sizeof(snd_size); err = getsockopt(s, SOL_SOCKET, SO_SNDBUF,&snd_size, &optlen); if(err<0){ printf("获取发送缓冲区大小错误\n"); } /*打印原始缓冲区设置情况*/ /*获得原始接收缓冲区大小*/ optlen = sizeof(rcv_size); err = getsockopt(s, SOL_SOCKET, SO_RCVBUF, &rcv_size, &optlen); if(err<0){ printf("获取接收缓冲区大小错误\n"); } printf(" 发送缓冲区原始大小为: %d 字节\n",snd_size); printf(" 接收缓冲区原始大小为: %d 字节\n",rcv_size); /*设置发送缓冲区大小*/ snd_size = 10*1024; /* 发送缓冲区大小为8K */ optlen = sizeof(snd_size); err = setsockopt(s, SOL_SOCKET, SO_SNDBUF, &snd_size, optlen); if(err<0){ printf("设置发送缓冲区大小错误\n"); } /*设置接收缓冲区大小*/ rcv_size = 10*1024; /* 接收缓冲区大小为8K */ optlen = sizeof(rcv_size); err = setsockopt(s,SOL_SOCKET,SO_RCVBUF, (char *)&rcv_size, optlen); if(err<0){ printf("设置接收缓冲区大小错误\n"); } /*检查上述缓冲区设置的情况,获得修改后发送缓冲区大小 */ optlen = sizeof(snd_size); err = getsockopt(s, SOL_SOCKET, SO_SNDBUF,&snd_size, &optlen); if(err<0){ printf("获取发送缓冲区大小错误\n"); } /*获得修改后接收缓冲区大小 */ optlen = sizeof(rcv_size); err = getsockopt(s, SOL_SOCKET, SO_RCVBUF,(char *)&rcv_size, &optlen); if(err<0){ printf("获取接收缓冲区大小错误\n"); } /* 打印结果 */ printf(" 发送缓冲区大小为: %d 字节\n",snd_size); printf(" 接收缓冲区大小为: %d 字节\n",rcv_size); close(s); return 0; }
2. 查看统计:
cat /proc/net/can/stats
eg:
[email protected]:~/zrj/laneseg_TRT$ cat /proc/net/can/stats 503740 transmitted frames (TXF) 661826 received frames (RXF) 0 matched frames (RXMF) 0 % total match ratio (RXMR) 0 frames/s total tx rate (TXR) 0 frames/s total rx rate (RXR) 0 % current match ratio (CRXMR) 351 frames/s current tx rate (CTXR) 351 frames/s current rx rate (CRXR) 0 % max match ratio (MRXMR) 408 frames/s max tx rate (MTXR) 3061 frames/s max rx rate (MRXR) 0 current receive list entries (CRCV) 0 maximum receive list entries (MRCV)
3. ifconfig can1
[email protected]:~/zrj/laneseg_TRT$ ifconfig can1 can1 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 UP RUNNING NOARP MTU:72 Metric:1 RX packets:81647 errors:31020 dropped:0 overruns:0 frame:1262 TX packets:250985 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:10 RX bytes:589825 (589.8 KB) TX bytes:2007880 (2.0 MB) Interrupt:172
4. other tools.
CANoe or CANPro etc...
END
以上是关于how to check CAN frame的主要内容,如果未能解决你的问题,请参考以下文章
14 - How to check replication status
How to read frame data (Fighting Game)
HOW TO CHECK FOR ACTIVE TRACE FLAGS ON MICROSOFT SQL SERVER
How to check AD Account & Group DN information
[Groovy] How to check if element in groovy array/hash/collection/list?
FreeMarker : How to check if a variable exists in a FreeMarker template