硬汉嵌入式论坛

 找回密码
 立即注册
查看: 7689|回复: 22
收起左侧

[以太网] 两个板子之间TCP通信和UDP通信速度测试,TCP是11.1MB/S,UDP是X.XMB/S,含测试程序(2020-12-04)

  [复制链接]

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
106534
QQ
发表于 2020-12-4 15:35:26 | 显示全部楼层 |阅读模式
TCP速度测试:

H743开发板的DM9162做客户端,F407开发板的DM9162做服务器,两个板子直连,H743发送数据给F407(H743的收发性能基本都可以满速,而F407接收性能满速,发送略差点)。
666.png

备份下程序。
H743客户端,IP地址192.168.28.240.

  1. #include "includes.h"        

  2. /*
  3. *********************************************************************************************************
  4. *                                          用于本文件的调试
  5. *********************************************************************************************************
  6. */
  7. #if 1
  8.         #define printf_debug printf
  9. #else
  10.         #define printf_debug(...)
  11. #endif


  12. /*
  13. *********************************************************************************************************
  14. *                                  宏定义,远程服务器的IP和端口
  15. *********************************************************************************************************
  16. */
  17. /* 要访问的远程服务器IP和端口配置,也就是电脑端调试助手设置的IP和端口号 */
  18. #define IP1            192
  19. #define IP2            168
  20. #define IP3            28
  21. #define IP4            241

  22. #define PORT_NUM         1002


  23. /*
  24. *********************************************************************************************************
  25. *                                             变量
  26. *********************************************************************************************************
  27. */
  28. NET_ADDR4 addr = { NET_ADDR_IP4, PORT_NUM, IP1,IP2,IP3,IP4};
  29. int32_t tcp_sock;


  30. /* TCPnet API的返回值 */
  31. static const char * ReVal_Table[]=
  32. {
  33.         "netOK: Operation succeeded",
  34.         "netBusy: Process is busy",
  35.         "netError: Unspecified error",
  36.         "netInvalidParameter: Invalid parameter specified",
  37.         "netWrongState: Wrong state error",
  38.         "netDriverError: Driver error",
  39.         "netServerError: Server error",
  40.         "netAuthenticationFailed: User authentication failed",
  41.         "netDnsResolverError: DNS host resolver failed",
  42.         "netFileError: File not found or file r/w error",
  43.         "netTimeout: Operation timeout",
  44. };

  45. /*
  46. *********************************************************************************************************
  47. *        函 数 名: tcp_cb_client
  48. *        功能说明: TCP Socket的回调函数
  49. *        形    参: socket  句柄
  50. *             event   事件类型
  51. *             addr    NET_ADDR类型变量,记录IP地址,端口号。
  52. *             buf     ptr指向的缓冲区记录着接收到的TCP数据。
  53. *             len     记录接收到的数据个数。
  54. *        返 回 值:
  55. *********************************************************************************************************
  56. */
  57. uint32_t tcp_cb_client (int32_t socket, netTCP_Event event,
  58.                         const NET_ADDR *addr, const uint8_t *buf, uint32_t len)
  59. {
  60.         switch (event)
  61.         {
  62.                 /*
  63.                         远程客户端连接消息
  64.                     1、数组ptr存储远程设备的IP地址,par中存储端口号。
  65.                     2、返回数值1允许连接,返回数值0禁止连接。
  66.                 */
  67.                 case netTCP_EventConnect:
  68.                         return (1);

  69.                 /* Socket远程连接已经建立 */
  70.                 case netTCP_EventEstablished:
  71.                         printf_debug("Socket is connected to remote peer\r\n");
  72.                         break;

  73.                 /* 连接断开 */
  74.                 case netTCP_EventClosed:
  75.                         printf_debug("Connection has been closed\r\n");
  76.                         break;

  77.                 /* 连接终止 */
  78.                 case netTCP_EventAborted:
  79.                         break;

  80.                 /* 发送的数据收到远程设备应答 */
  81.                 case netTCP_EventACK:
  82. //                        printf("----%d\r\n", osKernelGetTickCount ());
  83.                         break;

  84.                 /* 接收到TCP数据帧,ptr指向数据地址,par记录数据长度,单位字节 */
  85.                 case netTCP_EventData:
  86.                         //printf_debug("Data length = %d\r\n", len);
  87.                         //printf ("%.*s\r\n",len, buf);
  88.                         break;
  89.         }
  90.         return (0);
  91. }

  92. /*
  93. *********************************************************************************************************
  94. *        函 数 名: TCPnetTest
  95. *        功能说明: TCPnet应用
  96. *        形    参: 无
  97. *        返 回 值: 无
  98. *********************************************************************************************************
  99. */   
  100. void DM9162TCPnetTest(void)
  101. {
  102.         int32_t iCount;
  103.         uint8_t *sendbuf;
  104.         uint32_t maxlen;
  105.         netStatus res;
  106.         const uint16_t usMaxBlockTime = 2; /* 延迟周期 */
  107.         uint32_t EvtFlag;
  108.     uint32_t t1, t2;

  109.         tcp_sock = netTCP_GetSocket (tcp_cb_client);
  110.         
  111.         if (tcp_sock > 0)
  112.         {
  113.                 /* 使能TCP_TYPE_KEEP_ALIVE,会一直保持连接 */
  114.                 netTCP_SetOption (tcp_sock, netTCP_OptionKeepAlive, 1);        

  115.         res = netTCP_Connect (tcp_sock, (NET_ADDR *)&addr, 0);
  116.         printf_debug("%s\r\n", ReVal_Table[res]);      
  117.         }
  118.    

  119.         while (1)
  120.         {
  121.                 EvtFlag = osThreadFlagsWait(0x0000000FU, osFlagsWaitAny, usMaxBlockTime);
  122.                
  123.                 /* 按键消息的处理 */
  124.                 switch (EvtFlag)
  125.                 {
  126.                         /* 接收到K1键按下,给远程TCP客户端发送8字节数据 */
  127.                         case KEY1_BIT0:               
  128.                 t1 = osKernelGetTickCount ();
  129.                 printf("------%d\r\n", t1);
  130.                                 iCount = 100*1024*1024;
  131.                                 if(netTCP_GetState(tcp_sock) == netTCP_StateESTABLISHED)
  132.                                 {
  133.                                         do
  134.                                         {
  135.                                                 if(netTCP_SendReady(tcp_sock) == true )
  136.                                                 {
  137.                                                         maxlen  = netTCP_GetMaxSegmentSize (tcp_sock);

  138.                                                         iCount -= maxlen;
  139.                                                         
  140.                                                         if(iCount < 0)
  141.                                                         {
  142.                                                                 /* 这么计算没问题的 */
  143.                                                                 maxlen = iCount + maxlen;
  144.                                                         }
  145.                                                         
  146.                                                         sendbuf = netTCP_GetBuffer (maxlen);
  147.                                                         
  148.                                                         /* 必须使用申请的内存空间 */
  149.                                                         netTCP_Send (tcp_sock, sendbuf, maxlen);
  150.                                                 }
  151.                                                 
  152.                                         }while(iCount > 0);
  153.                                 }
  154.                 t2 = osKernelGetTickCount ();
  155.                 printf("测试速度 = %4.1fMB/S\r\n", (float)(100.0*1024*1024)/(t2-t1) * 1000/1024/1024);
  156.                                 break;
  157.                                 
  158.                          /* 其他的键值不处理 */
  159.                         default:                     
  160.                                 break;
  161.                 }
  162.         }
  163. }
