標題: STM32 LwIP用TCP連接方式在數(shù)據(jù)量比較大協(xié)議棧(4k緩沖區(qū)調(diào)試通過) [打印本頁]

作者: 向涵    時間: 2018-12-11 15:49
標題: STM32 LwIP用TCP連接方式在數(shù)據(jù)量比較大協(xié)議棧(4k緩沖區(qū)調(diào)試通過)


這段時間用STM32移植LwIP做語音傳輸。但是遇到一個問題困擾許久,在使用TCP方式做一個client去連接server,由于數(shù)據(jù)量比較大經(jīng)常在連接一個多小時候就出現(xiàn)斷線而

也ping不通。接下來我們看一下這個問題是怎么出現(xiàn)的和他的決絕方法(小白一枚,說錯的地方還望指正哈 。。。。共同學(xué)習(xí) 。嘻嘻 ^_^  )。

額,還沒有學(xué)操作系統(tǒng),還生活在裸奔的年代。。。 client和server采用LwIP的Raw函數(shù)編寫。連接過程采用短連接,即發(fā)送一次數(shù)據(jù)就請求斷開。

我們先看一個client端的程序。

/**************************************/
以太網(wǎng)實驗,步驟

///
1.把M3接入路由。

///
2.ping實驗。在接入相同路由的PC中,運行CMD,輸入命令: ping 192.168.1.18
  看是否能ping通,只有ping通后才能進行后續(xù)的實驗。

*********ping通的實驗現(xiàn)象如下(時間可能稍有區(qū)別)***********


    C:\Documents and Settings\>ping 192.168.1.18
   
    Pinging 192.168.1.18 with 32 bytes of data:
   
    Reply from 192.168.1.18: bytes=32 time=1ms TTL=255
    Reply from 192.168.1.18: bytes=32 time=2ms TTL=255
    Reply from 192.168.1.18: bytes=32 time<1ms TTL=255
    Reply from 192.168.1.18: bytes=32 time=1ms TTL=255
   
    Ping statistics for 192.168.1.18:
        Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
    Approximate round trip times in milli-seconds:
        Minimum = 0ms, Maximum = 2ms, Average = 1ms

******************************************************************
    若不能ping通,可能是路由的限制:
      可嘗試把M3與PC直接用網(wǎng)線相連, 再 ping 192.168.1.18  ,
    如果還不通,排除網(wǎng)線及接觸問題后,可能是代碼被修改或板子故障。

///
3.telnet實驗。ping通后,輸入命令: telnet 192.168.1.18

使用用戶名:wildfire 密碼:123456  登錄。
登錄成功后可選兩條指令:LED1_ON 和 LED1_OFF 用于遠程控制。

***************正常實驗現(xiàn)象如下****************************************
屏幕輸出        Please enter your username:

鍵盤輸入        wildfire

屏幕輸出        Please enter your password:

鍵盤輸入        123456

屏幕輸出        Please enter command:

鍵盤輸入        LED1_ON
        
屏幕輸出         Success,LED1 status is ON!
        
屏幕輸出        Please enter command:

鍵盤輸入        LED1_OFF
        
屏幕輸出         Success,LED1 status is OFF!
        
屏幕輸出        Please enter command:


************輸入命令LED1_ON后,板上的LED1會點亮,輸入LED1_OFF后,LED1熄滅****************
(win7系統(tǒng)沒有telnet,需要在網(wǎng)上下載該程序進行實驗)



////
4.瀏覽器實驗。打開瀏覽器,在地址欄輸入 http://192.168.1.18
  
  連接成功后,可看到登錄界面。輸入:
*****************************************************  
用戶名:wildfire
密碼  :123456
*****************************************************
登錄成功后,可點擊LED控制界面對M3板上的LED1進行控制。
(如果不是原版代碼,該網(wǎng)頁上的野火旗艦店網(wǎng)址鏈接可能會被惡意篡改。)

單片機源程序如下:
  1. /**
  2.   ******************************************************************************
  3.   * @file    main.c
  4.   * @author  fire
  5.   * @version V1.0
  6.   * @date    2013-xx-xx
  7.   * @brief   enc28j60+lwip測試,具體測試步驟參考工程里面的文件readme.txt

  8.   */

  9. /* Includes ------------------------------------------------------------------*/
  10. #include <stdio.h>
  11. #include "stm32f10x.h"
  12. #include "stm32f10x_usart.h"

  13. #include "err.h"
  14. #include "etharp.h"
  15.         
  16. #include "netconfig.h"
  17. #include "bsp_usart1.h"
  18. #include "bsp_SysTick.h"
  19. #include "spi.h"
  20. #include "bsp_led.h"

  21. #include "cmd.h"
  22. #include "httpd.h"


  23. #include "DAC.h"
  24. #include "TIM2delay.h"
  25. #include "edcode.h"
  26. #include "ADPCM.h"
  27. #include "ADC.h"

  28. /*****************************************************************************************************************************/




  29. __IO uint32_t LocalTime = 0;
  30. /* this variable is used to create a time reference incremented by 10ms */
  31.         
  32. /*
  33. * 函數(shù)名:main
  34. * 描述  :主函數(shù)
  35. * 輸入  :無
  36. * 輸出  : 無
  37. * 調(diào)用  :
  38. */
  39. int main(void)
  40. {
  41.         /*初始化串口*/
  42.   USART1_Config();         

  43.         /*初始化 以太網(wǎng)SPI接口*/
  44.         ENC_SPI_Init();                 

  45.         /*初始化systick,用于定時輪詢輸入或給LWIP提供定時*/
  46.         SysTick_Init();               

  47.     ADC1_Init();//ADC 初始化 采用DMA方式
  48.          
  49.         printf("\r\n************************\r\n");
  50.          
  51.           /* 初始化LWIP協(xié)議棧*/
  52.         LwIP_Init(); //192.168.1.18

  53.         /*初始化web server 顯示網(wǎng)頁程序*/
  54.         httpd_init();


  55.         DAC_init(); //DAC初始化
  56.         

  57.         
  58.         timer_init(32);//定時器初始化 開始播放

  59.   /* Infinite loop */  
  60.     while ( 1 )
  61.     {        
  62.         /*輪詢*/  
  63.         LwIP_Periodic_Handle(LocalTime);

  64.         decoding( );  //解碼
  65.         
  66.         encoding( );
  67.         

  68.         
  69.      
  70.     }
  71. }
復(fù)制代碼

所有資料51hei提供下載:
LwIP client server.7z (630.54 KB, 下載次數(shù): 60)







歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1