码迷,mamicode.com
首页 > 其他好文 > 详细

how to check CAN frame

时间:2018-05-22 10:45:59      阅读:161      评论:0      收藏:0      [点我收藏+]

标签:修改   alt   roc   drop   amp   end   mrc   获取   pes   

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; 
} 
View Code

2. 查看统计:

cat /proc/net/can/stats

eg:

nvidia@tegra-ubuntu:~/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

nvidia@tegra-ubuntu:~/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

标签:修改   alt   roc   drop   amp   end   mrc   获取   pes   

原文地址:https://www.cnblogs.com/happyamyhope/p/9070517.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!