复制代码


F407服务器,IP地址192.168.28.241

  1. #include "includes.h"        



  2. /*
  3. *********************************************************************************************************
  4. *                                          用于本文件的调试
  5. *********************************************************************************************************
  6. */
  7. #if 1
  8.         #define printf_debug printf
  9. #else
  10.         #define printf_debug(...)
  11. #endif


  12. /*
  13. *********************************************************************************************************
  14. *                                          宏定义
  15. *********************************************************************************************************
  16. */
  17. #define PORT_NUM       1002     /* TCP服务器监听端口号 */


  18. /*
  19. *********************************************************************************************************
  20. *                                             变量
  21. *********************************************************************************************************
  22. */
  23. static int32_t tcp_sock;

  24. /* TCPnet API的返回值 */
  25. static const char * ReVal_Table[]=
  26. {
  27.         "netOK: Operation succeeded",
  28.         "netBusy: Process is busy",
  29.         "netError: Unspecified error",
  30.         "netInvalidParameter: Invalid parameter specified",
  31.         "netWrongState: Wrong state error",
  32.         "netDriverError: Driver error",
  33.         "netServerError: Server error",
  34.         "netAuthenticationFailed: User authentication failed",
  35.         "netDnsResolverError: DNS host resolver failed",
  36.         "netFileError: File not found or file r/w error",
  37.         "netTimeout: Operation timeout",
  38. };

  39. /*
  40. *********************************************************************************************************
  41. *        函 数 名: tcp_cb_server
  42. *        功能说明: TCP Socket的回调函数
  43. *        形    参: socket  句柄
  44. *             event   事件类型
  45. *             addr    NET_ADDR类型变量,记录IP地址,端口号。
  46. *             buf     ptr指向的缓冲区记录着接收到的TCP数据。
  47. *             len     记录接收到的数据个数。
  48. *        返 回 值:
  49. *********************************************************************************************************
  50. */
  51. static uint32_t tcp_cb_server (int32_t socket, netTCP_Event event,
  52.                                const NET_ADDR *addr, const uint8_t *buf, uint32_t len)
  53. {
  54.         switch (event)
  55.         {
  56.                 /*
  57.                         远程客户端连接消息
  58.                     1、数组ptr存储远程设备的IP地址,par中存储端口号。
  59.                     2、返回数值1允许连接,返回数值0禁止连接。
  60.                 */
  61.                 case netTCP_EventConnect:
  62.                         if (addr->addr_type == NET_ADDR_IP4)
  63.                         {
  64.                                 printf_debug("DM9000远程客户端请求连接IP: %d.%d.%d.%d  端口号:%d\r\n",
  65.                                                                         addr->addr[0],
  66.                                                                         addr->addr[1],
  67.                                                                         addr->addr[2],
  68.                                                                         addr->addr[3],                 
  69.                                                                         addr->port);
  70.                                 return (1);
  71.                         }
  72.                         else if (addr->addr_type == NET_ADDR_IP6)  
  73.                         {
  74.                                 return (1);
  75.                         }
  76.                         
  77.                         return(0);

  78.                 /* Socket远程连接已经建立 */
  79.                 case netTCP_EventEstablished:
  80.                         printf_debug("DM9000 Socket is connected to remote peer\r\n");
  81.                         break;

  82.                 /* 连接断开 */
  83.                 case netTCP_EventClosed:
  84.                         printf_debug("DM9000 Connection has been closed\r\n");
  85.                         break;

  86.                 /* 连接终止 */
  87.                 case netTCP_EventAborted:
  88.                         break;

  89.                 /* 发送的数据收到远程设备应答 */
  90.                 case netTCP_EventACK:
  91.                         break;

  92.                 /* 接收到TCP数据帧,ptr指向数据地址,par记录数据长度,单位字节 */
  93.                 case netTCP_EventData:
  94.                         //printf_debug("DM9000 Data length = %d\r\n", len);
  95.                         //printf ("%.*s\r\n",len, buf);
  96.                         break;
  97.         }
  98.         return (0);
  99. }

  100. /*
  101. *********************************************************************************************************
  102. *        函 数 名: DM9000TCPnetTest
  103. *        功能说明: DM9000TCPnetTest应用
  104. *        形    参: 无
  105. *        返 回 值: 无
  106. *********************************************************************************************************
  107. */   
  108. void DM9162TCPnetTest(void)
  109. {
  110.         int32_t iCount;
  111.         uint8_t *sendbuf;
  112.         uint32_t maxlen;
  113.         netStatus res;
  114.         const uint16_t usMaxBlockTime = 2; /* 延迟周期 */
  115.         uint32_t EvtFlag;
  116.     uint32_t t1, t2;
  117.         
  118.         tcp_sock = netTCP_GetSocket (tcp_cb_server);
  119.         
  120.         if (tcp_sock > 0)
  121.         {
  122.                 res = netTCP_Listen (tcp_sock, PORT_NUM);
  123.                 printf_debug("DM9000 tcp listen res = %s\r\n", ReVal_Table[res]);
  124.         }
  125.         
  126.         while (1)
  127.         {
  128.                 EvtFlag = osThreadFlagsWait(0x00000007U, osFlagsWaitAny, usMaxBlockTime);
  129.                
  130.                 /* 按键消息的处理 */
  131.                 if(netTCP_GetState(tcp_sock) == netTCP_StateESTABLISHED)
  132.                 {
  133.                         switch (EvtFlag)
  134.                         {
  135.                 /* 接收到K1键按下,给远程TCP客户端发送8字节数据 */
  136.                 case KEY1_BIT0:               
  137.                     t1 = osKernelGetTickCount ();
  138.                     printf("------%d\r\n", t1);
  139.                     iCount = 100*1024*1024;
  140.                     if(netTCP_GetState(tcp_sock) == netTCP_StateESTABLISHED)
  141.                     {
  142.                         do
  143.                         {
  144.                             if(netTCP_SendReady(tcp_sock) == true )
  145.                             {
  146.                                 maxlen  = netTCP_GetMaxSegmentSize (tcp_sock);

  147.                                 iCount -= maxlen;
  148.                                 
  149.                                 if(iCount < 0)
  150.                                 {
  151.                                     /* 这么计算没问题的 */
  152.                                     maxlen = iCount + maxlen;
  153.                                 }
  154.                                 
  155.                                 sendbuf = netTCP_GetBuffer (maxlen);
  156.                                 
  157.                                 /* 必须使用申请的内存空间 */
  158.                                 netTCP_Send (tcp_sock, sendbuf, maxlen);
  159.                             }
  160.                            
  161.                         }while(iCount > 0);
  162.                     }
  163.                     t2 = osKernelGetTickCount ();
  164.                     printf("测试速度 = %4.1fMB/S\r\n", (float)(100.0*1024*1024)/(t2-t1) * 1000/1024/1024);
  165.                     break;

  166.                                  /* 其他的键值不处理 */
  167.                                 default:                     
  168.                                         break;
  169.                         }
  170.                 }
  171.         }
  172. }
