久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 6499|回復: 2
打印 上一主題 下一主題
收起左側

stm32通過w5500使用dns解讀IP地址 源程序

[復制鏈接]
跳轉到指定樓層
樓主
stm32通過w5500使用dns解讀IP地址的源程序:

完整源碼下載:
stm32_w5500_dns.zip (779.32 KB, 下載次數: 85)





源程序預覽(主程序):
  1. /**
  2.   ******************************************************************************
  3.   * @file    main.c
  4.   * $Author: 飛鴻踏雪 $
  5.   * $Revision: 17 $
  6.   * $Date:: 2014-10-25 11:16:48 +0800 #$
  7.   * @brief   主函數.
  8.   ******************************************************************************
  9.   * @attention
  10.   *
  11.   *
  12.   ******************************************************************************
  13.   */
  14. /* Includes ------------------------------------------------------------------*/
  15. #include "main.h"
  16. #include "usart.h"
  17. #include "delay.h"
  18. #include "spi.h"
  19. #include "socket.h"        // Just include one header for WIZCHIP
  20. #include "Internet/DNS/dns.h"
  21. /* Private typedef -----------------------------------------------------------*/
  22. /* Private define ------------------------------------------------------------*/
  23. #define _MAIN_DEBUG_
  24. #define SOCK_DNS                        0
  25. #define DATA_BUF_SIZE   2048
  26. /* Private macro -------------------------------------------------------------*/
  27. uint8_t gDATABUF[DATA_BUF_SIZE];
  28. // Default Network Configuration
  29. wiz_NetInfo gWIZNETINFO = { .mac = {0x00, 0x08, 0xdc,0x00, 0xab, 0xcd},
  30.                             .ip = {192, 168, 1, 123},
  31.                             .sn = {255,255,255,0},
  32.                             .gw = {192, 168, 1, 1},
  33.                             .dns = {8,8,8,8},
  34.                             .dhcp = NETINFO_STATIC };
  35. uint8_t DNS_2nd[4]    = {192, 168, 1, 1};                // Secondary DNS server IP
  36. uint8_t Domain_name[] = "www點embed-net點com";                // for Example domain name
  37. uint8_t Domain_IP[4]  = {0};                                        // Translated IP address by DNS
  38. volatile uint32_t msTicks; /* counts 100ms timeTicks */
  39. /* Private variables ---------------------------------------------------------*/
  40. /* Private function prototypes -----------------------------------------------*/
  41. /* Private functions ---------------------------------------------------------*/
  42. void platform_init(void);                                                                // initialize the dependent host peripheral
  43. void network_init(void);

  44. /*****************************************************************************
  45. * @brief SysTickIntHandler
  46. * Interrupt Service Routine for system tick counter
  47. *****************************************************************************/
  48. void SysTick_Handler(void)
  49. {
  50.         msTicks++; /* increment counter necessary in Delay()*/
  51.         // SHOULD BE Added DNS Timer Handler your 1s tick timer
  52.         if((msTicks % 1000) == 0){
  53.                 DNS_time_handler();
  54.         }
  55. }

  56. /**
  57.   * @brief  串口打印輸出
  58.   * @param  None
  59.   * @retval None
  60.   */
  61. int main(void)
  62. {
  63.    int8_t  ret;
  64.    uint8_t tmp;
  65.    uint8_t memsize[2][8] = { {2,2,2,2,2,2,2,2},{2,2,2,2,2,2,2,2}};
  66.         //Host dependent peripheral initialized
  67.         platform_init();
  68.         // First of all, Should register SPI callback functions implemented by user for accessing WIZCHIP
  69.         /* Critical section callback */
  70.         reg_wizchip_cris_cbfunc(SPI_CrisEnter, SPI_CrisExit);        //注冊臨界區函數
  71.         /* Chip selection call back */
  72. #if   _WIZCHIP_IO_MODE_ == _WIZCHIP_IO_MODE_SPI_VDM_
  73.         reg_wizchip_cs_cbfunc(SPI_CS_Select, SPI_CS_Deselect);//注冊SPI片選信號函數
  74. #elif _WIZCHIP_IO_MODE_ == _WIZCHIP_IO_MODE_SPI_FDM_
  75.         reg_wizchip_cs_cbfunc(SPI_CS_Select, SPI_CS_Deselect);  // CS must be tried with LOW.
  76. #else
  77.    #if (_WIZCHIP_IO_MODE_ & _WIZCHIP_IO_MODE_SIP_) != _WIZCHIP_IO_MODE_SIP_
  78.       #error "Unknown _WIZCHIP_IO_MODE_"
  79.    #else
  80.       reg_wizchip_cs_cbfunc(wizchip_select, wizchip_deselect);
  81.    #endif
  82. #endif
  83.         /* SPI Read & Write callback function */
  84.         reg_wizchip_spi_cbfunc(SPI_ReadByte, SPI_WriteByte);        //注冊讀寫函數

  85.         /* WIZCHIP SOCKET Buffer initialize */
  86.         if(ctlwizchip(CW_INIT_WIZCHIP,(void*)memsize) == -1){
  87.                  printf("WIZCHIP Initialized fail.\r\n");
  88.                  while(1);
  89.         }

  90.         /* PHY link status check */
  91.         do{
  92.                  if(ctlwizchip(CW_GET_PHYLINK, (void*)&tmp) == -1){
  93.                                 printf("Unknown PHY Link stauts.\r\n");
  94.                  }
  95.         }while(tmp == PHY_LINK_OFF);

  96.     /* Network initialization */
  97.     network_init(); // Static netinfo setting

  98.     /************************************************/
  99.     /* WIZnet W5500 Code Examples :                                 */
  100.     /* Implemented using ioLibrary_BSD Socket APIs        */
  101.     /************************************************/
  102.     /* >> DNS Client                                                                 */
  103.     /************************************************/

  104. #ifdef _MAIN_DEBUG_
  105.    printf("\r\n=== DNS Client Example ===============\r\n");
  106.    printf("> DNS 1st : %d.%d.%d.%d\r\n", gWIZNETINFO.dns[0], gWIZNETINFO.dns[1], gWIZNETINFO.dns[2], gWIZNETINFO.dns[3]);
  107.    printf("> DNS 2nd : %d.%d.%d.%d\r\n", DNS_2nd[0], DNS_2nd[1], DNS_2nd[2], DNS_2nd[3]);
  108.    printf("======================================\r\n");
  109.    printf("> Example Domain Name : %s\r\n", Domain_name);
  110. #endif
  111.    /* DNS client initialization */
  112.    DNS_init(SOCK_DNS, gDATABUF);

  113.    /* DNS procssing */
  114.    if ((ret = DNS_run(gWIZNETINFO.dns, Domain_name, Domain_IP)) > 0) // try to 1st DNS
  115.    {
  116. #ifdef _MAIN_DEBUG_
  117.       printf("> 1st DNS Reponsed\r\n");
  118. #endif
  119.    }
  120.    else if ((ret != -1) && ((ret = DNS_run(DNS_2nd, Domain_name, Domain_IP))>0))     // retry to 2nd DNS
  121.    {
  122. #ifdef _MAIN_DEBUG_
  123.       printf("> 2nd DNS Reponsed\r\n");
  124. #endif
  125.    }
  126.    else if(ret == -1)
  127.    {
  128. #ifdef _MAIN_DEBUG_
  129.       printf("> MAX_DOMAIN_NAME is too small. Should be redefined it.\r\n");
  130. #endif
  131.    }
  132.    else
  133.    {
  134. #ifdef _MAIN_DEBUG_
  135.       printf("> DNS Failed\r\n");
  136. #endif
  137.    }

  138.    if(ret > 0)
  139.    {
  140. #ifdef _MAIN_DEBUG_
  141.       printf("> Translated %s to %d.%d.%d.%d\r\n",Domain_name,Domain_IP[0],Domain_IP[1],Domain_IP[2],Domain_IP[3]);
  142. #endif
  143.       //
  144.       // TO DO
  145.       //
  146.    }
  147.         /* Main Loop */
  148.         while(1)
  149.         {

  150.         }
  151. } // end of main()




  152. /**
  153.   * @brief  Loopback Test Example Code using ioLibrary_BSD        
  154.   * @retval None
  155.   */
  156. void platform_init(void)
  157. {
  158.         SystemInit();//系統時鐘初始化
  159.         USART_Configuration();//串口1初始化
  160.         printf("\x0c");printf("\x0c");//超級終端清屏
  161.         printf("\033[1;40;32m");//設置超級終端背景為黑色,字符為綠色
  162.         printf("\r\n*******************************************************************************");
  163.         printf("\r\n************************ Copyright 2009-2014, EmbedNet ************************");
  164.         printf("\r\n*************************** http://www點embed-net點com **************************");
  165.         printf("\r\n***************************** All Rights Reserved *****************************");
  166.         printf("\r\n*******************************************************************************");
  167.         printf("\r\n");
  168.         //Config SPI
  169.         SPI_Configuration();
  170.         //滴答定時器初始化
  171.         SysTick_Config(72000000 / 1000);//1ms
  172. }

  173. /******************************************************************************
  174. * @brief  Network Init
  175. * Intialize the network information to be used in WIZCHIP
  176. *****************************************************************************/
  177. void network_init(void)
  178. {
  179. #ifdef _MAIN_DEBUG_
  180.         uint8_t tmpstr[6] = {0,};
  181.         wiz_NetInfo netinfo;
  182. #endif

  183.         // Set Network information from netinfo structure
  184.         ctlnetwork(CN_SET_NETINFO, (void*)&gWIZNETINFO);

  185. #ifdef _MAIN_DEBUG_
  186.         // Get Network information
  187.         ctlnetwork(CN_GET_NETINFO, (void*)&netinfo);

  188.         // Display Network Information
  189.         ctlwizchip(CW_GET_ID,(void*)tmpstr);

  190.         if(netinfo.dhcp == NETINFO_DHCP) printf("\r\n=== %s NET CONF : DHCP ===\r\n",(char*)tmpstr);
  191.         else printf("\r\n=== %s NET CONF : Static ===\r\n",(char*)tmpstr);

  192.         printf("MAC: %02X:%02X:%02X:%02X:%02X:%02X\r\n",netinfo.mac[0],netinfo.mac[1],netinfo.mac[2],
  193.                         netinfo.mac[3],netinfo.mac[4],netinfo.mac[5]);
  194.         printf("SIP: %d.%d.%d.%d\r\n", netinfo.ip[0],netinfo.ip[1],netinfo.ip[2],netinfo.ip[3]);
  195.         printf("GAR: %d.%d.%d.%d\r\n", netinfo.gw[0],netinfo.gw[1],netinfo.gw[2],netinfo.gw[3]);
  196.         printf("SUB: %d.%d.%d.%d\r\n", netinfo.sn[0],netinfo.sn[1],netinfo.sn[2],netinfo.sn[3]);
  197.         printf("DNS: %d.%d.%d.%d\r\n", netinfo.dns[0],netinfo.dns[1],netinfo.dns[2],netinfo.dns[3]);
  198.         printf("===========================\r\n");
  199. #endif

  200. }

  201. /*********************************END OF FILE**********************************/
