| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277 |
- /******************************************************************************
- 版权所有:
- 文件名称: serial_stat.c
- 文件版本: 01.01
- 创建作者: xxxxxx
- 创建日期: 2014-11-12
- 功能说明: 串口统计模块
- 其它说明:
- 修改记录:
- */
- #include "head.h"
- //串口统计数据结构
- struct s_stat{
- int protocol; //规约
- unsigned int tx; //发送字节数
- unsigned int rx; //接收字节数
- unsigned int rx_err;//接收错误字节数
- unsigned int tx_frames;//发送帧数
- unsigned int rx_frames;//接收帧数
- unsigned int tx_errframes;//发送错误帧数
- unsigned int rx_errframes;//接收错误帧数
- };
- struct s_stat g_s_stat[COMM_CHANNEL_NUM];
- extern const SET_LIST ProtocolList[];
- /******************************************************************************
- 函数名称: s_stat_tx
- 函数版本: 01.01
- 创建作者: xxxxxx
- 创建日期: 2014-11-12
- 函数说明: 统计发送字节数。
- 参数说明:
- chnl:通道号
- bytes:字节数
- 返回值: 无。
- 修改记录:
- */
- void s_stat_tx(int chnl, int bytes)
- {
- if((chnl < 0) || (chnl >= COMM_CHANNEL_NUM ))
- {
- return ;
- }
-
- g_s_stat[chnl].tx += (unsigned int)bytes;
-
- }
- /******************************************************************************
- 函数名称: s_stat_rx
- 函数版本: 01.01
- 创建作者: xxxxxx
- 创建日期: 2014-11-12
- 函数说明: 统计接收字节数。
- 参数说明:
- chnl:通道号
- bytes:字节数
- 返回值: 无。
- 修改记录:
- */
- void s_stat_rx(int chnl, int bytes)
- {
- if((chnl < 0) || (chnl >= COMM_CHANNEL_NUM ))
- {
- return ;
- }
-
- g_s_stat[chnl].rx += (unsigned int)bytes;
- }
-
- /******************************************************************************
- 函数名称: s_stat_rx_err
- 函数版本: 01.01
- 创建作者: xxxxxx
- 创建日期: 2014-11-12
- 函数说明: 统计接收错误字节数。
- 参数说明:
- chnl:通道号
- bytes:字节数
- 返回值: 无。
- 修改记录:
- */
- void s_stat_rx_err(int chnl, int bytes)
- {
- if((chnl < 0) || (chnl >= COMM_CHANNEL_NUM ))
- {
- return ;
- }
-
- g_s_stat[chnl].rx_err += (unsigned int)bytes;
- }
- /******************************************************************************
- 函数名称: s_stat_rx_frame
- 函数版本: 01.01
- 创建作者: xxxxxx
- 创建日期: 2014-11-12
- 函数说明: 统计接收帧数。
- 参数说明:
- chnl:通道号
- 返回值: 无。
- 修改记录:
- */
- void s_stat_rx_frame(int chnl)
- {
- if((chnl < 0) || (chnl >= COMM_CHANNEL_NUM ))
- {
- return ;
- }
-
- g_s_stat[chnl].rx_frames++;
- }
- /******************************************************************************
- 函数名称: s_stat_tx_frame
- 函数版本: 01.01
- 创建作者: xxxxxx
- 创建日期: 2014-11-12
- 函数说明: 统计发送帧数。
- 参数说明:
- chnl:通道号
- 返回值: 无。
- 修改记录:
- */
- void s_stat_tx_frame(int chnl)
- {
- if((chnl < 0) || (chnl >= COMM_CHANNEL_NUM ))
- {
- return ;
- }
-
- g_s_stat[chnl].tx_frames++;
- }
- /******************************************************************************
- 函数名称: s_stat_rx_errframe
- 函数版本: 01.01
- 创建作者: xxxxxx
- 创建日期: 2014-11-12
- 函数说明: 统计接收错误帧数。
- 参数说明:
- chnl:通道号
- 返回值: 无。
- 修改记录:
- */
- void s_stat_rx_errframe(int chnl)
- {
- if((chnl < 0) || (chnl >= COMM_CHANNEL_NUM ))
- {
- return ;
- }
-
- g_s_stat[chnl].rx_errframes++;
- }
- int s_stat_rx_errframe_rc(int chnl)
- {
- if((chnl < 0) || (chnl >= COMM_CHANNEL_NUM ))
- {
- return 0;
- }
- return(g_s_stat[chnl].rx_errframes);
- }
- /******************************************************************************
- 函数名称: s_stat_tx_errframe
- 函数版本: 01.01
- 创建作者: xxxxxx
- 创建日期: 2014-11-12
- 函数说明: 统计发送错误帧数。
- 参数说明:
- chnl:通道号
- 返回值: 无。
- 修改记录:
- */
- void s_stat_tx_errframe(int chnl)
- {
- if((chnl < 0) || (chnl >= COMM_CHANNEL_NUM ))
- {
- return ;
- }
-
- g_s_stat[chnl].tx_errframes++;
- }
-
- /******************************************************************************
- 函数名称: s_stat_protocol
- 函数版本: 01.01
- 创建作者: xxxxxx
- 创建日期: 2014-11-12
- 函数说明: 统计规约。
- 参数说明:
- chnl:通道号
- 返回值: 无。
- 修改记录:
- */
- void s_stat_protocol(int chnl, int protocol)
- {
- if((chnl < 0) || (chnl >= COMM_CHANNEL_NUM ))
- {
- return ;
- }
-
- g_s_stat[chnl].protocol = protocol;
- }
- /******************************************************************************
- 函数名称: s_stat_reset
- 函数版本: 01.01
- 创建作者: xxxxxx
- 创建日期: 2014-11-12
- 函数说明: 串口统计信息复位。
- 参数说明:
- all: 为0表示全部初始化;为1表示除了规约的初始化.
- 返回值: 无。
- 修改记录:
- */
- void s_stat_reset(int all)
- {
- int i=0;
-
- for(i=0; i<COMM_CHANNEL_NUM; i++)
- {
- //规约不复位
- g_s_stat[i].tx = 0; //发送字节数
- g_s_stat[i].rx = 0;//接收字节数
- g_s_stat[i].rx_err = 0;//接收错误字节数
- g_s_stat[i].tx_frames = 0;//发送帧数
- g_s_stat[i].rx_frames = 0;//接收帧数
- g_s_stat[i].tx_errframes = 0;//发送错误帧数
- g_s_stat[i].rx_errframes = 0;//接收错误帧数
- }
- }
- /******************************************************************************
- 函数名称: s_stat_display
- 函数版本: 01.01
- 创建作者: xxxxxx
- 创建日期: 2014-11-12
- 函数说明: 显示统计信息。
- 参数说明: 无
- 返回值: 无。
- 修改记录:
- */
- int s_stat_display(void)
- {
- int i;
-
- rt_printf("通道\t规约 \t 接收字节\t 接收帧数\t接收错误帧\t接收错误字节\t 发送字节\t 发送帧数\r\n");
- for(i=0; i<COMM_CHANNEL_NUM; i++)
- {
- rt_printf("%s\t%-10s\t%10u\t%10u\t%10u\t %10u\t%10u\t%10u\r\n",
- get_comm_name(i+1),ProtocolList[g_s_stat[i].protocol].str, g_s_stat[i].rx, g_s_stat[i].rx_frames, g_s_stat[i].rx_errframes, g_s_stat[i].rx_err, g_s_stat[i].tx, g_s_stat[i].tx_frames);
- }
- return 0;
- }
- unsigned int s_stat_get(int chnl,int type)
- {
- if(type==1)return g_s_stat[chnl].rx;
- if(type==2)return g_s_stat[chnl].tx;
- return 0;
- }
-
-
|