复制代码




评分

参与人数 2金币 +21 收起 理由
ahu5 + 1
jxgzlym + 20 赞一个!

查看全部评分

回复

使用道具 举报

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
106534
QQ
 楼主| 发表于 2020-12-4 16:40:41 | 显示全部楼层
UDP速度测试(测试错误)。

测试条件和TCP是一样的:

备份测试程序。UDP不分主从,给IP地址和端口号就可以发送。

7.png

H743的UDP程序:

  1. #include "includes.h"        



  2. /*
  3. *********************************************************************************************************
  4. *                                          用于本文件的调试
  5. *********************************************************************************************************
  6. */
  7. #if 1
  8.         #define printf_debug printf
  9. #else
  10.         #define printf_debug(...)
  11. #endif


  12. /*
  13. *********************************************************************************************************
  14. *                                  宏定义,远程服务器的IP和端口
  15. *********************************************************************************************************
  16. */
  17. /* 要访问的远程服务器IP和端口配置,也就是电脑端调试助手设置的IP和端口号 */
  18. #define IP1            192
  19. #define IP2            168
  20. #define IP3            28
  21. #define IP4            241

  22. #define PORT_NUM       1001
  23. #define Local_NUM      1001

  24. /*
  25. *********************************************************************************************************
  26. *                                             变量
  27. *********************************************************************************************************
  28. */
  29. static NET_ADDR addr = { NET_ADDR_IP4, PORT_NUM, IP1, IP2, IP3, IP4};


  30. static int32_t udp_sock;                       // UDP socket handle

  31. /* TCPnet API的返回值 */
  32. static const char * ReVal_Table[]=
  33. {
  34.         "netOK: Operation succeeded",
  35.         "netBusy: Process is busy",
  36.         "netError: Unspecified error",
  37.         "netInvalidParameter: Invalid parameter specified",
  38.         "netWrongState: Wrong state error",
  39.         "netDriverError: Driver error",
  40.         "netServerError: Server error",
  41.         "netAuthenticationFailed: User authentication failed",
  42.         "netDnsResolverError: DNS host resolver failed",
  43.         "netFileError: File not found or file r/w error",
  44.         "netTimeout: Operation timeout",
  45. };

  46. /*
  47. *********************************************************************************************************
  48. *        函 数 名: tcp_callback
  49. *        功能说明: TCP Socket的回调函数
  50. *        形    参: socket   UDP Socket类型
  51. *             remip    远程设备的IP地址
  52. *             remport  远程设备的端口号
  53. *             buf      远程设备发来的数据地址
  54. *             len      远程设备发来的数据长度,单位字节
  55. *        返 回 值: 默认返回0即可,一般用不上
  56. *********************************************************************************************************
  57. */
  58. static uint32_t udp_cb_func (int32_t socket, const NET_ADDR *addr, const uint8_t *buf, uint32_t len)
  59. {
  60. //        char buffer[50];
  61. //        uint16_t i = 0;

  62. //        /* 确保是udp_soc的回调 */
  63. //        if (socket != udp_sock)
  64. //        {
  65. //                return (0);
  66. //        }

  67. //        /* 发消息的远程IP,打印IP和端口号 */
  68. //        sprintf(buffer, "远程连接IP: %d.%d.%d.%d", addr->addr[0], addr->addr[1], addr->addr[2], addr->addr[3]);
  69. //        printf_debug("%s  port:%d\r\n", buffer, addr->port);

  70. //        /* 接收到的数据长度,单位字节 */
  71. //        printf_debug("Data length = %d\r\n", len);
  72. //        /* 打印接收到的消息 */
  73. //        for(i = 0; i < len; i++)
  74. //        {
  75. //                printf_debug("buf[%d] = %d\r\n", i, buf[i]);
  76. //        }

  77.         return (0);
  78. }

  79. /*
  80. *********************************************************************************************************
  81. *        函 数 名: DM9162TCPnetTest
  82. *        功能说明: DM9162TCPnetTest应用
  83. *        形    参: 无
  84. *        返 回 值: 无
  85. *********************************************************************************************************
  86. */   
  87. void DM9162TCPnetTest(void)
  88. {
  89.         int32_t iCount;
  90.         uint8_t *sendbuf;
  91.         netStatus res;
  92.         const uint16_t usMaxBlockTime = 2; /* 延迟周期 */
  93.         uint32_t EvtFlag;
  94.     uint32_t t1, t2;
  95.         
  96.     udp_sock = netUDP_GetSocket (udp_cb_func);
  97.    
  98.     if (udp_sock >= 0)
  99.     {
  100.         netUDP_Open (udp_sock, Local_NUM);
  101.         //netUDP_SetOption (udp_sock, netUDP_OptionInterface, NET_IF_CLASS_ETH | 0);
  102.     }
  103.         while (1)
  104.         {
  105.                 EvtFlag = osThreadFlagsWait(0x00000007U, osFlagsWaitAny, usMaxBlockTime);
  106.                
  107.                         switch (EvtFlag)
  108.                         {
  109.                                 /* 接收到K1键按下,给远程TCP客户端发送数据 */
  110.                                 case KEY1_BIT0:        
  111.                                         iCount = 50*1024;
  112.                     t1 = osKernelGetTickCount ();
  113.                     printf("------%d\r\n", t1);
  114.                                         do
  115.                                         {
  116.                                                 /* 申请8字节的空间 */
  117.                                                 sendbuf =  netUDP_GetBuffer(2000);
  118.                                        
  119.                                                 if(sendbuf != NULL)
  120.                                                 {
  121. //                                                        /* 初始化8个字节变量 */
  122. //                                                        sendbuf[0] = '1';
  123. //                                                        sendbuf[1] = '2';
  124. //                                                        sendbuf[2] = '3';
  125. //                                                        sendbuf[3] = '4';
  126. //                                                        sendbuf[4] = '5';
  127. //                                                        sendbuf[5] = '6';
  128. //                                                        sendbuf[6] = '7';
  129. //                                                        sendbuf[7] = '8';
  130.                                                         res = netUDP_Send(udp_sock, &addr, sendbuf, 2000);

  131.                                                         /* 保证发送成功了发送次数才可以减一,这里发送成功并不保证远程设备接受成功 */
  132.                                                         if(res == netOK)
  133.                                                         {
  134.                                                                 iCount--;
  135.                                                         }
  136.                             else
  137.                             {
  138.                                 printf("发送失败%s\r\n", ReVal_Table[res]);
  139.                             }
  140.                                                         //osDelay(50);
  141.                                                 }

  142.                                         }while(iCount > 0);
  143.                     t2 = osKernelGetTickCount ();
  144.                     printf("测试速度 = %4.1fMB/S\r\n", (float)(50.0*1024*2000)/(t2-t1) * 1000/1024/1024);
  145.                                         break;

  146.                                  /* 其他的键值不处理 */
  147.                                 default:                     
  148.                                         break;
  149.                 }
  150.         }
  151. }
