serial_stat.c 6.0 KB

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