Quellcode durchsuchen

优化netio 将初始化命令精简为netio

Meco Man vor 4 Jahren
Ursprung
Commit
2e2fed166f
2 geänderte Dateien mit 13 neuen und 17 gelöschten Zeilen
  1. 2 2
      netio/README.md
  2. 11 15
      netio/netio.c

+ 2 - 2
netio/README.md

@@ -13,7 +13,7 @@ RT-Thread 目前支持的是 NetIO TCP 服务器。
 需要在 RT-Thread 上使用 Finsh/MSH 命令来启动 NetIO 服务器,大致效果如下:
 
 ```
-msh />netio_init
+msh />netio
 NetIO server start successfully
 msh />
 ```
@@ -32,4 +32,4 @@ msh />
 - 点击 `Start measure` 开始测试(测试前务必确保服务器可以被 PC ping 通);
 - 等待测试结束。结束后,不同数据包对应的收发测试结果将会在结果区域显示出来。
 
-![netio_tested](../images/netio_tested.png)
+![netio_tested](../images/netio_tested.png)

+ 11 - 15
netio/netio.c

@@ -31,14 +31,16 @@
  *
  */
 
-#include <rtthread.h>
-
-#ifdef PKG_NETUTILS_NETIO
 #include "lwip/opt.h"
 
 #if LWIP_TCP
+#include <rtthread.h>
 #include "lwip/tcp.h"
 
+#define DBG_SECTION_NAME               "netio"
+#define DBG_LEVEL                      DBG_INFO
+#include <rtdbg.h>
+
 /*
  * This implements a netio server.
  *  The client sends a command word (4 bytes) then a data length word (4 bytes).
@@ -420,7 +422,7 @@ netio_accept(void *arg, struct tcp_pcb *pcb, err_t err)
     return ERR_OK;
 }
 
-void netio_init(void)
+static void netio_init(void)
 {
     static rt_bool_t init_ok = RT_FALSE;
     struct tcp_pcb *pcb;
@@ -433,21 +435,15 @@ void netio_init(void)
         pcb = tcp_listen(pcb);
         tcp_accept(pcb, netio_accept);
         init_ok = RT_TRUE;
-        rt_kprintf("NetIO server start successfully\n");
+        LOG_I("netio server start successfully");
     }
     else
     {
-        rt_kprintf("netio: server already running\n");
+        LOG_I("netio server has already run");
     }
 }
-
-#endif /* LWIP_TCP */
-
-#ifdef RT_USING_FINSH
-#include <finsh.h>
-FINSH_FUNCTION_EXPORT(netio_init, netio server);
 #ifdef FINSH_USING_MSH
-MSH_CMD_EXPORT(netio_init, netio server);
+#include <finsh.h>
+MSH_CMD_EXPORT_ALIAS(netio_init, netio, initalise netio server);
 #endif /* FINSH_USING_MSH */
-#endif /* RT_USING_FINSH */
-#endif /* PKG_NETUTILS_NETIO */
+#endif /* LWIP_TCP */