复制代码



F407的UDP程序:

  1. #include "includes.h"        



  2. /*
  3. *********************************************************************************************************
  4. *                                          用于本文件的调试
  5. *********************************************************************************************************
  6. */
  7. #if 1
  8.         #define printf_debug printf
  9. #else
  10.         #define printf_debug(...)
  11. #endif


  12. /*
  13. *********************************************************************************************************
  14. *                                  宏定义,远程服务器的IP和端口
  15. *********************************************************************************************************
  16. */
  17. /* 要访问的远程服务器IP和端口配置,也就是电脑端调试助手设置的IP和端口号 */
  18. #define IP1            192
  19. #define IP2            168
  20. #define IP3            28
  21. #define IP4            240

  22. #define PORT_NUM       1001

  23. #define Local_NUM      1001

  24. /*
  25. *********************************************************************************************************
  26. *                                             变量
  27. *********************************************************************************************************
  28. */
  29. static NET_ADDR addr = { NET_ADDR_IP4, PORT_NUM, IP1, IP2, IP3, IP4};


  30. static int32_t udp_sock;                       // UDP socket handle

  31. /* TCPnet API的返回值 */
  32. static const char * ReVal_Table[]=
  33. {
  34.         "netOK: Operation succeeded",
  35.         "netBusy: Process is busy",
  36.         "netError: Unspecified error",
  37.         "netInvalidParameter: Invalid parameter specified",
  38.         "netWrongState: Wrong state error",
  39.         "netDriverError: Driver error",
  40.         "netServerError: Server error",
  41.         "netAuthenticationFailed: User authentication failed",
  42.         "netDnsResolverError: DNS host resolver failed",
  43.         "netFileError: File not found or file r/w error",
  44.         "netTimeout: Operation timeout",
  45. };

  46. /*
  47. *********************************************************************************************************
  48. *        函 数 名: tcp_callback
  49. *        功能说明: TCP Socket的回调函数
  50. *        形    参: socket   UDP Socket类型
  51. *             remip    远程设备的IP地址
  52. *             remport  远程设备的端口号
  53. *             buf      远程设备发来的数据地址
  54. *             len      远程设备发来的数据长度,单位字节
  55. *        返 回 值: 默认返回0即可,一般用不上
  56. *********************************************************************************************************
  57. */
  58. static uint32_t udp_cb_func (int32_t socket, const NET_ADDR *addr, const uint8_t *buf, uint32_t len)
  59. {
  60. //        char buffer[50];
  61. //        uint16_t i = 0;

  62. //        /* 确保是udp_soc的回调 */
  63. //        if (socket != udp_sock)
  64. //        {
  65. //                return (0);
  66. //        }

  67. //        /* 发消息的远程IP,打印IP和端口号 */
  68. //        sprintf(buffer, "远程连接IP: %d.%d.%d.%d", addr->addr[0], addr->addr[1], addr->addr[2], addr->addr[3]);
  69. //        printf_debug("%s  port:%d\r\n", buffer, addr->port);

  70. //        /* 接收到的数据长度,单位字节 */
  71. //        printf_debug("Data length = %d\r\n", len);
  72. //        /* 打印接收到的消息 */
  73. //        for(i = 0; i < len; i++)
  74. //        {
  75. //                printf_debug("buf[%d] = %d\r\n", i, buf[i]);
  76. //        }

  77.         return (0);
  78. }

  79. /*
  80. *********************************************************************************************************
  81. *        函 数 名: DM9162TCPnetTest
  82. *        功能说明: DM9162TCPnetTest应用
  83. *        形    参: 无
  84. *        返 回 值: 无
  85. *********************************************************************************************************
  86. */   
  87. void DM9162TCPnetTest(void)
  88. {
  89.         int32_t iCount;
  90.         uint8_t *sendbuf;
  91.         netStatus res;
  92.         const uint16_t usMaxBlockTime = 2; /* 延迟周期 */
  93.         uint32_t EvtFlag;
  94.     uint32_t t1, t2;
  95.         
  96.     udp_sock = netUDP_GetSocket (udp_cb_func);
  97.    
  98.     if (udp_sock >= 0)
  99.     {
  100.         netUDP_Open (udp_sock, Local_NUM);
  101.         //netUDP_SetOption (udp_sock, netUDP_OptionInterface, NET_IF_CLASS_ETH | 0);
  102.     }
  103.         while (1)
  104.         {
  105.                 EvtFlag = osThreadFlagsWait(0x00000007U, osFlagsWaitAny, usMaxBlockTime);
  106.                
  107.                         switch (EvtFlag)
  108.                         {
  109.                                 /* 接收到K1键按下,给远程TCP客户端发送数据 */
  110.                                 case KEY1_BIT0:        
  111.                                         iCount = 50*1024;
  112.                     t1 = osKernelGetTickCount ();
  113.                     printf("------%d\r\n", t1);
  114.                                         do
  115.                                         {
  116.                                                 /* 申请8字节的空间 */
  117.                                                 sendbuf =  netUDP_GetBuffer(2000);
  118.                                        
  119.                                                 if(sendbuf != NULL)
  120.                                                 {
  121. //                                                        /* 初始化8个字节变量 */
  122. //                                                        sendbuf[0] = '1';
  123. //                                                        sendbuf[1] = '2';
  124. //                                                        sendbuf[2] = '3';
  125. //                                                        sendbuf[3] = '4';
  126. //                                                        sendbuf[4] = '5';
  127. //                                                        sendbuf[5] = '6';
  128. //                                                        sendbuf[6] = '7';
  129. //                                                        sendbuf[7] = '8';
  130.                                                         res = netUDP_Send(udp_sock, &addr, sendbuf, 2000);

  131.                                                         /* 保证发送成功了发送次数才可以减一,这里发送成功并不保证远程设备接受成功 */
  132.                                                         if(res == netOK)
  133.                                                         {
  134.                                                                 iCount--;
  135.                                                         }
  136.                             else
  137.                             {
  138.                                 printf("发送失败%s\r\n", ReVal_Table[res]);
  139.                             }
  140.                                                         //osDelay(50);
  141.                                                 }

  142.                                         }while(iCount > 0);
  143.                     t2 = osKernelGetTickCount ();
  144.                     printf("测试速度 = %4.1fMB/S\r\n", (float)(50.0*1024*2000)/(t2-t1) * 1000/1024/1024);
  145.                                         break;

  146.                                  /* 其他的键值不处理 */
  147.                                 default:                     
  148.                                         break;
  149.                 }
  150.         }
  151. }
