serial_stat.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. /******************************************************************************
  2. 版权所有:
  3. 文件名称: serial_stat.c
  4. 文件版本: 01.01
  5. 创建作者: xxxxxx
  6. 创建日期: 2014-11-12
  7. 功能说明: 串口统计模块
  8. 其它说明:
  9. 修改记录:
  10. */
  11. #include "head.h"
  12. //串口统计数据结构
  13. struct s_stat{
  14. int protocol; //规约
  15. unsigned int tx; //发送字节数
  16. unsigned int rx; //接收字节数
  17. unsigned int rx_err;//接收错误字节数
  18. unsigned int tx_frames;//发送帧数
  19. unsigned int rx_frames;//接收帧数
  20. unsigned int tx_errframes;//发送错误帧数
  21. unsigned int rx_errframes;//接收错误帧数
  22. };
  23. struct s_stat g_s_stat[COMM_CHANNEL_NUM];
  24. extern const SET_LIST ProtocolList[];
  25. /******************************************************************************
  26. 函数名称: s_stat_tx
  27. 函数版本: 01.01
  28. 创建作者: xxxxxx
  29. 创建日期: 2014-11-12
  30. 函数说明: 统计发送字节数。
  31. 参数说明:
  32. chnl:通道号
  33. bytes:字节数
  34. 返回值: 无。
  35. 修改记录:
  36. */
  37. void s_stat_tx(int chnl, int bytes)
  38. {
  39. if((chnl < 0) || (chnl >= COMM_CHANNEL_NUM ))
  40. {
  41. return ;
  42. }
  43. g_s_stat[chnl].tx += (unsigned int)bytes;
  44. }
  45. /******************************************************************************
  46. 函数名称: s_stat_rx
  47. 函数版本: 01.01
  48. 创建作者: xxxxxx
  49. 创建日期: 2014-11-12
  50. 函数说明: 统计接收字节数。
  51. 参数说明:
  52. chnl:通道号
  53. bytes:字节数
  54. 返回值: 无。
  55. 修改记录:
  56. */
  57. void s_stat_rx(int chnl, int bytes)
  58. {
  59. if((chnl < 0) || (chnl >= COMM_CHANNEL_NUM ))
  60. {
  61. return ;
  62. }
  63. g_s_stat[chnl].rx += (unsigned int)bytes;
  64. }
  65. /******************************************************************************
  66. 函数名称: s_stat_rx_err
  67. 函数版本: 01.01
  68. 创建作者: xxxxxx
  69. 创建日期: 2014-11-12
  70. 函数说明: 统计接收错误字节数。
  71. 参数说明:
  72. chnl:通道号
  73. bytes:字节数
  74. 返回值: 无。
  75. 修改记录:
  76. */
  77. void s_stat_rx_err(int chnl, int bytes)
  78. {
  79. if((chnl < 0) || (chnl >= COMM_CHANNEL_NUM ))
  80. {
  81. return ;
  82. }
  83. g_s_stat[chnl].rx_err += (unsigned int)bytes;
  84. }
  85. /******************************************************************************
  86. 函数名称: s_stat_rx_frame
  87. 函数版本: 01.01
  88. 创建作者: xxxxxx
  89. 创建日期: 2014-11-12
  90. 函数说明: 统计接收帧数。
  91. 参数说明:
  92. chnl:通道号
  93. 返回值: 无。
  94. 修改记录:
  95. */
  96. void s_stat_rx_frame(int chnl)
  97. {
  98. if((chnl < 0) || (chnl >= COMM_CHANNEL_NUM ))
  99. {
  100. return ;
  101. }
  102. g_s_stat[chnl].rx_frames++;
  103. }
  104. /******************************************************************************
  105. 函数名称: s_stat_tx_frame
  106. 函数版本: 01.01
  107. 创建作者: xxxxxx
  108. 创建日期: 2014-11-12
  109. 函数说明: 统计发送帧数。
  110. 参数说明:
  111. chnl:通道号
  112. 返回值: 无。
  113. 修改记录:
  114. */
  115. void s_stat_tx_frame(int chnl)
  116. {
  117. if((chnl < 0) || (chnl >= COMM_CHANNEL_NUM ))
  118. {
  119. return ;
  120. }
  121. g_s_stat[chnl].tx_frames++;
  122. }
  123. /******************************************************************************
  124. 函数名称: s_stat_rx_errframe
  125. 函数版本: 01.01
  126. 创建作者: xxxxxx
  127. 创建日期: 2014-11-12
  128. 函数说明: 统计接收错误帧数。
  129. 参数说明:
  130. chnl:通道号
  131. 返回值: 无。
  132. 修改记录:
  133. */
  134. void s_stat_rx_errframe(int chnl)
  135. {
  136. if((chnl < 0) || (chnl >= COMM_CHANNEL_NUM ))
  137. {
  138. return ;
  139. }
  140. g_s_stat[chnl].rx_errframes++;
  141. }
  142. int s_stat_rx_errframe_rc(int chnl)
  143. {
  144. if((chnl < 0) || (chnl >= COMM_CHANNEL_NUM ))
  145. {
  146. return 0;
  147. }
  148. return(g_s_stat[chnl].rx_errframes);
  149. }
  150. /******************************************************************************
  151. 函数名称: s_stat_tx_errframe
  152. 函数版本: 01.01
  153. 创建作者: xxxxxx
  154. 创建日期: 2014-11-12
  155. 函数说明: 统计发送错误帧数。
  156. 参数说明:
  157. chnl:通道号
  158. 返回值: 无。
  159. 修改记录:
  160. */
  161. void s_stat_tx_errframe(int chnl)
  162. {
  163. if((chnl < 0) || (chnl >= COMM_CHANNEL_NUM ))
  164. {
  165. return ;
  166. }
  167. g_s_stat[chnl].tx_errframes++;
  168. }
  169. /******************************************************************************
  170. 函数名称: s_stat_protocol
  171. 函数版本: 01.01
  172. 创建作者: xxxxxx
  173. 创建日期: 2014-11-12
  174. 函数说明: 统计规约。
  175. 参数说明:
  176. chnl:通道号
  177. 返回值: 无。
  178. 修改记录:
  179. */
  180. void s_stat_protocol(int chnl, int protocol)
  181. {
  182. if((chnl < 0) || (chnl >= COMM_CHANNEL_NUM ))
  183. {
  184. return ;
  185. }
  186. g_s_stat[chnl].protocol = protocol;
  187. }
  188. /******************************************************************************
  189. 函数名称: s_stat_reset
  190. 函数版本: 01.01
  191. 创建作者: xxxxxx
  192. 创建日期: 2014-11-12
  193. 函数说明: 串口统计信息复位。
  194. 参数说明:
  195. all: 为0表示全部初始化;为1表示除了规约的初始化.
  196. 返回值: 无。
  197. 修改记录:
  198. */
  199. void s_stat_reset(int all)
  200. {
  201. int i=0;
  202. for(i=0; i<COMM_CHANNEL_NUM; i++)
  203. {
  204. //规约不复位
  205. g_s_stat[i].tx = 0; //发送字节数
  206. g_s_stat[i].rx = 0;//接收字节数
  207. g_s_stat[i].rx_err = 0;//接收错误字节数
  208. g_s_stat[i].tx_frames = 0;//发送帧数
  209. g_s_stat[i].rx_frames = 0;//接收帧数
  210. g_s_stat[i].tx_errframes = 0;//发送错误帧数
  211. g_s_stat[i].rx_errframes = 0;//接收错误帧数
  212. }
  213. }
  214. /******************************************************************************
  215. 函数名称: s_stat_display
  216. 函数版本: 01.01
  217. 创建作者: xxxxxx
  218. 创建日期: 2014-11-12
  219. 函数说明: 显示统计信息。
  220. 参数说明: 无
  221. 返回值: 无。
  222. 修改记录:
  223. */
  224. int s_stat_display(void)
  225. {
  226. int i;
  227. rt_printf("通道\t规约 \t 接收字节\t 接收帧数\t接收错误帧\t接收错误字节\t 发送字节\t 发送帧数\r\n");
  228. for(i=0; i<COMM_CHANNEL_NUM; i++)
  229. {
  230. rt_printf("%s\t%-10s\t%10u\t%10u\t%10u\t %10u\t%10u\t%10u\r\n",
  231. 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);
  232. }
  233. return 0;
  234. }
  235. unsigned int s_stat_get(int chnl,int type)
  236. {
  237. if(type==1)return g_s_stat[chnl].rx;
  238. if(type==2)return g_s_stat[chnl].tx;
  239. return 0;
  240. }