復制代碼


分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復

使用道具 舉報

沙發
ID:137543 發表于 2018-1-27 14:29 | 只看該作者
感謝,看了10分鐘就調通了,樓主威武
回復

使用道具 舉報

板凳
ID:35312 發表于 2018-3-2 20:11 | 只看該作者
非常需要.謝謝樓主
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 欧美精品在线免费观看 | 国产免费播放视频 | 91看片官网 | 亚洲欧美日韩电影 | 91影院| 日韩在线观看中文字幕 | 粉嫩粉嫩芽的虎白女18在线视频 | 亚洲一区二区三区在线观看免费 | 国产成人精品免高潮在线观看 | 毛片在线视频 | 亚洲一区二区视频 | 一级做a爰片性色毛片 | 在线中文字幕av | 成人 在线 | 日韩在线视频一区 | 精品国产综合 | 久久一| 国产免费播放视频 | www.久久精品| www.久久久久久久久久久久 | 91精品国产91久久久久游泳池 | 国产91亚洲精品一区二区三区 | 国产一区二区三区四区hd | 六月成人网| 国产精品视频在线播放 | 一级欧美视频 | 韩日在线 | 热久久久 | 日韩av成人 | 国产福利资源在线 | 中文在线www | 国产电影一区二区在线观看 | xxxxx免费视频 | 欧美精品91 | 久久99深爱久久99精品 | 亚洲欧美另类在线观看 | 少妇一级淫片免费播放 | 中文字幕色站 | 毛片视频观看 | 欧美国产日韩精品 | 免费黄色的视频 |