复制代码
回复

使用道具 举报

3

主题

1220

回帖

1229

积分

至尊会员

积分
1229
发表于 2020-12-4 15:53:39 | 显示全部楼层
回复

使用道具 举报

0

主题

17

回帖

17

积分

新手上路

积分
17
发表于 2020-12-4 16:57:58 | 显示全部楼层
UDP比TCP还慢?
回复

使用道具 举报

0

主题

213

回帖

213

积分

高级会员

积分
213
发表于 2020-12-4 17:07:38 | 显示全部楼层
按说应该是UDP速度更快才对。起码不应该比TCP慢这么多
回复

使用道具 举报

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
106534
QQ
 楼主| 发表于 2020-12-4 17:48:14 | 显示全部楼层

估计是哪里的玩法不对,不测了,有时间换个姿势测测。
回复

使用道具 举报

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
106534
QQ
 楼主| 发表于 2020-12-4 17:48:22 | 显示全部楼层
regbbs 发表于 2020-12-4 17:07
按说应该是UDP速度更快才对。起码不应该比TCP慢这么多

估计是哪里的玩法不对,不测了,有时间换个姿势测测。
回复

使用道具 举报

4

主题

139

回帖

151

积分

初级会员

积分
151
QQ
发表于 2020-12-4 17:52:31 | 显示全部楼层
我用的wifi,不是以太网,测试udp比tcp快多了
按理说tcp不应该比udp快啊,而且快那么多
回复

使用道具 举报

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
106534
QQ
 楼主| 发表于 2020-12-4 18:03:45 | 显示全部楼层
qgyhd1234 发表于 2020-12-4 17:52
我用的wifi,不是以太网,测试udp比tcp快多了
按理说tcp不应该比udp快啊,而且快那么多
我们常用的那些wifi,速度略低,参考价值不高。

正常的情况下TCP就是可以满速。

而UDP就不行,板子给电脑发,不做握手,1MB/S都上不了,丢包非常厉害。而电脑给板子发,能有个2-3MB/S。
回复

使用道具 举报

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
106534
QQ
 楼主| 发表于 2020-12-4 19:14:48 | 显示全部楼层

确实测试错了,netUDP_GetBuffer最大可以支持64KB缓冲获取,我测试的是2K。。。
回复

使用道具 举报

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
106534
QQ
 楼主| 发表于 2020-12-4 19:14:54 | 显示全部楼层
qgyhd1234 发表于 2020-12-4 17:52
我用的wifi,不是以太网,测试udp比tcp快多了
按理说tcp不应该比udp快啊,而且快那么多

确实测试错了,netUDP_GetBuffer最大可以支持64KB缓冲获取,我测试的是2K。。。
回复

使用道具 举报

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
106534
QQ
 楼主| 发表于 2020-12-4 19:15:01 | 显示全部楼层
regbbs 发表于 2020-12-4 17:07
按说应该是UDP速度更快才对。起码不应该比TCP慢这么多

确实测试错了,netUDP_GetBuffer最大可以支持64KB缓冲获取,我测试的是2K。。。
回复

使用道具 举报

1

主题

22

回帖

25

积分

新手上路

积分
25
发表于 2021-4-27 19:26:07 | 显示全部楼层
硬漢哥,請教該两个板子之间TCP通信和UDP通信速度测试,有範例有釋出嗎? 有兩片V7 開發板,也要來試試該架構的。
回复

使用道具 举报

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
106534
QQ
 楼主| 发表于 2021-4-28 07:50:56 | 显示全部楼层
James2jian 发表于 2021-4-27 19:26
硬漢哥,請教該两个板子之间TCP通信和UDP通信速度测试,有範例有釋出嗎? 有兩片V7 開發板,也要來試試該架 ...

跑这个双网口的例子,注意,要两个板子设置不同的MAC,IP地址设置同一个网段,但不同IP

V7,V6,V5开发板RL-TCPnet V7.X双网口教程发布,单网络协议栈管理DM9000和DM9162(2020-11-30)
http://www.armbbs.cn/forum.php?m ... 0233&fromuid=58
(出处: 硬汉嵌入式论坛)
回复

使用道具 举报

1

主题

22

回帖

25

积分

新手上路

积分
25
发表于 2021-4-28 09:46:24 | 显示全部楼层
eric2013 发表于 2021-4-28 07:50
跑这个双网口的例子,注意,要两个板子设置不同的MAC,IP地址设置同一个网段,但不同IP

V7,V6,V5开 ...

感謝回覆再請教2個點:
1.兩片 V7 開發板子間的網路 RJ-45 有需要考慮跳線(RJ45: EIA/TIA-568B A種接線,B種接線)議題嗎?
  開發板附的黃色RJ-45 即可對連是唄。
2.兩片 V7 開發板,使用TCP Client /Server 相互連接ˊ有類似 PC 的 CMD "PING 192.168.XX.XX "的工具嗎?
   還是採用UART 進行DEBUG? 對應的指令要去何處查詢呢?
   
回复

使用道具 举报

6

主题

42

回帖

60

积分

初级会员

积分
60
发表于 2022-5-26 11:37:32 | 显示全部楼层
不会吧, udp速度比tcp低那么多?udp不是传输大规模大容量数据的传输协议吗? 怎么搞得只有 tcp的一半多一点
回复

使用道具 举报

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
106534
QQ
 楼主| 发表于 2022-5-26 11:53:13 | 显示全部楼层
中尴人 发表于 2022-5-26 11:37
不会吧, udp速度比tcp低那么多?udp不是传输大规模大容量数据的传输协议吗? 怎么搞得只有 tcp的一半多一 ...

测试方法问题。

像使用串口一样使用以太网,STM32H7的原始以太网数据包收发速度11.9MB/S,实用价值也很高(2020-12-05)
https://www.armbbs.cn/forum.php? ... 1966&fromuid=58
(出处: 硬汉嵌入式论坛)
回复

使用道具 举报

6

主题

42

回帖

60

积分

初级会员

积分
60
发表于 2022-5-31 16:15:13 | 显示全部楼层
为什么  H743 和 F407 代码不同啊? 要分开?
这个程序 两款MCU不能通用吗?
回复

使用道具 举报

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
106534
QQ
 楼主| 发表于 2022-5-31 17:08:16 | 显示全部楼层
中尴人 发表于 2022-5-31 16:15
为什么  H743 和 F407 代码不同啊? 要分开?
这个程序 两款MCU不能通用吗?

通用743没有代表性,

两个不一样的测试才有代表性。
回复

使用道具 举报

0

主题

1

回帖

1

积分

新手上路

积分
1
发表于 2022-6-21 12:25:38 | 显示全部楼层
楼主,我把两个电脑直接用网线链接网口,互相ping可以通,为什么udp通讯会报错bind失败呢?错误是10049无法分配请求的地址
回复

使用道具 举报

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
106534
QQ
 楼主| 发表于 2022-6-22 00:50:02 | 显示全部楼层
努力学习的小申 发表于 2022-6-21 12:25
楼主,我把两个电脑直接用网线链接网口,互相ping可以通,为什么udp通讯会报错bind失败呢?错误是10049无法 ...

两个都整个网络助手测试下,保证网络环境没问题。
回复

使用道具 举报

4

主题

166

回帖

178

积分

初级会员

积分
178
发表于 2023-2-17 10:49:42 | 显示全部楼层
tltcp的组播如何设置呢
回复

使用道具 举报

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
106534
QQ
 楼主| 发表于 2023-2-17 14:33:13 | 显示全部楼层
yuanzhongda 发表于 2023-2-17 10:49
tltcp的组播如何设置呢

image.png
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|Archiver|手机版|硬汉嵌入式论坛

GMT+8, 2024-4-24 07:11 , Processed in 0.248413 second(s), 31 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表